annotate pui-backend.c @ 58:9cbb0f8a66c4

Add setting to disable preferences widgets This just makes the widgets in the preferences application insensitive, settings can still be changed by directly editing the configuration file.
author Guido Berhoerster <guido+pui@berhoerster.name>
date Tue, 06 Sep 2022 19:11:21 +0200
parents 8ed91c5e0116
children a5ed1047ce14
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"
10
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
37 #include "pui-types.h"
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
38
31
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
39 #define LOW_BATTERY_THRESHOLD 10.0 /* % */
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
40 #define UPDATES_CHANGED_UNBLOCK_DELAY 4 /* s */
5
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
41
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
42 struct _PuiBackend {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
43 GObject parent_instance;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
44 PkControl *pk_control;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
45 GCancellable *cancellable;
10
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
46 PkClient *pk_client;
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
47 PkTransactionList *transaction_list;
5
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
48 UpClient *up_client;
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
49 UpDevice *up_device;
6
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
50 gchar *proxy_http;
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
51 gchar *proxy_https;
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
52 gchar *proxy_ftp;
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
53 gchar *proxy_socks;
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
54 gchar *no_proxy;
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
55 gchar *pac;
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
56 gint64 last_check;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
57 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
58 gboolean inhibited;
5
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
59 gboolean is_battery_low;
31
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
60 guint check_id;
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
61 guint unblock_updates_changed_id;
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
62 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
63 gboolean use_mobile_connection;
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
64 guint important_updates;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
65 guint normal_updates;
10
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
66 PuiRestart restart_type;
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
67 };
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 static void pui_backend_async_initable_iface_init(gpointer, gpointer);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
70
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
71 G_DEFINE_TYPE_WITH_CODE(PuiBackend, pui_backend, G_TYPE_OBJECT,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
72 G_IMPLEMENT_INTERFACE(G_TYPE_ASYNC_INITABLE,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
73 pui_backend_async_initable_iface_init))
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 STATE_CHANGED,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
77 RESTART_REQUIRED,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
78 SIGNAL_LAST
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
79 };
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
80
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
81 enum {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
82 PROP_0,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
83 PROP_IMPORTANT_UPDATES,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
84 PROP_NORMAL_UPDATES,
10
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
85 PROP_RESTART_TYPE,
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
86 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
87 PROP_USE_MOBILE_CONNECTION,
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
88 PROP_LAST
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
89 };
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
90
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
91 static guint signals[SIGNAL_LAST] = { 0 };
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
92 static GParamSpec *properties[PROP_LAST] = { NULL };
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 static gboolean periodic_check(gpointer);
31
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
95 static void on_updates_changed(PkControl *, gpointer);
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
96
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
97 GQuark
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
98 pui_backend_error_quark(void)
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
99 {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
100 return (g_quark_from_static_string("pui-backend-error-quark"));
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
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
103 static void
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
104 process_pk_package(gpointer data, gpointer user_data)
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
105 {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
106 PkPackage *package = data;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
107 PuiBackend *self = user_data;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
108 PkInfoEnum type_info = pk_package_get_info(package);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
109
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
110 switch (type_info) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
111 case PK_INFO_ENUM_LOW: /* FALLTHROUGH */
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
112 case PK_INFO_ENUM_ENHANCEMENT: /* FALLTHROUGH */
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
113 case PK_INFO_ENUM_NORMAL:
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
114 self->normal_updates++;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
115 break;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
116 case PK_INFO_ENUM_BUGFIX: /* FALLTHROUGH */
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
117 case PK_INFO_ENUM_IMPORTANT: /* FALLTHROUGH */
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
118 case PK_INFO_ENUM_SECURITY:
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
119 self->important_updates++;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
120 break;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
121 default:
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
122 break;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
123 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
124 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
125
31
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
126 static gboolean
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
127 unblock_updates_changed(gpointer user_data)
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
128 {
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
129 PuiBackend *self = user_data;
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
130
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
131 g_signal_handlers_unblock_by_func(self->pk_control, on_updates_changed,
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
132 self);
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
133 self->unblock_updates_changed_id = 0;
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
134
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
135 return (G_SOURCE_REMOVE);
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
136 }
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
137
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
138 static void
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
139 on_get_updates_finished(GObject *source_object, GAsyncResult *async_result,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
140 gpointer user_data)
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 PuiBackend *self = user_data;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
143 GPtrArray *package_list = NULL;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
144 GError *error = NULL;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
145 guint prev_normal_updates = self->normal_updates;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
146 guint prev_important_updates = self->important_updates;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
147
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
148 package_list = pui_get_updates_finish(async_result, &error);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
149 if (package_list == NULL) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
150 if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED) ||
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
151 g_error_matches(error, PUI_GET_UPDATES_ERROR,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
152 PUI_GET_UPDATES_ERROR_CANCELLED)) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
153 /* cancelled */
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
154 g_debug("cancelled checking for updates");
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
155 } else {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
156 g_warning("failed to check for updates: %s",
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
157 error->message);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
158 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
159 g_error_free(error);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
160 goto out;
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
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
163 self->normal_updates = 0;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
164 self->important_updates = 0;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
165 g_ptr_array_foreach(package_list, process_pk_package, self);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
166 g_debug("normal updates: %u, important updates: %u",
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
167 self->normal_updates, self->important_updates);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
168 if (self->normal_updates != prev_normal_updates) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
169 g_object_notify_by_pspec(G_OBJECT(self),
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
170 properties[PROP_NORMAL_UPDATES]);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
171 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
172 if (self->important_updates != prev_important_updates) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
173 g_object_notify_by_pspec(G_OBJECT(self),
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
174 properties[PROP_IMPORTANT_UPDATES]);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
175 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
176 if ((self->normal_updates != prev_normal_updates) ||
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
177 (self->important_updates != prev_important_updates)) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
178 g_debug("emitting signal state-changed");
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
179 g_signal_emit(self, signals[STATE_CHANGED], 0);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
180 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
181
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
182 /* last successful check */
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
183 self->last_check = g_get_monotonic_time();
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 out:
4
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
186 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
187
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
188 /* 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
189 if (!self->inhibited) {
31
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
190 self->check_id =
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
191 g_timeout_add_seconds(PUI_CHECK_UPDATES_INTERVAL,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
192 periodic_check, self);
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
31
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
195 /* handle get-updates signals again after a short delay */
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
196 self->unblock_updates_changed_id =
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
197 g_timeout_add_seconds(UPDATES_CHANGED_UNBLOCK_DELAY,
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
198 unblock_updates_changed, self);
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
199
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
200 if (package_list != NULL) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
201 g_ptr_array_unref(package_list);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
202 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
203 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
204
31
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
205 static void
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
206 run_check(PuiBackend *self, gboolean refresh_cache)
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
207 {
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
208 /* block any get-updates signals emitted when refreshing the cache */
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
209 if (self->unblock_updates_changed_id != 0) {
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
210 /* still blocked */
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
211 g_source_remove(self->unblock_updates_changed_id);
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
212 self->unblock_updates_changed_id = 0;
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
213 } else {
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
214 g_signal_handlers_block_by_func(self->pk_control,
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
215 G_CALLBACK(on_updates_changed), self);
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
216 }
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
217
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
218 self->cancellable = g_cancellable_new();
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
219 pui_get_updates_async(self->pk_control,
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
220 refresh_cache ? self->refresh_interval : G_MAXUINT,
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
221 self->cancellable, on_get_updates_finished, self);
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
222
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
223 /* next periodic check will be scheduled after completion */
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
224 self->check_id = 0;
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
225 }
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
226
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
227 static gboolean
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
228 irregular_check(gpointer user_data)
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
229 {
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
230 PuiBackend *self = user_data;
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
231
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
232 g_debug("running check");
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
233
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
234 run_check(self, FALSE);
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
235
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
236 return (G_SOURCE_REMOVE);
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
237 }
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
238
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
239 static gboolean
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
240 periodic_check(gpointer user_data)
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
241 {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
242 PuiBackend *self = user_data;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
243
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
244 g_debug("running periodic check");
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
245
31
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
246 run_check(self, TRUE);
0
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 return (G_SOURCE_REMOVE);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
249 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
250
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
251 static void
4
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
252 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
253 {
45
4a859595eabd Add debug logging when periodic checks are inhibited
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 32
diff changeset
254 gboolean is_offline;
4a859595eabd Add debug logging when periodic checks are inhibited
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 32
diff changeset
255 gboolean is_disallowed_mobile;
4
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
256 gboolean inhibited;
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
257 guint elapsed_time;
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
258 guint remaining_time;
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
259
45
4a859595eabd Add debug logging when periodic checks are inhibited
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 32
diff changeset
260 is_offline = self->network_state == PK_NETWORK_ENUM_OFFLINE;
4a859595eabd Add debug logging when periodic checks are inhibited
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 32
diff changeset
261 is_disallowed_mobile = !self->use_mobile_connection &&
4a859595eabd Add debug logging when periodic checks are inhibited
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 32
diff changeset
262 (self->network_state == PK_NETWORK_ENUM_MOBILE);
4a859595eabd Add debug logging when periodic checks are inhibited
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 32
diff changeset
263 inhibited = is_offline || is_disallowed_mobile || 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
264 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
265 return;
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
266 }
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
267
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
268 self->inhibited = inhibited;
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
269 if (inhibited) {
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
270 /* cancel periodic checks */
31
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
271 if (self->check_id != 0) {
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
272 g_source_remove(self->check_id);
4
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
273 }
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
274
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
275 /* cancel running operation */
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
276 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
277 !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
278 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
279 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
280 }
45
4a859595eabd Add debug logging when periodic checks are inhibited
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 32
diff changeset
281
4a859595eabd Add debug logging when periodic checks are inhibited
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 32
diff changeset
282 if (is_offline) {
4a859595eabd Add debug logging when periodic checks are inhibited
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 32
diff changeset
283 g_debug("perioidic checks inhibited: network offline");
4a859595eabd Add debug logging when periodic checks are inhibited
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 32
diff changeset
284 }
4a859595eabd Add debug logging when periodic checks are inhibited
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 32
diff changeset
285 if (is_disallowed_mobile) {
4a859595eabd Add debug logging when periodic checks are inhibited
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 32
diff changeset
286 g_debug("perioidic checks inhibited: use of mobile "
4a859595eabd Add debug logging when periodic checks are inhibited
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 32
diff changeset
287 "connection not allowed");
4a859595eabd Add debug logging when periodic checks are inhibited
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 32
diff changeset
288 }
4a859595eabd Add debug logging when periodic checks are inhibited
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 32
diff changeset
289 if (self->is_battery_low) {
4a859595eabd Add debug logging when periodic checks are inhibited
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 32
diff changeset
290 g_debug("perioidic checks inhibited: low battery");
4a859595eabd Add debug logging when periodic checks are inhibited
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 32
diff changeset
291 }
4
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
292 } else {
46
8ed91c5e0116 Explicitly schedule the initial check for updates after a fixed short delay
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 45
diff changeset
293 if (self->last_check == 0) {
8ed91c5e0116 Explicitly schedule the initial check for updates after a fixed short delay
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 45
diff changeset
294 /* first check after startup */
8ed91c5e0116 Explicitly schedule the initial check for updates after a fixed short delay
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 45
diff changeset
295 remaining_time = PUI_STARTUP_DELAY;
8ed91c5e0116 Explicitly schedule the initial check for updates after a fixed short delay
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 45
diff changeset
296
8ed91c5e0116 Explicitly schedule the initial check for updates after a fixed short delay
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 45
diff changeset
297 g_debug("scheduled first check in: %ds",
8ed91c5e0116 Explicitly schedule the initial check for updates after a fixed short delay
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 45
diff changeset
298 remaining_time);
8ed91c5e0116 Explicitly schedule the initial check for updates after a fixed short delay
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 45
diff changeset
299 } else {
8ed91c5e0116 Explicitly schedule the initial check for updates after a fixed short delay
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 45
diff changeset
300 /* schedule periodic checks when no longer inhibited */
8ed91c5e0116 Explicitly schedule the initial check for updates after a fixed short delay
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 45
diff changeset
301 elapsed_time =
8ed91c5e0116 Explicitly schedule the initial check for updates after a fixed short delay
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 45
diff changeset
302 (g_get_monotonic_time() - self->last_check) /
8ed91c5e0116 Explicitly schedule the initial check for updates after a fixed short delay
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 45
diff changeset
303 G_USEC_PER_SEC;
8ed91c5e0116 Explicitly schedule the initial check for updates after a fixed short delay
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 45
diff changeset
304 /*
8ed91c5e0116 Explicitly schedule the initial check for updates after a fixed short delay
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 45
diff changeset
305 * if more time than the check interval has passed
8ed91c5e0116 Explicitly schedule the initial check for updates after a fixed short delay
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 45
diff changeset
306 * since the last check, schedule a check after a short
8ed91c5e0116 Explicitly schedule the initial check for updates after a fixed short delay
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 45
diff changeset
307 * delay, otherwise wait until the interval has passed
8ed91c5e0116 Explicitly schedule the initial check for updates after a fixed short delay
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 45
diff changeset
308 */
8ed91c5e0116 Explicitly schedule the initial check for updates after a fixed short delay
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 45
diff changeset
309 remaining_time =
8ed91c5e0116 Explicitly schedule the initial check for updates after a fixed short delay
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 45
diff changeset
310 (elapsed_time < PUI_CHECK_UPDATES_INTERVAL) ?
8ed91c5e0116 Explicitly schedule the initial check for updates after a fixed short delay
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 45
diff changeset
311 PUI_CHECK_UPDATES_INTERVAL - elapsed_time :
8ed91c5e0116 Explicitly schedule the initial check for updates after a fixed short delay
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 45
diff changeset
312 PUI_STARTUP_DELAY;
8ed91c5e0116 Explicitly schedule the initial check for updates after a fixed short delay
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 45
diff changeset
313
8ed91c5e0116 Explicitly schedule the initial check for updates after a fixed short delay
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 45
diff changeset
314 g_debug("perioidic checks no longer inhibited, "
8ed91c5e0116 Explicitly schedule the initial check for updates after a fixed short delay
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 45
diff changeset
315 "time since last check: %ds, next check in: %ds",
8ed91c5e0116 Explicitly schedule the initial check for updates after a fixed short delay
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 45
diff changeset
316 elapsed_time, remaining_time);
8ed91c5e0116 Explicitly schedule the initial check for updates after a fixed short delay
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 45
diff changeset
317 }
31
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
318 self->check_id = g_timeout_add_seconds(remaining_time,
4
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
319 periodic_check, self);
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
320 }
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
321 }
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
322
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
323 static void
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
324 pui_backend_set_property(GObject *object, guint property_id,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
325 const GValue *value, GParamSpec *pspec)
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
326 {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
327 PuiBackend *self = PUI_BACKEND(object);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
328
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
329 switch (property_id) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
330 case PROP_REFRESH_INTERVAL:
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
331 self->refresh_interval = g_value_get_uint(value);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
332 g_debug("property \"refresh-interval\" set to %u",
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
333 self->refresh_interval);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
334 break;
4
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
335 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
336 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
337 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
338 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
339 check_inhibit(self);
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
340 break;
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
341 default:
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
342 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
343 break;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
344 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
345 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
346
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
347 static void
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
348 pui_backend_get_property(GObject *object, guint property_id, GValue *value,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
349 GParamSpec *pspec)
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 PuiBackend *self = PUI_BACKEND(object);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
352
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
353 switch (property_id) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
354 case PROP_IMPORTANT_UPDATES:
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
355 g_value_set_uint(value, self->important_updates);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
356 break;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
357 case PROP_NORMAL_UPDATES:
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
358 g_value_set_uint(value, self->normal_updates);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
359 break;
10
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
360 case PROP_RESTART_TYPE:
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
361 g_value_set_enum(value, self->restart_type);
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
362 break;
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
363 case PROP_REFRESH_INTERVAL:
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
364 g_value_set_uint(value, self->refresh_interval);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
365 break;
4
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
366 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
367 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
368 break;
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
369 default:
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
370 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
371 break;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
372 }
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
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
375 static void
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
376 pui_backend_dispose(GObject *object)
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
377 {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
378 PuiBackend *self = PUI_BACKEND(object);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
379
31
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
380 if (self->check_id != 0) {
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
381 g_source_remove(self->check_id);
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
382 self->check_id = 0;
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
383 }
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
384
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
385 if (self->unblock_updates_changed_id != 0) {
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
386 g_source_remove(self->unblock_updates_changed_id);
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
387 self->unblock_updates_changed_id = 0;
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
388 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
389
10
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
390 if (self->transaction_list != NULL) {
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
391 g_clear_object(&self->transaction_list);
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
392 }
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
393
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
394 if (self->pk_client != NULL) {
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
395 g_clear_object(&self->pk_client);
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
396 }
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
397
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
398 if (self->cancellable != NULL) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
399 g_cancellable_cancel(self->cancellable);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
400 g_clear_object(&self->cancellable);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
401 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
402
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
403 if (self->pk_control != NULL) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
404 g_clear_object(&self->pk_control);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
405 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
406
5
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
407 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
408 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
409 }
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
410
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
411 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
412 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
413 }
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
414
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
415 G_OBJECT_CLASS(pui_backend_parent_class)->dispose(object);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
416 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
417
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
418 static void
6
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
419 pui_backend_finalize(GObject *object)
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
420 {
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
421 PuiBackend *self = PUI_BACKEND(object);
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
422
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
423 g_free(self->proxy_http);
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
424 g_free(self->proxy_https);
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
425 g_free(self->proxy_ftp);
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
426 g_free(self->proxy_socks);
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
427 g_free(self->no_proxy);
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
428 g_free(self->pac);
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
429
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
430 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
431 }
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
432
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
433 static void
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
434 pui_backend_class_init(PuiBackendClass *klass)
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 GObjectClass *object_class = G_OBJECT_CLASS(klass);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
437
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
438 object_class->set_property = pui_backend_set_property;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
439 object_class->get_property = pui_backend_get_property;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
440 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
441 object_class->finalize = pui_backend_finalize;
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
442
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
443 properties[PROP_IMPORTANT_UPDATES] =
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
444 g_param_spec_uint("important-updates", "Important updates",
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
445 "Number of available important updates", 0, G_MAXUINT, 0,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
446 G_PARAM_READABLE);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
447
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
448 properties[PROP_NORMAL_UPDATES] =
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
449 g_param_spec_uint("normal-updates", "Normal updates",
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
450 "Number of available normal updates", 0, G_MAXUINT, 0,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
451 G_PARAM_READABLE);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
452
10
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
453 properties[PROP_RESTART_TYPE] =
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
454 g_param_spec_enum("restart-type", "Type of restart required",
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
455 "The Type of restart required", PUI_TYPE_RESTART, PUI_RESTART_NONE,
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
456 G_PARAM_READABLE);
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
457
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
458 properties[PROP_REFRESH_INTERVAL] =
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
459 g_param_spec_uint("refresh-interval", "Refresh interval",
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
460 "Interval in seconds for refreshing the package cache", 0,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
461 G_MAXUINT, PUI_DEFAULT_REFRESH_INTERVAL, G_PARAM_READWRITE);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
462
4
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
463 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
464 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
465 "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
466 "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
467 G_PARAM_READWRITE);
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
468
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
469 g_object_class_install_properties(object_class, PROP_LAST, properties);
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 signals[STATE_CHANGED] = g_signal_new("state-changed",
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
472 G_TYPE_FROM_CLASS(object_class),
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
473 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
474 NULL, NULL, NULL, G_TYPE_NONE, 0);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
475
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
476 signals[RESTART_REQUIRED] = g_signal_new("restart-required",
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
477 G_TYPE_FROM_CLASS(object_class),
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
478 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
479 NULL, NULL, NULL, G_TYPE_NONE, 0);
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
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
482 static void
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
483 pui_backend_init(PuiBackend *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 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
486
10
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
487 self->pk_client = pk_client_new();
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
488
4
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
489 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
490
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
491 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
492 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
493 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
494 }
0
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
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
497 static void
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
498 on_get_properties_finished(GObject *object, GAsyncResult *result,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
499 gpointer user_data)
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
500 {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
501 PkControl *control = PK_CONTROL(object);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
502 PuiBackend *self;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
503 GTask *task = user_data;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
504 GError *error = NULL;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
505 gchar *backend_name = NULL;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
506 PkBitfield roles = 0;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
507 gchar *roles_str = NULL;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
508
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
509 self = g_task_get_task_data(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 if (!pk_control_get_properties_finish(control, result, &error)) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
512 g_task_return_error(task, error);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
513 goto out;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
514 }
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 /* check whether the backend supports GetUpdates */
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
517 g_object_get(control, "backend-name", &backend_name, "roles", &roles,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
518 "network-state", &self->network_state, NULL);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
519 g_debug("backend: %s", backend_name);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
520 roles_str = pk_role_bitfield_to_string(roles);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
521 g_debug("roles: %s", roles_str);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
522 g_debug("network-state: %s",
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
523 pk_network_enum_to_string(self->network_state));
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
524 if (!pk_bitfield_contain(roles, PK_ROLE_ENUM_GET_UPDATES)) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
525 error = g_error_new(PUI_BACKEND_ERROR,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
526 PUI_BACKEND_ERROR_GET_UPDATES_NOT_IMPLEMENTED,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
527 "Getting updates is not implemented in the %s PackageKit "
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
528 "backend", backend_name);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
529 g_task_return_error(task, error);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
530 goto out;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
531 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
532
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
533 g_task_return_boolean(task, TRUE);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
534 out:
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
535 g_free(roles_str);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
536 g_free(backend_name);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
537 g_object_unref(task);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
538 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
539
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
540 static void
5
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
541 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
542 gpointer user_data)
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
543 {
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
544 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
545 UpDeviceKind kind;
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
546 gdouble percentage;
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
547
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
548 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
549 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
550 return;
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
551 }
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
552 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
553 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
554 (!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
555 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
556 check_inhibit(self);
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
557 }
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
558 }
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
559
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
560 static void
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
561 on_notify_network_state(PkControl *pk_control, GParamSpec *pspec,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
562 gpointer user_data)
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 PuiBackend *self = user_data;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
565
4
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
566 g_object_get(pk_control, "network-state", &self->network_state, NULL);
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
567 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
568 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
569 check_inhibit(self);
0
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 static void
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
573 on_updates_changed(PkControl *control, gpointer user_data)
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 PuiBackend *self = user_data;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
576
31
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
577 g_debug("package metatdata cache invalidated");
10
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
578
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
579 /*
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
580 * 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
581 * signals is coalesced
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
582 */
4
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
583 if (!self->inhibited) {
31
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
584 if (self->check_id != 0) {
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
585 g_source_remove(self->check_id);
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
586 }
32
b9c65915cc54 Reduce delay before checking for updates after an "updates-changed" signal
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 31
diff changeset
587 self->check_id =
b9c65915cc54 Reduce delay before checking for updates after an "updates-changed" signal
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 31
diff changeset
588 g_timeout_add_seconds(PUI_UPDATES_CHANGED_DELAY,
31
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
589 irregular_check, self);
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
590 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
591 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
592
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
593 static void
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
594 on_restart_schedule(PkControl *control, gpointer user_data)
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
595 {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
596 PuiBackend *self = user_data;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
597
10
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
598 /*
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
599 * do not restart package-update-indicator if a session or system
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
600 * restart is required since that iformation would be lost across the
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
601 * restart, rather keep running and risk errors when interacting with
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
602 * a newer version of the PackageKit daemon
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
603 */
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
604 if (self->restart_type > PUI_RESTART_NONE) {
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
605 return;
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
606 }
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
607
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
608 g_debug("emitting signal restart-required");
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
609 g_signal_emit(self, signals[RESTART_REQUIRED], 0);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
610 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
611
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
612 static void
10
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
613 on_transaction_adopt_finish(GObject *source_object, GAsyncResult *result,
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
614 gpointer user_data)
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
615 {
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
616 PuiBackend *self = user_data;
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
617 PkClient *pk_client = PK_CLIENT(source_object);
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
618 PkResults *results;
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
619 GError *error = NULL;
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
620 PkRestartEnum restart;
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
621
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
622 results = pk_client_generic_finish(pk_client, result, &error);
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
623 if (results == NULL) {
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
624 g_warning("failed to get transaction results: %s",
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
625 error->message);
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
626 g_error_free(error);
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
627 goto out;
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
628 }
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
629
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
630 /* check if transaction requires a restart */
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
631 restart = pk_results_get_require_restart_worst(results);
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
632 switch (restart) {
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
633 case PK_RESTART_ENUM_SESSION: /* FALLTHROUGH */
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
634 case PK_RESTART_ENUM_SECURITY_SESSION:
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
635 if (self->restart_type < PUI_RESTART_SESSION) {
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
636 self->restart_type = PUI_RESTART_SESSION;
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
637 g_object_notify_by_pspec(G_OBJECT(self),
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
638 properties[PROP_RESTART_TYPE]);
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
639 g_signal_emit(self, signals[STATE_CHANGED], 0);
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
640 }
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
641 break;
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
642 case PK_RESTART_ENUM_SYSTEM: /* FALLTHROUGH */
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
643 case PK_RESTART_ENUM_SECURITY_SYSTEM:
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
644 if (self->restart_type < PUI_RESTART_SYSTEM) {
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
645 self->restart_type = PUI_RESTART_SYSTEM;
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
646 g_object_notify_by_pspec(G_OBJECT(self),
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
647 properties[PROP_RESTART_TYPE]);
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
648 g_signal_emit(self, signals[STATE_CHANGED], 0);
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
649 }
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
650 break;
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
651 default:
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
652 /* do nothing */
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
653 break;
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
654 }
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
655
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
656 g_debug("transaction finished, required restart: %s",
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
657 pk_restart_enum_to_string(restart));
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
658
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
659 out:
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
660 if (results != NULL) {
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
661 g_object_unref(results);
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
662 }
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
663 }
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
664
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
665 static void
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
666 on_transaction_list_added(PkTransactionList *transaction_list,
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
667 const gchar *transaction_id, gpointer user_data)
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
668 {
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
669 PuiBackend *self = user_data;
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
670
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
671 /* adopt transaction in order to monitor it for restart requirements */
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
672 pk_client_adopt_async(self->pk_client, transaction_id, NULL, NULL,
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
673 NULL, on_transaction_adopt_finish, user_data);
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
674 }
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
675
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
676 static void
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
677 pui_backend_init_async(GAsyncInitable *initable, int io_priority,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
678 GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
679 {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
680 PuiBackend *self = PUI_BACKEND(initable);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
681 GTask *task;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
682
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
683 task = g_task_new(G_OBJECT(initable), cancellable, callback, user_data);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
684 g_task_set_priority(task, io_priority);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
685 g_task_set_task_data(task, g_object_ref(self),
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
686 (GDestroyNotify)g_object_unref);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
687
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
688 pk_control_get_properties_async(self->pk_control, cancellable,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
689 on_get_properties_finished, task);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
690 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
691
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
692 static gboolean
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
693 pui_backend_init_finish(GAsyncInitable *initable, GAsyncResult *result,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
694 GError **errorp)
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
695 {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
696 PuiBackend *self = PUI_BACKEND(initable);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
697 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
698 UpDeviceKind kind;
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
699 gdouble percentage;
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
700
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
701 if (!g_task_propagate_boolean(task, errorp)) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
702 return (FALSE);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
703 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
704
5
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
705 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
706 /* 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
707 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
708 &percentage, NULL);
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
709 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
710 (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
711 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
712 (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
713 }
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
714
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
715 /* 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
716 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
717 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
718 }
a4020e99e550 Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
719
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
720 /* get notification when the network state changes */
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
721 g_signal_connect(self->pk_control, "notify::network-state",
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
722 G_CALLBACK(on_notify_network_state), self);
31
9905d4ae351c Fix continuos loop of update checks if the refresh cache interval is 0
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
723 /* get notifications when the package metatdata cache is invalidated */
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
724 g_signal_connect(self->pk_control, "updates-changed",
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
725 G_CALLBACK(on_updates_changed), self);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
726 /* get notifications when an application restart is required */
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
727 g_signal_connect(self->pk_control, "restart-schedule",
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
728 G_CALLBACK(on_restart_schedule), self);
10
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
729 /* get notifications when a transactions are added */
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
730 self->transaction_list = pk_transaction_list_new();
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
731 g_signal_connect(self->transaction_list, "added",
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
732 G_CALLBACK(on_transaction_list_added), self);
4
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
733
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
734 check_inhibit(self);
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
735
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
736 return (TRUE);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
737 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
738
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
739 static void
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
740 pui_backend_async_initable_iface_init(gpointer g_iface, gpointer iface_data)
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
741 {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
742 GAsyncInitableIface *iface = g_iface;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
743
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
744 iface->init_async = pui_backend_init_async;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
745 iface->init_finish = pui_backend_init_finish;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
746 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
747
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
748 void
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
749 pui_backend_new_async(GCancellable *cancellable, GAsyncReadyCallback callback,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
750 gpointer user_data)
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
751 {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
752 g_async_initable_new_async(PUI_TYPE_BACKEND, G_PRIORITY_DEFAULT,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
753 cancellable, callback, user_data, NULL);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
754 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
755
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
756 PuiBackend *
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
757 pui_backend_new_finish(GAsyncResult *result, GError **errorp)
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
758 {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
759 GObject *object;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
760 GObject *source_object;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
761
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
762 source_object = g_async_result_get_source_object(result);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
763 object = g_async_initable_new_finish(G_ASYNC_INITABLE(source_object),
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
764 result, errorp);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
765 g_object_unref(source_object);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
766
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
767 return ((object != NULL) ? PUI_BACKEND(object) : NULL);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
768 }
6
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
769
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
770 static void
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
771 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
772 gpointer user_data)
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
773 {
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
774 PuiBackend *self = user_data;
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
775 GError *error = NULL;
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
776
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
777 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
778 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
779 g_error_free(error);
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
780 }
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
781 }
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
782
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
783 static void
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
784 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
785 gpointer user_data)
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
786 {
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
787 PuiBackend *self = user_data;
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
788 GPermission *permission;
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
789 GError *error = NULL;
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
790
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
791 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
792 if (permission == NULL) {
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
793 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
794 "network proxies: %s", error->message);
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
795 g_error_free(error);
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
796 return;
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
797 }
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
798
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
799 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
800 /* 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
801 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
802 return;
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
803 }
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
804
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
805 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
806 self->proxy_http : "(null)");
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
807 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
808 self->proxy_https : "(null)");
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
809 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
810 self->proxy_ftp : "(null)");
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
811 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
812 self->proxy_socks : "(null)");
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
813 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
814 "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
815 "(null)");
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
816 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
817 self->pac : "(null)");
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
818 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
819 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
820 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
821 }
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
822
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
823 void
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
824 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
825 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
826 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
827 {
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
828 g_free(self->proxy_http);
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
829 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
830 g_free(self->proxy_https);
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
831 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
832 NULL;
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
833 g_free(self->proxy_ftp);
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
834 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
835 g_free(self->proxy_socks);
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
836 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
837 NULL;
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
838 g_free(self->no_proxy);
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
839 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
840 g_free(self->pac);
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
841 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
842
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
843 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
844 "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
845 on_polkit_permission_finished, self);
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 5
diff changeset
846 }