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), buttonClicked_(false), themeScheduler_(0)
38 setWindowTitle(tr("Select theme"));
40 QHBoxLayout* layout = new QHBoxLayout;
41 QVBoxLayout* left = new QVBoxLayout;
42 QHBoxLayout* first = new QHBoxLayout;
44 QPushButton* saveButton = new QPushButton(tr("Save"));
45 connect(saveButton, SIGNAL(clicked(bool)), this, SLOT(saveTheme()));
46 QDialogButtonBox* buttons = new QDialogButtonBox;
47 buttons->setCenterButtons(false);
48 buttons->setOrientation(Qt::Vertical);
49 buttons->addButton(saveButton, QDialogButtonBox::AcceptRole);
51 selector_ = new ThemePicker(tr("Theme"), this);
52 connect(selector_, SIGNAL(clicked(bool)), this, SLOT(enableDisableScheduler()));
53 connect(selector_, SIGNAL(selected()), this, SLOT(disableScheduler()));
55 QPushButton* loadButton = new QPushButton(tr("Import"));
56 connect(loadButton, SIGNAL(clicked(bool)), this, SLOT(loadFromFile()));
58 QPushButton* scheduler = new QPushButton(tr("Theme scheduler"));
59 connect(scheduler, SIGNAL(clicked(bool)), this, SLOT(openScheduler()));
61 first->addWidget(selector_, Qt::AlignLeft);
62 first->addWidget(loadButton);
64 left->addLayout(first);
65 left->addWidget(scheduler);
67 layout->addLayout(left, Qt::AlignLeft);
68 layout->addWidget(buttons);
74 void ThemeSelector::saveTheme()
76 QString theme = selector_->value().toString();
77 Settings::instance().setValue("theme", theme);
82 void ThemeSelector::loadFromFile()
86 if(selector_->importFile(ThemeLoader::getThemeDir(),
88 "*" + ThemeLoader::getThemeSuffix(),
92 selector_->loadThemes();
93 selector_->selectTheme(file);
97 void ThemeSelector::openScheduler()
101 themeScheduler_ = new ThemeSchedulerSettings(this);
102 connect(themeScheduler_, SIGNAL(themeChanged()), this, SIGNAL(themeChanged()));
105 themeScheduler_->show();
108 void ThemeSelector::enableDisableScheduler()
110 buttonClicked_ = true;
113 void ThemeSelector::disableScheduler()
115 if(buttonClicked_ && ThemeScheduler::instance().isEnabled())
117 QMaemo5InformationBox::information(this, tr("Disabling theme scheduler..."), 1000);
118 ThemeScheduler::instance().setEnabled(false);
122 void ThemeSelector::setVisible(bool visible)
124 buttonClicked_ = false;
126 QDialog::setVisible(visible);