Split flowbox child into its own glade file, and wrapped them into event box.
This commit is contained in:
parent
460345f49a
commit
2955579f6d
@ -121,6 +121,7 @@ fn get_episode(connection: &SqliteConnection, ep: &mut Episode, dl_folder: &str)
|
||||
}
|
||||
|
||||
// pub fn cache_image(pd: &Podcast) -> Option<String> {
|
||||
// TODO: Refactor
|
||||
pub fn cache_image(title: &str, image_uri: Option<&str>) -> Option<String> {
|
||||
info!("{:?}", image_uri);
|
||||
if let Some(url) = image_uri {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- Generated with glade 3.20.0 -->
|
||||
<!-- Generated with glade 3.20.1 -->
|
||||
<interface>
|
||||
<requires lib="gtk+" version="3.20"/>
|
||||
<object class="GtkTreeStore" id="FooStore">
|
||||
@ -24,6 +24,39 @@
|
||||
<column type="gchararray"/>
|
||||
</columns>
|
||||
</object>
|
||||
<object class="GtkBox">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="orientation">vertical</property>
|
||||
<child>
|
||||
<object class="GtkScrolledWindow">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="shadow_type">in</property>
|
||||
<child>
|
||||
<object class="GtkViewport">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<child>
|
||||
<object class="GtkBox" id="box2">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="orientation">vertical</property>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<object class="GtkWindow" id="window1">
|
||||
<property name="can_focus">False</property>
|
||||
<property name="default_width">1000</property>
|
||||
@ -91,47 +124,4 @@
|
||||
<placeholder/>
|
||||
</child>
|
||||
</object>
|
||||
<object class="GtkWindow" id="window2">
|
||||
<property name="can_focus">False</property>
|
||||
<property name="default_width">800</property>
|
||||
<property name="default_height">400</property>
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="orientation">vertical</property>
|
||||
<child>
|
||||
<object class="GtkScrolledWindow">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="shadow_type">in</property>
|
||||
<child>
|
||||
<object class="GtkViewport">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<child>
|
||||
<object class="GtkBox" id="box2">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="orientation">vertical</property>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child type="titlebar">
|
||||
<placeholder/>
|
||||
</child>
|
||||
</object>
|
||||
</interface>
|
||||
|
||||
52
hammond-gtk/gtk/pd_fb_child.ui
Normal file
52
hammond-gtk/gtk/pd_fb_child.ui
Normal file
@ -0,0 +1,52 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- Generated with glade 3.20.1 -->
|
||||
<interface>
|
||||
<requires lib="gtk+" version="3.20"/>
|
||||
<object class="GtkBox" id="fb_child">
|
||||
<property name="width_request">200</property>
|
||||
<property name="height_request">200</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="orientation">vertical</property>
|
||||
<child>
|
||||
<object class="GtkOverlay">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<child>
|
||||
<object class="GtkEventBox">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<child>
|
||||
<object class="GtkImage" id="pd_cover">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="icon_name">gtk-missing-image</property>
|
||||
<property name="icon_size">6</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="index">-1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="pd_title">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">label</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
</interface>
|
||||
@ -11,36 +11,32 @@ extern crate loggerv;
|
||||
use log::LogLevel;
|
||||
use diesel::prelude::*;
|
||||
use gtk::{CellRendererText, TreeStore, TreeView, TreeViewColumn};
|
||||
use gtk::IconSize;
|
||||
use gtk::Orientation;
|
||||
// use gtk::Type;
|
||||
use gtk::prelude::*;
|
||||
use gdk_pixbuf::Pixbuf;
|
||||
use hammond_data::dbqueries;
|
||||
use hammond_data::models::Podcast;
|
||||
// use hammond_data::models::Podcast;
|
||||
|
||||
fn create_flowbox_child(title: &str, image_uri: Option<&str>) -> gtk::Box {
|
||||
let build_src = include_str!("../gtk/pd_fb_child.ui");
|
||||
let builder = gtk::Builder::new_from_string(build_src);
|
||||
|
||||
// Copy of gnome-music AlbumWidget
|
||||
let box_: gtk::Box = builder.get_object("fb_child").unwrap();
|
||||
let pd_title: gtk::Label = builder.get_object("pd_title").unwrap();
|
||||
let pd_cover: gtk::Image = builder.get_object("pd_cover").unwrap();
|
||||
|
||||
pd_title.set_text(&title);
|
||||
|
||||
// TODO: setup a img downloader, caching system, and then display them.
|
||||
fn create_child(title: &str, image_uri: Option<&str>) -> gtk::Box {
|
||||
let box_ = gtk::Box::new(Orientation::Vertical, 5);
|
||||
let imgpath = hammond_downloader::downloader::cache_image(title, image_uri);
|
||||
info!("{:?}", imgpath);
|
||||
let img = if let Some(i) = imgpath {
|
||||
|
||||
if let Some(i) = imgpath {
|
||||
let pixbuf = Pixbuf::new_from_file_at_scale(&i, 200, 200, true);
|
||||
// gtk::Image::new_from_file(&i)
|
||||
// Ugly hack
|
||||
if pixbuf.is_ok() {
|
||||
gtk::Image::new_from_pixbuf(&pixbuf.unwrap())
|
||||
} else {
|
||||
gtk::Image::new_from_icon_name("gtk-missing-image", IconSize::Menu.into())
|
||||
pd_cover.set_from_pixbuf(&pixbuf.unwrap())
|
||||
}
|
||||
} else {
|
||||
gtk::Image::new_from_icon_name("gtk-missing-image", IconSize::Menu.into())
|
||||
};
|
||||
|
||||
let label = gtk::Label::new(title);
|
||||
box_.set_size_request(200, 200);
|
||||
box_.pack_start(&img, true, true, 0);
|
||||
box_.pack_start(&label, false, false, 0);
|
||||
box_
|
||||
}
|
||||
|
||||
@ -92,12 +88,10 @@ fn create_and_setup_view() -> TreeView {
|
||||
|
||||
tree.set_headers_visible(false);
|
||||
|
||||
// Creating the two columns inside the view.
|
||||
let column = TreeViewColumn::new();
|
||||
let cell = CellRendererText::new();
|
||||
|
||||
column.pack_start(&cell, true);
|
||||
// Association of the view's column with the model's `id` column.
|
||||
column.add_attribute(&cell, "text", 1);
|
||||
tree.append_column(&column);
|
||||
|
||||
@ -127,7 +121,6 @@ fn main() {
|
||||
}
|
||||
hammond_data::init().unwrap();
|
||||
|
||||
// Adapted copy of the way gnome-music does albumview
|
||||
let glade_src = include_str!("../gtk/foo.ui");
|
||||
let header_src = include_str!("../gtk/headerbar.ui");
|
||||
let builder = gtk::Builder::new_from_string(glade_src);
|
||||
@ -135,17 +128,10 @@ fn main() {
|
||||
|
||||
// Get the main window
|
||||
let window: gtk::Window = builder.get_object("window1").unwrap();
|
||||
// let window: gtk::Window = builder.get_object("window2").unwrap();
|
||||
// Get the headerbar
|
||||
let header: gtk::HeaderBar = header_build.get_object("headerbar1").unwrap();
|
||||
window.set_titlebar(&header);
|
||||
|
||||
// Debuging TreeStore
|
||||
// let box2: gtk::Box = builder.get_object("box2").unwrap();
|
||||
// let treeview = create_and_setup_view();
|
||||
// treeview.set_model(Some(&pd_model));
|
||||
// box2.add(&treeview);
|
||||
|
||||
let refresh_button: gtk::Button = header_build.get_object("refbutton").unwrap();
|
||||
// TODO: Have a small dropdown menu
|
||||
let _add_button: gtk::Button = header_build.get_object("addbutton").unwrap();
|
||||
@ -164,6 +150,7 @@ fn main() {
|
||||
Inhibit(false)
|
||||
});
|
||||
|
||||
// Adapted copy of the way gnome-music does albumview
|
||||
let flowbox: gtk::FlowBox = builder.get_object("flowbox1").unwrap();
|
||||
let db = hammond_data::establish_connection();
|
||||
let pd_model = create_tree_store(&db, &builder);
|
||||
@ -175,7 +162,7 @@ fn main() {
|
||||
let title = pd_model.get_value(&iter, 1).get::<String>().unwrap();
|
||||
let image_uri = pd_model.get_value(&iter, 5).get::<String>();
|
||||
info!("{:?}", title);
|
||||
let f = create_child(&title, image_uri.as_ref().map(|s| s.as_str()));
|
||||
let f = create_flowbox_child(&title, image_uri.as_ref().map(|s| s.as_str()));
|
||||
|
||||
flowbox.add(&f);
|
||||
|
||||
@ -184,6 +171,14 @@ fn main() {
|
||||
}
|
||||
}
|
||||
|
||||
// Debuging TreeStore
|
||||
// let box2: gtk::Box = builder.get_object("box2").unwrap();
|
||||
// let treeview = create_and_setup_view();
|
||||
// treeview.set_model(Some(&pd_model));
|
||||
// box2.add(&treeview);
|
||||
// window.add(&box2);
|
||||
// window.show_all();
|
||||
|
||||
window.show_all();
|
||||
gtk::main();
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user