• Skip to content
  • Skip to link menu
KDE 4.1 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 <QDesktopWidget>
00024 #include <QDir>
00025 #include <QGraphicsLayout>
00026 
00027 #include <KDebug>
00028 #include <KDialog>
00029 #include <KGlobalSettings>
00030 #include <KStandardDirs>
00031 
00032 #include <plasma/containment.h>
00033 #include <plasma/dataenginemanager.h>
00034 
00035 DesktopCorona::DesktopCorona(QObject *parent)
00036     : Plasma::Corona(parent)
00037 {
00038     init();
00039 }
00040 
00041 void DesktopCorona::init()
00042 {
00043     QDesktopWidget *desktop = QApplication::desktop();
00044     m_numScreens = desktop->numScreens();
00045     QObject::connect(desktop, SIGNAL(resized(int)), this, SLOT(screenResized(int)));
00046 }
00047 
00048 void DesktopCorona::checkScreens()
00049 {
00050     // quick sanity check to ensure we have containments for each screen!
00051     int numScreens = QApplication::desktop()->numScreens();
00052     for (int i = 0; i < numScreens; ++i) {
00053         if (!containmentForScreen(i)) {
00054             //TODO: should we look for containments that aren't asigned but already exist?
00055             Plasma::Containment* c = addContainment("desktop");
00056             c->setScreen(i);
00057             c->setFormFactor(Plasma::Planar);
00058             c->flushPendingConstraintsEvents();
00059         } else if (i >= m_numScreens) {
00060             // now ensure that if our screen count changed we actually get views
00061             // for them, even if the Containment already existed for that screen
00062             // so we "lie" and emit a containmentAdded signal for every new screen
00063             // regardless of whether it actually already existed, or just got added
00064             // and therefore had this signal emitted. plasma can handle such
00065             // multiple emissions of the signal, and this is simply the most
00066             // straightforward way of accomplishing this
00067             kDebug() << "Notifying of new screen: " << i;
00068             emit containmentAdded(containmentForScreen(i));
00069         }
00070     }
00071 
00072     m_numScreens = numScreens;
00073 }
00074 
00075 void DesktopCorona::loadDefaultLayout()
00076 {
00077     QString defaultConfig = KStandardDirs::locate("appdata", "plasma-default-layoutrc");
00078     if (!defaultConfig.isEmpty()) {
00079         kDebug() << "attempting to load the default layout from:" << defaultConfig;
00080         loadLayout(defaultConfig);
00081         return;
00082     }
00083 
00084     QDesktopWidget *desktop = QApplication::desktop();
00085     int numScreens = desktop->numScreens();
00086     kDebug() << "number of screens is" << numScreens;
00087     int topLeftScreen = 0;
00088     QPoint topLeftCorner = desktop->screenGeometry(0).topLeft();
00089 
00090     // find our "top left" screen, use it as the primary
00091     for (int i = 0; i < numScreens; ++i) {
00092         QRect g = desktop->screenGeometry(i);
00093         kDebug() << "     screen " << i << "geometry is" << g;
00094 
00095         if (g.x() <= topLeftCorner.x() && g.y() >= topLeftCorner.y()) {
00096             topLeftCorner = g.topLeft();
00097             topLeftScreen = i;
00098         }
00099     }
00100 
00101     // used to force a save into the config file
00102     KConfigGroup invalidConfig;
00103 
00104     // create a containment for each screen
00105     for (int i = 0; i < numScreens; ++i) {
00106         // passing in an empty string will get us whatever the default
00107         // containment type is!
00108         Plasma::Containment* c = addContainmentDelayed(QString());
00109 
00110         if (!c) {
00111             continue;
00112         }
00113 
00114         c->init();
00115         c->setScreen(i);
00116         c->setFormFactor(Plasma::Planar);
00117         c->updateConstraints(Plasma::StartupCompletedConstraint);
00118         c->flushPendingConstraintsEvents();
00119         c->save(invalidConfig);
00120 
00121         // put a folder view on the first screen
00122         if (i == topLeftScreen) {
00123             QDir desktopFolder(KGlobalSettings::desktopPath());
00124             if (desktopFolder.exists()) {
00125                 //TODO: should we also not show this if the desktop folder is empty?
00126                 Plasma::Applet *folderView =  Plasma::Applet::load("folderview", c->id() + 1);
00127                 if (folderView) {
00128                     c->addApplet(folderView, QPointF(KDialog::spacingHint(), KDialog::spacingHint()), true);
00129                     KConfigGroup config = folderView->config();
00130                     config.writeEntry("url", "desktop:/");
00131                     folderView->init();
00132                     folderView->flushPendingConstraintsEvents();
00133                 }
00134             }
00135         }
00136 
00137         emit containmentAdded(c);
00138     }
00139 
00140     // make a panel at the bottom
00141     Plasma::Containment* panel = addContainmentDelayed("panel");
00142 
00143     if (!panel) {
00144         return;
00145     }
00146 
00147     panel->init();
00148     panel->setScreen(topLeftScreen);
00149     panel->setLocation(Plasma::BottomEdge);
00150     panel->updateConstraints(Plasma::StartupCompletedConstraint);
00151     panel->flushPendingConstraintsEvents();
00152 
00153     // some default applets to get a usable UI
00154     Plasma::Applet *applet = loadDefaultApplet("launcher", panel);
00155     if (applet) {
00156         applet->setGlobalShortcut(KShortcut("Alt+F1"));
00157     }
00158 
00159     loadDefaultApplet("notifier", panel);
00160     loadDefaultApplet("pager", panel);
00161     loadDefaultApplet("tasks", panel);
00162     loadDefaultApplet("systemtray", panel);
00163 
00164     Plasma::DataEngineManager *engines = Plasma::DataEngineManager::self();
00165     Plasma::DataEngine *power = engines->loadEngine("powermanagement");
00166     if (power) {
00167         const QStringList &batteries = power->query("Battery")["sources"].toStringList();
00168         if (!batteries.isEmpty()) {
00169             loadDefaultApplet("battery", panel);
00170         }
00171     }
00172     engines->unloadEngine("powermanagement");
00173 
00174     loadDefaultApplet("digital-clock", panel);
00175 
00176     foreach (Plasma::Applet* applet, panel->applets()) {
00177         applet->init();
00178         applet->flushPendingConstraintsEvents();
00179         applet->save(invalidConfig);
00180     }
00181 
00182     panel->save(invalidConfig);
00183     emit containmentAdded(panel);
00184 
00185     requestConfigSync();
00186     /*
00187     foreach (Plasma::Containment *c, containments()) {
00188         kDebug() << "letting the world know about" << (QObject*)c;
00189         emit containmentAdded(c);
00190     }
00191     */
00192 }
00193 
00194 Plasma::Applet *DesktopCorona::loadDefaultApplet(const QString &pluginName, Plasma::Containment *c)
00195 {
00196     QVariantList args;
00197     Plasma::Applet *applet = Plasma::Applet::load(pluginName, 0, args);
00198 
00199     if (applet) {
00200         c->addApplet(applet);
00201     }
00202 
00203     return applet;
00204 }
00205 
00206 void DesktopCorona::screenResized(int screen)
00207 {
00208     int numScreens = QApplication::desktop()->numScreens();
00209     if (screen < numScreens) {
00210         foreach (Plasma::Containment *c, containments()) {
00211             if (c->screen() == screen) {
00212                 // trigger a relayout
00213                 c->setScreen(screen);
00214             }
00215         }
00216 
00217         checkScreens(); // ensure we have containments for every screen
00218     } else {
00219         m_numScreens = numScreens;
00220     }
00221 }
00222 
00223 #include "desktopcorona.moc"
00224 

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
  •   libplasma
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
Generated for API Reference by doxygen 1.5.4
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