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

frmSums.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 frmSums.cpp 00022 * Application's main window body. 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/fileconf.h> 00041 #include <wx/filename.h> 00042 #include <wx/txtstrm.h> 00043 00044 #include "frmSums.hpp" 00045 #include "dlgAbout.hpp" 00046 #include "dlgBatchCreate.hpp" 00047 #include "dlgBatchCreateConf.hpp" 00048 #include "dlgConf.hpp" 00049 #include "dlgMultiCheck.hpp" 00050 #include "dlgMultiCheckConf.hpp" 00051 #include "dlgNewFile.hpp" 00052 #include "appprefs.hpp" 00053 #include "checksumfactory.hpp" 00054 #include "cmdlnopt.hpp" 00055 #include "comdefs.hpp" 00056 #include "fdftlmk.hpp" 00057 #include "fileutil.hpp" 00058 #include "language.hpp" 00059 #include "sfvfile.hpp" 00060 #include "md5file.hpp" 00061 #include "utils.hpp" 00062 00063 #if !defined(__WXMSW__) 00064 #include "bitmaps/icon_app_checksums.xpm" 00065 #endif // !defined(__WXMSW__) 00066 00067 // On Windows, set the bitmaps in the menus make the item accelerator doesn't 00068 // work... 00069 // See also addMenuItemWithBitmap(...). 00070 //#if !defined(__WXMSW__) 00071 #include "bitmaps/hi16_action_filenew.xpm" 00072 #include "bitmaps/hi16_action_fileopen.xpm" 00073 #include "bitmaps/hi16_action_filesave.xpm" 00074 #include "bitmaps/hi16_action_filesaveas.xpm" 00075 #include "bitmaps/hi16_action_fileclose.xpm" 00076 #include "bitmaps/hi16_action_exit.xpm" 00077 #include "bitmaps/hi16_action_fileadd.xpm" 00078 #include "bitmaps/hi16_action_directoryadd.xpm" 00079 #include "bitmaps/hi16_action_addmatchingfiles.xpm" 00080 #include "bitmaps/hi16_action_fileremove.xpm" 00081 #include "bitmaps/hi16_action_check.xpm" 00082 #include "bitmaps/hi16_action_recompute.xpm" 00083 #include "bitmaps/hi16_action_configure.xpm" 00084 #include "bitmaps/hi16_action_helpabout.xpm" 00085 //#endif // !defined(__WXMSW__) 00086 00087 #include "bitmaps/hi22_action_filenew.xpm" 00088 #include "bitmaps/hi22_action_fileopen.xpm" 00089 #include "bitmaps/hi22_action_filesave.xpm" 00090 #include "bitmaps/hi22_action_fileadd.xpm" 00091 #include "bitmaps/hi22_action_directoryadd.xpm" 00092 #include "bitmaps/hi22_action_addmatchingfiles.xpm" 00093 #include "bitmaps/hi22_action_fileremove.xpm" 00094 #include "bitmaps/hi22_action_check.xpm" 00095 #include "bitmaps/hi22_action_recompute.xpm" 00096 #include "bitmaps/hi22_action_configure.xpm" 00097 00098 #include "compat.hpp" 00099 //--------------------------------------------------------------------------- 00100 00101 00102 /// The C++ standard namespace. 00103 using namespace std; 00104 00105 /// The style of the main window. 00106 #define frmSUMS_STYLE wxDEFAULT_FRAME_STYLE 00107 //#define frmSUMS_STYLE wxWANTS_CHARS | wxMINIMIZE_BOX | wxMAXIMIZE_BOX | wxSYSTEM_MENU | wxCAPTION | wxRESIZE_BORDER 00108 00109 00110 00111 //########################################################################### 00112 // Useful fonctions 00113 //########################################################################### 00114 00115 /** 00116 * Adds a menu item with a bitmap to a menu. 00117 * 00118 * @param parentMenu Menu that the menu item belongs to. 00119 * @param id Identifier for this menu item. 00120 * @param text Text for the menu item, as shown on the menu. An 00121 * accelerator key can be specified using the ampersand '&' 00122 * character. In order to embed an ampersand character in 00123 * the menu item text, the ampersand must be doubled. 00124 * @param bitmap The bitmap for the menu item. 00125 * @param helpString Optional help string that will be shown on the status 00126 * bar. 00127 * @param kind May be <CODE>wxITEM_SEPARATOR</CODE>, 00128 * <CODE>wxITEM_NORMAL</CODE>, <CODE>wxITEM_CHECK</CODE> or 00129 * <CODE>wxITEM_RADIO</CODE>. 00130 * @param subMenu If non-NULL, indicates that the menu item is a submenu. 00131 */ 00132 static void addMenuItemWithBitmap(wxMenu* parentMenu, int id, 00133 const wxString& text, 00134 const wxBitmap& bitmap, 00135 const wxString& helpString = wxEmptyString, 00136 wxItemKind kind = wxITEM_NORMAL, 00137 wxMenu* subMenu = NULL) 00138 { 00139 wxMenuItem* menuItem; 00140 menuItem = new wxMenuItem(parentMenu, id, text, helpString, kind, subMenu); 00141 #if !defined(__WXMSW__) 00142 menuItem->SetBitmap(bitmap); 00143 #endif // !defined(__WXMSW__) 00144 parentMenu->Append(menuItem); 00145 } 00146 //--------------------------------------------------------------------------- 00147 00148 00149 00150 //########################################################################### 00151 // frmSums methods 00152 //########################################################################### 00153 00154 IMPLEMENT_DYNAMIC_CLASS(frmSums, wxFrame) 00155 00156 // Static attributes of the frmSums class 00157 // The maximum size of a toolbar button. 00158 const int frmSums::TOOL_BITMAP_SIZE = 24; 00159 00160 00161 /** 00162 * Creates a new frame. 00163 */ 00164 frmSums::frmSums() : wxFrame() 00165 { 00166 createControls(); 00167 } 00168 //--------------------------------------------------------------------------- 00169 00170 00171 /** 00172 * Creates a new frame. 00173 * 00174 * @param title the window's title. 00175 * @param xpos the horizontal position of the window. 00176 * @param ypos the vertical position of the window. 00177 * @param width the witdh of the window. 00178 * @param height the height of the window. 00179 */ 00180 frmSums::frmSums(const wxChar* title, int xpos, int ypos, int width, int height) : 00181 wxFrame((wxFrame*)NULL, -1, title, wxPoint(xpos, ypos), wxSize(width, height), frmSUMS_STYLE) 00182 { 00183 createControls(); 00184 } 00185 //--------------------------------------------------------------------------- 00186 00187 00188 /** 00189 * Creates a new frame. 00190 * Use system defaults for the position and the size of the window. 00191 * 00192 * @param title the window's title. 00193 */ 00194 frmSums::frmSums(const wxChar* title) : 00195 wxFrame((wxFrame*)NULL, -1, title, wxDefaultPosition, wxDefaultSize, frmSUMS_STYLE) 00196 { 00197 createControls(); 00198 } 00199 //--------------------------------------------------------------------------- 00200 00201 00202 /** 00203 * Creates and initializes the controls of the frame. 00204 */ 00205 void frmSums::createControls() 00206 { 00207 // Sets the frame icon 00208 this->SetIcon(wxICON(icon_app_checksums)); 00209 00210 00211 // Creates the status bar 00212 createStatusbar(); 00213 00214 // Creates the menus 00215 wxMenuItem* menuItem; 00216 wxMenuBar* menuBar = new wxMenuBar(wxMB_DOCKABLE); 00217 SetMenuBar(menuBar); 00218 00219 // Menu "File" 00220 wxMenu* mnuFile = new wxMenu(wxMENU_TEAROFF); 00221 menuBar->Append(mnuFile, _("&File")); 00222 // File->New item 00223 addMenuItemWithBitmap(mnuFile, ITM_FILE_NEW, _("&New...\tCtrl+N"), 00224 wxBitmap(hi16_action_filenew_xpm), 00225 _("Creates a new checksum file.")); 00226 // File->Open item 00227 addMenuItemWithBitmap(mnuFile, ITM_FILE_OPEN, _("&Open...\tCtrl+O"), 00228 wxBitmap(hi16_action_fileopen_xpm), 00229 _("Opens a checksum file.")); 00230 // File->Open recent menu 00231 mnuOpenRecent = new wxMenu(wxMENU_TEAROFF); 00232 mnuFile->Append(MNU_FILE_OPENRECENT, _("Open &recent"), mnuOpenRecent); 00233 // A separator 00234 mnuFile->AppendSeparator(); 00235 // File->Save item 00236 addMenuItemWithBitmap(mnuFile, ITM_FILE_SAVE, _("&Save\tCtrl+S"), 00237 wxBitmap(hi16_action_filesave_xpm), 00238 _("Saves the checksum file.")); 00239 // File->Save as item 00240 addMenuItemWithBitmap(mnuFile, ITM_FILE_SAVEAS, _("Save &as..."), 00241 wxBitmap(hi16_action_filesaveas_xpm), 00242 _("Saves the checksum file in another file.")); 00243 // A separator 00244 mnuFile->AppendSeparator(); 00245 // File->Close item 00246 addMenuItemWithBitmap(mnuFile, ITM_FILE_CLOSE, _("&Close\tCtrl+W"), 00247 wxBitmap(hi16_action_fileclose_xpm), 00248 _("Closes the checksum file.")); 00249 // A separator 00250 mnuFile->AppendSeparator(); 00251 // File->Quit item 00252 addMenuItemWithBitmap(mnuFile, ITM_FILE_QUIT, _("&Quit\tCtrl+Q"), 00253 wxBitmap(hi16_action_exit_xpm), 00254 wxString::Format(_("Quit %s."), wxT(APP_NAME))); 00255 00256 // Menu "Sums" 00257 wxMenu* mnuSums = new wxMenu(wxMENU_TEAROFF); 00258 menuBar->Append(mnuSums, _("&Sums")); 00259 // Sums->Add files item 00260 addMenuItemWithBitmap(mnuSums, ITM_SUMS_ADDFILES, _("Add &files...\tInsert"), 00261 wxBitmap(hi16_action_fileadd_xpm), 00262 _("Add files to the checksum file.")); 00263 // Sums->Add directories item 00264 addMenuItemWithBitmap(mnuSums, ITM_SUMS_ADDDIRECTORIES, _("Add &directories...\tCtrl+D"), 00265 wxBitmap(hi16_action_directoryadd_xpm), 00266 _("Add directories to the checksum file.")); 00267 // Sums->Add Add matching files item 00268 addMenuItemWithBitmap(mnuSums, ITM_SUMS_ADDMATCHINGFILES, _("Add &matching files...\tShift+Insert"), 00269 wxBitmap(hi16_action_addmatchingfiles_xpm), 00270 _("Select some files from a matching pattern and add them to the to the checksum file.")); 00271 // Sums->Add files item 00272 addMenuItemWithBitmap(mnuSums, ITM_SUMS_REMOVE, _("&Remove\tDelete"), 00273 wxBitmap(hi16_action_fileremove_xpm), 00274 _("Remove the selected checksums from the checksum file.")); 00275 // A separator 00276 mnuSums->AppendSeparator(); 00277 // Sums->Check item 00278 addMenuItemWithBitmap(mnuSums, ITM_SUMS_CHECK, _("&Check\tCtrl+C"), 00279 wxBitmap(hi16_action_check_xpm), 00280 _("Checks the selected files or all files if none is selected.")); 00281 // Sums->Recompute item 00282 addMenuItemWithBitmap(mnuSums, ITM_SUMS_RECOMPUTE, _("Re&compute\tCtrl+R"), 00283 wxBitmap(hi16_action_recompute_xpm), 00284 _("Recompute the checksums of the selected files.")); 00285 // A separator 00286 mnuSums->AppendSeparator(); 00287 // Sums->Sort by iter 00288 wxMenu* mnuSortBy = new wxMenu(wxMENU_TEAROFF); 00289 mnuSortBy->AppendRadioItem(ITM_SUMS_SORTBY_FILENAME, _("File &name"), _("Sort the checksums' list by file name.")); 00290 mnuSortBy->AppendRadioItem(ITM_SUMS_SORTBY_DIRECTORY, _("&Directory"), _("Sort the checksums' list by directory.")); 00291 mnuSortBy->AppendRadioItem(ITM_SUMS_SORTBY_CHECKSUMVALUE, _("Checksum &value"), _("Sort the checksums' list by value.")); 00292 mnuSortBy->AppendRadioItem(ITM_SUMS_SORTBY_STATE, _("&State"), _("Sort the checksums' list by state.")); 00293 #if defined(__WXGTK__) 00294 // This solves a problem with the radio item groups 00295 mnuSortBy->Append(ITM_SUMS_SORTBY_SEPARATOR1, wxEmptyString, wxEmptyString, wxITEM_SEPARATOR); 00296 #else 00297 mnuSortBy->AppendSeparator(); 00298 #endif // defined(__WXGTK__) 00299 mnuSortBy->AppendRadioItem(ITM_SUMS_SORTBY_ASCENDING, _("&Ascending order"), _("Sort the checksums' list in ascending order.")); 00300 mnuSortBy->AppendRadioItem(ITM_SUMS_SORTBY_DESCENDING, _("D&escending order"), _("Sort the checksums' list in descending order.")); 00301 mnuSortBy->AppendRadioItem(ITM_SUMS_SORTBY_NONE, _("D&on't sort"), _("Don't sort the checksums' list.")); 00302 mnuSums->Append(ITM_SUMS_SORTBY, _("&Sort by"), mnuSortBy); 00303 // Sums->Select all item 00304 mnuSums->Append(ITM_SUMS_SELECTALL, _("Select &all\tCtrl+A"), _("Selects all the files.")); 00305 // Sums->Invert the selection item 00306 mnuSums->Append(ITM_SUMS_INVERTSELECTION, _("&Invert selection\tCtrl+I"), _("Selects non-selected files and deselects selected files.")); 00307 00308 // Menu "Tools" 00309 wxMenu* mnuTools = new wxMenu(wxMENU_TEAROFF); 00310 menuBar->Append(mnuTools, _("&Tools")); 00311 mnuTools->Append(ITM_TOOLS_CHECK_MULTIPLE, _("Check &multiple checksums' files...\tCtrl+M"), _("Checks several checksums' files at the same time.")); 00312 mnuTools->Append(ITM_TOOLS_BATCH_CREATION, _("&Batch creation of checksums' files...\tCtrl+B"), _("Creates one checksums' file for each file selected in the following dialog.")); 00313 mnuTools->AppendSeparator(); 00314 // TODO: find an elegant way to show and hide the toolbar and statusbar 00315 // Tools->Show toolbar 00316 // mnuTools->Append(ITM_TOOLS_SHOW_TOOLBAR, _("Show &toolbar"), _("Shows or hides the toolbar"), wxITEM_CHECK); 00317 // Tools->Show statusbar 00318 // mnuTools->Append(ITM_TOOLS_SHOW_STATUSBAR, _("Show &statusbar"), _("Shows or hides the statusbar"), wxITEM_CHECK); 00319 // A separator 00320 // mnuTools->AppendSeparator(); 00321 // Tools->Configure 00322 addMenuItemWithBitmap(mnuTools, ITM_TOOLS_CONFIGURE, wxString::Format(_("&Configure %s..."), wxT(APP_NAME)), 00323 wxBitmap(hi16_action_configure_xpm), 00324 wxString::Format(_("Sets the parameters of %s."), wxT(APP_NAME))); 00325 00326 // Menu "Help" 00327 wxMenu* mnuHelp = new wxMenu(wxMENU_TEAROFF); 00328 menuBar->Append(mnuHelp, _("&Help")); 00329 // Help->About 00330 addMenuItemWithBitmap(mnuHelp, ITM_HELP_ABOUT, wxString::Format(_("&About %s..."), wxT(APP_NAME)), 00331 wxBitmap(hi16_action_helpabout_xpm), 00332 wxString::Format(_("Displays information about %s."), wxT(APP_NAME))); 00333 00334 00335 // Creates the tools bar 00336 createToolbar(); 00337 00338 // Creates the list 00339 long lvwSumsStyle = wxLC_REPORT; 00340 if (AppPrefs::get()->readBool(prGUI_MAIN_SUMS_HRULES)) 00341 lvwSumsStyle |= wxLC_HRULES; 00342 if (AppPrefs::get()->readBool(prGUI_MAIN_SUMS_VRULES)) 00343 lvwSumsStyle |= wxLC_VRULES; 00344 lvwSums = new ChecksumsListView(this, LVW_SUMS, NULL, wxDefaultPosition, 00345 wxDefaultSize, lvwSumsStyle); 00346 00347 //------------------------------------------------------------------------- 00348 // Creates the frame sizer 00349 00350 // Frame sizer 00351 wxBoxSizer* frmSumsSizer = new wxBoxSizer(wxVERTICAL); 00352 frmSumsSizer->Add(lvwSums, 1, wxALL | wxGROW, 0); 00353 this->SetSizer(frmSumsSizer); 00354 00355 // Set on the auto-layout feature 00356 this->SetAutoLayout(true); 00357 this->Layout(); 00358 00359 // Sets the background color 00360 //this->SetBackgroundColour(a_control->GetBackgroundColour()); 00361 00362 // Init some controls 00363 // This frame title 00364 updateTitle(); 00365 // Position and size of the main window. 00366 wxRect r = AppPrefs::getDefaultMainWindowRect(); 00367 wxPoint p; 00368 wxSize s; 00369 00370 if (AppPrefs::get()->readBool(prGUI_MAIN_SAVE_WINDOW_POSITION)) 00371 p = AppPrefs::get()->readPoint(prGUI_MAIN_WINDOW_POSITION); 00372 else 00373 p = wxPoint(r.GetX(), r.GetY()); 00374 this->Move(p); 00375 00376 if (AppPrefs::get()->readBool(prGUI_MAIN_SAVE_WINDOW_SIZE)) 00377 s = AppPrefs::get()->readSize(prGUI_MAIN_WINDOW_SIZE); 00378 else 00379 s = wxSize(r.GetWidth(), r.GetHeight()); 00380 this->SetSize(s); 00381 00382 // Init the checkables menus 00383 mnuTools->Check(ITM_TOOLS_SHOW_TOOLBAR, AppPrefs::get()->readBool(prGUI_MAIN_SHOW_TOOLBAR)); 00384 tlbTools->Show(AppPrefs::get()->readBool(prGUI_MAIN_SHOW_TOOLBAR)); 00385 mnuTools->Check(ITM_TOOLS_SHOW_STATUSBAR, AppPrefs::get()->readBool(prGUI_MAIN_SHOW_STATUSBAR)); 00386 stbStatus->Show(AppPrefs::get()->readBool(prGUI_MAIN_SHOW_STATUSBAR)); 00387 00388 // Sets the checksums list defaults 00389 lvwSums->SetColumnWidth(0, AppPrefs::get()->readLong(prGUI_MAIN_SUMS_COL_FILENAME_WIDTH)); 00390 lvwSums->SetColumnWidth(1, AppPrefs::get()->readLong(prGUI_MAIN_SUMS_COL_DIRECTORY_WIDTH)); 00391 lvwSums->SetColumnWidth(2, AppPrefs::get()->readLong(prGUI_MAIN_SUMS_COL_CHECKSUM_WIDTH)); 00392 lvwSums->SetColumnWidth(3, AppPrefs::get()->readLong(prGUI_MAIN_SUMS_COL_STATE_WIDTH)); 00393 ChecksumsListView::Columns cols[LVW_SUMS_NBCOLS]; 00394 cols[0] = static_cast<ChecksumsListView::Columns>(AppPrefs::get()->readLong(prGUI_MAIN_SUMS_COL_FIRST)); 00395 cols[1] = static_cast<ChecksumsListView::Columns>(AppPrefs::get()->readLong(prGUI_MAIN_SUMS_COL_SECOND)); 00396 cols[2] = static_cast<ChecksumsListView::Columns>(AppPrefs::get()->readLong(prGUI_MAIN_SUMS_COL_THIRD)); 00397 cols[3] = static_cast<ChecksumsListView::Columns>(AppPrefs::get()->readLong(prGUI_MAIN_SUMS_COL_FOURTH)); 00398 lvwSums->setColumns(cols); 00399 00400 // Sets the column to short and the column order 00401 lvwSums->setColumnToSort(static_cast<int>(AppPrefs::get()->readLong(prGUI_MAIN_SUMS_COLUMNTOSORT)), static_cast<ChecksumsListView::SortOrder>(AppPrefs::get()->readLong(prGUI_MAIN_SUMS_COLUMNSORTORDER))); 00402 itmSumsSortByUpdate(); 00403 00404 // Reads the recently open files. 00405 initializeOpenRecent(); 00406 } 00407 //--------------------------------------------------------------------------- 00408 00409 00410 /** 00411 * Creates the tools bar. 00412 */ 00413 void frmSums::createToolbar() 00414 { 00415 tlbTools = CreateToolBar(/*wxNO_BORDER |*/ wxHORIZONTAL | wxTB_FLAT | wxTB_DOCKABLE); 00416 tlbTools->SetToolBitmapSize(wxSize(TOOL_BITMAP_SIZE, TOOL_BITMAP_SIZE)); 00417 tlbTools->AddTool(ITM_FILE_NEW, _("New"), wxBitmap(hi22_action_filenew_xpm), wxNullBitmap, 00418 wxITEM_NORMAL, _("New"), _("Creates a new checksum file.")); 00419 tlbTools->AddTool(ITM_FILE_OPEN, _("Open"), wxBitmap(hi22_action_fileopen_xpm), wxNullBitmap, 00420 wxITEM_NORMAL, _("Open"), _("Opens a checksum file.")); 00421 tlbTools->AddTool(ITM_FILE_SAVE, _("Save"), wxBitmap(hi22_action_filesave_xpm), wxNullBitmap, 00422 wxITEM_NORMAL, _("Save"), _("Saves the checksum file.")); 00423 tlbTools->AddSeparator(); 00424 tlbTools->AddTool(ITM_SUMS_ADDFILES, _("Add files"), wxBitmap(hi22_action_fileadd_xpm), wxNullBitmap, 00425 wxITEM_NORMAL, _("Add files"), _("Add files to the checksum file.")); 00426 tlbTools->AddTool(ITM_SUMS_ADDDIRECTORIES, _("Add directories"), wxBitmap(hi22_action_directoryadd_xpm), wxNullBitmap, 00427 wxITEM_NORMAL, _("Add directories"), _("Add directories to the checksum file.")); 00428 tlbTools->AddTool(ITM_SUMS_ADDMATCHINGFILES, _("Add matching files"), wxBitmap(hi22_action_addmatchingfiles_xpm), wxNullBitmap, 00429 wxITEM_NORMAL, _("Add matching files"), _("Select some files from a matching pattern and add them to the to the checksum file.")); 00430 tlbTools->AddTool(ITM_SUMS_REMOVE, _("Remove checksums"), wxBitmap(hi22_action_fileremove_xpm), wxNullBitmap, 00431 wxITEM_NORMAL, _("Remove checksums"), _("Remove the selected checksums from the checksum file.")); 00432 tlbTools->AddSeparator(); 00433 tlbTools->AddTool(ITM_SUMS_CHECK, _("Check"), wxBitmap(hi22_action_check_xpm), wxNullBitmap, 00434 wxITEM_NORMAL, _("Check files"), _("Checks the selected files or all files if none is selected.")); 00435 tlbTools->AddTool(ITM_SUMS_RECOMPUTE, _("Recompute"), wxBitmap(hi22_action_recompute_xpm), wxNullBitmap, 00436 wxITEM_NORMAL, _("Recompute checksums"), _("Recompute the checksums of the selected files.")); 00437 tlbTools->AddSeparator(); 00438 tlbTools->AddTool(ITM_TOOLS_CONFIGURE, _("Configure"), wxBitmap(hi22_action_configure_xpm), wxNullBitmap, 00439 wxITEM_NORMAL, wxString::Format(_("Configure %s"), wxT(APP_NAME)), wxString::Format(_("Sets the parameters of %s."), wxT(APP_NAME))); 00440 tlbTools->Realize(); 00441 } 00442 //--------------------------------------------------------------------------- 00443 00444 00445 /** 00446 * Creates the status bar. 00447 */ 00448 void frmSums::createStatusbar() 00449 { 00450 int statusWidths[2]; 00451 00452 // Creates the status bar 00453 stbStatus = CreateStatusBar(1, wxST_SIZEGRIP, STB_STATUS); 00454 stbStatus->SetStatusText(_("Welcome")); 00455 00456 // Sets columns widths 00457 statusWidths[0] = -1; 00458 wxClientDC dc(stbStatus); 00459 statusWidths[1] = dc.GetCharWidth() * 6; 00460 stbStatus->SetFieldsCount(2, statusWidths); 00461 } 00462 //--------------------------------------------------------------------------- 00463 00464 00465 /** 00466 * The class descructor. 00467 */ 00468 frmSums::~frmSums() 00469 { 00470 } 00471 //--------------------------------------------------------------------------- 00472 00473 00474 /** 00475 * Initializes some parameters from the command line. 00476 * 00477 * Open a file if one has been given in the command line. 00478 * 00479 * @param error An error has occured during the initialisation from the 00480 * command line parameters. 00481 * @param warning A warning has occured during the initialisation from the 00482 * command line parameters. 00483 */ 00484 void frmSums::initializeFromCmdLine(bool& error, bool& warning) 00485 { 00486 bool cont = true; // continue 00487 error = false; // no error has occured 00488 warning = false; // no warning has occured 00489 00490 if (CmdLineOptions::action == CmdLineOptions::aOpen || 00491 CmdLineOptions::action == CmdLineOptions::aVerify) 00492 { 00493 // Existance of CmdLineOptions::files[0] should be verified by 00494 // CmdLineOptions::init(). CmdLineOptions::files[0] is a absolute path. 00495 if (lvwSums->openChecksumFile(CmdLineOptions::files[0])) 00496 { 00497 // Check the file ? 00498 if (CmdLineOptions::action == CmdLineOptions::aVerify && 00499 !AppPrefs::get()->readBool(prGUI_AUTO_CHECK_ON_OPEN)) 00500 lvwSums->check(); 00501 } 00502 else // The checksums' file can't be opened. 00503 error = true; 00504 } 00505 00506 if (CmdLineOptions::action == CmdLineOptions::aCreate || 00507 CmdLineOptions::action == CmdLineOptions::aAppend) 00508 { 00509 SumFile* sf = NULL; 00510 00511 // Checks that the checksums file is not a directory. 00512 if (::wxDirExists(CmdLineOptions::checksumsFileName)) 00513 { 00514 if (::wxMessageBox(wxString::Format(_("'%s' is a directory.\nThe checksums' file will be not be saved.\nDo you want to continue?"), CmdLineOptions::checksumsFileName.c_str()), wxString::Format(_("Error - %s"), wxT(APP_NAME)), wxYES_NO | wxICON_EXCLAMATION, this) == wxNO) 00515 cont = false; 00516 else 00517 error = true; 00518 } 00519 00520 if (cont && CmdLineOptions::action == CmdLineOptions::aAppend) 00521 { 00522 // Try to open the file. 00523 sf = ::openChecksumFile(CmdLineOptions::checksumsFileName); 00524 if (sf == NULL && wxFileName::FileExists(CmdLineOptions::checksumsFileName)) 00525 { 00526 if (::wxMessageBox(wxString::Format(_("'%s' exists but its format is unknown.\nDo you want to create a new checksums' file with this name and overwrite the existing file?"), CmdLineOptions::checksumsFileName.c_str()), wxString::Format(_("Warning - %s"), wxT(APP_NAME)), wxYES_NO | wxICON_EXCLAMATION, this) == wxNO) 00527 cont = false; 00528 } 00529 } 00530 00531 if (cont && sf == NULL) 00532 { 00533 // Create a new file. 00534 switch (CmdLineOptions::getchecksumsFileType()) 00535 { 00536 case CmdLineOptions::cftMD5 : sf = new MD5File(); break; 00537 case CmdLineOptions::cftSFV : 00538 default : // By default create an SFV checksums' file. 00539 sf = new SFVFile(); break; 00540 } 00541 } 00542 00543 if (cont) 00544 { 00545 // Sets the checksums' file informations 00546 sf->setFileName(CmdLineOptions::checksumsFileName); 00547 lvwSums->setSumFile(sf); 00548 00549 // Adds the files to the checksums' file 00550 lvwSums->addFiles(CmdLineOptions::files); 00551 this->updateTitle(); 00552 lvwSums->reformat(); 00553 00554 // Try to save the file 00555 if (!::wxDirExists(CmdLineOptions::checksumsFileName) && 00556 lvwSums->getSumFile()->write(CmdLineOptions::checksumsFileName)) 00557 { 00558 this->updateTitle(); 00559 lvwSums->reformat(); 00560 addFileNameToOpenRecent(CmdLineOptions::checksumsFileName); 00561 } 00562 else // an error has occured 00563 { 00564 error = true; 00565 ::wxMessageBox(_("An error has occurred during the save process of the file."), 00566 wxString::Format(_("Error - %s"), wxT(APP_NAME)), 00567 wxOK | wxICON_ERROR, this); 00568 if ((CmdLineOptions::action == CmdLineOptions::aCreate && 00569 static_cast<DisplayGUI>(AppPrefs::get()->readLong(prGUI_CLN_CREATE_SHOW_GUI)) == clgNever) || 00570 (CmdLineOptions::action == CmdLineOptions::aAppend && 00571 static_cast<DisplayGUI>(AppPrefs::get()->readLong(prGUI_CLN_APPEND_SHOW_GUI)) == clgNever)) 00572 // The user doesn't want to see the GUI, we say that the checksums' 00573 // file is not modified so the FrameClose method won't ask to save the 00574 // checksums' file. 00575 lvwSums->getSumFile()->setModified(false); 00576 } 00577 } 00578 } 00579 } 00580 //--------------------------------------------------------------------------- 00581 00582 00583 /** 00584 * Checks if the window should be closed after initialisation from the command 00585 * line. 00586 * 00587 * @param error An error has occured during the initialisation from the 00588 * command line parameters. 00589 * @param warning A warning has occured during the initialisation from the 00590 * command line parameters. 00591 * @return <CODE>true</CODE> if the window should be closed immediatly, 00592 * <CODE>false</CODE> otherwise. 00593 */ 00594 bool frmSums::closeAfterInitFromCmdLine(bool error, bool warning) 00595 { 00596 bool close = false; 00597 00598 if (CmdLineOptions::action == CmdLineOptions::aVerify) 00599 if (AppPrefs::get()->readBool(prGUI_CLN_VERIFY_DONT_SHOW_GUI)) 00600 if (error || warning) 00601 // If an error or a warning has occured, close the window 00602 close = true; 00603 else // if all the checksums are correct, close the window 00604 { 00605 wxArrayInt states = lvwSums->getStates(false); 00606 close = (states.GetCount() > ChecksumData::Verified && 00607 states[ChecksumData::Verified] == lvwSums->GetItemCount()); 00608 } 00609 00610 if (CmdLineOptions::action == CmdLineOptions::aCreate || 00611 CmdLineOptions::action == CmdLineOptions::aAppend) 00612 { 00613 DisplayGUI dispOn = static_cast<DisplayGUI>(AppPrefs::get()->readLong((CmdLineOptions::action == CmdLineOptions::aAppend) ? prGUI_CLN_APPEND_SHOW_GUI : prGUI_CLN_CREATE_SHOW_GUI)); 00614 close = ((dispOn == clgNever) || 00615 (dispOn == clgOnError && !error) || 00616 (dispOn == clgOnWarning && !error && !warning)); 00617 } 00618 00619 return close; 00620 } 00621 //--------------------------------------------------------------------------- 00622 00623 00624 /** 00625 * Sets the frame title. 00626 */ 00627 void frmSums::updateTitle() 00628 { 00629 wxString title; 00630 00631 if (lvwSums->getSumFile() != NULL) 00632 { 00633 wxFileName fn = lvwSums->getSumFile()->getFileName(); 00634 title += fn.GetFullName() + wxT(' '); 00635 if (lvwSums->getSumFile()->getModified()) 00636 title += _("(Modified) "); 00637 title += wxT("- ") + fn.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR); 00638 title += wxT(" - "); 00639 00640 // Set the file type in the status bar. 00641 stbStatus->SetStatusText(lvwSums->getSumFile()->getFileType(), 1); 00642 } 00643 else 00644 stbStatus->SetStatusText(wxString(), 1); 00645 00646 title += wxT(APP_NAME); 00647 SetTitle(title); 00648 00649 } 00650 //--------------------------------------------------------------------------- 00651 00652 00653 /** 00654 * Saves the current ckecksums file. 00655 * 00656 * @param fileName Name of the file where the checksums will be saved. 00657 * <CODE>fileName</CODE> must have an absolute path (not 00658 * verified by this function). 00659 * @return <CODE>true</CODE> if the file has been saved successfully in 00660 * <CODE>fileName</CODE>, <CODE>false</CODE> otherwise. 00661 */ 00662 bool frmSums::saveChecksumFile(const wxString& fileName) 00663 { 00664 if (lvwSums->getSumFile() != NULL) 00665 { 00666 // Check if all the state of the checksums are 'valid' 00667 if (AppPrefs::get()->readBool(prGUI_WARN_ON_INVALID_WHEN_SAVING)) 00668 { 00669 wxArrayInt states = lvwSums->getStates(false); 00670 if (states[ChecksumData::Verified] != lvwSums->GetItemCount()) 00671 if (::wxMessageBox(_("Some checksums are not valid.\nDo you really wish to save this checksums file?"), 00672 wxString::Format(_("Warning - %s"), wxT(APP_NAME)), 00673 wxYES_NO | wxCANCEL | wxICON_EXCLAMATION, this) != wxYES) 00674 // Don't save 00675 return false; 00676 } 00677 00678 // Try to save the file 00679 if (lvwSums->getSumFile()->write(fileName)) 00680 { 00681 this->updateTitle(); 00682 lvwSums->reformat(); 00683 addFileNameToOpenRecent(fileName); 00684 return true; 00685 } 00686 else // an error has occured 00687 { 00688 ::wxMessageBox(_("An error has occurred during the save process of the file."), 00689 wxString::Format(_("Error - %s"), wxT(APP_NAME)), 00690 wxOK | wxICON_ERROR, this); 00691 return false; 00692 } 00693 } 00694 else 00695 return false; 00696 } 00697 //--------------------------------------------------------------------------- 00698 00699 00700 /** 00701 * Checks if the current checksums' file has been saved before closing it. 00702 * 00703 * @return <UL> 00704 * <LI><CODE>wxYES</CODE> if the file wasn't modified or if the 00705 * file has been saved successfully.</LI> 00706 * <LI><CODE>wxNO</CODE> if the user doesn't want to save the file. 00707 * <LI><CODE>wxCANCEL</CODE> if the user want to cancel the process 00708 * (ex: closing the file, creating a new file, opening another 00709 * file).</LI></UL> 00710 */ 00711 int frmSums::checkFileBeforeClose() 00712 { 00713 int res = wxYES; 00714 00715 if (lvwSums->getSumFile() != NULL) 00716 { 00717 if (lvwSums->getSumFile()->getModified()) 00718 { 00719 bool askForSave = true; // ask the user for saving the file 00720 while (askForSave) 00721 { 00722 askForSave = false; 00723 switch (::wxMessageBox(_("This checksum file has been modified.\nWould you like to save it?"), 00724 wxString::Format(_("Warning - %s"), wxT(APP_NAME)), 00725 wxYES_NO | wxCANCEL | wxICON_EXCLAMATION, this)) 00726 { 00727 case wxYES : 00728 if (saveChecksumFile(lvwSums->getSumFile()->getFileName())) 00729 res = wxYES; 00730 else // save has failed, re-ask to the user what to do... 00731 askForSave = true; 00732 break; 00733 case wxNO : // don't save the file and close 00734 res = wxNO; 00735 break; 00736 default : // wxCANCEL 00737 res = wxCANCEL; 00738 } 00739 } 00740 } 00741 } 00742 00743 return res; 00744 } 00745 //--------------------------------------------------------------------------- 00746 00747 00748 /** 00749 * Initializes the open recent files. 00750 * 00751 * Loads the list from the preferences file and add the entries to the menu. 00752 */ 00753 void frmSums::initializeOpenRecent() 00754 { 00755 wxString s; 00756 int l = getOpenRecentHistoryMaxSize(); 00757 for (int i = l - 1; i >= 0; i--) 00758 { 00759 wxConfig::Get()->Read(getOpenRecentConfigKey(i), &s, wxEmptyString); 00760 if (!s.empty()) 00761 addFileNameToOpenRecent(s); 00762 } 00763 } 00764 //--------------------------------------------------------------------------- 00765 00766 00767 /** 00768 * Adds a name of file to the open recent submenu. 00769 * 00770 * If the file is already in the list it is moved on the first position. 00771 * If the list is full, the most older entry is erased. 00772 * 00773 * @param fileName Name of the file to be added is the list of files recently 00774 * opened. 00775 */ 00776 void frmSums::addFileNameToOpenRecent(const wxString& fileName) 00777 { 00778 size_t i, j; 00779 00780 // Checks if the file name is already present in the list. 00781 bool found = false; 00782 i = 0; 00783 while (!found && i < openRecent.GetCount()) 00784 if (::compareFileName(openRecent[i], fileName) == 0) 00785 found = true; 00786 else 00787 i++; 00788 00789 if (found && i == 0) 00790 // The file is already present and is in first position. No need to do nothing. 00791 return; 00792 00793 if (found) 00794 // Move the file name to the first position. 00795 for (j = i; j > 0; j--) 00796 openRecent[j] = openRecent[j - 1]; 00797 else // add the name of the file on the first item 00798 { 00799 // Check if a new menu entry can be created. 00800 if (static_cast<int>(openRecent.GetCount()) < getOpenRecentHistoryMaxSize()) 00801 openRecent.Add(wxEmptyString); 00802 for (j = openRecent.GetCount() - 1; j > 0; j--) 00803 openRecent[j] = openRecent[j - 1]; 00804 } 00805 openRecent[0] = fileName; 00806 00807 // Refresh the menu entries 00808 int lastItem = ITM_FILE_OPENRECENT1 + mnuOpenRecent->GetMenuItemCount(); 00809 int curItem = ITM_FILE_OPENRECENT1; 00810 for (i = 0; i < openRecent.GetCount(); i++) 00811 { 00812 if (curItem >= lastItem) 00813 // Create a menu item 00814 { 00815 mnuOpenRecent->Append(lastItem, openRecent[i], _("Open this checksums' file.")); 00816 lastItem++; 00817 } 00818 else 00819 mnuOpenRecent->SetLabel(curItem, openRecent[i]); 00820 curItem++; 00821 } 00822 } 00823 //--------------------------------------------------------------------------- 00824 00825 00826 /** 00827 * Gets the name of the file corresponding to the given identifier. 00828 * 00829 * @param id Idenfier of the menu that contain the file name. 00830 * @return The name of the file corresponding to the given identifier or an 00831 * empty string if the identifier is invalid. 00832 */ 00833 wxString frmSums::getOpenRecentFileName(const int id) 00834 { 00835 wxString res; 00836 if (id - ITM_FILE_OPENRECENT1 < static_cast<int>(openRecent.GetCount())) 00837 res = openRecent[id - ITM_FILE_OPENRECENT1]; 00838 00839 return res; 00840 } 00841 //--------------------------------------------------------------------------- 00842 00843 00844 /** 00845 * Gets the configuration key for the last files' names open recently. 00846 * 00847 * @param n The nth history configuration key to get. 00848 * @return The configuration key for the last files' names open recently or 00849 * an empty string if <CODE>n >= getOpenRecentHistoryMaxSize()</CODE>. 00850 */ 00851 wxString frmSums::getOpenRecentConfigKey(const int n) 00852 { 00853 wxString res; 00854 if (n >= 0 && n < getOpenRecentHistoryMaxSize()) 00855 res = wxString::Format(wxT("GUI/Main/History/File%02d"), n); 00856 00857 return res; 00858 } 00859 //--------------------------------------------------------------------------- 00860 00861 00862 /** 00863 * Gets the number of maximal files in the open recent history. 00864 * 00865 * @return The number of maximal files in the open recent history. 00866 */ 00867 inline int frmSums::getOpenRecentHistoryMaxSize() 00868 { 00869 return 16; 00870 } 00871 //--------------------------------------------------------------------------- 00872 00873 00874 /** 00875 * Processes menu File->New. 00876 * 00877 * @param event The event's parameters 00878 */ 00879 void frmSums::itmFileNewClick(wxCommandEvent& event) 00880 { 00881 int res = this->checkFileBeforeClose(); 00882 00883 if (res == wxYES || res == wxNO) 00884 { 00885 dlgNewFile dlg(this); 00886 if (dlg.ShowModal() == wxID_OK) 00887 { 00888 // Creates a new file 00889 SumFile* f; 00890 switch (dlg.getFileType()) 00891 { 00892 case dlgNewFile::ftSFV : f = new SFVFile(); break; 00893 case dlgNewFile::ftMD5 : f = new MD5File(); break; 00894 } 00895 00896 f->setFileName(dlg.getFileName()); 00897 lvwSums->setSumFile(f); 00898 updateTitle(); 00899 00900 // Save the last directory and last file type 00901 AppPrefs::get()->write(prGUI_NEWFILE_LAST_DIRECTORY, wxFileName(dlg.getFileName()).GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR)); 00902 AppPrefs::get()->write(prGUI_NEWFILE_LAST_FILETYPE, static_cast<long>(dlg.getFileType())); 00903 } 00904 } 00905 } 00906 //--------------------------------------------------------------------------- 00907 00908 00909 /** 00910 * Processes menu File->Open. 00911 * 00912 * @param event The event's parameters 00913 */ 00914 void frmSums::itmFileOpenClick(wxCommandEvent& event) 00915 { 00916 int res = this->checkFileBeforeClose(); 00917 00918 if (res == wxYES || res == wxNO) 00919 { 00920 wxLogNull logNo; // No log 00921 00922 // Gets the filter for knows types of checksums' files 00923 wxFileDialogFilterMaker fltMaker = ::getFilterForKnownTypesOfChecksumsFiles(); 00924 00925 // Show the open dialog 00926 wxFileDialog dlgOpen(this, _("Select the checksums file"), 00927 wxEmptyString, wxEmptyString, fltMaker.GetFilters(), 00928 wxOPEN | wxFILE_MUST_EXIST, wxDefaultPosition); 00929 wxString direct = AppPrefs::get()->readString(prGUI_MAIN_LAST_DIRECTORY); 00930 if (wxFileName::DirExists(direct)) 00931 dlgOpen.SetDirectory(direct); 00932 00933 if (dlgOpen.ShowModal() == wxID_OK) 00934 { 00935 AppPrefs::get()->write(prGUI_MAIN_LAST_DIRECTORY, dlgOpen.GetDirectory()); 00936 00937 lvwSums->openChecksumFile(dlgOpen.GetPath()); 00938 } 00939 } 00940 } 00941 //--------------------------------------------------------------------------- 00942 00943 00944 /** 00945 * Processes menu File->Open recent. 00946 * 00947 * @param event The event's parameters 00948 */ 00949 void frmSums::itmFileOpenRecentClick(wxCommandEvent& event) 00950 { 00951 wxString fileName = getOpenRecentFileName(event.GetId()); 00952 00953 if (lvwSums->getSumFile() != NULL) 00954 if (::compareFileName(lvwSums->getSumFile()->getFileName(), fileName) == 0) 00955 if (::wxMessageBox(wxString::Format(_("'%s' is already opened.\nDo you want to reopen it?"), fileName.c_str()), 00956 wxString::Format(_("Warning - %s"), wxT(APP_NAME)), 00957 wxYES_NO | wxICON_EXCLAMATION, this) == wxNO) 00958 // Dont reopen the file. 00959 return; 00960 00961 int res = this->checkFileBeforeClose(); 00962 00963 if (res == wxYES || res == wxNO) 00964 lvwSums->openChecksumFile(fileName); 00965 } 00966 //--------------------------------------------------------------------------- 00967 00968 00969 /** 00970 * Processes menu File->Save. 00971 * 00972 * @param event The event's parameters 00973 */ 00974 void frmSums::itmFileSaveClick(wxCommandEvent& event) 00975 { 00976 if (lvwSums->getSumFile() != NULL) 00977 if (lvwSums->getSumFile()->getModified()) 00978 this->saveChecksumFile(lvwSums->getSumFile()->getFileName()); 00979 } 00980 //--------------------------------------------------------------------------- 00981 00982 00983 /** 00984 * Processes menu File->Save as. 00985 * 00986 * @param event The event's parameters 00987 */ 00988 void frmSums::itmFileSaveAsClick(wxCommandEvent& event) 00989 { 00990 if (lvwSums->getSumFile() != NULL) 00991 { 00992 wxLogNull logNo; // No log 00993 00994 // Gets the filter for knows types of checksums' files 00995 wxFileDialogFilterMaker fltMaker = ::getFilterForKnownTypesOfChecksumsFiles(); 00996 00997 // Show the save as dialog 00998 wxFileDialog dlgSave(this, _("Save the checksums file as"), 00999 wxEmptyString, wxEmptyString, fltMaker.GetFilters(), 01000 wxSAVE | wxOVERWRITE_PROMPT, wxDefaultPosition); 01001 wxString direct = AppPrefs::get()->readString(prGUI_MAIN_LAST_DIRECTORY); 01002 if (wxFileName::DirExists(direct)) 01003 dlgSave.SetDirectory(direct); 01004 01005 int filterIdx = 0; 01006 int i = 0; 01007 while (filterIdx == 0 && i < SumFileFactory::getSumFilesCount()) 01008 if (lvwSums->getSumFile()->getFileType().CmpNoCase(SumFileFactory::getSumFileName(i)) == 0) 01009 filterIdx = i + 1; 01010 else 01011 i++; 01012 dlgSave.SetFilterIndex(filterIdx); 01013 01014 if (dlgSave.ShowModal() == wxID_OK) 01015 { 01016 AppPrefs::get()->write(prGUI_MAIN_LAST_DIRECTORY, dlgSave.GetDirectory()); 01017 01018 if (this->saveChecksumFile(dlgSave.GetPath())) 01019 updateTitle(); 01020 } 01021 } 01022 } 01023 //--------------------------------------------------------------------------- 01024 01025 01026 /** 01027 * Processes menu File->Close. 01028 * 01029 * @param event The event's parameters 01030 */ 01031 void frmSums::itmFileCloseClick(wxCommandEvent& event) 01032 { 01033 if (lvwSums->getSumFile() != NULL) 01034 { 01035 int res = this->checkFileBeforeClose(); 01036 01037 if (res == wxYES || res == wxNO) 01038 lvwSums->setSumFile(NULL); 01039 } 01040 01041 // Update the title bar 01042 this->updateTitle(); 01043 } 01044 //--------------------------------------------------------------------------- 01045 01046 01047 /** 01048 * Processes menu File->Quit. 01049 * 01050 * @param event The event's parameters 01051 */ 01052 void frmSums::itmFileQuitClick(wxCommandEvent& event) 01053 { 01054 Close(); 01055 } 01056 //--------------------------------------------------------------------------- 01057 01058 01059 /** 01060 * Processes menu Sums->Add files... 01061 * 01062 * @param event The event's parameters 01063 */ 01064 void frmSums::itmSumsAddFilesClick(wxCommandEvent& event) 01065 { 01066 lvwSums->selectFilesToAdd(); 01067 updateTitle(); 01068 } 01069 //--------------------------------------------------------------------------- 01070 01071 01072 /** 01073 * Processes menu Sums->Add directories... 01074 * 01075 * @param event The event's parameters 01076 */ 01077 void frmSums::itmSumsAddDirectoriesClick(wxCommandEvent& event) 01078 { 01079 lvwSums->selectDirectoriesToAdd(); 01080 updateTitle(); 01081 } 01082 //--------------------------------------------------------------------------- 01083 01084 01085 /** 01086 * Processes menu Sums->Add directories... 01087 * 01088 * @param event The event's parameters 01089 */ 01090 void frmSums::itmSumsAddMatchingFilesClick(wxCommandEvent& event) 01091 { 01092 lvwSums->selectMatchingFilesToAdd(); 01093 updateTitle(); 01094 } 01095 //--------------------------------------------------------------------------- 01096 01097 01098 /** 01099 * Processes menu Sums->Remove... 01100 * 01101 * @param event The event's parameters 01102 */ 01103 void frmSums::itmSumsRemoveClick(wxCommandEvent& event) 01104 { 01105 lvwSums->removeSelectedChecksums(); 01106 updateTitle(); 01107 } 01108 //--------------------------------------------------------------------------- 01109 01110 01111 /** 01112 * Processes menu Sums->Check 01113 * 01114 * @param event The event's parameters 01115 */ 01116 void frmSums::itmSumsCheckClick(wxCommandEvent& event) 01117 { 01118 lvwSums->check(); 01119 updateTitle(); 01120 //SetStatusText(lvwSums->sumUpStates(lvwSums->GetSelectedItemCount() != 0)); 01121 } 01122 //--------------------------------------------------------------------------- 01123 01124 01125 /** 01126 * Processes menu Sums->Recompute 01127 * 01128 * @param event The event's parameters 01129 */ 01130 void frmSums::itmSumsRecomputeClick(wxCommandEvent& event) 01131 { 01132 lvwSums->recompute(); 01133 updateTitle(); 01134 } 01135 //--------------------------------------------------------------------------- 01136 01137 01138 /** 01139 * Processes menu Sums->Sort by... 01140 * 01141 * @param event The event's parameters 01142 */ 01143 void frmSums::itmSumsSortByClick(wxCommandEvent& event) 01144 { 01145 bool changeColumn = false; 01146 ChecksumsListView::Columns colToChange; 01147 01148 switch (event.GetId()) 01149 { 01150 case ITM_SUMS_SORTBY_FILENAME : 01151 colToChange = ChecksumsListView::FILE_NAME; 01152 changeColumn = true; 01153 break; 01154 case ITM_SUMS_SORTBY_DIRECTORY : 01155 colToChange = ChecksumsListView::DIRECTORY; 01156 changeColumn = true; 01157 break; 01158 case ITM_SUMS_SORTBY_CHECKSUMVALUE : 01159 colToChange = ChecksumsListView::CHECKSUM_VALUE; 01160 changeColumn = true; 01161 break; 01162 case ITM_SUMS_SORTBY_STATE : 01163 colToChange = ChecksumsListView::STATE; 01164 changeColumn = true; 01165 break; 01166 case ITM_SUMS_SORTBY_NONE : 01167 lvwSums->setSortOrder(ChecksumsListView::NONE); 01168 break; 01169 case ITM_SUMS_SORTBY_ASCENDING : 01170 lvwSums->setSortOrder(ChecksumsListView::ASCENDING); 01171 break; 01172 case ITM_SUMS_SORTBY_DESCENDING : 01173 lvwSums->setSortOrder(ChecksumsListView::DESCENDING); 01174 break; 01175 } 01176 01177 if (changeColumn) 01178 { 01179 ChecksumsListView::Columns cols[LVW_SUMS_NBCOLS]; 01180 lvwSums->getColumns(cols); 01181 int i = 0; 01182 while (i < LVW_SUMS_NBCOLS) 01183 { 01184 if (cols[i] == colToChange) 01185 lvwSums->setColumnToSort(i); 01186 i++; 01187 } 01188 } 01189 01190 lvwSums->sort(); 01191 } 01192 //--------------------------------------------------------------------------- 01193 01194 01195 /** 01196 * Update the state of the Sort by... submenu. 01197 * 01198 * Checks the menus items corresponding to the new sort order and column. 01199 */ 01200 void frmSums::itmSumsSortByUpdate() 01201 { 01202 wxMenuItem* menuItem = NULL; 01203 01204 // Sort order 01205 switch (lvwSums->getSortOrder()) 01206 { 01207 case ChecksumsListView::NONE : 01208 menuItem = this->GetMenuBar()->FindItem(ITM_SUMS_SORTBY_NONE); 01209 break; 01210 case ChecksumsListView::ASCENDING : 01211 menuItem = this->GetMenuBar()->FindItem(ITM_SUMS_SORTBY_ASCENDING); 01212 break; 01213 case ChecksumsListView::DESCENDING : 01214 menuItem = this->GetMenuBar()->FindItem(ITM_SUMS_SORTBY_DESCENDING); 01215 break; 01216 } 01217 if (menuItem != NULL) 01218 menuItem->Check(true); 01219 01220 // Column to short 01221 menuItem = NULL; 01222 ChecksumsListView::Columns cols[LVW_SUMS_NBCOLS]; 01223 lvwSums->getColumns(cols); 01224 int col = lvwSums->getColumnToSort(); 01225 switch (cols[col]) 01226 { 01227 case ChecksumsListView::FILE_NAME : 01228 menuItem = this->GetMenuBar()->FindItem(ITM_SUMS_SORTBY_FILENAME); 01229 break; 01230 case ChecksumsListView::DIRECTORY : 01231 menuItem = this->GetMenuBar()->FindItem(ITM_SUMS_SORTBY_DIRECTORY); 01232 break; 01233 case ChecksumsListView::CHECKSUM_VALUE : 01234 menuItem = this->GetMenuBar()->FindItem(ITM_SUMS_SORTBY_CHECKSUMVALUE); 01235 break; 01236 case ChecksumsListView::STATE : 01237 menuItem = this->GetMenuBar()->FindItem(ITM_SUMS_SORTBY_STATE); 01238 break; 01239 } 01240 if (menuItem != NULL) 01241 menuItem->Check(true); 01242 } 01243 01244 01245 /** 01246 * Processes menu Sums->Select all 01247 * 01248 * @param event The event's parameters 01249 */ 01250 void frmSums::itmSumsSelectAllClick(wxCommandEvent& event) 01251 { 01252 lvwSums->selectAll(); 01253 } 01254 //--------------------------------------------------------------------------- 01255 01256 01257 /** 01258 * Processes menu Sums->Invert selection 01259 * 01260 * @param event The event's parameters 01261 */ 01262 void frmSums::itmSumsInvertSelectionClick(wxCommandEvent& event) 01263 { 01264 lvwSums->invertSelection(); 01265 } 01266 //--------------------------------------------------------------------------- 01267 01268 01269 /** 01270 * Processes menu Tools->Check multiple checksum's files 01271 * 01272 * @param event The event's parameters 01273 */ 01274 void frmSums::itmToolsCheckMultipleClick(wxCommandEvent& event) 01275 { 01276 wxArrayString files; 01277 01278 { 01279 dlgMultiCheckConf dlgConf(this); 01280 dlgConf.initialize(); 01281 if (dlgConf.ShowModal() == wxID_OK) 01282 dlgConf.getFileNames(files); 01283 } 01284 01285 if (!files.IsEmpty()) 01286 dlgMultiCheck::checkChecksumsFiles(files, this); 01287 } 01288 //--------------------------------------------------------------------------- 01289 01290 01291 /** 01292 * Processes menu Tools->Batch creation of checksums' files 01293 * 01294 * @param event The event's parameters 01295 */ 01296 void frmSums::itmToolsBatchCreationClick(wxCommandEvent& event) 01297 { 01298 wxArrayString files; 01299 wxArrayInt ckFileTypes; 01300 dlgBatchCreation::Options options; 01301 01302 { 01303 dlgBatchCreationConf dlgConf(this); 01304 dlgConf.initialize(); 01305 if (dlgConf.ShowModal() == wxID_OK) 01306 { 01307 dlgConf.getFileNames(files); 01308 ckFileTypes = dlgConf.getChecksumsFileTypeToCreate(); 01309 options = dlgConf.getOptions(); 01310 } 01311 } 01312 01313 if (!files.IsEmpty() && !ckFileTypes.IsEmpty()) 01314 dlgBatchCreation::batchCreation(files, options, ckFileTypes, this); 01315 } 01316 //--------------------------------------------------------------------------- 01317 01318 01319 /** 01320 * Processes menu Tools->Show toolbar 01321 * 01322 * @param event The event's parameters 01323 */ 01324 void frmSums::itmToolsShowToolbarClick(wxCommandEvent& event) 01325 { 01326 tlbTools->Show(event.IsChecked()); 01327 AppPrefs::get()->write(prGUI_MAIN_SHOW_TOOLBAR, event.IsChecked()); 01328 01329 // TODO: find a better way to refresh the frame... ^^;;; 01330 //this->Freeze(); 01331 wxSize s = this->GetSize(); 01332 s.SetWidth(s.GetWidth() + 1); 01333 this->SetSize(s); 01334 s.SetWidth(s.GetWidth() - 1); 01335 this->SetSize(s); 01336 //this->Thaw(); 01337 } 01338 //--------------------------------------------------------------------------- 01339 01340 01341 /** 01342 * Processes menu Tools->Show statusbar 01343 * 01344 * @param event The event's parameters 01345 */ 01346 void frmSums::itmToolsShowStatusbarClick(wxCommandEvent& event) 01347 { 01348 stbStatus->Show(event.IsChecked()); 01349 AppPrefs::get()->write(prGUI_MAIN_SHOW_STATUSBAR, event.IsChecked()); 01350 01351 // TODO: find a better way to refresh the frame... ^^;;; 01352 //this->Freeze(); 01353 wxSize s = this->GetSize(); 01354 s.SetWidth(s.GetWidth() + 1); 01355 this->SetSize(s); 01356 s.SetWidth(s.GetWidth() - 1); 01357 this->SetSize(s); 01358 //this->Thaw(); 01359 } 01360 //--------------------------------------------------------------------------- 01361 01362 01363 /** 01364 * Processes menu Tools->Configure 01365 * 01366 * @param event The event's parameters 01367 */ 01368 void frmSums::itmToolsConfigureClick(wxCommandEvent& event) 01369 { 01370 int i; 01371 ChecksumsListView::Columns cols[LVW_SUMS_NBCOLS]; 01372 lvwSums->getColumns(cols); 01373 01374 dlgConfigure d(this); 01375 for (i = 0; i < LVW_SUMS_NBCOLS; i++) 01376 d.lstSumsHeaders->Append(ChecksumsListView::getColumnName(cols[i]), reinterpret_cast<void*>(cols[i])); 01377 01378 if (d.ShowModal() == wxID_OK) 01379 { 01380 // Save the position of the splitter's sash 01381 AppPrefs::get()->write(prGUI_CONF_SASH_POSITION, static_cast<long>(d.sptConfigure->GetSashPosition())); 01382 01383 // Display tab 01384 AppPrefs::get()->write(prGUI_MAIN_SAVE_WINDOW_POSITION, d.chkWindowSavePosition->GetValue()); 01385 AppPrefs::get()->write(prGUI_MAIN_SAVE_WINDOW_SIZE, d.chkWindowSaveSize->GetValue()); 01386 AppPrefs::get()->write(prGUI_MAIN_SUMS_SAVECOLUMNTOSORT, d.chkSumsSaveColumnToSort->GetValue()); 01387 AppPrefs::get()->write(prGUI_MAIN_SUMS_SAVECOLUMNSWIDTHS, d.chkSumsSaveColumnsWidths->GetValue()); 01388 AppPrefs::get()->write(prGUI_MAIN_SUMS_DIRSINABSOLUTEPATH, d.chkSumsDirInAbsolutePath->GetValue()); 01389 AppPrefs::get()->write(prGUI_MAIN_SUMS_UPPERCASE, d.rbtSumsValuesCaseUpper->GetValue()); 01390 AppPrefs::get()->write(prGUI_MAIN_SUMS_HRULES, d.chkSumsHRules->GetValue()); 01391 AppPrefs::get()->write(prGUI_MAIN_SUMS_VRULES, d.chkSumsVRules->GetValue()); 01392 01393 // Gets the column order 01394 for (i = 0; i < LVW_SUMS_NBCOLS; i++) 01395 cols[i] = static_cast<ChecksumsListView::Columns>(reinterpret_cast<int>(d.lstSumsHeaders->GetClientData(i))); 01396 if (!lvwSums->setColumns(cols)) 01397 lvwSums->reformat(); 01398 01399 // Behavior 01400 AppPrefs::get()->write(prGUI_AUTO_CHECK_ON_OPEN, d.chkAutoCheckOnOpen->GetValue()); 01401 AppPrefs::get()->write(prGUI_DLG_SUMUP_CHECK, d.chkDlgSumUpCheck->GetValue()); 01402 AppPrefs::get()->write(prGUI_WARN_ON_INVALID_WHEN_SAVING, d.chkWarnOnInvalidWhenSaving->GetValue()); 01403 01404 // Language of the application 01405 if (d.lstLanguages->GetSelection() >= 0) 01406 { 01407 Languages languages; 01408 AppPrefs::get()->write(prLANGUAGE_NAME, languages.getLanguageShortName(reinterpret_cast<int>(d.lstLanguages->GetClientData(d.lstLanguages->GetSelection())))); 01409 } 01410 01411 // Command line 01412 AppPrefs::get()->write(prGUI_CLN_VERIFY_DONT_SHOW_GUI, d.chkCLnVerifyDontShowGUI->GetValue()); 01413 // Append option 01414 if (d.rbxCLnAppendNeverShowGUI->GetValue()) 01415 AppPrefs::get()->write(prGUI_CLN_APPEND_SHOW_GUI, static_cast<long>(clgNever)); 01416 else if (d.rbxCLnAppendShowGUIOnError->GetValue()) 01417 AppPrefs::get()->write(prGUI_CLN_APPEND_SHOW_GUI, static_cast<long>(clgOnError)); 01418 else if (d.rbxCLnAppendShowGUIOnWarning->GetValue()) 01419 AppPrefs::get()->write(prGUI_CLN_APPEND_SHOW_GUI, static_cast<long>(clgOnWarning)); 01420 else 01421 AppPrefs::get()->write(prGUI_CLN_APPEND_SHOW_GUI, static_cast<long>(clgAlways)); 01422 // Create option 01423 if (d.rbxCLnCreateNeverShowGUI->GetValue()) 01424 AppPrefs::get()->write(prGUI_CLN_CREATE_SHOW_GUI, static_cast<long>(clgNever)); 01425 else if (d.rbxCLnCreateShowGUIOnError->GetValue()) 01426 AppPrefs::get()->write(prGUI_CLN_CREATE_SHOW_GUI, static_cast<long>(clgOnError)); 01427 else if (d.rbxCLnCreateShowGUIOnWarning->GetValue()) 01428 AppPrefs::get()->write(prGUI_CLN_CREATE_SHOW_GUI, static_cast<long>(clgOnWarning)); 01429 else 01430 AppPrefs::get()->write(prGUI_CLN_CREATE_SHOW_GUI, static_cast<long>(clgAlways)); 01431 01432 // SFV files 01433 if (d.rbxSFVPathSepReadAuto->GetValue()) 01434 AppPrefs::get()->write(prSFV_READ_PATH_SEPARATOR, static_cast<long>(wxPATH_NATIVE)); 01435 else if (d.rbxSFVPathSepReadUnix->GetValue()) 01436 AppPrefs::get()->write(prSFV_READ_PATH_SEPARATOR, static_cast<long>(wxPATH_UNIX)); 01437 else if (d.rbxSFVPathSepReadWindows->GetValue()) 01438 AppPrefs::get()->write(prSFV_READ_PATH_SEPARATOR, static_cast<long>(wxPATH_WIN)); 01439 else 01440 AppPrefs::get()->write(prSFV_READ_PATH_SEPARATOR, static_cast<long>(wxPATH_MAC)); 01441 AppPrefs::get()->write(prSFV_WRITE_GEN_AND_DATE, d.chkSFVSaveGenerator->GetValue()); 01442 // Save the generator identificator 01443 if (d.cboSFVIdentifyAs->GetSelection() == 0) 01444 AppPrefs::get()->write(prSFV_IDENTIFY_AS, wxString()); 01445 else 01446 AppPrefs::get()->write(prSFV_IDENTIFY_AS, d.cboSFVIdentifyAs->GetString(d.cboSFVIdentifyAs->GetSelection())); 01447 // Save the history 01448 for (i = 2; i < d.getSFVGeneratorIdentifierHistoryMaxSize() + 2; i++) // + 2 => two first items are always there 01449 if (i < static_cast<int>(d.cboSFVIdentifyAs->GetCount())) 01450 wxConfig::Get()->Write(d.getSFVGeneratorIdentifierConfigKey(i - 1), d.cboSFVIdentifyAs->GetString(i)); 01451 else 01452 wxConfig::Get()->Write(d.getSFVGeneratorIdentifierConfigKey(i - 1), wxString()); 01453 AppPrefs::get()->write(prSFV_WRITE_FILE_SIZE_AND_DATE, d.chkSFVSaveFilesInfo->GetValue()); 01454 if (d.rbxSFVPathSepWriteSystem->GetValue()) 01455 AppPrefs::get()->write(prSFV_WRITE_PATH_SEPARATOR, static_cast<long>(wxPATH_NATIVE)); 01456 else if (d.rbxSFVPathSepWriteUnix->GetValue()) 01457 AppPrefs::get()->write(prSFV_WRITE_PATH_SEPARATOR, static_cast<long>(wxPATH_UNIX)); 01458 else if (d.rbxSFVPathSepWriteWindows->GetValue()) 01459 AppPrefs::get()->write(prSFV_WRITE_PATH_SEPARATOR, static_cast<long>(wxPATH_WIN)); 01460 else 01461 AppPrefs::get()->write(prSFV_WRITE_PATH_SEPARATOR, static_cast<long>(wxPATH_MAC)); 01462 if (d.rbxSFVEOLWriteWindows->GetValue()) 01463 AppPrefs::get()->write(prSFV_WRITE_EOL, static_cast<long>(wxEOL_DOS)); 01464 else if (d.rbxSFVEOLWriteUnix->GetValue()) 01465 AppPrefs::get()->write(prSFV_WRITE_EOL, static_cast<long>(wxEOL_UNIX)); 01466 else if (d.rbxSFVEOLWriteMAC->GetValue()) 01467 AppPrefs::get()->write(prSFV_WRITE_EOL, static_cast<long>(wxEOL_MAC)); 01468 else 01469 AppPrefs::get()->write(prSFV_WRITE_EOL, static_cast<long>(wxEOL_NATIVE)); 01470 01471 // MD5 files 01472 if (d.rbxMD5PathSepReadAuto->GetValue()) 01473 AppPrefs::get()->write(prMD5_READ_PATH_SEPARATOR, static_cast<long>(wxPATH_NATIVE)); 01474 else if (d.rbxMD5PathSepReadUnix->GetValue()) 01475 AppPrefs::get()->write(prMD5_READ_PATH_SEPARATOR, static_cast<long>(wxPATH_UNIX)); 01476 else if (d.rbxMD5PathSepReadWindows->GetValue()) 01477 AppPrefs::get()->write(prMD5_READ_PATH_SEPARATOR, static_cast<long>(wxPATH_WIN)); 01478 else 01479 AppPrefs::get()->write(prMD5_READ_PATH_SEPARATOR, static_cast<long>(wxPATH_MAC)); 01480 AppPrefs::get()->write(prMD5_WRITE_GEN_AND_DATE, d.chkMD5SaveGenerator->GetValue()); 01481 AppPrefs::get()->write(prMD5_WRITE_FILE_SIZE_AND_DATE, d.chkMD5SaveFilesInfo->GetValue()); 01482 if (d.rbxMD5PathSepWriteSystem->GetValue()) 01483 AppPrefs::get()->write(prMD5_WRITE_PATH_SEPARATOR, static_cast<long>(wxPATH_NATIVE)); 01484 else if (d.rbxMD5PathSepWriteUnix->GetValue()) 01485 AppPrefs::get()->write(prMD5_WRITE_PATH_SEPARATOR, static_cast<long>(wxPATH_UNIX)); 01486 else if (d.rbxMD5PathSepWriteWindows->GetValue()) 01487 AppPrefs::get()->write(prMD5_WRITE_PATH_SEPARATOR, static_cast<long>(wxPATH_WIN)); 01488 else 01489 AppPrefs::get()->write(prMD5_WRITE_PATH_SEPARATOR, static_cast<long>(wxPATH_MAC)); 01490 if (d.rbxMD5EOLWriteWindows->GetValue()) 01491 AppPrefs::get()->write(prMD5_WRITE_EOL, static_cast<long>(wxEOL_DOS)); 01492 else if (d.rbxMD5EOLWriteUnix->GetValue()) 01493 AppPrefs::get()->write(prMD5_WRITE_EOL, static_cast<long>(wxEOL_UNIX)); 01494 else if (d.rbxMD5EOLWriteMAC->GetValue()) 01495 AppPrefs::get()->write(prMD5_WRITE_EOL, static_cast<long>(wxEOL_MAC)); 01496 else 01497 AppPrefs::get()->write(prMD5_WRITE_EOL, static_cast<long>(wxEOL_NATIVE)); 01498 01499 // Multi-check tools 01500 AppPrefs::get()->write(prMC_GLOBAL_SUMMARY, d.chkMCGlobalSummary->GetValue()); 01501 AppPrefs::get()->write(prMC_CHECKSUMS_FILE_SUMMARY, d.chkMCChecksumsFileSummary->GetValue()); 01502 AppPrefs::get()->write(prMC_FILE_STATE, d.chkMCFileState->GetValue()); 01503 AppPrefs::get()->write(prMC_NO_CORRECT_FILE_STATE, d.chkMCNoCorrectFileState->GetValue()); 01504 AppPrefs::get()->write(prMC_NORMAL_COLOUR, ::wxColourToLong(d.MCNormalColour)); 01505 AppPrefs::get()->write(prMC_SUCCESS_COLOUR, ::wxColourToLong(d.MCSuccessColour)); 01506 AppPrefs::get()->write(prMC_WARNING_COLOUR, ::wxColourToLong(d.MCWarningColour)); 01507 AppPrefs::get()->write(prMC_ERROR_COLOUR, ::wxColourToLong(d.MCErrorColour)); 01508 01509 // Batch creation tools 01510 AppPrefs::get()->write(prBC_OVERWRITE_WHEN_CKFILE_EXISTS, d.rbxBCOverwriteExistingCkFile->GetValue()); 01511 AppPrefs::get()->write(prBC_REPLACE_FILE_EXTENSION, d.rbxBCReplaceFileExtension->GetValue()); 01512 AppPrefs::get()->write(prBC_VERBOSITY_LEVEL, static_cast<long>(d.cboBCVerbosityLevel->GetSelection())); 01513 AppPrefs::get()->write(prBC_NORMAL_COLOUR, ::wxColourToLong(d.BCNormalColour)); 01514 AppPrefs::get()->write(prBC_SUCCESS_COLOUR, ::wxColourToLong(d.BCSuccessColour)); 01515 AppPrefs::get()->write(prBC_WARNING_COLOUR, ::wxColourToLong(d.BCWarningColour)); 01516 AppPrefs::get()->write(prBC_ERROR_COLOUR, ::wxColourToLong(d.BCErrorColour)); 01517 01518 // Configuration dialog size 01519 AppPrefs::get()->write(prGUI_CONF_WINDOW_SIZE, d.GetSize()); 01520 } 01521 } 01522 //--------------------------------------------------------------------------- 01523 01524 01525 /** 01526 * Processes menu Help->About 01527 * 01528 * @param event The event's parameters 01529 */ 01530 void frmSums::itmHelpAboutClick(wxCommandEvent& event) 01531 { 01532 dlgAbout dlg(this); 01533 dlg.ShowModal(); 01534 } 01535 //--------------------------------------------------------------------------- 01536 01537 01538 01539 /** 01540 * Event handler to respond to system close events. 01541 * 01542 * @param event event parameters. 01543 */ 01544 void frmSums::FrameClose(wxCloseEvent& event) 01545 { 01546 bool close = true; 01547 01548 if (lvwSums->getSumFile() != NULL) 01549 { 01550 if (lvwSums->getSumFile()->getModified()) 01551 { 01552 // Informs the user that the application will be closed whatever the user do 01553 if (!event.CanVeto()) 01554 ::wxMessageBox(wxString::Format(_("'%s' will be closed even if you choose to cancel.\nIf you want to save the current checksums file, choose 'yes' now."), wxT(APP_NAME)), 01555 wxString::Format(_("Warning - %s"), wxT(APP_NAME)), 01556 wxOK | wxICON_EXCLAMATION, this); 01557 01558 int res = this->checkFileBeforeClose(); 01559 if (res == wxCANCEL) 01560 close = false; 01561 } 01562 } 01563 01564 // Update the title bar 01565 this->updateTitle(); 01566 01567 if (close || !event.CanVeto()) 01568 { 01569 // Saves window parameters 01570 if (AppPrefs::get()->readBool(prGUI_MAIN_SAVE_WINDOW_POSITION)) 01571 AppPrefs::get()->write(prGUI_MAIN_WINDOW_POSITION, this->GetPosition()); 01572 if (AppPrefs::get()->readBool(prGUI_MAIN_SAVE_WINDOW_SIZE)) 01573 AppPrefs::get()->write(prGUI_MAIN_WINDOW_SIZE, this->GetSize()); 01574 if (AppPrefs::get()->readBool(prGUI_MAIN_SUMS_SAVECOLUMNSWIDTHS)) 01575 { 01576 AppPrefs::get()->write(prGUI_MAIN_SUMS_COL_FILENAME_WIDTH, static_cast<long>(lvwSums->GetColumnWidth(0))); 01577 AppPrefs::get()->write(prGUI_MAIN_SUMS_COL_DIRECTORY_WIDTH, static_cast<long>(lvwSums->GetColumnWidth(1))); 01578 AppPrefs::get()->write(prGUI_MAIN_SUMS_COL_CHECKSUM_WIDTH, static_cast<long>(lvwSums->GetColumnWidth(2))); 01579 AppPrefs::get()->write(prGUI_MAIN_SUMS_COL_STATE_WIDTH, static_cast<long>(lvwSums->GetColumnWidth(3))); 01580 } 01581 if (AppPrefs::get()->readBool(prGUI_MAIN_SUMS_SAVECOLUMNTOSORT)) 01582 { 01583 AppPrefs::get()->write(prGUI_MAIN_SUMS_COLUMNTOSORT, static_cast<long>(lvwSums->getColumnToSort())); 01584 AppPrefs::get()->write(prGUI_MAIN_SUMS_COLUMNSORTORDER, static_cast<long>(lvwSums->getSortOrder())); 01585 } 01586 01587 ChecksumsListView::Columns cols[LVW_SUMS_NBCOLS]; 01588 lvwSums->getColumns(cols); 01589 AppPrefs::get()->write(prGUI_MAIN_SUMS_COL_FIRST, static_cast<long>(cols[0])); 01590 AppPrefs::get()->write(prGUI_MAIN_SUMS_COL_SECOND, static_cast<long>(cols[1])); 01591 AppPrefs::get()->write(prGUI_MAIN_SUMS_COL_THIRD, static_cast<long>(cols[2])); 01592 AppPrefs::get()->write(prGUI_MAIN_SUMS_COL_FOURTH, static_cast<long>(cols[3])); 01593 01594 // Save the history 01595 for (size_t i = 0; i < openRecent.GetCount(); i++) 01596 wxConfig::Get()->Write(getOpenRecentConfigKey(static_cast<int>(i)), openRecent[i]); 01597 01598 Destroy(); 01599 } 01600 else // cancel the closing of the frame 01601 event.Veto(true); 01602 } 01603 //--------------------------------------------------------------------------- 01604 01605 01606 /** 01607 * Event handler for a keypressed. 01608 * 01609 * @param event event parameters. 01610 */ 01611 void frmSums::FrameCharHook(wxKeyEvent& event) 01612 { 01613 event.Skip(); 01614 return; 01615 #if 0 01616 switch (event.GetKeyCode()) 01617 { 01618 case WXK_ESCAPE : 01619 // Numeric characters are allowed, so the base class wxTextCtrl 01620 // is allowed to process the event. This is done using the Skip() method. 01621 // Do something 01622 break; 01623 /* case WXK_RETURN : // wxEVT_COMMAND_TEXT_ENTER 01624 // Do something 01625 break;*/ 01626 default : 01627 event.Skip(); 01628 } 01629 #endif 01630 } 01631 //--------------------------------------------------------------------------- 01632 01633 01634 /** 01635 * Processes a click on a header of a column of the list of checksums. 01636 * 01637 * @param event event parameters. 01638 */ 01639 void frmSums::lvwSumsColumnClick(wxListEvent& event) 01640 { 01641 int col = event.GetColumn(); 01642 int prevCol = lvwSums->getColumnToSort(); 01643 ChecksumsListView::SortOrder sortOrder = lvwSums->getSortOrder(); 01644 01645 if (col == prevCol) 01646 { 01647 ChecksumsListView::SortOrder newSortOrder; 01648 newSortOrder = (sortOrder == ChecksumsListView::ASCENDING) ? ChecksumsListView::DESCENDING : ChecksumsListView::ASCENDING; 01649 lvwSums->setSortOrder(newSortOrder); 01650 } 01651 else 01652 lvwSums->setColumnToSort(col, ChecksumsListView::ASCENDING); 01653 01654 lvwSums->sort(); 01655 01656 // Update the state of the Sort by... submenu. 01657 itmSumsSortByUpdate(); 01658 } 01659 //--------------------------------------------------------------------------- 01660 01661 01662 /** 01663 * Processes the <CODE>EVENT_UPDATE_SUMS_FRAME_TITLE_COMMAND</CODE> event. 01664 * 01665 * @param event event parameters. 01666 */ 01667 void frmSums::OnUpdateTitle(wxCommandEvent& event) 01668 { 01669 updateTitle(); 01670 } 01671 //--------------------------------------------------------------------------- 01672 01673 01674 /** 01675 * Processes the <CODE>EVENT_UPDATE_SUMS_FRAME_STATUSBAR_COMMAND</CODE> event. 01676 * 01677 * The <CODE>m_commandString</CODE> member of the event contains the message 01678 * to display. 01679 * The <CODE>m_commandInt</CODE> member of the event contains the status field 01680 * (starting from zero) to set. 01681 * 01682 * @param event event parameters. 01683 */ 01684 void frmSums::OnUpdateStatusBar(wxCommandEvent& event) 01685 { 01686 SetStatusText(event.GetString(), event.GetInt()); 01687 } 01688 //--------------------------------------------------------------------------- 01689 01690 01691 /** 01692 * Processes the <CODE>EVENT_OPEN_RECENT_ADD_FILE</CODE> event. 01693 * 01694 * The <CODE>m_commandString</CODE> member of the event contains the message 01695 * to display. 01696 * 01697 * @param event event parameters. 01698 */ 01699 void frmSums::OnOpenRecentAddFile(wxCommandEvent& event) 01700 { 01701 addFileNameToOpenRecent(event.GetString()); 01702 } 01703 //--------------------------------------------------------------------------- 01704 01705 01706 01707 BEGIN_EVENT_TABLE(frmSums, wxFrame) 01708 EVT_MENU(ITM_FILE_NEW, frmSums::itmFileNewClick) 01709 EVT_MENU(ITM_FILE_OPEN, frmSums::itmFileOpenClick) 01710 EVT_MENU_RANGE(ITM_FILE_OPENRECENT1, ITM_FILE_OPENRECENT16, frmSums::itmFileOpenRecentClick) 01711 EVT_MENU(ITM_FILE_SAVE, frmSums::itmFileSaveClick) 01712 EVT_MENU(ITM_FILE_SAVEAS, frmSums::itmFileSaveAsClick) 01713 EVT_MENU(ITM_FILE_CLOSE, frmSums::itmFileCloseClick) 01714 EVT_MENU(ITM_FILE_QUIT, frmSums::itmFileQuitClick) 01715 EVT_MENU(ITM_SUMS_ADDFILES, frmSums::itmSumsAddFilesClick) 01716 EVT_MENU(ITM_SUMS_ADDDIRECTORIES, frmSums::itmSumsAddDirectoriesClick) 01717 EVT_MENU(ITM_SUMS_ADDMATCHINGFILES, frmSums::itmSumsAddMatchingFilesClick) 01718 EVT_MENU(ITM_SUMS_REMOVE, frmSums::itmSumsRemoveClick) 01719 EVT_MENU(ITM_SUMS_CHECK, frmSums::itmSumsCheckClick) 01720 EVT_MENU(ITM_SUMS_RECOMPUTE, frmSums::itmSumsRecomputeClick) 01721 EVT_MENU(ITM_SUMS_SORTBY_FILENAME, frmSums::itmSumsSortByClick) 01722 EVT_MENU(ITM_SUMS_SORTBY_DIRECTORY, frmSums::itmSumsSortByClick) 01723 EVT_MENU(ITM_SUMS_SORTBY_CHECKSUMVALUE, frmSums::itmSumsSortByClick) 01724 EVT_MENU(ITM_SUMS_SORTBY_STATE, frmSums::itmSumsSortByClick) 01725 EVT_MENU(ITM_SUMS_SORTBY_NONE, frmSums::itmSumsSortByClick) 01726 EVT_MENU(ITM_SUMS_SORTBY_ASCENDING, frmSums::itmSumsSortByClick) 01727 EVT_MENU(ITM_SUMS_SORTBY_DESCENDING, frmSums::itmSumsSortByClick) 01728 EVT_MENU(ITM_SUMS_SELECTALL, frmSums::itmSumsSelectAllClick) 01729 EVT_MENU(ITM_SUMS_INVERTSELECTION, frmSums::itmSumsInvertSelectionClick) 01730 EVT_MENU(ITM_HELP_ABOUT, frmSums::itmHelpAboutClick) 01731 EVT_MENU(ITM_TOOLS_CHECK_MULTIPLE, frmSums::itmToolsCheckMultipleClick) 01732 EVT_MENU(ITM_TOOLS_BATCH_CREATION, frmSums::itmToolsBatchCreationClick) 01733 EVT_MENU(ITM_TOOLS_SHOW_TOOLBAR, frmSums::itmToolsShowToolbarClick) 01734 EVT_MENU(ITM_TOOLS_SHOW_STATUSBAR, frmSums::itmToolsShowStatusbarClick) 01735 EVT_MENU(ITM_TOOLS_CONFIGURE, frmSums::itmToolsConfigureClick) 01736 EVT_CLOSE(frmSums::FrameClose) 01737 EVT_LIST_COL_CLICK(LVW_SUMS, frmSums::lvwSumsColumnClick) 01738 EVT_CUSTOM(EVENT_UPDATE_SUMS_FRAME_TITLE_COMMAND, -1, frmSums::OnUpdateTitle) 01739 EVT_CUSTOM(EVENT_UPDATE_SUMS_FRAME_STATUSBAR_COMMAND, -1, frmSums::OnUpdateStatusBar) 01740 EVT_CUSTOM(EVENT_OPEN_RECENT_ADD_FILE, -1, frmSums::OnOpenRecentAddFile) 01741 END_EVENT_TABLE() 01742 //---------------------------------------------------------------------------

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