aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--configure.ac6
-rw-r--r--src/Makefile.am4
-rw-r--r--src/apt-transaction.c263
-rw-r--r--src/apt-transaction.h49
-rw-r--r--src/apt-watcher.c511
-rw-r--r--src/apt-watcher.h2
-rw-r--r--src/user-widget.c2
7 files changed, 160 insertions, 677 deletions
diff --git a/configure.ac b/configure.ac
index 1a53757..7fa6b48 100644
--- a/configure.ac
+++ b/configure.ac
@@ -63,7 +63,8 @@ AS_IF([test "x$with_gtk" = x3],
dbus-glib-1
gudev-1.0
gio-unix-2.0
- indicator3-0.4 >= $INDICATOR_REQUIRED_VERSION)
+ indicator3-0.4 >= $INDICATOR_REQUIRED_VERSION
+ packagekit-glib2)
],
[test "x$with_gtk" = x2],
[PKG_CHECK_MODULES(SESSIONSERVICE, dbusmenu-glib-0.4 >= $DBUSMENUGLIB_REQUIRED_VERSION
@@ -71,7 +72,8 @@ AS_IF([test "x$with_gtk" = x3],
gudev-1.0
dbus-glib-1
gio-unix-2.0
- indicator-0.4 >= $INDICATOR_REQUIRED_VERSION)
+ indicator-0.4 >= $INDICATOR_REQUIRED_VERSION
+ packagekit-glib2)
]
)
diff --git a/src/Makefile.am b/src/Makefile.am
index afee66c..67a1cb6 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -114,9 +114,7 @@ indicator_session_service_SOURCES = \
if BUILD_APT
indicator_session_service_SOURCES += \
apt-watcher.h \
- apt-watcher.c \
- apt-transaction.h \
- apt-transaction.c
+ apt-watcher.c
endif
indicator_session_service_CFLAGS = \
diff --git a/src/apt-transaction.c b/src/apt-transaction.c
deleted file mode 100644
index 2b3f5a4..0000000
--- a/src/apt-transaction.c
+++ /dev/null
@@ -1,263 +0,0 @@
-/*
-Copyright 2011 Canonical Ltd.
-
-Authors:
- Conor Curran <conor.curran@canonical.com>
-
-This program is free software: you can redistribute it and/or modify it
-under the terms of the GNU General Public License version 3, as published
-by the Free Software Foundation.
-
-This program is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranties of
-MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
-PURPOSE. See the GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License along
-with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#include <gio/gio.h>
-
-#include "apt-transaction.h"
-#include "dbus-shared-names.h"
-
-static void apt_transaction_investigate (AptTransaction* self);
-static void apt_transaction_simulate_transaction_cb (GObject * obj,
- GAsyncResult * res,
- gpointer user_data);
-static void apt_transaction_receive_signal (GDBusProxy * proxy,
- gchar * sender_name,
- gchar * signal_name,
- GVariant * parameters,
- gpointer user_data);
-static void apt_transaction_finish_proxy_setup (GObject *source_object,
- GAsyncResult *res,
- gpointer user_data);
-
-struct _AptTransaction
-{
- GObject parent_instance;
- GDBusProxy * proxy;
- GCancellable * proxy_cancel;
- gchar* id;
- TransactionType type;
-};
-
-enum {
- UPDATE,
- LAST_SIGNAL
-};
-
-static guint signals[LAST_SIGNAL] = { 0 };
-
-G_DEFINE_TYPE (AptTransaction, apt_transaction, G_TYPE_OBJECT);
-
-static void
-apt_transaction_init (AptTransaction *self)
-{
- self->proxy = NULL;
- self->id = NULL;
- self->proxy_cancel = g_cancellable_new();
-}
-
-static void
-apt_transaction_finalize (GObject *object)
-{
- AptTransaction* self = APT_TRANSACTION(object);
- g_signal_handlers_disconnect_by_func (G_OBJECT (self->proxy),
- G_CALLBACK (apt_transaction_receive_signal),
- self);
- if (self->proxy != NULL){
- g_object_unref (self->proxy);
- self->proxy = NULL;
- }
- g_free (self->id);
- G_OBJECT_CLASS (apt_transaction_parent_class)->finalize (object);
-}
-
-static void
-apt_transaction_class_init (AptTransactionClass *klass)
-{
- GObjectClass* object_class = G_OBJECT_CLASS (klass);
- object_class->finalize = apt_transaction_finalize;
-
- signals[UPDATE] = g_signal_new("state-update",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST,
- 0,
- NULL, NULL,
- g_cclosure_marshal_VOID__INT,
- G_TYPE_NONE, 1, G_TYPE_INT);
-}
-
-// TODO: you don't need this additional helper
-// Just GObject properties properly
-static void
-apt_transaction_investigate (AptTransaction* self)
-{
- g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
- G_DBUS_PROXY_FLAGS_NONE,
- NULL,
- "org.debian.apt",
- self->id,
- "org.debian.apt.transaction",
- self->proxy_cancel,
- apt_transaction_finish_proxy_setup,
- self);
-}
-
-static void
-apt_transaction_finish_proxy_setup (GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
-{
- g_return_if_fail (APT_IS_TRANSACTION (user_data));
- AptTransaction* self = APT_TRANSACTION(user_data);
- GError * error = NULL;
-
- GDBusProxy * proxy = g_dbus_proxy_new_for_bus_finish(res, &error);
-
- if (self->proxy_cancel != NULL) {
- g_object_unref(self->proxy_cancel);
- self->proxy_cancel = NULL;
- }
-
- if (error != NULL) {
- g_warning("Could not grab DBus proxy for %s: %s",
- "org.debian.apt", error->message);
- g_error_free(error);
- return;
- }
-
- self->proxy = proxy;
-
- g_signal_connect (G_OBJECT(self->proxy),
- "g-signal",
- G_CALLBACK (apt_transaction_receive_signal),
- self);
-
- if (self->type == SIMULATION){
- g_dbus_proxy_call (self->proxy,
- "Simulate",
- NULL,
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- apt_transaction_simulate_transaction_cb,
- self);
- }
-}
-
-static void
-apt_transaction_receive_signal (GDBusProxy * proxy,
- gchar * sender_name,
- gchar * signal_name,
- GVariant * parameters,
- gpointer user_data)
-{
- g_return_if_fail (APT_IS_TRANSACTION (user_data));
- AptTransaction* self = APT_TRANSACTION(user_data);
- AptState current_state = DONT_KNOW;
-
- if (g_strcmp0(signal_name, "PropertyChanged") == 0)
- {
- gchar* prop_name= NULL;
- GVariant* value = NULL;
- g_variant_get (parameters, "(sv)", &prop_name, &value);
- g_debug ("transaction prop update - prop = %s", prop_name);
-
- if (g_variant_is_of_type (value, G_VARIANT_TYPE_STRING) == TRUE){
- gchar* key = NULL;
- g_variant_get (value, "s", &key);
- g_debug ("transaction prop update - value = %s", key);
- }
-
- if (g_strcmp0 (prop_name, "Dependencies") == 0){
-
- gchar** install = NULL;
- gchar** reinstall = NULL;
- gchar** remove = NULL;
- gchar** purge = NULL;
- gchar** upgrade = NULL;
- gchar** downgrade = NULL;
- gchar** keep = NULL;
- g_variant_get (value, "(asasasasasasas)", &install,
- &reinstall, &remove, &purge, &upgrade, &downgrade,
- &keep);
- /*
- g_debug ("upgrade package length %i", g_strv_length(upgrade));
- g_debug ("install package length %i", g_strv_length(install));
- g_debug ("reinstall package length %i", g_strv_length(reinstall));
- g_debug ("remove package length %i", g_strv_length(remove));
- g_debug ("purge package length %i", g_strv_length(purge));
- */
- gboolean upgrade_needed = (g_strv_length(upgrade) > 1) ||
- (g_strv_length(install) > 1) ||
- (g_strv_length(reinstall) > 1) ||
- (g_strv_length(remove) > 1) ||
- (g_strv_length(purge) > 1);
- if (upgrade_needed == TRUE){
- current_state = UPDATES_AVAILABLE;
- }
- else{
- current_state = UP_TO_DATE;
- }
- }
- if (self->type == REAL)
- {
- GVariant* role = g_dbus_proxy_get_cached_property (self->proxy,
- "Role");
- if (g_variant_is_of_type (role, G_VARIANT_TYPE_STRING) == TRUE){
- gchar* current_role = NULL;
- g_variant_get (role, "s", &current_role);
- //g_debug ("Current transaction role = %s", current_role);
- if (g_strcmp0 (current_role, "role-commit-packages") == 0 ||
- g_strcmp0 (current_role, "role-upgrade-system") == 0){
- g_debug ("UPGRADE IN PROGRESS");
- current_state = UPGRADE_IN_PROGRESS;
- }
- }
- }
- }
- else if (g_strcmp0(signal_name, "Finished") == 0)
- {
- g_debug ("TRANSACTION Finished");
- current_state = FINISHED;
- }
- // Finally send out the state update
- if (current_state != DONT_KNOW){
- g_signal_emit (self,
- signals[UPDATE],
- 0,
- current_state);
- }
-}
-
-static void
-apt_transaction_simulate_transaction_cb (GObject * obj,
- GAsyncResult * res,
- gpointer user_data)
-{
- GError * error = NULL;
- if (error != NULL) {
- g_warning ("unable to complete the simulate call");
- g_error_free (error);
- return;
- }
-}
-TransactionType
-apt_transaction_get_transaction_type (AptTransaction* self)
-{
- return self->type;
-}
-
-AptTransaction* apt_transaction_new (gchar* transaction_id, TransactionType t)
-{
- AptTransaction* tr = g_object_new (APT_TYPE_TRANSACTION, NULL);
- tr->id = transaction_id;
- tr->type = t;
- g_debug ("Apt transaction new id = %s", tr->id);
- apt_transaction_investigate (tr);
- return tr;
-}
diff --git a/src/apt-transaction.h b/src/apt-transaction.h
deleted file mode 100644
index 9e4370d..0000000
--- a/src/apt-transaction.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
-Copyright 2011 Canonical Ltd.
-
-Authors:
- Conor Curran <conor.curran@canonical.com>
-
-This program is free software: you can redistribute it and/or modify it
-under the terms of the GNU General Public License version 3, as published
-by the Free Software Foundation.
-
-This program is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranties of
-MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
-PURPOSE. See the GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License along
-with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#ifndef _APT_TRANSACTION_H_
-#define _APT_TRANSACTION_H_
-
-#include <glib-object.h>
-#include "dbus-shared-names.h"
-
-G_BEGIN_DECLS
-
-#define APT_TYPE_TRANSACTION (apt_transaction_get_type ())
-#define APT_TRANSACTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), APT_TYPE_TRANSACTION, AptTransaction))
-#define APT_TRANSACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), APT_TYPE_TRANSACTION, AptTransactionClass))
-#define APT_IS_TRANSACTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), APT_TYPE_TRANSACTION))
-#define APT_IS_TRANSACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), APT_TYPE_TRANSACTION))
-#define APT_TRANSACTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), APT_TYPE_TRANSACTION, AptTransactionClass))
-
-typedef struct _AptTransactionClass AptTransactionClass;
-typedef struct _AptTransaction AptTransaction;
-
-struct _AptTransactionClass
-{
- GObjectClass parent_class;
-};
-
-AptTransaction* apt_transaction_new (gchar* transaction_id, TransactionType t);
-TransactionType apt_transaction_get_transaction_type (AptTransaction* self);
-GType apt_transaction_get_type (void) G_GNUC_CONST;
-
-G_END_DECLS
-
-#endif /* _APT_TRANSACTION_H_ */
diff --git a/src/apt-watcher.c b/src/apt-watcher.c
index 481029a..4e69ee6 100644
--- a/src/apt-watcher.c
+++ b/src/apt-watcher.c
@@ -17,150 +17,120 @@ You should have received a copy of the GNU General Public License along
with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include <gio/gio.h>
+// Conor - 6/2/2012
+// Please pull in packagekit's client lib
+// using apt-get install --no-install-recommends libpackagekit-glib2-dev
+// make sure you don't install package-kit
+#define I_KNOW_THE_PACKAGEKIT_GLIB2_API_IS_SUBJECT_TO_CHANGE
+
#include <glib/gi18n.h>
+#include <packagekit-glib2/packagekit.h>
#include "apt-watcher.h"
-#include "apt-transaction.h"
+#include "dbus-shared-names.h"
static guint watcher_id;
struct _AptWatcher
{
GObject parent_instance;
- guint reboot_query;
- GCancellable * proxy_cancel;
- GDBusProxy * proxy;
SessionDbus* session_dbus_interface;
DbusmenuMenuitem* apt_item;
AptState current_state;
- AptTransaction* current_transaction;
+ GCancellable * proxy_cancel;
+ GDBusProxy * proxy;
};
-
-static void
-apt_watcher_on_name_appeared (GDBusConnection *connection,
- const gchar *name,
- const gchar *name_owner,
- gpointer user_data);
-static void
-apt_watcher_on_name_vanished (GDBusConnection *connection,
- const gchar *name,
- gpointer user_data);
-static void fetch_proxy_cb (GObject * object,
- GAsyncResult * res,
- gpointer user_data);
-
-static void apt_watcher_upgrade_system_cb (GObject * obj,
- GAsyncResult * res,
- gpointer user_data);
-
-
-static void apt_watcher_show_apt_dialog (DbusmenuMenuitem* mi,
- guint timestamp,
- gpointer userdata);
-
-static void apt_watcher_signal_cb (GDBusProxy* proxy,
- gchar* sender_name,
- gchar* signal_name,
- GVariant* parameters,
- gpointer user_data);
-static void apt_watcher_manage_transactions (AptWatcher* self,
- gchar* transaction_id);
-static gboolean apt_watcher_query_reboot_status (gpointer self);
-static void apt_watcher_transaction_state_simulation_update_cb (AptTransaction* trans,
- gint update,
- gpointer user_data);
-static void apt_watcher_transaction_state_real_update_cb (AptTransaction* trans,
- gint update,
- gpointer user_data);
-static gboolean apt_watcher_start_apt_interaction (gpointer data);
-
+
G_DEFINE_TYPE (AptWatcher, apt_watcher, G_TYPE_OBJECT);
+
static void
-apt_watcher_init (AptWatcher *self)
+get_updates_complete (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
{
- self->current_state = UP_TO_DATE;
- self->proxy_cancel = g_cancellable_new();
- self->proxy = NULL;
- self->reboot_query = 0;
- self->current_transaction = NULL;
- g_timeout_add_seconds (60,
- apt_watcher_start_apt_interaction,
- self);
-}
+ g_return_if_fail (APT_IS_WATCHER (user_data));
+ AptWatcher* self = APT_WATCHER (user_data);
-static gboolean
-apt_watcher_start_apt_interaction (gpointer data)
-{
- g_return_val_if_fail (APT_IS_WATCHER (data), FALSE);
- AptWatcher* self = APT_WATCHER (data);
- g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
- G_DBUS_PROXY_FLAGS_NONE,
- NULL,
- "org.debian.apt",
- "/org/debian/apt",
- "org.debian.apt",
- self->proxy_cancel,
- fetch_proxy_cb,
- self);
- return FALSE;
-}
+ PkResults *results;
+
+ results = pk_client_generic_finish (PK_CLIENT(source_object), res, NULL);
+
+ if (results == NULL){
+ g_warning ("Unable to query for updates - results were NULL ?");
+ return;
+ }
-static void
-apt_watcher_finalize (GObject *object)
-{
- g_bus_unwatch_name (watcher_id);
- AptWatcher* self = APT_WATCHER (object);
-
- if (self->proxy != NULL)
- g_object_unref (self->proxy);
+ GPtrArray *packages;
+ packages = pk_results_get_package_array (results);
+
+ const gchar* disposition;
+ disposition = dbusmenu_menuitem_property_get (self->apt_item,
+ DBUSMENU_MENUITEM_PROP_DISPOSITION);
+ gboolean do_update;
+ do_update = g_strcmp0 (disposition, DBUSMENU_MENUITEM_DISPOSITION_ALERT) != 0;
- G_OBJECT_CLASS (apt_watcher_parent_class)->finalize (object);
+ if (packages->len > 0){
+ g_print ("Apparently we have updates available - change dbmitem %i", do_update);
+ if (do_update)
+ dbusmenu_menuitem_property_set (self->apt_item,
+ DBUSMENU_MENUITEM_PROP_LABEL,
+ _("Updates Available…"));
+ }
+ else{
+ g_print ("No updates available - change dbmitem - %i", do_update);
+ if (do_update)
+ dbusmenu_menuitem_property_set (self->apt_item,
+ DBUSMENU_MENUITEM_PROP_LABEL,
+ _("Software Up to Date"));
+ }
+ g_ptr_array_unref (packages);
+ g_object_unref (results);
+ g_object_unref (source_object);
}
static void
-apt_watcher_class_init (AptWatcherClass *klass)
+apt_watcher_check_for_updates (AptWatcher* self)
{
- GObjectClass* object_class = G_OBJECT_CLASS (klass);
- object_class->finalize = apt_watcher_finalize;
+ PkClient* client;
+ client = pk_client_new ();
+
+ pk_client_get_updates_async (client,
+ PK_FILTER_ENUM_NONE,
+ NULL, NULL, NULL,
+ (GAsyncReadyCallback)get_updates_complete,
+ self);
}
-static void
-fetch_proxy_cb (GObject * object, GAsyncResult * res, gpointer user_data)
+static void apt_watcher_signal_cb ( GDBusProxy* proxy,
+ gchar* sender_name,
+ gchar* signal_name,
+ GVariant* parameters,
+ gpointer user_data)
{
- GError * error = NULL;
-
- AptWatcher* self = APT_WATCHER(user_data);
- g_return_if_fail(self != NULL);
-
- GDBusProxy * proxy = g_dbus_proxy_new_for_bus_finish(res, &error);
-
- if (self->proxy_cancel != NULL) {
- g_object_unref(self->proxy_cancel);
- self->proxy_cancel = NULL;
- }
+ g_return_if_fail (APT_IS_WATCHER (user_data));
+ AptWatcher* self = APT_WATCHER (user_data);
- if (error != NULL) {
- g_warning("Could not grab DBus proxy for %s: %s",
- "org.debian.apt", error->message);
- g_error_free(error);
- return;
- }
+ g_variant_ref_sink (parameters);
+ g_debug ("apt-watcher-signal cb signal name - %s", signal_name);
+ if (g_strcmp0(signal_name, "UpdatesChanged") == 0){
+ g_debug ("updates changed signal received");
+ apt_watcher_check_for_updates (self);
+ }
+ else if (g_strcmp0(signal_name, "RestartScheduled") == 0) {
+ g_debug ("RestartScheduled signal received");
+ dbusmenu_menuitem_property_set (self->apt_item,
+ DBUSMENU_MENUITEM_PROP_LABEL,
+ _("Restart to Complete Updates…"));
+ dbusmenu_menuitem_property_set (self->apt_item,
+ DBUSMENU_MENUITEM_PROP_DISPOSITION,
+ DBUSMENU_MENUITEM_DISPOSITION_ALERT);
+ }
+ else if (g_strcmp0(signal_name, "TransactionListChanged") == 0) {
+ GVariant *value = g_variant_get_child_value (parameters, 0);
+ g_variant_unref (value);
- self->proxy = proxy;
- // Set up the watch.
- watcher_id = g_bus_watch_name (G_BUS_TYPE_SYSTEM,
- "org.debian.apt",
- G_BUS_NAME_WATCHER_FLAGS_NONE,
- apt_watcher_on_name_appeared,
- apt_watcher_on_name_vanished,
- self,
- NULL);
-
- g_signal_connect (self->proxy,
- "g-signal",
- G_CALLBACK(apt_watcher_signal_cb),
- self);
+ }
+ g_variant_unref (parameters);
}
static void
@@ -170,21 +140,12 @@ apt_watcher_on_name_appeared (GDBusConnection *connection,
gpointer user_data)
{
g_return_if_fail (APT_IS_WATCHER (user_data));
- AptWatcher* watcher = APT_WATCHER (user_data);
+ // AptWatcher* watcher = APT_WATCHER (user_data);
g_print ("Name %s on %s is owned by %s\n",
name,
"the system bus",
name_owner);
-
- g_dbus_proxy_call (watcher->proxy,
- "UpgradeSystem",
- g_variant_new("(b)", TRUE),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- apt_watcher_upgrade_system_cb,
- user_data);
}
@@ -199,36 +160,61 @@ apt_watcher_on_name_vanished (GDBusConnection *connection,
}
static void
-apt_watcher_upgrade_system_cb (GObject * obj,
- GAsyncResult * res,
- gpointer user_data)
+fetch_proxy_cb (GObject * object, GAsyncResult * res, gpointer user_data)
{
- g_return_if_fail (APT_IS_WATCHER (user_data));
- AptWatcher* self = APT_WATCHER (user_data);
+ GError * error = NULL;
- GError * error = NULL;
- GVariant * result;
+ AptWatcher* self = APT_WATCHER(user_data);
+ g_return_if_fail(self != NULL);
- result = g_dbus_proxy_call_finish(self->proxy, res, &error);
+ GDBusProxy * proxy = g_dbus_proxy_new_for_bus_finish (res, &error);
- if (error != NULL) {
- g_warning ("unable to complete the UpgradeSystem apt call");
- g_error_free (error);
- return;
- }
-
- gchar* transaction_id = NULL;
- g_variant_get (result, "(s)", &transaction_id);
+ if (self->proxy_cancel != NULL) {
+ g_object_unref (self->proxy_cancel);
+ self->proxy_cancel = NULL;
+ }
- if (transaction_id == NULL){
- g_warning ("apt_watcher_upgrade_system_cb - transaction id is null");
+ if (error != NULL) {
+ g_warning("Could not grab DBus proxy for %s: %s",
+ "org.debian.apt", error->message);
+ g_error_free(error);
return;
- }
-
- apt_watcher_manage_transactions (self, transaction_id);
-
+ }
+
+ self->proxy = proxy;
+ // Set up the watch.
+ watcher_id = g_bus_watch_name (G_BUS_TYPE_SYSTEM,
+ "org.freedesktop.PackageKit",
+ G_BUS_NAME_WATCHER_FLAGS_NONE,
+ apt_watcher_on_name_appeared,
+ apt_watcher_on_name_vanished,
+ self,
+ NULL);
+ g_signal_connect (self->proxy,
+ "g-signal",
+ G_CALLBACK(apt_watcher_signal_cb),
+ self);
+}
+
+static gboolean
+apt_watcher_start_apt_interaction (gpointer data)
+{
+ g_return_val_if_fail (APT_IS_WATCHER (data), FALSE);
+ AptWatcher* self = APT_WATCHER (data);
+ g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
+ G_DBUS_PROXY_FLAGS_NONE,
+ NULL,
+ "org.freedesktop.PackageKit",
+ "/org/freedesktop/PackageKit",
+ "org.freedesktop.PackageKit",
+ self->proxy_cancel,
+ fetch_proxy_cb,
+ self);
+ apt_watcher_check_for_updates (self);
+ return FALSE;
}
+
static void
apt_watcher_show_apt_dialog (DbusmenuMenuitem * mi,
guint timestamp,
@@ -261,224 +247,31 @@ apt_watcher_show_apt_dialog (DbusmenuMenuitem * mi,
}
static void
-apt_watcher_transaction_state_real_update_cb (AptTransaction* trans,
- gint update,
- gpointer user_data)
-{
- g_debug ("apt-watcher -transaction update %i", update);
- g_return_if_fail (APT_IS_WATCHER (user_data));
- AptWatcher* self = APT_WATCHER (user_data);
-
- AptState state = (AptState)update;
- if (self->current_state != RESTART_NEEDED)
- {
- if (state == UP_TO_DATE){
- dbusmenu_menuitem_property_set (self->apt_item,
- DBUSMENU_MENUITEM_PROP_LABEL,
- _("Software Up to Date"));
- self->current_state = state;
- }
- else if (state == UPDATES_AVAILABLE){
- dbusmenu_menuitem_property_set (self->apt_item,
- DBUSMENU_MENUITEM_PROP_LABEL,
- _("Updates Available…"));
- self->current_state = state;
- }
- else if (state == UPGRADE_IN_PROGRESS){
- dbusmenu_menuitem_property_set (self->apt_item,
- DBUSMENU_MENUITEM_PROP_LABEL,
- _("Updates Installing…"));
- self->current_state = state;
- }
- else if (state == FINISHED){
- gboolean query_again = FALSE;
-
- // Only query if the previous state was an upgrade.
- if (self->current_state != UPGRADE_IN_PROGRESS){
- query_again = TRUE;
- }
- else{
- if (self->reboot_query != 0){
- g_source_remove (self->reboot_query);
- self->reboot_query = 0;
- }
- self->reboot_query = g_timeout_add_seconds (1,
- apt_watcher_query_reboot_status,
- self);
- }
- self->current_state = state;
-
- g_object_unref (G_OBJECT(self->current_transaction));
- self->current_transaction = NULL;
-
- // It is impossible to determine from a 'real' transaction whether
- // updates are available therefore it is necessary to check again via a
- // simulation whether there are updates available.
- if (query_again){
- g_dbus_proxy_call (self->proxy,
- "UpgradeSystem",
- g_variant_new("(b)", TRUE),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- apt_watcher_upgrade_system_cb,
- self);
- }
- }
- }
-}
-
-
-static void
-apt_watcher_transaction_state_simulation_update_cb (AptTransaction* trans,
- gint update,
- gpointer user_data)
-{
- g_debug ("apt-watcher -transaction update %i", update);
- g_return_if_fail (APT_IS_WATCHER (user_data));
- AptWatcher* self = APT_WATCHER (user_data);
-
- AptState state = (AptState)update;
- if (self->current_state != RESTART_NEEDED)
- {
- if (state == UP_TO_DATE){
- dbusmenu_menuitem_property_set (self->apt_item,
- DBUSMENU_MENUITEM_PROP_LABEL,
- _("Software Up to Date"));
- if (self->reboot_query != 0){
- g_source_remove (self->reboot_query);
- self->reboot_query = 0;
- }
- self->reboot_query = g_timeout_add_seconds (1,
- apt_watcher_query_reboot_status,
- self);
- }
- else if (state == UPDATES_AVAILABLE){
- dbusmenu_menuitem_property_set (self->apt_item,
- DBUSMENU_MENUITEM_PROP_LABEL,
- _("Updates Available…"));
- }
- else if (state == UPGRADE_IN_PROGRESS){
- dbusmenu_menuitem_property_set (self->apt_item,
- DBUSMENU_MENUITEM_PROP_LABEL,
- _("Updates Installing…"));
- }
- self->current_state = state;
- }
- if (self->current_state != UPGRADE_IN_PROGRESS){
- g_object_unref (G_OBJECT(self->current_transaction));
- self->current_transaction = NULL;
- }
-}
-
-static void
-apt_watcher_manage_transactions (AptWatcher* self, gchar* transaction_id)
+apt_watcher_init (AptWatcher *self)
{
- if (self->current_transaction == NULL){
- self->current_transaction = apt_transaction_new (transaction_id, SIMULATION);
- g_signal_connect (G_OBJECT(self->current_transaction),
- "state-update",
- G_CALLBACK(apt_watcher_transaction_state_simulation_update_cb), self);
- }
+ self->current_state = UP_TO_DATE;
+ g_timeout_add_seconds (60,
+ apt_watcher_start_apt_interaction,
+ self);
}
-static gboolean
-apt_watcher_query_reboot_status (gpointer data)
+static void
+apt_watcher_finalize (GObject *object)
{
- g_return_val_if_fail (APT_IS_WATCHER (data), FALSE);
- AptWatcher* self = APT_WATCHER (data);
-
- GVariant* reboot_result = g_dbus_proxy_get_cached_property (self->proxy,
- "RebootRequired");
- gboolean reboot = FALSE;
- g_variant_get (reboot_result, "b", &reboot);
- g_debug ("apt_watcher_query_reboot_status: reboot prop = %i", reboot);
- if (reboot == FALSE){
- dbusmenu_menuitem_property_set (self->apt_item,
- DBUSMENU_MENUITEM_PROP_LABEL,
- _("Software Up to Date"));
- dbusmenu_menuitem_property_set (self->apt_item,
- DBUSMENU_MENUITEM_PROP_DISPOSITION,
- DBUSMENU_MENUITEM_DISPOSITION_NORMAL);
-
- }
- else{
- dbusmenu_menuitem_property_set (self->apt_item,
- DBUSMENU_MENUITEM_PROP_LABEL,
- _("Restart to Complete Updates…"));
- dbusmenu_menuitem_property_set (self->apt_item,
- DBUSMENU_MENUITEM_PROP_DISPOSITION,
- DBUSMENU_MENUITEM_DISPOSITION_ALERT);
- session_dbus_restart_required (self->session_dbus_interface);
- self->current_state = RESTART_NEEDED;
- }
- self->reboot_query = 0;
- return FALSE;
+ g_bus_unwatch_name (watcher_id);
+ AptWatcher* self = APT_WATCHER (object);
+
+ if (self->proxy != NULL)
+ g_object_unref (self->proxy);
+
+ G_OBJECT_CLASS (apt_watcher_parent_class)->finalize (object);
}
-static void apt_watcher_signal_cb ( GDBusProxy* proxy,
- gchar* sender_name,
- gchar* signal_name,
- GVariant* parameters,
- gpointer user_data)
+static void
+apt_watcher_class_init (AptWatcherClass *klass)
{
- g_return_if_fail (APT_IS_WATCHER (user_data));
- AptWatcher* self = APT_WATCHER (user_data);
-
- g_variant_ref_sink (parameters);
- GVariant *value = g_variant_get_child_value (parameters, 0);
-
- if (g_strcmp0(signal_name, "ActiveTransactionsChanged") == 0){
- gchar* current = NULL;
- g_debug ("ActiveTransactionsChanged");
-
- g_variant_get(value, "s", &current);
-
- if (g_str_has_prefix (current, "/org/debian/apt/transaction/") == TRUE){
- g_debug ("ActiveTransactionsChanged - current is %s", current);
-
- // Cancel all existing operations.
- if (self->reboot_query != 0){
- g_source_remove (self->reboot_query);
- self->reboot_query = 0;
- }
-
- if (self->current_transaction != NULL)
- {
- g_object_unref (G_OBJECT(self->current_transaction));
- self->current_transaction = NULL;
- }
-
- self->current_transaction = apt_transaction_new (current, REAL);
- g_signal_connect (G_OBJECT(self->current_transaction),
- "state-update",
- G_CALLBACK(apt_watcher_transaction_state_real_update_cb), self);
- }
- }
- else if (g_strcmp0(signal_name, "PropertyChanged") == 0)
- {
- gchar* prop_name= NULL;
- GVariant* value = NULL;
- g_variant_get (parameters, "(sv)", &prop_name, &value);
- g_debug ("transaction prop update - prop = %s", prop_name);
-
- if (g_strcmp0 (prop_name, "RebootRequired") == 0){
- gboolean reboot_required = FALSE;
- g_variant_get (value, "(b)", &reboot_required);
- if (reboot_required){
- dbusmenu_menuitem_property_set (self->apt_item,
- DBUSMENU_MENUITEM_PROP_LABEL,
- _("Restart to Complete Updates…"));
- dbusmenu_menuitem_property_set (self->apt_item,
- DBUSMENU_MENUITEM_PROP_DISPOSITION,
- DBUSMENU_MENUITEM_DISPOSITION_ALERT);
- self->current_state = RESTART_NEEDED;
- }
- }
- }
-
- g_variant_unref (value);
- g_variant_unref (parameters);
+ GObjectClass* object_class = G_OBJECT_CLASS (klass);
+ object_class->finalize = apt_watcher_finalize;
}
AptWatcher* apt_watcher_new (SessionDbus* session_dbus,
diff --git a/src/apt-watcher.h b/src/apt-watcher.h
index 6b7d5e1..54d26f5 100644
--- a/src/apt-watcher.h
+++ b/src/apt-watcher.h
@@ -28,6 +28,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
#include <libdbusmenu-gtk/menuitem.h>
#include "session-dbus.h"
+#include "dbus-shared-names.h"
G_BEGIN_DECLS
@@ -50,7 +51,6 @@ GType apt_watcher_get_type (void) G_GNUC_CONST;
AptWatcher* apt_watcher_new (SessionDbus* session_dbus,
DbusmenuMenuitem* apt_item);
-
G_END_DECLS
#endif /* _APT_WATCHER_H_ */
diff --git a/src/user-widget.c b/src/user-widget.c
index 88ac11c..33b9e40 100644
--- a/src/user-widget.c
+++ b/src/user-widget.c
@@ -136,11 +136,13 @@ user_widget_init (UserWidget *self)
gtk_misc_set_padding (GTK_MISC(priv->user_image),0, 4.0);
priv->user_name = gtk_label_new ("");
+
#if HAVE_GTK3
priv->container = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
#else
priv->container = gtk_hbox_new (FALSE, 0);
#endif
+
priv->tick_icon = gtk_image_new_from_icon_name ("account-logged-in",
GTK_ICON_SIZE_MENU);
gtk_misc_set_alignment(GTK_MISC(priv->tick_icon), 1.0, 0.5);