~ubuntu-branches/ubuntu/wily/gnome-software/wily-proposed

« back to all changes in this revision

Viewing changes to src/plugins/gs-plugin-packagekit-history.c

  • Committer: Package Import Robot
  • Author(s): Michael Biebl
  • Date: 2015-07-22 00:03:04 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20150722000304-ctnkwytku720qft7
Tags: 3.16.4-1
* New upstream release.
* Update Build-Depends as per configure.ac:
  - Add appstream-util.
  - Add libpolkit-gobject-1-dev.
  - Bump libappstream-glib-dev to (>= 0.3.4).
  - Bump libgtk-3-dev to (>= 3.16).
* Drop hard-coded dependency on libappstream-glib7 now that the library
  provides a symbols file.
* Use dh_install's exclude (-X) functionality to not install the .a and .la
  files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
#define I_KNOW_THE_PACKAGEKIT_GLIB2_API_IS_SUBJECT_TO_CHANGE
25
25
#include <packagekit-glib2/packagekit.h>
26
26
 
 
27
#include "gs-cleanup.h"
27
28
#include <gs-plugin.h>
28
29
 
29
30
#define GS_PLUGIN_PACKAGEKIT_HISTORY_TIMEOUT    5000 /* ms */
82
83
{
83
84
        const gchar *version;
84
85
        gboolean ret;
85
 
        GsApp *history;
86
86
        guint64 timestamp;
87
87
        PkInfoEnum info_enum;
 
88
        _cleanup_object_unref_ GsApp *history = NULL;
88
89
 
89
90
        /* create new history item with same ID as parent */
90
91
        history = gs_app_new (gs_app_get_id (app));
105
106
                gs_app_set_state (history, AS_APP_STATE_UPDATABLE);
106
107
                break;
107
108
        default:
108
 
                ret = FALSE;
109
 
                break;
110
 
        }
111
 
 
112
 
        /* we have nothing useful to show for this item */
113
 
        if (!ret) {
114
109
                g_debug ("ignoring history kind: %s",
115
110
                         pk_info_enum_to_string (info_enum));
116
 
                goto out;
 
111
                return;
117
112
        }
118
113
 
119
114
        /* set the history time and date */
131
126
 
132
127
        /* use the last event as approximation of the package timestamp */
133
128
        gs_app_set_install_date (app, timestamp);
134
 
out:
135
 
        g_object_unref (history);
136
129
}
137
130
 
138
131
/**
141
134
static gboolean
142
135
gs_plugin_load (GsPlugin *plugin, GCancellable *cancellable, GError **error)
143
136
{
144
 
        gboolean ret = TRUE;
145
137
        plugin->priv->connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM,
146
138
                                                   cancellable,
147
139
                                                   error);
148
 
        if (plugin->priv->connection == NULL)
149
 
                ret = FALSE;
150
 
        return ret;
 
140
        return plugin->priv->connection != NULL;
151
141
}
152
142
 
153
143
static gboolean
156
146
                             GCancellable *cancellable,
157
147
                             GError **error)
158
148
{
159
 
        const gchar **package_names = NULL;
160
 
        gboolean ret = TRUE;
 
149
        gboolean ret;
161
150
        GError *error_local = NULL;
162
151
        GList *l;
163
152
        GsApp *app;
164
 
        GsApp *app_dummy;
165
153
        guint i = 0;
166
154
        GVariantIter iter;
167
 
        GVariant *result = NULL;
168
 
        GVariant *tuple = NULL;
169
155
        GVariant *value;
 
156
        _cleanup_free_ const gchar **package_names = NULL;
 
157
        _cleanup_variant_unref_ GVariant *result = NULL;
 
158
        _cleanup_variant_unref_ GVariant *tuple = NULL;
170
159
 
171
160
        /* already loaded */
172
161
        if (g_once_init_enter (&plugin->priv->loaded)) {
173
162
                ret = gs_plugin_load (plugin, cancellable, error);
174
163
                g_once_init_leave (&plugin->priv->loaded, TRUE);
175
164
                if (!ret)
176
 
                        goto out;
 
165
                        return FALSE;
177
166
        }
178
167
 
179
168
        /* get an array of package names */
201
190
                                     G_DBUS_ERROR_UNKNOWN_METHOD)) {
202
191
                        g_debug ("No history available as PackageKit is too old: %s",
203
192
                                 error_local->message);
204
 
                        g_error_free (error_local);
205
193
 
206
194
                        /* just set this to something non-zero so we don't keep
207
195
                         * trying to call GetPackageHistory */
214
202
                                            G_IO_ERROR_TIMED_OUT)) {
215
203
                        g_debug ("No history as PackageKit took too long: %s",
216
204
                                 error_local->message);
217
 
                        g_error_free (error_local);
218
205
                        for (l = list; l != NULL; l = l->next) {
219
206
                                app = GS_APP (l->data);
220
207
                                gs_app_set_install_date (app, GS_APP_INSTALL_DATE_UNKNOWN);
221
208
                        }
222
 
                } else {
223
 
                        ret = FALSE;
224
 
                        g_propagate_error (error, error_local);
225
209
                }
226
 
                goto out;
 
210
                g_set_error (error,
 
211
                             GS_PLUGIN_ERROR,
 
212
                             GS_PLUGIN_ERROR_FAILED,
 
213
                             "Failed to get history: %s",
 
214
                             error_local->message);
 
215
                return FALSE;
227
216
        }
228
217
 
229
218
        /* get any results */
238
227
                        /* make up a fake entry as we know this package was at
239
228
                         * least installed at some point in time */
240
229
                        if (gs_app_get_state (app) == AS_APP_STATE_INSTALLED) {
 
230
                                _cleanup_object_unref_ GsApp *app_dummy = NULL;
241
231
                                app_dummy = gs_app_new (gs_app_get_id (app));
242
232
                                gs_app_set_install_date (app_dummy, GS_APP_INSTALL_DATE_UNKNOWN);
243
233
                                gs_app_set_kind (app_dummy, GS_APP_KIND_PACKAGE);
244
234
                                gs_app_set_state (app_dummy, AS_APP_STATE_INSTALLED);
245
235
                                gs_app_set_version (app_dummy, gs_app_get_version (app));
246
236
                                gs_app_add_history (app, app_dummy);
247
 
                                g_object_unref (app_dummy);
248
237
                        }
249
238
                        gs_app_set_install_date (app, GS_APP_INSTALL_DATE_UNKNOWN);
250
239
                        continue;
257
246
                        g_variant_unref (value);
258
247
                }
259
248
        }
260
 
 
261
 
        /* success */
262
 
        ret = TRUE;
263
 
out:
264
 
        g_free (package_names);
265
 
        if (tuple != NULL)
266
 
                g_variant_unref (tuple);
267
 
        if (result != NULL)
268
 
                g_variant_unref (result);
269
 
        return ret;
 
249
        return TRUE;
270
250
}
271
251
 
272
252
/**
279
259
                  GCancellable *cancellable,
280
260
                  GError **error)
281
261
{
282
 
        gboolean ret = TRUE;
 
262
        gboolean ret;
283
263
        GList *l;
284
 
        GList *packages = NULL;
285
264
        GsApp *app;
286
265
        GPtrArray *sources;
 
266
        _cleanup_list_free_ GList *packages = NULL;
287
267
 
288
268
        if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_HISTORY) == 0)
289
 
                goto out;
 
269
                return TRUE;
290
270
 
291
271
        /* add any missing history data */
292
272
        for (l = *list; l != NULL; l = l->next) {
304
284
                                                   cancellable,
305
285
                                                   error);
306
286
                if (!ret)
307
 
                        goto out;
 
287
                        return FALSE;
308
288
        }
309
 
out:
310
 
        g_list_free (packages);
311
 
        return ret;
 
289
        return TRUE;
312
290
}