Implement auto start ibus.
authorHuang Peng <shawn.p.huang@gmail.com>
Thu, 7 Aug 2008 02:15:05 +0000 (10:15 +0800)
committerHuang Peng <shawn.p.huang@gmail.com>
Thu, 7 Aug 2008 02:15:05 +0000 (10:15 +0800)
setup/main.py
setup/setup.glade

index 77a9324..2e11c98 100644 (file)
@@ -59,7 +59,7 @@ class Setup(object):
     def __flush_gtk_events(self):
         while gtk.events_pending():
             gtk.main_iteration()
-        
+
     def __init__(self):
         super(Setup, self).__init__()
         glade.textdomain("ibus")
@@ -107,6 +107,9 @@ class Setup(object):
 
 
         self.__dialog = self.__xml.get_widget("dialog_setup")
+        self.__checkbutton_auto_start = self.__xml.get_widget("checkbutton_auto_start")
+        self.__checkbutton_auto_start.set_active(self.__is_auto_start())
+        self.__checkbutton_auto_start.connect("toggled", self.__checkbutton_auto_start_toggled_cb)
         self.__tree = self.__xml.get_widget("treeview_engines")
         self.__preload_engines = set(self.__bus.config_get_value(CONFIG_PRELOAD_ENGINES, []))
         model = self.__create_model()
@@ -284,6 +287,28 @@ class Setup(object):
 
         return model
 
+    def __is_auto_start(self):
+        link_file = path.join(BaseDirectory.xdg_config_home, "autostart/ibus.desktop")
+        ibus_desktop = path.join(os.getenv("IBUS_PREFIX"), "share/applications/ibus.desktop")
+
+        if not path.exists(link_file):
+            return False
+        if not path.islink(link_file):
+            return False
+        if path.realpath(link_file) != ibus_desktop:
+            return False
+        return True
+
+    def __checkbutton_auto_start_toggled_cb(self, button):
+        link_file = path.join(BaseDirectory.xdg_config_home, "autostart/ibus.desktop")
+        ibus_desktop = path.join(os.getenv("IBUS_PREFIX"), "share/applications/ibus.desktop")
+        # unlink file
+        try:
+            os.unlink(link_file)
+        except:
+            pass
+        if self.__checkbutton_auto_start.get_active():
+            os.symlink(ibus_desktop, link_file)
 
     def run(self):
         return self.__dialog.run()
index 2ea708a..ef05f3d 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
 <!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
-<!--Generated with glade3 3.4.4 on Wed Aug  6 22:38:17 2008 -->
+<!--Generated with glade3 3.4.4 on Thu Aug  7 09:58:25 2008 -->
 <glade-interface>
   <widget class="GtkDialog" id="dialog_setup">
     <property name="border_width">5</property>
@@ -21,7 +21,7 @@
               <widget class="GtkVBox" id="vbox2">
                 <property name="visible">True</property>
                 <child>
-                  <widget class="GtkCheckButton" id="checkbutton2">
+                  <widget class="GtkCheckButton" id="checkbutton_auto_start">
                     <property name="visible">True</property>
                     <property name="can_focus">True</property>
                     <property name="label" translatable="yes">Auto start IBus on session login</property>