← Back to team overview

gtg team mailing list archive

[Merge] lp:~gtg-user/gtg/uri-support into lp:gtg

 

Luca Invernizzi has proposed merging lp:~gtg-user/gtg/uri-support into lp:gtg.

Requested reviews:
  Gtg developers (gtg)


GTG support for URIs of the format gtg://<gtg-task-id>
These URIs are useful for putting tasks links in other programs (e.g, in a tomboy note).
I'm currently using it in the Zeitgeist backend, to let the tasks registered in Zeitgeist and shown through the Activity Journal to be clickable.

On every start, GTG checks if GNOME knows about this kind of URI and, if not, puts itself as an application capable of handling those. Therefore, you can use
xdg-open gtg://<gtg-task-id>.

Tomboy has the same kind of feature through a note:// URI.
-- 
https://code.launchpad.net/~gtg-user/gtg/uri-support/+merge/32643
Your team Gtg developers is requested to review the proposed merge of lp:~gtg-user/gtg/uri-support into lp:gtg.
=== modified file 'CHANGELOG'
--- CHANGELOG	2010-08-04 00:30:22 +0000
+++ CHANGELOG	2010-08-13 23:44:57 +0000
@@ -4,6 +4,7 @@
     * Fixed bug with data consistency #579189, by Marko Kevac
     * Added samba bugzilla to the bugzilla plugin, by Jelmer Vernoij
     * Fixed bug #532392, a start date is later than a due date, by Volodymyr Floreskul
+    * support for gtg:// URIs by Luca Invernizzi
 
 2010-03-01 Getting Things GNOME! 0.2.2
     * Autostart on login, by Luca Invernizzi

=== modified file 'GTG/__init__.py'
--- GTG/__init__.py	2010-03-12 11:16:15 +0000
+++ GTG/__init__.py	2010-08-13 23:44:57 +0000
@@ -92,3 +92,13 @@
 
 if os.path.isdir(os.path.join(config_home, 'gtg/plugins')):
     PLUGIN_DIR.append(os.path.join(config_home, 'gtg/plugins'))
+
+#Register GTG URI (temporary, it should be created by a schema upon installing)
+import gconf
+domain = "/desktop/gnome/url-handlers/gtg/"
+client = gconf.client_get_default()
+#this should work both in debugging mode and in deployed mode
+client.set_string(os.path.join(domain, "command"), "gtg %s")
+client.set_bool(os.path.join(domain, "enabled"), True)
+client.set_bool(os.path.join(domain, "needs_terminal"), False)
+

=== modified file 'GTG/gtg.py'
--- GTG/gtg.py	2010-08-03 17:07:31 +0000
+++ GTG/gtg.py	2010-08-13 23:44:57 +0000
@@ -46,8 +46,8 @@
 
 #=== IMPORT ===================================================================
 import os
+import sys
 import logging
-
 import dbus
 
 #our own imports
@@ -55,7 +55,7 @@
 from GTG                import _
 from GTG.core           import CoreConfig
 from GTG.core.datastore import DataStore
-#from GTG.gtk.crashhandler import signal_catcher
+from GTG.gtk.crashhandler import signal_catcher
 from GTG.gtk.manager    import Manager
 from GTG.tools.logger   import Log
 
@@ -66,8 +66,11 @@
 #that's why we put the pid file in the data directory :
 #we allow one instance of gtg by data directory.
 
-def check_instance(directory):
-    """Check if gtg is already running."""
+def check_instance(directory, uri_list = []):
+    """
+    Check if gtg is already running.
+    If so, open the tasks whose ids are in the uri_list
+    """
     pidfile = os.path.join(directory, "gtg.pid")
     if not os.path.exists(pidfile):
         open(pidfile, "w").close()
@@ -83,6 +86,10 @@
             d=dbus.SessionBus().get_object(CoreConfig.BUSNAME,\
                                            CoreConfig.BUSINTERFACE)
             d.show_task_browser()
+            #if the user has specified a task to open, do that
+            for uri in uri_list:
+                if uri.startswith("gtg://"):
+                    d.open_task_editor(uri[6:])
             raise SystemExit
             
     #write the pid file
@@ -102,10 +109,10 @@
     #To be more user friendly and get the logs of crashes, we show an apport
     # hooked window upon crashes
     if options.no_crash_handler == False:
-        #FIXME: Why is this disabled?  Please comment when disabling functionality so we know. :-)
-        #with signal_catcher(manager.close_browser):
-        pass
-    manager.main(once_thru=options.boot_test)
+        with signal_catcher(manager.close_browser):
+            manager.main(once_thru=options.boot_test, uri_list = args)
+    else:
+        manager.main(once_thru=options.boot_test, uri_list = args)
     core_main_quit(config, ds)
 
 def core_main_init(options = None, args = None):
@@ -116,10 +123,11 @@
     if options.debug:
         Log.setLevel(logging.DEBUG)
         Log.debug("Debug output enabled.")
-        Log.set_debugging_mode(True)
-
+    else:
+        Log.setLevel(logging.INFO)
+    Log.set_debugging_mode(options.debug)
     config = CoreConfig()
-    check_instance(config.get_data_dir())
+    check_instance(config.get_data_dir(), args)
     backends_list = BackendFactory().get_saved_backends_list()
     # Load data store
     ds = DataStore()
@@ -145,6 +153,8 @@
     # Ending the application: we save configuration
     config.save()
     ds.save(quit = True)
+    sys.exit(0)
+
 
 #=== EXECUTION ================================================================
 

=== modified file 'GTG/gtk/browser/browser.py'
--- GTG/gtk/browser/browser.py	2010-08-10 17:30:24 +0000
+++ GTG/gtk/browser/browser.py	2010-08-13 23:44:57 +0000
@@ -953,7 +953,9 @@
                     text = \
                         text.replace("%s%s:%s" % (spaces, attribute, args), "")
             # Create the new task
-            task = self.req.new_task(tags=[t.get_name() for t in tags], newtask=True)
+            task = self.req.new_task( newtask=True)
+            for tag in tags:
+                task.add_tag(tag.get_name())
             if text != "":
                 task.set_title(text.strip())
                 task.set_to_keep()

=== modified file 'GTG/gtk/manager.py'
--- GTG/gtk/manager.py	2010-08-03 17:07:31 +0000
+++ GTG/gtk/manager.py	2010-08-13 23:44:57 +0000
@@ -211,7 +211,11 @@
                     self.close_task(t)
             
 ### MAIN ###################################################################
-    def main(self, once_thru=False):
+
+    def main(self, once_thru = False,  uri_list = []):
+        for uri in uri_list:
+            if uri.startswith("gtg://"):
+                self.open_task(uri[6:])
         gobject.threads_init()
         if once_thru:
             gtk.main_iteration()


Follow ups