ftuapplication/src/ftufirsttimeuse.cpp
changeset 0 c464cd7e2753
child 2 66c26770985f
equal deleted inserted replaced
-1:000000000000 0:c464cd7e2753
       
     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:  First Time Use application main class.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "ftufirsttimeuse.h"
       
    20 
       
    21 #include <QStateMachine>
       
    22 #include <qservicemanager.h>
       
    23 #include <qservicefilter.h>
       
    24 #include <qserviceinterfacedescriptor.h>
       
    25 #include <QFileInfo>
       
    26 #include <QDir>
       
    27 #include <QApplication>
       
    28 
       
    29 
       
    30 QTM_USE_NAMESPACE
       
    31 
       
    32 const char* ftuRuntimeUri = "com.nokia.ftu.runtime.FtuRuntime";
       
    33 
       
    34 // ---------------------------------------------------------------------------
       
    35 // FtuFirstTimeUse::FtuFirstTimeUse
       
    36 // ---------------------------------------------------------------------------
       
    37 //
       
    38 FtuFirstTimeUse::FtuFirstTimeUse(QObject* aParent) : 
       
    39     QObject(aParent),
       
    40     mRuntime(NULL)
       
    41 {  
       
    42     FTUTEST_FUNC_ENTRY("FTU::FtuFirstTimeUse::FtuFirstTimeUse");
       
    43     
       
    44     registerServicePlugins();
       
    45 
       
    46     QServiceManager manager;
       
    47     QServiceFilter filter(ftuRuntimeUri);
       
    48     QList<QServiceInterfaceDescriptor> interfaces = manager.findInterfaces(
       
    49                                                                     filter);
       
    50     
       
    51     qDebug() << "ftu: found " << interfaces.count() 
       
    52              << " instances of runtime";
       
    53     
       
    54     if(interfaces.count() > 0){
       
    55         mRuntime = (QStateMachine*)(manager.loadInterface(
       
    56                                         interfaces.first().interfaceName()));
       
    57     }
       
    58 
       
    59         
       
    60     
       
    61     if(mRuntime) {
       
    62         mRuntime->setParent(this);
       
    63         connect(mRuntime, SIGNAL(started()), SLOT(handleRuntimeStarted()));
       
    64         connect(mRuntime, SIGNAL(stopped()), SLOT(handleRuntimeStopped()));
       
    65         connect(mRuntime, SIGNAL(faulted()), SLOT(handleRuntimeFaulted()));    
       
    66     }
       
    67     
       
    68     FTUTEST_FUNC_EXIT("FTU::FtuFirstTimeUse::FtuFirstTimeUse");
       
    69 }
       
    70 
       
    71 // ---------------------------------------------------------------------------
       
    72 // FtuFirstTimeUse::~FtuFirstTimeUse()
       
    73 // ---------------------------------------------------------------------------
       
    74 //
       
    75 FtuFirstTimeUse::~FtuFirstTimeUse()
       
    76 {
       
    77 	if(mRuntime)
       
    78 	{
       
    79 		disconnect(mRuntime, SIGNAL(started()), this, SLOT(handleRuntimeStarted()));
       
    80         disconnect(mRuntime, SIGNAL(stopped()), this, SLOT(handleRuntimeStopped()));
       
    81         disconnect(mRuntime, SIGNAL(faulted()), this, SLOT(handleRuntimeFaulted()));
       
    82 
       
    83 		delete mRuntime;
       
    84 	}
       
    85 }
       
    86 
       
    87 // ---------------------------------------------------------------------------
       
    88 // FtuFirstTimeUse::start()
       
    89 // ---------------------------------------------------------------------------
       
    90 //
       
    91 void FtuFirstTimeUse::start()
       
    92 {
       
    93     FTUTEST_FUNC_ENTRY("FTU::FtuFirstTimeUse::start");
       
    94     
       
    95     if(mRuntime) {
       
    96         mRuntime->start();
       
    97     } else {
       
    98         emit exit();
       
    99     }
       
   100     
       
   101     FTUTEST_FUNC_EXIT("FTU::FtuFirstTimeUse::start");
       
   102 }
       
   103 
       
   104 // ---------------------------------------------------------------------------
       
   105 // FtuFirstTimeUse::stop()
       
   106 // ---------------------------------------------------------------------------
       
   107 //
       
   108 void FtuFirstTimeUse::stop()
       
   109 {
       
   110     FTUTEST_FUNC_ENTRY("FTU::FtuFirstTimeUse::stop");
       
   111     
       
   112     mRuntime->stop();
       
   113     
       
   114     FTUTEST_FUNC_EXIT("FTU::FtuFirstTimeUse::stop");
       
   115 }
       
   116 
       
   117 // ---------------------------------------------------------------------------
       
   118 // FtuFirstTimeUse::handleRuntimeStarted()
       
   119 // ---------------------------------------------------------------------------
       
   120 //
       
   121 void FtuFirstTimeUse::handleRuntimeStarted()
       
   122 {
       
   123 }
       
   124  
       
   125 // ---------------------------------------------------------------------------
       
   126 // FtuFirstTimeUse::handleRuntimeStopped()
       
   127 // ---------------------------------------------------------------------------
       
   128 //
       
   129 void FtuFirstTimeUse::handleRuntimeStopped()
       
   130 {
       
   131     emit exit();
       
   132 }
       
   133  
       
   134 // ---------------------------------------------------------------------------
       
   135 // FtuFirstTimeUse::handleRuntimeFaulted()
       
   136 // ---------------------------------------------------------------------------
       
   137 //
       
   138 void FtuFirstTimeUse::handleRuntimeFaulted()
       
   139 {
       
   140     emit exit();
       
   141 }
       
   142 // ---------------------------------------------------------------------------
       
   143 // FtuFirstTimeUse::registerServicePlugins()
       
   144 // ---------------------------------------------------------------------------
       
   145 //
       
   146 void FtuFirstTimeUse::registerServicePlugins()
       
   147 {
       
   148     FTUTEST_FUNC_ENTRY("FTU::FtuFirstTimeUse::registerServicePlugins()");
       
   149     QStringList pluginPaths;
       
   150 
       
   151     pluginPaths << "fturesources/plugins";
       
   152 
       
   153     QFileInfoList drives = QDir::drives();
       
   154     foreach(const QString pluginPath, pluginPaths) {
       
   155 #ifdef Q_OS_SYMBIAN
       
   156         //Check plugin dirs from root of different drives
       
   157         foreach(QFileInfo drive, drives) {
       
   158             QString driveLetter = drive.absolutePath();
       
   159             QString path = driveLetter + pluginPath;
       
   160             if(QDir(path).exists()) {
       
   161                 registerServicePlugins(path);
       
   162             }
       
   163         }
       
   164 #endif
       
   165         //Check plugin path relative to current dir
       
   166         if(QDir(pluginPath).exists()) {
       
   167             registerServicePlugins(pluginPath);
       
   168         }
       
   169     }
       
   170     FTUTEST_FUNC_EXIT("FTU::FtuFirstTimeUse::registerServicePlugins()");
       
   171 }
       
   172 
       
   173 // ---------------------------------------------------------------------------
       
   174 // FtuFirstTimeUse::registerServicePlugins()
       
   175 // ---------------------------------------------------------------------------
       
   176 //
       
   177 void FtuFirstTimeUse::registerServicePlugins(const QString &root)
       
   178 {
       
   179     FTUTEST_FUNC_ENTRY("FTU::FtuFirstTimeUse::registerServicePlugins(const QString &)");
       
   180     qDebug() << "FTU: root: " << root;
       
   181     QDir dir = QDir(root);
       
   182     QFileInfoList fileInfos = dir.entryInfoList(QDir::AllDirs | QDir::NoDotAndDotDot);
       
   183 
       
   184     foreach (QFileInfo fileInfo, fileInfos) {
       
   185         registerServicePlugins(fileInfo.absoluteFilePath());
       
   186     }
       
   187 
       
   188     fileInfos = dir.entryInfoList(QStringList("*.xml"));
       
   189 
       
   190     if (!fileInfos.isEmpty()) {
       
   191         //Plugin dll and xml are in the same directory
       
   192         QApplication::addLibraryPath(root);
       
   193         qDebug() << QString("FTU::FtuFirstTimeUse::registerServicePlugins - Directory added to application's library paths: ")
       
   194                  << root;
       
   195         QServiceManager manager;
       
   196         foreach(QFileInfo fileInfo, fileInfos) {
       
   197             manager.addService(fileInfo.absoluteFilePath());
       
   198             qDebug() << QString("FTU::FtuFirstTimeUse::registerServicePlugins - Plugin registered: ") + fileInfo.fileName();
       
   199         }
       
   200     }
       
   201     FTUTEST_FUNC_EXIT("FTU::FtuFirstTimeUse::registerServicePlugins(const QString &)");
       
   202 }