tsdevicedialog/tsdevicedialogplugin/src/tsdevicedialogplugin.cpp
branchRCL_3
changeset 29 0efa10d348c0
equal deleted inserted replaced
28:053c6c7c14f3 29:0efa10d348c0
       
     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 "tsdevicedialogplugin.h"
       
    19 
       
    20 #include <QTranslator>
       
    21 #include <QCoreApplication>
       
    22 #include <QLocale>
       
    23 #include <QtPlugin>
       
    24 
       
    25 #include <QValueSpacePublisher>
       
    26 #include <QServiceManager>
       
    27 
       
    28 #include <HbDeviceDialog>
       
    29 #include <HbMainWindow>
       
    30 
       
    31 #include <tspropertydefs.h>
       
    32 
       
    33 #include "tsdevicedialogcontainer.h"
       
    34 #include "tstasksgrid.h"
       
    35 #include "tstasksgriditem.h"
       
    36 #include "tsdocumentloader.h"
       
    37 #include "tsmodel.h"
       
    38 
       
    39 QTM_USE_NAMESPACE
       
    40 
       
    41 /*!
       
    42     \class TsDeviceDialogPlugin
       
    43     \ingroup group_tsdevicedialogplugin
       
    44     \brief TaskSwitcher Device Dialog Plug-in.
       
    45  */
       
    46 
       
    47 namespace
       
    48 {
       
    49     const char KTranslationPath[] = "resource/qt/translations";
       
    50     const char KTsDialogType[] = "com.nokia.taskswitcher.tsdevicedialogplugin/1.0";
       
    51     const char KActivityManaged [] = "com.nokia.qt.activities.ActivityManager";
       
    52 } 
       
    53  
       
    54 /*!
       
    55     Constructor.
       
    56  */
       
    57 TsDeviceDialogPlugin::TsDeviceDialogPlugin()
       
    58 : 
       
    59 mModel(0), 
       
    60 mStorage(0), 
       
    61 mTriedToLoadTranslation(false)
       
    62 {
       
    63 }
       
    64 
       
    65 TsDeviceDialogPlugin::~TsDeviceDialogPlugin()
       
    66 {
       
    67     delete mModel;
       
    68 }
       
    69 /*!
       
    70     \reimp
       
    71  */
       
    72 bool TsDeviceDialogPlugin::accessAllowed(const QString &deviceDialogType, 
       
    73                                          const QVariantMap &parameters, 
       
    74                                          const QVariantMap &securityInfo) const
       
    75 {
       
    76     Q_UNUSED(deviceDialogType)
       
    77     Q_UNUSED(parameters)
       
    78     Q_UNUSED(securityInfo)
       
    79 
       
    80     // This plugin doesn't perform operations that may compromise security.
       
    81     // All clients are allowed to use it.
       
    82     return true;
       
    83 }
       
    84 
       
    85 /*!
       
    86     \reimp
       
    87  */
       
    88 HbDeviceDialogInterface * 
       
    89 TsDeviceDialogPlugin::createDeviceDialog(const QString &deviceDialogType, 
       
    90                                          const QVariantMap &parameters)
       
    91 {
       
    92     Q_UNUSED(parameters)
       
    93     HbDeviceDialogInterface *dialogInterface(0);
       
    94     if (deviceDialogType == QString(KTsDialogType)) {
       
    95         // lazy loading of translation
       
    96         if (!mTriedToLoadTranslation) {
       
    97             mTriedToLoadTranslation = true;
       
    98 
       
    99             QTranslator *translator = new QTranslator(this);
       
   100             QString translationFile = 
       
   101                 QString("taskswitcher_%1").arg(QLocale::system().name());
       
   102     
       
   103             bool translationLoaded(false);
       
   104             #ifdef Q_OS_SYMBIAN
       
   105                 translationLoaded = 
       
   106                     translator->load(translationFile, 
       
   107                                      QString("z:/") + KTranslationPath);
       
   108                 if (!translationLoaded) {
       
   109                     translationLoaded = 
       
   110                         translator->load(translationFile, 
       
   111                                          QString("c:/") + KTranslationPath);
       
   112                 }
       
   113             #else
       
   114                 translationLoaded = 
       
   115                     translator->load(translationFile, 
       
   116                                      QString(KTranslationPath));
       
   117             #endif //Q_OS_SYMBIAN
       
   118 
       
   119             Q_ASSERT(translationLoaded);
       
   120             qApp->installTranslator(translator);
       
   121         }
       
   122     
       
   123         // lazy loading of model
       
   124         if (!mModel) {
       
   125             mStorage = new TsTaskMonitor(this);
       
   126             
       
   127             QServiceManager serviceManager;
       
   128             QObject *activityManager(serviceManager.loadInterface(KActivityManaged));
       
   129             if (activityManager) {
       
   130                 activityManager->setParent(this); //make it autodestructed
       
   131             } else {
       
   132                 activityManager = this; //activity plugin is not present. provide invalid instance because its not critical functionality.
       
   133                 //QMetaObject::invokeMethod is safe to use in such a case.
       
   134             }
       
   135             mModel = new TsModel(*mStorage, *activityManager);
       
   136         }
       
   137             
       
   138         // ensure the dismiss request property is set to false
       
   139 
       
   140         QValueSpacePublisher dismissRequestPublisher(TsProperty::KTsPath);
       
   141         dismissRequestPublisher.setValue(TsProperty::KDismissRequestPath, static_cast<int>(false));
       
   142         dismissRequestPublisher.sync();
       
   143 
       
   144         
       
   145         // create device dialog
       
   146         dialogInterface = new TsDeviceDialogContainer(mModel);
       
   147     }
       
   148     return dialogInterface;
       
   149 }
       
   150 
       
   151 /*!
       
   152     \reimp
       
   153  */
       
   154 bool TsDeviceDialogPlugin::deviceDialogInfo(const QString &deviceDialogType, 
       
   155                                             const QVariantMap &parameters, 
       
   156                                             DeviceDialogInfo *info) const
       
   157 {
       
   158     Q_UNUSED(parameters)
       
   159     Q_UNUSED(deviceDialogType)
       
   160 
       
   161     info->group = GenericDeviceDialogGroup;
       
   162     info->flags = SingleInstance;
       
   163     info->priority = DefaultPriority;
       
   164 
       
   165     return true;
       
   166 }
       
   167 
       
   168 /*!
       
   169     \reimp
       
   170  */
       
   171 QStringList TsDeviceDialogPlugin::deviceDialogTypes() const
       
   172 {
       
   173     return QStringList(QString(KTsDialogType));
       
   174 }
       
   175 
       
   176 /*!
       
   177     \reimp
       
   178  */
       
   179 HbDeviceDialogPlugin::PluginFlags TsDeviceDialogPlugin::pluginFlags() const
       
   180 {
       
   181     return PluginFlags(PreloadPlugin | KeepPluginLoaded);
       
   182 }
       
   183 
       
   184 /*!
       
   185     \reimp
       
   186  */
       
   187 int TsDeviceDialogPlugin::error() const
       
   188 {
       
   189     return 0;
       
   190 }
       
   191 
       
   192 #ifdef COVERAGE_MEASUREMENT
       
   193 #pragma CTC SKIP
       
   194 #endif //COVERAGE_MEASUREMENT
       
   195 
       
   196 Q_EXPORT_PLUGIN2(tsdevicedialogplugin, TsDeviceDialogPlugin)
       
   197 
       
   198 #ifdef COVERAGE_MEASUREMENT
       
   199 #pragma CTC ENDSKIP
       
   200 #endif //COVERAGE_MEASUREMENT