summaryrefslogtreecommitdiff
path: root/src/deamon.vala
diff options
context:
space:
mode:
Diffstat (limited to 'src/deamon.vala')
-rw-r--r--src/deamon.vala143
1 files changed, 66 insertions, 77 deletions
diff --git a/src/deamon.vala b/src/deamon.vala
index fb9618b..2e79d10 100644
--- a/src/deamon.vala
+++ b/src/deamon.vala
@@ -36,15 +36,12 @@ public class Deamon : GLib.Object {
/////////////////////////////////////////////////////////////////////
public static int main(string[] args) {
- version = "0.5.6";
+ version = "0.5.7";
Logger.init();
- Gdk.threads_init();
Gtk.init(ref args);
Paths.init();
- message("Welcome to Gnome-Pie " + version + "!");
-
// create the Deamon and run it
var deamon = new GnomePie.Deamon();
deamon.run(args);
@@ -83,95 +80,51 @@ public class Deamon : GLib.Object {
/////////////////////////////////////////////////////////////////////
public void run(string[] args) {
- // create command line options
- var context = new GLib.OptionContext("");
- context.set_help_enabled(true);
- context.add_main_entries(options, null);
- context.add_group(Gtk.get_option_group (false));
-
- try {
- context.parse(ref args);
- } catch(GLib.OptionError error) {
- warning(error.message);
- }
-
- if (Deamon.reset) {
- if (GLib.FileUtils.remove(Paths.pie_config) == 0)
- message("Removed file \"%s\"", Paths.pie_config);
- if (GLib.FileUtils.remove(Paths.settings) == 0)
- message("Removed file \"%s\"", Paths.settings);
-
- return;
- }
// create unique application
- var app = new Unique.App("org.gnome.gnomepie", null);
-
- #if HAVE_GTK_3
- if (app.is_running()) {
- #else
- if (app.is_running) {
- #endif
- // inform the running instance of the pie to be opened
- if (open_pie != null) {
- message("Gnome-Pie is already running. Sending request to open pie " + open_pie + ".");
- var data = new Unique.MessageData();
- data.set_text(open_pie, open_pie.length);
- app.send_message(Unique.Command.ACTIVATE, data);
-
- return;
- }
-
- message("Gnome-Pie is already running. Sending request to open config menu.");
- app.send_message(Unique.Command.ACTIVATE, null);
+ var app = new GLib.Application("org.gnome.gnomepie", GLib.ApplicationFlags.HANDLES_COMMAND_LINE);
- return;
- }
-
- // wait for incoming messages
- app.message_received.connect((cmd, data, event_time) => {
- if (cmd == Unique.Command.ACTIVATE) {
- var pie = data.get_text();
-
- if (pie != null && pie != "") PieManager.open_pie(pie);
- else this.indicator.show_preferences();
-
- return Unique.Response.OK;
+ app.command_line.connect((cmd) => {
+ string[] tmp = cmd.get_arguments();
+ unowned string[] remote_args = tmp;
+ if (!handle_command_line(remote_args, true)) {
+ Gtk.main_quit();
}
- return Unique.Response.PASSTHROUGH;
+ return 0;
});
- Gdk.threads_enter();
+ app.startup.connect(() => {
- // init locale support
- Intl.bindtextdomain ("gnomepie", Paths.locales);
- Intl.textdomain ("gnomepie");
+ message("Welcome to Gnome-Pie " + version + "!");
- // init toolkits and static stuff
- ActionRegistry.init();
- GroupRegistry.init();
+ // init locale support
+ Intl.bindtextdomain ("gnomepie", Paths.locales);
+ Intl.textdomain ("gnomepie");
- PieManager.init();
- Icon.init();
+ // init toolkits and static stuff
+ ActionRegistry.init();
+ GroupRegistry.init();
- // launch the indicator
- this.indicator = new Indicator();
+ PieManager.init();
+ Icon.init();
- // connect SigHandlers
- Posix.signal(Posix.SIGINT, sig_handler);
- Posix.signal(Posix.SIGTERM, sig_handler);
+ // launch the indicator
+ this.indicator = new Indicator();
- // finished loading... so run the prog!
- message("Started happily...");
+ // connect SigHandlers
+ Posix.signal(Posix.SIGINT, sig_handler);
+ Posix.signal(Posix.SIGTERM, sig_handler);
- // open pie if neccessary
- if (open_pie != null)
- PieManager.open_pie(open_pie);
+ // finished loading... so run the prog!
+ message("Started happily...");
- Gtk.main();
+ if (handle_command_line(args, false)) {
+ Gtk.main();
+ }
+ });
- Gdk.threads_leave();
+ app.run(args);
}
/////////////////////////////////////////////////////////////////////
@@ -183,6 +136,42 @@ public class Deamon : GLib.Object {
message("Caught signal (%d), bye!".printf(sig));
Gtk.main_quit();
}
+
+ /////////////////////////////////////////////////////////////////////
+ /// Handles command line parameters.
+ /////////////////////////////////////////////////////////////////////
+
+ private bool handle_command_line(string[] args, bool show_preferences) {
+ // create command line options
+ var context = new GLib.OptionContext("");
+ context.set_help_enabled(true);
+ context.add_main_entries(options, null);
+ context.add_group(Gtk.get_option_group (false));
+
+ try {
+ context.parse(ref args);
+ } catch(GLib.OptionError error) {
+ warning(error.message);
+ }
+
+ if (reset) {
+ if (GLib.FileUtils.remove(Paths.pie_config) == 0)
+ message("Removed file \"%s\"", Paths.pie_config);
+ if (GLib.FileUtils.remove(Paths.settings) == 0)
+ message("Removed file \"%s\"", Paths.settings);
+
+ return false;
+ }
+
+ if (open_pie != null && open_pie != "") {
+ PieManager.open_pie(open_pie);
+ open_pie = "";
+ } else if (show_preferences) {
+ this.indicator.show_preferences();
+ }
+
+ return true;
+ }
}
}