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