EpisodesView: Ugly and Hacky Prototype of episode splitting.

This commit is contained in:
Jordan Petridis 2017-12-20 15:12:55 +02:00
parent ace62f7ed6
commit c070fc3032
No known key found for this signature in database
GPG Key ID: CEABAD9F5683B9A6
2 changed files with 318 additions and 98 deletions

View File

@ -44,15 +44,50 @@
<property name="orientation">vertical</property>
<property name="spacing">7</property>
<child>
<object class="GtkLabel" id="today_label">
<object class="GtkBox" id="today_box">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="no_show_all">True</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Today</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel" id="today_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Today</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkFrame">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label_xalign">0</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkListBox" id="today_list">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="selection_mode">none</property>
</object>
</child>
<child type="label_item">
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
@ -61,22 +96,49 @@
</packing>
</child>
<child>
<object class="GtkFrame">
<object class="GtkBox" id="yday_box">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="no_show_all">True</property>
<property name="label_xalign">0</property>
<property name="shadow_type">in</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkListBox" id="today_box">
<object class="GtkLabel" id="yday_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="no_show_all">True</property>
<property name="selection_mode">none</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Yesterday</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child type="label_item">
<placeholder/>
<child>
<object class="GtkFrame">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label_xalign">0</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkListBox" id="yday_list">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="selection_mode">none</property>
</object>
</child>
<child type="label_item">
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
@ -86,15 +148,50 @@
</packing>
</child>
<child>
<object class="GtkLabel" id="yday_label">
<object class="GtkBox" id="week_box">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="no_show_all">True</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Yesterday</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel" id="week_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">This Week</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkFrame">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label_xalign">0</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkListBox" id="week_list">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="selection_mode">none</property>
</object>
</child>
<child type="label_item">
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
@ -103,20 +200,49 @@
</packing>
</child>
<child>
<object class="GtkFrame">
<object class="GtkBox" id="month_box">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label_xalign">0</property>
<property name="shadow_type">in</property>
<property name="no_show_all">True</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkListBox" id="yday_box">
<object class="GtkLabel" id="month_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="selection_mode">none</property>
<property name="halign">start</property>
<property name="label" translatable="yes">This Month</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child type="label_item">
<placeholder/>
<child>
<object class="GtkFrame">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label_xalign">0</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkListBox" id="month_list">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="selection_mode">none</property>
</object>
</child>
<child type="label_item">
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
@ -126,15 +252,50 @@
</packing>
</child>
<child>
<object class="GtkLabel" id="week_label">
<object class="GtkBox" id="year_box">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="no_show_all">True</property>
<property name="halign">start</property>
<property name="label" translatable="yes">This Week</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel" id="year_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">This Year</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkFrame">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label_xalign">0</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkListBox" id="year_list">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="selection_mode">none</property>
</object>
</child>
<child type="label_item">
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
@ -143,20 +304,50 @@
</packing>
</child>
<child>
<object class="GtkFrame">
<object class="GtkBox" id="rest_box">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label_xalign">0</property>
<property name="shadow_type">in</property>
<property name="no_show_all">True</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkListBox" id="week_box">
<object class="GtkLabel" id="rest_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="selection_mode">none</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Older than a Year</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child type="label_item">
<placeholder/>
<child>
<object class="GtkFrame">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label_xalign">0</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkListBox" id="rest_list">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="no_show_all">True</property>
<property name="selection_mode">none</property>
</object>
</child>
<child type="label_item">
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
@ -165,46 +356,6 @@
<property name="position">5</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="month_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="no_show_all">True</property>
<property name="halign">start</property>
<property name="label" translatable="yes">This Month</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">6</property>
</packing>
</child>
<child>
<object class="GtkFrame">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label_xalign">0</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkListBox" id="month_box">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="selection_mode">none</property>
</object>
</child>
<child type="label_item">
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">7</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>

View File

@ -16,20 +16,32 @@ enum ListSplit {
Yday,
Week,
Month,
Year,
Rest,
}
#[derive(Debug, Clone)]
pub struct EpisodesView {
pub container: gtk::Box,
frame_parent: gtk::Box,
today_box: gtk::ListBox,
yday_box: gtk::ListBox,
week_box: gtk::ListBox,
month_box: gtk::ListBox,
today_box: gtk::Box,
yday_box: gtk::Box,
week_box: gtk::Box,
month_box: gtk::Box,
year_box: gtk::Box,
rest_box: gtk::Box,
today_list: gtk::ListBox,
yday_list: gtk::ListBox,
week_list: gtk::ListBox,
month_list: gtk::ListBox,
year_list: gtk::ListBox,
rest_list: gtk::ListBox,
today_label: gtk::Label,
yday_label: gtk::Label,
week_label: gtk::Label,
month_label: gtk::Label,
year_label: gtk::Label,
rest_label: gtk::Label,
}
impl Default for EpisodesView {
@ -37,14 +49,24 @@ impl Default for EpisodesView {
let builder = gtk::Builder::new_from_resource("/org/gnome/hammond/gtk/episodes_view.ui");
let container: gtk::Box = builder.get_object("container").unwrap();
let frame_parent: gtk::Box = builder.get_object("frame_parent").unwrap();
let today_box: gtk::ListBox = builder.get_object("today_box").unwrap();
let yday_box: gtk::ListBox = builder.get_object("yday_box").unwrap();
let week_box: gtk::ListBox = builder.get_object("week_box").unwrap();
let month_box: gtk::ListBox = builder.get_object("month_box").unwrap();
let today_box: gtk::Box = builder.get_object("today_box").unwrap();
let yday_box: gtk::Box = builder.get_object("yday_box").unwrap();
let week_box: gtk::Box = builder.get_object("week_box").unwrap();
let month_box: gtk::Box = builder.get_object("month_box").unwrap();
let year_box: gtk::Box = builder.get_object("year_box").unwrap();
let rest_box: gtk::Box = builder.get_object("rest_box").unwrap();
let today_list: gtk::ListBox = builder.get_object("today_list").unwrap();
let yday_list: gtk::ListBox = builder.get_object("yday_list").unwrap();
let week_list: gtk::ListBox = builder.get_object("week_list").unwrap();
let month_list: gtk::ListBox = builder.get_object("month_list").unwrap();
let year_list: gtk::ListBox = builder.get_object("year_list").unwrap();
let rest_list: gtk::ListBox = builder.get_object("rest_list").unwrap();
let today_label: gtk::Label = builder.get_object("today_label").unwrap();
let yday_label: gtk::Label = builder.get_object("yday_label").unwrap();
let week_label: gtk::Label = builder.get_object("week_label").unwrap();
let month_label: gtk::Label = builder.get_object("month_label").unwrap();
let year_label: gtk::Label = builder.get_object("year_label").unwrap();
let rest_label: gtk::Label = builder.get_object("rest_label").unwrap();
EpisodesView {
container,
@ -53,10 +75,20 @@ impl Default for EpisodesView {
yday_box,
week_box,
month_box,
year_box,
rest_box,
today_list,
yday_list,
week_list,
month_list,
year_list,
rest_list,
today_label,
yday_label,
week_label,
month_label,
year_label,
rest_label,
}
}
}
@ -76,31 +108,64 @@ impl EpisodesView {
let t = split(now_utc, ep.epoch());
match t {
ListSplit::Today => {
view.today_box.add(&viewep.container);
view.today_box.add(&sep)
view.today_list.add(&viewep.container);
view.today_list.add(&sep)
}
ListSplit::Yday => {
view.yday_box.add(&viewep.container);
view.yday_box.add(&sep)
view.yday_list.add(&viewep.container);
view.yday_list.add(&sep)
}
ListSplit::Week => {
view.week_box.add(&viewep.container);
view.week_box.add(&sep)
view.week_list.add(&viewep.container);
view.week_list.add(&sep)
}
_ => {
view.month_box.add(&viewep.container);
view.month_box.add(&sep)
ListSplit::Month => {
view.month_list.add(&viewep.container);
view.month_list.add(&sep)
}
ListSplit::Year => {
view.year_list.add(&viewep.container);
view.year_list.add(&sep)
}
ListSplit::Rest => {
view.rest_list.add(&viewep.container);
view.rest_list.add(&sep)
}
}
sep.show()
});
if view.today_list.get_children().is_empty() {
view.today_box.hide();
}
if view.yday_list.get_children().is_empty() {
view.yday_box.hide();
}
if view.week_list.get_children().is_empty() {
view.week_box.hide();
}
if view.month_list.get_children().is_empty() {
view.month_box.hide();
}
if view.year_list.get_children().is_empty() {
view.year_box.hide();
}
if view.rest_list.get_children().is_empty() {
view.rest_box.hide();
}
view.container.show_all();
Rc::new(view)
}
}
// TODO: Avoid epoch calculations, use chrono instead.
fn split(now_utc: i32, epoch: i32) -> ListSplit {
let t = now_utc - epoch;
@ -110,8 +175,12 @@ fn split(now_utc: i32, epoch: i32) -> ListSplit {
ListSplit::Yday
} else if t < 604_800 {
ListSplit::Week
} else {
} else if t < 2_419_200 {
ListSplit::Month
} else if t < 31_536_000 {
ListSplit::Year
} else {
ListSplit::Rest
}
}