-
Notifications
You must be signed in to change notification settings - Fork 2
/
quickedit
executable file
·239 lines (205 loc) · 9.14 KB
/
quickedit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# [email protected] 2012-04-25
"""
You can use QuickEdit to change the Quick-launch icons on the bottom when
you swipe half the way up the screen from any app. Just start the app, click on
the Quick-launch icon you want to change and then on the new app. That's all!
Further information: http://xengi.de/quickedit
"""
__usage__ = "usage: %prog [--help]"
__version__ = "toggle [xengi.de 2012-04-25]"
import sys,os,errno,fileinput
from PySide import QtCore
from PySide import QtGui
from PySide import QtDeclarative
from PySide import QtOpenGL
class AppWrapper(QtCore.QObject):
def __init__(self, app):
QtCore.QObject.__init__(self)
self._app = app
def _name(self):
return str(self._app.name)
def _icon(self):
return str(self._app.icon)
def _isQL(self):
return str(self._app.isQL)
changed = QtCore.Signal()
name = QtCore.Property(unicode, _name, notify=changed)
icon = QtCore.Property(unicode, _icon, notify=changed)
isQL = QtCore.Property(unicode, _isQL, notify=changed)
class AppListModel(QtCore.QAbstractListModel):
COLUMNS = ('app',)
def __init__(self, apps):
QtCore.QAbstractListModel.__init__(self)
self._apps = apps
self.setRoleNames(dict(enumerate(AppListModel.COLUMNS)))
def rowCount(self, parent=QtCore.QModelIndex()):
return len(self._apps)
def data(self, index, role):
if index.isValid() and role == AppListModel.COLUMNS.index('app'):
return self._apps[index.row()]
return None
class Controller(QtCore.QObject):
@QtCore.Slot(QtCore.QObject)
def appSelected(self, wrapper):
global qlSelected
global view
global quickList
if "quicklaunch" in wrapper._app.desktopfile:
if qlSelected > -1:
rc = view.rootContext()
rc.setContextProperty('quickListModel', AppListModel(updateQuickLaunch()))
qlSelected = wrapper._app.desktopfile[51:52]
print "quicklaunch pressed", wrapper._app.desktopfile[51:52]
else:
print "app pressed", wrapper._app.name
if qlSelected > -1:
try:
os.symlink(wrapper._app.desktopfile, "/home/user/.local/share/applications/quicklaunchbar" + qlSelected + ".desktop")
print "quick-launch", qlSelected, "updated"
except OSError, e:
if e.errno == errno.EEXIST:
os.remove("/home/user/.local/share/applications/quicklaunchbar" + qlSelected + ".desktop")
os.symlink(wrapper._app.desktopfile, "/home/user/.local/share/applications/quicklaunchbar" + qlSelected + ".desktop")
print "quick-launch", qlSelected, "force updated"
qlSelected = -1
# update quick launch
rc = view.rootContext()
rc.setContextProperty('quickListModel', AppListModel(updateQuickLaunch()))
class App(object):
def __init__(self, name, icon, isQL, desktopfile):
self.name = name
self.icon = icon
self.isQL = isQL
self.desktopfile = desktopfile
def __str__(self):
return self.name
def repairQuickLaunch(quickdirlist):
global rebootNeeded
# check if quick-launch links are broken
for filename in quickdirlist:
if not os.path.exists(os.readlink(filename)):
# replace broken links with standard browser
try:
os.symlink("/usr/share/applications/browser.desktop", filename)
except OSError, e:
if e.errno == errno.EEXIST:
os.remove(filename)
os.symlink("/usr/share/applications/browser.desktop", filename)
print "Broken quick-launch symlink fixed!"
# check if an app of the quicklaunch was uninstalled and fix it
reboot = False
for line in fileinput.input("/home/user/.config/meegotouchhome-nokia/launcherbuttons.data", inplace=1):
if line.startswith("home\\user\\.local\\share\\applications\\quicklaunchbar"):
if not line.endswith('=quicklaunchbar/' + line[50:51] + "\n"):
line = line.replace(line, line[:60] + "quicklaunchbar/" + line[50:51] + "\n")
reboot = True
sys.stdout.write(line)
if reboot:
print "You need to reboot to repair your quick-launch."
rebootNeeded = 1
def updateQuickLaunch():
quicklist = []
quickdirlist = ["/home/user/.local/share/applications/quicklaunchbar0.desktop",
"/home/user/.local/share/applications/quicklaunchbar1.desktop",
"/home/user/.local/share/applications/quicklaunchbar2.desktop",
"/home/user/.local/share/applications/quicklaunchbar3.desktop"]
repairQuickLaunch(quickdirlist)
for filename in quickdirlist:
f = file(filename)
lines = f.readlines()
appname = ""
appicon = ""
for line in lines:
line = line.rstrip()
if ( line.startswith("Name=") ) and ( appname == "" ):
appname = line[5:]
if line.startswith("Icon="):
if "/" in line:
appicon = line[5:]
else:
appicon = "/usr/share/themes/blanco/meegotouch/icons/" + line[5:] + ".png"
if not os.path.isfile(appicon):
appicon = "/usr/share/themes/base/meegotouch/icons/" + line[5:] + ".svg"
if not os.path.isfile(appicon):
appicon = "/usr/share/icons/hicolor/64x64/apps/" + line[5:] + ".png"
if ( appname != "" ) and ( appicon != "" ):
quicklist.append(App(appname, appicon, "1", filename))
return [AppWrapper(app) for app in quicklist]
if __name__ == "__main__":
qapp = QtGui.QApplication(sys.argv)
view = QtDeclarative.QDeclarativeView()
glw = QtOpenGL.QGLWidget()
view.setViewport(glw)
applist = []
path = "/usr/share/applications/"
dirList = os.listdir(path)
for filename in dirList:
if ( filename.endswith(".desktop") ) and ( not os.path.islink(path + filename) ):
f = file(path + filename)
lines = f.readlines()
appname = ""
appicon = ""
show = True
for line in lines:
line = line.rstrip()
if ( line.startswith("Name=") ) and ( appname == "" ):
appname = line[5:]
if line.startswith("Icon="):
if "/" in line:
appicon = line[5:]
else:
appicon = "/usr/share/themes/blanco/meegotouch/icons/" + line[5:] + ".png"
if not os.path.isfile(appicon):
appicon = "/usr/share/themes/base/meegotouch/icons/" + line[5:] + ".svg"
if not os.path.isfile(appicon):
appicon = "/usr/share/icons/hicolor/64x64/apps/" + line[5:] + ".png"
if line.startswith("NotShowIn=X-MeeGo"):
show = False
if ( appname != "" ) and ( appicon != "" ) and show:
applist.append(App(appname, appicon, "0", path + filename))
path = "/var/lib/apt-desktop/entries/"
dirList = os.listdir(path)
for filename in dirList:
if not os.path.islink(path + filename):
f = file(path + filename)
lines = f.readlines()
appname = ""
appicon = ""
show = True
for line in lines:
line = line.rstrip()
if ( line.startswith("Name=") ) and ( appname == "" ):
appname = line[5:]
if line.startswith("Icon="):
if "/" in line:
appicon = line[5:]
else:
appicon = "/usr/share/themes/blanco/meegotouch/icons/" + line[5:] + ".png"
if not os.path.isfile(appicon):
appicon = "/usr/share/themes/base/meegotouch/icons/" + line[5:] + ".svg"
if not os.path.isfile(appicon):
appicon = "/usr/share/icons/hicolor/64x64/apps/" + line[5:] + ".png"
if line.startswith("NotShowIn=X-MeeGo"):
show = False
if ( appname != "" ) and ( appicon != "" ) and show:
applist.append(App(appname, appicon, "0", path + filename))
apps = [AppWrapper(app) for app in applist]
rebootNeeded = 0
controller = Controller()
appList = AppListModel(apps)
quickList = AppListModel(updateQuickLaunch())
qlSelected = -1
rc = view.rootContext()
rc.setContextProperty('controller', controller)
rc.setContextProperty('appListModel', appList)
rc.setContextProperty('quickListModel', quickList)
rc.setContextProperty('rebootneeded', rebootNeeded);
if os.path.exists('/opt/quickedit/qml/'):
view.setSource('/opt/quickedit/qml/main.qml')
else:
view.setSource(os.path.join('qml','main.qml'))
view.showFullScreen()
qapp.exec_()