diff --git a/.gitignore b/.gitignore
index fd910838b..5f714f959 100644
--- a/.gitignore
+++ b/.gitignore
@@ -24,7 +24,6 @@ autom4te.cache
m4
gnome-doc-utils.make
hamster-time-tracker-*.tar.gz
-org.gnome.hamster.service
.lock-wscript
.lock-waf*
build
diff --git a/data/hamster.metainfo.xml b/data/hamster.metainfo.xml
index 9667aa0f4..9f24402c3 100644
--- a/data/hamster.metainfo.xml
+++ b/data/hamster.metainfo.xml
@@ -27,7 +27,7 @@
- hamster.desktop
+ org.gnome.Hamster.GUI.desktop
diff --git a/data/hamster.desktop.in b/data/org.gnome.Hamster.GUI.desktop.in
similarity index 50%
rename from data/hamster.desktop.in
rename to data/org.gnome.Hamster.GUI.desktop.in
index 78fc314af..29ea925d4 100644
--- a/data/hamster.desktop.in
+++ b/data/org.gnome.Hamster.GUI.desktop.in
@@ -5,5 +5,15 @@ Terminal=false
Name=Hamster
Comment=Your personal time keeping tool
Icon=hamster
+DBusActivatable=true
Exec=@BINDIR@/hamster
Categories=GNOME;GTK;Utility;
+Actions=overview;add;
+
+[Desktop Action overview]
+Exec= @BINDIR@/hamster overview
+Name=overview
+
+[Desktop Action add]
+Exec= @BINDIR@/hamster add
+Name=add
diff --git a/data/wscript_build b/data/wscript_build
index a2b0afcf6..46c6d48c0 100644
--- a/data/wscript_build
+++ b/data/wscript_build
@@ -15,7 +15,7 @@ bld.install_files('${DATADIR}/icons/hicolor/scalable/apps','art/scalable/hamster
bld.install_files('${DATADIR}/metainfo', 'hamster.metainfo.xml')
-for filename in ["hamster.desktop"]:
+for filename in ["org.gnome.Hamster.GUI.desktop"]:
bld(features = "subst",
source= "%s.in" % filename,
target= "%s" % filename,
diff --git a/org.gnome.Hamster.GUI.service.in b/org.gnome.Hamster.GUI.service.in
new file mode 100644
index 000000000..ddb9e21db
--- /dev/null
+++ b/org.gnome.Hamster.GUI.service.in
@@ -0,0 +1,3 @@
+[D-BUS Service]
+Name=org.gnome.Hamster.GUI
+Exec=@BINDIR@/hamster --gapplication-service
diff --git a/org.gnome.hamster.Windows.service.in b/org.gnome.Hamster.WindowServer.service.in
similarity index 100%
rename from org.gnome.hamster.Windows.service.in
rename to org.gnome.Hamster.WindowServer.service.in
diff --git a/org.gnome.hamster.service.in b/org.gnome.Hamster.service.in
similarity index 100%
rename from org.gnome.hamster.service.in
rename to org.gnome.Hamster.service.in
diff --git a/po/POTFILES.in b/po/POTFILES.in
index d2a97e337..beba40947 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -3,7 +3,7 @@
data/date_range.ui
data/edit_activity.ui
data/preferences.ui
-data/hamster.desktop.in
+data/org.gnome.Hamster.GUI.desktop.in
data/org.gnome.hamster.gschema.xml
src/hamster-cli.py
src/hamster/about.py
diff --git a/po/POTFILES.skip b/po/POTFILES.skip
index 921bfdc8e..567609b12 100644
--- a/po/POTFILES.skip
+++ b/po/POTFILES.skip
@@ -1,2 +1 @@
-data/hamster.desktop.in
build/
diff --git a/src/hamster-cli.py b/src/hamster-cli.py
index af75d53b0..e6d71537d 100644
--- a/src/hamster-cli.py
+++ b/src/hamster-cli.py
@@ -92,18 +92,23 @@ def fact_dict(fact_data, with_date):
class Hamster(gtk.Application):
+ """Hamster gui.
+
+ Can be accessed across D-Bus with the 'org.gnome.Hamster.GUI' id.
+ """
+
def __init__(self):
# inactivity_timeout: How long (ms) the service should stay alive
# after all windows have been closed.
gtk.Application.__init__(self,
- application_id="org.gnome.Hamster.WindowServer",
+ application_id="org.gnome.Hamster.GUI",
#inactivity_timeout=10000,
register_session=True)
self.about_controller = None # 'about' window controller
self.add_controller = None # "add activity" window controller
self.overview_controller = None # overview window controller
- self.prefs_controller = None # settings window controller
+ self.preferences_controller = None # settings window controller
self.connect("startup", self.on_startup)
self.connect("activate", self.on_activate)
@@ -114,7 +119,7 @@ def __init__(self):
self.add_actions()
def add_actions(self):
- for name in ("about", "add", "overview", "prefs"):
+ for name in ("about", "add", "overview", "preferences"):
action = gio.SimpleAction.new(name, None)
action.connect("activate", self.on_activate_window)
self.add_action(action)
@@ -158,11 +163,11 @@ def _open_window(self, name, data=None):
self.overview_controller = Overview()
logger.debug("new Overview")
controller = self.overview_controller
- elif name == "prefs":
- if not self.prefs_controller:
- self.prefs_controller = PreferencesEditor()
+ elif name == "preferences":
+ if not self.preferences_controller:
+ self.preferences_controller = PreferencesEditor()
logger.debug("new PreferencesEditor")
- controller = self.prefs_controller
+ controller = self.preferences_controller
window = controller.window
if window not in self.get_windows():
@@ -376,7 +381,7 @@ def version(self):
* activities: List all the activities names, one per line.
* categories: List all the categories names, one per line.
- * overview / prefs / add / about: launch specific window
+ * overview / preferences / add / about: launch specific window
* version: Show the Hamster version
@@ -430,10 +435,13 @@ def version(self):
if args.action in ("start", "track"):
action = "add" # alias
+ elif args.action == "prefs":
+ # for backward compatibility
+ action = "preferences"
else:
action = args.action
- if action in ("about", "add", "overview", "prefs"):
+ if action in ("about", "add", "overview", "preferences"):
if action == "add" and args.action_args:
assert not unknown_args, "unknown options: {}".format(unknown_args)
# directly add fact from arguments
@@ -443,8 +451,9 @@ def version(self):
else:
app.register()
app.activate_action(action)
- logger.debug("run")
- status = app.run([sys.argv[0]] + unknown_args)
+ run_args = [sys.argv[0]] + unknown_args
+ logger.debug("run {}".format(run_args))
+ status = app.run(run_args)
logger.debug("app exited")
sys.exit(status)
elif hasattr(hamster_client, action):
diff --git a/src/hamster-windows-service.py b/src/hamster-windows-service.py
index ec1a82ae1..7954213a6 100644
--- a/src/hamster-windows-service.py
+++ b/src/hamster-windows-service.py
@@ -1,9 +1,12 @@
#!/usr/bin/env python3
# nicked off hamster-service
-from gi.repository import GLib as glib
-import dbus, dbus.service
+import dbus
+import dbus.service
+import subprocess
+
from dbus.mainloop.glib import DBusGMainLoop
+from gi.repository import GLib as glib
DBusGMainLoop(set_as_default=True)
loop = glib.MainLoop()
@@ -13,7 +16,12 @@
quit()
-# maintain just one instance. this code feels hackish again
+# Legacy server. Still used by the shell-extension.
+# new code could access the org.gnome.Hamster.GUI actions directly
+# http://lazka.github.io/pgi-docs/Gio-2.0/classes/Application.html#Gio.Application
+# > The actions are also exported on the session bus,
+# and GIO provides the Gio.DBusActionGroup wrapper
+# to conveniently access them remotely.
class WindowServer(dbus.service.Object):
__dbus_object_path__ = "/org/gnome/Hamster/WindowServer"
@@ -29,24 +37,21 @@ def Quit(self):
"""Shutdown the service"""
self.mainloop.quit()
-
- @dbus.service.method("org.gnome.Hamster.WindowServer")
- def edit(self, id=None):
- dialogs.edit.show(self.app, fact_id = id)
+ def _open_window(self, name):
+ subprocess.run("hamster {} &".format(name),
+ shell=True)
@dbus.service.method("org.gnome.Hamster.WindowServer")
def overview(self):
- dialogs.overview.show(self.app)
+ self._open_window("overview")
@dbus.service.method("org.gnome.Hamster.WindowServer")
def about(self):
- dialogs.about.show(self.app)
+ self._open_window("about")
@dbus.service.method("org.gnome.Hamster.WindowServer")
def preferences(self):
- dialogs.prefs.show(self.app)
-
-
+ self._open_window("prefs")
if __name__ == '__main__':
diff --git a/wscript b/wscript
index c39d4655d..f0be657f0 100644
--- a/wscript
+++ b/wscript
@@ -66,14 +66,20 @@ def build(bld):
)
bld(features="subst",
- source= "org.gnome.hamster.service.in",
- target= "org.gnome.hamster.service",
+ source= "org.gnome.Hamster.service.in",
+ target= "org.gnome.Hamster.service",
install_path="${DATADIR}/dbus-1/services",
)
bld(features="subst",
- source= "org.gnome.hamster.Windows.service.in",
- target= "org.gnome.hamster.Windows.service",
+ source= "org.gnome.Hamster.GUI.service.in",
+ target= "org.gnome.Hamster.GUI.service",
+ install_path="${DATADIR}/dbus-1/services",
+ )
+
+ bld(features="subst",
+ source= "org.gnome.Hamster.WindowServer.service.in",
+ target= "org.gnome.Hamster.WindowServer.service",
install_path="${DATADIR}/dbus-1/services",
)