gget r8 - trunk/gget



Author: johans
Date: Mon Jun 16 16:55:22 2008
New Revision: 8
URL: http://svn.gnome.org/viewvc/gget?rev=8&view=rev

Log:
Implemented autostart on login.

Modified:
   trunk/gget/PreferencesDialog.py

Modified: trunk/gget/PreferencesDialog.py
==============================================================================
--- trunk/gget/PreferencesDialog.py	(original)
+++ trunk/gget/PreferencesDialog.py	Mon Jun 16 16:55:22 2008
@@ -18,15 +18,21 @@
 # along with gget; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 
+import os.path
+import shutil
 from gettext import gettext as _
 
 import gtk
 import gconf
+import gnomedesktop
 
 import Configuration
 import GUI
 from gget import NAME
 
+AUTOSTART_DIR = "~/.config/autostart"
+DESKTOP_FILE = "gget.desktop"
+
 class PreferencesDialog:
     def __init__(self, config):
         self.config = config
@@ -132,6 +138,29 @@
         elif entry.value.type == gconf.VALUE_BOOL:
             value = entry.value.get_bool()
             self.autostart_checkbutton.set_active(value)
+
+            autostart_dir = os.path.expanduser(AUTOSTART_DIR)
+            if value:
+                try:
+                    item = gnomedesktop.item_new_from_basename(DESKTOP_FILE,
+                            gnomedesktop.LOAD_ONLY_IF_EXISTS)
+                except gobject.GError:
+                    raise ValueError("File path not a .desktop file")
+
+                if not item:
+                    raise ValueError("URI not found")
+
+                # Looks like gnomedesktop.DesktopItem.save(str, bool) isn't
+                # implemented so copying manually for now.
+                if not os.path.exists(autostart_dir):
+                    os.makedirs(autostart_dir)
+
+                shutil.copy2(item.get_location().replace("file://", ""),
+                        autostart_dir)
+            else:
+                autostart_file = os.path.join(autostart_dir, DESKTOP_FILE)
+                if os.path.exists(autostart_file):
+                    os.remove(autostart_file)
         else:
             self.autostart_checkbutton.set_active(True)
 



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