From a20ffbbb6f15f468fe3c60a925eb31348c93deb3 Mon Sep 17 00:00:00 2001 From: Kaj-Michael Lang Date: Fri, 1 Feb 2008 16:23:42 +0200 Subject: [PATCH] Misc UI changes: - Use the new dialogs.c, - Add quit confirm dialog. - Remove the "first time" settings dialogs and popups, the user knows what to do. --- src/Makefile.am | 1 + src/cb.c | 1 + src/dialogs.c | 3 +- src/gpx.c | 7 +- src/mapper.c | 3 +- src/settings-gui.c | 7 +- src/ui-common.c | 193 +++++++++++++++------------------------------ src/ui-common.h | 7 +- 8 files changed, 79 insertions(+), 143 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index 938e023..c129230 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -67,6 +67,7 @@ mapper_SOURCES = utils.c \ speed-display.c \ hildon-wrappers.c \ ui-common.c \ + dialogs.c \ config-gconf.c \ speak.c \ announcements.c \ diff --git a/src/cb.c b/src/cb.c index 3525100..a74b4c6 100644 --- a/src/cb.c +++ b/src/cb.c @@ -59,6 +59,7 @@ #include "gps-panels.h" #include "gps-conn.h" #include "search.h" +#include "dialogs.h" #include "help.h" gboolean diff --git a/src/dialogs.c b/src/dialogs.c index 3320039..33a17e8 100644 --- a/src/dialogs.c +++ b/src/dialogs.c @@ -43,7 +43,8 @@ GtkWidget *dialog; dialog=gtk_dialog_new(); gtk_window_set_title(GTK_WINDOW(dialog), title); -gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(window)); +if (window) + gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(window)); gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); #ifndef WITH_HILDON gtk_window_set_deletable(GTK_WINDOW(dialog), FALSE); diff --git a/src/gpx.c b/src/gpx.c index 7a2d24d..2a9a5f3 100644 --- a/src/gpx.c +++ b/src/gpx.c @@ -54,19 +54,18 @@ #include "latlon.h" #include "map.h" #include "gpx.h" +#include "dialogs.h" #define XML_DATE_FORMAT "%FT%T" #define WRITE_STRING(string) { \ GnomeVFSResult vfs_result; \ GnomeVFSFileSize size; \ - if(GNOME_VFS_OK != (vfs_result = gnome_vfs_write( \ - handle, (string), strlen((string)), &size))) \ + if(GNOME_VFS_OK != (vfs_result = gnome_vfs_write(handle, (string), strlen((string)), &size))) \ { \ gchar buffer[BUFFER_SIZE]; \ g_snprintf(buffer, sizeof(buffer), \ - "%s:\n%s\n%s", _("Error while writing to file"), \ - _("File is incomplete."), \ + "%s:\n%s\n%s", _("Error while writing to file"), _("File is incomplete."), \ gnome_vfs_result_to_string(vfs_result)); \ popup_error(_window, buffer); \ return FALSE; \ diff --git a/src/mapper.c b/src/mapper.c index bb51c85..8ee7956 100644 --- a/src/mapper.c +++ b/src/mapper.c @@ -70,6 +70,7 @@ #include "speak.h" #include "gpx.h" #include "config-gconf.h" +#include "dialogs.h" gfloat UNITS_CONVERT[] = {1.85200,1.15077945,1.f,}; @@ -409,7 +410,7 @@ gst_init(&argc, &argv); #endif init_progress=gtk_progress_bar_new(); -init_dialog=progress_dialog("Mapper is loading...",init_progress); +init_dialog=progress_dialog(NULL, "Mapper is loading...",init_progress); g_idle_add((GSourceFunc)mapper_init, NULL); gtk_main(); mapper_destroy(); diff --git a/src/settings-gui.c b/src/settings-gui.c index a8c5354..f15f9b1 100644 --- a/src/settings-gui.c +++ b/src/settings-gui.c @@ -113,7 +113,7 @@ GtkWidget *btn_defaults; dialog = gtk_dialog_new_with_buttons(_("Hardware Keys"), GTK_WINDOW(_window), GTK_DIALOG_MODAL, GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, NULL); gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->action_area), btn_defaults = gtk_button_new_with_label(_("Reset..."))); -g_signal_connect(G_OBJECT(btn_defaults), "clicked", G_CALLBACK(settings_dialog_hardkeys_reset), &bdi); +g_signal_connect(G_OBJECT(btn_defaults), "clicked", G_CALLBACK(settings_dialog_hardkeys_reset), &bdi); gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT); gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), table = gtk_table_new(2, 9, FALSE), TRUE, TRUE, 0); @@ -450,11 +450,10 @@ return TRUE; } /** - * Bring up the Settings dialog. Return TRUE if and only if the recever - * information has changed (MAC or channel). + * Bring up the Settings dialog. */ gboolean -settings_dialog(void) +settings_dialog() { GtkWidget *dialog; GtkWidget *notebook; diff --git a/src/ui-common.c b/src/ui-common.c index de8bd6a..c2662f3 100644 --- a/src/ui-common.c +++ b/src/ui-common.c @@ -33,6 +33,7 @@ #include "gps-panels.h" #include "gps-conn.h" #include "filter.h" +#include "dialogs.h" #include "settings-gui.h" /* Callbacks */ @@ -66,6 +67,8 @@ struct ui_notebook_struct ui_notebook; #define GTK_STOCK_INFO GTK_STOCK_PROPERTIES #endif +static gboolean mapper_cb_quit(GtkWidget *widget, GdkEvent *event, gpointer data); + /** * Action groups and UI */ @@ -201,7 +204,7 @@ static GtkActionEntry ui_entries[] = { {"file_settings_colors", NULL, N_("_Colors..."), NULL, NULL, G_CALLBACK(menu_cb_settings_colors) }, {"file_settings_gps", NULL, N_("_Gps..."), NULL, NULL, G_CALLBACK(menu_cb_settings_gps) }, {"file_settings_osm", NULL, N_("_Map info..."), NULL, NULL, G_CALLBACK(menu_cb_settings_osm) }, - {"file_quit", GTK_STOCK_QUIT, N_("_Quit"), "Q", NULL, G_CALLBACK(gtk_main_quit) }, + {"file_quit", GTK_STOCK_QUIT, N_("_Quit"), "Q", NULL, G_CALLBACK(mapper_cb_quit) }, {"help", NULL, N_("_Help"), NULL, NULL, NULL }, {"help_help", GTK_STOCK_HELP, N_("_Help"), NULL, NULL, G_CALLBACK(menu_cb_help) }, @@ -333,23 +336,14 @@ void force_min_visible_bars(void *a, gint b) } #endif -/** - * Pop up a modal dialog box with simple error information in it. - */ -void -popup_error(GtkWidget * window, const gchar * error) +static gboolean +mapper_cb_quit(GtkWidget *widget, GdkEvent *event, gpointer data) { -GtkWidget *dialog; - -#ifdef WITH_HILDON -dialog = hildon_note_new_information(GTK_WINDOW(window), error); -#else -dialog = gtk_message_dialog_new (GTK_WINDOW(window), - GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_INFO, GTK_BUTTONS_OK, error); -#endif -gtk_dialog_run(GTK_DIALOG(dialog)); -gtk_widget_destroy(dialog); +if (dialog_confirm(_window, _("Are sure you'd like to quit ?"))==TRUE) { + gtk_main_quit(); + return FALSE; +} +return TRUE; } void @@ -391,59 +385,12 @@ for (curr = g_list_last(_repo_list); curr; curr = curr->prev) { } /** - * Call gtk_window_present() on Mapper. This also checks the - * configuration and brings up the Settings dialog if the GPS Receiver is - * not set up, the first time it is called. + * Call gtk_window_present() on Mapper. */ gboolean window_present() { -static gint been_here = 0; -static gint done_here = 0; - -if (!been_here++) { - /* Set connection state first, to avoid going into this if twice. */ - if (!_gps->io.address && _enable_gps) { - GtkWidget *confirm; - - gtk_window_present(GTK_WINDOW(_window)); - popup_error(_window, _("It looks like this is your first time running Mapper. Press OK to continue.")); - - if (settings_dialog()) { - popup_error(_window, - _("OpenStreetMap.org provides public, free-to-use maps. " - "You can also download a sample set of repositories from " - " the internet by using the \"Download...\" button.")); - repoman_dialog(); - if (_curr_repo->type != REPOTYPE_NONE) { - confirm = hildon_note_new_confirmation(GTK_WINDOW(_window), - _("You will now see a blank screen. You can download" - " maps using the \"Manage Maps\" menu item in the" - " \"Maps\" menu. Or, press OK to enable" - " Auto-Download.")); - if (GTK_RESPONSE_OK == gtk_dialog_run(GTK_DIALOG(confirm))) { - set_action_activate("map_auto_download", FALSE); - } - gtk_widget_destroy(confirm); - } - } else { - gtk_main_quit(); - } - } - - done_here++; /* Don't ask... */ -} -if (done_here) { - gtk_window_present(GTK_WINDOW(_window)); - - /* Re-enable any banners that might have been up. */ - { - GpsConnState old_state = _gps->io.conn; - gps_conn_set_state(_gps, RCVR_OFF); - gps_conn_set_state(_gps, old_state); - } -} - +gtk_window_present(GTK_WINDOW(_window)); return FALSE; } @@ -548,6 +495,42 @@ _menu_map = menu; #endif } +static GtkWidget * +mapper_window_new(void) +{ +GtkWidget *window; + +#ifdef WITH_HILDON +_program=HILDON_PROGRAM(hildon_program_get_instance()); +window=GTK_WIDGET(hildon_window_new()); +hildon_program_add_window(_program, HILDON_WINDOW(window)); +#else +window=gtk_window_new(GTK_WINDOW_TOPLEVEL); +gtk_window_set_title(GTK_WINDOW(window), "Mapper"); +gtk_window_set_resizable(GTK_WINDOW(window), TRUE); +gtk_widget_set_size_request(GTK_WIDGET(window), WINDOW_SIZE_X, WINDOW_SIZE_Y); +gtk_window_resize(GTK_WINDOW(window), WINDOW_SIZE_X, WINDOW_SIZE_Y); +#endif + +return window; +} + +/** + * Create a tree view inside given container + */ +static GtkWidget * +mapper_tree_view_new(GtkWidget *container) +{ +GtkWidget *tree_view, *sw; +tree_view=gtk_tree_view_new(); +sw=gtk_scrolled_window_new(NULL, NULL); +gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); +gtk_container_add(GTK_CONTAINER(sw), tree_view); +gtk_box_pack_start(container, sw, TRUE, TRUE, 0); +gtk_tree_selection_set_mode(gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_view)), GTK_SELECTION_SINGLE); +gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(tree_view), TRUE); +return tree_view; +} /** * Initialize everything required in preparation for calling gtk_main(). @@ -558,24 +541,12 @@ mapper_ui_init(void) GError *error = NULL; GtkWidget *hbox, *mapvbox, *label, *vbox_main; GtkWidget *vbox; -GtkWidget *sw; GtkNotebook *notebook; GtkToolItem *item; GtkTreeViewColumn *column; GtkCellRenderer *renderer; -#ifdef WITH_HILDON -_program = HILDON_PROGRAM(hildon_program_get_instance()); -_window = GTK_WIDGET(hildon_window_new()); -hildon_program_add_window(_program, HILDON_WINDOW(_window)); -#else -_window = gtk_window_new(GTK_WINDOW_TOPLEVEL); -gtk_window_set_title(GTK_WINDOW(_window), "Mapper"); -gtk_widget_set_size_request(GTK_WIDGET(_window), WINDOW_SIZE_X, WINDOW_SIZE_Y); -gtk_window_resize(GTK_WINDOW(_window), WINDOW_SIZE_X, WINDOW_SIZE_Y); -gtk_window_set_resizable(GTK_WINDOW(_window), TRUE); -#endif - +_window=mapper_window_new(); gtk_container_set_border_width (GTK_CONTAINER (_window), 0); actions = gtk_action_group_new ("Actions"); @@ -592,7 +563,7 @@ gtk_action_group_add_radio_actions (actions, ui_autocenter_entries, gtk_ui_manager_insert_action_group (ui, actions, 0); g_object_unref (actions); -/* N810 has keyboard so set this up */ +/* N810 has keyboard so set this up on hildon too */ gtk_window_add_accel_group (GTK_WINDOW(_window), gtk_ui_manager_get_accel_group (ui)); if (!gtk_ui_manager_add_ui_from_string (ui, mapper_ui, -1, &error)) { @@ -608,6 +579,7 @@ g_assert(menu_bar); toolbar = gtk_ui_manager_get_widget (ui, "/ToolBar"); g_assert(toolbar); +/* Toolbar progress item */ item=gtk_tool_item_new(); _progress_item=gtk_progress_bar_new(); gtk_tool_item_set_expand(item, TRUE); @@ -645,15 +617,12 @@ hildon_program_set_common_toolbar(_program, GTK_TOOLBAR(toolbar)); GtkMenu *hmenu; hmenu = GTK_MENU(gtk_menu_new()); - gtk_container_foreach(GTK_CONTAINER(menu_bar), - (GtkCallback) gtk_widget_reparent, hmenu); - + gtk_container_foreach(GTK_CONTAINER(menu_bar), (GtkCallback)gtk_widget_reparent, hmenu); hildon_window_set_menu(HILDON_WINDOW(_window), hmenu); } gtk_widget_show_all(GTK_WIDGET(toolbar)); #else _status_bar = gtk_statusbar_new(); - gtk_box_pack_start(GTK_BOX(vbox_main), menu_bar, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(vbox_main), toolbar, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(vbox_main), notebook, TRUE, TRUE, 0); @@ -693,18 +662,19 @@ _tab_compass = gtk_compass_new(&_gps->data); gtk_box_pack_start(GTK_BOX(vbox), _tab_compass, TRUE, TRUE, 0); ui_notebook.heading=gtk_notebook_append_page(notebook, vbox, label); +/* Track Tab */ +vbox=gtk_vbox_new(FALSE, 0); +label=gtk_label_new("Track"); +track_tree_view=mapper_tree_view_new(vbox); +#if 0 +g_signal_connect(G_OBJECT(track_tree_view), "row-activated", G_CALLBACK(track_waypoint_activated_cb), NULL); +#endif +ui_notebook.track=gtk_notebook_append_page(notebook, vbox, label); + /* Route Tab */ vbox=gtk_vbox_new(FALSE, 0); label=gtk_label_new("Route"); - -route_tree_view=gtk_tree_view_new(); -sw=gtk_scrolled_window_new(NULL, NULL); -gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); -gtk_box_pack_start(vbox, sw, TRUE, TRUE, 0); -gtk_container_add(GTK_CONTAINER(sw), route_tree_view); - -gtk_tree_selection_set_mode(gtk_tree_view_get_selection (GTK_TREE_VIEW(route_tree_view)), GTK_SELECTION_SINGLE); -gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(route_tree_view), TRUE); +route_tree_view=mapper_tree_view_new(vbox); renderer=gtk_cell_renderer_text_new(); column=gtk_tree_view_column_new_with_attributes(_("Location"), renderer, "text", ROUTE_LATLON, NULL); @@ -719,24 +689,17 @@ column=gtk_tree_view_column_new_with_attributes(_("Waypoint"), renderer, "text", gtk_tree_view_append_column(GTK_TREE_VIEW(route_tree_view), column); #if 0 -g_signal_connect(G_OBJECT(route_tree), "row-activated", G_CALLBACK(route_waypoint_activated_cb), NULL); +g_signal_connect(G_OBJECT(route_tree_view), "row-activated", G_CALLBACK(route_waypoint_activated_cb), NULL); #endif ui_notebook.route=gtk_notebook_append_page(notebook, vbox, label); -/* Track Tab */ -#if 0 -vbox=gtk_vbox_new(FALSE, 0); -label=gtk_label_new("Track"); - -ui_notebook.track=gtk_notebook_append_page(notebook, vbox, label); -#endif - menu_maps_add_repos(); menu_init_cmenu(); _last_spoken_phrase = g_strdup(""); memset(&_autoroute_data, 0, sizeof(_autoroute_data)); +g_signal_connect(G_OBJECT(_window), "delete_event", G_CALLBACK(mapper_cb_quit), NULL); g_signal_connect(G_OBJECT(_window), "destroy", G_CALLBACK(gtk_main_quit), NULL); gtk_widget_show_all(GTK_WIDGET(vbox_main)); @@ -774,32 +737,6 @@ gps_show_info(&_gps->data); gtk_idle_add((GSourceFunc)window_present, NULL); } -GtkWidget * -progress_dialog(const gchar *title, GtkWidget *progress) -{ -GtkWidget *dialog; - -dialog = gtk_dialog_new(); -gtk_window_set_title(GTK_WINDOW(dialog), title); -gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(_window)); -gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); -#ifndef WITH_HILDON -gtk_window_set_deletable(GTK_WINDOW(dialog), FALSE); -#endif -/* gtk_window_set_decorated(GTK_WINDOW(dialog), FALSE); */ -gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), gtk_label_new(title), TRUE, TRUE, 0); -gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), progress, TRUE, TRUE, 0); -gtk_widget_show_all(dialog); -return dialog; -} - -void -progress_dialog_remove(GtkWidget *dialog) -{ -if (dialog) - gtk_widget_destroy(dialog); -} - gboolean gps_info_update(Gps *gps) { diff --git a/src/ui-common.h b/src/ui-common.h index 7c9c029..88e3b08 100644 --- a/src/ui-common.h +++ b/src/ui-common.h @@ -112,21 +112,18 @@ struct _info_banner info_banner; GtkMenu *_menu_map; GtkWidget *route_tree_view; +GtkWidget *track_tree_view; /** Context menu click location on map */ guint _cmenu_position_x; guint _cmenu_position_y; -gboolean window_present(); -void popup_error(GtkWidget * window, const gchar * error); void mapper_ui_init(void); +gboolean window_present(); void set_action_sensitive(const char *name, gboolean sensitive); void set_action_activate(const char *name, gboolean active); -GtkWidget *progress_dialog(const gchar *title, GtkWidget *progress); -void progress_dialog_remove(GtkWidget *dialog); - /* XXX: Not the right place but.. */ gboolean gps_info_update(Gps *gps); gboolean gps_location_update(Gps *gps); -- 2.39.5