[baobab] Add recent files support
- From: Paolo Borelli <pborelli src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [baobab] Add recent files support
- Date: Fri, 27 Jul 2012 15:42:21 +0000 (UTC)
commit b6addfba95ad01a99c3ddee0b469be657554bc4f
Author: Paolo Borelli <pborelli gnome org>
Date: Fri Jul 27 15:21:37 2012 +0200
Add recent files support
Recently scanned directories are now listed on the "home page"
src/baobab-location-list.vala | 4 +++
src/baobab-location-monitor.vala | 56 ++++++++++++++++++++++++++++++++++++-
src/baobab-location.vala | 22 ++++++++++++---
src/baobab-window.vala | 3 ++
4 files changed, 79 insertions(+), 6 deletions(-)
---
diff --git a/src/baobab-location-list.vala b/src/baobab-location-list.vala
index 8915673..c844c31 100644
--- a/src/baobab-location-list.vala
+++ b/src/baobab-location-list.vala
@@ -52,5 +52,9 @@ namespace Baobab {
show_all ();
}
+
+ public void recent_add (File directory) {
+ location_monitor.recent_add (directory);
+ }
}
}
diff --git a/src/baobab-location-monitor.vala b/src/baobab-location-monitor.vala
index 4246a99..b837b0e 100644
--- a/src/baobab-location-monitor.vala
+++ b/src/baobab-location-monitor.vala
@@ -21,6 +21,8 @@
namespace Baobab {
public class LocationMonitor {
+ private const int MAX_RECENT_LOCATIONS = 5;
+
private static LocationMonitor? instance = null;
private VolumeMonitor monitor;
@@ -119,11 +121,61 @@ namespace Baobab {
}
}
- if (Location.get_home_location () == null) {
- locations.append(new Location.for_home_folder ());
+ locations.append (Location.get_home_location ());
+
+ Gtk.RecentManager recent_manager = Gtk.RecentManager.get_default ();
+ List<Gtk.RecentInfo> recent_items = recent_manager.get_items ();
+
+ int n_recents = 0;
+ foreach (var info in recent_items) {
+ if (n_recents >= this.MAX_RECENT_LOCATIONS) {
+ break;
+ }
+ if (info.has_group ("baobab") && info.exists ()) {
+ // FIXME: I do not like this hack to avoid duplucates
+ // and beside locations should have a proper uri field
+ // to be uniquely identified
+ bool dup = false;
+ foreach (var l in locations) {
+ if (l.mount_point == info.get_uri_display ()) {
+ dup = true;
+ }
+ }
+ if (!dup) {
+ locations.append (new Location.for_recent_info (info));
+ n_recents++;
+ }
+ }
}
changed ();
}
+
+ public void recent_add (File directory) {
+ Gtk.RecentData data = Gtk.RecentData ();
+ data.display_name = null;
+ data.description = null;
+ data.mime_type = "inode/directory";
+ data.app_name = GLib.Environment.get_application_name ();
+ data.app_exec = "%s %%u".printf (GLib.Environment.get_prgname ());
+ string[] groups = new string[2];
+ groups[0] = "baobab";
+ groups[1] = null;
+ data.groups = groups;
+
+ Gtk.RecentManager.get_default ().add_full (directory.get_uri (), data);
+
+ // FIXME: it would probably be cleaner to add the dir to the list of
+ // locations ourselves, but for now we cheat and just rebuild the list
+ // from scratch so that we get the proper ordering and deduplication
+ // FIXME: is this really how I clear a list in vala??
+ unowned List<Location> l = locations;
+ while (l != null) {
+ unowned List<Location> tmp = l.next;
+ locations.delete_link (l);
+ l = tmp;
+ }
+ initial_fill ();
+ }
}
}
diff --git a/src/baobab-location.vala b/src/baobab-location.vala
index 9f95fd6..f53c8e9 100644
--- a/src/baobab-location.vala
+++ b/src/baobab-location.vala
@@ -38,7 +38,18 @@ namespace Baobab {
private static Location? home_location = null;
+ Location.for_home_folder () {
+ mount_point = Environment.get_home_dir ();
+ make_this_home_location ();
+
+ get_fs_usage (File.new_for_path (mount_point));
+ }
+
public static Location get_home_location () {
+ if (home_location == null) {
+ home_location = new Location.for_home_folder ();
+ }
+
return home_location;
}
@@ -69,11 +80,14 @@ namespace Baobab {
get_fs_usage (File.new_for_path (mount_point));
}
- public Location.for_home_folder () {
- mount_point = Environment.get_home_dir ();
- make_this_home_location ();
+ public Location.for_recent_info (Gtk.RecentInfo info) {
+ name = info.get_display_name ();
+ mount_point = info.get_uri_display ();
+ icon = info.get_gicon ();
- get_fs_usage (File.new_for_path (mount_point));
+ if (info.is_local ()) {
+ get_fs_usage (File.new_for_uri (info.get_uri ()));
+ }
}
public void update () {
diff --git a/src/baobab-window.vala b/src/baobab-window.vala
index 83f594e..91ace63 100644
--- a/src/baobab-window.vala
+++ b/src/baobab-window.vala
@@ -529,6 +529,9 @@ namespace Baobab {
return;
}
+ // FIXME: only add folders and skip volumes?
+ location_list.recent_add (directory);
+
scanner = new Scanner (directory, flags);
set_model (scanner);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]