Mercurial > projects > pk-update-icon
diff pkui-icon.c @ 46:aa5d3752091d
Make the update viewer command configurable
Make the update viewer command configurable at copile time through the
UPDATE_VIEWER_COMMAND macro.
Make the update viewer command configurable at run time through the
-c/--command command line option.
Treat the update viewer command as a shell command and parse it via
g_shell_parse_argv(), this allows for running the update viewer via xdg-su,
gnomesu, pkexec etc.
Disable install action in the notification and on the status icon in case no
update viewer command has been provided.
author | Guido Berhoerster <gber@opensuse.org> |
---|---|
date | Thu, 18 Jun 2015 14:10:57 +0200 |
parents | f6edbee6441f |
children | 1eb92ab03287 |
line wrap: on
line diff
--- a/pkui-icon.c Thu Jun 18 13:35:55 2015 +0200 +++ b/pkui-icon.c Thu Jun 18 14:10:57 2015 +0200 @@ -25,7 +25,9 @@ G_DEFINE_TYPE(PkuiIcon, pkui_icon, G_TYPE_OBJECT) -#define UPDATE_VIEWER_COMMAND "/usr/bin/gpk-update-viewer" +#ifndef UPDATE_VIEWER_COMMAND +#define UPDATE_VIEWER_COMMAND "" +#endif /* UPDATE_VIEWER_COMMAND */ #define PKUI_ICON_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), \ PKUI_TYPE_ICON, PkuiIconPrivate)) @@ -37,6 +39,7 @@ GtkStatusIcon *status_icon; GtkWidget *status_icon_popup_menu; NotifyNotification *notification; + gchar *update_viewer_command; }; static GtkWidget* icon_popup_menu_create(PkuiIcon *self); @@ -60,6 +63,7 @@ g_object_unref(self->priv->notification); } g_object_unref(self->priv->backend); + g_free(self->priv->update_viewer_command); G_OBJECT_CLASS(pkui_icon_parent_class)->finalize(gobject); } @@ -97,23 +101,34 @@ self->priv->notification = NULL; self->priv->backend = NULL; + + self->priv->update_viewer_command = NULL; } static void exec_update_viewer(PkuiIcon *self) { - static const gchar *argv[] = { UPDATE_VIEWER_COMMAND, NULL }; + gchar **argv = NULL; + GError *error = NULL; GPid pid; - gboolean retval; g_return_if_fail(PKUI_IS_BACKEND(self->priv->backend)); + g_return_if_fail(self->priv->update_viewer_command != NULL); - g_debug("executing " UPDATE_VIEWER_COMMAND); + g_debug("executing command %s", self->priv->update_viewer_command); - retval = g_spawn_async(NULL, (gchar **)argv, NULL, - G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, &pid, NULL); - if (!retval) { - g_warning("Could not execute" UPDATE_VIEWER_COMMAND); + if (!g_shell_parse_argv(self->priv->update_viewer_command, NULL, + &argv, &error)) { + g_warning("Could not parse command: %s", error->message); + g_error_free(error); + return; + } + + if (!g_spawn_async(NULL, argv, NULL, + G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH, NULL, NULL, &pid, + &error)) { + g_warning("Could not execute command: %s", error->message); + g_error_free(error); return; } g_child_watch_add(pid, (GChildWatchFunc)update_viewer_exited, self); @@ -215,8 +230,9 @@ { PkuiIcon *self = PKUI_ICON(user_data); - if (strcmp(action, "install-updates") == 0) + if (strcmp(action, "install-updates") == 0) { exec_update_viewer(self); + } } static void @@ -262,10 +278,13 @@ , NULL #endif ); - notify_notification_add_action(self->priv->notification, - "install-updates", ngettext("Install Update", - "Install Updates", updates_normal + updates_important), - notification_handle_action, self, NULL); + if (self->priv->update_viewer_command != NULL) { + notify_notification_add_action(self->priv->notification, + "install-updates", ngettext("Install Update", + "Install Updates", + updates_normal + updates_important), + notification_handle_action, self, NULL); + } } else notify_notification_update(self->priv->notification, title, message, icon); @@ -323,14 +342,19 @@ { PkuiIcon *self = PKUI_ICON(user_data); - exec_update_viewer(self); + if (self->priv->update_viewer_command != NULL) { + exec_update_viewer(self); + } } PkuiIcon * -pkui_icon_new(guint startup_delay, guint check_interval) +pkui_icon_new(guint startup_delay, guint check_interval, + const gchar *update_viewer_command) { PkuiIcon *icon = g_object_new(PKUI_TYPE_ICON, NULL); + icon->priv->update_viewer_command = g_strdup((update_viewer_command != + NULL) ? update_viewer_command : UPDATE_VIEWER_COMMAND); icon->priv->backend = pkui_backend_new(startup_delay, check_interval); g_signal_connect(icon->priv->backend, "state-changed", G_CALLBACK(backend_state_changed), icon);