Contents of /trunk/src/banner.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 209 - (show annotations)
Fri Jul 10 19:45:31 2009 UTC (14 years, 11 months ago) by harbaum
File MIME type: text/plain
File size: 4669 byte(s)
Version increase
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 = GTK_WIDGET(appdata->window);
36 #if MAEMO_VERSION_MAJOR < 5
37 GtkWidget *menu = GTK_WIDGET(hildon_window_get_menu(HILDON_WINDOW(win)));
38 GtkWidget *menu_att = gtk_menu_get_attach_widget(
39 hildon_window_get_menu(HILDON_WINDOW(win)));
40 #endif
41 gtk_widget_set_sensitive(win, TRUE);
42 #if MAEMO_VERSION_MAJOR < 5
43 gtk_widget_set_sensitive(menu, TRUE);
44 gtk_widget_set_sensitive(menu_att, TRUE);
45 #endif
46 }
47 gtk_widget_destroy(appdata->banner);
48 g_object_unref(appdata->banner);
49 appdata->banner = NULL;
50 }
51
52
53 // Cancel any animations currently going, and show a brief text message.
54
55 void banner_show_info(appdata_t *appdata, char *text) {
56 if (!appdata->window)
57 return;
58 banner_clear(appdata);
59 appdata->banner = hildon_banner_show_information(
60 GTK_WIDGET(appdata->window), NULL, text);
61 g_object_ref(appdata->banner);
62 gtk_widget_show(appdata->banner);
63 }
64
65 /*
66 * Start a spinner animation going to demonstrate that something's happening
67 * behind the scenes. If `grab` is true, use the Yeti trick to grab the pointer
68 * during the animation: this gives the impression that the app is doing
69 * something while blocking the rest of the UI. banner_busy_stop() and
70 * banner_clear() will ungrab if grab is set.
71 *
72 * Yeti mode:
73 * http://mail.gnome.org/archives/gtk-app-devel-list/2006-May/msg00020.html
74 */
75
76 void banner_busy_start(appdata_t *appdata, gboolean grab, char *text) {
77 if (!appdata->window)
78 return;
79 banner_clear(appdata);
80 appdata->banner = hildon_banner_show_animation(
81 GTK_WIDGET(appdata->window), NULL, text);
82 g_object_ref(appdata->banner);
83 gtk_widget_show(appdata->banner);
84 appdata->banner_is_grabby = grab;
85 if (appdata->banner_is_grabby) {
86 GtkWidget *win = GTK_WIDGET(appdata->window);
87 #if MAEMO_VERSION_MAJOR < 5
88 GtkWidget *menu = GTK_WIDGET(hildon_window_get_menu(HILDON_WINDOW(win)));
89 GtkWidget *menu_att = gtk_menu_get_attach_widget(
90 hildon_window_get_menu(HILDON_WINDOW(win)));
91 #endif
92 gtk_widget_set_sensitive(win, FALSE);
93 #if MAEMO_VERSION_MAJOR < 5
94 gtk_widget_set_sensitive(menu, FALSE);
95 gtk_widget_set_sensitive(menu_att, FALSE);
96 #endif
97 gtk_grab_add(YETI_PASSIVE_WIDGET);
98 }
99 banner_busy_tick();
100 }
101
102
103 #else // USE_HILDON
104
105 /*
106 * For non-Hildon builds, use the "brief" message in the statusbar to show
107 * what's happening.
108 */
109
110 #include "statusbar.h"
111
112 void banner_show_info(appdata_t *appdata, char *text) {
113 banner_clear(appdata);
114 statusbar_brief(appdata, text, 0);
115 }
116
117 void banner_busy_start(appdata_t *appdata, gboolean grab, char *text) {
118 banner_clear(appdata);
119 statusbar_brief(appdata, text, -1);
120 appdata->banner_is_grabby = grab;
121 if (appdata->banner_is_grabby) {
122 GtkWidget *win;
123 win = GTK_WIDGET(appdata->window);
124 gtk_widget_set_sensitive(win, FALSE);
125 gtk_grab_add(YETI_PASSIVE_WIDGET);
126 }
127 }
128
129 void banner_clear(appdata_t *appdata) {
130 statusbar_brief(appdata, NULL, 0);
131 if (appdata->banner_is_grabby) {
132 GtkWidget *win;
133 win = GTK_WIDGET(appdata->window);
134 gtk_widget_set_sensitive(win, TRUE);
135 gtk_grab_remove(YETI_PASSIVE_WIDGET);
136 }
137 }
138
139
140 #endif //USE_HILDON
141
142
143 // Just an alias right now
144
145 void banner_busy_stop(appdata_t *appdata) {
146 banner_clear(appdata);
147 }
148
149
150 /*
151 * Process any outstanding GTK events to make the app look more responsive
152 * while still allowing long-running things to process in the mainloop.
153 * This could perhaps be generalised; it isn't banner-specific.
154 */
155
156 void banner_busy_tick() {
157 while (gtk_events_pending()) {
158 gtk_main_iteration();
159 }
160 }
161
162
163 // vim:et:ts=8:sw=2:sts=2:ai
164
165