Mercurial > projects > pk-update-icon
annotate main.c @ 48:1eb92ab03287
Avoid passing more arguments to g_strdup_printf() than specified in the format
Avoid passing more arguments to g_strdup_printf() than specified in the format
depending on the number of updates.
Split sentences with two plural forms up, otherwise they cannot be formatted
properly.
author | Stanislav Brabec <sbrabec@suse.com> |
---|---|
date | Thu, 18 Jun 2015 22:55:08 +0200 |
parents | aa5d3752091d |
children | 7de92a24e86c |
rev | line source |
---|---|
2 | 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 | 3 * |
4 * Licensed under the GNU General Public License Version 2 | |
5 * | |
6 * This program is free software; you can redistribute it and/or modify | |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; either version 2 of the License, or | |
9 * (at your option) any later version. | |
10 * | |
11 * This program is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 * GNU General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License | |
17 * along with this program; if not, write to the Free Software | |
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
19 */ | |
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 | 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 | 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; |
46
aa5d3752091d
Make the update viewer command configurable
Guido Berhoerster <gber@opensuse.org>
parents:
31
diff
changeset
|
35 gchar *update_viewer_command = NULL; |
31
f549b75c3c22
increase the default update interval and delay before checking for updates
Guido Berhoerster <gber@opensuse.org>
parents:
16
diff
changeset
|
36 gint startup_delay = 300; |
f549b75c3c22
increase the default update interval and delay before checking for updates
Guido Berhoerster <gber@opensuse.org>
parents:
16
diff
changeset
|
37 gint check_interval = 86400; |
16
7af115023d5a
add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents:
14
diff
changeset
|
38 GOptionContext *context; |
7af115023d5a
add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents:
14
diff
changeset
|
39 GError *error = NULL; |
7af115023d5a
add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents:
14
diff
changeset
|
40 const GOptionEntry options[] = { |
46
aa5d3752091d
Make the update viewer command configurable
Guido Berhoerster <gber@opensuse.org>
parents:
31
diff
changeset
|
41 { "command", 'c', 0, G_OPTION_ARG_STRING, |
aa5d3752091d
Make the update viewer command configurable
Guido Berhoerster <gber@opensuse.org>
parents:
31
diff
changeset
|
42 &update_viewer_command, N_("Command for starting the " |
aa5d3752091d
Make the update viewer command configurable
Guido Berhoerster <gber@opensuse.org>
parents:
31
diff
changeset
|
43 "software update viewer"), "command" }, |
16
7af115023d5a
add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents:
14
diff
changeset
|
44 { "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
|
45 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
|
46 "updates"), "delay" }, |
7af115023d5a
add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents:
14
diff
changeset
|
47 { "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
|
48 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
|
49 "updates"), "interval" }, |
7af115023d5a
add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents:
14
diff
changeset
|
50 { "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
|
51 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
|
52 { 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
|
53 }; |
0 | 54 |
8
58a3312a1c59
add internationalization support
Guido Berhoerster <guido@berhoerster.name>
parents:
3
diff
changeset
|
55 setlocale(LC_ALL, ""); |
14
64f05992d8ec
GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
9
diff
changeset
|
56 |
8
58a3312a1c59
add internationalization support
Guido Berhoerster <guido@berhoerster.name>
parents:
3
diff
changeset
|
57 bindtextdomain(PACKAGE, LOCALEDIR); |
58a3312a1c59
add internationalization support
Guido Berhoerster <guido@berhoerster.name>
parents:
3
diff
changeset
|
58 bind_textdomain_codeset(PACKAGE, "UTF-8"); |
58a3312a1c59
add internationalization support
Guido Berhoerster <guido@berhoerster.name>
parents:
3
diff
changeset
|
59 textdomain(PACKAGE); |
58a3312a1c59
add internationalization support
Guido Berhoerster <guido@berhoerster.name>
parents:
3
diff
changeset
|
60 |
0 | 61 gtk_init(&argc, &argv); |
14
64f05992d8ec
GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
9
diff
changeset
|
62 |
16
7af115023d5a
add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents:
14
diff
changeset
|
63 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
|
64 "software updates")); |
7af115023d5a
add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents:
14
diff
changeset
|
65 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
|
66 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
|
67 g_option_context_free(context); |
7af115023d5a
add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents:
14
diff
changeset
|
68 if (error) { |
7af115023d5a
add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents:
14
diff
changeset
|
69 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
|
70 error->message); |
7af115023d5a
add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents:
14
diff
changeset
|
71 g_error_free(error); |
7af115023d5a
add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents:
14
diff
changeset
|
72 exitval = 1; |
7af115023d5a
add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents:
14
diff
changeset
|
73 goto out; |
7af115023d5a
add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents:
14
diff
changeset
|
74 } |
7af115023d5a
add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents:
14
diff
changeset
|
75 |
7af115023d5a
add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents:
14
diff
changeset
|
76 if (startup_delay < 0) { |
7af115023d5a
add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents:
14
diff
changeset
|
77 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
|
78 "greater or equal to zero\n"); |
7af115023d5a
add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents:
14
diff
changeset
|
79 exitval = 1; |
7af115023d5a
add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents:
14
diff
changeset
|
80 goto out; |
7af115023d5a
add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents:
14
diff
changeset
|
81 } |
7af115023d5a
add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents:
14
diff
changeset
|
82 |
7af115023d5a
add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents:
14
diff
changeset
|
83 if (check_interval < 0) { |
7af115023d5a
add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents:
14
diff
changeset
|
84 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
|
85 "be greater or equal to zero\n"); |
7af115023d5a
add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents:
14
diff
changeset
|
86 exitval = 1; |
7af115023d5a
add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents:
14
diff
changeset
|
87 goto out; |
7af115023d5a
add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents:
14
diff
changeset
|
88 } |
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 if (version) { |
7af115023d5a
add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents:
14
diff
changeset
|
91 g_print("%s %s\n", PACKAGE, VERSION); |
7af115023d5a
add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents:
14
diff
changeset
|
92 goto out; |
7af115023d5a
add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents:
14
diff
changeset
|
93 } |
7af115023d5a
add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents:
14
diff
changeset
|
94 |
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 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
|
96 if (unique_app_is_running(app)) { |
14
64f05992d8ec
GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
9
diff
changeset
|
97 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
|
98 "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
|
99 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
|
100 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
|
101 } |
0 | 102 |
14
64f05992d8ec
GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
9
diff
changeset
|
103 notify_init(PACKAGE); |
64f05992d8ec
GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
9
diff
changeset
|
104 |
46
aa5d3752091d
Make the update viewer command configurable
Guido Berhoerster <gber@opensuse.org>
parents:
31
diff
changeset
|
105 icon = pkui_icon_new(startup_delay, check_interval, |
aa5d3752091d
Make the update viewer command configurable
Guido Berhoerster <gber@opensuse.org>
parents:
31
diff
changeset
|
106 update_viewer_command); |
0 | 107 |
108 gtk_main(); | |
109 | |
14
64f05992d8ec
GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
9
diff
changeset
|
110 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
|
111 out: |
16
7af115023d5a
add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents:
14
diff
changeset
|
112 if (app != NULL) |
7af115023d5a
add CLI, make delay and interval configurable
Guido Berhoerster <guido@berhoerster.name>
parents:
14
diff
changeset
|
113 g_object_unref(app); |
14
64f05992d8ec
GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
9
diff
changeset
|
114 if (notify_is_initted()) |
64f05992d8ec
GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
9
diff
changeset
|
115 notify_uninit (); |
46
aa5d3752091d
Make the update viewer command configurable
Guido Berhoerster <gber@opensuse.org>
parents:
31
diff
changeset
|
116 g_free(update_viewer_command); |
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
|
117 |
14
64f05992d8ec
GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
9
diff
changeset
|
118 return (exitval); |
0 | 119 } |