예제 #1
0
	def __writeItem(self, item=None, icon=None, name=None, comment=None, command=None, use_term=None, no_display=None, startup_notify=None, hidden=None):
		if item:
			file_path = item.get_desktop_file_path()
			file_id = item.get_desktop_file_id()
			keyfile = util.DesktopParser(file_path)
		elif item == None and name == None:
			raise Exception('New menu items need a name')
		else:
			file_id = util.getUniqueFileId(name, '.desktop')
			keyfile = util.DesktopParser()
		if icon:
			keyfile.set('Icon', icon)
			keyfile.set('Icon', icon, self.locale)
		if name:
			keyfile.set('Name', name)
			keyfile.set('Name', name, self.locale)
		if comment:
			keyfile.set('Comment', comment)
			keyfile.set('Comment', comment, self.locale)
		if command:
			keyfile.set('Exec', command)
		if use_term != None:
			keyfile.set('Terminal', use_term)
		if no_display != None:
			keyfile.set('NoDisplay', no_display)
		if startup_notify != None:
			keyfile.set('StartupNotify', startup_notify)
		if hidden != None:
			keyfile.set('Hidden', hidden)
		out_path = os.path.join(util.getUserItemPath(), file_id)
		keyfile.write(open(out_path, 'w'))
		return file_id
예제 #2
0
	def __writeMenu(self, menu=None, icon=None, name=None, comment=None, no_display=None):
		if menu:
			file_id = os.path.split(menu.get_desktop_file_path())[1]
			file_path = menu.get_desktop_file_path()
			keyfile = util.DesktopParser(file_path)
		elif menu == None and name == None:
			raise Exception('New menus need a name')
		else:
			file_id = util.getUniqueFileId(name, '.directory')
			keyfile = util.DesktopParser(file_type='Directory')
		if icon:
			keyfile.set('Icon', icon)
		if name:
			keyfile.set('Name', name)
			keyfile.set('Name', name, self.locale)
		if comment:
			keyfile.set('Comment', comment)
			keyfile.set('Comment', comment, self.locale)
		if no_display != None:
			keyfile.set('NoDisplay', no_display)
		out_path = os.path.join(util.getUserDirectoryPath(), file_id)
		keyfile.write(open(out_path, 'w'))
		return file_id
예제 #3
0
	def copyItem(self, item, new_parent, before=None, after=None):
		dom = self.__getMenu(new_parent).dom
		file_path = item.get_desktop_file_path()
		keyfile = util.DesktopParser(file_path)
		#erase Categories in new file
		keyfile.set('Categories', ('',))
		keyfile.set('Hidden', False)
		file_id = util.getUniqueFileId(item.get_name(), '.desktop')
		out_path = os.path.join(util.getUserItemPath(), file_id)
		keyfile.write(open(out_path, 'w'))
		self.__addItem(new_parent, file_id, dom)
		self.__positionItem(new_parent, ('Item', file_id), before, after)
		self.__addUndo([self.__getMenu(new_parent), ('Item', file_id)])
		self.save()
		return file_id
예제 #4
0
    def on_edit_properties_activate(self, menu):
        item_tree = self.tree.get_object('item_tree')
        items, iter = item_tree.get_selection().get_selected()
        if not iter:
            return
        item = items[iter][3]
        if item.get_type() not in (gmenu.TYPE_ENTRY, gmenu.TYPE_DIRECTORY):
            return

        if item.get_type() == gmenu.TYPE_ENTRY:
            file_path = os.path.join(util.getUserItemPath(),
                                     item.get_desktop_file_id())
            file_type = 'Item'
        elif item.get_type() == gmenu.TYPE_DIRECTORY:
            if item.get_desktop_file_path() == None:
                file_path = util.getUniqueFileId('alacarte-made', '.directory')
                parser = util.DesktopParser(file_path, 'Directory')
                parser.set('Name', item.get_name())
                parser.set('Comment', item.get_comment())
                parser.set('Icon', item.get_icon())
                parser.write(open(file_path))
            else:
                file_path = os.path.join(
                    util.getUserDirectoryPath(),
                    os.path.split(item.get_desktop_file_path())[1])
            file_type = 'Menu'

        if not os.path.isfile(file_path):
            data = open(item.get_desktop_file_path()).read()
            open(file_path, 'w').write(data)
            self.editor._MenuEditor__addUndo([
                (file_type, os.path.split(file_path)[1]),
            ])
        else:
            self.editor._MenuEditor__addUndo([
                item,
            ])
        if file_path not in self.edit_pool:
            self.edit_pool.append(file_path)
            process = subprocess.Popen(['gnome-desktop-item-edit', file_path],
                                       env=os.environ)
            gobject.timeout_add(100, self.waitForEditProcess, process,
                                file_path)
예제 #5
0
 def on_item_tree_drag_data_received(self, treeview, context, x, y,
                                     selection, info, etime):
     items = treeview.get_model()
     types = (gtk.TREE_VIEW_DROP_BEFORE, gtk.TREE_VIEW_DROP_INTO_OR_BEFORE)
     if selection.target == 'ALACARTE_ITEM_ROW':
         drop_info = treeview.get_dest_row_at_pos(x, y)
         before = None
         after = None
         if self.drag_data == None:
             return False
         item = self.drag_data
         if drop_info:
             path, position = drop_info
             if position in types:
                 before = items[path][3]
             else:
                 after = items[path][3]
         else:
             path = (len(items) - 1, )
             after = items[path][3]
         if item.get_type() == gmenu.TYPE_ENTRY:
             self.editor.moveItem(item, item.get_parent(), before, after)
         elif item.get_type() == gmenu.TYPE_DIRECTORY:
             if self.editor.moveMenu(item, item.get_parent(), before,
                                     after) == False:
                 self.loadUpdates()
         elif item.get_type() == gmenu.TYPE_SEPARATOR:
             self.editor.moveSeparator(item, item.get_parent(), before,
                                       after)
         context.finish(True, True, etime)
     elif selection.target == 'text/plain':
         if selection.data == None:
             return False
         menus, iter = self.tree.get_object(
             'menu_tree').get_selection().get_selected()
         parent = menus[iter][2]
         drop_info = treeview.get_dest_row_at_pos(x, y)
         before = None
         after = None
         if drop_info:
             path, position = drop_info
             if position in types:
                 before = items[path][3]
             else:
                 after = items[path][3]
         else:
             path = (len(items) - 1, )
             after = items[path][3]
         file_path = urllib.unquote(selection.data).strip()
         if not file_path.startswith('file:'):
             return
         myfile = gio.File(uri=file_path)
         file_info = myfile.query_info(
             gio.FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE)
         content_type = file_info.get_content_type()
         if content_type == 'application/x-desktop':
             input_stream = myfile.read()
             open('/tmp/alacarte-dnd.desktop',
                  'w').write(input_stream.read())
             parser = util.DesktopParser('/tmp/alacarte-dnd.desktop')
             self.editor.createItem(
                 parent, parser.get('Icon'),
                 parser.get('Name', self.editor.locale),
                 parser.get('Comment', self.editor.locale),
                 parser.get('Exec'), parser.get('Terminal'), before, after)
         elif content_type in ('application/x-shellscript',
                               'application/x-executable'):
             self.editor.createItem(
                 parent, None,
                 os.path.split(file_path)[1].strip(), None,
                 file_path.replace('file://', '').strip(), False, before,
                 after)
     self.drag_data = None