projects/package-update-indicator

view pui-application.c @ 10:adba37525ee5

Notify about required session or system restarts

Follow all PackageKit transactions and indicate when a session or system
restart is required.
Generate enum types with glib-mkenums.
author Guido Berhoerster <guido+pui@berhoerster.name>
date Fri Jul 06 14:12:46 2018 +0200 (2018-07-06)
parents 2477a6151087
children f783ba95ec4a
line source
1 /*
2 * Copyright (C) 2018 Guido Berhoerster <guido+pui@berhoerster.name>
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
24 #include <gio/gdesktopappinfo.h>
25 #include <glib/gi18n.h>
26 #include <libappindicator/app-indicator.h>
27 #include <stdlib.h>
28 #include <string.h>
30 #include "pui-application.h"
31 #include "pui-backend.h"
32 #include "pui-common.h"
33 #include "pui-settings.h"
34 #include "pui-types.h"
36 struct _PuiApplication {
37 GApplication parent_instance;
38 GSettings *settings;
39 GCancellable *cancellable;
40 PuiBackend *backend;
41 AppIndicator *indicator;
42 GtkWidget *about_dialog;
43 GIcon *icons[PUI_STATE_LAST];
44 PuiState state;
45 gchar *update_command;
46 gchar *error_message;
47 };
49 G_DEFINE_TYPE(PuiApplication, pui_application, G_TYPE_APPLICATION)
51 enum {
52 PROP_0,
53 PROP_UPDATE_COMMAND,
54 PROP_LAST
55 };
57 extern gboolean restart;
59 static GParamSpec *properties[PROP_LAST] = { NULL };
61 static const gchar *icon_names[PUI_STATE_LAST] = {
62 [PUI_STATE_INITIAL] = "system-software-update",
63 [PUI_STATE_UP_TO_DATE] = "system-software-update",
64 [PUI_STATE_NORMAL_UPDATES_AVAILABLE] = "software-update-available",
65 [PUI_STATE_IMPORTANT_UPDATES_AVAILABLE] = "software-update-urgent",
66 [PUI_STATE_SESSION_RESTART_REQUIRED] = "system-log-out",
67 [PUI_STATE_SYSTEM_RESTART_REQUIRED] = "system-reboot",
68 [PUI_STATE_ERROR] = "dialog-warning"
69 };
71 static const GOptionEntry cmd_options[] = {
72 { "debug", '\0', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, NULL,
73 N_("Enable debugging messages"), NULL },
74 { "quit", 'q', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, NULL,
75 N_("Quit running instance of Package Update Indicator"), NULL },
76 { "version", 'V', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, NULL,
77 N_("Print the version number and quit"), NULL },
78 { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, NULL, NULL, NULL },
79 { NULL }
80 };
82 static void pui_application_show_about_dialog(GSimpleAction *, GVariant *,
83 gpointer);
84 static void pui_application_open_preferences(GSimpleAction *, GVariant *,
85 gpointer);
86 static void pui_application_quit(GSimpleAction *, GVariant *, gpointer);
87 static void pui_application_install_updates(GSimpleAction *, GVariant *,
88 gpointer);
90 static const GActionEntry pui_application_actions[] = {
91 { "about", pui_application_show_about_dialog },
92 { "preferences", pui_application_open_preferences },
93 { "quit", pui_application_quit },
94 { "install-updates", pui_application_install_updates }
95 };
97 static gboolean
98 program_exists(const gchar *command_line)
99 {
100 gboolean is_program_in_path;
101 gchar **argv = NULL;
102 gchar *program_path;
104 if (!g_shell_parse_argv(command_line, NULL, &argv, NULL)) {
105 return (FALSE);
106 }
107 program_path = g_find_program_in_path(argv[0]);
108 is_program_in_path = (program_path != NULL) ? TRUE : FALSE;
109 g_free(program_path);
110 g_strfreev(argv);
112 return (is_program_in_path);
113 }
115 static void
116 pui_application_show_about_dialog(GSimpleAction *simple, GVariant *parameter,
117 gpointer user_data)
118 {
119 PuiApplication *self = user_data;
120 GtkBuilder *builder;
122 if (self->about_dialog == NULL) {
123 /* get dialog from builder */
124 builder = gtk_builder_new_from_resource("/org"
125 "/guido-berhoerster/code/package-update-indicator"
126 "/pui-about-dialog.ui");
128 self->about_dialog = GTK_WIDGET(gtk_builder_get_object(builder,
129 "about-dialog"));
131 g_object_unref(builder);
132 }
134 gtk_dialog_run(GTK_DIALOG(self->about_dialog));
135 gtk_widget_hide(self->about_dialog);
136 }
138 static void
139 pui_application_open_preferences(GSimpleAction *simple, GVariant *parameter,
140 gpointer user_data)
141 {
142 GDesktopAppInfo *prefs_app_info;
143 GError *error = NULL;
145 prefs_app_info = g_desktop_app_info_new("org.guido-berhoerster.code."
146 "package-update-indicator.preferences.desktop");
147 if (prefs_app_info == NULL) {
148 g_warning("desktop file \"org.guido-berhoerster.code."
149 "package-update-indicator.preferences.desktop\" not found");
150 return;
151 }
153 if (!g_app_info_launch(G_APP_INFO(prefs_app_info), NULL, NULL,
154 &error)) {
155 g_warning("failed to launch preferences: %s", error->message);
156 g_error_free(error);
157 }
158 }
160 static void
161 pui_application_quit(GSimpleAction *simple, GVariant *parameter,
162 gpointer user_data)
163 {
164 PuiApplication *self = user_data;
166 /* quit the GTK main loop if the about dialog is running */
167 if (self->about_dialog != NULL) {
168 gtk_widget_hide(self->about_dialog);
169 }
171 g_application_quit(G_APPLICATION(self));
172 }
174 static void
175 pui_application_install_updates(GSimpleAction *simple, GVariant *parameter,
176 gpointer user_data)
177 {
178 PuiApplication *self = user_data;
179 GError *error = NULL;
181 if (!g_spawn_command_line_async(self->update_command, &error)) {
182 g_warning("failed to run update command: %s", error->message);
183 g_error_free(error);
184 }
185 }
187 static void
188 update_ui(PuiApplication *self)
189 {
190 GSimpleAction *install_updates_action;
191 guint important_updates = 0;
192 guint normal_updates = 0;
193 gchar *title = NULL;
194 gchar *body = NULL;
195 GApplication *application = G_APPLICATION(self);
196 GNotification *notification = NULL;
198 install_updates_action =
199 G_SIMPLE_ACTION(g_action_map_lookup_action(G_ACTION_MAP(self),
200 "install-updates"));
202 if ((self->state == PUI_STATE_NORMAL_UPDATES_AVAILABLE) ||
203 (self->state == PUI_STATE_IMPORTANT_UPDATES_AVAILABLE)) {
204 g_object_get(self->backend,
205 "important-updates", &important_updates,
206 "normal-updates", &normal_updates, NULL);
207 }
209 /* actions */
210 switch (self->state) {
211 case PUI_STATE_INITIAL: /* FALLTHGROUGH */
212 case PUI_STATE_UP_TO_DATE: /* FALLTHGROUGH */
213 case PUI_STATE_SESSION_RESTART_REQUIRED: /* FALLTHGROUGH */
214 case PUI_STATE_SYSTEM_RESTART_REQUIRED: /* FALLTHGROUGH */
215 case PUI_STATE_ERROR:
216 g_simple_action_set_enabled(install_updates_action, FALSE);
217 break;
218 case PUI_STATE_NORMAL_UPDATES_AVAILABLE: /* FALLTHROUGH */
219 case PUI_STATE_IMPORTANT_UPDATES_AVAILABLE:
220 g_simple_action_set_enabled(install_updates_action,
221 program_exists(self->update_command));
222 break;
223 }
225 /* title and body for indicator and notification */
226 switch (self->state) {
227 case PUI_STATE_INITIAL:
228 title = g_strdup("");
229 body = g_strdup("");
230 break;
231 case PUI_STATE_UP_TO_DATE:
232 title = g_strdup(_("Up to Date"));
233 body = g_strdup(_("The system is up to date."));
234 break;
235 case PUI_STATE_NORMAL_UPDATES_AVAILABLE:
236 title = g_strdup(g_dngettext(NULL, "Software Update",
237 "Software Updates", (gulong)normal_updates));
238 if (normal_updates == 1) {
239 body = g_strdup(_("There is a software update "
240 "avaliable."));
241 } else {
242 body = g_strdup_printf(_("There are %u "
243 "software updates avaliable."), normal_updates);
244 }
245 break;
246 case PUI_STATE_IMPORTANT_UPDATES_AVAILABLE:
247 title = g_strdup(g_dngettext(NULL, "Important Software Update",
248 "Important Software Updates", (gulong)important_updates));
249 if ((normal_updates == 0) && (important_updates == 1)) {
250 body = g_strdup(_("There is an important "
251 "software update available."));
252 } else if ((normal_updates == 0) && (important_updates > 1)) {
253 body = g_strdup_printf(_("There are %u "
254 "important software updates available."),
255 important_updates);
256 } else if ((normal_updates > 0) && (important_updates == 1)) {
257 body = g_strdup_printf(_("There are %u "
258 "software updates available, "
259 "one of them is important."),
260 normal_updates + important_updates);
261 } else {
262 body = g_strdup_printf(_("There are %u "
263 "software updates available, "
264 "%u of them are important."),
265 normal_updates + important_updates,
266 important_updates);
267 }
268 break;
269 case PUI_STATE_SESSION_RESTART_REQUIRED:
270 title = g_strdup(_("Logout Required"));
271 body = g_strdup(_("You need to log out and back in for the "
272 "update to take effect."));
273 break;
274 case PUI_STATE_SYSTEM_RESTART_REQUIRED:
275 title = g_strdup(_("Restart Required"));
276 body = g_strdup(_("The computer has to be restarted for the "
277 "updates to take effect."));
278 break;
279 case PUI_STATE_ERROR:
280 title = g_strdup(self->error_message);
281 break;
282 }
284 /* indicator */
285 switch (self->state) {
286 case PUI_STATE_INITIAL:
287 app_indicator_set_status(self->indicator,
288 APP_INDICATOR_STATUS_PASSIVE);
289 break;
290 case PUI_STATE_UP_TO_DATE: /* FALLTHGROUGH */
291 case PUI_STATE_NORMAL_UPDATES_AVAILABLE: /* FALLTHGROUGH */
292 case PUI_STATE_IMPORTANT_UPDATES_AVAILABLE: /* FALLTHGROUGH */
293 case PUI_STATE_SESSION_RESTART_REQUIRED: /* FALLTHGROUGH */
294 case PUI_STATE_SYSTEM_RESTART_REQUIRED: /* FALLTHGROUGH */
295 case PUI_STATE_ERROR:
296 app_indicator_set_status(self->indicator,
297 APP_INDICATOR_STATUS_ACTIVE);
298 break;
299 }
300 app_indicator_set_icon_full(self->indicator, icon_names[self->state],
301 title);
303 /* notification */
304 switch (self->state) {
305 case PUI_STATE_INITIAL: /* FALLTHGROUGH */
306 case PUI_STATE_UP_TO_DATE: /* FALLTHGROUGH */
307 case PUI_STATE_ERROR:
308 /* withdraw exisiting notification */
309 g_application_withdraw_notification(application,
310 "package-updates-or-restart-required");
311 break;
312 case PUI_STATE_NORMAL_UPDATES_AVAILABLE: /* FALLTHGROUGH */
313 case PUI_STATE_IMPORTANT_UPDATES_AVAILABLE: /* FALLTHGROUGH */
314 case PUI_STATE_SESSION_RESTART_REQUIRED: /* FALLTHGROUGH */
315 case PUI_STATE_SYSTEM_RESTART_REQUIRED:
316 /* create notification */
317 notification = g_notification_new(title);
318 g_notification_set_body(notification, body);
319 g_notification_set_icon(notification, self->icons[self->state]);
320 g_notification_set_priority(notification,
321 G_NOTIFICATION_PRIORITY_NORMAL);
322 if (g_action_get_enabled(G_ACTION(install_updates_action))) {
323 g_notification_add_button(notification,
324 _("Install Updates"),
325 "app.install-updates");
326 }
327 g_application_send_notification(application,
328 "package-updates-or-restart-required", notification);
329 break;
330 }
332 if (notification != NULL) {
333 g_object_unref(notification);
334 }
336 g_debug("indicator icon: %s, notification title: \"%s\", "
337 "notification body: \"%s\"", icon_names[self->state], title, body);
339 g_free(body);
340 g_free(title);
341 }
343 static void
344 transition_state(PuiApplication *self)
345 {
346 PuiState state = self->state;
347 PuiRestart restart_type;
348 guint important_updates;
349 guint normal_updates;
350 gchar *old_state;
351 gchar *new_state;
353 switch (self->state) {
354 case PUI_STATE_INITIAL: /* FALLTHROUGH */
355 case PUI_STATE_UP_TO_DATE: /* FALLTHROUGH */
356 case PUI_STATE_NORMAL_UPDATES_AVAILABLE: /* FALLTHROUGH */
357 case PUI_STATE_IMPORTANT_UPDATES_AVAILABLE:
358 if (self->error_message != NULL) {
359 state = PUI_STATE_ERROR;
360 break;
361 }
363 g_object_get(self->backend, "restart-type", &restart_type,
364 "important-updates", &important_updates,
365 "normal-updates", &normal_updates, NULL);
366 if (restart_type == PUI_RESTART_SESSION) {
367 state = PUI_STATE_SESSION_RESTART_REQUIRED;
368 } else if (restart_type == PUI_RESTART_SYSTEM) {
369 state = PUI_STATE_SYSTEM_RESTART_REQUIRED;
370 } else if (important_updates > 0) {
371 state = PUI_STATE_IMPORTANT_UPDATES_AVAILABLE;
372 } else if (normal_updates > 0) {
373 state = PUI_STATE_NORMAL_UPDATES_AVAILABLE;
374 } else {
375 state = PUI_STATE_UP_TO_DATE;
376 }
377 break;
378 case PUI_STATE_SESSION_RESTART_REQUIRED:
379 g_object_get(self->backend, "restart-type", &restart_type,
380 NULL);
381 if (restart_type == PUI_RESTART_SYSTEM) {
382 state = PUI_STATE_SYSTEM_RESTART_REQUIRED;
383 }
384 break;
385 case PUI_STATE_SYSTEM_RESTART_REQUIRED: /* FALLTHROUGH */
386 case PUI_STATE_ERROR:
387 break;
388 }
390 if (state != self->state) {
391 old_state = pui_types_enum_to_string(PUI_TYPE_STATE,
392 self->state);
393 new_state = pui_types_enum_to_string(PUI_TYPE_STATE, state);
394 g_debug("state %s -> %s", old_state, new_state);
396 self->state = state;
397 update_ui(self);
399 g_free(new_state);
400 g_free(old_state);
401 }
402 }
404 static void
405 on_backend_restart_required(PuiBackend *backend, gpointer user_data)
406 {
407 PuiApplication *self = user_data;
409 restart = TRUE;
410 g_action_group_activate_action(G_ACTION_GROUP(G_APPLICATION(self)),
411 "quit", NULL);
412 }
414 static void
415 on_backend_state_changed(PuiBackend *backend, gpointer user_data)
416 {
417 PuiApplication *self = user_data;
419 transition_state(self);
420 }
422 static void
423 on_pui_backend_finished(GObject *source_object, GAsyncResult *result,
424 gpointer user_data)
425 {
426 PuiApplication *self = user_data;
427 GError *error = NULL;
429 self->backend = pui_backend_new_finish(result, &error);
430 if (self->backend == NULL) {
431 g_warning("failed to instantiate backend: %s", error->message);
432 g_free(self->error_message);
433 g_error_free(error);
434 self->error_message = g_strdup(_("Update notifications "
435 "are not supported."));
436 transition_state(self);
437 return;
438 }
440 pui_backend_set_proxy(self->backend, g_getenv("http_proxy"),
441 g_getenv("https_proxy"), g_getenv("ftp_proxy"),
442 g_getenv("socks_proxy"), g_getenv("no_proxy"), NULL);
444 g_settings_bind(self->settings, "refresh-interval", self->backend,
445 "refresh-interval", G_SETTINGS_BIND_GET);
446 g_settings_bind(self->settings, "use-mobile-connection", self->backend,
447 "use-mobile-connection", G_SETTINGS_BIND_GET);
449 transition_state(self);
451 g_signal_connect(self->backend, "restart-required",
452 G_CALLBACK(on_backend_restart_required), self);
453 g_signal_connect(self->backend, "state-changed",
454 G_CALLBACK(on_backend_state_changed), self);
455 }
457 static void
458 pui_application_startup(GApplication *application)
459 {
460 PuiApplication *self = PUI_APPLICATION(application);
461 gsize i;
462 GtkBuilder *builder;
463 GtkWidget *menu;
465 G_APPLICATION_CLASS(pui_application_parent_class)->startup(application);
467 /* create actions */
468 g_action_map_add_action_entries(G_ACTION_MAP(self),
469 pui_application_actions, G_N_ELEMENTS(pui_application_actions),
470 self);
472 /* load icons */
473 for (i = 0; i < G_N_ELEMENTS(self->icons); i++) {
474 self->icons[i] = g_themed_icon_new(icon_names[i]);
475 }
477 /* create settings */
478 self->settings = pui_settings_new();
479 g_settings_bind(self->settings, "update-command", self,
480 "update-command", G_SETTINGS_BIND_GET);
482 /* start instantiating backend */
483 pui_backend_new_async(self->cancellable, on_pui_backend_finished, self);
485 /* create indicator */
486 self->indicator = app_indicator_new(APPLICATION_ID,
487 "system-software-update",
488 APP_INDICATOR_CATEGORY_APPLICATION_STATUS);
490 /* get menu from builder and add it to the indicator */
491 builder = gtk_builder_new_from_resource("/org/guido-berhoerster/code/"
492 "package-update-indicator/pui-menu.ui");
493 menu = GTK_WIDGET(gtk_builder_get_object(builder, "menu"));
494 gtk_widget_insert_action_group(menu, "app", G_ACTION_GROUP(self));
495 gtk_widget_show_all(menu);
496 app_indicator_set_menu(self->indicator, GTK_MENU(menu));
498 update_ui(self);
500 /* keep GApplication running */
501 g_application_hold(application);
503 g_object_unref(builder);
504 }
506 static void
507 pui_application_shutdown(GApplication *application)
508 {
509 GApplicationClass *application_class =
510 G_APPLICATION_CLASS(pui_application_parent_class);
512 application_class->shutdown(application);
513 }
515 static gint
516 pui_application_handle_local_options(GApplication *application,
517 GVariantDict *options)
518 {
519 gchar *messages_debug;
520 gchar **args = NULL;
521 GError *error = NULL;
523 /* filename arguments are not allowed */
524 if (g_variant_dict_lookup(options, G_OPTION_REMAINING, "^a&ay",
525 &args)) {
526 g_printerr("invalid argument: \"%s\"\n", args[0]);
527 g_free(args);
528 return (1);
529 }
531 if (g_variant_dict_contains(options, "version")) {
532 g_print("%s %s\n", PACKAGE, VERSION);
534 /* quit */
535 return (0);
536 }
538 if (g_variant_dict_contains(options, "debug")) {
539 /* enable debug logging */
540 messages_debug = g_strjoin(":", G_LOG_DOMAIN,
541 g_getenv("G_MESSAGES_DEBUG"), NULL);
542 g_setenv("G_MESSAGES_DEBUG", messages_debug, TRUE);
543 g_free(messages_debug);
544 }
546 /*
547 * register with the session bus so that it is possible to discern
548 * between remote and primary instance and that remote actions can be
549 * invoked, this causes the startup signal to be emitted which, in case
550 * of the primary instance, starts to instantiate the
551 * backend with the given values
552 */
553 if (!g_application_register(application, NULL, &error)) {
554 g_critical("g_application_register: %s", error->message);
555 g_error_free(error);
556 return (1);
557 }
559 if (g_variant_dict_contains(options, "quit")) {
560 /* only valid if a remote instance is running */
561 if (!g_application_get_is_remote(application)) {
562 g_printerr("%s is not running\n", g_get_prgname());
563 return (1);
564 }
566 /* signal remote instance to quit */
567 g_action_group_activate_action(G_ACTION_GROUP(application),
568 "quit", NULL);
570 /* quit local instance */
571 return (0);
572 }
574 /* proceed with default command line processing */
575 return (-1);
576 }
578 static void
579 pui_application_activate(GApplication *application) {
580 GApplicationClass *application_class =
581 G_APPLICATION_CLASS(pui_application_parent_class);
583 /* do nothing, implementation required by GApplication */
585 application_class->activate(application);
586 }
588 static void
589 pui_application_set_property(GObject *object, guint property_id,
590 const GValue *value, GParamSpec *pspec)
591 {
592 PuiApplication *self = PUI_APPLICATION(object);
594 switch (property_id) {
595 case PROP_UPDATE_COMMAND:
596 g_free(self->update_command);
597 self->update_command = g_value_dup_string(value);
598 g_debug("property \"update-command\" set to \"%s\"",
599 self->update_command);
600 break;
601 default:
602 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
603 break;
604 }
605 }
607 static void
608 pui_application_get_property(GObject *object, guint property_id, GValue *value,
609 GParamSpec *pspec)
610 {
611 PuiApplication *self = PUI_APPLICATION(object);
613 switch (property_id) {
614 case PROP_UPDATE_COMMAND:
615 g_value_set_string(value, self->update_command);
616 break;
617 default:
618 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
619 break;
620 }
621 }
623 static void
624 pui_application_dispose(GObject *object)
625 {
626 PuiApplication *self = PUI_APPLICATION(object);
627 gsize i;
629 if (self->settings != NULL) {
630 g_signal_handlers_disconnect_by_data(self->settings, self);
631 g_clear_object(&self->settings);
632 }
634 if (self->cancellable != NULL) {
635 g_cancellable_cancel(self->cancellable);
636 g_clear_object(&self->cancellable);
637 }
639 if (self->backend != NULL) {
640 g_clear_object(&self->backend);
641 }
643 if (self->indicator != NULL) {
644 g_clear_object(&self->indicator);
645 }
647 if (self->about_dialog != NULL) {
648 g_clear_pointer(&self->about_dialog,
649 (GDestroyNotify)(gtk_widget_destroy));
650 }
652 for (i = 0; i < G_N_ELEMENTS(self->icons); i++) {
653 if (self->icons[i] != NULL) {
654 g_clear_object(&self->icons[i]);
655 }
656 }
658 G_OBJECT_CLASS(pui_application_parent_class)->dispose(object);
659 }
661 static void
662 pui_application_finalize(GObject *object)
663 {
664 PuiApplication *self = PUI_APPLICATION(object);
666 g_free(self->update_command);
667 g_free(self->error_message);
669 G_OBJECT_CLASS(pui_application_parent_class)->finalize(object);
670 }
672 static void
673 pui_application_class_init(PuiApplicationClass *klass)
674 {
675 GObjectClass *object_class = G_OBJECT_CLASS(klass);
676 GApplicationClass *application_class = G_APPLICATION_CLASS(klass);
678 object_class->set_property = pui_application_set_property;
679 object_class->get_property = pui_application_get_property;
680 object_class->dispose = pui_application_dispose;
681 object_class->finalize = pui_application_finalize;
683 properties[PROP_UPDATE_COMMAND] = g_param_spec_string("update-command",
684 "Update command", "Command for installing updates", NULL,
685 G_PARAM_READWRITE);
687 g_object_class_install_properties(object_class, PROP_LAST, properties);
689 application_class->startup = pui_application_startup;
690 application_class->shutdown = pui_application_shutdown;
691 application_class->handle_local_options =
692 pui_application_handle_local_options;
693 application_class->activate = pui_application_activate;
694 }
696 static void
697 pui_application_init(PuiApplication *self)
698 {
699 g_application_add_main_option_entries(G_APPLICATION(self),
700 cmd_options);
702 self->cancellable = g_cancellable_new();
703 }
705 PuiApplication *
706 pui_application_new(void)
707 {
708 return (g_object_new(PUI_TYPE_APPLICATION, "application-id",
709 APPLICATION_ID, NULL));
710 }