[gnome-boxes/wip/props-ui-files: 4/12] Add DeferredChange class
- From: Zeeshan Ali Khattak <zeeshanak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-boxes/wip/props-ui-files: 4/12] Add DeferredChange class
- Date: Fri, 3 Jun 2016 13:43:09 +0000 (UTC)
commit 6ec9afcd4ddb79abd7a3bdc92ecd7aa54b72906a
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 | 40 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 41 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..6151d33
--- /dev/null
+++ b/src/deferred-change.vala
@@ -0,0 +1,40 @@
+// 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 = 1) {
+ 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 () {
+ func ();
+
+ 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]