2 * This file is part of jSpeed.
4 * jSpeed is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * jSpeed is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with jSpeed. If not, see <http://www.gnu.org/licenses/>.
19 #include <QtCore/QDir>
20 #include <QtCore/QDebug>
21 #include <QtCore/QString>
22 #include <QtCore/QStringList>
23 #include <QtGui/QFileDialog>
24 #include <QtGui/QDialogButtonBox>
25 #include <QtGui/QPushButton>
26 #include <QtGui/QHBoxLayout>
27 #include <QtGui/QVBoxLayout>
28 #include <QtGui/QMessageBox>
29 #include <QMaemo5InformationBox>
30 #include "themeselector.h"
31 #include "themepicker.h"
32 #include "themeloader.h"
34 #include "themeschedulersettings.h"
36 ThemeSelector::ThemeSelector(QWidget* parent): QDialog(parent),
37 buttonClicked_(false), themeSelected_(false), themeScheduler_(0)
39 setWindowTitle(tr("Select theme"));
41 QHBoxLayout* layout = new QHBoxLayout;
42 QVBoxLayout* left = new QVBoxLayout;
43 QHBoxLayout* first = new QHBoxLayout;
45 QPushButton* saveButton = new QPushButton(tr("Save"));
46 connect(saveButton, SIGNAL(clicked(bool)), this, SLOT(saveTheme()));
47 QDialogButtonBox* buttons = new QDialogButtonBox;
48 buttons->setCenterButtons(false);
49 buttons->setOrientation(Qt::Vertical);
50 buttons->addButton(saveButton, QDialogButtonBox::AcceptRole);
52 selector_ = new ThemePicker(tr("Theme"), this);
53 connect(selector_, SIGNAL(clicked(bool)), this, SLOT(setButtonClicked()));
54 connect(selector_, SIGNAL(selected()), this, SLOT(setThemeSelected()));
56 QPushButton* loadButton = new QPushButton(tr("Import"));
57 connect(loadButton, SIGNAL(clicked(bool)), this, SLOT(loadFromFile()));
59 QPushButton* scheduler = new QPushButton(tr("Theme scheduler"));
60 connect(scheduler, SIGNAL(clicked(bool)), this, SLOT(openScheduler()));
62 first->addWidget(selector_, Qt::AlignLeft);
63 first->addWidget(loadButton);
65 left->addLayout(first);
66 left->addWidget(scheduler);
68 layout->addLayout(left, Qt::AlignLeft);
69 layout->addWidget(buttons);
75 void ThemeSelector::saveTheme()
77 QString theme = selector_->value().toString();
78 Settings::instance().setValue("theme", theme);
81 if(buttonClicked_ && themeSelected_ && ThemeScheduler::instance().isEnabled())
83 QMaemo5InformationBox::information(this, tr("Disabling theme scheduler..."), 1000);
84 ThemeScheduler::instance().setEnabled(false);
85 themeSelected_ = false;
86 buttonClicked_ = false;
92 void ThemeSelector::loadFromFile()
96 if(selector_->importFile(ThemeLoader::getThemeDir(),
98 "*" + ThemeLoader::getThemeSuffix(),
102 selector_->loadThemes();
103 selector_->selectTheme(file);
107 void ThemeSelector::openScheduler()
111 themeScheduler_ = new ThemeSchedulerSettings(this);
112 connect(themeScheduler_, SIGNAL(themeChanged()), this, SLOT(onThemeChanged()));
115 themeScheduler_->show();
118 void ThemeSelector::setButtonClicked()
120 buttonClicked_ = true;
123 void ThemeSelector::setThemeSelected()
125 themeSelected_ = true;
128 void ThemeSelector::onThemeChanged()
130 buttonClicked_ = false;
131 themeSelected_ = false;
136 void ThemeSelector::setVisible(bool visible)
138 QDialog::setVisible(visible);