[gnome-packagekit] Check in more places if a user is able to restart before advertising to the user
- From: Richard Hughes <rhughes src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnome-packagekit] Check in more places if a user is able to restart before advertising to the user
- Date: Wed, 19 Aug 2009 13:06:30 +0000 (UTC)
commit 72d53bd7f21ad92eb1cf6949641e123d7f9c2046
Author: Richard Hughes <richard hughsie com>
Date: Wed Aug 19 13:59:05 2009 +0100
Check in more places if a user is able to restart before advertising to the user
src/gpk-update-viewer.c | 18 ++++++++++++++----
src/gpk-watch.c | 17 ++++++++++-------
2 files changed, 24 insertions(+), 11 deletions(-)
---
diff --git a/src/gpk-update-viewer.c b/src/gpk-update-viewer.c
index 0e97573..d8db4c5 100644
--- a/src/gpk-update-viewer.c
+++ b/src/gpk-update-viewer.c
@@ -78,6 +78,7 @@ static PkRestartEnum restart_update = PK_RESTART_ENUM_NONE;
static guint size_total = 0;
static GConfClient *gconf_client = NULL;
static gchar **install_package_ids = NULL;
+static EggConsoleKit *console = NULL;
enum {
GPK_UPDATES_COLUMN_TEXT,
@@ -138,18 +139,15 @@ out:
static void
gpk_update_viewer_shutdown (void)
{
- EggConsoleKit *console;
GError *error = NULL;
gboolean ret;
/* use consolekit to restart */
- console = egg_console_kit_new ();
ret = egg_console_kit_restart (console, &error);
if (!ret) {
egg_warning ("cannot restart: %s", error->message);
g_error_free (error);
}
- g_object_unref (console);
}
/**
@@ -1560,6 +1558,7 @@ gpk_update_viewer_check_restart (PkRestartEnum restart)
const gchar *message;
const gchar *button;
GtkResponseType response;
+ gboolean show_button = TRUE;
/* get the text */
title = gpk_restart_enum_to_localised_text (restart);
@@ -1597,7 +1596,16 @@ gpk_update_viewer_check_restart (PkRestartEnum restart)
dialog = gtk_message_dialog_new (window, GTK_DIALOG_MODAL,
GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE,
"%s", title);
- gtk_dialog_add_button (GTK_DIALOG (dialog), button, GTK_RESPONSE_OK);
+
+ /* check to see if restart is possible */
+ if (restart == PK_RESTART_ENUM_SYSTEM ||
+ restart == PK_RESTART_ENUM_SECURITY_SYSTEM) {
+ egg_console_kit_can_restart (console, &show_button, NULL);
+ }
+
+ /* only show the button if we can do the action */
+ if (show_button)
+ gtk_dialog_add_button (GTK_DIALOG (dialog), button, GTK_RESPONSE_OK);
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG(dialog), "%s", message);
gtk_window_set_icon_name (GTK_WINDOW(dialog), GPK_ICON_SOFTWARE_INSTALLER);
@@ -2855,6 +2863,7 @@ main (int argc, char *argv[])
/* get GConf instance */
gconf_client = gconf_client_get_default ();
+ console = egg_console_kit_new ();
g_signal_connect (unique_app, "message-received", G_CALLBACK (gpk_update_viewer_message_received_cb), NULL);
@@ -3074,6 +3083,7 @@ out_build:
g_object_unref (markdown);
g_object_unref (client_primary);
g_object_unref (client_secondary);
+ g_object_unref (console);
g_object_unref (builder);
unique_out:
g_object_unref (unique_app);
diff --git a/src/gpk-watch.c b/src/gpk-watch.c
index ea2ba29..8448549 100644
--- a/src/gpk-watch.c
+++ b/src/gpk-watch.c
@@ -76,6 +76,7 @@ struct GpkWatchPrivate
guint set_proxy_timeout;
gchar *error_details;
gboolean hide_warning;
+ EggConsoleKit *console;
};
typedef struct {
@@ -1273,20 +1274,17 @@ gpk_watch_menu_log_out_cb (GtkMenuItem *item, gpointer data)
* gpk_watch_menu_restart_cb:
**/
static void
-gpk_watch_menu_restart_cb (GtkMenuItem *item, gpointer data)
+gpk_watch_menu_restart_cb (GtkMenuItem *item, GpkWatch *watch)
{
gboolean ret;
GError *error = NULL;
- EggConsoleKit *console;
/* restart using ConsoleKit */
- console = egg_console_kit_new ();
- ret = egg_console_kit_restart (console, &error);
+ ret = egg_console_kit_restart (watch->priv->console, &error);
if (!ret) {
egg_warning ("restarting failed: %s", error->message);
g_error_free (error);
}
- g_object_unref (console);
}
/**
@@ -1303,6 +1301,7 @@ gpk_watch_activate_status_cb (GtkStatusIcon *status_icon, GpkWatch *watch)
GtkWidget *image;
guint len;
gboolean show_hide = FALSE;
+ gboolean can_restart = FALSE;
g_return_if_fail (GPK_IS_WATCH (watch));
@@ -1338,8 +1337,10 @@ gpk_watch_activate_status_cb (GtkStatusIcon *status_icon, GpkWatch *watch)
}
/* restart computer */
- if (watch->priv->restart == PK_RESTART_ENUM_SYSTEM ||
- watch->priv->restart == PK_RESTART_ENUM_SECURITY_SYSTEM) {
+ egg_console_kit_can_restart (watch->priv->console, &can_restart, NULL);
+ if (can_restart &&
+ (watch->priv->restart == PK_RESTART_ENUM_SYSTEM ||
+ watch->priv->restart == PK_RESTART_ENUM_SECURITY_SYSTEM)) {
/* TRANSLATORS: this menu item restarts the computer after an update */
widget = gtk_image_menu_item_new_with_mnemonic (_("_Restart computer"));
image = gtk_image_new_from_icon_name ("system-shutdown", GTK_ICON_SIZE_MENU);
@@ -1644,6 +1645,7 @@ gpk_watch_init (GpkWatch *watch)
watch->priv->notification_cached_messages = NULL;
watch->priv->restart = PK_RESTART_ENUM_NONE;
watch->priv->hide_warning = FALSE;
+ watch->priv->console = egg_console_kit_new ();
watch->priv->gconf_client = gconf_client_get_default ();
@@ -1753,6 +1755,7 @@ gpk_watch_finalize (GObject *object)
g_object_unref (watch->priv->gconf_client);
g_object_unref (watch->priv->client_primary);
g_object_unref (watch->priv->dialog);
+ g_object_unref (watch->priv->console);
G_OBJECT_CLASS (gpk_watch_parent_class)->finalize (object);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]