[gnome-boxes/wip/props-ui-files: 81/96] Add DeferredChange class
- From: Zeeshan Ali <zeeshanak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-boxes/wip/props-ui-files: 81/96] Add DeferredChange class
- Date: Sat, 26 Nov 2016 16:43:39 +0000 (UTC)
commit 73a772a5a9c0ff4b757fed4d7307242d52818d24
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date: Wed Jun 1 20:07:51 2016 +0100
Add DeferredChange class
Add a class to represent a deferred change in properties view.
src/Makefile.am | 1 +
src/deferred-change.vala | 44 ++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 45 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 48a2bea..adfc8ed 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -105,6 +105,7 @@ gnome_boxes_SOURCES = \
collection.vala \
collection-filter-switcher.vala \
collection-toolbar.vala \
+ deferred-change.vala \
display-page.vala \
display-toolbar.vala \
display.vala \
diff --git a/src/deferred-change.vala b/src/deferred-change.vala
new file mode 100644
index 0000000..58087c7
--- /dev/null
+++ b/src/deferred-change.vala
@@ -0,0 +1,44 @@
+// This file is part of GNOME Boxes. License: LGPLv2+
+
+private class DeferredChange {
+ public signal void flushed ();
+
+ public string id { get; private set; }
+ public SourceFunc func;
+ public uint interval { get; private set; } // In seconds
+
+ private uint timeout_id;
+
+ public DeferredChange (string id, owned SourceFunc func, uint interval = 0) {
+ this.id = id;
+ this.func = (owned) func;
+ this.interval = interval;
+
+ if (interval == 0)
+ return;
+
+ timeout_id = Timeout.add_seconds (interval, () => {
+ flush ();
+
+ return false;
+ });
+ }
+
+ public void flush () {
+ if (func == null)
+ return;
+
+ func ();
+ func = null;
+
+ unschedule ();
+
+ flushed ();
+ }
+
+ public void unschedule () {
+ if (timeout_id > 0)
+ Source.remove (timeout_id);
+ timeout_id = 0;
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]