Mercurial > projects > package-update-indicator
annotate pui-application.c @ 6:2477a6151087
Make PackagKit use the user's network proxies
Pick up network proxies from the user's environment and make PackagKit use
them. Setting network proxies is a privileged operation, so it is only
attempted if the user is allowed to use the polkit action
org.freedesktop.packagekit.system-network-proxy-configure without
authentication.
author | Guido Berhoerster <guido+pui@berhoerster.name> |
---|---|
date | Tue, 19 Jun 2018 15:44:36 +0200 |
parents | 3d72ca76538d |
children | adba37525ee5 |
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> |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
26 #include <libappindicator/app-indicator.h> |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
27 #include <stdlib.h> |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
28 #include <string.h> |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
29 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
30 #include "pui-application.h" |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
31 #include "pui-backend.h" |
1
2f04ec9e0506
Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
0
diff
changeset
|
32 #include "pui-common.h" |
2f04ec9e0506
Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
0
diff
changeset
|
33 #include "pui-settings.h" |
2f04ec9e0506
Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
0
diff
changeset
|
34 #include "pui-types.h" |
0
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
35 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
36 struct _PuiApplication { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
37 GApplication parent_instance; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
38 GSettings *settings; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
39 GCancellable *cancellable; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
40 PuiBackend *backend; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
41 AppIndicator *indicator; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
42 GtkWidget *about_dialog; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
43 GIcon *icons[PUI_STATE_LAST]; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
44 PuiState state; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
45 gchar *update_command; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
46 gchar *error_message; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
47 }; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
48 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
49 G_DEFINE_TYPE(PuiApplication, pui_application, G_TYPE_APPLICATION) |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
50 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
51 enum { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
52 PROP_0, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
53 PROP_UPDATE_COMMAND, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
54 PROP_LAST |
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 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
57 extern gboolean restart; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
58 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
59 static GParamSpec *properties[PROP_LAST] = { NULL }; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
60 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
61 static const gchar *icon_names[PUI_STATE_LAST] = { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
62 [PUI_STATE_INITIAL] = "system-software-update", |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
63 [PUI_STATE_UP_TO_DATE] = "system-software-update", |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
64 [PUI_STATE_NORMAL_UPDATES_AVAILABLE] = "software-update-available", |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
65 [PUI_STATE_IMPORTANT_UPDATES_AVAILABLE] = "software-update-urgent", |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
66 [PUI_STATE_ERROR] = "dialog-warning" |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
67 }; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
68 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
69 static const GOptionEntry cmd_options[] = { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
70 { "debug", '\0', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, NULL, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
71 N_("Enable debugging messages"), NULL }, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
72 { "quit", 'q', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, NULL, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
73 N_("Quit running instance of Package Update Indicator"), NULL }, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
74 { "version", 'V', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, NULL, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
75 N_("Print the version number and quit"), NULL }, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
76 { 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
|
77 { NULL } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
78 }; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
79 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
80 static void pui_application_show_about_dialog(GSimpleAction *, GVariant *, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
81 gpointer); |
3
2fa34d6272c6
Add menu item to launch the preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
2
diff
changeset
|
82 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
|
83 gpointer); |
0
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
84 static void pui_application_quit(GSimpleAction *, GVariant *, gpointer); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
85 static void pui_application_install_updates(GSimpleAction *, GVariant *, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
86 gpointer); |
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 const GActionEntry pui_application_actions[] = { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
89 { "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
|
90 { "preferences", pui_application_open_preferences }, |
0
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
91 { "quit", pui_application_quit }, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
92 { "install-updates", pui_application_install_updates } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
93 }; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
94 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
95 static gboolean |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
96 program_exists(const gchar *command_line) |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
97 { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
98 gboolean is_program_in_path; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
99 gchar **argv = NULL; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
100 gchar *program_path; |
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 if (!g_shell_parse_argv(command_line, NULL, &argv, NULL)) { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
103 return (FALSE); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
104 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
105 program_path = g_find_program_in_path(argv[0]); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
106 is_program_in_path = (program_path != NULL) ? TRUE : FALSE; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
107 g_free(program_path); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
108 g_strfreev(argv); |
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 return (is_program_in_path); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
111 } |
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 static void |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
114 pui_application_show_about_dialog(GSimpleAction *simple, GVariant *parameter, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
115 gpointer user_data) |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
116 { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
117 PuiApplication *self = user_data; |
2
7172a0db97af
Use GtkBuilder for all widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
1
diff
changeset
|
118 GtkBuilder *builder; |
0
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 if (self->about_dialog == NULL) { |
2
7172a0db97af
Use GtkBuilder for all widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
1
diff
changeset
|
121 /* get dialog from builder */ |
7172a0db97af
Use GtkBuilder for all widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
1
diff
changeset
|
122 builder = gtk_builder_new_from_resource("/org" |
7172a0db97af
Use GtkBuilder for all widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
1
diff
changeset
|
123 "/guido-berhoerster/code/package-update-indicator" |
7172a0db97af
Use GtkBuilder for all widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
1
diff
changeset
|
124 "/pui-about-dialog.ui"); |
0
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
125 |
2
7172a0db97af
Use GtkBuilder for all widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
1
diff
changeset
|
126 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
|
127 "about-dialog")); |
7172a0db97af
Use GtkBuilder for all widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
1
diff
changeset
|
128 |
7172a0db97af
Use GtkBuilder for all widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
1
diff
changeset
|
129 g_object_unref(builder); |
0
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
130 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
131 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
132 gtk_dialog_run(GTK_DIALOG(self->about_dialog)); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
133 gtk_widget_hide(self->about_dialog); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
134 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
135 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
136 static void |
3
2fa34d6272c6
Add menu item to launch the preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
2
diff
changeset
|
137 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
|
138 gpointer user_data) |
2fa34d6272c6
Add menu item to launch the preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
2
diff
changeset
|
139 { |
2fa34d6272c6
Add menu item to launch the preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
2
diff
changeset
|
140 GDesktopAppInfo *prefs_app_info; |
2fa34d6272c6
Add menu item to launch the preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
2
diff
changeset
|
141 GError *error = NULL; |
2fa34d6272c6
Add menu item to launch the preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
2
diff
changeset
|
142 |
2fa34d6272c6
Add menu item to launch the preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
2
diff
changeset
|
143 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
|
144 "package-update-indicator.preferences.desktop"); |
2fa34d6272c6
Add menu item to launch the preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
2
diff
changeset
|
145 if (prefs_app_info == NULL) { |
2fa34d6272c6
Add menu item to launch the preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
2
diff
changeset
|
146 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
|
147 "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
|
148 return; |
2fa34d6272c6
Add menu item to launch the preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
2
diff
changeset
|
149 } |
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 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
|
152 &error)) { |
2fa34d6272c6
Add menu item to launch the preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
2
diff
changeset
|
153 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
|
154 g_error_free(error); |
2fa34d6272c6
Add menu item to launch the preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
2
diff
changeset
|
155 } |
2fa34d6272c6
Add menu item to launch the preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
2
diff
changeset
|
156 } |
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 static void |
0
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
159 pui_application_quit(GSimpleAction *simple, GVariant *parameter, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
160 gpointer user_data) |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
161 { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
162 PuiApplication *self = user_data; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
163 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
164 /* quit the GTK main loop if the about dialog is running */ |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
165 if (self->about_dialog != NULL) { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
166 gtk_widget_hide(self->about_dialog); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
167 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
168 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
169 g_application_quit(G_APPLICATION(self)); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
170 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
171 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
172 static void |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
173 pui_application_install_updates(GSimpleAction *simple, GVariant *parameter, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
174 gpointer user_data) |
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 PuiApplication *self = user_data; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
177 GError *error = NULL; |
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 if (!g_spawn_command_line_async(self->update_command, &error)) { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
180 g_warning("failed to run update command: %s", error->message); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
181 g_error_free(error); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
182 } |
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 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
185 static void |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
186 update_ui(PuiApplication *self) |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
187 { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
188 GSimpleAction *install_updates_action; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
189 guint important_updates = 0; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
190 guint normal_updates = 0; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
191 gchar *title = NULL; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
192 gchar *body = NULL; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
193 GApplication *application = G_APPLICATION(self); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
194 GNotification *notification = NULL; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
195 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
196 install_updates_action = |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
197 G_SIMPLE_ACTION(g_action_map_lookup_action(G_ACTION_MAP(self), |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
198 "install-updates")); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
199 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
200 if ((self->state == PUI_STATE_NORMAL_UPDATES_AVAILABLE) || |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
201 (self->state == PUI_STATE_IMPORTANT_UPDATES_AVAILABLE)) { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
202 g_object_get(self->backend, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
203 "important-updates", &important_updates, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
204 "normal-updates", &normal_updates, NULL); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
205 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
206 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
207 /* actions */ |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
208 switch (self->state) { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
209 case PUI_STATE_INITIAL: /* FALLTHGROUGH */ |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
210 case PUI_STATE_UP_TO_DATE: /* FALLTHGROUGH */ |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
211 case PUI_STATE_ERROR: |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
212 g_simple_action_set_enabled(install_updates_action, FALSE); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
213 break; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
214 case PUI_STATE_NORMAL_UPDATES_AVAILABLE: /* FALLTHROUGH */ |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
215 case PUI_STATE_IMPORTANT_UPDATES_AVAILABLE: |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
216 g_simple_action_set_enabled(install_updates_action, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
217 program_exists(self->update_command)); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
218 break; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
219 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
220 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
221 /* title and body for indicator and notification */ |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
222 switch (self->state) { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
223 case PUI_STATE_INITIAL: |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
224 title = g_strdup(""); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
225 body = g_strdup(""); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
226 break; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
227 case PUI_STATE_UP_TO_DATE: |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
228 title = g_strdup(_("Up to Date")); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
229 body = g_strdup(_("The system is up to date.")); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
230 break; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
231 case PUI_STATE_NORMAL_UPDATES_AVAILABLE: |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
232 title = g_strdup(g_dngettext(NULL, "Software Update", |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
233 "Software Updates", (gulong)normal_updates)); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
234 if (normal_updates == 1) { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
235 body = g_strdup(_("There is a software update " |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
236 "avaliable.")); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
237 } else { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
238 body = g_strdup_printf(_("There are %u " |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
239 "software updates avaliable."), normal_updates); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
240 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
241 break; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
242 case PUI_STATE_IMPORTANT_UPDATES_AVAILABLE: |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
243 title = g_strdup(g_dngettext(NULL, "Important Software Update", |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
244 "Important Software Updates", (gulong)important_updates)); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
245 if ((normal_updates == 0) && (important_updates == 1)) { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
246 body = g_strdup(_("There is an important " |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
247 "software update available.")); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
248 } else if ((normal_updates == 0) && (important_updates > 1)) { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
249 body = g_strdup_printf(_("There are %u " |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
250 "important software updates available."), |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
251 important_updates); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
252 } else if ((normal_updates > 0) && (important_updates == 1)) { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
253 body = g_strdup_printf(_("There are %u " |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
254 "software updates available, " |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
255 "one of them is important."), |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
256 normal_updates + important_updates); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
257 } else { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
258 body = g_strdup_printf(_("There are %u " |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
259 "software updates available, " |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
260 "%u of them are important."), |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
261 normal_updates + important_updates, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
262 important_updates); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
263 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
264 break; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
265 case PUI_STATE_ERROR: |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
266 title = g_strdup(self->error_message); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
267 break; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
268 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
269 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
270 /* indicator */ |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
271 switch (self->state) { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
272 case PUI_STATE_INITIAL: |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
273 app_indicator_set_status(self->indicator, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
274 APP_INDICATOR_STATUS_PASSIVE); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
275 break; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
276 case PUI_STATE_UP_TO_DATE: /* FALLTHGROUGH */ |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
277 case PUI_STATE_NORMAL_UPDATES_AVAILABLE: /* FALLTHGROUGH */ |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
278 case PUI_STATE_IMPORTANT_UPDATES_AVAILABLE: /* FALLTHGROUGH */ |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
279 case PUI_STATE_ERROR: |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
280 app_indicator_set_status(self->indicator, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
281 APP_INDICATOR_STATUS_ACTIVE); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
282 break; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
283 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
284 app_indicator_set_icon_full(self->indicator, icon_names[self->state], |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
285 title); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
286 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
287 /* notification */ |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
288 switch (self->state) { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
289 case PUI_STATE_INITIAL: /* FALLTHGROUGH */ |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
290 case PUI_STATE_UP_TO_DATE: /* FALLTHGROUGH */ |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
291 case PUI_STATE_ERROR: |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
292 /* withdraw exisiting notification */ |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
293 g_application_withdraw_notification(application, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
294 "package-updates"); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
295 break; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
296 case PUI_STATE_NORMAL_UPDATES_AVAILABLE: /* FALLTHGROUGH */ |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
297 case PUI_STATE_IMPORTANT_UPDATES_AVAILABLE: |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
298 /* create notification */ |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
299 notification = g_notification_new(title); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
300 g_notification_set_body(notification, body); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
301 g_notification_set_icon(notification, self->icons[self->state]); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
302 g_notification_set_priority(notification, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
303 G_NOTIFICATION_PRIORITY_NORMAL); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
304 if (g_action_get_enabled(G_ACTION(install_updates_action))) { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
305 g_notification_add_button(notification, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
306 _("Install Updates"), |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
307 "app.install-updates"); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
308 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
309 g_application_send_notification(application, "package-updates", |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
310 notification); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
311 break; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
312 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
313 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
314 if (notification != NULL) { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
315 g_object_unref(notification); |
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 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
318 g_debug("indicator icon: %s, notification title: \"%s\", " |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
319 "notification body: \"%s\"", icon_names[self->state], title, body); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
320 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
321 g_free(body); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
322 g_free(title); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
323 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
324 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
325 static void |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
326 transition_state(PuiApplication *self) |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
327 { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
328 PuiState state = self->state; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
329 guint important_updates; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
330 guint normal_updates; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
331 gchar *old_state; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
332 gchar *new_state; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
333 |
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: /* FALLTHROUGH */ |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
336 case PUI_STATE_UP_TO_DATE: /* FALLTHROUGH */ |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
337 case PUI_STATE_NORMAL_UPDATES_AVAILABLE: /* FALLTHROUGH */ |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
338 case PUI_STATE_IMPORTANT_UPDATES_AVAILABLE: |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
339 if (self->error_message != NULL) { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
340 state = PUI_STATE_ERROR; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
341 break; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
342 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
343 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
344 g_object_get(self->backend, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
345 "important-updates", &important_updates, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
346 "normal-updates", &normal_updates, NULL); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
347 if (important_updates > 0) { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
348 state = PUI_STATE_IMPORTANT_UPDATES_AVAILABLE; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
349 } else if (normal_updates > 0) { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
350 state = PUI_STATE_NORMAL_UPDATES_AVAILABLE; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
351 } else { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
352 state = PUI_STATE_UP_TO_DATE; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
353 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
354 break; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
355 case PUI_STATE_ERROR: |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
356 break; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
357 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
358 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
359 if (state != self->state) { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
360 old_state = pui_types_enum_to_string(PUI_TYPE_STATE, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
361 self->state); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
362 new_state = pui_types_enum_to_string(PUI_TYPE_STATE, state); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
363 g_debug("state %s -> %s", old_state, new_state); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
364 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
365 self->state = state; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
366 update_ui(self); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
367 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
368 g_free(new_state); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
369 g_free(old_state); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
370 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
371 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
372 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
373 static void |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
374 on_backend_restart_required(PuiBackend *backend, gpointer user_data) |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
375 { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
376 PuiApplication *self = user_data; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
377 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
378 restart = TRUE; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
379 g_action_group_activate_action(G_ACTION_GROUP(G_APPLICATION(self)), |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
380 "quit", NULL); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
381 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
382 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
383 static void |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
384 on_backend_state_changed(PuiBackend *backend, gpointer user_data) |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
385 { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
386 PuiApplication *self = user_data; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
387 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
388 transition_state(self); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
389 } |
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 static void |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
392 on_pui_backend_finished(GObject *source_object, GAsyncResult *result, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
393 gpointer user_data) |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
394 { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
395 PuiApplication *self = user_data; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
396 GError *error = NULL; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
397 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
398 self->backend = pui_backend_new_finish(result, &error); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
399 if (self->backend == NULL) { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
400 g_warning("failed to instantiate backend: %s", error->message); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
401 g_free(self->error_message); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
402 g_error_free(error); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
403 self->error_message = g_strdup(_("Update notifications " |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
404 "are not supported.")); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
405 transition_state(self); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
406 return; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
407 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
408 |
6
2477a6151087
Make PackagKit use the user's network proxies
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
4
diff
changeset
|
409 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
|
410 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
|
411 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
|
412 |
0
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
413 g_settings_bind(self->settings, "refresh-interval", self->backend, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
414 "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
|
415 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
|
416 "use-mobile-connection", G_SETTINGS_BIND_GET); |
0
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
417 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
418 transition_state(self); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
419 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
420 g_signal_connect(self->backend, "restart-required", |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
421 G_CALLBACK(on_backend_restart_required), self); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
422 g_signal_connect(self->backend, "state-changed", |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
423 G_CALLBACK(on_backend_state_changed), self); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
424 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
425 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
426 static void |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
427 pui_application_startup(GApplication *application) |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
428 { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
429 PuiApplication *self = PUI_APPLICATION(application); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
430 gsize i; |
2
7172a0db97af
Use GtkBuilder for all widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
1
diff
changeset
|
431 GtkBuilder *builder; |
0
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
432 GtkWidget *menu; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
433 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
434 G_APPLICATION_CLASS(pui_application_parent_class)->startup(application); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
435 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
436 /* create actions */ |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
437 g_action_map_add_action_entries(G_ACTION_MAP(self), |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
438 pui_application_actions, G_N_ELEMENTS(pui_application_actions), |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
439 self); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
440 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
441 /* load icons */ |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
442 for (i = 0; i < G_N_ELEMENTS(self->icons); i++) { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
443 self->icons[i] = g_themed_icon_new(icon_names[i]); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
444 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
445 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
446 /* create settings */ |
1
2f04ec9e0506
Add preferences application
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
0
diff
changeset
|
447 self->settings = pui_settings_new(); |
0
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
448 g_settings_bind(self->settings, "update-command", self, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
449 "update-command", G_SETTINGS_BIND_GET); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
450 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
451 /* start instantiating backend */ |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
452 pui_backend_new_async(self->cancellable, on_pui_backend_finished, self); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
453 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
454 /* create indicator */ |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
455 self->indicator = app_indicator_new(APPLICATION_ID, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
456 "system-software-update", |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
457 APP_INDICATOR_CATEGORY_APPLICATION_STATUS); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
458 |
2
7172a0db97af
Use GtkBuilder for all widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
1
diff
changeset
|
459 /* 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
|
460 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
|
461 "package-update-indicator/pui-menu.ui"); |
7172a0db97af
Use GtkBuilder for all widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
1
diff
changeset
|
462 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
|
463 gtk_widget_insert_action_group(menu, "app", G_ACTION_GROUP(self)); |
0
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
464 gtk_widget_show_all(menu); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
465 app_indicator_set_menu(self->indicator, GTK_MENU(menu)); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
466 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
467 update_ui(self); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
468 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
469 /* keep GApplication running */ |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
470 g_application_hold(application); |
2
7172a0db97af
Use GtkBuilder for all widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
1
diff
changeset
|
471 |
7172a0db97af
Use GtkBuilder for all widgets
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
1
diff
changeset
|
472 g_object_unref(builder); |
0
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 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
475 static void |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
476 pui_application_shutdown(GApplication *application) |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
477 { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
478 GApplicationClass *application_class = |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
479 G_APPLICATION_CLASS(pui_application_parent_class); |
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 application_class->shutdown(application); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
482 } |
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 static gint |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
485 pui_application_handle_local_options(GApplication *application, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
486 GVariantDict *options) |
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 gchar *messages_debug; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
489 gchar **args = NULL; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
490 GError *error = NULL; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
491 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
492 /* filename arguments are not allowed */ |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
493 if (g_variant_dict_lookup(options, G_OPTION_REMAINING, "^a&ay", |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
494 &args)) { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
495 g_printerr("invalid argument: \"%s\"\n", args[0]); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
496 g_free(args); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
497 return (1); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
498 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
499 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
500 if (g_variant_dict_contains(options, "version")) { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
501 g_print("%s %s\n", PACKAGE, VERSION); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
502 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
503 /* quit */ |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
504 return (0); |
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 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
507 if (g_variant_dict_contains(options, "debug")) { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
508 /* enable debug logging */ |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
509 messages_debug = g_strjoin(":", G_LOG_DOMAIN, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
510 g_getenv("G_MESSAGES_DEBUG"), NULL); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
511 g_setenv("G_MESSAGES_DEBUG", messages_debug, TRUE); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
512 g_free(messages_debug); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
513 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
514 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
515 /* |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
516 * register with the session bus so that it is possible to discern |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
517 * between remote and primary instance and that remote actions can be |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
518 * invoked, this causes the startup signal to be emitted which, in case |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
519 * of the primary instance, starts to instantiate the |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
520 * backend with the given values |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
521 */ |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
522 if (!g_application_register(application, NULL, &error)) { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
523 g_critical("g_application_register: %s", error->message); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
524 g_error_free(error); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
525 return (1); |
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 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
528 if (g_variant_dict_contains(options, "quit")) { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
529 /* only valid if a remote instance is running */ |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
530 if (!g_application_get_is_remote(application)) { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
531 g_printerr("%s is not running\n", g_get_prgname()); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
532 return (1); |
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 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
535 /* signal remote instance to quit */ |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
536 g_action_group_activate_action(G_ACTION_GROUP(application), |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
537 "quit", NULL); |
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 /* quit local instance */ |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
540 return (0); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
541 } |
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 /* proceed with default command line processing */ |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
544 return (-1); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
545 } |
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 static void |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
548 pui_application_activate(GApplication *application) { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
549 GApplicationClass *application_class = |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
550 G_APPLICATION_CLASS(pui_application_parent_class); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
551 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
552 /* do nothing, implementation required by GApplication */ |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
553 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
554 application_class->activate(application); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
555 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
556 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
557 static void |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
558 pui_application_set_property(GObject *object, guint property_id, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
559 const GValue *value, GParamSpec *pspec) |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
560 { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
561 PuiApplication *self = PUI_APPLICATION(object); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
562 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
563 switch (property_id) { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
564 case PROP_UPDATE_COMMAND: |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
565 g_free(self->update_command); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
566 self->update_command = g_value_dup_string(value); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
567 g_debug("property \"update-command\" set to \"%s\"", |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
568 self->update_command); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
569 break; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
570 default: |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
571 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
572 break; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
573 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
574 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
575 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
576 static void |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
577 pui_application_get_property(GObject *object, guint property_id, GValue *value, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
578 GParamSpec *pspec) |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
579 { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
580 PuiApplication *self = PUI_APPLICATION(object); |
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 switch (property_id) { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
583 case PROP_UPDATE_COMMAND: |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
584 g_value_set_string(value, self->update_command); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
585 break; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
586 default: |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
587 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
588 break; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
589 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
590 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
591 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
592 static void |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
593 pui_application_dispose(GObject *object) |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
594 { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
595 PuiApplication *self = PUI_APPLICATION(object); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
596 gsize i; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
597 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
598 if (self->settings != NULL) { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
599 g_signal_handlers_disconnect_by_data(self->settings, self); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
600 g_clear_object(&self->settings); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
601 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
602 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
603 if (self->cancellable != NULL) { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
604 g_cancellable_cancel(self->cancellable); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
605 g_clear_object(&self->cancellable); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
606 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
607 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
608 if (self->backend != NULL) { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
609 g_clear_object(&self->backend); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
610 } |
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 if (self->indicator != NULL) { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
613 g_clear_object(&self->indicator); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
614 } |
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 if (self->about_dialog != NULL) { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
617 g_clear_pointer(&self->about_dialog, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
618 (GDestroyNotify)(gtk_widget_destroy)); |
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 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
621 for (i = 0; i < G_N_ELEMENTS(self->icons); i++) { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
622 if (self->icons[i] != NULL) { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
623 g_clear_object(&self->icons[i]); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
624 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
625 } |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
626 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
627 G_OBJECT_CLASS(pui_application_parent_class)->dispose(object); |
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 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
630 static void |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
631 pui_application_finalize(GObject *object) |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
632 { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
633 PuiApplication *self = PUI_APPLICATION(object); |
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 g_free(self->update_command); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
636 g_free(self->error_message); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
637 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
638 G_OBJECT_CLASS(pui_application_parent_class)->finalize(object); |
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 static void |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
642 pui_application_class_init(PuiApplicationClass *klass) |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
643 { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
644 GObjectClass *object_class = G_OBJECT_CLASS(klass); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
645 GApplicationClass *application_class = G_APPLICATION_CLASS(klass); |
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 object_class->set_property = pui_application_set_property; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
648 object_class->get_property = pui_application_get_property; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
649 object_class->dispose = pui_application_dispose; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
650 object_class->finalize = pui_application_finalize; |
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 properties[PROP_UPDATE_COMMAND] = g_param_spec_string("update-command", |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
653 "Update command", "Command for installing updates", NULL, |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
654 G_PARAM_READWRITE); |
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 g_object_class_install_properties(object_class, PROP_LAST, properties); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
657 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
658 application_class->startup = pui_application_startup; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
659 application_class->shutdown = pui_application_shutdown; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
660 application_class->handle_local_options = |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
661 pui_application_handle_local_options; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
662 application_class->activate = pui_application_activate; |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
663 } |
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 static void |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
666 pui_application_init(PuiApplication *self) |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
667 { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
668 g_application_add_main_option_entries(G_APPLICATION(self), |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
669 cmd_options); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
670 |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
671 self->cancellable = g_cancellable_new(); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
672 } |
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 * |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
675 pui_application_new(void) |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
676 { |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
677 return (g_object_new(PUI_TYPE_APPLICATION, "application-id", |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
678 APPLICATION_ID, NULL)); |
6884bb8130ca
Initial revision
Guido Berhoerster <guido+pui@berhoerster.name>
parents:
diff
changeset
|
679 } |