Changeset 94

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

When the main window is resized or moved, the current position and size is saved to the configuration values.

The configuration now is saved by main.cxx when the application quits correctly.

Location:
trunk/src
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/Config.cxx

    r93 r94  
    197197 
    198198/// 
     199/// @brief Save the current configuration to a file. 
     200/// 
     201void 
     202Config::save () 
     203{ 
     204    gchar *contents = g_key_file_to_data (m_Values, NULL, NULL); 
     205    gchar *configFile = getConfigFileName (); 
     206    GError *error = NULL; 
     207    if ( !g_file_set_contents (configFile, contents, -1, &error) ) 
     208    { 
     209        g_warning ("Couldn't write configuration file: %s\n", error->message); 
     210        g_error_free (error); 
     211    } 
     212    g_free (contents); 
     213    g_free (configFile); 
     214} 
     215 
     216/// 
    199217/// @brief Saves the current window's size. 
    200218/// 
     
    255273    GList *dirs = NULL; 
    256274    gchar *dirName = g_strdup (path); 
    257     while ( !g_file_test (dirName, G_FILE_TEST_EXISTS) ); 
     275    while ( !g_file_test (dirName, G_FILE_TEST_EXISTS) ) 
    258276    { 
    259277        dirs = g_list_prepend (dirs, dirName); 
     
    263281    // Now create all of them. 
    264282    GList *dir = g_list_first (dirs); 
    265     while ( NULL != dir ); 
     283    while ( NULL != dir ) 
    266284    { 
    267285        if ( -1 == g_mkdir ((gchar *)dir->data, 0700) ) 
  • trunk/src/Config.h

    r93 r94  
    4343            gint getWindowX (void); 
    4444            gint getWindowY (void); 
     45            void save(void); 
    4546            void setWindowSize (gint width, gint height); 
    4647            void setWindowPos (gint x, gint y); 
  • trunk/src/gtk/MainView.cxx

    r89 r94  
    3434// Forward declarations. 
    3535static void main_window_about_box_cb (GtkWidget *, gpointer); 
     36static gboolean main_window_moved_or_resized_cb (GtkWidget *,  
     37                                                 GdkEventConfigure *, gpointer); 
    3638static void main_window_go_to_first_page_cb (GtkWidget *, gpointer); 
    3739static void main_window_go_to_last_page_cb (GtkWidget *, gpointer); 
     
    143145    m_MainWindow = gtk_window_new (GTK_WINDOW_TOPLEVEL); 
    144146    setMainWindowIcon (); 
    145     // Connect already the destroy signal. 
     147    // Connect already the destroy and delete signal. 
    146148    g_signal_connect (G_OBJECT (m_MainWindow), "destroy", 
    147149                      G_CALLBACK (main_window_quit_cb), NULL); 
     150    g_signal_connect (G_OBJECT (m_MainWindow), "configure-event", 
     151                      G_CALLBACK (main_window_moved_or_resized_cb), NULL); 
    148152    // Create the main vertical box. 
    149153    m_MainBox = gtk_vbox_new (FALSE, 0); 
     
    358362MainView::show (void) 
    359363{     
     364    Config &config = Config::getConfig (); 
     365    gtk_window_set_default_size (GTK_WINDOW (m_MainWindow), 
     366                                 config.getWindowWidth (), 
     367                                 config.getWindowHeight ()); 
    360368    gtk_widget_show (m_MainWindow); 
    361     gtk_window_maximize (GTK_WINDOW (m_MainWindow)); 
     369    gtk_window_move (GTK_WINDOW (m_MainWindow),  
     370                     config.getWindowX (), config.getWindowY ()); 
    362371} 
    363372 
     
    754763 
    755764/// 
     765/// @brief Called when the window is moved or resized. 
     766/// 
     767/// This is used to save the current window's position and size. 
     768/// 
     769gboolean 
     770main_window_moved_or_resized_cb (GtkWidget *widget, GdkEventConfigure *event,  
     771                                 gpointer data) 
     772{ 
     773    // First set the window's size and position to the configuration. 
     774    GtkWindow *m_MainWindow = GTK_WINDOW (widget); 
     775    Config &config = Config::getConfig (); 
     776    config.setWindowSize (event->width, event->height); 
     777    gint x; 
     778    gint y; 
     779    gtk_window_get_position (m_MainWindow, &x, &y); 
     780    config.setWindowPos (x, y); 
     781 
     782    return FALSE; 
     783} 
     784 
     785/// 
    756786/// @brief The user tries to go to the first page. 
    757787/// 
  • trunk/src/main.cxx

    r73 r94  
    2424#include <MainView.h> 
    2525#include "MainPter.h" 
     26#include "Config.h" 
    2627 
    2728 
     
    9293    // the presenter's responsibility. 
    9394    delete mainPter; 
     95 
     96    // Save the configuration. 
     97    Config::getConfig().save (); 
     98     
    9499    // All done!. 
    95100    return EXIT_SUCCESS;