annotate pui-application.c @ 0:6884bb8130ca

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