Initial commit
[tietoopcom] / src / TocUi / TocThemesSettingsWidget.cpp
1 /** \file TocThemesSettingsWidget.cpp
2  * \brief Implementation of TocThemesSettingsWidget 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 "TocThemesSettingsWidget"
33 #include "ui_TocThemesSettingsWidget.h"
34 #include "macros.h"
35
36 #include <TocSettings>
37 #include <QListWidgetItem>
38 #include <QShowEvent>
39 #include <QDebug>
40
41
42 TocThemesSettingsWidget::TocThemesSettingsWidget(QWidget *parent, Qt::WindowFlags flags)
43         : QWidget(parent, flags) {
44         
45         ui = new Ui_TocThemesSettingsWidgetClass();
46         ui->setupUi(this);
47         setContentsMargins(-10, -10, -10, -10);
48         
49         ui->applyThemeButton->setText(tr("Apply"));
50         ui->backThemeButton->setText(tr("Back"));
51
52         //TODO: functionality is not implemented. Add Theme button is hidden. 
53         ui->addThemeButton->setVisible(false);
54         ui->addThemeButton->setText(tr("Add theme"));
55
56 #ifdef QT_NO_DEBUG
57   #define ssPath        QString("/usr/share/tietoopcom/stylesheets/")
58 #else
59   #define ssPath        QString("./data/stylesheets/")
60 #endif
61
62         qDebug() << ssPath;
63
64         QListWidgetItem* pItem = new QListWidgetItem("Default theme", ui->themesListWidget);
65         pItem->setToolTip(ssPath + "default.qss");
66
67         pItem = new QListWidgetItem("My theme", ui->themesListWidget);
68         pItem->setToolTip(ssPath + "my.qss");
69
70         CONNECT(ui->backThemeButton,SIGNAL(clicked()),this,SIGNAL(backClicked()));
71         CONNECT(ui->applyThemeButton,SIGNAL(clicked()),this,SLOT(saveThemesSettings()));
72 }
73
74 TocThemesSettingsWidget::~TocThemesSettingsWidget() {
75         delete ui;
76 }
77
78 void TocThemesSettingsWidget::showEvent( QShowEvent* event ) {
79
80         TocSettings* pSettings = TocSettings::getInstance();
81         for(int i = 0; i < ui->themesListWidget->count(); ++i)
82                 if(ui->themesListWidget->item(i)->toolTip() == pSettings->currentTheme()) {
83                         ui->themesListWidget->setCurrentRow(i);
84                 }
85         event->accept();
86 }
87
88 void TocThemesSettingsWidget::saveThemesSettings() {
89
90         TocSettings* pSettings = TocSettings::getInstance();
91
92         QListWidgetItem* pThemesListItem = ui->themesListWidget->currentItem();
93         if(!pThemesListItem)
94                 return;
95
96         QString themeUrl = pThemesListItem->toolTip();
97         if(themeUrl == pSettings->currentTheme())
98                 return;
99
100         pSettings->setCurrentTheme(themeUrl);
101         emit currentThemeChanged();
102 }