41#include "main_window.h"
51 if (ui->gui->input_filename != NULL)
53 g_string_free(ui->gui->input_filename,TRUE);
55 ui->gui->input_filename = g_string_new(filename);
57 if (ui->gui->open_file_chooser_button != NULL && !ui->status->file_selection_changed)
59 gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(ui->gui->open_file_chooser_button), filename);
62 update_example_output_dir_for_single_file_split(ui);
64 export_cue_file_in_configuration_directory(ui);
75 if (gui->input_filename != NULL)
77 return gui->input_filename->str;
83static gboolean configure_window_callback(GtkWindow *window, GdkEvent *event,
ui_state *ui)
85 ui_set_main_win_position(ui, event->configure.x, event->configure.y);
86 ui_set_main_win_size(ui, event->configure.width, event->configure.height);
88 refresh_drawing_area(ui->gui, ui->infos);
89 refresh_preview_drawing_areas(ui->gui);
91 clear_previous_distances(ui);
96static void initialize_window(GApplication *app,
ui_state *ui)
98 GtkWidget *window = gtk_application_window_new(GTK_APPLICATION(app));
99 ui->gui->window = window;
101 g_signal_connect(G_OBJECT(window),
"configure-event", G_CALLBACK(configure_window_callback), ui);
103 gtk_window_set_title(GTK_WINDOW(window), PACKAGE_NAME
" "VERSION);
104 gtk_container_set_border_width(GTK_CONTAINER(window), 0);
106 g_signal_connect(G_OBJECT(window),
"delete_event", G_CALLBACK(exit_application), ui);
108 GString *imagefile = g_string_new(
"");
109 build_path(imagefile, PIXMAP_PATH,
"mp3splt-gtk_ico"ICON_EXT);
110 GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(imagefile->str, NULL);
111 gtk_window_set_default_icon(pixbuf);
112 g_string_free(imagefile, TRUE);
115static void activate_url(GtkAboutDialog *about,
const gchar *link,
ui_state *ui)
118 char default_browser[512] = {
'\0' };
119 DWORD dwType, dwSize =
sizeof(default_browser) - 1;
121 SHGetValue(HKEY_CURRENT_USER,
122 TEXT(
"Software\\Clients\\StartMenuInternet"),
128 if (default_browser[0] !=
'\0')
130 SHGetValue(HKEY_LOCAL_MACHINE,
131 TEXT(
"SOFTWARE\\Clients\\StartMenuInternet"),
138 if (default_browser[0] !=
'\0')
140 char browser_exe[2048] = {
'\0' };
141 dwSize =
sizeof(browser_exe) - 1;
143 char browser_exe_registry[1024] = {
'\0' };
144 snprintf(browser_exe_registry, 1024,
145 "SOFTWARE\\Clients\\StartMenuInternet\\%s\\shell\\open\\command\\",
148 SHGetValue(HKEY_LOCAL_MACHINE,
149 TEXT(browser_exe_registry), TEXT(
""),
150 &dwType, browser_exe, &dwSize);
152 if (browser_exe[0] !=
'\0')
154 gint browser_command_size = strlen(browser_exe) + strlen(link) + 2;
155 char *browser_command = g_malloc(
sizeof(
char) * browser_command_size);
158 snprintf(browser_command, browser_command_size,
"%s %s",
162 PROCESS_INFORMATION pinf;
163 ZeroMemory(&si,
sizeof(si));
165 ZeroMemory(&pinf,
sizeof(pinf));
167 if (! CreateProcess(NULL, browser_command,
168 NULL, NULL, FALSE, 0, NULL, NULL, &si, &pinf))
173 CloseHandle(pinf.hProcess);
174 CloseHandle(pinf.hThread);
176 g_free(browser_command);
177 browser_command = NULL;
184static void about_window(GSimpleAction *action, GVariant *parameter, gpointer data)
188 GtkWidget *dialog = gtk_about_dialog_new();
190 GString *imagefile = g_string_new(
"");
191 build_path(imagefile, PIXMAP_PATH,
"mp3splt-gtk.png");
192 GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(imagefile->str, NULL);
193 gtk_about_dialog_set_logo(GTK_ABOUT_DIALOG(dialog), pixbuf);
194 g_string_free(imagefile, TRUE);
196 gtk_about_dialog_set_program_name(GTK_ABOUT_DIALOG(dialog), (gchar *)PACKAGE_NAME);
197 gtk_about_dialog_set_version(GTK_ABOUT_DIALOG(dialog), VERSION);
198 gtk_about_dialog_set_copyright(GTK_ABOUT_DIALOG(dialog),
199 PACKAGE_NAME
" : Copyright © 2005-2014 Alexandru"
200 " Munteanu \n mp3splt : Copyright © 2002-2005 Matteo Trotta");
202 gchar b3[100] = {
'\0' };
203 gchar *b1 = _(
"using");
205 char *library_version = mp3splt_get_version();
206 g_snprintf(b3, 100,
"-%s-\n%s libmp3splt %s",
207 _(
"release of "MP3SPLT_GTK_DATE), b1, library_version);
208 free(library_version);
210 gtk_about_dialog_set_comments(GTK_ABOUT_DIALOG(dialog), b3);
212 gtk_about_dialog_set_license(GTK_ABOUT_DIALOG(dialog),
214 "This program is free software; you can "
215 "redistribute it and/or \n"
216 "modify it under the terms of the GNU General Public License\n"
217 "as published by the Free Software "
218 "Foundation; either version 2\n"
219 "of the License, or (at your option) "
220 "any later version.\n\n"
221 "This program is distributed in the "
222 "hope that it will be useful,\n"
223 "but WITHOUT ANY WARRANTY; without even "
224 "the implied warranty of\n"
225 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
226 "GNU General Public License for more details.\n\n"
227 "You should have received a copy of the GNU General Public License\n"
228 "along with this program; if not, write "
229 "to the Free Software\n"
231 "51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.");
233 g_signal_connect(G_OBJECT(dialog),
"activate-link", G_CALLBACK(activate_url), ui);
235 gtk_about_dialog_set_website_label(GTK_ABOUT_DIALOG(dialog),
236 "http://mp3splt.sourceforge.net");
237 gtk_about_dialog_set_website(GTK_ABOUT_DIALOG(dialog),
238 "http://mp3splt.sourceforge.net");
240 gtk_about_dialog_set_translator_credits(GTK_ABOUT_DIALOG(dialog),
241 "Mario Blättermann <mariobl@gnome.org>");
243 gtk_dialog_run(GTK_DIALOG(dialog));
244 gtk_widget_destroy(dialog);
253 guint status_id = gtk_statusbar_get_context_id(gui->status_bar,
"mess");
254 gtk_statusbar_pop(gui->status_bar, status_id);
281 if (mess_type == SPLT_MESSAGE_INFO || mess_type == SPLT_MESSAGE_WARNING)
283 guint status_id = gtk_statusbar_get_context_id(gui->status_bar,
"mess");
284 gtk_statusbar_pop(gui->status_bar, status_id);
285 gtk_statusbar_push(gui->status_bar, status_id, text);
291void set_stop_split_safe(gboolean value,
ui_state *ui)
293 lock_mutex(&ui->variables_mutex);
294 ui->status->stop_split = value;
295 unlock_mutex(&ui->variables_mutex);
301 lmanager_stop_split(ui);
303 set_stop_split_safe(TRUE, ui);
307 gtk_widget_set_sensitive(widget, FALSE);
313void set_is_splitting_safe(gboolean value,
ui_state *ui)
315 lock_mutex(&ui->variables_mutex);
316 ui->status->splitting = value;
317 unlock_mutex(&ui->variables_mutex);
320gint get_is_splitting_safe(
ui_state *ui)
322 lock_mutex(&ui->variables_mutex);
323 gint is_splitting = ui->status->splitting;
324 unlock_mutex(&ui->variables_mutex);
328static void _set_process_in_progress_safe(gboolean value,
ui_state *ui)
330 lock_mutex(&ui->variables_mutex);
333 ui->status->process_in_progress++;
337 ui->status->process_in_progress--;
339 unlock_mutex(&ui->variables_mutex);
342void set_process_in_progress_and_wait_safe(gboolean value,
ui_state *ui)
346 while (get_process_in_progress_safe(ui))
348 g_usleep(G_USEC_PER_SEC / 4);
352 _set_process_in_progress_safe(value, ui);
355void set_process_in_progress_safe(gboolean value,
ui_state *ui)
358 _set_process_in_progress_safe(value, ui);
362gint get_process_in_progress_safe(
ui_state *ui)
364 lock_mutex(&ui->variables_mutex);
365 gint process_in_progress = ui->status->process_in_progress;
366 unlock_mutex(&ui->variables_mutex);
367 return process_in_progress > 0;
373 if (get_is_splitting_safe(ui))
389void set_split_file_mode(gint file_mode,
ui_state *ui)
391 ui->infos->split_file_mode = file_mode;
394gint get_split_file_mode(
ui_state *ui)
396 return ui->infos->split_file_mode;
399static void single_file_mode_split_button_event(GtkWidget *widget,
ui_state *ui)
401 set_split_file_mode(FILE_MODE_SINGLE, ui);
405static void show_messages_history_window(GSimpleAction *action, GVariant *parameter, gpointer data)
408 wh_show_window(ui->gui->mess_history_window);
412static void ShowHelp(GSimpleAction *action, GVariant *parameter, gpointer data)
414 GError* gerror = NULL;
415 gtk_show_uri(gdk_screen_get_default(),
"ghelp:mp3splt-gtk", gtk_get_current_event_time(), &gerror);
419static void player_pause_action(GSimpleAction *action, GVariant *parameter, gpointer data)
425static void player_seek_forward_action(GSimpleAction *action, GVariant *parameter, gpointer data)
429 gfloat total_time = ui->infos->total_time;
430 gfloat new_time = ui->infos->current_time * 10 +
431 (ui->infos->seek_jump_value != 0 ? ui->infos->seek_jump_value :
432 2./100. * total_time * 10);
433 if (new_time > total_time * 10) { new_time = total_time * 10; }
437static void player_seek_backward_action(GSimpleAction *action, GVariant *parameter, gpointer data)
441 gfloat total_time = ui->infos->total_time;
442 gfloat new_time = ui->infos->current_time * 10 -
443 (ui->infos->seek_jump_value != 0 ? ui->infos->seek_jump_value :
444 2./100. * total_time * 10);
445 if (new_time <= 0) { new_time = 0; }
449static void player_big_seek_forward_action(GSimpleAction *action, GVariant *parameter, gpointer data)
453 gfloat total_time = ui->infos->total_time;
454 gfloat new_time = ui->infos->current_time * 10 +
455 (ui->infos->big_seek_jump_value != 0 ? ui->infos->big_seek_jump_value :
456 15./100. * total_time * 10);
457 if (new_time > total_time * 10) { new_time = total_time * 10; }
461static void player_big_seek_backward_action(GSimpleAction *action, GVariant *parameter, gpointer data)
465 gfloat total_time = ui->infos->total_time;
466 gfloat new_time = ui->infos->current_time * 10 -
467 (ui->infos->big_seek_jump_value != 0 ? ui->infos->big_seek_jump_value :
468 15./100. * total_time * 10);
469 if (new_time <= 0) { new_time = 0; }
473static void player_small_seek_forward_action(GSimpleAction *action, GVariant *parameter, gpointer data)
477 gfloat total_time = ui->infos->total_time;
478 gfloat new_time = ui->infos->current_time * 10 + ui->infos->small_seek_jump_value;
479 if (new_time > total_time * 10) { new_time = total_time * 10; }
483static void player_small_seek_backward_action(GSimpleAction *action, GVariant *parameter, gpointer data)
487 gfloat new_time = ui->infos->current_time * 10 - ui->infos->small_seek_jump_value;
488 if (new_time <= 0) { new_time = 0; }
492static void player_seek_to_next_splitpoint_action(GSimpleAction *action, GVariant *parameter, gpointer data)
497 gint time_right = -1;
498 get_current_splitpoints_time_left_right(&time_left, &time_right, NULL, ui);
500 if (time_right != -1)
506static void player_seek_to_previous_splitpoint_action(GSimpleAction *action, GVariant *parameter, gpointer data)
511 gint time_right = -1;
512 get_current_splitpoints_time_left_right(&time_left, &time_right, NULL, ui);
520static int find_closest_splitpoint(
ui_state *ui)
522 gint left_index_point = -1;
523 gint right_index_point = -1;
526 for (i = 0; i < ui->infos->splitnumber; i++ )
529 if (current_point_hundr_secs <= ui->infos->current_time)
531 left_index_point = i;
535 if (current_point_hundr_secs >= ui->infos->current_time)
537 right_index_point = i;
542 if (left_index_point == -1 && right_index_point == -1)
547 gint time_to_left = INT_MAX;
548 if (left_index_point != -1)
553 gint time_to_right = INT_MAX;
554 if (right_index_point != -1)
559 if (time_to_right > time_to_left)
561 return left_index_point;
564 return right_index_point;
567static void delete_closest_splitpoint(GSimpleAction *action, GVariant *parameter, gpointer data)
571 int closest_splitpoint_index = find_closest_splitpoint(ui);
572 if (closest_splitpoint_index == -1)
580static void player_seek_before_closest_splitpoint(GSimpleAction *action, GVariant *parameter, gpointer data)
584 int closest_splitpoint_index = find_closest_splitpoint(ui);
585 if (closest_splitpoint_index == -1) {
return; }
588 player_seek((current_point_hundr_secs * 10) - 100 * 3 * 10, ui);
590 if (closest_splitpoint_index == 0) {
return; }
592 set_preview_start_position_safe(
get_splitpoint_time(closest_splitpoint_index - 1, ui), ui);
593 ui->status->preview_start_splitpoint = closest_splitpoint_index - 1;
594 if (closest_splitpoint_index < ui->infos->splitnumber)
596 set_quick_preview_end_splitpoint_safe(closest_splitpoint_index, ui);
600 set_quick_preview_end_splitpoint_safe(-1, ui);
605 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ui->gui->pause_button), FALSE);
608 ui->status->quick_preview = TRUE;
611static void player_seek_closest_splitpoint_no_pause(GSimpleAction *action, GVariant *parameter, gpointer data)
615 int closest_splitpoint_index = find_closest_splitpoint(ui);
616 if (closest_splitpoint_index == -1) {
return; }
621 set_preview_start_position_safe(current_point_hundr_secs, ui);
622 ui->status->preview_start_splitpoint = closest_splitpoint_index;
624 if (closest_splitpoint_index < (ui->infos->splitnumber - 1))
626 set_quick_preview_end_splitpoint_safe(closest_splitpoint_index + 1, ui);
630 set_quick_preview_end_splitpoint_safe(-1, ui);
635 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ui->gui->pause_button), FALSE);
638 ui->status->quick_preview = TRUE;
641static void player_seek_closest_splitpoint(GSimpleAction *action, GVariant *parameter, gpointer data)
644 player_seek_closest_splitpoint_no_pause(NULL, NULL, ui);
645 ui->status->stop_preview_right_after_start = TRUE;
648static void zoom_in(GSimpleAction *action, GVariant *parameter, gpointer data)
652 gdouble fraction = 40./100. * ui->infos->zoom_coeff;
653 ui->infos->zoom_coeff += fraction;
654 adjust_zoom_coeff(ui->infos);
655 refresh_drawing_area(ui->gui, ui->infos);
658static void zoom_out(GSimpleAction *action, GVariant *parameter, gpointer data)
662 gdouble fraction = 40./100. * ui->infos->zoom_coeff;
663 ui->infos->zoom_coeff -= fraction;
664 adjust_zoom_coeff(ui->infos);
665 refresh_drawing_area(ui->gui, ui->infos);
668void add_filters_to_file_chooser(GtkWidget *file_chooser)
670 GtkFileFilter *our_filter = gtk_file_filter_new();
671 gtk_file_filter_set_name(our_filter, _(
"mp3, ogg vorbis and flac files (*.mp3 *.ogg *.flac)"));
672 gtk_file_filter_add_pattern(our_filter,
"*.mp3");
673 gtk_file_filter_add_pattern(our_filter,
"*.ogg");
674 gtk_file_filter_add_pattern(our_filter,
"*.flac");
675 gtk_file_filter_add_pattern(our_filter,
"*.MP3");
676 gtk_file_filter_add_pattern(our_filter,
"*.OGG");
677 gtk_file_filter_add_pattern(our_filter,
"*.FLAC");
678 gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(file_chooser), our_filter);
680 our_filter = gtk_file_filter_new();
681 gtk_file_filter_set_name (our_filter, _(
"mp3 files (*.mp3)"));
682 gtk_file_filter_add_pattern(our_filter,
"*.mp3");
683 gtk_file_filter_add_pattern(our_filter,
"*.MP3");
684 gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(file_chooser), our_filter);
686 our_filter = gtk_file_filter_new();
687 gtk_file_filter_set_name (our_filter, _(
"ogg vorbis files (*.ogg)"));
688 gtk_file_filter_add_pattern(our_filter,
"*.ogg");
689 gtk_file_filter_add_pattern(our_filter,
"*.OGG");
690 gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(file_chooser), our_filter);
692 our_filter = gtk_file_filter_new();
693 gtk_file_filter_set_name (our_filter, _(
"flac files (*.flac)"));
694 gtk_file_filter_add_pattern(our_filter,
"*.flac");
695 gtk_file_filter_add_pattern(our_filter,
"*.FLAC");
696 gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(file_chooser), our_filter);
699static void file_selection_changed(GtkFileChooser *open_file_chooser,
ui_state *ui)
701 gchar *filename = gtk_file_chooser_get_filename(open_file_chooser);
704 if (previous_fname != NULL && filename != NULL &&
705 strcmp(filename, previous_fname) == 0)
710 if (filename != NULL)
712 ui->status->file_selection_changed = TRUE;
713 file_chooser_ok_event(filename, ui);
714 ui->status->file_selection_changed = FALSE;
722static void file_set_event(GtkFileChooserButton *open_file_chooser_button,
ui_state *ui)
724 file_selection_changed(GTK_FILE_CHOOSER(open_file_chooser_button), ui);
727static GtkWidget *create_choose_file_frame(
ui_state *ui)
729 GtkWidget *open_file_chooser_button = gtk_file_chooser_button_new(_(
"Open file ..."), GTK_FILE_CHOOSER_ACTION_OPEN);
730 dnd_add_drag_data_received_to_widget(open_file_chooser_button, DND_SINGLE_MODE_AUDIO_FILE, ui);
732 ui->gui->open_file_chooser_button = open_file_chooser_button;
733 add_filters_to_file_chooser(open_file_chooser_button);
734 wh_set_browser_directory_handler(ui, open_file_chooser_button);
736 g_signal_connect(G_OBJECT(open_file_chooser_button),
"file-set", G_CALLBACK(file_set_event), ui);
737 g_signal_connect(G_OBJECT(open_file_chooser_button),
"selection-changed",
738 G_CALLBACK(file_selection_changed), ui);
741 if (fname != NULL && strlen(fname) != 0)
743 gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(open_file_chooser_button),
get_input_filename(ui->gui));
746 return open_file_chooser_button;
750static GtkWidget *create_main_vbox(
ui_state *ui)
752 GtkWidget *main_vbox = wh_vbox_new();
753 gtk_container_set_border_width(GTK_CONTAINER(main_vbox), 0);
756 GtkWidget *notebook = gtk_notebook_new();
758 gtk_box_pack_start(GTK_BOX(main_vbox), notebook, TRUE, TRUE, 0);
759 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(notebook), TRUE);
760 gtk_notebook_set_show_border(GTK_NOTEBOOK(notebook), FALSE);
761 gtk_notebook_set_scrollable(GTK_NOTEBOOK(notebook), TRUE);
764 GtkWidget *player_vbox = wh_vbox_new();
767 GtkWidget *top_hbox = wh_hbox_new();
768 gtk_box_pack_start(GTK_BOX(player_vbox), top_hbox, FALSE, FALSE, 0);
771 gtk_box_pack_start(GTK_BOX(top_hbox), create_choose_file_frame(ui), TRUE, TRUE, 0);
774 GtkWidget *split_button = wh_create_cool_button(
"system-run",_(
"Split"), FALSE);
775 g_signal_connect(G_OBJECT(split_button),
"clicked",
776 G_CALLBACK(single_file_mode_split_button_event), ui);
777 gtk_widget_set_tooltip_text(split_button, _(
"Split the current file"));
778 gtk_box_pack_start(GTK_BOX(top_hbox), split_button, FALSE, FALSE, 4);
781 gtk_box_pack_start(GTK_BOX(player_vbox), ui->gui->player_box, FALSE, FALSE, 0);
784 gtk_box_pack_start(GTK_BOX(player_vbox), ui->gui->playlist_box, TRUE, TRUE, 0);
786 GtkWidget *notebook_label = wh_create_cool_label(NULL, _(
"Manual single file split"));
787 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), player_vbox, notebook_label);
799 GtkWidget *special_split_vbox = wh_vbox_new();
800 gtk_container_set_border_width(GTK_CONTAINER(special_split_vbox), 0);
802 gtk_box_pack_start(GTK_BOX(special_split_vbox), frame, TRUE, TRUE, 0);
804 notebook_label = wh_create_cool_label(NULL, _(
"Batch & automatic split"));
805 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), special_split_vbox, notebook_label);
811 GtkProgressBar *percent_progress_bar = GTK_PROGRESS_BAR(gtk_progress_bar_new());
812 ui->gui->percent_progress_bar = percent_progress_bar;
813 gtk_progress_bar_set_fraction(percent_progress_bar, 0.0);
814 gtk_progress_bar_set_text(percent_progress_bar,
"");
816 gtk_progress_bar_set_show_text(percent_progress_bar, TRUE);
818 GtkWidget *hbox = wh_hbox_new();
819 gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(percent_progress_bar), TRUE, TRUE, 0);
822 GtkWidget *cancel_button = wh_create_cool_button(
"process-stop", _(
"S_top"), FALSE);
823 ui->gui->cancel_button = cancel_button;
825 gtk_box_pack_start(GTK_BOX(hbox), cancel_button, FALSE, TRUE, 3);
826 gtk_widget_set_sensitive(cancel_button, FALSE);
828 gtk_box_pack_start(GTK_BOX(main_vbox), hbox, FALSE, FALSE, 2);
834 GtkStatusbar *status_bar = GTK_STATUSBAR(gtk_statusbar_new());
835 ui->gui->status_bar = status_bar;
837 gtk_box_pack_start(GTK_BOX(main_vbox), GTK_WIDGET(status_bar), FALSE, FALSE, 0);
842static void move_and_resize_main_window(
ui_state *ui)
846 gint x = main_win->root_x_pos;
847 gint y = main_win->root_y_pos;
849 if (x != 0 && y != 0)
851 gtk_window_move(GTK_WINDOW(ui->gui->window), x, y);
855 gtk_window_set_position(GTK_WINDOW(ui->gui->window), GTK_WIN_POS_CENTER);
858 gtk_window_resize(GTK_WINDOW(ui->gui->window), main_win->width, main_win->height);
861static void application_startup(GApplication *app,
ui_state *ui)
863 GtkBuilder *builder = gtk_builder_new();
865 gtk_builder_add_from_string(builder,
866 "<?xml version=\"1.0\" ?>"
869 " <menu id=\"appmenu\">"
872 " <attribute name=\"label\" translatable=\"yes\">_Preferences</attribute>"
873 " <attribute name=\"action\">app.preferences</attribute>"
874 " <attribute name=\"accel\"><Primary>p</attribute>"
877 " <attribute name=\"label\" translatable=\"yes\">_Quit</attribute>"
878 " <attribute name=\"action\">app.quit</attribute>"
879 " <attribute name=\"accel\"><Primary>q</attribute>"
884 " <menu id=\"menubar\">"
887 " <attribute name=\"label\" translatable=\"yes\">_File</attribute>"
890 " <attribute name=\"label\" translatable=\"yes\">_Open single file...</attribute>"
891 " <attribute name=\"action\">app.open_single_file</attribute>"
892 " <attribute name=\"accel\"><Primary>o</attribute>"
895 " <attribute name=\"label\" translatable=\"yes\">_Add files or directories to batch...</attribute>"
896 " <attribute name=\"action\">app.add_files_to_batch</attribute>"
897 " <attribute name=\"accel\"><Primary>d</attribute>"
902 " <attribute name=\"label\" translatable=\"yes\">_Import splitpoints from file...</attribute>"
903 " <attribute name=\"action\">app.import_splitpoints_from_file</attribute>"
904 " <attribute name=\"accel\"><Primary>i</attribute>"
907 " <attribute name=\"label\" translatable=\"yes\">_Import splitpoints from _TrackType.org...</attribute>"
908 " <attribute name=\"action\">app.import_splitpoints_from_tracktype</attribute>"
909 " <attribute name=\"accel\"><Primary>t</attribute>"
912 " <attribute name=\"label\" translatable=\"yes\">_Export splitpoints...</attribute>"
913 " <attribute name=\"action\">app.export_splitpoints</attribute>"
914 " <attribute name=\"accel\"><Primary>e</attribute>"
919 " <attribute name=\"label\" translatable=\"yes\">_Split</attribute>"
920 " <attribute name=\"action\">app.split</attribute>"
921 " <attribute name=\"accel\"><Primary>s</attribute>"
924 " <attribute name=\"label\" translatable=\"yes\">_Batch split</attribute>"
925 " <attribute name=\"action\">app.batch_split</attribute>"
926 " <attribute name=\"accel\"><Primary>b</attribute>"
932 " <attribute name=\"label\" translatable=\"yes\">_View</attribute>"
935 " <attribute name=\"label\" translatable=\"yes\">_Splitpoints</attribute>"
936 " <attribute name=\"action\">app.view_splitpoints</attribute>"
937 " <attribute name=\"accel\"><Primary>l</attribute>"
940 " <attribute name=\"label\" translatable=\"yes\">Split _files</attribute>"
941 " <attribute name=\"action\">app.view_split_files</attribute>"
942 " <attribute name=\"accel\"><Primary>f</attribute>"
948 " <attribute name=\"label\" translatable=\"yes\">_Player</attribute>"
951 " <attribute name=\"label\" translatable=\"yes\">P_ause / Play</attribute>"
952 " <attribute name=\"action\">app.pause_play</attribute>"
953 " <attribute name=\"accel\">space</attribute>"
959 " <attribute name=\"label\" translatable=\"yes\">Seek _forward</attribute>"
960 " <attribute name=\"action\">app.seek_forward</attribute>"
961 " <attribute name=\"accel\">Right</attribute>"
964 " <attribute name=\"label\" translatable=\"yes\">Seek _backward</attribute>"
965 " <attribute name=\"action\">app.seek_backward</attribute>"
966 " <attribute name=\"accel\">Left</attribute>"
969 " <attribute name=\"label\" translatable=\"yes\">Small seek f_orward</attribute>"
970 " <attribute name=\"action\">app.small_seek_forward</attribute>"
971 " <attribute name=\"accel\"><Alt>Right</attribute>"
974 " <attribute name=\"label\" translatable=\"yes\">Small seek back_ward</attribute>"
975 " <attribute name=\"action\">app.small_seek_backward</attribute>"
976 " <attribute name=\"accel\"><Alt>Left</attribute>"
979 " <attribute name=\"label\" translatable=\"yes\">Big seek fo_rward</attribute>"
980 " <attribute name=\"action\">app.big_seek_forward</attribute>"
981 " <attribute name=\"accel\"><Shift>Right</attribute>"
984 " <attribute name=\"label\" translatable=\"yes\">Big seek bac_kward</attribute>"
985 " <attribute name=\"action\">app.big_seek_backward</attribute>"
986 " <attribute name=\"accel\"><Shift>Left</attribute>"
989 " <attribute name=\"label\" translatable=\"yes\">Seek to _next splitpoint</attribute>"
990 " <attribute name=\"action\">app.seek_next_splitpoint</attribute>"
991 " <attribute name=\"accel\"><Primary>Right</attribute>"
994 " <attribute name=\"label\" translatable=\"yes\">Seek to _previous splitpoint</attribute>"
995 " <attribute name=\"action\">app.seek_previous_splitpoint</attribute>"
996 " <attribute name=\"accel\"><Primary>Left</attribute>"
1002 " <attribute name=\"label\" translatable=\"yes\">Preview clos_est splitpoint</attribute>"
1003 " <attribute name=\"action\">app.preview_closest</attribute>"
1004 " <attribute name=\"accel\"><Shift>Up</attribute>"
1007 " <attribute name=\"label\" translatable=\"yes\">Preview _closest splitpoint & pause</attribute>"
1008 " <attribute name=\"action\">app.preview_closest_and_pause</attribute>"
1009 " <attribute name=\"accel\"><Primary>Up</attribute>"
1012 " <attribute name=\"label\" translatable=\"yes\">Preview before c_losest splitpoint</attribute>"
1013 " <attribute name=\"action\">app.preview_before_closest</attribute>"
1014 " <attribute name=\"accel\"><Primary>Down</attribute>"
1020 " <attribute name=\"label\" translatable=\"yes\">Add _splitpoint</attribute>"
1021 " <attribute name=\"action\">app.add_splitpoint</attribute>"
1022 " <attribute name=\"accel\">s</attribute>"
1025 " <attribute name=\"label\" translatable=\"yes\">_Delete closest splitpoint</attribute>"
1026 " <attribute name=\"action\">app.delete_closest_splitpoint</attribute>"
1027 " <attribute name=\"accel\">d</attribute>"
1033 " <attribute name=\"label\" translatable=\"yes\">Zoom _in</attribute>"
1034 " <attribute name=\"action\">app.zoom_in</attribute>"
1035 " <attribute name=\"accel\"><Primary>plus</attribute>"
1038 " <attribute name=\"label\" translatable=\"yes\">Zoom _out</attribute>"
1039 " <attribute name=\"action\">app.zoom_out</attribute>"
1040 " <attribute name=\"accel\"><Primary>minus</attribute>"
1046 " <attribute name=\"label\" translatable=\"yes\">_Help</attribute>"
1049 " <attribute name=\"label\" translatable=\"yes\">Messages _history</attribute>"
1050 " <attribute name=\"action\">app.messages_history</attribute>"
1051 " <attribute name=\"accel\"><Primary>h</attribute>"
1055 " <attribute name=\"label\" translatable=\"yes\">_Contents</attribute>"
1056 " <attribute name=\"action\">app.contents</attribute>"
1057 " <attribute name=\"accel\">F1</attribute>"
1061 " <attribute name=\"label\" translatable=\"yes\">_About</attribute>"
1062 " <attribute name=\"action\">app.about</attribute>"
1063 " <attribute name=\"accel\"><Primary>a</attribute>"
1069 "</interface>", -1, NULL);
1071 GMenuModel *appmenu = (GMenuModel *) gtk_builder_get_object(builder,
"appmenu");
1072 gtk_application_set_app_menu(GTK_APPLICATION(app), appmenu);
1074 GMenuModel *menubar = (GMenuModel *) gtk_builder_get_object (builder,
"menubar");
1075 gtk_application_set_menubar(GTK_APPLICATION(app), menubar);
1077 g_object_unref(builder);
1080static void parse_command_line_options(gint argc, gchar * argv[],
ui_state *ui)
1084 while ((option = getopt(argc, argv,
"d:")) != -1)
1089 fprintf(stdout, _(
"Setting the output directory to %s.\n"), optarg);
1090 set_output_directory_and_update_ui((gchar *)optarg, ui);
1094 mkdir(optarg, 0777);
1098 ui_fail(ui,
"Error: The specified output directory is inaccessible!\n");
1103 ui_fail(ui, _(
"Option -%c requires an argument.\n"), optopt);
1104 else if (isprint(optopt))
1105 ui_fail(ui, _(
"Unknown option `-%c'.\n"), optopt, NULL);
1107 ui_fail(ui, _(
"Unknown option character `\\x%x'.\n"), optopt);
1121 ui_fail(ui, _(
"Cannot open input file %s\n"), argv[optind]);
1125 char *input_filename = realpath(argv[optind], NULL);
1127 free(input_filename);
1133static void application_activate(GApplication *app,
ui_state *ui)
1135 initialize_window(app, ui);
1137 GtkWidget *window_vbox = wh_vbox_new();
1138 gtk_container_add(GTK_CONTAINER(ui->gui->window), window_vbox);
1140 gtk_box_pack_start(GTK_BOX(window_vbox), create_main_vbox(ui), TRUE, TRUE, 0);
1142 ui_load_preferences(ui);
1144 move_and_resize_main_window(ui);
1146 gtk_widget_show_all(ui->gui->window);
1148 if (ui->infos->selected_player != PLAYER_GSTREAMER)
1150 gtk_widget_hide(ui->gui->playlist_box);
1153 hide_freedb_spinner(ui->gui);
1155 import_cue_file_from_the_configuration_directory(ui);
1157 parse_command_line_options(ui->argc, ui->argv, ui);
1160static void open_file_menu_action(GSimpleAction *action, GVariant *parameter, gpointer data)
1164 GtkWidget *file_chooser = gtk_file_chooser_dialog_new(_(
"Choose File"), NULL,
1165 GTK_FILE_CHOOSER_ACTION_OPEN,
1167 GTK_RESPONSE_CANCEL,
1169 GTK_RESPONSE_ACCEPT, NULL);
1171 add_filters_to_file_chooser(file_chooser);
1172 wh_set_browser_directory_handler(ui, file_chooser);
1174 if (gtk_dialog_run(GTK_DIALOG(file_chooser)) == GTK_RESPONSE_ACCEPT)
1176 gchar *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(file_chooser));
1177 file_chooser_ok_event(filename, ui);
1185 gtk_widget_destroy(file_chooser);
1189static void multiple_files_add_menu_action(GSimpleAction *action, GVariant *parameter, gpointer data)
1192 multiple_files_add_button_event(NULL, ui);
1195static void import_event_menu_action(GSimpleAction *action, GVariant *parameter, gpointer data)
1201static void show_tracktype_window_menu_action(GSimpleAction *action, GVariant *parameter, gpointer data)
1205 if (ui->gui->freedb_window == NULL)
1207 ui->gui->freedb_window =
1208 wh_create_window_with_close_button(_(
"TrackType"), 500, 300, GTK_WIN_POS_CENTER,
1209 GTK_WINDOW(ui->gui->window),
1210 ui->gui->freedb_widget,
1211 ui->gui->freedb_add_button, NULL);
1214 wh_show_window(ui->gui->freedb_window);
1215 hide_freedb_spinner(ui->gui);
1218static void show_preferences_window_menu_action(GSimpleAction *action, GVariant *parameter, gpointer data)
1222 if (ui->gui->preferences_window == NULL)
1224 ui->gui->preferences_window =
1225 wh_create_window_with_close_button(_(
"Preferences"), 750, 450, GTK_WIN_POS_CENTER,
1226 GTK_WINDOW(ui->gui->window), ui->gui->preferences_widget, NULL);
1229 wh_show_window(ui->gui->preferences_window);
1232static void split_menu_action(GSimpleAction *action, GVariant *parameter, gpointer data)
1235 single_file_mode_split_button_event(NULL, ui);
1238static void batch_split_menu_action(GSimpleAction *action, GVariant *parameter, gpointer data)
1241 batch_file_mode_split_button_event(NULL, ui);
1244static void exit_application_menu_action(GSimpleAction *action, GVariant *parameter, gpointer data)
1247 exit_application(NULL, NULL, ui);
1250static void show_splitpoints_window_menu_action(GSimpleAction *action, GVariant *parameter, gpointer data)
1254 if (ui->gui->splitpoints_window == NULL)
1256 ui->gui->splitpoints_window =
1257 wh_create_window_with_close_button(_(
"Splitpoints"), 500, 300, GTK_WIN_POS_CENTER,
1258 GTK_WINDOW(ui->gui->window),
1259 ui->gui->splitpoints_widget,
1260 ui->gui->scan_trim_silence_button, ui->gui->scan_silence_button, NULL);
1263 wh_show_window(ui->gui->splitpoints_window);
1266static void show_split_files_window_menu_action(GSimpleAction *action, GVariant *parameter, gpointer data)
1270 if (ui->gui->split_files_window == NULL)
1272 ui->gui->split_files_window =
1273 wh_create_window_with_close_button(_(
"Split files"), 500, 300, GTK_WIN_POS_CENTER,
1274 GTK_WINDOW(ui->gui->window),
1275 ui->gui->split_files_widget,
1276 ui->gui->queue_files_button, ui->gui->remove_file_button,
1277 ui->gui->remove_all_files_button, NULL);
1280 wh_show_window(ui->gui->split_files_window);
1283static void add_splitpoint_from_player_menu_action(GSimpleAction *action, GVariant *parameter, gpointer data)
1286 add_splitpoint_from_player(NULL, ui);
1289const static GActionEntry app_entries[] = {
1290 {
"open_single_file", open_file_menu_action},
1291 {
"add_files_to_batch", multiple_files_add_menu_action},
1292 {
"import_splitpoints_from_file", import_event_menu_action},
1293 {
"import_splitpoints_from_tracktype", show_tracktype_window_menu_action},
1294 {
"export_splitpoints", export_menu_action},
1295 {
"preferences", show_preferences_window_menu_action},
1296 {
"split", split_menu_action},
1297 {
"batch_split", batch_split_menu_action},
1298 {
"quit", exit_application_menu_action},
1300 {
"view_splitpoints", show_splitpoints_window_menu_action},
1301 {
"view_split_files", show_split_files_window_menu_action},
1303 {
"pause_play", player_pause_action},
1304 {
"seek_forward", player_seek_forward_action},
1305 {
"seek_backward", player_seek_backward_action},
1306 {
"small_seek_forward", player_small_seek_forward_action},
1307 {
"small_seek_backward", player_small_seek_backward_action},
1308 {
"big_seek_forward", player_big_seek_forward_action},
1309 {
"big_seek_backward", player_big_seek_backward_action},
1310 {
"seek_next_splitpoint", player_seek_to_next_splitpoint_action},
1311 {
"seek_previous_splitpoint", player_seek_to_previous_splitpoint_action},
1312 {
"preview_closest", player_seek_closest_splitpoint_no_pause},
1313 {
"preview_closest_and_pause", player_seek_closest_splitpoint},
1314 {
"preview_before_closest", player_seek_before_closest_splitpoint},
1315 {
"add_splitpoint", add_splitpoint_from_player_menu_action},
1316 {
"delete_closest_splitpoint", delete_closest_splitpoint},
1317 {
"zoom_in", zoom_in},
1318 {
"zoom_out", zoom_out},
1320 {
"messages_history", show_messages_history_window},
1322 {
"contents", ShowHelp},
1324 {
"about", about_window}
1327void create_application(
ui_state *ui)
1329 GtkApplication *app = gtk_application_new(
"net.sf.mp3splt", G_APPLICATION_FLAGS_NONE);
1330 ui->gui->application = app;
1332 g_action_map_add_action_entries(G_ACTION_MAP(app), app_entries, G_N_ELEMENTS(app_entries), ui);
1334 player_key_actions_set_sensitivity(FALSE, ui->gui);
1336 g_signal_connect(app,
"startup", G_CALLBACK(application_startup), ui);
1337 g_signal_connect(app,
"activate", G_CALLBACK(application_activate), ui);
1346 char *error_from_library = mp3splt_get_strerror(ui->mp3splt_state, error);
1347 if (error_from_library == NULL) {
return; }
1350 free(error_from_library);
1351 error_from_library = NULL;
1354static gboolean put_status_message_idle(
ui_with_fname *ui_fname)
1358 g_free(ui_fname->fname);
1364void put_status_message_in_idle(
const gchar *text,
ui_state *ui)
1366 if (text == NULL) {
return; }
1370 ui_fname->fname = strdup(text);
1371 if (ui_fname->fname == NULL)
1377 add_idle(G_PRIORITY_HIGH_IDLE,
1378 (GSourceFunc)put_status_message_idle, ui_fname, NULL);
1381void print_status_bar_confirmation_in_idle(gint error,
ui_state *ui)
1383 char *error_from_library = mp3splt_get_strerror(ui->mp3splt_state, error);
1384 put_status_message_in_idle(error_from_library, ui);
GtkWidget * create_freedb_frame(ui_state *ui)
creates the freedb box
void import_file(gchar *filename, ui_state *ui, gboolean force_import_cue)
Handles the import of an input file (audio or splitpoint)
void import_event(GtkWidget *widget, ui_state *ui)
What happens if the "Import" button is pressed.
void print_status_bar_confirmation(gint error, ui_state *ui)
Output an error message from libmp3splt to the status bar.
void set_input_filename(const gchar *filename, ui_state *ui)
Set the name of the input file.
void put_status_message_with_type(const gchar *text, splt_message_type mess_type, ui_state *ui)
Output a message to the status message bar.
void cancel_button_event(GtkWidget *widget, ui_state *ui)
event for the cancel button
void remove_status_message(gui_state *gui)
Removes status bar message.
void split_button_event(GtkWidget *widget, ui_state *ui)
event for the split button
gchar * get_input_filename(gui_state *gui)
Get the name of the input file.
void put_status_message(const gchar *text, ui_state *ui)
Output a info message to the status message bar.
void create_mess_history_window(ui_state *ui)
Create the message history dialog.
void put_message_in_history(const gchar *message, splt_message_type mess_type, ui_state *ui)
Record this message in the message history.
gint player_is_paused(ui_state *ui)
Check if the player is paused.
void player_seek(gint position, ui_state *ui)
jumps to a position in the song
GtkWidget * create_player_playlist_frame(ui_state *ui)
creates the playlist of the player
GtkWidget * create_player_control_frame(ui_state *ui)
creates the control player frame, stop button, play button, etc.
void pause_event(GtkWidget *widget, ui_state *ui)
pause button event
gchar * get_output_directory(ui_state *ui)
Get the name of the output directory.
GtkWidget * create_choose_preferences(ui_state *ui)
creates the preferences tab
GtkWidget * create_split_files_frame(ui_state *ui)
creates the split files tab
GtkWidget * create_special_split_page(ui_state *ui)
creates the special split page
GtkWidget * create_splitpoints_frame(ui_state *ui)
creates the choose splitpoints frame
gint get_splitpoint_time(gint splitpoint_index, ui_state *ui)
returns a splitpoint from the table
void remove_splitpoint(gint index, gint stop_preview, ui_state *ui)
removes a splitpoint
gint file_exists(const gchar *fname)
check if specified file exists
gint directory_exists(const gchar *directory)
check if specified directory exists