Show confidential meeting details setting added
[qtmeetings] / src / UserInterface / Views / SettingsView.cpp
index d233662..fad4c15 100644 (file)
 #include "DisplaySettings.h"
 #include "ConnectionSettings.h"
 #include "StartupSettings.h"
+#include <QScrollArea>
 
 #include <QtDebug>
 
+#define QT_DELETE(X) \
+       if ( X != 0 ) \
+       { \
+               qDebug() << "delete " << X; \
+               delete X; \
+               X = 0; \
+       }
+
 SettingsView::SettingsView( QWidget *aParent ) :
                ViewBase( ViewBase::NormalView, aParent )
 {
@@ -45,6 +54,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,98 +64,37 @@ SettingsView::SettingsView( QWidget *aParent ) :
        mainLayout->addLayout( buttonLayout );
 
        setLayout( mainLayout );
+       setValues();
+
+       setAutoFillBackground( true );
 
        // Handle component connections
        connect( iOkButton, SIGNAL( clicked() ), this, SLOT( handleOkClicked() ) );
+       connect( iCancelButton, SIGNAL( clicked() ), this, SLOT( handleCancelClicked() ) );
 }
 
 SettingsView::~SettingsView()
 {
-       if ( iTabWidget != 0 )
-       {
-               delete iTabWidget;
-               iTabWidget = 0;
-       }
-       if ( iOkButton != 0 )
-       {
-               delete iOkButton;
-               iOkButton = 0;
-       }
-       if ( iSettingsTab != 0 )
-       {
-               delete iSettingsTab;
-               iSettingsTab = 0;
-       }
-       if ( iWeekViewTab != 0 )
-       {
-               delete iWeekViewTab;
-               iWeekViewTab = 0;
-       }
-       if ( iResourcesTab != 0 )
-       {
-               delete iResourcesTab;
-               iResourcesTab = 0;
-       }
-       if ( iKioskModeTab != 0 )
-       {
-               delete iKioskModeTab;
-               iKioskModeTab = 0;
-       }
-       if ( iUserName != 0 )
-       {
-               delete iUserName;
-               iUserName = 0;
-       }
-       if ( iPassword != 0 )
-       {
-               delete iPassword;
-               iPassword = 0;
-       }
-       if ( iServerAddress != 0 )
-       {
-               delete iServerAddress;
-               iServerAddress = 0;
-       }
-       if ( iDayStartTime != 0 )
-       {
-               delete iDayStartTime;
-               iDayStartTime = 0;
-       }
-       if ( iDayEndTime != 0 )
-       {
-               delete iDayEndTime;
-               iDayEndTime = 0;
-       }
-       if ( iFiveDays != 0 )
-       {
-               delete iFiveDays;
-               iFiveDays = 0;
-       }
-       if ( iSevenDays != 0 )
-       {
-               delete iSevenDays;
-               iSevenDays = 0;
-       }
-       if ( iRefreshInterval != 0 )
-       {
-               delete iRefreshInterval;
-               iRefreshInterval = 0;
-       }
-       if ( iPowerSaveEnabled != 0 )
-       {
-               delete iPowerSaveEnabled;
-               iPowerSaveEnabled = 0;
-       }
-       if ( iPowerSaveStartTime != 0 )
-       {
-               delete iPowerSaveStartTime;
-               iPowerSaveStartTime = 0;
-       }
-       if ( iPowerSaveEndTime != 0 )
-       {
-               delete iPowerSaveEndTime;
-               iPowerSaveEndTime = 0;
-       }
+       qDebug() << "[SettingsView::~SettingsView]";
+       /*QT_DELETE(iOkButton);
+       QT_DELETE(iCancelButton);
+       QT_DELETE(iUserName);
+       QT_DELETE(iPassword);
+       QT_DELETE(iServerAddress);
+       QT_DELETE(iDayStartTime);
+       QT_DELETE(iDayEndTime);
+       QT_DELETE(iFiveDays);
+       QT_DELETE(iSevenDays);
+       QT_DELETE(iRefreshInterval);
+       QT_DELETE(iPowerSaveEnabled);
+       QT_DELETE(iPowerSaveStartTime);
+       QT_DELETE(iPowerSaveEndTime);
+       QT_DELETE(iShowConfidentialMeetingDetails);
+       QT_DELETE(iSettingsTab);
+       QT_DELETE(iWeekViewTab);
+       QT_DELETE(iResourcesTab);
+       QT_DELETE(iKioskModeTab);
+       QT_DELETE(iTabWidget);*/
 }
 
 QWidget *SettingsView::initSettingsTab()
@@ -159,16 +110,10 @@ 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" ) );
+       QGroupBox *privacySettingsGroup = new QGroupBox( tr( "Privacy Settings" ) );
 
        // Prepare the user infromation group box
        QGridLayout *ugl = new QGridLayout;
@@ -196,14 +141,25 @@ QWidget *SettingsView::initSettingsTab()
 
        serverInformationGroup->setLayout( sgl );
 
+       // Prepare meeting info setting box
+       QGridLayout *pgl = new QGridLayout;
+       iShowConfidentialMeetingDetails = new QCheckBox( tr( "Show confidential meeting details" ) );
+
+       pgl->addWidget( iShowConfidentialMeetingDetails, 0, 0 );
+
+       privacySettingsGroup->setLayout( pgl );
+       
        // Prepare and set the main layout
        QVBoxLayout *mainLayout = new QVBoxLayout;
        mainLayout->addWidget( userInformationGroup );
        mainLayout->addWidget( serverInformationGroup );
+       mainLayout->addWidget( privacySettingsGroup );
 
        widget->setLayout( mainLayout );
 
-       return widget;
+       QScrollArea *scroll = new QScrollArea;
+       scroll->setWidget(widget);
+       return scroll;
 }
 
 QWidget *SettingsView::initWeekViewTab()
@@ -216,19 +172,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;
@@ -259,7 +202,9 @@ QWidget *SettingsView::initWeekViewTab()
 
        widget->setLayout( mainLayout );
 
-       return widget;
+       QScrollArea *scroll = new QScrollArea;
+       scroll->setWidget(widget);
+       return scroll;
 }
 
 QWidget *SettingsView::initResourcesTab()
@@ -306,7 +251,9 @@ QWidget *SettingsView::initResourcesTab()
 
        widget->setLayout( mainLayout );
 
-       return widget;
+       QScrollArea *scroll = new QScrollArea;
+       scroll->setWidget(widget);
+       return scroll;
 }
 
 QWidget *SettingsView::initKioskModeTab()
@@ -328,7 +275,7 @@ QWidget *SettingsView::initKioskModeTab()
        }
        iPowerSaveStartTime->setTime( Configuration::instance()->startupSettings()->turnOnAt() );
        iPowerSaveEndTime->setTime( Configuration::instance()->startupSettings()->turnOffAt() );
-
+       
        // Prepare the admin password box
        QGroupBox *adminPasswordGroup = new QGroupBox( tr( "Admin Password" ) );
        QLabel *oldPwdLabel = new QLabel( tr( "Old password:" ) );
@@ -377,7 +324,9 @@ QWidget *SettingsView::initKioskModeTab()
 
        widget->setLayout( mainLayout );
 
-       return widget;
+       QScrollArea *scroll = new QScrollArea;
+       scroll->setWidget(widget);
+       return scroll;
 }
 
 void SettingsView::handleOkClicked()
@@ -393,21 +342,110 @@ 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
+       bool showConfidentialMeetingDetails = iShowConfidentialMeetingDetails->isChecked();
+       
+       // set values to Configuration
+       // set user information
+       Configuration::instance()->setUsername(userName);//connectionSettings()->setUsername( userName );
+       Configuration::instance()->setPassword(password);//connectionSettings()->setPassword( password );
+       
+       // set server information
+       Configuration::instance()->setServerUrl(serverAddress);//connectionSettings()->setServerUrl( serverAddress );
+       if ( ok )
+       {
+               Configuration::instance()->setRefreshinterval(refreshInterval);//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 );
+       
+       // set privacy settings
+       Configuration::instance()->setShowConfidentialMeetingDetails( showConfidentialMeetingDetails );
+       
+       qDebug() << "[SettingsView::okClicked] save()";
+       
+       // save configuration
+       Configuration::instance()->save();
+
+       qDebug() << "[SettingsView::okClicked] setValues()";
        
        // Emit the signal to notify that ok is pressed and data is saved.
+       setValues();
        emit okClicked();
 }
 
-void SettingsView::viewResized(const QSize &size)
+void SettingsView::viewResized(const QSize &newSize, const QSize &oldSize)
+{
+       if ( oldSize.height() > newSize.height() )
+       {
+               // Get the button's height and add that to the new size so that
+               // the ok button is hidden under the keyboard.
+               size().rheight() += iOkButton->size().height();
+       }
+}
+
+void SettingsView::handleCancelClicked()
+{
+       setValues();
+       emit cancelClicked();
+}
+
+void SettingsView::setValues()
 {
-       qDebug() << "[SettingsView::viewResized] <Invoked>";
+       // set user information
+       iUserName->setText( Configuration::instance()->getUsername() );
+       iPassword->setText( Configuration::instance()->getPassword());//connectionSettings()->password() );
+       // set server information
+       iServerAddress->setText( Configuration::instance()->getServerUrl().toString());//connectionSettings()->serverUrl().toString() );
+       QString refreshIntervalStr;
+       refreshIntervalStr.setNum( Configuration::instance()->getRefreshinterval());//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() );
        
-       qDebug() << "[SettingsView::viewResized] <Finished>";
-}
\ No newline at end of file
+       // set privacy settings
+       iShowConfidentialMeetingDetails->setChecked( Configuration::instance()->showConfidentialMeetingDetails() );
+}