Contents of /trunk/src/banner.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 42 - (show annotations)
Wed Jan 21 20:01:18 2009 UTC (15 years, 3 months ago) by harbaum
File MIME type: text/plain
File size: 4539 byte(s)
ID hashing for fast ID resolving
1 /*
2 * Copyright (C) 2008 Andrew Chadwick <andrewc-osm2go@piffle.org>.
3 *
4 * This file is part of OSM2Go.
5 *
6 * OSM2Go is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * OSM2Go 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
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with OSM2Go. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "banner.h"
21 #include <gtk/gtk.h>
22
23 #define YETI_PASSIVE_WIDGET appdata->statusbar->widget
24
25 #ifdef USE_HILDON
26 #include <hildon/hildon.h>
27
28 // Clear any current animations.
29
30 void banner_clear(appdata_t *appdata) {
31 if (! (appdata->window && appdata->banner))
32 return;
33 if (appdata->banner_is_grabby) {
34 gtk_grab_remove(YETI_PASSIVE_WIDGET);
35 GtkWidget *win, *menu, *menu_att;
36 win = GTK_WIDGET(appdata->window);
37 menu = GTK_WIDGET(hildon_window_get_menu(HILDON_WINDOW(win)));
38 menu_att = gtk_menu_get_attach_widget(
39 hildon_window_get_menu(HILDON_WINDOW(win)));
40 gtk_widget_set_sensitive(win, TRUE);
41 gtk_widget_set_sensitive(menu, TRUE);
42 gtk_widget_set_sensitive(menu_att, TRUE);
43 }
44 gtk_widget_destroy(appdata->banner);
45 g_object_unref(appdata->banner);
46 appdata->banner = NULL;
47 }
48
49
50 // Cancel any animations currently going, and show a brief text message.
51
52 void banner_show_info(appdata_t *appdata, char *text) {
53 if (!appdata->window)
54 return;
55 banner_clear(appdata);
56 appdata->banner = hildon_banner_show_information(
57 GTK_WIDGET(appdata->window), NULL, text);
58 g_object_ref(appdata->banner);
59 gtk_widget_show(appdata->banner);
60 }
61
62 /*
63 * Start a spinner animation going to demonstrate that something's happening
64 * behind the scenes. If `grab` is true, use the Yeti trick to grab the pointer
65 * during the animation: this gives the impression that the app is doing
66 * something while blocking the rest of the UI. banner_busy_stop() and
67 * banner_clear() will ungrab if grab is set.
68 *
69 * Yeti mode:
70 * http://mail.gnome.org/archives/gtk-app-devel-list/2006-May/msg00020.html
71 */
72
73 void banner_busy_start(appdata_t *appdata, gboolean grab, char *text) {
74 if (!appdata->window)
75 return;
76 banner_clear(appdata);
77 appdata->banner = hildon_banner_show_animation(
78 GTK_WIDGET(appdata->window), NULL, text);
79 g_object_ref(appdata->banner);
80 gtk_widget_show(appdata->banner);
81 appdata->banner_is_grabby = grab;
82 if (appdata->banner_is_grabby) {
83 GtkWidget *win, *menu, *menu_att;
84 win = GTK_WIDGET(appdata->window);
85 menu = GTK_WIDGET(hildon_window_get_menu(HILDON_WINDOW(win)));
86 menu_att = gtk_menu_get_attach_widget(
87 hildon_window_get_menu(HILDON_WINDOW(win)));
88 gtk_widget_set_sensitive(win, FALSE);
89 gtk_widget_set_sensitive(menu, FALSE);
90 gtk_widget_set_sensitive(menu_att, FALSE);
91 gtk_grab_add(YETI_PASSIVE_WIDGET);
92 }
93 banner_busy_tick();
94 }
95
96
97 #else // USE_HILDON
98
99 /*
100 * For non-Hildon builds, use the "brief" message in the statusbar to show
101 * what's happening.
102 */
103
104 #include "statusbar.h"
105
106 void banner_show_info(appdata_t *appdata, char *text) {
107 banner_clear(appdata);
108 statusbar_brief(appdata, text, 0);
109 }
110
111 void banner_busy_start(appdata_t *appdata, gboolean grab, char *text) {
112 banner_clear(appdata);
113 statusbar_brief(appdata, text, -1);
114 appdata->banner_is_grabby = grab;
115 if (appdata->banner_is_grabby) {
116 GtkWidget *win;
117 win = GTK_WIDGET(appdata->window);
118 gtk_widget_set_sensitive(win, FALSE);
119 gtk_grab_add(YETI_PASSIVE_WIDGET);
120 }
121 }
122
123 void banner_clear(appdata_t *appdata) {
124 statusbar_brief(appdata, NULL, 0);
125 if (appdata->banner_is_grabby) {
126 GtkWidget *win;
127 win = GTK_WIDGET(appdata->window);
128 gtk_widget_set_sensitive(win, TRUE);
129 gtk_grab_remove(YETI_PASSIVE_WIDGET);
130 }
131 }
132
133
134 #endif //USE_HILDON
135
136
137 // Just an alias right now
138
139 void banner_busy_stop(appdata_t *appdata) {
140 banner_clear(appdata);
141 }
142
143
144 /*
145 * Process any outstanding GTK events to make the app look more responsive
146 * while still allowing long-running things to process in the mainloop.
147 * This could perhaps be generalised; it isn't banner-specific.
148 */
149
150 void banner_busy_tick() {
151 while (gtk_events_pending()) {
152 gtk_main_iteration();
153 }
154 }
155
156
157 // vim:et:ts=8:sw=2:sts=2:ai
158
159