aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorConor Curran <conor.curran@canonical.com>2011-07-21 20:23:22 +0100
committerConor Curran <conor.curran@canonical.com>2011-07-21 20:23:22 +0100
commit7e6cf4cec8da62fc8e784d183af0baed8e7f905c (patch)
treeba243a417ccbb7b4277f9079ccae4f2c8c72e683
parentc3a8c16fbfed17d6c3f8a3cae0a6f6abe5194eaa (diff)
downloadayatana-indicator-session-7e6cf4cec8da62fc8e784d183af0baed8e7f905c.tar.gz
ayatana-indicator-session-7e6cf4cec8da62fc8e784d183af0baed8e7f905c.tar.bz2
ayatana-indicator-session-7e6cf4cec8da62fc8e784d183af0baed8e7f905c.zip
apt item now sensitive to updates available
-rw-r--r--src/apt-transaction.c128
-rw-r--r--src/apt-watcher.c93
-rw-r--r--src/dbus-shared-names.h4
-rw-r--r--src/device-menu-mgr.c122
4 files changed, 146 insertions, 201 deletions
diff --git a/src/apt-transaction.c b/src/apt-transaction.c
index 89a62af..1a4aa47 100644
--- a/src/apt-transaction.c
+++ b/src/apt-transaction.c
@@ -20,25 +20,33 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
#include <gio/gio.h>
#include "apt-transaction.h"
-
-
-static void apt_transaction_on_properties_changed (GDBusProxy *proxy,
- GVariant *changed_properties,
- const gchar* const *invalidated_properties,
- gpointer user_data);
+#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);
struct _AptTransaction
{
GObject parent_instance;
GDBusProxy * proxy;
gchar* id;
+ AptState current_state;
};
+enum {
+ UPDATE,
+ LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL] = { 0 };
+
G_DEFINE_TYPE (AptTransaction, apt_transaction, G_TYPE_OBJECT);
static void
@@ -46,6 +54,7 @@ apt_transaction_init (AptTransaction *self)
{
self->proxy = NULL;
self->id = NULL;
+
}
static void
@@ -67,6 +76,14 @@ apt_transaction_class_init (AptTransactionClass *klass)
GObjectClass* object_class = G_OBJECT_CLASS (klass);
//GObjectClass* parent_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);
}
static void
@@ -75,22 +92,24 @@ apt_transaction_investigate(AptTransaction* self)
GError * error = NULL;
self->proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
- G_DBUS_PROXY_FLAGS_NONE,
+ G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
NULL, /* GDBusInterfaceInfo */
"org.debian.apt",
self->id,
"org.debian.apt.transaction",
NULL, /* GCancellable */
&error);
+ g_debug ("Just after creating the proxy for the transaction - id = %s",
+ self->id);
if (error != NULL) {
g_warning ("unable to fetch proxy for transaction object path %s", self->id);
g_error_free (error);
return;
}
g_debug ("connecting to the properties changed signal on the transaction object");
- g_signal_connect (self->proxy,
- "g-properties-changed",
- G_CALLBACK (apt_transaction_on_properties_changed),
+ g_signal_connect (G_OBJECT(self->proxy),
+ "g-signal",
+ G_CALLBACK (apt_transaction_receive_signal),
self);
g_debug ("calling simulate on the transaction object");
@@ -105,32 +124,64 @@ apt_transaction_investigate(AptTransaction* self)
}
static void
-apt_transaction_on_properties_changed (GDBusProxy *proxy,
- GVariant *changed_properties,
- const gchar* const *invalidated_properties,
- gpointer user_data)
+apt_transaction_receive_signal (GDBusProxy * proxy,
+ gchar * sender_name,
+ gchar * signal_name,
+ GVariant * parameters,
+ gpointer user_data)
{
- g_print (" *** Apt Transaction Properties Changed:\n");
-
- if (g_variant_n_children (changed_properties) > 0)
+ g_return_if_fail (APT_IS_TRANSACTION (user_data));
+ AptTransaction* self = APT_TRANSACTION(user_data);
+
+ if (g_strcmp0 (signal_name, "Finished") == 0){
+ g_signal_emit (self,
+ signals[UPDATE],
+ 0,
+ FINISHED_CHECKING);
+
+ }
+ else if (g_strcmp0(signal_name, "PropertyChanged") == 0)
{
- GVariantIter *iter;
- const gchar *key;
- GVariant *value;
-
- g_print (" *** Apt Transaction Properties Changed:\n");
- g_variant_get (changed_properties,
- "a{sv}",
- &iter);
- while (g_variant_iter_loop (iter, "{&sv}", &key, &value))
- {
- gchar *value_str;
- value_str = g_variant_print (value, TRUE);
- g_print (" %s -> %s\n", key, value_str);
- g_free (value_str);
+ gchar* prop_name= NULL;
+ GVariant* value = NULL;
+ g_variant_get (parameters, "(sv)", &prop_name, &value);
+
+ 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 ("Seemed to uppack dependencies without any warnings");
+ //g_debug ("Upgrade quantity : %u", g_strv_length(upgrade));
+ gboolean upgrade_needed = (g_strv_length(upgrade) > 0) ||
+ (g_strv_length(install) > 0) ||
+ (g_strv_length(reinstall) > 0) ||
+ (g_strv_length(remove) > 0) ||
+ (g_strv_length(purge) > 0);
+ if (upgrade_needed == TRUE){
+ g_signal_emit (self,
+ signals[UPDATE],
+ 0,
+ UPDATES_AVAILABLE);
+
+ }
+ else{
+ g_signal_emit (self,
+ signals[UPDATE],
+ 0,
+ UP_TO_DATE);
+ }
}
- g_variant_iter_free (iter);
- }
+ }
}
static void
@@ -138,24 +189,13 @@ apt_transaction_simulate_transaction_cb (GObject * obj,
GAsyncResult * res,
gpointer user_data)
{
- g_debug ("Simulate return");
- g_return_if_fail (APT_IS_TRANSACTION (user_data));
- AptTransaction* self = APT_TRANSACTION (user_data);
-
GError * error = NULL;
- GVariant * result;
-
- result = g_dbus_proxy_call_finish(self->proxy, res, &error);
if (error != NULL) {
g_warning ("unable to complete the simulate call");
g_error_free (error);
return;
}
-
- g_debug ("simulate returned a %s",
- g_variant_get_type_string (result));
-
}
AptTransaction* apt_transaction_new (gchar* transaction_id)
diff --git a/src/apt-watcher.c b/src/apt-watcher.c
index 7553f6e..844e273 100644
--- a/src/apt-watcher.c
+++ b/src/apt-watcher.c
@@ -32,7 +32,7 @@ struct _AptWatcher
GDBusProxy * proxy;
SessionDbus* session_dbus_interface;
DbusmenuMenuitem* apt_item;
- gint current_state;
+ AptState current_state;
AptTransaction* current_transaction;
};
@@ -45,11 +45,6 @@ static void
apt_watcher_on_name_vanished (GDBusConnection *connection,
const gchar *name,
gpointer user_data);
-/*static void
-apt_watcher_get_active_transactions_cb (GObject * obj,
- GAsyncResult * res,
- gpointer user_data);
- * */
static void fetch_proxy_cb (GObject * object,
GAsyncResult * res,
gpointer user_data);
@@ -68,9 +63,9 @@ static void apt_watcher_signal_cb (GDBusProxy* proxy,
gchar* signal_name,
GVariant* parameters,
gpointer user_data);
-
-/*static void apt_watcher_determine_state (AptWatcher* self,
- GVariant* update);*/
+static void apt_watcher_manage_transactions (AptWatcher* self,
+ gchar* transaction_id);
+
G_DEFINE_TYPE (AptWatcher, apt_watcher, G_TYPE_OBJECT);
@@ -144,7 +139,6 @@ fetch_proxy_cb (GObject * object, GAsyncResult * res, gpointer user_data)
self,
NULL);
- //We'll need to connect to the state changed signal
g_signal_connect (self->proxy,
"g-signal",
G_CALLBACK(apt_watcher_signal_cb),
@@ -174,17 +168,6 @@ apt_watcher_on_name_appeared (GDBusConnection *connection,
NULL,
apt_watcher_upgrade_system_cb,
user_data);
-
- g_debug ("UpgradeSystem apt call made");
-
- /*g_dbus_proxy_call (watcher->proxy,
- "GetActiveTransactions",
- NULL,
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- apt_watcher_get_active_transactions_cb,
- user_data);*/
}
static void
@@ -197,27 +180,6 @@ apt_watcher_on_name_vanished (GDBusConnection *connection,
g_return_if_fail (APT_IS_WATCHER (user_data));
}
-/*static void
-apt_watcher_get_active_transactions_cb (GObject * obj,
- GAsyncResult * res,
- gpointer user_data)
-{
- g_return_if_fail (APT_IS_WATCHER (user_data));
- AptWatcher* self = APT_WATCHER (user_data);
-
- GError * error = NULL;
- GVariant * result;
-
- result = g_dbus_proxy_call_finish(self->proxy, res, &error);
-
- if (error != NULL) {
- g_warning ("unable to complete the fetching of active transactions");
- g_error_free (error);
- return;
- }
- apt_watcher_determine_state (self, result);
-}*/
-
static void
apt_watcher_upgrade_system_cb (GObject * obj,
GAsyncResult * res,
@@ -247,10 +209,8 @@ apt_watcher_upgrade_system_cb (GObject * obj,
return;
}
- if (self->current_transaction == NULL){
- self->current_transaction = apt_transaction_new (transaction_id);
- }
-
+ apt_watcher_manage_transactions (self, transaction_id);
+
}
@@ -297,6 +257,42 @@ apt_watcher_show_apt_dialog (DbusmenuMenuitem * mi,
{
}
+
+static void
+apt_watcher_transaction_state_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 ( state == UP_TO_DATE ){
+ dbusmenu_menuitem_property_set (self->apt_item,
+ DBUSMENU_MENUITEM_PROP_LABEL,
+ _("Software Up to Date"));
+ }
+ else if ( state == UPDATES_AVAILABLE ){
+ dbusmenu_menuitem_property_set (self->apt_item,
+ DBUSMENU_MENUITEM_PROP_LABEL,
+ _("Updates Available…"));
+ }
+ self->current_state = state;
+}
+
+static void
+apt_watcher_manage_transactions (AptWatcher* self, gchar* transaction_id)
+{
+ if (self->current_transaction == NULL){
+ self->current_transaction = apt_transaction_new (transaction_id);
+ g_signal_connect (G_OBJECT(self->current_transaction),
+ "state-update",
+ G_CALLBACK(apt_watcher_transaction_state_update_cb), self);
+ }
+}
+
// TODO - Ask MVO about this.
// Signal is of type s not sas which is on d-feet !!!
static void apt_watcher_signal_cb ( GDBusProxy* proxy,
@@ -312,13 +308,10 @@ static void apt_watcher_signal_cb ( GDBusProxy* proxy,
GVariant *value = g_variant_get_child_value (parameters, 0);
if (g_strcmp0(signal_name, "ActiveTransactionsChanged") == 0){
- g_debug ("Active Transactions signal received");
gchar* input = NULL;
g_variant_get(value, "s", & input);
g_debug ("Active Transactions signal - input = %s", input);
- if (self->current_transaction == NULL){
- self->current_transaction = apt_transaction_new (input);
- }
+ apt_watcher_manage_transactions (self, input);
}
g_variant_unref (parameters);
}
diff --git a/src/dbus-shared-names.h b/src/dbus-shared-names.h
index 8d0c6db..13ad227 100644
--- a/src/dbus-shared-names.h
+++ b/src/dbus-shared-names.h
@@ -22,8 +22,10 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
typedef enum {
UP_TO_DATE,
- UPDATES_IN_PROGRESS,
+ CHECKING_FOR_UPDATES,
UPDATES_AVAILABLE,
+ FINISHED_CHECKING,
+ UPDATING,
RESTART_NEEDED
}AptState;
diff --git a/src/device-menu-mgr.c b/src/device-menu-mgr.c
index 9c54ef3..b13b2fa 100644
--- a/src/device-menu-mgr.c
+++ b/src/device-menu-mgr.c
@@ -54,7 +54,6 @@ static DbusmenuMenuitem *printers_menuitem = NULL;
static DbusmenuMenuitem *scanners_menuitem = NULL;
static DbusmenuMenuitem *webcam_menuitem = NULL;
-
static DBusGProxyCall * suspend_call = NULL;
static DBusGProxyCall * hibernate_call = NULL;
@@ -188,6 +187,7 @@ sleep_response (DBusGProxy * proxy, DBusGProxyCall * call, gpointer data)
return;
}
+
/*static void
machine_sleep_from_suspend (DbusmenuMenuitem * mi,
guint timestamp,
@@ -251,16 +251,15 @@ suspend_prop_cb (DBusGProxy * proxy, DBusGProxyCall * call, gpointer userdata)
gboolean local_can_suspend = g_value_get_boolean(&candoit);
if (local_can_suspend != can_suspend) {
can_suspend = local_can_suspend;
+ // TODO figure out what needs updating on the menu
device_menu_mgr_rebuild_items(self);
}
-
return;
}
/* Response to getting the hibernate property */
// TODO
// Is this needed anymore
-
static void
hibernate_prop_cb (DBusGProxy * proxy, DBusGProxyCall * call, gpointer userdata)
{
@@ -435,6 +434,19 @@ show_dialog (DbusmenuMenuitem * mi, guint timestamp, gchar * type)
}
static void
+show_session_properties (DbusmenuMenuitem * mi,
+ guint timestamp,
+ gchar * type)
+{
+ GError * error = NULL;
+ if (!g_spawn_command_line_async("gnome-session-properties", &error))
+ {
+ g_warning("Unable to show dialog: %s", error->message);
+ g_error_free(error);
+ }
+}
+
+static void
show_system_settings_with_context (DbusmenuMenuitem * mi,
guint timestamp,
gchar * type)
@@ -496,7 +508,7 @@ device_menu_mgr_build_static_items (DeviceMenuMgr* self)
_("Login Items..."));
g_signal_connect (G_OBJECT(login_settings_menuitem),
DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED,
- G_CALLBACK(show_system_settings_with_context),
+ G_CALLBACK(show_session_properties),
"login");
dbusmenu_menuitem_child_add_position(self->root_item,
login_settings_menuitem,
@@ -660,108 +672,6 @@ device_menu_mgr_build_static_items (DeviceMenuMgr* self)
static void
device_menu_mgr_rebuild_items (DeviceMenuMgr* self)
{
- //gboolean can_lockscreen;
-
- /* Make sure we have a valid GConf client, and build one
- if needed */
- //device_menu_mgr_ensure_gconf_client (self);
-
- /*can_lockscreen = !gconf_client_get_bool ( gconf_client,
- LOCKDOWN_KEY_SCREENSAVER,
- NULL);
- if (can_lockscreen) {
- lock_menuitem = dbusmenu_menuitem_new();
- dbusmenu_menuitem_property_set (lock_menuitem,
- DBUSMENU_MENUITEM_PROP_LABEL,
- _("Lock Screen"));
-
- gchar * shortcut = gconf_client_get_string(gconf_client, KEY_LOCK_SCREEN, NULL);
- if (shortcut != NULL) {
- g_debug("Lock screen shortcut: %s", shortcut);
- dbusmenu_menuitem_property_set_shortcut_string(lock_menuitem, shortcut);
- g_free(shortcut);
- } else {
- g_debug("Unable to get lock screen shortcut.");
- }
-
- g_signal_connect (G_OBJECT(lock_menuitem),
- DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED,
- G_CALLBACK(lock_screen), NULL);
- dbusmenu_menuitem_child_append(self->root_item, lock_menuitem);
- }
-
- logout_mi = dbusmenu_menuitem_new();
- if (supress_confirmations()) {
- dbusmenu_menuitem_property_set (logout_mi,
- DBUSMENU_MENUITEM_PROP_LABEL,
- _("Log Out"));
- } else {
- dbusmenu_menuitem_property_set (logout_mi,
- DBUSMENU_MENUITEM_PROP_LABEL,
- _("Log Out\342\200\246"));
- }
- dbusmenu_menuitem_property_set_bool (logout_mi,
- DBUSMENU_MENUITEM_PROP_VISIBLE,
- show_logout());
- dbusmenu_menuitem_child_append(self->root_item, logout_mi);
- g_signal_connect( G_OBJECT(logout_mi),
- DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED,
- G_CALLBACK(show_dialog), "logout");
-
- if (can_suspend && allow_suspend) {
- suspend_mi = dbusmenu_menuitem_new();
- dbusmenu_menuitem_property_set (suspend_mi,
- DBUSMENU_MENUITEM_PROP_LABEL,
- _("Suspend"));
- dbusmenu_menuitem_child_append (self->root_item, suspend_mi);
- g_signal_connect( G_OBJECT(suspend_mi),
- DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED,
- G_CALLBACK(machine_sleep_from_suspend),
- self);
- }
-
- if (can_hibernate && allow_hibernate) {
- hibernate_mi = dbusmenu_menuitem_new();
- dbusmenu_menuitem_property_set (hibernate_mi,
- DBUSMENU_MENUITEM_PROP_LABEL,
- _("Hibernate"));
- dbusmenu_menuitem_child_append(self->root_item, hibernate_mi);
- g_signal_connect (G_OBJECT(hibernate_mi),
- DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED,
- G_CALLBACK(machine_sleep_from_hibernate), self);
- }
-
- dbusmenu_menuitem_child_append(self->root_item, restart_mi);
- g_signal_connect (G_OBJECT(restart_mi),
- DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED,
- G_CALLBACK(show_dialog), "restart");
-
- shutdown_mi = dbusmenu_menuitem_new();
- if (supress_confirmations()) {
- dbusmenu_menuitem_property_set (shutdown_mi,
- DBUSMENU_MENUITEM_PROP_LABEL,
- _("Shut Down"));
- } else {
- dbusmenu_menuitem_property_set (shutdown_mi,
- DBUSMENU_MENUITEM_PROP_LABEL,
- _("Shut Down\342\200\246"));
- }
- dbusmenu_menuitem_property_set_bool (shutdown_mi,
- DBUSMENU_MENUITEM_PROP_VISIBLE,
- show_shutdown());
- dbusmenu_menuitem_child_append (self->root_item, shutdown_mi);
- g_signal_connect (G_OBJECT(shutdown_mi),
- DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED,
- G_CALLBACK(show_dialog), "shutdown");
-
- RestartShutdownLogoutMenuItems * restart_shutdown_logout_mi = g_new0 (RestartShutdownLogoutMenuItems, 1);
- restart_shutdown_logout_mi->logout_mi = logout_mi;
- restart_shutdown_logout_mi->restart_mi = restart_mi;
- restart_shutdown_logout_mi->shutdown_mi = shutdown_mi;
-
- update_menu_entries(restart_shutdown_logout_mi);
-
- return;*/
}
/* When the directory changes we need to figure out how our menu