Mercurial > projects > pk-update-icon
comparison main.c @ 16:7af115023d5a
add CLI, make delay and interval configurable
author | Guido Berhoerster <guido@berhoerster.name> |
---|---|
date | Thu, 20 Oct 2011 12:06:42 +0200 |
parents | 64f05992d8ec |
children | f549b75c3c22 |
comparison
equal
deleted
inserted
replaced
15:c7eac2574c76 | 16:7af115023d5a |
---|---|
27 | 27 |
28 int | 28 int |
29 main(int argc, char **argv) | 29 main(int argc, char **argv) |
30 { | 30 { |
31 PkuiIcon *icon; | 31 PkuiIcon *icon; |
32 UniqueApp *app; | 32 UniqueApp *app = NULL; |
33 int exitval = 0; | 33 int exitval = 0; |
34 gboolean version = FALSE; | |
35 gint startup_delay = 10; | |
36 gint check_interval = 2 * 3600; | |
37 GOptionContext *context; | |
38 GError *error = NULL; | |
39 const GOptionEntry options[] = { | |
40 { "delay", 'd', 0, G_OPTION_ARG_INT, &startup_delay, | |
41 N_("Set the delay in seconds before the first check for " | |
42 "updates"), "delay" }, | |
43 { "interval", 'i', 0, G_OPTION_ARG_INT, &check_interval, | |
44 N_("Set the interval in seconds between checks for " | |
45 "updates"), "interval" }, | |
46 { "version", 'v', 0, G_OPTION_ARG_NONE, &version, | |
47 N_("Print the version number and exit"), NULL }, | |
48 { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, 0 } | |
49 }; | |
34 | 50 |
35 setlocale(LC_ALL, ""); | 51 setlocale(LC_ALL, ""); |
36 | 52 |
37 bindtextdomain(PACKAGE, LOCALEDIR); | 53 bindtextdomain(PACKAGE, LOCALEDIR); |
38 bind_textdomain_codeset(PACKAGE, "UTF-8"); | 54 bind_textdomain_codeset(PACKAGE, "UTF-8"); |
39 textdomain(PACKAGE); | 55 textdomain(PACKAGE); |
40 | 56 |
41 gtk_init(&argc, &argv); | 57 gtk_init(&argc, &argv); |
42 | 58 |
59 context = g_option_context_new(_("- display notifications about " | |
60 "software updates")); | |
61 g_option_context_add_main_entries(context, options, PACKAGE); | |
62 g_option_context_parse(context, &argc, &argv, &error); | |
63 g_option_context_free(context); | |
64 if (error) { | |
65 g_printerr("Error parsing command line options: %s\n", | |
66 error->message); | |
67 g_error_free(error); | |
68 exitval = 1; | |
69 goto out; | |
70 } | |
71 | |
72 if (startup_delay < 0) { | |
73 g_printerr("Error parsing command line options: delay must be " | |
74 "greater or equal to zero\n"); | |
75 exitval = 1; | |
76 goto out; | |
77 } | |
78 | |
79 if (check_interval < 0) { | |
80 g_printerr("Error parsing command line options: interval must " | |
81 "be greater or equal to zero\n"); | |
82 exitval = 1; | |
83 goto out; | |
84 } | |
85 | |
86 if (version) { | |
87 g_print("%s %s\n", PACKAGE, VERSION); | |
88 goto out; | |
89 } | |
90 | |
43 app = unique_app_new(APP_NAME, NULL); | 91 app = unique_app_new(APP_NAME, NULL); |
44 if (unique_app_is_running(app)) { | 92 if (unique_app_is_running(app)) { |
45 g_printerr("Another instance of pk-update-icon is already " | 93 g_printerr("Another instance of pk-update-icon is already " |
46 "running. Exiting.\n"); | 94 "running, exiting\n"); |
47 exitval = 1; | 95 exitval = 1; |
48 goto out; | 96 goto out; |
49 } | 97 } |
50 | 98 |
51 notify_init(PACKAGE); | 99 notify_init(PACKAGE); |
52 | 100 |
53 icon = pkui_icon_new(10, 2 * 3600); | 101 icon = pkui_icon_new(startup_delay, check_interval); |
54 | 102 |
55 gtk_main(); | 103 gtk_main(); |
56 | 104 |
57 g_object_unref(icon); | 105 g_object_unref(icon); |
58 out: | 106 out: |
59 g_object_unref(app); | 107 if (app != NULL) |
108 g_object_unref(app); | |
60 if (notify_is_initted()) | 109 if (notify_is_initted()) |
61 notify_uninit (); | 110 notify_uninit (); |
62 | 111 |
63 return (exitval); | 112 return (exitval); |
64 } | 113 } |