Show confidential meeting details setting added
[qtmeetings] / src / UserInterface / Views / SettingsView.cpp
1 #include "SettingsView.h"
2
3 #include <QTabWidget>
4 #include <QVBoxLayout>
5 #include <QHBoxLayout>
6 #include <QPushButton>
7 #include <QGroupBox>
8 #include <QLabel>
9 #include <QLineEdit>
10 #include <QRadioButton>
11 #include <QTimeEdit>
12 #include <QListView>
13 #include <QList>
14 #include <QTime>
15 #include <QIntValidator>
16 #include <QGridLayout>
17 #include <QCheckBox>
18 #include "Configuration.h"
19 #include "Room.h"
20 #include "DisplaySettings.h"
21 #include "ConnectionSettings.h"
22 #include "StartupSettings.h"
23 #include <QScrollArea>
24
25 #include <QtDebug>
26
27 #define QT_DELETE(X) \
28         if ( X != 0 ) \
29         { \
30                 qDebug() << "delete " << X; \
31                 delete X; \
32                 X = 0; \
33         }
34
35 SettingsView::SettingsView( QWidget *aParent ) :
36                 ViewBase( ViewBase::NormalView, aParent )
37 {
38         qDebug() << "SettingsView::ctor invoked";
39         // Prepare the tabbed view
40         iTabWidget = new QTabWidget;
41
42         iSettingsTab = initSettingsTab();
43         iWeekViewTab = initWeekViewTab();
44         iResourcesTab = initResourcesTab();
45         iKioskModeTab = initKioskModeTab();
46
47         iTabWidget->addTab( iSettingsTab, tr( "Settings" ) );
48         iTabWidget->addTab( iWeekViewTab, tr( "Weekly View" ) );
49         iTabWidget->addTab( iResourcesTab, tr( "Resources" ) );
50         iTabWidget->addTab( iKioskModeTab, tr( "KIOSK Mode" ) );
51
52         // Prepare the buttons and button layout
53         QHBoxLayout *buttonLayout = new QHBoxLayout;
54         iOkButton = new QPushButton;
55         iOkButton->setText( tr( "OK" ) );
56         buttonLayout->addWidget( iOkButton );
57         iCancelButton = new QPushButton;
58         iCancelButton->setText( tr( "Cancel" ));
59         buttonLayout->addWidget( iCancelButton );
60
61         // Handle the main layout
62         QVBoxLayout *mainLayout = new QVBoxLayout;
63         mainLayout->addWidget( iTabWidget );
64         mainLayout->addLayout( buttonLayout );
65
66         setLayout( mainLayout );
67         setValues();
68
69         setAutoFillBackground( true );
70
71         // Handle component connections
72         connect( iOkButton, SIGNAL( clicked() ), this, SLOT( handleOkClicked() ) );
73         connect( iCancelButton, SIGNAL( clicked() ), this, SLOT( handleCancelClicked() ) );
74 }
75
76 SettingsView::~SettingsView()
77 {
78         qDebug() << "[SettingsView::~SettingsView]";
79         /*QT_DELETE(iOkButton);
80         QT_DELETE(iCancelButton);
81         QT_DELETE(iUserName);
82         QT_DELETE(iPassword);
83         QT_DELETE(iServerAddress);
84         QT_DELETE(iDayStartTime);
85         QT_DELETE(iDayEndTime);
86         QT_DELETE(iFiveDays);
87         QT_DELETE(iSevenDays);
88         QT_DELETE(iRefreshInterval);
89         QT_DELETE(iPowerSaveEnabled);
90         QT_DELETE(iPowerSaveStartTime);
91         QT_DELETE(iPowerSaveEndTime);
92         QT_DELETE(iShowConfidentialMeetingDetails);
93         QT_DELETE(iSettingsTab);
94         QT_DELETE(iWeekViewTab);
95         QT_DELETE(iResourcesTab);
96         QT_DELETE(iKioskModeTab);
97         QT_DELETE(iTabWidget);*/
98 }
99
100 QWidget *SettingsView::initSettingsTab()
101 {
102         QWidget *widget = new QWidget( iTabWidget );
103
104         // Prepare the widgets that are member variables
105         iUserName = new QLineEdit;
106         iPassword = new QLineEdit;
107         iPassword->setEchoMode( QLineEdit::Password );
108         iServerAddress = new QLineEdit;
109         iRefreshInterval = new QLineEdit;
110         QIntValidator *qiv = new QIntValidator( 0 );
111         iRefreshInterval->setValidator( qiv );
112
113         // Create the group boxes
114         QGroupBox *userInformationGroup = new QGroupBox( tr( "User Information" ) );
115         QGroupBox *serverInformationGroup = new QGroupBox( tr( "Server Information" ) );
116         QGroupBox *privacySettingsGroup = new QGroupBox( tr( "Privacy Settings" ) );
117
118         // Prepare the user infromation group box
119         QGridLayout *ugl = new QGridLayout;
120         QLabel *userNameLabel = new QLabel( tr( "Username:" ) );
121         QLabel *passwordLabel = new QLabel( tr( "Password:" ) );
122
123         ugl->addWidget( userNameLabel, 0, 0 );
124         ugl->addWidget( iUserName, 0, 1 );
125         ugl->addWidget( passwordLabel, 1, 0 );
126         ugl->addWidget( iPassword, 1, 1 );
127
128         userInformationGroup->setLayout( ugl );
129
130         // Prepare the server information group box
131         QGridLayout *sgl = new QGridLayout;
132         QLabel *serverURLLabel = new QLabel( tr( "Server URL:" ) );
133         QLabel *refreshLabel = new QLabel( tr( "Refresh interval" ) );
134         QLabel *secondsLabel = new QLabel( tr( "seconds" ) );
135
136         sgl->addWidget( serverURLLabel, 0, 0, 1, 2 );
137         sgl->addWidget( iServerAddress, 0, 1 );
138         sgl->addWidget( refreshLabel, 1, 0 );
139         sgl->addWidget( iRefreshInterval, 1, 1 );
140         sgl->addWidget( secondsLabel, 1, 2 );
141
142         serverInformationGroup->setLayout( sgl );
143
144         // Prepare meeting info setting box
145         QGridLayout *pgl = new QGridLayout;
146         iShowConfidentialMeetingDetails = new QCheckBox( tr( "Show confidential meeting details" ) );
147
148         pgl->addWidget( iShowConfidentialMeetingDetails, 0, 0 );
149
150         privacySettingsGroup->setLayout( pgl );
151         
152         // Prepare and set the main layout
153         QVBoxLayout *mainLayout = new QVBoxLayout;
154         mainLayout->addWidget( userInformationGroup );
155         mainLayout->addWidget( serverInformationGroup );
156         mainLayout->addWidget( privacySettingsGroup );
157
158         widget->setLayout( mainLayout );
159
160         QScrollArea *scroll = new QScrollArea;
161         scroll->setWidget(widget);
162         return scroll;
163 }
164
165 QWidget *SettingsView::initWeekViewTab()
166 {
167         QWidget *widget = new QWidget( iTabWidget );
168
169         // Prepare the member variable widgets
170         iFiveDays = new QRadioButton( tr( "5" ) );
171         iSevenDays = new QRadioButton( tr( "7" ) );
172         iDayStartTime = new QTimeEdit;
173         iDayEndTime = new QTimeEdit;
174
175         // Create group box and the grid layout
176         QGroupBox *weeklyInformation = new QGroupBox( tr( "Weekly View" ) );
177         QGridLayout *wgl = new QGridLayout;
178
179         // Prepare the number of days row
180         QLabel *daysLabel = new QLabel( tr( "Days:" ) );
181
182         wgl->addWidget( daysLabel, 0, 0 );
183         wgl->addWidget( iFiveDays, 0, 1 );
184         wgl->addWidget( iSevenDays, 0, 2 );
185
186         // Preare the day starts row
187         QLabel *dayStartsLabel = new QLabel( tr( "Day starts:" ) );
188
189         wgl->addWidget( dayStartsLabel, 1, 0 );
190         wgl->addWidget( iDayStartTime, 1, 1, 1, 2 );
191
192         // Prepare the day ends row
193         QLabel *dayEndsLabel = new QLabel( tr( "Day ends:" ) );
194
195         wgl->addWidget( dayEndsLabel, 2, 0 );
196         wgl->addWidget( iDayEndTime, 2, 1, 1, 2 );
197
198         weeklyInformation->setLayout( wgl );
199
200         QVBoxLayout *mainLayout = new QVBoxLayout;
201         mainLayout->addWidget( weeklyInformation );
202
203         widget->setLayout( mainLayout );
204
205         QScrollArea *scroll = new QScrollArea;
206         scroll->setWidget(widget);
207         return scroll;
208 }
209
210 QWidget *SettingsView::initResourcesTab()
211 {
212         QWidget *widget = new QWidget( iTabWidget );
213
214         QHBoxLayout *mainLayout = new QHBoxLayout;
215
216         // Available resources
217         QVBoxLayout *availableResourcesLayout = new QVBoxLayout;
218         QLabel *availableResourcesLabel = new QLabel( tr( "Available Resources:" ) );
219         QListView *availableResourcesList = new QListView;
220
221         // Fill the list
222         QList<Room*> rooms = Configuration::instance()->rooms();
223         for ( int i = 0; i < rooms.count(); i++ )
224         {
225                 Room *tmp_room = ( Room * ) rooms.at( i );
226                 qDebug() << "Room: " << tmp_room->name();
227         }
228
229         availableResourcesLayout->addWidget( availableResourcesLabel );
230         availableResourcesLayout->addWidget( availableResourcesList );
231
232         // Selected resources
233         QVBoxLayout *selectedResourcesLayout = new QVBoxLayout;
234         QLabel *selectedResourcesLabel = new QLabel( tr( "Selected Resources:" ) );
235         QListView *selectedResourcesList = new QListView;
236
237         selectedResourcesLayout->addWidget( selectedResourcesLabel );
238         selectedResourcesLayout->addWidget( selectedResourcesList );
239
240         // Button lauout
241         QVBoxLayout *controlButtonsLayout = new QVBoxLayout;
242         QPushButton *addButton = new QPushButton( tr( "->" ) );
243         QPushButton *removeButton = new QPushButton( tr( "<-" ) );
244         controlButtonsLayout->addWidget( addButton );
245         controlButtonsLayout->addWidget( removeButton );
246
247         // Prepare main layout
248         mainLayout->addLayout( availableResourcesLayout );
249         mainLayout->addLayout( controlButtonsLayout );
250         mainLayout->addLayout( selectedResourcesLayout );
251
252         widget->setLayout( mainLayout );
253
254         QScrollArea *scroll = new QScrollArea;
255         scroll->setWidget(widget);
256         return scroll;
257 }
258
259 QWidget *SettingsView::initKioskModeTab()
260 {
261         QWidget *widget = new QWidget( iTabWidget );
262
263         // Prepare member variable widgets
264         iPowerSaveEnabled = new QCheckBox( tr( "Power save enabled" ) );
265         iPowerSaveStartTime = new QTimeEdit;
266         iPowerSaveEndTime = new QTimeEdit;
267
268         if ( Configuration::instance()->startupSettings()->isPowersavingEnabled() )
269         {
270                 iPowerSaveEnabled->setChecked( true );
271         }
272         else
273         {
274                 iPowerSaveEnabled->setChecked( false );
275         }
276         iPowerSaveStartTime->setTime( Configuration::instance()->startupSettings()->turnOnAt() );
277         iPowerSaveEndTime->setTime( Configuration::instance()->startupSettings()->turnOffAt() );
278         
279         // Prepare the admin password box
280         QGroupBox *adminPasswordGroup = new QGroupBox( tr( "Admin Password" ) );
281         QLabel *oldPwdLabel = new QLabel( tr( "Old password:" ) );
282         QLabel *newPwdLabel = new QLabel( tr( "New password:" ) );
283         QLabel *confirmPwdLabel = new QLabel( tr( "Confirm password:" ) );
284         QPushButton *applyPwdButton = new QPushButton( tr( "Apply" ) );
285
286         QLineEdit *oldPwdEdit = new QLineEdit;
287         QLineEdit *newPwdEdit = new QLineEdit;
288         QLineEdit *confirmPwdEdit = new QLineEdit;
289
290         oldPwdEdit->setEchoMode( QLineEdit::Password );
291         newPwdEdit->setEchoMode( QLineEdit::Password );
292         confirmPwdEdit->setEchoMode( QLineEdit::Password );
293
294         QGridLayout *agl = new QGridLayout;
295
296         agl->addWidget( oldPwdLabel, 0, 0 );
297         agl->addWidget( oldPwdEdit, 0, 1 );
298         agl->addWidget( newPwdLabel, 1, 0 );
299         agl->addWidget( newPwdEdit, 1, 1 );
300         agl->addWidget( confirmPwdLabel, 2, 0 );
301         agl->addWidget( confirmPwdEdit, 2, 1 );
302         agl->addWidget( applyPwdButton, 3, 0, 1, 2, Qt::AlignRight );
303
304         adminPasswordGroup->setLayout( agl );
305
306         // Prepare the power save options
307         QGroupBox *powerSaveGroup = new QGroupBox( tr( "Power Save" ) );
308         QLabel *switchedOnLabel = new QLabel( tr( "Switched on from:" ) );
309         QLabel *toLabel = new QLabel( tr( "to" ) );
310         QGridLayout *psgl = new QGridLayout;
311
312         psgl->addWidget( iPowerSaveEnabled, 0, 0, 1, 4, Qt::AlignLeft );
313         psgl->addWidget( switchedOnLabel, 1, 0 );
314         psgl->addWidget( iPowerSaveStartTime, 1, 1 );
315         psgl->addWidget( toLabel, 1, 2 );
316         psgl->addWidget( iPowerSaveEndTime, 1, 3 );
317
318         powerSaveGroup->setLayout( psgl );
319
320         // Prepare the main layout
321         QVBoxLayout *mainLayout = new QVBoxLayout;
322         mainLayout->addWidget( adminPasswordGroup );
323         mainLayout->addWidget( powerSaveGroup );
324
325         widget->setLayout( mainLayout );
326
327         QScrollArea *scroll = new QScrollArea;
328         scroll->setWidget(widget);
329         return scroll;
330 }
331
332 void SettingsView::handleOkClicked()
333 {
334         qDebug() << "[SettingsView::okClicked] <Invoked>";
335
336         // Collect the configration data
337         QTime calendarStart = iDayStartTime->time();
338         QTime calendarEnd = iDayEndTime->time();
339         QTime powerSaveStart = iPowerSaveStartTime->time();
340         QTime powerSaveEnd = iPowerSaveEndTime->time();
341
342         QString userName = iUserName->text();
343         QString password = iPassword->text();
344         QString serverAddress = iServerAddress->text();
345         bool ok;
346         uint refreshInterval = iRefreshInterval->text().toUInt(&ok, 10);
347
348         bool fiveDays = iFiveDays->isChecked();
349         bool sevenDays = iSevenDays->isChecked();
350         bool powerSaveEnabled = iPowerSaveEnabled->isChecked();
351
352         bool showConfidentialMeetingDetails = iShowConfidentialMeetingDetails->isChecked();
353         
354         // set values to Configuration
355         // set user information
356         Configuration::instance()->setUsername(userName);//connectionSettings()->setUsername( userName );
357         Configuration::instance()->setPassword(password);//connectionSettings()->setPassword( password );
358         
359         // set server information
360         Configuration::instance()->setServerUrl(serverAddress);//connectionSettings()->setServerUrl( serverAddress );
361         if ( ok )
362         {
363                 Configuration::instance()->setRefreshinterval(refreshInterval);//connectionSettings()->setRefreshInterval( refreshInterval );
364         }
365         
366         // set weekly view settings
367         if ( fiveDays )
368         {
369                 Configuration::instance()->displaySettings()->setDaysInSchedule( DisplaySettings::WeekdaysInSchedule );
370         }
371         else if ( sevenDays )
372         {
373                 Configuration::instance()->displaySettings()->setDaysInSchedule( DisplaySettings::WholeWeekInSchedule );
374         }
375         Configuration::instance()->displaySettings()->setDayStartsAt( calendarStart );
376         Configuration::instance()->displaySettings()->setDayEndsAt( calendarEnd );
377         
378         // set power save settings
379         Configuration::instance()->startupSettings()->setPowersavingEnabled( powerSaveEnabled );
380         Configuration::instance()->startupSettings()->setTurnOnAt( powerSaveStart );
381         Configuration::instance()->startupSettings()->setTurnOffAt( powerSaveEnd );
382         
383         // set privacy settings
384         Configuration::instance()->setShowConfidentialMeetingDetails( showConfidentialMeetingDetails );
385         
386         qDebug() << "[SettingsView::okClicked] save()";
387         
388         // save configuration
389         Configuration::instance()->save();
390
391         qDebug() << "[SettingsView::okClicked] setValues()";
392         
393         // Emit the signal to notify that ok is pressed and data is saved.
394         setValues();
395         emit okClicked();
396 }
397
398 void SettingsView::viewResized(const QSize &newSize, const QSize &oldSize)
399 {
400         if ( oldSize.height() > newSize.height() )
401         {
402                 // Get the button's height and add that to the new size so that
403                 // the ok button is hidden under the keyboard.
404                 size().rheight() += iOkButton->size().height();
405         }
406 }
407
408 void SettingsView::handleCancelClicked()
409 {
410         setValues();
411         emit cancelClicked();
412 }
413
414 void SettingsView::setValues()
415 {
416         // set user information
417         iUserName->setText( Configuration::instance()->getUsername() );
418         iPassword->setText( Configuration::instance()->getPassword());//connectionSettings()->password() );
419         // set server information
420         iServerAddress->setText( Configuration::instance()->getServerUrl().toString());//connectionSettings()->serverUrl().toString() );
421         QString refreshIntervalStr;
422         refreshIntervalStr.setNum( Configuration::instance()->getRefreshinterval());//connectionSettings()->refreshInterval() );
423         iRefreshInterval->setText( refreshIntervalStr );
424         // set weekly view display settings
425         if ( Configuration::instance()->displaySettings()->daysInSchedule() == DisplaySettings::WeekdaysInSchedule )
426         {
427                 iFiveDays->setChecked( true );
428                 iSevenDays->setChecked( false );
429         }
430         else
431         {
432                 iFiveDays->setChecked( false );
433                 iSevenDays->setChecked( true );
434         }
435         iDayStartTime->setTime( Configuration::instance()->displaySettings()->dayStartsAt() );
436         iDayEndTime->setTime( Configuration::instance()->displaySettings()->dayEndsAt() );
437         // set startup settings
438         if ( Configuration::instance()->startupSettings()->isPowersavingEnabled() )
439         {
440                 iPowerSaveEnabled->setChecked( true );
441         }
442         else
443         {
444                 iPowerSaveEnabled->setChecked( false );
445         }
446         iPowerSaveStartTime->setTime( Configuration::instance()->startupSettings()->turnOnAt() );
447         iPowerSaveEndTime->setTime( Configuration::instance()->startupSettings()->turnOffAt() );
448         
449         // set privacy settings
450         iShowConfidentialMeetingDetails->setChecked( Configuration::instance()->showConfidentialMeetingDetails() );
451 }