| 1 |
/* |
|---|
| 2 |
* @file tests/test-image.c Unit test: images |
|---|
| 3 |
* |
|---|
| 4 |
* @Copyright(C) 2004 Mike Hearn <mike@navi.cx> |
|---|
| 5 |
* |
|---|
| 6 |
* This library is free software; you can redistribute it and/or |
|---|
| 7 |
* modify it under the terms of the GNU Lesser General Public |
|---|
| 8 |
* License as published by the Free Software Foundation; either |
|---|
| 9 |
* version 2.1 of the License, or(at your option) any later version. |
|---|
| 10 |
* |
|---|
| 11 |
* This library is distributed in the hope that it will be useful, |
|---|
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|---|
| 14 |
* Lesser General Public License for more details. |
|---|
| 15 |
* |
|---|
| 16 |
* You should have received a copy of the GNU Lesser General Public |
|---|
| 17 |
* License along with this library; if not, write to the |
|---|
| 18 |
* Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
|---|
| 19 |
* Boston, MA 02111-1307, USA. |
|---|
| 20 |
*/ |
|---|
| 21 |
|
|---|
| 22 |
#include <libnotify/notify.h> |
|---|
| 23 |
#include <stdio.h> |
|---|
| 24 |
#include <unistd.h> |
|---|
| 25 |
#include <stdlib.h> |
|---|
| 26 |
#include <assert.h> |
|---|
| 27 |
#include <string.h> |
|---|
| 28 |
#include <errno.h> |
|---|
| 29 |
#include <sys/mman.h> |
|---|
| 30 |
#include <sys/stat.h> |
|---|
| 31 |
#include <unistd.h> |
|---|
| 32 |
#include <fcntl.h> |
|---|
| 33 |
|
|---|
| 34 |
#define DBUS_API_SUBJECT_TO_CHANGE |
|---|
| 35 |
|
|---|
| 36 |
#include <glib.h> |
|---|
| 37 |
#include <gtk/gtk.h> |
|---|
| 38 |
#include <dbus/dbus.h> |
|---|
| 39 |
#include <dbus/dbus-glib.h> |
|---|
| 40 |
#include <dbus/dbus-glib-lowlevel.h> |
|---|
| 41 |
|
|---|
| 42 |
GMainLoop *loop; |
|---|
| 43 |
NotifyNotification *n; |
|---|
| 44 |
|
|---|
| 45 |
int |
|---|
| 46 |
main(int argc, char *argv[]) |
|---|
| 47 |
{ |
|---|
| 48 |
char file[PATH_MAX]; |
|---|
| 49 |
int size; |
|---|
| 50 |
char *uri; |
|---|
| 51 |
GdkPixbuf *icon; |
|---|
| 52 |
GtkWidget *helper; |
|---|
| 53 |
|
|---|
| 54 |
gtk_init(&argc, &argv); |
|---|
| 55 |
|
|---|
| 56 |
if (!notify_init("Images Test")) |
|---|
| 57 |
exit(1); |
|---|
| 58 |
|
|---|
| 59 |
/* Stock icon */ |
|---|
| 60 |
n = notify_notification_new("Icon Test", "Testing stock icon", |
|---|
| 61 |
"appointment-new", NULL); |
|---|
| 62 |
|
|---|
| 63 |
if (!notify_notification_show(n, NULL)) |
|---|
| 64 |
{ |
|---|
| 65 |
fprintf(stderr, "failed to send notification\n"); |
|---|
| 66 |
return 1; |
|---|
| 67 |
} |
|---|
| 68 |
|
|---|
| 69 |
g_object_unref(G_OBJECT(n)); |
|---|
| 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 |
/* URIs */ |
|---|
| 78 |
n = notify_notification_new("Alert!", "Testing URI icons", uri, NULL); |
|---|
| 79 |
|
|---|
| 80 |
if (!notify_notification_show(n, NULL)) |
|---|
| 81 |
{ |
|---|
| 82 |
fprintf(stderr, "failed to send notification\n"); |
|---|
| 83 |
return 1; |
|---|
| 84 |
} |
|---|
| 85 |
|
|---|
| 86 |
g_object_unref(G_OBJECT(n)); |
|---|
| 87 |
|
|---|
| 88 |
/* Raw image */ |
|---|
| 89 |
n = notify_notification_new("Raw image test", |
|---|
| 90 |
"Testing sending raw pixbufs", NULL, NULL); |
|---|
| 91 |
|
|---|
| 92 |
/* |
|---|
| 93 |
* This is just a hack to get a stock icon's pixbuf in a realworld app |
|---|
| 94 |
* if you were sending bitmapped data you would know the file location |
|---|
| 95 |
* and open it up with a method that could generate a bmp for you |
|---|
| 96 |
*/ |
|---|
| 97 |
helper = gtk_button_new(); |
|---|
| 98 |
icon = gtk_widget_render_icon(helper, |
|---|
| 99 |
GTK_STOCK_DIALOG_QUESTION, |
|---|
| 100 |
GTK_ICON_SIZE_DIALOG, |
|---|
| 101 |
NULL); |
|---|
| 102 |
gtk_widget_destroy(helper); |
|---|
| 103 |
|
|---|
| 104 |
notify_notification_set_icon_from_pixbuf(n, icon); |
|---|
| 105 |
g_object_unref(G_OBJECT(icon)); |
|---|
| 106 |
|
|---|
| 107 |
if (!notify_notification_show(n, NULL)) |
|---|
| 108 |
{ |
|---|
| 109 |
fprintf(stderr, "failed to send notification\n"); |
|---|
| 110 |
return 1; |
|---|
| 111 |
} |
|---|
| 112 |
|
|---|
| 113 |
g_object_unref(G_OBJECT(n)); |
|---|
| 114 |
|
|---|
| 115 |
return 0; |
|---|
| 116 |
} |
|---|