~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
25
   if(!g_spawn_command_line_sync(CRASHREPORT_HELPER " --system", NULL, NULL, 
26
				 &exitcode, NULL)) {
27
      g_warning("Can not run %s\n", CRASHREPORT_HELPER);
28
      return FALSE;
29
   }
30
31
   return exitcode == 0;
32
}
33
253 by Michael Vogt
* improved the crash report handling:
34
static gboolean 
262 by Michael Vogt
* src/crash.c:
35
run_apport(TrayApplet *ta)
253 by Michael Vogt
* improved the crash report handling:
36
{
37
   g_debug("fire up the crashreport tool\n");
276.1.1 by martin at piware
* src/crash.c: If the user is an admin, also check for crashes of system
38
   if (check_system_crashes()) {
284 by Martin Pitt
* src/crash.c: Use a more meaningful message for gksu'ing to access system
39
       invoke_with_gksu(CRASHREPORT_REPORT_APP, 
40
	_("<span weight=\"bold\" size=\"larger\">Please enter your password to access problem reports of system programs</span>"),
41
	TRUE);
276.1.1 by martin at piware
* src/crash.c: If the user is an admin, also check for crashes of system
42
       return TRUE;
43
   } else
44
       return g_spawn_command_line_async(CRASHREPORT_REPORT_APP, NULL);
253 by Michael Vogt
* improved the crash report handling:
45
}
248 by Michael Vogt
* src/crash.{c,h}:
46
334 by Michael Vogt
* fix crash in leftover from pre-GtkStatusIcon code (LP: #127965)
47
static gboolean
248 by Michael Vogt
* src/crash.{c,h}:
48
show_notification (TrayApplet *ta)
49
{
329 by Michael Vogt
* use GtkStatusIcon instead of EggTrayIcon, that makes
50
   NotifyNotification *n;
51
365 by Michael Vogt
* src/update.c, src/crash.c, src/hooks.c:
52
   // check if the update-icon is still visible (in the delay time a 
53
   // update may already have been performed)
54
   if(!gtk_status_icon_get_visible(ta->tray_icon))
55
      return FALSE;
56
329 by Michael Vogt
* use GtkStatusIcon instead of EggTrayIcon, that makes
57
   GdkRectangle area;
58
   gtk_status_icon_get_geometry(ta->tray_icon, NULL, &area, NULL);
59
60
   // no usefull coordiante yet, do another timeout
61
   if(area.x <= 0 || area.y <= 0 || area.width <= 0 || area.height <= 0)
62
      return TRUE;
63
64
   // now show a notification handle 
65
   n = notify_notification_new_with_status_icon(
66
				     _("Crash report detected"),
301 by Jonathan Riddell
Fix grammer, A application -> An Application
67
				     _("An application has crashed on your "
248 by Michael Vogt
* src/crash.{c,h}:
68
				       "system (now or in the past). "
69
				       "Click on the notification icon to "
70
				       "display details. "
71
				       ),
72
				     GTK_STOCK_DIALOG_INFO,
329 by Michael Vogt
* use GtkStatusIcon instead of EggTrayIcon, that makes
73
				     ta->tray_icon);
248 by Michael Vogt
* src/crash.{c,h}:
74
	notify_notification_set_timeout (n, 60000);
75
	notify_notification_show (n, NULL);
76
	g_object_set_data (G_OBJECT(ta->tray_icon), "notification", n);
77
78
	return FALSE;
79
}
80
262 by Michael Vogt
* src/crash.c:
81
static void 
82
hide_crash_applet(TrayApplet *ta)
83
{
84
   NotifyNotification *n;
85
 
329 by Michael Vogt
* use GtkStatusIcon instead of EggTrayIcon, that makes
86
   gtk_status_icon_set_visible(ta->tray_icon, FALSE);
262 by Michael Vogt
* src/crash.c:
87
   
88
   /* Hide any notification popup */
89
   n = g_object_get_data (G_OBJECT(ta->tray_icon), "notification");
90
   if (n)
91
      notify_notification_close (n, NULL);
92
   g_object_set_data (G_OBJECT(ta->tray_icon), "notification", NULL);
93
}
94
248 by Michael Vogt
* src/crash.{c,h}:
95
gboolean
96
crashreport_check (TrayApplet *ta)
97
{
98
   int crashreports_found = 0;
253 by Michael Vogt
* improved the crash report handling:
99
   static gboolean first_run = TRUE;
282 by Martin Pitt
* src/crash.c: Only show a notification for system crash reports, do not
100
   gboolean system_crashes;
248 by Michael Vogt
* src/crash.{c,h}:
101
461 by Michael Vogt
remove some debug output
102
   //   g_debug("crashreport_check\n");
248 by Michael Vogt
* src/crash.{c,h}:
103
257 by Michael Vogt
* debian/control:
104
   // don't do anything if no apport-gtk is installed
105
   if(!g_file_test(CRASHREPORT_REPORT_APP, G_FILE_TEST_IS_EXECUTABLE))
254 by Michael Vogt
* src/crash.c, src/hooks.c:
106
      return FALSE;
248 by Michael Vogt
* src/crash.{c,h}:
107
311 by Martin Pitt
* src/crash.c: Do not show apport crash reports if above gconf key is false.
108
   // Check whether the user doesn't want notifications
109
   if (!gconf_client_get_bool ((GConfClient*) ta->user_data,
110
       GCONF_KEY_APPORT_NOTIFICATIONS, NULL)) {
312 by Martin Pitt
src/crash.c: demote g_warning to g_debug for disabled apport crashes
111
       g_debug("apport notifications disabled in gconf, not displaying crashes");
311 by Martin Pitt
* src/crash.c: Do not show apport crash reports if above gconf key is false.
112
       return FALSE;
113
   }
114
257 by Michael Vogt
* debian/control:
115
   // check for (new) reports by calling CRASHREPORT_HELPER
116
   // and checking the return code
117
   int exitcode;
118
   if(!g_spawn_command_line_sync(CRASHREPORT_HELPER, NULL, NULL, 
119
				 &exitcode, NULL)) {
120
      g_warning("Can not run %s\n", CRASHREPORT_HELPER);
121
      return FALSE;
248 by Michael Vogt
* src/crash.{c,h}:
122
   }
257 by Michael Vogt
* debian/control:
123
   // exitcode == 0: repots found, else no reports
282 by Martin Pitt
* src/crash.c: Only show a notification for system crash reports, do not
124
   system_crashes = check_system_crashes();
125
   crashreports_found = !exitcode || system_crashes;
248 by Michael Vogt
* src/crash.{c,h}:
126
253 by Michael Vogt
* improved the crash report handling:
127
   // crashreport found and first run: show notification bubble and
128
   // return
329 by Michael Vogt
* use GtkStatusIcon instead of EggTrayIcon, that makes
129
   gboolean visible = gtk_status_icon_get_visible(ta->tray_icon);
255 by Michael Vogt
* src/update-notifier.c:
130
131
   //   g_print("reports: %i, visible: %i\n",crashreports_found,visible);
132
282 by Martin Pitt
* src/crash.c: Only show a notification for system crash reports, do not
133
   if((crashreports_found > 0) && (system_crashes || first_run)) {
329 by Michael Vogt
* use GtkStatusIcon instead of EggTrayIcon, that makes
134
      gtk_status_icon_set_tooltip(ta->tray_icon,
135
				  _("Crash report detected"));
136
      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.
137
      /* Show the notification, after a delay so it doesn't look ugly
138
       * if we've just logged in */
139
      g_timeout_add(5000, (GSourceFunc)(show_notification), ta);
253 by Michael Vogt
* improved the crash report handling:
140
   }
141
   // crashreport found and already visible
282 by Martin Pitt
* src/crash.c: Only show a notification for system crash reports, do not
142
   else if((crashreports_found > 0) && !(system_crashes || first_run)) {
262 by Michael Vogt
* src/crash.c:
143
      run_apport(ta);
260 by Michael Vogt
* src/crash.c:
144
      // if apport was run, we don't care anymore and hide the icon
145
      crashreports_found=0;
253 by Michael Vogt
* improved the crash report handling:
146
   }
260 by Michael Vogt
* src/crash.c:
147
253 by Michael Vogt
* improved the crash report handling:
148
   // no crashreports, but visible
260 by Michael Vogt
* src/crash.c:
149
   if((crashreports_found == 0) && visible) {
262 by Michael Vogt
* src/crash.c:
150
      hide_crash_applet(ta);
248 by Michael Vogt
* src/crash.{c,h}:
151
   }
152
253 by Michael Vogt
* improved the crash report handling:
153
   first_run = FALSE;
248 by Michael Vogt
* src/crash.{c,h}:
154
   return TRUE;
155
}
156
157
static gboolean
158
button_release_cb (GtkWidget *widget,
159
		   TrayApplet *ta)
160
{
329 by Michael Vogt
* use GtkStatusIcon instead of EggTrayIcon, that makes
161
run_apport(ta);
162
hide_crash_applet(ta);
248 by Michael Vogt
* src/crash.{c,h}:
163
	return TRUE;
164
}
165
166
167
void
168
crashreport_tray_icon_init (TrayApplet *ta)
169
{
170
171
	ta->user_data = gconf_client_get_default();
172
        g_signal_connect (G_OBJECT(ta->tray_icon),
329 by Michael Vogt
* use GtkStatusIcon instead of EggTrayIcon, that makes
173
			  "activate",
248 by Michael Vogt
* src/crash.{c,h}:
174
			  G_CALLBACK (button_release_cb),
175
			  ta);
176
177
	/* Check for crashes for the first time */
178
	crashreport_check (ta);
179
}