Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

dlgBatchCreateConf.cpp

Go to the documentation of this file.
00001 /* 00002 * wxChecksums 00003 * Copyright (C) 2003-2004 Julien Couot 00004 * 00005 * This program is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU General Public License 00007 * as published by the Free Software Foundation; either version 2 00008 * of the License, or (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00018 */ 00019 00020 /** 00021 * \file dlgBatchCreateConf.cpp 00022 * Configuration dialog for creating one checksums' file for each selected file. 00023 */ 00024 00025 00026 //--------------------------------------------------------------------------- 00027 // For compilers that support precompilation, includes "wx.h". 00028 #include <wx/wxprec.h> 00029 00030 #ifdef __BORLANDC__ 00031 #pragma hdrstop 00032 #endif 00033 00034 #ifndef WX_PRECOMP 00035 // Include your minimal set of headers here, or wx.h 00036 #include <wx/wx.h> 00037 #endif 00038 00039 #include <wx/config.h> 00040 #include <wx/valgen.h> 00041 00042 #include "dlgBatchCreateConf.hpp" 00043 #include "appprefs.hpp" 00044 #include "checksumfactory.hpp" 00045 #include "comdefs.hpp" 00046 #include "fdftlmk.hpp" 00047 00048 #include "compat.hpp" 00049 //--------------------------------------------------------------------------- 00050 00051 00052 /// The C++ standard namespace. 00053 using namespace std; 00054 00055 00056 //########################################################################### 00057 // dlgBatchCreationConfOptions class 00058 //########################################################################### 00059 00060 /** 00061 * Dialog for changing batch creation options. 00062 */ 00063 class dlgBatchCreationConfOptions : public wxDialog 00064 { 00065 public: 00066 /// Creates a new dialog. 00067 dlgBatchCreationConfOptions() : wxDialog() { createControls(); } 00068 00069 // Creates a new dialog. 00070 dlgBatchCreationConfOptions(wxWindow* parent, const dlgBatchCreation::Options& options); 00071 00072 // Destructor. 00073 virtual ~dlgBatchCreationConfOptions(); 00074 00075 protected: 00076 // Creates and initializes the controls of the dialog. 00077 void createControls(); 00078 00079 int verbosity; ///< Report's Verbosity. 00080 /** 00081 * If <CODE>true</CODE>, when a checksums' file already exists it is 00082 * overwritten. Otherwise the creation of the checksums' file is skipped. 00083 */ 00084 bool ovrCkFileWhenItExists; 00085 /** 00086 * If <CODE>true</CODE> the name of the checksums' file will be made by 00087 * replacing the extension of the source file with the extension of the type 00088 * of the checksums' file. Otherwise, the name of the checksums' file will be 00089 * made by adding the extension of the type of checksums' file to the name of 00090 * the source file. 00091 */ 00092 bool replaceExtension; 00093 00094 public: 00095 // Gets the options modified by the user. 00096 dlgBatchCreation::Options getOptions() const; 00097 00098 private: 00099 DECLARE_DYNAMIC_CLASS(dlgBatchCreationConfOptions) 00100 }; 00101 //--------------------------------------------------------------------------- 00102 00103 IMPLEMENT_DYNAMIC_CLASS(dlgBatchCreationConfOptions, wxDialog) 00104 00105 00106 /** 00107 * Creates a new dialog. 00108 * 00109 * @param parent Parent of the dialog. 00110 * @param options Initial options. 00111 */ 00112 dlgBatchCreationConfOptions::dlgBatchCreationConfOptions(wxWindow* parent, 00113 const dlgBatchCreation::Options& options) : 00114 wxDialog(parent, -1, wxString(_("Options of the batch creation of checksums' files"))) 00115 { 00116 // Initializes the options. 00117 ovrCkFileWhenItExists = options.ovrCkFileWhenItExists; 00118 replaceExtension = options.replaceExtension; 00119 verbosity = options.getVerbosity(); 00120 00121 // Creates the controls. 00122 createControls(); 00123 00124 // Make a well-sized dialog 00125 Fit(); 00126 Centre(); 00127 } 00128 //--------------------------------------------------------------------------- 00129 00130 00131 /** 00132 * Creates and initializes the controls of the dialog. 00133 */ 00134 void dlgBatchCreationConfOptions::createControls() 00135 { 00136 // "When a checksums' file alrealdy exists" frame. 00137 wxStaticBox* fraBCCkFileExists = new wxStaticBox(this, -1, _("When a checksums' file alrealdy exists:")); 00138 wxRadioButton* rbxBCSkipExistingCkFile = new wxRadioButton(this, -1, _("S&kip the creation"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP); 00139 wxRadioButton* rbxBCOverwriteExistingCkFile = new wxRadioButton(this, -1, _("&Overwrite it"), wxDefaultPosition, wxDefaultSize, 0, wxGenericValidator(&ovrCkFileWhenItExists)); 00140 00141 // "Create the name of the checksums' file by:" frame 00142 wxStaticBox* fraBCChecksumsFileName = new wxStaticBox(this, -1, _("Create the name of the checksums' file by:")); 00143 wxRadioButton* rbxBCReplaceFileExtension = new wxRadioButton(this, -1, _("&Replacing the extension of the source file with the extension of the type of the checksums' file."), wxDefaultPosition, wxDefaultSize, wxRB_GROUP, wxGenericValidator(&replaceExtension)); 00144 wxRadioButton* rbxBCAddFileExtension = new wxRadioButton(this, -1, _("&Adding the extension of the type of the checksums' file to the name of the source file."), wxDefaultPosition, wxDefaultSize); 00145 00146 // The "Verbosity level of the report:" frame 00147 wxStaticBox* fraBCVerbosityLevel = new wxStaticBox(this, -1, _("Level of &verbosity of the report:")); 00148 const wxString strVerbosityLevels[] = { _("Errors only"), _("Errors and warnings"), _("Normal"), _("Talkative") }; 00149 wxChoice* cboBCVerbosityLevel = new wxChoice(this, -1, wxDefaultPosition, wxDefaultSize, 00150 4, strVerbosityLevels, 0, wxGenericValidator(&verbosity)); 00151 if (verbosity < dlgBatchCreation::Verbosity_Min || verbosity > dlgBatchCreation::Verbosity_Max) 00152 verbosity = dlgBatchCreation::vNormal; 00153 00154 wxButton* btnOK = new wxButton(this, wxID_OK, _("&OK")); 00155 btnOK->SetDefault(); 00156 wxButton* btnCancel = new wxButton(this, wxID_CANCEL, _("&Cancel")); 00157 00158 // Batch creation page sizer 00159 // The dialog sizer 00160 wxBoxSizer* dlgBatchCreationConfOptionsSizer2 = new wxBoxSizer(wxVERTICAL); 00161 this->SetSizer(dlgBatchCreationConfOptionsSizer2); 00162 wxBoxSizer* dlgBatchCreationConfOptionsSizer = new wxBoxSizer(wxVERTICAL); 00163 dlgBatchCreationConfOptionsSizer2->Add(dlgBatchCreationConfOptionsSizer, 1, wxALL | wxGROW, CONTROL_SPACE); 00164 00165 // The "When a checksums' file alrealdy exists" frame sizer 00166 wxStaticBoxSizer* fraBCCkFileExistsSizer2 = new wxStaticBoxSizer(fraBCCkFileExists, wxVERTICAL); 00167 dlgBatchCreationConfOptionsSizer->Add(fraBCCkFileExistsSizer2, 0, wxGROW); 00168 wxBoxSizer* fraBCCkFileExistsSizer = new wxBoxSizer(wxVERTICAL); 00169 fraBCCkFileExistsSizer2->Add(fraBCCkFileExistsSizer, 0, wxALL | wxGROW, CONTROL_SPACE / 2); 00170 00171 fraBCCkFileExistsSizer->Add(rbxBCSkipExistingCkFile); 00172 fraBCCkFileExistsSizer->Add(rbxBCOverwriteExistingCkFile, 0, wxTOP, CONTROL_SPACE / 2); 00173 00174 // The "Create the name of the checksums' file by:" frame sizer 00175 wxStaticBoxSizer* fraBCChecksumsFileNameSizer2 = new wxStaticBoxSizer(fraBCChecksumsFileName, wxVERTICAL); 00176 dlgBatchCreationConfOptionsSizer->Add(fraBCChecksumsFileNameSizer2, 0, wxGROW | wxTOP, CONTROL_SPACE); 00177 wxBoxSizer* fraBCChecksumsFileNameSizer = new wxBoxSizer(wxVERTICAL); 00178 fraBCChecksumsFileNameSizer2->Add(fraBCChecksumsFileNameSizer, 0, wxALL | wxGROW, CONTROL_SPACE / 2); 00179 00180 fraBCChecksumsFileNameSizer->Add(rbxBCReplaceFileExtension); 00181 fraBCChecksumsFileNameSizer->Add(rbxBCAddFileExtension, 0, wxTOP, CONTROL_SPACE / 2); 00182 00183 // The "Verbosity level of the report:" frame sizer 00184 wxStaticBoxSizer* fraBCVerbosityLevelSizer2 = new wxStaticBoxSizer(fraBCVerbosityLevel, wxVERTICAL); 00185 dlgBatchCreationConfOptionsSizer->Add(fraBCVerbosityLevelSizer2, 0, wxGROW | wxTOP, CONTROL_SPACE); 00186 wxBoxSizer* fraBCVerbosityLevelSizer = new wxBoxSizer(wxVERTICAL); 00187 fraBCVerbosityLevelSizer2->Add(fraBCVerbosityLevelSizer, 0, wxALL | wxGROW, CONTROL_SPACE / 2); 00188 00189 fraBCVerbosityLevelSizer->Add(cboBCVerbosityLevel); 00190 00191 // Validation buttons sizer 00192 wxGridSizer* buttonsSizer = new wxGridSizer(2, 0, 2 * CONTROL_SPACE); 00193 buttonsSizer->Add(btnOK); 00194 buttonsSizer->Add(btnCancel); 00195 dlgBatchCreationConfOptionsSizer->Add(buttonsSizer, 0, wxTOP | wxALIGN_RIGHT, 2 * CONTROL_SPACE); 00196 00197 // Set on the auto-layout feature 00198 this->SetAutoLayout(true); 00199 this->Layout(); 00200 00201 // Initializes the controls. 00202 this->TransferDataToWindow(); 00203 00204 // Needed because the validator don't choose another control. 00205 if (ovrCkFileWhenItExists) 00206 rbxBCOverwriteExistingCkFile->SetValue(true); 00207 else 00208 rbxBCSkipExistingCkFile->SetValue(true); 00209 00210 if (replaceExtension) 00211 rbxBCReplaceFileExtension->SetValue(true); 00212 else 00213 rbxBCAddFileExtension->SetValue(true); 00214 00215 } 00216 //--------------------------------------------------------------------------- 00217 00218 00219 /** 00220 * The class descructor. 00221 */ 00222 dlgBatchCreationConfOptions::~dlgBatchCreationConfOptions() 00223 { 00224 } 00225 //--------------------------------------------------------------------------- 00226 00227 00228 /** 00229 * Gets the options modified by the user. 00230 * 00231 * @return The options modified by the user. 00232 */ 00233 dlgBatchCreation::Options dlgBatchCreationConfOptions::getOptions() const 00234 { 00235 return dlgBatchCreation::Options(ovrCkFileWhenItExists, replaceExtension, 00236 static_cast<dlgBatchCreation::Verbosity>(verbosity)); 00237 } 00238 //--------------------------------------------------------------------------- 00239 00240 00241 00242 00243 //########################################################################### 00244 // dlgBatchCreationConf methods 00245 //########################################################################### 00246 00247 IMPLEMENT_DYNAMIC_CLASS(dlgBatchCreationConf, dlgFilesSelector) 00248 00249 00250 /** 00251 * Creates a new dialog. 00252 */ 00253 dlgBatchCreationConf::dlgBatchCreationConf() : dlgFilesSelector() 00254 { 00255 } 00256 //--------------------------------------------------------------------------- 00257 00258 00259 /** 00260 * Creates a new dialog. 00261 * 00262 * @param parent Parent of the dialog. 00263 */ 00264 dlgBatchCreationConf::dlgBatchCreationConf(wxWindow* parent) : 00265 dlgFilesSelector(parent, true) 00266 { 00267 } 00268 //--------------------------------------------------------------------------- 00269 00270 00271 /** 00272 * Initializes the dialog. 00273 * 00274 * If you derivate this method, please call the one of the parent class before 00275 * doing anything. 00276 */ 00277 void dlgBatchCreationConf::initialize() 00278 { 00279 dlgFilesSelector::initialize(); 00280 00281 createControls(); 00282 00283 // These folling lines are necessary even if they are in 00284 // dlgFilesSelector::initialize() :( 00285 Fit(); 00286 00287 // Get the size of the window 00288 wxSize s; 00289 if (PreferenceValue::read(getConfigKey(prGUI_WINDOW_SIZE), &s)) 00290 SetSize(s); 00291 00292 Centre(); 00293 00294 // Initialazing dlgBatchCreate options 00295 options = dlgBatchCreation::Options(AppPrefs::get()->readBool(prBC_OVERWRITE_WHEN_CKFILE_EXISTS), 00296 AppPrefs::get()->readBool(prBC_REPLACE_FILE_EXTENSION), 00297 static_cast<dlgBatchCreation::Verbosity>(AppPrefs::get()->readLong(prBC_VERBOSITY_LEVEL))); 00298 } 00299 //--------------------------------------------------------------------------- 00300 00301 00302 /** 00303 * Creates and initializes the controls of the dialog. 00304 */ 00305 void dlgBatchCreationConf::createControls() 00306 { 00307 int i; 00308 00309 // Creates the controls 00310 wxStaticBox* fraCkFileTypes = new wxStaticBox(this, -1, _("Create the following types of checks&ums' file:")); 00311 btnOptions = new wxButton(this, BTN_OPTIONS, _("O&ptions...")); 00312 for (i = 0; i < SumFileFactory::getSumFilesCount(); i++) 00313 chkCkFileTypes.Add(new wxCheckBox(this, -1, SumFileFactory::getSumFileName(i))); 00314 00315 00316 //------------------------------------------------------------------------- 00317 // Creates the dialog sizers 00318 00319 // Static frame 00320 wxStaticBoxSizer* fraCkFileTypesSizer2 = new wxStaticBoxSizer(fraCkFileTypes, wxVERTICAL); 00321 extendSizer->Add(fraCkFileTypesSizer2, 1, wxGROW | wxTOP, CONTROL_SPACE); 00322 wxBoxSizer* fraCkFileTypesSizer = new wxBoxSizer(wxHORIZONTAL); 00323 fraCkFileTypesSizer2->Add(fraCkFileTypesSizer, 1, wxALL | wxGROW, CONTROL_SPACE / 2); 00324 00325 // Checksums' file types 00326 wxBoxSizer* ckFileTypeSizer = new wxBoxSizer(wxHORIZONTAL); 00327 fraCkFileTypesSizer->Add(ckFileTypeSizer, 1, wxGROW | wxALIGN_CENTER_VERTICAL); 00328 for (i = 0; i < SumFileFactory::getSumFilesCount(); i++) 00329 if (i == 0) 00330 ckFileTypeSizer->Add(chkCkFileTypes[i], 0, wxALIGN_CENTER_VERTICAL); 00331 else 00332 ckFileTypeSizer->Add(chkCkFileTypes[i], 0, wxLEFT | wxALIGN_CENTER_VERTICAL, CONTROL_SPACE); 00333 00334 // Options button 00335 fraCkFileTypesSizer->Add(btnOptions, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT | wxLEFT, CONTROL_SPACE); 00336 00337 this->Layout(); 00338 00339 00340 //------------------------------------------------------------------------- 00341 // Initializes the controls 00342 for (i = 0; i < SumFileFactory::getSumFilesCount(); i++) 00343 { 00344 bool value; 00345 wxConfig::Get()->Read(getCkFileTypeCreateConfigKey(i), &value, true); 00346 chkCkFileTypes[i]->SetValue(value); 00347 } 00348 } 00349 //--------------------------------------------------------------------------- 00350 00351 00352 /** 00353 * The class descructor. 00354 */ 00355 dlgBatchCreationConf::~dlgBatchCreationConf() 00356 { 00357 } 00358 //--------------------------------------------------------------------------- 00359 00360 00361 /** 00362 * Processes button Options. 00363 * 00364 * @param event The event's parameters 00365 */ 00366 void dlgBatchCreationConf::btnOptionsClick(wxCommandEvent& event) 00367 { 00368 dlgBatchCreationConfOptions dlg(this, options); 00369 if (dlg.ShowModal() == wxID_OK) 00370 options = dlg.getOptions(); 00371 } 00372 //--------------------------------------------------------------------------- 00373 00374 00375 /** 00376 * Processes button OK. 00377 * 00378 * @param event The event's parameters 00379 */ 00380 void dlgBatchCreationConf::btnOKClick(wxCommandEvent& event) 00381 { 00382 ckFileTypes.Empty(); 00383 for (int i = 0; i < SumFileFactory::getSumFilesCount(); i++) 00384 { 00385 if (chkCkFileTypes[i]->GetValue()) 00386 ckFileTypes.Add(i); 00387 wxConfig::Get()->Write(getCkFileTypeCreateConfigKey(i), chkCkFileTypes[i]->GetValue()); 00388 } 00389 00390 if (ckFileTypes.IsEmpty()) 00391 { 00392 ::wxMessageBox(_("Select as least a type of checksums' file."), _("Warning"), wxOK | wxICON_EXCLAMATION); 00393 return; 00394 } 00395 else 00396 event.Skip(); // let the rest of the work to the superclass event handler. 00397 } 00398 //--------------------------------------------------------------------------- 00399 00400 00401 /** 00402 * Gets the types of the checksums' file to create. 00403 * 00404 * @return The types of the checksums' file to create. 00405 */ 00406 wxArrayInt dlgBatchCreationConf::getChecksumsFileTypeToCreate() const 00407 { 00408 return ckFileTypes; 00409 } 00410 //--------------------------------------------------------------------------- 00411 00412 00413 /** 00414 * Gets the options for <CODE>dlgBatchCreation</CODE>. 00415 * 00416 * @return The options for <CODE>dlgBatchCreation</CODE>. 00417 */ 00418 dlgBatchCreation::Options dlgBatchCreationConf::getOptions() const 00419 { 00420 return options; 00421 } 00422 //--------------------------------------------------------------------------- 00423 00424 00425 /** 00426 * Gets the root configuration key for parameters of this dialog. 00427 * 00428 * The returned string must be ended the a '<CODE>/</CODE>' character. 00429 * 00430 * @return The root configuration key for parameters of this dialog. 00431 */ 00432 wxString dlgBatchCreationConf::getRootConfigKey() 00433 { 00434 return wxT("GUI/BatchCreationConfigDlg/"); 00435 } 00436 //--------------------------------------------------------------------------- 00437 00438 00439 /** 00440 * Gets the configuration key for the values of the checksums' files types 00441 * check boxes. 00442 * 00443 * @param sumFileType Type of the checksums' file of which the caller want 00444 * the configuration key. Should be a value of the 00445 * <CODE>SumFileFactory::SumFileType</CODE> enumeration. 00446 * @return The configuration key for the values of the checksums' files types 00447 * check boxes or an empty string if <CODE>sumFileType</CODE> has an 00448 * invalid value. 00449 */ 00450 wxString dlgBatchCreationConf::getCkFileTypeCreateConfigKey(const int sumFileType) 00451 { 00452 if (sumFileType < 0 || sumFileType >= SumFileFactory::getSumFilesCount()) 00453 return wxEmptyString; 00454 00455 return getRootConfigKey() + wxT("CreateChecksumsFileType/") + SumFileFactory::getSumFileName(sumFileType); 00456 } 00457 //--------------------------------------------------------------------------- 00458 00459 00460 /** 00461 * Gets the string for the specified UI element. 00462 * 00463 * @param id Identifier of the wanted UI element. 00464 * @return The string for the specified UI element and an empty string if the 00465 * given UI element is invalid. 00466 */ 00467 wxString dlgBatchCreationConf::getUIString(UIStrings id) 00468 { 00469 wxString res; 00470 switch (id) 00471 { 00472 case uiDialogTitle : 00473 res = _("Batch creation of checksums' files"); break; 00474 case uiBtnOK : 00475 res = _("&Create"); break; 00476 case uiFraFilesList : 00477 res = _("List of files from which the c&hecksums' files will be created:"); break; 00478 case uiFraSearchFiles : 00479 res = _("Search &for some files:"); break; 00480 case uiOpenDlgAddFiles : 00481 res = _("Select the files to be added"); break; 00482 case uiOpenDlgAddList : 00483 res = _("Add a list of files"); break; 00484 case uiOpenDlgLoadList : 00485 res = _("Load a list of files"); break; 00486 case uiSaveDlgAddList : 00487 res = _("Save a list of files"); break; 00488 }; 00489 00490 return res; 00491 } 00492 //--------------------------------------------------------------------------- 00493 00494 00495 /** 00496 * Returns a set of filters for the "Add files" dialog. 00497 * 00498 * @return A set of filters for the "Add files" dialog. 00499 */ 00500 wxFileDialogFilterMaker dlgBatchCreationConf::getFiltersForAddFilesDialog() 00501 { 00502 wxFileDialogFilterMaker fltMaker; 00503 fltMaker.AddFilter(_("All the files"), wxT("*")); 00504 00505 return fltMaker; 00506 } 00507 //--------------------------------------------------------------------------- 00508 00509 00510 00511 BEGIN_EVENT_TABLE(dlgBatchCreationConf, dlgFilesSelector) 00512 EVT_BUTTON(BTN_OPTIONS, dlgBatchCreationConf::btnOptionsClick) 00513 EVT_BUTTON(BTN_OK, dlgBatchCreationConf::btnOKClick) 00514 END_EVENT_TABLE() 00515 //--------------------------------------------------------------------------- 00516

Generated on Sun May 30 13:37:44 2004 for wxChecksums by doxygen 1.3.7