2011-09-23 22:06:21 +02:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
2011-12-15 18:34:48 +01:00
|
|
|
* Copyright (C) 2010-2011 David Rosca <nowrep@gmail.com>
|
2011-09-23 22:06:21 +02:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
* ============================================================ */
|
2011-09-11 19:15:06 +02:00
|
|
|
#include "thememanager.h"
|
|
|
|
#include "ui_thememanager.h"
|
|
|
|
#include "mainapplication.h"
|
2011-09-18 15:35:44 +02:00
|
|
|
#include "globalfunctions.h"
|
2011-09-11 19:15:06 +02:00
|
|
|
|
|
|
|
ThemeManager::ThemeManager(QWidget* parent)
|
|
|
|
: QWidget()
|
|
|
|
, ui(new Ui::ThemeManager)
|
|
|
|
{
|
|
|
|
ui->setupUi(parent);
|
2011-09-18 15:35:44 +02:00
|
|
|
ui->license->hide();
|
2011-11-06 17:01:23 +01:00
|
|
|
QSettings settings(mApp->getActiveProfilPath() + "settings.ini", QSettings::IniFormat);
|
2011-09-11 19:15:06 +02:00
|
|
|
settings.beginGroup("Themes");
|
2011-10-17 09:57:07 +02:00
|
|
|
m_activeTheme = settings.value("activeTheme",
|
|
|
|
#ifdef Q_WS_X11
|
|
|
|
"linux"
|
|
|
|
#else
|
|
|
|
"windows"
|
|
|
|
#endif
|
2011-11-06 17:01:23 +01:00
|
|
|
).toString();
|
2011-09-11 19:15:06 +02:00
|
|
|
settings.endGroup();
|
|
|
|
|
|
|
|
QDir themeDir(mApp->THEMESDIR);
|
|
|
|
QStringList list = themeDir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot);
|
|
|
|
foreach(QString name, list) {
|
|
|
|
Theme themeInfo = parseTheme(name);
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!themeInfo.isValid) {
|
2011-09-11 19:15:06 +02:00
|
|
|
continue;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-09-11 19:15:06 +02:00
|
|
|
|
|
|
|
QListWidgetItem* item = new QListWidgetItem(ui->listWidget);
|
|
|
|
item->setText(themeInfo.name + "\n" + themeInfo.shortDescription);
|
|
|
|
item->setIcon(themeInfo.icon);
|
|
|
|
item->setData(Qt::UserRole, name);
|
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
if (m_activeTheme == name) {
|
2011-09-11 19:15:06 +02:00
|
|
|
ui->listWidget->setCurrentItem(item);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-09-11 19:15:06 +02:00
|
|
|
|
|
|
|
ui->listWidget->addItem(item);
|
|
|
|
}
|
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
connect(ui->listWidget, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, SLOT(currentChanged()));
|
2011-09-18 15:35:44 +02:00
|
|
|
connect(ui->license, SIGNAL(clicked(QPoint)), this, SLOT(showLicense()));
|
2011-09-11 19:15:06 +02:00
|
|
|
|
|
|
|
currentChanged();
|
|
|
|
}
|
|
|
|
|
2011-09-18 15:35:44 +02:00
|
|
|
void ThemeManager::showLicense()
|
|
|
|
{
|
|
|
|
QListWidgetItem* currentItem = ui->listWidget->currentItem();
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!currentItem) {
|
2011-09-18 15:35:44 +02:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-09-18 15:35:44 +02:00
|
|
|
|
|
|
|
Theme currentTheme = m_themeHash[currentItem->data(Qt::UserRole).toString()];
|
|
|
|
|
|
|
|
QTextBrowser* b = new QTextBrowser();
|
|
|
|
b->setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
b->setWindowTitle(tr("License Viewer"));
|
|
|
|
// b->move(mapToGlobal(parent()->pos()));
|
|
|
|
b->resize(450, 500);
|
|
|
|
b->setText(currentTheme.license);
|
2011-09-23 19:42:34 +02:00
|
|
|
qz_centerWidgetOnScreen(b);
|
2011-09-18 15:35:44 +02:00
|
|
|
b->show();
|
|
|
|
}
|
|
|
|
|
2011-09-11 19:15:06 +02:00
|
|
|
void ThemeManager::currentChanged()
|
|
|
|
{
|
|
|
|
QListWidgetItem* currentItem = ui->listWidget->currentItem();
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!currentItem) {
|
2011-09-11 19:15:06 +02:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-09-11 19:15:06 +02:00
|
|
|
|
|
|
|
Theme currentTheme = m_themeHash[currentItem->data(Qt::UserRole).toString()];
|
|
|
|
|
|
|
|
ui->name->setText(currentTheme.name);
|
|
|
|
ui->author->setText(currentTheme.author);
|
|
|
|
ui->descirption->setText(currentTheme.longDescription);
|
2011-09-18 15:35:44 +02:00
|
|
|
ui->license->setHidden(currentTheme.license.isEmpty());
|
2011-09-11 19:15:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ThemeManager::Theme ThemeManager::parseTheme(const QString &name)
|
|
|
|
{
|
|
|
|
Theme info;
|
|
|
|
info.name = name;
|
|
|
|
|
|
|
|
QString path = mApp->THEMESDIR + name + "/";
|
|
|
|
if (!QFile(path + "main.css").exists() || !QFile(path + "theme.info").exists()) {
|
|
|
|
info.isValid = false;
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
if (QFile(path + "theme.png").exists()) {
|
2011-09-11 19:15:06 +02:00
|
|
|
info.icon = QIcon(path + "theme.png");
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
|
|
|
else {
|
2011-09-11 19:15:06 +02:00
|
|
|
info.icon = QIcon(":icons/preferences/style-default.png");
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-09-11 19:15:06 +02:00
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
if (QFile(path + "theme.license").exists()) {
|
2011-09-18 15:35:44 +02:00
|
|
|
info.license = qz_readAllFileContents(path + "theme.license");
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-09-18 15:35:44 +02:00
|
|
|
|
|
|
|
QString theme_info = qz_readAllFileContents(path + "theme.info");
|
2011-09-11 19:15:06 +02:00
|
|
|
|
|
|
|
QRegExp rx("Name:(.*)\\n");
|
|
|
|
rx.setMinimal(true);
|
|
|
|
rx.indexIn(theme_info);
|
2011-11-06 17:01:23 +01:00
|
|
|
if (rx.captureCount() == 1) {
|
2011-09-11 19:15:06 +02:00
|
|
|
info.name = rx.cap(1).trimmed();
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-09-11 19:15:06 +02:00
|
|
|
|
|
|
|
rx.setPattern("Author:(.*)\\n");
|
|
|
|
rx.indexIn(theme_info);
|
2011-11-06 17:01:23 +01:00
|
|
|
if (rx.captureCount() == 1) {
|
2011-09-11 19:15:06 +02:00
|
|
|
info.author = rx.cap(1).trimmed();
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-09-11 19:15:06 +02:00
|
|
|
|
|
|
|
rx.setPattern("Short Description:(.*)\\n");
|
|
|
|
rx.indexIn(theme_info);
|
2011-11-06 17:01:23 +01:00
|
|
|
if (rx.captureCount() == 1) {
|
2011-09-11 19:15:06 +02:00
|
|
|
info.shortDescription = rx.cap(1).trimmed();
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-09-11 19:15:06 +02:00
|
|
|
|
|
|
|
rx.setPattern("Long Description:(.*)\\n");
|
|
|
|
rx.indexIn(theme_info);
|
2011-11-06 17:01:23 +01:00
|
|
|
if (rx.captureCount() == 1) {
|
2011-09-11 19:15:06 +02:00
|
|
|
info.longDescription = rx.cap(1).trimmed();
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-09-11 19:15:06 +02:00
|
|
|
|
|
|
|
info.isValid = true;
|
|
|
|
m_themeHash.insert(name, info);
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ThemeManager::save()
|
|
|
|
{
|
2011-11-06 17:01:23 +01:00
|
|
|
QSettings settings(mApp->getActiveProfilPath() + "settings.ini", QSettings::IniFormat);
|
2011-09-11 19:15:06 +02:00
|
|
|
settings.beginGroup("Themes");
|
|
|
|
settings.setValue("activeTheme", ui->listWidget->currentItem()->data(Qt::UserRole));
|
|
|
|
settings.endGroup();
|
|
|
|
}
|
|
|
|
|
|
|
|
ThemeManager::~ThemeManager()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|