Changeset 98 for trunk/src/Config.cxx

Show
Ignore:
Timestamp:
04/20/06 11:13:01 (3 years ago)
Author:
jordi
Message:

Divided the pageZoom function from the MainPter? test to ZoomInAndOut?, ZoomWidth? and ZoomFit?, because I'm planning to make ZoomToWith? and ZoomToHeigh? toggle action that deserved separate test cases.

Also added the ZoomToFit? and ZoomToWidth? options to the configuration class. Also the test case was added.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/Config.cxx

    r96 r98  
    2828static gint DEFAULT_WINDOW_X = 0; 
    2929static gint DEFAULT_WINDOW_Y = 0; 
     30static gboolean DEFAULT_ZOOM_TO_FIT = FALSE; 
     31static gboolean DEFAULT_ZOOM_TO_WIDTH = FALSE; 
    3032 
    3133// Static member attributes. 
     
    105107 
    106108/// 
    107 /// @brief Gets an integer configuration option. 
     109/// @brief Gets a boolean configuration option. 
    108110/// 
    109111/// @param group Configuration group where the key belongs. 
     
    114116///         doesn't exists. 
    115117/// 
    116 gint 
    117 Config::getInteger (const gchar *group, const gchar *key, gint defaultValue) 
    118 { 
    119     gint value = defaultValue; 
     118gboolean 
     119Config::getBoolean (const gchar *group, const gchar *key, gboolean defaultValue) 
     120{ 
     121    gboolean value = defaultValue; 
    120122 
    121123    if ( g_key_file_has_key (m_Values, group, key, NULL) ) 
    122124    { 
    123125        GError *error = NULL; 
    124         gint savedValue = g_key_file_get_integer (m_Values, group, key, &error); 
     126        gboolean savedValue =  
     127            g_key_file_get_boolean (m_Values, group, key, &error); 
    125128        if ( NULL == error ) 
    126129        { 
     
    139142 
    140143/// 
     144/// @brief Gets an integer configuration option. 
     145/// 
     146/// @param group Configuration group where the key belongs. 
     147/// @param key The key name to retrieve its value. 
     148/// @param defaultValue The default value to return if @a key doesn't exists. 
     149/// 
     150/// @return The value of the @a key in @a group or @a defaultValue if @a key 
     151///         doesn't exists. 
     152/// 
     153gint 
     154Config::getInteger (const gchar *group, const gchar *key, gint defaultValue) 
     155{ 
     156    gint value = defaultValue; 
     157 
     158    if ( g_key_file_has_key (m_Values, group, key, NULL) ) 
     159    { 
     160        GError *error = NULL; 
     161        gint savedValue = g_key_file_get_integer (m_Values, group, key, &error); 
     162        if ( NULL == error ) 
     163        { 
     164            value = savedValue; 
     165        } 
     166        else 
     167        { 
     168            g_warning ("Error reading key '%s' from group '%s': %s\n",  
     169                       key, group, error->message); 
     170            g_error_free (error); 
     171        }         
     172    } 
     173 
     174    return value; 
     175} 
     176 
     177/// 
    141178/// @brief Gets an string configuration option. 
    142179/// 
     
    299336    g_key_file_set_integer (m_Values, "main window", "x", x); 
    300337    g_key_file_set_integer (m_Values, "main window", "y", y); 
     338} 
     339 
     340/// 
     341/// @brief Sets the zoom to fit option. 
     342/// 
     343/// @param activate Set to TRUE to activate the zoom to fit option. FALSE 
     344///        otherwise. 
     345/// 
     346void 
     347Config::setZoomToFit (gboolean activate) 
     348{ 
     349    g_key_file_set_boolean (m_Values, "main window", "zoomToFit", activate); 
     350    g_key_file_set_boolean (m_Values, "main window", "zoomToWidth",  
     351            !activate && zoomToWidth ()); 
     352} 
     353 
     354/// 
     355/// @brief Sets the zoom to with option. 
     356/// 
     357/// @param activate Set to TRUE to activate the zoom to width option. FALSE 
     358///        otherwise. 
     359/// 
     360void 
     361Config::setZoomToWidth (gboolean activate) 
     362{ 
     363    g_key_file_set_boolean (m_Values, "main window", "zoomToFit",  
     364            !activate && zoomToFit ()); 
     365    g_key_file_set_boolean (m_Values, "main window", "zoomToWidth", activate); 
     366} 
     367 
     368/// 
     369/// @brief Gets the zoom to fit option. 
     370/// 
     371/// @return TRUE if the zoom to fit option is activated. FALSE otherwise. 
     372/// 
     373gboolean 
     374Config::zoomToFit () 
     375{ 
     376    return getBoolean ("main window", "zoomToFit", DEFAULT_ZOOM_TO_FIT); 
     377} 
     378 
     379/// 
     380/// @brief Gets the zoom to width option. 
     381/// 
     382/// @return TRUE if the zoom to width option is activated. FALSE otherwise. 
     383/// 
     384gboolean 
     385Config::zoomToWidth () 
     386{ 
     387    return getBoolean ("main window", "zoomToWidth", DEFAULT_ZOOM_TO_WIDTH); 
    301388} 
    302389