Settings view fixed.
authoritkonma <marko.itkonen@ixonos.com>
Mon, 1 Jun 2009 07:26:47 +0000 (10:26 +0300)
committeritkonma <marko.itkonen@ixonos.com>
Mon, 1 Jun 2009 07:26:47 +0000 (10:26 +0300)
src/BusinessLogic/UIManager.cpp
src/BusinessLogic/UIManager.h
src/Domain/Configuration/Configuration.cpp
src/UserInterface/Views/SettingsView.cpp
src/UserInterface/Views/SettingsView.h

index d6d16b3..e4cdc67 100644 (file)
@@ -98,6 +98,7 @@ void UIManager::createSettingsView()
        
        // Connect signals
        connect( iSettingsView, SIGNAL( okClicked() ), this, SLOT( settingsOkClicked() ) );
        
        // Connect signals
        connect( iSettingsView, SIGNAL( okClicked() ), this, SLOT( settingsOkClicked() ) );
+       connect( iSettingsView, SIGNAL( cancelClicked() ), this, SLOT( settingsCancelClicked() ) );
 }
 
 void UIManager::createRoomStatusIndicator()
 }
 
 void UIManager::createRoomStatusIndicator()
@@ -298,3 +299,13 @@ void UIManager::hideProgressBar()
                iProgressBar->close();
        }
 }
                iProgressBar->close();
        }
 }
+
+void UIManager::settingsCancelClicked()
+{
+       // Show the weekly view and restart the idle timer
+       if ( iWeeklyView != 0 )
+       {
+               iWindowManager->showView( static_cast<ViewBase *>( iWeeklyView ) );
+               iEngine->startIdleTimeCounter();
+       }
+}
index de123b6..0c40c2b 100644 (file)
@@ -37,6 +37,7 @@ public slots:
 
        void settingsViewRequest();
        void settingsOkClicked();
 
        void settingsViewRequest();
        void settingsOkClicked();
+       void settingsCancelClicked();
        void roomStatusIndicatorRequested();
        void previousViewRestored();
        void changeModeOrdered( DeviceManager::OperationMode aMode );
        void roomStatusIndicatorRequested();
        void previousViewRestored();
        void changeModeOrdered( DeviceManager::OperationMode aMode );
index 0076e23..54648ca 100644 (file)
@@ -159,17 +159,38 @@ void Configuration::saveConnectionSettings( const QDomNode &aXML )
                if ( tagName == QString( "serverurl" ) )
                {
                        QDomText t = node.ownerDocument().createTextNode( iConnectionSettings->serverUrl().toString() );
                if ( tagName == QString( "serverurl" ) )
                {
                        QDomText t = node.ownerDocument().createTextNode( iConnectionSettings->serverUrl().toString() );
-                       e.replaceChild( t, e.firstChild() );
+                       if ( e.hasChildNodes() )
+                       {
+                               e.replaceChild( t, e.firstChild() );
+                       }
+                       else
+                       {
+                               e.appendChild( e.firstChild() );
+                       }
                }
                else if ( tagName == QString( "username" ) )
                {
                        QDomText t = node.ownerDocument().createTextNode( iConnectionSettings->username() );
                }
                else if ( tagName == QString( "username" ) )
                {
                        QDomText t = node.ownerDocument().createTextNode( iConnectionSettings->username() );
-                       e.replaceChild( t, e.firstChild() );
+                       if ( e.hasChildNodes() )
+                       {
+                               e.replaceChild( t, e.firstChild() );
+                       }
+                       else
+                       {
+                               e.appendChild( e.firstChild() );
+                       }
                }
                else if ( tagName == QString( "password" ) )
                {
                        QDomText t = node.ownerDocument().createTextNode( iConnectionSettings->password() );
                }
                else if ( tagName == QString( "password" ) )
                {
                        QDomText t = node.ownerDocument().createTextNode( iConnectionSettings->password() );
-                       e.replaceChild( t, e.firstChild() );
+                       if ( e.hasChildNodes() )
+                       {
+                               e.replaceChild( t, e.firstChild() );
+                       }
+                       else
+                       {
+                               e.appendChild( e.firstChild() );
+                       }
                }
                else if ( tagName == QString( "refreshinterval" ) )
                {
                }
                else if ( tagName == QString( "refreshinterval" ) )
                {
@@ -198,6 +219,7 @@ void Configuration::saveRooms( const QDomNode &aXML )
                node = next;
        }
 
                node = next;
        }
 
+       node = aXML;
        QList<Room*>::iterator i;
        for ( i = iRooms.begin(); i != iRooms.end(); ++i )
        {
        QList<Room*>::iterator i;
        for ( i = iRooms.begin(); i != iRooms.end(); ++i )
        {
@@ -619,7 +641,7 @@ DateTimeSettings * Configuration::readDateTimeSettings( const QDomNode &aXML )
                        
                        bool success = false;
                        unsigned int weekDayTmp = e.text().toUInt( &success );
                        
                        bool success = false;
                        unsigned int weekDayTmp = e.text().toUInt( &success );
-                       if( success && weekDayTmp >= 0 && weekDayTmp < 7)
+                       if( success && weekDayTmp < 7 )
                        {
                                dayOfWeek = (DateTimeSettings::weekDay)weekDayTmp;
                        }
                        {
                                dayOfWeek = (DateTimeSettings::weekDay)weekDayTmp;
                        }
index 1021d77..5471b0c 100644 (file)
@@ -45,6 +45,9 @@ SettingsView::SettingsView( QWidget *aParent ) :
        iOkButton = new QPushButton;
        iOkButton->setText( tr( "OK" ) );
        buttonLayout->addWidget( iOkButton );
        iOkButton = new QPushButton;
        iOkButton->setText( tr( "OK" ) );
        buttonLayout->addWidget( iOkButton );
+       iCancelButton = new QPushButton;
+       iCancelButton->setText( tr( "Cancel" ));
+       buttonLayout->addWidget( iCancelButton );
 
        // Handle the main layout
        QVBoxLayout *mainLayout = new QVBoxLayout;
 
        // Handle the main layout
        QVBoxLayout *mainLayout = new QVBoxLayout;
@@ -52,9 +55,11 @@ SettingsView::SettingsView( QWidget *aParent ) :
        mainLayout->addLayout( buttonLayout );
 
        setLayout( mainLayout );
        mainLayout->addLayout( buttonLayout );
 
        setLayout( mainLayout );
+       setValues();
 
        // Handle component connections
        connect( iOkButton, SIGNAL( clicked() ), this, SLOT( handleOkClicked() ) );
 
        // Handle component connections
        connect( iOkButton, SIGNAL( clicked() ), this, SLOT( handleOkClicked() ) );
+       connect( iCancelButton, SIGNAL( clicked() ), this, SLOT( handleCancelClicked() ) );
 }
 
 SettingsView::~SettingsView()
 }
 
 SettingsView::~SettingsView()
@@ -69,6 +74,11 @@ SettingsView::~SettingsView()
                delete iOkButton;
                iOkButton = 0;
        }
                delete iOkButton;
                iOkButton = 0;
        }
+       if ( iCancelButton != 0 )
+       {
+               delete iCancelButton;
+               iCancelButton = 0;
+       }
        if ( iSettingsTab != 0 )
        {
                delete iSettingsTab;
        if ( iSettingsTab != 0 )
        {
                delete iSettingsTab;
@@ -159,13 +169,6 @@ QWidget *SettingsView::initSettingsTab()
        QIntValidator *qiv = new QIntValidator( 0 );
        iRefreshInterval->setValidator( qiv );
 
        QIntValidator *qiv = new QIntValidator( 0 );
        iRefreshInterval->setValidator( qiv );
 
-       iUserName->setText( Configuration::instance()->connectionSettings()->username() );
-       iPassword->setText( Configuration::instance()->connectionSettings()->password() );
-       iServerAddress->setText( Configuration::instance()->connectionSettings()->serverUrl().toString() );
-       QString refreshIntervalStr;
-       refreshIntervalStr.setNum( Configuration::instance()->connectionSettings()->refreshInterval() );
-       iRefreshInterval->setText( refreshIntervalStr );
-
        // Create the group boxes
        QGroupBox *userInformationGroup = new QGroupBox( tr( "User Information" ) );
        QGroupBox *serverInformationGroup = new QGroupBox( tr( "Server Information" ) );
        // Create the group boxes
        QGroupBox *userInformationGroup = new QGroupBox( tr( "User Information" ) );
        QGroupBox *serverInformationGroup = new QGroupBox( tr( "Server Information" ) );
@@ -216,19 +219,6 @@ QWidget *SettingsView::initWeekViewTab()
        iDayStartTime = new QTimeEdit;
        iDayEndTime = new QTimeEdit;
 
        iDayStartTime = new QTimeEdit;
        iDayEndTime = new QTimeEdit;
 
-       if ( Configuration::instance()->displaySettings()->daysInSchedule() == DisplaySettings::WeekdaysInSchedule )
-       {
-               iFiveDays->setChecked( true );
-               iSevenDays->setChecked( false );
-       }
-       else
-       {
-               iFiveDays->setChecked( false );
-               iSevenDays->setChecked( true );
-       }
-       iDayStartTime->setTime( Configuration::instance()->displaySettings()->dayStartsAt() );
-       iDayEndTime->setTime( Configuration::instance()->displaySettings()->dayEndsAt() );
-
        // Create group box and the grid layout
        QGroupBox *weeklyInformation = new QGroupBox( tr( "Weekly View" ) );
        QGridLayout *wgl = new QGridLayout;
        // Create group box and the grid layout
        QGroupBox *weeklyInformation = new QGroupBox( tr( "Weekly View" ) );
        QGridLayout *wgl = new QGridLayout;
@@ -393,15 +383,47 @@ void SettingsView::handleOkClicked()
        QString userName = iUserName->text();
        QString password = iPassword->text();
        QString serverAddress = iServerAddress->text();
        QString userName = iUserName->text();
        QString password = iPassword->text();
        QString serverAddress = iServerAddress->text();
-       QString refreshInterval = iRefreshInterval->text();
+       bool ok;
+       uint refreshInterval = iRefreshInterval->text().toUInt(&ok, 10);
 
        bool fiveDays = iFiveDays->isChecked();
        bool sevenDays = iSevenDays->isChecked();
        bool powerSaveEnabled = iPowerSaveEnabled->isChecked();
 
 
        bool fiveDays = iFiveDays->isChecked();
        bool sevenDays = iSevenDays->isChecked();
        bool powerSaveEnabled = iPowerSaveEnabled->isChecked();
 
-       // TODO : Set the values to configuration and save it
+       // set values to Configuration
+       // set user information
+       Configuration::instance()->connectionSettings()->setUsername( userName );
+       Configuration::instance()->connectionSettings()->setPassword( password );
+       
+       // set server information
+       Configuration::instance()->connectionSettings()->setServerUrl( serverAddress );
+       if ( ok )
+       {
+               Configuration::instance()->connectionSettings()->setRefreshInterval( refreshInterval );
+       }
+       
+       // set weekly view settings
+       if ( fiveDays )
+       {
+               Configuration::instance()->displaySettings()->setDaysInSchedule( DisplaySettings::WeekdaysInSchedule );
+       }
+       else if ( sevenDays )
+       {
+               Configuration::instance()->displaySettings()->setDaysInSchedule( DisplaySettings::WholeWeekInSchedule );
+       }
+       Configuration::instance()->displaySettings()->setDayStartsAt( calendarStart );
+       Configuration::instance()->displaySettings()->setDayEndsAt( calendarEnd );
+       
+       // set power save settings
+       Configuration::instance()->startupSettings()->setPowersavingEnabled( powerSaveEnabled );
+       Configuration::instance()->startupSettings()->setTurnOnAt( powerSaveStart );
+       Configuration::instance()->startupSettings()->setTurnOffAt( powerSaveEnd );
+       
+       // save configuration
+       Configuration::instance()->save();
        
        // Emit the signal to notify that ok is pressed and data is saved.
        
        // Emit the signal to notify that ok is pressed and data is saved.
+       setValues();
        emit okClicked();
 }
 
        emit okClicked();
 }
 
@@ -413,4 +435,46 @@ void SettingsView::viewResized(const QSize &newSize, const QSize &oldSize)
                // the ok button is hidden under the keyboard.
                size().rheight() += iOkButton->size().height();
        }
                // the ok button is hidden under the keyboard.
                size().rheight() += iOkButton->size().height();
        }
-}
\ No newline at end of file
+}
+
+void SettingsView::handleCancelClicked()
+{
+       setValues();
+       emit cancelClicked();
+}
+
+void SettingsView::setValues()
+{
+       // set user information
+       iUserName->setText( Configuration::instance()->connectionSettings()->username() );
+       iPassword->setText( Configuration::instance()->connectionSettings()->password() );
+       // set server information
+       iServerAddress->setText( Configuration::instance()->connectionSettings()->serverUrl().toString() );
+       QString refreshIntervalStr;
+       refreshIntervalStr.setNum( Configuration::instance()->connectionSettings()->refreshInterval() );
+       iRefreshInterval->setText( refreshIntervalStr );
+       // set weekly view display settings
+       if ( Configuration::instance()->displaySettings()->daysInSchedule() == DisplaySettings::WeekdaysInSchedule )
+       {
+               iFiveDays->setChecked( true );
+               iSevenDays->setChecked( false );
+       }
+       else
+       {
+               iFiveDays->setChecked( false );
+               iSevenDays->setChecked( true );
+       }
+       iDayStartTime->setTime( Configuration::instance()->displaySettings()->dayStartsAt() );
+       iDayEndTime->setTime( Configuration::instance()->displaySettings()->dayEndsAt() );
+       // set startup settings
+       if ( Configuration::instance()->startupSettings()->isPowersavingEnabled() )
+       {
+               iPowerSaveEnabled->setChecked( true );
+       }
+       else
+       {
+               iPowerSaveEnabled->setChecked( false );
+       }
+       iPowerSaveStartTime->setTime( Configuration::instance()->startupSettings()->turnOnAt() );
+       iPowerSaveEndTime->setTime( Configuration::instance()->startupSettings()->turnOffAt() );
+}
index 2845a8d..c86e690 100644 (file)
@@ -30,12 +30,16 @@ public:
 signals:
        void okClicked();
        
 signals:
        void okClicked();
        
+       void cancelClicked();
+       
 public slots:
        void viewResized(const QSize &newSize, const QSize &oldSize);
 
 private slots:
        //! Slot to handle the Ok button pressing.
        void handleOkClicked();
 public slots:
        void viewResized(const QSize &newSize, const QSize &oldSize);
 
 private slots:
        //! Slot to handle the Ok button pressing.
        void handleOkClicked();
+       //! Slot to handle the Cancel button pressing.
+       void handleCancelClicked();
 
 private:
        //! Initialize "Settings" tab.
 
 private:
        //! Initialize "Settings" tab.
@@ -46,11 +50,15 @@ private:
        QWidget *initResourcesTab();
        //! Initialize "KIOSK Mode" tab.
        QWidget *initKioskModeTab();
        QWidget *initResourcesTab();
        //! Initialize "KIOSK Mode" tab.
        QWidget *initKioskModeTab();
+       //! Set values to fields
+       void setValues();
 
        //! The tabbed settings view component.
        QTabWidget *iTabWidget;
        //! OK button to dismiss the settings view with saving the settings.
        QPushButton *iOkButton;
 
        //! The tabbed settings view component.
        QTabWidget *iTabWidget;
        //! OK button to dismiss the settings view with saving the settings.
        QPushButton *iOkButton;
+       //! Cancel button to dismiss the settings view without saving the settings
+       QPushButton *iCancelButton;
        //! Settings tab.
        QWidget *iSettingsTab;
        //! Week View tab.
        //! Settings tab.
        QWidget *iSettingsTab;
        //! Week View tab.