diff options
Diffstat (limited to 'src/apt-transaction.c')
-rw-r--r-- | src/apt-transaction.c | 128 |
1 files changed, 84 insertions, 44 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) |