taskswitcherapp/tsapplication/src/tstaskswitcher.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:
       
    15 *
       
    16 */
       
    17 
       
    18 #include "tstaskswitcher.h"
       
    19 
       
    20 #include <QStateMachine>
       
    21 #include <QEventLoop>
       
    22 
       
    23 #include <qservicemanager.h>
       
    24 
       
    25 QTM_USE_NAMESPACE
       
    26 
       
    27 TsTaskSwitcher::TsTaskSwitcher(QObject* aParent) : QObject(aParent)
       
    28 {
       
    29     // FIXME: we're leaking service manager to prevent crash caused by QServiceManager deletion
       
    30     QServiceManager *serviceManager = new QServiceManager;
       
    31             
       
    32     // FIXME: temporary workaround for bug in QtSF database - this process have to add services
       
    33     QList<QServiceInterfaceDescriptor> tsServiceInterfaces = serviceManager->findInterfaces("TaskSwitcher");
       
    34     QStringList requiredInterfaces;
       
    35     requiredInterfaces << "com.nokia.taskswitcher.itemprovider";
       
    36     requiredInterfaces << "com.nokia.taskswitcher.activation";
       
    37     requiredInterfaces << "com.nokia.taskswitcher.deactivation";
       
    38     requiredInterfaces << "com.nokia.taskswitcher.presentation";
       
    39     requiredInterfaces << "com.nokia.taskswitcher.runtime.defaultruntime";
       
    40 
       
    41     foreach (const QServiceInterfaceDescriptor &interface, tsServiceInterfaces) {
       
    42         QString interfaceName = interface.interfaceName();
       
    43         if (requiredInterfaces.contains(interfaceName)) {
       
    44             requiredInterfaces.removeAll(interfaceName);
       
    45         }
       
    46     }
       
    47     
       
    48     if (!requiredInterfaces.isEmpty()) {
       
    49         // clean old entries
       
    50         serviceManager->removeService("TaskSwitcher");
       
    51         
       
    52         bool servicesAdded = serviceManager->addService(":/tsserviceplugin.xml");
       
    53         Q_ASSERT_X(servicesAdded, "Adding Ts Services", qPrintable(QString("addService returned false, error %1").arg(serviceManager->error())));
       
    54 
       
    55         bool runtimeAdded = serviceManager->addService(":/tsdefaultruntimeplugin.xml");
       
    56         Q_ASSERT_X(runtimeAdded, "Adding Ts Runtime", qPrintable(QString("addService returned false, error %1").arg(serviceManager->error())));
       
    57     }
       
    58     // FIXME
       
    59     
       
    60     mRuntime = serviceManager->loadLocalTypedInterface<QStateMachine>("com.nokia.taskswitcher.runtime.defaultruntime");
       
    61     if (mRuntime) {
       
    62         mRuntime->setParent(this);
       
    63         connect(mRuntime, SIGNAL(stopped()), this, SIGNAL(exit()));
       
    64     } else {
       
    65         qCritical("Failed to create runtime");
       
    66     }
       
    67 }
       
    68 
       
    69 void TsTaskSwitcher::start()
       
    70 {
       
    71     if (mRuntime) {
       
    72         mRuntime->start();
       
    73     } else {
       
    74         emit exit();
       
    75     }
       
    76 }
       
    77 
       
    78 void TsTaskSwitcher::stop()
       
    79 {
       
    80     if (mRuntime) {
       
    81         if (mRuntime->isRunning()) {
       
    82             QEventLoop eventLoop;
       
    83             connect(mRuntime, SIGNAL(finished()), &eventLoop, SLOT(quit()));
       
    84             QMetaObject::invokeMethod(mRuntime, "event_exit", Qt::QueuedConnection);
       
    85             eventLoop.exec(); 
       
    86         }        
       
    87     }
       
    88 }