Contents of /trunk/src/banner.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 190 - (show annotations)
Mon Jul 6 19:17:24 2009 UTC (14 years, 10 months ago) by harbaum
File MIME type: text/plain
File size: 4604 byte(s)
More fremantle menu work
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 GtkWidget *menu = GTK_WIDGET(hildon_window_get_menu(HILDON_WINDOW(win)));
37 #if MAEMO_VERSION_MAJOR < 5
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 gtk_widget_set_sensitive(menu, TRUE);
43 #if MAEMO_VERSION_MAJOR < 5
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, *menu, *menu_att;
87 win = GTK_WIDGET(appdata->window);
88 menu = GTK_WIDGET(hildon_window_get_menu(HILDON_WINDOW(win)));
89 menu_att = gtk_menu_get_attach_widget(
90 hildon_window_get_menu(HILDON_WINDOW(win)));
91 gtk_widget_set_sensitive(win, FALSE);
92 gtk_widget_set_sensitive(menu, FALSE);
93 gtk_widget_set_sensitive(menu_att, FALSE);
94 gtk_grab_add(YETI_PASSIVE_WIDGET);
95 }
96 banner_busy_tick();
97 }
98
99
100 #else // USE_HILDON
101
102 /*
103 * For non-Hildon builds, use the "brief" message in the statusbar to show
104 * what's happening.
105 */
106
107 #include "statusbar.h"
108
109 void banner_show_info(appdata_t *appdata, char *text) {
110 banner_clear(appdata);
111 statusbar_brief(appdata, text, 0);
112 }
113
114 void banner_busy_start(appdata_t *appdata, gboolean grab, char *text) {
115 banner_clear(appdata);
116 statusbar_brief(appdata, text, -1);
117 appdata->banner_is_grabby = grab;
118 if (appdata->banner_is_grabby) {
119 GtkWidget *win;
120 win = GTK_WIDGET(appdata->window);
121 gtk_widget_set_sensitive(win, FALSE);
122 gtk_grab_add(YETI_PASSIVE_WIDGET);
123 }
124 }
125
126 void banner_clear(appdata_t *appdata) {
127 statusbar_brief(appdata, NULL, 0);
128 if (appdata->banner_is_grabby) {
129 GtkWidget *win;
130 win = GTK_WIDGET(appdata->window);
131 gtk_widget_set_sensitive(win, TRUE);
132 gtk_grab_remove(YETI_PASSIVE_WIDGET);
133 }
134 }
135
136
137 #endif //USE_HILDON
138
139
140 // Just an alias right now
141
142 void banner_busy_stop(appdata_t *appdata) {
143 banner_clear(appdata);
144 }
145
146
147 /*
148 * Process any outstanding GTK events to make the app look more responsive
149 * while still allowing long-running things to process in the mainloop.
150 * This could perhaps be generalised; it isn't banner-specific.
151 */
152
153 void banner_busy_tick() {
154 while (gtk_events_pending()) {
155 gtk_main_iteration();
156 }
157 }
158
159
160 // vim:et:ts=8:sw=2:sts=2:ai
161
162