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

« back to all changes in this revision

Viewing changes to src/crash.c

  • Committer: Michael Vogt
  • Date: 2006-07-24 12:57:34 UTC
  • Revision ID: michael.vogt@ubuntu.com-20060724125734-4f91f51b166e4c1f
* src/crash.{c,h}:
  - basic crashreporting support added
* src/update-notifier.c:
  - added checking for crashreports in /var/crash

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 <glade/glade.h>
 
10
#include <libnotify/notify.h>
 
11
 
 
12
#include "update-notifier.h"
 
13
#include "update.h"
 
14
 
 
15
 
 
16
static gint
 
17
show_notification (TrayApplet *ta)
 
18
{
 
19
        NotifyNotification *n;
 
20
        int                 x, y;
 
21
 
 
22
        // only show once the icon is realy availabe
 
23
        if(!GTK_WIDGET_REALIZED(ta->tray_icon))
 
24
           return TRUE;
 
25
 
 
26
        /* Get the location of the icon.  If there's no location, come back
 
27
         * in a few seconds. */
 
28
        gdk_window_get_origin (GTK_WIDGET(ta->tray_icon)->window, &x, &y);
 
29
        if ((x <= 0) || (y <= 0))
 
30
                return TRUE;
 
31
 
 
32
        /* Check whether the icon is still visible, may have gone away */
 
33
        if (!GTK_WIDGET_VISIBLE (ta->tray_icon))
 
34
                return FALSE;
 
35
 
 
36
        /* Create and show the notification */
 
37
        n = notify_notification_new (_("Crashreport detected"),
 
38
                                     _("A application has crashed on your "
 
39
                                       "system (now or in the past). "
 
40
                                       "Click on the notification icon to "
 
41
                                       "display details. "
 
42
                                       ),
 
43
                                     GTK_STOCK_DIALOG_INFO,
 
44
                                     GTK_WIDGET(ta->tray_icon));
 
45
        notify_notification_set_timeout (n, 60000);
 
46
        notify_notification_show (n, NULL);
 
47
        g_object_set_data (G_OBJECT(ta->tray_icon), "notification", n);
 
48
 
 
49
        return FALSE;
 
50
}
 
51
 
 
52
gboolean
 
53
crashreport_check (TrayApplet *ta)
 
54
{
 
55
   NotifyNotification *n;
 
56
   GDir* dir;
 
57
   const gchar *crashreport;
 
58
   int crashreports_found = 0;
 
59
 
 
60
   g_debug("crashreport_check\n");
 
61
 
 
62
   // check for (new) reports
 
63
   dir=g_dir_open(CRASHREPORT_DIR, 0, NULL);
 
64
   if(dir == NULL)
 
65
      g_warning("can't read %s directory\n",HOOKS_DIR);
 
66
 
 
67
   g_debug("reading '%s' dir", CRASHREPORT_DIR);
 
68
   while((crashreport=g_dir_read_name(dir)) != NULL) {
 
69
      g_debug("investigating file '%s' ", crashreport); 
 
70
      crashreports_found++;
 
71
   }
 
72
   g_dir_close(dir);
 
73
 
 
74
 
 
75
   // act
 
76
   if(crashreports_found) {
 
77
      if (GTK_WIDGET_VISIBLE(GTK_WIDGET(ta->tray_icon)))
 
78
         return TRUE;
 
79
      
 
80
      gtk_tooltips_set_tip (GTK_TOOLTIPS(ta->tooltip),
 
81
                            GTK_WIDGET (ta->eventbox),
 
82
                            _("Crashreport detected"),
 
83
                            _("Click on the notification icon to "
 
84
                              "display details. "));
 
85
 
 
86
        gtk_widget_show (GTK_WIDGET(ta->tray_icon));
 
87
 
 
88
        /* Check whether the user doesn't like notifications */
 
89
        if (gconf_client_get_bool ((GConfClient*) ta->user_data,
 
90
                                   GCONF_KEY_NO_UPDATE_NOTIFICATIONS, NULL))
 
91
                return TRUE;
 
92
 
 
93
        /* Show the notification, after a delay so it doesn't look ugly
 
94
         * if we've just logged in */
 
95
        g_timeout_add(5000, (GSourceFunc)(show_notification), ta);
 
96
 
 
97
   } else {
 
98
      gtk_widget_hide (GTK_WIDGET(ta->tray_icon));
 
99
      gtk_widget_unrealize (GTK_WIDGET(ta->tray_icon));
 
100
 
 
101
      /* Hide any notification popup */
 
102
      n = g_object_get_data (G_OBJECT(ta->tray_icon), "notification");
 
103
      if (n)
 
104
         notify_notification_close (n, NULL);
 
105
      g_object_set_data (G_OBJECT(ta->tray_icon), "notification", NULL);
 
106
   }
 
107
 
 
108
   return TRUE;
 
109
}
 
110
 
 
111
 
 
112
static gboolean
 
113
button_release_cb (GtkWidget *widget,
 
114
                   GdkEventButton *event,
 
115
                   TrayApplet *ta)
 
116
{
 
117
        if ((event->button == 1) && (event->type == GDK_BUTTON_RELEASE)) {
 
118
                // fire up the crashreport tool
 
119
                g_debug("fire up the crashreport tool\n");
 
120
                g_spawn_command_line_async("/usr/bin/bug-reporting-tool",
 
121
                                           NULL);
 
122
        }
 
123
 
 
124
        return TRUE;
 
125
}
 
126
 
 
127
 
 
128
void
 
129
crashreport_tray_icon_init (TrayApplet *ta)
 
130
{
 
131
        GtkWidget *widget;
 
132
 
 
133
        ta->user_data = gconf_client_get_default();
 
134
        g_signal_connect (G_OBJECT(ta->tray_icon),
 
135
                          "button-release-event",
 
136
                          G_CALLBACK (button_release_cb),
 
137
                          ta);
 
138
 
 
139
        /* Check for crashes for the first time */
 
140
        crashreport_check (ta);
 
141
}