diff --git a/chrome/newtask.py b/chrome/newtask.py index 3505988..40099ce 100755 --- a/chrome/newtask.py +++ b/chrome/newtask.py @@ -19,6 +19,34 @@ import dbus import sys +class GTG: + """ Unified interface to different versions of GTG D-Bus """ + + def __init__(self): + try: + self.version = "0.2.9" + bus = dbus.SessionBus() + gtg_obj = bus.get_object('org.gnome.GTG', '/org/gnome/GTG') + self.gtg = dbus.Interface(gtg_obj, 'org.gnome.GTG') + except dbus.exceptions.DBusException, e: + # Use older version + self.version = "0.2.4" + bus = dbus.SessionBus() + gtg_obj = bus.get_object('org.GTG', '/org/GTG') + self.gtg = dbus.Interface(gtg_obj, 'org.GTG') + + def new_task(self, title, message): + if self.version == "0.2.9": + return self.gtg.NewTask('Active', title, '', '', '', [], message, []) + else: + return self.gtg.new_task('Active', title, '', '', '', [], message, []) + + def open_task(self, task_id): + if self.version == "0.2.9": + return self.gtg.OpenTaskEditor(task_id) + else: + return self.gtg.open_task_editor(task_id) + def show_notification(title, message): try: import pynotify @@ -45,11 +73,14 @@ def show_notification(title, message): title = sys.argv[1] message = "\n".join(sys.argv[2:]) - bus = dbus.SessionBus() - gtg_obj = bus.get_object('org.gnome.GTG', '/org/gnome/GTG') - gtg = dbus.Interface(gtg_obj, 'org.gnome.GTG') + try: + gtg = GTG() + except dbus.exceptions.DBusException, e: + show_notification("Failed to find GTG", "There is no D-Bus interface for GTG") + print "D-Bus exception:", e + sys.exit(1) - task = gtg.NewTask('Active', title, '', '', '', [], message, []) + task = gtg.new_task(title, message) # if notification fails, open the task if force_editor or not show_notification("New GTG task added", title): - gtg.OpenTaskEditor(task['id']) + gtg.open_task(task['id']) diff --git a/install.rdf b/install.rdf index 97b667a..cd87406 100644 --- a/install.rdf +++ b/install.rdf @@ -5,11 +5,11 @@ about="urn:mozilla:install-manifest" em:name="GTG Task Button" - em:description="Easily transform a page into a GTG task with one click" + em:description="Easily transform a page into a task for Getting Things GNOME! with a single click." em:creator="Izidor Matušov" em:id="gtg@fritalk.com" - em:version="1.0" + em:version="1.1" em:homepageURL="http://gtg.fritalk.com" em:iconURL="chrome://gtgtask/content/icon.png" > diff --git a/package.sh b/package.sh index cbeef8a..c598b90 100755 --- a/package.sh +++ b/package.sh @@ -8,4 +8,5 @@ # # Created by Izidor Matušov +rm -f ../gtgtask.xpi zip -r9 ../gtgtask.xpi chrome/ chrome.manifest defaults/ install.rdf