]> err.no Git - mapper/commitdiff
Fix repository selection menu items to use GtkUIManager
authorKaj-Michael Lang <milang@angel.tal.org>
Mon, 3 Sep 2007 22:27:59 +0000 (01:27 +0300)
committerKaj-Michael Lang <milang@angel.tal.org>
Mon, 3 Sep 2007 22:27:59 +0000 (01:27 +0300)
src/map-repo.c
src/settings-gui.c
src/ui-common.c
src/ui-common.h

index fc76dde1e2003b54654eaf6c4c50ac63bfe4ba81..feca4f59f2eac089a49ef043f10aa7fc0b472a08 100644 (file)
@@ -677,75 +677,50 @@ repoman_dialog()
                gint i;
                GList *curr;
                gchar *old_curr_repo_name = _curr_repo->name;
+
                for (i = 0, curr = rmi.repo_edits;
                     verified && curr; curr = curr->next, i++) {
                        RepoEditInfo *rei = curr->data;
-                       gchar *expanded =
-                           gnome_vfs_expand_initial_tilde(gtk_entry_get_text
-                                                          (GTK_ENTRY
-                                                           (rei->
-                                                            txt_cache_dir)));
-                       verified =
-                           repo_make_cache_dir(rei->name, expanded,
-                                               rmi.dialog);
+                       gchar *expanded = gnome_vfs_expand_initial_tilde(gtk_entry_get_text(GTK_ENTRY(rei->txt_cache_dir)));
+                       verified = repo_make_cache_dir(rei->name, expanded,     rmi.dialog);
                        g_free(expanded);
                }
                if (!verified) {
-                       gtk_combo_box_set_active(GTK_COMBO_BOX(rmi.cmb_repos),
-                                                i - 1);
+                       gtk_combo_box_set_active(GTK_COMBO_BOX(rmi.cmb_repos), i - 1);
                        continue;
                }
 
-               /* We're good to replace.  Remove old _repo_list menu items. */
-               menu_maps_remove_repos();
+               /* ** */
 
                /* But keep the repo list in memory, in case downloads are using it. */
                _repo_list = NULL;
 
                /* Write new _repo_list. */
-               curr_repo_index =
-                   gtk_combo_box_get_active(GTK_COMBO_BOX(rmi.cmb_repos));
+               curr_repo_index = gtk_combo_box_get_active(GTK_COMBO_BOX(rmi.cmb_repos));
                _curr_repo = NULL;
                for (i = 0, curr = rmi.repo_edits; curr; curr = curr->next, i++) {
                        RepoEditInfo *rei = curr->data;
                        RepoData *rd = g_new(RepoData, 1);
                        rd->name = g_strdup(rei->name);
-                       rd->url =
-                           g_strdup(gtk_entry_get_text
-                                    (GTK_ENTRY(rei->txt_url)));
-                       rd->cache_dir =
-                           gnome_vfs_expand_initial_tilde(gtk_entry_get_text
-                                                          (GTK_ENTRY
-                                                           (rei->
-                                                            txt_cache_dir)));
-                       rd->dl_zoom_steps =
-                           hildon_controlbar_get_value(HILDON_CONTROLBAR
-                                                       (rei->
-                                                        num_dl_zoom_steps));
-                       rd->view_zoom_steps =
-                           hildon_controlbar_get_value(HILDON_CONTROLBAR
-                                                       (rei->
-                                                        num_view_zoom_steps));
-                       rd->double_size =
-                           gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON
-                                                        (rei->
-                                                         chk_double_size));
-                       rd->nextable =
-                           gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON
-                                                        (rei->chk_nextable));
+                       rd->url = g_strdup(gtk_entry_get_text(GTK_ENTRY(rei->txt_url)));
+                       rd->cache_dir = gnome_vfs_expand_initial_tilde(gtk_entry_get_text(GTK_ENTRY(rei->txt_cache_dir)));
+                       rd->dl_zoom_steps = hildon_controlbar_get_value(HILDON_CONTROLBAR(rei->num_dl_zoom_steps));
+                       rd->view_zoom_steps = hildon_controlbar_get_value(HILDON_CONTROLBAR(rei->num_view_zoom_steps));
+                       rd->double_size = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(rei->chk_double_size));
+                       rd->nextable = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(rei->chk_nextable));
                        set_repo_type(rd);
 
                        _repo_list = g_list_append(_repo_list, rd);
 
-                       if (!_curr_repo
-                           && !strcmp(old_curr_repo_name, rd->name))
+                       if (!_curr_repo && !strcmp(old_curr_repo_name, rd->name))
                                repo_set_curr(rd);
                        else if (i == curr_repo_index)
                                repo_set_curr(rd);
                }
                if (!_curr_repo)
                        repo_set_curr((RepoData *) g_list_first(_repo_list)->data);
-               menu_maps_add_repos(_menu_maps_submenu);
+
+               menu_maps_add_repos();
 
                config_save_repo();
                break;
index c66ddc709e29ed0f93fbdeb44c8d60735425f002..48b2609746041e0760a34fa7e7ca416fcd7996b9 100644 (file)
@@ -621,16 +621,13 @@ settings_dialog(void)
                                g_free(_rcvr_mac);
                                _rcvr_mac = NULL;
                                rcvr_changed = TRUE;
-                               gtk_widget_set_sensitive(GTK_WIDGET(_menu_gps_details_item), FALSE);
+                               set_action_sensitive("gps_details", FALSE);
                        }
                        if (_enable_gps) {
-                               gtk_check_menu_item_set_active
-                                   (GTK_CHECK_MENU_ITEM(_menu_enable_gps_item),
-                                    FALSE);
-                               popup_error(dialog, _("No GPS Receiver MAC provided.\n"
-                                             "GPS will be disabled."));
+                               set_action_activate("gps_details", FALSE);
+                               popup_error(dialog, _("No GPS Receiver MAC provided.\nGPS will be disabled."));
                                rcvr_changed = TRUE;
-                               gtk_widget_set_sensitive(GTK_WIDGET(_menu_gps_details_item), FALSE);
+                               set_action_sensitive("gps_details", FALSE);
                        }
                } else if (!_rcvr_mac || strcmp(_rcvr_mac, gtk_entry_get_text(GTK_ENTRY(txt_rcvr_mac)))) {
                        /* User specified a new rcvr mac. */
@@ -673,7 +670,6 @@ settings_dialog(void)
                gtk_widget_set_sensitive(_cmenu_loc_add_poi, _db != NULL);
                gtk_widget_set_sensitive(_cmenu_way_add_poi, _db != NULL);
                gtk_widget_set_sensitive(_cmenu_poi, _db != NULL);
-               gtk_widget_set_sensitive(_menu_poi_item, _db != NULL);
 
                _poi_zoom = hildon_number_editor_get_value(HILDON_NUMBER_EDITOR(num_poi_zoom));
 
index dc9846384de09461821742b42d8f20f586e3e5c5..6c385a4cd2d56ded1d5c59e607cf1728a6faa817 100644 (file)
@@ -45,6 +45,7 @@ static GtkWidget *toolbar;
 GtkWidget *_fix_banner=NULL;
 
 static GtkActionGroup *actions;
+static GtkActionGroup *map_repos_action_group;
 static GtkUIManager *ui;
 
 /**
@@ -62,7 +63,6 @@ static const gchar *mapper_ui =
 "    </menu>"
 "    <menu action='map' name='map'>"
 "      <menu action='map_maps' name='map_maps'>"
-"         <placeholder />"
 "      </menu>"
 "      <separator/>"
 "      <menuitem action='map_manager'/>"
@@ -243,6 +243,31 @@ static guint n_ui_autocenter_entries = G_N_ELEMENTS (ui_autocenter_entries);
 
 /************************************************************************************/
 
+void
+set_action_sensitive(const char *name, gboolean sensitive)
+{
+GtkAction *action = gtk_action_group_get_action(actions, name);
+gtk_action_set_sensitive(action, sensitive);
+}
+
+void
+set_action_activate(const char *name, gboolean active)
+{
+GtkAction *action = gtk_action_group_get_action(actions, name);
+gtk_toggle_action_set_active(action, active);
+}
+
+#if 0
+void
+set_radio_action_value(const char *name, gint value)
+{
+GtkAction *action = gtk_action_group_get_action(actions, name);
+gtk_radio_action_set_current_value(action, value);
+}
+#endif
+
+/************************************************************************************/
+
 #ifdef WITH_HILDON
 void force_min_visible_bars(HildonControlbar * control_bar, gint num_bars)
 {
@@ -277,46 +302,42 @@ gtk_dialog_run(GTK_DIALOG(dialog));
 gtk_widget_destroy(dialog);
 }
 
-void
-menu_maps_remove_repos()
+void 
+menu_maps_add_repos(void)
 {
 GList *curr;
+GtkWidget *last_repo = NULL;
+static gint id=0;
+gint i=0;
 
-/* Delete one menu item for each repo. */
-for (curr = _repo_list; curr; curr = curr->next) {
-       gtk_widget_destroy(gtk_container_get_children(GTK_CONTAINER(_menu_maps_submenu))->data);
+if (id>0) {
+       gtk_ui_manager_remove_ui(ui, id);
+} else {
+       id=gtk_ui_manager_new_merge_id(ui);
 }
+
+if (map_repos_action_group) {
+       gtk_ui_manager_remove_action_group(ui, map_repos_action_group);
+       g_object_unref(map_repos_action_group);
 }
 
-void 
-menu_maps_add_repos(GtkWidget *map_menu)
-{
-GList *curr;
-GtkWidget *last_repo = NULL;
+map_repos_action_group=gtk_action_group_new("map_repos_actions");
+gtk_ui_manager_insert_action_group(ui, map_repos_action_group, 0);
+gtk_ui_manager_ensure_update(ui);
 
 for (curr = g_list_last(_repo_list); curr; curr = curr->prev) {
        RepoData *rd = (RepoData *) curr->data;
-       GtkWidget *menu_item;
-
-       if (last_repo) {
-               gtk_menu_prepend(map_menu, menu_item = gtk_radio_menu_item_new_with_label_from_widget(GTK_RADIO_MENU_ITEM(last_repo), rd->name));
-       } else {
-               gtk_menu_prepend(map_menu, menu_item = gtk_radio_menu_item_new_with_label(NULL, rd->name));
-               last_repo = menu_item;
-       }
-       gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu_item), rd == _curr_repo);
-       rd->menu_item = menu_item;
-}
-
-/* Add signals (must be after entire menu is built). */
-{
-       GList *currmi = gtk_container_get_children(GTK_CONTAINER(_menu_maps_submenu));
-       for (curr = _repo_list; curr; curr = curr->next, currmi = currmi->next) {
-               g_signal_connect(G_OBJECT(currmi->data), "activate", G_CALLBACK(menu_cb_maps_select), curr->data);
-       }
+       GtkAction *action;
+       gchar *action_name;
+
+       action_name = g_strdup_printf ("MapRepo%u", i++);
+       action=g_object_new(GTK_TYPE_ACTION, "name", action_name, "label", rd->name, NULL);
+       g_signal_connect(G_OBJECT(action), "activate", G_CALLBACK (menu_cb_maps_select), curr->data);
+       gtk_action_group_add_action(map_repos_action_group, action);
+       g_object_unref(action);
+       gtk_ui_manager_add_ui(ui, id, "/MenuBar/map/map_maps", rd->name, action_name, GTK_UI_MANAGER_MENUITEM, FALSE);
 }
 
-gtk_widget_show_all(map_menu);
 }
 
 /**
@@ -352,7 +373,7 @@ if (!been_here++) {
                                              " \"Maps\" menu.  Or, press OK to enable"
                                              " Auto-Download."));
                                if (GTK_RESPONSE_OK == gtk_dialog_run(GTK_DIALOG(confirm))) {
-                                       gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(_menu_auto_download_item), TRUE);
+                                       set_action_activate("map_auto_download", FALSE);
                                }
                                gtk_widget_destroy(confirm);
                        }
@@ -583,29 +604,6 @@ SPEED_LOCATION_TEXT[SPEED_LOCATION_BOTTOM_RIGHT] = _("Bottom-Right");
 SPEED_LOCATION_TEXT[SPEED_LOCATION_BOTTOM_LEFT] = _("Bottom-Left");
 }
 
-void
-set_action_sensitive(const char *name, gboolean sensitive)
-{
-GtkAction *action = gtk_action_group_get_action(actions, name);
-gtk_action_set_sensitive(action, sensitive);
-}
-
-void
-set_action_activate(const char *name, gboolean active)
-{
-GtkAction *action = gtk_action_group_get_action(actions, name);
-gtk_toggle_action_set_active(action, active);
-}
-
-#if 0
-void
-set_radio_action_value(const char *name, gint value)
-{
-GtkAction *action = gtk_action_group_get_action(actions, name);
-gtk_radio_action_set_current_value(action, value);
-}
-#endif
-
 /**
  * Initialize everything required in preparation for calling gtk_main().
  */
@@ -715,10 +713,7 @@ gps_show_info();
 map_poi_init(_map_widget);
 gtk_widget_realize(_map_widget);
 
-g_print("A\n");
-_menu_maps_submenu = gtk_ui_manager_get_widget (ui, "/MenuBar/map/map_maps");
-menu_maps_add_repos(_menu_maps_submenu);
-g_print("B\n");
+menu_maps_add_repos();
 
 menu_init_cmenu();
 
index dc8a4bc5d91de0a367b79db3c73d029a89d819f8..31b9611d5930b083254b7ceb4c6880021c6d8cef 100644 (file)
@@ -85,72 +85,9 @@ PangoFontDescription *_sat_details_expose_fontdesc;
 GdkGC *_gc[COLORABLE_ENUM_COUNT];
 GdkColor _color[COLORABLE_ENUM_COUNT];
 
-/* Menu items for the "Route" submenu. */
-GtkWidget *_menu_route_download_item;
-GtkWidget *_menu_route_open_item;
-GtkWidget *_menu_route_save_item;
-GtkWidget *_menu_route_distnext_item;
-GtkWidget *_menu_route_distlast_item;
-GtkWidget *_menu_route_reset_item;
-GtkWidget *_menu_route_clear_item;
-
-/* Menu items for the "Track" submenu. */
-GtkWidget *_menu_track_open_item;
-GtkWidget *_menu_track_save_item;
-GtkWidget *_menu_track_insert_break_item;
-GtkWidget *_menu_track_insert_mark_item;
-GtkWidget *_menu_track_distlast_item;
-GtkWidget *_menu_track_distfirst_item;
-GtkWidget *_menu_track_clear_item;
-GtkWidget *_menu_track_filter;
-
-/* Menu items for the "Maps" submenu. */
-GtkWidget *_menu_maps_submenu;
-GtkWidget *_menu_maps_mapman_item;
-GtkWidget *_menu_maps_repoman_item;
-GtkWidget *_menu_auto_download_item;
-
-/* Menu items for the "View" submenu. */
-GtkWidget *_menu_zoomin_item;
-GtkWidget *_menu_zoomout_item;
-GtkWidget *_menu_fullscreen_item;
-GtkWidget *_menu_show_scale_item;
-GtkWidget *_menu_show_routes_item;
-GtkWidget *_menu_show_tracks_item;
-GtkWidget *_menu_show_velvec_item;
-GtkWidget *_menu_show_poi_item;
-GtkWidget *_menu_poi_item;
-
 /* Toolbar items */
-GtkToolItem *_toolbar_fullscreen_item;
 GtkProgressBar *_progress_item;
 
-/* Menu items for the "Auto-Center" submenu. */
-GtkWidget *_menu_ac_latlon_item;
-GtkWidget *_menu_ac_lead_item;
-GtkWidget *_menu_ac_none_item;
-
-/* Menu items for the "Go to" submenu. */
-GtkWidget *_menu_goto_home;
-GtkWidget *_menu_goto_destination;
-GtkWidget *_menu_goto_address;
-GtkWidget *_menu_goto_latlon;
-GtkWidget *_menu_goto_gps;
-GtkWidget *_menu_goto_nextway;
-GtkWidget *_menu_goto_nearpoi;
-
-/* Menu items for the "GPS" submenu. */
-GtkWidget *_menu_enable_gps_item;
-GtkWidget *_menu_gps_show_info_item;
-GtkWidget *_menu_gps_details_item;
-GtkWidget *_menu_gps_reset_item;
-
-/* Menu items for the other menu items. */
-GtkWidget *_menu_settings_item;
-GtkWidget *_menu_help_item;
-GtkWidget *_menu_about_item;
-GtkWidget *_menu_close_item;
-
 /* Menu items for the "Location" context menu. */
 GtkWidget *_cmenu_loc_show_latlon_item;
 GtkWidget *_cmenu_loc_clip_latlon_item;
@@ -158,7 +95,6 @@ GtkWidget *_cmenu_loc_route_to_item;
 GtkWidget *_cmenu_loc_distance_to_item;
 GtkWidget *_cmenu_loc_add_route;
 GtkWidget *_cmenu_loc_add_way;
-GtkWidget *_cmenu_loc_add_poi;
 GtkWidget *_cmenu_loc_set_gps;
 GtkWidget *_cmenu_loc_set_destination;
 GtkWidget *_cmenu_loc_set_home;
@@ -179,6 +115,7 @@ GtkWidget *_cmenu_poi;
 GtkWidget *_cmenu_poi_edit_poi;
 GtkWidget *_cmenu_poi_route_to_item;
 GtkWidget *_cmenu_poi_distance_to_item;
+GtkWidget *_cmenu_loc_add_poi;
 GtkWidget *_cmenu_poi_add_route;
 GtkWidget *_cmenu_poi_add_way;
 GtkWidget *_cmenu_poi_goto_nearpoi;