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

« back to all changes in this revision

Viewing changes to src/crash.c

  • Committer: Michael Vogt
  • Date: 2011-01-04 11:28:17 UTC
  • Revision ID: michael.vogt@ubuntu.com-20110104112817-0ytbx3qdvhrfynh7
* src/crash.c:
  - add dialog when system crashes are detected to avoid fullscreen
    gksu window
  - fix incorrect bits from the previous merge (thanks to Sebastien Bacher)

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
   return exitcode == 0;
41
41
}
42
42
 
 
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 reporting the problem "
 
49
                    "now?");
 
50
   dialog = gtk_message_dialog_new (NULL,
 
51
                                    GTK_DIALOG_DESTROY_WITH_PARENT,
 
52
                                    GTK_MESSAGE_QUESTION,
 
53
                                    GTK_BUTTONS_NONE,
 
54
                                    msg);
 
55
   gtk_message_dialog_format_secondary_text(dialog, descr);
 
56
   gtk_dialog_add_button(dialog, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
 
57
   gtk_dialog_add_button(dialog, _("Report problem…"), GTK_RESPONSE_ACCEPT);
 
58
   int res = gtk_dialog_run(dialog);
 
59
   gtk_widget_destroy(dialog);
 
60
   if (res == GTK_RESPONSE_ACCEPT)
 
61
      return TRUE;
 
62
   return FALSE;
 
63
}
 
64
 
43
65
static gboolean 
44
66
run_apport(TrayApplet *ta)
45
67
{
46
68
   g_debug("fire up the crashreport tool\n");
47
69
   if (check_system_crashes()) {
48
 
       invoke_with_gksu(CRASHREPORT_REPORT_APP, 
49
 
        _("<span weight=\"bold\" size=\"larger\">Please enter your password to access problem reports of system programs</span>"),
50
 
        TRUE);
51
 
       return TRUE;
 
70
      // be nice and always ask first before firing up gksu with its fullscreen
 
71
      // window
 
72
      if (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
      }
 
77
      return TRUE;
52
78
   } else
53
 
       return g_spawn_command_line_async(CRASHREPORT_REPORT_APP, NULL);
 
79
      return g_spawn_command_line_async(CRASHREPORT_REPORT_APP, NULL);
54
80
}
55
81
 
56
82
static gboolean
143
169
 
144
170
   gboolean visible = gtk_status_icon_get_visible(ta->tray_icon);
145
171
 
146
 
   // special case for unity (and generally stuff that lacks a 
147
 
   // notification area, if the icon can not be embedded we just
148
 
   // fire up apport regardless (but skip if there are system 
149
 
   // crashes as this will result in gksu windows
150
 
   if (!gtk_status_icon_is_embedded (ta->tray_icon) && 
151
 
       crashreports_found > 0 && 
152
 
       !system_crashes) {
153
 
      g_debug("unity handler");
154
 
      crashreports_found=0;
155
 
      run_apport(ta);
156
 
      return TRUE;
157
 
   }
158
 
 
159
172
   // normal operation
160
173
 
161
174
   // crashreport found and first run: show notification bubble and
167
180
      /* Show the notification, after a delay so it doesn't look ugly
168
181
       * if we've just logged in */
169
182
      g_timeout_add(5000, (GSourceFunc)(show_notification), ta);
170
 
 
171
183
   }
172
184
   // crashreport found and already visible
173
185
   else if((crashreports_found > 0) && !(system_crashes || first_run)) {
181
193
      hide_crash_applet(ta);
182
194
   }
183
195
 
 
196
   // special case for unity (and generally stuff that lacks a 
 
197
   // notification area, if the icon can not be embedded we just
 
198
   // fire up apport regardless in-your-face
 
199
   // WARNING: this needs to be *after* the normal operation
 
200
   //          and the event loop needs to be flushed, otherwise
 
201
   //          gtk_status_icon_is_embedded() will return FALSE
 
202
   while (gtk_events_pending())
 
203
      gtk_main_iteration();
 
204
   if (!gtk_status_icon_is_embedded (ta->tray_icon) && 
 
205
       crashreports_found > 0) {
 
206
      g_debug("unity handler");
 
207
      crashreports_found=0;
 
208
      run_apport(ta);
 
209
      return TRUE;
 
210
   }
 
211
 
 
212
 
184
213
   first_run = FALSE;
185
214
   return TRUE;
186
215
}
194
223
   return TRUE;
195
224
}
196
225
 
 
226
static gboolean
 
227
crashreport_check_initially(TrayApplet *ta)
 
228
{
 
229
   crashreport_check(ta);
 
230
   // stop timeout handler
 
231
   return FALSE;
 
232
}
197
233
 
198
234
void
199
235
crashreport_tray_icon_init (TrayApplet *ta)
206
242
                          ta);
207
243
 
208
244
        /* Check for crashes for the first time */
209
 
        crashreport_check (ta);
 
245
        g_timeout_add_seconds(1, crashreport_check_initially, ta);
210
246
}