libnotify/tests/test-replace-widget.c

94 lines
2.9 KiB
C
Raw Normal View History

2010-01-29 02:46:42 -06:00
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
2010-01-29 01:59:26 -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
* version 2.1 of the License, or(at your option) any later version.
*
* 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 <glib.h>
#include <gtk/gtk.h>
2010-01-29 01:59:26 -06:00
static int count = 0;
2006-01-09 12:16:48 -06:00
static void
2010-01-29 01:59:26 -06:00
on_exposed (GtkWidget *widget,
GdkEventExpose *ev,
void *user_data)
2006-01-09 12:16:48 -06:00
{
2010-01-29 01:59:26 -06:00
NotifyNotification *n = NOTIFY_NOTIFICATION (user_data);
2010-01-29 01:59:26 -06:00
g_signal_handlers_disconnect_by_func (widget, on_exposed, user_data);
2010-01-29 01:59:26 -06:00
notify_notification_show (n, NULL);
}
2006-01-09 12:16:48 -06:00
static void
2010-01-29 01:59:26 -06:00
on_clicked (GtkButton *button,
void *user_data)
2006-01-09 12:16:48 -06:00
{
2010-01-29 01:59:26 -06:00
gchar *buf;
NotifyNotification *n = NOTIFY_NOTIFICATION (user_data);
2010-01-29 01:59:26 -06:00
count++;
buf = g_strdup_printf ("You clicked the button %i times", count);
notify_notification_update (n, "Widget Attachment Test", buf, NULL);
g_free (buf);
2010-01-29 01:59:26 -06:00
notify_notification_show (n, NULL);
}
2006-01-09 12:16:48 -06:00
int
2010-01-29 01:59:26 -06:00
main (int argc, char *argv[])
2006-01-09 12:16:48 -06:00
{
2010-01-29 01:59:26 -06:00
NotifyNotification *n;
GtkWidget *window;
GtkWidget *button;
2006-01-09 12:16:48 -06:00
2010-01-29 01:59:26 -06:00
gtk_init (&argc, &argv);
notify_init ("Replace Test");
2010-01-29 01:59:26 -06:00
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
g_signal_connect (G_OBJECT (window),
"delete_event",
G_CALLBACK (gtk_main_quit),
NULL);
2010-01-29 01:59:26 -06:00
button = gtk_button_new_with_label ("click here to change notification");
gtk_container_add (GTK_CONTAINER (window), button);
2010-01-29 01:59:26 -06:00
gtk_widget_show_all (window);
2010-01-29 01:59:26 -06:00
n = notify_notification_new ("Widget Attachment Test",
"Button has not been clicked yet",
NULL); //no icon
2010-01-29 01:59:26 -06:00
notify_notification_set_timeout (n, 0); //don't timeout
2010-01-29 01:59:26 -06:00
g_signal_connect (G_OBJECT (button),
"clicked",
G_CALLBACK (on_clicked),
n);
g_signal_connect_after (G_OBJECT (button),
"expose-event",
G_CALLBACK (on_exposed),
n);
2010-01-29 01:59:26 -06:00
gtk_main ();
2010-01-29 01:59:26 -06:00
return 0;
}