From 466a7da039606a3079867ff2c583027d914a869f Mon Sep 17 00:00:00 2001 From: Ricardo Band Date: Wed, 25 Feb 2015 02:33:17 +0100 Subject: [PATCH 1/5] Just a little polish for that dusty ugly code --- quickedit | 52 +++++++++++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/quickedit b/quickedit index c75e685..38e0d89 100755 --- a/quickedit +++ b/quickedit @@ -1,7 +1,5 @@ -#!/usr/bin/python +#!/usr/bin/env python2 # -*- coding: utf-8 -*- -# -# me@xengi.de 2012-04-25 """ You can use QuickEdit to change the Quick-launch icons on the bottom when @@ -10,15 +8,17 @@ 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 +import os +import errno +import fileinput -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) @@ -39,11 +39,12 @@ class AppWrapper(QtCore.QObject): icon = QtCore.Property(unicode, _icon, notify=changed) isQL = QtCore.Property(unicode, _isQL, notify=changed) + class AppListModel(QtCore.QAbstractListModel): - COLUMNS = ('app',) + COLUMNS = ('app', ) def __init__(self, apps): - QtCore.QAbstractListModel.__init__(self) + super(QtCore.QAbstractListModel, self).__init__() self._apps = apps self.setRoleNames(dict(enumerate(AppListModel.COLUMNS))) @@ -55,6 +56,7 @@ class AppListModel(QtCore.QAbstractListModel): return self._apps[index.row()] return None + class Controller(QtCore.QObject): @QtCore.Slot(QtCore.QObject) def appSelected(self, wrapper): @@ -66,23 +68,24 @@ class Controller(QtCore.QObject): rc = view.rootContext() rc.setContextProperty('quickListModel', AppListModel(updateQuickLaunch())) qlSelected = wrapper._app.desktopfile[51:52] - print "quicklaunch pressed", wrapper._app.desktopfile[51:52] + # print "quicklaunch pressed", wrapper._app.desktopfile[51:52] else: - print "app pressed", wrapper._app.name + # 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" + # 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" + # 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 @@ -93,6 +96,7 @@ class App(object): def __str__(self): return self.name + def repairQuickLaunch(quickdirlist): global rebootNeeded @@ -106,7 +110,7 @@ def repairQuickLaunch(quickdirlist): if e.errno == errno.EEXIST: os.remove(filename) os.symlink("/usr/share/applications/browser.desktop", filename) - print "Broken quick-launch symlink fixed!" + # print "Broken quick-launch symlink fixed!" # check if an app of the quicklaunch was uninstalled and fix it reboot = False @@ -120,6 +124,7 @@ def repairQuickLaunch(quickdirlist): print "You need to reboot to repair your quick-launch." rebootNeeded = 1 + def updateQuickLaunch(): quicklist = [] quickdirlist = ["/home/user/.local/share/applications/quicklaunchbar0.desktop", @@ -136,7 +141,7 @@ def updateQuickLaunch(): appicon = "" for line in lines: line = line.rstrip() - if ( line.startswith("Name=") ) and ( appname == "" ): + if line.startswith("Name=") and appname == "": appname = line[5:] if line.startswith("Icon="): if "/" in line: @@ -147,11 +152,12 @@ def updateQuickLaunch(): 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 != "" ): + 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() @@ -163,15 +169,15 @@ if __name__ == "__main__": 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) + if filename.endswith(".desktop") and not os.path.islink(os.path.join(path, filename)): + f = file(os.path.join(path, filename)) lines = f.readlines() appname = "" appicon = "" show = True for line in lines: line = line.rstrip() - if ( line.startswith("Name=") ) and ( appname == "" ): + if line.startswith("Name=") and appname == "": appname = line[5:] if line.startswith("Icon="): if "/" in line: @@ -184,21 +190,21 @@ if __name__ == "__main__": appicon = "/usr/share/icons/hicolor/64x64/apps/" + line[5:] + ".png" if line.startswith("NotShowIn=X-MeeGo"): show = False - if ( appname != "" ) and ( appicon != "" ) and show: + 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) + if not os.path.islink(os.path.join(path, filename)): + f = file(os.path.join(path, filename)) lines = f.readlines() appname = "" appicon = "" show = True for line in lines: line = line.rstrip() - if ( line.startswith("Name=") ) and ( appname == "" ): + if line.startswith("Name=") and appname == "": appname = line[5:] if line.startswith("Icon="): if "/" in line: @@ -211,7 +217,7 @@ if __name__ == "__main__": appicon = "/usr/share/icons/hicolor/64x64/apps/" + line[5:] + ".png" if line.startswith("NotShowIn=X-MeeGo"): show = False - if ( appname != "" ) and ( appicon != "" ) and show: + if appname != "" and appicon != "" and show: applist.append(App(appname, appicon, "0", path + filename)) apps = [AppWrapper(app) for app in applist] From a576f9a9315f3937774b85df69116006b3ef40bb Mon Sep 17 00:00:00 2001 From: Ricardo Band Date: Wed, 25 Feb 2015 02:35:54 +0100 Subject: [PATCH 2/5] email address updated --- quickedit.psa | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quickedit.psa b/quickedit.psa index a3d9d11..b7cb13d 100644 --- a/quickedit.psa +++ b/quickedit.psa @@ -6,6 +6,6 @@ section = system pyversion = 2.6 project = quickedit template = harmattan -email = quickedit@xengi.de +email = email@ricardo.band desc = Change your Quick-launch icons easily. From 26b1a5b844e8aaffe4b95715360ceeffea31b3c1 Mon Sep 17 00:00:00 2001 From: Ricardo Band Date: Wed, 25 Feb 2015 02:36:36 +0100 Subject: [PATCH 3/5] email address updated --- setup.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 102ce12..ad22bd0 100644 --- a/setup.py +++ b/setup.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- + from distutils.core import setup import os, sys, glob @@ -8,7 +10,7 @@ def read(fname): scripts=['quickedit'], version='0.99.9', maintainer="Ricardo Band", - maintainer_email="quickedit@xengi.de", + maintainer_email="email@ricardo.band", description="Change your Quick-launch icons easily.", long_description=read('quickedit.longdesc'), data_files=[('share/applications',['quickedit.desktop']), From 419d571f106acbc009db2d05275b8673befd2c3b Mon Sep 17 00:00:00 2001 From: Ricardo Band Date: Wed, 25 Feb 2015 02:39:59 +0100 Subject: [PATCH 4/5] licence file added --- setup.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index ad22bd0..1a00b47 100644 --- a/setup.py +++ b/setup.py @@ -15,4 +15,5 @@ def read(fname): long_description=read('quickedit.longdesc'), data_files=[('share/applications',['quickedit.desktop']), ('share/icons/hicolor/64x64/apps', ['quickedit.png']), - ('/opt/quickedit/qml', glob.glob('qml/*.qml')), ],) + ('/opt/quickedit/qml', glob.glob('qml/*.qml')), + ('', ['LICENSE']), ], ) From df66894ff66bfb3c20376e723fee49de270a4cb3 Mon Sep 17 00:00:00 2001 From: Ricardo Band Date: Wed, 25 Feb 2015 02:41:15 +0100 Subject: [PATCH 5/5] Create LICENCE --- LICENCE | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 LICENCE diff --git a/LICENCE b/LICENCE new file mode 100644 index 0000000..39164d2 --- /dev/null +++ b/LICENCE @@ -0,0 +1,19 @@ +Copyright (c) 2015 Ricardo (XenGi) Band + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE.