annotate pui-backend.c @ 9:b571e7ade208

Add Indonesian translations
author Guido Berhoerster <guido+pui@berhoerster.name>
date Wed, 04 Jul 2018 17:08:47 +0200
parents 2477a6151087
children adba37525ee5
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>
6
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
27 #include <polkit/polkit.h>
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
28 #include <string.h>
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
29 #include <sys/stat.h>
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
30 #include <sys/types.h>
5
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
31 #include <upower.h>
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
32 #include <utime.h>
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
33
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
34 #include "pui-common.h"
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
35 #include "pui-backend.h"
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
36 #include "pui-get-updates.h"
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
37
5
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
38 #define LOW_BATTERY_THRESHOLD 10.0
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
39
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
40 struct _PuiBackend {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
41 GObject parent_instance;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
42 PkControl *pk_control;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
43 GCancellable *cancellable;
5
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
44 UpClient *up_client;
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
45 UpDevice *up_device;
6
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
46 gchar *proxy_http;
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
47 gchar *proxy_https;
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
48 gchar *proxy_ftp;
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
49 gchar *proxy_socks;
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
50 gchar *no_proxy;
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
51 gchar *pac;
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
52 gint64 last_check;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
53 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
54 gboolean inhibited;
5
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
55 gboolean is_battery_low;
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
56 guint periodic_check_id;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
57 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
58 gboolean use_mobile_connection;
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
59 guint important_updates;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
60 guint normal_updates;
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
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
63 static void pui_backend_async_initable_iface_init(gpointer, gpointer);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
64
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
65 G_DEFINE_TYPE_WITH_CODE(PuiBackend, pui_backend, G_TYPE_OBJECT,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
66 G_IMPLEMENT_INTERFACE(G_TYPE_ASYNC_INITABLE,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
67 pui_backend_async_initable_iface_init))
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
68
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
69 enum {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
70 STATE_CHANGED,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
71 RESTART_REQUIRED,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
72 SIGNAL_LAST
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
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
75 enum {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
76 PROP_0,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
77 PROP_IMPORTANT_UPDATES,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
78 PROP_NORMAL_UPDATES,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
79 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
80 PROP_USE_MOBILE_CONNECTION,
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
81 PROP_LAST
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
82 };
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
83
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
84 static guint signals[SIGNAL_LAST] = { 0 };
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
85 static GParamSpec *properties[PROP_LAST] = { NULL };
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
86
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
87 static gboolean periodic_check(gpointer);
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 GQuark
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
90 pui_backend_error_quark(void)
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
91 {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
92 return (g_quark_from_static_string("pui-backend-error-quark"));
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
93 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
94
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
95 static void
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
96 process_pk_package(gpointer data, gpointer user_data)
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
97 {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
98 PkPackage *package = data;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
99 PuiBackend *self = user_data;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
100 PkInfoEnum type_info = pk_package_get_info(package);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
101
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
102 switch (type_info) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
103 case PK_INFO_ENUM_LOW: /* FALLTHROUGH */
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
104 case PK_INFO_ENUM_ENHANCEMENT: /* FALLTHROUGH */
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
105 case PK_INFO_ENUM_NORMAL:
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
106 self->normal_updates++;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
107 break;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
108 case PK_INFO_ENUM_BUGFIX: /* FALLTHROUGH */
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
109 case PK_INFO_ENUM_IMPORTANT: /* FALLTHROUGH */
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
110 case PK_INFO_ENUM_SECURITY:
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
111 self->important_updates++;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
112 break;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
113 default:
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
114 break;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
115 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
116 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
117
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
118 static void
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
119 on_get_updates_finished(GObject *source_object, GAsyncResult *async_result,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
120 gpointer user_data)
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
121 {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
122 PuiBackend *self = user_data;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
123 GPtrArray *package_list = NULL;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
124 GError *error = NULL;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
125 guint prev_normal_updates = self->normal_updates;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
126 guint prev_important_updates = self->important_updates;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
127
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
128 package_list = pui_get_updates_finish(async_result, &error);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
129 if (package_list == NULL) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
130 if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED) ||
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
131 g_error_matches(error, PUI_GET_UPDATES_ERROR,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
132 PUI_GET_UPDATES_ERROR_CANCELLED)) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
133 /* cancelled */
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
134 g_debug("cancelled checking for updates");
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
135 } else {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
136 g_warning("failed to check for updates: %s",
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
137 error->message);
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 g_error_free(error);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
140 goto out;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
141 }
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 self->normal_updates = 0;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
144 self->important_updates = 0;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
145 g_ptr_array_foreach(package_list, process_pk_package, self);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
146 g_debug("normal updates: %u, important updates: %u",
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
147 self->normal_updates, self->important_updates);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
148 if (self->normal_updates != prev_normal_updates) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
149 g_object_notify_by_pspec(G_OBJECT(self),
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
150 properties[PROP_NORMAL_UPDATES]);
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 if (self->important_updates != prev_important_updates) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
153 g_object_notify_by_pspec(G_OBJECT(self),
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
154 properties[PROP_IMPORTANT_UPDATES]);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
155 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
156 if ((self->normal_updates != prev_normal_updates) ||
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
157 (self->important_updates != prev_important_updates)) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
158 g_debug("emitting signal state-changed");
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
159 g_signal_emit(self, signals[STATE_CHANGED], 0);
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 /* last successful check */
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
163 self->last_check = g_get_monotonic_time();
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 out:
4
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
166 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
167
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
168 /* 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
169 if (!self->inhibited) {
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
170 self->periodic_check_id =
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
171 g_timeout_add_seconds(PUI_CHECK_UPDATES_INTERVAL,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
172 periodic_check, self);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
173 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
174
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
175 if (package_list != NULL) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
176 g_ptr_array_unref(package_list);
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 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
179
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
180 static gboolean
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
181 periodic_check(gpointer user_data)
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 PuiBackend *self = user_data;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
184
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
185 g_debug("running periodic check");
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
186
4
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
187 self->cancellable = g_cancellable_new();
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
188 pui_get_updates_async(self->pk_control, self->refresh_interval,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
189 self->cancellable, on_get_updates_finished, self);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
190
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
191 /* next periodic check will be scheduled after completion */
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
192 self->periodic_check_id = 0;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
193
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
194 return (G_SOURCE_REMOVE);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
195 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
196
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
197 static void
4
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
198 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
199 {
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
200 gboolean inhibited;
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
201 guint elapsed_time;
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
202 guint remaining_time;
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 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
205 (!self->use_mobile_connection &&
5
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
206 (self->network_state == PK_NETWORK_ENUM_MOBILE)) ||
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
207 self->is_battery_low);
4
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
208 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
209 return;
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
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
212 self->inhibited = inhibited;
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
213 if (inhibited) {
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
214 /* cancel periodic checks */
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
215 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
216 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
217 }
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
218
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
219 /* cancel running operation */
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
220 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
221 !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
222 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
223 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
224 }
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
225 } else {
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
226 /* 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
227 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
228 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
229 /*
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
230 * 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
231 * 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
232 * 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
233 */
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
234 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
235 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
236 PUI_STARTUP_DELAY;
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
237 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
238 periodic_check, self);
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
239 }
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
240 }
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
241
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
242 static void
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
243 pui_backend_set_property(GObject *object, guint property_id,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
244 const GValue *value, GParamSpec *pspec)
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
245 {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
246 PuiBackend *self = PUI_BACKEND(object);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
247
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
248 switch (property_id) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
249 case PROP_REFRESH_INTERVAL:
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
250 self->refresh_interval = g_value_get_uint(value);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
251 g_debug("property \"refresh-interval\" set to %u",
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
252 self->refresh_interval);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
253 break;
4
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
254 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
255 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
256 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
257 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
258 check_inhibit(self);
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
259 break;
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
260 default:
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
261 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
262 break;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
263 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
264 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
265
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
266 static void
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
267 pui_backend_get_property(GObject *object, guint property_id, GValue *value,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
268 GParamSpec *pspec)
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
269 {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
270 PuiBackend *self = PUI_BACKEND(object);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
271
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
272 switch (property_id) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
273 case PROP_IMPORTANT_UPDATES:
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
274 g_value_set_uint(value, self->important_updates);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
275 break;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
276 case PROP_NORMAL_UPDATES:
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
277 g_value_set_uint(value, self->normal_updates);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
278 break;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
279 case PROP_REFRESH_INTERVAL:
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
280 g_value_set_uint(value, self->refresh_interval);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
281 break;
4
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
282 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
283 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
284 break;
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
285 default:
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
286 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
287 break;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
288 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
289 }
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 static void
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
292 pui_backend_dispose(GObject *object)
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
293 {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
294 PuiBackend *self = PUI_BACKEND(object);
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 if (self->periodic_check_id != 0) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
297 g_source_remove(self->periodic_check_id);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
298 self->periodic_check_id = 0;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
299 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
300
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
301 if (self->cancellable != NULL) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
302 g_cancellable_cancel(self->cancellable);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
303 g_clear_object(&self->cancellable);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
304 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
305
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
306 if (self->pk_control != NULL) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
307 g_clear_object(&self->pk_control);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
308 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
309
5
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
310 if (self->up_device != NULL) {
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
311 g_clear_object(&self->up_device);
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
312 }
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
313
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
314 if (self->up_client != NULL) {
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
315 g_clear_object(&self->up_client);
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
316 }
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
317
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
318 G_OBJECT_CLASS(pui_backend_parent_class)->dispose(object);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
319 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
320
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
321 static void
6
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
322 pui_backend_finalize(GObject *object)
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
323 {
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
324 PuiBackend *self = PUI_BACKEND(object);
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
325
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
326 g_free(self->proxy_http);
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
327 g_free(self->proxy_https);
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
328 g_free(self->proxy_ftp);
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
329 g_free(self->proxy_socks);
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
330 g_free(self->no_proxy);
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
331 g_free(self->pac);
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
332
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
333 G_OBJECT_CLASS(pui_backend_parent_class)->finalize(object);
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
334 }
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
335
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
336 static void
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
337 pui_backend_class_init(PuiBackendClass *klass)
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
338 {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
339 GObjectClass *object_class = G_OBJECT_CLASS(klass);
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 object_class->set_property = pui_backend_set_property;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
342 object_class->get_property = pui_backend_get_property;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
343 object_class->dispose = pui_backend_dispose;
6
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
344 object_class->finalize = pui_backend_finalize;
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
345
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
346 properties[PROP_IMPORTANT_UPDATES] =
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
347 g_param_spec_uint("important-updates", "Important updates",
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
348 "Number of available important updates", 0, G_MAXUINT, 0,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
349 G_PARAM_READABLE);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
350
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
351 properties[PROP_NORMAL_UPDATES] =
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
352 g_param_spec_uint("normal-updates", "Normal updates",
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
353 "Number of available normal updates", 0, G_MAXUINT, 0,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
354 G_PARAM_READABLE);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
355
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
356 properties[PROP_REFRESH_INTERVAL] =
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
357 g_param_spec_uint("refresh-interval", "Refresh interval",
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
358 "Interval in seconds for refreshing the package cache", 0,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
359 G_MAXUINT, PUI_DEFAULT_REFRESH_INTERVAL, G_PARAM_READWRITE);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
360
4
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
361 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
362 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
363 "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
364 "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
365 G_PARAM_READWRITE);
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
366
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
367 g_object_class_install_properties(object_class, PROP_LAST, properties);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
368
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
369 signals[STATE_CHANGED] = g_signal_new("state-changed",
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
370 G_TYPE_FROM_CLASS(object_class),
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
371 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
372 NULL, NULL, NULL, G_TYPE_NONE, 0);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
373
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
374 signals[RESTART_REQUIRED] = g_signal_new("restart-required",
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
375 G_TYPE_FROM_CLASS(object_class),
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
376 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
377 NULL, NULL, NULL, G_TYPE_NONE, 0);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
378 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
379
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
380 static void
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
381 pui_backend_init(PuiBackend *self)
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
382 {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
383 self->pk_control = pk_control_new();
5
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
384
4
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
385 self->inhibited = TRUE;
5
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
386
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
387 self->up_client = up_client_new();
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
388 if (self->up_client) {
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
389 self->up_device = up_client_get_display_device(self->up_client);
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
390 }
0
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
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
393 static void
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
394 on_get_properties_finished(GObject *object, GAsyncResult *result,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
395 gpointer user_data)
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
396 {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
397 PkControl *control = PK_CONTROL(object);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
398 PuiBackend *self;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
399 GTask *task = user_data;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
400 GError *error = NULL;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
401 gchar *backend_name = NULL;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
402 PkBitfield roles = 0;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
403 gchar *roles_str = NULL;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
404
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
405 self = g_task_get_task_data(task);
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 if (!pk_control_get_properties_finish(control, result, &error)) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
408 g_task_return_error(task, error);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
409 goto out;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
410 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
411
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
412 /* check whether the backend supports GetUpdates */
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
413 g_object_get(control, "backend-name", &backend_name, "roles", &roles,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
414 "network-state", &self->network_state, NULL);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
415 g_debug("backend: %s", backend_name);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
416 roles_str = pk_role_bitfield_to_string(roles);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
417 g_debug("roles: %s", roles_str);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
418 g_debug("network-state: %s",
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
419 pk_network_enum_to_string(self->network_state));
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
420 if (!pk_bitfield_contain(roles, PK_ROLE_ENUM_GET_UPDATES)) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
421 error = g_error_new(PUI_BACKEND_ERROR,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
422 PUI_BACKEND_ERROR_GET_UPDATES_NOT_IMPLEMENTED,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
423 "Getting updates is not implemented in the %s PackageKit "
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
424 "backend", backend_name);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
425 g_task_return_error(task, error);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
426 goto out;
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
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
429 g_task_return_boolean(task, TRUE);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
430 out:
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
431 g_free(roles_str);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
432 g_free(backend_name);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
433 g_object_unref(task);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
434 }
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 static void
5
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
437 on_notify_device_charge_percentage(UpDevice *device, GParamSpec *pspec,
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
438 gpointer user_data)
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
439 {
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
440 PuiBackend *self = user_data;
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
441 UpDeviceKind kind;
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
442 gdouble percentage;
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
443
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
444 g_object_get(device, "kind", &kind, "percentage", &percentage, NULL);
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
445 if ((kind != UP_DEVICE_KIND_BATTERY) && (kind != UP_DEVICE_KIND_UPS)) {
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
446 return;
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
447 }
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
448 g_debug("charge percentage changed: %.0f%%\n", percentage);
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
449 if ((self->is_battery_low && (percentage > LOW_BATTERY_THRESHOLD)) ||
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
450 (!self->is_battery_low && (percentage < LOW_BATTERY_THRESHOLD))) {
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
451 self->is_battery_low = !self->is_battery_low;
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
452 check_inhibit(self);
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
453 }
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
454 }
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
455
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
456 static void
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
457 on_notify_network_state(PkControl *pk_control, GParamSpec *pspec,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
458 gpointer user_data)
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
459 {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
460 PuiBackend *self = user_data;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
461
4
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
462 g_object_get(pk_control, "network-state", &self->network_state, NULL);
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
463 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
464 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
465 check_inhibit(self);
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
466 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
467
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
468 static void
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
469 on_updates_changed(PkControl *control, gpointer user_data)
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 PuiBackend *self = user_data;
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 * 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
475 * signals is coalesced
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
476 */
4
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
477 if (!self->inhibited) {
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
478 if (self->periodic_check_id != 0) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
479 g_source_remove(self->periodic_check_id);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
480 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
481 self->periodic_check_id =
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
482 g_timeout_add_seconds(PUI_STARTUP_DELAY, periodic_check,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
483 self);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
484 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
485 }
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 static void
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
488 on_restart_schedule(PkControl *control, gpointer user_data)
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 PuiBackend *self = user_data;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
491
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
492 g_debug("emitting signal restart-required");
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
493 g_signal_emit(self, signals[RESTART_REQUIRED], 0);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
494 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
495
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
496 static void
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
497 pui_backend_init_async(GAsyncInitable *initable, int io_priority,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
498 GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
499 {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
500 PuiBackend *self = PUI_BACKEND(initable);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
501 GTask *task;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
502
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
503 task = g_task_new(G_OBJECT(initable), cancellable, callback, user_data);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
504 g_task_set_priority(task, io_priority);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
505 g_task_set_task_data(task, g_object_ref(self),
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
506 (GDestroyNotify)g_object_unref);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
507
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
508 pk_control_get_properties_async(self->pk_control, cancellable,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
509 on_get_properties_finished, task);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
510 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
511
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
512 static gboolean
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
513 pui_backend_init_finish(GAsyncInitable *initable, GAsyncResult *result,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
514 GError **errorp)
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
515 {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
516 PuiBackend *self = PUI_BACKEND(initable);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
517 GTask *task = G_TASK(result);
5
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
518 UpDeviceKind kind;
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
519 gdouble percentage;
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
520
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
521 if (!g_task_propagate_boolean(task, errorp)) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
522 return (FALSE);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
523 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
524
5
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
525 if (self->up_device != NULL) {
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
526 /* get the kind of device and charge percentage */
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
527 g_object_get(self->up_device, "kind", &kind, "percentage",
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
528 &percentage, NULL);
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
529 if ((kind == UP_DEVICE_KIND_BATTERY) ||
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
530 (kind == UP_DEVICE_KIND_UPS)) {
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
531 self->is_battery_low =
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
532 (percentage < LOW_BATTERY_THRESHOLD);
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
533 }
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
534
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
535 /* get notification if the charge percentage changes */
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
536 g_signal_connect(self->up_device, "notify::percentage",
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
537 G_CALLBACK(on_notify_device_charge_percentage), self);
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
538 }
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
539
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
540 /* get notification when the network state changes */
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
541 g_signal_connect(self->pk_control, "notify::network-state",
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
542 G_CALLBACK(on_notify_network_state), self);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
543 /* get notifications when the available package updates change */
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
544 g_signal_connect(self->pk_control, "updates-changed",
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
545 G_CALLBACK(on_updates_changed), self);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
546 /* get notifications when an application restart is required */
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
547 g_signal_connect(self->pk_control, "restart-schedule",
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
548 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
549
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
550 check_inhibit(self);
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
551
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
552 return (TRUE);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
553 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
554
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
555 static void
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
556 pui_backend_async_initable_iface_init(gpointer g_iface, gpointer iface_data)
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
557 {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
558 GAsyncInitableIface *iface = g_iface;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
559
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
560 iface->init_async = pui_backend_init_async;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
561 iface->init_finish = pui_backend_init_finish;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
562 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
563
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
564 void
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
565 pui_backend_new_async(GCancellable *cancellable, GAsyncReadyCallback callback,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
566 gpointer user_data)
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
567 {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
568 g_async_initable_new_async(PUI_TYPE_BACKEND, G_PRIORITY_DEFAULT,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
569 cancellable, callback, user_data, NULL);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
570 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
571
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
572 PuiBackend *
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
573 pui_backend_new_finish(GAsyncResult *result, GError **errorp)
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
574 {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
575 GObject *object;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
576 GObject *source_object;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
577
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
578 source_object = g_async_result_get_source_object(result);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
579 object = g_async_initable_new_finish(G_ASYNC_INITABLE(source_object),
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
580 result, errorp);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
581 g_object_unref(source_object);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
582
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
583 return ((object != NULL) ? PUI_BACKEND(object) : NULL);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
584 }
6
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
585
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
586 static void
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
587 on_set_proxy_finished(GObject *source_object, GAsyncResult *result,
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
588 gpointer user_data)
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
589 {
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
590 PuiBackend *self = user_data;
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
591 GError *error = NULL;
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
592
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
593 if (!pk_control_set_proxy_finish(self->pk_control, result, &error)) {
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
594 g_warning("failed to set proxies: %s", error->message);
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
595 g_error_free(error);
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
596 }
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
597 }
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
598
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
599 static void
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
600 on_polkit_permission_finished(GObject *source_object, GAsyncResult *result,
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
601 gpointer user_data)
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
602 {
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
603 PuiBackend *self = user_data;
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
604 GPermission *permission;
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
605 GError *error = NULL;
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
606
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
607 permission = polkit_permission_new_finish(result, &error);
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
608 if (permission == NULL) {
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
609 g_warning("failed to create PolKit permission for setting the "
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
610 "network proxies: %s", error->message);
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
611 g_error_free(error);
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
612 return;
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
613 }
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
614
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
615 if (!g_permission_get_allowed(permission)) {
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
616 /* setting the proxy requires authentication or is disallowed */
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
617 g_debug("setting the network proxy is not allowed");
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
618 return;
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
619 }
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
620
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
621 g_debug("setting HTTP proxy to \"%s\"", (self->proxy_http != NULL) ?
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
622 self->proxy_http : "(null)");
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
623 g_debug("setting HTTPS proxy to \"%s\"", (self->proxy_https != NULL) ?
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
624 self->proxy_https : "(null)");
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
625 g_debug("setting FTP proxy to \"%s\"", (self->proxy_ftp != NULL) ?
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
626 self->proxy_ftp : "(null)");
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
627 g_debug("setting SOCKS proxy to \"%s\"", (self->proxy_socks != NULL) ?
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
628 self->proxy_socks : "(null)");
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
629 g_debug("setting the list of download IPs which should not go through "
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
630 "a proxy to \"%s\"", (self->no_proxy != NULL) ? self->no_proxy :
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
631 "(null)");
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
632 g_debug("setting the PAC string to \"%s\"", (self->pac != NULL) ?
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
633 self->pac : "(null)");
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
634 pk_control_set_proxy2_async(self->pk_control, self->proxy_http,
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
635 self->proxy_https, self->proxy_ftp, self->proxy_socks,
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
636 self->no_proxy, self->pac, NULL, on_set_proxy_finished, self);
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
637 }
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
638
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
639 void
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
640 pui_backend_set_proxy(PuiBackend *self, const gchar *proxy_http,
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
641 const gchar *proxy_https, const gchar *proxy_ftp, const gchar *proxy_socks,
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
642 const gchar *no_proxy, const gchar *pac)
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
643 {
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
644 g_free(self->proxy_http);
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
645 self->proxy_http = (proxy_http != NULL) ? g_strdup(proxy_http) : NULL;
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
646 g_free(self->proxy_https);
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
647 self->proxy_https = (proxy_https != NULL) ? g_strdup(proxy_https) :
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
648 NULL;
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
649 g_free(self->proxy_ftp);
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
650 self->proxy_ftp = (proxy_ftp != NULL) ? g_strdup(proxy_ftp) : NULL;
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
651 g_free(self->proxy_socks);
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
652 self->proxy_socks = (proxy_socks != NULL) ? g_strdup(proxy_socks) :
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
653 NULL;
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
654 g_free(self->no_proxy);
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
655 self->no_proxy = (no_proxy != NULL) ? g_strdup(no_proxy) : NULL;
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
656 g_free(self->pac);
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
657 self->pac = (pac != NULL) ? g_strdup(pac) : NULL;
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
658
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
659 polkit_permission_new("org.freedesktop.packagekit."
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
660 "system-network-proxy-configure", NULL, NULL,
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
661 on_polkit_permission_finished, self);
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
662 }