annotate pui-backend.c @ 4:3d72ca76538d

Add setting to control whether to use a mobile connection
author Guido Berhoerster <guido+pui@berhoerster.name>
date Sun, 17 Jun 2018 11:05:28 +0200
parents 6884bb8130ca
children a4020e99e550
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
1 /*
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
2 * Copyright (C) 2018 Guido Berhoerster <guido+pui@berhoerster.name>
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
3 *
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
4 * Permission is hereby granted, free of charge, to any person obtaining
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
5 * a copy of this software and associated documentation files (the
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
6 * "Software"), to deal in the Software without restriction, including
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
7 * without limitation the rights to use, copy, modify, merge, publish,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
8 * distribute, sublicense, and/or sell copies of the Software, and to
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
9 * permit persons to whom the Software is furnished to do so, subject to
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
10 * the following conditions:
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
11 *
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
12 * The above copyright notice and this permission notice shall be included
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
13 * in all copies or substantial portions of the Software.
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
14 *
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
22 */
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
23
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
24 #include <errno.h>
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
25 #include <fcntl.h>
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
26 #include <packagekit-glib2/packagekit.h>
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
27 #include <string.h>
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
28 #include <sys/stat.h>
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
29 #include <sys/types.h>
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
30 #include <utime.h>
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
31
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
32 #include "pui-common.h"
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
33 #include "pui-backend.h"
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
34 #include "pui-get-updates.h"
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
35
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
36 struct _PuiBackend {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
37 GObject parent_instance;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
38 PkControl *pk_control;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
39 GCancellable *cancellable;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
40 gint64 last_check;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
41 PkNetworkEnum network_state;
4
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
42 gboolean inhibited;
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
43 guint periodic_check_id;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
44 guint refresh_interval;
4
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
45 gboolean use_mobile_connection;
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
46 guint important_updates;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
47 guint normal_updates;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
48 };
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
49
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
50 static void pui_backend_async_initable_iface_init(gpointer, gpointer);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
51
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
52 G_DEFINE_TYPE_WITH_CODE(PuiBackend, pui_backend, G_TYPE_OBJECT,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
53 G_IMPLEMENT_INTERFACE(G_TYPE_ASYNC_INITABLE,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
54 pui_backend_async_initable_iface_init))
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
55
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
56 enum {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
57 STATE_CHANGED,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
58 RESTART_REQUIRED,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
59 SIGNAL_LAST
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
60 };
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
61
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
62 enum {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
63 PROP_0,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
64 PROP_IMPORTANT_UPDATES,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
65 PROP_NORMAL_UPDATES,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
66 PROP_REFRESH_INTERVAL,
4
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
67 PROP_USE_MOBILE_CONNECTION,
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
68 PROP_LAST
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
69 };
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
70
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
71 static guint signals[SIGNAL_LAST] = { 0 };
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
72 static GParamSpec *properties[PROP_LAST] = { NULL };
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
73
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
74 static gboolean periodic_check(gpointer);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
75
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
76 GQuark
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
77 pui_backend_error_quark(void)
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
78 {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
79 return (g_quark_from_static_string("pui-backend-error-quark"));
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
80 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
81
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
82 static void
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
83 process_pk_package(gpointer data, gpointer user_data)
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
84 {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
85 PkPackage *package = data;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
86 PuiBackend *self = user_data;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
87 PkInfoEnum type_info = pk_package_get_info(package);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
88
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
89 switch (type_info) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
90 case PK_INFO_ENUM_LOW: /* FALLTHROUGH */
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
91 case PK_INFO_ENUM_ENHANCEMENT: /* FALLTHROUGH */
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
92 case PK_INFO_ENUM_NORMAL:
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
93 self->normal_updates++;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
94 break;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
95 case PK_INFO_ENUM_BUGFIX: /* FALLTHROUGH */
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
96 case PK_INFO_ENUM_IMPORTANT: /* FALLTHROUGH */
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
97 case PK_INFO_ENUM_SECURITY:
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
98 self->important_updates++;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
99 break;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
100 default:
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
101 break;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
102 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
103 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
104
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
105 static void
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
106 on_get_updates_finished(GObject *source_object, GAsyncResult *async_result,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
107 gpointer user_data)
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
108 {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
109 PuiBackend *self = user_data;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
110 GPtrArray *package_list = NULL;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
111 GError *error = NULL;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
112 guint prev_normal_updates = self->normal_updates;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
113 guint prev_important_updates = self->important_updates;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
114
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
115 package_list = pui_get_updates_finish(async_result, &error);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
116 if (package_list == NULL) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
117 if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED) ||
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
118 g_error_matches(error, PUI_GET_UPDATES_ERROR,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
119 PUI_GET_UPDATES_ERROR_CANCELLED)) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
120 /* cancelled */
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
121 g_debug("cancelled checking for updates");
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
122 } else {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
123 g_warning("failed to check for updates: %s",
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
124 error->message);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
125 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
126 g_error_free(error);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
127 goto out;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
128 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
129
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
130 self->normal_updates = 0;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
131 self->important_updates = 0;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
132 g_ptr_array_foreach(package_list, process_pk_package, self);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
133 g_debug("normal updates: %u, important updates: %u",
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
134 self->normal_updates, self->important_updates);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
135 if (self->normal_updates != prev_normal_updates) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
136 g_object_notify_by_pspec(G_OBJECT(self),
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
137 properties[PROP_NORMAL_UPDATES]);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
138 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
139 if (self->important_updates != prev_important_updates) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
140 g_object_notify_by_pspec(G_OBJECT(self),
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
141 properties[PROP_IMPORTANT_UPDATES]);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
142 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
143 if ((self->normal_updates != prev_normal_updates) ||
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
144 (self->important_updates != prev_important_updates)) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
145 g_debug("emitting signal state-changed");
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
146 g_signal_emit(self, signals[STATE_CHANGED], 0);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
147 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
148
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
149 /* last successful check */
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
150 self->last_check = g_get_monotonic_time();
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
151
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
152 out:
4
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
153 g_clear_object(&self->cancellable);
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
154
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
155 /* reschedule periodic check */
4
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
156 if (!self->inhibited) {
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
157 self->periodic_check_id =
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
158 g_timeout_add_seconds(PUI_CHECK_UPDATES_INTERVAL,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
159 periodic_check, self);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
160 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
161
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
162 if (package_list != NULL) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
163 g_ptr_array_unref(package_list);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
164 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
165 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
166
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
167 static gboolean
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
168 periodic_check(gpointer user_data)
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
169 {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
170 PuiBackend *self = user_data;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
171
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
172 g_debug("running periodic check");
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
173
4
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
174 self->cancellable = g_cancellable_new();
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
175 pui_get_updates_async(self->pk_control, self->refresh_interval,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
176 self->cancellable, on_get_updates_finished, self);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
177
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
178 /* next periodic check will be scheduled after completion */
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
179 self->periodic_check_id = 0;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
180
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
181 return (G_SOURCE_REMOVE);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
182 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
183
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
184 static void
4
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
185 check_inhibit(PuiBackend *self)
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
186 {
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
187 gboolean inhibited;
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
188 guint elapsed_time;
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
189 guint remaining_time;
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
190
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
191 inhibited = ((self->network_state == PK_NETWORK_ENUM_OFFLINE) ||
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
192 (!self->use_mobile_connection &&
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
193 (self->network_state == PK_NETWORK_ENUM_MOBILE)));
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
194 if (self->inhibited == inhibited) {
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
195 return;
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
196 }
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
197
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
198 self->inhibited = inhibited;
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
199 if (inhibited) {
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
200 /* cancel periodic checks */
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
201 if (self->periodic_check_id != 0) {
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
202 g_source_remove(self->periodic_check_id);
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
203 }
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
204
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
205 /* cancel running operation */
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
206 if ((self->cancellable != NULL) &&
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
207 !g_cancellable_is_cancelled(self->cancellable)) {
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
208 g_cancellable_cancel(self->cancellable);
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
209 g_clear_object(&self->cancellable);
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
210 }
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
211 } else {
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
212 /* schedule periodic checks when no longer inhibited */
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
213 elapsed_time = (g_get_monotonic_time() - self->last_check) /
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
214 G_USEC_PER_SEC;
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
215 /*
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
216 * if more time that the check interval has passed since the
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
217 * last check, schedule a check after a short delay, otherwise
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
218 * wait until the interval has passed
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
219 */
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
220 remaining_time = (elapsed_time < PUI_CHECK_UPDATES_INTERVAL) ?
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
221 PUI_CHECK_UPDATES_INTERVAL - elapsed_time :
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
222 PUI_STARTUP_DELAY;
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
223 self->periodic_check_id = g_timeout_add_seconds(remaining_time,
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
224 periodic_check, self);
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
225 }
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
226 }
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
227
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
228 static void
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
229 pui_backend_set_property(GObject *object, guint property_id,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
230 const GValue *value, GParamSpec *pspec)
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
231 {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
232 PuiBackend *self = PUI_BACKEND(object);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
233
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
234 switch (property_id) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
235 case PROP_REFRESH_INTERVAL:
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
236 self->refresh_interval = g_value_get_uint(value);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
237 g_debug("property \"refresh-interval\" set to %u",
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
238 self->refresh_interval);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
239 break;
4
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
240 case PROP_USE_MOBILE_CONNECTION:
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
241 self->use_mobile_connection = g_value_get_boolean(value);
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
242 g_debug("property \"use-mobile-connection\" set to %s",
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
243 self->use_mobile_connection ? "true" : "false");
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
244 check_inhibit(self);
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
245 break;
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
246 default:
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
247 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
248 break;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
249 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
250 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
251
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
252 static void
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
253 pui_backend_get_property(GObject *object, guint property_id, GValue *value,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
254 GParamSpec *pspec)
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
255 {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
256 PuiBackend *self = PUI_BACKEND(object);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
257
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
258 switch (property_id) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
259 case PROP_IMPORTANT_UPDATES:
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
260 g_value_set_uint(value, self->important_updates);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
261 break;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
262 case PROP_NORMAL_UPDATES:
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
263 g_value_set_uint(value, self->normal_updates);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
264 break;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
265 case PROP_REFRESH_INTERVAL:
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
266 g_value_set_uint(value, self->refresh_interval);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
267 break;
4
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
268 case PROP_USE_MOBILE_CONNECTION:
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
269 g_value_set_boolean(value, self->use_mobile_connection);
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
270 break;
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
271 default:
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
272 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
273 break;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
274 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
275 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
276
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
277 static void
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
278 pui_backend_dispose(GObject *object)
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
279 {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
280 PuiBackend *self = PUI_BACKEND(object);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
281
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
282 if (self->periodic_check_id != 0) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
283 g_source_remove(self->periodic_check_id);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
284 self->periodic_check_id = 0;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
285 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
286
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
287 if (self->cancellable != NULL) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
288 g_cancellable_cancel(self->cancellable);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
289 g_clear_object(&self->cancellable);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
290 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
291
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
292 if (self->pk_control != NULL) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
293 g_clear_object(&self->pk_control);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
294 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
295
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
296 G_OBJECT_CLASS(pui_backend_parent_class)->dispose(object);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
297 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
298
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
299 static void
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
300 pui_backend_class_init(PuiBackendClass *klass)
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
301 {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
302 GObjectClass *object_class = G_OBJECT_CLASS(klass);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
303
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
304 object_class->set_property = pui_backend_set_property;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
305 object_class->get_property = pui_backend_get_property;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
306 object_class->dispose = pui_backend_dispose;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
307
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
308 properties[PROP_IMPORTANT_UPDATES] =
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
309 g_param_spec_uint("important-updates", "Important updates",
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
310 "Number of available important updates", 0, G_MAXUINT, 0,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
311 G_PARAM_READABLE);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
312
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
313 properties[PROP_NORMAL_UPDATES] =
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
314 g_param_spec_uint("normal-updates", "Normal updates",
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
315 "Number of available normal updates", 0, G_MAXUINT, 0,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
316 G_PARAM_READABLE);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
317
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
318 properties[PROP_REFRESH_INTERVAL] =
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
319 g_param_spec_uint("refresh-interval", "Refresh interval",
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
320 "Interval in seconds for refreshing the package cache", 0,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
321 G_MAXUINT, PUI_DEFAULT_REFRESH_INTERVAL, G_PARAM_READWRITE);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
322
4
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
323 properties[PROP_USE_MOBILE_CONNECTION] =
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
324 g_param_spec_boolean("use-mobile-connection",
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
325 "Whether to use a mobile connection", "Whether to use a mobile "
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
326 "connection for refreshing the package cache", FALSE,
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
327 G_PARAM_READWRITE);
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
328
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
329 g_object_class_install_properties(object_class, PROP_LAST, properties);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
330
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
331 signals[STATE_CHANGED] = g_signal_new("state-changed",
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
332 G_TYPE_FROM_CLASS(object_class),
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
333 G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS, 0,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
334 NULL, NULL, NULL, G_TYPE_NONE, 0);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
335
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
336 signals[RESTART_REQUIRED] = g_signal_new("restart-required",
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
337 G_TYPE_FROM_CLASS(object_class),
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
338 G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS, 0,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
339 NULL, NULL, NULL, G_TYPE_NONE, 0);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
340 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
341
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
342 static void
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
343 pui_backend_init(PuiBackend *self)
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
344 {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
345 self->pk_control = pk_control_new();
4
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
346 self->inhibited = TRUE;
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
347 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
348
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
349 static void
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
350 on_get_properties_finished(GObject *object, GAsyncResult *result,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
351 gpointer user_data)
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
352 {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
353 PkControl *control = PK_CONTROL(object);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
354 PuiBackend *self;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
355 GTask *task = user_data;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
356 GError *error = NULL;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
357 gchar *backend_name = NULL;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
358 PkBitfield roles = 0;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
359 gchar *roles_str = NULL;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
360
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
361 self = g_task_get_task_data(task);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
362
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
363 if (!pk_control_get_properties_finish(control, result, &error)) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
364 g_task_return_error(task, error);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
365 goto out;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
366 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
367
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
368 /* check whether the backend supports GetUpdates */
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
369 g_object_get(control, "backend-name", &backend_name, "roles", &roles,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
370 "network-state", &self->network_state, NULL);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
371 g_debug("backend: %s", backend_name);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
372 roles_str = pk_role_bitfield_to_string(roles);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
373 g_debug("roles: %s", roles_str);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
374 g_debug("network-state: %s",
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
375 pk_network_enum_to_string(self->network_state));
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
376 if (!pk_bitfield_contain(roles, PK_ROLE_ENUM_GET_UPDATES)) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
377 error = g_error_new(PUI_BACKEND_ERROR,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
378 PUI_BACKEND_ERROR_GET_UPDATES_NOT_IMPLEMENTED,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
379 "Getting updates is not implemented in the %s PackageKit "
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
380 "backend", backend_name);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
381 g_task_return_error(task, error);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
382 goto out;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
383 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
384
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
385 g_task_return_boolean(task, TRUE);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
386 out:
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
387 g_free(roles_str);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
388 g_free(backend_name);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
389 g_object_unref(task);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
390 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
391
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
392 static void
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
393 on_notify_network_state(PkControl *pk_control, GParamSpec *pspec,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
394 gpointer user_data)
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
395 {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
396 PuiBackend *self = user_data;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
397
4
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
398 g_object_get(pk_control, "network-state", &self->network_state, NULL);
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
399 g_debug("network state changed: %s",
4
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
400 pk_network_enum_to_string(self->network_state));
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
401 check_inhibit(self);
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
402 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
403
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
404 static void
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
405 on_updates_changed(PkControl *control, gpointer user_data)
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
406 {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
407 PuiBackend *self = user_data;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
408
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
409 /*
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
410 * schedule a check after a short delay so that a rapid succession of
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
411 * signals is coalesced
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
412 */
4
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
413 if (!self->inhibited) {
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
414 if (self->periodic_check_id != 0) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
415 g_source_remove(self->periodic_check_id);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
416 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
417 self->periodic_check_id =
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
418 g_timeout_add_seconds(PUI_STARTUP_DELAY, periodic_check,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
419 self);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
420 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
421 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
422
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
423 static void
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
424 on_restart_schedule(PkControl *control, gpointer user_data)
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
425 {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
426 PuiBackend *self = user_data;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
427
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
428 g_debug("emitting signal restart-required");
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
429 g_signal_emit(self, signals[RESTART_REQUIRED], 0);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
430 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
431
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
432 static void
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
433 pui_backend_init_async(GAsyncInitable *initable, int io_priority,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
434 GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
435 {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
436 PuiBackend *self = PUI_BACKEND(initable);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
437 GTask *task;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
438
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
439 task = g_task_new(G_OBJECT(initable), cancellable, callback, user_data);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
440 g_task_set_priority(task, io_priority);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
441 g_task_set_task_data(task, g_object_ref(self),
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
442 (GDestroyNotify)g_object_unref);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
443
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
444 pk_control_get_properties_async(self->pk_control, cancellable,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
445 on_get_properties_finished, task);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
446 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
447
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
448 static gboolean
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
449 pui_backend_init_finish(GAsyncInitable *initable, GAsyncResult *result,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
450 GError **errorp)
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
451 {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
452 PuiBackend *self = PUI_BACKEND(initable);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
453 GTask *task = G_TASK(result);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
454
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
455 if (!g_task_propagate_boolean(task, errorp)) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
456 return (FALSE);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
457 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
458
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
459 /* get notification when the network state changes */
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
460 g_signal_connect(self->pk_control, "notify::network-state",
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
461 G_CALLBACK(on_notify_network_state), self);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
462 /* get notifications when the available package updates change */
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
463 g_signal_connect(self->pk_control, "updates-changed",
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
464 G_CALLBACK(on_updates_changed), self);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
465 /* get notifications when an application restart is required */
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
466 g_signal_connect(self->pk_control, "restart-schedule",
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
467 G_CALLBACK(on_restart_schedule), self);
4
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
468
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
469 check_inhibit(self);
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
470
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
471 return (TRUE);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
472 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
473
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
474 static void
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
475 pui_backend_async_initable_iface_init(gpointer g_iface, gpointer iface_data)
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
476 {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
477 GAsyncInitableIface *iface = g_iface;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
478
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
479 iface->init_async = pui_backend_init_async;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
480 iface->init_finish = pui_backend_init_finish;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
481 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
482
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
483 void
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
484 pui_backend_new_async(GCancellable *cancellable, GAsyncReadyCallback callback,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
485 gpointer user_data)
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
486 {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
487 g_async_initable_new_async(PUI_TYPE_BACKEND, G_PRIORITY_DEFAULT,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
488 cancellable, callback, user_data, NULL);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
489 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
490
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
491 PuiBackend *
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
492 pui_backend_new_finish(GAsyncResult *result, GError **errorp)
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
493 {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
494 GObject *object;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
495 GObject *source_object;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
496
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
497 source_object = g_async_result_get_source_object(result);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
498 object = g_async_initable_new_finish(G_ASYNC_INITABLE(source_object),
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
499 result, errorp);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
500 g_object_unref(source_object);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
501
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
502 return ((object != NULL) ? PUI_BACKEND(object) : NULL);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
503 }