/* * Copyright (C) 2004-2005 Vadim Berezniker * http://www.kryptolus.com * * This Program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This Program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GNU Make; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. * http://www.gnu.org/copyleft/gpl.html * */ #include "stdafx.h" #include "common.h" #include "sabbu.h" #include "kryArray.h" #include "kryString.h" #include "krySSACommandParser.h" #include "krySSACommandStripper.h" #include "gui_export.h" #include "gui_export_text.h" #include "gui_export_encore.h" #include "gui_main_script.h" #include "gui_status_bar.h" #include "krySubSSA.h" #include "krySubWriter.h" #include "krySubWriterSSA.h" #include "krySubWriterTXT.h" #include "krySubWriterAdobeEncore.h" extern struct sabbu app; void gui_export_format_options_strip_cb(GtkToggleButton *widget, struct export_settings *settings) { settings->strip_ssa_commands = gtk_toggle_button_get_active(widget); } GtkWidget *gui_export_format_options_create_ui(struct export_settings *settings) { GtkFrame *frame_options = GTK_FRAME(gtk_frame_new(_("Source Format Options"))); GtkVBox *vbox_options = GTK_VBOX(gtk_vbox_new(FALSE, 0)); GtkCheckButton *button_strip_commands = GTK_CHECK_BUTTON(gtk_check_button_new_with_label(_("Strip SSA/ASS commands"))); g_signal_connect(G_OBJECT(button_strip_commands), "toggled", G_CALLBACK(gui_export_format_options_strip_cb), settings); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button_strip_commands), app.prefs->GetInt("StripSSACommands", 1)); gtk_box_pack_start(GTK_BOX(vbox_options), GTK_WIDGET(button_strip_commands), FALSE, TRUE, 2); gtk_container_add(GTK_CONTAINER(frame_options), GTK_WIDGET(vbox_options)); return GTK_WIDGET(frame_options); } void gui_export_format_options_save(struct export_settings *settings) { app.prefs->SetInt("StripSSACommands", settings->strip_ssa_commands); } void gui_export_cb(GtkMenuItem *item, enum kryScriptType type) { char *filename; char *error = NULL; //int rv; struct export_settings *settings = NULL; if(type == KRY_FORMAT_TEXT) { gui_main_disable(); settings = (struct export_settings *) gui_export_text_show(); gui_main_enable(); gui_main_focus(); if(!settings) return; filename = gui_main_save_file(__("FileDialog|Export Script"), file_filter_export_txt, "txt", app.script->GetSuggestedFilename()); } else if(type == KRY_FORMAT_ENCORE) { gui_main_disable(); settings = (struct export_settings *) gui_export_encore_show(); gui_main_enable(); gui_main_focus(); if(!settings) return; filename = gui_main_save_file(__("FileDialog|Export Script"), file_filter_export_encore, "txt", app.script->GetSuggestedFilename()); } else { return; } if(!filename) { kry_free(settings); return; } kryScript *script_copy = app.script->Copy(); if(settings->strip_ssa_commands) { kryListIterator iter; script_copy->GetEventIterator(&iter); while(kryEvent *event = iter.GetNext()) { if(event->GetText()) { krySSACommandStripper stripper(event->GetText()); char *newstr = stripper.GetString(); event->SetText(newstr); kry_free(newstr); } } } krySubWriter *writer = NULL; if(type == KRY_FORMAT_TEXT) { writer = new krySubWriterTXT(script_copy, filename, (struct export_settings_text*) settings); } else if(type == KRY_FORMAT_ENCORE) { writer = new krySubWriterAdobeEncore(script_copy, filename, (struct export_settings_encore*) settings); } else { error = "Invalid export format"; } if(writer) { error = writer->WriteScript(); delete writer; } delete script_copy; if(error) { gui_error(_("Error exporting script: %s"), error); } else { gui_status_bar_push_text_with_color(app.ui.status_bar, STATUS_SAVED, __("Status|Script Exported"), app.ui.status_bar_color_table->Get(STATUS_COLOR_SUCCESS)); } return; }