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

« back to all changes in this revision

Viewing changes to src/crash.c

  • Committer: Michael Vogt
  • Date: 2008-11-10 18:04:02 UTC
  • Revision ID: michael.vogt@ubuntu.com-20081110180402-lvolg0ct1xr4vqoi
* debian/update-notifier-common.install:
  - move apt-check, apt-cdrom-check and cdromdistupgrade
    into update-notifier-common

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
#include <sys/stat.h>
7
7
#include <unistd.h>
8
8
 
 
9
#include <glade/glade.h>
9
10
#include <libnotify/notify.h>
10
11
 
11
12
#include "update-notifier.h"
22
23
      return FALSE;
23
24
 
24
25
   // check for system crashes
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)) {
 
26
   if(!g_spawn_command_line_sync(CRASHREPORT_HELPER " --system", NULL, NULL, 
 
27
                                 &exitcode, NULL)) {
36
28
      g_warning("Can not run %s\n", CRASHREPORT_HELPER);
37
29
      return FALSE;
38
30
   }
40
32
   return exitcode == 0;
41
33
}
42
34
 
43
 
static gboolean
44
 
ask_invoke_apport_with_gksu()
45
 
{
46
 
   GtkDialog *dialog;
47
 
   gchar *msg = _("System program problem detected");
48
 
   gchar *descr = _("Do you want to report the problem "
49
 
                    "now?");
50
 
   dialog = (GtkDialog*)gtk_message_dialog_new (NULL,
51
 
                                    GTK_DIALOG_DESTROY_WITH_PARENT,
52
 
                                    GTK_MESSAGE_QUESTION,
53
 
                                    GTK_BUTTONS_NONE,
54
 
                                    "%s", msg);
55
 
   gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),
56
 
                                            "%s", descr);
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);
60
 
   gtk_widget_destroy(GTK_WIDGET(dialog));
61
 
   if (res == GTK_RESPONSE_ACCEPT)
62
 
      return TRUE;
63
 
   return FALSE;
64
 
}
65
 
 
66
35
static gboolean 
67
36
run_apport(TrayApplet *ta)
68
37
{
69
38
   g_debug("fire up the crashreport tool\n");
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 {
77
 
      return g_spawn_command_line_async(CRASHREPORT_REPORT_APP, NULL);
78
 
   }
79
 
   return TRUE;
 
39
   if (check_system_crashes()) {
 
40
       invoke_with_gksu(CRASHREPORT_REPORT_APP, 
 
41
        _("<span weight=\"bold\" size=\"larger\">Please enter your password to access problem reports of system programs</span>"),
 
42
        TRUE);
 
43
       return TRUE;
 
44
   } else
 
45
       return g_spawn_command_line_async(CRASHREPORT_REPORT_APP, NULL);
80
46
}
81
47
 
82
48
static gboolean
133
99
   int crashreports_found = 0;
134
100
   static gboolean first_run = TRUE;
135
101
   gboolean system_crashes;
 
102
 
136
103
   g_debug("crashreport_check\n");
137
104
 
138
105
   // don't do anything if no apport-gtk is installed
142
109
   // Check whether the user doesn't want notifications
143
110
   if (!gconf_client_get_bool ((GConfClient*) ta->user_data,
144
111
       GCONF_KEY_APPORT_NOTIFICATIONS, NULL)) {
145
 
      g_debug("apport notifications disabled in gconf, not displaying crashes");
146
 
      return FALSE;
 
112
       g_debug("apport notifications disabled in gconf, not displaying crashes");
 
113
       return FALSE;
147
114
   }
148
115
 
149
116
   // check for (new) reports by calling CRASHREPORT_HELPER
150
117
   // and checking the return code
151
118
   int exitcode;
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)) {
 
119
   if(!g_spawn_command_line_sync(CRASHREPORT_HELPER, NULL, NULL, 
 
120
                                 &exitcode, NULL)) {
163
121
      g_warning("Can not run %s\n", CRASHREPORT_HELPER);
164
122
      return FALSE;
165
123
   }
167
125
   system_crashes = check_system_crashes();
168
126
   crashreports_found = !exitcode || system_crashes;
169
127
 
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
 
128
   // crashreport found and first run: show notification bubble and
 
129
   // return
184
130
   gboolean visible = gtk_status_icon_get_visible(ta->tray_icon);
185
131
 
186
 
   // crashreport found 
187
 
   if(crashreports_found > 0 && !visible) {
 
132
   //   g_print("reports: %i, visible: %i\n",crashreports_found,visible);
 
133
 
 
134
   if((crashreports_found > 0) && (system_crashes || first_run)) {
188
135
      gtk_status_icon_set_tooltip(ta->tray_icon,
189
136
                                  _("Crash report detected"));
190
137
      gtk_status_icon_set_visible(ta->tray_icon, TRUE);
192
139
       * if we've just logged in */
193
140
      g_timeout_add(5000, (GSourceFunc)(show_notification), ta);
194
141
   }
 
142
   // crashreport found and already visible
 
143
   else if((crashreports_found > 0) && !(system_crashes || first_run)) {
 
144
      run_apport(ta);
 
145
      // if apport was run, we don't care anymore and hide the icon
 
146
      crashreports_found=0;
 
147
   }
195
148
 
196
149
   // no crashreports, but visible
197
150
   if((crashreports_found == 0) && visible) {
206
159
button_release_cb (GtkWidget *widget,
207
160
                   TrayApplet *ta)
208
161
{
209
 
   run_apport(ta);
210
 
   hide_crash_applet(ta);
211
 
   return TRUE;
 
162
run_apport(ta);
 
163
hide_crash_applet(ta);
 
164
        return TRUE;
212
165
}
213
166
 
214
 
static gboolean
215
 
crashreport_check_initially(TrayApplet *ta)
216
 
{
217
 
   crashreport_check(ta);
218
 
   // stop timeout handler
219
 
   return FALSE;
220
 
}
221
167
 
222
168
void
223
169
crashreport_tray_icon_init (TrayApplet *ta)
230
176
                          ta);
231
177
 
232
178
        /* Check for crashes for the first time */
233
 
        g_timeout_add_seconds(1, (GSourceFunc)crashreport_check_initially, ta);
 
179
        crashreport_check (ta);
234
180
}