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
41
#include "BackupRestoreBaseFrame.h"
45
//-----------------------------------------------------------------------------
46
BackupRestoreBaseFrame::BackupRestoreBaseFrame(wxWindow* parent, YDatabase* db):
47
BaseFrame(parent, -1, _T(""), wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE|wxNO_FULL_REPAINT_ON_RESIZE)
50
serverM = reinterpret_cast<YServer*>(db->getParent());
53
threadMsgTimeMillisM = 0;
55
storageNameM = "unassigned";
57
// create controls in constructor of descendant class to allow for correct tab order
60
text_ctrl_filename = 0;
68
wxBitmap bmp(backup_xpm);
70
icon.CopyFromBitmap(bmp);
73
//-----------------------------------------------------------------------------
74
//! some controls need additional setup after descendant frame's controls are created
75
void BackupRestoreBaseFrame::setupControls()
77
text_ctrl_log->StyleSetForeground(1, *wxBLUE);
78
text_ctrl_log->StyleSetForeground(2, *wxRED);
79
text_ctrl_log->SetMarginWidth(1, 0);
80
text_ctrl_log->SetWrapMode(wxSTC_WRAP_WORD);
82
//-----------------------------------------------------------------------------
83
//! implementation details
84
void BackupRestoreBaseFrame::addThreadMsg(const wxString msg, bool& notificationNeeded)
86
notificationNeeded = false;
87
wxLongLong millisNow = ::wxGetLocalTimeMillis();
89
wxCriticalSectionLocker locker(critsectM);
91
// we post no more than 10 events per second to prevent flooding of the message queue
92
// and keep the frame responsive for user interaction
93
if ((millisNow - threadMsgTimeMillisM).GetLo() > 100)
95
threadMsgTimeMillisM = millisNow;
96
notificationNeeded = true;
99
//-----------------------------------------------------------------------------
100
void BackupRestoreBaseFrame::cancelBackupRestore()
108
//-----------------------------------------------------------------------------
109
void BackupRestoreBaseFrame::clearLog()
113
text_ctrl_log->ClearAll();
115
//-----------------------------------------------------------------------------
116
bool BackupRestoreBaseFrame::Destroy()
118
cancelBackupRestore();
119
return BaseFrame::Destroy();
121
//-----------------------------------------------------------------------------
122
void BackupRestoreBaseFrame::doReadConfigSettings(const std::string& prefix)
124
BaseFrame::doReadConfigSettings(prefix);
127
if (!config().getValue(prefix + "::verboselog", verbose))
129
combobox_showlog->SetValue(verbose);
132
if (config().getValue(prefix + "::backupfilename", bkfile) && !bkfile.empty())
133
text_ctrl_filename->SetValue(std2wx(bkfile));
135
//-----------------------------------------------------------------------------
136
void BackupRestoreBaseFrame::doWriteConfigSettings(const std::string& prefix) const
138
BaseFrame::doWriteConfigSettings(prefix);
139
config().setValue(prefix + "::verboselog", combobox_showlog->GetValue());
140
config().setValue(prefix + "::backupfilename", wx2std(text_ctrl_filename->GetValue()));
142
//-----------------------------------------------------------------------------
143
const std::string BackupRestoreBaseFrame::getStorageName() const
145
if (storageNameM == "unassigned")
147
StorageGranularity g;
148
if (!config().getValue(getName() + "StorageGranularity", g))
154
storageNameM = getName();
157
storageNameM = getName() + "::" + databaseM->getItemPath();
166
//-----------------------------------------------------------------------------
167
bool BackupRestoreBaseFrame::startThread(wxThread* thread)
169
wxASSERT(threadM == 0);
170
if (wxTHREAD_NO_ERROR != thread->Create())
172
::wxMessageBox(_("Error creating thread!"), _("Error"), wxICON_ERROR);
176
if (wxTHREAD_NO_ERROR != thread->Run())
178
::wxMessageBox(_("Error starting thread!"), _("Error"), wxICON_ERROR);
185
//-----------------------------------------------------------------------------
186
void BackupRestoreBaseFrame::threadOutputMsg(const wxString msg, MsgKind kind)
194
case important_message:
197
case progress_message:
204
bool doPostMsg = false;
205
addThreadMsg(s, doPostMsg);
208
wxCommandEvent event(wxEVT_COMMAND_MENU_SELECTED, ID_thread_output);
209
wxPostEvent(this, event);
212
//-----------------------------------------------------------------------------
213
void BackupRestoreBaseFrame::updateMessages(size_t firstmsg, size_t lastmsg)
215
if (lastmsg > msgsM.GetCount())
216
lastmsg = msgsM.GetCount();
218
for (size_t i = firstmsg; i < lastmsg; i++)
221
switch ((MsgKind)msgKindsM[i])
223
case progress_message:
227
case important_message:
234
int startpos = text_ctrl_log->GetLength();
235
text_ctrl_log->AddText(msgsM[i] + wxT("\n"));
236
int endpos = text_ctrl_log->GetLength();
237
text_ctrl_log->StartStyling(startpos, 255);
238
text_ctrl_log->SetStyling(endpos-startpos-1, style);
243
text_ctrl_log->GotoPos(text_ctrl_log->GetLength());
245
//-----------------------------------------------------------------------------
247
BEGIN_EVENT_TABLE(BackupRestoreBaseFrame, BaseFrame)
248
EVT_BUTTON(BackupRestoreBaseFrame::ID_button_cancel, BackupRestoreBaseFrame::OnCancelButtonClick)
249
EVT_CHECKBOX(BackupRestoreBaseFrame::ID_checkbox_showlog, BackupRestoreBaseFrame::OnVerboseLogChange)
250
EVT_MENU(BackupRestoreBaseFrame::ID_thread_finished, BackupRestoreBaseFrame::OnThreadFinished)
251
EVT_MENU(BackupRestoreBaseFrame::ID_thread_output, BackupRestoreBaseFrame::OnThreadOutput)
252
EVT_TEXT(BackupRestoreBaseFrame::ID_text_ctrl_filename, BackupRestoreBaseFrame::OnSettingsChange)
254
//-----------------------------------------------------------------------------
255
void BackupRestoreBaseFrame::OnCancelButtonClick(wxCommandEvent& WXUNUSED(event))
257
cancelBackupRestore();
260
//-----------------------------------------------------------------------------
261
void BackupRestoreBaseFrame::OnSettingsChange(wxCommandEvent& WXUNUSED(event))
266
//-----------------------------------------------------------------------------
267
void BackupRestoreBaseFrame::OnThreadFinished(wxCommandEvent& event)
270
OnThreadOutput(event);
273
//-----------------------------------------------------------------------------
274
void BackupRestoreBaseFrame::OnThreadOutput(wxCommandEvent& WXUNUSED(event))
276
wxCriticalSectionLocker locker(critsectM);
277
threadMsgTimeMillisM = ::wxGetLocalTimeMillis();
279
size_t first = msgsM.GetCount();
280
for (size_t i = 0; i < threadMsgsM.GetCount(); i++)
282
wxString s(threadMsgsM[i]);
285
switch (s.GetChar(0))
288
msgKindsM.Add((int)error_message);
291
msgKindsM.Add((int)important_message);
294
msgKindsM.Add((int)progress_message);
297
// this depends on server type, so just in case...
298
if (s.Last() == '\n')
304
updateMessages(first, msgsM.GetCount());
306
//-----------------------------------------------------------------------------
307
void BackupRestoreBaseFrame::OnVerboseLogChange(wxCommandEvent& WXUNUSED(event))
310
verboseMsgsM = combobox_showlog->IsChecked();
312
text_ctrl_log->Freeze();
313
text_ctrl_log->ClearAll();
314
updateMessages(0, msgsM.GetCount());
315
text_ctrl_log->Thaw();
317
//-----------------------------------------------------------------------------