Commit b36c4911 authored by Felix Häcker's avatar Felix Häcker

restructured project tree, initial page work

parent cd2d04af
......@@ -3,4 +3,7 @@
target/
target
**/*.rs.bk
Cargo.toml
\ No newline at end of file
Cargo.lock
_build
.buildconfig
de.haeckerfelix.Gradio.json~
\ No newline at end of file
This diff is collapsed.
[package]
name = "gradio"
version = "0.8.0"
authors = ["Felix Häcker <haecker.felix1207@gmail.com>"]
[dependencies]
log = "0.4"
pretty_env_logger = "0.2"
gio = "0.4.0"
[dependencies.gtk]
version = "0.4.0"
features = ["v3_10"]
[dependencies.rustio]
path = "./rustio"
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.0 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkSizeGroup" id="content_sz"/>
<object class="GtkApplicationWindow" id="main_window">
<property name="width_request">600</property>
<property name="height_request">400</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="default_width">800</property>
<property name="default_height">500</property>
<property name="icon_name">de.haeckerfelix.Gradio</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkBox" id="sidebar_box">
<property name="width_request">230</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkStackSidebar">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="border_width">12</property>
<property name="stack">page_stack</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkSeparator">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkBox" id="content_box">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkStack" id="page_stack">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="border_width">12</property>
<child>
<object class="GtkBox" id="test_page">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">6</property>
<child>
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="column_spacing">12</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Station Name</property>
<style>
<class name="dim-label"/>
</style>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="station_name_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">-</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="station_language_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">-</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Current title</property>
<style>
<class name="dim-label"/>
</style>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">3</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Language</property>
<style>
<class name="dim-label"/>
</style>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Playable URL</property>
<style>
<class name="dim-label"/>
</style>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">2</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="current_title_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">-</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">3</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="playable_url_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">-</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="id_entry">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="placeholder_text" translatable="yes">Enter a station id....</property>
<property name="input_purpose">number</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkButton" id="get_button">
<property name="label" translatable="yes">Get station data</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkButton" id="start_playback_button">
<property name="label" translatable="yes">Start playback</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
<child>
<object class="GtkSeparator">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">3</property>
</packing>
</child>
<child>
<object class="GtkButton" id="stop_playback_button">
<property name="label" translatable="yes">Stop playback</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">4</property>
</packing>
</child>
</object>
<packing>
<property name="name">test</property>
<property name="title" translatable="yes">Test Page</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
</child>
<child type="titlebar">
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkHeaderBar" id="sidebar_header">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkSeparator">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkHeaderBar" id="content_header">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="title">Gradio</property>
<property name="subtitle">Rust Preview</property>
<property name="show_close_button">True</property>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
</child>
</object>
<object class="GtkSizeGroup" id="sidebar_sz">
<widgets>
<widget name="sidebar_box"/>
<widget name="sidebar_header"/>
</widgets>
</object>
</interface>
max_width=200
\ No newline at end of file
[package]
name = "rustio"
version = "0.1.0"
authors = ["Felix Häcker <haecker.felix1207@gmail.com>"]
[dependencies]
gstreamer = "0.11.1"
reqwest = "0.8.5"
serde = "1.0.43"
serde_json = "1.0"
serde_derive = "1.0.43"
log = "0.4"
\ No newline at end of file
extern crate gio;
extern crate gtk;
use gio::{ApplicationExt, ApplicationExtManual};
use gtk::prelude::*;
extern crate rustio;
use rustio::{audioplayer::AudioPlayer, client::Client};
use std::cell::RefCell;
use std::rc::Rc;
use page::library_page::LibraryPage;
use page::page::Page;
use page::test_page::TestPage;
pub struct GradioApp {
pub player: Rc<RefCell<AudioPlayer>>,
pub client: Rc<Client>,
builder: gtk::Builder,
gtk_app: gtk::Application,
window: gtk::ApplicationWindow,
page_stack: gtk::Stack,
library_page: LibraryPage,
test_page: TestPage,
}
impl GradioApp {
pub fn new() -> GradioApp {
let player = Rc::new(RefCell::new(AudioPlayer::new()));
let client = Rc::new(Client::new());
let builder = gtk::Builder::new_from_string(include_str!("window.ui"));
let gtk_app = gtk::Application::new("de.haeckerfelix.Gradio", gio::ApplicationFlags::empty()).expect("Failed to initialize GtkApplication");
let window: gtk::ApplicationWindow = builder.get_object("main_window").unwrap();
let page_stack: gtk::Stack = builder.get_object("page_stack").unwrap();
let library_page: LibraryPage = Page::new();
page_stack.add_titled(library_page.get_container(), &library_page.get_name(), &library_page.get_title());
let test_page: TestPage = Page::new();
page_stack.add_titled(test_page.get_container(), &test_page.get_name(), &test_page.get_title());
GradioApp {
player,
client,
builder,
gtk_app,
window,
page_stack,
library_page,
test_page,
}
}
pub fn run(&self) {
self.connect_signals();
self.gtk_app.run(&[]);
}
fn connect_signals(&self) {
// GTK Application activate
let window_clone = self.window.clone();
self.gtk_app.connect_activate(move |app| {
app.add_window(&window_clone);
debug!("gtk application activate");
});
// Test Page
let player = self.player.clone();
let client = self.client.clone();
self.test_page.connect_signals(&player, &client);
}
}
#[macro_use] extern crate log;
#[macro_use]
extern crate log;
extern crate pretty_env_logger;
extern crate gtk;
extern crate gio;
extern crate gtk;
extern crate rustio;
mod app;
mod page;
use app::GradioApp;
fn main() {
......@@ -21,4 +23,4 @@ fn main() {
// Run App
let app = GradioApp::new();
app.run();
}
\ No newline at end of file
}
extern crate gtk;
use gtk::prelude::*;
use page::page::Page;
pub struct LibraryPage {
title: String,
name: String,
builder: gtk::Builder,
container: gtk::Box,
}
impl LibraryPage {}
impl Page for LibraryPage {
fn new() -> Self {
let title = "Library".to_string();
let name = "library_page".to_string();
let builder = gtk::Builder::new_from_string(include_str!("library_page.ui"));
let container: gtk::Box = builder.get_object("library_page").unwrap();
Self { title, name, builder, container }
}
fn get_title(&self) -> &String {
&self.title
}
fn get_name(&self) -> &String {
&self.name
}
fn get_container(&self) -> &gtk::Box {
&self.container
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.0 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkBox" id="library_page">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Library Page</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
</object>
</interface>
pub mod library_page;
pub mod page;
pub mod test_page;
extern crate gtk;
use gtk::prelude::*;
pub trait Page {
fn new() -> Self;
fn get_title(&self) -> &String;
fn get_name(&self) -> &String;
fn get_container(&self) -> &gtk::Box;
}
extern crate gio;
extern crate gtk;
use gtk::prelude::*;
use gio::{ApplicationExtManual, ApplicationExt};
extern crate rustio;
use rustio::{client::Client, audioplayer::AudioPlayer};
use std::str::FromStr;
use std::rc::Rc;
use std::cell::RefCell;
use std::rc::Rc;
use std::str::FromStr;
use page::page::Page;
use rustio::{audioplayer::AudioPlayer, client::Client};
pub struct GradioApp{
pub player: Rc<RefCell<AudioPlayer>>,
pub client: Rc<Client>,
pub struct TestPage {
title: String,
name: String,
gtk_app: gtk::Application,
window: gtk::ApplicationWindow,
builder: gtk::Builder,
container: gtk::Box,
}
impl GradioApp {
pub fn new() -> GradioApp {
let player = Rc::new(RefCell::new(AudioPlayer::new()));
let client = Rc::new(Client::new());
let gtk_app = gtk::Application::new("de.haeckerfelix.Gradio", gio::ApplicationFlags::empty()).expect("Failed to initialize GtkApplication");
let builder = gtk::Builder::new_from_string(include_str!("window.ui"));
let window: gtk::ApplicationWindow = builder.get_object("main_window").unwrap();
GradioApp{player, client, gtk_app, window, builder}
}
pub fn run(&self){
self.connect_signals();
self.gtk_app.run(&[]);
}
fn connect_signals(&self) {
impl TestPage {
pub fn connect_signals(&self, app_player: &Rc<RefCell<AudioPlayer>>, app_client: &Rc<Client>) {
let get_button: gtk::Button = self.builder.get_object("get_button").unwrap();
let stop_playback_button: gtk::Button = self.builder.get_object("stop_playback_button").unwrap();
let start_playback_button: gtk::Button = self.builder.get_object("start_playback_button").unwrap();
......@@ -45,17 +26,10 @@ impl GradioApp {
let station_language_label: gtk::Label = self.builder.get_object("station_language_label").unwrap();
let playable_url_label: gtk::Label = self.builder.get_object("playable_url_label").unwrap();
// GTK Application activate
let window_clone = self.window.clone();
self.gtk_app.connect_activate(move|app| {
app.add_window(&window_clone);
debug!("gtk application activate");
});
// get_button clicked
let player = self.player.clone();
let client = self.client.clone();
get_button.connect_clicked(move|_|{
let player = app_player.clone();
let client = app_client.clone();
get_button.connect_clicked(move |_| {
let station_id: i32 = FromStr::from_str(&id_entry.get_text().unwrap()).unwrap();
let new_station = client.get_station_by_id(station_id);
......@@ -66,20 +40,43 @@ impl GradioApp {
playable_url_label.set_text(&playable_url);
player.borrow_mut().set_station_url(playable_url);
//self.current_station = Some(new_station);
info!("button clicked");
});
// start_playback_button clicked
let player = self.player.clone();
start_playback_button.connect_clicked(move|_|{
player.borrow_mut().set_playback(true);
let player = app_player.clone();
start_playback_button.connect_clicked(move |_| {
player.borrow_mut().set_playback(true);
});
// stop_playback_button clicked
let player = self.player.clone();
stop_playback_button.connect_clicked(move|_|{
player.borrow_mut().set_playback(false);
let player = app_player.clone();
stop_playback_button.connect_clicked(move |_| {
player.borrow_mut().set_playback(false);
});
}
}
\ No newline at end of file
}
impl Page for TestPage {
fn new() -> Self {
let title = "Test/Debug".to_string();
let name = "test_page".to_string();
let builder = gtk::Builder::new_from_string(include_str!("test_page.ui"));
let container: gtk::Box = builder.get_object("test_page").unwrap();
Self { title, name, builder, container }
}
fn get_title(&self) -> &String {
&self.title
}
fn get_name(&self) -> &String {
&self.name
}
fn get_container(&self) -> &gtk::Box {
&self.container
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.0 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkBox" id="test_page">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="border_width">12</property>
<property name="orientation">vertical</property>
<property name="spacing">6</property>
<child>
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="column_spacing">12</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Station Name</property>
<style>
<class name="dim-label"/>
</style>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="station_name_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">-</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="station_language_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">-</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>