22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
1 |
/*
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
2 |
* Copyright (c) Linux community.
|
3 |
*
|
|
4 |
* This library is free software; you can redistribute it and/or
|
|
5 |
* modify it under the terms of the GNU Library General Public
|
|
6 |
* License as published by the Free Software Foundation; either
|
|
7 |
* version 2 of the License, or (at your option) any later version.
|
|
8 |
*
|
|
9 |
* This library is distributed in the hope that it will be useful,
|
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
12 |
* Library General Public License for more details.
|
|
13 |
*
|
|
14 |
* You should have received a copy of the GNU Library General Public
|
|
15 |
* License along with this library; if not, write to the
|
|
16 |
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
17 |
* Boston, MA 02111-1307, USA.
|
|
18 |
*/
|
|
19 |
#include "media-profiles.h" |
|
20 |
#include "log.h" |
|
21 |
||
22 |
// Get media-profiles from the GNOME's media library (from the libgnome-media-dev package).
|
|
23 |
// You can find these values in the the GConf registry.
|
|
24 |
// Start gconf-editor and browse to: system -> gstreamer -> 0.10 -> audio -> profiles.
|
|
25 |
||
26 |
// Keep a list of supported media profiles (audio formats)
|
|
27 |
static GList *media_profiles_list = NULL; |
|
28 |
||
29 |
void media_profiles_init() { |
|
30 |
LOG_DEBUG("Init media-profiles.c.\n"); |
|
31 |
||
32 |
// Init GNOME's media profiles module
|
|
33 |
gnome_media_profiles_init(NULL); |
|
34 |
}
|
|
35 |
||
36 |
void media_profiles_exit() { |
|
37 |
LOG_DEBUG("Clean up media-profiles.c.\n"); |
|
38 |
||
39 |
// Clean up. Free the list, do not touch data items.
|
|
40 |
if (media_profiles_list) |
|
41 |
g_list_free(media_profiles_list); |
|
42 |
media_profiles_list = NULL; |
|
43 |
}
|
|
44 |
||
45 |
void media_profiles_load() { |
|
46 |
// Load _active_ media profiles (audio formats)
|
|
47 |
if (media_profiles_list) return; |
|
48 |
||
49 |
// Ref: http://www.susaaland.dk/sharedoc/gnome-media-2.10.2/ChangeLog
|
|
50 |
media_profiles_list = gm_audio_profile_get_active_list(); |
|
51 |
}
|
|
52 |
||
53 |
GMAudioProfile *media_profiles_get_profile(gchar *id) { |
|
54 |
// Return media profile for the given id.
|
|
55 |
// See: gconf-editor, key: system -> gstreamer -> 0.10 -> audio -> profiles.
|
|
56 |
GMAudioProfile *profile = gm_audio_profile_lookup(id); |
|
57 |
||
58 |
// Do not free this value.
|
|
59 |
return profile; |
|
60 |
}
|
|
61 |
||
62 |
gchar *media_profiles_get_extension(gchar *id) { |
|
63 |
// Return file extension (such as .mp3, .ogg, .m4a) for the given profile id.
|
|
64 |
// See: gconf-editor, key: system -> gstreamer -> 0.10 -> audio -> profiles (value for extension).
|
|
65 |
const gchar *extension = NULL; |
|
66 |
||
67 |
GMAudioProfile *profile = gm_audio_profile_lookup(id); |
|
68 |
if (profile) |
|
69 |
extension = gm_audio_profile_get_extension(profile); |
|
70 |
||
71 |
// The caller should g_free() this value
|
|
72 |
return g_strdup(extension); |
|
73 |
}
|
|
74 |
||
75 |
gchar *media_profiles_get_pipeline(gchar *id) { |
|
76 |
// Return partial GStreamer pipeline for the given id.
|
|
77 |
// See: gconf-editor, key: system -> gstreamer -> 0.10 -> audio -> profiles (value for pipeline).
|
|
78 |
const gchar *pipeline = NULL; |
|
79 |
||
80 |
GMAudioProfile *profile = gm_audio_profile_lookup(id); |
|
81 |
if (profile) |
|
82 |
pipeline = gm_audio_profile_get_pipeline(profile); |
|
83 |
||
84 |
// The caller should g_free() this value
|
|
85 |
return g_strdup(pipeline); |
|
86 |
}
|
|
87 |
||
88 |
void media_profiles_add_data(GtkListStore *store) { |
|
89 |
// Fill the list store with _active_ media profiles (audio format ids and names).
|
|
90 |
||
91 |
media_profiles_load(); |
|
92 |
||
93 |
GtkTreeIter iter; |
|
94 |
||
95 |
GList *item = g_list_first(media_profiles_list); |
|
96 |
while (item) { |
|
97 |
GMAudioProfile *profile = (GMAudioProfile*)item->data; |
|
98 |
||
99 |
const gchar *id = gm_audio_profile_get_id(profile); |
|
100 |
const gchar *name = gm_audio_profile_get_name(profile); |
|
101 |
const gchar *extension = gm_audio_profile_get_extension(profile); |
|
102 |
||
103 |
// Typical audio format list is
|
|
104 |
// CD Quality, AAC (.m4a)
|
|
105 |
// CD Quality, Lossless (.flac)
|
|
106 |
// CD Quality, Lossy (.ogg)
|
|
107 |
// CD Quality, MP2 (.mp2)
|
|
108 |
// CD Quality, MP3 (.mp3)
|
|
109 |
// Voice, Lossless (.wav)
|
|
110 |
// Voice, Lossy (.spx)
|
|
111 |
||
112 |
gchar *e = g_utf8_strup(extension, -1); |
|
113 |
gchar *n = g_utf8_strdown(name, -1); |
|
114 |
gchar *txt = g_strdup_printf(".%s (%s)", e, n); |
|
115 |
||
116 |
// Add OGG type "CD Quality, Lossy" as first (becomes default)
|
|
117 |
if (!g_strcmp0(extension, "ogg") || !g_strcmp0(extension, "oga")) { |
|
118 |
gtk_list_store_prepend(GTK_LIST_STORE(store), &iter); |
|
119 |
} else { |
|
120 |
// Add last
|
|
121 |
gtk_list_store_append(GTK_LIST_STORE(store), &iter); |
|
122 |
}
|
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
123 |
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
124 |
gtk_list_store_set(GTK_LIST_STORE(store), &iter, 0, id, 1, txt, -1); |
125 |
||
126 |
g_free(txt); |
|
127 |
g_free(e); |
|
128 |
g_free(n); |
|
129 |
||
130 |
item = g_list_next(item); |
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
131 |
}
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
132 |
}
|
133 |
||
134 |
gchar *media_profiles_get_selected_id(GtkWidget *widget) { |
|
135 |
// Return selected GMAudioProfile id (audio format id)
|
|
136 |
||
137 |
GtkComboBox *combo = GTK_COMBO_BOX(widget); |
|
138 |
g_return_val_if_fail (GTK_IS_COMBO_BOX(combo), NULL); |
|
139 |
||
140 |
GtkTreeIter iter; |
|
141 |
gchar *id = NULL; |
|
142 |
||
143 |
if (!gtk_combo_box_get_active_iter(combo, &iter)) return NULL; |
|
144 |
||
145 |
gtk_tree_model_get(gtk_combo_box_get_model(combo), &iter, COL_PROFILE_ID, &id, -1); |
|
146 |
||
147 |
// The caller should g_free() this value
|
|
148 |
return id; |
|
149 |
}
|
|
150 |
||
151 |
GtkWidget *media_profiles_create_combobox() { |
|
152 |
// Create a GtkComboBox with N_PROFILE_COLUMNS. Populate it with supported audio formats.
|
|
153 |
||
154 |
// Create list store
|
|
155 |
GtkListStore *store = gtk_list_store_new(N_PROFILE_COLUMNS, G_TYPE_STRING, G_TYPE_STRING); |
|
156 |
||
157 |
// Get audio formats (media profiles) and add to the store
|
|
158 |
media_profiles_add_data(store); |
|
159 |
||
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
160 |
GtkWidget *combo = gtk_combo_box_new_with_model(GTK_TREE_MODEL(store)); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
161 |
|
162 |
// Unref store
|
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
163 |
g_object_unref(store); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
164 |
|
165 |
// "Id" column, invisible
|
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
166 |
GtkCellRenderer *cell = gtk_cell_renderer_text_new(); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
167 |
g_object_set(cell, "visible", 0, NULL); |
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
168 |
gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), cell, TRUE); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
169 |
gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo), cell, "text", COL_PROFILE_ID, NULL); |
170 |
||
171 |
// "Name" column, visible
|
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
172 |
cell = gtk_cell_renderer_text_new(); |
173 |
gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), cell, TRUE); |
|
174 |
gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo), cell, "text", COL_PROFILE_TXT, NULL); |
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
175 |
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
176 |
return combo; |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
177 |
}
|
178 |
||
179 |