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

Plasma

desktopcorona.cpp

Go to the documentation of this file.
00001 /*
00002  *   Copyright 2008 Aaron Seigo <aseigo@kde.org>
00003  *
00004  *   This program is free software; you can redistribute it and/or modify
00005  *   it under the terms of the GNU Library General Public License as
00006  *   published by the Free Software Foundation; either version 2, or
00007  *   (at your option) any later version.
00008  *
00009  *   This program is distributed in the hope that it will be useful,
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *   GNU General Public License for more details
00013  *
00014  *   You should have received a copy of the GNU Library General Public
00015  *   License along with this program; if not, write to the
00016  *   Free Software Foundation, Inc.,
00017  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00018  */
00019 
00020 #include "desktopcorona.h"
00021 
00022 #include <QApplication>
00023 #include <QDir>
00024 #include <QGraphicsLayout>
00025 #include <QTimer>
00026 
00027 #include <KDebug>
00028 #include <KDialog>
00029 #include <KGlobalSettings>
00030 #include <KStandardDirs>
00031 #include <KWindowSystem>
00032 
00033 #include <Plasma/Containment>
00034 #include <Plasma/DataEngineManager>
00035 
00036 #include <kephal/screens.h>
00037 
00038 #include "panelview.h"
00039 #include "plasmaapp.h"
00040 #include "plasma-shell-desktop.h"
00041 
00042 DesktopCorona::DesktopCorona(QObject *parent)
00043     : Plasma::Corona(parent)
00044 {
00045     init();
00046 }
00047 
00048 void DesktopCorona::init()
00049 {
00050     Kephal::Screens *screens = Kephal::Screens::self();
00051     connect(screens, SIGNAL(screenAdded(Kephal::Screen *)), SLOT(screenAdded(Kephal::Screen *)));
00052     connect(KWindowSystem::self(), SIGNAL(workAreaChanged()), this, SIGNAL(availableScreenRegionChanged()));
00053 }
00054 
00055 void DesktopCorona::checkScreens()
00056 {
00057     // quick sanity check to ensure we have containments for each screen
00058     int numScreens = Kephal::ScreenUtils::numScreens();
00059     for (int i = 0; i < numScreens; ++i) {
00060         checkScreen(i);
00061     }
00062 }
00063 
00064 void DesktopCorona::checkScreen(int screen, bool signalWhenExists)
00065 {
00066     if (AppSettings::perVirtualDesktopViews()) {
00067         int numDesktops = KWindowSystem::numberOfDesktops();
00068 
00069         for (int j = 0; j < numDesktops; ++j) {
00070             Plasma::Containment *c = containmentForScreen(screen, j);
00071 
00072             if (!c) {
00073                 addDesktopContainment(screen, j);
00074             } else if (signalWhenExists) {
00075                 emit containmentAdded(c);
00076             }
00077         }
00078     } else {
00079         Plasma::Containment *c = containmentForScreen(screen);
00080         if (!containmentForScreen(screen)) {
00081             addDesktopContainment(screen);
00082         } else if (signalWhenExists) {
00083             emit containmentAdded(c);
00084         }
00085     }
00086 }
00087 
00088 void DesktopCorona::addDesktopContainment(int screen, int desktop)
00089 {
00090     kDebug() << screen << desktop;
00091     Plasma::Containment* c = addContainment("desktop");
00092     c->setScreen(screen, desktop);
00093     c->setFormFactor(Plasma::Planar);
00094     c->flushPendingConstraintsEvents();
00095     c->setActivity(i18n("Desktop"));
00096     emit containmentAdded(c);
00097 }
00098 
00099 int DesktopCorona::numScreens() const
00100 {
00101     return Kephal::ScreenUtils::numScreens();
00102 }
00103 
00104 QRect DesktopCorona::screenGeometry(int id) const
00105 {
00106     return Kephal::ScreenUtils::screenGeometry(id);
00107 }
00108 
00109 QRegion DesktopCorona::availableScreenRegion(int id) const
00110 {
00111     QRegion r(screenGeometry(id));
00112     foreach (PanelView *view, PlasmaApp::self()->panelViews()) {
00113         if (view->screen() == id && view->visibilityMode() == PanelView::NormalPanel) {
00114             r = r.subtracted(view->geometry());
00115         }
00116     }
00117 
00118     return r;
00119 }
00120 
00121 void DesktopCorona::loadDefaultLayout()
00122 {
00123     QString defaultConfig = KStandardDirs::locate("appdata", "plasma-default-layoutrc");
00124     if (!defaultConfig.isEmpty()) {
00125         kDebug() << "attempting to load the default layout from:" << defaultConfig;
00126         loadLayout(defaultConfig);
00127         return;
00128     }
00129 
00130     kDebug() << "number of screens is" << Kephal::ScreenUtils::numScreens();
00131     int topLeftScreen = 0;
00132     QPoint topLeftCorner = Kephal::ScreenUtils::screenGeometry(0).topLeft();
00133 
00134     // find our "top left" screen, use it as the primary
00135     for (int i = 0; i < Kephal::ScreenUtils::numScreens(); ++i) {
00136         QRect g = Kephal::ScreenUtils::screenGeometry(i);
00137         kDebug() << "     screen " << i << "geometry is" << g;
00138 
00139         if (g.x() <= topLeftCorner.x() && g.y() >= topLeftCorner.y()) {
00140             topLeftCorner = g.topLeft();
00141             topLeftScreen = i;
00142         }
00143     }
00144 
00145     // create a containment for each screen
00146     for (int i = 0; i < Kephal::ScreenUtils::numScreens(); ++i) {
00147         // passing in an empty string will get us whatever the default
00148         // containment type is!
00149         Plasma::Containment* c = addContainmentDelayed(QString());
00150 
00151         if (!c) {
00152             continue;
00153         }
00154 
00155         c->init();
00156         c->setScreen(i, 0);
00157         c->setWallpaper("image", "SingleImage");
00158         c->setFormFactor(Plasma::Planar);
00159         c->updateConstraints(Plasma::StartupCompletedConstraint);
00160         c->flushPendingConstraintsEvents();
00161 
00162         // put a folder view on the first screen
00163         if (i == topLeftScreen) {
00164             QString desktopPath = KGlobalSettings::desktopPath();
00165             QDir desktopFolder(desktopPath);
00166             if (desktopPath != QDir::homePath() && desktopFolder.exists()) {
00167                 Plasma::Applet *folderView =  Plasma::Applet::load("folderview", c->id() + 1);
00168                 if (folderView) {
00169                     c->addApplet(folderView, QPointF(KDialog::spacingHint(), KDialog::spacingHint()), true);
00170                     KConfigGroup config = folderView->config();
00171                     config.writeEntry("url", "desktop:/");
00172                 }
00173             }
00174         }
00175 
00176         emit containmentAdded(c);
00177     }
00178 
00179     // make a panel at the bottom
00180     Plasma::Containment *panel = addContainmentDelayed("panel");
00181 
00182     if (!panel) {
00183         return;
00184     }
00185 
00186     panel->init();
00187     panel->setScreen(topLeftScreen);
00188     panel->setLocation(Plasma::BottomEdge);
00189     panel->updateConstraints(Plasma::StartupCompletedConstraint);
00190     panel->flushPendingConstraintsEvents();
00191 
00192     // some default applets to get a usable UI
00193     Plasma::Applet *applet = loadDefaultApplet("launcher", panel);
00194     if (applet) {
00195         applet->setGlobalShortcut(KShortcut("Alt+F1"));
00196     }
00197 
00198     loadDefaultApplet("notifier", panel);
00199     loadDefaultApplet("pager", panel);
00200     loadDefaultApplet("tasks", panel);
00201     loadDefaultApplet("systemtray", panel);
00202 
00203     Plasma::DataEngineManager *engines = Plasma::DataEngineManager::self();
00204     Plasma::DataEngine *power = engines->loadEngine("powermanagement");
00205     if (power) {
00206         const QStringList &batteries = power->query("Battery")["sources"].toStringList();
00207         if (!batteries.isEmpty()) {
00208             loadDefaultApplet("battery", panel);
00209         }
00210     }
00211     engines->unloadEngine("powermanagement");
00212 
00213     loadDefaultApplet("digital-clock", panel);
00214     emit containmentAdded(panel);
00215 
00216     QTimer::singleShot(1000, this, SLOT(saveDefaultSetup()));
00217 }
00218 
00219 void DesktopCorona::saveDefaultSetup()
00220 {
00221     // a "null" KConfigGroup is used to force a save into the config file
00222     KConfigGroup invalidConfig;
00223 
00224     foreach (Plasma::Containment *containment, containments()) {
00225         containment->save(invalidConfig);
00226 
00227         foreach (Plasma::Applet* applet, containment->applets()) {
00228             applet->init();
00229             applet->flushPendingConstraintsEvents();
00230             applet->save(invalidConfig);
00231         }
00232     }
00233 
00234     requestConfigSync();
00235 }
00236 
00237 Plasma::Applet *DesktopCorona::loadDefaultApplet(const QString &pluginName, Plasma::Containment *c)
00238 {
00239     QVariantList args;
00240     Plasma::Applet *applet = Plasma::Applet::load(pluginName, 0, args);
00241 
00242     if (applet) {
00243         c->addApplet(applet);
00244     }
00245 
00246     return applet;
00247 }
00248 
00249 void DesktopCorona::screenAdded(Kephal::Screen *s)
00250 {
00251     kDebug() << s->id();
00252     checkScreen(s->id(), true);
00253 }
00254 
00255 #include "desktopcorona.moc"
00256 

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
Generated for API Reference by doxygen 1.5.7
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