• Skip to content
  • Skip to link menu
KDE 4.4 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

Plasma

backgrounddialog.cpp

Go to the documentation of this file.
00001 /*
00002   Copyright (c) 2007 Paolo Capriotti <p.capriotti@gmail.com>
00003   Copyright (C) 2007 Ivan Cukic <ivan.cukic+kde@gmail.com>
00004   Copyright (c) 2008 by Petri Damsten <damu@iki.fi>
00005 
00006   This program is free software; you can redistribute it and/or modify
00007   it under the terms of the GNU General Public License as published by
00008   the Free Software Foundation; either version 2 of the License, or
00009   (at your option) any later version.
00010 */
00011 
00012 #include "backgrounddialog.h"
00013 
00014 //#include <QFile>
00015 //#include <QAbstractItemView>
00016 //#include <QStandardItemModel>
00017 
00018 //#include <KStandardDirs>
00019 //#include <KDesktopFile>
00020 //#include <KColorScheme>
00021 
00022 #include <Plasma/Containment>
00023 #include <Plasma/FrameSvg>
00024 #include <Plasma/Wallpaper>
00025 #include <Plasma/View>
00026 //#include <Plasma/Corona>
00027 
00028 #include "plasmaapp.h"
00029 #include "plasmagenericshell/wallpaperpreview.h"
00030 
00031 #include "../../../libs/kworkspace/screenpreviewwidget.h"
00032 
00033 typedef QPair<QString, QString> WallpaperInfo;
00034 Q_DECLARE_METATYPE(WallpaperInfo)
00035 
00036 
00037 BackgroundDialog::BackgroundDialog(const QSize& res, Plasma::Containment *c, Plasma::View* view, QWidget* parent)
00038     : KDialog(parent),
00039       m_wallpaper(0),
00040       m_view(view),
00041       m_containment(c),
00042       m_preview(0)
00043 {
00044     //setWindowIcon(KIcon("preferences-desktop-wallpaper"));
00045     setCaption(i18n("Background Settings"));
00046     showButtonSeparator(true);
00047     setButtons(Ok | Cancel | Apply);
00048 
00049     QWidget * main = new QWidget(this);
00050     setupUi(main);
00051 
00052     // Size of monitor image: 200x186
00053     // Geometry of "display" part of monitor image: (23,14)-[151x115]
00054     qreal previewRatio = (qreal)res.width() / (qreal)res.height();
00055     QSize monitorSize(200, int(200 * previewRatio));
00056 
00057     m_monitor->setFixedSize(200,200);
00058     m_monitor->setText(QString());
00059     m_monitor->setWhatsThis(i18n(
00060         "This picture of a monitor contains a preview of "
00061         "what the current settings will look like on your desktop."));
00062     m_preview = new ScreenPreviewWidget(m_monitor);
00063     m_preview->setRatio(previewRatio);
00064     m_preview->resize(200,200);
00065 
00066     connect(this, SIGNAL(finished(int)), this, SLOT(cleanup()));
00067     connect(this, SIGNAL(okClicked()), this, SLOT(saveConfig()));
00068     connect(this, SIGNAL(applyClicked()), this, SLOT(saveConfig()));
00069 
00070     setMainWidget(main);
00071     reloadConfig();
00072     adjustSize();
00073 }
00074 
00075 BackgroundDialog::~BackgroundDialog()
00076 {
00077     cleanup();
00078 }
00079 
00080 void BackgroundDialog::cleanup()
00081 {
00082     //FIXME could be bad if we get hidden and reshown
00083     delete m_wallpaper;
00084     m_wallpaper = 0;
00085 }
00086 
00087 void BackgroundDialog::reloadConfig()
00088 {
00089     //transparency
00090     m_activeSlider->setValue(PlasmaApp::self()->activeOpacity() * 10);
00091     m_idleSlider->setValue(PlasmaApp::self()->idleOpacity() * 10);
00092 
00093     label->setVisible(PlasmaApp::hasComposite());
00094     m_activeSlider->setVisible(PlasmaApp::hasComposite());
00095 
00096     // Wallpaper
00097     disconnect(m_wallpaperMode, SIGNAL(currentIndexChanged(int)), this, SLOT(changeBackgroundMode(int)));
00098     int wallpaperIndex = 0;
00099 
00100     bool doWallpaper = m_containment->drawWallpaper() && ! PlasmaApp::hasComposite();
00101     m_wallpaperLabel->setVisible(doWallpaper);
00102     m_wallpaperTypeLabel->setVisible(doWallpaper);
00103     m_wallpaperMode->setVisible(doWallpaper);
00104     m_wallpaperConfig->setVisible(doWallpaper);
00105     m_monitor->setVisible(doWallpaper);
00106     m_preview->setVisible(doWallpaper);
00107     if (doWallpaper) {
00108         // Load wallpaper plugins
00109         QString currentPlugin;
00110         QString currentMode;
00111 
00112         Plasma::Wallpaper *currentWallpaper = m_containment->wallpaper();
00113         if (currentWallpaper) {
00114             currentPlugin = currentWallpaper->pluginName();
00115             currentMode = currentWallpaper->renderingMode().name();
00116         }
00117 
00118         const KPluginInfo::List plugins = Plasma::Wallpaper::listWallpaperInfo();
00119         m_wallpaperMode->clear();
00120         int i = 0;
00121         QString placeholder = i18n("No Wallpaper");
00122         //m_wallpaperMode->addItem(KIcon(), i18n("No Wallpaper"),
00123         //                         QVariant::fromValue(WallpaperInfo(QString(), QString())));
00124         foreach (const KPluginInfo& info, plugins) {
00125             bool matches = info.pluginName() == currentPlugin;
00126             const QList<KServiceAction>& modes = info.service()->actions();
00127             if (modes.count() > 0) {
00128                 foreach (const KServiceAction& mode, modes) {
00129                     m_wallpaperMode->addItem(KIcon(mode.icon()), mode.text(),
00130                                     QVariant::fromValue(WallpaperInfo(info.pluginName(), mode.name())));
00131                     if (matches && mode.name() == currentMode) {
00132                         wallpaperIndex = i;
00133                     }
00134                     ++i;
00135                 }
00136             } else {
00137                 m_wallpaperMode->addItem(KIcon(info.icon()), info.name(),
00138                                 QVariant::fromValue(WallpaperInfo(info.pluginName(), QString())));
00139                 if (matches) {
00140                     wallpaperIndex = i;
00141                 }
00142                 ++i;
00143             }
00144         }
00145         m_wallpaperMode->setCurrentIndex(wallpaperIndex);
00146         changeBackgroundMode(wallpaperIndex);
00147     }
00148 
00149     connect(m_wallpaperMode, SIGNAL(currentIndexChanged(int)), this, SLOT(changeBackgroundMode(int)));
00150 }
00151 
00152 void BackgroundDialog::changeBackgroundMode(int mode)
00153 {
00154     kDebug();
00155     QWidget* w = 0;
00156     WallpaperInfo wallpaperInfo = m_wallpaperMode->itemData(mode).value<WallpaperInfo>();
00157 
00158     if (!m_wallpaperConfig->layout()) {
00159         new QVBoxLayout(m_wallpaperConfig);
00160     }
00161 
00162     if (m_wallpaperConfig->layout()->count() > 0) {
00163         delete dynamic_cast<QWidgetItem*>(m_wallpaperConfig->layout()->takeAt(0))->widget();
00164     }
00165 
00166     if (m_wallpaper && m_wallpaper->pluginName() != wallpaperInfo.first) {
00167         delete m_wallpaper;
00168         m_wallpaper = 0;
00169     }
00170 
00171     if (wallpaperInfo.first.isEmpty()) {
00172         return;
00173     }
00174 
00175     if (!m_wallpaper) {
00176         m_wallpaper = Plasma::Wallpaper::load(wallpaperInfo.first);
00177         m_preview->setPreview(m_wallpaper);
00178     }
00179 
00180     if (m_wallpaper) {
00181         m_wallpaper->setRenderingMode(wallpaperInfo.second);
00182         KConfigGroup cfg = wallpaperConfig(wallpaperInfo.first);
00183         kDebug() << "making a" << wallpaperInfo.first << "in mode" << wallpaperInfo.second;
00184         m_wallpaper->restore(cfg);
00185         w = m_wallpaper->createConfigurationInterface(m_wallpaperConfig);
00186     }
00187 
00188     if (!w) {
00189         w = new QWidget(m_wallpaperConfig);
00190     }
00191 
00192     m_wallpaperConfig->layout()->addWidget(w);
00193 }
00194 
00195 KConfigGroup BackgroundDialog::wallpaperConfig(const QString &plugin)
00196 {
00197     Q_ASSERT(m_containment);
00198 
00199     //FIXME: we have details about the structure of the containment config duplicated here!
00200     KConfigGroup cfg = m_containment->config();
00201     cfg = KConfigGroup(&cfg, "Wallpaper");
00202     return KConfigGroup(&cfg, plugin);
00203 }
00204 
00205 void BackgroundDialog::saveConfig()
00206 {
00207     //transparency
00208     PlasmaApp::self()->setActiveOpacity(m_activeSlider->value() / 10.0);
00209     PlasmaApp::self()->setIdleOpacity(m_idleSlider->value() / 10.0);
00210 
00211     // Wallpaper
00212     QString wallpaperPlugin = m_wallpaperMode->itemData(m_wallpaperMode->currentIndex()).value<WallpaperInfo>().first;
00213     QString wallpaperMode = m_wallpaperMode->itemData(m_wallpaperMode->currentIndex()).value<WallpaperInfo>().second;
00214 
00215     Plasma::Wallpaper *currentWallpaper = m_containment->wallpaper();
00216     if (currentWallpaper) {
00217         KConfigGroup cfg = wallpaperConfig(currentWallpaper->pluginName());
00218         currentWallpaper->save(cfg);
00219     }
00220 
00221     if (m_wallpaper) {
00222         KConfigGroup cfg = wallpaperConfig(m_wallpaper->pluginName());
00223         m_wallpaper->save(cfg);
00224     }
00225 
00226     m_containment->setWallpaper(wallpaperPlugin, wallpaperMode);
00227 }

Plasma

Skip menu "Plasma"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • KWin
  •   KWin Libraries
  • Libraries
  •   libkworkspace
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •     Animators
  •     Applets
  •     Engines
  • Solid Modules
  • System Settings
  •   SystemSettingsView
Generated for API Reference by doxygen 1.5.9-20090814
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal