~ubuntu-branches/ubuntu/jaunty/libnotify/jaunty

« back to all changes in this revision

Viewing changes to tests/test-image.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Vogt
  • Date: 2006-01-02 15:56:18 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060102155618-6sbpi0enbolsnng6
Tags: 0.3.0-0ubuntu1
* New upstream release
* works with new notify-daemon, contains a new (more gtk-ish) API

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
#define DBUS_API_SUBJECT_TO_CHANGE 1
35
35
 
36
36
#include <glib.h>
 
37
#include <gtk/gtk.h>
37
38
#include <dbus/dbus.h>
38
39
#include <dbus/dbus-glib.h>
39
40
#include <dbus/dbus-glib-lowlevel.h>
40
41
 
41
42
GMainLoop *loop;
42
 
NotifyHandle *n;
43
 
 
44
 
static void send(char *i, size_t rawlen, char *s, char *b)
45
 
{
46
 
        NotifyIcon *icon;
47
 
 
48
 
        if (rawlen > 0)
49
 
                icon = notify_icon_new_from_data(rawlen, i);
50
 
        else
51
 
                icon = notify_icon_new_from_uri(i);
52
 
 
53
 
        n = notify_send_notification(NULL, // replaces nothing
54
 
                                                                 NULL,
55
 
                                                                 NOTIFY_URGENCY_NORMAL,
56
 
                                                                 s, b,
57
 
                                                                 icon,
58
 
                                                                 TRUE, 0,
59
 
                                                                 NULL, // no hints
60
 
                                                                 NULL, // no user data
61
 
                                                                 0);
62
 
 
63
 
        if (!n) {
64
 
                fprintf(stderr, "failed to send notification\n");
65
 
                exit(1);
66
 
        }
67
 
 
68
 
        notify_icon_destroy(icon);      
69
 
}
70
 
 
71
 
int
72
 
main(int argc, char **argv)
73
 
{
74
 
        loop = g_main_loop_new(NULL, FALSE);
75
 
 
76
 
        if (!notify_glib_init("Images Test", NULL))
77
 
                exit(1);
78
 
 
79
 
        /*
80
 
         * These images exist on fedora core 2 workstation profile.
81
 
         * Might not on yours
82
 
         */
83
 
 
84
 
        send("gnome-starthere",
85
 
                 0,
86
 
                 "Welcome to Linux!",
87
 
                 "This is your first login. To begin exploring the system, click on 'Start Here', 'Computer' or 'Applications'");
88
 
 
89
 
        char file[1024];
90
 
        readlink("/proc/self/exe", file, sizeof(file));
91
 
        *strrchr(file, '/') = '\0';
92
 
        strcat(file, "/../applet-critical.png");
93
 
 
94
 
        printf("sending %s\n", file);
95
 
 
96
 
        send(file,
97
 
                 0,
98
 
                 "Alert!",
99
 
                 "Warning!");
100
 
 
101
 
 
102
 
        struct stat buf;
103
 
        if (stat(file, &buf) == -1)
104
 
        {
105
 
                fprintf(stderr, "could not stat %s: %s", file, strerror(errno));
106
 
                exit(1);
107
 
        }
108
 
 
109
 
        int fd = open(file, O_RDONLY);
110
 
 
111
 
        void *pngbase = mmap(NULL, buf.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
112
 
 
113
 
        close(fd);
114
 
 
115
 
        send(pngbase,
116
 
                 buf.st_size,
117
 
                 "Raw image test",
118
 
                 "This is an image marshalling test");
119
 
 
 
43
NotifyNotification *n;
 
44
 
 
45
int main(int argc, char *argv[]) {
 
46
        char file[PATH_MAX];
 
47
        int size;
 
48
        char *uri;
 
49
        GdkPixbuf *icon;
 
50
        gchar *buf;
 
51
        gsize buf_size;
 
52
        GtkWidget *helper;
 
53
 
 
54
        gtk_init (&argc, &argv);
 
55
 
 
56
        if (!notify_init("Images Test")) exit(1);
 
57
 
 
58
        n = notify_notification_new ("Icon Test", "Testing stock icon", "stock_help", NULL);
 
59
 
 
60
        notify_notification_set_hint_int32 (n, "x", 300);
 
61
        notify_notification_set_hint_int32 (n, "y", 24);
 
62
 
 
63
        notify_notification_set_timeout (n, NOTIFY_TIMEOUT_NEVER);
 
64
        if (!notify_notification_show (n, NULL)) {
 
65
                fprintf(stderr, "failed to send notification\n");
 
66
                return 1;
 
67
        }
 
68
 
 
69
        g_usleep (5000000); //5 seconds
 
70
 
 
71
        size = readlink("/proc/self/cwd", file, PATH_MAX - 1);
 
72
        file[size] = '\0';
 
73
        uri = g_strdup_printf ("file://%s/%s", file, "applet-critical.png");
 
74
 
 
75
        printf("sending %s\n", uri);
 
76
 
 
77
        notify_notification_update (n, "Alert!", "Testing URI icons", uri);
 
78
 
 
79
        if (!notify_notification_show (n, NULL)) {
 
80
                fprintf(stderr, "failed to send notification\n");
 
81
                return 1;
 
82
        }
 
83
 
 
84
        g_usleep (5000000); //5 seconds
 
85
 
 
86
        notify_notification_update (n, "Raw image test", "Testing sending raw pixbufs", NULL);
 
87
 
 
88
        /* This is just a hack to get a stock icon's pixbuf
 
89
           in a realworld app if you were sending bitmapped data
 
90
           you would know the file location and open it up with
 
91
           a method that could generate a bmp for you*/
 
92
        helper = gtk_button_new();
 
93
        icon = gtk_widget_render_icon (helper,
 
94
                                      GTK_STOCK_DIALOG_QUESTION,
 
95
                                      GTK_ICON_SIZE_DIALOG,
 
96
                                      "");
 
97
 
 
98
 
 
99
        notify_notification_set_icon_data_from_pixbuf (n, 
 
100
                                                       icon);
 
101
 
 
102
        if (!notify_notification_show (n, NULL)) {
 
103
                fprintf(stderr, "failed to send notification\n");
 
104
                return 1;
 
105
        }
 
106
 
 
107
 
 
108
        gtk_widget_destroy (helper);
 
109
        g_object_unref ((GObject *)icon);
 
110
 
 
111
        g_usleep (5000000); //5 seconds
120
112
        return 0;
121
113
}