Mercurial > audlegacy-plugins
annotate src/filewriter/filewriter.c @ 3092:1e39f795348c
gio: make sure we return the number of bytes we pulled off the getc() stack.
(This makes wavpack happy, but not libid3tag.)
author | William Pitcock <nenolod@atheme.org> |
---|---|
date | Thu, 30 Apr 2009 07:02:04 -0500 |
parents | 8a7364b4c957 |
children | 0d47d41b39ec |
rev | line source |
---|---|
984 | 1 /* FileWriter-Plugin |
2 * (C) copyright 2007 merging of Disk Writer and Out-Lame by Michael Färber | |
3 * | |
4 * Original Out-Lame-Plugin: | |
5 * (C) copyright 2002 Lars Siebold <khandha5@gmx.net> | |
6 * (C) copyright 2006-2007 porting to audacious by Yoshiki Yazawa <yaz@cc.rim.or.jp> | |
7 * | |
8 * This program is free software; you can redistribute it and/or modify | |
9 * it under the terms of the GNU General Public License as published by | |
10 * the Free Software Foundation; either version 2 of the License, or | |
11 * (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, | |
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 * GNU General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU General Public License | |
19 * along with this program; if not, write to the Free Software | |
2771
949d790e8e33
fixed FSF HQ address again
Andrew O. Shadoura <bugzilla@tut.by>
parents:
2766
diff
changeset
|
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
984 | 21 */ |
22 | |
23 #include "filewriter.h" | |
24 #include "plugins.h" | |
2874
11ef2164d90b
re-written format conversion using libSAD;
Andrew O. Shadoura <bugzilla@tut.by>
parents:
2873
diff
changeset
|
25 #include "convert.h" |
984 | 26 |
1569
25ea2127eefa
filewriter: fix symbol collisions
William Pitcock <nenolod@atheme.org>
parents:
1525
diff
changeset
|
27 struct format_info input; |
25ea2127eefa
filewriter: fix symbol collisions
William Pitcock <nenolod@atheme.org>
parents:
1525
diff
changeset
|
28 |
984 | 29 static GtkWidget *configure_win = NULL, *configure_vbox; |
30 static GtkWidget *path_hbox, *path_label, *path_dirbrowser; | |
31 static GtkWidget *configure_bbox, *configure_ok, *configure_cancel; | |
32 | |
33 static GtkWidget *fileext_hbox, *fileext_label, *fileext_combo, *plugin_button; | |
1000 | 34 |
35 enum fileext_t | |
36 { | |
2181
bbb631ab78e9
started initial (very humble) efforts on making FileWriter a general
mf0102 <0102@gmx.at>
parents:
2124
diff
changeset
|
37 WAV = 0, |
1000 | 38 #ifdef FILEWRITER_MP3 |
2181
bbb631ab78e9
started initial (very humble) efforts on making FileWriter a general
mf0102 <0102@gmx.at>
parents:
2124
diff
changeset
|
39 MP3, |
1000 | 40 #endif |
41 #ifdef FILEWRITER_VORBIS | |
2181
bbb631ab78e9
started initial (very humble) efforts on making FileWriter a general
mf0102 <0102@gmx.at>
parents:
2124
diff
changeset
|
42 VORBIS, |
1000 | 43 #endif |
44 #ifdef FILEWRITER_FLAC | |
2181
bbb631ab78e9
started initial (very humble) efforts on making FileWriter a general
mf0102 <0102@gmx.at>
parents:
2124
diff
changeset
|
45 FLAC, |
1000 | 46 #endif |
2181
bbb631ab78e9
started initial (very humble) efforts on making FileWriter a general
mf0102 <0102@gmx.at>
parents:
2124
diff
changeset
|
47 FILEEXT_MAX |
1000 | 48 }; |
49 | |
2970
57d499fc5056
revert default format to wav
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
2969
diff
changeset
|
50 static gint fileext = WAV; |
1000 | 51 static gchar *fileext_str[] = |
52 { | |
2181
bbb631ab78e9
started initial (very humble) efforts on making FileWriter a general
mf0102 <0102@gmx.at>
parents:
2124
diff
changeset
|
53 "wav", |
1000 | 54 #ifdef FILEWRITER_MP3 |
2181
bbb631ab78e9
started initial (very humble) efforts on making FileWriter a general
mf0102 <0102@gmx.at>
parents:
2124
diff
changeset
|
55 "mp3", |
1000 | 56 #endif |
57 #ifdef FILEWRITER_VORBIS | |
2181
bbb631ab78e9
started initial (very humble) efforts on making FileWriter a general
mf0102 <0102@gmx.at>
parents:
2124
diff
changeset
|
58 "ogg", |
1000 | 59 #endif |
60 #ifdef FILEWRITER_FLAC | |
2181
bbb631ab78e9
started initial (very humble) efforts on making FileWriter a general
mf0102 <0102@gmx.at>
parents:
2124
diff
changeset
|
61 "flac" |
1000 | 62 #endif |
63 }; | |
64 | |
3041
d6fa54737096
Copying structs is not a good idea. Lets use a pointer here.
William Pitcock <nenolod@atheme.org>
parents:
3020
diff
changeset
|
65 static FileWriter *plugin; |
984 | 66 |
67 static GtkWidget *saveplace_hbox, *saveplace; | |
68 static gboolean save_original = TRUE; | |
69 | |
70 static GtkWidget *filenamefrom_hbox, *filenamefrom_label, *filenamefrom_toggle; | |
71 static gboolean filenamefromtags = TRUE; | |
72 | |
73 static GtkWidget *use_suffix_toggle = NULL; | |
74 static gboolean use_suffix = FALSE; | |
75 | |
76 static GtkWidget *prependnumber_toggle; | |
2969
20ad1c7ff026
changed default values for filewriter:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
2950
diff
changeset
|
77 static gboolean prependnumber = TRUE; |
984 | 78 |
79 static gchar *file_path = NULL; | |
80 | |
2766
6d08e3120615
make some file filewriter backends use callbacks instead of calling VFS directly
Andrew O. Shadoura <bugzilla@tut.by>
parents:
2227
diff
changeset
|
81 VFSFile *output_file = NULL; |
6d08e3120615
make some file filewriter backends use callbacks instead of calling VFS directly
Andrew O. Shadoura <bugzilla@tut.by>
parents:
2227
diff
changeset
|
82 guint64 offset = 0; |
6d08e3120615
make some file filewriter backends use callbacks instead of calling VFS directly
Andrew O. Shadoura <bugzilla@tut.by>
parents:
2227
diff
changeset
|
83 Tuple *tuple = NULL; |
6d08e3120615
make some file filewriter backends use callbacks instead of calling VFS directly
Andrew O. Shadoura <bugzilla@tut.by>
parents:
2227
diff
changeset
|
84 |
3020
fdcf79446ddf
Port to new API, lowest prio and NO_DEVICES to avoid autoselect.
Tony Vroon <chainsaw@gentoo.org>
parents:
2970
diff
changeset
|
85 static OutputPluginInitStatus file_init(void); |
984 | 86 static void file_about(void); |
87 static gint file_open(AFormat fmt, gint rate, gint nch); | |
88 static void file_write(void *ptr, gint length); | |
2766
6d08e3120615
make some file filewriter backends use callbacks instead of calling VFS directly
Andrew O. Shadoura <bugzilla@tut.by>
parents:
2227
diff
changeset
|
89 static gint file_write_output(void *ptr, gint length); |
984 | 90 static void file_close(void); |
91 static void file_flush(gint time); | |
92 static void file_pause(short p); | |
93 static gint file_free(void); | |
94 static gint file_playing(void); | |
95 static gint file_get_written_time(void); | |
96 static gint file_get_output_time(void); | |
97 static void file_configure(void); | |
98 | |
99 OutputPlugin file_op = | |
100 { | |
1651 | 101 .description = "FileWriter Plugin", |
3020
fdcf79446ddf
Port to new API, lowest prio and NO_DEVICES to avoid autoselect.
Tony Vroon <chainsaw@gentoo.org>
parents:
2970
diff
changeset
|
102 .probe_priority = 0, |
1651 | 103 .init = file_init, |
104 .about = file_about, | |
105 .configure = file_configure, | |
106 .open_audio = file_open, | |
107 .write_audio = file_write, | |
108 .close_audio = file_close, | |
109 .flush = file_flush, | |
110 .pause = file_pause, | |
111 .buffer_free = file_free, | |
112 .buffer_playing = file_playing, | |
113 .output_time = file_get_output_time, | |
114 .written_time = file_get_written_time | |
984 | 115 }; |
116 | |
1076 | 117 OutputPlugin *file_oplist[] = { &file_op, NULL }; |
118 | |
1651 | 119 SIMPLE_OUTPUT_PLUGIN(filewriter, file_oplist); |
984 | 120 |
3042 | 121 FileWriter *plugins[FILEEXT_MAX] = { |
122 &wav_plugin, | |
123 #ifdef FILEWRITER_MP3 | |
124 &mp3_plugin, | |
125 #endif | |
126 #ifdef FILEWRITER_VORBIS | |
127 &vorbis_plugin, | |
128 #endif | |
129 #ifdef FILEWRITER_FLAC | |
130 &flac_plugin, | |
131 #endif | |
132 }; | |
133 | |
984 | 134 static void set_plugin(void) |
135 { | |
136 if (fileext < 0 || fileext >= FILEEXT_MAX) | |
137 fileext = 0; | |
138 | |
3042 | 139 plugin = plugins[fileext]; |
984 | 140 } |
141 | |
3020
fdcf79446ddf
Port to new API, lowest prio and NO_DEVICES to avoid autoselect.
Tony Vroon <chainsaw@gentoo.org>
parents:
2970
diff
changeset
|
142 static OutputPluginInitStatus file_init(void) |
984 | 143 { |
144 ConfigDb *db; | |
145 | |
3043
8a7364b4c957
add a debugging notice
William Pitcock <nenolod@atheme.org>
parents:
3042
diff
changeset
|
146 g_print("file_init called\n"); |
8a7364b4c957
add a debugging notice
William Pitcock <nenolod@atheme.org>
parents:
3042
diff
changeset
|
147 |
2124 | 148 db = aud_cfg_db_open(); |
2807
f06ec6936b7e
migrated some plugins to auto_CFGID
Andrew O. Shadoura <bugzilla@tut.by>
parents:
2775
diff
changeset
|
149 aud_cfg_db_get_int(db, FILEWRITER_CFGID, "fileext", &fileext); |
f06ec6936b7e
migrated some plugins to auto_CFGID
Andrew O. Shadoura <bugzilla@tut.by>
parents:
2775
diff
changeset
|
150 aud_cfg_db_get_string(db, FILEWRITER_CFGID, "file_path", &file_path); |
f06ec6936b7e
migrated some plugins to auto_CFGID
Andrew O. Shadoura <bugzilla@tut.by>
parents:
2775
diff
changeset
|
151 aud_cfg_db_get_bool(db, FILEWRITER_CFGID, "save_original", &save_original); |
f06ec6936b7e
migrated some plugins to auto_CFGID
Andrew O. Shadoura <bugzilla@tut.by>
parents:
2775
diff
changeset
|
152 aud_cfg_db_get_bool(db, FILEWRITER_CFGID, "use_suffix", &use_suffix); |
f06ec6936b7e
migrated some plugins to auto_CFGID
Andrew O. Shadoura <bugzilla@tut.by>
parents:
2775
diff
changeset
|
153 aud_cfg_db_get_bool(db, FILEWRITER_CFGID, "filenamefromtags", &filenamefromtags); |
f06ec6936b7e
migrated some plugins to auto_CFGID
Andrew O. Shadoura <bugzilla@tut.by>
parents:
2775
diff
changeset
|
154 aud_cfg_db_get_bool(db, FILEWRITER_CFGID, "prependnumber", &prependnumber); |
2124 | 155 aud_cfg_db_close(db); |
984 | 156 |
157 if (!file_path) | |
158 file_path = g_strdup(g_get_home_dir()); | |
159 | |
160 set_plugin(); | |
3041
d6fa54737096
Copying structs is not a good idea. Lets use a pointer here.
William Pitcock <nenolod@atheme.org>
parents:
3020
diff
changeset
|
161 if (plugin->init) |
d6fa54737096
Copying structs is not a good idea. Lets use a pointer here.
William Pitcock <nenolod@atheme.org>
parents:
3020
diff
changeset
|
162 plugin->init(&file_write_output); |
3020
fdcf79446ddf
Port to new API, lowest prio and NO_DEVICES to avoid autoselect.
Tony Vroon <chainsaw@gentoo.org>
parents:
2970
diff
changeset
|
163 |
fdcf79446ddf
Port to new API, lowest prio and NO_DEVICES to avoid autoselect.
Tony Vroon <chainsaw@gentoo.org>
parents:
2970
diff
changeset
|
164 return OUTPUT_PLUGIN_INIT_NO_DEVICES; |
984 | 165 } |
166 | |
167 void file_about(void) | |
168 { | |
169 static GtkWidget *dialog; | |
170 | |
171 if (dialog != NULL) | |
172 return; | |
173 | |
1677
f6f5603a0954
xmms_show_message() changed to audacious_info_dialog()
Matti Hamalainen <ccr@tnsp.org>
parents:
1651
diff
changeset
|
174 dialog = audacious_info_dialog(_("About FileWriter-Plugin"), |
1298
94eee8a16189
The "i18n" saga is still going on...
Stany HENRY <StrassBoy@gmail.com>
parents:
1269
diff
changeset
|
175 _("FileWriter-Plugin\n\n" |
984 | 176 "This program is free software; you can redistribute it and/or modify\n" |
177 "it under the terms of the GNU General Public License as published by\n" | |
178 "the Free Software Foundation; either version 2 of the License, or\n" | |
179 "(at your option) any later version.\n" | |
180 "\n" | |
181 "This program is distributed in the hope that it will be useful,\n" | |
182 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" | |
183 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" | |
184 "GNU General Public License for more details.\n" | |
185 "\n" | |
186 "You should have received a copy of the GNU General Public License\n" | |
187 "along with this program; if not, write to the Free Software\n" | |
2771
949d790e8e33
fixed FSF HQ address again
Andrew O. Shadoura <bugzilla@tut.by>
parents:
2766
diff
changeset
|
188 "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,\n" |
1298
94eee8a16189
The "i18n" saga is still going on...
Stany HENRY <StrassBoy@gmail.com>
parents:
1269
diff
changeset
|
189 "USA."), _("Ok"), FALSE, NULL, NULL); |
984 | 190 gtk_signal_connect(GTK_OBJECT(dialog), "destroy", |
191 GTK_SIGNAL_FUNC(gtk_widget_destroyed), &dialog); | |
192 } | |
193 | |
194 static gint file_open(AFormat fmt, gint rate, gint nch) | |
195 { | |
1011
4a693f5b7054
[svn] - replace xmms_remote_*() with playlist functions.
yaz
parents:
1004
diff
changeset
|
196 gchar *filename = NULL, *temp = NULL; |
1687
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1569
diff
changeset
|
197 const gchar *directory; |
984 | 198 gint pos; |
1004
be2d04b2bd28
[svn] - move bmp_title_input_free() into file_open() to avoid memory leak.
yaz
parents:
1000
diff
changeset
|
199 gint rv; |
1011
4a693f5b7054
[svn] - replace xmms_remote_*() with playlist functions.
yaz
parents:
1004
diff
changeset
|
200 Playlist *playlist; |
984 | 201 |
202 input.format = fmt; | |
203 input.frequency = rate; | |
204 input.channels = nch; | |
205 | |
2057
cf4fa45ffd80
playlist API vtabling
William Pitcock <nenolod@atheme.org>
parents:
2055
diff
changeset
|
206 playlist = aud_playlist_get_active(); |
1011
4a693f5b7054
[svn] - replace xmms_remote_*() with playlist functions.
yaz
parents:
1004
diff
changeset
|
207 if(!playlist) |
4a693f5b7054
[svn] - replace xmms_remote_*() with playlist functions.
yaz
parents:
1004
diff
changeset
|
208 return 0; |
984 | 209 |
2057
cf4fa45ffd80
playlist API vtabling
William Pitcock <nenolod@atheme.org>
parents:
2055
diff
changeset
|
210 pos = aud_playlist_get_position(playlist); |
cf4fa45ffd80
playlist API vtabling
William Pitcock <nenolod@atheme.org>
parents:
2055
diff
changeset
|
211 tuple = aud_playlist_get_tuple(playlist, pos); |
1011
4a693f5b7054
[svn] - replace xmms_remote_*() with playlist functions.
yaz
parents:
1004
diff
changeset
|
212 if(!tuple) |
4a693f5b7054
[svn] - replace xmms_remote_*() with playlist functions.
yaz
parents:
1004
diff
changeset
|
213 return 0; |
984 | 214 |
215 if (filenamefromtags) | |
216 { | |
2055 | 217 gchar *utf8 = aud_tuple_formatter_make_title_string(tuple, aud_get_gentitle_format()); |
1011
4a693f5b7054
[svn] - replace xmms_remote_*() with playlist functions.
yaz
parents:
1004
diff
changeset
|
218 |
2950
dcd8d93ba781
- mp3: adapted to lame-3.98. now filewriter writes valid TLEN.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
2874
diff
changeset
|
219 g_strchomp(utf8); /* chop trailing ^J --yaz */ |
984 | 220 |
221 filename = g_locale_from_utf8(utf8, -1, NULL, NULL, NULL); | |
222 g_free(utf8); | |
223 while (filename != NULL && (temp = strchr(filename, '/')) != NULL) | |
224 *temp = '-'; | |
225 } | |
226 if (filename == NULL) | |
227 { | |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1712
diff
changeset
|
228 filename = g_strdup(aud_tuple_get_string(tuple, FIELD_FILE_NAME, NULL)); |
984 | 229 if (!use_suffix) |
230 if ((temp = strrchr(filename, '.')) != NULL) | |
231 *temp = '\0'; | |
232 } | |
233 if (filename == NULL) | |
234 filename = g_strdup_printf("aud-%d", pos); | |
235 | |
236 | |
237 if (prependnumber) | |
238 { | |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1712
diff
changeset
|
239 gint number = aud_tuple_get_int(tuple, FIELD_TRACK_NUMBER, NULL); |
1687
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1569
diff
changeset
|
240 if (!tuple || !number) |
984 | 241 number = pos + 1; |
242 | |
243 temp = g_strdup_printf("%.02d %s", number, filename); | |
244 g_free(filename); | |
245 filename = temp; | |
246 } | |
247 | |
248 if (save_original) | |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1712
diff
changeset
|
249 directory = aud_tuple_get_string(tuple, FIELD_FILE_PATH, NULL); |
984 | 250 else |
1687
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1569
diff
changeset
|
251 directory = file_path; |
984 | 252 |
1269
0e160bafce1c
- adapt filewriter for file:// scheme.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1113
diff
changeset
|
253 temp = g_strdup_printf("file://%s/%s.%s", |
984 | 254 directory, filename, fileext_str[fileext]); |
255 g_free(filename); | |
256 filename = temp; | |
257 | |
1978 | 258 output_file = aud_vfs_fopen(filename, "w"); |
984 | 259 g_free(filename); |
260 | |
261 if (!output_file) | |
262 return 0; | |
263 | |
3041
d6fa54737096
Copying structs is not a good idea. Lets use a pointer here.
William Pitcock <nenolod@atheme.org>
parents:
3020
diff
changeset
|
264 convert_init(fmt, plugin->format_required, nch); |
2874
11ef2164d90b
re-written format conversion using libSAD;
Andrew O. Shadoura <bugzilla@tut.by>
parents:
2873
diff
changeset
|
265 |
3041
d6fa54737096
Copying structs is not a good idea. Lets use a pointer here.
William Pitcock <nenolod@atheme.org>
parents:
3020
diff
changeset
|
266 rv = (plugin->open)(); |
1004
be2d04b2bd28
[svn] - move bmp_title_input_free() into file_open() to avoid memory leak.
yaz
parents:
1000
diff
changeset
|
267 |
be2d04b2bd28
[svn] - move bmp_title_input_free() into file_open() to avoid memory leak.
yaz
parents:
1000
diff
changeset
|
268 return rv; |
984 | 269 } |
270 | |
271 static void file_write(void *ptr, gint length) | |
272 { | |
2874
11ef2164d90b
re-written format conversion using libSAD;
Andrew O. Shadoura <bugzilla@tut.by>
parents:
2873
diff
changeset
|
273 int len; |
984 | 274 |
2874
11ef2164d90b
re-written format conversion using libSAD;
Andrew O. Shadoura <bugzilla@tut.by>
parents:
2873
diff
changeset
|
275 len = convert_process(ptr, length); |
11ef2164d90b
re-written format conversion using libSAD;
Andrew O. Shadoura <bugzilla@tut.by>
parents:
2873
diff
changeset
|
276 |
3041
d6fa54737096
Copying structs is not a good idea. Lets use a pointer here.
William Pitcock <nenolod@atheme.org>
parents:
3020
diff
changeset
|
277 plugin->write(convert_output, len); |
984 | 278 } |
279 | |
2766
6d08e3120615
make some file filewriter backends use callbacks instead of calling VFS directly
Andrew O. Shadoura <bugzilla@tut.by>
parents:
2227
diff
changeset
|
280 static gint file_write_output(void *ptr, gint length) |
6d08e3120615
make some file filewriter backends use callbacks instead of calling VFS directly
Andrew O. Shadoura <bugzilla@tut.by>
parents:
2227
diff
changeset
|
281 { |
6d08e3120615
make some file filewriter backends use callbacks instead of calling VFS directly
Andrew O. Shadoura <bugzilla@tut.by>
parents:
2227
diff
changeset
|
282 return aud_vfs_fwrite(ptr, 1, length, output_file); |
6d08e3120615
make some file filewriter backends use callbacks instead of calling VFS directly
Andrew O. Shadoura <bugzilla@tut.by>
parents:
2227
diff
changeset
|
283 } |
6d08e3120615
make some file filewriter backends use callbacks instead of calling VFS directly
Andrew O. Shadoura <bugzilla@tut.by>
parents:
2227
diff
changeset
|
284 |
984 | 285 static void file_close(void) |
286 { | |
3041
d6fa54737096
Copying structs is not a good idea. Lets use a pointer here.
William Pitcock <nenolod@atheme.org>
parents:
3020
diff
changeset
|
287 plugin->close(); |
2874
11ef2164d90b
re-written format conversion using libSAD;
Andrew O. Shadoura <bugzilla@tut.by>
parents:
2873
diff
changeset
|
288 convert_free(); |
984 | 289 |
290 if (output_file) | |
291 { | |
1978 | 292 aud_vfs_fclose(output_file); |
984 | 293 } |
294 output_file = NULL; | |
295 } | |
296 | |
297 static void file_flush(gint time) | |
298 { | |
299 if (time < 0) | |
300 return; | |
301 | |
302 file_close(); | |
303 file_open(input.format, input.frequency, input.channels); | |
304 | |
305 offset = time; | |
306 } | |
307 | |
308 static void file_pause(short p) | |
309 { | |
310 } | |
311 | |
312 static gint file_free(void) | |
313 { | |
3041
d6fa54737096
Copying structs is not a good idea. Lets use a pointer here.
William Pitcock <nenolod@atheme.org>
parents:
3020
diff
changeset
|
314 return plugin->free(); |
984 | 315 } |
316 | |
317 static gint file_playing(void) | |
318 { | |
3041
d6fa54737096
Copying structs is not a good idea. Lets use a pointer here.
William Pitcock <nenolod@atheme.org>
parents:
3020
diff
changeset
|
319 return plugin->playing(); |
984 | 320 } |
321 | |
322 static gint file_get_written_time(void) | |
323 { | |
3041
d6fa54737096
Copying structs is not a good idea. Lets use a pointer here.
William Pitcock <nenolod@atheme.org>
parents:
3020
diff
changeset
|
324 return plugin->get_written_time(); |
984 | 325 } |
326 | |
327 static gint file_get_output_time(void) | |
328 { | |
329 return file_get_written_time(); | |
330 } | |
331 | |
332 static void configure_ok_cb(gpointer data) | |
333 { | |
334 ConfigDb *db; | |
335 | |
336 fileext = gtk_combo_box_get_active(GTK_COMBO_BOX(fileext_combo)); | |
337 | |
338 g_free(file_path); | |
339 file_path = g_strdup(gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER(path_dirbrowser))); | |
340 | |
341 use_suffix = | |
342 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(use_suffix_toggle)); | |
343 | |
344 prependnumber = | |
345 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(prependnumber_toggle)); | |
346 | |
2124 | 347 db = aud_cfg_db_open(); |
2807
f06ec6936b7e
migrated some plugins to auto_CFGID
Andrew O. Shadoura <bugzilla@tut.by>
parents:
2775
diff
changeset
|
348 aud_cfg_db_set_int(db, FILEWRITER_CFGID, "fileext", fileext); |
f06ec6936b7e
migrated some plugins to auto_CFGID
Andrew O. Shadoura <bugzilla@tut.by>
parents:
2775
diff
changeset
|
349 aud_cfg_db_set_string(db, FILEWRITER_CFGID, "file_path", file_path); |
f06ec6936b7e
migrated some plugins to auto_CFGID
Andrew O. Shadoura <bugzilla@tut.by>
parents:
2775
diff
changeset
|
350 aud_cfg_db_set_bool(db, FILEWRITER_CFGID, "save_original", save_original); |
f06ec6936b7e
migrated some plugins to auto_CFGID
Andrew O. Shadoura <bugzilla@tut.by>
parents:
2775
diff
changeset
|
351 aud_cfg_db_set_bool(db, FILEWRITER_CFGID, "filenamefromtags", filenamefromtags); |
f06ec6936b7e
migrated some plugins to auto_CFGID
Andrew O. Shadoura <bugzilla@tut.by>
parents:
2775
diff
changeset
|
352 aud_cfg_db_set_bool(db, FILEWRITER_CFGID, "use_suffix", use_suffix); |
f06ec6936b7e
migrated some plugins to auto_CFGID
Andrew O. Shadoura <bugzilla@tut.by>
parents:
2775
diff
changeset
|
353 aud_cfg_db_set_bool(db, FILEWRITER_CFGID, "prependnumber", prependnumber); |
984 | 354 |
2124 | 355 aud_cfg_db_close(db); |
984 | 356 |
357 gtk_widget_destroy(configure_win); | |
358 if (path_dirbrowser) | |
359 gtk_widget_destroy(path_dirbrowser); | |
360 } | |
361 | |
362 static void fileext_cb(GtkWidget *combo, gpointer data) | |
363 { | |
364 fileext = gtk_combo_box_get_active(GTK_COMBO_BOX(fileext_combo)); | |
365 set_plugin(); | |
3041
d6fa54737096
Copying structs is not a good idea. Lets use a pointer here.
William Pitcock <nenolod@atheme.org>
parents:
3020
diff
changeset
|
366 if (plugin->init) |
d6fa54737096
Copying structs is not a good idea. Lets use a pointer here.
William Pitcock <nenolod@atheme.org>
parents:
3020
diff
changeset
|
367 plugin->init(&file_write_output); |
984 | 368 |
3041
d6fa54737096
Copying structs is not a good idea. Lets use a pointer here.
William Pitcock <nenolod@atheme.org>
parents:
3020
diff
changeset
|
369 gtk_widget_set_sensitive(plugin_button, plugin->configure != NULL); |
984 | 370 } |
371 | |
372 static void plugin_configure_cb(GtkWidget *button, gpointer data) | |
373 { | |
3041
d6fa54737096
Copying structs is not a good idea. Lets use a pointer here.
William Pitcock <nenolod@atheme.org>
parents:
3020
diff
changeset
|
374 if (plugin->configure) |
d6fa54737096
Copying structs is not a good idea. Lets use a pointer here.
William Pitcock <nenolod@atheme.org>
parents:
3020
diff
changeset
|
375 plugin->configure(); |
984 | 376 } |
377 | |
378 | |
379 static void saveplace_original_cb(GtkWidget *button, gpointer data) | |
380 { | |
381 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button))) | |
382 { | |
383 gtk_widget_set_sensitive(path_hbox, FALSE); | |
384 save_original = TRUE; | |
385 } | |
386 } | |
387 | |
388 static void saveplace_custom_cb(GtkWidget *button, gpointer data) | |
389 { | |
390 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button))) | |
391 { | |
392 gtk_widget_set_sensitive(path_hbox, TRUE); | |
393 save_original = FALSE; | |
394 } | |
395 } | |
396 | |
397 static void filenamefromtags_cb(GtkWidget *button, gpointer data) | |
398 { | |
399 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button))) | |
400 { | |
401 gtk_widget_set_sensitive(use_suffix_toggle, FALSE); | |
402 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(use_suffix_toggle), FALSE); | |
403 use_suffix = FALSE; | |
404 filenamefromtags = TRUE; | |
405 } | |
406 } | |
407 | |
408 static void filenamefromfilename_cb(GtkWidget *button, gpointer data) | |
409 { | |
410 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button))) | |
411 { | |
412 gtk_widget_set_sensitive(use_suffix_toggle, TRUE); | |
413 filenamefromtags = FALSE; | |
414 } | |
415 } | |
416 | |
417 | |
418 static void configure_destroy(void) | |
419 { | |
420 if (path_dirbrowser) | |
421 gtk_widget_destroy(path_dirbrowser); | |
422 } | |
423 | |
424 static void file_configure(void) | |
425 { | |
426 GtkTooltips *use_suffix_tooltips; | |
427 | |
428 if (!configure_win) | |
429 { | |
430 configure_win = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
431 | |
432 gtk_signal_connect(GTK_OBJECT(configure_win), "destroy", | |
433 GTK_SIGNAL_FUNC(configure_destroy), NULL); | |
434 gtk_signal_connect(GTK_OBJECT(configure_win), "destroy", | |
435 GTK_SIGNAL_FUNC(gtk_widget_destroyed), | |
436 &configure_win); | |
437 | |
438 gtk_window_set_title(GTK_WINDOW(configure_win), | |
985 | 439 _("File Writer Configuration")); |
984 | 440 gtk_window_set_position(GTK_WINDOW(configure_win), GTK_WIN_POS_MOUSE); |
441 | |
442 gtk_container_set_border_width(GTK_CONTAINER(configure_win), 10); | |
443 | |
444 configure_vbox = gtk_vbox_new(FALSE, 10); | |
445 gtk_container_add(GTK_CONTAINER(configure_win), configure_vbox); | |
446 | |
447 | |
448 fileext_hbox = gtk_hbox_new(FALSE, 5); | |
449 gtk_box_pack_start(GTK_BOX(configure_vbox), fileext_hbox, FALSE, FALSE, 0); | |
450 | |
986 | 451 fileext_label = gtk_label_new(_("Output file format:")); |
984 | 452 gtk_box_pack_start(GTK_BOX(fileext_hbox), fileext_label, FALSE, FALSE, 0); |
453 | |
454 fileext_combo = gtk_combo_box_new_text(); | |
455 gtk_combo_box_append_text(GTK_COMBO_BOX(fileext_combo), "WAV"); | |
1000 | 456 #ifdef FILEWRITER_MP3 |
984 | 457 gtk_combo_box_append_text(GTK_COMBO_BOX(fileext_combo), "MP3"); |
1000 | 458 #endif |
459 #ifdef FILEWRITER_VORBIS | |
986 | 460 gtk_combo_box_append_text(GTK_COMBO_BOX(fileext_combo), "Vorbis"); |
1000 | 461 #endif |
462 #ifdef FILEWRITER_FLAC | |
991 | 463 gtk_combo_box_append_text(GTK_COMBO_BOX(fileext_combo), "FLAC"); |
1000 | 464 #endif |
984 | 465 gtk_box_pack_start(GTK_BOX(fileext_hbox), fileext_combo, FALSE, FALSE, 0); |
466 gtk_combo_box_set_active(GTK_COMBO_BOX(fileext_combo), fileext); | |
467 g_signal_connect(G_OBJECT(fileext_combo), "changed", G_CALLBACK(fileext_cb), NULL); | |
468 | |
469 plugin_button = gtk_button_new_with_label(_("Configure")); | |
3041
d6fa54737096
Copying structs is not a good idea. Lets use a pointer here.
William Pitcock <nenolod@atheme.org>
parents:
3020
diff
changeset
|
470 gtk_widget_set_sensitive(plugin_button, plugin->configure != NULL); |
984 | 471 g_signal_connect(G_OBJECT(plugin_button), "clicked", G_CALLBACK(plugin_configure_cb), NULL); |
472 gtk_box_pack_end(GTK_BOX(fileext_hbox), plugin_button, FALSE, FALSE, 0); | |
473 | |
474 | |
475 | |
476 | |
477 gtk_box_pack_start(GTK_BOX(configure_vbox), gtk_hseparator_new(), FALSE, FALSE, 0); | |
478 | |
479 | |
480 | |
481 saveplace_hbox = gtk_hbox_new(FALSE, 5); | |
482 gtk_container_add(GTK_CONTAINER(configure_vbox), saveplace_hbox); | |
483 | |
484 saveplace = gtk_radio_button_new_with_label(NULL, _("Save into original directory")); | |
485 g_signal_connect(G_OBJECT(saveplace), "toggled", G_CALLBACK(saveplace_original_cb), NULL); | |
486 gtk_box_pack_start(GTK_BOX(saveplace_hbox), saveplace, FALSE, FALSE, 0); | |
487 | |
488 saveplace = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(saveplace), | |
489 _("Save into custom directory")); | |
490 g_signal_connect(G_OBJECT(saveplace), "toggled", G_CALLBACK(saveplace_custom_cb), NULL); | |
491 gtk_box_pack_start(GTK_BOX(saveplace_hbox), saveplace, FALSE, FALSE, 0); | |
492 | |
493 if (!save_original) | |
494 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(saveplace), TRUE); | |
495 | |
496 | |
497 | |
498 path_hbox = gtk_hbox_new(FALSE, 5); | |
499 gtk_box_pack_start(GTK_BOX(configure_vbox), path_hbox, FALSE, FALSE, 0); | |
500 | |
501 path_label = gtk_label_new(_("Output file folder:")); | |
502 gtk_box_pack_start(GTK_BOX(path_hbox), path_label, FALSE, FALSE, 0); | |
503 | |
504 path_dirbrowser = | |
1298
94eee8a16189
The "i18n" saga is still going on...
Stany HENRY <StrassBoy@gmail.com>
parents:
1269
diff
changeset
|
505 gtk_file_chooser_button_new (_("Pick a folder"), |
984 | 506 GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER); |
507 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(path_dirbrowser), | |
508 file_path); | |
509 gtk_box_pack_start(GTK_BOX(path_hbox), path_dirbrowser, TRUE, TRUE, 0); | |
510 | |
511 if (save_original) | |
512 gtk_widget_set_sensitive(path_hbox, FALSE); | |
513 | |
514 | |
515 | |
516 | |
517 gtk_box_pack_start(GTK_BOX(configure_vbox), gtk_hseparator_new(), FALSE, FALSE, 0); | |
518 | |
519 | |
520 | |
521 | |
522 filenamefrom_hbox = gtk_hbox_new(FALSE, 5); | |
523 gtk_container_add(GTK_CONTAINER(configure_vbox), filenamefrom_hbox); | |
524 | |
525 filenamefrom_label = gtk_label_new(_("Get filename from:")); | |
526 gtk_box_pack_start(GTK_BOX(filenamefrom_hbox), filenamefrom_label, FALSE, FALSE, 0); | |
527 | |
528 filenamefrom_toggle = gtk_radio_button_new_with_label(NULL, _("original file tags")); | |
529 g_signal_connect(G_OBJECT(filenamefrom_toggle), "toggled", G_CALLBACK(filenamefromtags_cb), NULL); | |
530 gtk_box_pack_start(GTK_BOX(filenamefrom_hbox), filenamefrom_toggle, FALSE, FALSE, 0); | |
531 | |
532 filenamefrom_toggle = | |
533 gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(filenamefrom_toggle), | |
534 _("original filename")); | |
535 g_signal_connect(G_OBJECT(filenamefrom_toggle), "toggled", G_CALLBACK(filenamefromfilename_cb), NULL); | |
536 gtk_box_pack_start(GTK_BOX(filenamefrom_hbox), filenamefrom_toggle, FALSE, FALSE, 0); | |
537 | |
538 if (!filenamefromtags) | |
539 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(filenamefrom_toggle), TRUE); | |
540 | |
541 | |
542 | |
543 | |
544 use_suffix_toggle = gtk_check_button_new_with_label(_("Don't strip file name extension")); | |
545 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(use_suffix_toggle), use_suffix); | |
546 gtk_box_pack_start(GTK_BOX(configure_vbox), use_suffix_toggle, FALSE, FALSE, 0); | |
547 use_suffix_tooltips = gtk_tooltips_new(); | |
1525
bee9eaedefa5
- made the MP3 FileWriter output plugin less braindead
mf0102 <0102@gmx.at>
parents:
1510
diff
changeset
|
548 gtk_tooltips_set_tip(use_suffix_tooltips, use_suffix_toggle, _("If enabled, the extension from the original filename will not be stripped before adding the new file extension to the end."), NULL); |
984 | 549 gtk_tooltips_enable(use_suffix_tooltips); |
550 | |
551 if (filenamefromtags) | |
552 gtk_widget_set_sensitive(use_suffix_toggle, FALSE); | |
553 | |
554 | |
555 | |
556 | |
557 gtk_box_pack_start(GTK_BOX(configure_vbox), gtk_hseparator_new(), FALSE, FALSE, 0); | |
558 | |
559 | |
560 | |
561 | |
562 prependnumber_toggle = gtk_check_button_new_with_label(_("Prepend track number to filename")); | |
563 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(prependnumber_toggle), prependnumber); | |
564 gtk_box_pack_start(GTK_BOX(configure_vbox), prependnumber_toggle, FALSE, FALSE, 0); | |
565 | |
566 | |
567 | |
568 configure_bbox = gtk_hbutton_box_new(); | |
569 gtk_button_box_set_layout(GTK_BUTTON_BOX(configure_bbox), | |
570 GTK_BUTTONBOX_END); | |
571 gtk_button_box_set_spacing(GTK_BUTTON_BOX(configure_bbox), 5); | |
572 gtk_box_pack_start(GTK_BOX(configure_vbox), configure_bbox, | |
573 FALSE, FALSE, 0); | |
574 | |
575 configure_cancel = gtk_button_new_from_stock(GTK_STOCK_CANCEL); | |
576 gtk_signal_connect_object(GTK_OBJECT(configure_cancel), "clicked", | |
577 GTK_SIGNAL_FUNC(gtk_widget_destroy), | |
578 GTK_OBJECT(configure_win)); | |
579 gtk_box_pack_start(GTK_BOX(configure_bbox), configure_cancel, | |
580 TRUE, TRUE, 0); | |
581 | |
582 configure_ok = gtk_button_new_from_stock(GTK_STOCK_OK); | |
583 gtk_signal_connect(GTK_OBJECT(configure_ok), "clicked", | |
584 GTK_SIGNAL_FUNC(configure_ok_cb), NULL); | |
585 gtk_box_pack_start(GTK_BOX(configure_bbox), configure_ok, | |
586 TRUE, TRUE, 0); | |
587 | |
588 gtk_widget_show_all(configure_win); | |
589 } | |
590 } |