1/*
2 * KCMDesktopTheme
3 * Copyright (C) 2002 Karol Szwed <gallium@kde.org>
4 * Copyright (C) 2002 Daniel Molkentin <molkentin@kde.org>
5 * Copyright (C) 2007 Urs Wolfer <uwolfer @ kde.org>
6 * Copyright (C) 2009 by Davide Bettio <davide.bettio@kdemail.net>
7
8 * Portions Copyright (C) 2007 Paolo Capriotti <p.capriotti@gmail.com>
9 * Portions Copyright (C) 2007 Ivan Cukic <ivan.cukic+kde@gmail.com>
10 * Portions Copyright (C) 2008 by Petri Damsten <damu@iki.fi>
11 * Portions Copyright (C) 2000 TrollTech AS.
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public
15 * License version 2 as published by the Free Software Foundation.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; see the file COPYING. If not, write to
24 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 * Boston, MA 02110-1301, USA.
26 */
27
28#include "kcmdesktoptheme.h"
29
30#include "thememodel.h"
31
32
33#include <kaboutdata.h>
34#include <kautostart.h>
35#include <KStandardDirs>
36#include <knewstuff3/downloaddialog.h>
37
38#include <Plasma/Theme>
39
40/**** DLL Interface for kcontrol ****/
41
42#include <kpluginfactory.h>
43#include <kpluginloader.h>
44
45K_PLUGIN_FACTORY(KCMDesktopThemeFactory, registerPlugin<KCMDesktopTheme>();)
46K_EXPORT_PLUGIN(KCMDesktopThemeFactory("kcmdesktoptheme","kcm_desktopthemedetails"))
47
48
49KCMDesktopTheme::KCMDesktopTheme( QWidget* parent, const QVariantList& )
50 : KCModule( KCMDesktopThemeFactory::componentData(), parent )
51{
52 setQuickHelp( i18n("<h1>Desktop Theme</h1>"
53 "This module allows you to modify the visual appearance "
54 "of the desktop."));
55
56 setupUi(this);
57
58 m_bDesktopThemeDirty = false;
59 m_bDetailsDirty = false;
60
61 KAutostart plasmaNetbookAutoStart("plasma-netbook");
62 m_isNetbook = plasmaNetbookAutoStart.autostarts();
63
64 KGlobal::dirs()->addResourceType("themes", "data", "kstyle/themes");
65
66 KAboutData *about =
67 new KAboutData( I18N_NOOP("KCMDesktopTheme"), 0,
68 ki18n("KDE Desktop Theme Module"),
69 0, KLocalizedString(), KAboutData::License_GPL,
70 ki18n("(c) 2002 Karol Szwed, Daniel Molkentin"));
71
72 about->addAuthor(ki18n("Karol Szwed"), KLocalizedString(), "gallium@kde.org");
73 about->addAuthor(ki18n("Daniel Molkentin"), KLocalizedString(), "molkentin@kde.org");
74 about->addAuthor(ki18n("Ralf Nolden"), KLocalizedString(), "nolden@kde.org");
75 setAboutData( about );
76
77 m_newThemeButton->setIcon(KIcon("get-hot-new-stuff"));
78
79 m_themeModel = new ThemeModel(this);
80 m_theme->setModel(m_themeModel);
81 m_theme->setItemDelegate(new ThemeDelegate(m_theme));
82 m_theme->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
83
84 connect(m_detailsWidget, SIGNAL(changed()), this, SLOT(detailChanged()));
85
86 connect(m_theme->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
87 this, SLOT(setDesktopThemeDirty()));
88 connect(m_newThemeButton, SIGNAL(clicked()), this, SLOT(getNewThemes()));
89}
90
91
92KCMDesktopTheme::~KCMDesktopTheme()
93{
94}
95
96void KCMDesktopTheme::load()
97{
98 KConfig config( "kdeglobals", KConfig::FullConfig );
99
100 loadDesktopTheme();
101
102 m_bDesktopThemeDirty = false;
103 m_bDetailsDirty = false;
104
105 emit changed( false );
106}
107
108
109void KCMDesktopTheme::save()
110{
111 // Don't do anything if we don't need to.
112 if ( !( m_bDesktopThemeDirty) && !(m_bDetailsDirty) )
113 return;
114
115 //Desktop theme
116 if ( m_bDesktopThemeDirty )
117 {
118 QString theme = m_themeModel->data(m_theme->currentIndex(), ThemeModel::PackageNameRole).toString();
119 if (m_isNetbook) {
120 KConfigGroup cg(KSharedConfig::openConfig("plasmarc"), "Theme-plasma-netbook");
121 cg.writeEntry("name", theme);
122 } else {
123 Plasma::Theme::defaultTheme()->setThemeName(theme);
124 }
125 }
126
127 if (m_bDetailsDirty)
128 {
129 m_detailsWidget->save();
130 }
131
132 // Clean up
133 m_bDesktopThemeDirty = false;
134 m_bDetailsDirty = false;
135 emit changed( false );
136}
137
138void KCMDesktopTheme::defaults()
139{
140 // TODO: reset back to default theme?
141}
142
143void KCMDesktopTheme::setDesktopThemeDirty()
144{
145 m_bDesktopThemeDirty = true;
146 emit changed(true);
147}
148
149void KCMDesktopTheme::getNewThemes()
150{
151 KNS3::DownloadDialog dialog("plasma-themes.knsrc", this);
152 dialog.exec();
153 KNS3::Entry::List entries = dialog.changedEntries();
154
155 if (entries.size() > 0) {
156 loadDesktopTheme();
157 }
158}
159
160void KCMDesktopTheme::loadDesktopTheme()
161{
162 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
163 m_themeModel->reload();
164 QString themeName;
165 if (m_isNetbook) {
166 KConfigGroup cg(KSharedConfig::openConfig("plasmarc"), "Theme-plasma-netbook");
167 themeName = cg.readEntry("name", "air-netbook");
168 } else {
169 themeName = Plasma::Theme::defaultTheme()->themeName();
170 }
171 m_theme->setCurrentIndex(m_themeModel->indexOf(themeName));
172 QApplication::restoreOverrideCursor();
173}
174
175void KCMDesktopTheme::detailChanged()
176{
177 m_bDetailsDirty = true;
178 emit changed(true);
179}
180
181#include "kcmdesktoptheme.moc"
182
183// vim: set noet ts=4:
184