Debian Codegraph @

tests/test-replace-widget.c

raw
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
2 *
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2.1 of the License, or(at your option) any later version.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the
15 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16 * Boston, MA 02111-1307, USA.
17 */
18
19 #include <libnotify/notify.h>
20 #include <stdio.h>
21 #include <unistd.h>
22 #include <glib.h>
23 #include <gtk/gtk.h>
24
25 static int count = 0;
26
27 static void
28 on_mapped (GtkWidget *widget,
29 void *user_data)
30 {
31 NotifyNotification *n = NOTIFY_NOTIFICATION (user_data);
32
33 g_signal_handlers_disconnect_by_func (widget, on_mapped, user_data);
34
35 notify_notification_show (n, NULL);
36 }
37
38 static void
39 on_clicked (GtkButton *button,
40 void *user_data)
41 {
42 gchar *buf;
43 NotifyNotification *n = NOTIFY_NOTIFICATION (user_data);
44
45 count++;
46 buf = g_strdup_printf ("You clicked the button %i times", count);
47 notify_notification_update (n, "Widget Attachment Test", buf, NULL);
48 g_free (buf);
49
50 notify_notification_show (n, NULL);
51 }
52
53 int
54 main (int argc, char *argv[])
55 {
56 NotifyNotification *n;
57 GtkWidget *window;
58 GtkWidget *button;
59
60 gtk_init ();
61 notify_init ("Replace Test");
62
63 window = gtk_window_new ();
64 g_signal_connect (G_OBJECT (window),
65 "delete_event",
66 G_CALLBACK (gtk_window_destroy),
67 NULL);
68
69 button = gtk_button_new_with_label ("click here to change notification");
70
71 gtk_window_set_child (GTK_WINDOW (window), button);
72
73 n = notify_notification_new ("Widget Attachment Test",
74 "Button has not been clicked yet",
75 NULL); //no icon
76
77 notify_notification_set_timeout (n, 0); //don't timeout
78
79 g_signal_connect (G_OBJECT (button),
80 "clicked",
81 G_CALLBACK (on_clicked),
82 n);
83 g_signal_connect_after (G_OBJECT (button),
84 "map",
85 G_CALLBACK (on_mapped),
86 n);
87
88 while (g_list_model_get_n_items (gtk_window_get_toplevels ()) > 0)
89 g_main_context_iteration (NULL, TRUE);
90
91 return 0;
92 }