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 "ass_file.h"
#include "utils.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) : name(name)
, priority(priority) , priority(priority)
, autoExporter(false)
, hidden(false)
, description(description) , description(description)
, auto_apply(auto_apply)
{ {
} }
@ -57,44 +56,45 @@ void AssExportFilterChain::Register(AssExportFilter *filter) {
// Remove pipes from name // Remove pipes from name
filter->name.Replace("|", ""); filter->name.Replace("|", "");
FilterList::iterator begin = GetFilterList()->begin(); int filter_copy = 1;
FilterList::iterator end = GetFilterList()->end(); wxString name = filter->name;
// Find a unique name
while (GetFilter(name))
name = wxString::Format("%s (%d)", filter->name, filter_copy++);
int filter_copy = 0; filter->name = name;
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;
// Look for place to insert // Look for place to insert
FilterList::iterator begin = filters()->begin();
FilterList::iterator end = filters()->end();
while (begin != end && (*begin)->priority >= filter->priority) ++begin; while (begin != end && (*begin)->priority >= filter->priority) ++begin;
GetFilterList()->insert(begin, filter); filters()->insert(begin, filter);
} }
void AssExportFilterChain::Unregister(AssExportFilter *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); 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; static FilterList instance;
return &instance; return &instance;
} }
void AssExportFilterChain::Clear() { const FilterList *AssExportFilterChain::GetFilterList() {
delete_clear(*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 /// DOCME
class AssExportFilterChain { class AssExportFilterChain {
friend class AssExporter; static FilterList *filters();
/// Get the singleton instance
static FilterList *GetFilterList();
public: public:
/// Register an export filter /// Register an export filter
static void Register(AssExportFilter *filter); static void Register(AssExportFilter *filter);
@ -69,6 +66,11 @@ public:
static void Unregister(AssExportFilter *filter); static void Unregister(AssExportFilter *filter);
/// Unregister and delete all export filters /// Unregister and delete all export filters
static void Clear(); 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 /// DOCME
@ -77,7 +79,8 @@ public:
/// ///
/// DOCME /// DOCME
class AssExportFilter { 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; friend class AssExportFilterChain;
/// This filter's name /// This filter's name
@ -86,27 +89,31 @@ class AssExportFilter {
/// Higher priority = run earlier /// Higher priority = run earlier
int priority; 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 /// User-visible description of this filter
wxString description; wxString description;
/// Should this filter be automatically applied when sending subtitles to
/// the renderer and exporting to non-ASS formats
bool auto_apply;
public: 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() { }; 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 /// 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 /// Draw setup controls
virtual wxWindow *GetConfigDialogWindow(wxWindow *parent) { return 0; } 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_export_filter.h"
#include "ass_exporter.h" #include "ass_exporter.h"
#include "ass_file.h" #include "ass_file.h"
#include "frame_main.h"
/// @brief Constructor static inline std::list<AssExportFilter*>::const_iterator filter_list_begin() {
/// @param subs return AssExportFilterChain::GetFilterList()->begin();
/// }
AssExporter::AssExporter (AssFile *subs) {
OriginalSubs = subs; static inline std::list<AssExportFilter*>::const_iterator filter_list_end() {
IsDefault = true; return AssExportFilterChain::GetFilterList()->end();
}
AssExporter::AssExporter(AssFile *subs)
: original_subs(subs)
, is_default(true)
{
} }
/// @brief Destructor
///
AssExporter::~AssExporter () { AssExporter::~AssExporter () {
} }
/// @brief Draw control settings void AssExporter::DrawSettings(wxWindow *parent, wxSizer *target_sizer) {
/// @param parent is_default = false;
/// @param AddTo for (filter_iterator cur = filter_list_begin(); cur != filter_list_end(); ++cur) {
///
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++) {
// Make sure to construct static box sizer first, so it won't overlap // Make sure to construct static box sizer first, so it won't overlap
// the controls on wxMac. // the controls on wxMac.
box = new wxStaticBoxSizer(wxVERTICAL,parent,(*cur)->name); wxSizer *box = new wxStaticBoxSizer(wxVERTICAL, parent, (*cur)->GetName());
window = (*cur)->GetConfigDialogWindow(parent); wxWindow *window = (*cur)->GetConfigDialogWindow(parent);
if (window) { if (window) {
box->Add(window,0,wxEXPAND,0); box->Add(window, 0, wxEXPAND, 0);
AddTo->Add(box,0,wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM,5); target_sizer->Add(box, 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 5);
AddTo->Show(box,false); target_sizer->Show(box, false);
Sizers[(*cur)->name] = box; Sizers[(*cur)->GetName()] = box;
} }
else { else {
delete box; delete box;
@ -81,101 +76,53 @@ void AssExporter::DrawSettings(wxWindow *parent,wxSizer *AddTo) {
} }
} }
/// @brief Add filter to chain void AssExporter::AddFilter(wxString const& name) {
/// @param name AssExportFilter *filter = AssExportFilterChain::GetFilter(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;
}
}
// Check
if (!filter) throw wxString::Format("Filter not found: %s", name); 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() { void AssExporter::AddAutoFilters() {
FilterList::iterator begin = AssExportFilterChain::GetFilterList()->begin(); for (filter_iterator it = filter_list_begin(); it != filter_list_end(); ++it) {
FilterList::iterator end = AssExportFilterChain::GetFilterList()->end(); if ((*it)->GetAutoApply())
for (FilterList::iterator cur=begin;cur!=end;cur++) { filters.push_back(*it);
if ((*cur)->autoExporter) {
Filters.push_back(*cur);
}
} }
} }
/// @brief Get name of all filters
/// @return
///
wxArrayString AssExporter::GetAllFilterNames() { wxArrayString AssExporter::GetAllFilterNames() {
wxArrayString names; wxArrayString names;
FilterList::iterator begin = AssExportFilterChain::GetFilterList()->begin(); transform(filter_list_begin(), filter_list_end(),
FilterList::iterator end = AssExportFilterChain::GetFilterList()->end(); std::back_inserter(names), std::mem_fun(&AssExportFilter::GetName));
for (FilterList::iterator cur=begin;cur!=end;cur++) {
if (!(*cur)->hidden) names.Add((*cur)->name);
}
return names; return names;
} }
/// @brief Transform for export AssFile *AssExporter::ExportTransform(wxWindow *export_dialog, bool copy) {
/// @param export_dialog AssFile *subs = copy ? new AssFile(*original_subs) : original_subs;
/// @return
///
AssFile *AssExporter::ExportTransform(wxWindow *export_dialog,bool copy) {
// Copy
AssFile *Subs = copy ? new AssFile(*OriginalSubs) : OriginalSubs;
// Run filters for (filter_iterator cur = filters.begin(); cur != filters.end(); cur++) {
for (FilterList::iterator cur=Filters.begin();cur!=Filters.end();cur++) { (*cur)->LoadSettings(is_default);
(*cur)->LoadSettings(IsDefault); (*cur)->ProcessSubs(subs, export_dialog);
(*cur)->ProcessSubs(Subs, export_dialog);
} }
// Done return subs;
return Subs;
} }
/// @brief Export void AssExporter::Export(wxString const& filename, wxString const& charset, wxWindow *export_dialog) {
/// @param filename std::auto_ptr<AssFile> subs(ExportTransform(export_dialog, true));
/// @param charset subs->Save(filename, false, false, 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);
} }
/// @brief Get window associated with name wxSizer *AssExporter::GetSettingsSizer(wxString const& name) {
/// @param name std::map<wxString, wxSizer*>::iterator pos = Sizers.find(name);
/// @return if (pos == Sizers.end()) return 0;
/// return pos->second;
wxSizer *AssExporter::GetSettingsSizer(wxString name) {
SizerMap::iterator pos = Sizers.find(name);
if (pos == Sizers.end()) return NULL;
else return pos->second;
} }
/// @brief Get description of filter wxString const& AssExporter::GetDescription(wxString const& name) {
/// @param name AssExportFilter *filter = AssExportFilterChain::GetFilter(name);
/// if (filter)
wxString AssExporter::GetDescription(wxString name) { return filter->GetDescription();
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();
}
}
throw wxString::Format("Filter not found: %s", name); throw wxString::Format("Filter not found: %s", name);
} }

View file

@ -34,11 +34,6 @@
/// @ingroup export /// @ingroup export
/// ///
///////////
// Headers
#ifndef AGI_PRE #ifndef AGI_PRE
#include <wx/arrstr.h> #include <wx/arrstr.h>
#include <wx/sizer.h> #include <wx/sizer.h>
@ -48,58 +43,68 @@
#include <map> #include <map>
#endif #endif
//////////////
// Prototypes
class AssExportFilter; class AssExportFilter;
class AssFile; class AssFile;
/// DOCME
typedef std::list<AssExportFilter*> FilterList; typedef std::list<AssExportFilter*> FilterList;
/// DOCME
typedef std::map<wxString,wxSizer*> SizerMap;
/// DOCME /// DOCME
/// @class AssExporter /// @class AssExporter
/// @brief DOCME /// @brief DOCME
/// ///
/// DOCME /// DOCME
class AssExporter { class AssExporter {
private: typedef FilterList::const_iterator filter_iterator;
/// DOCME /// Sizers for configuration panels
SizerMap Sizers; std::map<wxString, wxSizer*> Sizers;
/// DOCME /// Filters which will be applied to the subtitles
FilterList Filters; FilterList filters;
/// DOCME /// Input subtitle file
AssFile *OriginalSubs; AssFile *original_subs;
/// DOCME /// Have the config windows been created, or should filters simply use
bool IsDefault; /// their default settings
bool is_default;
public: public:
AssExporter(AssFile *subs); AssExporter(AssFile *subs);
~AssExporter(); ~AssExporter();
/// Get the names of all registered export filters
wxArrayString GetAllFilterNames(); 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 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 /// Run all added export filters
/// /// @param parent_window Parent window the filters should use when opening dialogs
AssFile *GetOriginalSubs() { return OriginalSubs; } /// @param copy Should the file be copied rather than transformed in-place?
wxString GetDescription(wxString name); /// @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) { void operator()(agi::Context *c) {
c->videoController->Stop(); c->videoController->Stop();
DialogExport(c->parent, c->ass).ShowModal(); DialogExport(c).ShowModal();
} }
}; };

View file

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

View file

@ -49,7 +49,6 @@
AssFixStylesFilter::AssFixStylesFilter() AssFixStylesFilter::AssFixStylesFilter()
: AssExportFilter(_("Fix Styles"), _("Fixes styles by replacing any style that isn't available on file with Default."), -5000) : 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 *) { void AssFixStylesFilter::ProcessSubs(AssFile *subs, wxWindow *) {

View file

@ -44,8 +44,6 @@
/// DOCME /// DOCME
class AssFixStylesFilter : public AssExportFilter { class AssFixStylesFilter : public AssExportFilter {
public: public:
void ProcessSubs(AssFile *subs, wxWindow *export_dialog); void ProcessSubs(AssFile *subs, wxWindow *);
AssFixStylesFilter(); 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); TransformFrameRate(subs);
} }

View file

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