2
* This file is part of GNAC - Gnome Audio Converter
4
* Copyright (C) 2007 - 2012 Gnac
6
* - DUPASQUIER Benoit <bdupasqu@src.gnome.org>
7
* - JOAQUIM David <djoaquim@src.gnome.org>
8
* - ROUX Alexandre <alexroux@src.gnome.org>
10
* GNAC is free software; you can redistribute it and/or modify
11
* it under the terms of the GNU General Public License as published by
12
* the Free Software Foundation; either version 3 of the License, or
13
* (at your option) any later version.
15
* GNAC is distributed in the hope that it will be useful,
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
* GNU General Public License for more details.
20
* You should have received a copy of the GNU General Public License
21
* along with GNAC; if not, write to the Free Software
22
* Foundation, Inc., 51 Franklin St, Fifth Floor,
23
* Boston, MA 02110-1301 USA
31
#include <glib/gi18n.h>
33
#include "gnac-main.h"
34
#include "gnac-profiles.h"
35
#include "gnac-profiles-default.h"
36
#include "gnac-profiles-manager.h"
37
#include "gnac-settings.h"
39
#include "gnac-ui-utils.h"
40
#include "gnac-utils.h"
41
#include "libgnac-debug.h"
43
/* Translators: Suffix added to a copied profile: 'profile (copy).xml' */
44
#define GNAC_COPY_SUFFIX N_(" (copy)")
71
GtkBuilder *profiles_mgr_builder = NULL;
73
static GtkTargetEntry target_list[] = {
74
{ "text/uri-list", 0, DND_TARGET_URI },
75
{ "text/plain" , 0, DND_TARGET_PLAIN }
78
static guint n_targets = G_N_ELEMENTS(target_list);
81
gnac_profiles_mgr_populate(void);
84
gnac_profiles_mgr_import_default_profiles(void);
87
gnac_profiles_mgr_clear(void);
90
gnac_profiles_mgr_insert(gpointer profile);
93
gnac_profiles_mgr_remove(GtkTreeRowReference *ref);
96
gnac_profiles_mgr_delete_profile_file(const gchar *name);
99
gnac_profiles_mgr_get(GtkTreeRowReference *ref,
101
AudioProfileGeneric **profile);
104
gnac_profiles_mgr_set(GtkTreeRowReference *ref, ...);
107
gnac_profiles_mgr_get_selected_rows(void);
110
gnac_profiles_mgr_activate_buttons(gboolean activate);
113
gnac_profiles_mgr_set_progress_bar_fraction(gdouble fraction);
116
gnac_profiles_mgr_display_status_message(const gchar *ok,
120
gnac_profiles_mgr_set_window_sensitive(gboolean sensitive);
123
gnac_profiles_mgr_copy_and_load_files(gpointer data);
126
gnac_profiles_mgr_get_selected_uris(void);
129
gnac_profiles_mgr_on_drag_profile_copied(goffset current_num_bytes,
130
goffset total_num_bytes,
134
gnac_profiles_mgr_on_edit_profile(GtkWidget *widget,
138
gnac_profiles_mgr_on_new_profile(GtkWidget *widget,
142
gnac_profiles_mgr_on_treeselection_changed(void);
146
gnac_profiles_mgr_get_object(const gchar *object_name)
148
return gnac_ui_utils_get_object(profiles_mgr_builder, object_name);
153
gnac_profiles_mgr_get_widget(const gchar *widget_name)
155
return gnac_ui_utils_get_widget(profiles_mgr_builder, widget_name);
160
gnac_profiles_mgr_set_widget_sensitive(const gchar *widget_name,
163
gnac_ui_utils_set_widget_sensitive(profiles_mgr_builder, widget_name, sensitive);
168
gnac_profiles_mgr_show_widget(const gchar *widget_name,
171
GtkWidget *widget = gnac_profiles_mgr_get_widget(widget_name);
173
gtk_widget_show_all(widget);
175
gtk_widget_hide(widget);
181
gnac_profiles_mgr_show_description_frame(gboolean show)
183
gnac_profiles_mgr_show_widget("frame-description", show);
188
gnac_profiles_mgr_show_import_progressbar(gboolean show)
190
gnac_profiles_mgr_show_widget("frame-import", show);
195
gnac_profiles_mgr_set_parent(void)
197
GtkWindow *parent = GTK_WINDOW(gnac_ui_get_widget("main_window"));
198
GtkWindow *window = GTK_WINDOW(
199
gnac_profiles_mgr_get_widget("profile_manager_window"));
200
gtk_window_set_transient_for(window, parent);
201
gnac_profiles_properties_set_parent(window);
206
gnac_profiles_mgr_init(void)
208
profiles_mgr_builder = gnac_ui_utils_create_gtk_builder(
209
PKGDATADIR "/profiles/gnac-profiles-manager.xml");
211
GtkTreeView *view = GTK_TREE_VIEW(
212
gnac_profiles_mgr_get_widget("profile_treeview"));
213
GtkTreeSelection *selection = gtk_tree_view_get_selection(view);
215
g_signal_connect(G_OBJECT(selection), "changed",
216
G_CALLBACK(gnac_profiles_mgr_on_treeselection_changed), NULL);
218
gtk_drag_dest_set(GTK_WIDGET(view), GTK_DEST_DEFAULT_ALL, target_list,
219
n_targets, GDK_ACTION_COPY);
221
gtk_drag_source_set(GTK_WIDGET(view), GDK_BUTTON1_MASK, target_list,
222
n_targets, GDK_ACTION_COPY);
224
gnac_profiles_properties_init();
225
gnac_profiles_mgr_set_parent();
227
gnac_profiles_mgr_show_import_progressbar(FALSE);
228
gnac_profiles_mgr_display_status_message(NULL, NULL);
230
gnac_profiles_mgr_populate();
235
gnac_profiles_mgr_get_profiles_dir(void)
237
saved_profiles_dir = g_build_filename(g_get_user_data_dir(),
238
PACKAGE, "profiles", NULL);
239
GFile *dir = g_file_new_for_path(saved_profiles_dir);
240
if (g_file_query_exists(dir, NULL)) {
244
GError *error = NULL;
246
if (!g_file_make_directory_with_parents(dir, NULL, &error)) {
247
libgnac_warning("%s: %s",
248
_("Unable to create the profiles directory"), error->message);
249
g_clear_error(&error);
258
gnac_profiles_mgr_list_profiles(void)
260
GFile *dir = gnac_profiles_mgr_get_profiles_dir();
262
GError *error = NULL;
263
GFileEnumerator *files = g_file_enumerate_children(dir,
264
G_FILE_ATTRIBUTE_STANDARD_NAME ","
265
G_FILE_ATTRIBUTE_STANDARD_TYPE,
266
G_FILE_QUERY_INFO_NONE, NULL, &error);
268
if (!files && error) {
269
g_clear_error(&error);
270
/* no profiles found, try to import the default ones */
271
gnac_profiles_mgr_import_default_profiles();
272
files = g_file_enumerate_children(dir,
273
G_FILE_ATTRIBUTE_STANDARD_NAME ","
274
G_FILE_ATTRIBUTE_STANDARD_TYPE,
275
G_FILE_QUERY_INFO_NONE, NULL, &error);
276
if (!files && error) {
277
g_printerr(_("No profiles available"));
278
libgnac_warning("%s", error->message);
279
g_clear_error(&error);
284
g_print(_("Available audio profiles:"));
287
gchar *last_used_profile = gnac_settings_get_string(
288
GNAC_KEY_LAST_USED_PROFILE);
290
GFile *profile_file = g_file_enumerator_get_container(files);
291
gchar *profile_file_path = g_file_get_path(profile_file);
293
GFileInfo *file_info;
294
GSList *profiles = NULL;
296
while ((file_info = g_file_enumerator_next_file(files, NULL, NULL))) {
297
if (g_file_info_get_file_type(file_info) == G_FILE_TYPE_REGULAR) {
298
AudioProfileGeneric *profile;
299
const gchar *profile_file_name = g_file_info_get_name(file_info);
300
gchar *profile_file_full_path = g_build_filename(profile_file_path,
301
profile_file_name, NULL);
302
gnac_profiles_default_load_generic_audio_profile(profile_file_full_path,
305
gpointer name = (profile->generic)->name;
306
profiles = g_slist_prepend(profiles, name);
309
g_free(profile_file_full_path);
312
g_object_unref(file_info);
315
g_free(profile_file_path);
317
profiles = g_slist_reverse(profiles);
319
guint count = g_slist_length(profiles);
322
g_print(_("No profiles available"));
325
/* check if last_used_profile exists */
326
if (!g_slist_find_custom(profiles, last_used_profile,
327
(GCompareFunc) g_strcmp0))
329
last_used_profile = NULL;
333
for (tmp = profiles; tmp; tmp = g_slist_next(tmp)) {
334
gint pos = g_slist_position(profiles, tmp);
335
gchar *count_str = g_strdup_printf("%u", pos+1);
336
/* if last_used_profile is not set, assume the
337
* first profile was last used */
338
gchar *name = tmp->data;
339
gboolean found = ((pos == 0 && !last_used_profile)
340
|| gnac_utils_str_equal(name, last_used_profile));
341
g_print("\t%2s) %s\n", found ? "*" : count_str, name);
348
g_slist_free(profiles);
349
g_free(last_used_profile);
351
g_file_enumerator_close(files, NULL, NULL);
352
g_object_unref(files);
357
gnac_profiles_mgr_populate(void)
359
gnac_profiles_mgr_clear();
361
GError *error = NULL;
363
GFile *dir = g_file_new_for_path(saved_profiles_dir);
364
if (!g_file_query_exists(dir, NULL)) {
365
if (!g_file_make_directory_with_parents(dir, NULL, &error)) {
366
const gchar *msg = N_("Unable to create the profiles directory");
367
libgnac_warning("%s %s: %s",
368
msg, _("You may not be able to save your profiles"), error->message);
369
gnac_profiles_mgr_display_status_message(NULL, msg);
370
g_clear_error(&error);
373
gnac_profiles_mgr_import_default_profiles();
377
GFileEnumerator *files = g_file_enumerate_children(dir,
378
G_FILE_ATTRIBUTE_STANDARD_NAME ","
379
G_FILE_ATTRIBUTE_STANDARD_TYPE,
380
G_FILE_QUERY_INFO_NONE, NULL, &error);
381
if (!files && error) {
382
const gchar *msg = N_("Unable to browse the profiles directory");
383
libgnac_warning("%s: %s", msg, error->message);
384
gnac_profiles_mgr_display_status_message(NULL, msg);
385
g_clear_error(&error);
389
GFileInfo *file_info = g_file_enumerator_next_file(files, NULL, NULL);
391
gnac_profiles_mgr_import_default_profiles();
392
g_file_enumerator_close(files, NULL, NULL);
393
files = g_file_enumerate_children(dir,
394
G_FILE_ATTRIBUTE_STANDARD_NAME ","
395
G_FILE_ATTRIBUTE_STANDARD_TYPE,
396
G_FILE_QUERY_INFO_NONE, NULL, &error);
397
file_info = g_file_enumerator_next_file(files, NULL, NULL);
400
GFile *profile_file = g_file_enumerator_get_container(files);
401
gchar *profile_file_path = g_file_get_path(profile_file);
404
if (g_file_info_get_file_type(file_info) == G_FILE_TYPE_REGULAR) {
405
const gchar *profile_file_name = g_file_info_get_name(file_info);
406
gchar *profile_file_full_path = g_build_filename(profile_file_path,
407
profile_file_name, NULL);
408
gpointer profile = gnac_profiles_properties_load_profile_from_file(
409
profile_file_full_path, profile_file_name, &error);
411
g_free(profile_file_full_path);
414
gnac_profiles_mgr_insert(profile);
416
libgnac_warning("%s", error->message);
417
g_clear_error(&error);
421
g_object_unref(file_info);
422
file_info = g_file_enumerator_next_file(files, NULL, NULL);
425
gnac_profiles_mgr_display_status_message(NULL, NULL);
428
g_free(profile_file_path);
429
g_file_enumerator_close(files, NULL, NULL);
430
g_object_unref(files);
434
static GFileEnumerator *
435
gnac_profiles_mgr_get_default_profiles_enumerator(void)
437
GFile *dir = g_file_new_for_path(PKGDATADIR "/profiles/default");
438
if (!g_file_query_exists(dir, NULL)) {
439
libgnac_warning("%s", _("Unable to find the default profiles directory"));
443
GError *error = NULL;
444
GFileEnumerator *files = g_file_enumerate_children(dir,
445
G_FILE_ATTRIBUTE_STANDARD_NAME ","
446
G_FILE_ATTRIBUTE_STANDARD_TYPE,
447
G_FILE_QUERY_INFO_NONE, NULL, &error);
449
libgnac_warning("%s: %s",
450
_("Unable to browse the default profiles directory"),
452
g_clear_error(&error);
464
gnac_profiles_mgr_import_default_profiles(void)
466
gnac_profiles_mgr_clear();
468
GFileEnumerator *files = gnac_profiles_mgr_get_default_profiles_enumerator();
470
GFile *profile_file = g_file_enumerator_get_container(files);
471
gchar *profile_file_path = g_file_get_path(profile_file);
473
GFileInfo *file_info;
474
while ((file_info = g_file_enumerator_next_file(files, NULL, NULL))) {
475
if (g_file_info_get_file_type(file_info) == G_FILE_TYPE_REGULAR) {
476
GError *error = NULL;
477
const gchar *profile_file_name = g_file_info_get_name(file_info);
478
gchar *profile_file_full_path = g_build_filename(profile_file_path,
479
profile_file_name, NULL);
480
gpointer profile = gnac_profiles_properties_load_profile_from_file(
481
profile_file_full_path, profile_file_name, &error);
484
gnac_profiles_properties_save_profile(profile);
486
libgnac_warning("%s", error->message);
487
g_clear_error(&error);
490
g_free(profile_file_full_path);
491
gnac_profiles_properties_free_audio_profile(profile);
494
g_free(profile_file_path);
495
g_object_unref(file_info);
498
g_file_enumerator_close(files, NULL, NULL);
499
g_object_unref(files);
504
gnac_profiles_mgr_get_profiles_list(void)
507
GtkTreeModel *model = GTK_TREE_MODEL(
508
gnac_profiles_mgr_get_object("liststore"));
509
gboolean has_next = gtk_tree_model_get_iter_first(model, &iter);
513
AudioProfileGeneric *profile;
514
gtk_tree_model_get(model, &iter, COL_PROFILE, &profile, -1);
515
list = g_list_prepend(list, profile);
516
has_next = gtk_tree_model_iter_next(model, &iter);
519
return g_list_reverse(list);
524
gnac_profiles_mgr_destroy(void)
526
if (profiles_mgr_builder) {
527
gnac_profiles_mgr_clear();
528
GtkWidget *widget = gnac_profiles_mgr_get_widget("profile_manager_window");
529
gtk_widget_destroy(widget);
530
g_object_unref(profiles_mgr_builder);
533
gnac_profiles_properties_destroy();
538
gnac_profiles_mgr_show(void)
540
static gboolean first_show = TRUE;
543
gnac_profiles_mgr_populate();
548
GtkWidget *window = gnac_profiles_mgr_get_widget("profile_manager_window");
549
gtk_widget_show(window);
551
GList *selected = gnac_profiles_mgr_get_selected_rows();
553
gnac_profiles_mgr_show_description_frame(FALSE);
554
gnac_profiles_mgr_activate_buttons(FALSE);
557
g_list_free_full(selected, (GDestroyNotify) gtk_tree_row_reference_free);
562
gnac_profiles_mgr_clear(void)
565
GtkTreeModel *model = GTK_TREE_MODEL(
566
gnac_profiles_mgr_get_object("liststore"));
567
gboolean has_next = gtk_tree_model_get_iter_first(model, &iter);
570
AudioProfileGeneric *profile;
571
gtk_tree_model_get(model, &iter, COL_PROFILE, &profile, -1);
572
gnac_profiles_properties_free_audio_profile(profile);
573
has_next = gtk_tree_model_iter_next(model, &iter);
576
gtk_list_store_clear(GTK_LIST_STORE(model));
581
gnac_profiles_mgr_insert(gpointer profile)
583
GtkListStore *model = GTK_LIST_STORE(
584
gnac_profiles_mgr_get_object("liststore"));
585
AudioProfileGeneric *generic = AUDIO_PROFILE_GET_GENERIC(profile);
586
gchar *formatted_name = gnac_profiles_properties_filter_text_for_display(
587
generic->name, MAX_NAME_DISPLAY_SIZE);
590
gtk_list_store_append(model, &iter);
591
gtk_list_store_set(model, &iter,
592
COL_NAME, formatted_name,
593
COL_FORMAT, generic->format_name,
594
COL_EXTENSION, generic->extension,
595
COL_PROFILE, profile,
598
g_free(formatted_name);
603
gnac_profiles_mgr_remove(GtkTreeRowReference *ref)
605
g_return_if_fail(ref);
607
GtkTreeModel *model = GTK_TREE_MODEL(
608
gnac_profiles_mgr_get_object("liststore"));
609
GtkTreePath *path = gtk_tree_row_reference_get_path(ref);
614
if (gtk_tree_model_get_iter(model, &iter, path)) {
615
AudioProfileGeneric *profile;
616
gtk_tree_model_get(model, &iter, COL_PROFILE, &profile, -1);
617
gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
618
gnac_profiles_properties_free_audio_profile(profile);
621
gtk_tree_path_free(path);
626
gnac_profiles_mgr_get(GtkTreeRowReference *ref,
628
AudioProfileGeneric **profile)
630
g_return_if_fail(ref);
632
GtkTreeModel *model = GTK_TREE_MODEL(
633
gnac_profiles_mgr_get_object("liststore"));
634
GtkTreePath *path = gtk_tree_row_reference_get_path(ref);
639
if (gtk_tree_model_get_iter(model, &iter, path)) {
640
gtk_tree_model_get(model, &iter, col_number, profile, -1);
643
gtk_tree_path_free(path);
648
gnac_profiles_mgr_set(GtkTreeRowReference *ref, ...)
650
g_return_if_fail(ref);
652
GtkListStore *list_store = GTK_LIST_STORE(
653
gnac_profiles_mgr_get_object("liststore"));
654
GtkTreePath *path = gtk_tree_row_reference_get_path(ref);
660
if (gtk_tree_model_get_iter(GTK_TREE_MODEL(list_store), &iter, path)) {
662
gtk_list_store_set_valist(list_store, &iter, ap);
665
gtk_tree_path_free(path);
670
gnac_profiles_mgr_get_selected_rows(void)
672
GtkTreeModel *model = GTK_TREE_MODEL(
673
gnac_profiles_mgr_get_object("liststore"));
674
GtkTreeView *view = GTK_TREE_VIEW(
675
gnac_profiles_mgr_get_widget("profile_treeview"));
676
GtkTreeSelection *selection = gtk_tree_view_get_selection(view);
678
/* Convert path to GtkTreeRowReference */
679
GList *next = gtk_tree_selection_get_selected_rows(selection, &model);
680
GList *next_temp = next;
681
GList *row_references = NULL;
684
row_references = g_list_prepend(row_references,
685
gtk_tree_row_reference_new(model, next->data));
686
next = g_list_next(next);
689
row_references = g_list_reverse(row_references);
691
g_list_free_full(next_temp, (GDestroyNotify) gtk_tree_path_free);
693
return row_references;
698
gnac_profiles_mgr_activate_buttons(gboolean activate)
700
gnac_profiles_mgr_set_widget_sensitive("copy_button", activate);
701
gnac_profiles_mgr_set_widget_sensitive("edit_button", activate);
702
gnac_profiles_mgr_set_widget_sensitive("delete_button", activate);
707
gnac_profiles_mgr_set_window_sensitive(gboolean sensitive)
709
gnac_profiles_mgr_set_widget_sensitive("frame-profiles-list", sensitive);
710
gnac_profiles_mgr_set_widget_sensitive("frame-description", sensitive);
711
gnac_profiles_mgr_set_widget_sensitive("frame-status", sensitive);
712
gnac_profiles_mgr_set_widget_sensitive("close_button", sensitive);
717
gnac_profiles_mgr_set_progress_bar_fraction(gdouble fraction)
719
GtkWidget *widget = gnac_profiles_mgr_get_widget("progressbar-import");
720
gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(widget), fraction);
725
gnac_profiles_mgr_display_status_message(const gchar *success_message,
726
const gchar *error_message)
728
GtkWidget *frame_status = gnac_profiles_mgr_get_widget("frame-status");
730
if (!success_message && !error_message) {
731
gtk_widget_hide(frame_status);
735
gtk_widget_show_all(frame_status);
737
GtkWidget *label_ok = gnac_profiles_mgr_get_widget("label-status-ok");
738
GtkWidget *image_ok = gnac_profiles_mgr_get_widget("image-status-ok");
740
if (success_message) {
741
gtk_label_set_markup(GTK_LABEL(label_ok), success_message);
742
gtk_widget_show(label_ok);
743
gtk_widget_show(image_ok);
745
gtk_widget_hide(label_ok);
746
gtk_widget_hide(image_ok);
749
GtkWidget *label_error = gnac_profiles_mgr_get_widget("label-status-error");
750
GtkWidget *image_error = gnac_profiles_mgr_get_widget("image-status-error");
753
gtk_label_set_markup(GTK_LABEL(label_error), error_message);
754
gtk_widget_show(label_error);
755
gtk_widget_show(image_error);
757
gtk_widget_hide(label_error);
758
gtk_widget_hide(image_error);
764
gnac_profiles_mgr_on_drag_data_received(GtkWidget *widget,
765
GdkDragContext *context,
768
GtkSelectionData *selection_data,
773
gchar **uris = g_uri_list_extract_uris((const gchar *)
774
gtk_selection_data_get_data(selection_data));
776
gtk_drag_finish(context, FALSE, FALSE, time);
780
ThreadCopyData *tcopy_data = g_malloc(sizeof(ThreadCopyData));
781
tcopy_data->uris = uris;
782
tcopy_data->info = info;
784
GError *error = NULL;
786
g_thread_create((GThreadFunc) gnac_profiles_mgr_copy_and_load_files,
787
tcopy_data, TRUE, &error);
789
libgnac_debug("Failed to create thread: %s", error->message);
790
gnac_profiles_mgr_display_status_message(NULL,
791
_("Impossible to import file(s)"));
792
g_clear_error(&error);
795
gtk_drag_finish(context, TRUE, FALSE, time);
800
gnac_profiles_mgr_get_file_name(GFile *file,
803
GError *error = NULL;
805
GFileInfo *file_info = g_file_query_info(file,
806
G_FILE_ATTRIBUTE_STANDARD_NAME ","
807
G_FILE_ATTRIBUTE_STANDARD_TYPE,
808
G_FILE_QUERY_INFO_NONE, NULL, &error);
810
libgnac_warning("%s", error->message);
811
g_clear_error(&error);
820
if (g_file_info_get_file_type(file_info) == G_FILE_TYPE_REGULAR) {
821
name = g_strdup(g_file_info_get_name(file_info));
825
case DND_TARGET_PLAIN:
826
if (g_file_info_get_file_type(file_info) == G_FILE_TYPE_UNKNOWN) {
827
name = g_file_get_basename(file);
832
g_object_unref(file_info);
839
gnac_profiles_mgr_display_import_status(guint profiles_ok,
840
guint profiles_error)
843
gchar *errors = NULL;
845
if (profiles_error > 0) {
846
errors = g_strdup_printf(ngettext("%d file failed to be imported",
847
"%d files failed to be imported", profiles_error), profiles_error);
850
if (profiles_ok > 0) {
851
oks = g_strdup_printf(ngettext("%d file successfully imported",
852
"%d files successfully imported", profiles_ok), profiles_ok);
856
gnac_profiles_mgr_set_window_sensitive(TRUE);
857
gnac_profiles_mgr_show_import_progressbar(FALSE);
858
gnac_profiles_mgr_display_status_message(oks, errors);
867
gnac_profiles_mgr_copy_file(GFile *src_file,
868
const gchar *dest_name)
870
GError *error = NULL;
871
gchar *path = g_build_filename(g_get_tmp_dir(), dest_name, NULL);
872
GFile *dest_file = g_file_new_for_path(path);
873
CopyData copy_data = { path, dest_name, &error, FALSE };
876
gnac_profiles_mgr_set_progress_bar_fraction(0.0);
879
gboolean success = g_file_copy(src_file, dest_file, G_FILE_COPY_NONE, NULL,
880
(GFileProgressCallback) gnac_profiles_mgr_on_drag_profile_copied,
883
libgnac_warning("%s", error->message);
884
g_clear_error(&error);
888
g_object_unref(dest_file);
895
gnac_profiles_mgr_copy_and_load_files(gpointer data)
897
ThreadCopyData *tcopy_data = (ThreadCopyData *) data;
898
gchar **uris = tcopy_data->uris;
901
gchar *uri = uris[index];
904
gnac_profiles_mgr_set_window_sensitive(FALSE);
905
gnac_profiles_mgr_show_import_progressbar(TRUE);
908
guint profiles_ok = 0;
909
guint profiles_error = 0;
912
GFile *file = g_file_new_for_uri(uri);
913
gchar *name = gnac_profiles_mgr_get_file_name(file, tcopy_data->info);
917
_("Impossible to import file \"%s\". File type not supported."),
920
} else if (gnac_profiles_properties_saved_profiles_contain_name(name)) {
922
_("Impossible to load file \"%s\": "
923
"a profile with the same name already exists."), uri);
925
} else if (gnac_profiles_mgr_copy_file(file, name)) {
936
g_object_unref(file);
939
gnac_profiles_mgr_display_import_status(profiles_ok, profiles_error);
941
g_strfreev(tcopy_data->uris);
947
gnac_profiles_mgr_on_drag_profile_copied(goffset current_num_bytes,
948
goffset total_num_bytes,
951
/* CLAMP ensures that frac is between 0.0 and 1.0 */
952
gdouble frac = CLAMP(
953
((gdouble) current_num_bytes) / ((gdouble) total_num_bytes),
957
gnac_profiles_mgr_set_progress_bar_fraction(frac);
960
if (current_num_bytes >= total_num_bytes) {
961
CopyData *copy_data = (CopyData *) user_data;
962
if (!copy_data->toggle) {
963
copy_data->toggle = TRUE;
965
AudioProfileGeneric *profile =
966
gnac_profiles_properties_load_profile_from_file(
967
copy_data->path, copy_data->name, copy_data->error);
969
if (profile && !(*(copy_data->error))) {
971
gnac_profiles_properties_save_profile(profile);
972
gnac_profiles_mgr_insert(profile);
976
GFile *file = g_file_new_for_path(copy_data->path);
978
g_file_delete(file, NULL, NULL);
979
g_object_unref(file);
986
gnac_profiles_mgr_on_drag_data_get(GtkWidget *widget,
987
GdkDragContext *drag_context,
988
GtkSelectionData *data,
993
gchar **uris = gnac_profiles_mgr_get_selected_uris();
994
gtk_selection_data_set_uris(data, uris);
999
gnac_profiles_mgr_get_selected_uris(void)
1001
GList *selected = gnac_profiles_mgr_get_selected_rows();
1002
if (!selected) return NULL;
1004
GtkTreeRowReference *reference = (GtkTreeRowReference *) selected->data;
1005
gchar **uris = g_malloc((g_list_length(selected)+1) * sizeof(gchar *));
1010
for (i = 0, temp = selected; temp; temp = g_list_next(temp), i++) {
1011
AudioProfileGeneric *profile;
1012
gnac_profiles_mgr_get(reference, COL_PROFILE, &profile);
1013
profile = profile->generic;
1014
gchar *path = g_strconcat(GNAC_SAVED_PROFILES_URL_WITH_EXT(profile->name),
1016
GFile *file = g_file_new_for_path(path);
1017
uris[i] = g_file_get_uri(file);
1024
g_list_free_full(selected, (GDestroyNotify) gtk_tree_row_reference_free);
1031
gnac_profiles_mgr_on_add(GtkWidget *widget,
1034
gnac_profiles_properties_show(NULL, _("New Profile"),
1035
G_CALLBACK(gnac_profiles_mgr_on_new_profile));
1040
gnac_profiles_mgr_on_new_profile(GtkWidget *widget,
1043
gnac_profiles_mgr_insert(data);
1044
gnac_profiles_mgr_display_status_message(NULL, NULL);
1049
gnac_profiles_mgr_on_copy(GtkWidget *widget,
1052
GList *selected = gnac_profiles_mgr_get_selected_rows();
1053
if (!selected) return;
1055
GtkTreeRowReference *reference = (GtkTreeRowReference *) selected->data;
1057
AudioProfileGeneric *profile;
1058
gnac_profiles_mgr_get(reference, COL_PROFILE, &profile);
1059
AudioProfileGeneric *generic = profile->generic;
1061
gchar *full_path = g_strconcat(GNAC_SAVED_PROFILES_URL_WITH_EXT(generic->name),
1063
gchar *new_name = g_strconcat(GNAC_SAVED_PROFILES_URL(generic->name),
1064
gettext(GNAC_COPY_SUFFIX), NULL);
1065
gchar *new_path = g_strconcat(new_name, ".xml", NULL);
1067
GFile *src = g_file_new_for_path(full_path);
1068
GFile *dst = g_file_new_for_path(new_path);
1072
GError *error = NULL;
1073
g_file_copy(src, dst, G_FILE_COPY_NONE, NULL, NULL, NULL, &error);
1076
libgnac_debug("Failed to copy the profile %s: %s",
1077
generic->name, error->message);
1078
gnac_profiles_mgr_display_status_message(
1079
NULL, _("Failed to copy the profile"));
1081
g_clear_error(&error);
1082
g_object_unref(src);
1083
g_object_unref(dst);
1086
g_list_free_full(selected, (GDestroyNotify) gtk_tree_row_reference_free);
1091
// FIXME seems we have a leak here
1092
AudioProfileGeneric *copy_profile =
1093
gnac_profiles_properties_load_profile_from_file(
1094
new_path, new_name, &error);
1097
(copy_profile->generic)->name = g_strconcat(generic->name,
1098
gettext(GNAC_COPY_SUFFIX), NULL);
1099
gnac_profiles_properties_save_profile(copy_profile);
1100
gnac_profiles_mgr_insert(copy_profile);
1104
libgnac_debug("Failed to copy the profile %s: %s",
1105
(copy_profile->generic)->name, error->message);
1106
gnac_profiles_mgr_display_status_message(
1107
NULL, _("Failed to copy the profile"));
1108
g_clear_error(&error);
1111
g_object_unref(src);
1112
g_object_unref(dst);
1115
g_list_free_full(selected, (GDestroyNotify) gtk_tree_row_reference_free);
1120
gnac_profiles_mgr_on_edit(GtkWidget *widget,
1123
GList *selected = gnac_profiles_mgr_get_selected_rows();
1124
if (!selected) return;
1126
GtkTreeRowReference *reference = (GtkTreeRowReference *) selected->data;
1127
AudioProfileGeneric *profile;
1128
gnac_profiles_mgr_get(reference, COL_PROFILE, &profile);
1129
profile->generic->user_data = selected->data;
1131
g_list_free_full(selected, (GDestroyNotify) gtk_tree_row_reference_free);
1133
gnac_profiles_properties_show(profile, _("Edit Profile"),
1134
G_CALLBACK(gnac_profiles_mgr_on_edit_profile));
1139
gnac_profiles_mgr_on_edit_profile(GtkWidget *widget,
1142
GList *selected = gnac_profiles_mgr_get_selected_rows();
1143
if (!selected) return;
1145
GtkTreeRowReference *reference = (GtkTreeRowReference *) selected->data;
1147
AudioProfileGeneric *old_profile;
1148
gnac_profiles_mgr_get(reference, COL_PROFILE, &old_profile);
1149
AudioProfileGeneric *old_generic = old_profile->generic;
1151
AudioProfileGeneric *profile = (AudioProfileGeneric *) data;
1152
AudioProfileGeneric *generic = profile->generic;
1154
if (!gnac_utils_str_equal(generic->name, old_generic->name)) {
1155
gnac_profiles_mgr_delete_profile_file(old_generic->name);
1158
gchar *formatted_name = gnac_profiles_properties_filter_text_for_display(
1159
generic->name, MAX_NAME_DISPLAY_SIZE);
1160
gnac_profiles_mgr_set(reference,
1161
COL_NAME, formatted_name,
1162
COL_FORMAT, generic->format_name,
1163
COL_EXTENSION, generic->extension,
1164
COL_PROFILE, profile,
1167
g_free(formatted_name);
1168
gnac_profiles_properties_free_audio_profile(old_profile);
1169
g_list_free_full(selected, (GDestroyNotify) gtk_tree_row_reference_free);
1171
gnac_profiles_mgr_display_status_message(NULL, NULL);
1173
gnac_profiles_mgr_on_treeselection_changed();
1178
gnac_profiles_mgr_on_remove(GtkWidget *widget,
1181
GList *selected = gnac_profiles_mgr_get_selected_rows();
1182
if (!selected) return;
1184
GtkTreeRowReference *reference = (GtkTreeRowReference *) selected->data;
1186
AudioProfileGeneric *profile;
1187
gnac_profiles_mgr_get(reference, COL_PROFILE, &profile);
1188
gnac_profiles_mgr_delete_profile_file(profile->generic->name);
1190
gnac_profiles_mgr_display_status_message(NULL, NULL);
1192
GtkTreeModel *model = gtk_tree_row_reference_get_model(reference);
1193
GtkTreePath *path = gtk_tree_row_reference_get_path(reference);
1196
gboolean new_selected = FALSE;
1197
if (gtk_tree_model_get_iter(model, &iter, path)) {
1198
if (gtk_tree_model_iter_next(model, &iter)
1199
|| (gtk_tree_path_prev(path) &&
1200
gtk_tree_model_get_iter(model, &iter, path)))
1202
GtkTreeView *view = GTK_TREE_VIEW(
1203
gnac_profiles_mgr_get_widget("profile_treeview"));
1204
GtkTreeSelection *selection = gtk_tree_view_get_selection(view);
1205
gtk_tree_selection_select_iter(selection, &iter);
1206
new_selected = TRUE;
1210
gnac_profiles_mgr_remove(reference);
1212
gnac_profiles_mgr_activate_buttons(new_selected);
1213
gnac_profiles_mgr_show_description_frame(new_selected);
1215
gtk_tree_path_free(path);
1216
g_list_free_full(selected, (GDestroyNotify) gtk_tree_row_reference_free);
1221
gnac_profiles_mgr_delete_profile_file(const gchar *name)
1223
gchar *full_path = g_strconcat(GNAC_SAVED_PROFILES_URL_WITH_EXT(name), NULL);
1224
GFile *file = g_file_new_for_path(full_path);
1226
g_file_delete(file, NULL, NULL);
1228
g_object_unref(file);
1234
gnac_profiles_mgr_on_treeselection_changed(void)
1236
GList *selected = gnac_profiles_mgr_get_selected_rows();
1237
if (!selected) return;
1239
GtkTreeRowReference *reference = (GtkTreeRowReference *) selected->data;
1241
gnac_profiles_mgr_activate_buttons(TRUE);
1242
gnac_profiles_mgr_display_status_message(NULL, NULL);
1244
AudioProfileGeneric *profile;
1245
gnac_profiles_mgr_get(reference, COL_PROFILE, &profile);
1246
GtkWidget *widget = gnac_profiles_mgr_get_widget("label-description-content");
1247
gchar *descr = gnac_profiles_properties_filter_text_for_display(
1248
profile->generic->description, MAX_DESCR_DISPLAY_SIZE);
1249
gtk_label_set_text(GTK_LABEL(widget), descr);
1253
gnac_profiles_mgr_show_description_frame(TRUE);
1255
g_list_free_full(selected, (GDestroyNotify) gtk_tree_row_reference_free);
1260
gnac_profiles_mgr_on_close(GtkWidget *widget,
1263
GtkWidget *window = gnac_profiles_mgr_get_widget("profile_manager_window");
1264
gtk_widget_hide(window);
1265
gnac_profiles_populate_combo();
1270
gnac_profiles_mgr_on_delete_event(GtkWidget *widget,
1274
gnac_profiles_mgr_on_close(NULL, NULL);
1280
gnac_profiles_mgr_list_on_key_pressed(GtkWidget *widget,
1284
if (gnac_ui_utils_event_is_delete_key(event)) {
1285
gnac_profiles_mgr_on_remove(NULL, NULL);
1294
gnac_profiles_mgr_on_key_pressed(GtkWidget *widget,
1298
if (gnac_ui_utils_event_is_escape_key(event)) {
1299
gnac_profiles_mgr_on_close(NULL, NULL);