2005-11-10 13:18:10 -06:00
|
|
|
/*
|
|
|
|
* @file tests/test-image.c Unit test: images
|
|
|
|
*
|
2006-01-09 12:16:48 -06:00
|
|
|
* @Copyright(C) 2004 Mike Hearn <mike@navi.cx>
|
2005-11-10 13:18:10 -06:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
2006-01-09 12:16:48 -06:00
|
|
|
* version 2.1 of the License, or(at your option) any later version.
|
2005-11-10 13:18:10 -06:00
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <libnotify/notify.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
2006-01-09 12:16:48 -06:00
|
|
|
#define DBUS_API_SUBJECT_TO_CHANGE
|
2005-11-10 13:18:10 -06:00
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#include <dbus/dbus.h>
|
|
|
|
#include <dbus/dbus-glib.h>
|
|
|
|
#include <dbus/dbus-glib-lowlevel.h>
|
|
|
|
|
|
|
|
GMainLoop *loop;
|
|
|
|
NotifyNotification *n;
|
|
|
|
|
2006-01-09 12:16:48 -06:00
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
2005-11-10 13:18:10 -06:00
|
|
|
char file[PATH_MAX];
|
|
|
|
int size;
|
2006-01-09 12:16:48 -06:00
|
|
|
char *uri;
|
2005-11-10 13:18:10 -06:00
|
|
|
GdkPixbuf *icon;
|
|
|
|
GtkWidget *helper;
|
|
|
|
|
2006-01-09 12:16:48 -06:00
|
|
|
gtk_init(&argc, &argv);
|
2005-11-10 13:18:10 -06:00
|
|
|
|
2006-01-09 12:16:48 -06:00
|
|
|
if (!notify_init("Images Test"))
|
|
|
|
exit(1);
|
2005-11-10 13:18:10 -06:00
|
|
|
|
2006-01-21 02:38:35 -06:00
|
|
|
/* Stock icon */
|
2006-01-09 12:16:48 -06:00
|
|
|
n = notify_notification_new("Icon Test", "Testing stock icon",
|
|
|
|
"stock_help", NULL);
|
2005-12-02 14:36:46 -06:00
|
|
|
|
2006-01-09 12:16:48 -06:00
|
|
|
if (!notify_notification_show(n, NULL))
|
|
|
|
{
|
2005-11-10 13:18:10 -06:00
|
|
|
fprintf(stderr, "failed to send notification\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2006-01-21 02:38:35 -06:00
|
|
|
g_object_unref(G_OBJECT(n));
|
2005-11-10 13:18:10 -06:00
|
|
|
|
|
|
|
size = readlink("/proc/self/cwd", file, PATH_MAX - 1);
|
|
|
|
file[size] = '\0';
|
2006-01-09 12:16:48 -06:00
|
|
|
uri = g_strdup_printf("file://%s/%s", file, "applet-critical.png");
|
2005-11-10 13:18:10 -06:00
|
|
|
|
|
|
|
printf("sending %s\n", uri);
|
|
|
|
|
2006-01-21 02:38:35 -06:00
|
|
|
/* URIs */
|
|
|
|
n = notify_notification_new("Alert!", "Testing URI icons", uri, NULL);
|
2005-11-10 13:18:10 -06:00
|
|
|
|
2006-01-09 12:16:48 -06:00
|
|
|
if (!notify_notification_show(n, NULL))
|
|
|
|
{
|
2005-11-10 13:18:10 -06:00
|
|
|
fprintf(stderr, "failed to send notification\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2006-01-21 02:38:35 -06:00
|
|
|
g_object_unref(G_OBJECT(n));
|
2005-11-10 13:18:10 -06:00
|
|
|
|
2006-01-21 02:38:35 -06:00
|
|
|
/* Raw image */
|
|
|
|
n = notify_notification_new("Raw image test",
|
|
|
|
"Testing sending raw pixbufs", NULL, NULL);
|
2005-11-10 13:18:10 -06:00
|
|
|
|
2006-01-09 12:16:48 -06:00
|
|
|
/*
|
|
|
|
* This is just a hack to get a stock icon's pixbuf in a realworld app
|
|
|
|
* if you were sending bitmapped data you would know the file location
|
|
|
|
* and open it up with a method that could generate a bmp for you
|
|
|
|
*/
|
2005-11-10 13:18:10 -06:00
|
|
|
helper = gtk_button_new();
|
2006-01-09 12:16:48 -06:00
|
|
|
icon = gtk_widget_render_icon(helper,
|
2005-11-10 13:18:10 -06:00
|
|
|
GTK_STOCK_DIALOG_QUESTION,
|
|
|
|
GTK_ICON_SIZE_DIALOG,
|
2006-01-20 00:11:53 -06:00
|
|
|
NULL);
|
2006-01-21 02:38:35 -06:00
|
|
|
gtk_widget_destroy(helper);
|
2005-11-10 13:18:10 -06:00
|
|
|
|
2006-01-20 00:11:53 -06:00
|
|
|
notify_notification_set_icon_from_pixbuf(n, icon);
|
2006-01-21 02:38:35 -06:00
|
|
|
g_object_unref(G_OBJECT(icon));
|
2005-11-10 13:18:10 -06:00
|
|
|
|
2006-01-09 12:16:48 -06:00
|
|
|
if (!notify_notification_show(n, NULL))
|
|
|
|
{
|
2005-11-10 13:18:10 -06:00
|
|
|
fprintf(stderr, "failed to send notification\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2006-01-21 02:38:35 -06:00
|
|
|
g_object_unref(G_OBJECT(n));
|
2005-11-10 13:18:10 -06:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|