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