~ubuntu-branches/ubuntu/quantal/indicator-session/quantal

« back to all changes in this revision

Viewing changes to src/apt-transaction.c

  • Committer: Package Import Robot
  • Author(s): Sebastien Bacher, Ken VanDine
  • Date: 2012-02-14 18:49:02 UTC
  • mfrom: (1.1.46)
  • Revision ID: package-import@ubuntu.com-20120214184902-uf9zw55ys3x2v7za
Tags: 0.3.91-0ubuntu1

* Backport "Don't lock the session when switching to another one"
  work from Robert Ancell, the screen locking is already done by 
  consolekit and enforcing it there is problematic to i.e use the 
  lightdm greeter as a lock screen (lp: #878836)
* debian/control:
  - recommends python-aptdaemon.pkcompat so packagekit doesn't get installed
* debian/source/format:
  - use v1, v3 doesn't play nicely with vcs backports

[ Ken VanDine ]
* New upstream release. (lp: #903756)
* debian/control
  - added new build depends on libpackagekit-glib2-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
Copyright 2011 Canonical Ltd.
3
 
 
4
 
Authors:
5
 
    Conor Curran <conor.curran@canonical.com>
6
 
 
7
 
This program is free software: you can redistribute it and/or modify it 
8
 
under the terms of the GNU General Public License version 3, as published 
9
 
by the Free Software Foundation.
10
 
 
11
 
This program is distributed in the hope that it will be useful, but 
12
 
WITHOUT ANY WARRANTY; without even the implied warranties of 
13
 
MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR 
14
 
PURPOSE.  See the GNU General Public License for more details.
15
 
 
16
 
You should have received a copy of the GNU General Public License along 
17
 
with this program.  If not, see <http://www.gnu.org/licenses/>.
18
 
*/
19
 
 
20
 
#include <gio/gio.h>
21
 
 
22
 
#include "apt-transaction.h"
23
 
#include "dbus-shared-names.h"
24
 
 
25
 
static void apt_transaction_investigate (AptTransaction* self);
26
 
static void apt_transaction_simulate_transaction_cb (GObject * obj,
27
 
                                                     GAsyncResult * res,
28
 
                                                     gpointer user_data);
29
 
static void apt_transaction_receive_signal (GDBusProxy * proxy,
30
 
                                            gchar * sender_name,
31
 
                                            gchar * signal_name,
32
 
                                            GVariant * parameters,
33
 
                                            gpointer user_data);
34
 
static void apt_transaction_finish_proxy_setup (GObject *source_object,
35
 
                                                GAsyncResult *res,
36
 
                                                gpointer user_data);
37
 
 
38
 
struct _AptTransaction
39
 
{
40
 
        GObject       parent_instance;
41
 
        GDBusProxy *  proxy;    
42
 
        GCancellable * proxy_cancel;  
43
 
  gchar*        id;
44
 
  TransactionType type;
45
 
};
46
 
 
47
 
enum {
48
 
  UPDATE,
49
 
  LAST_SIGNAL
50
 
};
51
 
 
52
 
static guint signals[LAST_SIGNAL] = { 0 };
53
 
 
54
 
G_DEFINE_TYPE (AptTransaction, apt_transaction, G_TYPE_OBJECT);
55
 
 
56
 
static void
57
 
apt_transaction_init (AptTransaction *self)
58
 
{
59
 
  self->proxy = NULL;
60
 
  self->id = NULL;
61
 
  self->proxy_cancel = g_cancellable_new();
62
 
}
63
 
 
64
 
static void
65
 
apt_transaction_finalize (GObject *object)
66
 
{
67
 
  AptTransaction* self = APT_TRANSACTION(object);
68
 
  g_signal_handlers_disconnect_by_func (G_OBJECT (self->proxy),
69
 
                                        G_CALLBACK (apt_transaction_receive_signal),
70
 
                                        self);
71
 
  if (self->proxy != NULL){
72
 
    g_object_unref (self->proxy);
73
 
    self->proxy = NULL;
74
 
  }
75
 
  g_free (self->id);
76
 
        G_OBJECT_CLASS (apt_transaction_parent_class)->finalize (object);
77
 
}
78
 
 
79
 
static void
80
 
apt_transaction_class_init (AptTransactionClass *klass)
81
 
{
82
 
        GObjectClass* object_class = G_OBJECT_CLASS (klass);
83
 
        object_class->finalize = apt_transaction_finalize;
84
 
 
85
 
  signals[UPDATE] =  g_signal_new("state-update",
86
 
                                   G_TYPE_FROM_CLASS (klass),
87
 
                                   G_SIGNAL_RUN_LAST,
88
 
                                   0,
89
 
                                   NULL, NULL,
90
 
                                   g_cclosure_marshal_VOID__INT,
91
 
                                   G_TYPE_NONE, 1, G_TYPE_INT);  
92
 
}
93
 
 
94
 
// TODO: you don't need this additional helper
95
 
// Just GObject properties properly
96
 
static void
97
 
apt_transaction_investigate (AptTransaction* self)
98
 
{
99
 
  g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
100
 
                            G_DBUS_PROXY_FLAGS_NONE,
101
 
                            NULL,
102
 
                            "org.debian.apt",
103
 
                            self->id,
104
 
                            "org.debian.apt.transaction",
105
 
                            self->proxy_cancel,
106
 
                            apt_transaction_finish_proxy_setup,
107
 
                            self);
108
 
}
109
 
 
110
 
static void
111
 
apt_transaction_finish_proxy_setup (GObject *source_object,
112
 
                                    GAsyncResult *res,
113
 
                                    gpointer user_data)
114
 
{
115
 
  g_return_if_fail (APT_IS_TRANSACTION (user_data));
116
 
  AptTransaction* self = APT_TRANSACTION(user_data);      
117
 
        GError * error = NULL;
118
 
 
119
 
        GDBusProxy * proxy = g_dbus_proxy_new_for_bus_finish(res, &error);
120
 
 
121
 
        if (self->proxy_cancel != NULL) {
122
 
                g_object_unref(self->proxy_cancel);
123
 
                self->proxy_cancel = NULL;
124
 
        }
125
 
 
126
 
        if (error != NULL) {
127
 
                g_warning("Could not grab DBus proxy for %s: %s",
128
 
               "org.debian.apt", error->message);
129
 
                g_error_free(error);
130
 
                return;
131
 
        }
132
 
  
133
 
  self->proxy = proxy;
134
 
 
135
 
  g_signal_connect (G_OBJECT(self->proxy),
136
 
                    "g-signal",
137
 
                    G_CALLBACK (apt_transaction_receive_signal),
138
 
                    self);    
139
 
 
140
 
  if (self->type == SIMULATION){
141
 
    g_dbus_proxy_call (self->proxy,
142
 
                       "Simulate",
143
 
                       NULL,
144
 
                       G_DBUS_CALL_FLAGS_NONE,
145
 
                       -1,
146
 
                       NULL,
147
 
                       apt_transaction_simulate_transaction_cb,
148
 
                       self);                                                                                        
149
 
  }                       
150
 
}
151
 
 
152
 
static void
153
 
apt_transaction_receive_signal (GDBusProxy * proxy,
154
 
                                gchar * sender_name,
155
 
                                gchar * signal_name,
156
 
                                GVariant * parameters,
157
 
                                gpointer user_data)
158
 
{
159
 
  g_return_if_fail (APT_IS_TRANSACTION (user_data));
160
 
  AptTransaction* self = APT_TRANSACTION(user_data);
161
 
  AptState current_state = DONT_KNOW;
162
 
  
163
 
  if (g_strcmp0(signal_name, "PropertyChanged") == 0) 
164
 
  {
165
 
    gchar* prop_name= NULL;
166
 
    GVariant* value = NULL;
167
 
    g_variant_get (parameters, "(sv)", &prop_name, &value);    
168
 
    g_debug ("transaction prop update - prop = %s", prop_name);
169
 
    
170
 
    if (g_variant_is_of_type (value, G_VARIANT_TYPE_STRING) == TRUE){
171
 
      gchar* key = NULL;
172
 
      g_variant_get (value, "s", &key);
173
 
      g_debug ("transaction prop update - value = %s", key);
174
 
    }
175
 
    
176
 
    if (g_strcmp0 (prop_name, "Dependencies") == 0){
177
 
            
178
 
      gchar** install = NULL;
179
 
      gchar** reinstall = NULL;
180
 
      gchar** remove = NULL;
181
 
      gchar** purge = NULL;
182
 
      gchar** upgrade = NULL;
183
 
      gchar** downgrade = NULL;
184
 
      gchar** keep = NULL;
185
 
      g_variant_get (value, "(asasasasasasas)", &install, 
186
 
                     &reinstall, &remove, &purge, &upgrade, &downgrade,
187
 
                     &keep);      
188
 
      /*                     
189
 
      g_debug ("upgrade package length %i", g_strv_length(upgrade));                
190
 
      g_debug ("install package length %i", g_strv_length(install));
191
 
      g_debug ("reinstall package length %i", g_strv_length(reinstall));
192
 
      g_debug ("remove package length %i", g_strv_length(remove));
193
 
      g_debug ("purge package length %i", g_strv_length(purge));
194
 
      */
195
 
      gboolean upgrade_needed = (g_strv_length(upgrade) > 1) ||
196
 
                                (g_strv_length(install) > 1) ||
197
 
                                (g_strv_length(reinstall) > 1) ||
198
 
                                (g_strv_length(remove) > 1) ||
199
 
                                (g_strv_length(purge) > 1);
200
 
      if (upgrade_needed == TRUE){
201
 
        current_state = UPDATES_AVAILABLE;        
202
 
      }
203
 
      else{
204
 
        current_state = UP_TO_DATE;
205
 
      }
206
 
    }
207
 
    if (self->type == REAL)
208
 
    {
209
 
      GVariant* role = g_dbus_proxy_get_cached_property (self->proxy,
210
 
                                                         "Role");
211
 
      if (g_variant_is_of_type (role, G_VARIANT_TYPE_STRING) == TRUE){
212
 
        gchar* current_role = NULL;
213
 
        g_variant_get (role, "s", &current_role);
214
 
        //g_debug ("Current transaction role = %s", current_role);
215
 
        if (g_strcmp0 (current_role, "role-commit-packages") == 0 ||
216
 
            g_strcmp0 (current_role, "role-upgrade-system") == 0){
217
 
          g_debug ("UPGRADE IN PROGRESS");
218
 
          current_state = UPGRADE_IN_PROGRESS;                        
219
 
        }
220
 
      }
221
 
    } 
222
 
  }
223
 
  else if (g_strcmp0(signal_name, "Finished") == 0) 
224
 
  {
225
 
    g_debug ("TRANSACTION Finished");
226
 
    current_state = FINISHED;
227
 
  }
228
 
  // Finally send out the state update  
229
 
  if (current_state != DONT_KNOW){
230
 
    g_signal_emit (self,
231
 
                   signals[UPDATE],
232
 
                   0,
233
 
                   current_state);
234
 
  }
235
 
}
236
 
 
237
 
static void
238
 
apt_transaction_simulate_transaction_cb (GObject * obj,
239
 
                                         GAsyncResult * res,
240
 
                                         gpointer user_data)
241
 
{
242
 
        GError * error = NULL;
243
 
        if (error != NULL) {
244
 
    g_warning ("unable to complete the simulate call");
245
 
    g_error_free (error);
246
 
                return;
247
 
        }
248
 
}
249
 
TransactionType 
250
 
apt_transaction_get_transaction_type (AptTransaction* self)
251
 
{
252
 
  return self->type;
253
 
}
254
 
 
255
 
AptTransaction* apt_transaction_new (gchar* transaction_id, TransactionType t)
256
 
{
257
 
  AptTransaction* tr = g_object_new (APT_TYPE_TRANSACTION, NULL);
258
 
  tr->id = transaction_id;
259
 
  tr->type = t;
260
 
  g_debug ("Apt transaction new id = %s", tr->id);
261
 
  apt_transaction_investigate (tr);
262
 
  return tr;
263
 
}