Settings saved with ok and cancel added to SettingsView.
authoritkonma <marko.itkonen@ixonos.com>
Fri, 29 May 2009 10:11:03 +0000 (13:11 +0300)
committeritkonma <marko.itkonen@ixonos.com>
Fri, 29 May 2009 10:11:03 +0000 (13:11 +0300)
TODO: application restart needed after saving settings.

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..ab1bad2 100644 (file)
@@ -98,6 +98,7 @@ void UIManager::createSettingsView()
        
        // Connect signals
        connect( iSettingsView, SIGNAL( okClicked() ), this, SLOT( settingsOkClicked() ) );
+       connect( iSettingsView, SIGNAL( cancelClicked() ), this, SLOT( settingsCancelClicked() ) );
 }
 
 void UIManager::createRoomStatusIndicator()
@@ -298,3 +299,13 @@ void UIManager::hideProgressBar()
                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();
+       }
+}
\ No newline at end of file
index de123b6..0c40c2b 100644 (file)
@@ -37,6 +37,7 @@ public slots:
 
        void settingsViewRequest();
        void settingsOkClicked();
+       void settingsCancelClicked();
        void roomStatusIndicatorRequested();
        void previousViewRestored();
        void changeModeOrdered( DeviceManager::OperationMode aMode );
index 0076e23..9872192 100644 (file)
@@ -155,21 +155,41 @@ void Configuration::saveConnectionSettings( const QDomNode &aXML )
        {
                QDomElement e = node.toElement();
                QString tagName = e.tagName().toLower();
-
                if ( tagName == QString( "serverurl" ) )
                {
                        QDomText t = node.ownerDocument().createTextNode( iConnectionSettings->serverUrl().toString() );
-                       e.replaceChild( t, e.firstChild() );
+                       if ( e.childNodes().length() == 0 )
+                       {
+                               e.appendChild( t );
+                       }
+                       else
+                       {
+                               e.replaceChild( t, e.firstChild() );
+                       }
                }
                else if ( tagName == QString( "username" ) )
                {
                        QDomText t = node.ownerDocument().createTextNode( iConnectionSettings->username() );
-                       e.replaceChild( t, e.firstChild() );
+                       if ( e.childNodes().length() == 0 )
+                       {
+                               e.appendChild( t );
+                       }
+                       else
+                       {
+                               e.replaceChild( t, e.firstChild() );
+                       }
                }
                else if ( tagName == QString( "password" ) )
                {
                        QDomText t = node.ownerDocument().createTextNode( iConnectionSettings->password() );
-                       e.replaceChild( t, e.firstChild() );
+                       if ( e.childNodes().length() == 0 )
+                       {
+                               e.appendChild( t );
+                       }
+                       else
+                       {
+                               e.replaceChild( t, e.firstChild() );
+                       }
                }
                else if ( tagName == QString( "refreshinterval" ) )
                {
@@ -182,6 +202,7 @@ void Configuration::saveConnectionSettings( const QDomNode &aXML )
 
 void Configuration::saveRooms( const QDomNode &aXML )
 {
+       qDebug() << "saveRooms";
        //! List of rooms must be cleared and rewritten again
        QDomDocument doc = aXML.ownerDocument();
        QDomNode root = aXML; 
@@ -190,19 +211,19 @@ void Configuration::saveRooms( const QDomNode &aXML )
        int count = root.childNodes().count();
        QDomNode node = root.firstChild();
        QDomNode next;
-       for (int i=0; i<count; i++)
+       for (int i = 0; i < count; i++)
        {
                qDebug() << "remove " << node.toElement().text();
                next = node.nextSibling();
                node = root.removeChild(node);
                node = next;
        }
-
        QList<Room*>::iterator i;
        for ( i = iRooms.begin(); i != iRooms.end(); ++i )
        {
                QDomElement tag = doc.createElement( "room" );
-               node.appendChild( tag );
+               qDebug() << "write room: " << ( *i )->name() << " to node " << node.toElement().tagName();
+               root.appendChild( tag );
 
                // First room in the list is a dafault room
                if ( i == iRooms.begin() )
@@ -442,6 +463,7 @@ QList<Room*> Configuration::readRooms( const QDomNode &aXML )
                                if ( tagName == QString( "name" ) )
                                {
                                        name = roomElem.text();
+                                       qDebug() << "got room: " << name;
                                }
                                else if ( tagName == QString( "address" ) )
                                {
@@ -619,7 +641,7 @@ DateTimeSettings * Configuration::readDateTimeSettings( const QDomNode &aXML )
                        
                        bool success = false;
                        unsigned int weekDayTmp = e.text().toUInt( &success );
-                       if( success && weekDayTmp >= 0 && weekDayTmp < 7)
+                       if( success && weekDayTmp < 7 )
                        {
                                dayOfWeek = (DateTimeSettings::weekDay)weekDayTmp;
                        }
index 1021d77..75dc85a 100644 (file)
@@ -45,6 +45,9 @@ SettingsView::SettingsView( QWidget *aParent ) :
        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;
@@ -52,9 +55,11 @@ SettingsView::SettingsView( QWidget *aParent ) :
        mainLayout->addLayout( buttonLayout );
 
        setLayout( mainLayout );
+       setValues();
 
        // Handle component connections
        connect( iOkButton, SIGNAL( clicked() ), this, SLOT( handleOkClicked() ) );
+       connect( iCancelButton, SIGNAL( clicked() ), this, SLOT( handleCancelClicked() ) );
 }
 
 SettingsView::~SettingsView()
@@ -159,13 +164,6 @@ QWidget *SettingsView::initSettingsTab()
        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" ) );
@@ -216,19 +214,6 @@ QWidget *SettingsView::initWeekViewTab()
        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;
@@ -393,13 +378,44 @@ void SettingsView::handleOkClicked()
        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();
 
-       // 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 okClicked();
@@ -413,4 +429,46 @@ void SettingsView::viewResized(const QSize &newSize, const QSize &oldSize)
                // 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();
        
+       void cancelClicked();
+       
 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.
@@ -46,11 +50,15 @@ private:
        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;
+       //! Cancel button to dismiss the settings view without saving the settings
+       QPushButton *iCancelButton;
        //! Settings tab.
        QWidget *iSettingsTab;
        //! Week View tab.