Changeset 96
- Timestamp:
- 04/20/06 09:41:29 (2 years ago)
- Files:
-
- trunk/src/Config.cxx (modified) (3 diffs)
- trunk/src/Config.h (modified) (3 diffs)
- trunk/tests/ConfigTest.cxx (modified) (5 diffs)
- trunk/tests/ConfigTest.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/Config.cxx
r94 r96 23 23 24 24 // Constants 25 static gchar *DEFAULT_OPEN_FILE_FOLDER = NULL; 25 26 static gint DEFAULT_WINDOW_HEIGHT = 650; 26 27 static gint DEFAULT_WINDOW_WIDTH = 600; … … 138 139 139 140 /// 141 /// @brief Gets an string configuration option. 142 /// 143 /// @param group Configuration group where the key belongs. 144 /// @param key The key name to retrieve its value. 145 /// @param defaultValue The default value to return if @a key doesn't exists. 146 /// 147 /// @return The value of the @a key in @a group or @a defaultValue if @a key 148 /// doesn't exists. 149 /// 150 gchar * 151 Config::getString (const gchar *group, const gchar *key, 152 const gchar *defaultValue) 153 { 154 gchar *value = g_strdup (defaultValue); 155 if ( g_key_file_has_key (m_Values, group, key, NULL) ) 156 { 157 GError *error = NULL; 158 gchar *savedValue = 159 g_key_file_get_string (m_Values, group, key, &error); 160 if ( NULL == error ) 161 { 162 g_free (value); 163 value = savedValue; 164 } 165 else 166 { 167 g_warning ("Error reading key '%s' from group '%s': %s\n", 168 key, group, error->message); 169 g_error_free (error); 170 } 171 } 172 173 return value; 174 } 175 176 /// 177 /// @brief Gets the last folder used to open a file. 178 /// 179 /// @return The path to the last folder that was used to open a file. 180 /// This string must be freed using g_free(). NULL if no folder 181 /// has been used yet, which means to use the current working directory. 182 /// 183 gchar * 184 Config::getOpenFileFolder () 185 { 186 return getString ("open dialog", "folder", DEFAULT_OPEN_FILE_FOLDER); 187 } 188 189 /// 140 190 /// @brief Gets the main window's height. 141 191 /// … … 212 262 g_free (contents); 213 263 g_free (configFile); 264 } 265 266 /// 267 /// @brief Saves the last folder used to open a file. 268 /// 269 /// @param folder The path to the last folder used. 270 /// 271 void 272 Config::setOpenFileFolder (const gchar *folder) 273 { 274 g_key_file_set_string (m_Values, "open dialog", "folder", folder); 214 275 } 215 276 trunk/src/Config.h
r94 r96 39 39 ~Config (void); 40 40 41 gchar *getOpenFileFolder (void); 41 42 gint getWindowHeight (void); 42 43 gint getWindowWidth (void); … … 44 45 gint getWindowY (void); 45 46 void save(void); 47 void setOpenFileFolder (const gchar *folder); 46 48 void setWindowSize (gint width, gint height); 47 49 void setWindowPos (gint x, gint y); … … 58 60 gint getInteger (const gchar *group, const char *key, 59 61 gint defaultValue); 62 gchar *getString (const gchar *group, const char *key, 63 const gchar *defaultValue); 60 64 }; 61 65 } trunk/tests/ConfigTest.cxx
r93 r96 33 33 ConfigTest::setUp () 34 34 { 35 Config::loadFile (FALSE); 35 36 } 36 37 … … 50 51 ConfigTest::defaultValues () 51 52 { 52 Config::loadFile (FALSE);53 53 Config &config = Config::getConfig (); 54 54 … … 57 57 CPPUNIT_ASSERT_EQUAL (600, config.getWindowWidth ()); 58 58 CPPUNIT_ASSERT_EQUAL (650, config.getWindowHeight ()); 59 CPPUNIT_ASSERT_EQUAL ((gchar *)NULL, config.getOpenFileFolder ()); 59 60 } 60 61 … … 65 66 ConfigTest::windowValues () 66 67 { 67 Config::loadFile (FALSE);68 68 Config &config = Config::getConfig (); 69 69 … … 76 76 CPPUNIT_ASSERT_EQUAL (90, config.getWindowHeight ()); 77 77 } 78 79 /// 80 /// @brief Check setting the current folder for opening files. 81 /// 82 void 83 ConfigTest::currentFolder () 84 { 85 Config &config = Config::getConfig (); 86 87 config.setOpenFileFolder ("/tmp"); 88 gchar *openFolder = config.getOpenFileFolder (); 89 CPPUNIT_ASSERT ( 0 == g_ascii_strcasecmp("/tmp", openFolder)); 90 g_free (openFolder); 91 } trunk/tests/ConfigTest.h
r93 r96 28 28 CPPUNIT_TEST (defaultValues); 29 29 CPPUNIT_TEST (windowValues); 30 CPPUNIT_TEST (currentFolder); 30 31 CPPUNIT_TEST_SUITE_END (); 31 32 … … 36 37 void defaultValues (void); 37 38 void windowValues (void); 39 void currentFolder (void); 38 40 }; 39 41 }
