~ubuntu-branches/ubuntu/wily/aegisub/wily-proposed

« back to all changes in this revision

Viewing changes to src/dialog_export.cpp

  • Committer: Package Import Robot
  • Author(s): Sebastian Reichel, Pascal De Vuyst, Juan Picca, Sebastian Reichel
  • Date: 2015-08-04 21:40:50 UTC
  • mfrom: (5.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20150804214050-y2aghm9vdksoc8t7
Tags: 3.2.2+dfsg-1
[ Pascal De Vuyst ]
* Fix Typo in package description (Closes: #739219)

[ Juan Picca ]
* Add patch to fix reproducible build (Closes: #789728)

[ Sebastian Reichel ]
* New upstream release
 - remove vendor directory from orig tarball
* Update Debian Standards Version to 3.9.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
//
28
28
// Aegisub Project http://www.aegisub.org/
29
29
 
30
 
/// @file dialog_export.cpp
31
 
/// @brief Export set-up dialogue box
32
 
/// @ingroup export
33
 
///
34
 
 
35
 
#include "config.h"
36
 
 
37
 
#include "dialog_export.h"
38
 
 
39
30
#include "ass_exporter.h"
40
31
#include "ass_file.h"
41
32
#include "compat.h"
46
37
#include "utils.h"
47
38
 
48
39
#include <libaegisub/charset_conv.h>
49
 
#include <libaegisub/util.h>
50
40
 
51
41
#include <algorithm>
52
42
#include <boost/filesystem/path.hpp>
53
43
#include <boost/tokenizer.hpp>
54
 
 
55
44
#include <wx/button.h>
 
45
#include <wx/dialog.h>
56
46
#include <wx/checklst.h>
57
47
#include <wx/choice.h>
58
48
#include <wx/msgdlg.h>
60
50
#include <wx/stattext.h>
61
51
#include <wx/textctrl.h>
62
52
 
 
53
namespace {
 
54
class DialogExport {
 
55
        wxDialog d;
 
56
        agi::Context *c;
 
57
 
 
58
        /// The export transform engine
 
59
        AssExporter exporter;
 
60
 
 
61
        /// The description of the currently selected export filter
 
62
        wxTextCtrl *filter_description;
 
63
 
 
64
        /// A list of all registered export filters
 
65
        wxCheckListBox *filter_list;
 
66
 
 
67
        /// A list of available target charsets
 
68
        wxChoice *charset_list;
 
69
 
 
70
        wxSizer *opt_sizer;
 
71
 
 
72
        void OnProcess(wxCommandEvent &);
 
73
        void OnChange(wxCommandEvent &);
 
74
 
 
75
        /// Set all the checkboxes
 
76
        void SetAll(bool new_value);
 
77
        /// Update which options sizers are shown
 
78
        void RefreshOptions();
 
79
 
 
80
public:
 
81
        DialogExport(agi::Context *c);
 
82
        ~DialogExport();
 
83
        void ShowModal() { d.ShowModal(); }
 
84
};
 
85
 
63
86
// Swap the items at idx and idx + 1
64
 
static void swap(wxCheckListBox *list, int idx, int sel_dir) {
 
87
void swap(wxCheckListBox *list, int idx, int sel_dir) {
65
88
        if (idx < 0 || idx + 1 == (int)list->GetCount()) return;
66
89
 
67
90
        list->Freeze();
76
99
}
77
100
 
78
101
DialogExport::DialogExport(agi::Context *c)
79
 
: wxDialog(c->parent, -1, _("Export"), wxDefaultPosition, wxSize(200, 100), wxCAPTION | wxCLOSE_BOX)
 
102
: d(c->parent, -1, _("Export"), wxDefaultPosition, wxSize(200, 100), wxCAPTION | wxCLOSE_BOX)
80
103
, c(c)
81
 
, exporter(agi::util::make_unique<AssExporter>(c))
 
104
, exporter(c)
82
105
{
83
 
        SetIcon(GETICON(export_menu_16));
84
 
        SetExtraStyle(wxWS_EX_VALIDATE_RECURSIVELY);
 
106
        d.SetIcon(GETICON(export_menu_16));
 
107
        d.SetExtraStyle(wxWS_EX_VALIDATE_RECURSIVELY);
85
108
 
86
 
        std::vector<std::string> filters = exporter->GetAllFilterNames();
87
 
        filter_list = new wxCheckListBox(this, -1, wxDefaultPosition, wxSize(200, 100), to_wx(filters));
 
109
        std::vector<std::string> filters = exporter.GetAllFilterNames();
 
110
        filter_list = new wxCheckListBox(&d, -1, wxDefaultPosition, wxSize(200, 100), to_wx(filters));
88
111
        filter_list->Bind(wxEVT_CHECKLISTBOX, [=](wxCommandEvent&) { RefreshOptions(); });
89
112
        filter_list->Bind(wxEVT_LISTBOX, &DialogExport::OnChange, this);
90
113
 
91
114
        // Get selected filters
92
 
        std::string selected = c->ass->GetScriptInfo("Export filters");
 
115
        std::string const& selected = c->ass->Properties.export_filters;
93
116
        boost::char_separator<char> sep("|");
94
117
        for (auto const& token : boost::tokenizer<boost::char_separator<char>>(selected, sep)) {
95
118
                auto it = find(begin(filters), end(filters), token);
97
120
                        filter_list->Check(distance(begin(filters), it));
98
121
        }
99
122
 
100
 
        wxButton *btn_up = new wxButton(this, -1, _("Move &Up"), wxDefaultPosition, wxSize(90, -1));
101
 
        wxButton *btn_down = new wxButton(this, -1, _("Move &Down"), wxDefaultPosition, wxSize(90, -1));
102
 
        wxButton *btn_all = new wxButton(this, -1, _("Select &All"), wxDefaultPosition, wxSize(80, -1));
103
 
        wxButton *btn_none = new wxButton(this, -1, _("Select &None"), wxDefaultPosition, wxSize(80, -1));
 
123
        wxButton *btn_up = new wxButton(&d, -1, _("Move &Up"), wxDefaultPosition, wxSize(90, -1));
 
124
        wxButton *btn_down = new wxButton(&d, -1, _("Move &Down"), wxDefaultPosition, wxSize(90, -1));
 
125
        wxButton *btn_all = new wxButton(&d, -1, _("Select &All"), wxDefaultPosition, wxSize(80, -1));
 
126
        wxButton *btn_none = new wxButton(&d, -1, _("Select &None"), wxDefaultPosition, wxSize(80, -1));
104
127
 
105
128
        btn_up->Bind(wxEVT_BUTTON, [=](wxCommandEvent&) { swap(filter_list, filter_list->GetSelection() - 1, 0); });
106
129
        btn_down->Bind(wxEVT_BUTTON, [=](wxCommandEvent&) { swap(filter_list, filter_list->GetSelection() - 1, 0); });
113
136
        top_buttons->Add(btn_all, wxSizerFlags(1).Expand());
114
137
        top_buttons->Add(btn_none, wxSizerFlags(1).Expand());
115
138
 
116
 
        filter_description = new wxTextCtrl(this, -1, "", wxDefaultPosition, wxSize(200, 60), wxTE_MULTILINE | wxTE_READONLY);
 
139
        filter_description = new wxTextCtrl(&d, -1, "", wxDefaultPosition, wxSize(200, 60), wxTE_MULTILINE | wxTE_READONLY);
117
140
 
118
141
        // Charset dropdown list
119
 
        wxStaticText *charset_list_label = new wxStaticText(this, -1, _("Text encoding:"));
120
 
        charset_list = new wxChoice(this, -1, wxDefaultPosition, wxDefaultSize, agi::charset::GetEncodingsList<wxArrayString>());
 
142
        wxStaticText *charset_list_label = new wxStaticText(&d, -1, _("Text encoding:"));
 
143
        charset_list = new wxChoice(&d, -1, wxDefaultPosition, wxDefaultSize, agi::charset::GetEncodingsList<wxArrayString>());
121
144
        wxSizer *charset_list_sizer = new wxBoxSizer(wxHORIZONTAL);
122
145
        charset_list_sizer->Add(charset_list_label, wxSizerFlags().Center().Border(wxRIGHT));
123
146
        charset_list_sizer->Add(charset_list, wxSizerFlags(1).Expand());
124
 
        if (!charset_list->SetStringSelection(to_wx(c->ass->GetScriptInfo("Export Encoding"))))
 
147
        if (!charset_list->SetStringSelection(to_wx(c->ass->Properties.export_encoding)))
125
148
                charset_list->SetStringSelection("Unicode (UTF-8)");
126
149
 
127
 
        wxSizer *top_sizer = new wxStaticBoxSizer(wxVERTICAL, this, _("Filters"));
 
150
        wxSizer *top_sizer = new wxStaticBoxSizer(wxVERTICAL, &d, _("Filters"));
128
151
        top_sizer->Add(filter_list, wxSizerFlags(1).Expand());
129
152
        top_sizer->Add(top_buttons, wxSizerFlags(0).Expand());
130
153
        top_sizer->Add(filter_description, wxSizerFlags(0).Expand().Border(wxTOP));
131
154
        top_sizer->Add(charset_list_sizer, wxSizerFlags(0).Expand().Border(wxTOP));
132
155
 
133
 
        wxStdDialogButtonSizer *btn_sizer = CreateStdDialogButtonSizer(wxOK | wxCANCEL | wxHELP);
 
156
        auto btn_sizer = d.CreateStdDialogButtonSizer(wxOK | wxCANCEL | wxHELP);
134
157
        btn_sizer->GetAffirmativeButton()->SetLabelText(_("Export..."));
135
 
        Bind(wxEVT_BUTTON, &DialogExport::OnProcess, this, wxID_OK);
136
 
        Bind(wxEVT_BUTTON, std::bind(&HelpButton::OpenPage, "Export"), wxID_HELP);
 
158
        d.Bind(wxEVT_BUTTON, &DialogExport::OnProcess, this, wxID_OK);
 
159
        d.Bind(wxEVT_BUTTON, std::bind(&HelpButton::OpenPage, "Export"), wxID_HELP);
137
160
 
138
161
        wxSizer *horz_sizer = new wxBoxSizer(wxHORIZONTAL);
139
162
        opt_sizer = new wxBoxSizer(wxVERTICAL);
140
 
        exporter->DrawSettings(this, opt_sizer);
 
163
        exporter.DrawSettings(&d, opt_sizer);
141
164
        horz_sizer->Add(top_sizer, wxSizerFlags().Expand().Border(wxALL & ~wxRIGHT));
142
165
        horz_sizer->Add(opt_sizer, wxSizerFlags(1).Expand().Border(wxALL & ~wxLEFT));
143
166
 
144
167
        wxSizer *main_sizer = new wxBoxSizer(wxVERTICAL);
145
168
        main_sizer->Add(horz_sizer, wxSizerFlags(1).Expand());
146
169
        main_sizer->Add(btn_sizer, wxSizerFlags().Expand().Border(wxALL & ~wxTOP));
147
 
        SetSizerAndFit(main_sizer);
 
170
        d.SetSizerAndFit(main_sizer);
148
171
        RefreshOptions();
149
 
        CenterOnParent();
 
172
        d.CenterOnParent();
150
173
}
151
174
 
152
175
DialogExport::~DialogExport() {
153
 
        std::string infoList;
 
176
        c->ass->Properties.export_filters.clear();
154
177
        for (size_t i = 0; i < filter_list->GetCount(); ++i) {
155
178
                if (filter_list->IsChecked(i)) {
156
 
                        if (!infoList.empty())
157
 
                                infoList += "|";
158
 
                        infoList += from_wx(filter_list->GetString(i));
 
179
                        if (!c->ass->Properties.export_filters.empty())
 
180
                                c->ass->Properties.export_filters += "|";
 
181
                        c->ass->Properties.export_filters += from_wx(filter_list->GetString(i));
159
182
                }
160
183
        }
161
 
        c->ass->SetScriptInfo("Export filters", infoList);
162
184
}
163
185
 
164
186
void DialogExport::OnProcess(wxCommandEvent &) {
165
 
        if (!TransferDataFromWindow()) return;
 
187
        if (!d.TransferDataFromWindow()) return;
166
188
 
167
 
        auto filename = SaveFileSelector(_("Export subtitles file"), "", "", "", to_wx(SubtitleFormat::GetWildcards(1)), this);
 
189
        auto filename = SaveFileSelector(_("Export subtitles file"), "", "", "", to_wx(SubtitleFormat::GetWildcards(1)), &d);
168
190
        if (filename.empty()) return;
169
191
 
170
192
        for (size_t i = 0; i < filter_list->GetCount(); ++i) {
171
193
                if (filter_list->IsChecked(i))
172
 
                        exporter->AddFilter(from_wx(filter_list->GetString(i)));
 
194
                        exporter.AddFilter(from_wx(filter_list->GetString(i)));
173
195
        }
174
196
 
175
197
        try {
176
198
                wxBusyCursor busy;
177
 
                c->ass->SetScriptInfo("Export Encoding", from_wx(charset_list->GetStringSelection()));
178
 
                exporter->Export(filename, from_wx(charset_list->GetStringSelection()), this);
179
 
        }
180
 
        catch (agi::UserCancelException const&) {
181
 
        }
182
 
        catch (const char *error) {
183
 
                wxMessageBox(error, "Error exporting subtitles", wxOK | wxICON_ERROR | wxCENTER, this);
184
 
        }
185
 
        catch (wxString const& error) {
186
 
                wxMessageBox(error, "Error exporting subtitles", wxOK | wxICON_ERROR | wxCENTER, this);
187
 
        }
 
199
                c->ass->Properties.export_encoding = from_wx(charset_list->GetStringSelection());
 
200
                exporter.Export(filename, from_wx(charset_list->GetStringSelection()), &d);
 
201
        }
 
202
        catch (agi::UserCancelException const&) { }
188
203
        catch (agi::Exception const& err) {
189
 
                wxMessageBox(to_wx(err.GetMessage()), "Error exporting subtitles", wxOK | wxICON_ERROR | wxCENTER, this);
 
204
                wxMessageBox(to_wx(err.GetMessage()), "Error exporting subtitles", wxOK | wxICON_ERROR | wxCENTER, &d);
190
205
        }
191
206
        catch (std::exception const& err) {
192
 
                wxMessageBox(to_wx(err.what()), "Error exporting subtitles", wxOK | wxICON_ERROR | wxCENTER, this);
 
207
                wxMessageBox(to_wx(err.what()), "Error exporting subtitles", wxOK | wxICON_ERROR | wxCENTER, &d);
193
208
        }
194
209
        catch (...) {
195
 
                wxMessageBox("Unknown error", "Error exporting subtitles", wxOK | wxICON_ERROR | wxCENTER, this);
 
210
                wxMessageBox("Unknown error", "Error exporting subtitles", wxOK | wxICON_ERROR | wxCENTER, &d);
196
211
        }
197
212
 
198
 
        EndModal(0);
 
213
        d.EndModal(0);
199
214
}
200
215
 
201
216
void DialogExport::OnChange(wxCommandEvent &) {
202
217
        wxString sel = filter_list->GetStringSelection();
203
218
        if (!sel.empty())
204
 
                filter_description->SetValue(to_wx(exporter->GetDescription(from_wx(sel))));
 
219
                filter_description->SetValue(to_wx(exporter.GetDescription(from_wx(sel))));
205
220
}
206
221
 
207
222
void DialogExport::SetAll(bool new_value) {
215
230
 
216
231
void DialogExport::RefreshOptions() {
217
232
        for (size_t i = 0; i < filter_list->GetCount(); ++i) {
218
 
                if (wxSizer *sizer = exporter->GetSettingsSizer(from_wx(filter_list->GetString(i))))
 
233
                if (wxSizer *sizer = exporter.GetSettingsSizer(from_wx(filter_list->GetString(i))))
219
234
                        opt_sizer->Show(sizer, filter_list->IsChecked(i), true);
220
235
        }
221
 
        Layout();
222
 
        GetSizer()->Fit(this);
 
236
        d.Layout();
 
237
        d.GetSizer()->Fit(&d);
 
238
}
 
239
}
 
240
 
 
241
void ShowExportDialog(agi::Context *c) {
 
242
        DialogExport(c).ShowModal();
223
243
}