683
685
gtk_widget_set_sensitive(save_button, sel);
688
static void list_view_scroll_to_active_preset_cb(GtkWidget *widget, gpointer data)
690
GtkTreePath *path = NULL;
694
if (settings.presets == NULL) {
695
gtk_widget_grab_focus(add_button);
699
active = gtk_combo_box_get_active(GTK_COMBO_BOX(preset_combo)) - 1;
702
gtk_widget_grab_focus(add_button);
706
if (!gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(list_store), &iter, NULL, active))
709
path = gtk_tree_model_get_path(GTK_TREE_MODEL(list_store), &iter);
711
gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW (list_view), path, NULL, FALSE, 0, 0);
712
gtk_tree_view_set_cursor(GTK_TREE_VIEW (list_view), path, NULL, FALSE );
713
gtk_tree_path_free(path);
715
gtk_widget_grab_focus(list_view);
686
718
static void free_preset_list(gpointer data, gpointer user_data)
843
875
xmlNodePtr current;
844
876
xmlChar *title, *freq, *position;
845
877
GtkTreeModel *model;
878
GtkTreePath *path = NULL;
846
879
GtkTreeIter iter;
880
GtkAdjustment* v_scb;
847
881
GList* menuitems;
848
882
GtkWidget *menuitem;
850
884
/* load the file */
851
885
doc = xmlParseFile(filename);
852
886
/* get the root item */
853
890
current = xmlDocGetRootElement(doc);
891
if (current == NULL) {
855
if (doc == NULL || current == NULL || xmlStrcmp(current->name, (guchar*)"gnomeradio"))
896
if (xmlStrcmp(current->name, (guchar*)"gnomeradio")) {
858
char *caption = g_strdup_printf(_("Cannot parsing file \"%s\"."), filename);
859
char *detail = g_strdup_printf(_("To create FM radio station presets use \"Add preset\" button"));
860
show_error_message(caption, detail);
866
901
/* remove previous presets */
867
902
if (settings.presets != NULL) {
868
g_list_foreach(settings.presets, free_preset_list, NULL);
869
g_list_free(settings.presets);
870
settings.presets = NULL;
871
gtk_list_store_clear(GTK_LIST_STORE(list_store));
873
903
if (main_visible) {
874
gtk_combo_box_text_remove_all(GTK_COMBO_BOX_TEXT(preset_combo));
875
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(preset_combo), _("manual"));
876
mom_ps = g_list_length(settings.presets) - 1;
877
preset_combo_set_item(mom_ps);
879
menuitems = gtk_container_get_children(GTK_CONTAINER(tray_menu));
882
count = g_list_length(menuitems);
906
count = g_list_length (settings.presets);
907
for (i = 0; i < count; i++)
908
gtk_combo_box_text_remove(GTK_COMBO_BOX_TEXT(preset_combo), 1);
910
menuitems = gtk_container_get_children (GTK_CONTAINER (tray_menu));
912
count = g_list_length (menuitems);
883
913
for (i = 0; i < count - 6; i++) {
884
menuitem = g_list_nth_data(menuitems, i);
885
gtk_widget_destroy(menuitem);
914
menuitem = g_list_nth_data (menuitems, i);
915
gtk_widget_destroy (menuitem);
919
gtk_list_store_clear(GTK_LIST_STORE(list_store));
921
g_list_free_full (settings.presets, free_presets_list);
922
settings.presets = NULL;
890
925
/* get the tree view's model */
893
928
/* iterate through the root's children items */
894
929
current = current->xmlChildrenNode;
897
/* check for the proper element name */
898
if (!xmlStrcmp(current->name, (guchar*)"station"))
900
/* get the saved properties */
901
title = xmlGetProp(current, (guchar*)"name");
902
freq = xmlGetProp(current, (guchar*)"freq");
903
position = xmlGetProp(current, (guchar*)"position");
905
preset *ps = g_malloc0(sizeof(preset));
906
ps->title = g_strdup((gchar*)title);
907
ps->freq = atof((gchar*)freq);
908
settings.presets = g_list_append(settings.presets, ps);
909
/* make sure that the path exists */
910
gtk_tree_model_generate_path(model, (gchar*)position);
911
/* get an iter to the path */
912
gtk_tree_model_get_iter_from_string(model, &iter, (gchar*)position);
914
gtk_list_store_set(GTK_LIST_STORE(list_store), &iter, 0, title, 1, freq, -1);
917
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(preset_combo), ps->title);
918
mom_ps = g_list_length(settings.presets) - 1;
919
preset_combo_set_item(mom_ps);
921
menuitem = gtk_menu_item_new_with_label(ps->title);
923
gtk_menu_shell_insert(GTK_MENU_SHELL(tray_menu), menuitem, mom_ps);
924
g_signal_connect(G_OBJECT(menuitem), "activate", (GCallback)preset_menuitem_activate_cb, GINT_TO_POINTER (mom_ps));
925
gtk_widget_show(menuitem);
931
if(!xmlIsBlankNode(current)) {
932
/* check for the proper element name */
933
if (!xmlStrcmp(current->name, (guchar*)"station")) {
934
/* get the saved properties */
935
title = xmlGetProp(current, (guchar*)"name");
936
freq = xmlGetProp(current, (guchar*)"freq");
937
position = xmlGetProp(current, (guchar*)"position");
939
if( title && freq && position ) {
940
preset *ps = g_malloc0(sizeof(preset));
941
ps->title = g_strdup((gchar*)title);
942
ps->freq = atof((gchar*)freq);
944
settings.presets = g_list_append(settings.presets, ps);
946
/* make sure that the path exists */
947
gtk_tree_model_generate_path(model, (gchar*)position);
948
/* get an iter to the path */
949
gtk_tree_model_get_iter_from_string(model, &iter, (gchar*)position);
951
gtk_list_store_set(GTK_LIST_STORE(list_store), &iter, 0, title, 1, freq, -1);
953
gtk_tree_selection_unselect_all(selection);
955
v_scb = gtk_scrollable_get_vadjustment(GTK_SCROLLABLE(list_view));
956
gtk_adjustment_set_value(v_scb, gtk_adjustment_get_upper(v_scb));
959
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(preset_combo), title);
960
mom_ps = g_list_length(settings.presets) - 1;
961
preset_combo_set_item(mom_ps);
963
menuitem = gtk_menu_item_new_with_label(title);
965
gtk_menu_shell_insert(GTK_MENU_SHELL(tray_menu), menuitem, mom_ps);
966
g_signal_connect(G_OBJECT(menuitem), "activate",
967
(GCallback)preset_menuitem_activate_cb,
968
GINT_TO_POINTER (mom_ps));
969
gtk_widget_show(menuitem);
977
current = current->next;
932
current = current->next;
934
980
/* free the doc node */
983
if (settings.presets == NULL)
986
path = gtk_tree_model_get_path(GTK_TREE_MODEL(list_store), &iter);
988
gtk_tree_view_set_cursor(GTK_TREE_VIEW (list_view), path, NULL, FALSE );
989
gtk_tree_path_free(path);
991
gtk_widget_grab_focus(list_view);
993
list_view_cursor_changed_cb(list_view, NULL);
937
994
gtk_widget_set_sensitive(save_button, TRUE);
938
gtk_widget_set_sensitive(remove_button, FALSE);
939
gtk_widget_set_sensitive(move_up_button, FALSE);
940
gtk_widget_set_sensitive(move_down_button, FALSE);
995
gtk_widget_set_sensitive(remove_button, TRUE);
943
998
/* Callback for the "Load from file" button; calls load_from_file */