[gnome-boxes/wip/inhibit: 10/13] app: Add inhibit methods



commit b5cef4c9d69f4995c9c81d3ecef09407bfc8566f
Author: Felipe Borges <felipeborges gnome org>
Date:   Wed Apr 4 13:16:15 2018 +0200

    app: Add inhibit methods
    
    Due to the European Union power saving regulations [0],
    more and more users have been reporting that their VM
    installs are getting corrupted due to suspending
    happening during it.
    
    Therefore we should rely on Gtk.Applications inhibit
    API to prevent the system from suspending while Boxes
    is performing some of its operations.
    
    [0] gnome-settings-daemon@2fdb48fa
    
    Fixes #193

 src/app.vala | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
---
diff --git a/src/app.vala b/src/app.vala
index 89aba7a8..77d7d7c6 100644
--- a/src/app.vala
+++ b/src/app.vala
@@ -44,6 +44,8 @@ public virtual async void add_source (CollectionSource source) throws GLib.Error
     public CollectionSource default_source { get { return sources.get (DEFAULT_SOURCE_NAME); } }
     public AsyncLauncher async_launcher;
 
+    private uint inhibit_cookie = 0;
+
     public App () {
         application_id = "org.gnome.Boxes";
         flags |= ApplicationFlags.HANDLES_COMMAND_LINE | ApplicationFlags.HANDLES_OPEN;
@@ -617,6 +619,29 @@ public new bool remove_window (AppWindow window) {
 
         return initial_windows_count != windows.length ();
     }
+
+    public new void inhibit (Gtk.Window? window = main_window, Gtk.ApplicationInhibitFlags? flags = null, 
string? reason = null) {
+        if (reason == null) {
+            reason = _("Boxes is doing something");
+        }
+
+        if (flags == null) {
+            flags = Gtk.ApplicationInhibitFlags.IDLE | Gtk.ApplicationInhibitFlags.SUSPEND;
+        }
+
+        uint new_cookie = base.inhibit (window, flags, reason);
+        if (inhibit_cookie != 0) {
+            base.uninhibit (inhibit_cookie);
+        }
+
+        inhibit_cookie = new_cookie;
+    }
+
+    public new void uninhibit () {
+        if (inhibit_cookie != 0) {
+            base.uninhibit (inhibit_cookie);
+        }
+    }
 }
 
 [GtkTemplate (ui = "/org/gnome/Boxes/ui/kbd-shortcuts-window.ui")]


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