annotate pui-application.c @ 58:9cbb0f8a66c4

Add setting to disable preferences widgets This just makes the widgets in the preferences application insensitive, settings can still be changed by directly editing the configuration file.
author Guido Berhoerster <guido+pui@berhoerster.name>
date Tue, 06 Sep 2022 19:11:21 +0200
parents 08747f3a718b
children
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
3
2fa34d6272c6 Add menu item to launch the preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 2
diff changeset
24 #include <gio/gdesktopappinfo.h>
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
25 #include <glib/gi18n.h>
27
73081cc299f5 Fix support for libayatana-appindicator
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 16
diff changeset
26 #ifndef HAVE_AYATANA_APPINDICATOR
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
27 #include <libappindicator/app-indicator.h>
27
73081cc299f5 Fix support for libayatana-appindicator
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 16
diff changeset
28 #else /* !HAVE_AYATANA_APPINDICATOR */
73081cc299f5 Fix support for libayatana-appindicator
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 16
diff changeset
29 #include <libayatana-appindicator/app-indicator.h>
73081cc299f5 Fix support for libayatana-appindicator
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 16
diff changeset
30 #endif /* !HAVE_AYATANA_APPINDICATOR */
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
31 #include <stdlib.h>
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
32 #include <string.h>
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
33
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
34 #include "pui-application.h"
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
35 #include "pui-backend.h"
1
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
36 #include "pui-common.h"
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
37 #include "pui-settings.h"
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
38 #include "pui-types.h"
0
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;
55
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
51 gboolean always_active;
0
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
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
54 G_DEFINE_TYPE(PuiApplication, pui_application, G_TYPE_APPLICATION)
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
55
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
56 enum {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
57 PROP_0,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
58 PROP_UPDATE_COMMAND,
55
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
59 PROP_ALWAYS_ACTIVE,
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
60 PROP_LAST
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
61 };
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 extern gboolean restart;
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 GParamSpec *properties[PROP_LAST] = { NULL };
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
66
35
c4b8785d0b75 Back out fallback icon support which does not work as intended
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 30
diff changeset
67 static const gchar *icon_names[PUI_STATE_LAST] = {
c4b8785d0b75 Back out fallback icon support which does not work as intended
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 30
diff changeset
68 [PUI_STATE_INITIAL] = "system-software-update",
c4b8785d0b75 Back out fallback icon support which does not work as intended
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 30
diff changeset
69 [PUI_STATE_UP_TO_DATE] = "system-software-update",
c4b8785d0b75 Back out fallback icon support which does not work as intended
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 30
diff changeset
70 [PUI_STATE_NORMAL_UPDATES_AVAILABLE] = "software-update-available",
c4b8785d0b75 Back out fallback icon support which does not work as intended
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 30
diff changeset
71 [PUI_STATE_IMPORTANT_UPDATES_AVAILABLE] = "software-update-urgent",
c4b8785d0b75 Back out fallback icon support which does not work as intended
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 30
diff changeset
72 [PUI_STATE_SESSION_RESTART_REQUIRED] = "system-log-out",
c4b8785d0b75 Back out fallback icon support which does not work as intended
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 30
diff changeset
73 [PUI_STATE_SYSTEM_RESTART_REQUIRED] = "system-reboot",
c4b8785d0b75 Back out fallback icon support which does not work as intended
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 30
diff changeset
74 [PUI_STATE_ERROR] = "dialog-warning"
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
75 };
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
76
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
77 static const GOptionEntry cmd_options[] = {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
78 { "debug", '\0', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, NULL,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
79 N_("Enable debugging messages"), NULL },
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
80 { "quit", 'q', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, NULL,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
81 N_("Quit running instance of Package Update Indicator"), NULL },
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
82 { "version", 'V', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, NULL,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
83 N_("Print the version number and quit"), NULL },
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
84 { 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
85 { NULL }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
86 };
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
87
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
88 static void pui_application_show_about_dialog(GSimpleAction *, GVariant *,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
89 gpointer);
3
2fa34d6272c6 Add menu item to launch the preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 2
diff changeset
90 static void pui_application_open_preferences(GSimpleAction *, GVariant *,
2fa34d6272c6 Add menu item to launch the preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 2
diff changeset
91 gpointer);
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
92 static void pui_application_quit(GSimpleAction *, GVariant *, gpointer);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
93 static void pui_application_install_updates(GSimpleAction *, GVariant *,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
94 gpointer);
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 const GActionEntry pui_application_actions[] = {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
97 { "about", pui_application_show_about_dialog },
3
2fa34d6272c6 Add menu item to launch the preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 2
diff changeset
98 { "preferences", pui_application_open_preferences },
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
99 { "quit", pui_application_quit },
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
100 { "install-updates", pui_application_install_updates }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
101 };
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 static gboolean
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
104 program_exists(const gchar *command_line)
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 gboolean is_program_in_path;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
107 gchar **argv = NULL;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
108 gchar *program_path;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
109
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
110 if (!g_shell_parse_argv(command_line, NULL, &argv, NULL)) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
111 return (FALSE);
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 program_path = g_find_program_in_path(argv[0]);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
114 is_program_in_path = (program_path != NULL) ? TRUE : FALSE;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
115 g_free(program_path);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
116 g_strfreev(argv);
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 return (is_program_in_path);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
119 }
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 static void
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
122 pui_application_show_about_dialog(GSimpleAction *simple, GVariant *parameter,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
123 gpointer user_data)
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
124 {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
125 PuiApplication *self = user_data;
2
7172a0db97af Use GtkBuilder for all widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 1
diff changeset
126 GtkBuilder *builder;
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
127
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
128 if (self->about_dialog == NULL) {
2
7172a0db97af Use GtkBuilder for all widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 1
diff changeset
129 /* get dialog from builder */
7172a0db97af Use GtkBuilder for all widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 1
diff changeset
130 builder = gtk_builder_new_from_resource("/org"
7172a0db97af Use GtkBuilder for all widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 1
diff changeset
131 "/guido-berhoerster/code/package-update-indicator"
7172a0db97af Use GtkBuilder for all widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 1
diff changeset
132 "/pui-about-dialog.ui");
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
133
2
7172a0db97af Use GtkBuilder for all widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 1
diff changeset
134 self->about_dialog = GTK_WIDGET(gtk_builder_get_object(builder,
7172a0db97af Use GtkBuilder for all widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 1
diff changeset
135 "about-dialog"));
7172a0db97af Use GtkBuilder for all widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 1
diff changeset
136
7172a0db97af Use GtkBuilder for all widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 1
diff changeset
137 g_object_unref(builder);
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
138 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
139
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
140 gtk_dialog_run(GTK_DIALOG(self->about_dialog));
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
141 gtk_widget_hide(self->about_dialog);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
142 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
143
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
144 static void
3
2fa34d6272c6 Add menu item to launch the preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 2
diff changeset
145 pui_application_open_preferences(GSimpleAction *simple, GVariant *parameter,
2fa34d6272c6 Add menu item to launch the preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 2
diff changeset
146 gpointer user_data)
2fa34d6272c6 Add menu item to launch the preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 2
diff changeset
147 {
2fa34d6272c6 Add menu item to launch the preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 2
diff changeset
148 GDesktopAppInfo *prefs_app_info;
2fa34d6272c6 Add menu item to launch the preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 2
diff changeset
149 GError *error = NULL;
2fa34d6272c6 Add menu item to launch the preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 2
diff changeset
150
2fa34d6272c6 Add menu item to launch the preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 2
diff changeset
151 prefs_app_info = g_desktop_app_info_new("org.guido-berhoerster.code."
2fa34d6272c6 Add menu item to launch the preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 2
diff changeset
152 "package-update-indicator.preferences.desktop");
2fa34d6272c6 Add menu item to launch the preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 2
diff changeset
153 if (prefs_app_info == NULL) {
2fa34d6272c6 Add menu item to launch the preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 2
diff changeset
154 g_warning("desktop file \"org.guido-berhoerster.code."
2fa34d6272c6 Add menu item to launch the preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 2
diff changeset
155 "package-update-indicator.preferences.desktop\" not found");
2fa34d6272c6 Add menu item to launch the preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 2
diff changeset
156 return;
2fa34d6272c6 Add menu item to launch the preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 2
diff changeset
157 }
2fa34d6272c6 Add menu item to launch the preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 2
diff changeset
158
2fa34d6272c6 Add menu item to launch the preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 2
diff changeset
159 if (!g_app_info_launch(G_APP_INFO(prefs_app_info), NULL, NULL,
2fa34d6272c6 Add menu item to launch the preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 2
diff changeset
160 &error)) {
2fa34d6272c6 Add menu item to launch the preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 2
diff changeset
161 g_warning("failed to launch preferences: %s", error->message);
2fa34d6272c6 Add menu item to launch the preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 2
diff changeset
162 g_error_free(error);
2fa34d6272c6 Add menu item to launch the preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 2
diff changeset
163 }
2fa34d6272c6 Add menu item to launch the preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 2
diff changeset
164 }
2fa34d6272c6 Add menu item to launch the preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 2
diff changeset
165
2fa34d6272c6 Add menu item to launch the preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 2
diff changeset
166 static void
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
167 pui_application_quit(GSimpleAction *simple, GVariant *parameter,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
168 gpointer user_data)
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
169 {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
170 PuiApplication *self = user_data;
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 /* quit the GTK main loop if the about dialog is running */
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
173 if (self->about_dialog != NULL) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
174 gtk_widget_hide(self->about_dialog);
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
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
177 g_application_quit(G_APPLICATION(self));
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
178 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
179
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
180 static void
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
181 pui_application_install_updates(GSimpleAction *simple, GVariant *parameter,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
182 gpointer user_data)
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 PuiApplication *self = user_data;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
185 GError *error = NULL;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
186
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
187 if (!g_spawn_command_line_async(self->update_command, &error)) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
188 g_warning("failed to run update command: %s", error->message);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
189 g_error_free(error);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
190 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
191 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
192
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
193 static void
56
08747f3a718b Add new setting to hide indicator menu items
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 55
diff changeset
194 update_menu_item(GtkWidget* widget, gpointer user_data)
08747f3a718b Add new setting to hide indicator menu items
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 55
diff changeset
195 {
08747f3a718b Add new setting to hide indicator menu items
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 55
diff changeset
196 gchar ** hidden_menu_items = user_data;
08747f3a718b Add new setting to hide indicator menu items
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 55
diff changeset
197 const gchar * action_name;
08747f3a718b Add new setting to hide indicator menu items
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 55
diff changeset
198 const gchar * name;
08747f3a718b Add new setting to hide indicator menu items
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 55
diff changeset
199
08747f3a718b Add new setting to hide indicator menu items
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 55
diff changeset
200 g_return_if_fail(GTK_IS_MENU_ITEM(widget));
08747f3a718b Add new setting to hide indicator menu items
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 55
diff changeset
201 action_name = gtk_actionable_get_action_name(GTK_ACTIONABLE(widget));
08747f3a718b Add new setting to hide indicator menu items
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 55
diff changeset
202 if (!g_str_has_prefix(action_name, "app.")) {
08747f3a718b Add new setting to hide indicator menu items
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 55
diff changeset
203 return;
08747f3a718b Add new setting to hide indicator menu items
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 55
diff changeset
204 }
08747f3a718b Add new setting to hide indicator menu items
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 55
diff changeset
205 name = action_name + strlen("app.");
08747f3a718b Add new setting to hide indicator menu items
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 55
diff changeset
206 gtk_widget_set_visible(widget,
08747f3a718b Add new setting to hide indicator menu items
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 55
diff changeset
207 !g_strv_contains((const gchar * const *)hidden_menu_items, name));
08747f3a718b Add new setting to hide indicator menu items
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 55
diff changeset
208 }
08747f3a718b Add new setting to hide indicator menu items
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 55
diff changeset
209
08747f3a718b Add new setting to hide indicator menu items
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 55
diff changeset
210 static void
08747f3a718b Add new setting to hide indicator menu items
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 55
diff changeset
211 update_menu_items(PuiApplication *self)
08747f3a718b Add new setting to hide indicator menu items
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 55
diff changeset
212 {
08747f3a718b Add new setting to hide indicator menu items
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 55
diff changeset
213 gchar ** hidden_menu_items;
08747f3a718b Add new setting to hide indicator menu items
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 55
diff changeset
214 GtkMenu * menu;
08747f3a718b Add new setting to hide indicator menu items
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 55
diff changeset
215
08747f3a718b Add new setting to hide indicator menu items
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 55
diff changeset
216 menu = app_indicator_get_menu(self->indicator);
08747f3a718b Add new setting to hide indicator menu items
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 55
diff changeset
217 hidden_menu_items = g_settings_get_strv(self->settings,
08747f3a718b Add new setting to hide indicator menu items
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 55
diff changeset
218 "hide-menu-items");
08747f3a718b Add new setting to hide indicator menu items
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 55
diff changeset
219 g_return_if_fail(hidden_menu_items != NULL);
08747f3a718b Add new setting to hide indicator menu items
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 55
diff changeset
220 g_return_if_fail((menu != NULL) && GTK_IS_CONTAINER(menu));
08747f3a718b Add new setting to hide indicator menu items
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 55
diff changeset
221 gtk_container_foreach(GTK_CONTAINER(menu), update_menu_item,
08747f3a718b Add new setting to hide indicator menu items
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 55
diff changeset
222 hidden_menu_items);
08747f3a718b Add new setting to hide indicator menu items
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 55
diff changeset
223 g_strfreev(hidden_menu_items);
08747f3a718b Add new setting to hide indicator menu items
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 55
diff changeset
224 }
08747f3a718b Add new setting to hide indicator menu items
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 55
diff changeset
225
08747f3a718b Add new setting to hide indicator menu items
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 55
diff changeset
226 static void
55
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
227 update_indicator(PuiApplication *self, const gchar *title)
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
228 {
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
229 switch (self->state) {
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
230 case PUI_STATE_INITIAL:
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
231 app_indicator_set_status(self->indicator,
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
232 APP_INDICATOR_STATUS_PASSIVE);
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
233 break;
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
234 case PUI_STATE_UP_TO_DATE:
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
235 app_indicator_set_status(self->indicator, self->always_active ?
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
236 APP_INDICATOR_STATUS_ACTIVE :
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
237 APP_INDICATOR_STATUS_PASSIVE);
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
238 break;
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
239 case PUI_STATE_NORMAL_UPDATES_AVAILABLE: /* FALLTHGROUGH */
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
240 case PUI_STATE_IMPORTANT_UPDATES_AVAILABLE: /* FALLTHGROUGH */
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
241 case PUI_STATE_SESSION_RESTART_REQUIRED: /* FALLTHGROUGH */
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
242 case PUI_STATE_SYSTEM_RESTART_REQUIRED: /* FALLTHGROUGH */
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
243 case PUI_STATE_ERROR:
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
244 app_indicator_set_status(self->indicator,
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
245 APP_INDICATOR_STATUS_ACTIVE);
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
246 break;
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
247 }
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
248 app_indicator_set_icon_full(self->indicator, icon_names[self->state],
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
249 title);
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
250 }
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
251
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
252 static void
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
253 update_notification(PuiApplication *self, const gchar *title, const gchar *body)
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
254 {
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
255 GSimpleAction *install_updates_action;
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
256 GApplication *application = G_APPLICATION(self);
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
257 GNotification *notification = NULL;
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
258
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
259 install_updates_action =
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
260 G_SIMPLE_ACTION(g_action_map_lookup_action(G_ACTION_MAP(self),
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
261 "install-updates"));
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
262
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
263 switch (self->state) {
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
264 case PUI_STATE_INITIAL: /* FALLTHGROUGH */
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
265 case PUI_STATE_UP_TO_DATE: /* FALLTHGROUGH */
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
266 case PUI_STATE_ERROR:
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
267 /* withdraw exisiting notification */
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
268 g_application_withdraw_notification(application,
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
269 "package-updates-or-restart-required");
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
270 break;
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
271 case PUI_STATE_NORMAL_UPDATES_AVAILABLE: /* FALLTHGROUGH */
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
272 case PUI_STATE_IMPORTANT_UPDATES_AVAILABLE: /* FALLTHGROUGH */
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
273 case PUI_STATE_SESSION_RESTART_REQUIRED: /* FALLTHGROUGH */
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
274 case PUI_STATE_SYSTEM_RESTART_REQUIRED:
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
275 /* create notification */
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
276 notification = g_notification_new(title);
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
277 g_notification_set_body(notification, body);
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
278 g_notification_set_icon(notification, self->icons[self->state]);
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
279 g_notification_set_priority(notification,
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
280 G_NOTIFICATION_PRIORITY_NORMAL);
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
281 if (g_action_get_enabled(G_ACTION(install_updates_action))) {
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
282 g_notification_add_button(notification,
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
283 _("Install Updates"),
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
284 "app.install-updates");
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
285 }
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
286 g_application_send_notification(application,
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
287 "package-updates-or-restart-required", notification);
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
288 break;
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
289 }
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
290
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
291 if (notification != NULL) {
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
292 g_object_unref(notification);
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
293 }
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
294 }
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
295
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
296 static void
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
297 update_ui(PuiApplication *self)
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
298 {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
299 GSimpleAction *install_updates_action;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
300 guint important_updates = 0;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
301 guint normal_updates = 0;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
302 gchar *title = NULL;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
303 gchar *body = NULL;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
304 GApplication *application = G_APPLICATION(self);
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 install_updates_action =
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
307 G_SIMPLE_ACTION(g_action_map_lookup_action(G_ACTION_MAP(self),
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
308 "install-updates"));
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
309
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
310 if ((self->state == PUI_STATE_NORMAL_UPDATES_AVAILABLE) ||
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
311 (self->state == PUI_STATE_IMPORTANT_UPDATES_AVAILABLE)) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
312 g_object_get(self->backend,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
313 "important-updates", &important_updates,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
314 "normal-updates", &normal_updates, NULL);
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
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
317 /* actions */
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
318 switch (self->state) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
319 case PUI_STATE_INITIAL: /* FALLTHGROUGH */
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
320 case PUI_STATE_UP_TO_DATE: /* FALLTHGROUGH */
10
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
321 case PUI_STATE_SESSION_RESTART_REQUIRED: /* FALLTHGROUGH */
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
322 case PUI_STATE_SYSTEM_RESTART_REQUIRED: /* FALLTHGROUGH */
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
323 case PUI_STATE_ERROR:
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
324 g_simple_action_set_enabled(install_updates_action, FALSE);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
325 break;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
326 case PUI_STATE_NORMAL_UPDATES_AVAILABLE: /* FALLTHROUGH */
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
327 case PUI_STATE_IMPORTANT_UPDATES_AVAILABLE:
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
328 g_simple_action_set_enabled(install_updates_action,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
329 program_exists(self->update_command));
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
330 break;
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
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
333 /* title and body for indicator and notification */
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
334 switch (self->state) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
335 case PUI_STATE_INITIAL:
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
336 title = g_strdup("");
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
337 body = g_strdup("");
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
338 break;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
339 case PUI_STATE_UP_TO_DATE:
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
340 title = g_strdup(_("Up to Date"));
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
341 body = g_strdup(_("The system is up to date."));
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_NORMAL_UPDATES_AVAILABLE:
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
344 title = g_strdup(g_dngettext(NULL, "Software Update",
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
345 "Software Updates", (gulong)normal_updates));
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
346 if (normal_updates == 1) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
347 body = g_strdup(_("There is a software update "
16
6304dbbedb67 Fix typo in notification message
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 14
diff changeset
348 "available."));
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
349 } else {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
350 body = g_strdup_printf(_("There are %u "
16
6304dbbedb67 Fix typo in notification message
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 14
diff changeset
351 "software updates available."), normal_updates);
0
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 break;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
354 case PUI_STATE_IMPORTANT_UPDATES_AVAILABLE:
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
355 title = g_strdup(g_dngettext(NULL, "Important Software Update",
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
356 "Important Software Updates", (gulong)important_updates));
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
357 if ((normal_updates == 0) && (important_updates == 1)) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
358 body = g_strdup(_("There is an important "
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
359 "software update available."));
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
360 } else if ((normal_updates == 0) && (important_updates > 1)) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
361 body = g_strdup_printf(_("There are %u "
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
362 "important software updates available."),
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
363 important_updates);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
364 } else if ((normal_updates > 0) && (important_updates == 1)) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
365 body = g_strdup_printf(_("There are %u "
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
366 "software updates available, "
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
367 "one of them is important."),
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
368 normal_updates + important_updates);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
369 } else {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
370 body = g_strdup_printf(_("There are %u "
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
371 "software updates available, "
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
372 "%u of them are important."),
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
373 normal_updates + important_updates,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
374 important_updates);
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 break;
10
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
377 case PUI_STATE_SESSION_RESTART_REQUIRED:
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
378 title = g_strdup(_("Logout Required"));
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
379 body = g_strdup(_("You need to log out and back in for the "
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
380 "update to take effect."));
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
381 break;
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
382 case PUI_STATE_SYSTEM_RESTART_REQUIRED:
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
383 title = g_strdup(_("Restart Required"));
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
384 body = g_strdup(_("The computer has to be restarted for the "
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
385 "updates to take effect."));
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
386 break;
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
387 case PUI_STATE_ERROR:
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
388 title = g_strdup(self->error_message);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
389 break;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
390 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
391
55
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
392 update_indicator(self, title);
56
08747f3a718b Add new setting to hide indicator menu items
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 55
diff changeset
393 update_menu_items(self);
55
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
394 update_notification(self, title, body);
0
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 g_debug("indicator icon: %s, notification title: \"%s\", "
35
c4b8785d0b75 Back out fallback icon support which does not work as intended
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 30
diff changeset
397 "notification body: \"%s\"", icon_names[self->state], title, body);
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
398
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
399 g_free(body);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
400 g_free(title);
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
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
403 static void
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
404 transition_state(PuiApplication *self)
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
405 {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
406 PuiState state = self->state;
10
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
407 PuiRestart restart_type;
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
408 guint important_updates;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
409 guint normal_updates;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
410 gchar *old_state;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
411 gchar *new_state;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
412
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
413 switch (self->state) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
414 case PUI_STATE_INITIAL: /* FALLTHROUGH */
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
415 case PUI_STATE_UP_TO_DATE: /* FALLTHROUGH */
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
416 case PUI_STATE_NORMAL_UPDATES_AVAILABLE: /* FALLTHROUGH */
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
417 case PUI_STATE_IMPORTANT_UPDATES_AVAILABLE:
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
418 if (self->error_message != NULL) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
419 state = PUI_STATE_ERROR;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
420 break;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
421 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
422
10
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
423 g_object_get(self->backend, "restart-type", &restart_type,
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
424 "important-updates", &important_updates,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
425 "normal-updates", &normal_updates, NULL);
10
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
426 if (restart_type == PUI_RESTART_SESSION) {
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
427 state = PUI_STATE_SESSION_RESTART_REQUIRED;
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
428 } else if (restart_type == PUI_RESTART_SYSTEM) {
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
429 state = PUI_STATE_SYSTEM_RESTART_REQUIRED;
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
430 } else if (important_updates > 0) {
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
431 state = PUI_STATE_IMPORTANT_UPDATES_AVAILABLE;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
432 } else if (normal_updates > 0) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
433 state = PUI_STATE_NORMAL_UPDATES_AVAILABLE;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
434 } else {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
435 state = PUI_STATE_UP_TO_DATE;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
436 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
437 break;
10
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
438 case PUI_STATE_SESSION_RESTART_REQUIRED:
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
439 g_object_get(self->backend, "restart-type", &restart_type,
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
440 NULL);
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
441 if (restart_type == PUI_RESTART_SYSTEM) {
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
442 state = PUI_STATE_SYSTEM_RESTART_REQUIRED;
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
443 }
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
444 break;
adba37525ee5 Notify about required session or system restarts
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 6
diff changeset
445 case PUI_STATE_SYSTEM_RESTART_REQUIRED: /* FALLTHROUGH */
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
446 case PUI_STATE_ERROR:
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
447 break;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
448 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
449
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
450 if (state != self->state) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
451 old_state = pui_types_enum_to_string(PUI_TYPE_STATE,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
452 self->state);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
453 new_state = pui_types_enum_to_string(PUI_TYPE_STATE, state);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
454 g_debug("state %s -> %s", old_state, new_state);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
455
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
456 self->state = state;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
457 update_ui(self);
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 g_free(new_state);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
460 g_free(old_state);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
461 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
462 }
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 static void
56
08747f3a718b Add new setting to hide indicator menu items
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 55
diff changeset
465 on_hide_menu_items_changed(GSettings *settings, gchar *key, gpointer user_data)
08747f3a718b Add new setting to hide indicator menu items
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 55
diff changeset
466 {
08747f3a718b Add new setting to hide indicator menu items
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 55
diff changeset
467 g_debug("setting hide-menu-items changed");
08747f3a718b Add new setting to hide indicator menu items
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 55
diff changeset
468 update_menu_items(user_data);
08747f3a718b Add new setting to hide indicator menu items
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 55
diff changeset
469 }
08747f3a718b Add new setting to hide indicator menu items
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 55
diff changeset
470
08747f3a718b Add new setting to hide indicator menu items
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 55
diff changeset
471 static void
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
472 on_backend_restart_required(PuiBackend *backend, gpointer user_data)
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
473 {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
474 PuiApplication *self = user_data;
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 restart = TRUE;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
477 g_action_group_activate_action(G_ACTION_GROUP(G_APPLICATION(self)),
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
478 "quit", NULL);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
479 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
480
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
481 static void
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
482 on_backend_state_changed(PuiBackend *backend, gpointer user_data)
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 PuiApplication *self = user_data;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
485
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
486 transition_state(self);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
487 }
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 static void
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
490 on_pui_backend_finished(GObject *source_object, GAsyncResult *result,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
491 gpointer user_data)
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 PuiApplication *self = user_data;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
494 GError *error = NULL;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
495
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
496 self->backend = pui_backend_new_finish(result, &error);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
497 if (self->backend == NULL) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
498 g_warning("failed to instantiate backend: %s", error->message);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
499 g_free(self->error_message);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
500 g_error_free(error);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
501 self->error_message = g_strdup(_("Update notifications "
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
502 "are not supported."));
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
503 transition_state(self);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
504 return;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
505 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
506
6
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
507 pui_backend_set_proxy(self->backend, g_getenv("http_proxy"),
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
508 g_getenv("https_proxy"), g_getenv("ftp_proxy"),
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
509 g_getenv("socks_proxy"), g_getenv("no_proxy"), NULL);
2477a6151087 Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 4
diff changeset
510
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
511 g_settings_bind(self->settings, "refresh-interval", self->backend,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
512 "refresh-interval", G_SETTINGS_BIND_GET);
4
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 3
diff changeset
513 g_settings_bind(self->settings, "use-mobile-connection", self->backend,
3d72ca76538d Add setting to control whether to use a mobile connection
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 3
diff changeset
514 "use-mobile-connection", G_SETTINGS_BIND_GET);
0
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 transition_state(self);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
517
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
518 g_signal_connect(self->backend, "restart-required",
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
519 G_CALLBACK(on_backend_restart_required), self);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
520 g_signal_connect(self->backend, "state-changed",
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
521 G_CALLBACK(on_backend_state_changed), self);
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
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
524 static void
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
525 pui_application_startup(GApplication *application)
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
526 {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
527 PuiApplication *self = PUI_APPLICATION(application);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
528 gsize i;
2
7172a0db97af Use GtkBuilder for all widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 1
diff changeset
529 GtkBuilder *builder;
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
530 GtkWidget *menu;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
531
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
532 G_APPLICATION_CLASS(pui_application_parent_class)->startup(application);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
533
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
534 /* create actions */
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
535 g_action_map_add_action_entries(G_ACTION_MAP(self),
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
536 pui_application_actions, G_N_ELEMENTS(pui_application_actions),
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
537 self);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
538
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
539 /* load icons */
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
540 for (i = 0; i < G_N_ELEMENTS(self->icons); i++) {
35
c4b8785d0b75 Back out fallback icon support which does not work as intended
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 30
diff changeset
541 self->icons[i] = g_themed_icon_new(icon_names[i]);
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
55
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
544 /* create settings backend */
1
2f04ec9e0506 Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 0
diff changeset
545 self->settings = pui_settings_new();
0
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 /* start instantiating backend */
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
548 pui_backend_new_async(self->cancellable, on_pui_backend_finished, self);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
549
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
550 /* create indicator */
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
551 self->indicator = app_indicator_new(APPLICATION_ID,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
552 "system-software-update",
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
553 APP_INDICATOR_CATEGORY_APPLICATION_STATUS);
14
f783ba95ec4a Set application indicator title
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 10
diff changeset
554 app_indicator_set_title(self->indicator, _("Package Update Indicator"));
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
555
2
7172a0db97af Use GtkBuilder for all widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 1
diff changeset
556 /* get menu from builder and add it to the indicator */
7172a0db97af Use GtkBuilder for all widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 1
diff changeset
557 builder = gtk_builder_new_from_resource("/org/guido-berhoerster/code/"
7172a0db97af Use GtkBuilder for all widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 1
diff changeset
558 "package-update-indicator/pui-menu.ui");
7172a0db97af Use GtkBuilder for all widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 1
diff changeset
559 menu = GTK_WIDGET(gtk_builder_get_object(builder, "menu"));
7172a0db97af Use GtkBuilder for all widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 1
diff changeset
560 gtk_widget_insert_action_group(menu, "app", G_ACTION_GROUP(self));
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
561 gtk_widget_show_all(menu);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
562 app_indicator_set_menu(self->indicator, GTK_MENU(menu));
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
563
55
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
564 /*
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
565 * bind settings to properties after indicator with its menu are
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
566 * initialized, if the setting "always-active" is set by the user the
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
567 * corresponding property is set accordingly which in turn invokes
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
568 * update_ui() so order matters here
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
569 */
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
570 g_settings_bind(self->settings, "update-command", self,
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
571 "update-command", G_SETTINGS_BIND_GET);
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
572 g_settings_bind(self->settings, "always-active", self,
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
573 "always-active", G_SETTINGS_BIND_GET);
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
574
56
08747f3a718b Add new setting to hide indicator menu items
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 55
diff changeset
575 /* watch hide-menu-items setting in order to update the menu */
08747f3a718b Add new setting to hide indicator menu items
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 55
diff changeset
576 g_signal_connect(self->settings, "changed::hide-menu-items",
08747f3a718b Add new setting to hide indicator menu items
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 55
diff changeset
577 G_CALLBACK(on_hide_menu_items_changed), self);
08747f3a718b Add new setting to hide indicator menu items
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 55
diff changeset
578
55
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
579 /* ensure the ui reflects the current state */
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
580 update_ui(self);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
581
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
582 /* keep GApplication running */
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
583 g_application_hold(application);
2
7172a0db97af Use GtkBuilder for all widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 1
diff changeset
584
7172a0db97af Use GtkBuilder for all widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 1
diff changeset
585 g_object_unref(builder);
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
586 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
587
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
588 static void
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
589 pui_application_shutdown(GApplication *application)
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 GApplicationClass *application_class =
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
592 G_APPLICATION_CLASS(pui_application_parent_class);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
593
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
594 application_class->shutdown(application);
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
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
597 static gint
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
598 pui_application_handle_local_options(GApplication *application,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
599 GVariantDict *options)
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
600 {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
601 gchar *messages_debug;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
602 gchar **args = NULL;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
603 GError *error = NULL;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
604
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
605 /* filename arguments are not allowed */
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
606 if (g_variant_dict_lookup(options, G_OPTION_REMAINING, "^a&ay",
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
607 &args)) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
608 g_printerr("invalid argument: \"%s\"\n", args[0]);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
609 g_free(args);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
610 return (1);
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 (g_variant_dict_contains(options, "version")) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
614 g_print("%s %s\n", PACKAGE, VERSION);
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 /* quit */
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
617 return (0);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
618 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
619
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
620 if (g_variant_dict_contains(options, "debug")) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
621 /* enable debug logging */
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
622 messages_debug = g_strjoin(":", G_LOG_DOMAIN,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
623 g_getenv("G_MESSAGES_DEBUG"), NULL);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
624 g_setenv("G_MESSAGES_DEBUG", messages_debug, TRUE);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
625 g_free(messages_debug);
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 /*
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
629 * register with the session bus so that it is possible to discern
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
630 * between remote and primary instance and that remote actions can be
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
631 * invoked, this causes the startup signal to be emitted which, in case
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
632 * of the primary instance, starts to instantiate the
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
633 * backend with the given values
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
634 */
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
635 if (!g_application_register(application, NULL, &error)) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
636 g_critical("g_application_register: %s", error->message);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
637 g_error_free(error);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
638 return (1);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
639 }
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 if (g_variant_dict_contains(options, "quit")) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
642 /* only valid if a remote instance is running */
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
643 if (!g_application_get_is_remote(application)) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
644 g_printerr("%s is not running\n", g_get_prgname());
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
645 return (1);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
646 }
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 /* signal remote instance to quit */
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
649 g_action_group_activate_action(G_ACTION_GROUP(application),
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
650 "quit", NULL);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
651
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
652 /* quit local instance */
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
653 return (0);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
654 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
655
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
656 /* proceed with default command line processing */
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
657 return (-1);
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
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
660 static void
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
661 pui_application_activate(GApplication *application) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
662 GApplicationClass *application_class =
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
663 G_APPLICATION_CLASS(pui_application_parent_class);
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 /* do nothing, implementation required by GApplication */
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
666
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
667 application_class->activate(application);
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
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
670 static void
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
671 pui_application_set_property(GObject *object, guint property_id,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
672 const GValue *value, GParamSpec *pspec)
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 PuiApplication *self = PUI_APPLICATION(object);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
675
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
676 switch (property_id) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
677 case PROP_UPDATE_COMMAND:
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
678 g_free(self->update_command);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
679 self->update_command = g_value_dup_string(value);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
680 g_debug("property \"update-command\" set to \"%s\"",
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
681 self->update_command);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
682 break;
55
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
683 case PROP_ALWAYS_ACTIVE:
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
684 self->always_active = g_value_get_boolean(value);
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
685 g_debug("property \"always-active\" set to \"%s\"",
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
686 self->always_active ? "TRUE" : "FALSE");
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
687 update_ui(self);
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
688 break;
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
689 default:
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
690 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
691 break;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
692 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
693 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
694
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
695 static void
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
696 pui_application_get_property(GObject *object, guint property_id, GValue *value,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
697 GParamSpec *pspec)
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
698 {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
699 PuiApplication *self = PUI_APPLICATION(object);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
700
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
701 switch (property_id) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
702 case PROP_UPDATE_COMMAND:
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
703 g_value_set_string(value, self->update_command);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
704 break;
55
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
705 case PROP_ALWAYS_ACTIVE:
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
706 g_value_set_boolean(value, self->always_active);
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
707 break;
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
708 default:
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
709 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
710 break;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
711 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
712 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
713
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
714 static void
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
715 pui_application_dispose(GObject *object)
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
716 {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
717 PuiApplication *self = PUI_APPLICATION(object);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
718 gsize i;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
719
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
720 if (self->settings != NULL) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
721 g_signal_handlers_disconnect_by_data(self->settings, self);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
722 g_clear_object(&self->settings);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
723 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
724
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
725 if (self->cancellable != NULL) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
726 g_cancellable_cancel(self->cancellable);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
727 g_clear_object(&self->cancellable);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
728 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
729
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
730 if (self->backend != NULL) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
731 g_clear_object(&self->backend);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
732 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
733
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
734 if (self->indicator != NULL) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
735 g_clear_object(&self->indicator);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
736 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
737
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
738 if (self->about_dialog != NULL) {
55
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
739 g_clear_pointer(&self->about_dialog, gtk_widget_destroy);
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
740 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
741
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
742 for (i = 0; i < G_N_ELEMENTS(self->icons); i++) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
743 if (self->icons[i] != NULL) {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
744 g_clear_object(&self->icons[i]);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
745 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
746 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
747
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
748 G_OBJECT_CLASS(pui_application_parent_class)->dispose(object);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
749 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
750
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
751 static void
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
752 pui_application_finalize(GObject *object)
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
753 {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
754 PuiApplication *self = PUI_APPLICATION(object);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
755
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
756 g_free(self->update_command);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
757 g_free(self->error_message);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
758
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
759 G_OBJECT_CLASS(pui_application_parent_class)->finalize(object);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
760 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
761
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
762 static void
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
763 pui_application_class_init(PuiApplicationClass *klass)
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
764 {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
765 GObjectClass *object_class = G_OBJECT_CLASS(klass);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
766 GApplicationClass *application_class = G_APPLICATION_CLASS(klass);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
767
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
768 object_class->set_property = pui_application_set_property;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
769 object_class->get_property = pui_application_get_property;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
770 object_class->dispose = pui_application_dispose;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
771 object_class->finalize = pui_application_finalize;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
772
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
773 properties[PROP_UPDATE_COMMAND] = g_param_spec_string("update-command",
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
774 "Update command", "Command for installing updates", NULL,
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
775 G_PARAM_READWRITE);
55
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
776 properties[PROP_ALWAYS_ACTIVE] = g_param_spec_boolean("always-active",
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
777 "Whether the indicator is always active",
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
778 "Whether the indicator is active even when packages are up to date",
24cba399757f Add new setting "always-active"
Guido Berhoerster <guido+pui@berhoerster.name>
parents: 35
diff changeset
779 TRUE, G_PARAM_READWRITE);
0
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
780
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
781 g_object_class_install_properties(object_class, PROP_LAST, properties);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
782
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
783 application_class->startup = pui_application_startup;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
784 application_class->shutdown = pui_application_shutdown;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
785 application_class->handle_local_options =
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
786 pui_application_handle_local_options;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
787 application_class->activate = pui_application_activate;
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
788 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
789
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
790 static void
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
791 pui_application_init(PuiApplication *self)
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
792 {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
793 g_application_add_main_option_entries(G_APPLICATION(self),
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
794 cmd_options);
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
795
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
796 self->cancellable = g_cancellable_new();
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
797 }
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
798
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
799 PuiApplication *
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
800 pui_application_new(void)
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
801 {
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
802 return (g_object_new(PUI_TYPE_APPLICATION, "application-id",
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
803 APPLICATION_ID, NULL));
6884bb8130ca Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff changeset
804 }