[gnome-tweak-tool] Autostart nautilus if configured to show desktop icons



commit 22f007d7e476b59b56ab995dc56b585c97174c2c
Author: John Stowers <john stowers gmail com>
Date:   Wed Apr 27 19:47:46 2011 +1200

    Autostart nautilus if configured to show desktop icons

 NEWS                            |    3 ++-
 gnome-tweak-tool                |    3 +++
 gtweak/tweaks/tweak_nautilus.py |   20 +++++++++++++++++++-
 gtweak/utils.py                 |   20 +++++++++++++-------
 4 files changed, 37 insertions(+), 9 deletions(-)
---
diff --git a/NEWS b/NEWS
index 21b209c..4ba0eff 100644
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,6 @@
 3.0.3
-   *
+   * Autostart nautilus at login if it is configured to show
+     desktop icons (bug 648087)
 
 3.0.2
    * Really tweak window theme - both the fallback and the
diff --git a/gnome-tweak-tool b/gnome-tweak-tool
index d89128c..4902a66 100755
--- a/gnome-tweak-tool
+++ b/gnome-tweak-tool
@@ -15,6 +15,7 @@
 
 import os.path
 import optparse
+import logging
 
 import gi
 gi.require_version("Gtk", "3.0")
@@ -78,5 +79,7 @@ if __name__ == '__main__':
     gtweak.PKG_DATA_DIR = PKG_DATA_DIR
     gtweak.ENABLE_TEST = options.test
 
+    logging.basicConfig()
+
     MainWindow()
 
diff --git a/gtweak/tweaks/tweak_nautilus.py b/gtweak/tweaks/tweak_nautilus.py
index b359bbb..7ed3670 100644
--- a/gtweak/tweaks/tweak_nautilus.py
+++ b/gtweak/tweaks/tweak_nautilus.py
@@ -17,11 +17,29 @@
 
 from gi.repository import Gtk
 
+import gtweak
+from gtweak.utils import AutostartManager
 from gtweak.tweakmodel import TweakGroup
 from gtweak.widgets import GSettingsSwitchTweak
 
+class DesktopIconTweak(GSettingsSwitchTweak):
+    def __init__(self, **options):
+        GSettingsSwitchTweak.__init__(self,
+            "org.gnome.desktop.background",
+            "show-desktop-icons",
+            **options)
+
+        #when the user enables nautilus to draw the desktop icons, set nautilus
+        #to autostart
+        self.nautilus = AutostartManager(gtweak.DATA_DIR, "nautilus.desktop", "nautilus -n")
+        self.settings.connect('changed::'+self.key_name, self._on_setting_changed)
+
+    def _on_setting_changed(self, setting, key):
+        self.nautilus.update_start_at_login(
+                self.settings.get_boolean(key))
+
 TWEAK_GROUPS = (
         TweakGroup(
             "File Manager",
-            GSettingsSwitchTweak("org.gnome.desktop.background", "show-desktop-icons")),
+            DesktopIconTweak()),
 )
diff --git a/gtweak/utils.py b/gtweak/utils.py
index f0a1538..846aa11 100644
--- a/gtweak/utils.py
+++ b/gtweak/utils.py
@@ -16,14 +16,16 @@
 # along with gnome-tweak-tool.  If not, see <http://www.gnu.org/licenses/>.
 
 import os.path
+import logging
 
 from gi.repository import GLib
 
 class AutostartManager:
-    def __init__(self, DATA_DIR, desktop_filename, extra_exec_args=""):
-        self._desktop_file = os.path.join(DATA_DIR, desktop_filename)
+    def __init__(self, DATA_DIR, desktop_filename, exec_cmd="", extra_exec_args=""):
+        self._desktop_file = os.path.join(DATA_DIR, "applications", desktop_filename)
         self._autostart_file = os.path.join(
                                     GLib.get_user_config_dir(), "autostart", desktop_filename)
+        self._exec_cmd = exec_cmd
         self._extra_exec_args = " %s\n" % extra_exec_args
 
     def is_start_at_login_enabled(self):
@@ -36,25 +38,29 @@ class AutostartManager:
             return False
 
     def update_start_at_login(self, update):
+        logging.debug("updating autostart desktop file: %s" % update)
 
         if os.path.exists(self._autostart_file):
-            log.info("Removing autostart desktop file")
+            logging.info("Removing autostart desktop file")
             os.remove(self._autostart_file)
 
         if update:
             if not os.path.exists(self._desktop_file):
-                log.critical("Could not find desktop file: %s" % self._desktop_file)
+                logging.critical("Could not find desktop file: %s" % self._desktop_file)
                 return
 
-            log.info("Adding autostart desktop file")
+            logging.info("Adding autostart desktop file")
             #copy the original file to the new file, but add the extra exec args
             old = open(self._desktop_file, "r")
             new = open(self._autostart_file, "w")
 
             for l in old.readlines():         
                 if l.startswith("Exec="):
-                    new.write(l[0:-1])
-                    new.write(self._extra_exec_args)
+                    if self._exec_cmd:
+                        new.write("Exec=%s\n" % self._exec_cmd)
+                    else:
+                        new.write(l[0:-1])
+                        new.write(self._extra_exec_args)
                 else:
                     new.write(l)
 



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