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

appprefs.hpp

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 appprefs.hpp 00022 * Common preferences for the application. 00023 */ 00024 00025 #ifndef INC_APPPREFS_HPP 00026 #define INC_APPPREFS_HPP 00027 00028 //--------------------------------------------------------------------------- 00029 // For compilers that support precompilation, includes "wx.h". 00030 #include <wx/wxprec.h> 00031 00032 #ifdef __BORLANDC__ 00033 #pragma hdrstop 00034 #endif 00035 00036 #ifndef WX_PRECOMP 00037 // Include your minimal set of headers here, or wx.h 00038 #include <wx/wx.h> 00039 #endif 00040 #include <wx/hashmap.h> 00041 #include <wx/config.h> 00042 //--------------------------------------------------------------------------- 00043 00044 00045 /** 00046 * Encapsulates a preference value. 00047 * 00048 * A preference value has a type and can have a corresponding key in the 00049 * global configuration file (see <CODE>wxConfig::Get()</CODE> in the wxWidgets 00050 * documentation). 00051 * 00052 * The type of the preference is fixed at the construction of the instance and 00053 * can't be changed. The type is always checked when the value is set or gotten. 00054 * 00055 * If a key is specified: 00056 * <UL> 00057 * <LI>At initialization, if the constructor parameter 00058 * <CODE>initFromCfgFile</CODE> is <CODE>true</CODE>, then the preference 00059 * value is initialized by reading the global configuration file (on 00060 * failure the given value is used).</LI> 00061 * <LI>When a <CODE>set</CODE> method is called, the preference value is 00062 * written in the global configuration file.</LI> 00063 * </UL> 00064 * 00065 * The static <CODE>read</CODE> methods provide facility for reading the complex 00066 * types that are handled by this class (such as wxRect for example). 00067 */ 00068 class PreferenceValue 00069 { 00070 protected: 00071 /// Type of the preference value 00072 enum PreferenceType 00073 { 00074 ptNotDefined = 0, 00075 ptLong, 00076 ptString, 00077 ptDouble, 00078 ptBoolean, 00079 ptRect, 00080 ptSize, 00081 ptPoint 00082 }; 00083 00084 /// Value of the preference 00085 union value_t 00086 { 00087 long* valLong; ///< Pointer on the long integer type value. 00088 wxString* valString; ///< Pointer on the string type value. 00089 double* valDouble; ///< Pointer on the double type value. 00090 bool* valBool; ///< Pointer on the boolean type value. 00091 wxRect* valRect; ///< Pointer on a wxRect instance. 00092 wxSize* valSize; ///< Pointer on a wxSize instance. 00093 wxPoint* valPoint; ///< Pointer on a wxPoint instance. 00094 }; 00095 00096 value_t _value; ///< Value of the preference. 00097 PreferenceType _valueType; ///< Type of the preference. 00098 wxString _cfgKey; ///< Corresponding key in the configuration file. Must be empty if this item isn't stored in the configuration file. 00099 00100 protected: 00101 // Clones the source instance in this instance. 00102 void clone(const PreferenceValue& source); 00103 00104 // Cleans up the memory. 00105 void cleanup(); 00106 00107 public: 00108 // Default constructor. 00109 PreferenceValue(); 00110 00111 // Constructor with a long integer type. 00112 PreferenceValue(const long value, const wxString& cfgKey = wxEmptyString, const bool initFromCfgFile = true); 00113 00114 // Constructor with a string type. 00115 PreferenceValue(const wxString& value, const wxString& cfgKey = wxEmptyString, const bool initFromCfgFile = true); 00116 00117 // Constructor with a double type. 00118 PreferenceValue(const double value, const wxString& cfgKey = wxEmptyString, const bool initFromCfgFile = true); 00119 00120 // Constructor with a boolean type. 00121 PreferenceValue(const bool value, const wxString& cfgKey = wxEmptyString, const bool initFromCfgFile = true); 00122 00123 // Constructor with a wxRect type. 00124 PreferenceValue(const wxRect& value, const wxString& cfgKey = wxEmptyString, const bool initFromCfgFile = true); 00125 00126 // Constructor with a wxPoint type. 00127 PreferenceValue(const wxPoint& value, const wxString& cfgKey = wxEmptyString, const bool initFromCfgFile = true); 00128 00129 // Constructor with a wxSize type. 00130 PreferenceValue(const wxSize& value, const wxString& cfgKey = wxEmptyString, const bool initFromCfgFile = true); 00131 00132 // Copy constructor. 00133 PreferenceValue(const PreferenceValue& source); 00134 00135 // Assignment operator. 00136 PreferenceValue& operator=(const PreferenceValue& source); 00137 00138 // Destructor. 00139 ~PreferenceValue(); 00140 00141 // Gets the key of the preference in the configuration file. 00142 wxString getConfigKey() const; 00143 00144 // Gets a long integer value. 00145 bool get(long& value) const; 00146 00147 // Sets a long integer value. 00148 bool set(const long newValue); 00149 00150 // Gets a string value. 00151 bool get(wxString& value) const; 00152 00153 // Sets a string value. 00154 bool set(const wxString& newValue); 00155 00156 // Gets a double value. 00157 bool get(double& value) const; 00158 00159 // Sets a string value. 00160 bool set(const double newValue); 00161 00162 // Gets a boolean value. 00163 bool get(bool& value) const; 00164 00165 // Sets a boolean value. 00166 bool set(const bool newValue); 00167 00168 // Gets a wxRect value. 00169 bool get(wxRect& value) const; 00170 00171 // Sets a wxRect value. 00172 bool set(const wxRect& newValue); 00173 00174 // Gets a wxPoint value. 00175 bool get(wxPoint& value) const; 00176 00177 // Sets a wxPoint value. 00178 bool set(const wxPoint& newValue); 00179 00180 // Gets a wxSize value. 00181 bool get(wxSize& value) const; 00182 00183 // Sets a wxSize value. 00184 bool set(const wxSize& newValue); 00185 00186 // Reads a wxRect value from the configuration file. 00187 static bool read(const wxString& key, wxRect* r, wxConfigBase* cfg = NULL); 00188 00189 // Reads a wxRect value from the configuration file. 00190 static wxRect read(const wxString& key, const wxRect& def, wxConfigBase* cfg = NULL); 00191 00192 // Reads a wxPoint value from the configuration file. 00193 static bool read(const wxString& key, wxPoint* r, wxConfigBase* cfg = NULL); 00194 00195 // Reads a wxPoint value from the configuration file. 00196 static wxPoint read(const wxString& key, const wxPoint& def, wxConfigBase* cfg = NULL); 00197 00198 // Reads a wxSize value from the configuration file. 00199 static bool read(const wxString& key, wxSize* r, wxConfigBase* cfg = NULL); 00200 00201 // Reads a wxSize value from the configuration file. 00202 static wxSize read(const wxString& key, const wxSize& def, wxConfigBase* cfg = NULL); 00203 }; 00204 //--------------------------------------------------------------------------- 00205 00206 00207 /// A hash map type with integer keys and PreferenceValue values. 00208 WX_DECLARE_HASH_MAP(int, PreferenceValue, wxIntegerHash, wxIntegerEqual, HashPrefs); 00209 //--------------------------------------------------------------------------- 00210 00211 00212 /** 00213 * Manages the application preferences. 00214 * 00215 * You can't create directly an instance of this class. In order to get one, 00216 * use the method <CODE>get()</CODE>. Use the method 00217 * <CODE>cleanupGlobal()</CODE> at the end of the program to clean up the 00218 * memory. 00219 * 00220 * <B>Don't</B> use the method <CODE>get()</CODE> (and more generally don't 00221 * create an instance of AppPrefs) before setting a correct global configuration 00222 * file (see <CODE>wxConfig</CODE> in the wxWidgets documentation). 00223 * 00224 * Use the methods <CODE>read</CODE> and <CODE>write</CODE> to get and set the 00225 * values of the preferences. 00226 */ 00227 class AppPrefs 00228 { 00229 protected: 00230 HashPrefs prefs; ///< Hashmap that contains the data of preferences. 00231 00232 // Clones the source instance in this instance. 00233 void clone(const AppPrefs& source); 00234 00235 // Inits the instance. 00236 void init(); 00237 00238 // Constructor. 00239 AppPrefs(); 00240 00241 // Copy constructor. 00242 AppPrefs(const AppPrefs& source); 00243 00244 // Assignment operator. 00245 AppPrefs& operator=(const AppPrefs& source); 00246 00247 public: 00248 // Gets the key of the preference in the configuration file. 00249 wxString getConfigKey(const int key) const; 00250 00251 // Reads a string from the key. 00252 bool read(const int key, wxString& str) const; 00253 00254 // Reads a string from the key. 00255 wxString readString(const int key, const wxString& def = wxEmptyString) const; 00256 00257 // Reads a long integer value from the key. 00258 bool read(const int key, long& l) const; 00259 00260 // Reads a long integer value from the key. 00261 long readLong(const int key, const long def = -1L) const; 00262 00263 // Reads a double value from the key. 00264 bool read(const int key, double& d) const; 00265 00266 // Reads a double value from the key. 00267 double readDouble(const int key, const double def = -1.0) const; 00268 00269 // Reads a boolean value from the key. 00270 bool read(const int key, bool& b) const; 00271 00272 // Reads a boolean value from the key. 00273 bool readBool(const int key, const bool def = false) const; 00274 00275 // Reads a wxRect value from the key. 00276 bool read(const int key, wxRect& r) const; 00277 00278 // Reads a wxRect value from the key. 00279 wxRect readRect(const int key, const wxRect& def = wxRect(0, 0, 0, 0)) const; 00280 00281 // Reads a wxPoint value from the key. 00282 bool read(const int key, wxPoint& p) const; 00283 00284 // Reads a wxPoint value from the key. 00285 wxPoint readPoint(const int key, const wxPoint& def = wxPoint(0, 0)) const; 00286 00287 // Reads a wxSize value from the key. 00288 bool read(const int key, wxSize& s) const; 00289 00290 // Reads a wxSize value from the key. 00291 wxSize readSize(const int key, const wxSize& def = wxSize(0, 0)) const; 00292 00293 // Write a string in the preference given by the key. 00294 bool write(const int key, const wxString& str); 00295 00296 // Write a long integer value in the preference given by the key. 00297 bool write(const int key, const long l); 00298 00299 // Write a double value in the preference given by the key. 00300 bool write(const int key, const double d); 00301 00302 // Write a boolean value in the preference given by the key. 00303 bool write(const int key, const bool b); 00304 00305 // Write a wxRect value in the preference given by the key. 00306 bool write(const int key, const wxRect& r); 00307 00308 // Write a wxPoint value in the preference given by the key. 00309 bool write(const int key, const wxPoint& p); 00310 00311 // Write a wxSize value in the preference given by the key. 00312 bool write(const int key, const wxSize& s); 00313 00314 // Static attributes and methods. 00315 protected: 00316 static AppPrefs* global; ///< Global preferences. 00317 static wxString configDir; ///< Full name of the directory which contains the application's preferences. 00318 static wxString configFileName; ///< Name of the file which contains the application preferences. 00319 00320 // Gets the full name of the directory where the preferences of the application are stored. 00321 static wxString getConfigDir(); 00322 00323 // Gets the name of the file which contains the application's preferences. 00324 static wxString getConfigFileName(); 00325 00326 // Gets the name of the file which contains the application's languages settings. 00327 static wxString getLanguagesFileName(); 00328 00329 // Gets the name of the directory which contains the application's preferences. 00330 static wxString getConfigDirName(); 00331 00332 // Sets the global preferences. 00333 static AppPrefs* set(AppPrefs* pAppPrefs); 00334 00335 public: 00336 // Gets a pointer on the global preferences. 00337 static AppPrefs* get(); 00338 00339 // Cleans up the global instance. 00340 static void cleanupGlobal(); 00341 00342 // Gets the full path of the file which contains the application's preferences. 00343 static wxString getConfigPathName(); 00344 00345 // Gets the full path of the file which contains the application's languages settings. 00346 static wxString getLanguagesPathName(); 00347 00348 // Gets the default rects of the main window 00349 static wxRect getDefaultMainWindowRect(); 00350 00351 // Gets the directory where the user stores its documents. 00352 static wxString getUserDocumentsDirName(); 00353 }; 00354 //--------------------------------------------------------------------------- 00355 00356 00357 /// Preferences keys 00358 enum PreferencesKeys 00359 { 00360 prGUI_MAIN_SAVE_WINDOW_POSITION = 100, 00361 prGUI_MAIN_SAVE_WINDOW_SIZE, 00362 prGUI_MAIN_WINDOW_POSITION, 00363 prGUI_MAIN_WINDOW_SIZE, 00364 prGUI_MAIN_SHOW_TOOLBAR, 00365 prGUI_MAIN_SHOW_STATUSBAR, 00366 prGUI_MAIN_SUMS_SAVECOLUMNTOSORT, 00367 prGUI_MAIN_SUMS_COLUMNTOSORT, 00368 prGUI_MAIN_SUMS_COLUMNSORTORDER, 00369 prGUI_MAIN_SUMS_SAVECOLUMNSWIDTHS, 00370 prGUI_MAIN_SUMS_COL_FILENAME_WIDTH, 00371 prGUI_MAIN_SUMS_COL_DIRECTORY_WIDTH, 00372 prGUI_MAIN_SUMS_COL_CHECKSUM_WIDTH, 00373 prGUI_MAIN_SUMS_COL_STATE_WIDTH, 00374 prGUI_MAIN_SUMS_COL_FIRST, 00375 prGUI_MAIN_SUMS_COL_SECOND, 00376 prGUI_MAIN_SUMS_COL_THIRD, 00377 prGUI_MAIN_SUMS_COL_FOURTH, 00378 prGUI_MAIN_SUMS_DIRSINABSOLUTEPATH, 00379 prGUI_MAIN_SUMS_UPPERCASE, 00380 prGUI_MAIN_SUMS_HRULES, 00381 prGUI_MAIN_SUMS_VRULES, 00382 prGUI_MAIN_LAST_DIRECTORY, 00383 prGUI_CONF_WINDOW_SIZE, 00384 prGUI_CONF_SASH_POSITION, 00385 prGUI_NEWFILE_LAST_DIRECTORY, 00386 prGUI_NEWFILE_LAST_FILETYPE, 00387 prGUI_AUTO_CHECK_ON_OPEN, 00388 prGUI_DLG_SUMUP_CHECK, 00389 prGUI_WARN_ON_INVALID_WHEN_SAVING, 00390 prGUI_CLN_VERIFY_DONT_SHOW_GUI, 00391 prGUI_CLN_APPEND_SHOW_GUI, 00392 prGUI_CLN_CREATE_SHOW_GUI, 00393 prLANGUAGE_NAME, 00394 prSFV_READ_PATH_SEPARATOR, 00395 prSFV_WRITE_GEN_AND_DATE, 00396 prSFV_IDENTIFY_AS, 00397 prSFV_WRITE_FILE_SIZE_AND_DATE, 00398 prSFV_WRITE_PATH_SEPARATOR, 00399 prSFV_WRITE_EOL, 00400 prMD5_READ_PATH_SEPARATOR, 00401 prMD5_WRITE_GEN_AND_DATE, 00402 prMD5_WRITE_FILE_SIZE_AND_DATE, 00403 prMD5_WRITE_PATH_SEPARATOR, 00404 prMD5_WRITE_EOL, 00405 prMC_WINDOW_SIZE, 00406 prMC_GLOBAL_SUMMARY, 00407 prMC_CHECKSUMS_FILE_SUMMARY, 00408 prMC_FILE_STATE, 00409 prMC_NO_CORRECT_FILE_STATE, 00410 prMC_NORMAL_COLOUR, 00411 prMC_SUCCESS_COLOUR, 00412 prMC_WARNING_COLOUR, 00413 prMC_ERROR_COLOUR, 00414 prBC_WINDOW_SIZE, 00415 prBC_OVERWRITE_WHEN_CKFILE_EXISTS, 00416 prBC_REPLACE_FILE_EXTENSION, 00417 prBC_VERBOSITY_LEVEL, 00418 prBC_NORMAL_COLOUR, 00419 prBC_SUCCESS_COLOUR, 00420 prBC_WARNING_COLOUR, 00421 prBC_ERROR_COLOUR, 00422 prENGINE_READ_BUFFER 00423 }; 00424 //--------------------------------------------------------------------------- 00425 00426 00427 #endif // #define INC_APPPREFS_HPP

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