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

« back to all changes in this revision

Viewing changes to src/gs-update-monitor.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:
27
27
#include <packagekit-glib2/packagekit.h>
28
28
#include <gsettings-desktop-schemas/gdesktop-enums.h>
29
29
 
 
30
#include "gs-cleanup.h"
30
31
#include "gs-update-monitor.h"
31
32
#include "gs-utils.h"
32
33
#include "gs-offline-updates.h"
41
42
        guint            start_hourly_checks_id;
42
43
        GDateTime       *check_timestamp;
43
44
        GDateTime       *install_timestamp;
44
 
        gboolean         refresh_cache_due;
 
45
        gboolean         refresh_cache_due;
45
46
        gboolean         get_updates_due;
46
47
        gboolean         network_available;
47
48
        gchar           **pending_downloads;
77
78
static void
78
79
notify_offline_update_available (GsUpdateMonitor *monitor)
79
80
{
80
 
        GNotification *n;
81
81
        const gchar *title;
82
82
        const gchar *body;
 
83
        _cleanup_object_unref_ GNotification *n = NULL;
83
84
 
84
85
        if (!g_file_query_exists (monitor->offline_update_file, NULL))
85
86
                return;
99
100
        body = _("Important OS and application updates are ready to be installed");
100
101
        n = g_notification_new (title);
101
102
        g_notification_set_body (n, body);
 
103
        g_notification_add_button (n, _("Not Now"), "app.nop");
102
104
        g_notification_add_button_with_target (n, _("View"), "app.set-mode", "s", "updates");
103
 
        g_notification_add_button (n, _("Not Now"), "app.nop");
104
105
        g_notification_set_default_action_and_target (n, "app.set-mode", "s", "updates");
105
106
        g_application_send_notification (monitor->application, "updates-available", n);
106
 
        g_object_unref (n);
107
107
}
108
108
 
109
109
static void
110
110
offline_update_monitor_cb (GFileMonitor      *file_monitor,
111
 
                           GFile             *file,
112
 
                           GFile             *other_file,
 
111
                           GFile             *file,
 
112
                           GFile             *other_file,
113
113
                           GFileMonitorEvent  event_type,
114
114
                           GsUpdateMonitor   *monitor)
115
115
{
131
131
{
132
132
        const gchar *message;
133
133
        const gchar *title;
134
 
        GNotification *notification;
135
 
        GIcon *icon;
136
 
        PkResults *results;
 
134
        _cleanup_object_unref_ GIcon *icon = NULL;
 
135
        _cleanup_object_unref_ GNotification *notification = NULL;
 
136
        _cleanup_object_unref_ PkResults *results = NULL;
137
137
 
138
138
        results = pk_offline_get_results (NULL);
139
139
        if (results == NULL)
160
160
        g_notification_set_body (notification, message);
161
161
        icon = g_themed_icon_new ("gnome-software-symbolic");
162
162
        g_notification_set_icon (notification, icon);
163
 
        g_object_unref (icon);
164
 
        if (pk_results_get_exit_code (results) == PK_EXIT_ENUM_SUCCESS)
 
163
        if (pk_results_get_exit_code (results) == PK_EXIT_ENUM_SUCCESS) {
165
164
                g_notification_add_button_with_target (notification, _("Review"), "app.set-mode", "s", "updated");
166
 
        else
 
165
                g_notification_set_default_action_and_target (notification, "app.set-mode", "s", "updated");
 
166
        } else {
167
167
                g_notification_add_button (notification, _("Show Details"), "app.show-offline-update-error");
168
 
        g_notification_add_button (notification, _("OK"), "app.clear-offline-updates");
 
168
                g_notification_set_default_action (notification, "app.show-offline-update-error");
 
169
        }
169
170
 
170
171
        g_application_send_notification (monitor->application, "offline-updates", notification);
171
 
        g_object_unref (notification);
172
 
        g_object_unref (results);
173
172
}
174
173
 
175
174
static gboolean
180
179
        guint64 time_update_completed;
181
180
 
182
181
        g_settings_get (monitor->settings,
183
 
                        "install-timestamp", "x", &time_last_notified);
 
182
                        "install-timestamp", "x", &time_last_notified);
184
183
 
185
184
        time_update_completed = pk_offline_get_results_mtime (NULL);
186
185
        if (time_update_completed > 0) {
188
187
                        show_installed_updates_notification (monitor);
189
188
 
190
189
                g_settings_set (monitor->settings,
191
 
                                "install-timestamp", "x", time_update_completed);
 
190
                                "install-timestamp", "x", time_update_completed);
192
191
        }
193
192
 
194
193
        start_monitoring_offline_updates (monitor);
195
194
 
196
 
        monitor->check_offline_update_id = 0;
 
195
        monitor->check_offline_update_id = 0;
197
196
 
198
 
        return G_SOURCE_REMOVE;
 
197
        return G_SOURCE_REMOVE;
199
198
}
200
199
 
201
200
static gboolean
217
216
static gboolean
218
217
no_updates_for_a_week (GsUpdateMonitor *monitor)
219
218
{
220
 
        GDateTime *last_update;
221
 
        GDateTime *now;
222
219
        GTimeSpan d;
223
220
        gint64 tmp;
 
221
        _cleanup_date_time_unref_ GDateTime *last_update = NULL;
 
222
        _cleanup_date_time_unref_ GDateTime *now = NULL;
224
223
 
225
224
        g_settings_get (monitor->settings, "install-timestamp", "x", &tmp);
226
225
        if (tmp == 0)
234
233
 
235
234
        now = g_date_time_new_now_local ();
236
235
        d = g_date_time_difference (now, last_update);
237
 
        g_date_time_unref (last_update);
238
 
        g_date_time_unref (now);
239
236
 
240
237
        if (d >= 7 * G_TIME_SPAN_DAY)
241
238
                return TRUE;
249
246
                              gpointer data)
250
247
{
251
248
        GsUpdateMonitor *monitor = data;
252
 
        PkResults *results;
253
 
        GError *error = NULL;
254
 
        PkError *error_code;
 
249
        _cleanup_error_free_ GError *error = NULL;
 
250
        _cleanup_object_unref_ PkError *error_code = NULL;
 
251
        _cleanup_object_unref_ PkResults *results = NULL;
255
252
 
256
253
        results = pk_client_generic_finish (PK_CLIENT (object), res, &error);
257
254
        if (results == NULL) {
258
 
                if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
 
255
                if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
259
256
                        g_warning ("failed to download: %s", error->message);
260
 
                }
261
 
                g_error_free (error);
262
257
                return;
263
258
        }
264
259
 
265
 
        error_code = pk_results_get_error_code (results);
266
 
        if (error_code != NULL) {
267
 
                g_warning ("failed to download: %s, %s",
268
 
                           pk_error_enum_to_string (pk_error_get_code (error_code)),
269
 
                           pk_error_get_details (error_code));
270
 
                g_object_unref (error_code);
271
 
                g_object_unref (results);
 
260
        error_code = pk_results_get_error_code (results);
 
261
        if (error_code != NULL) {
 
262
                g_warning ("failed to download: %s, %s",
 
263
                           pk_error_enum_to_string (pk_error_get_code (error_code)),
 
264
                           pk_error_get_details (error_code));
272
265
                return;
273
266
        }
274
267
 
275
268
        g_debug ("Downloaded updates");
276
 
 
277
269
        g_clear_pointer (&monitor->pending_downloads, g_strfreev);
278
 
        g_object_unref (results);
279
270
}
280
271
 
281
272
static void
303
294
                         gpointer data)
304
295
{
305
296
        GsUpdateMonitor *monitor = data;
306
 
        PkResults *results;
307
 
        PkError *error_code;
308
 
        GError *error = NULL;
309
 
        GPtrArray *packages;
310
297
        guint i;
311
298
        PkPackage *pkg;
 
299
        _cleanup_error_free_ GError *error = NULL;
 
300
        _cleanup_object_unref_ PkError *error_code = NULL;
 
301
        _cleanup_object_unref_ PkResults *results = NULL;
 
302
        _cleanup_ptrarray_unref_ GPtrArray *packages = NULL;
312
303
 
313
304
        results = pk_client_generic_finish (PK_CLIENT (object), res, &error);
314
305
        if (results == NULL) {
315
 
                if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
 
306
                if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
316
307
                        g_warning ("failed to get updates: %s", error->message);
317
 
                }
318
 
                g_error_free (error);
319
308
                return;
320
309
        }
321
310
 
324
313
                g_warning ("failed to get updates: %s, %s",
325
314
                           pk_error_enum_to_string (pk_error_get_code (error_code)),
326
315
                           pk_error_get_details (error_code));
327
 
                g_object_unref (error_code);
328
 
                g_object_unref (results);
329
316
                return;
330
317
        }
331
318
 
348
335
 
349
336
                download_updates (monitor);
350
337
        }
351
 
 
352
 
        g_ptr_array_unref (packages);
353
 
        g_object_unref (results);
354
338
}
355
339
 
356
340
static void
378
362
                           gpointer data)
379
363
{
380
364
        GsUpdateMonitor *monitor = data;
381
 
        PkResults *results;
382
 
        PkError *error_code;
383
 
        GError *error = NULL;
 
365
        _cleanup_error_free_ GError *error = NULL;
 
366
        _cleanup_object_unref_ PkError *error_code = NULL;
 
367
        _cleanup_object_unref_ PkResults *results = NULL;
384
368
 
385
369
        results = pk_client_generic_finish (PK_CLIENT (object), res, &error);
386
370
        if (results == NULL) {
387
 
                if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
 
371
                if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
388
372
                        g_warning ("failed to refresh the cache: %s", error->message);
389
 
                }
390
 
                g_error_free (error);
391
373
                return;
392
374
        }
393
375
 
396
378
                g_warning ("failed to refresh the cache: %s, %s",
397
379
                           pk_error_enum_to_string (pk_error_get_code (error_code)),
398
380
                           pk_error_get_details (error_code));
399
 
                g_object_unref (error_code);
400
 
                g_object_unref (results);
401
381
                return;
402
382
        }
403
383
 
404
384
        monitor->refresh_cache_due = FALSE;
405
385
 
406
 
        g_object_unref (results);
407
 
 
408
386
        get_updates (monitor);
409
387
}
410
388
 
418
396
                return;
419
397
 
420
398
        g_debug ("Refreshing cache");
421
 
 
422
399
        pk_client_refresh_cache_async (PK_CLIENT (monitor->task),
423
400
                                       TRUE,
424
401
                                       monitor->cancellable,
435
412
                return;
436
413
 
437
414
        if (monitor->check_timestamp != NULL) {
438
 
                GDateTime *now;
439
415
                gint now_year, now_month, now_day, now_hour;
440
416
                gint year, month, day;
 
417
                _cleanup_date_time_unref_ GDateTime *now = NULL;
441
418
 
442
419
                now = g_date_time_new_now_local ();
443
420
 
444
421
                g_date_time_get_ymd (now, &now_year, &now_month, &now_day);
445
422
                now_hour = g_date_time_get_hour (now);
446
 
                g_date_time_unref (now);
447
423
 
448
424
                g_date_time_get_ymd (monitor->check_timestamp, &year, &month, &day);
449
425
 
547
523
                      "only-download", TRUE,
548
524
                      NULL);
549
525
 
550
 
        monitor->network_available = FALSE;
 
526
        monitor->network_available = FALSE;
551
527
        monitor->control = pk_control_new ();
552
528
        g_signal_connect (monitor->control, "notify::network-state",
553
529
                          G_CALLBACK (notify_network_state_cb), monitor);
578
554
                g_source_remove (monitor->reenable_offline_update_id);
579
555
                monitor->reenable_offline_update_id = 0;
580
556
        }
 
557
        if (monitor->control != NULL) {
 
558
                g_signal_handlers_disconnect_by_func (monitor->control, notify_network_state_cb, monitor);
 
559
                g_clear_object (&monitor->control);
 
560
        }
 
561
        if (monitor->offline_update_monitor != NULL) {
 
562
                g_signal_handlers_disconnect_by_func (monitor->offline_update_monitor, offline_update_monitor_cb, monitor);
 
563
                g_clear_object (&monitor->offline_update_monitor);
 
564
        }
581
565
        g_clear_pointer (&monitor->pending_downloads, g_strfreev);
582
566
        g_clear_pointer (&monitor->check_timestamp, g_date_time_unref);
583
567
        g_clear_object (&monitor->task);
584
 
        g_clear_object (&monitor->control);
585
568
        g_clear_object (&monitor->offline_update_file);
586
 
        g_clear_object (&monitor->offline_update_monitor);
587
569
        g_clear_object (&monitor->settings);
588
570
        g_application_release (monitor->application);
589
571
 
604
586
                g_debug ("Withdrawing stale notifications");
605
587
 
606
588
                g_application_withdraw_notification (monitor->application,
607
 
                                                     "updates-available");
 
589
                                                     "updates-available");
608
590
                g_application_withdraw_notification (monitor->application,
609
 
                                                     "offline-updates");
 
591
                                                     "offline-updates");
610
592
        }
611
593
}
612
594