annotate pkui-backend.c @ 14:64f05992d8ec

GObject-based rewrite use asynchronous packagekit-glib API use persistent menu widget and notification object update existing notification when new updates become available, close it when no updates are available show status icon when updates are available, hide it when no updates are available hide icon when gpk-update-viewer is executed, check for updates when gpk-update-viewer exits introduce a startup delay before the first check for updates is made add context menu item to manually trigger a check for updates remove context menu item for quitting pk-update-icon
author Guido Berhoerster <guido@berhoerster.name>
date Thu, 20 Oct 2011 08:19:22 +0200
parents
children a8d8fba520ec
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
1 /*
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
2 * (C) 2011 Guido Berhoerster <gber@opensuse.org>
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
3 *
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
4 * Licensed under the GNU General Public License Version 2
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
5 *
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or modify
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
7 * it under the terms of the GNU General Public License as published by
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
9 * (at your option) any later version.
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
10 *
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
11 * This program is distributed in the hope that it will be useful,
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
14 * GNU General Public License for more details.
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
15 *
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
17 * along with this program; if not, write to the Free Software
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
19 */
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
20
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
21 #include <packagekit-glib2/packagekit.h>
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
22 #include "pkui-backend.h"
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
23
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
24 G_DEFINE_TYPE(PkuiBackend, pkui_backend, G_TYPE_OBJECT)
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
25
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
26 #define PKUI_BACKEND_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), \
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
27 PKUI_TYPE_BACKEND, PkuiBackendPrivate))
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
28
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
29 struct _PkuiBackendPrivate
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
30 {
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
31 PkuiBackend *backend;
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
32 PkClient *pk_client;
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
33 guint periodic_check_id;
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
34 guint updates_normal;
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
35 guint updates_important;
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
36 guint previous_updates_normal;
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
37 guint previous_updates_important;
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
38 guint startup_delay;
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
39 guint check_interval;
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
40 gint64 last_check;
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
41 gboolean inhibit_check;
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
42 };
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
43
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
44 enum
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
45 {
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
46 PROP_0,
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
47
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
48 PROP_UPDATES_NORMAL,
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
49 PROP_UPDATES_IMPORTANT,
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
50 PROP_STARTUP_DELAY,
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
51 PROP_CHECK_INTERVAL,
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
52 PROP_INHIBIT_CHECK
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
53 };
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
54
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
55 enum
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
56 {
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
57 STATE_CHANGED_SIGNAL,
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
58
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
59 LAST_SIGNAL
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
60 };
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
61
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
62 static guint pkui_backend_signals[LAST_SIGNAL] = { 0, };
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
63
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
64 static gboolean periodic_check(gpointer data);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
65
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
66 static void
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
67 pkui_backend_set_property(GObject *object, guint property_id,
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
68 const GValue *value, GParamSpec *pspec)
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
69 {
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
70 PkuiBackend *self = PKUI_BACKEND(object);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
71 gboolean inhibit_check;
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
72 gint64 time_to_check;
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
73
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
74 switch (property_id) {
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
75 case PROP_STARTUP_DELAY:
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
76 self->priv->startup_delay = g_value_get_uint(value);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
77
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
78 g_source_remove(self->priv->periodic_check_id);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
79 self->priv->periodic_check_id =
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
80 g_timeout_add_seconds(self->priv->startup_delay,
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
81 (GSourceFunc)periodic_check, self);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
82 break;
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
83 case PROP_CHECK_INTERVAL:
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
84 self->priv->check_interval = g_value_get_uint(value);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
85
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
86 /*
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
87 * reschedule only if the first run has been completed and
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
88 * checks are currently not inibited, otherwise the new
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
89 * interval will be picked up anyway
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
90 */
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
91 if (!self->priv->inhibit_check && self->priv->last_check > 0) {
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
92 time_to_check = g_get_real_time() -
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
93 self->priv->last_check;
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
94 if (time_to_check <= 0)
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
95 pkui_backend_check_now(self);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
96 else {
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
97 g_source_remove(self->priv->periodic_check_id);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
98 self->priv->periodic_check_id =
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
99 g_timeout_add_seconds(time_to_check,
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
100 periodic_check, self);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
101 }
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
102 }
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
103 break;
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
104 case PROP_INHIBIT_CHECK:
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
105 inhibit_check = g_value_get_boolean(value);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
106
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
107 /*
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
108 * when changing self->priv->inhibit_check from FALSE to TRUE
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
109 * and the first run has been completed remove the periodic
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
110 * check, when changing from TRUE to FALSE either trigger a run
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
111 * immediately when more time than self->priv->check_interval
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
112 * has passed or just reschedule the next check
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
113 */
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
114 if (!self->priv->inhibit_check && inhibit_check &&
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
115 self->priv->periodic_check_id != 0) {
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
116 g_source_remove(self->priv->periodic_check_id);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
117 self->priv->periodic_check_id = 0;
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
118 } else if (self->priv->inhibit_check && !inhibit_check) {
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
119 self->priv->periodic_check_id =
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
120 g_timeout_add_seconds(self->priv->check_interval,
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
121 (GSourceFunc)periodic_check, self);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
122 }
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
123 self->priv->inhibit_check = inhibit_check;
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
124 break;
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
125 default:
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
126 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
127 break;
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
128 }
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
129 }
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
130
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
131 static void
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
132 pkui_backend_get_property(GObject *object, guint property_id, GValue *value,
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
133 GParamSpec *pspec)
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
134 {
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
135 PkuiBackend *self = PKUI_BACKEND(object);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
136
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
137 switch (property_id) {
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
138 case PROP_UPDATES_NORMAL:
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
139 g_value_set_uint(value, self->priv->updates_normal);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
140 break;
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
141 case PROP_UPDATES_IMPORTANT:
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
142 g_value_set_uint(value, self->priv->updates_important);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
143 break;
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
144 case PROP_STARTUP_DELAY:
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
145 g_value_set_uint(value, self->priv->startup_delay);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
146 break;
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
147 case PROP_CHECK_INTERVAL:
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
148 g_value_set_uint(value, self->priv->check_interval);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
149 break;
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
150 case PROP_INHIBIT_CHECK:
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
151 g_value_set_boolean(value, self->priv->inhibit_check);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
152 break;
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
153 default:
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
154 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
155 break;
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
156 }
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
157 }
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
158
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
159 static void
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
160 pkui_backend_finalize(GObject *gobject)
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
161 {
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
162 PkuiBackend *self = PKUI_BACKEND(gobject);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
163
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
164 if (self->priv->pk_client != NULL)
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
165 g_object_unref(self->priv->pk_client);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
166
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
167 G_OBJECT_CLASS(pkui_backend_parent_class)->finalize(gobject);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
168 }
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
169
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
170 static void
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
171 pkui_backend_class_init(PkuiBackendClass *klass)
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
172 {
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
173 GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
174 GParamSpec *pspec;
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
175
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
176 gobject_class->set_property = pkui_backend_set_property;
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
177 gobject_class->get_property = pkui_backend_get_property;
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
178 gobject_class->finalize = pkui_backend_finalize;
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
179
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
180 pspec = g_param_spec_uint("updates-normal", "Normal updates",
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
181 "Number of normal package updates", 0, G_MAXUINT, 0,
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
182 G_PARAM_READABLE);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
183 g_object_class_install_property(gobject_class, PROP_UPDATES_NORMAL,
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
184 pspec);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
185
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
186 pspec = g_param_spec_uint("updates-important", "Important updates",
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
187 "Number of important package updates", 0, G_MAXUINT, 0,
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
188 G_PARAM_READABLE);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
189 g_object_class_install_property(gobject_class, PROP_UPDATES_IMPORTANT,
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
190 pspec);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
191
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
192 pspec = g_param_spec_uint("startup-delay", "Startup delay",
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
193 "Initial delay in second before the first check for new package "
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
194 "updates", 0, G_MAXUINT, 60,
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
195 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
196 g_object_class_install_property(gobject_class, PROP_STARTUP_DELAY,
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
197 pspec);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
198
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
199 pspec = g_param_spec_uint("check-interval", "Check interval",
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
200 "Interval in seconds for checking for new package updates", 1,
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
201 G_MAXUINT, 3600, G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
202 g_object_class_install_property(gobject_class, PROP_CHECK_INTERVAL,
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
203 pspec);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
204
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
205 pspec = g_param_spec_boolean("inhibit-check", "Inhibit check",
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
206 "Whether to inhibit checks for new package updates", FALSE,
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
207 G_PARAM_READWRITE);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
208 g_object_class_install_property(gobject_class, PROP_INHIBIT_CHECK,
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
209 pspec);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
210
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
211 pkui_backend_signals[STATE_CHANGED_SIGNAL] =
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
212 g_signal_newv("state-changed", G_TYPE_FROM_CLASS(gobject_class),
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
213 G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS, NULL,
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
214 NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0, NULL);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
215
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
216 g_type_class_add_private(klass, sizeof (PkuiBackendPrivate));
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
217 }
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
218
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
219 static void
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
220 pkui_backend_init(PkuiBackend *self)
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
221 {
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
222 self->priv = PKUI_BACKEND_GET_PRIVATE(self);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
223
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
224 self->priv->pk_client = pk_client_new();
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
225 self->priv->updates_normal = 0;
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
226 self->priv->updates_important = 0;
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
227 self->priv->periodic_check_id =
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
228 g_timeout_add_seconds(self->priv->startup_delay,
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
229 (GSourceFunc)periodic_check, self);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
230 self->priv->last_check = 0;
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
231 }
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
232
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
233 static gboolean
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
234 periodic_check(gpointer data)
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
235 {
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
236 PkuiBackend *self = PKUI_BACKEND(data);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
237
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
238 pkui_backend_check_now(self);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
239
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
240 /* rescheduling happens after results are available */
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
241 return (FALSE);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
242 }
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
243
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
244 static void
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
245 process_pk_package_info(PkPackage *pkg, gpointer *user_data)
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
246 {
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
247 PkuiBackend *self = PKUI_BACKEND(user_data);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
248 PkInfoEnum type_info = pk_package_get_info(pkg);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
249
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
250 switch (type_info) {
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
251 case PK_INFO_ENUM_LOW:
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
252 case PK_INFO_ENUM_ENHANCEMENT:
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
253 case PK_INFO_ENUM_NORMAL:
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
254 self->priv->updates_normal++;
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
255 break;
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
256 case PK_INFO_ENUM_BUGFIX:
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
257 case PK_INFO_ENUM_IMPORTANT:
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
258 case PK_INFO_ENUM_SECURITY:
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
259 self->priv->updates_important++;
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
260 break;
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
261 default:
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
262 break;
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
263 }
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
264 }
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
265
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
266 static void
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
267 get_updates_finished(GObject *object, GAsyncResult *res, gpointer user_data)
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
268 {
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
269 PkClient *client = PK_CLIENT(object);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
270 PkuiBackend *self = PKUI_BACKEND(user_data);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
271 PkResults *results = NULL;
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
272 GError *error = NULL;
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
273 GPtrArray *list = NULL;
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
274
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
275 g_debug("PackageKit finished checking for updates");
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
276
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
277 results = pk_client_generic_finish(PK_CLIENT(client), res, &error);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
278 if (results == NULL) {
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
279 g_warning("error: %s\n", error->message);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
280 g_error_free(error);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
281 goto out;
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
282 }
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
283
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
284 list = pk_results_get_package_array(results);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
285 if (list == NULL)
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
286 goto out;
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
287 self->priv->previous_updates_normal = self->priv->updates_normal;
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
288 self->priv->previous_updates_important = self->priv->updates_important;
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
289 self->priv->updates_normal = 0;
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
290 self->priv->updates_important = 0;
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
291 g_ptr_array_foreach(list, (GFunc)process_pk_package_info, self);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
292
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
293 if (self->priv->updates_normal != self->priv->previous_updates_normal ||
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
294 self->priv->updates_important !=
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
295 self->priv->previous_updates_important) {
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
296 g_debug("normal updates: %d, important updates: %d",
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
297 self->priv->updates_normal, self->priv->updates_important);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
298 g_debug("emit state-changed");
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
299
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
300 g_signal_emit(self, pkui_backend_signals[STATE_CHANGED_SIGNAL],
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
301 0);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
302 }
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
303
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
304 out:
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
305 if (results != NULL)
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
306 g_object_unref(results);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
307 if (list != NULL)
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
308 g_ptr_array_unref(list);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
309
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
310 self->priv->last_check = g_get_real_time();
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
311
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
312 if (!self->priv->inhibit_check) {
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
313 if (self->priv->periodic_check_id != 0)
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
314 g_source_remove(self->priv->periodic_check_id);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
315 self->priv->periodic_check_id =
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
316 g_timeout_add_seconds(self->priv->check_interval,
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
317 (GSourceFunc)periodic_check, self);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
318 }
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
319 }
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
320
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
321 PkuiBackend *
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
322 pkui_backend_new(guint startup_delay, guint check_interval)
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
323 {
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
324 g_return_val_if_fail(check_interval > 0, NULL);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
325
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
326 return (g_object_new(PKUI_TYPE_BACKEND, "startup-delay", startup_delay,
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
327 "check-interval", check_interval, NULL));
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
328 }
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
329
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
330 guint
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
331 pkui_backend_get_updates_normal(PkuiBackend *self)
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
332 {
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
333 guint updates_normal;
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
334
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
335 g_return_val_if_fail(PKUI_IS_BACKEND(self), 0);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
336
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
337 g_object_get(G_OBJECT(self), "updates-normal", &updates_normal, NULL);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
338
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
339 return (updates_normal);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
340 }
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
341
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
342 guint
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
343 pkui_backend_get_updates_important(PkuiBackend *self)
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
344 {
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
345 guint updates_important;
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
346
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
347 g_return_val_if_fail(PKUI_IS_BACKEND(self), 0);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
348
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
349 g_object_get(G_OBJECT(self), "updates-important", &updates_important,
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
350 NULL);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
351
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
352 return (updates_important);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
353 }
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
354
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
355 void
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
356 pkui_backend_set_inhibit_check(PkuiBackend *self, gboolean inhibit_check)
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
357 {
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
358 g_return_if_fail(PKUI_IS_BACKEND(self));
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
359
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
360 g_object_set(G_OBJECT(self), "inhibit-check", inhibit_check, NULL);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
361 }
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
362
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
363 gboolean
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
364 pkui_backend_get_inhibit_check(PkuiBackend *self)
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
365 {
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
366 gboolean inhibit_check;
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
367
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
368 g_return_val_if_fail(PKUI_IS_BACKEND(self), FALSE);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
369
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
370 g_object_get(G_OBJECT(self), "inhibit-check", &inhibit_check, NULL);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
371
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
372 return (inhibit_check);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
373 }
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
374
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
375 guint
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
376 pkui_backend_get_startup_interval(PkuiBackend *self)
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
377 {
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
378 guint startup_interval;
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
379
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
380 g_return_val_if_fail(PKUI_IS_BACKEND(self), 0);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
381
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
382 g_object_get(G_OBJECT(self), "startup-interval", &startup_interval,
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
383 NULL);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
384
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
385 return (startup_interval);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
386 }
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
387
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
388 void
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
389 pkui_backend_set_check_interval(PkuiBackend *self, guint check_interval)
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
390 {
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
391 g_return_if_fail(PKUI_IS_BACKEND(self));
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
392
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
393 g_object_set(G_OBJECT(self), "check-interval", check_interval, NULL);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
394 }
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
395
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
396 guint
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
397 pkui_backend_get_check_interval(PkuiBackend *self)
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
398 {
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
399 guint check_interval;
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
400
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
401 g_return_val_if_fail(PKUI_IS_BACKEND(self), 0);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
402
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
403 g_object_get(G_OBJECT(self), "check-interval", &check_interval, NULL);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
404
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
405 return (check_interval);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
406 }
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
407
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
408 void
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
409 pkui_backend_check_now(PkuiBackend *self)
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
410 {
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
411 g_return_if_fail(PKUI_IS_BACKEND(self));
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
412
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
413 g_debug("querying PackageKit for updates");
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
414
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
415 pk_client_get_updates_async(self->priv->pk_client,
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
416 pk_bitfield_value(PK_FILTER_ENUM_NONE), NULL, NULL, NULL,
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
417 get_updates_finished, self);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
418 }