Mercurial > projects > pk-update-icon
diff 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 |
line wrap: on
line diff
--- a/main.c Thu Oct 20 09:06:52 2011 +0200 +++ b/main.c Thu Oct 20 12:06:42 2011 +0200 @@ -29,8 +29,24 @@ main(int argc, char **argv) { PkuiIcon *icon; - UniqueApp *app; + UniqueApp *app = NULL; int exitval = 0; + gboolean version = FALSE; + gint startup_delay = 10; + gint check_interval = 2 * 3600; + GOptionContext *context; + GError *error = NULL; + const GOptionEntry options[] = { + { "delay", 'd', 0, G_OPTION_ARG_INT, &startup_delay, + N_("Set the delay in seconds before the first check for " + "updates"), "delay" }, + { "interval", 'i', 0, G_OPTION_ARG_INT, &check_interval, + N_("Set the interval in seconds between checks for " + "updates"), "interval" }, + { "version", 'v', 0, G_OPTION_ARG_NONE, &version, + N_("Print the version number and exit"), NULL }, + { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, 0 } + }; setlocale(LC_ALL, ""); @@ -40,23 +56,56 @@ gtk_init(&argc, &argv); + context = g_option_context_new(_("- display notifications about " + "software updates")); + g_option_context_add_main_entries(context, options, PACKAGE); + g_option_context_parse(context, &argc, &argv, &error); + g_option_context_free(context); + if (error) { + g_printerr("Error parsing command line options: %s\n", + error->message); + g_error_free(error); + exitval = 1; + goto out; + } + + if (startup_delay < 0) { + g_printerr("Error parsing command line options: delay must be " + "greater or equal to zero\n"); + exitval = 1; + goto out; + } + + if (check_interval < 0) { + g_printerr("Error parsing command line options: interval must " + "be greater or equal to zero\n"); + exitval = 1; + goto out; + } + + if (version) { + g_print("%s %s\n", PACKAGE, VERSION); + goto out; + } + app = unique_app_new(APP_NAME, NULL); if (unique_app_is_running(app)) { g_printerr("Another instance of pk-update-icon is already " - "running. Exiting.\n"); + "running, exiting\n"); exitval = 1; goto out; } notify_init(PACKAGE); - icon = pkui_icon_new(10, 2 * 3600); + icon = pkui_icon_new(startup_delay, check_interval); gtk_main(); g_object_unref(icon); out: - g_object_unref(app); + if (app != NULL) + g_object_unref(app); if (notify_is_initted()) notify_uninit ();