From 5f419d81f72eda682a3f1591d56e432f7ba92939 Mon Sep 17 00:00:00 2001 From: Icius Date: Thu, 21 Jan 2010 17:59:19 -0500 Subject: [PATCH 1/7] Added a simple "Edit" menu item to the Favorites right click context menu to launch gnome-desktop-item-edit in context. Not complete yet, more to do... --- usr/lib/linuxmint/mintMenu/plugins/applications.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/usr/lib/linuxmint/mintMenu/plugins/applications.py b/usr/lib/linuxmint/mintMenu/plugins/applications.py index 28c1a9e..dfc1051 100755 --- a/usr/lib/linuxmint/mintMenu/plugins/applications.py +++ b/usr/lib/linuxmint/mintMenu/plugins/applications.py @@ -633,6 +633,7 @@ class pluginclass( object ): mTree = gtk.glade.XML( self.gladefile, "favoritesMenu" ) #i18n launchMenuItem = gtk.MenuItem(_("Launch")) + editMenuItem = gtk.MenuItem(_("Edit")) removeFromFavMenuItem = gtk.MenuItem(_("Remove from favorites")) startupMenuItem = gtk.CheckMenuItem(_("Launch when I log in")) separator = gtk.SeparatorMenuItem() @@ -641,11 +642,13 @@ class pluginclass( object ): launchMenuItem.connect( "activate", self.onLaunchApp, widget) + editMenuItem.connect( "activate", self.onEditApp, widget) removeFromFavMenuItem.connect( "activate", self.onFavoritesRemove, widget ) insertSpaceMenuItem.connect( "activate", self.onFavoritesInsertSpace, widget, insertBefore ) insertSeparatorMenuItem.connect( "activate", self.onFavoritesInsertSeparator, widget, insertBefore ) mTree.get_widget("favoritesMenu").append(launchMenuItem) + mTree.get_widget("favoritesMenu").append(editMenuItem) mTree.get_widget("favoritesMenu").append(removeFromFavMenuItem) mTree.get_widget("favoritesMenu").append(startupMenuItem) mTree.get_widget("favoritesMenu").append(separator) @@ -718,6 +721,11 @@ class pluginclass( object ): widget.execute() self.mintMenuWin.hide() + def onEditApp( self, menu, widget ): + # print u"Location of favorite is: " + widget.desktopFile + os.system('gnome-desktop-item-edit ' + widget.desktopFile) + self.mintMenuWin.hide() + def onUninstallApp( self, menu, widget ): widget.uninstall() self.mintMenuWin.hide() From 18a491a38c1c92966667531714922c6ff519b6ed Mon Sep 17 00:00:00 2001 From: Icius Date: Fri, 22 Jan 2010 12:43:21 -0500 Subject: [PATCH 2/7] Added new getUserItemPath function Renamed "Edit" to "Prop" throughout to indicate Properties of the menu item Added code in to copy the .desktop file in the /usr directory structure to the user's local directory before editing properties Updated menuPopup function to include the new functionality as well --- .../mintMenu/plugins/applications.py | 37 ++++++++++++++++--- 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/usr/lib/linuxmint/mintMenu/plugins/applications.py b/usr/lib/linuxmint/mintMenu/plugins/applications.py index dfc1051..82e3450 100755 --- a/usr/lib/linuxmint/mintMenu/plugins/applications.py +++ b/usr/lib/linuxmint/mintMenu/plugins/applications.py @@ -73,6 +73,20 @@ gettext.install("mintmenu", "/usr/share/linuxmint/locale") # #xdg.Menu.parse = xdgParsePatched +# Helper function for retrieving the user's location for storing new or modified menu items +def getUserItemPath(): + item_dir = None + + if os.environ.has_key('XDG_DATA_HOME'): + item_dir = os.path.join(os.environ['XDG_DATA_HOME'], 'applications') + else: + item_dir = os.path.join(os.environ['HOME'], '.local', 'share', 'applications') + + if not os.path.isdir(item_dir): + os.makedirs(item_dir) + + return item_dir + class Menu: def __init__( self, MenuToLookup ): self.tree = gmenu.lookup_tree( MenuToLookup ) @@ -633,7 +647,7 @@ class pluginclass( object ): mTree = gtk.glade.XML( self.gladefile, "favoritesMenu" ) #i18n launchMenuItem = gtk.MenuItem(_("Launch")) - editMenuItem = gtk.MenuItem(_("Edit")) + propsMenuItem = gtk.MenuItem(_("Properties")) removeFromFavMenuItem = gtk.MenuItem(_("Remove from favorites")) startupMenuItem = gtk.CheckMenuItem(_("Launch when I log in")) separator = gtk.SeparatorMenuItem() @@ -642,13 +656,13 @@ class pluginclass( object ): launchMenuItem.connect( "activate", self.onLaunchApp, widget) - editMenuItem.connect( "activate", self.onEditApp, widget) + propsMenuItem.connect( "activate", self.onPropsApp, widget) removeFromFavMenuItem.connect( "activate", self.onFavoritesRemove, widget ) insertSpaceMenuItem.connect( "activate", self.onFavoritesInsertSpace, widget, insertBefore ) insertSeparatorMenuItem.connect( "activate", self.onFavoritesInsertSeparator, widget, insertBefore ) mTree.get_widget("favoritesMenu").append(launchMenuItem) - mTree.get_widget("favoritesMenu").append(editMenuItem) + mTree.get_widget("favoritesMenu").append(propsMenuItem) mTree.get_widget("favoritesMenu").append(removeFromFavMenuItem) mTree.get_widget("favoritesMenu").append(startupMenuItem) mTree.get_widget("favoritesMenu").append(separator) @@ -687,11 +701,13 @@ class pluginclass( object ): #i18n launchMenuItem = gtk.MenuItem(_("Launch")) + propsMenuItem = gtk.MenuItem(_("Properties")) favoriteMenuItem = gtk.CheckMenuItem(_("Show in my favorites")) startupMenuItem = gtk.CheckMenuItem(_("Launch when I log in")) separator = gtk.SeparatorMenuItem() uninstallMenuItem = gtk.MenuItem(_("Uninstall")) mTree.get_widget("applicationsMenu").append(launchMenuItem) + mTree.get_widget("applicationsMenu").append(propsMenuItem) mTree.get_widget("applicationsMenu").append(favoriteMenuItem) mTree.get_widget("applicationsMenu").append(startupMenuItem) mTree.get_widget("applicationsMenu").append(separator) @@ -699,6 +715,7 @@ class pluginclass( object ): mTree.get_widget("applicationsMenu").show_all() launchMenuItem.connect( "activate", self.onLaunchApp, widget ) + propsMenuItem.connect( "activate", self.onPropsApp, widget) uninstallMenuItem.connect ( "activate", self.onUninstallApp, widget ) if self.isLocationInFavorites( widget.desktopFile ): @@ -721,11 +738,19 @@ class pluginclass( object ): widget.execute() self.mintMenuWin.hide() - def onEditApp( self, menu, widget ): - # print u"Location of favorite is: " + widget.desktopFile - os.system('gnome-desktop-item-edit ' + widget.desktopFile) + def onPropsApp( self, menu, widget ): + + # Building a path to the .desktop file in the user's home directory + file_path = os.path.join(getUserItemPath(), os.path.basename(widget.desktopFile)) + + if not os.path.isfile(file_path): + data = open(widget.desktopFile).read() + open(file_path, 'w').write(data) + + os.system('gnome-desktop-item-edit ' + file_path) self.mintMenuWin.hide() + def onUninstallApp( self, menu, widget ): widget.uninstall() self.mintMenuWin.hide() From 8392acfa8ec947aaebe66d01f9dae0d06d23e11d Mon Sep 17 00:00:00 2001 From: Icius Date: Fri, 22 Jan 2010 15:54:03 -0500 Subject: [PATCH 3/7] Added code to determine if the user truly modifed the .desktop file using gnome-desktop-item-edit. If they did not make any changes then the user's local copy is removed. --- usr/lib/linuxmint/mintMenu/plugins/applications.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/usr/lib/linuxmint/mintMenu/plugins/applications.py b/usr/lib/linuxmint/mintMenu/plugins/applications.py index 82e3450..8c7359b 100755 --- a/usr/lib/linuxmint/mintMenu/plugins/applications.py +++ b/usr/lib/linuxmint/mintMenu/plugins/applications.py @@ -12,6 +12,7 @@ import gettext import gnomevfs import threading import commands +import filecmp from easybuttons import * from execute import Execute @@ -748,8 +749,14 @@ class pluginclass( object ): open(file_path, 'w').write(data) os.system('gnome-desktop-item-edit ' + file_path) - self.mintMenuWin.hide() + if filecmp.cmp(widget.desktopFile, file_path): + try: + os.remove(file_path) + except os.error: + pass + + self.mintMenuWin.hide() def onUninstallApp( self, menu, widget ): widget.uninstall() From 805029402181987165814a6d9111758e6aec8e58 Mon Sep 17 00:00:00 2001 From: Icius Date: Fri, 22 Jan 2010 16:24:50 -0500 Subject: [PATCH 4/7] Added a condition around the local file removal logic to only do it if the .desktop file exists somewhere other than the user's local directory structure. --- usr/lib/linuxmint/mintMenu/plugins/applications.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/usr/lib/linuxmint/mintMenu/plugins/applications.py b/usr/lib/linuxmint/mintMenu/plugins/applications.py index 8c7359b..8499ef0 100755 --- a/usr/lib/linuxmint/mintMenu/plugins/applications.py +++ b/usr/lib/linuxmint/mintMenu/plugins/applications.py @@ -750,11 +750,12 @@ class pluginclass( object ): os.system('gnome-desktop-item-edit ' + file_path) - if filecmp.cmp(widget.desktopFile, file_path): - try: - os.remove(file_path) - except os.error: - pass + if file_path != widget.desktopFile: + if filecmp.cmp(widget.desktopFile, file_path): + try: + os.remove(file_path) + except os.error: + pass self.mintMenuWin.hide() From c029e9ac6c21aca41f9053f8e9ec3aa78a407c6f Mon Sep 17 00:00:00 2001 From: Icius Date: Sat, 23 Jan 2010 01:16:49 -0500 Subject: [PATCH 5/7] changed the os.system command to os.spawnlp. When using os.system, the context menu stays visible while the gnome-desktop-item-edit program is running. Looked a bit strange. This change is at the cost of the cleanup routine to delete idential .desktop files in the users directory. --- usr/lib/linuxmint/mintMenu/plugins/applications.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/usr/lib/linuxmint/mintMenu/plugins/applications.py b/usr/lib/linuxmint/mintMenu/plugins/applications.py index 8499ef0..b44c72a 100755 --- a/usr/lib/linuxmint/mintMenu/plugins/applications.py +++ b/usr/lib/linuxmint/mintMenu/plugins/applications.py @@ -748,14 +748,7 @@ class pluginclass( object ): data = open(widget.desktopFile).read() open(file_path, 'w').write(data) - os.system('gnome-desktop-item-edit ' + file_path) - - if file_path != widget.desktopFile: - if filecmp.cmp(widget.desktopFile, file_path): - try: - os.remove(file_path) - except os.error: - pass + pid = os.spawnlp(os.P_NOWAIT, "/usr/bin/gnome-desktop-item-edit", "gnome-desktop-item-edit", file_path) self.mintMenuWin.hide() From 9551b3fb887bc8dba73948ce94524cabcf85398c Mon Sep 17 00:00:00 2001 From: Icius Date: Sat, 6 Feb 2010 01:56:44 -0500 Subject: [PATCH 6/7] Added the rel_path function. can eventually be replaced by the native 2.6 function Added logic to handle items that create their own directory in /usr/share/applications such as kde apps Added logic to determine if the item being modified already exists in the user's directory Renamed variables and function names per pylint recommendation --- .../mintMenu/plugins/applications.py | 45 ++++++++++++++++--- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/usr/lib/linuxmint/mintMenu/plugins/applications.py b/usr/lib/linuxmint/mintMenu/plugins/applications.py index b44c72a..01efab0 100755 --- a/usr/lib/linuxmint/mintMenu/plugins/applications.py +++ b/usr/lib/linuxmint/mintMenu/plugins/applications.py @@ -75,7 +75,7 @@ gettext.install("mintmenu", "/usr/share/linuxmint/locale") #xdg.Menu.parse = xdgParsePatched # Helper function for retrieving the user's location for storing new or modified menu items -def getUserItemPath(): +def get_user_item_path(): item_dir = None if os.environ.has_key('XDG_DATA_HOME'): @@ -88,6 +88,28 @@ def getUserItemPath(): return item_dir + +def rel_path(target, base=os.curdir): + + if not os.path.exists(target): + raise OSError, 'Target does not exist: '+target + + if not os.path.isdir(base): + raise OSError, 'Base is not a directory or does not exist: '+base + + base_list = (os.path.abspath(base)).split(os.sep) + target_list = (os.path.abspath(target)).split(os.sep) + + for i in range(min(len(base_list), len(target_list))): + if base_list[i] <> target_list[i]: break + else: + i += 1 + + rel_list = [os.pardir] * (len(base_list)-i) + target_list[i:] + + return os.path.join(*rel_list) + + class Menu: def __init__( self, MenuToLookup ): self.tree = gmenu.lookup_tree( MenuToLookup ) @@ -741,14 +763,23 @@ class pluginclass( object ): def onPropsApp( self, menu, widget ): - # Building a path to the .desktop file in the user's home directory - file_path = os.path.join(getUserItemPath(), os.path.basename(widget.desktopFile)) + relPath = rel_path(widget.desktopFile, "/usr/share/applications") - if not os.path.isfile(file_path): - data = open(widget.desktopFile).read() - open(file_path, 'w').write(data) + if widget.desktopFile == os.path.join("/usr/share/applications" , relPath): + filePath = os.path.join(get_user_item_path(), relPath) + (head,tail) = os.path.split(filePath) - pid = os.spawnlp(os.P_NOWAIT, "/usr/bin/gnome-desktop-item-edit", "gnome-desktop-item-edit", file_path) + if not os.path.isdir(head): + os.makedirs(head) + + if not os.path.isfile(filePath): + data = open(widget.desktopFile).read() + open(filePath, 'w').write(data) + + else: + filePath = widget.desktopFile + + pid = os.spawnlp(os.P_NOWAIT, "/usr/bin/gnome-desktop-item-edit", "gnome-desktop-item-edit", filePath) self.mintMenuWin.hide() From 1cbff0b2ed0b198534de7b328b0e142cc487fbd7 Mon Sep 17 00:00:00 2001 From: Icius Date: Sat, 6 Feb 2010 02:42:31 -0500 Subject: [PATCH 7/7] Added get_system_item_paths function to retrieve XDG_DATA_DIRS Changed Logic in onPropsApp to iterate through all XDG_DATA_DIRS Removed filecmp import --- .../mintMenu/plugins/applications.py | 42 +++++++++++++------ 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/usr/lib/linuxmint/mintMenu/plugins/applications.py b/usr/lib/linuxmint/mintMenu/plugins/applications.py index 01efab0..ed22b6d 100755 --- a/usr/lib/linuxmint/mintMenu/plugins/applications.py +++ b/usr/lib/linuxmint/mintMenu/plugins/applications.py @@ -12,7 +12,7 @@ import gettext import gnomevfs import threading import commands -import filecmp +import subprocess from easybuttons import * from execute import Execute @@ -88,6 +88,15 @@ def get_user_item_path(): return item_dir +def get_system_item_paths(): + item_dir = None + + if os.environ.has_key('XDG_DATA_DIRS'): + item_dirs = os.environ['XDG_DATA_DIRS'].split(":") + else: + item_dirs = [os.path.join('usr', 'share')] + + return item_dirs def rel_path(target, base=os.curdir): @@ -763,23 +772,30 @@ class pluginclass( object ): def onPropsApp( self, menu, widget ): - relPath = rel_path(widget.desktopFile, "/usr/share/applications") + sysPaths = get_system_item_paths() - if widget.desktopFile == os.path.join("/usr/share/applications" , relPath): - filePath = os.path.join(get_user_item_path(), relPath) - (head,tail) = os.path.split(filePath) + for path in sysPaths: - if not os.path.isdir(head): - os.makedirs(head) + path += "applications" - if not os.path.isfile(filePath): - data = open(widget.desktopFile).read() - open(filePath, 'w').write(data) + relPath = os.path.relpath(widget.desktopFile, path) - else: - filePath = widget.desktopFile + if widget.desktopFile == os.path.join(path, relPath): + filePath = os.path.join(get_user_item_path(), relPath) + (head,tail) = os.path.split(filePath) - pid = os.spawnlp(os.P_NOWAIT, "/usr/bin/gnome-desktop-item-edit", "gnome-desktop-item-edit", filePath) + if not os.path.isdir(head): + os.makedirs(head) + + if not os.path.isfile(filePath): + data = open(widget.desktopFile).read() + open(filePath, 'w').write(data) + break + + else: + filePath = widget.desktopFile + + pid = subprocess.Popen(["/usr/bin/gnome-desktop-item-edit", filePath]).pid self.mintMenuWin.hide()