[baobab] Rework contributed code
- From: Stefano Facchini <sfacchini src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [baobab] Rework contributed code
- Date: Fri, 12 Aug 2016 15:11:22 +0000 (UTC)
commit 366cc60675c378318a4c27357e85571241323768
Author: Stefano Facchini <stefano facchini gmail com>
Date: Wed Aug 10 19:37:33 2016 +0200
Rework contributed code
Just one class for the location list widget.
po/POTFILES.in | 1 +
src/baobab-location-list.ui | 59 ++++++++++++++++---
src/baobab-location-list.vala | 128 +++++++++++++----------------------------
src/baobab-location-row.ui | 7 +--
src/baobab-main-window.ui | 16 +-----
src/baobab-window.vala | 19 +-----
6 files changed, 96 insertions(+), 134 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 95dfd46..cfaf4b9 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -6,6 +6,7 @@ data/org.gnome.baobab.gschema.xml.in
src/baobab-application.vala
src/baobab-cellrenderers.vala
src/baobab-location.vala
+src/baobab-location-list.ui
src/baobab-main-window.ui
src/baobab-window.vala
src/menus.ui
diff --git a/src/baobab-location-list.ui b/src/baobab-location-list.ui
index d70eb66..e616e65 100644
--- a/src/baobab-location-list.ui
+++ b/src/baobab-location-list.ui
@@ -1,30 +1,69 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<!-- interface-requires gtk+ 3.0 -->
- <template class="BaobabBaseLocationListWidget" parent="GtkBox">
+ <template class="BaobabLocationList" parent="GtkBox">
<property name="visible">True</property>
<property name="orientation">vertical</property>
- <property name="spacing">6</property>
+ <property name="spacing">32</property>
+ <property name="margin">32</property>
<child>
- <object class="GtkLabel" id="label_widget">
+ <object class="GtkBox" id="local_box">
<property name="visible">True</property>
- <property name="halign">start</property>
- <style>
- <class name="dim-label"/>
- </style>
+ <property name="orientation">vertical</property>
+ <child>
+ <object class="GtkLabel" id="local_label">
+ <property name="visible">True</property>
+ <property name="halign">start</property>
+ <property name="label" translatable="yes">This Computer</property>
+ <style>
+ <class name="dim-label"/>
+ </style>
+ </object>
+ </child>
+ <child>
+ <object class="GtkFrame">
+ <property name="visible">True</property>
+ <child>
+ <object class="GtkListBox" id="local_list_box">
+ <property name="visible">True</property>
+ <property name="selection_mode">none</property>
+ <style>
+ <class name="view"/>
+ </style>
+ </object>
+ </child>
+ </object>
+ </child>
</object>
</child>
<child>
- <object class="GtkFrame">
+ <object class="GtkBox" id="remote_box">
<property name="visible">True</property>
+ <property name="orientation">vertical</property>
<child>
- <object class="GtkListBox" id="list">
+ <object class="GtkLabel" id="remote_label">
<property name="visible">True</property>
+ <property name="halign">start</property>
+ <property name="label" translatable="yes">Remote Locations</property>
<style>
- <class name="view"/>
+ <class name="dim-label"/>
</style>
</object>
</child>
+ <child>
+ <object class="GtkFrame">
+ <property name="visible">True</property>
+ <child>
+ <object class="GtkListBox" id="remote_list_box">
+ <property name="visible">True</property>
+ <property name="selection_mode">none</property>
+ <style>
+ <class name="view"/>
+ </style>
+ </object>
+ </child>
+ </object>
+ </child>
</object>
</child>
</template>
diff --git a/src/baobab-location-list.vala b/src/baobab-location-list.vala
index 1b3acd6..56ccc3e 100644
--- a/src/baobab-location-list.vala
+++ b/src/baobab-location-list.vala
@@ -55,11 +55,10 @@ namespace Baobab {
if (location.is_volume || location.is_main_volume) {
if (location.size != null) {
- total_size_label.label = "%s Total".printf (format_size (location.size));
- total_size_label.show ();
+ total_size_label.label = _("%s Total").printf (format_size (location.size));
if (location.used != null) {
- available_label.label = "%s Available".printf (format_size (location.size -
location.used));
+ available_label.label = _("%s Available").printf (format_size (location.size -
location.used));
usage_bar.max_value = location.size;
@@ -68,30 +67,35 @@ namespace Baobab {
usage_bar.value = location.used;
usage_bar.show ();
} else {
- available_label.label = "Unknown";
+ available_label.label = _("Unknown");
}
- }
-
- if (location.used != null) {
+ } else if (location.used != null) {
// useful for some remote mounts where we don't know the
// size but do have a usage figure
- available_label.label = "%s Used".printf (format_size (location.used));
+ available_label.label = _("%s Used").printf (format_size (location.used));
}
-
- available_label.show ();
}
}
}
- public class LocationList : Object {
+ [GtkTemplate (ui = "/org/gnome/baobab/ui/baobab-location-list.ui")]
+ public class LocationList : Gtk.Box {
+ [GtkChild]
+ private Gtk.ListBox local_list_box;
+ [GtkChild]
+ private Gtk.ListBox remote_list_box;
+ [GtkChild]
+ private Gtk.Box remote_box;
+
+ public delegate void LocationAction (Location l);
+ private LocationAction? location_action;
+
private const int MAX_RECENT_LOCATIONS = 5;
private VolumeMonitor monitor;
private List<Location> locations = null;
- public signal void update ();
-
construct {
monitor = VolumeMonitor.get ();
monitor.mount_changed.connect (mount_changed);
@@ -101,18 +105,16 @@ namespace Baobab {
monitor.volume_removed.connect (volume_removed);
monitor.volume_added.connect (volume_added);
- populate ();
- }
+ local_list_box.set_header_func (update_header);
+ local_list_box.row_activated.connect (row_activated);
- public void append (Location location) {
- locations.append(location);
- }
+ remote_list_box.set_header_func (update_header);
+ remote_list_box.row_activated.connect (row_activated);
- public void @foreach (Func<Location> func) {
- locations.foreach (func);
+ populate ();
}
- public bool already_present (File file) {
+ bool already_present (File file) {
foreach (var l in locations) {
if (l.file != null && l.file.equal (file)) {
return true;
@@ -137,7 +139,7 @@ namespace Baobab {
}
void volume_added (Volume volume) {
- append (new Location.from_volume (volume));
+ locations.append (new Location.from_volume (volume));
update ();
}
@@ -159,7 +161,7 @@ namespace Baobab {
var volume = mount.get_volume ();
if (volume == null) {
if (!already_present (mount.get_root ())) {
- append (new Location.from_mount (mount));
+ locations.append (new Location.from_mount (mount));
}
} else {
foreach (var location in locations) {
@@ -174,8 +176,8 @@ namespace Baobab {
}
void populate () {
- append (new Location.for_home_folder ());
- append (new Location.for_main_volume ());
+ locations.append (new Location.for_home_folder ());
+ locations.append (new Location.for_main_volume ());
foreach (var volume in monitor.get_volumes ()) {
volume_added (volume);
@@ -209,51 +211,11 @@ namespace Baobab {
recent_items.reverse ();
foreach (var info in recent_items) {
- append (new Location.for_recent_info (info));
+ locations.append (new Location.for_recent_info (info));
}
update ();
}
- }
-
- [GtkTemplate (ui = "/org/gnome/baobab/ui/baobab-location-list.ui")]
- public abstract class BaseLocationListWidget : Gtk.Box {
- [GtkChild]
- private Gtk.Label label_widget;
- [GtkChild]
- private Gtk.ListBox list;
-
- public abstract string label { get; }
-
- private LocationList locations = null;
- public void set_locations (LocationList locations) {
- this.locations = locations;
- locations.update.connect (update);
- }
-
- public delegate void LocationAction (Location l);
- private LocationAction? location_action;
-
- construct {
- label_widget.label = _(label);
- list.selection_mode = Gtk.SelectionMode.NONE;
- list.set_header_func (update_header);
- list.row_activated.connect (row_activated);
- }
-
- public abstract bool allow_display (Location location);
-
- public override void show_all () {
- base.show_all (); // set children to visible
-
- if (list.get_children ().length () == 0) {
- visible = false;
- }
- }
-
- public void set_adjustment (Gtk.Adjustment adj) {
- list.set_adjustment (adj);
- }
void update_header (Gtk.ListBoxRow row, Gtk.ListBoxRow? before_row) {
if (before_row != null && row.get_header () == null) {
@@ -275,15 +237,19 @@ namespace Baobab {
}
public void update () {
- list.foreach ((widget) => { widget.destroy (); });
+ local_list_box.foreach ((widget) => { widget.destroy (); });
+ remote_list_box.foreach ((widget) => { widget.destroy (); });
- locations.foreach((location) => {
- if (allow_display (location)) {
- list.add (new LocationRow (location));
- }
- });
+ remote_box.visible = false;
- show_all ();
+ foreach (var location in locations) {
+ if (location.is_remote) {
+ remote_list_box.add (new LocationRow (location));
+ remote_box.visible = true;
+ } else {
+ local_list_box.add (new LocationRow (location));
+ }
+ }
}
public void add_location (Location location) {
@@ -291,7 +257,7 @@ namespace Baobab {
return;
}
- if (!locations.already_present (location.file)) {
+ if (!already_present (location.file)) {
locations.append (location);
}
@@ -311,18 +277,4 @@ namespace Baobab {
Gtk.RecentManager.get_default ().add_full (location.file.get_uri (), data);
}
}
-
- public class LocalLocationList : BaseLocationListWidget {
- public override string label { get { return "This Computer"; } }
- public override bool allow_display (Location location) {
- return !location.is_remote;
- }
- }
-
- public class RemoteLocationList : BaseLocationListWidget {
- public override string label { get { return "Remote Locations"; } }
- public override bool allow_display (Location location) {
- return location.is_remote;
- }
- }
}
diff --git a/src/baobab-location-row.ui b/src/baobab-location-row.ui
index ac8ecf0..e74cf98 100644
--- a/src/baobab-location-row.ui
+++ b/src/baobab-location-row.ui
@@ -60,9 +60,8 @@
</child>
<child>
<object class="GtkLabel" id="available_label">
- <property name="visible">False</property>
+ <property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="no_show_all">True</property>
<property name="halign">end</property>
<property name="valign">end</property>
</object>
@@ -75,9 +74,8 @@
</child>
<child>
<object class="GtkLabel" id="total_size_label">
- <property name="visible">False</property>
+ <property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="no_show_all">True</property>
<property name="halign">end</property>
<property name="valign">start</property>
<style>
@@ -95,7 +93,6 @@
<object class="GtkLevelBar" id="usage_bar">
<property name="visible">False</property>
<property name="can_focus">False</property>
- <property name="no_show_all">True</property>
<property name="halign">fill</property>
<property name="valign">start</property>
<property name="hexpand">True</property>
diff --git a/src/baobab-main-window.ui b/src/baobab-main-window.ui
index 4fbd809..30d34e3 100644
--- a/src/baobab-main-window.ui
+++ b/src/baobab-main-window.ui
@@ -189,24 +189,10 @@
<property name="hexpand">True</property>
<property name="hscrollbar-policy">never</property>
<child>
- <object class="GtkBox">
+ <object class="BaobabLocationList" id="location_list">
<property name="visible">True</property>
- <property name="orientation">vertical</property>
- <property name="spacing">32</property>
- <property name="margin">32</property>
- <property name="border-width">12</property>
<property name="halign">center</property>
<property name="width-request">700</property>
- <child>
- <object class="BaobabLocalLocationList" id="local_location_list">
- <property name="visible">True</property>
- </object>
- </child>
- <child>
- <object class="BaobabRemoteLocationList" id="remote_location_list">
- <property name="visible">True</property>
- </object>
- </child>
</object>
</child>
</object>
diff --git a/src/baobab-window.vala b/src/baobab-window.vala
index e5f20aa..a1b9b52 100644
--- a/src/baobab-window.vala
+++ b/src/baobab-window.vala
@@ -48,11 +48,7 @@ namespace Baobab {
[GtkChild]
private Gtk.Button infobar_close_button;
[GtkChild]
- private Gtk.ScrolledWindow location_scrolled_window;
- [GtkChild]
- private LocalLocationList local_location_list;
- [GtkChild]
- private RemoteLocationList remote_location_list;
+ private LocationList location_list;
[GtkChild]
private Gtk.TreeView treeview;
[GtkChild]
@@ -129,13 +125,7 @@ namespace Baobab {
var action = ui_settings.create_action ("active-chart");
add_action (action);
- var locations = new LocationList();
- foreach (BaseLocationListWidget location_list in new BaseLocationListWidget[]
{local_location_list, remote_location_list}) {
- location_list.set_locations (locations);
- location_list.set_adjustment (location_scrolled_window.get_vadjustment ());
- location_list.set_action (on_scan_location_activate);
- location_list.update ();
- }
+ location_list.set_action (on_scan_location_activate);
setup_treeview ();
@@ -228,10 +218,7 @@ namespace Baobab {
active_location = location;
// Update the timestamp for GtkRecentManager
- if (location.is_remote)
- remote_location_list.add_location (location);
- else
- local_location_list.add_location (location);
+ location_list.add_location (location);
}
void on_scan_location_activate (Location location) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]