Mercurial > projects > xinhibit-applet
comparison 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 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:9a16bf50daba |
---|---|
1 /* | |
2 * Copyright (C) 2013 Guido Berhoerster <guido+xinhibit-applet@berhoerster.name> | |
3 * | |
4 * Permission is hereby granted, free of charge, to any person obtaining | |
5 * a copy of this software and associated documentation files (the | |
6 * "Software"), to deal in the Software without restriction, including | |
7 * without limitation the rights to use, copy, modify, merge, publish, | |
8 * distribute, sublicense, and/or sell copies of the Software, and to | |
9 * permit persons to whom the Software is furnished to do so, subject to | |
10 * the following conditions: | |
11 * | |
12 * The above copyright notice and this permission notice shall be included | |
13 * in all copies or substantial portions of the Software. | |
14 * | |
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | |
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | |
19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | |
20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | |
21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
22 */ | |
23 | |
24 #include <stdlib.h> | |
25 #include <locale.h> | |
26 #include <glib/gi18n.h> | |
27 #include <gtk/gtk.h> | |
28 #include <unique/unique.h> | |
29 #include "xia-debug.h" | |
30 #include "xia-icon.h" | |
31 | |
32 int | |
33 main(int argc, char **argv) | |
34 { | |
35 XiaIcon *icon; | |
36 UniqueApp *app = NULL; | |
37 int exitval = 0; | |
38 gboolean debug_mode = FALSE; | |
39 gboolean version = FALSE; | |
40 GOptionContext *context; | |
41 GError *error = NULL; | |
42 const GOptionEntry options[] = { | |
43 { "debug", 'd', 0, G_OPTION_ARG_NONE, &debug_mode, | |
44 N_("Enable debugging output"), NULL }, | |
45 { "version", 'v', 0, G_OPTION_ARG_NONE, &version, | |
46 N_("Print the version number and exit"), NULL }, | |
47 { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, 0 } | |
48 }; | |
49 | |
50 setlocale(LC_ALL, ""); | |
51 | |
52 bindtextdomain(PACKAGE, LOCALEDIR); | |
53 bind_textdomain_codeset(PACKAGE, "UTF-8"); | |
54 textdomain(PACKAGE); | |
55 | |
56 gtk_init(&argc, &argv); | |
57 | |
58 g_set_application_name(_("XInhibit Applet")); | |
59 gtk_window_set_default_icon_name("xinhibit-applet"); | |
60 | |
61 context = g_option_context_new(_("- inhibit automatic power " | |
62 "management")); | |
63 g_option_context_add_main_entries(context, options, PACKAGE); | |
64 g_option_context_parse(context, &argc, &argv, &error); | |
65 g_option_context_free(context); | |
66 if (error) { | |
67 g_printerr("Error parsing command line options: %s\n", | |
68 error->message); | |
69 g_error_free(error); | |
70 exitval = 1; | |
71 goto out; | |
72 } | |
73 | |
74 xia_debug_init(debug_mode); | |
75 | |
76 if (version) { | |
77 g_print("%s %s\n", PACKAGE, VERSION); | |
78 goto out; | |
79 } | |
80 | |
81 app = unique_app_new(APP_NAME, NULL); | |
82 if (unique_app_is_running(app)) { | |
83 g_printerr("Another instance of " PACKAGE " is already " | |
84 "running, exiting\n"); | |
85 exitval = 1; | |
86 goto out; | |
87 } | |
88 | |
89 icon = xia_icon_new(); | |
90 | |
91 gtk_main(); | |
92 | |
93 g_object_unref(icon); | |
94 out: | |
95 if (app != NULL) | |
96 g_object_unref(app); | |
97 | |
98 exit(exitval); | |
99 } |