annotate main.c @ 29:3104191b44ca version-0.2.1

release pk-update-icon-0.2.1
author Guido Berhoerster <gber@opensuse.org>
date Tue, 15 Nov 2011 13:03:17 +0100
parents 7af115023d5a
children f549b75c3c22
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
847ae02bc13b added GPLv2 headers
Pavol Rusnak <stick@gk2.sk>
parents: 1
diff changeset
1 /*
8
58a3312a1c59 add internationalization support
Guido Berhoerster <guido@berhoerster.name>
parents: 3
diff changeset
2 * Copyright (C) 2011 Guido Berhoerster <gber@opensuse.org>
2
847ae02bc13b added GPLv2 headers
Pavol Rusnak <stick@gk2.sk>
parents: 1
diff changeset
3 *
847ae02bc13b added GPLv2 headers
Pavol Rusnak <stick@gk2.sk>
parents: 1
diff changeset
4 * Licensed under the GNU General Public License Version 2
847ae02bc13b added GPLv2 headers
Pavol Rusnak <stick@gk2.sk>
parents: 1
diff changeset
5 *
847ae02bc13b added GPLv2 headers
Pavol Rusnak <stick@gk2.sk>
parents: 1
diff changeset
6 * This program is free software; you can redistribute it and/or modify
847ae02bc13b added GPLv2 headers
Pavol Rusnak <stick@gk2.sk>
parents: 1
diff changeset
7 * it under the terms of the GNU General Public License as published by
847ae02bc13b added GPLv2 headers
Pavol Rusnak <stick@gk2.sk>
parents: 1
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or
847ae02bc13b added GPLv2 headers
Pavol Rusnak <stick@gk2.sk>
parents: 1
diff changeset
9 * (at your option) any later version.
847ae02bc13b added GPLv2 headers
Pavol Rusnak <stick@gk2.sk>
parents: 1
diff changeset
10 *
847ae02bc13b added GPLv2 headers
Pavol Rusnak <stick@gk2.sk>
parents: 1
diff changeset
11 * This program is distributed in the hope that it will be useful,
847ae02bc13b added GPLv2 headers
Pavol Rusnak <stick@gk2.sk>
parents: 1
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
847ae02bc13b added GPLv2 headers
Pavol Rusnak <stick@gk2.sk>
parents: 1
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
847ae02bc13b added GPLv2 headers
Pavol Rusnak <stick@gk2.sk>
parents: 1
diff changeset
14 * GNU General Public License for more details.
847ae02bc13b added GPLv2 headers
Pavol Rusnak <stick@gk2.sk>
parents: 1
diff changeset
15 *
847ae02bc13b added GPLv2 headers
Pavol Rusnak <stick@gk2.sk>
parents: 1
diff changeset
16 * You should have received a copy of the GNU General Public License
847ae02bc13b added GPLv2 headers
Pavol Rusnak <stick@gk2.sk>
parents: 1
diff changeset
17 * along with this program; if not, write to the Free Software
847ae02bc13b added GPLv2 headers
Pavol Rusnak <stick@gk2.sk>
parents: 1
diff changeset
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
847ae02bc13b added GPLv2 headers
Pavol Rusnak <stick@gk2.sk>
parents: 1
diff changeset
19 */
847ae02bc13b added GPLv2 headers
Pavol Rusnak <stick@gk2.sk>
parents: 1
diff changeset
20
8
58a3312a1c59 add internationalization support
Guido Berhoerster <guido@berhoerster.name>
parents: 3
diff changeset
21 #include <locale.h>
58a3312a1c59 add internationalization support
Guido Berhoerster <guido@berhoerster.name>
parents: 3
diff changeset
22 #include <glib/gi18n.h>
0
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
23 #include <gtk/gtk.h>
9
0e50d3652326 use libunique to ensure that only a single instance of pk-update-icon can be run
Guido Berhoerster <guido@berhoerster.name>
parents: 8
diff changeset
24 #include <unique/unique.h>
14
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents: 9
diff changeset
25 #include <libnotify/notify.h>
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents: 9
diff changeset
26 #include "pkui-icon.h"
1
483f5fe9d2b2 change icon and tooltip of the tray icon
Pavol Rusnak <stick@gk2.sk>
parents: 0
diff changeset
27
14
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents: 9
diff changeset
28 int
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents: 9
diff changeset
29 main(int argc, char **argv)
0
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
30 {
14
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents: 9
diff changeset
31 PkuiIcon *icon;
16
7af115023d5a add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
32 UniqueApp *app = NULL;
14
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents: 9
diff changeset
33 int exitval = 0;
16
7af115023d5a add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
34 gboolean version = FALSE;
7af115023d5a add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
35 gint startup_delay = 10;
7af115023d5a add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
36 gint check_interval = 2 * 3600;
7af115023d5a add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
37 GOptionContext *context;
7af115023d5a add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
38 GError *error = NULL;
7af115023d5a add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
39 const GOptionEntry options[] = {
7af115023d5a add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
40 { "delay", 'd', 0, G_OPTION_ARG_INT, &startup_delay,
7af115023d5a add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
41 N_("Set the delay in seconds before the first check for "
7af115023d5a add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
42 "updates"), "delay" },
7af115023d5a add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
43 { "interval", 'i', 0, G_OPTION_ARG_INT, &check_interval,
7af115023d5a add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
44 N_("Set the interval in seconds between checks for "
7af115023d5a add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
45 "updates"), "interval" },
7af115023d5a add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
46 { "version", 'v', 0, G_OPTION_ARG_NONE, &version,
7af115023d5a add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
47 N_("Print the version number and exit"), NULL },
7af115023d5a add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
48 { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, 0 }
7af115023d5a add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
49 };
0
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
50
8
58a3312a1c59 add internationalization support
Guido Berhoerster <guido@berhoerster.name>
parents: 3
diff changeset
51 setlocale(LC_ALL, "");
14
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents: 9
diff changeset
52
8
58a3312a1c59 add internationalization support
Guido Berhoerster <guido@berhoerster.name>
parents: 3
diff changeset
53 bindtextdomain(PACKAGE, LOCALEDIR);
58a3312a1c59 add internationalization support
Guido Berhoerster <guido@berhoerster.name>
parents: 3
diff changeset
54 bind_textdomain_codeset(PACKAGE, "UTF-8");
58a3312a1c59 add internationalization support
Guido Berhoerster <guido@berhoerster.name>
parents: 3
diff changeset
55 textdomain(PACKAGE);
58a3312a1c59 add internationalization support
Guido Berhoerster <guido@berhoerster.name>
parents: 3
diff changeset
56
0
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
57 gtk_init(&argc, &argv);
14
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents: 9
diff changeset
58
16
7af115023d5a add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
59 context = g_option_context_new(_("- display notifications about "
7af115023d5a add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
60 "software updates"));
7af115023d5a add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
61 g_option_context_add_main_entries(context, options, PACKAGE);
7af115023d5a add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
62 g_option_context_parse(context, &argc, &argv, &error);
7af115023d5a add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
63 g_option_context_free(context);
7af115023d5a add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
64 if (error) {
7af115023d5a add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
65 g_printerr("Error parsing command line options: %s\n",
7af115023d5a add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
66 error->message);
7af115023d5a add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
67 g_error_free(error);
7af115023d5a add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
68 exitval = 1;
7af115023d5a add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
69 goto out;
7af115023d5a add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
70 }
7af115023d5a add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
71
7af115023d5a add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
72 if (startup_delay < 0) {
7af115023d5a add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
73 g_printerr("Error parsing command line options: delay must be "
7af115023d5a add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
74 "greater or equal to zero\n");
7af115023d5a add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
75 exitval = 1;
7af115023d5a add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
76 goto out;
7af115023d5a add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
77 }
7af115023d5a add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
78
7af115023d5a add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
79 if (check_interval < 0) {
7af115023d5a add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
80 g_printerr("Error parsing command line options: interval must "
7af115023d5a add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
81 "be greater or equal to zero\n");
7af115023d5a add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
82 exitval = 1;
7af115023d5a add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
83 goto out;
7af115023d5a add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
84 }
7af115023d5a add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
85
7af115023d5a add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
86 if (version) {
7af115023d5a add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
87 g_print("%s %s\n", PACKAGE, VERSION);
7af115023d5a add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
88 goto out;
7af115023d5a add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
89 }
7af115023d5a add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
90
9
0e50d3652326 use libunique to ensure that only a single instance of pk-update-icon can be run
Guido Berhoerster <guido@berhoerster.name>
parents: 8
diff changeset
91 app = unique_app_new(APP_NAME, NULL);
0e50d3652326 use libunique to ensure that only a single instance of pk-update-icon can be run
Guido Berhoerster <guido@berhoerster.name>
parents: 8
diff changeset
92 if (unique_app_is_running(app)) {
14
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents: 9
diff changeset
93 g_printerr("Another instance of pk-update-icon is already "
16
7af115023d5a add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
94 "running, exiting\n");
9
0e50d3652326 use libunique to ensure that only a single instance of pk-update-icon can be run
Guido Berhoerster <guido@berhoerster.name>
parents: 8
diff changeset
95 exitval = 1;
0e50d3652326 use libunique to ensure that only a single instance of pk-update-icon can be run
Guido Berhoerster <guido@berhoerster.name>
parents: 8
diff changeset
96 goto out;
0e50d3652326 use libunique to ensure that only a single instance of pk-update-icon can be run
Guido Berhoerster <guido@berhoerster.name>
parents: 8
diff changeset
97 }
0
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
98
14
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents: 9
diff changeset
99 notify_init(PACKAGE);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents: 9
diff changeset
100
16
7af115023d5a add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
101 icon = pkui_icon_new(startup_delay, check_interval);
0
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
102
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
103 gtk_main();
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
104
14
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents: 9
diff changeset
105 g_object_unref(icon);
9
0e50d3652326 use libunique to ensure that only a single instance of pk-update-icon can be run
Guido Berhoerster <guido@berhoerster.name>
parents: 8
diff changeset
106 out:
16
7af115023d5a add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
107 if (app != NULL)
7af115023d5a add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
108 g_object_unref(app);
14
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents: 9
diff changeset
109 if (notify_is_initted())
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents: 9
diff changeset
110 notify_uninit ();
9
0e50d3652326 use libunique to ensure that only a single instance of pk-update-icon can be run
Guido Berhoerster <guido@berhoerster.name>
parents: 8
diff changeset
111
14
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents: 9
diff changeset
112 return (exitval);
0
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
113 }