taskswitcherapp/runtimeplugins/tsdefaultruntimeplugin/src/tsdefaultruntime.cpp
changeset 39 4e8ebe173323
parent 36 cdae8c6c3876
child 42 517f4fb5ec74
child 46 23b5d6a29cce
equal deleted inserted replaced
36:cdae8c6c3876 39:4e8ebe173323
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: Default TaskSwitcher runtime.
       
    15 *
       
    16 */
       
    17 
       
    18 #include <QAbstractItemModel>
       
    19 #include <QState>
       
    20 #include <QFinalState>
       
    21 #include <qservicemanager.h>
       
    22 
       
    23 #include "tsdefaultruntime.h"
       
    24 
       
    25 QTM_USE_NAMESPACE
       
    26 
       
    27 /*!
       
    28     \class TsDefaultRuntime
       
    29     \ingroup group_tsdefaultruntimeplugin
       
    30     \brief Default implementation of the taskswitcher runtime.
       
    31 */
       
    32 
       
    33 /*!
       
    34     Constructs a new TsDefaultRuntime with parent.
       
    35 */
       
    36 TsDefaultRuntime::TsDefaultRuntime(QObject *parent) : QStateMachine(parent)
       
    37 {
       
    38     // load services
       
    39     // FIXME: workaround for bug in QtSF - can't destroy QServiceManager
       
    40     QServiceManager *serviceManager = new QServiceManager;  
       
    41     QObject *itemProvider = createCriticalInterface(serviceManager, "com.nokia.taskswitcher.itemprovider");
       
    42     QObject *activation = createCriticalInterface(serviceManager, "com.nokia.taskswitcher.activation");
       
    43     QObject *deactivation = createCriticalInterface(serviceManager, "com.nokia.taskswitcher.deactivation");
       
    44     QObject *presentation = createCriticalInterface(serviceManager, "com.nokia.taskswitcher.presentation");
       
    45 
       
    46     // create states
       
    47     QState *taskSwitcherStates = new QState(this);
       
    48     QState *backgroundState = new QState(taskSwitcherStates);
       
    49     QState *activeState = new QState(taskSwitcherStates);
       
    50     QFinalState *finalState = new QFinalState(this);
       
    51     setInitialState(taskSwitcherStates);
       
    52     taskSwitcherStates->setInitialState(backgroundState);
       
    53 
       
    54     // Forward signals emited by statemachine.
       
    55     backgroundState->addTransition(activation, SIGNAL(activated()), activeState);
       
    56     activeState->addTransition(deactivation, SIGNAL(deactivated()), backgroundState);
       
    57     taskSwitcherStates->addTransition(this, SIGNAL(event_exit()), finalState);
       
    58 
       
    59     // exchange model between itemprovider and presentation service
       
    60     QAbstractItemModel *model;
       
    61     QMetaObject::invokeMethod(itemProvider, "model", Q_RETURN_ARG(QAbstractItemModel*, model));
       
    62     QMetaObject::invokeMethod(presentation, "setModel", Q_ARG(QAbstractItemModel*, model));
       
    63 
       
    64     // connect all services
       
    65     connect(presentation, SIGNAL(openApplication(QModelIndex)), itemProvider, SLOT(openApplication(QModelIndex)));
       
    66     connect(presentation, SIGNAL(closeApplication(QModelIndex)), itemProvider, SLOT(closeApplication(QModelIndex)));
       
    67     connect(presentation, SIGNAL(closeAllApplications()), itemProvider, SLOT(closeAllApplications()));
       
    68 
       
    69     connect(presentation, SIGNAL(hideTaskSwitcher()), deactivation, SIGNAL(deactivated()));
       
    70 
       
    71     connect(activeState, SIGNAL(exited()), presentation, SLOT(hide()));
       
    72     connect(activeState, SIGNAL(entered()), presentation, SLOT(show()));
       
    73 
       
    74     connect(activeState, SIGNAL(exited()), itemProvider, SLOT(clearClosedApplicationList()));
       
    75 }
       
    76 
       
    77 /*!
       
    78     Creates critical interface with /a name using passed /a serviceManager.
       
    79 */
       
    80 QObject *TsDefaultRuntime::createCriticalInterface(QServiceManager *serviceManager, const QString &name)
       
    81 {
       
    82     QObject *interface = serviceManager->loadInterface(name);
       
    83     Q_ASSERT_X(interface, "TsDefaultRuntime::createCriticalInterface", qPrintable(QString("Cannot initialize critical %1 interafce").arg(name)));
       
    84     interface->setParent(this);
       
    85     return interface;
       
    86 }