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/
|
|
|
|
|
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>
|
|
|
|
|
|
|
|
#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>
|
2014-05-22 21:07:15 +02:00
|
|
|
#include <wx/dialog.h>
|
2012-12-30 01:53:30 +01:00
|
|
|
#include <wx/checklst.h>
|
|
|
|
#include <wx/choice.h>
|
|
|
|
#include <wx/msgdlg.h>
|
|
|
|
#include <wx/sizer.h>
|
|
|
|
#include <wx/stattext.h>
|
|
|
|
#include <wx/textctrl.h>
|
|
|
|
|
2014-05-22 21:07:15 +02:00
|
|
|
namespace {
|
2014-05-31 02:05:25 +02:00
|
|
|
class DialogExport {
|
|
|
|
wxDialog d;
|
2014-05-22 21:07:15 +02:00
|
|
|
agi::Context *c;
|
|
|
|
|
|
|
|
/// The export transform engine
|
|
|
|
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;
|
|
|
|
|
|
|
|
wxSizer *opt_sizer;
|
|
|
|
|
|
|
|
void OnProcess(wxCommandEvent &);
|
|
|
|
void OnChange(wxCommandEvent &);
|
|
|
|
|
|
|
|
/// Set all the checkboxes
|
|
|
|
void SetAll(bool new_value);
|
|
|
|
/// Update which options sizers are shown
|
|
|
|
void RefreshOptions();
|
|
|
|
|
|
|
|
public:
|
|
|
|
DialogExport(agi::Context *c);
|
|
|
|
~DialogExport();
|
2014-05-31 02:05:25 +02:00
|
|
|
void ShowModal() { d.ShowModal(); }
|
2014-05-22 21:07:15 +02:00
|
|
|
};
|
|
|
|
|
2012-12-02 22:29:46 +01:00
|
|
|
// Swap the items at idx and idx + 1
|
2014-05-22 21:07:15 +02:00
|
|
|
void swap(wxCheckListBox *list, int idx, int sel_dir) {
|
2012-12-02 22:29:46 +01:00
|
|
|
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)
|
2014-05-31 02:05:25 +02:00
|
|
|
: d(c->parent, -1, _("Export"), wxDefaultPosition, wxSize(200, 100), wxCAPTION | wxCLOSE_BOX)
|
2011-09-28 21:46:41 +02:00
|
|
|
, c(c)
|
2014-05-22 21:07:15 +02:00
|
|
|
, exporter(c)
|
2006-01-16 22:02:54 +01:00
|
|
|
{
|
2014-05-31 02:05:25 +02:00
|
|
|
d.SetIcon(GETICON(export_menu_16));
|
|
|
|
d.SetExtraStyle(wxWS_EX_VALIDATE_RECURSIVELY);
|
2012-03-07 02:30:52 +01:00
|
|
|
|
2014-05-22 21:07:15 +02:00
|
|
|
std::vector<std::string> filters = exporter.GetAllFilterNames();
|
2014-05-31 02:05:25 +02:00
|
|
|
filter_list = new wxCheckListBox(&d, -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
|
2014-05-22 03:32:42 +02:00
|
|
|
std::string const& selected = c->ass->Properties.export_filters;
|
2013-01-04 16:01:50 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-05-31 02:05:25 +02:00
|
|
|
wxButton *btn_up = new wxButton(&d, -1, _("Move &Up"), wxDefaultPosition, wxSize(90, -1));
|
|
|
|
wxButton *btn_down = new wxButton(&d, -1, _("Move &Down"), wxDefaultPosition, wxSize(90, -1));
|
|
|
|
wxButton *btn_all = new wxButton(&d, -1, _("Select &All"), wxDefaultPosition, wxSize(80, -1));
|
|
|
|
wxButton *btn_none = new wxButton(&d, -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
|
|
|
|
2014-05-31 02:05:25 +02:00
|
|
|
filter_description = new wxTextCtrl(&d, -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
|
2014-05-31 02:05:25 +02:00
|
|
|
wxStaticText *charset_list_label = new wxStaticText(&d, -1, _("Text encoding:"));
|
|
|
|
charset_list = new wxChoice(&d, -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());
|
2014-05-22 03:32:42 +02:00
|
|
|
if (!charset_list->SetStringSelection(to_wx(c->ass->Properties.export_encoding)))
|
2011-09-28 21:46:41 +02:00
|
|
|
charset_list->SetStringSelection("Unicode (UTF-8)");
|
|
|
|
|
2014-05-31 02:05:25 +02:00
|
|
|
wxSizer *top_sizer = new wxStaticBoxSizer(wxVERTICAL, &d, _("Filters"));
|
2011-09-28 21:46:41 +02:00
|
|
|
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));
|
|
|
|
|
2014-05-31 02:05:25 +02:00
|
|
|
auto btn_sizer = d.CreateStdDialogButtonSizer(wxOK | wxCANCEL | wxHELP);
|
2011-09-28 21:46:41 +02:00
|
|
|
btn_sizer->GetAffirmativeButton()->SetLabelText(_("Export..."));
|
2014-05-31 02:05:25 +02:00
|
|
|
d.Bind(wxEVT_BUTTON, &DialogExport::OnProcess, this, wxID_OK);
|
|
|
|
d.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);
|
2014-05-31 02:05:25 +02:00
|
|
|
exporter.DrawSettings(&d, opt_sizer);
|
2011-09-28 21:46:41 +02:00
|
|
|
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));
|
2014-05-31 02:05:25 +02:00
|
|
|
d.SetSizerAndFit(main_sizer);
|
2006-01-16 22:02:54 +01:00
|
|
|
RefreshOptions();
|
2014-05-31 02:05:25 +02:00
|
|
|
d.CenterOnParent();
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
DialogExport::~DialogExport() {
|
2014-05-22 03:32:42 +02:00
|
|
|
c->ass->Properties.export_filters.clear();
|
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)) {
|
2014-05-22 03:32:42 +02:00
|
|
|
if (!c->ass->Properties.export_filters.empty())
|
|
|
|
c->ass->Properties.export_filters += "|";
|
|
|
|
c->ass->Properties.export_filters += from_wx(filter_list->GetString(i));
|
2013-01-04 16:01:50 +01:00
|
|
|
}
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-28 21:46:41 +02:00
|
|
|
void DialogExport::OnProcess(wxCommandEvent &) {
|
2014-05-31 02:05:25 +02:00
|
|
|
if (!d.TransferDataFromWindow()) return;
|
2012-03-07 02:30:52 +01:00
|
|
|
|
2015-01-01 04:41:56 +01:00
|
|
|
auto filename = SaveFileSelector(_("Export subtitles file"), "", "", "", SubtitleFormat::GetWildcards(1), &d);
|
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))
|
2014-05-22 21:07:15 +02: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;
|
2014-05-22 03:32:42 +02:00
|
|
|
c->ass->Properties.export_encoding = from_wx(charset_list->GetStringSelection());
|
2014-05-31 02:05:25 +02:00
|
|
|
exporter.Export(filename, from_wx(charset_list->GetStringSelection()), &d);
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
2014-06-11 00:28:45 +02:00
|
|
|
catch (agi::UserCancelException const&) { }
|
2011-09-28 21:46:41 +02:00
|
|
|
catch (agi::Exception const& err) {
|
2014-05-31 02:05:25 +02:00
|
|
|
wxMessageBox(to_wx(err.GetMessage()), "Error exporting subtitles", wxOK | wxICON_ERROR | wxCENTER, &d);
|
2010-06-03 22:32:25 +02:00
|
|
|
}
|
2013-01-04 16:01:50 +01:00
|
|
|
catch (std::exception const& err) {
|
2014-05-31 02:05:25 +02:00
|
|
|
wxMessageBox(to_wx(err.what()), "Error exporting subtitles", wxOK | wxICON_ERROR | wxCENTER, &d);
|
2013-01-04 16:01:50 +01:00
|
|
|
}
|
2006-01-16 22:02:54 +01:00
|
|
|
catch (...) {
|
2014-05-31 02:05:25 +02:00
|
|
|
wxMessageBox("Unknown error", "Error exporting subtitles", wxOK | wxICON_ERROR | wxCENTER, &d);
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
2014-05-31 02:05:25 +02:00
|
|
|
d.EndModal(0);
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
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())
|
2014-05-22 21:07:15 +02:00
|
|
|
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) {
|
2014-05-22 21:07:15 +02: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
|
|
|
}
|
2014-05-31 02:05:25 +02:00
|
|
|
d.Layout();
|
|
|
|
d.GetSizer()->Fit(&d);
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
2014-05-22 21:07:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ShowExportDialog(agi::Context *c) {
|
|
|
|
DialogExport(c).ShowModal();
|
|
|
|
}
|