Initial commit
[tietoopcom] / src / TocUi / TocGeneralSettingsWidget.cpp
1 /** \file TocGeneralSettingsWidget.cpp
2  * \brief Implementation of TocGeneralSettingsWidget class
3  * 
4  * Tieto Open Communicator - Client for the Telepathy communications framework.
5  * Copyright (c) 2010, Tieto Corporation
6  *
7  * All rights reserved.
8  * Redistribution and use in source and binary forms, with or without modification,
9  * are permitted provided that the following conditions are met:
10  *
11  *      Redistributions of source code must retain the above copyright notice,
12  *      this list of conditions and the following disclaimer.
13  *      Redistributions in binary form must reproduce the above copyright notice,
14  *      this list of conditions and the following disclaimer in the documentation
15  *      and/or other materials provided with the distribution.
16  *      Neither the name of the Tieto Corporation nor the names of its contributors 
17  *      may be used to endorse or promote products derived from this software without
18  *      specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23  * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  * 
30  */
31  
32 #include "TocGeneralSettingsWidget"
33 #include "ui_TocGeneralSettingsWidget.h"
34
35 #include "TocSettings"
36 #include "macros.h"
37
38 #include <QtDebug>
39 #include <QCommonStyle>
40
41 TocGeneralSettingsWidget::TocGeneralSettingsWidget(QWidget * parent, Qt::WindowFlags flags)
42         : QWidget(parent, flags) {
43         
44           
45         setStyle(new QCommonStyle());
46         ui = new Ui_TocGeneralSettingsWidgetClass();
47         ui->setupUi( this );
48         setContentsMargins( -10, -10, -10, -10 );
49
50         TocSettings* pSettings = TocSettings::getInstance();
51
52         /*ui->alphaRadioButton->setAttribute(Qt::WA_TranslucentBackground, true);
53         ui->presenceRadioButton->setAttribute(Qt::WA_TranslucentBackground, false);
54         ui->dragDropRadioButton->setAttribute(Qt::WA_TranslucentBackground, false);
55         ui->acceptRadioButton->setAttribute(Qt::WA_TranslucentBackground, false);
56         ui->askRadioButton->setAttribute(Qt::WA_TranslucentBackground, false);
57         ui->denyRadioButton->setAttribute(Qt::WA_TranslucentBackground, false);*/
58         
59         switch( pSettings->sortOrder() ) {
60         case Alphabetical:
61                 ui->alphaRadioButton->setChecked( true );
62                 break;
63         //TODO: To be implemented.
64         /*case ByStatus:
65                 ui->presenceRadioButton->setChecked( true );
66                 break;
67         case None:
68                 ui->dragDropRadioButton->setChecked( true );
69                 break;*/
70         default:
71                 ui->alphaRadioButton->setChecked( true );
72         }
73
74         switch( pSettings->authorizationRule() ) {
75         case AlwaysAccept:
76                 ui->acceptRadioButton->setChecked( true );
77                 break;
78         //TODO: To be implemented.
79         /*case Ask:
80                 ui->askRadioButton->setChecked( true );
81                 break;
82         case AlwaysDeny:
83                 ui->denyRadioButton->setChecked( true );
84                 break;*/
85         default:
86                 //TODO: Change to the commented one when implementation will be done. 
87                 //ui->askRadioButton->setChecked( true );
88                 ui->acceptRadioButton->setChecked( true );
89         }
90
91         CONNECT(ui->okButton, SIGNAL(clicked()), this, SLOT(saveGeneralSettings()));
92         CONNECT(ui->backButton, SIGNAL(clicked()), this, SIGNAL(backClicked()));
93         
94 }
95
96 TocGeneralSettingsWidget::~TocGeneralSettingsWidget() {
97         delete ui;
98 }
99
100 void TocGeneralSettingsWidget::saveGeneralSettings() {
101
102         TocSettings* pSettings = TocSettings::getInstance();
103
104         if( ui->alphaRadioButton->isChecked() )
105                 pSettings->setSortOrder( Alphabetical );
106         else if( ui->presenceRadioButton->isChecked() )
107                 pSettings->setSortOrder( ByStatus );
108         else if( ui->dragDropRadioButton->isChecked() )
109                 pSettings->setSortOrder( None );
110
111         if( ui->askRadioButton->isChecked() )
112                 pSettings->setAuthorizationRule( Ask );
113         else if( ui->acceptRadioButton->isChecked() )
114                 pSettings->setAuthorizationRule( AlwaysAccept );
115         else if( ui->denyRadioButton->isChecked() )
116                 pSettings->setAuthorizationRule( AlwaysDeny );
117
118         emit finished();
119 }