[gnome-tweak-tool] If nautilus uses GSettings AutostartCondition, then we only need to change the key



commit 9ca5b576cf8bb3aa5784a09d2ba85af4715684dc
Author: John Stowers <john stowers gmail com>
Date:   Mon Jun 6 17:34:29 2011 +1200

    If nautilus uses GSettings AutostartCondition, then we only need to change the key

 gtweak/tweaks/tweak_nautilus.py |    5 ++++-
 gtweak/utils.py                 |   14 +++++++++++---
 2 files changed, 15 insertions(+), 4 deletions(-)
---
diff --git a/gtweak/tweaks/tweak_nautilus.py b/gtweak/tweaks/tweak_nautilus.py
index 7ddd2b5..04272e4 100644
--- a/gtweak/tweaks/tweak_nautilus.py
+++ b/gtweak/tweaks/tweak_nautilus.py
@@ -34,7 +34,10 @@ class DesktopIconTweak(GSettingsSwitchTweak):
         self.nautilus = AutostartManager("nautilus.desktop",
                             autostart_desktop_filename="nautilus-autostart.desktop",
                             exec_cmd="nautilus -n")
-        self.settings.connect('changed::'+self.key_name, self._on_setting_changed)
+        #we only need to install the desktop file on old versions of nautilus/gnome-session.
+        #new ones use the new AutostartCondition and watch the gsettings key automatically
+        if not self.nautilus.uses_autostart_condition("GSettings"):
+            self.settings.connect('changed::'+self.key_name, self._on_setting_changed)
 
     def _on_setting_changed(self, setting, key):
         self.nautilus.update_start_at_login(
diff --git a/gtweak/utils.py b/gtweak/utils.py
index 90d782a..ebbc22f 100644
--- a/gtweak/utils.py
+++ b/gtweak/utils.py
@@ -120,8 +120,16 @@ class AutostartManager:
                             return l.split("=")[-1].strip()
         return None
 
-    def uses_autostart_condition(self):
-        return self.get_autostart_condition() != None
+    def uses_autostart_condition(self, autostart_type=None):
+        asc = self.get_autostart_condition()
+        try:
+            if autostart_type:
+                return asc.split(" ", 1)[0] == autostart_type
+            else:
+                return asc != None
+        except:
+            logging.warning("Testing for expected AutostartCondition failed: Got (%s)" % asc, exc_info=True)
+            return False
 
     def is_start_at_login_enabled(self):
         if os.path.exists(self._user_autostart_file):
@@ -203,7 +211,7 @@ if __name__ == "__main__":
     d = AutostartManager("orca.desktop", "orca-autostart.desktop")
     print d.desktop_filename, "uses autostartcondition", d.uses_autostart_condition()
     print d.desktop_filename, "autostartcondition is:", d.get_autostart_condition()
-    print d.desktop_filename, "autostarts", d.is_start_at_login_enabled()
+    print d.desktop_filename, "uses GSettings autostartcondition", d.uses_autostart_condition("GSettings")
     print d.desktop_filename, "autostarts", d.is_start_at_login_enabled()
 
     d = AutostartManager("dropbox.desktop")



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