2
The contents of this file are subject to the Initial Developer's Public
3
License Version 1.0 (the "License"); you may not use this file except in
4
compliance with the License. You may obtain a copy of the License here:
5
http://www.flamerobin.org/license.html.
7
Software distributed under the License is distributed on an "AS IS"
8
basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
9
License for the specific language governing rights and limitations under
12
The Original Code is FlameRobin (TM).
14
The Initial Developer of the Original Code is Michael Hieke.
16
Portions created by the original developer
17
are Copyright (C) 2004 Michael Hieke.
23
Contributor(s): Milan Babuskov
26
// For compilers that support precompilation, includes "wx/wx.h".
27
#include "wx/wxprec.h"
33
// for all others, include the necessary headers (this file is usually all you
34
// need because it includes almost all "standard" wxWindows headers
40
#include <wx/datetime.h>
43
#include "BackupFrame.h"
45
#include "styleguide.h"
48
//-----------------------------------------------------------------------------
49
// worker thread class to perform database backup
50
class BackupThread: public wxThread {
52
BackupThread(BackupFrame* frame, std::string server, std::string username,
53
std::string password, std::string dbfilename, std::string bkfilename,
56
virtual void* Entry();
57
virtual void OnExit();
61
std::string usernameM;
62
std::string passwordM;
66
void logError(wxString& msg);
67
void logImportant(wxString& msg);
68
void logProgress(wxString& msg);
70
//-----------------------------------------------------------------------------
71
BackupThread::BackupThread(BackupFrame* frame, std::string server, std::string username,
72
std::string password, std::string dbfilename, std::string bkfilename, IBPP::BRF flags):
81
// always use verbose flag to make cancelling possible
82
brfM = (IBPP::BRF)((int)flags | (int)IBPP::brVerbose);
84
//-----------------------------------------------------------------------------
85
void* BackupThread::Entry()
92
msg.Printf(_("Connecting to server %s..."), serverM.c_str());
94
IBPP::Service svc = IBPP::ServiceFactory(serverM, usernameM, passwordM);
97
now = wxDateTime::Now();
98
msg.Printf(_("Database backup started %s"), now.FormatTime().c_str());
100
svc->StartBackup(dbfileM, bkfileM, brfM);
105
now = wxDateTime::Now();
106
msg.Printf(_("Database backup cancelled %s"), now.FormatTime().c_str());
110
const char* c = svc->WaitMsg();
113
now = wxDateTime::Now();
114
msg.Printf(_("Database backup finished %s"), now.FormatTime().c_str());
123
catch (IBPP::Exception& e)
125
now = wxDateTime::Now();
126
msg.Printf(_("Database backup cancelled %s due to IBPP exception:\n\n"), now.FormatTime().c_str());
127
msg += std2wx(e.ErrorMessage());
132
now = wxDateTime::Now();
133
msg.Printf(_("Database backup cancelled %s due to exception"), now.FormatTime().c_str());
138
//-----------------------------------------------------------------------------
139
void BackupThread::OnExit()
143
wxCommandEvent event(wxEVT_COMMAND_MENU_SELECTED, BackupRestoreBaseFrame::ID_thread_finished);
144
wxPostEvent(frameM, event);
147
//-----------------------------------------------------------------------------
148
void BackupThread::logError(wxString& msg)
151
frameM->threadOutputMsg(msg, BackupRestoreBaseFrame::error_message);
153
//-----------------------------------------------------------------------------
154
void BackupThread::logImportant(wxString& msg)
157
frameM->threadOutputMsg(msg, BackupRestoreBaseFrame::important_message);
159
//-----------------------------------------------------------------------------
160
void BackupThread::logProgress(wxString& msg)
163
frameM->threadOutputMsg(msg, BackupRestoreBaseFrame::progress_message);
165
//-----------------------------------------------------------------------------
166
BackupFrame::BackupFrame(wxWindow* parent, YDatabase* db):
167
BackupRestoreBaseFrame(parent, db)
170
s.Printf(_("Backup Database \"%s:%s\""),
171
serverM->getName().c_str(), databaseM->getName().c_str());
174
panel_controls = new wxPanel(this, -1, wxDefaultPosition, wxDefaultSize,
175
wxTAB_TRAVERSAL|wxCLIP_CHILDREN|wxNO_FULL_REPAINT_ON_RESIZE);
176
label_filename = new wxStaticText(panel_controls, -1, _("Backup file:"));
177
text_ctrl_filename = new wxTextCtrl(panel_controls, ID_text_ctrl_filename, _(""));
178
button_browse = new wxButton(panel_controls, ID_button_browse, _("..."), wxDefaultPosition,
179
wxDefaultSize, wxBU_EXACTFIT);
181
checkbox_checksum = new wxCheckBox(panel_controls, -1, _("Ignore Checksums"));
182
checkbox_limbo = new wxCheckBox(panel_controls, -1, _("Ignore Limbo Transactions"));
183
checkbox_metadata = new wxCheckBox(panel_controls, -1, _("Only backup metadata"));
184
checkbox_garbage = new wxCheckBox(panel_controls, -1, _("Don't do garbage collection"));
185
checkbox_transport = new wxCheckBox(panel_controls, -1, _("Use non-transportable format"));
186
checkbox_extern = new wxCheckBox(panel_controls, -1, _("Convert external tables"));
188
combobox_showlog = new wxCheckBox(panel_controls, ID_checkbox_showlog, _("Show complete log"));
189
button_start = new wxButton(panel_controls, ID_button_start, _("Backup"));
190
button_cancel = new wxButton(panel_controls, ID_button_cancel, _("Cancel"));
192
text_ctrl_log = new wxStyledTextCtrl(this, ID_text_ctrl_log);
198
//-----------------------------------------------------------------------------
199
//! implementation details
200
void BackupFrame::do_layout()
202
int wh = text_ctrl_filename->GetMinHeight();
203
button_browse->SetSize(wh, wh);
205
wxBoxSizer* sizerFilename = new wxBoxSizer(wxHORIZONTAL);
206
sizerFilename->Add(label_filename, 0, wxALIGN_CENTER_VERTICAL);
207
sizerFilename->Add(styleguide().getControlLabelMargin(), 0);
208
sizerFilename->Add(text_ctrl_filename, 1, wxALIGN_CENTER_VERTICAL);
209
sizerFilename->Add(styleguide().getBrowseButtonMargin(), 0);
210
sizerFilename->Add(button_browse, 0, wxALIGN_CENTER_VERTICAL);
212
wxGridSizer* sizerChecks = new wxGridSizer(2, 2,
213
styleguide().getCheckboxSpacing(),
214
styleguide().getUnrelatedControlMargin(wxHORIZONTAL));
215
sizerChecks->Add(checkbox_checksum);
216
sizerChecks->Add(checkbox_metadata);
217
sizerChecks->Add(checkbox_limbo);
218
sizerChecks->Add(checkbox_garbage);
219
sizerChecks->Add(checkbox_transport);
220
sizerChecks->Add(checkbox_extern);
222
wxBoxSizer* sizerButtons = new wxBoxSizer(wxHORIZONTAL);
223
sizerButtons->Add(combobox_showlog, 0, wxALIGN_CENTER_VERTICAL);
224
sizerButtons->Add(0, 0, 1, wxEXPAND);
225
sizerButtons->Add(button_start);
226
sizerButtons->Add(styleguide().getBetweenButtonsMargin(wxHORIZONTAL), 0);
227
sizerButtons->Add(button_cancel);
229
wxBoxSizer* sizerPanelV = new wxBoxSizer(wxVERTICAL);
230
sizerPanelV->Add(0, styleguide().getFrameMargin(wxTOP));
231
sizerPanelV->Add(sizerFilename, 0, wxEXPAND);
232
sizerPanelV->Add(0, styleguide().getRelatedControlMargin(wxVERTICAL));
233
sizerPanelV->Add(sizerChecks);
234
sizerPanelV->Add(0, styleguide().getUnrelatedControlMargin(wxVERTICAL));
235
sizerPanelV->Add(sizerButtons, 0, wxEXPAND);
236
sizerPanelV->Add(0, styleguide().getRelatedControlMargin(wxVERTICAL));
237
wxBoxSizer* sizerPanelH = new wxBoxSizer(wxHORIZONTAL);
238
sizerPanelH->Add(styleguide().getFrameMargin(wxLEFT), 0);
239
sizerPanelH->Add(sizerPanelV, 1, wxEXPAND);
240
sizerPanelH->Add(styleguide().getFrameMargin(wxRIGHT), 0);
241
panel_controls->SetSizerAndFit(sizerPanelH);
243
wxBoxSizer* sizerMain = new wxBoxSizer(wxVERTICAL);
244
sizerMain->Add(panel_controls, 0, wxEXPAND);
245
sizerMain->Add(text_ctrl_log, 1, wxEXPAND);
246
// show at least one line of text
247
sizerMain->SetItemMinSize(text_ctrl_log, -1, text_ctrl_filename->GetSize().GetHeight());
248
SetSizerAndFit(sizerMain);
250
//-----------------------------------------------------------------------------
251
void BackupFrame::doReadConfigSettings(const std::string& prefix)
253
BackupRestoreBaseFrame::doReadConfigSettings(prefix);
254
std::vector<std::string> flags;
255
if (config().getValue(prefix + "::options", flags) && !flags.empty())
257
checkbox_checksum->SetValue(
258
flags.end() != std::find(flags.begin(), flags.end(), "ignore_checksums"));
259
checkbox_limbo->SetValue(
260
flags.end() != std::find(flags.begin(), flags.end(), "ignore_limbo"));
261
checkbox_metadata->SetValue(
262
flags.end() != std::find(flags.begin(), flags.end(), "metadata_only"));
263
checkbox_garbage->SetValue(
264
flags.end() != std::find(flags.begin(), flags.end(), "no_garbage_collect"));
265
checkbox_transport->SetValue(
266
flags.end() != std::find(flags.begin(), flags.end(), "no_transportable"));
267
checkbox_extern->SetValue(
268
flags.end() != std::find(flags.begin(), flags.end(), "external_tables"));
272
//-----------------------------------------------------------------------------
273
void BackupFrame::doWriteConfigSettings(const std::string& prefix) const
275
BackupRestoreBaseFrame::doWriteConfigSettings(prefix);
276
std::vector<std::string> flags;
277
if (checkbox_checksum->IsChecked())
278
flags.push_back("ignore_checksums");
279
if (checkbox_limbo->IsChecked())
280
flags.push_back("ignore_limbo");
281
if (checkbox_metadata->IsChecked())
282
flags.push_back("metadata_only");
283
if (checkbox_garbage->IsChecked())
284
flags.push_back("no_garbage_collect");
285
if (checkbox_transport->IsChecked())
286
flags.push_back("no_transportable");
287
if (checkbox_extern->IsChecked())
288
flags.push_back("external_tables");
289
config().setValue(prefix + "::options", flags);
291
//-----------------------------------------------------------------------------
292
const std::string BackupFrame::getName() const
294
return "BackupFrame";
296
//-----------------------------------------------------------------------------
297
void BackupFrame::updateControls()
299
bool running = threadM != 0;
300
button_browse->Enable(!running);
301
text_ctrl_filename->Enable(!running);
302
checkbox_checksum->Enable(!running);
303
checkbox_limbo->Enable(!running);
304
checkbox_metadata->Enable(!running);
305
checkbox_garbage->Enable(!running);
306
checkbox_transport->Enable(!running);
307
checkbox_extern->Enable(!running);
308
button_start->Enable(!running && !text_ctrl_filename->GetValue().empty());
309
button_cancel->Enable(running);
311
//-----------------------------------------------------------------------------
313
BEGIN_EVENT_TABLE(BackupFrame, BackupRestoreBaseFrame)
314
EVT_BUTTON(BackupRestoreBaseFrame::ID_button_browse, BackupFrame::OnBrowseButtonClick)
315
EVT_BUTTON(BackupRestoreBaseFrame::ID_button_start, BackupFrame::OnStartButtonClick)
317
//-----------------------------------------------------------------------------
318
void BackupFrame::OnBrowseButtonClick(wxCommandEvent& WXUNUSED(event))
320
wxString filename = ::wxFileSelector(_("Select Backup File"), wxT(""), wxT(""),
321
wxT(""), _("All files (*.*)|*.*"), 0, this);
322
if (!filename.empty())
323
text_ctrl_filename->SetValue(filename);
325
//-----------------------------------------------------------------------------
326
void BackupFrame::OnStartButtonClick(wxCommandEvent& WXUNUSED(event))
328
verboseMsgsM = combobox_showlog->IsChecked();
331
// TODO: create a global helper function
332
// bool getDatabasePassword(wxFrame* parent, YDatabase* db, wxString password);
333
// this would simplify the next lines to
334
// if (!getDatabasePassword(this, databaseM, password))
337
std::string password = databaseM->getPassword();
338
if (password.empty())
341
msg.Printf(_("Enter password for user %s:"), databaseM->getUsername().c_str());
342
password = wx2std(::wxGetPasswordFromUser(msg, _("Connecting To Server")));
343
if (password.empty())
347
int flags = (int)IBPP::brVerbose; // this will be ORed in anyway
348
if (checkbox_checksum->IsChecked())
349
flags |= (int)IBPP::brIgnoreChecksums;
350
if (checkbox_limbo->IsChecked())
351
flags |= (int)IBPP::brIgnoreLimbo;
352
if (checkbox_metadata->IsChecked())
353
flags |= (int)IBPP::brMetadataOnly;
354
if (checkbox_garbage->IsChecked())
355
flags |= (int)IBPP::brNoGarbageCollect;
356
if (checkbox_transport->IsChecked())
357
flags |= (int)IBPP::brNonTransportable;
358
if (checkbox_extern->IsChecked())
359
flags |= (int)IBPP::brConvertExtTables;
361
BackupThread* thread = new BackupThread(this, serverM->getName(), databaseM->getUsername(),
362
password, databaseM->getPath(), wx2std(text_ctrl_filename->GetValue()), (IBPP::BRF)flags);
366
//-----------------------------------------------------------------------------