Mercurial > projects > package-update-indicator
annotate pui-backend.c @ 14:f783ba95ec4a
Set application indicator title
The title property is displayed by some implementations in the menu and/or in
the tooltip.
author | Guido Berhoerster <guido+pui@berhoerster.name> |
---|---|
date | Sat, 14 Jul 2018 09:57:39 +0200 |
parents | adba37525ee5 |
children | 9905d4ae351c |
rev | line source |
---|---|
0
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
1 /* |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
2 * Copyright (C) 2018 Guido Berhoerster <guido+pui@berhoerster.name> |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
3 * |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
4 * Permission is hereby granted, free of charge, to any person obtaining |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
5 * a copy of this software and associated documentation files (the |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
6 * "Software"), to deal in the Software without restriction, including |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
7 * without limitation the rights to use, copy, modify, merge, publish, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
8 * distribute, sublicense, and/or sell copies of the Software, and to |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
9 * permit persons to whom the Software is furnished to do so, subject to |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
10 * the following conditions: |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
11 * |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
12 * The above copyright notice and this permission notice shall be included |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
13 * in all copies or substantial portions of the Software. |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
14 * |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
22 */ |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
23 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
24 #include <errno.h> |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
25 #include <fcntl.h> |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
26 #include <packagekit-glib2/packagekit.h> |
6
2477a6151087
Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
5
diff
changeset
|
27 #include <polkit/polkit.h> |
0
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
28 #include <string.h> |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
29 #include <sys/stat.h> |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
30 #include <sys/types.h> |
5
a4020e99e550
Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
4
diff
changeset
|
31 #include <upower.h> |
0
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
32 #include <utime.h> |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
33 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
34 #include "pui-common.h" |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
35 #include "pui-backend.h" |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
36 #include "pui-get-updates.h" |
10
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
37 #include "pui-types.h" |
0
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
38 |
5
a4020e99e550
Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
4
diff
changeset
|
39 #define LOW_BATTERY_THRESHOLD 10.0 |
a4020e99e550
Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
4
diff
changeset
|
40 |
0
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
41 struct _PuiBackend { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
42 GObject parent_instance; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
43 PkControl *pk_control; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
44 GCancellable *cancellable; |
10
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
45 PkClient *pk_client; |
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
46 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
|
47 UpClient *up_client; |
a4020e99e550
Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
4
diff
changeset
|
48 UpDevice *up_device; |
6
2477a6151087
Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
5
diff
changeset
|
49 gchar *proxy_http; |
2477a6151087
Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
5
diff
changeset
|
50 gchar *proxy_https; |
2477a6151087
Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
5
diff
changeset
|
51 gchar *proxy_ftp; |
2477a6151087
Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
5
diff
changeset
|
52 gchar *proxy_socks; |
2477a6151087
Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
5
diff
changeset
|
53 gchar *no_proxy; |
2477a6151087
Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
5
diff
changeset
|
54 gchar *pac; |
0
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
55 gint64 last_check; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
56 PkNetworkEnum network_state; |
4
3d72ca76538d
Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
0
diff
changeset
|
57 gboolean inhibited; |
5
a4020e99e550
Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
4
diff
changeset
|
58 gboolean is_battery_low; |
0
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
59 guint periodic_check_id; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
60 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
|
61 gboolean use_mobile_connection; |
0
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
62 guint important_updates; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
63 guint normal_updates; |
10
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
64 PuiRestart restart_type; |
0
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
65 }; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
66 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
67 static void pui_backend_async_initable_iface_init(gpointer, gpointer); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
68 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
69 G_DEFINE_TYPE_WITH_CODE(PuiBackend, pui_backend, G_TYPE_OBJECT, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
70 G_IMPLEMENT_INTERFACE(G_TYPE_ASYNC_INITABLE, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
71 pui_backend_async_initable_iface_init)) |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
72 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
73 enum { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
74 STATE_CHANGED, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
75 RESTART_REQUIRED, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
76 SIGNAL_LAST |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
77 }; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
78 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
79 enum { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
80 PROP_0, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
81 PROP_IMPORTANT_UPDATES, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
82 PROP_NORMAL_UPDATES, |
10
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
83 PROP_RESTART_TYPE, |
0
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
84 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
|
85 PROP_USE_MOBILE_CONNECTION, |
0
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
86 PROP_LAST |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
87 }; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
88 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
89 static guint signals[SIGNAL_LAST] = { 0 }; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
90 static GParamSpec *properties[PROP_LAST] = { NULL }; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
91 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
92 static gboolean periodic_check(gpointer); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
93 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
94 GQuark |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
95 pui_backend_error_quark(void) |
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 return (g_quark_from_static_string("pui-backend-error-quark")); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
98 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
99 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
100 static void |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
101 process_pk_package(gpointer data, gpointer user_data) |
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 PkPackage *package = data; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
104 PuiBackend *self = user_data; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
105 PkInfoEnum type_info = pk_package_get_info(package); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
106 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
107 switch (type_info) { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
108 case PK_INFO_ENUM_LOW: /* FALLTHROUGH */ |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
109 case PK_INFO_ENUM_ENHANCEMENT: /* FALLTHROUGH */ |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
110 case PK_INFO_ENUM_NORMAL: |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
111 self->normal_updates++; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
112 break; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
113 case PK_INFO_ENUM_BUGFIX: /* FALLTHROUGH */ |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
114 case PK_INFO_ENUM_IMPORTANT: /* FALLTHROUGH */ |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
115 case PK_INFO_ENUM_SECURITY: |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
116 self->important_updates++; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
117 break; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
118 default: |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
119 break; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
120 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
121 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
122 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
123 static void |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
124 on_get_updates_finished(GObject *source_object, GAsyncResult *async_result, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
125 gpointer user_data) |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
126 { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
127 PuiBackend *self = user_data; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
128 GPtrArray *package_list = NULL; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
129 GError *error = NULL; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
130 guint prev_normal_updates = self->normal_updates; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
131 guint prev_important_updates = self->important_updates; |
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 package_list = pui_get_updates_finish(async_result, &error); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
134 if (package_list == NULL) { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
135 if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED) || |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
136 g_error_matches(error, PUI_GET_UPDATES_ERROR, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
137 PUI_GET_UPDATES_ERROR_CANCELLED)) { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
138 /* cancelled */ |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
139 g_debug("cancelled checking for updates"); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
140 } else { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
141 g_warning("failed to check for updates: %s", |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
142 error->message); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
143 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
144 g_error_free(error); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
145 goto out; |
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 self->normal_updates = 0; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
149 self->important_updates = 0; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
150 g_ptr_array_foreach(package_list, process_pk_package, self); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
151 g_debug("normal updates: %u, important updates: %u", |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
152 self->normal_updates, self->important_updates); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
153 if (self->normal_updates != prev_normal_updates) { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
154 g_object_notify_by_pspec(G_OBJECT(self), |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
155 properties[PROP_NORMAL_UPDATES]); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
156 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
157 if (self->important_updates != prev_important_updates) { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
158 g_object_notify_by_pspec(G_OBJECT(self), |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
159 properties[PROP_IMPORTANT_UPDATES]); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
160 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
161 if ((self->normal_updates != prev_normal_updates) || |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
162 (self->important_updates != prev_important_updates)) { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
163 g_debug("emitting signal state-changed"); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
164 g_signal_emit(self, signals[STATE_CHANGED], 0); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
165 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
166 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
167 /* last successful check */ |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
168 self->last_check = g_get_monotonic_time(); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
169 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
170 out: |
4
3d72ca76538d
Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
0
diff
changeset
|
171 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
|
172 |
0
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
173 /* 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
|
174 if (!self->inhibited) { |
0
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
175 self->periodic_check_id = |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
176 g_timeout_add_seconds(PUI_CHECK_UPDATES_INTERVAL, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
177 periodic_check, self); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
178 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
179 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
180 if (package_list != NULL) { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
181 g_ptr_array_unref(package_list); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
182 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
183 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
184 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
185 static gboolean |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
186 periodic_check(gpointer user_data) |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
187 { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
188 PuiBackend *self = user_data; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
189 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
190 g_debug("running periodic check"); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
191 |
4
3d72ca76538d
Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
0
diff
changeset
|
192 self->cancellable = g_cancellable_new(); |
0
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
193 pui_get_updates_async(self->pk_control, self->refresh_interval, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
194 self->cancellable, on_get_updates_finished, self); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
195 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
196 /* next periodic check will be scheduled after completion */ |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
197 self->periodic_check_id = 0; |
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 return (G_SOURCE_REMOVE); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
200 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
201 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
202 static void |
4
3d72ca76538d
Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
0
diff
changeset
|
203 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
|
204 { |
3d72ca76538d
Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
0
diff
changeset
|
205 gboolean inhibited; |
3d72ca76538d
Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
0
diff
changeset
|
206 guint elapsed_time; |
3d72ca76538d
Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
0
diff
changeset
|
207 guint remaining_time; |
3d72ca76538d
Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
0
diff
changeset
|
208 |
3d72ca76538d
Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
0
diff
changeset
|
209 inhibited = ((self->network_state == PK_NETWORK_ENUM_OFFLINE) || |
3d72ca76538d
Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
0
diff
changeset
|
210 (!self->use_mobile_connection && |
5
a4020e99e550
Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
4
diff
changeset
|
211 (self->network_state == PK_NETWORK_ENUM_MOBILE)) || |
a4020e99e550
Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
4
diff
changeset
|
212 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
|
213 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
|
214 return; |
3d72ca76538d
Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
0
diff
changeset
|
215 } |
3d72ca76538d
Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
0
diff
changeset
|
216 |
3d72ca76538d
Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
0
diff
changeset
|
217 self->inhibited = inhibited; |
3d72ca76538d
Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
0
diff
changeset
|
218 if (inhibited) { |
3d72ca76538d
Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
0
diff
changeset
|
219 /* cancel periodic checks */ |
3d72ca76538d
Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
0
diff
changeset
|
220 if (self->periodic_check_id != 0) { |
3d72ca76538d
Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
0
diff
changeset
|
221 g_source_remove(self->periodic_check_id); |
3d72ca76538d
Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
0
diff
changeset
|
222 } |
3d72ca76538d
Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
0
diff
changeset
|
223 |
3d72ca76538d
Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
0
diff
changeset
|
224 /* cancel running operation */ |
3d72ca76538d
Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
0
diff
changeset
|
225 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
|
226 !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
|
227 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
|
228 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
|
229 } |
3d72ca76538d
Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
0
diff
changeset
|
230 } else { |
3d72ca76538d
Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
0
diff
changeset
|
231 /* schedule periodic checks when no longer inhibited */ |
3d72ca76538d
Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
0
diff
changeset
|
232 elapsed_time = (g_get_monotonic_time() - self->last_check) / |
3d72ca76538d
Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
0
diff
changeset
|
233 G_USEC_PER_SEC; |
3d72ca76538d
Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
0
diff
changeset
|
234 /* |
3d72ca76538d
Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
0
diff
changeset
|
235 * if more time that the check interval has passed since the |
3d72ca76538d
Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
0
diff
changeset
|
236 * last check, schedule a check after a short delay, otherwise |
3d72ca76538d
Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
0
diff
changeset
|
237 * wait until the interval has passed |
3d72ca76538d
Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
0
diff
changeset
|
238 */ |
3d72ca76538d
Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
0
diff
changeset
|
239 remaining_time = (elapsed_time < PUI_CHECK_UPDATES_INTERVAL) ? |
3d72ca76538d
Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
0
diff
changeset
|
240 PUI_CHECK_UPDATES_INTERVAL - elapsed_time : |
3d72ca76538d
Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
0
diff
changeset
|
241 PUI_STARTUP_DELAY; |
3d72ca76538d
Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
0
diff
changeset
|
242 self->periodic_check_id = g_timeout_add_seconds(remaining_time, |
3d72ca76538d
Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
0
diff
changeset
|
243 periodic_check, self); |
3d72ca76538d
Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
0
diff
changeset
|
244 } |
3d72ca76538d
Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
0
diff
changeset
|
245 } |
3d72ca76538d
Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
0
diff
changeset
|
246 |
3d72ca76538d
Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
0
diff
changeset
|
247 static void |
0
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
248 pui_backend_set_property(GObject *object, guint property_id, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
249 const GValue *value, GParamSpec *pspec) |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
250 { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
251 PuiBackend *self = PUI_BACKEND(object); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
252 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
253 switch (property_id) { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
254 case PROP_REFRESH_INTERVAL: |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
255 self->refresh_interval = g_value_get_uint(value); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
256 g_debug("property \"refresh-interval\" set to %u", |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
257 self->refresh_interval); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
258 break; |
4
3d72ca76538d
Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
0
diff
changeset
|
259 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
|
260 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
|
261 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
|
262 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
|
263 check_inhibit(self); |
3d72ca76538d
Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
0
diff
changeset
|
264 break; |
0
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
265 default: |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
266 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
267 break; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
268 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
269 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
270 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
271 static void |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
272 pui_backend_get_property(GObject *object, guint property_id, GValue *value, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
273 GParamSpec *pspec) |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
274 { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
275 PuiBackend *self = PUI_BACKEND(object); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
276 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
277 switch (property_id) { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
278 case PROP_IMPORTANT_UPDATES: |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
279 g_value_set_uint(value, self->important_updates); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
280 break; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
281 case PROP_NORMAL_UPDATES: |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
282 g_value_set_uint(value, self->normal_updates); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
283 break; |
10
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
284 case PROP_RESTART_TYPE: |
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
285 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
|
286 break; |
0
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
287 case PROP_REFRESH_INTERVAL: |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
288 g_value_set_uint(value, self->refresh_interval); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
289 break; |
4
3d72ca76538d
Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
0
diff
changeset
|
290 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
|
291 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
|
292 break; |
0
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
293 default: |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
294 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
295 break; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
296 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
297 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
298 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
299 static void |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
300 pui_backend_dispose(GObject *object) |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
301 { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
302 PuiBackend *self = PUI_BACKEND(object); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
303 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
304 if (self->periodic_check_id != 0) { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
305 g_source_remove(self->periodic_check_id); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
306 self->periodic_check_id = 0; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
307 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
308 |
10
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
309 if (self->transaction_list != NULL) { |
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
310 g_clear_object(&self->transaction_list); |
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
311 } |
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
312 |
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
313 if (self->pk_client != NULL) { |
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
314 g_clear_object(&self->pk_client); |
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
315 } |
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
316 |
0
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
317 if (self->cancellable != NULL) { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
318 g_cancellable_cancel(self->cancellable); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
319 g_clear_object(&self->cancellable); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
320 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
321 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
322 if (self->pk_control != NULL) { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
323 g_clear_object(&self->pk_control); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
324 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
325 |
5
a4020e99e550
Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
4
diff
changeset
|
326 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
|
327 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
|
328 } |
a4020e99e550
Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
4
diff
changeset
|
329 |
a4020e99e550
Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
4
diff
changeset
|
330 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
|
331 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
|
332 } |
a4020e99e550
Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
4
diff
changeset
|
333 |
0
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
334 G_OBJECT_CLASS(pui_backend_parent_class)->dispose(object); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
335 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
336 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
337 static void |
6
2477a6151087
Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
5
diff
changeset
|
338 pui_backend_finalize(GObject *object) |
2477a6151087
Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
5
diff
changeset
|
339 { |
2477a6151087
Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
5
diff
changeset
|
340 PuiBackend *self = PUI_BACKEND(object); |
2477a6151087
Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
5
diff
changeset
|
341 |
2477a6151087
Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
5
diff
changeset
|
342 g_free(self->proxy_http); |
2477a6151087
Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
5
diff
changeset
|
343 g_free(self->proxy_https); |
2477a6151087
Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
5
diff
changeset
|
344 g_free(self->proxy_ftp); |
2477a6151087
Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
5
diff
changeset
|
345 g_free(self->proxy_socks); |
2477a6151087
Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
5
diff
changeset
|
346 g_free(self->no_proxy); |
2477a6151087
Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
5
diff
changeset
|
347 g_free(self->pac); |
2477a6151087
Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
5
diff
changeset
|
348 |
2477a6151087
Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
5
diff
changeset
|
349 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
|
350 } |
2477a6151087
Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
5
diff
changeset
|
351 |
2477a6151087
Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
5
diff
changeset
|
352 static void |
0
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
353 pui_backend_class_init(PuiBackendClass *klass) |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
354 { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
355 GObjectClass *object_class = G_OBJECT_CLASS(klass); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
356 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
357 object_class->set_property = pui_backend_set_property; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
358 object_class->get_property = pui_backend_get_property; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
359 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
|
360 object_class->finalize = pui_backend_finalize; |
0
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
361 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
362 properties[PROP_IMPORTANT_UPDATES] = |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
363 g_param_spec_uint("important-updates", "Important updates", |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
364 "Number of available important updates", 0, G_MAXUINT, 0, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
365 G_PARAM_READABLE); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
366 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
367 properties[PROP_NORMAL_UPDATES] = |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
368 g_param_spec_uint("normal-updates", "Normal updates", |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
369 "Number of available normal updates", 0, G_MAXUINT, 0, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
370 G_PARAM_READABLE); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
371 |
10
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
372 properties[PROP_RESTART_TYPE] = |
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
373 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
|
374 "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
|
375 G_PARAM_READABLE); |
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
376 |
0
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
377 properties[PROP_REFRESH_INTERVAL] = |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
378 g_param_spec_uint("refresh-interval", "Refresh interval", |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
379 "Interval in seconds for refreshing the package cache", 0, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
380 G_MAXUINT, PUI_DEFAULT_REFRESH_INTERVAL, G_PARAM_READWRITE); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
381 |
4
3d72ca76538d
Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
0
diff
changeset
|
382 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
|
383 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
|
384 "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
|
385 "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
|
386 G_PARAM_READWRITE); |
3d72ca76538d
Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
0
diff
changeset
|
387 |
0
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
388 g_object_class_install_properties(object_class, PROP_LAST, properties); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
389 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
390 signals[STATE_CHANGED] = g_signal_new("state-changed", |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
391 G_TYPE_FROM_CLASS(object_class), |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
392 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
|
393 NULL, NULL, NULL, G_TYPE_NONE, 0); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
394 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
395 signals[RESTART_REQUIRED] = g_signal_new("restart-required", |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
396 G_TYPE_FROM_CLASS(object_class), |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
397 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
|
398 NULL, NULL, NULL, G_TYPE_NONE, 0); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
399 } |
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 static void |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
402 pui_backend_init(PuiBackend *self) |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
403 { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
404 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
|
405 |
10
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
406 self->pk_client = pk_client_new(); |
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
407 |
4
3d72ca76538d
Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
0
diff
changeset
|
408 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
|
409 |
a4020e99e550
Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
4
diff
changeset
|
410 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
|
411 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
|
412 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
|
413 } |
0
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
414 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
415 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
416 static void |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
417 on_get_properties_finished(GObject *object, GAsyncResult *result, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
418 gpointer user_data) |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
419 { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
420 PkControl *control = PK_CONTROL(object); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
421 PuiBackend *self; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
422 GTask *task = user_data; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
423 GError *error = NULL; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
424 gchar *backend_name = NULL; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
425 PkBitfield roles = 0; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
426 gchar *roles_str = NULL; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
427 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
428 self = g_task_get_task_data(task); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
429 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
430 if (!pk_control_get_properties_finish(control, result, &error)) { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
431 g_task_return_error(task, error); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
432 goto out; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
433 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
434 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
435 /* check whether the backend supports GetUpdates */ |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
436 g_object_get(control, "backend-name", &backend_name, "roles", &roles, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
437 "network-state", &self->network_state, NULL); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
438 g_debug("backend: %s", backend_name); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
439 roles_str = pk_role_bitfield_to_string(roles); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
440 g_debug("roles: %s", roles_str); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
441 g_debug("network-state: %s", |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
442 pk_network_enum_to_string(self->network_state)); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
443 if (!pk_bitfield_contain(roles, PK_ROLE_ENUM_GET_UPDATES)) { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
444 error = g_error_new(PUI_BACKEND_ERROR, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
445 PUI_BACKEND_ERROR_GET_UPDATES_NOT_IMPLEMENTED, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
446 "Getting updates is not implemented in the %s PackageKit " |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
447 "backend", backend_name); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
448 g_task_return_error(task, error); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
449 goto out; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
450 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
451 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
452 g_task_return_boolean(task, TRUE); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
453 out: |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
454 g_free(roles_str); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
455 g_free(backend_name); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
456 g_object_unref(task); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
457 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
458 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
459 static void |
5
a4020e99e550
Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
4
diff
changeset
|
460 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
|
461 gpointer user_data) |
a4020e99e550
Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
4
diff
changeset
|
462 { |
a4020e99e550
Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
4
diff
changeset
|
463 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
|
464 UpDeviceKind kind; |
a4020e99e550
Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
4
diff
changeset
|
465 gdouble percentage; |
a4020e99e550
Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
4
diff
changeset
|
466 |
a4020e99e550
Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
4
diff
changeset
|
467 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
|
468 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
|
469 return; |
a4020e99e550
Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
4
diff
changeset
|
470 } |
a4020e99e550
Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
4
diff
changeset
|
471 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
|
472 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
|
473 (!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
|
474 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
|
475 check_inhibit(self); |
a4020e99e550
Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
4
diff
changeset
|
476 } |
a4020e99e550
Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
4
diff
changeset
|
477 } |
a4020e99e550
Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
4
diff
changeset
|
478 |
a4020e99e550
Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
4
diff
changeset
|
479 static void |
0
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
480 on_notify_network_state(PkControl *pk_control, GParamSpec *pspec, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
481 gpointer user_data) |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
482 { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
483 PuiBackend *self = user_data; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
484 |
4
3d72ca76538d
Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
0
diff
changeset
|
485 g_object_get(pk_control, "network-state", &self->network_state, NULL); |
0
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
486 g_debug("network state changed: %s", |
4
3d72ca76538d
Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
0
diff
changeset
|
487 pk_network_enum_to_string(self->network_state)); |
3d72ca76538d
Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
0
diff
changeset
|
488 check_inhibit(self); |
0
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
489 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
490 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
491 static void |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
492 on_updates_changed(PkControl *control, gpointer user_data) |
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 PuiBackend *self = user_data; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
495 |
10
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
496 g_debug("number of updates changed"); |
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
497 |
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 * 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
|
500 * signals is coalesced |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
501 */ |
4
3d72ca76538d
Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
0
diff
changeset
|
502 if (!self->inhibited) { |
0
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
503 if (self->periodic_check_id != 0) { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
504 g_source_remove(self->periodic_check_id); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
505 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
506 self->periodic_check_id = |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
507 g_timeout_add_seconds(PUI_STARTUP_DELAY, periodic_check, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
508 self); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
509 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
510 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
511 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
512 static void |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
513 on_restart_schedule(PkControl *control, gpointer user_data) |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
514 { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
515 PuiBackend *self = user_data; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
516 |
10
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
517 /* |
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
518 * 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
|
519 * 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
|
520 * 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
|
521 * 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
|
522 */ |
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
523 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
|
524 return; |
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
525 } |
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
526 |
0
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
527 g_debug("emitting signal restart-required"); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
528 g_signal_emit(self, signals[RESTART_REQUIRED], 0); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
529 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
530 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
531 static void |
10
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
532 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
|
533 gpointer user_data) |
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
534 { |
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
535 PuiBackend *self = user_data; |
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
536 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
|
537 PkResults *results; |
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
538 GError *error = NULL; |
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
539 PkRestartEnum restart; |
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
540 |
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
541 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
|
542 if (results == NULL) { |
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
543 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
|
544 error->message); |
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
545 g_error_free(error); |
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
546 goto out; |
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
547 } |
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
548 |
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
549 /* check if transaction requires a restart */ |
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
550 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
|
551 switch (restart) { |
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
552 case PK_RESTART_ENUM_SESSION: /* FALLTHROUGH */ |
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
553 case PK_RESTART_ENUM_SECURITY_SESSION: |
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
554 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
|
555 self->restart_type = PUI_RESTART_SESSION; |
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
556 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
|
557 properties[PROP_RESTART_TYPE]); |
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
558 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
|
559 } |
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
560 break; |
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
561 case PK_RESTART_ENUM_SYSTEM: /* FALLTHROUGH */ |
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
562 case PK_RESTART_ENUM_SECURITY_SYSTEM: |
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
563 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
|
564 self->restart_type = PUI_RESTART_SYSTEM; |
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
565 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
|
566 properties[PROP_RESTART_TYPE]); |
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
567 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
|
568 } |
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
569 break; |
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
570 default: |
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
571 /* do nothing */ |
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
572 break; |
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
573 } |
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
574 |
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
575 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
|
576 pk_restart_enum_to_string(restart)); |
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
577 |
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
578 out: |
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
579 if (results != NULL) { |
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
580 g_object_unref(results); |
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
581 } |
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
582 } |
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
583 |
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
584 static void |
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
585 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
|
586 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
|
587 { |
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
588 PuiBackend *self = user_data; |
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
589 |
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
590 /* 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
|
591 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
|
592 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
|
593 } |
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
594 |
adba37525ee5
Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
6
diff
changeset
|
595 static void |
0
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
596 pui_backend_init_async(GAsyncInitable *initable, int io_priority, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
597 GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
598 { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
599 PuiBackend *self = PUI_BACKEND(initable); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
600 GTask *task; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
601 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
602 task = g_task_new(G_OBJECT(initable), cancellable, callback, user_data); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
603 g_task_set_priority(task, io_priority); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
604 g_task_set_task_data(task, g_object_ref(self), |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
605 (GDestroyNotify)g_object_unref); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
606 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
607 pk_control_get_properties_async(self->pk_control, cancellable, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
608 on_get_properties_finished, task); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
609 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
610 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
611 static gboolean |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
612 pui_backend_init_finish(GAsyncInitable *initable, GAsyncResult *result, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
613 GError **errorp) |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
614 { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
615 PuiBackend *self = PUI_BACKEND(initable); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
616 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
|
617 UpDeviceKind kind; |
a4020e99e550
Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
4
diff
changeset
|
618 gdouble percentage; |
0
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
619 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
620 if (!g_task_propagate_boolean(task, errorp)) { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
621 return (FALSE); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
622 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
623 |
5
a4020e99e550
Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
4
diff
changeset
|
624 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
|
625 /* 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
|
626 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
|
627 &percentage, NULL); |
a4020e99e550
Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
4
diff
changeset
|
628 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
|
629 (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
|
630 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
|
631 (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
|
632 } |
a4020e99e550
Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
4
diff
changeset
|
633 |
a4020e99e550
Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
4
diff
changeset
|
634 /* 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
|
635 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
|
636 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
|
637 } |
a4020e99e550
Do not check for updates if the battery is low
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
4
diff
changeset
|
638 |
0
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
639 /* get notification when the network state changes */ |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
640 g_signal_connect(self->pk_control, "notify::network-state", |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
641 G_CALLBACK(on_notify_network_state), self); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
642 /* get notifications when the available package updates change */ |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
643 g_signal_connect(self->pk_control, "updates-changed", |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
644 G_CALLBACK(on_updates_changed), self); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
645 /* get notifications when an application restart is required */ |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
646 g_signal_connect(self->pk_control, "restart-schedule", |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
647 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
|
648 /* 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
|
649 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
|
650 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
|
651 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
|
652 |
3d72ca76538d
Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
0
diff
changeset
|
653 check_inhibit(self); |
0
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
654 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
655 return (TRUE); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
656 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
657 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
658 static void |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
659 pui_backend_async_initable_iface_init(gpointer g_iface, gpointer iface_data) |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
660 { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
661 GAsyncInitableIface *iface = g_iface; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
662 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
663 iface->init_async = pui_backend_init_async; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
664 iface->init_finish = pui_backend_init_finish; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
665 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
666 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
667 void |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
668 pui_backend_new_async(GCancellable *cancellable, GAsyncReadyCallback callback, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
669 gpointer user_data) |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
670 { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
671 g_async_initable_new_async(PUI_TYPE_BACKEND, G_PRIORITY_DEFAULT, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
672 cancellable, callback, user_data, NULL); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
673 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
674 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
675 PuiBackend * |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
676 pui_backend_new_finish(GAsyncResult *result, GError **errorp) |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
677 { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
678 GObject *object; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
679 GObject *source_object; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
680 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
681 source_object = g_async_result_get_source_object(result); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
682 object = g_async_initable_new_finish(G_ASYNC_INITABLE(source_object), |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
683 result, errorp); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
684 g_object_unref(source_object); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
685 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
686 return ((object != NULL) ? PUI_BACKEND(object) : NULL); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
687 } |
6
2477a6151087
Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
5
diff
changeset
|
688 |
2477a6151087
Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
5
diff
changeset
|
689 static void |
2477a6151087
Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
5
diff
changeset
|
690 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
|
691 gpointer user_data) |
2477a6151087
Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
5
diff
changeset
|
692 { |
2477a6151087
Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
5
diff
changeset
|
693 PuiBackend *self = user_data; |
2477a6151087
Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
5
diff
changeset
|
694 GError *error = NULL; |
2477a6151087
Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
5
diff
changeset
|
695 |
2477a6151087
Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
5
diff
changeset
|
696 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
|
697 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
|
698 g_error_free(error); |
2477a6151087
Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
5
diff
changeset
|
699 } |
2477a6151087
Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
5
diff
changeset
|
700 } |
2477a6151087
Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
5
diff
changeset
|
701 |
2477a6151087
Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
5
diff
changeset
|
702 static void |
2477a6151087
Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
5
diff
changeset
|
703 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
|
704 gpointer user_data) |
2477a6151087
Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
5
diff
changeset
|
705 { |
2477a6151087
Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
5
diff
changeset
|
706 PuiBackend *self = user_data; |
2477a6151087
Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
5
diff
changeset
|
707 GPermission *permission; |
2477a6151087
Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
5
diff
changeset
|
708 GError *error = NULL; |
2477a6151087
Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
5
diff
changeset
|
709 |
2477a6151087
Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
5
diff
changeset
|
710 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
|
711 if (permission == NULL) { |
2477a6151087
Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
5
diff
changeset
|
712 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
|
713 "network proxies: %s", error->message); |
2477a6151087
Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
5
diff
changeset
|
714 g_error_free(error); |
2477a6151087
Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
5
diff
changeset
|
715 return; |
2477a6151087
Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
5
diff
changeset
|
716 } |
2477a6151087
Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
5
diff
changeset
|
717 |
2477a6151087
Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
5
diff
changeset
|
718 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
|
719 /* 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
|
720 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
|
721 return; |
2477a6151087
Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
5
diff
changeset
|
722 } |
2477a6151087
Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
5
diff
changeset
|
723 |
2477a6151087
Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
5
diff
changeset
|
724 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
|
725 self->proxy_http : "(null)"); |
2477a6151087
Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
5
diff
changeset
|
726 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
|
727 self->proxy_https : "(null)"); |
2477a6151087
Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
5
diff
changeset
|
728 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
|
729 self->proxy_ftp : "(null)"); |
2477a6151087
Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
5
diff
changeset
|
730 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
|
731 self->proxy_socks : "(null)"); |
2477a6151087
Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
5
diff
changeset
|
732 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
|
733 "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
|
734 "(null)"); |
2477a6151087
Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
5
diff
changeset
|
735 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
|
736 self->pac : "(null)"); |
2477a6151087
Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
5
diff
changeset
|
737 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
|
738 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
|
739 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
|
740 } |
2477a6151087
Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
5
diff
changeset
|
741 |
2477a6151087
Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
5
diff
changeset
|
742 void |
2477a6151087
Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
5
diff
changeset
|
743 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
|
744 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
|
745 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
|
746 { |
2477a6151087
Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
5
diff
changeset
|
747 g_free(self->proxy_http); |
2477a6151087
Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
5
diff
changeset
|
748 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
|
749 g_free(self->proxy_https); |
2477a6151087
Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
5
diff
changeset
|
750 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
|
751 NULL; |
2477a6151087
Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
5
diff
changeset
|
752 g_free(self->proxy_ftp); |
2477a6151087
Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
5
diff
changeset
|
753 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
|
754 g_free(self->proxy_socks); |
2477a6151087
Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
5
diff
changeset
|
755 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
|
756 NULL; |
2477a6151087
Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
5
diff
changeset
|
757 g_free(self->no_proxy); |
2477a6151087
Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
5
diff
changeset
|
758 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
|
759 g_free(self->pac); |
2477a6151087
Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
5
diff
changeset
|
760 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
|
761 |
2477a6151087
Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
5
diff
changeset
|
762 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
|
763 "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
|
764 on_polkit_permission_finished, self); |
2477a6151087
Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
5
diff
changeset
|
765 } |