~ubuntu-branches/ubuntu/trusty/gnomeradio/trusty

« back to all changes in this revision

Viewing changes to .pc/gnomeradio-media_types.patch/src/prefs.c

  • Committer: Package Import Robot
  • Author(s): POJAR GEORGE
  • Date: 2013-09-11 15:06:44 UTC
  • Revision ID: package-import@ubuntu.com-20130911150644-l8x3ubsyqmrvnkh8
Tags: 1.8-2ubuntu20
* Updated debian/patches/gnomeradio-station_list.patch: Prevent to parse
  malformed/incomplete/invalid XML file.
* Updated debian/patches/gnomeradio-auto_device.patch:
  - Automatically detect radio device when users type auto in settings field.
  - Updated error messages to be clear and precise.
* Updated debian/patches/gnomeradio-alsamixer.patch: Make presets list the
  default widget when open settings dialog. Presets are the most common
  settings for users than devices settings.
* Updated debian/patches/gnomeradio-about.patch: It is not safe in principle
  to write raw UTF-8 in narrow string literals, made to be multibyte
  encodings.
* debian/patches/gnomeradio-prefs.patch: Renamed to
  debian/patches/gnomeradio-about.patch.
* debian/patches/gnomeradio-preferences.patch: Make sentence capitalization in
  text and increased preferences dialog.

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
 
37
37
static GtkWidget *device_entry, *mixer_entry;
38
38
static GtkWidget *mute_on_exit_cb;
39
 
static GtkWidget *save_button, *move_up_button, *move_down_button, *remove_button;
 
39
static GtkWidget *save_button, *move_up_button, *move_down_button, *add_button, *remove_button;
40
40
static GtkWidget *list_view;
41
41
static GtkListStore *list_store;
42
42
static GtkTreeSelection *selection;
641
641
        GtkTreePath *path = NULL;
642
642
        GtkTreeViewColumn *focus_column = NULL;
643
643
        
644
 
        if (settings.presets == NULL) return;
 
644
        if (settings.presets == NULL)
 
645
                return;
645
646
 
646
647
        gtk_tree_view_get_cursor(GTK_TREE_VIEW(list_view), &path, &focus_column);
647
648
        
648
 
        if (!path) return;
 
649
        if (!path)
 
650
                return;
649
651
 
650
652
        row = gtk_tree_path_get_indices(path);
651
653
        g_assert(row);
683
685
        gtk_widget_set_sensitive(save_button, sel);
684
686
}
685
687
 
 
688
static void list_view_scroll_to_active_preset_cb(GtkWidget *widget, gpointer data)
 
689
{
 
690
        GtkTreePath *path = NULL;
 
691
        GtkTreeIter iter;
 
692
        gint active;
 
693
 
 
694
        if (settings.presets == NULL) {
 
695
                gtk_widget_grab_focus(add_button);
 
696
                return;
 
697
        }
 
698
 
 
699
        active = gtk_combo_box_get_active(GTK_COMBO_BOX(preset_combo)) - 1;
 
700
 
 
701
        if (active < 0) {
 
702
                gtk_widget_grab_focus(add_button);
 
703
                return;
 
704
        }
 
705
 
 
706
        if (!gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(list_store), &iter, NULL, active))
 
707
                return;
 
708
 
 
709
        path = gtk_tree_model_get_path(GTK_TREE_MODEL(list_store), &iter);
 
710
 
 
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);
 
714
 
 
715
        gtk_widget_grab_focus(list_view);
 
716
}
 
717
 
686
718
static void free_preset_list(gpointer data, gpointer user_data)
687
719
{
688
720
        preset *ps;
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;
849
883
 
850
884
        /* load the file */
851
885
        doc = xmlParseFile(filename);
852
886
        /* get the root item */
 
887
        if (doc == NULL)
 
888
                return;
 
889
 
853
890
        current = xmlDocGetRootElement(doc);
 
891
        if (current == NULL) {
 
892
                xmlFreeDoc(doc);
 
893
                return;
 
894
        }
854
895
 
855
 
        if (doc == NULL || current == NULL || xmlStrcmp(current->name, (guchar*)"gnomeradio"))
856
 
        {
 
896
        if (xmlStrcmp(current->name, (guchar*)"gnomeradio")) {
857
897
                xmlFreeDoc(doc);
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);
861
 
                g_free(caption);
862
 
                g_free(detail);
863
898
                return;
864
899
        }
865
900
 
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));
872
 
 
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);
878
 
 
879
 
                        menuitems = gtk_container_get_children(GTK_CONTAINER(tray_menu));
880
 
 
881
904
                        gint i, count;
882
 
                        count = g_list_length(menuitems);
 
905
 
 
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);
 
909
 
 
910
                        menuitems = gtk_container_get_children (GTK_CONTAINER (tray_menu));
 
911
 
 
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);
886
916
                        }
887
 
                }
 
917
                }
 
918
 
 
919
                gtk_list_store_clear(GTK_LIST_STORE(list_store));
 
920
 
 
921
                g_list_free_full (settings.presets, free_presets_list);
 
922
                settings.presets = NULL;
888
923
        }
889
924
 
890
925
        /* get the tree view's model */
892
927
 
893
928
        /* iterate through the root's children items */
894
929
        current = current->xmlChildrenNode;
895
 
        while (current)
896
 
        {
897
 
                /* check for the proper element name */
898
 
                if (!xmlStrcmp(current->name, (guchar*)"station"))
899
 
                {
900
 
                        /* get the saved properties */
901
 
                        title = xmlGetProp(current, (guchar*)"name");
902
 
                        freq = xmlGetProp(current, (guchar*)"freq");
903
 
                        position = xmlGetProp(current, (guchar*)"position");
904
 
 
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);
913
 
                        /* set the data */
914
 
                        gtk_list_store_set(GTK_LIST_STORE(list_store), &iter, 0, title, 1, freq, -1);
915
 
 
916
 
                        if (main_visible) {
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);
920
 
 
921
 
                                menuitem = gtk_menu_item_new_with_label(ps->title);
922
 
 
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);
 
930
        while (current) {
 
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");
 
938
 
 
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);
 
943
 
 
944
                                        settings.presets = g_list_append(settings.presets, ps);
 
945
 
 
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);
 
950
                                        /* set the data */
 
951
                                        gtk_list_store_set(GTK_LIST_STORE(list_store), &iter, 0, title, 1, freq, -1);
 
952
 
 
953
                                        gtk_tree_selection_unselect_all(selection);
 
954
 
 
955
                                        v_scb = gtk_scrollable_get_vadjustment(GTK_SCROLLABLE(list_view));
 
956
                                        gtk_adjustment_set_value(v_scb, gtk_adjustment_get_upper(v_scb));
 
957
 
 
958
                                        if (main_visible) {
 
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);
 
962
 
 
963
                                                menuitem = gtk_menu_item_new_with_label(title);
 
964
 
 
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);
 
970
                                        }
 
971
                                }
 
972
                                /* free the data */
 
973
                                xmlFree(title);
 
974
                                xmlFree(freq);
 
975
                                xmlFree(position);
926
976
                        }
927
 
                        /* free the data */
928
 
                        xmlFree(title);
929
 
                        xmlFree(freq);
930
 
                        xmlFree(position);
 
977
                        current = current->next;
931
978
                }
932
 
                current = current->next;
933
979
        }
934
980
        /* free the doc node */
935
981
        xmlFreeDoc(doc);
936
982
 
 
983
        if (settings.presets == NULL)
 
984
                return;
 
985
 
 
986
        path = gtk_tree_model_get_path(GTK_TREE_MODEL(list_store), &iter);
 
987
 
 
988
        gtk_tree_view_set_cursor(GTK_TREE_VIEW (list_view), path, NULL, FALSE );
 
989
        gtk_tree_path_free(path);
 
990
 
 
991
        gtk_widget_grab_focus(list_view);
 
992
 
 
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);
941
996
}
942
997
 
943
998
/* Callback for the "Load from file" button; calls load_from_file */
976
1031
        gtk_widget_destroy(dialog);
977
1032
}
978
1033
 
979
 
gboolean settings_device_cb (gint mode)
 
1034
gboolean action_mode (gint mode)
980
1035
{
981
1036
        switch (mode) {
982
1037
                case RADIO_DEVICE:
985
1040
                case MIXER_DEVICE:
986
1041
                        gtk_widget_grab_focus (mixer_entry);
987
1042
                        break;
 
1043
                case PRESETS:
 
1044
                        list_view_scroll_to_active_preset_cb(list_view, NULL);
 
1045
                        break;
988
1046
                default:
989
1047
                        break;
990
1048
        }
1005
1063
        GtkWidget *profile_eb;
1006
1064
        GtkWidget *device_label, *mixer_label;
1007
1065
        GtkWidget *button_box;
1008
 
        GtkWidget *open_button, *add_button;
 
1066
        GtkWidget *open_button;
1009
1067
        GtkWidget *scrolled_window;
1010
1068
        GtkCellRenderer *cellrenderer;
1011
1069
        GtkTreeViewColumn *list_column;