[gnome-clocks] application: turn us into a service
- From: Ryan Lortie <ryanl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-clocks] application: turn us into a service
- Date: Sun, 21 Apr 2013 23:34:10 +0000 (UTC)
commit abe5c227d3098e46b2a4b6a27eee37149f1f4c40
Author: Ryan Lortie <desrt desrt ca>
Date: Sun Apr 21 15:54:16 2013 -0400
application: turn us into a service
Start using GApplication 'service' mode for gnome-clocks. This allows
us to launch via D-Bus activation.
Provide a 'launcher' helper to install in /usr/bin so we can still be
started from the commandline.
https://bugzilla.gnome.org/show_bug.cgi?id=698525
Makefile.am | 20 ++++++++++++++---
src/application.vala | 33 +--------------------------
src/launcher.vala | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 81 insertions(+), 35 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 024993d..0b82e7e 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -9,6 +9,14 @@ SUBDIRS = libgd po
applicationsdir = $(datadir)/applications
applications_DATA = data/gnome-clocks.desktop
dist_noinst_DATA = data/gnome-clocks.desktop.in
+dbusservicedir = $(datadir)/dbus-1/services
+dbusservice_DATA = data/org.gnome.clocks.service
+
+data/org.gnome.clocks.service: Makefile
+ $(AM_V_GEN) (echo '[D-BUS Service]'; \
+ echo 'Name=org.gnome.clocks'; \
+ echo 'Exec=${libexecdir}/gnome-clocks-service') > $ tmp && \
+ mv $ tmp $@
# gsettings
gsettings_SCHEMAS = data/org.gnome.clocks.gschema.xml
@@ -91,6 +99,7 @@ AM_VALAFLAGS = \
--pkg libnotify \
--pkg gd-1.0
+libexec_PROGRAMS = gnome-clocks-service
bin_PROGRAMS = gnome-clocks
BUILT_SOURCES = \
@@ -111,7 +120,7 @@ VALA_SOURCES = \
src/widgets.vala \
src/main.vala
-gnome_clocks_SOURCES = \
+gnome_clocks_service_SOURCES = \
$(BUILT_SOURCES) \
$(VALA_SOURCES) \
src/cutils.c \
@@ -125,12 +134,17 @@ AM_CFLAGS = \
-Wno-unused-but-set-variable \
-Wno-unused-variable
-gnome_clocks_LDFLAGS = -export-dynamic
-gnome_clocks_LDADD = \
+gnome_clocks_service_LDFLAGS = -export-dynamic
+gnome_clocks_service_LDADD = \
$(top_builddir)/libgd/libgd.la \
$(CLOCKS_LIBS) \
-lm
+gnome_clocks_LDADD = $(CLOCKS_LIBS)
+gnome_clocks_SOURCES = \
+ src/launcher.vala \
+ src/config.vapi
+
EXTRA_DIST = \
$(icon_files) \
$(hcicon_files) \
diff --git a/src/application.vala b/src/application.vala
index 711e8cf..1d32200 100644
--- a/src/application.vala
+++ b/src/application.vala
@@ -19,12 +19,6 @@
namespace Clocks {
public class Application : Gtk.Application {
- static bool print_version;
- const OptionEntry[] option_entries = {
- { "version", 'v', 0, OptionArg.NONE, ref print_version, N_("Print version information and exit"),
null },
- { null }
- };
-
const GLib.ActionEntry[] action_entries = {
{ "quit", on_quit_activate }
};
@@ -32,7 +26,7 @@ public class Application : Gtk.Application {
private Window window;
public Application () {
- Object (application_id: "org.gnome.clocks");
+ Object (application_id: "org.gnome.clocks", flags: ApplicationFlags.IS_SERVICE);
add_action_entries (action_entries, this);
}
@@ -60,31 +54,6 @@ public class Application : Gtk.Application {
add_accelerator ("<Primary>a", "win.select-all", null);
}
- protected override bool local_command_line ([CCode (array_length = false, array_null_terminated = true)]
ref unowned string[] arguments, out int exit_status) {
- var ctx = new OptionContext ("");
-
- ctx.add_main_entries (option_entries, Config.GETTEXT_PACKAGE);
- ctx.add_group (Gtk.get_option_group (true));
-
- // Workaround for bug #642885
- unowned string[] argv = arguments;
-
- try {
- ctx.parse (ref argv);
- } catch (Error e) {
- exit_status = 1;
- return true;
- }
-
- if (print_version) {
- print ("%s %s\n", Environment.get_application_name (), Config.VERSION);
- exit_status = 0;
- return true;
- }
-
- return base.local_command_line (ref arguments, out exit_status);
- }
-
void on_quit_activate () {
quit ();
}
diff --git a/src/launcher.vala b/src/launcher.vala
new file mode 100644
index 0000000..ef57bf5
--- /dev/null
+++ b/src/launcher.vala
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2013 Paolo Borelli <pborelli gnome org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+class Application : Gtk.Application {
+ static bool print_version;
+ const OptionEntry[] option_entries = {
+ { "version", 'v', 0, OptionArg.NONE, ref print_version, N_("Print version information and exit"),
null },
+ { null }
+ };
+
+ public Application () {
+ Object (application_id: "org.gnome.clocks", flags: ApplicationFlags.IS_LAUNCHER);
+ }
+
+ protected override bool local_command_line ([CCode (array_length = false, array_null_terminated = true)]
ref unowned string[] arguments, out int exit_status) {
+ var ctx = new OptionContext ("");
+
+ ctx.add_main_entries (option_entries, Config.GETTEXT_PACKAGE);
+ ctx.add_group (Gtk.get_option_group (true));
+
+ // Workaround for bug #642885
+ unowned string[] argv = arguments;
+
+ try {
+ ctx.parse (ref argv);
+ } catch (Error e) {
+ exit_status = 1;
+ return true;
+ }
+
+ if (print_version) {
+ print ("%s %s\n", Environment.get_application_name (), Config.VERSION);
+ exit_status = 0;
+ return true;
+ }
+
+ return base.local_command_line (ref arguments, out exit_status);
+ }
+}
+
+int main (string[] args) {
+ Intl.bindtextdomain (Config.GETTEXT_PACKAGE, Config.GNOMELOCALEDIR);
+ Intl.bind_textdomain_codeset (Config.GETTEXT_PACKAGE, "UTF-8");
+ Intl.textdomain (Config.GETTEXT_PACKAGE);
+
+ var app = new Application ();
+ return app.run (args);
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]