diff main.c @ 0:9a16bf50daba

Initial revision
author Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
date Sat, 27 Apr 2013 00:33:11 +0200
parents
children 54ecfe6a14cf
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.c	Sat Apr 27 00:33:11 2013 +0200
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2013 Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include <stdlib.h>
+#include <locale.h>
+#include <glib/gi18n.h>
+#include <gtk/gtk.h>
+#include <unique/unique.h>
+#include "xia-debug.h"
+#include "xia-icon.h"
+
+int
+main(int argc, char **argv)
+{
+	XiaIcon		*icon;
+	UniqueApp	*app = NULL;
+	int		exitval = 0;
+	gboolean	debug_mode = FALSE;
+	gboolean	version = FALSE;
+	GOptionContext	*context;
+	GError		*error = NULL;
+	const GOptionEntry options[] = {
+		{ "debug", 'd', 0, G_OPTION_ARG_NONE, &debug_mode,
+		    N_("Enable debugging output"), NULL },
+		{ "version", 'v', 0, G_OPTION_ARG_NONE, &version,
+		    N_("Print the version number and exit"), NULL },
+		{ NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, 0 }
+	};
+
+	setlocale(LC_ALL, "");
+
+	bindtextdomain(PACKAGE, LOCALEDIR);
+	bind_textdomain_codeset(PACKAGE, "UTF-8");
+	textdomain(PACKAGE);
+
+	gtk_init(&argc, &argv);
+
+	g_set_application_name(_("XInhibit Applet"));
+	gtk_window_set_default_icon_name("xinhibit-applet");
+
+	context = g_option_context_new(_("- inhibit automatic power "
+	    "management"));
+	g_option_context_add_main_entries(context, options, PACKAGE);
+	g_option_context_parse(context, &argc, &argv, &error);
+	g_option_context_free(context);
+	if (error) {
+		g_printerr("Error parsing command line options: %s\n",
+		    error->message);
+		g_error_free(error);
+		exitval = 1;
+		goto out;
+	}
+
+	xia_debug_init(debug_mode);
+
+	if (version) {
+		g_print("%s %s\n", PACKAGE, VERSION);
+		goto out;
+	}
+
+	app = unique_app_new(APP_NAME, NULL);
+	if (unique_app_is_running(app)) {
+		g_printerr("Another instance of " PACKAGE " is already "
+		    "running, exiting\n");
+		exitval = 1;
+		goto out;
+	}
+
+	icon = xia_icon_new();
+
+	gtk_main();
+
+	g_object_unref(icon);
+out:
+	if (app != NULL)
+		g_object_unref(app);
+
+	exit(exitval);
+}