def test_basic(self): entry = DesktopEntry(self.test_file) assert entry.hasKey("Categories") assert not entry.hasKey("TryExec") assert entry.hasGroup("Desktop Action Window") assert not entry.hasGroup("Desktop Action Door")
class Autostart(gobject.GObject): __gsignals__ = { 'changed' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_BOOLEAN,)), } def __init__(self): gobject.GObject.__init__(self) self.config = Config.Config(tgcm.country_support) # Determine the path for XDG autostart dirs self.autofile_name = 'tgcm-%s.desktop' % tgcm.country_support self.user_autodir = None for foo in BaseDirectory.load_config_paths('autostart'): if foo.startswith(os.path.expanduser('~')): self.user_autodir = foo else: self.system_autodir = foo self.__create_desktop_entry_if_necessary() # Listen to file changes myfile = gio.File(self.user_autofile) self.desktopentry_monitor = myfile.monitor_file() self.desktopentry_monitor.connect('changed', self.on_desktopentry_changed) def __create_desktop_entry_if_necessary(self): # Create user autostart dir if it does not exists if self.user_autodir is None: self.user_autodir = BaseDirectory.save_config_path('autostart') # It it does not exists an autostart file for TGCM in userdir, # create a copy from the global one self.user_autofile = os.path.join(self.user_autodir, self.autofile_name) if not os.path.exists(self.user_autofile): autofile_path = os.path.join(self.system_autodir, self.autofile_name) shutil.copy(autofile_path, self.user_autofile) # Honor 'launch-startup' policy in regional-info.xml file self.desktopentry = DesktopEntry(self.user_autofile) is_autostart = self.config.check_policy('launch-startup') self.set_enabled(is_autostart) else: self.desktopentry = DesktopEntry(self.user_autofile) def is_enabled(self): self.__create_desktop_entry_if_necessary() # Check if the DesktopEntry object has an autostart attribute if self.desktopentry.hasKey('X-GNOME-Autostart-enabled'): is_autostart = self.desktopentry.get('X-GNOME-Autostart-enabled', \ type='boolean') else: is_autostart = True if self.desktopentry.hasKey('Hidden'): is_shown = not self.desktopentry.get('Hidden', type='boolean') else: is_shown = True return is_shown and is_autostart def set_enabled(self, value): self.__create_desktop_entry_if_necessary() value = str(value).lower() self.desktopentry.set('X-GNOME-Autostart-enabled', value) self.desktopentry.removeKey('Hidden') self.desktopentry.write() def on_desktopentry_changed(self, monitor, myfile, other_file, event): if event == gio.FILE_MONITOR_EVENT_DELETED: self.__create_desktop_entry_if_necessary() is_enabled = self.is_enabled() self.emit('changed', is_enabled)
class Autostart(gobject.GObject): __gsignals__ = { 'changed': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_BOOLEAN, )), } def __init__(self): gobject.GObject.__init__(self) self.config = Config.Config(tgcm.country_support) # Determine the path for XDG autostart dirs self.autofile_name = 'tgcm-%s.desktop' % tgcm.country_support self.user_autodir = None for foo in BaseDirectory.load_config_paths('autostart'): if foo.startswith(os.path.expanduser('~')): self.user_autodir = foo else: self.system_autodir = foo self.__create_desktop_entry_if_necessary() # Listen to file changes myfile = gio.File(self.user_autofile) self.desktopentry_monitor = myfile.monitor_file() self.desktopentry_monitor.connect('changed', self.on_desktopentry_changed) def __create_desktop_entry_if_necessary(self): # Create user autostart dir if it does not exists if self.user_autodir is None: self.user_autodir = BaseDirectory.save_config_path('autostart') # It it does not exists an autostart file for TGCM in userdir, # create a copy from the global one self.user_autofile = os.path.join(self.user_autodir, self.autofile_name) if not os.path.exists(self.user_autofile): autofile_path = os.path.join(self.system_autodir, self.autofile_name) shutil.copy(autofile_path, self.user_autofile) # Honor 'launch-startup' policy in regional-info.xml file self.desktopentry = DesktopEntry(self.user_autofile) is_autostart = self.config.check_policy('launch-startup') self.set_enabled(is_autostart) else: self.desktopentry = DesktopEntry(self.user_autofile) def is_enabled(self): self.__create_desktop_entry_if_necessary() # Check if the DesktopEntry object has an autostart attribute if self.desktopentry.hasKey('X-GNOME-Autostart-enabled'): is_autostart = self.desktopentry.get('X-GNOME-Autostart-enabled', \ type='boolean') else: is_autostart = True if self.desktopentry.hasKey('Hidden'): is_shown = not self.desktopentry.get('Hidden', type='boolean') else: is_shown = True return is_shown and is_autostart def set_enabled(self, value): self.__create_desktop_entry_if_necessary() value = str(value).lower() self.desktopentry.set('X-GNOME-Autostart-enabled', value) self.desktopentry.removeKey('Hidden') self.desktopentry.write() def on_desktopentry_changed(self, monitor, myfile, other_file, event): if event == gio.FILE_MONITOR_EVENT_DELETED: self.__create_desktop_entry_if_necessary() is_enabled = self.is_enabled() self.emit('changed', is_enabled)