[baobab/wip/vala: 54/65] Implement a custom view for the volume list
- From: Paolo Borelli <pborelli src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [baobab/wip/vala: 54/65] Implement a custom view for the volume list
- Date: Thu, 5 Apr 2012 12:19:30 +0000 (UTC)
commit 4951e41b49bb55b83f05dd6c718a38636f0e614a
Author: Stefano Facchini <stefano facchini gmail com>
Date: Sun Apr 1 18:35:58 2012 +0200
Implement a custom view for the volume list
src/baobab-main-window.ui | 136 +++---------------------------------------
src/baobab-volume-list.vala | 88 ++++++++++++++--------------
src/baobab-window.vala | 69 +++++++++++-----------
3 files changed, 89 insertions(+), 204 deletions(-)
---
diff --git a/src/baobab-main-window.ui b/src/baobab-main-window.ui
index 5ceaed1..77c9866 100644
--- a/src/baobab-main-window.ui
+++ b/src/baobab-main-window.ui
@@ -141,114 +141,27 @@
<property name="show_tabs">False</property> -->
<property name="show_border">False</property> -->
<child>
- <object class="GtkGrid" id="home-page-grid">
+ <object class="GtkGrid" id="home-page">
<property name="can_focus">False</property>
<property name="visible">True</property>
+ <property name="orientation">vertical</property>
<child>
<object class="GtkScrolledWindow" id="volume-scrolled-window">
<property name="visible">True</property>
- <property name="shadow_type">in</property>
- <property name="margin">6</property>
+ <property name="vexpand">True</property>
+ <property name="hexpand">True</property>
<child>
- <object class="GtkTreeView" id="volume-treeview">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="hexpand">True</property>
- <property name="vexpand">True</property>
- <child>
- <object class="GtkTreeViewColumn" id="volume-column">
- <property name="sizing">autosize</property>
- <property name="title" translatable="yes">Volume</property>
- <property name="expand">True</property>
- <property name="clickable">True</property>
- <property name="reorderable">True</property>
- <property name="sort_column_id">0</property>
- <child>
- <object class="GtkCellRendererPixbuf" id="icon-renderer"/>
- <attributes>
- <attribute name="gicon">5</attribute>
- </attributes>
- </child>
- <child>
- <object class="GtkCellRendererText" id="volume-renderer"/>
- <attributes>
- <attribute name="text">0</attribute>
- </attributes>
- </child>
- </object>
- </child>
- <child>
- <object class="GtkTreeViewColumn" id="mount-column">
- <property name="sizing">autosize</property>
- <property name="title" translatable="yes">Mounted at</property>
- <property name="expand">True</property>
- <property name="clickable">True</property>
- <property name="reorderable">True</property>
- <property name="sort_column_id">0</property>
- <child>
- <object class="GtkCellRendererText" id="mount-renderer"/>
- </child>
- </object>
- </child>
- <child>
- <object class="GtkTreeViewColumn" id="size-column-home-page">
- <property name="title" translatable="yes">Size</property>
- <child>
- <object class="GtkCellRendererText" id="size-renderer"/>
- <attributes>
- <attribute name="text">2</attribute>
- </attributes>
- </child>
- </object>
- </child>
- <child>
- <object class="GtkTreeViewColumn" id="usage-column-home-page">
- <property name="title" translatable="yes">Usage</property>
- <child>
- <object class="GtkCellRendererProgress" id="usage-renderer">
- <property name="width">140</property>
- <property name="ypad">8</property>
- </object>
- <attributes>
- <attribute name="text">4</attribute>
- <attribute name="value">3</attribute>
- </attributes>
- </child>
- </object>
- </child>
- </object>
+ <placeholder/>
</child>
</object>
</child>
<child>
- <object class="GtkButtonBox" id="dialog-action_area1">
- <property name="can_focus">False</property>
- <property name="layout_style">end</property>
+ <object class="GtkButtonBox" id="scan-buttonbox">
<property name="visible">True</property>
- <child>
- <object class="GtkButton" id="scan-home-button">
- <property name="use_action_appearance">False</property>
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="has_tooltip">True</property>
- <property name="tooltip_markup" translatable="yes">Scan your home folder</property>
- <property name="tooltip_text" translatable="yes">Scan your home folder</property>
- <property name="use_action_appearance">False</property>
- <property name="action_name">win.scan-home</property>
- <property name="label" translatable="yes">Scan Home</property>
- <property name="use_underline">True</property>
- <!--<property name="stock_id">gtk-home</property>-->
- <child internal-child="accessible">
- <object class="AtkObject" id="scan-home-button-atkobject">
- <property name="AtkObject::accessible-name" translatable="yes">Scan your home folder</property>
- </object>
- </child>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="position">0</property>
- </packing>
- </child>
+ <property name="layout_style">start</property>
+ <style>
+ <class name="linked"/>
+ </style>
<child>
<object class="GtkButton" id="scan-folder-button">
<property name="use_action_appearance">False</property>
@@ -263,10 +176,6 @@
<property name="use_underline">True</property>
<!--<property name="stock_id">gtk-directory</property>-->
</object>
- <packing>
- <property name="expand">False</property>
- <property name="position">1</property>
- </packing>
</child>
<child>
<object class="GtkButton" id="scan-remote-button">
@@ -282,33 +191,8 @@
<property name="use_underline">True</property>
<!--<property name="stock_id">gtk-network</property>-->
</object>
- <packing>
- <property name="expand">False</property>
- <property name="position">1</property>
- </packing>
- </child>
- <child>
- <object class="GtkButton" id="scan-button">
- <property name="label" translatable="yes">_Scan</property>
- <property name="use_action_appearance">False</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
- <property name="use_underline">True</property>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">True</property>
- <property name="position">3</property>
- </packing>
</child>
</object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">1</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
</child>
</object>
</child>
diff --git a/src/baobab-volume-list.vala b/src/baobab-volume-list.vala
index e41eb59..7abeff8 100644
--- a/src/baobab-volume-list.vala
+++ b/src/baobab-volume-list.vala
@@ -22,7 +22,7 @@ namespace Baobab {
}
public void mount () throws Error {
- if (mount_point != null)
+ if (mount_point != null || udisks_volume == null)
return;
string mount_point_;
@@ -146,54 +146,54 @@ namespace Baobab {
}
}
- public class VolumeList : Gtk.ListStore {
- public enum Columns {
- NAME,
- MOUNT_POINT,
- SIZE_LABEL,
- USAGE_PERCENT,
- USAGE_LABEL,
- ICON,
- LOCATION,
- COLUMNS
- }
-
- public VolumeList () {
- set_column_types (new Type[] {
- typeof (string), // NAME
- typeof (string), // MOUNT_POINT
- typeof (string), // SIZE_LABEL
- typeof (int), // USAGE_PERCENT
- typeof (string), // USAGE_LABEL
- typeof (Icon), // ICON
- typeof (Object)}); // LOCATION
- }
-
- public void update (List<Location> locations) {
- clear ();
+ public class LocationWidget : Gtk.Grid {
+ public delegate void ActionOnClick (Location location);
+
+ public LocationWidget (Location location, ActionOnClick action) {
+ orientation = Gtk.Orientation.HORIZONTAL;
+ column_spacing = 10;
+ margin = 6;
+
+ var image = new Gtk.Image.from_gicon (location.icon, Gtk.IconSize.DIALOG);
+ add (image);
+
+ var label_grid = new Gtk.Grid ();
+ label_grid.orientation = Gtk.Orientation.VERTICAL;
+ var label = new Gtk.Label (location.name);
+ label.hexpand = true;
+ label.halign = Gtk.Align.START;
+ label_grid.add (label);
+ if (location.mount_point != null) {
+ label = new Gtk.Label (location.mount_point);
+ label.halign = Gtk.Align.START;
+ label.get_style_context ().add_class ("dim-label");
+ label_grid.add (label);
+ }
+ add (label_grid);
- Gtk.TreeIter iter;
+ if (location.size != null) {
+ label = new Gtk.Label (format_size (location.size));
+ add (label);
+ }
- foreach (var location in locations) {
- append (out iter);
+ if (location.used != null) {
+ var progress = new Gtk.ProgressBar ();
+ progress.valign = Gtk.Align.CENTER;
+ progress.set_fraction ((double) location.used / location.size);
+ add (progress);
+ } else {
+ label = new Gtk.Label (_("Usage unknown"));
+ add (label);
+ }
- set (iter,
- Columns.NAME, location.name,
- Columns.MOUNT_POINT, location.mount_point,
- Columns.ICON, location.icon,
- Columns.LOCATION, location);
+ string button_label = location.mount_point != null ? _("Scan") : _("Mount and scan");
+ var button = new Gtk.Button.with_label (button_label);
+ button.valign = Gtk.Align.CENTER;
+ add (button);
- if (location.size != null)
- set (iter, Columns.SIZE_LABEL, format_size (location.size));
+ button.clicked.connect(() => { action (location); });
- // Assuming that location.used != null implies location.size != null
- if (location.used != null) {
- var percent = (int) ((double) location.used / location.size * 100);
- set (iter, Columns.USAGE_PERCENT, percent);
- } else {
- set (iter, Columns.USAGE_LABEL, _("Unknown"));
- }
- }
+ show_all ();
}
}
}
diff --git a/src/baobab-window.vala b/src/baobab-window.vala
index 2fbce43..7a39941 100644
--- a/src/baobab-window.vala
+++ b/src/baobab-window.vala
@@ -305,47 +305,48 @@ namespace Baobab {
return true;
}
+ delegate void UpdateFunc ();
void setup_home_page (Gtk.Builder builder) {
- var volume_treeview = builder.get_object ("volume-treeview") as Gtk.TreeView;
- var mount_column = builder.get_object ("mount-column") as Gtk.TreeViewColumn;
- var mount_renderer = builder.get_object ("mount-renderer") as Gtk.CellRendererText;
- var scan_button = builder.get_object ("scan-button") as Gtk.Button;
-
var location_monitor = new LocationMonitor ();
- var model = new VolumeList ();
-
- location_monitor.changed.connect (() => {
- model.update (location_monitor.get_locations ());
- });
- model.update (location_monitor.get_locations ());
-
- volume_treeview.model = model;
- mount_column.set_cell_data_func (mount_renderer, (layout, cell, model, iter) => {
- string? mount_point = null;
- model.get (iter, VolumeList.Columns.MOUNT_POINT, out mount_point);
- ((Gtk.CellRendererText) cell).text = mount_point != null ? mount_point : _("Not mounted");
- });
-
- scan_button.clicked.connect (() => {
- try {
- Gtk.TreePath path = volume_treeview.get_selection ().get_selected_rows (null).data;
- Gtk.TreeIter iter;
+ var scrolled_window = builder.get_object ("volume-scrolled-window") as Gtk.ScrolledWindow;
+ var grid = new Gtk.Grid ();
+ grid.orientation = Gtk.Orientation.VERTICAL;
+ scrolled_window.add_with_viewport (grid);
+
+ UpdateFunc update_locations = () => {
+ grid.foreach ((widget) => { widget.destroy (); });
+
+ foreach (var location in location_monitor.get_locations ()) {
+ var loc_widget = new LocationWidget (location, (location_) => {
+ try {
+ location_.mount ();
+ set_ui_page (UIPage.RESULT);
+ scan_directory (File.new_for_path (location_.mount_point),
+ ScanFlags.EXCLUDE_MOUNTS);
+ } catch (Error e) {
+ message (_("Could not analyze volume."), e.message, Gtk.MessageType.ERROR);
+ }
+ });
+ grid.add (loc_widget);
+ }
- model.get_iter (out iter, path);
+ var home_loc = new Location (_("Home folder"),
+ GLib.Environment.get_home_dir (),
+ null,
+ null,
+ new ThemedIcon (Gtk.Stock.HOME),
+ null);
- Location location;
- model.get (iter, VolumeList.Columns.LOCATION, out location);
+ grid.add (new LocationWidget (home_loc, (location) => {
+ on_scan_home_activate ();
+ }));
- location.mount ();
+ grid.show_all ();
+ };
- set_ui_page (UIPage.RESULT);
- scan_directory (File.new_for_path (location.mount_point),
- ScanFlags.EXCLUDE_MOUNTS);
- } catch (Error e) {
- message (_("Could not analyze volume."), e.message, Gtk.MessageType.ERROR);
- }
- });
+ location_monitor.changed.connect (() => { update_locations (); });
+ update_locations ();
}
void setup_treeview (Gtk.Builder builder) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]