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