Merge lp:~john-pankov/dockmanager/quicklists into lp:dockmanager

Proposed by Eugene Pankov
Status: Merged
Merged at revision: 95
Proposed branch: lp:~john-pankov/dockmanager/quicklists
Merge into: lp:dockmanager
Diff against target: 142 lines (+111/-0)
4 files modified
metadata/Makefile.am (+1/-0)
metadata/quicklists.py.info (+4/-0)
scripts/Makefile.am (+1/-0)
scripts/quicklists.py (+105/-0)
To merge this branch: bzr merge lp:~john-pankov/dockmanager/quicklists
Reviewer Review Type Date Requested Status
Eugene Pankov (community) Approve
Rico Tzschichholz Approve
Michal Hruby (community) Approve
Review via email: mp+63570@code.launchpad.net

Description of the change

Added support for the Unity Quicklists

To post a comment you must log in.
Revision history for this message
Michal Hruby (mhr3) wrote :

Since this is Ubuntu-specific, I think it'd be much better to read just the desktop cache file and also install a file monitor on it, and if it doesn't exist then assume this ain't Ubuntu and there are no Unity-specific desktop files.

Revision history for this message
Eugene Pankov (john-pankov) wrote :

AFAIK desktop*.cache doesn't contain X-Ayatana-Desktop-Shortcuts entries.
Also not sure if the file monitor is needed - we'll get item_path_found() if user launches newly installed app.
Please let me know your thoughts on this.

Revision history for this message
Michal Hruby (mhr3) wrote :

You're right, my bad... Still I don't like the crawling of all the desktop files, ultimately you do get the path to desktop file in the item_path_found() method, so it'd be much better to just load it there.

Revision history for this message
Rico Tzschichholz (ricotz) wrote :

Interesting, but indeed you should use the desktop-file-path over dbus and scan it for quicklists. Scanning the whole applications-folder everytime isnt nice.

review: Needs Fixing
96. By Eugene Pankov

Enhanced quicklists backend

Revision history for this message
Eugene Pankov (john-pankov) wrote :

Fixed

review: Needs Resubmitting
Revision history for this message
Michal Hruby (mhr3) wrote :

1) the DesktopFile property can be empty string if the window can't be matched, you don't handle that
2) you should cache the desktop files you already loaded at some point, we don't need extra i/o on every window close/open cycle

review: Needs Fixing
97. By Eugene Pankov

Added desktop file caching to quicklists

Revision history for this message
Eugene Pankov (john-pankov) wrote :

Fixed both points

review: Needs Resubmitting
Revision history for this message
Michal Hruby (mhr3) wrote :

One last thing, please use glib/gio to launch the desktop files (instead of Popen), that will enable you to get rid of the remove_params function.

review: Needs Fixing
98. By Eugene Pankov

Replaced subprocess with gio in quicklists helper

Revision history for this message
Eugene Pankov (john-pankov) wrote :

Fixed

Revision history for this message
Michal Hruby (mhr3) wrote :

Looks good to me...

review: Approve
Revision history for this message
Rico Tzschichholz (ricotz) wrote :

Would be nice if available translations of the QuickList entries could be taken into account. This means using Name[LOCALE]=... with a fallback to Name=...

99. By Eugene Pankov

Added localization support to quicklists

Revision history for this message
Eugene Pankov (john-pankov) wrote :

Done

Revision history for this message
Rico Tzschichholz (ricotz) :
review: Approve
Revision history for this message
Eugene Pankov (john-pankov) wrote :

...

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'metadata/Makefile.am'
2--- metadata/Makefile.am 2011-04-23 11:23:30 +0000
3+++ metadata/Makefile.am 2011-06-28 14:19:52 +0000
4@@ -18,6 +18,7 @@
5 tomboy_menus.py.info \
6 transmission_badge.py.info \
7 tsclient_menus.py.info \
8+ quicklists.py.info \
9 workrave_helper.py.info \
10 zeitgeist_menus.py.info \
11 zeitgeist_journal.py.info
12
13=== added file 'metadata/quicklists.py.info'
14--- metadata/quicklists.py.info 1970-01-01 00:00:00 +0000
15+++ metadata/quicklists.py.info 2011-06-28 14:19:52 +0000
16@@ -0,0 +1,4 @@
17+[DockmanagerHelper]
18+Name=Unity Quicklists
19+Description=Adds quicklist entries to apps' context menus
20+Icon=alacarte
21
22=== modified file 'scripts/Makefile.am'
23--- scripts/Makefile.am 2011-04-23 11:23:30 +0000
24+++ scripts/Makefile.am 2011-06-28 14:19:52 +0000
25@@ -18,6 +18,7 @@
26 tomboy_menus.py \
27 transmission_badge.py \
28 tsclient_menus.py \
29+ quicklists.py \
30 workrave_helper.py \
31 zeitgeist_menus.py \
32 zeitgeist_journal.py
33
34=== added file 'scripts/quicklists.py'
35--- scripts/quicklists.py 1970-01-01 00:00:00 +0000
36+++ scripts/quicklists.py 2011-06-28 14:19:52 +0000
37@@ -0,0 +1,105 @@
38+#!/usr/bin/env python
39+
40+#
41+# Copyright (C) 2010 Eugeny Pankov
42+#
43+# This program is free software: you can redistribute it and/or modify
44+# it under the terms of the GNU General Public License as published by
45+# the Free Software Foundation, either version 3 of the License, or
46+# (at your option) any later version.
47+#
48+# This program is distributed in the hope that it will be useful,
49+# but WITHOUT ANY WARRANTY; without even the implied warranty of
50+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
51+# GNU General Public License for more details.
52+#
53+# You should have received a copy of the GNU General Public License
54+# along with this program. If not, see <http://www.gnu.org/licenses/>.
55+
56+import atexit
57+import gobject
58+import glib
59+import gio
60+import locale
61+import sys
62+import os
63+import subprocess
64+from ConfigParser import ConfigParser
65+from signal import signal, SIGTERM
66+from sys import exit
67+
68+try:
69+ from dockmanager.dockmanager import DockManagerItem, DockManagerSink, DOCKITEM_IFACE
70+except ImportError, e:
71+ print e
72+ exit()
73+
74+desktop_cache = {}
75+
76+
77+class QuickListItem(DockManagerItem):
78+ def __init__(self, sink, name, path):
79+ global desktop_cache
80+ DockManagerItem.__init__(self, sink, path)
81+
82+ if name in desktop_cache:
83+ cfg = desktop_cache[name]
84+ else:
85+ cfg = ConfigParser()
86+ cfg.read(name)
87+ desktop_cache[name] = cfg
88+
89+ try:
90+ icon = cfg.get('Desktop Entry', 'Icon')
91+ except:
92+ icon = os.path.split(name)[1].split('.')[0]
93+
94+ self.items = {}
95+
96+ lc = locale.getdefaultlocale()[0]
97+ names = [
98+ 'Name[%s]'%lc,
99+ 'Name[%s]'%lc.split('_')[0],
100+ 'Name',
101+ ]
102+
103+ for section in cfg.sections():
104+ if section.endswith('Shortcut Group'):
105+ name = None
106+ for n in names:
107+ try:
108+ name = cfg.get(section, n)
109+ break
110+ except:
111+ pass
112+
113+ self.add_menu_item(
114+ name,
115+ icon,
116+ 'Quicklist',
117+ )
118+ self.items[name] = cfg.get(section, 'Exec')
119+
120+ def menu_pressed(self, menu_id):
121+ gio.AppInfo(self.items[self.id_map[menu_id]]).launch()
122+
123+
124+class QuickListSink(DockManagerSink):
125+ def item_path_found(self, pathtoitem, item):
126+ name = str(item.Get(DOCKITEM_IFACE, 'DesktopFile', dbus_interface='org.freedesktop.DBus.Properties'))
127+ if name:
128+ self.items[pathtoitem] = QuickListItem(self, name, pathtoitem)
129+
130+
131+sink = QuickListSink()
132+
133+def cleanup ():
134+ sink.dispose()
135+
136+if __name__ == '__main__':
137+ mainloop = gobject.MainLoop(is_running=True)
138+
139+ atexit.register (cleanup)
140+ signal(SIGTERM, lambda signum, stack_frame: exit(1))
141+
142+ mainloop.run()

Subscribers

People subscribed via source and target branches

to status/vote changes: