~ubuntu-core-dev/update-notifier/ubuntu

248 by Michael Vogt
* src/crash.{c,h}:
1
#ifdef HAVE_CONFIG_H
2
#include "config.h"
3
#endif
4
5
#include <sys/types.h>
6
#include <sys/stat.h>
7
#include <unistd.h>
8
9
#include <libnotify/notify.h>
10
11
#include "update-notifier.h"
12
#include "update.h"
13
279 by Michael Vogt
* src/update-notifier.{c,h}:
14
15
16
276.1.1 by martin at piware
* src/crash.c: If the user is an admin, also check for crashes of system
17
static gboolean
18
check_system_crashes() {
19
   int exitcode;
280 by Michael Vogt
* src/crash.c:
20
279 by Michael Vogt
* src/update-notifier.{c,h}:
21
   if(!in_admin_group())
22
      return FALSE;
276.1.1 by martin at piware
* src/crash.c: If the user is an admin, also check for crashes of system
23
24
   // check for system crashes
608 by Michael Vogt
* src/crash.c:
25
   gchar *argv[] = { CRASHREPORT_HELPER, "--system", NULL };
26
   if(!g_spawn_sync(NULL,
27
                    argv,
28
                    NULL,
29
                    G_SPAWN_STDOUT_TO_DEV_NULL|G_SPAWN_STDERR_TO_DEV_NULL,
30
                    NULL,
31
                    NULL,
32
                    NULL,
33
                    NULL,
34
                    &exitcode,
35
                    NULL)) {
276.1.1 by martin at piware
* src/crash.c: If the user is an admin, also check for crashes of system
36
      g_warning("Can not run %s\n", CRASHREPORT_HELPER);
37
      return FALSE;
38
   }
39
40
   return exitcode == 0;
41
}
42
610 by Michael Vogt
* src/crash.c:
43
static gboolean
44
ask_invoke_apport_with_gksu()
45
{
46
   GtkDialog *dialog;
47
   gchar *msg = _("System program problem detected");
613 by Michael Vogt
src/crash.c: fix typo (thanks to seb128)
48
   gchar *descr = _("Do you want to report the problem "
610 by Michael Vogt
* src/crash.c:
49
                    "now?");
614 by Michael Vogt
src/crash.c: make -Wall clean
50
   dialog = (GtkDialog*)gtk_message_dialog_new (NULL,
610 by Michael Vogt
* src/crash.c:
51
                                    GTK_DIALOG_DESTROY_WITH_PARENT,
52
                                    GTK_MESSAGE_QUESTION,
53
                                    GTK_BUTTONS_NONE,
614 by Michael Vogt
src/crash.c: make -Wall clean
54
                                    "%s", msg);
55
   gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),
56
                                            "%s", descr);
610 by Michael Vogt
* src/crash.c:
57
   gtk_dialog_add_button(dialog, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
58
   gtk_dialog_add_button(dialog, _("Report problem…"), GTK_RESPONSE_ACCEPT);
59
   int res = gtk_dialog_run(dialog);
614 by Michael Vogt
src/crash.c: make -Wall clean
60
   gtk_widget_destroy(GTK_WIDGET(dialog));
610 by Michael Vogt
* src/crash.c:
61
   if (res == GTK_RESPONSE_ACCEPT)
62
      return TRUE;
63
   return FALSE;
64
}
65
253 by Michael Vogt
* improved the crash report handling:
66
static gboolean 
262 by Michael Vogt
* src/crash.c:
67
run_apport(TrayApplet *ta)
253 by Michael Vogt
* improved the crash report handling:
68
{
607 by Michael Vogt
merged from seb128, modified slightly to make the unity special case more obvious
69
   g_debug("fire up the crashreport tool\n");
612 by Michael Vogt
src/crash.c: still run apport (just without gksu) if the user declines to report the system crashes
70
   // be nice and always ask first before firing up gksu with its fullscreen
71
   // window
72
   if (check_system_crashes() && ask_invoke_apport_with_gksu()) {
73
      invoke_with_gksu(CRASHREPORT_REPORT_APP, 
74
                              _("<span weight=\"bold\" size=\"larger\">Please enter your password to access problem reports of system programs</span>"),
75
                              TRUE);
76
   } else {
610 by Michael Vogt
* src/crash.c:
77
      return g_spawn_command_line_async(CRASHREPORT_REPORT_APP, NULL);
612 by Michael Vogt
src/crash.c: still run apport (just without gksu) if the user declines to report the system crashes
78
   }
79
   return TRUE;
253 by Michael Vogt
* improved the crash report handling:
80
}
248 by Michael Vogt
* src/crash.{c,h}:
81
334 by Michael Vogt
* fix crash in leftover from pre-GtkStatusIcon code (LP: #127965)
82
static gboolean
248 by Michael Vogt
* src/crash.{c,h}:
83
show_notification (TrayApplet *ta)
84
{
329 by Michael Vogt
* use GtkStatusIcon instead of EggTrayIcon, that makes
85
   NotifyNotification *n;
86
365 by Michael Vogt
* src/update.c, src/crash.c, src/hooks.c:
87
   // check if the update-icon is still visible (in the delay time a 
88
   // update may already have been performed)
89
   if(!gtk_status_icon_get_visible(ta->tray_icon))
90
      return FALSE;
91
329 by Michael Vogt
* use GtkStatusIcon instead of EggTrayIcon, that makes
92
   GdkRectangle area;
93
   gtk_status_icon_get_geometry(ta->tray_icon, NULL, &area, NULL);
94
95
   // no usefull coordiante yet, do another timeout
96
   if(area.x <= 0 || area.y <= 0 || area.width <= 0 || area.height <= 0)
97
      return TRUE;
98
99
   // now show a notification handle 
100
   n = notify_notification_new_with_status_icon(
101
				     _("Crash report detected"),
301 by Jonathan Riddell
Fix grammer, A application -> An Application
102
				     _("An application has crashed on your "
248 by Michael Vogt
* src/crash.{c,h}:
103
				       "system (now or in the past). "
104
				       "Click on the notification icon to "
105
				       "display details. "
106
				       ),
107
				     GTK_STOCK_DIALOG_INFO,
329 by Michael Vogt
* use GtkStatusIcon instead of EggTrayIcon, that makes
108
				     ta->tray_icon);
248 by Michael Vogt
* src/crash.{c,h}:
109
	notify_notification_set_timeout (n, 60000);
110
	notify_notification_show (n, NULL);
111
	g_object_set_data (G_OBJECT(ta->tray_icon), "notification", n);
112
113
	return FALSE;
114
}
115
262 by Michael Vogt
* src/crash.c:
116
static void 
117
hide_crash_applet(TrayApplet *ta)
118
{
119
   NotifyNotification *n;
120
 
329 by Michael Vogt
* use GtkStatusIcon instead of EggTrayIcon, that makes
121
   gtk_status_icon_set_visible(ta->tray_icon, FALSE);
262 by Michael Vogt
* src/crash.c:
122
   
123
   /* Hide any notification popup */
124
   n = g_object_get_data (G_OBJECT(ta->tray_icon), "notification");
125
   if (n)
126
      notify_notification_close (n, NULL);
127
   g_object_set_data (G_OBJECT(ta->tray_icon), "notification", NULL);
128
}
129
248 by Michael Vogt
* src/crash.{c,h}:
130
gboolean
131
crashreport_check (TrayApplet *ta)
132
{
133
   int crashreports_found = 0;
253 by Michael Vogt
* improved the crash report handling:
134
   static gboolean first_run = TRUE;
282 by Martin Pitt
* src/crash.c: Only show a notification for system crash reports, do not
135
   gboolean system_crashes;
608 by Michael Vogt
* src/crash.c:
136
   g_debug("crashreport_check\n");
611 by Michael Vogt
honor the /apps/update-notifier/auto_launch gconf key, if that is
137
257 by Michael Vogt
* debian/control:
138
   // don't do anything if no apport-gtk is installed
139
   if(!g_file_test(CRASHREPORT_REPORT_APP, G_FILE_TEST_IS_EXECUTABLE))
254 by Michael Vogt
* src/crash.c, src/hooks.c:
140
      return FALSE;
248 by Michael Vogt
* src/crash.{c,h}:
141
311 by Martin Pitt
* src/crash.c: Do not show apport crash reports if above gconf key is false.
142
   // Check whether the user doesn't want notifications
143
   if (!gconf_client_get_bool ((GConfClient*) ta->user_data,
144
       GCONF_KEY_APPORT_NOTIFICATIONS, NULL)) {
607 by Michael Vogt
merged from seb128, modified slightly to make the unity special case more obvious
145
      g_debug("apport notifications disabled in gconf, not displaying crashes");
146
      return FALSE;
311 by Martin Pitt
* src/crash.c: Do not show apport crash reports if above gconf key is false.
147
   }
148
257 by Michael Vogt
* debian/control:
149
   // check for (new) reports by calling CRASHREPORT_HELPER
150
   // and checking the return code
151
   int exitcode;
608 by Michael Vogt
* src/crash.c:
152
   gchar *argv[] = { CRASHREPORT_HELPER, NULL };
153
   if(!g_spawn_sync(NULL,
154
                    argv,
155
                    NULL,
156
                    G_SPAWN_STDOUT_TO_DEV_NULL|G_SPAWN_STDERR_TO_DEV_NULL,
157
                    NULL,
158
                    NULL,
159
                    NULL,
160
                    NULL,
161
                    &exitcode,
162
                    NULL)) {
257 by Michael Vogt
* debian/control:
163
      g_warning("Can not run %s\n", CRASHREPORT_HELPER);
164
      return FALSE;
248 by Michael Vogt
* src/crash.{c,h}:
165
   }
257 by Michael Vogt
* debian/control:
166
   // exitcode == 0: repots found, else no reports
282 by Martin Pitt
* src/crash.c: Only show a notification for system crash reports, do not
167
   system_crashes = check_system_crashes();
168
   crashreports_found = !exitcode || system_crashes;
248 by Michael Vogt
* src/crash.{c,h}:
169
611 by Michael Vogt
honor the /apps/update-notifier/auto_launch gconf key, if that is
170
   // in autolaunch mode, just open windows, 
171
   gboolean autolaunch = gconf_client_get_bool((GConfClient*) ta->user_data,
172
                                               GCONF_KEY_AUTO_LAUNCH, NULL); 
173
   if (autolaunch) {
174
      if (crashreports_found > 0) {
175
         g_debug("autolaunch mode, just running apport now");
176
         crashreports_found=0;
177
         run_apport(ta);
178
         return TRUE;
179
      } else
180
         return FALSE;
181
   }
182
183
   // non-autolaunch will always use the notification area
607 by Michael Vogt
merged from seb128, modified slightly to make the unity special case more obvious
184
   gboolean visible = gtk_status_icon_get_visible(ta->tray_icon);
185
611 by Michael Vogt
honor the /apps/update-notifier/auto_launch gconf key, if that is
186
   // crashreport found 
187
   if(crashreports_found > 0 && !visible) {
329 by Michael Vogt
* use GtkStatusIcon instead of EggTrayIcon, that makes
188
      gtk_status_icon_set_tooltip(ta->tray_icon,
189
				  _("Crash report detected"));
190
      gtk_status_icon_set_visible(ta->tray_icon, TRUE);
311 by Martin Pitt
* src/crash.c: Do not show apport crash reports if above gconf key is false.
191
      /* Show the notification, after a delay so it doesn't look ugly
192
       * if we've just logged in */
193
      g_timeout_add(5000, (GSourceFunc)(show_notification), ta);
253 by Michael Vogt
* improved the crash report handling:
194
   }
260 by Michael Vogt
* src/crash.c:
195
253 by Michael Vogt
* improved the crash report handling:
196
   // no crashreports, but visible
260 by Michael Vogt
* src/crash.c:
197
   if((crashreports_found == 0) && visible) {
262 by Michael Vogt
* src/crash.c:
198
      hide_crash_applet(ta);
248 by Michael Vogt
* src/crash.{c,h}:
199
   }
200
253 by Michael Vogt
* improved the crash report handling:
201
   first_run = FALSE;
248 by Michael Vogt
* src/crash.{c,h}:
202
   return TRUE;
203
}
204
205
static gboolean
206
button_release_cb (GtkWidget *widget,
207
		   TrayApplet *ta)
208
{
607 by Michael Vogt
merged from seb128, modified slightly to make the unity special case more obvious
209
   run_apport(ta);
210
   hide_crash_applet(ta);
211
   return TRUE;
248 by Michael Vogt
* src/crash.{c,h}:
212
}
213
610 by Michael Vogt
* src/crash.c:
214
static gboolean
215
crashreport_check_initially(TrayApplet *ta)
216
{
217
   crashreport_check(ta);
218
   // stop timeout handler
219
   return FALSE;
220
}
248 by Michael Vogt
* src/crash.{c,h}:
221
222
void
223
crashreport_tray_icon_init (TrayApplet *ta)
224
{
225
226
	ta->user_data = gconf_client_get_default();
227
        g_signal_connect (G_OBJECT(ta->tray_icon),
329 by Michael Vogt
* use GtkStatusIcon instead of EggTrayIcon, that makes
228
			  "activate",
248 by Michael Vogt
* src/crash.{c,h}:
229
			  G_CALLBACK (button_release_cb),
230
			  ta);
231
232
	/* Check for crashes for the first time */
614 by Michael Vogt
src/crash.c: make -Wall clean
233
	g_timeout_add_seconds(1, (GSourceFunc)crashreport_check_initially, ta);
248 by Michael Vogt
* src/crash.{c,h}:
234
}