projects/pk-update-icon

changeset 16:7af115023d5a

add CLI, make delay and interval configurable
author Guido Berhoerster <guido@berhoerster.name>
date Thu Oct 20 12:06:42 2011 +0200 (2011-10-20)
parents c7eac2574c76
children a28d0d9b5410
files Makefile main.c pk-update-icon.1 po/de.po
line diff
     1.1 --- a/Makefile	Thu Oct 20 09:06:52 2011 +0200
     1.2 +++ b/Makefile	Thu Oct 20 12:06:42 2011 +0200
     1.3 @@ -26,6 +26,7 @@
     1.4  		-DI_KNOW_THE_PACKAGEKIT_GLIB2_API_IS_SUBJECT_TO_CHANGE \
     1.5  		-DPACKAGE="\"$(PACKAGE)\"" \
     1.6  		-DAPP_NAME=\"$(APP_NAME)\" \
     1.7 +		-DVERSION=\"$(VERSION)\" \
     1.8  		-DLOCALEDIR="\"$(localedir)\""
     1.9  LDLIBS :=	$(shell pkg-config --libs gtk+-2.0 unique-1.0 libnotify packagekit-glib2)
    1.10  
     2.1 --- a/main.c	Thu Oct 20 09:06:52 2011 +0200
     2.2 +++ b/main.c	Thu Oct 20 12:06:42 2011 +0200
     2.3 @@ -29,8 +29,24 @@
     2.4  main(int argc, char **argv)
     2.5  {
     2.6  	PkuiIcon	*icon;
     2.7 -	UniqueApp	*app;
     2.8 +	UniqueApp	*app = NULL;
     2.9  	int		exitval = 0;
    2.10 +	gboolean	version = FALSE;
    2.11 +	gint		startup_delay = 10;
    2.12 +	gint		check_interval = 2 * 3600;
    2.13 +	GOptionContext	*context;
    2.14 +	GError		*error = NULL;
    2.15 +	const GOptionEntry options[] = {
    2.16 +		{ "delay", 'd', 0, G_OPTION_ARG_INT, &startup_delay,
    2.17 +		    N_("Set the delay in seconds before the first check for "
    2.18 +		    "updates"), "delay" },
    2.19 +		{ "interval", 'i', 0, G_OPTION_ARG_INT, &check_interval,
    2.20 +		    N_("Set the interval in seconds between checks for "
    2.21 +		    "updates"), "interval" },
    2.22 +		{ "version", 'v', 0, G_OPTION_ARG_NONE, &version,
    2.23 +		    N_("Print the version number and exit"), NULL },
    2.24 +		{ NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, 0 }
    2.25 +	};
    2.26  
    2.27  	setlocale(LC_ALL, "");
    2.28  
    2.29 @@ -40,23 +56,56 @@
    2.30  
    2.31  	gtk_init(&argc, &argv);
    2.32  
    2.33 +	context = g_option_context_new(_("- display notifications about "
    2.34 +	    "software updates"));
    2.35 +	g_option_context_add_main_entries(context, options, PACKAGE);
    2.36 +	g_option_context_parse(context, &argc, &argv, &error);
    2.37 +	g_option_context_free(context);
    2.38 +	if (error) {
    2.39 +		g_printerr("Error parsing command line options: %s\n",
    2.40 +		    error->message);
    2.41 +		g_error_free(error);
    2.42 +		exitval = 1;
    2.43 +		goto out;
    2.44 +	}
    2.45 +
    2.46 +	if (startup_delay < 0) {
    2.47 +		g_printerr("Error parsing command line options: delay must be "
    2.48 +		    "greater or equal to zero\n");
    2.49 +		exitval = 1;
    2.50 +		goto out;
    2.51 +	}
    2.52 +
    2.53 +	if (check_interval < 0) {
    2.54 +		g_printerr("Error parsing command line options: interval must "
    2.55 +		    "be greater or equal to zero\n");
    2.56 +		exitval = 1;
    2.57 +		goto out;
    2.58 +	}
    2.59 +
    2.60 +	if (version) {
    2.61 +		g_print("%s %s\n", PACKAGE, VERSION);
    2.62 +		goto out;
    2.63 +	}
    2.64 +
    2.65  	app = unique_app_new(APP_NAME, NULL);
    2.66  	if (unique_app_is_running(app)) {
    2.67  		g_printerr("Another instance of pk-update-icon is already "
    2.68 -		    "running. Exiting.\n");
    2.69 +		    "running, exiting\n");
    2.70  		exitval = 1;
    2.71  		goto out;
    2.72  	}
    2.73  
    2.74  	notify_init(PACKAGE);
    2.75  
    2.76 -	icon = pkui_icon_new(10, 2 * 3600);
    2.77 +	icon = pkui_icon_new(startup_delay, check_interval);
    2.78  
    2.79  	gtk_main();
    2.80  
    2.81  	g_object_unref(icon);
    2.82  out:
    2.83 -	g_object_unref(app);
    2.84 +	if (app != NULL)
    2.85 +		g_object_unref(app);
    2.86  	if (notify_is_initted())
    2.87  		notify_uninit ();
    2.88  
     3.1 --- a/pk-update-icon.1	Thu Oct 20 09:06:52 2011 +0200
     3.2 +++ b/pk-update-icon.1	Thu Oct 20 12:06:42 2011 +0200
     3.3 @@ -16,11 +16,35 @@
     3.4  .\" along with this program; if not, write to the Free Software
     3.5  .\" Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
     3.6  .\"
     3.7 -.TH PK\-UPDATE\-ICON 1 "9 Oct 2011"
     3.8 +.TH PK\-UPDATE\-ICON 1 "20 Oct 2011"
     3.9  .SH NAME
    3.10 -pk\-update\-icon \- display notifications about package updates
    3.11 +pk\-update\-icon \- display notifications about software updates
    3.12  .SH SYNOPSIS
    3.13 -.B pk\-update\-icon
    3.14 +\fBpk\-update\-icon\fR
    3.15 +[\fB\-hv?\fR]
    3.16 +[\fB\-d\fR \fIdelay\fR | \fB\-\-delay\fR=\fIdelay\fR]
    3.17 +[\fB\-i\fR \fIinterval\fR | \fB\-\-interval\fR=\fIinterval\fR]
    3.18  .SH DESCRIPTION
    3.19  \fBpk\-update\-icon\fR displays notifications and an icon in the tray area of
    3.20  the panel when package updates are available.
    3.21 +.SH OPTIONS
    3.22 +The following options are supported:
    3.23 +.TP
    3.24 +.BR \-d ", " \-\-delay =\fIdelay\fR
    3.25 +Set the delay in seconds before the first check for updates.
    3.26 +.TP
    3.27 +.BR \-h ", " \-? ", " \-\-help
    3.28 +Print a summary of all command line options and exit.
    3.29 +.TP
    3.30 +.BR \-i ", " \-\-interval =\fIinterval\fR
    3.31 +Set the interval in seconds between checks for updates.
    3.32 +.TP
    3.33 +.BR \-v ", " \-\-version
    3.34 +Print the version number and exit.
    3.35 +.SH EXIT STATUS
    3.36 +.TP
    3.37 +.B 0
    3.38 +The program has exited normally.
    3.39 +.TP
    3.40 +.B >0
    3.41 +An Error has occurred.
     4.1 --- a/po/de.po	Thu Oct 20 09:06:52 2011 +0200
     4.2 +++ b/po/de.po	Thu Oct 20 12:06:42 2011 +0200
     4.3 @@ -7,7 +7,7 @@
     4.4  msgstr ""
     4.5  "Project-Id-Version: pk-update-icon 0.1\n"
     4.6  "Report-Msgid-Bugs-To: \n"
     4.7 -"POT-Creation-Date: 2011-10-19 23:05+0200\n"
     4.8 +"POT-Creation-Date: 2011-10-20 12:07+0200\n"
     4.9  "PO-Revision-Date: 2011-10-10 19:21+0200\n"
    4.10  "Last-Translator: Guido Berhoerster <gber@opensuse.org>\n"
    4.11  "Language-Team: German\n"
    4.12 @@ -17,40 +17,60 @@
    4.13  "Content-Transfer-Encoding: 8bit\n"
    4.14  "Plural-Forms: nplurals=2; plural=(n != 1);\n"
    4.15  
    4.16 -#: ../pkui-icon.c:86
    4.17 +#: ../main.c:41
    4.18 +msgid "Set the delay in seconds before the first check for updates"
    4.19 +msgstr "Bestimme die Verzögerung in Sekunden vor dem ersten Überprüfen auf Aktualisierungen"
    4.20 +
    4.21 +#: ../main.c:44
    4.22 +msgid "Set the interval in seconds between checks for updates"
    4.23 +msgstr "Bestimme das Intervall in Sekunden zwischen dem Überprüfen auf Aktualisierungen"
    4.24 +
    4.25 +#: ../main.c:47
    4.26 +msgid "Print the version number and exit"
    4.27 +msgstr "Zeige die Versionsnummer und breche ab"
    4.28 +
    4.29 +#: ../main.c:59
    4.30 +msgid "- display notifications about software updates"
    4.31 +msgstr "- zeige Benachrichtigungen über Softwareaktualisierungen"
    4.32 +
    4.33 +#: ../pkui-icon.c:88
    4.34  msgid "Software Updates"
    4.35  msgstr "Softwareaktualisierungen"
    4.36  
    4.37 -#: ../pkui-icon.c:115
    4.38 +#: ../pkui-icon.c:117
    4.39  msgid "_Check for Updates"
    4.40  msgstr "Nach Aktualisierungen _Suchen"
    4.41  
    4.42 -#: ../pkui-icon.c:144
    4.43 +#: ../pkui-icon.c:146
    4.44  msgid "Important Software Update"
    4.45  msgid_plural "Important Software Updates"
    4.46  msgstr[0] "Wichtige Aktualisierung"
    4.47  msgstr[1] "Wichtige Aktualisierungen"
    4.48  
    4.49 -#: ../pkui-icon.c:146
    4.50 +#: ../pkui-icon.c:148
    4.51  msgid "Software Update"
    4.52  msgid_plural "Software Updates"
    4.53  msgstr[0] "Softwareaktualisierung"
    4.54  msgstr[1] "Softwareaktualisierungen"
    4.55  
    4.56 -#: ../pkui-icon.c:153
    4.57 +#: ../pkui-icon.c:155
    4.58 +#, c-format
    4.59  msgid "There are %d software updates available, %d of them is important."
    4.60  msgid_plural ""
    4.61  "There are %d software updates available, %d of them are important."
    4.62 -msgstr[0] "Es sind %d Softwareaktualisierungen verfügbar, davon ist %d wichtig."
    4.63 -msgstr[1] "Es sind %d Softwareaktualisierungen verfügbar, davon sind %d wichtig."
    4.64 +msgstr[0] ""
    4.65 +"Es sind %d Softwareaktualisierungen verfügbar, davon ist %d wichtig."
    4.66 +msgstr[1] ""
    4.67 +"Es sind %d Softwareaktualisierungen verfügbar, davon sind %d wichtig."
    4.68  
    4.69 -#: ../pkui-icon.c:161
    4.70 +#: ../pkui-icon.c:163
    4.71 +#, c-format
    4.72  msgid "There is an important software update available."
    4.73  msgid_plural "There are %d important software updates available."
    4.74  msgstr[0] "Es ist eine wichtige Softwareaktualisierung verfügbar."
    4.75  msgstr[1] "Es sind %d wichtige Softwareaktualisierungen verfügbar."
    4.76  
    4.77 -#: ../pkui-icon.c:166
    4.78 +#: ../pkui-icon.c:168
    4.79  #, c-format
    4.80  msgid "There is a software update available."
    4.81  msgid_plural "There are %d software updates available."