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

« back to all changes in this revision

Viewing changes to .pc/gnomeradio-auto_device.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:
35
35
 
36
36
extern int mom_ps;
37
37
extern gnomeradio_settings settings;
 
38
 
38
39
extern gboolean main_visible;
39
40
 
40
41
static GtkWidget *device_entry;
46
47
static GtkWidget *save_button;
47
48
static GtkWidget *move_up_button;
48
49
static GtkWidget *move_down_button;
 
50
static GtkWidget *add_button;
49
51
static GtkWidget *remove_button;
50
52
static GtkWidget *audio_profile_combo;
51
53
static GtkWidget *install_button;
772
774
        GtkTreePath *path = NULL;
773
775
        GtkTreeViewColumn *focus_column = NULL;
774
776
        
775
 
        if (settings.presets == NULL) return;
 
777
        if (settings.presets == NULL)
 
778
                return;
776
779
 
777
780
        gtk_tree_view_get_cursor(GTK_TREE_VIEW(list_view), &path, &focus_column);
778
781
        
779
 
        if (!path) return;
 
782
        if (!path)
 
783
                return;
780
784
 
781
785
        row = gtk_tree_path_get_indices(path);
782
786
        g_assert(row);
814
818
        gtk_widget_set_sensitive(save_button, sel);
815
819
}
816
820
 
 
821
static void list_view_scroll_to_active_preset_cb(GtkWidget *widget, gpointer data)
 
822
{
 
823
        GtkTreePath *path = NULL;
 
824
        GtkTreeIter iter;
 
825
        gint active;
 
826
 
 
827
        if (settings.presets == NULL) {
 
828
                gtk_widget_grab_focus(add_button);
 
829
                return;
 
830
        }
 
831
 
 
832
        active = gtk_combo_box_get_active(GTK_COMBO_BOX(preset_combo)) - 1;
 
833
 
 
834
        if (active < 0) {
 
835
                gtk_widget_grab_focus(add_button);
 
836
                return;
 
837
        }
 
838
 
 
839
        if (!gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(list_store), &iter, NULL, active))
 
840
                return;
 
841
 
 
842
        path = gtk_tree_model_get_path(GTK_TREE_MODEL(list_store), &iter);
 
843
 
 
844
        gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW (list_view), path, NULL, FALSE, 0, 0);
 
845
        gtk_tree_view_set_cursor(GTK_TREE_VIEW (list_view), path, NULL, FALSE );
 
846
        gtk_tree_path_free(path);
 
847
 
 
848
        gtk_widget_grab_focus(list_view);
 
849
}
 
850
 
817
851
static void free_presets_list (gpointer data)
818
852
{
819
853
        preset *ps = (preset *) data;
972
1006
        xmlNodePtr current;
973
1007
        xmlChar *title, *freq, *position;
974
1008
        GtkTreeModel *model;
 
1009
        GtkTreePath *path = NULL;
975
1010
        GtkTreeIter iter;
 
1011
        GtkAdjustment* v_scb;
976
1012
        GList* menuitems;
977
1013
        GtkWidget *menuitem;
978
1014
 
979
1015
        /* load the file */
980
1016
        doc = xmlParseFile(filename);
981
1017
        /* get the root item */
 
1018
        if (doc == NULL)
 
1019
                return;
 
1020
 
982
1021
        current = xmlDocGetRootElement(doc);
 
1022
        if (current == NULL) {
 
1023
                xmlFreeDoc(doc);
 
1024
                return;
 
1025
        }
983
1026
 
984
 
        if (doc == NULL || current == NULL || xmlStrcmp(current->name, (guchar*)"gnomeradio"))
985
 
        {
 
1027
        if (xmlStrcmp(current->name, (guchar*)"gnomeradio")) {
986
1028
                xmlFreeDoc(doc);
987
 
                char *caption = g_strdup_printf(_("Cannot parsing file \"%s\"."), filename);
988
 
                char *detail = g_strdup_printf(_("To create FM radio station presets use \"Add preset\" button"));
989
 
                show_error_message(caption, detail);
990
 
                g_free(caption);
991
 
                g_free(detail);
992
1029
                return;
993
1030
        }
994
1031
 
995
1032
        /* remove previous presets */
996
1033
        if (settings.presets != NULL) {
997
 
                g_list_free_full (settings.presets, free_presets_list);
998
 
                settings.presets = NULL;
999
 
 
1000
 
                gtk_list_store_clear(GTK_LIST_STORE(list_store));
1001
 
 
1002
1034
                if (main_visible) {
1003
 
                        gtk_combo_box_text_remove_all(GTK_COMBO_BOX_TEXT(preset_combo));
1004
 
                        gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(preset_combo), _("manual"));
1005
 
                        mom_ps = g_list_length(settings.presets) - 1;
1006
 
                        preset_combo_set_item(mom_ps);
1007
 
 
1008
 
                        menuitems = gtk_container_get_children(GTK_CONTAINER(tray_menu));
1009
 
 
1010
1035
                        gint i, count;
1011
 
                        count = g_list_length(menuitems);
 
1036
 
 
1037
                        count = g_list_length (settings.presets);
 
1038
                        for (i = 0; i < count; i++)
 
1039
                                gtk_combo_box_text_remove(GTK_COMBO_BOX_TEXT(preset_combo), 1);
 
1040
 
 
1041
                        menuitems = gtk_container_get_children (GTK_CONTAINER (tray_menu));
 
1042
 
 
1043
                        count = g_list_length (menuitems);
1012
1044
                        for (i = 0; i < count - 6; i++) {
1013
 
                                menuitem = g_list_nth_data(menuitems, i);
1014
 
                                gtk_widget_destroy(menuitem);
 
1045
                                menuitem = g_list_nth_data (menuitems, i);
 
1046
                                gtk_widget_destroy (menuitem);
1015
1047
                        }
1016
 
                }
 
1048
                }
 
1049
 
 
1050
                gtk_list_store_clear(GTK_LIST_STORE(list_store));
 
1051
 
 
1052
                g_list_free_full (settings.presets, free_presets_list);
 
1053
                settings.presets = NULL;
1017
1054
        }
1018
1055
 
1019
1056
        /* get the tree view's model */
1021
1058
 
1022
1059
        /* iterate through the root's children items */
1023
1060
        current = current->xmlChildrenNode;
1024
 
        while (current)
1025
 
        {
1026
 
                /* check for the proper element name */
1027
 
                if (!xmlStrcmp(current->name, (guchar*)"station"))
1028
 
                {
1029
 
                        /* get the saved properties */
1030
 
                        title = xmlGetProp(current, (guchar*)"name");
1031
 
                        freq = xmlGetProp(current, (guchar*)"freq");
1032
 
                        position = xmlGetProp(current, (guchar*)"position");
1033
 
 
1034
 
                        preset *ps = g_malloc0(sizeof(preset));
1035
 
                        ps->title = g_strdup((gchar*)title);
1036
 
                        ps->freq = atof((gchar*)freq);
1037
 
 
1038
 
                        settings.presets = g_list_prepend(settings.presets, ps);
1039
 
 
1040
 
                        /* make sure that the path exists */
1041
 
                        gtk_tree_model_generate_path(model, (gchar*)position);
1042
 
                        /* get an iter to the path */
1043
 
                        gtk_tree_model_get_iter_from_string(model, &iter, (gchar*)position);
1044
 
                        /* set the data */
1045
 
                        gtk_list_store_set(GTK_LIST_STORE(list_store), &iter, 0, title, 1, freq, -1);
1046
 
 
1047
 
                        if (main_visible) {
1048
 
                                gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(preset_combo), ps->title);
1049
 
                                mom_ps = g_list_length(settings.presets) - 1;
1050
 
                                preset_combo_set_item(mom_ps);
1051
 
 
1052
 
                                menuitem = gtk_menu_item_new_with_label(ps->title);
1053
 
 
1054
 
                                gtk_menu_shell_insert(GTK_MENU_SHELL(tray_menu), menuitem, mom_ps);
1055
 
                                g_signal_connect(G_OBJECT(menuitem), "activate", (GCallback)preset_menuitem_activate_cb, GINT_TO_POINTER (mom_ps));
1056
 
                                gtk_widget_show(menuitem);
 
1061
        while (current) {
 
1062
                if(!xmlIsBlankNode(current)) {
 
1063
                        /* check for the proper element name */
 
1064
                        if (!xmlStrcmp(current->name, (guchar*)"station")) {
 
1065
                                /* get the saved properties */
 
1066
                                title = xmlGetProp(current, (guchar*)"name");
 
1067
                                freq = xmlGetProp(current, (guchar*)"freq");
 
1068
                                position = xmlGetProp(current, (guchar*)"position");
 
1069
 
 
1070
                                if( title && freq && position ) {
 
1071
                                        preset *ps = g_malloc0(sizeof(preset));
 
1072
                                        ps->title = g_strdup((gchar*)title);
 
1073
                                        ps->freq = atof((gchar*)freq);
 
1074
 
 
1075
                                        settings.presets = g_list_append(settings.presets, ps);
 
1076
 
 
1077
                                        /* make sure that the path exists */
 
1078
                                        gtk_tree_model_generate_path(model, (gchar*)position);
 
1079
                                        /* get an iter to the path */
 
1080
                                        gtk_tree_model_get_iter_from_string(model, &iter, (gchar*)position);
 
1081
                                        /* set the data */
 
1082
                                        gtk_list_store_set(GTK_LIST_STORE(list_store), &iter, 0, title, 1, freq, -1);
 
1083
 
 
1084
                                        gtk_tree_selection_unselect_all(selection);
 
1085
 
 
1086
                                        v_scb = gtk_scrollable_get_vadjustment(GTK_SCROLLABLE(list_view));
 
1087
                                        gtk_adjustment_set_value(v_scb, gtk_adjustment_get_upper(v_scb));
 
1088
 
 
1089
                                        if (main_visible) {
 
1090
                                                gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(preset_combo), title);
 
1091
                                                mom_ps = g_list_length(settings.presets) - 1;
 
1092
                                                preset_combo_set_item(mom_ps);
 
1093
 
 
1094
                                                menuitem = gtk_menu_item_new_with_label(title);
 
1095
 
 
1096
                                                gtk_menu_shell_insert(GTK_MENU_SHELL(tray_menu), menuitem, mom_ps);
 
1097
                                                g_signal_connect(G_OBJECT(menuitem), "activate",
 
1098
                                                                 (GCallback)preset_menuitem_activate_cb,
 
1099
                                                                 GINT_TO_POINTER (mom_ps));
 
1100
                                                gtk_widget_show(menuitem);
 
1101
                                        }
 
1102
                                }
 
1103
                                /* free the data */
 
1104
                                xmlFree(title);
 
1105
                                xmlFree(freq);
 
1106
                                xmlFree(position);
1057
1107
                        }
1058
 
                        /* free the data */
1059
 
                        xmlFree(title);
1060
 
                        xmlFree(freq);
1061
 
                        xmlFree(position);
 
1108
                        current = current->next;
1062
1109
                }
1063
 
                current = current->next;
1064
1110
        }
1065
1111
        /* free the doc node */
1066
1112
        xmlFreeDoc(doc);
1067
1113
 
1068
 
        settings.presets = g_list_reverse(settings.presets);
1069
 
 
 
1114
        if (settings.presets == NULL)
 
1115
                return;
 
1116
 
 
1117
        path = gtk_tree_model_get_path(GTK_TREE_MODEL(list_store), &iter);
 
1118
 
 
1119
        gtk_tree_view_set_cursor(GTK_TREE_VIEW (list_view), path, NULL, FALSE );
 
1120
        gtk_tree_path_free(path);
 
1121
 
 
1122
        gtk_widget_grab_focus(list_view);
 
1123
 
 
1124
        list_view_cursor_changed_cb(list_view, NULL);
1070
1125
        gtk_widget_set_sensitive(save_button, TRUE);
1071
 
        gtk_widget_set_sensitive(remove_button, FALSE);
1072
 
        gtk_widget_set_sensitive(move_up_button, FALSE);
1073
 
        gtk_widget_set_sensitive(move_down_button, FALSE);
 
1126
        gtk_widget_set_sensitive(remove_button, TRUE);
1074
1127
}
1075
1128
 
1076
1129
/* Callback for the "Load from file" button; calls load_from_file */
1109
1162
        gtk_widget_destroy(dialog);
1110
1163
}
1111
1164
 
1112
 
gboolean settings_device_cb (gint mode)
 
1165
gboolean action_mode (gint mode)
1113
1166
{
1114
1167
        switch (mode) {
1115
1168
                case RADIO_DEVICE:
1118
1171
                case MIXER_DEVICE:
1119
1172
                        gtk_widget_grab_focus (mixer_entry);
1120
1173
                        break;
 
1174
                case PRESETS:
 
1175
                        list_view_scroll_to_active_preset_cb(list_view, NULL);
 
1176
                        break;
1121
1177
                default:
1122
1178
                        break;
1123
1179
        }
1136
1192
        GtkCellRenderer *cellrenderer;
1137
1193
        GtkTreeViewColumn *list_column;
1138
1194
        GtkWidget *button_box;
1139
 
        GtkWidget *open_button, *add_button;
 
1195
        GtkWidget *open_button;
1140
1196
        GtkWidget *destination_button;
1141
1197
        GtkWidget *image;
1142
1198
 
1143
1199
        GstEncodingProfile *profile;
 
1200
 
1144
1201
        gint i;
1145
1202
        gchar *markup;
1146
1203
        preset* ps;