[gnome-boxes] display: move DisplayProperties in seperate file
- From: Marc-Andre Lureau <malureau src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-boxes] display: move DisplayProperties in seperate file
- Date: Mon, 13 Aug 2012 12:20:48 +0000 (UTC)
commit 8e0c53a073e150f079c2e22de099d1a7d671d050
Author: Marc-Andrà Lureau <marcandre lureau gmail com>
Date: Sat Aug 4 18:30:57 2012 +0200
display: move DisplayProperties in seperate file
This allow the file to be used seperately by gnome-boxes-search-provider.
https://bugzilla.gnome.org/show_bug.cgi?id=681246
src/Makefile.am | 1 +
src/display-properties.vala | 103 +++++++++++++++++++++++++++++++++++++++++++
src/display.vala | 80 +--------------------------------
3 files changed, 107 insertions(+), 77 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index f2cd031..3eee03d 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -42,6 +42,7 @@ gnome_boxes_SOURCES = \
collection.vala \
display-config.vala \
display-page.vala \
+ display-properties.vala \
display.vala \
editable-entry.vala \
fedora-installer.vala \
diff --git a/src/display-properties.vala b/src/display-properties.vala
new file mode 100644
index 0000000..9af4bdd
--- /dev/null
+++ b/src/display-properties.vala
@@ -0,0 +1,103 @@
+// This file is part of GNOME Boxes. License: LGPLv2+
+
+// too bad we can't make it just a mixin
+private class Boxes.DisplayProperties: GLib.Object {
+ protected struct SavedProperty {
+ string name;
+ Value default_value;
+ }
+
+ private int64 started_time;
+ protected void access_start () {
+ if (started_time != 0)
+ return;
+
+ started_time = get_monotonic_time ();
+ access_last_time = get_real_time ();
+ access_ntimes += 1;
+
+ if (access_first_time == 0)
+ access_first_time = access_last_time;
+ }
+
+ protected void access_finish () {
+ if (started_time == 0)
+ return;
+
+ var duration = get_monotonic_time () - started_time;
+ duration /= 1000000; // convert to seconds
+ 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 SavedProperty[] access_saved_properties;
+
+ construct {
+ access_saved_properties = {
+ SavedProperty () { name = "access-last-time", default_value = (int64)(-1) },
+ SavedProperty () { name = "access-first-time", default_value = (int64)(-1) },
+ SavedProperty () { name = "access-total-time", default_value = (int64)(-1) },
+ SavedProperty () { name = "access-ntimes", default_value = (uint64)0 }
+ };
+
+ this.notify["config"].connect (() => {
+ sync_config_with_display (this, access_saved_properties);
+ });
+ }
+
+ public DisplayProperties.with_config (DisplayConfig config) {
+ this.config = config;
+
+ update_filter_data ();
+ }
+
+ ~DisplayProperties () {
+ access_finish ();
+ }
+
+ public DisplayConfig? config { get; set; }
+
+ public void sync_config_with_display (Object display, SavedProperty[] saved_properties) {
+ if (config == null)
+ return;
+
+ foreach (var prop in saved_properties)
+ config.load_display_property (display, prop.name, prop.default_value);
+
+ display.notify.connect ((pspec) => {
+ foreach (var prop in saved_properties)
+ if (pspec.name == prop.name) {
+ config.save_display_property (display, pspec.name);
+ break;
+ }
+ });
+ }
+
+ 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/display.vala b/src/display.vala
index 9f707c5..7f75f35 100644
--- a/src/display.vala
+++ b/src/display.vala
@@ -1,83 +1,7 @@
// This file is part of GNOME Boxes. License: LGPLv2+
using Gtk;
-// too bad we can't make it just a mixin
-private abstract class Boxes.DisplayProperties: GLib.Object, Boxes.IPropertiesProvider {
- protected struct SavedProperty {
- string name;
- Value default_value;
- }
-
- public abstract List<Boxes.Property> get_properties (Boxes.PropertiesPage page);
-
- private int64 started_time;
- protected void access_start () {
- if (started_time != 0)
- return;
-
- started_time = get_monotonic_time ();
- access_last_time = get_real_time ();
- access_ntimes += 1;
-
- if (access_first_time == 0)
- access_first_time = access_last_time;
- }
-
- protected void access_finish () {
- if (started_time == 0)
- return;
-
- var duration = get_monotonic_time () - started_time;
- duration /= 1000000; // convert to seconds
- 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 SavedProperty[] access_saved_properties;
-
- construct {
- access_saved_properties = {
- SavedProperty () { name = "access-last-time", default_value = (int64)(-1) },
- SavedProperty () { name = "access-first-time", default_value = (int64)(-1) },
- SavedProperty () { name = "access-total-time", default_value = (int64)(-1) },
- SavedProperty () { name = "access-ntimes", default_value = (uint64)0 }
- };
-
- this.notify["config"].connect (() => {
- sync_config_with_display (this, access_saved_properties);
- });
- }
-
- ~DisplayProperties () {
- access_finish ();
- }
-
- public DisplayConfig? config { get; set; }
-
- public void sync_config_with_display (Object display, SavedProperty[] saved_properties) {
- if (config == null)
- return;
-
- foreach (var prop in saved_properties)
- config.load_display_property (display, prop.name, prop.default_value);
-
- display.notify.connect ((pspec) => {
- foreach (var prop in saved_properties)
- if (pspec.name == prop.name) {
- config.save_display_property (display, pspec.name);
- break;
- }
- });
- }
-}
-
-private abstract class Boxes.Display: Boxes.DisplayProperties {
+private abstract class Boxes.Display: Boxes.DisplayProperties, Boxes.IPropertiesProvider {
public abstract string protocol { get; }
public abstract string uri { owned get; }
@@ -99,6 +23,8 @@ private abstract class Boxes.Display: Boxes.DisplayProperties {
public abstract void connect_it ();
public abstract void disconnect_it ();
+ public abstract List<Boxes.Property> get_properties (Boxes.PropertiesPage page);
+
protected HashTable<int, Gtk.Widget?> displays;
construct {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]