Mercurial > projects > package-update-indicator
annotate pui-get-updates.c @ 23:e49c0fe6ab6c
Use consistent vocabulary in German translations
author | Guido Berhoerster <guido+pui@berhoerster.name> |
---|---|
date | Wed, 24 Jul 2019 10:30:38 +0200 |
parents | 6884bb8130ca |
children |
rev | line source |
---|---|
0
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
1 /* |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
2 * Copyright (C) 2018 Guido Berhoerster <guido+pui@berhoerster.name> |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
3 * |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
4 * Permission is hereby granted, free of charge, to any person obtaining |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
5 * a copy of this software and associated documentation files (the |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
6 * "Software"), to deal in the Software without restriction, including |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
7 * without limitation the rights to use, copy, modify, merge, publish, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
8 * distribute, sublicense, and/or sell copies of the Software, and to |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
9 * permit persons to whom the Software is furnished to do so, subject to |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
10 * the following conditions: |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
11 * |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
12 * The above copyright notice and this permission notice shall be included |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
13 * in all copies or substantial portions of the Software. |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
14 * |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
22 */ |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
23 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
24 #include "pui-get-updates.h" |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
25 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
26 typedef struct { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
27 PkControl *pk_control; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
28 PkTask *pk_task; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
29 guint refresh_interval; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
30 } PuiGetUpdates; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
31 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
32 GQuark |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
33 pui_get_updates_error_quark(void) |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
34 { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
35 return (g_quark_from_static_string("pui-get-updates-error-quark")); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
36 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
37 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
38 static void |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
39 on_get_updates_finished(GObject *source_object, GAsyncResult *async_result, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
40 gpointer user_data) |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
41 { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
42 GTask *task = user_data; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
43 PuiGetUpdates *get_updates; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
44 PkResults *results = NULL; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
45 PkError *pk_error = NULL; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
46 GError *error = NULL; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
47 gint error_code; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
48 GPtrArray *package_list; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
49 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
50 get_updates = g_task_get_task_data(task); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
51 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
52 g_debug("get updates transaction finished"); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
53 results = pk_client_generic_finish(PK_CLIENT(get_updates->pk_task), |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
54 async_result, &error); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
55 if (results == NULL) { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
56 /* pass the error on */ |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
57 g_task_return_error(task, error); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
58 goto out; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
59 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
60 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
61 pk_error = pk_results_get_error_code(results); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
62 if (pk_error != NULL) { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
63 /* transaction failed, return error */ |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
64 g_debug("failed to refresh the cache: %s", |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
65 pk_error_get_details(pk_error)); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
66 if (pk_error_get_code(pk_error) == |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
67 PK_ERROR_ENUM_TRANSACTION_CANCELLED) { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
68 error_code = PUI_GET_UPDATES_ERROR_CANCELLED; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
69 } else { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
70 error_code = |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
71 PUI_GET_UPDATES_ERROR_GET_UPDATES_FAILED; |
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 error = g_error_new(PUI_GET_UPDATES_ERROR, error_code, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
74 "Failed to get package updates: %s", |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
75 pk_error_get_details(pk_error)); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
76 g_task_return_error(task, error); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
77 g_object_unref(pk_error); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
78 goto out; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
79 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
80 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
81 /* return results */ |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
82 package_list = pk_results_get_package_array(results); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
83 g_assert(package_list != NULL); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
84 g_task_return_pointer(task, package_list, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
85 (GDestroyNotify)g_ptr_array_unref); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
86 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
87 out: |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
88 if (results != NULL) { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
89 g_object_unref(results); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
90 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
91 g_object_unref(task); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
92 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
93 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
94 static void |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
95 on_refresh_cache_finished(GObject *source_object, GAsyncResult *async_result, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
96 gpointer user_data) |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
97 { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
98 GTask *task = user_data; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
99 PuiGetUpdates *get_updates; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
100 PkResults *results = NULL; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
101 PkClient *pk_client; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
102 GError *error = NULL; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
103 PkError *pk_error = NULL; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
104 gint error_code; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
105 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
106 get_updates = g_task_get_task_data(task); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
107 pk_client = PK_CLIENT(get_updates->pk_task); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
108 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
109 g_debug("refresh cache transaction finished"); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
110 results = pk_client_generic_finish(pk_client, async_result, &error); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
111 if (results == NULL) { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
112 g_task_return_error(task, error); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
113 goto out; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
114 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
115 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
116 pk_error = pk_results_get_error_code(results); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
117 if (pk_error != NULL) { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
118 /* transaction failed, return error */ |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
119 g_debug("failed to refresh the cache: %s", |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
120 pk_error_get_details(pk_error)); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
121 if (pk_error_get_code(pk_error) == |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
122 PK_ERROR_ENUM_TRANSACTION_CANCELLED) { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
123 error_code = PUI_GET_UPDATES_ERROR_CANCELLED; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
124 } else { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
125 error_code = PUI_GET_UPDATES_ERROR_REFRESH_FAILED; |
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 error = g_error_new(PUI_GET_UPDATES_ERROR, error_code, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
128 "Failed to refresh the cache: %s", |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
129 pk_error_get_details(pk_error)); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
130 g_task_return_error(task, error); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
131 g_object_unref(pk_error); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
132 goto out; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
133 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
134 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
135 /* cache is up to date, get updates */ |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
136 pk_client_get_updates_async(pk_client, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
137 pk_bitfield_value(PK_FILTER_ENUM_NONE), |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
138 g_task_get_cancellable(task), NULL, NULL, on_get_updates_finished, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
139 task); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
140 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
141 out: |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
142 if (results != NULL) { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
143 g_object_unref(results); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
144 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
145 } |
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 static void |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
148 on_get_time_since_refresh_finished(GObject *source_object, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
149 GAsyncResult *async_result, gpointer user_data) |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
150 { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
151 GTask *task = user_data; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
152 PuiGetUpdates *get_updates; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
153 guint last_refresh; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
154 GError *error = NULL; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
155 PkClient *pk_client; |
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 get_updates = g_task_get_task_data(task); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
158 pk_client = PK_CLIENT(get_updates->pk_task); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
159 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
160 last_refresh = |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
161 pk_control_get_time_since_action_finish(get_updates->pk_control, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
162 async_result, &error); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
163 if (last_refresh == 0) { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
164 g_task_return_error(task, error); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
165 g_object_unref(task); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
166 return; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
167 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
168 g_debug("time since last cache refresh: %us", last_refresh); |
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 if (last_refresh > get_updates->refresh_interval) { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
171 /* cache is out of date, refresh first */ |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
172 g_debug("refreshing the cache"); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
173 pk_client_refresh_cache_async(pk_client, FALSE, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
174 g_task_get_cancellable(task), NULL, NULL, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
175 on_refresh_cache_finished, task); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
176 } else { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
177 /* cache is up to date, get updates */ |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
178 g_debug("getting updates"); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
179 pk_client_get_updates_async(pk_client, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
180 pk_bitfield_value(PK_FILTER_ENUM_NONE), |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
181 g_task_get_cancellable(task), NULL, NULL, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
182 on_get_updates_finished, task); |
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 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
186 static void |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
187 pui_get_updates_free(gpointer data) |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
188 { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
189 PuiGetUpdates *get_updates = data; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
190 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
191 g_object_unref(get_updates->pk_control); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
192 g_object_unref(get_updates->pk_task); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
193 g_slice_free(PuiGetUpdates, data); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
194 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
195 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
196 void |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
197 pui_get_updates_async(PkControl *pk_control, guint refresh_interval, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
198 GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
199 { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
200 PuiGetUpdates *get_updates; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
201 GTask *task; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
202 PkClient *pk_client; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
203 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
204 get_updates = g_slice_new0(PuiGetUpdates); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
205 get_updates->pk_control = g_object_ref(pk_control); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
206 get_updates->pk_task = pk_task_new(); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
207 get_updates->refresh_interval = refresh_interval; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
208 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
209 pk_client = PK_CLIENT(get_updates->pk_task); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
210 pk_client_set_cache_age(pk_client, refresh_interval); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
211 pk_client_set_background(pk_client, TRUE); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
212 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
213 task = g_task_new(NULL, cancellable, callback, user_data); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
214 g_task_set_task_data(task, get_updates, pui_get_updates_free); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
215 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
216 /* check whether to refresh the cache before checking for updates */ |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
217 g_debug("getting the time since the cache was last refreshed"); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
218 pk_control_get_time_since_action_async(pk_control, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
219 PK_ROLE_ENUM_REFRESH_CACHE, cancellable, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
220 on_get_time_since_refresh_finished, task); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
221 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
222 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
223 GPtrArray * |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
224 pui_get_updates_finish(GAsyncResult *result, GError **errorp) |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
225 { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
226 return (g_task_propagate_pointer(G_TASK(result), errorp)); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
227 } |