mp3splt-gtk: src/export.c Source File

mp3splt-gtk 0.9.3.1519

Loading...
Searching...
No Matches
export.c
Go to the documentation of this file.
1/**********************************************************
2 *
3 * mp3splt-gtk -- utility based on mp3splt,
4 * for mp3/ogg splitting without decoding
5 *
6 * Copyright: (C) 2005-2010 Alexandru Munteanu
7 * Contact: m@ioalex.net
8 *
9 * http://mp3splt.sourceforge.net/
10 *
11 *********************************************************/
12
13/**********************************************************
14 *
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
28 * USA.
29 *
30 *********************************************************/
31
32/*!********************************************************
33 * \file
34 * The function that allows to export the current list of
35 * splitpoints as a Cue sheet.
36 *********************************************************/
37
38#include "export.h"
39
41static void export_to_cue_file(const gchar* filename, ui_state *ui, points_and_tags *pat)
42{
43 const gchar *old_fname = mp3splt_get_filename_to_split(ui->mp3splt_state);
44 gchar *fname = NULL;
45 if (old_fname != NULL) { fname = g_strdup(old_fname); }
46
47 gchar *directory = g_path_get_dirname(filename);
48 mp3splt_set_path_of_split(ui->mp3splt_state, directory);
49 g_free(directory);
50
51 mp3splt_erase_all_splitpoints(ui->mp3splt_state);
52 mp3splt_erase_all_tags(ui->mp3splt_state);
53
54 gint i = 0;
55 for (i = 0;i < pat->splitpoints->len; i++)
56 {
57 splt_point *point = g_ptr_array_index(pat->splitpoints, i);
58 mp3splt_append_splitpoint(ui->mp3splt_state, point);
59 splt_tags *tags = g_ptr_array_index(pat->tags, i);
60 mp3splt_append_tags(ui->mp3splt_state, tags);
61 }
62 free_points_and_tags(&pat);
63
64 gchar *file = g_path_get_basename(filename);
65 splt_code err = mp3splt_export(ui->mp3splt_state, CUE_EXPORT, file, SPLT_FALSE);
66 print_status_bar_confirmation_in_idle(err, ui);
67 g_free(file);
68
69 mp3splt_set_filename_to_split(ui->mp3splt_state, fname);
70 if (fname != NULL) { g_free(fname); }
71}
72
73static gpointer export_cue_in_configuration_directory_for_thread(ui_with_pat *ui_pat)
74{
75 ui_state *ui = ui_pat->ui;
76
77 if (ui_pat->previous_thread)
78 {
79 g_thread_join(ui_pat->previous_thread);
80 }
81
82 set_process_in_progress_and_wait_safe(TRUE, ui);
83
84 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_CUE_DISABLE_CUE_FILE_CREATED_MESSAGE,
85 SPLT_TRUE);
86
87 gchar *configuration_directory = get_configuration_directory();
88
89 gsize filename_size = strlen(configuration_directory) + 20;
90 gchar *splitpoints_cue_filename = g_malloc(filename_size * sizeof(gchar));
91 g_snprintf(splitpoints_cue_filename, filename_size, "%s%s%s", configuration_directory,
92 G_DIR_SEPARATOR_S, "splitpoints.cue");
93
94 export_to_cue_file(splitpoints_cue_filename, ui, ui_pat->pat);
95
96 g_free(configuration_directory);
97 g_free(splitpoints_cue_filename);
98
99 mp3splt_set_int_option(ui->mp3splt_state, SPLT_OPT_CUE_DISABLE_CUE_FILE_CREATED_MESSAGE,
100 SPLT_FALSE);
101
102 set_process_in_progress_and_wait_safe(FALSE, ui);
103
104 g_free(ui_pat);
105
106 return NULL;
107}
108
109void export_cue_file_in_configuration_directory(ui_state *ui)
110{
111 if (ui->status->lock_cue_export) { return; }
112
113 ui_with_pat *ui_pat = g_malloc0(sizeof(ui_with_pat));
114 ui_pat->ui = ui;
115 ui_pat->pat = get_splitpoints_and_tags_for_mp3splt_state(ui);
116 if (ui->infos->previous_export_thread != NULL)
117 {
118 ui_pat->previous_thread = ui->infos->previous_export_thread;
119 }
120 else
121 {
122 ui_pat->previous_thread = NULL;
123 }
124
125 ui->infos->previous_export_thread =
126 create_thread((GThreadFunc) export_cue_in_configuration_directory_for_thread,
127 ui_pat, ui, "export_cue_auto");
128}
129
130static gpointer export_to_cue_file_for_thread(ui_with_pat *ui_pat)
131{
132 if (ui_pat->previous_thread)
133 {
134 g_thread_join(ui_pat->previous_thread);
135 }
136
137 set_process_in_progress_and_wait_safe(TRUE, ui_pat->ui);
138
139 export_to_cue_file(ui_pat->export_filename, ui_pat->ui, ui_pat->pat);
140
141 g_free(ui_pat->export_filename);
142
143 set_process_in_progress_and_wait_safe(FALSE, ui_pat->ui);
144
145 g_free(ui_pat);
146
147 return NULL;
148}
149
150void export_menu_action(GSimpleAction *action, GVariant *parameter, gpointer data)
151{
152 ui_state *ui = (ui_state *) data;
153
154 GtkWidget *file_chooser = gtk_file_chooser_dialog_new(_("Cue filename to export"),
155 NULL,
156 GTK_FILE_CHOOSER_ACTION_SAVE,
157 _("_Cancel"),
158 GTK_RESPONSE_CANCEL,
159 _("_Save"),
160 GTK_RESPONSE_ACCEPT,
161 NULL);
162
163 wh_set_browser_directory_handler(ui, file_chooser);
164
165 GtkFileFilter *our_filter = gtk_file_filter_new();
166 gtk_file_filter_set_name (our_filter, _("cue files (*.cue)"));
167 gtk_file_filter_add_pattern(our_filter, "*.cue");
168 gtk_file_filter_add_pattern(our_filter, "*.CUE");
169 gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(file_chooser), our_filter);
170 gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(file_chooser),TRUE);
171
172 if (gtk_dialog_run(GTK_DIALOG(file_chooser)) == GTK_RESPONSE_ACCEPT)
173 {
174 ui_with_pat *ui_pat = g_malloc0(sizeof(ui_with_pat));
175 ui_pat->ui = ui;
176 ui_pat->pat = get_splitpoints_and_tags_for_mp3splt_state(ui);
177 ui_pat->export_filename =
178 g_strdup(gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(file_chooser)));
179 if (ui->infos->previous_export_thread != NULL)
180 {
181 ui_pat->previous_thread = ui->infos->previous_export_thread;
182 }
183 else
184 {
185 ui_pat->previous_thread = NULL;
186 }
187
188 ui->infos->previous_export_thread =
189 create_thread((GThreadFunc) export_to_cue_file_for_thread, ui_pat, ui, "export_cue");
190 }
191
192 gtk_widget_destroy(file_chooser);
193}
194
points_and_tags
Definition ui_types.h:99
ui_state
Definition ui_types.h:509
ui_with_pat
Definition ui_types.h:553