diff options
author | Siegfried-Angel Gevatter Pujals <siegfried@gevatter.com> | 2012-02-01 13:26:45 +0100 |
---|---|---|
committer | Siegfried-Angel Gevatter Pujals <siegfried@gevatter.com> | 2012-02-01 13:26:45 +0100 |
commit | b71f82db463cb2d303bb62bf3ee73dac78b1cd09 (patch) | |
tree | 642e0286d92b9429db10f458ea97cf24861deeb6 | |
parent | 2677b51ad51e6ef15680815bb50bbde6ae6ca85f (diff) |
Random fixes for Michal.
-rw-r--r-- | src/kde-recent-document-provider.vala | 21 | ||||
-rw-r--r-- | src/utils.vala | 34 |
2 files changed, 32 insertions, 23 deletions
diff --git a/src/kde-recent-document-provider.vala b/src/kde-recent-document-provider.vala index 9f4b4c0..3cd08db 100644 --- a/src/kde-recent-document-provider.vala +++ b/src/kde-recent-document-provider.vala @@ -135,7 +135,7 @@ public class RecentDocumentsKDE : DataProvider return null; recent_info.get_modification_time (out timeval); - int64 event_time = Utils.timeval_to_timestamp (timeval); + int64 event_time = Timestamp.from_timeval (timeval); string? content = Utils.get_file_contents (file); if (content == null) @@ -168,13 +168,13 @@ public class RecentDocumentsKDE : DataProvider FILE_ATTRIBUTE_QUERY_SUBJECT, GLib.FileQueryInfoFlags.NONE); subject_info.get_modification_time (out timeval); - int64 modification_time = Utils.timeval_to_timestamp (timeval); + int64 modification_time = Timestamp.from_timeval (timeval); timeval.tv_sec = (long) subject_info.get_attribute_uint64 ( GLib.FILE_ATTRIBUTE_TIME_CHANGED); timeval.tv_usec = subject_info.get_attribute_uint32 ( GLib.FILE_ATTRIBUTE_TIME_CHANGED_USEC); - int64 creation_time = Utils.timeval_to_timestamp (timeval); + int64 creation_time = Timestamp.from_timeval (timeval); string mimetype = subject_info.get_attribute_string ( FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE); @@ -228,16 +228,18 @@ public class RecentDocumentsKDE : DataProvider return null; } - private async void crawl_all_items () throws GLib.FileError + private async void crawl_all_items () throws GLib.Error { - string filename; GenericArray<Event> events = new GenericArray<Event> (); - GLib.Dir directory = GLib.Dir.open (recent_document_path); - while ((filename = directory.read_name ()) != null) + GLib.File directory = GLib.File.new_for_path (recent_document_path); + GLib.FileEnumerator enumerator = directory.enumerate_children ( + FILE_ATTRIBUTE_STANDARD_NAME, GLib.FileQueryInfoFlags.NONE); + GLib.FileInfo fi; + while ((fi = enumerator.next_file ()) != null) { - var file = GLib.File.new_for_path ( - recent_document_path + "/" + filename); + string path = Path.build_filename (recent_document_path, fi.get_name ()); + var file = GLib.File.new_for_path (path); try { Event? event = yield parse_file (file); @@ -249,6 +251,7 @@ public class RecentDocumentsKDE : DataProvider // Silently ignore. The files may be gone by now - who cares? } } + enumerator.close (); // Zeitgeist will take care of ignoring the duplicates items_available (events); diff --git a/src/utils.vala b/src/utils.vala index 877e5cf..64e8779 100644 --- a/src/utils.vala +++ b/src/utils.vala @@ -28,6 +28,7 @@ public class Utils : Object { private static HashTable<string, string> app_to_desktop_file = null; private static string[] desktop_file_prefixes = null; + private static GLib.Regex duplicate_path_separator_regex; // FIXME: Do we want to make this async? // FIXME: this can throw GLib.Error, but if we use try/catch or throws @@ -44,16 +45,7 @@ public class Utils : Object if (!file.load_contents (null, out contents, null, null)) return null; #endif - return (owned) contents; - } - - /* - * Takes a TimeVal and returns a Zeitgeist timestamp (ie. timestamp in msec). - * - * */ - public static int64 timeval_to_timestamp (TimeVal timeval) - { - return (timeval.tv_sec * 1000) + (timeval.tv_usec / 1000); + return contents; } /* @@ -65,12 +57,20 @@ public class Utils : Object if (desktop_file_prefixes != null) return; - unowned string session_var = Environment.get_variable ("DESKTOP_SESSION"); + duplicate_path_separator_regex = new Regex ("//"); + + unowned string session_var; + + session_var = Environment.get_variable ("XDG_CURRENT_DESKTOP"); if (session_var == null) { - // let's assume it's gnome - DesktopAppInfo.set_desktop_env ("GNOME"); - return; + session_var = Environment.get_variable ("DESKTOP_SESSION"); + if (session_var == null) + { + // let's assume it's gnome + DesktopAppInfo.set_desktop_env ("GNOME"); + return; + } } string desktop_session = session_var.up (); @@ -105,12 +105,18 @@ public class Utils : Object * Takes a path to a .desktop file and returns the Desktop ID for it. * This isn't simply the basename, but may contain part of the path; * eg. kde4-kate.desktop for /usr/share/applications/kde4/kate.desktop. + * + * Warning: init_desktop_id () must be called before this function can + * be used. * */ private static string extract_desktop_id (string path) { if (!path.has_prefix ("/")) return path; + string normalized_path = duplicate_path_separator_regex.replace ( + path, path.length, 0, "/"); + foreach (unowned string prefix in desktop_file_prefixes) { string without_prefix = path.substring (prefix.length); |