[gnome-boxes] Move access information to DisplayConfig



commit c4a9eb87d57175fdab03a2c5e549af00ca39913b
Author: Marc-Andrà Lureau <marcandre lureau gmail com>
Date:   Wed Oct 24 22:35:15 2012 +0200

    Move access information to DisplayConfig
    
    https://bugzilla.gnome.org/show_bug.cgi?id=680826

 src/display-config.vala              |   43 ++++++++++++++++++++++++++
 src/display-properties.vala          |   56 +++-------------------------------
 src/gnome-boxes-search-provider.vala |   25 +++++++--------
 3 files changed, 60 insertions(+), 64 deletions(-)
---
diff --git a/src/display-config.vala b/src/display-config.vala
index 4857e44..b889bab 100644
--- a/src/display-config.vala
+++ b/src/display-config.vala
@@ -37,11 +37,28 @@ public class Boxes.DisplayConfig: GLib.Object, Boxes.IConfig {
         set { keyfile.set_string_list (group, "categories", value); }
     }
 
+    public int64 access_last_time { set; get; }
+    public int64 access_first_time { set; get; }
+    public int64 access_total_time { set; get; } // in seconds
+    public int64 access_ntimes { set; get; }
+    private SyncProperty[] access_properties;
+
+    construct {
+        access_properties = {
+            SyncProperty () { name = "access-last-time", default_value = (int64)(-1) },
+            SyncProperty () { name = "access-first-time", default_value = (int64)(-1) },
+            SyncProperty () { name = "access-total-time", default_value = (int64)(-1) },
+            SyncProperty () { name = "access-ntimes", default_value = (uint64)0 }
+        };
+    }
+
     public DisplayConfig.with_group (CollectionSource source, string group) {
         this.source = source;
 
         warn_if_fail (group.has_prefix ("display"));
         this.group = group;
+
+        sync_properties (this, access_properties);
     }
 
     public void delete () {
@@ -138,4 +155,30 @@ public class Boxes.DisplayConfig: GLib.Object, Boxes.IConfig {
                 }
         });
     }
+
+    private string? filter_data;
+
+    private void update_filter_data () {
+        var builder = new StringBuilder ();
+
+        if (last_seen_name != null) {
+            builder.append (canonicalize_for_search (last_seen_name));
+            builder.append_unichar (' ');
+        }
+
+        // add categories, url? other metadata etc..
+
+        filter_data = builder.str;
+    }
+
+    public bool contains_strings (string[] strings) {
+        if (filter_data == null)
+            update_filter_data ();
+
+        foreach (string i in strings) {
+            if (! (i in filter_data))
+                return false;
+        }
+        return true;
+    }
 }
diff --git a/src/display-properties.vala b/src/display-properties.vala
index 201c351..4f45f94 100644
--- a/src/display-properties.vala
+++ b/src/display-properties.vala
@@ -8,11 +8,11 @@ public class Boxes.DisplayProperties: GLib.Object {
             return;
 
         started_time = get_monotonic_time ();
-        access_last_time = get_real_time ();
-        access_ntimes += 1;
+        config.access_last_time = get_real_time ();
+        config.access_ntimes += 1;
 
-        if (access_first_time == 0)
-            access_first_time = access_last_time;
+        if (config.access_first_time == 0)
+            config.access_first_time = config.access_last_time;
     }
 
     protected void access_finish () {
@@ -21,60 +21,14 @@ public class Boxes.DisplayProperties: GLib.Object {
 
         var duration = get_monotonic_time () - started_time;
         duration /= 1000000; // convert to seconds
-        access_total_time += duration;
+        config.access_total_time += duration;
 
         started_time = 0;
     }
 
-    public int64 access_last_time { set; get; }
-    public int64 access_first_time { set; get; }
-    public int64 access_total_time { set; get; } // in seconds
-    public int64 access_ntimes { set; get; }
-    private DisplayConfig.SyncProperty[] access_properties;
-
-    construct {
-        access_properties = {
-            DisplayConfig.SyncProperty () { name = "access-last-time", default_value = (int64)(-1) },
-            DisplayConfig.SyncProperty () { name = "access-first-time", default_value = (int64)(-1) },
-            DisplayConfig.SyncProperty () { name = "access-total-time", default_value = (int64)(-1) },
-            DisplayConfig.SyncProperty () { name = "access-ntimes", default_value = (uint64)0 }
-        };
-
-        config.sync_properties (this, access_properties);
-    }
-
-    public DisplayProperties.with_config (DisplayConfig config) {
-        this.config = config;
-
-        update_filter_data ();
-    }
-
     ~DisplayProperties () {
         access_finish ();
     }
 
     public DisplayConfig? config { get; set; }
-
-    private string filter_data;
-
-    private void update_filter_data () {
-        var builder = new StringBuilder ();
-
-        if (config.last_seen_name != null) {
-            builder.append (canonicalize_for_search (config.last_seen_name));
-            builder.append_unichar (' ');
-        }
-
-        // add categories, url? other metadata etc..
-
-        filter_data = builder.str;
-    }
-
-    public bool contains_strings (string[] strings) {
-        foreach (string i in strings) {
-            if (! (i in filter_data))
-                return false;
-        }
-        return true;
-    }
 }
diff --git a/src/gnome-boxes-search-provider.vala b/src/gnome-boxes-search-provider.vala
index 1b8da11..53dd166 100644
--- a/src/gnome-boxes-search-provider.vala
+++ b/src/gnome-boxes-search-provider.vala
@@ -5,15 +5,15 @@ public class Boxes.SearchProvider: Object {
     private SearchProviderApp app;
     private bool loading;
     public bool loaded { get; set; }
-    private HashTable<string, DisplayProperties> boxes;
+    private HashTable<string, DisplayConfig> boxes;
     private uint next_id;
 
     public SearchProvider (SearchProviderApp app) {
         this.app = app;
-        boxes = new HashTable<string, DisplayProperties> (str_hash, str_equal);
+        boxes = new HashTable<string, DisplayConfig> (str_hash, str_equal);
     }
 
-    private void add_box (DisplayProperties box) {
+    private void add_box (DisplayConfig box) {
         var id = next_id++.to_string ();
         box.set_data ("search-id", id);
 
@@ -42,8 +42,7 @@ public class Boxes.SearchProvider: Object {
                 return false;
 
             foreach (var group in source.get_groups ("display")) {
-                var config = new DisplayConfig.with_group (source, group);
-                var box = new DisplayProperties.with_config (config);
+                var box = new DisplayConfig.with_group (source, group);
                 add_box (box);
             }
 
@@ -54,13 +53,13 @@ public class Boxes.SearchProvider: Object {
         loading = false;
     }
 
-    private static int compare_boxes (DisplayProperties a, DisplayProperties b) {
+    private static int compare_boxes (DisplayConfig a, DisplayConfig b) {
         // sort first by last time used
         if (a.access_last_time > b.access_last_time)
             return -1;
 
-        var a_name = a.config.last_seen_name;
-        var b_name = b.config.last_seen_name;
+        var a_name = a.last_seen_name;
+        var b_name = b.last_seen_name;
 
         // then by name
         if (is_set (a_name) && is_set (b_name))
@@ -78,7 +77,7 @@ public class Boxes.SearchProvider: Object {
     private async string[] search (owned string[] terms) {
         app.hold ();
         string[] normalized_terms = canonicalize_for_search (string.joinv(" ", terms)).split(" ");
-        var matches = new GenericArray<DisplayProperties> ();
+        var matches = new GenericArray<DisplayConfig> ();
 
         debug ("search (%s)", string.joinv (", ", terms));
         if (!loaded)
@@ -89,7 +88,7 @@ public class Boxes.SearchProvider: Object {
                 matches.add (box);
         }
 
-        matches.sort((CompareFunc<DisplayProperties>) compare_boxes);
+        matches.sort((CompareFunc<DisplayConfig>) compare_boxes);
         var results = new string[matches.length];
         for (int i = 0; i < matches.length; i++)
             results[i] = matches[i].get_data ("search-id");
@@ -123,9 +122,9 @@ public class Boxes.SearchProvider: Object {
             n++;
 
             meta.insert ("id", new Variant.string (id));
-            meta.insert ("name", new Variant.string (box.config.last_seen_name));
+            meta.insert ("name", new Variant.string (box.last_seen_name));
 
-            var file = File.new_for_path (Boxes.get_screenshot_filename (box.config.uuid));
+            var file = File.new_for_path (Boxes.get_screenshot_filename (box.uuid));
             FileInfo? info = null;
             try {
                 info = yield file.query_info_async (FileAttribute.STANDARD_TYPE, FileQueryInfoFlags.NONE);
@@ -161,7 +160,7 @@ public class Boxes.SearchProvider: Object {
             return;
         }
 
-        string uuid = box.config.uuid;
+        string uuid = box.uuid;
         try {
             var cmd = "gnome-boxes --open-uuid " + uuid;
             if (!Process.spawn_command_line_async (cmd))



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]