diff options
Diffstat (limited to 'src/plugins/fs/extensions/musicinsert.c')
-rw-r--r-- | src/plugins/fs/extensions/musicinsert.c | 782 |
1 files changed, 782 insertions, 0 deletions
diff --git a/src/plugins/fs/extensions/musicinsert.c b/src/plugins/fs/extensions/musicinsert.c new file mode 100644 index 00000000..002bf8e9 --- /dev/null +++ b/src/plugins/fs/extensions/musicinsert.c | |||
@@ -0,0 +1,782 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2005 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 2, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file src/musicinsert.c | ||
23 | * @brief Music insertion dialog for gnunet-gtk | ||
24 | * @author Milan Bouchet | ||
25 | */ | ||
26 | |||
27 | |||
28 | #ifdef HAVE_CONFIG_H | ||
29 | # include <config.h> | ||
30 | #endif | ||
31 | |||
32 | #include <gtk/gtk.h> | ||
33 | #include <glade/glade.h> | ||
34 | #include <glib-object.h> | ||
35 | #include <glib.h> | ||
36 | |||
37 | #include <stdio.h> | ||
38 | #include <stdlib.h> | ||
39 | #include <string.h> | ||
40 | #include <unistd.h> | ||
41 | |||
42 | #include <extractor.h> | ||
43 | |||
44 | #include "main.h" | ||
45 | |||
46 | /* platform.h will be needed */ | ||
47 | |||
48 | #define _ | ||
49 | |||
50 | int | ||
51 | main (int argc, char *argv[]) | ||
52 | { | ||
53 | |||
54 | |||
55 | |||
56 | gtk_init(&argc, &argv); | ||
57 | |||
58 | show_musicinsertdialog (); | ||
59 | |||
60 | gtk_main (); | ||
61 | return 0; | ||
62 | } | ||
63 | |||
64 | void show_musicinsertdialog () | ||
65 | { | ||
66 | musicinsertXML = glade_xml_new("../musicinsert.glade", "musicinsertdialog", NULL); | ||
67 | glade_xml_signal_autoconnect(musicinsertXML); | ||
68 | /* libglade*/ | ||
69 | |||
70 | |||
71 | gtk_set_locale (); | ||
72 | |||
73 | /* | ||
74 | * The following code was added by Glade to create one of each component | ||
75 | * (except popup menus), just so that you see something after building | ||
76 | * the project. Delete any components that you don't want shown initially. | ||
77 | */ | ||
78 | //musicinsertdialog = create_musicinsertdialog (); | ||
79 | GtkWidget *musicinsertdialog; | ||
80 | musicinsertdialog = glade_xml_get_widget(musicinsertXML, "musicinsertdialog"); | ||
81 | |||
82 | /* | ||
83 | * Create the 3 ComboBoxEntry manually (libglade doesn't handle this well : | ||
84 | * should use gtk_combo_box_entry_new_text instead of gtk_combo_box_entry_new) | ||
85 | */ | ||
86 | artistcombobox = GTK_COMBO_BOX_ENTRY(gtk_combo_box_entry_new_text ()); | ||
87 | albumcombobox = GTK_COMBO_BOX_ENTRY(gtk_combo_box_entry_new_text ()); | ||
88 | typecombobox = GTK_COMBO_BOX_ENTRY(gtk_combo_box_entry_new_text ()); | ||
89 | |||
90 | gtk_combo_box_append_text (GTK_COMBO_BOX(typecombobox), "Ogg (application/ogg)"); | ||
91 | gtk_combo_box_append_text (GTK_COMBO_BOX(typecombobox), "MP3 (audio/mpeg)"); | ||
92 | gtk_combo_box_append_text (GTK_COMBO_BOX(typecombobox), "MPC (application/x-musepack)"); | ||
93 | gtk_combo_box_append_text (GTK_COMBO_BOX(typecombobox), "AAC"); | ||
94 | gtk_combo_box_append_text (GTK_COMBO_BOX(typecombobox), "WMA (audio/x-ms-wma)"); | ||
95 | gtk_combo_box_append_text (GTK_COMBO_BOX(typecombobox), "FLAC (audio/flac)"); | ||
96 | gtk_combo_box_append_text (GTK_COMBO_BOX(typecombobox), "APE"); | ||
97 | gtk_combo_box_append_text (GTK_COMBO_BOX(typecombobox), "WAV (application/x-wav)"); | ||
98 | gtk_combo_box_append_text (GTK_COMBO_BOX(typecombobox), "REAL (audio/vnd.rn-realaudio)"); | ||
99 | gtk_combo_box_append_text (GTK_COMBO_BOX(typecombobox), "MIDI (audio/x-midi)"); | ||
100 | |||
101 | GtkWidget *globaltable = glade_xml_get_widget (musicinsertXML, "globaltable"); | ||
102 | gtk_table_attach (GTK_TABLE(globaltable), GTK_WIDGET(artistcombobox), 1, 3, 1, 2, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0); | ||
103 | gtk_table_attach (GTK_TABLE(globaltable), GTK_WIDGET(albumcombobox), 1, 3, 2, 3, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0); | ||
104 | gtk_table_attach (GTK_TABLE(globaltable), GTK_WIDGET(typecombobox), 1, 3, 3, 4, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0); | ||
105 | |||
106 | gtk_widget_show (GTK_WIDGET(artistcombobox)); | ||
107 | gtk_widget_show (GTK_WIDGET(albumcombobox)); | ||
108 | gtk_widget_show (GTK_WIDGET(typecombobox)); | ||
109 | |||
110 | /* | ||
111 | * treeview creation | ||
112 | */ | ||
113 | |||
114 | /* liststore model */ | ||
115 | filelist_store = | ||
116 | gtk_list_store_new (COLS_NUMBER, G_TYPE_STRING, G_TYPE_STRING, | ||
117 | G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, | ||
118 | G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); | ||
119 | |||
120 | /* view */ | ||
121 | GtkWidget *filelist = glade_xml_get_widget (musicinsertXML, "filelist"); | ||
122 | gtk_tree_view_set_model (GTK_TREE_VIEW (filelist), | ||
123 | GTK_TREE_MODEL (filelist_store)); | ||
124 | |||
125 | /* cells definition */ | ||
126 | GtkCellRenderer *filename_renderer = gtk_cell_renderer_text_new (); | ||
127 | g_object_set (filename_renderer, "editable", TRUE, NULL); | ||
128 | GtkCellRenderer *title_renderer = gtk_cell_renderer_text_new (); | ||
129 | g_object_set (title_renderer, "editable", TRUE, NULL); | ||
130 | GtkCellRenderer *artist_renderer = gtk_cell_renderer_text_new (); | ||
131 | g_object_set (artist_renderer, "editable", TRUE, NULL); | ||
132 | GtkCellRenderer *album_renderer = gtk_cell_renderer_text_new (); | ||
133 | g_object_set (album_renderer, "editable", TRUE, NULL); | ||
134 | GtkCellRenderer *type_renderer = gtk_cell_renderer_text_new (); | ||
135 | g_object_set (type_renderer, "editable", TRUE, NULL); | ||
136 | GtkCellRenderer *format_renderer = gtk_cell_renderer_text_new (); | ||
137 | g_object_set (format_renderer, "editable", TRUE, NULL); | ||
138 | GtkCellRenderer *keywords_renderer = gtk_cell_renderer_text_new (); | ||
139 | g_object_set (keywords_renderer, "editable", TRUE, NULL); | ||
140 | |||
141 | |||
142 | g_signal_connect ((gpointer) filename_renderer, "edited", | ||
143 | G_CALLBACK (on_renderer_edited), (gpointer) &filename_col_num); | ||
144 | g_signal_connect ((gpointer) title_renderer, "edited", | ||
145 | G_CALLBACK (on_renderer_edited), (gpointer) &title_col_num); | ||
146 | g_signal_connect ((gpointer) artist_renderer, "edited", | ||
147 | G_CALLBACK (on_renderer_edited), (gpointer) &artist_col_num); | ||
148 | g_signal_connect ((gpointer) album_renderer, "edited", | ||
149 | G_CALLBACK (on_renderer_edited), (gpointer) &album_col_num); | ||
150 | g_signal_connect ((gpointer) type_renderer, "edited", | ||
151 | G_CALLBACK (on_renderer_edited), (gpointer) &type_col_num); | ||
152 | g_signal_connect ((gpointer) format_renderer, "edited", | ||
153 | G_CALLBACK (on_renderer_edited), (gpointer) &format_col_num); | ||
154 | g_signal_connect ((gpointer) keywords_renderer, "edited", | ||
155 | G_CALLBACK (on_renderer_edited), (gpointer) &keywords_col_num); | ||
156 | |||
157 | /* columns definition */ | ||
158 | filename_list_col = | ||
159 | gtk_tree_view_column_new_with_attributes (_("Published filename"), | ||
160 | filename_renderer, | ||
161 | "text", FILENAME_COL, NULL); | ||
162 | title_list_col = | ||
163 | gtk_tree_view_column_new_with_attributes (_("Title"), | ||
164 | title_renderer, | ||
165 | "text", TITLE_COL, NULL); | ||
166 | artist_list_col = | ||
167 | gtk_tree_view_column_new_with_attributes (_("Artist"), | ||
168 | artist_renderer, | ||
169 | "text", ARTIST_COL, NULL); | ||
170 | album_list_col = | ||
171 | gtk_tree_view_column_new_with_attributes (_("Album"), | ||
172 | album_renderer, | ||
173 | "text", ALBUM_COL, NULL); | ||
174 | type_list_col = | ||
175 | gtk_tree_view_column_new_with_attributes (_("Type"), | ||
176 | type_renderer, | ||
177 | "text", TYPE_COL, NULL); | ||
178 | format_list_col = | ||
179 | gtk_tree_view_column_new_with_attributes (_("Format"), | ||
180 | format_renderer, | ||
181 | "text", FORMAT_COL, NULL); | ||
182 | keywords_list_col = | ||
183 | gtk_tree_view_column_new_with_attributes (_("Keywords"), | ||
184 | keywords_renderer, | ||
185 | "text", KEYWORDS_COL, NULL); | ||
186 | |||
187 | /* Allow sorting for all columns */ | ||
188 | gtk_tree_view_column_set_sort_column_id (filename_list_col, FILENAME_COL); | ||
189 | gtk_tree_view_column_set_sort_column_id (title_list_col, TITLE_COL); | ||
190 | gtk_tree_view_column_set_sort_column_id (artist_list_col, ARTIST_COL); | ||
191 | gtk_tree_view_column_set_sort_column_id (album_list_col, ALBUM_COL); | ||
192 | gtk_tree_view_column_set_sort_column_id (type_list_col, TYPE_COL); | ||
193 | gtk_tree_view_column_set_sort_column_id (format_list_col, FORMAT_COL); | ||
194 | gtk_tree_view_column_set_sort_column_id (keywords_list_col, KEYWORDS_COL); | ||
195 | |||
196 | /* Allow to resize all columns */ | ||
197 | gtk_tree_view_column_set_resizable (filename_list_col, TRUE); | ||
198 | gtk_tree_view_column_set_resizable (title_list_col, TRUE); | ||
199 | gtk_tree_view_column_set_resizable (artist_list_col, TRUE); | ||
200 | gtk_tree_view_column_set_resizable (album_list_col, TRUE); | ||
201 | gtk_tree_view_column_set_resizable (type_list_col, TRUE); | ||
202 | gtk_tree_view_column_set_resizable (format_list_col, TRUE); | ||
203 | gtk_tree_view_column_set_resizable (keywords_list_col, TRUE); | ||
204 | |||
205 | /* Hide unedeed columns */ | ||
206 | gtk_tree_view_column_set_visible (artist_list_col, FALSE); | ||
207 | gtk_tree_view_column_set_visible (album_list_col, FALSE); | ||
208 | gtk_tree_view_column_set_visible (type_list_col, FALSE); | ||
209 | gtk_tree_view_column_set_visible (keywords_list_col, FALSE); | ||
210 | |||
211 | /* Set a smart option */ | ||
212 | gtk_tree_view_get_hover_expand (GTK_TREE_VIEW (filelist)); | ||
213 | |||
214 | /* add columns to view */ | ||
215 | gtk_tree_view_append_column (GTK_TREE_VIEW (filelist), filename_list_col); | ||
216 | gtk_tree_view_append_column (GTK_TREE_VIEW (filelist), title_list_col); | ||
217 | gtk_tree_view_append_column (GTK_TREE_VIEW (filelist), artist_list_col); | ||
218 | gtk_tree_view_append_column (GTK_TREE_VIEW (filelist), album_list_col); | ||
219 | gtk_tree_view_append_column (GTK_TREE_VIEW (filelist), type_list_col); | ||
220 | gtk_tree_view_append_column (GTK_TREE_VIEW (filelist), format_list_col); | ||
221 | gtk_tree_view_append_column (GTK_TREE_VIEW (filelist), keywords_list_col); | ||
222 | |||
223 | /* Expand columns */ | ||
224 | gtk_tree_view_column_set_expand (filename_list_col, TRUE); | ||
225 | gtk_tree_view_column_set_expand (artist_list_col, TRUE); | ||
226 | gtk_tree_view_column_set_expand (album_list_col, TRUE); | ||
227 | gtk_tree_view_column_set_expand (type_list_col, TRUE); | ||
228 | gtk_tree_view_column_set_expand (format_list_col, TRUE); | ||
229 | gtk_tree_view_column_set_expand (keywords_list_col, TRUE); | ||
230 | |||
231 | /* Allow multiple selections */ | ||
232 | GtkTreeSelection *filelist_selection = | ||
233 | gtk_tree_view_get_selection (GTK_TREE_VIEW (filelist)); | ||
234 | gtk_tree_selection_set_mode (filelist_selection, GTK_SELECTION_MULTIPLE); | ||
235 | |||
236 | |||
237 | |||
238 | AlbumList = NULL; | ||
239 | ArtistList = NULL; | ||
240 | |||
241 | Extractors = EXTRACTOR_loadDefaultLibraries (); | ||
242 | Extractors = EXTRACTOR_loadConfigLibraries (Extractors, "libextractor_filename"); | ||
243 | |||
244 | /* Create the popup menu */ | ||
245 | filelist_popup = gtk_menu_new (); | ||
246 | GtkWidget *select_all_menu_item = | ||
247 | gtk_menu_item_new_with_label (_("Select all files")); | ||
248 | GtkWidget *delete_menu_item = | ||
249 | gtk_menu_item_new_with_label (_("Remove selected files")); | ||
250 | gtk_menu_attach (GTK_MENU (filelist_popup), select_all_menu_item, 0, 1, 0, | ||
251 | 1); | ||
252 | gtk_menu_attach (GTK_MENU (filelist_popup), delete_menu_item, 0, 1, 1, 2); | ||
253 | gtk_widget_show (select_all_menu_item); | ||
254 | gtk_widget_show (delete_menu_item); | ||
255 | gtk_signal_connect (GTK_OBJECT (filelist), "button-press-event", | ||
256 | GTK_SIGNAL_FUNC (popup_delete), (gpointer) NULL); | ||
257 | gtk_signal_connect (GTK_OBJECT (select_all_menu_item), "activate", | ||
258 | GTK_SIGNAL_FUNC (select_all_files), (gpointer) TRUE); | ||
259 | gtk_signal_connect (GTK_OBJECT (delete_menu_item), "activate", | ||
260 | GTK_SIGNAL_FUNC (remove_file_from_list), | ||
261 | (gpointer) NULL); | ||
262 | |||
263 | /* | ||
264 | * show the main window | ||
265 | */ | ||
266 | gtk_widget_show (musicinsertdialog); | ||
267 | } | ||
268 | |||
269 | /** | ||
270 | * @brief Get an EXTRACTOR_KeywordList for a specified file | ||
271 | * @param a pointer to the extractors used to get the keywords | ||
272 | * @param the name of the file to extract the keywords from | ||
273 | */ | ||
274 | EXTRACTOR_KeywordList * | ||
275 | get_EXTRACTORKeywords (const EXTRACTOR_ExtractorList | ||
276 | * exList, const char *filename) | ||
277 | { | ||
278 | EXTRACTOR_KeywordList *keyList; | ||
279 | |||
280 | keyList = | ||
281 | EXTRACTOR_getKeywords ((EXTRACTOR_ExtractorList *) exList, filename); | ||
282 | keyList = | ||
283 | EXTRACTOR_removeDuplicateKeywords (keyList, | ||
284 | EXTRACTOR_DUPLICATES_REMOVE_UNKNOWN); | ||
285 | keyList = EXTRACTOR_removeEmptyKeywords (keyList); | ||
286 | return keyList; | ||
287 | } | ||
288 | |||
289 | |||
290 | |||
291 | /** | ||
292 | * @brief Get an EXTRACTOR_KeywordList for a specified file | ||
293 | * @param a pointer to the extractors used to get the keywords | ||
294 | * @param the name of the file to extract the keywords from | ||
295 | */ | ||
296 | void | ||
297 | set_File_Keywords (const gchar * filename) | ||
298 | { | ||
299 | char *keywords[7]; | ||
300 | GtkTreeIter pIter; | ||
301 | |||
302 | EXTRACTOR_KeywordList *KeywordList = | ||
303 | get_EXTRACTORKeywords (Extractors, filename); | ||
304 | |||
305 | |||
306 | keywords[0] = (char *) EXTRACTOR_extractLast (EXTRACTOR_FILENAME, KeywordList); | ||
307 | |||
308 | keywords[1] = (char *) EXTRACTOR_extractLast (EXTRACTOR_FILENAME, KeywordList); | ||
309 | |||
310 | keywords[2] = (char *) EXTRACTOR_extractLast (EXTRACTOR_TITLE, KeywordList); | ||
311 | |||
312 | keywords[3] = | ||
313 | (char *) EXTRACTOR_extractLast (EXTRACTOR_ARTIST, KeywordList); | ||
314 | if (keywords[3] != '\0' | ||
315 | && (g_list_find_custom (ArtistList, keywords[3], (GCompareFunc) strcmp) == NULL)) | ||
316 | { | ||
317 | ArtistList = g_list_append (ArtistList, STRDUP(keywords[3])); | ||
318 | gtk_combo_box_append_text (GTK_COMBO_BOX | ||
319 | (artistcombobox), keywords[3]); | ||
320 | } | ||
321 | |||
322 | keywords[4] = (char *) EXTRACTOR_extractLast (EXTRACTOR_ALBUM, KeywordList); | ||
323 | if (keywords[4] != '\0' | ||
324 | && (g_list_find_custom (AlbumList, keywords[4], (GCompareFunc) strcmp)) == NULL) | ||
325 | { | ||
326 | AlbumList = g_list_append (AlbumList, STRDUP(keywords[4])); | ||
327 | gtk_combo_box_append_text (GTK_COMBO_BOX | ||
328 | (albumcombobox), keywords[4]); | ||
329 | } | ||
330 | |||
331 | keywords[5] = | ||
332 | (char *) EXTRACTOR_extractLast (EXTRACTOR_MIMETYPE, KeywordList); | ||
333 | if (keywords[5] != '\0') | ||
334 | { | ||
335 | if ((g_list_find_custom (TypeList, keywords[5], (GCompareFunc) strcmp)) == NULL) | ||
336 | TypeList = g_list_append (TypeList, STRDUP(keywords[5])); | ||
337 | |||
338 | if (strcmp (keywords[5], "application/ogg") == 0) | ||
339 | gtk_combo_box_set_active (GTK_COMBO_BOX | ||
340 | (typecombobox), | ||
341 | FORMAT_OGG); | ||
342 | else if (strcmp (keywords[5], "audio/mpeg") == 0) | ||
343 | gtk_combo_box_set_active | ||
344 | (GTK_COMBO_BOX | ||
345 | (typecombobox), FORMAT_MP3); | ||
346 | else if (strcmp (keywords[5], "application/x-wav") == 0) | ||
347 | gtk_combo_box_set_active | ||
348 | (GTK_COMBO_BOX | ||
349 | (typecombobox), FORMAT_WAV); | ||
350 | else if (strcmp (keywords[5], "audio/vnd.rn-realaudio") == 0) | ||
351 | gtk_combo_box_set_active | ||
352 | (GTK_COMBO_BOX | ||
353 | (typecombobox), FORMAT_REAL); | ||
354 | } | ||
355 | else | ||
356 | { | ||
357 | TypeList = g_list_append (TypeList, STRDUP("unspecified")); | ||
358 | } | ||
359 | |||
360 | keywords[6] = | ||
361 | (char *) EXTRACTOR_extractLast (EXTRACTOR_FORMAT, KeywordList); | ||
362 | |||
363 | gtk_list_store_append (filelist_store, &pIter); | ||
364 | gtk_list_store_set (filelist_store, &pIter, REAL_FILENAME_COL, keywords[0], | ||
365 | FILENAME_COL, keywords[1], TITLE_COL, keywords[2], | ||
366 | ARTIST_COL, keywords[3], ALBUM_COL, keywords[4], | ||
367 | TYPE_COL, keywords[5], FORMAT_COL, keywords[6], | ||
368 | KEYWORDS_COL, "", -1); | ||
369 | EXTRACTOR_freeKeywords (KeywordList); | ||
370 | return; | ||
371 | } | ||
372 | |||
373 | /** | ||
374 | * @brief Select entries in combo boxes based on per-file infos | ||
375 | */ | ||
376 | void | ||
377 | activateComboBoxes () | ||
378 | { | ||
379 | |||
380 | if (gtk_combo_box_get_active (GTK_COMBO_BOX (albumcombobox)) < 0 | ||
381 | && | ||
382 | gtk_tree_model_iter_n_children (gtk_combo_box_get_model | ||
383 | (GTK_COMBO_BOX (albumcombobox)), | ||
384 | NULL) != 0) | ||
385 | gtk_combo_box_set_active (GTK_COMBO_BOX | ||
386 | (albumcombobox), 0); | ||
387 | |||
388 | if (gtk_combo_box_get_active (GTK_COMBO_BOX (artistcombobox)) < 0 | ||
389 | && | ||
390 | gtk_tree_model_iter_n_children (gtk_combo_box_get_model | ||
391 | (GTK_COMBO_BOX (artistcombobox)), | ||
392 | NULL) != 0) | ||
393 | gtk_combo_box_set_active (GTK_COMBO_BOX | ||
394 | (artistcombobox), 0); | ||
395 | |||
396 | if (gtk_combo_box_get_active (GTK_COMBO_BOX (typecombobox)) < 0 | ||
397 | && | ||
398 | gtk_tree_model_iter_n_children (gtk_combo_box_get_model | ||
399 | (GTK_COMBO_BOX (typecombobox)), | ||
400 | NULL) != 0) | ||
401 | gtk_combo_box_set_active (GTK_COMBO_BOX | ||
402 | (typecombobox), 0); | ||
403 | |||
404 | return; | ||
405 | } | ||
406 | |||
407 | /** | ||
408 | * @brief Hide or show specific columns if needed | ||
409 | */ | ||
410 | void | ||
411 | updateColumns () | ||
412 | { | ||
413 | if (g_list_length (ArtistList) > 1) | ||
414 | gtk_tree_view_column_set_visible (type_list_col, TRUE); | ||
415 | else | ||
416 | gtk_tree_view_column_set_visible (type_list_col, FALSE); | ||
417 | |||
418 | if (g_list_length (AlbumList) > 1) | ||
419 | gtk_tree_view_column_set_visible (type_list_col, TRUE); | ||
420 | else | ||
421 | gtk_tree_view_column_set_visible (type_list_col, FALSE); | ||
422 | |||
423 | if (g_list_length (TypeList) > 1) | ||
424 | gtk_tree_view_column_set_visible (type_list_col, TRUE); | ||
425 | else | ||
426 | gtk_tree_view_column_set_visible (type_list_col, FALSE); | ||
427 | |||
428 | gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (filelist_store), | ||
429 | FILENAME_COL, GTK_SORT_ASCENDING); | ||
430 | } | ||
431 | |||
432 | /** | ||
433 | * @brief Get an EXTRACTOR_KeywordList for a specified file | ||
434 | * @param a pointer to the extractors used to get the keywords | ||
435 | * @param the name of the file to extract the keywords from | ||
436 | * | ||
437 | int inv_strcomp (gconstpointer a, gconstpointer b) | ||
438 | { | ||
439 | return !strcmp ((char *)a, (char *)b); | ||
440 | } | ||
441 | */ | ||
442 | /* Callback functions */ | ||
443 | |||
444 | /** | ||
445 | * @brief Called when musicinsertdialog is destroyed (callback) | ||
446 | */ | ||
447 | void | ||
448 | on_musicinsertdialog_destroy (GtkObject * object, gpointer user_data) | ||
449 | { | ||
450 | gtk_main_quit (); | ||
451 | } | ||
452 | |||
453 | /** | ||
454 | * @brief Called when 'Cancel' button is clicked (callback) | ||
455 | */ | ||
456 | void | ||
457 | on_cancelbutton_clicked (GtkButton * button, gpointer user_data) | ||
458 | { | ||
459 | gtk_main_quit (); | ||
460 | } | ||
461 | |||
462 | /** | ||
463 | * @brief Called when the user validates the insertion (callback) | ||
464 | */ | ||
465 | void | ||
466 | on_okbutton_clicked (GtkButton * button, gpointer user_data) | ||
467 | { | ||
468 | return; | ||
469 | } | ||
470 | |||
471 | /** | ||
472 | * @brief Called when the 'Add a directory' button is clicked (callback) | ||
473 | */ | ||
474 | void | ||
475 | on_diraddbutton_clicked (GtkButton * button, gpointer user_data) | ||
476 | { | ||
477 | gchar *path; | ||
478 | GtkWidget *musicinsertdialog = glade_xml_get_widget(musicinsertXML, "musicinsertdialog"); | ||
479 | /* choose the directory to list */ | ||
480 | GtkWidget *filechooser = | ||
481 | gtk_file_chooser_dialog_new (_("Choose the directory to insert..."), | ||
482 | GTK_WINDOW (musicinsertdialog), | ||
483 | GTK_FILE_CHOOSER_ACTION_OPEN, | ||
484 | GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, | ||
485 | GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, | ||
486 | NULL); | ||
487 | gtk_file_chooser_set_action (GTK_FILE_CHOOSER (filechooser), | ||
488 | GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER); | ||
489 | gtk_window_set_modal (GTK_WINDOW (filechooser), TRUE); | ||
490 | switch (gtk_dialog_run (GTK_DIALOG (filechooser))) | ||
491 | { | ||
492 | case GTK_RESPONSE_ACCEPT: | ||
493 | /* get the path */ | ||
494 | path = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (filechooser)); | ||
495 | gtk_widget_destroy (filechooser); | ||
496 | break; | ||
497 | default: | ||
498 | gtk_widget_destroy (filechooser); | ||
499 | return; | ||
500 | } | ||
501 | |||
502 | /* list directory and fill the fields */ | ||
503 | GDir *directory; | ||
504 | GString *long_filename; | ||
505 | GError *dir_opening_error; | ||
506 | GSList *file_error_list = NULL; | ||
507 | gchar *filename; | ||
508 | if ((directory = g_dir_open (path, 0, &dir_opening_error))) | ||
509 | { | ||
510 | while ((filename = (gchar *) g_dir_read_name (directory))) | ||
511 | { | ||
512 | long_filename = g_string_new (path); | ||
513 | g_string_append_c (long_filename, DIR_SEPARATOR); | ||
514 | g_string_append (long_filename, filename); | ||
515 | if (!(ACCESS (long_filename->str, F_OK | R_OK))) | ||
516 | { | ||
517 | if (!(g_file_test (long_filename->str, G_FILE_TEST_IS_DIR))) | ||
518 | set_File_Keywords (long_filename->str); | ||
519 | } | ||
520 | else | ||
521 | { | ||
522 | file_error_list = g_slist_append (file_error_list, filename); | ||
523 | g_string_free (long_filename, TRUE); | ||
524 | } | ||
525 | } | ||
526 | |||
527 | g_free (path); | ||
528 | activateComboBoxes (); | ||
529 | updateColumns (); | ||
530 | if (g_slist_length (file_error_list) > 0) | ||
531 | { | ||
532 | GString *file_error_message = | ||
533 | g_string_new (_ | ||
534 | ("The following files won't be added for I could not read them :")); | ||
535 | while ((file_error_list = g_slist_next (file_error_list))) | ||
536 | { | ||
537 | g_string_append_c (file_error_message, '\n'); | ||
538 | g_string_append (file_error_message, | ||
539 | (gchar *) file_error_list->data); | ||
540 | } | ||
541 | GtkWidget *file_error_dialog = | ||
542 | gtk_message_dialog_new (GTK_WINDOW (musicinsertdialog), | ||
543 | GTK_DIALOG_DESTROY_WITH_PARENT, | ||
544 | GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, | ||
545 | file_error_message->str); | ||
546 | gtk_dialog_run (GTK_DIALOG (file_error_dialog)); | ||
547 | gtk_widget_destroy (file_error_dialog); | ||
548 | g_string_free (file_error_message, TRUE); | ||
549 | } | ||
550 | g_dir_close (directory); | ||
551 | } | ||
552 | else | ||
553 | { | ||
554 | gchar *error_message = STRDUP (_("Could not open the directory :\n")); | ||
555 | GtkWidget *message_dialog = | ||
556 | gtk_message_dialog_new (GTK_WINDOW (musicinsertdialog), | ||
557 | GTK_DIALOG_DESTROY_WITH_PARENT, | ||
558 | GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, | ||
559 | "%s%s", error_message, | ||
560 | dir_opening_error->message); | ||
561 | gtk_dialog_run (GTK_DIALOG (message_dialog)); | ||
562 | gtk_widget_destroy (message_dialog); | ||
563 | g_free (error_message); | ||
564 | g_error_free (dir_opening_error); | ||
565 | } | ||
566 | } | ||
567 | |||
568 | /** | ||
569 | * @brief Called when the 'Add a file' button is clicked (callback) | ||
570 | */ | ||
571 | void | ||
572 | on_fileaddbutton_clicked (GtkButton * button, gpointer user_data) | ||
573 | { | ||
574 | GSList *pathlist; | ||
575 | GtkWidget *musicinsertdialog = glade_xml_get_widget(musicinsertXML, "musicinsertdialog"); | ||
576 | /* choose the file to add */ | ||
577 | GtkWidget *filechooser = | ||
578 | gtk_file_chooser_dialog_new (_("Choose files to insert..."), | ||
579 | GTK_WINDOW (musicinsertdialog), | ||
580 | GTK_FILE_CHOOSER_ACTION_OPEN, | ||
581 | GTK_STOCK_CANCEL, | ||
582 | GTK_RESPONSE_CANCEL, | ||
583 | GTK_STOCK_OPEN, | ||
584 | GTK_RESPONSE_ACCEPT, NULL); | ||
585 | gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (filechooser), TRUE); | ||
586 | gtk_window_set_modal (GTK_WINDOW (filechooser), TRUE); | ||
587 | |||
588 | if (gtk_dialog_run (GTK_DIALOG (filechooser)) == GTK_RESPONSE_ACCEPT) | ||
589 | { | ||
590 | GSList *file_error_list = NULL; | ||
591 | /* get the path */ | ||
592 | pathlist = | ||
593 | gtk_file_chooser_get_filenames (GTK_FILE_CHOOSER (filechooser)); | ||
594 | gtk_widget_destroy (filechooser); | ||
595 | do | ||
596 | { | ||
597 | if (!(ACCESS (pathlist->data, F_OK | R_OK))) | ||
598 | { | ||
599 | set_File_Keywords (pathlist->data); | ||
600 | } | ||
601 | else | ||
602 | { | ||
603 | file_error_list = | ||
604 | g_slist_append (file_error_list, pathlist->data); | ||
605 | } | ||
606 | } | ||
607 | while ((pathlist = g_slist_next (pathlist))); | ||
608 | g_slist_free (pathlist); | ||
609 | |||
610 | activateComboBoxes (); | ||
611 | updateColumns (); | ||
612 | |||
613 | if (g_slist_length (file_error_list) > 0) | ||
614 | { | ||
615 | GString *file_error_message = | ||
616 | g_string_new (_ | ||
617 | ("The following files won't be added for I could not read them :")); | ||
618 | while ((file_error_list = g_slist_next (file_error_list))) | ||
619 | { | ||
620 | g_string_append_c (file_error_message, '\n'); | ||
621 | g_string_append (file_error_message, | ||
622 | (gchar *) file_error_list->data); | ||
623 | } | ||
624 | |||
625 | GtkWidget *file_error_dialog = | ||
626 | gtk_message_dialog_new (GTK_WINDOW (musicinsertdialog), | ||
627 | GTK_DIALOG_DESTROY_WITH_PARENT, | ||
628 | GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, | ||
629 | file_error_message->str); | ||
630 | gtk_dialog_run (GTK_DIALOG (file_error_dialog)); | ||
631 | g_string_free (file_error_message, TRUE); | ||
632 | gtk_widget_destroy (file_error_dialog); | ||
633 | } | ||
634 | return; | ||
635 | } | ||
636 | else | ||
637 | { | ||
638 | gtk_widget_destroy (filechooser); | ||
639 | return; | ||
640 | } | ||
641 | } | ||
642 | |||
643 | /** | ||
644 | * @brief Called when the user chooses the 'Full insertion' toggle button | ||
645 | */ | ||
646 | void | ||
647 | on_radioinsert_toggled (GtkRadioButton * radiobutton, gpointer user_data) | ||
648 | { | ||
649 | gtk_widget_set_sensitive (GTK_WIDGET | ||
650 | (glade_xml_get_widget (musicinsertXML, "copyfilesbutton")), FALSE); | ||
651 | } | ||
652 | |||
653 | /** | ||
654 | * @brief Called when the user chooses the 'Index only' toggle button | ||
655 | */ | ||
656 | void | ||
657 | on_radioindex_toggled (GtkRadioButton * radiobutton, gpointer user_data) | ||
658 | { | ||
659 | gtk_widget_set_sensitive | ||
660 | (GTK_WIDGET (glade_xml_get_widget (musicinsertXML, "copyfilesbutton")), TRUE); | ||
661 | } | ||
662 | |||
663 | /** | ||
664 | * @brief Hide or show the album column when needed | ||
665 | */ | ||
666 | void | ||
667 | on_albumtogglebutton_toggled | ||
668 | (GtkToggleButton * togglebutton, gpointer user_data) | ||
669 | { | ||
670 | if (gtk_toggle_button_get_active (togglebutton)) | ||
671 | gtk_tree_view_column_set_visible (album_list_col, FALSE); | ||
672 | else | ||
673 | gtk_tree_view_column_set_visible (album_list_col, TRUE); | ||
674 | } | ||
675 | |||
676 | /** | ||
677 | * @brief Hide or show the artist column when needed | ||
678 | */ | ||
679 | void | ||
680 | on_artisttogglebutton_toggled | ||
681 | (GtkToggleButton * togglebutton, gpointer user_data) | ||
682 | { | ||
683 | if (gtk_toggle_button_get_active (togglebutton)) | ||
684 | gtk_tree_view_column_set_visible (artist_list_col, FALSE); | ||
685 | else | ||
686 | gtk_tree_view_column_set_visible (artist_list_col, TRUE); | ||
687 | } | ||
688 | |||
689 | /** | ||
690 | * @brief Hide or show the keywords column when needed | ||
691 | */ | ||
692 | void | ||
693 | on_keywordstogglebutton_toggled | ||
694 | (GtkToggleButton * togglebutton, gpointer user_data) | ||
695 | { | ||
696 | if (gtk_toggle_button_get_active (togglebutton)) | ||
697 | gtk_tree_view_column_set_visible (keywords_list_col, FALSE); | ||
698 | else | ||
699 | gtk_tree_view_column_set_visible (keywords_list_col, TRUE); | ||
700 | } | ||
701 | |||
702 | /** | ||
703 | * @brief Make to user able to modify the per-file data | ||
704 | */ | ||
705 | void | ||
706 | on_renderer_edited | ||
707 | (GtkCellRendererText * | ||
708 | cellrenderertext, | ||
709 | gchar * path_string, gchar * new_text, gpointer user_data) | ||
710 | { | ||
711 | GtkTreePath *path = gtk_tree_path_new_from_string (path_string); | ||
712 | GtkTreeIter iter; | ||
713 | gtk_tree_model_get_iter (GTK_TREE_MODEL (filelist_store), &iter, path); | ||
714 | gtk_list_store_set (filelist_store, &iter, | ||
715 | (gint) * ((gint *) user_data), new_text, -1); | ||
716 | gtk_tree_path_free (path); | ||
717 | } | ||
718 | |||
719 | gboolean | ||
720 | popup_delete (GtkWidget * widget, GdkEventButton * event, gpointer user_data) | ||
721 | { | ||
722 | if ((event->type == GDK_BUTTON_PRESS) && (event->button == 3)) | ||
723 | { | ||
724 | gtk_menu_popup (GTK_MENU (filelist_popup), NULL, NULL, NULL, NULL, | ||
725 | event->button, event->time); | ||
726 | return TRUE; | ||
727 | } | ||
728 | return FALSE; | ||
729 | } | ||
730 | |||
731 | /** | ||
732 | * @brief Remove a file from the list to insert | ||
733 | */ | ||
734 | void | ||
735 | remove_file_from_list (gpointer user_data) | ||
736 | { | ||
737 | GtkTreeIter iter; | ||
738 | GtkWidget *filelist = glade_xml_get_widget (musicinsertXML, "filelist"); | ||
739 | GtkTreeSelection *selection = | ||
740 | gtk_tree_view_get_selection (GTK_TREE_VIEW (filelist)); | ||
741 | GList *selected_paths = gtk_tree_selection_get_selected_rows (selection, | ||
742 | (GtkTreeModel | ||
743 | **) & | ||
744 | filelist_store); | ||
745 | GList *selected_refs = NULL; | ||
746 | GtkTreePath *path; | ||
747 | /* Get static references from paths */ | ||
748 | while (selected_paths) | ||
749 | { | ||
750 | selected_refs = g_list_append (selected_refs, | ||
751 | gtk_tree_row_reference_new | ||
752 | (GTK_TREE_MODEL (filelist_store), | ||
753 | selected_paths->data)); | ||
754 | selected_paths = g_list_next (selected_paths); | ||
755 | } | ||
756 | g_list_foreach (selected_paths, (GFunc) gtk_tree_path_free, NULL); | ||
757 | g_list_free (selected_paths); | ||
758 | |||
759 | /* Remove items from references */ | ||
760 | while (selected_refs) | ||
761 | { | ||
762 | path = gtk_tree_row_reference_get_path (selected_refs->data); | ||
763 | gtk_tree_model_get_iter (GTK_TREE_MODEL (filelist_store), &iter, path); | ||
764 | gtk_list_store_remove (filelist_store, &iter); | ||
765 | gtk_tree_path_free (path); | ||
766 | selected_refs = g_list_next (selected_refs); | ||
767 | } | ||
768 | g_list_foreach (selected_paths, (GFunc) gtk_tree_row_reference_free, NULL); | ||
769 | g_list_free (selected_paths); | ||
770 | } | ||
771 | |||
772 | /** | ||
773 | * @brief Select all the entries of the list view | ||
774 | */ | ||
775 | void | ||
776 | select_all_files (gpointer user_data) | ||
777 | { | ||
778 | GtkWidget *filelist = glade_xml_get_widget (musicinsertXML, "filelist"); | ||
779 | GtkTreeSelection *selection = | ||
780 | gtk_tree_view_get_selection (GTK_TREE_VIEW (filelist)); | ||
781 | gtk_tree_selection_select_all (selection); | ||
782 | } | ||