projects/package-update-indicator

view pui-application.c @ 52:707e9e3deeac

Do not hardcode pkg-config

Using a macro allows passing a different executable in case of
cross-compilation.
author Helmut Grohne <helmut@subdivi.de>
date Sat Dec 12 01:08:21 2020 -0500 (11 months ago)
parents 811df672633d
children
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 #ifndef HAVE_AYATANA_APPINDICATOR
27 #include <libappindicator/app-indicator.h>
28 #else /* !HAVE_AYATANA_APPINDICATOR */
29 #include <libayatana-appindicator/app-indicator.h>
30 #endif /* !HAVE_AYATANA_APPINDICATOR */
31 #include <stdlib.h>
32 #include <string.h>
34 #include "pui-application.h"
35 #include "pui-backend.h"
36 #include "pui-common.h"
37 #include "pui-settings.h"
38 #include "pui-types.h"
40 struct _PuiApplication {
41 GApplication parent_instance;
42 GSettings *settings;
43 GCancellable *cancellable;
44 PuiBackend *backend;
45 AppIndicator *indicator;
46 GtkWidget *about_dialog;
47 GIcon *icons[PUI_STATE_LAST];
48 PuiState state;
49 gchar *update_command;
50 gchar *error_message;
51 };
53 G_DEFINE_TYPE(PuiApplication, pui_application, G_TYPE_APPLICATION)
55 enum {
56 PROP_0,
57 PROP_UPDATE_COMMAND,
58 PROP_LAST
59 };
61 extern gboolean restart;
63 static GParamSpec *properties[PROP_LAST] = { NULL };
65 static const gchar *icon_names[PUI_STATE_LAST] = {
66 [PUI_STATE_INITIAL] = "system-software-update",
67 [PUI_STATE_UP_TO_DATE] = "system-software-update",
68 [PUI_STATE_NORMAL_UPDATES_AVAILABLE] = "software-update-available",
69 [PUI_STATE_IMPORTANT_UPDATES_AVAILABLE] = "software-update-urgent",
70 [PUI_STATE_SESSION_RESTART_REQUIRED] = "system-log-out",
71 [PUI_STATE_SYSTEM_RESTART_REQUIRED] = "system-reboot",
72 [PUI_STATE_ERROR] = "dialog-warning"
73 };
75 static const GOptionEntry cmd_options[] = {
76 { "debug", '\0', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, NULL,
77 N_("Enable debugging messages"), NULL },
78 { "quit", 'q', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, NULL,
79 N_("Quit running instance of Package Update Indicator"), NULL },
80 { "version", 'V', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, NULL,
81 N_("Print the version number and quit"), NULL },
82 { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, NULL, NULL, NULL },
83 { NULL }
84 };
86 static void pui_application_show_about_dialog(GSimpleAction *, GVariant *,
87 gpointer);
88 static void pui_application_open_preferences(GSimpleAction *, GVariant *,
89 gpointer);
90 static void pui_application_quit(GSimpleAction *, GVariant *, gpointer);
91 static void pui_application_install_updates(GSimpleAction *, GVariant *,
92 gpointer);
94 static const GActionEntry pui_application_actions[] = {
95 { "about", pui_application_show_about_dialog },
96 { "preferences", pui_application_open_preferences },
97 { "quit", pui_application_quit },
98 { "install-updates", pui_application_install_updates }
99 };
101 static gboolean
102 program_exists(const gchar *command_line)
103 {
104 gboolean is_program_in_path;
105 gchar **argv = NULL;
106 gchar *program_path;
108 if (!g_shell_parse_argv(command_line, NULL, &argv, NULL)) {
109 return (FALSE);
110 }
111 program_path = g_find_program_in_path(argv[0]);
112 is_program_in_path = (program_path != NULL) ? TRUE : FALSE;
113 g_free(program_path);
114 g_strfreev(argv);
116 return (is_program_in_path);
117 }
119 static void
120 pui_application_show_about_dialog(GSimpleAction *simple, GVariant *parameter,
121 gpointer user_data)
122 {
123 PuiApplication *self = user_data;
124 GtkBuilder *builder;
126 if (self->about_dialog == NULL) {
127 /* get dialog from builder */
128 builder = gtk_builder_new_from_resource("/org"
129 "/guido-berhoerster/code/package-update-indicator"
130 "/pui-about-dialog.ui");
132 self->about_dialog = GTK_WIDGET(gtk_builder_get_object(builder,
133 "about-dialog"));
135 g_object_unref(builder);
136 }
138 gtk_dialog_run(GTK_DIALOG(self->about_dialog));
139 gtk_widget_hide(self->about_dialog);
140 }
142 static void
143 pui_application_open_preferences(GSimpleAction *simple, GVariant *parameter,
144 gpointer user_data)
145 {
146 GDesktopAppInfo *prefs_app_info;
147 GError *error = NULL;
149 prefs_app_info = g_desktop_app_info_new("org.guido-berhoerster.code."
150 "package-update-indicator.preferences.desktop");
151 if (prefs_app_info == NULL) {
152 g_warning("desktop file \"org.guido-berhoerster.code."
153 "package-update-indicator.preferences.desktop\" not found");
154 return;
155 }
157 if (!g_app_info_launch(G_APP_INFO(prefs_app_info), NULL, NULL,
158 &error)) {
159 g_warning("failed to launch preferences: %s", error->message);
160 g_error_free(error);
161 }
162 }
164 static void
165 pui_application_quit(GSimpleAction *simple, GVariant *parameter,
166 gpointer user_data)
167 {
168 PuiApplication *self = user_data;
170 /* quit the GTK main loop if the about dialog is running */
171 if (self->about_dialog != NULL) {
172 gtk_widget_hide(self->about_dialog);
173 }
175 g_application_quit(G_APPLICATION(self));
176 }
178 static void
179 pui_application_install_updates(GSimpleAction *simple, GVariant *parameter,
180 gpointer user_data)
181 {
182 PuiApplication *self = user_data;
183 GError *error = NULL;
185 if (!g_spawn_command_line_async(self->update_command, &error)) {
186 g_warning("failed to run update command: %s", error->message);
187 g_error_free(error);
188 }
189 }
191 static void
192 update_ui(PuiApplication *self)
193 {
194 GSimpleAction *install_updates_action;
195 guint important_updates = 0;
196 guint normal_updates = 0;
197 gchar *title = NULL;
198 gchar *body = NULL;
199 GApplication *application = G_APPLICATION(self);
200 GNotification *notification = NULL;
202 install_updates_action =
203 G_SIMPLE_ACTION(g_action_map_lookup_action(G_ACTION_MAP(self),
204 "install-updates"));
206 if ((self->state == PUI_STATE_NORMAL_UPDATES_AVAILABLE) ||
207 (self->state == PUI_STATE_IMPORTANT_UPDATES_AVAILABLE)) {
208 g_object_get(self->backend,
209 "important-updates", &important_updates,
210 "normal-updates", &normal_updates, NULL);
211 }
213 /* actions */
214 switch (self->state) {
215 case PUI_STATE_INITIAL: /* FALLTHGROUGH */
216 case PUI_STATE_UP_TO_DATE: /* FALLTHGROUGH */
217 case PUI_STATE_SESSION_RESTART_REQUIRED: /* FALLTHGROUGH */
218 case PUI_STATE_SYSTEM_RESTART_REQUIRED: /* FALLTHGROUGH */
219 case PUI_STATE_ERROR:
220 g_simple_action_set_enabled(install_updates_action, FALSE);
221 break;
222 case PUI_STATE_NORMAL_UPDATES_AVAILABLE: /* FALLTHROUGH */
223 case PUI_STATE_IMPORTANT_UPDATES_AVAILABLE:
224 g_simple_action_set_enabled(install_updates_action,
225 program_exists(self->update_command));
226 break;
227 }
229 /* title and body for indicator and notification */
230 switch (self->state) {
231 case PUI_STATE_INITIAL:
232 title = g_strdup("");
233 body = g_strdup("");
234 break;
235 case PUI_STATE_UP_TO_DATE:
236 title = g_strdup(_("Up to Date"));
237 body = g_strdup(_("The system is up to date."));
238 break;
239 case PUI_STATE_NORMAL_UPDATES_AVAILABLE:
240 title = g_strdup(g_dngettext(NULL, "Software Update",
241 "Software Updates", (gulong)normal_updates));
242 if (normal_updates == 1) {
243 body = g_strdup(_("There is a software update "
244 "available."));
245 } else {
246 body = g_strdup_printf(_("There are %u "
247 "software updates available."), normal_updates);
248 }
249 break;
250 case PUI_STATE_IMPORTANT_UPDATES_AVAILABLE:
251 title = g_strdup(g_dngettext(NULL, "Important Software Update",
252 "Important Software Updates", (gulong)important_updates));
253 if ((normal_updates == 0) && (important_updates == 1)) {
254 body = g_strdup(_("There is an important "
255 "software update available."));
256 } else if ((normal_updates == 0) && (important_updates > 1)) {
257 body = g_strdup_printf(_("There are %u "
258 "important software updates available."),
259 important_updates);
260 } else if ((normal_updates > 0) && (important_updates == 1)) {
261 body = g_strdup_printf(_("There are %u "
262 "software updates available, "
263 "one of them is important."),
264 normal_updates + important_updates);
265 } else {
266 body = g_strdup_printf(_("There are %u "
267 "software updates available, "
268 "%u of them are important."),
269 normal_updates + important_updates,
270 important_updates);
271 }
272 break;
273 case PUI_STATE_SESSION_RESTART_REQUIRED:
274 title = g_strdup(_("Logout Required"));
275 body = g_strdup(_("You need to log out and back in for the "
276 "update to take effect."));
277 break;
278 case PUI_STATE_SYSTEM_RESTART_REQUIRED:
279 title = g_strdup(_("Restart Required"));
280 body = g_strdup(_("The computer has to be restarted for the "
281 "updates to take effect."));
282 break;
283 case PUI_STATE_ERROR:
284 title = g_strdup(self->error_message);
285 break;
286 }
288 /* indicator */
289 switch (self->state) {
290 case PUI_STATE_INITIAL:
291 app_indicator_set_status(self->indicator,
292 APP_INDICATOR_STATUS_PASSIVE);
293 break;
294 case PUI_STATE_UP_TO_DATE: /* FALLTHGROUGH */
295 case PUI_STATE_NORMAL_UPDATES_AVAILABLE: /* FALLTHGROUGH */
296 case PUI_STATE_IMPORTANT_UPDATES_AVAILABLE: /* FALLTHGROUGH */
297 case PUI_STATE_SESSION_RESTART_REQUIRED: /* FALLTHGROUGH */
298 case PUI_STATE_SYSTEM_RESTART_REQUIRED: /* FALLTHGROUGH */
299 case PUI_STATE_ERROR:
300 app_indicator_set_status(self->indicator,
301 APP_INDICATOR_STATUS_ACTIVE);
302 break;
303 }
304 app_indicator_set_icon_full(self->indicator, icon_names[self->state],
305 title);
307 /* notification */
308 switch (self->state) {
309 case PUI_STATE_INITIAL: /* FALLTHGROUGH */
310 case PUI_STATE_UP_TO_DATE: /* FALLTHGROUGH */
311 case PUI_STATE_ERROR:
312 /* withdraw exisiting notification */
313 g_application_withdraw_notification(application,
314 "package-updates-or-restart-required");
315 break;
316 case PUI_STATE_NORMAL_UPDATES_AVAILABLE: /* FALLTHGROUGH */
317 case PUI_STATE_IMPORTANT_UPDATES_AVAILABLE: /* FALLTHGROUGH */
318 case PUI_STATE_SESSION_RESTART_REQUIRED: /* FALLTHGROUGH */
319 case PUI_STATE_SYSTEM_RESTART_REQUIRED:
320 /* create notification */
321 notification = g_notification_new(title);
322 g_notification_set_body(notification, body);
323 g_notification_set_icon(notification, self->icons[self->state]);
324 g_notification_set_priority(notification,
325 G_NOTIFICATION_PRIORITY_NORMAL);
326 if (g_action_get_enabled(G_ACTION(install_updates_action))) {
327 g_notification_add_button(notification,
328 _("Install Updates"),
329 "app.install-updates");
330 }
331 g_application_send_notification(application,
332 "package-updates-or-restart-required", notification);
333 break;
334 }
336 if (notification != NULL) {
337 g_object_unref(notification);
338 }
340 g_debug("indicator icon: %s, notification title: \"%s\", "
341 "notification body: \"%s\"", icon_names[self->state], title, body);
343 g_free(body);
344 g_free(title);
345 }
347 static void
348 transition_state(PuiApplication *self)
349 {
350 PuiState state = self->state;
351 PuiRestart restart_type;
352 guint important_updates;
353 guint normal_updates;
354 gchar *old_state;
355 gchar *new_state;
357 switch (self->state) {
358 case PUI_STATE_INITIAL: /* FALLTHROUGH */
359 case PUI_STATE_UP_TO_DATE: /* FALLTHROUGH */
360 case PUI_STATE_NORMAL_UPDATES_AVAILABLE: /* FALLTHROUGH */
361 case PUI_STATE_IMPORTANT_UPDATES_AVAILABLE:
362 if (self->error_message != NULL) {
363 state = PUI_STATE_ERROR;
364 break;
365 }
367 g_object_get(self->backend, "restart-type", &restart_type,
368 "important-updates", &important_updates,
369 "normal-updates", &normal_updates, NULL);
370 if (restart_type == PUI_RESTART_SESSION) {
371 state = PUI_STATE_SESSION_RESTART_REQUIRED;
372 } else if (restart_type == PUI_RESTART_SYSTEM) {
373 state = PUI_STATE_SYSTEM_RESTART_REQUIRED;
374 } else if (important_updates > 0) {
375 state = PUI_STATE_IMPORTANT_UPDATES_AVAILABLE;
376 } else if (normal_updates > 0) {
377 state = PUI_STATE_NORMAL_UPDATES_AVAILABLE;
378 } else {
379 state = PUI_STATE_UP_TO_DATE;
380 }
381 break;
382 case PUI_STATE_SESSION_RESTART_REQUIRED:
383 g_object_get(self->backend, "restart-type", &restart_type,
384 NULL);
385 if (restart_type == PUI_RESTART_SYSTEM) {
386 state = PUI_STATE_SYSTEM_RESTART_REQUIRED;
387 }
388 break;
389 case PUI_STATE_SYSTEM_RESTART_REQUIRED: /* FALLTHROUGH */
390 case PUI_STATE_ERROR:
391 break;
392 }
394 if (state != self->state) {
395 old_state = pui_types_enum_to_string(PUI_TYPE_STATE,
396 self->state);
397 new_state = pui_types_enum_to_string(PUI_TYPE_STATE, state);
398 g_debug("state %s -> %s", old_state, new_state);
400 self->state = state;
401 update_ui(self);
403 g_free(new_state);
404 g_free(old_state);
405 }
406 }
408 static void
409 on_backend_restart_required(PuiBackend *backend, gpointer user_data)
410 {
411 PuiApplication *self = user_data;
413 restart = TRUE;
414 g_action_group_activate_action(G_ACTION_GROUP(G_APPLICATION(self)),
415 "quit", NULL);
416 }
418 static void
419 on_backend_state_changed(PuiBackend *backend, gpointer user_data)
420 {
421 PuiApplication *self = user_data;
423 transition_state(self);
424 }
426 static void
427 on_pui_backend_finished(GObject *source_object, GAsyncResult *result,
428 gpointer user_data)
429 {
430 PuiApplication *self = user_data;
431 GError *error = NULL;
433 self->backend = pui_backend_new_finish(result, &error);
434 if (self->backend == NULL) {
435 g_warning("failed to instantiate backend: %s", error->message);
436 g_free(self->error_message);
437 g_error_free(error);
438 self->error_message = g_strdup(_("Update notifications "
439 "are not supported."));
440 transition_state(self);
441 return;
442 }
444 pui_backend_set_proxy(self->backend, g_getenv("http_proxy"),
445 g_getenv("https_proxy"), g_getenv("ftp_proxy"),
446 g_getenv("socks_proxy"), g_getenv("no_proxy"), NULL);
448 g_settings_bind(self->settings, "refresh-interval", self->backend,
449 "refresh-interval", G_SETTINGS_BIND_GET);
450 g_settings_bind(self->settings, "use-mobile-connection", self->backend,
451 "use-mobile-connection", G_SETTINGS_BIND_GET);
453 transition_state(self);
455 g_signal_connect(self->backend, "restart-required",
456 G_CALLBACK(on_backend_restart_required), self);
457 g_signal_connect(self->backend, "state-changed",
458 G_CALLBACK(on_backend_state_changed), self);
459 }
461 static void
462 pui_application_startup(GApplication *application)
463 {
464 PuiApplication *self = PUI_APPLICATION(application);
465 gsize i;
466 GtkBuilder *builder;
467 GtkWidget *menu;
469 G_APPLICATION_CLASS(pui_application_parent_class)->startup(application);
471 /* create actions */
472 g_action_map_add_action_entries(G_ACTION_MAP(self),
473 pui_application_actions, G_N_ELEMENTS(pui_application_actions),
474 self);
476 /* load icons */
477 for (i = 0; i < G_N_ELEMENTS(self->icons); i++) {
478 self->icons[i] = g_themed_icon_new(icon_names[i]);
479 }
481 /* create settings */
482 self->settings = pui_settings_new();
483 g_settings_bind(self->settings, "update-command", self,
484 "update-command", G_SETTINGS_BIND_GET);
486 /* start instantiating backend */
487 pui_backend_new_async(self->cancellable, on_pui_backend_finished, self);
489 /* create indicator */
490 self->indicator = app_indicator_new(APPLICATION_ID,
491 "system-software-update",
492 APP_INDICATOR_CATEGORY_APPLICATION_STATUS);
493 app_indicator_set_title(self->indicator, _("Package Update Indicator"));
495 /* get menu from builder and add it to the indicator */
496 builder = gtk_builder_new_from_resource("/org/guido-berhoerster/code/"
497 "package-update-indicator/pui-menu.ui");
498 menu = GTK_WIDGET(gtk_builder_get_object(builder, "menu"));
499 gtk_widget_insert_action_group(menu, "app", G_ACTION_GROUP(self));
500 gtk_widget_show_all(menu);
501 app_indicator_set_menu(self->indicator, GTK_MENU(menu));
503 update_ui(self);
505 /* keep GApplication running */
506 g_application_hold(application);
508 g_object_unref(builder);
509 }
511 static void
512 pui_application_shutdown(GApplication *application)
513 {
514 GApplicationClass *application_class =
515 G_APPLICATION_CLASS(pui_application_parent_class);
517 application_class->shutdown(application);
518 }
520 static gint
521 pui_application_handle_local_options(GApplication *application,
522 GVariantDict *options)
523 {
524 gchar *messages_debug;
525 gchar **args = NULL;
526 GError *error = NULL;
528 /* filename arguments are not allowed */
529 if (g_variant_dict_lookup(options, G_OPTION_REMAINING, "^a&ay",
530 &args)) {
531 g_printerr("invalid argument: \"%s\"\n", args[0]);
532 g_free(args);
533 return (1);
534 }
536 if (g_variant_dict_contains(options, "version")) {
537 g_print("%s %s\n", PACKAGE, VERSION);
539 /* quit */
540 return (0);
541 }
543 if (g_variant_dict_contains(options, "debug")) {
544 /* enable debug logging */
545 messages_debug = g_strjoin(":", G_LOG_DOMAIN,
546 g_getenv("G_MESSAGES_DEBUG"), NULL);
547 g_setenv("G_MESSAGES_DEBUG", messages_debug, TRUE);
548 g_free(messages_debug);
549 }
551 /*
552 * register with the session bus so that it is possible to discern
553 * between remote and primary instance and that remote actions can be
554 * invoked, this causes the startup signal to be emitted which, in case
555 * of the primary instance, starts to instantiate the
556 * backend with the given values
557 */
558 if (!g_application_register(application, NULL, &error)) {
559 g_critical("g_application_register: %s", error->message);
560 g_error_free(error);
561 return (1);
562 }
564 if (g_variant_dict_contains(options, "quit")) {
565 /* only valid if a remote instance is running */
566 if (!g_application_get_is_remote(application)) {
567 g_printerr("%s is not running\n", g_get_prgname());
568 return (1);
569 }
571 /* signal remote instance to quit */
572 g_action_group_activate_action(G_ACTION_GROUP(application),
573 "quit", NULL);
575 /* quit local instance */
576 return (0);
577 }
579 /* proceed with default command line processing */
580 return (-1);
581 }
583 static void
584 pui_application_activate(GApplication *application) {
585 GApplicationClass *application_class =
586 G_APPLICATION_CLASS(pui_application_parent_class);
588 /* do nothing, implementation required by GApplication */
590 application_class->activate(application);
591 }
593 static void
594 pui_application_set_property(GObject *object, guint property_id,
595 const GValue *value, GParamSpec *pspec)
596 {
597 PuiApplication *self = PUI_APPLICATION(object);
599 switch (property_id) {
600 case PROP_UPDATE_COMMAND:
601 g_free(self->update_command);
602 self->update_command = g_value_dup_string(value);
603 g_debug("property \"update-command\" set to \"%s\"",
604 self->update_command);
605 break;
606 default:
607 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
608 break;
609 }
610 }
612 static void
613 pui_application_get_property(GObject *object, guint property_id, GValue *value,
614 GParamSpec *pspec)
615 {
616 PuiApplication *self = PUI_APPLICATION(object);
618 switch (property_id) {
619 case PROP_UPDATE_COMMAND:
620 g_value_set_string(value, self->update_command);
621 break;
622 default:
623 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
624 break;
625 }
626 }
628 static void
629 pui_application_dispose(GObject *object)
630 {
631 PuiApplication *self = PUI_APPLICATION(object);
632 gsize i;
634 if (self->settings != NULL) {
635 g_signal_handlers_disconnect_by_data(self->settings, self);
636 g_clear_object(&self->settings);
637 }
639 if (self->cancellable != NULL) {
640 g_cancellable_cancel(self->cancellable);
641 g_clear_object(&self->cancellable);
642 }
644 if (self->backend != NULL) {
645 g_clear_object(&self->backend);
646 }
648 if (self->indicator != NULL) {
649 g_clear_object(&self->indicator);
650 }
652 if (self->about_dialog != NULL) {
653 g_clear_pointer(&self->about_dialog,
654 (GDestroyNotify)(gtk_widget_destroy));
655 }
657 for (i = 0; i < G_N_ELEMENTS(self->icons); i++) {
658 if (self->icons[i] != NULL) {
659 g_clear_object(&self->icons[i]);
660 }
661 }
663 G_OBJECT_CLASS(pui_application_parent_class)->dispose(object);
664 }
666 static void
667 pui_application_finalize(GObject *object)
668 {
669 PuiApplication *self = PUI_APPLICATION(object);
671 g_free(self->update_command);
672 g_free(self->error_message);
674 G_OBJECT_CLASS(pui_application_parent_class)->finalize(object);
675 }
677 static void
678 pui_application_class_init(PuiApplicationClass *klass)
679 {
680 GObjectClass *object_class = G_OBJECT_CLASS(klass);
681 GApplicationClass *application_class = G_APPLICATION_CLASS(klass);
683 object_class->set_property = pui_application_set_property;
684 object_class->get_property = pui_application_get_property;
685 object_class->dispose = pui_application_dispose;
686 object_class->finalize = pui_application_finalize;
688 properties[PROP_UPDATE_COMMAND] = g_param_spec_string("update-command",
689 "Update command", "Command for installing updates", NULL,
690 G_PARAM_READWRITE);
692 g_object_class_install_properties(object_class, PROP_LAST, properties);
694 application_class->startup = pui_application_startup;
695 application_class->shutdown = pui_application_shutdown;
696 application_class->handle_local_options =
697 pui_application_handle_local_options;
698 application_class->activate = pui_application_activate;
699 }
701 static void
702 pui_application_init(PuiApplication *self)
703 {
704 g_application_add_main_option_entries(G_APPLICATION(self),
705 cmd_options);
707 self->cancellable = g_cancellable_new();
708 }
710 PuiApplication *
711 pui_application_new(void)
712 {
713 return (g_object_new(PUI_TYPE_APPLICATION, "application-id",
714 APPLICATION_ID, NULL));
715 }