Changeset 96 for trunk/src/Config.cxx

Show
Ignore:
Timestamp:
04/20/06 09:41:29 (3 years ago)
Author:
jordi
Message:

The configuration class can now hold the last used directory to open a file.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/Config.cxx

    r94 r96  
    2323 
    2424// Constants 
     25static gchar *DEFAULT_OPEN_FILE_FOLDER = NULL; 
    2526static gint DEFAULT_WINDOW_HEIGHT = 650; 
    2627static gint DEFAULT_WINDOW_WIDTH = 600; 
     
    138139 
    139140/// 
     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/// 
     150gchar * 
     151Config::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/// 
     183gchar * 
     184Config::getOpenFileFolder () 
     185{ 
     186    return getString ("open dialog", "folder", DEFAULT_OPEN_FILE_FOLDER); 
     187} 
     188 
     189/// 
    140190/// @brief Gets the main window's height. 
    141191/// 
     
    212262    g_free (contents); 
    213263    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/// 
     271void 
     272Config::setOpenFileFolder (const gchar *folder) 
     273{ 
     274    g_key_file_set_string (m_Values, "open dialog", "folder", folder); 
    214275} 
    215276