~ubuntu-branches/ubuntu/raring/plasma-mobile/raring-proposed

« back to all changes in this revision

Viewing changes to shell/plasmaapp.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2012-07-17 12:04:43 UTC
  • mfrom: (1.1.6)
  • Revision ID: package-import@ubuntu.com-20120717120443-q3ig9u2fnltx67yg
Tags: 2.0+git2012071701-0ubuntu1
* New upstream snapshot
* Remove build-dep on kde-runtime-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
64
64
 
65
65
#include <Nepomuk/ResourceManager>
66
66
 
67
 
#include "../components/runnermodel/runnermodel.h"
68
 
 
 
67
#ifdef Q_WS_X11
69
68
#include <X11/Xlib.h>
70
69
#include <X11/extensions/Xrender.h>
71
 
 
 
70
#endif
72
71
 
73
72
PlasmaApp* PlasmaApp::self()
74
73
{
96
95
    Nepomuk::ResourceManager::instance()->init();
97
96
 
98
97
    qmlRegisterType<PanelProxy>("org.kde.plasma.deviceshell", 0, 1, "DevicePanel");
 
98
    qmlRegisterUncreatableType<ContainmentProperties>("org.kde.plasma.deviceshell", 0, 1, "ContainmentProperties", "ContainmentProperties is just a type holder");
99
99
 
100
100
    //FIXME: why does not work?
101
101
    //qmlRegisterInterface<Plasma::Wallpaper>("Wallpaper");
120
120
    }
121
121
 
122
122
 
123
 
    int width = 1024;
124
 
    int height = 600;
 
123
    int width = 800;
 
124
    int height = 480;
125
125
    if (isDesktop) {
126
126
        QRect rect = QApplication::desktop()->screenGeometry(m_mainView->screen());
127
127
        width = rect.width();
163
163
    corona();
164
164
    connect(this, SIGNAL(aboutToQuit()), this, SLOT(cleanup()));
165
165
 
 
166
    connect(KWindowSystem::self(), SIGNAL(activeWindowChanged(WId)),
 
167
            this, SLOT(activeWindowChanged(WId)));
 
168
 
166
169
    if (isDesktop) {
167
170
        notifyStartup(true);
168
171
    }
170
173
    m_startupInfo = new KStartupInfo(KStartupInfo::CleanOnCantDetect, this );
171
174
 
172
175
    connect(m_startupInfo,
173
 
            SIGNAL(gotNewStartup(const KStartupInfoId&, const KStartupInfoData&)),
174
 
            SLOT(gotStartup(const KStartupInfoId&, const KStartupInfoData&)));
175
 
    connect(m_startupInfo,
176
 
            SIGNAL(gotStartupChange(const KStartupInfoId&, const KStartupInfoData&)),
177
 
            SLOT(gotStartup(const KStartupInfoId&, const KStartupInfoData&)));
178
 
    connect(m_startupInfo,
179
 
            SIGNAL(gotRemoveStartup(const KStartupInfoId&, const KStartupInfoData&)),
180
 
            SLOT(killStartup(const KStartupInfoId&)));
 
176
            SIGNAL(gotNewStartup(KStartupInfoId,KStartupInfoData)),
 
177
            SLOT(gotStartup(KStartupInfoId,KStartupInfoData)));
 
178
    connect(m_startupInfo,
 
179
            SIGNAL(gotStartupChange(KStartupInfoId,KStartupInfoData)),
 
180
            SLOT(gotStartup(KStartupInfoId,KStartupInfoData)));
 
181
    connect(m_startupInfo,
 
182
            SIGNAL(gotRemoveStartup(KStartupInfoId,KStartupInfoData)),
 
183
            SLOT(killStartup(KStartupInfoId)));
181
184
}
182
185
 
183
186
PlasmaApp::~PlasmaApp()
279
282
    connect(m_mainView, SIGNAL(containmentActivated()),
280
283
            this, SLOT(mainContainmentActivated()));
281
284
 
282
 
    connect(m_homeScreen, SIGNAL(transformingChanged(bool)),
283
 
            this, SLOT(containmentsTransformingChanged(bool)));
284
 
 
285
285
    connect(m_homeScreen, SIGNAL(focusActivityView()),
286
286
            this, SLOT(focusMainView()));
287
287
 
288
 
    connect(m_homeScreen, SIGNAL(nextActivityRequested()),
289
 
            m_corona, SLOT(activateNextActivity()));
 
288
    KAction *focusHomeAction = new KAction(this);
 
289
    focusHomeAction->setObjectName("Focus Homescreen");
 
290
    focusHomeAction->setGlobalShortcut(
 
291
        KShortcut(QKeySequence(Qt::Key_HomePage)),
 
292
        KAction::ShortcutTypes(KAction::ActiveShortcut | KAction::DefaultShortcut),
 
293
        KAction::NoAutoloading);
 
294
    connect(focusHomeAction, SIGNAL(triggered()),
 
295
            this, SLOT(focusMainView()));
290
296
 
291
 
    connect(m_homeScreen, SIGNAL(previousActivityRequested()),
292
 
            m_corona, SLOT(activatePreviousActivity()));
 
297
    KAction *togglePanelAction = new KAction(this);
 
298
    togglePanelAction->setObjectName("Toggle Panel");
 
299
    togglePanelAction->setGlobalShortcut(
 
300
        KShortcut(QKeySequence(Qt::Key_Menu)),
 
301
        KAction::ShortcutTypes(KAction::ActiveShortcut | KAction::DefaultShortcut),
 
302
        KAction::NoAutoloading);
 
303
    connect(togglePanelAction, SIGNAL(triggered()),
 
304
            m_homeScreen, SLOT(togglePanel()));
293
305
 
294
306
    connect(m_homeScreen, SIGNAL(newActivityRequested()),
295
307
            this, SLOT(showActivityCreation()));
306
318
 
307
319
    m_oldContainment = m_currentContainment;
308
320
 
309
 
    //FIXME: it should be possible to access containment.wallpaper
310
 
    //expose the current wallpaper into the corona QML
311
 
    if (containment->wallpaper()) {
312
 
        QDeclarativeProperty containmentProperty(m_homeScreen, "activeWallpaper");
313
 
        containmentProperty.write(QVariant::fromValue(static_cast<QObject*>(containment->wallpaper())));
314
 
    }
315
 
 
316
321
    m_currentContainment = containment;
317
322
}
318
323
 
327
332
        connect(m_corona, SIGNAL(containmentAdded(Plasma::Containment*)),
328
333
                this, SLOT(manageNewContainment(Plasma::Containment*)), Qt::QueuedConnection);
329
334
        connect(m_corona, SIGNAL(configSynced()), this, SLOT(syncConfig()));
330
 
        connect(m_corona, SIGNAL(screenOwnerChanged(int, int, Plasma::Containment *)), this, SLOT(containmentScreenOwnerChanged(int,int,Plasma::Containment*)));
 
335
        connect(m_corona, SIGNAL(screenOwnerChanged(int,int,Plasma::Containment*)), this, SLOT(containmentScreenOwnerChanged(int,int,Plasma::Containment*)));
331
336
 
332
337
 
333
338
        // setup our QML home screen;
389
394
    connect(containment, SIGNAL(configureRequested(Plasma::Containment*)),
390
395
            this, SLOT(showActivityConfiguration(Plasma::Containment*)));
391
396
 
392
 
    //Is it a panel?
393
 
    //put it into the main scene:
394
 
    //if it's on an edge find a qml element propely named
395
 
    //otherwise delete it
396
 
    QString containmentPanelName;
397
 
 
398
 
    switch (containment->location()) {
399
 
    case Plasma::LeftEdge:
400
 
        containmentPanelName = "leftEdgePanel";
401
 
        break;
402
 
    case Plasma::TopEdge:
403
 
        containmentPanelName = "topEdgePanel";
404
 
        break;
405
 
    case Plasma::RightEdge:
406
 
        containmentPanelName = "rightEdgePanel";
407
 
        break;
408
 
    case Plasma::BottomEdge:
409
 
        containmentPanelName = "bottomEdgePanel";
410
 
        break;
411
 
    default:
412
 
        break;
413
 
    }
414
397
 
415
398
    //is it a panel?
416
 
    if (!containmentPanelName.isEmpty()) {
417
 
        QDeclarativeItem *containmentPanel = m_homeScreen->findChild<QDeclarativeItem*>(containmentPanelName);
418
 
 
419
 
        if (containmentPanel) {
420
 
            containment->setParentItem(containmentPanel);
421
 
            containment->setParent(containmentPanel);
422
 
 
423
 
            containmentPanel->metaObject()->invokeMethod(containmentPanel, "addContainment", Q_ARG(QVariant, QVariant::fromValue<QGraphicsWidget *>(containment)));
424
 
 
425
 
            m_panelContainments.insert(containment->id(), containment);
426
 
 
427
 
            //done, don't need further management
428
 
            return;
429
 
        } else {
430
 
            //no panel? discard the containment
431
 
            containment->deleteLater();
432
 
            return;
433
 
        }
 
399
    if (containment->location() == Plasma::LeftEdge ||
 
400
        containment->location() == Plasma::TopEdge ||
 
401
        containment->location() == Plasma::RightEdge ||
 
402
        containment->location() == Plasma::BottomEdge) {
 
403
 
 
404
 
 
405
        m_panelContainments.insert(containment->id(), containment);
 
406
 
 
407
        //add the panel into the QML homescreen
 
408
        m_homeScreen->metaObject()->invokeMethod(m_homeScreen, "addPanel", 
 
409
                                                    Q_ARG(QVariant, QVariant::fromValue<QGraphicsWidget *>(containment)),
 
410
                                                    Q_ARG(QVariant, containment->formFactor()),
 
411
                                                    Q_ARG(QVariant, containment->location()));
 
412
 
 
413
        //done, don't need further management
 
414
        return;
434
415
    }
435
416
 
436
417
 
438
419
    // to retrieve it later.
439
420
    m_containments.insert(containment->id(), containment);
440
421
 
441
 
    connect(containment, SIGNAL(destroyed(QObject *)), this, SLOT(containmentDestroyed(QObject *)));
 
422
    connect(containment, SIGNAL(destroyed(QObject*)), this, SLOT(containmentDestroyed(QObject*)));
442
423
 
443
424
    containment->resize(m_mainView->size());
444
425
 
450
431
    }
451
432
 
452
433
    // we need our homescreen to show something!
453
 
    // for the alternate screen (such as a launcher) we need a containment setted as excludeFromActivities
454
 
    //FIXME: use only the declarativeSlot key?
455
434
    if (containment->config().readEntry("excludeFromActivities", false)) {
456
 
        const QString declarativeSlot = containment->config().readEntry("declarativeSlot", "alternateSlot");
457
 
        QDeclarativeItem *alternateSlot = m_homeScreen->findChild<QDeclarativeItem*>(declarativeSlot);
458
 
 
459
 
        if (alternateSlot) {
460
 
            m_alternateContainments << containment;
461
 
            alternateSlot->setProperty("width", m_mainView->size().width());
462
 
            alternateSlot->setProperty("height", m_mainView->size().height());
463
 
            containment->setParentItem(alternateSlot);
464
 
            containment->setParent(alternateSlot);
465
 
            containment->setPos(0, 0);
466
 
            containment->setVisible(true);
467
 
            return;
468
 
        }
 
435
        //Do nothing!
 
436
        //Don't remove this empty branch
469
437
    } else if (containment->screen() > -1) {
470
438
        changeContainment(containment);
471
439
    } else {
484
452
    }
485
453
}
486
454
 
 
455
void PlasmaApp::activeWindowChanged(WId id)
 
456
{
 
457
    m_homeScreen->setProperty("windowActive", (id == m_mainView->winId()));
 
458
}
 
459
 
487
460
void PlasmaApp::mainViewGeometryChanged()
488
461
{
489
462
    if (m_declarativeWidget) {
495
468
        m_declarativeWidget->setGeometry(m_mainView->mapToScene(QRect(QPoint(0,0), m_mainView->size())).boundingRect());
496
469
 
497
470
        QRect availableScreenRect(QPoint(0,0), m_mainView->size());
498
 
        QDeclarativeItem *availableScreenRectItem = m_homeScreen->findChild<QDeclarativeItem*>("availableScreenRect");
 
471
 
 
472
        QDeclarativeItem *availableScreenRectItem = m_homeScreen->property("availableScreenRect").value<QDeclarativeItem*>();
 
473
 
499
474
        //is there an item that defines the screen geometry?
500
475
        if (availableScreenRectItem) {
501
476
            availableScreenRect = QRect((int)availableScreenRectItem->property("x").toReal(),
516
491
        if (m_currentContainment) {
517
492
            m_currentContainment->resize(m_mainView->size());
518
493
        }
519
 
        foreach (Plasma::Containment *cont, m_alternateContainments) {
520
 
            cont->resize(m_mainView->size());
521
 
            cont->setPos(0, 0);
522
 
        }
 
494
 
523
495
        if (m_widgetsExplorer) {
524
496
            m_widgetsExplorer.data()->setGeometry(m_declarativeWidget->geometry());
525
497
        }