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 |
// now show a notification handle
|
628
by Martin Pitt
Port to current libnotify 0.7 API. Bump libnotify-dev build dependency. |
93 |
n = notify_notification_new( |
329
by Michael Vogt
* use GtkStatusIcon instead of EggTrayIcon, that makes |
94 |
_("Crash report detected"), |
301
by Jonathan Riddell
Fix grammer, A application -> An Application |
95 |
_("An application has crashed on your " |
248
by Michael Vogt
* src/crash.{c,h}: |
96 |
"system (now or in the past). "
|
97 |
"Click on the notification icon to "
|
|
98 |
"display details. "
|
|
99 |
),
|
|
628
by Martin Pitt
Port to current libnotify 0.7 API. Bump libnotify-dev build dependency. |
100 |
GTK_STOCK_DIALOG_INFO); |
101 |
notify_notification_set_timeout (n, 60000); |
|
102 |
notify_notification_show (n, NULL); |
|
248
by Michael Vogt
* src/crash.{c,h}: |
103 |
|
628
by Martin Pitt
Port to current libnotify 0.7 API. Bump libnotify-dev build dependency. |
104 |
return FALSE; |
248
by Michael Vogt
* src/crash.{c,h}: |
105 |
}
|
106 |
||
262
by Michael Vogt
* src/crash.c: |
107 |
static void |
108 |
hide_crash_applet(TrayApplet *ta) |
|
109 |
{
|
|
110 |
NotifyNotification *n; |
|
111 |
||
329
by Michael Vogt
* use GtkStatusIcon instead of EggTrayIcon, that makes |
112 |
gtk_status_icon_set_visible(ta->tray_icon, FALSE); |
262
by Michael Vogt
* src/crash.c: |
113 |
|
114 |
/* Hide any notification popup */
|
|
115 |
n = g_object_get_data (G_OBJECT(ta->tray_icon), "notification"); |
|
116 |
if (n) |
|
117 |
notify_notification_close (n, NULL); |
|
118 |
g_object_set_data (G_OBJECT(ta->tray_icon), "notification", NULL); |
|
119 |
}
|
|
120 |
||
248
by Michael Vogt
* src/crash.{c,h}: |
121 |
gboolean
|
122 |
crashreport_check (TrayApplet *ta) |
|
123 |
{
|
|
124 |
int crashreports_found = 0; |
|
253
by Michael Vogt
* improved the crash report handling: |
125 |
static gboolean first_run = TRUE; |
282
by Martin Pitt
* src/crash.c: Only show a notification for system crash reports, do not |
126 |
gboolean system_crashes; |
608
by Michael Vogt
* src/crash.c: |
127 |
g_debug("crashreport_check\n"); |
611
by Michael Vogt
honor the /apps/update-notifier/auto_launch gconf key, if that is |
128 |
|
257
by Michael Vogt
* debian/control: |
129 |
// don't do anything if no apport-gtk is installed
|
130 |
if(!g_file_test(CRASHREPORT_REPORT_APP, G_FILE_TEST_IS_EXECUTABLE)) |
|
254
by Michael Vogt
* src/crash.c, src/hooks.c: |
131 |
return FALSE; |
248
by Michael Vogt
* src/crash.{c,h}: |
132 |
|
311
by Martin Pitt
* src/crash.c: Do not show apport crash reports if above gconf key is false. |
133 |
// Check whether the user doesn't want notifications
|
134 |
if (!gconf_client_get_bool ((GConfClient*) ta->user_data, |
|
135 |
GCONF_KEY_APPORT_NOTIFICATIONS, NULL)) { |
|
607
by Michael Vogt
merged from seb128, modified slightly to make the unity special case more obvious |
136 |
g_debug("apport notifications disabled in gconf, not displaying crashes"); |
137 |
return FALSE; |
|
311
by Martin Pitt
* src/crash.c: Do not show apport crash reports if above gconf key is false. |
138 |
}
|
139 |
||
257
by Michael Vogt
* debian/control: |
140 |
// check for (new) reports by calling CRASHREPORT_HELPER
|
141 |
// and checking the return code
|
|
142 |
int exitcode; |
|
608
by Michael Vogt
* src/crash.c: |
143 |
gchar *argv[] = { CRASHREPORT_HELPER, NULL }; |
144 |
if(!g_spawn_sync(NULL, |
|
145 |
argv, |
|
146 |
NULL, |
|
147 |
G_SPAWN_STDOUT_TO_DEV_NULL|G_SPAWN_STDERR_TO_DEV_NULL, |
|
148 |
NULL, |
|
149 |
NULL, |
|
150 |
NULL, |
|
151 |
NULL, |
|
152 |
&exitcode, |
|
153 |
NULL)) { |
|
257
by Michael Vogt
* debian/control: |
154 |
g_warning("Can not run %s\n", CRASHREPORT_HELPER); |
155 |
return FALSE; |
|
248
by Michael Vogt
* src/crash.{c,h}: |
156 |
}
|
257
by Michael Vogt
* debian/control: |
157 |
// exitcode == 0: repots found, else no reports
|
282
by Martin Pitt
* src/crash.c: Only show a notification for system crash reports, do not |
158 |
system_crashes = check_system_crashes(); |
159 |
crashreports_found = !exitcode || system_crashes; |
|
248
by Michael Vogt
* src/crash.{c,h}: |
160 |
|
611
by Michael Vogt
honor the /apps/update-notifier/auto_launch gconf key, if that is |
161 |
// in autolaunch mode, just open windows,
|
162 |
gboolean autolaunch = gconf_client_get_bool((GConfClient*) ta->user_data, |
|
163 |
GCONF_KEY_AUTO_LAUNCH, NULL); |
|
164 |
if (autolaunch) { |
|
165 |
if (crashreports_found > 0) { |
|
166 |
g_debug("autolaunch mode, just running apport now"); |
|
167 |
crashreports_found=0; |
|
168 |
run_apport(ta); |
|
169 |
return TRUE; |
|
170 |
} else |
|
171 |
return FALSE; |
|
172 |
}
|
|
173 |
||
174 |
// 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 |
175 |
gboolean visible = gtk_status_icon_get_visible(ta->tray_icon); |
176 |
||
611
by Michael Vogt
honor the /apps/update-notifier/auto_launch gconf key, if that is |
177 |
// crashreport found
|
178 |
if(crashreports_found > 0 && !visible) { |
|
329
by Michael Vogt
* use GtkStatusIcon instead of EggTrayIcon, that makes |
179 |
gtk_status_icon_set_tooltip(ta->tray_icon, |
180 |
_("Crash report detected")); |
|
181 |
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. |
182 |
/* Show the notification, after a delay so it doesn't look ugly
|
183 |
* if we've just logged in */
|
|
184 |
g_timeout_add(5000, (GSourceFunc)(show_notification), ta); |
|
253
by Michael Vogt
* improved the crash report handling: |
185 |
}
|
260
by Michael Vogt
* src/crash.c: |
186 |
|
253
by Michael Vogt
* improved the crash report handling: |
187 |
// no crashreports, but visible
|
260
by Michael Vogt
* src/crash.c: |
188 |
if((crashreports_found == 0) && visible) { |
262
by Michael Vogt
* src/crash.c: |
189 |
hide_crash_applet(ta); |
248
by Michael Vogt
* src/crash.{c,h}: |
190 |
}
|
191 |
||
253
by Michael Vogt
* improved the crash report handling: |
192 |
first_run = FALSE; |
248
by Michael Vogt
* src/crash.{c,h}: |
193 |
return TRUE; |
194 |
}
|
|
195 |
||
196 |
static gboolean |
|
197 |
button_release_cb (GtkWidget *widget, |
|
198 |
TrayApplet *ta) |
|
199 |
{
|
|
607
by Michael Vogt
merged from seb128, modified slightly to make the unity special case more obvious |
200 |
run_apport(ta); |
201 |
hide_crash_applet(ta); |
|
202 |
return TRUE; |
|
248
by Michael Vogt
* src/crash.{c,h}: |
203 |
}
|
204 |
||
610
by Michael Vogt
* src/crash.c: |
205 |
static gboolean |
206 |
crashreport_check_initially(TrayApplet *ta) |
|
207 |
{
|
|
208 |
crashreport_check(ta); |
|
209 |
// stop timeout handler
|
|
210 |
return FALSE; |
|
211 |
}
|
|
248
by Michael Vogt
* src/crash.{c,h}: |
212 |
|
213 |
void
|
|
214 |
crashreport_tray_icon_init (TrayApplet *ta) |
|
215 |
{
|
|
216 |
||
217 |
ta->user_data = gconf_client_get_default(); |
|
218 |
g_signal_connect (G_OBJECT(ta->tray_icon), |
|
329
by Michael Vogt
* use GtkStatusIcon instead of EggTrayIcon, that makes |
219 |
"activate", |
248
by Michael Vogt
* src/crash.{c,h}: |
220 |
G_CALLBACK (button_release_cb), |
221 |
ta); |
|
222 |
||
223 |
/* Check for crashes for the first time */
|
|
614
by Michael Vogt
src/crash.c: make -Wall clean |
224 |
g_timeout_add_seconds(1, (GSourceFunc)crashreport_check_initially, ta); |
248
by Michael Vogt
* src/crash.{c,h}: |
225 |
}
|