Пример #1
0
    def save(self):
        util.fillKeyFile(self.keyfile, self.get_keyfile_edits())
        contents, length = self.keyfile.to_data()
        need_exec = False
        if self.destdir is not None:
            self.item_path = os.path.join(
                self.destdir,
                self.builder.get_object('name-entry').get_text() + ".desktop")
            need_exec = True

        try:
            with open(self.item_path, 'w') as f:
                f.write(contents)
            if need_exec:
                os.chmod(self.item_path, 0o755)

            subprocess.Popen(
                ['update-desktop-database',
                 util.getUserItemPath()],
                env=os.environ)
        except IOError as e:
            if ask(
                    _("Cannot create the launcher at this location.  Add to the desktop instead?"
                      )):
                self.destdir = GLib.get_user_special_dir(
                    GLib.UserDirectory.DIRECTORY_DESKTOP)
                self.save()
Пример #2
0
    def makeKeyFile(self, file_path, kwargs):
        if 'KeyFile' in kwargs:
            return kwargs['KeyFile']

        keyfile = GLib.KeyFile()

        if file_path is not None:
            keyfile.load_from_file(file_path, util.KEY_FILE_FLAGS)

        util.fillKeyFile(keyfile, kwargs)
        return keyfile
Пример #3
0
    def makeKeyFile(self, file_path, kwargs):
        if 'KeyFile' in kwargs:
            return kwargs['KeyFile']

        keyfile = GLib.KeyFile()

        if file_path is not None:
            keyfile.load_from_file(file_path, util.KEY_FILE_FLAGS)

        util.fillKeyFile(keyfile, kwargs)
        return keyfile
    def save(self):
        util.fillKeyFile(self.keyfile, self.get_keyfile_edits())
        contents, length = self.keyfile.to_data()
        need_exec = False
        if self.destdir is not None:
            self.item_path = os.path.join(self.destdir, self.builder.get_object('name-entry').get_text() + ".desktop")
            need_exec = True

        try:
            with open(self.item_path, 'w') as f:
                f.write(contents)
            if need_exec:
                os.chmod(self.item_path, 0o755)
        except IOError:
            if ask(_("Cannot create the launcher at this location.  Add to the desktop instead?")):
                self.destdir = GLib.get_user_special_dir(GLib.UserDirectory.DIRECTORY_DESKTOP)
                self.save()
Пример #5
0
 def pasteItem(self, cut_copy_buffer, menu, file_id = None):
     try:
         path = self.getPath(menu)
         util.fillKeyFile(cut_copy_buffer, dict(Hidden=False, NoDisplay=False))
         name = util.getNameFromKeyFile(cut_copy_buffer)
         if file_id is None:
             file_id = util.getUniqueFileId(name.replace(os.sep, '-'), '.desktop')
         out_path = os.path.join(util.getUserItemPath(), file_id)
         contents, length = cut_copy_buffer.to_data()
         f = open(out_path, 'w')
         f.write(contents)
         f.close()
         menu_xml = self.getXmlMenu(path, self.dom.documentElement, self.dom)
         self.addXmlFilename(menu_xml, self.dom, file_id, 'Include')
         self.addXmlTextElement(menu_xml, 'AppDir', util.getUserItemPath(), self.dom)
         self.save()
         return True
     except:
         return False
Пример #6
0
 def pasteItem(self, cut_copy_buffer, menu, file_id = None):
     try:
         path = self.getPath(menu)
         util.fillKeyFile(cut_copy_buffer, dict(Hidden=False, NoDisplay=False))
         name = util.getNameFromKeyFile(cut_copy_buffer)
         if file_id is None:
             file_id = util.getUniqueFileId(name.replace(os.sep, '-'), '.desktop')
         out_path = os.path.join(util.getUserItemPath(), file_id)
         contents, length = cut_copy_buffer.to_data()
         f = open(out_path, 'w')
         f.write(contents)
         f.close()
         menu_xml = self.getXmlMenu(path, self.dom.documentElement, self.dom)
         self.addXmlFilename(menu_xml, self.dom, file_id, 'Include')
         self.addXmlTextElement(menu_xml, 'AppDir', util.getUserItemPath(), self.dom)
         self.save()
         return True
     except:
         return False
Пример #7
0
    def writeMenu(self, menu, **kwargs):
        if menu is not None:
            file_id = os.path.split(menu.get_desktop_file_path())[1]
            file_path = menu.get_desktop_file_path()
            keyfile = GLib.KeyFile()
            keyfile.load_from_file(file_path, util.KEY_FILE_FLAGS)
        elif menu is None and 'Name' not in kwargs:
            raise Exception('New menus need a name')
        else:
            file_id = util.getUniqueFileId(kwargs['Name'], '.directory')
            keyfile = GLib.KeyFile()

        util.fillKeyFile(keyfile, kwargs)

        contents, length = keyfile.to_data()

        f = open(os.path.join(util.getUserDirectoryPath(), file_id), 'w')
        f.write(contents)
        f.close()
        return file_id
Пример #8
0
    def writeMenu(self, menu, **kwargs):
        if menu is not None:
            file_id = os.path.split(menu.get_desktop_file_path())[1]
            file_path = menu.get_desktop_file_path()
            keyfile = GLib.KeyFile()
            keyfile.load_from_file(file_path, util.KEY_FILE_FLAGS)
        elif menu is None and 'Name' not in kwargs:
            raise Exception('New menus need a name')
        else:
            file_id = util.getUniqueFileId(kwargs['Name'], '.directory')
            keyfile = GLib.KeyFile()

        util.fillKeyFile(keyfile, kwargs)

        contents, length = keyfile.to_data()

        f = open(os.path.join(util.getUserDirectoryPath(), file_id), 'w')
        f.write(contents)
        f.close()
        return file_id
Пример #9
0
    def copyItem(self, item, new_parent, before=None, after=None):
        dom = self.dom
        file_path = item.get_desktop_file_path()
        keyfile = GLib.KeyFile()
        keyfile.load_from_file(file_path, util.KEY_FILE_FLAGS)

        util.fillKeyFile(keyfile, dict(Categories=[], Hidden=False))

        app_info = item.get_app_info()
        file_id = util.getUniqueFileId(app_info.get_name().replace(os.sep, '-'), '.desktop')
        out_path = os.path.join(util.getUserItemPath(), file_id)

        contents, length = keyfile.to_data()

        f = open(out_path, 'w')
        f.write(contents)
        f.close()

        self.addItem(new_parent, file_id, dom)
        self.positionItem(new_parent, ('Item', file_id), before, after)
        self.save()
        return file_id