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;
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);
110
110
offline_update_monitor_cb (GFileMonitor *file_monitor,
113
113
GFileMonitorEvent event_type,
114
114
GsUpdateMonitor *monitor)
132
132
const gchar *message;
133
133
const gchar *title;
134
GNotification *notification;
134
_cleanup_object_unref_ GIcon *icon = NULL;
135
_cleanup_object_unref_ GNotification *notification = NULL;
136
_cleanup_object_unref_ PkResults *results = NULL;
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");
165
g_notification_set_default_action_and_target (notification, "app.set-mode", "s", "updated");
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");
170
171
g_application_send_notification (monitor->application, "offline-updates", notification);
171
g_object_unref (notification);
172
g_object_unref (results);
180
179
guint64 time_update_completed;
182
181
g_settings_get (monitor->settings,
183
"install-timestamp", "x", &time_last_notified);
182
"install-timestamp", "x", &time_last_notified);
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);
190
189
g_settings_set (monitor->settings,
191
"install-timestamp", "x", time_update_completed);
190
"install-timestamp", "x", time_update_completed);
194
193
start_monitoring_offline_updates (monitor);
196
monitor->check_offline_update_id = 0;
195
monitor->check_offline_update_id = 0;
198
return G_SOURCE_REMOVE;
197
return G_SOURCE_REMOVE;
218
217
no_updates_for_a_week (GsUpdateMonitor *monitor)
220
GDateTime *last_update;
221
_cleanup_date_time_unref_ GDateTime *last_update = NULL;
222
_cleanup_date_time_unref_ GDateTime *now = NULL;
225
224
g_settings_get (monitor->settings, "install-timestamp", "x", &tmp);
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);
240
237
if (d >= 7 * G_TIME_SPAN_DAY)
251
248
GsUpdateMonitor *monitor = data;
253
GError *error = NULL;
249
_cleanup_error_free_ GError *error = NULL;
250
_cleanup_object_unref_ PkError *error_code = NULL;
251
_cleanup_object_unref_ PkResults *results = NULL;
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);
261
g_error_free (error);
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));
275
268
g_debug ("Downloaded updates");
277
269
g_clear_pointer (&monitor->pending_downloads, g_strfreev);
278
g_object_unref (results);
305
296
GsUpdateMonitor *monitor = data;
308
GError *error = NULL;
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;
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);
318
g_error_free (error);
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);
380
364
GsUpdateMonitor *monitor = data;
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;
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);
390
g_error_free (error);
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);
404
384
monitor->refresh_cache_due = FALSE;
406
g_object_unref (results);
408
386
get_updates (monitor);
437
414
if (monitor->check_timestamp != NULL) {
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;
442
419
now = g_date_time_new_now_local ();
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);
448
424
g_date_time_get_ymd (monitor->check_timestamp, &year, &month, &day);
547
523
"only-download", TRUE,
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;
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);
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);
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);