Document and clean up a bunch of exporter related things. Break some friendships, and add a getter for export filter names.

Originally committed to SVN as r5628.
This commit is contained in:
Thomas Goyne 2011-09-28 19:46:41 +00:00
parent cec07012e7
commit 9ce579e187
12 changed files with 287 additions and 490 deletions

View File

@ -44,12 +44,11 @@
#include "ass_file.h"
#include "utils.h"
AssExportFilter::AssExportFilter(wxString const& name, wxString const& description, int priority)
AssExportFilter::AssExportFilter(wxString const& name, wxString const& description, int priority, bool auto_apply)
: name(name)
, priority(priority)
, autoExporter(false)
, hidden(false)
, description(description)
, auto_apply(auto_apply)
{
}
@ -57,44 +56,45 @@ void AssExportFilterChain::Register(AssExportFilter *filter) {
// Remove pipes from name
filter->name.Replace("|", "");
FilterList::iterator begin = GetFilterList()->begin();
FilterList::iterator end = GetFilterList()->end();
int filter_copy = 1;
wxString name = filter->name;
// Find a unique name
while (GetFilter(name))
name = wxString::Format("%s (%d)", filter->name, filter_copy++);
int filter_copy = 0;
wxString tmpnam = filter->name;
if (false) {
try_new_name:
tmpnam = wxString::Format("%s (%d)", filter->name, filter_copy);
}
// Check if name exists
for (FilterList::iterator cur=begin;cur!=end;cur++) {
if ((*cur)->name == tmpnam) {
// Instead of just failing and making a big noise about it, let multiple filters share name, but append something to the later arrivals -jfs
filter_copy++;
goto try_new_name;
}
}
filter->name = tmpnam;
filter->name = name;
// Look for place to insert
FilterList::iterator begin = filters()->begin();
FilterList::iterator end = filters()->end();
while (begin != end && (*begin)->priority >= filter->priority) ++begin;
GetFilterList()->insert(begin, filter);
filters()->insert(begin, filter);
}
void AssExportFilterChain::Unregister(AssExportFilter *filter) {
if (find(GetFilterList()->begin(), GetFilterList()->end(), filter) == GetFilterList()->end())
if (find(filters()->begin(), filters()->end(), filter) == filters()->end())
throw wxString::Format("Unregister export filter: name \"%s\" is not registered.", filter->name);
GetFilterList()->remove(filter);
filters()->remove(filter);
}
FilterList *AssExportFilterChain::GetFilterList() {
FilterList *AssExportFilterChain::filters() {
static FilterList instance;
return &instance;
}
void AssExportFilterChain::Clear() {
delete_clear(*GetFilterList());
const FilterList *AssExportFilterChain::GetFilterList() {
return filters();
}
void AssExportFilterChain::Clear() {
delete_clear(*filters());
}
AssExportFilter *AssExportFilterChain::GetFilter(wxString const& name) {
for (FilterList::iterator it = filters()->begin(); it != filters()->end(); ++it) {
if ((*it)->name == name)
return *it;
}
return 0;
}

View File

@ -58,10 +58,7 @@ typedef std::list<AssExportFilter*> FilterList;
///
/// DOCME
class AssExportFilterChain {
friend class AssExporter;
/// Get the singleton instance
static FilterList *GetFilterList();
static FilterList *filters();
public:
/// Register an export filter
static void Register(AssExportFilter *filter);
@ -69,6 +66,11 @@ public:
static void Unregister(AssExportFilter *filter);
/// Unregister and delete all export filters
static void Clear();
/// Get a filter by name or NULL if it doesn't exist
static AssExportFilter *GetFilter(wxString const& name);
/// Get the list of registered filters
static const FilterList *GetFilterList();
};
/// DOCME
@ -77,7 +79,8 @@ public:
///
/// DOCME
class AssExportFilter {
friend class AssExporter;
/// The filter chain needs to be able to muck around with filter names when
/// they're registered to avoid duplicates
friend class AssExportFilterChain;
/// This filter's name
@ -86,27 +89,31 @@ class AssExportFilter {
/// Higher priority = run earlier
int priority;
protected:
/// Should this filter be used when sending subtitles to the subtitle provider
bool autoExporter;
/// Should this filter be hidden from the user
bool hidden;
/// User-visible description of this filter
wxString description;
/// Should this filter be automatically applied when sending subtitles to
/// the renderer and exporting to non-ASS formats
bool auto_apply;
public:
AssExportFilter(wxString const& name, wxString const& description, int priority = 0);
AssExportFilter(wxString const& name, wxString const& description, int priority = 0, bool auto_apply = false);
virtual ~AssExportFilter() { };
const wxString& GetDescription() const { return description; }
wxString const& GetName() const { return name; }
wxString const& GetDescription() const { return description; }
bool GetAutoApply() const { return auto_apply; }
/// Process subtitles
virtual void ProcessSubs(AssFile *subs, wxWindow *export_dialog=0)=0;
/// @param subs Subtitles to process
/// @param parent_window Window to use as the parent if the filter wishes
/// to open a progress dialog
virtual void ProcessSubs(AssFile *subs, wxWindow *parent_window=0)=0;
/// Draw setup controls
virtual wxWindow *GetConfigDialogWindow(wxWindow *parent) { return 0; }
/// Config dialog is done - extract data now.
virtual void LoadSettings(bool IsDefault) { }
};
/// Load settings to use from the configuration dialog
/// @param is_default If true use default settings instead
virtual void LoadSettings(bool is_default) { }
};

View File

@ -39,41 +39,36 @@
#include "ass_export_filter.h"
#include "ass_exporter.h"
#include "ass_file.h"
#include "frame_main.h"
/// @brief Constructor
/// @param subs
///
AssExporter::AssExporter (AssFile *subs) {
OriginalSubs = subs;
IsDefault = true;
static inline std::list<AssExportFilter*>::const_iterator filter_list_begin() {
return AssExportFilterChain::GetFilterList()->begin();
}
static inline std::list<AssExportFilter*>::const_iterator filter_list_end() {
return AssExportFilterChain::GetFilterList()->end();
}
AssExporter::AssExporter(AssFile *subs)
: original_subs(subs)
, is_default(true)
{
}
/// @brief Destructor
///
AssExporter::~AssExporter () {
}
/// @brief Draw control settings
/// @param parent
/// @param AddTo
///
void AssExporter::DrawSettings(wxWindow *parent,wxSizer *AddTo) {
IsDefault = false;
wxWindow *window;
wxSizer *box;
FilterList::iterator begin = AssExportFilterChain::GetFilterList()->begin();
FilterList::iterator end = AssExportFilterChain::GetFilterList()->end();
for (FilterList::iterator cur=begin;cur!=end;cur++) {
void AssExporter::DrawSettings(wxWindow *parent, wxSizer *target_sizer) {
is_default = false;
for (filter_iterator cur = filter_list_begin(); cur != filter_list_end(); ++cur) {
// Make sure to construct static box sizer first, so it won't overlap
// the controls on wxMac.
box = new wxStaticBoxSizer(wxVERTICAL,parent,(*cur)->name);
window = (*cur)->GetConfigDialogWindow(parent);
wxSizer *box = new wxStaticBoxSizer(wxVERTICAL, parent, (*cur)->GetName());
wxWindow *window = (*cur)->GetConfigDialogWindow(parent);
if (window) {
box->Add(window,0,wxEXPAND,0);
AddTo->Add(box,0,wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM,5);
AddTo->Show(box,false);
Sizers[(*cur)->name] = box;
box->Add(window, 0, wxEXPAND, 0);
target_sizer->Add(box, 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 5);
target_sizer->Show(box, false);
Sizers[(*cur)->GetName()] = box;
}
else {
delete box;
@ -81,101 +76,53 @@ void AssExporter::DrawSettings(wxWindow *parent,wxSizer *AddTo) {
}
}
/// @brief Add filter to chain
/// @param name
///
void AssExporter::AddFilter(wxString name) {
// Get filter
AssExportFilter *filter = NULL;
FilterList::iterator begin = AssExportFilterChain::GetFilterList()->begin();
FilterList::iterator end = AssExportFilterChain::GetFilterList()->end();
for (FilterList::iterator cur=begin;cur!=end;cur++) {
if ((*cur)->name == name) {
filter = *cur;
break;
}
}
void AssExporter::AddFilter(wxString const& name) {
AssExportFilter *filter = AssExportFilterChain::GetFilter(name);
// Check
if (!filter) throw wxString::Format("Filter not found: %s", name);
// Add to list
Filters.push_back(filter);
filters.push_back(filter);
}
/// @brief Adds all autoexporting filters to chain
///
void AssExporter::AddAutoFilters() {
FilterList::iterator begin = AssExportFilterChain::GetFilterList()->begin();
FilterList::iterator end = AssExportFilterChain::GetFilterList()->end();
for (FilterList::iterator cur=begin;cur!=end;cur++) {
if ((*cur)->autoExporter) {
Filters.push_back(*cur);
}
for (filter_iterator it = filter_list_begin(); it != filter_list_end(); ++it) {
if ((*it)->GetAutoApply())
filters.push_back(*it);
}
}
/// @brief Get name of all filters
/// @return
///
wxArrayString AssExporter::GetAllFilterNames() {
wxArrayString names;
FilterList::iterator begin = AssExportFilterChain::GetFilterList()->begin();
FilterList::iterator end = AssExportFilterChain::GetFilterList()->end();
for (FilterList::iterator cur=begin;cur!=end;cur++) {
if (!(*cur)->hidden) names.Add((*cur)->name);
}
transform(filter_list_begin(), filter_list_end(),
std::back_inserter(names), std::mem_fun(&AssExportFilter::GetName));
return names;
}
/// @brief Transform for export
/// @param export_dialog
/// @return
///
AssFile *AssExporter::ExportTransform(wxWindow *export_dialog,bool copy) {
// Copy
AssFile *Subs = copy ? new AssFile(*OriginalSubs) : OriginalSubs;
AssFile *AssExporter::ExportTransform(wxWindow *export_dialog, bool copy) {
AssFile *subs = copy ? new AssFile(*original_subs) : original_subs;
// Run filters
for (FilterList::iterator cur=Filters.begin();cur!=Filters.end();cur++) {
(*cur)->LoadSettings(IsDefault);
(*cur)->ProcessSubs(Subs, export_dialog);
for (filter_iterator cur = filters.begin(); cur != filters.end(); cur++) {
(*cur)->LoadSettings(is_default);
(*cur)->ProcessSubs(subs, export_dialog);
}
// Done
return Subs;
return subs;
}
/// @brief Export
/// @param filename
/// @param charset
/// @param export_dialog
///
void AssExporter::Export(wxString filename, wxString charset, wxWindow *export_dialog) {
std::auto_ptr<AssFile> Subs(ExportTransform(export_dialog,true));
Subs->Save(filename,false,false,charset);
void AssExporter::Export(wxString const& filename, wxString const& charset, wxWindow *export_dialog) {
std::auto_ptr<AssFile> subs(ExportTransform(export_dialog, true));
subs->Save(filename, false, false, charset);
}
/// @brief Get window associated with name
/// @param name
/// @return
///
wxSizer *AssExporter::GetSettingsSizer(wxString name) {
SizerMap::iterator pos = Sizers.find(name);
if (pos == Sizers.end()) return NULL;
else return pos->second;
wxSizer *AssExporter::GetSettingsSizer(wxString const& name) {
std::map<wxString, wxSizer*>::iterator pos = Sizers.find(name);
if (pos == Sizers.end()) return 0;
return pos->second;
}
/// @brief Get description of filter
/// @param name
///
wxString AssExporter::GetDescription(wxString name) {
FilterList::iterator begin = AssExportFilterChain::GetFilterList()->begin();
FilterList::iterator end = AssExportFilterChain::GetFilterList()->end();
for (FilterList::iterator cur=begin;cur!=end;cur++) {
if ((*cur)->name == name) {
return (*cur)->GetDescription();
}
}
wxString const& AssExporter::GetDescription(wxString const& name) {
AssExportFilter *filter = AssExportFilterChain::GetFilter(name);
if (filter)
return filter->GetDescription();
throw wxString::Format("Filter not found: %s", name);
}

View File

@ -34,11 +34,6 @@
/// @ingroup export
///
///////////
// Headers
#ifndef AGI_PRE
#include <wx/arrstr.h>
#include <wx/sizer.h>
@ -48,58 +43,68 @@
#include <map>
#endif
//////////////
// Prototypes
class AssExportFilter;
class AssFile;
/// DOCME
typedef std::list<AssExportFilter*> FilterList;
/// DOCME
typedef std::map<wxString,wxSizer*> SizerMap;
/// DOCME
/// @class AssExporter
/// @brief DOCME
///
/// DOCME
class AssExporter {
private:
typedef FilterList::const_iterator filter_iterator;
/// DOCME
SizerMap Sizers;
/// Sizers for configuration panels
std::map<wxString, wxSizer*> Sizers;
/// DOCME
FilterList Filters;
/// Filters which will be applied to the subtitles
FilterList filters;
/// DOCME
AssFile *OriginalSubs;
/// Input subtitle file
AssFile *original_subs;
/// DOCME
bool IsDefault;
/// Have the config windows been created, or should filters simply use
/// their default settings
bool is_default;
public:
AssExporter(AssFile *subs);
~AssExporter();
/// Get the names of all registered export filters
wxArrayString GetAllFilterNames();
void AddFilter(wxString name);
/// Add the named filter to the list of filters to be run
/// @throws wxString if filter is not found
void AddFilter(wxString const& name);
/// Add all export filters which have indicated they should apply in
/// non-transform contexts
void AddAutoFilters();
void DrawSettings(wxWindow *parent,wxSizer *AddTo);
void Export(wxString file, wxString charset, wxWindow *export_dialog=NULL);
AssFile *ExportTransform(wxWindow *export_dialog=NULL,bool copy=false);
wxSizer *GetSettingsSizer(wxString name);
/// @brief DOCME
///
AssFile *GetOriginalSubs() { return OriginalSubs; }
wxString GetDescription(wxString name);
/// Run all added export filters
/// @param parent_window Parent window the filters should use when opening dialogs
/// @param copy Should the file be copied rather than transformed in-place?
/// @return The new subtitle file (which is the old one if copy is false)
AssFile *ExportTransform(wxWindow *parent_window = 0, bool copy = false);
/// Apply selected export filters and save with the given charset
/// @param file Target filename
/// @param charset Target charset
/// @param parent_window Parent window the filters should use when opening dialogs
void Export(wxString const& file, wxString const& charset, wxWindow *parent_window= 0);
/// Add configuration panels for all registered filters to the target sizer
/// @param parent Parent window for controls
/// @param target_sizer Sizer to add configuration panels to
void DrawSettings(wxWindow *parent, wxSizer *target_sizer);
/// Get the sizer created by DrawSettings for a specific filter
wxSizer *GetSettingsSizer(wxString const& name);
/// Get the description of the named export filter
/// @throws wxString if filter is not found
wxString const& GetDescription(wxString const& name);
};

View File

@ -86,7 +86,7 @@ struct tool_export : public Command {
void operator()(agi::Context *c) {
c->videoController->Stop();
DialogExport(c->parent, c->ass).ShowModal();
DialogExport(c).ShowModal();
}
};

View File

@ -44,297 +44,185 @@
#include <wx/tokenzr.h>
#endif
#include "dialog_export.h"
#include "ass_exporter.h"
#include "ass_file.h"
#include "include/aegisub/context.h"
#include "charset_conv.h"
#include "dialog_export.h"
#include "help_button.h"
/// @brief Constructor
/// @param parent
///
DialogExport::DialogExport (wxWindow *parent, AssFile *subs)
: wxDialog (parent, -1, _("Export"), wxDefaultPosition, wxSize(200,100), wxCAPTION | wxCLOSE_BOX, "Export")
DialogExport::DialogExport(agi::Context *c)
: wxDialog(c->parent, -1, _("Export"), wxDefaultPosition, wxSize(200, 100), wxCAPTION | wxCLOSE_BOX, "Export")
, c(c)
, exporter(new AssExporter(c->ass))
{
// Filter list
wxSizer *TopSizer = new wxStaticBoxSizer(wxVERTICAL,this,_("Filters"));
Export = new AssExporter(subs);
wxArrayString filters = Export->GetAllFilterNames();
FilterList = new wxCheckListBox(this, Filter_List_Box, wxDefaultPosition, wxSize(200,100), filters);
wxArrayString filters = exporter->GetAllFilterNames();
filter_list = new wxCheckListBox(this, -1, wxDefaultPosition, wxSize(200, 100), filters);
filter_list->Bind(wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, &DialogExport::OnCheck, this);
filter_list->Bind(wxEVT_COMMAND_LISTBOX_SELECTED, &DialogExport::OnChange, this);
// Get selected filters
wxString selected = Export->GetOriginalSubs()->GetScriptInfo("Export filters");
wxString selected = c->ass->GetScriptInfo("Export filters");
wxStringTokenizer token(selected, "|");
int n = 0;
while (token.HasMoreTokens()) {
wxString cur = token.GetNextToken();
if (!cur.IsEmpty()) {
n++;
for (unsigned int i=0;i<FilterList->GetCount();i++) {
if (FilterList->GetString(i) == cur) {
FilterList->Check(i);
break;
}
}
if (!cur.empty()) {
int idx = filters.Index(cur);
if (idx != wxNOT_FOUND)
filter_list->Check(idx);
}
}
// No filters listed on header, select all
/*if (n == 0) {
for (unsigned int i=0;i<FilterList->GetCount();i++) {
FilterList->Check(i);
}
}*/
wxButton *btn_up = new wxButton(this, -1, _("Move up"), wxDefaultPosition, wxSize(90, -1));
wxButton *btn_down = new wxButton(this, -1, _("Move down"), wxDefaultPosition, wxSize(90, -1));
wxButton *btn_all = new wxButton(this, -1, _("Select all"), wxDefaultPosition, wxSize(80, -1));
wxButton *btn_none = new wxButton(this, -1, _("Select none"), wxDefaultPosition, wxSize(80, -1));
// Top buttons
wxSizer *TopButtons = new wxBoxSizer(wxHORIZONTAL);
TopButtons->Add(new wxButton(this,Button_Move_Up,_("Move up"),wxDefaultPosition,wxSize(90,-1)),1,wxEXPAND | wxRIGHT,0);
TopButtons->Add(new wxButton(this,Button_Move_Down,_("Move down"),wxDefaultPosition,wxSize(90,-1)),1,wxEXPAND | wxRIGHT,5);
TopButtons->Add(new wxButton(this,Button_Select_All,_("Select all"),wxDefaultPosition,wxSize(80,-1)),1,wxEXPAND | wxRIGHT,0);
TopButtons->Add(new wxButton(this,Button_Select_None,_("Select none"),wxDefaultPosition,wxSize(80,-1)),1,wxEXPAND | wxRIGHT,0);
btn_up->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &DialogExport::OnMoveUp, this);
btn_down->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &DialogExport::OnMoveDown, this);
btn_all->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &DialogExport::OnSelectAll, this);
btn_none->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &DialogExport::OnSelectNone, this);
// Description field
Description = new wxTextCtrl(this, -1, "", wxDefaultPosition, wxSize(200,60), wxTE_MULTILINE | wxTE_READONLY);
wxSizer *top_buttons = new wxBoxSizer(wxHORIZONTAL);
top_buttons->Add(btn_up, wxSizerFlags(1).Expand());
top_buttons->Add(btn_down, wxSizerFlags(1).Expand().Border(wxRIGHT));
top_buttons->Add(btn_all, wxSizerFlags(1).Expand());
top_buttons->Add(btn_none, wxSizerFlags(1).Expand());
filter_description = new wxTextCtrl(this, -1, "", wxDefaultPosition, wxSize(200, 60), wxTE_MULTILINE | wxTE_READONLY);
// Charset dropdown list
wxStaticText *charset_list_label = new wxStaticText(this, -1, _("Text encoding:"));
CharsetList = new wxChoice(this, Charset_List_Box, wxDefaultPosition, wxDefaultSize, agi::charset::GetEncodingsList<wxArrayString>());
charset_list = new wxChoice(this, -1, wxDefaultPosition, wxDefaultSize, agi::charset::GetEncodingsList<wxArrayString>());
wxSizer *charset_list_sizer = new wxBoxSizer(wxHORIZONTAL);
charset_list_sizer->Add(charset_list_label, 0, wxALIGN_CENTER | wxRIGHT, 5);
charset_list_sizer->Add(CharsetList, 1, wxEXPAND);
if (!CharsetList->SetStringSelection(Export->GetOriginalSubs()->GetScriptInfo("Export Encoding"))) {
CharsetList->SetStringSelection("Unicode (UTF-8)");
}
charset_list_sizer->Add(charset_list_label, wxSizerFlags().Center().Border(wxRIGHT));
charset_list_sizer->Add(charset_list, wxSizerFlags(1).Expand());
if (!charset_list->SetStringSelection(c->ass->GetScriptInfo("Export Encoding")))
charset_list->SetStringSelection("Unicode (UTF-8)");
// Top sizer
TopSizer->Add(FilterList,1,wxEXPAND,0);
TopSizer->Add(TopButtons,0,wxEXPAND,0);
TopSizer->Add(Description,0,wxEXPAND | wxTOP,5);
TopSizer->Add(charset_list_sizer, 0, wxEXPAND | wxTOP, 5);
wxSizer *top_sizer = new wxStaticBoxSizer(wxVERTICAL, this, _("Filters"));
top_sizer->Add(filter_list, wxSizerFlags(1).Expand());
top_sizer->Add(top_buttons, wxSizerFlags(0).Expand());
top_sizer->Add(filter_description, wxSizerFlags(0).Expand().Border(wxTOP));
top_sizer->Add(charset_list_sizer, wxSizerFlags(0).Expand().Border(wxTOP));
// Button sizer
wxStdDialogButtonSizer *ButtonSizer = new wxStdDialogButtonSizer();
wxButton *process = new wxButton(this,Button_Process,_("Export..."));
ButtonSizer->AddButton(process);
ButtonSizer->AddButton(new wxButton(this,wxID_CANCEL));
ButtonSizer->AddButton(new HelpButton(this,"Export"));
ButtonSizer->SetAffirmativeButton(process);
ButtonSizer->Realize();
wxStdDialogButtonSizer *btn_sizer = CreateStdDialogButtonSizer(wxOK | wxCANCEL | wxHELP);
btn_sizer->GetAffirmativeButton()->SetLabelText(_("Export..."));
btn_sizer->GetAffirmativeButton()->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &DialogExport::OnProcess, this);
btn_sizer->GetHelpButton()->Bind(wxEVT_COMMAND_BUTTON_CLICKED, std::tr1::bind(&HelpButton::OpenPage, "Export"));
// Draw stuff sizer
HorizSizer = new wxBoxSizer(wxHORIZONTAL);
OptionsSizer = new wxBoxSizer(wxVERTICAL);
Export->DrawSettings(this,OptionsSizer);
HorizSizer->Add(TopSizer,0,wxEXPAND | wxLEFT | wxTOP | wxBOTTOM,5);
HorizSizer->Add(OptionsSizer,1,wxEXPAND | wxTOP | wxRIGHT | wxBOTTOM,5);
wxSizer *horz_sizer = new wxBoxSizer(wxHORIZONTAL);
opt_sizer = new wxBoxSizer(wxVERTICAL);
exporter->DrawSettings(this, opt_sizer);
horz_sizer->Add(top_sizer, wxSizerFlags().Expand().Border(wxALL & ~wxRIGHT));
horz_sizer->Add(opt_sizer, wxSizerFlags(1).Expand().Border(wxALL & ~wxLEFT));
// Main sizer
MainSizer = new wxBoxSizer(wxVERTICAL);
MainSizer->Add(HorizSizer,1,wxEXPAND,0);
MainSizer->Add(ButtonSizer,0,wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM,5);
MainSizer->SetSizeHints(this);
SetSizer(MainSizer);
wxSizer *main_sizer = new wxBoxSizer(wxVERTICAL);
main_sizer->Add(horz_sizer, wxSizerFlags(1).Expand());
main_sizer->Add(btn_sizer, wxSizerFlags().Expand().Border(wxALL & ~wxTOP));
SetSizerAndFit(main_sizer);
RefreshOptions();
CenterOnParent();
}
/// @brief Destructor
///
DialogExport::~DialogExport() {
// Set script info data
int n = 0;
wxString infoList;
for (unsigned int i=0;i<FilterList->GetCount();i++) {
if (FilterList->IsChecked(i)) {
infoList += FilterList->GetString(i) + "|";
n++;
}
for (size_t i = 0; i < filter_list->GetCount(); ++i) {
if (filter_list->IsChecked(i))
infoList += filter_list->GetString(i) + "|";
}
if (n > 0) infoList = infoList.Left(infoList.Length()-1);
Export->GetOriginalSubs()->SetScriptInfo("Export filters",infoList);
// Delete exporter
if (Export) delete Export;
Export = NULL;
if (!infoList.empty()) infoList.RemoveLast();
c->ass->SetScriptInfo("Export filters", infoList);
}
/// @brief Refresh displaying of options
///
void DialogExport::RefreshOptions() {
int num = FilterList->GetCount();
for (int i=0;i<num;i++) {
wxSizer *sizer = Export->GetSettingsSizer(FilterList->GetString(i));
if (sizer) OptionsSizer->Show(sizer,FilterList->IsChecked(i)?1:0,true);
}
Layout();
MainSizer->Fit(this);
}
///////////////
// Event table
BEGIN_EVENT_TABLE(DialogExport,wxDialog)
EVT_BUTTON(Button_Process,DialogExport::OnProcess)
EVT_BUTTON(Button_Move_Up,DialogExport::OnMoveUp)
EVT_BUTTON(Button_Move_Down,DialogExport::OnMoveDown)
EVT_BUTTON(Button_Select_All,DialogExport::OnSelectAll)
EVT_BUTTON(Button_Select_None,DialogExport::OnSelectNone)
EVT_CHECKLISTBOX(Filter_List_Box,DialogExport::OnCheck)
EVT_LISTBOX(Filter_List_Box, DialogExport::OnChange)
END_EVENT_TABLE()
/// @brief Process start
/// @param event
/// @return
///
void DialogExport::OnProcess(wxCommandEvent &event) {
// Get destination
wxString filename = wxFileSelector(_("Export subtitles file"),"","","",AssFile::GetWildcardList(2),wxFD_SAVE | wxFD_OVERWRITE_PROMPT,this);
void DialogExport::OnProcess(wxCommandEvent &) {
wxString filename = wxFileSelector(_("Export subtitles file"), "", "", "", AssFile::GetWildcardList(2), wxFD_SAVE | wxFD_OVERWRITE_PROMPT, this);
if (filename.empty()) return;
// Add filters
for (unsigned int i=0;i<FilterList->GetCount();i++) {
if (FilterList->IsChecked(i)) {
Export->AddFilter(FilterList->GetString(i));
}
for (size_t i = 0; i < filter_list->GetCount(); ++i) {
if (filter_list->IsChecked(i))
exporter->AddFilter(filter_list->GetString(i));
}
// Export
try {
wxBusyCursor busy;
Export->GetOriginalSubs()->SetScriptInfo("Export Encoding", CharsetList->GetStringSelection());
Export->Export(filename, CharsetList->GetStringSelection(), this);
c->ass->SetScriptInfo("Export Encoding", charset_list->GetStringSelection());
exporter->Export(filename, charset_list->GetStringSelection(), this);
}
catch (const char *error) {
wxString err(error);
wxMessageBox(err, "Error exporting subtitles", wxOK | wxICON_ERROR, this);
wxMessageBox(error, "Error exporting subtitles", wxOK | wxICON_ERROR, this);
}
catch (const agi::charset::ConvError& err) {
catch (wxString const& error) {
wxMessageBox(error, "Error exporting subtitles", wxOK | wxICON_ERROR, this);
}
catch (agi::Exception const& err) {
wxMessageBox(err.GetMessage(), "Error exporting subtitles", wxOK | wxICON_ERROR, this);
}
catch (...) {
wxMessageBox("Unknown error", "Error exporting subtitles", wxOK | wxICON_ERROR, this);
}
// Close dialog
EndModal(0);
}
/// @brief Checked or unchecked item
/// @param event
///
void DialogExport::OnCheck(wxCommandEvent &event) {
int n = event.GetInt();
wxSizer *sizer = Export->GetSettingsSizer(FilterList->GetString(n));
if (sizer) MainSizer->Show(sizer,FilterList->IsChecked(n)?1:0,true);
Layout();
MainSizer->Fit(this);
void DialogExport::OnCheck(wxCommandEvent &) {
RefreshOptions();
}
/// @brief Changed item
/// @param event
///
void DialogExport::OnChange(wxCommandEvent &event) {
int n = FilterList->GetSelection();
void DialogExport::OnChange(wxCommandEvent &) {
int n = filter_list->GetSelection();
if (n != wxNOT_FOUND) {
wxString name = FilterList->GetString(n);
//Description->SetValue(wxGetTranslation(Export->GetDescription(name)));
Description->SetValue(Export->GetDescription(name));
wxString name = filter_list->GetString(n);
filter_description->SetValue(exporter->GetDescription(name));
}
}
// Swap the items at idx and idx + 1
static void swap(wxCheckListBox *list, int idx, int sel_dir) {
if (idx < 0 || idx + 1 == list->GetCount()) return;
/// @brief Move up
/// @param event
/// @return
///
void DialogExport::OnMoveUp(wxCommandEvent &event) {
int pos = FilterList->GetSelection();
if (pos <= 0) return;
FilterList->Freeze();
wxString tempname = FilterList->GetString(pos);
bool tempval = FilterList->IsChecked(pos);
FilterList->SetString(pos,FilterList->GetString(pos-1));
FilterList->Check(pos,FilterList->IsChecked(pos-1));
FilterList->SetString(pos-1,tempname);
FilterList->Check(pos-1,tempval);
FilterList->SetSelection(pos-1);
FilterList->Thaw();
list->Freeze();
wxString tempname = list->GetString(idx);
bool tempval = list->IsChecked(idx);
list->SetString(idx, list->GetString(idx + 1));
list->Check(idx, list->IsChecked(idx + 1));
list->SetString(idx + 1, tempname);
list->Check(idx + 1, tempval);
list->SetSelection(idx + sel_dir);
list->Thaw();
}
/// @brief Move down
/// @param event
/// @return
///
void DialogExport::OnMoveDown(wxCommandEvent &event) {
int pos = FilterList->GetSelection();
int n = FilterList->GetCount();
if (pos == n-1 || pos == -1) return;
FilterList->Freeze();
wxString tempname = FilterList->GetString(pos);
bool tempval = FilterList->IsChecked(pos);
FilterList->SetString(pos,FilterList->GetString(pos+1));
FilterList->Check(pos,FilterList->IsChecked(pos+1));
FilterList->SetString(pos+1,tempname);
FilterList->Check(pos+1,tempval);
FilterList->SetSelection(pos+1);
FilterList->Thaw();
void DialogExport::OnMoveUp(wxCommandEvent &) {
swap(filter_list, filter_list->GetSelection() - 1, 0);
}
void DialogExport::OnMoveDown(wxCommandEvent &) {
swap(filter_list, filter_list->GetSelection(), 1);
}
void DialogExport::OnSelectAll(wxCommandEvent &) {
SetAll(true);
}
/// @brief Select all
/// @param event
///
void DialogExport::OnSelectAll(wxCommandEvent &event) {
Freeze();
FilterList->Freeze();
for (unsigned int i=0;i<FilterList->GetCount();i++) {
FilterList->Check(i,true);
wxSizer *sizer = Export->GetSettingsSizer(FilterList->GetString(i));
if (sizer) MainSizer->Show(sizer,true,true);
void DialogExport::OnSelectNone(wxCommandEvent &) {
SetAll(false);
}
void DialogExport::SetAll(bool new_value) {
filter_list->Freeze();
for (size_t i = 0; i < filter_list->GetCount(); ++i)
filter_list->Check(i, new_value);
filter_list->Thaw();
RefreshOptions();
}
void DialogExport::RefreshOptions() {
for (size_t i = 0; i < filter_list->GetCount(); ++i) {
if (wxSizer *sizer = exporter->GetSettingsSizer(filter_list->GetString(i)))
opt_sizer->Show(sizer, filter_list->IsChecked(i), true);
}
// Update dialog
Layout();
MainSizer->Fit(this);
FilterList->Thaw();
Thaw();
GetSizer()->Fit(this);
}
/// @brief Select none
/// @param event
///
void DialogExport::OnSelectNone(wxCommandEvent &event) {
Freeze();
FilterList->Freeze();
for (unsigned int i=0;i<FilterList->GetCount();i++) {
FilterList->Check(i,false);
wxSizer *sizer = Export->GetSettingsSizer(FilterList->GetString(i));
if (sizer) MainSizer->Show(sizer,false,true);
}
// Update dialog
FilterList->Thaw();
Thaw();
Layout();
MainSizer->Fit(this);
}

View File

@ -34,11 +34,6 @@
/// @ingroup export
///
///////////
// Headers
#ifndef AGI_PRE
#include <map>
@ -51,16 +46,10 @@
#include <wx/textctrl.h>
#endif
#include <libaegisub/scoped_ptr.h>
/// DOCME
typedef std::map<wxString,wxSizer*> SizerMap;
//////////////
// Prototypes
class AssExporter;
namespace agi { struct Context; }
/// DOCME
/// @class DialogExport
@ -68,73 +57,37 @@ class AssExporter;
///
/// DOCME
class DialogExport : public wxDialog {
private:
agi::Context *c;
/// The export transform engine
agi::scoped_ptr<AssExporter> exporter;
/// The description of the currently selected export filter
wxTextCtrl *filter_description;
/// A list of all registered export filters
wxCheckListBox *filter_list;
/// A list of available target charsets
wxChoice *charset_list;
/// DOCME
AssExporter *Export;
wxSizer *opt_sizer;
/// DOCME
SizerMap SetupMap;
void OnProcess(wxCommandEvent &);
void OnMoveUp(wxCommandEvent &);
void OnMoveDown(wxCommandEvent &);
void OnSelectAll(wxCommandEvent &);
void OnSelectNone(wxCommandEvent &);
void OnCheck(wxCommandEvent &);
void OnChange(wxCommandEvent &);
/// DOCME
wxTextCtrl *Description;
/// DOCME
wxCheckListBox *FilterList;
/// DOCME
wxChoice *CharsetList;
/// DOCME
wxSizer *MainSizer;
/// DOCME
wxSizer *HorizSizer;
/// DOCME
wxSizer *OptionsSizer;
void OnProcess(wxCommandEvent &event);
void OnMoveUp(wxCommandEvent &event);
void OnMoveDown(wxCommandEvent &event);
void OnSelectAll(wxCommandEvent &event);
void OnSelectNone(wxCommandEvent &event);
void OnCheck(wxCommandEvent &event);
void OnChange(wxCommandEvent &event);
/// Set all the checkboxes
void SetAll(bool new_value);
/// Update which options sizers are shown
void RefreshOptions();
public:
DialogExport(wxWindow *parent, AssFile *subs);
DialogExport(agi::Context *c);
~DialogExport();
DECLARE_EVENT_TABLE()
};
///////
// IDs
enum {
/// DOCME
Button_Process = 1400,
/// DOCME
Button_Move_Up,
/// DOCME
Button_Move_Down,
/// DOCME
Button_Select_All,
/// DOCME
Button_Select_None,
/// DOCME
Filter_List_Box,
/// DOCME
Charset_List_Box
};

View File

@ -44,6 +44,6 @@
/// DOCME
class AssTransformCleanInfoFilter : public AssExportFilter {
public:
void ProcessSubs(AssFile *subs, wxWindow *export_dialog);
void ProcessSubs(AssFile *subs, wxWindow *);
AssTransformCleanInfoFilter();
};

View File

@ -49,7 +49,6 @@
AssFixStylesFilter::AssFixStylesFilter()
: AssExportFilter(_("Fix Styles"), _("Fixes styles by replacing any style that isn't available on file with Default."), -5000)
{
autoExporter = true;
}
void AssFixStylesFilter::ProcessSubs(AssFile *subs, wxWindow *) {

View File

@ -44,8 +44,6 @@
/// DOCME
class AssFixStylesFilter : public AssExportFilter {
public:
void ProcessSubs(AssFile *subs, wxWindow *export_dialog);
void ProcessSubs(AssFile *subs, wxWindow *);
AssFixStylesFilter();
};

View File

@ -62,7 +62,7 @@ AssTransformFramerateFilter::AssTransformFramerateFilter()
{
}
void AssTransformFramerateFilter::ProcessSubs(AssFile *subs, wxWindow *export_dialog) {
void AssTransformFramerateFilter::ProcessSubs(AssFile *subs, wxWindow *) {
TransformFrameRate(subs);
}

View File

@ -91,7 +91,7 @@ class AssTransformFramerateFilter : public AssExportFilter {
public:
/// Constructor
AssTransformFramerateFilter();
void ProcessSubs(AssFile *subs, wxWindow *export_dialog);
void ProcessSubs(AssFile *subs, wxWindow *);
wxWindow *GetConfigDialogWindow(wxWindow *parent);
void LoadSettings(bool IsDefault);
};