2006-01-16 22:02:54 +01:00
|
|
|
// Copyright (c) 2005, Rodrigo Braz Monteiro, Niels Martin Hansen
|
|
|
|
// All rights reserved.
|
|
|
|
//
|
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer in the documentation
|
|
|
|
// and/or other materials provided with the distribution.
|
|
|
|
// * Neither the name of the Aegisub Group nor the names of its contributors
|
|
|
|
// may be used to endorse or promote products derived from this software
|
|
|
|
// without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
// POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// Aegisub Project http://www.aegisub.org/
|
|
|
|
|
|
|
|
/// @file dialog_export.cpp
|
|
|
|
/// @brief Export set-up dialogue box
|
|
|
|
/// @ingroup export
|
|
|
|
///
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2009-01-04 07:31:48 +01:00
|
|
|
#include "config.h"
|
|
|
|
|
2011-09-28 21:46:41 +02:00
|
|
|
#include "dialog_export.h"
|
|
|
|
|
2006-01-16 22:02:54 +01:00
|
|
|
#include "ass_exporter.h"
|
2009-09-10 15:06:40 +02:00
|
|
|
#include "ass_file.h"
|
2012-12-30 01:53:30 +01:00
|
|
|
#include "compat.h"
|
2011-09-28 21:46:41 +02:00
|
|
|
#include "include/aegisub/context.h"
|
2008-01-14 00:34:38 +01:00
|
|
|
#include "help_button.h"
|
2012-04-03 22:40:33 +02:00
|
|
|
#include "libresrc/libresrc.h"
|
2012-10-12 05:08:38 +02:00
|
|
|
#include "subtitle_format.h"
|
2013-01-22 05:27:56 +01:00
|
|
|
#include "utils.h"
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
#include <libaegisub/charset_conv.h>
|
2013-10-23 23:43:05 +02:00
|
|
|
#include <libaegisub/util.h>
|
2013-01-04 16:01:50 +01:00
|
|
|
|
|
|
|
#include <algorithm>
|
2013-01-26 02:57:46 +01:00
|
|
|
#include <boost/filesystem/path.hpp>
|
2013-01-04 16:01:50 +01:00
|
|
|
#include <boost/tokenizer.hpp>
|
|
|
|
|
2012-12-30 01:53:30 +01:00
|
|
|
#include <wx/button.h>
|
|
|
|
#include <wx/checklst.h>
|
|
|
|
#include <wx/choice.h>
|
|
|
|
#include <wx/msgdlg.h>
|
|
|
|
#include <wx/sizer.h>
|
|
|
|
#include <wx/stattext.h>
|
|
|
|
#include <wx/textctrl.h>
|
|
|
|
|
2012-12-02 22:29:46 +01:00
|
|
|
// Swap the items at idx and idx + 1
|
|
|
|
static void swap(wxCheckListBox *list, int idx, int sel_dir) {
|
|
|
|
if (idx < 0 || idx + 1 == (int)list->GetCount()) return;
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2011-09-28 21:46:41 +02:00
|
|
|
DialogExport::DialogExport(agi::Context *c)
|
2012-03-07 02:30:52 +01:00
|
|
|
: wxDialog(c->parent, -1, _("Export"), wxDefaultPosition, wxSize(200, 100), wxCAPTION | wxCLOSE_BOX)
|
2011-09-28 21:46:41 +02:00
|
|
|
, c(c)
|
2013-10-23 23:43:05 +02:00
|
|
|
, exporter(agi::util::make_unique<AssExporter>(c))
|
2006-01-16 22:02:54 +01:00
|
|
|
{
|
2012-04-03 22:40:33 +02:00
|
|
|
SetIcon(GETICON(export_menu_16));
|
2012-03-07 02:30:52 +01:00
|
|
|
SetExtraStyle(wxWS_EX_VALIDATE_RECURSIVELY);
|
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
std::vector<std::string> filters = exporter->GetAllFilterNames();
|
|
|
|
filter_list = new wxCheckListBox(this, -1, wxDefaultPosition, wxSize(200, 100), to_wx(filters));
|
2013-12-12 03:25:13 +01:00
|
|
|
filter_list->Bind(wxEVT_CHECKLISTBOX, [=](wxCommandEvent&) { RefreshOptions(); });
|
|
|
|
filter_list->Bind(wxEVT_LISTBOX, &DialogExport::OnChange, this);
|
2006-01-16 22:02:54 +01:00
|
|
|
|
|
|
|
// Get selected filters
|
2013-01-04 16:01:50 +01:00
|
|
|
std::string selected = c->ass->GetScriptInfo("Export filters");
|
|
|
|
boost::char_separator<char> sep("|");
|
|
|
|
for (auto const& token : boost::tokenizer<boost::char_separator<char>>(selected, sep)) {
|
|
|
|
auto it = find(begin(filters), end(filters), token);
|
|
|
|
if (it != end(filters))
|
|
|
|
filter_list->Check(distance(begin(filters), it));
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
2012-01-08 02:05:25 +01:00
|
|
|
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));
|
2011-09-28 21:46:41 +02:00
|
|
|
|
2013-12-12 03:25:13 +01:00
|
|
|
btn_up->Bind(wxEVT_BUTTON, [=](wxCommandEvent&) { swap(filter_list, filter_list->GetSelection() - 1, 0); });
|
|
|
|
btn_down->Bind(wxEVT_BUTTON, [=](wxCommandEvent&) { swap(filter_list, filter_list->GetSelection() - 1, 0); });
|
|
|
|
btn_all->Bind(wxEVT_BUTTON, [=](wxCommandEvent&) { SetAll(true); });
|
|
|
|
btn_none->Bind(wxEVT_BUTTON, [=](wxCommandEvent&) { SetAll(false); });
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2011-09-28 21:46:41 +02:00
|
|
|
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());
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2011-09-28 21:46:41 +02:00
|
|
|
filter_description = new wxTextCtrl(this, -1, "", wxDefaultPosition, wxSize(200, 60), wxTE_MULTILINE | wxTE_READONLY);
|
2007-08-16 01:17:42 +02:00
|
|
|
|
2006-01-16 22:02:54 +01:00
|
|
|
// Charset dropdown list
|
|
|
|
wxStaticText *charset_list_label = new wxStaticText(this, -1, _("Text encoding:"));
|
2011-09-28 21:46:41 +02:00
|
|
|
charset_list = new wxChoice(this, -1, wxDefaultPosition, wxDefaultSize, agi::charset::GetEncodingsList<wxArrayString>());
|
2006-01-16 22:02:54 +01:00
|
|
|
wxSizer *charset_list_sizer = new wxBoxSizer(wxHORIZONTAL);
|
2011-09-28 21:46:41 +02:00
|
|
|
charset_list_sizer->Add(charset_list_label, wxSizerFlags().Center().Border(wxRIGHT));
|
|
|
|
charset_list_sizer->Add(charset_list, wxSizerFlags(1).Expand());
|
2013-01-04 16:01:50 +01:00
|
|
|
if (!charset_list->SetStringSelection(to_wx(c->ass->GetScriptInfo("Export Encoding"))))
|
2011-09-28 21:46:41 +02:00
|
|
|
charset_list->SetStringSelection("Unicode (UTF-8)");
|
|
|
|
|
|
|
|
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));
|
|
|
|
|
|
|
|
wxStdDialogButtonSizer *btn_sizer = CreateStdDialogButtonSizer(wxOK | wxCANCEL | wxHELP);
|
|
|
|
btn_sizer->GetAffirmativeButton()->SetLabelText(_("Export..."));
|
2013-12-12 03:25:13 +01:00
|
|
|
Bind(wxEVT_BUTTON, &DialogExport::OnProcess, this, wxID_OK);
|
|
|
|
Bind(wxEVT_BUTTON, std::bind(&HelpButton::OpenPage, "Export"), wxID_HELP);
|
2011-09-28 21:46:41 +02:00
|
|
|
|
|
|
|
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));
|
|
|
|
|
|
|
|
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);
|
2006-01-16 22:02:54 +01:00
|
|
|
RefreshOptions();
|
|
|
|
CenterOnParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
DialogExport::~DialogExport() {
|
2013-01-04 16:01:50 +01:00
|
|
|
std::string infoList;
|
2011-09-28 21:46:41 +02:00
|
|
|
for (size_t i = 0; i < filter_list->GetCount(); ++i) {
|
2013-01-04 16:01:50 +01:00
|
|
|
if (filter_list->IsChecked(i)) {
|
|
|
|
if (!infoList.empty())
|
|
|
|
infoList += "|";
|
|
|
|
infoList += from_wx(filter_list->GetString(i));
|
|
|
|
}
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
2011-09-28 21:46:41 +02:00
|
|
|
c->ass->SetScriptInfo("Export filters", infoList);
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
2011-09-28 21:46:41 +02:00
|
|
|
void DialogExport::OnProcess(wxCommandEvent &) {
|
2012-03-07 02:30:52 +01:00
|
|
|
if (!TransferDataFromWindow()) return;
|
|
|
|
|
2013-01-22 05:27:56 +01:00
|
|
|
auto filename = SaveFileSelector(_("Export subtitles file"), "", "", "", to_wx(SubtitleFormat::GetWildcards(1)), this);
|
2006-01-16 22:02:54 +01:00
|
|
|
if (filename.empty()) return;
|
|
|
|
|
2011-09-28 21:46:41 +02:00
|
|
|
for (size_t i = 0; i < filter_list->GetCount(); ++i) {
|
|
|
|
if (filter_list->IsChecked(i))
|
2013-01-04 16:01:50 +01:00
|
|
|
exporter->AddFilter(from_wx(filter_list->GetString(i)));
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2006-12-28 23:31:33 +01:00
|
|
|
wxBusyCursor busy;
|
2013-01-04 16:01:50 +01:00
|
|
|
c->ass->SetScriptInfo("Export Encoding", from_wx(charset_list->GetStringSelection()));
|
2013-01-22 05:27:56 +01:00
|
|
|
exporter->Export(filename, from_wx(charset_list->GetStringSelection()), this);
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
2012-03-25 06:04:48 +02:00
|
|
|
catch (agi::UserCancelException const&) {
|
|
|
|
}
|
2011-09-28 21:43:11 +02:00
|
|
|
catch (const char *error) {
|
2012-03-29 01:59:19 +02:00
|
|
|
wxMessageBox(error, "Error exporting subtitles", wxOK | wxICON_ERROR | wxCENTER, this);
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
2011-09-28 21:46:41 +02:00
|
|
|
catch (wxString const& error) {
|
2012-03-29 01:59:19 +02:00
|
|
|
wxMessageBox(error, "Error exporting subtitles", wxOK | wxICON_ERROR | wxCENTER, this);
|
2011-09-28 21:46:41 +02:00
|
|
|
}
|
|
|
|
catch (agi::Exception const& err) {
|
2012-12-30 01:53:30 +01:00
|
|
|
wxMessageBox(to_wx(err.GetMessage()), "Error exporting subtitles", wxOK | wxICON_ERROR | wxCENTER, this);
|
2010-06-03 22:32:25 +02:00
|
|
|
}
|
2013-01-04 16:01:50 +01:00
|
|
|
catch (std::exception const& err) {
|
|
|
|
wxMessageBox(to_wx(err.what()), "Error exporting subtitles", wxOK | wxICON_ERROR | wxCENTER, this);
|
|
|
|
}
|
2006-01-16 22:02:54 +01:00
|
|
|
catch (...) {
|
2012-03-29 01:59:19 +02:00
|
|
|
wxMessageBox("Unknown error", "Error exporting subtitles", wxOK | wxICON_ERROR | wxCENTER, this);
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
EndModal(0);
|
|
|
|
}
|
|
|
|
|
2011-09-28 21:46:41 +02:00
|
|
|
void DialogExport::OnChange(wxCommandEvent &) {
|
2013-01-04 16:01:50 +01:00
|
|
|
wxString sel = filter_list->GetStringSelection();
|
|
|
|
if (!sel.empty())
|
|
|
|
filter_description->SetValue(to_wx(exporter->GetDescription(from_wx(sel))));
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
2011-09-28 21:46:41 +02:00
|
|
|
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();
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2011-09-28 21:46:41 +02:00
|
|
|
RefreshOptions();
|
|
|
|
}
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
2011-09-28 21:46:41 +02:00
|
|
|
void DialogExport::RefreshOptions() {
|
|
|
|
for (size_t i = 0; i < filter_list->GetCount(); ++i) {
|
2013-01-04 16:01:50 +01:00
|
|
|
if (wxSizer *sizer = exporter->GetSettingsSizer(from_wx(filter_list->GetString(i))))
|
2011-09-28 21:46:41 +02:00
|
|
|
opt_sizer->Show(sizer, filter_list->IsChecked(i), true);
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
Layout();
|
2011-09-28 21:46:41 +02:00
|
|
|
GetSizer()->Fit(this);
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|