taskswitcherapp/tsdevicedialogplugin/src/tsdevicedialogplugin.cpp
changeset 62 341166945d65
parent 57 2e2dc3d30ca8
child 63 52b0f64eeb51
equal deleted inserted replaced
57:2e2dc3d30ca8 62:341166945d65
     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 <QtPlugin>
       
    19 #include <hbdevicedialog.h>
       
    20 #include <HbMainWindow>
       
    21 #include <qservicemanager.h>
       
    22 
       
    23 #include "tsdevicedialogplugin.h"
       
    24 #include "tsdevicedialog.h"
       
    25 #include "tstasksgrid.h"
       
    26 #include "tstasksgriditem.h"
       
    27 #include "tsdocumentloader.h"
       
    28 #include "tsmodel.h"
       
    29 
       
    30 /*!
       
    31     \class TsDeviceDialogPlugin
       
    32     \ingroup group_tsdevicedialogplugin
       
    33     \brief TaskSwitcher Device Dialog Plug-in.
       
    34  */
       
    35 
       
    36 const QString KTsDialogType = "com.nokia.taskswitcher.tsdevicedialogplugin/1.0";
       
    37 
       
    38 /*!
       
    39     Constructor.
       
    40  */
       
    41 TsDeviceDialogPlugin::TsDeviceDialogPlugin() : mError(0), mModel(0), mStorage(0)
       
    42 {
       
    43 }
       
    44 
       
    45 TsDeviceDialogPlugin::~TsDeviceDialogPlugin()
       
    46 {
       
    47     delete mModel;
       
    48 }
       
    49 /*!
       
    50     \reimp
       
    51  */
       
    52 bool TsDeviceDialogPlugin::accessAllowed(const QString &deviceDialogType, const QVariantMap &parameters, const QVariantMap &securityInfo) const
       
    53 {
       
    54     Q_UNUSED(deviceDialogType)
       
    55     Q_UNUSED(parameters)
       
    56     Q_UNUSED(securityInfo)
       
    57 
       
    58     // This plugin doesn't perform operations that may compromise security.
       
    59     // All clients are allowed to use.
       
    60     return true;
       
    61 }
       
    62 
       
    63 /*!
       
    64     \reimp
       
    65  */
       
    66 HbDeviceDialogInterface *TsDeviceDialogPlugin::createDeviceDialog(const QString &deviceDialogType, const QVariantMap &parameters)
       
    67 {
       
    68     Q_UNUSED(parameters)
       
    69     TsDeviceDialog *dialog(0);
       
    70     if (deviceDialogType == KTsDialogType) {
       
    71         if (0 == mModel) {
       
    72             mStorage = new TsTaskMonitor(this);
       
    73             if (0 == mStorage) {
       
    74                 return 0;
       
    75             }
       
    76             QtMobility::QServiceManager serviceManager;
       
    77             QObject *objPtr(serviceManager.loadInterface("com.nokia.qt.activities.ActivityManager"));
       
    78             if (objPtr) {
       
    79                 objPtr->setParent(this);//make it autodestucted
       
    80             } else {
       
    81                 objPtr = this;//activity plugin is not present. provide invalid instance because its not critical functionality.
       
    82                 //QMetaObject::invokeMethod is safe to use in such a case.
       
    83             }
       
    84             mModel = new TsModel(*mStorage, *objPtr);
       
    85         }
       
    86 
       
    87         mLoader.reset();
       
    88         bool ok(true);
       
    89         mLoader.load(":/xml/resource/layout.docml", &ok);
       
    90         Q_ASSERT(ok);
       
    91 
       
    92         dialog = qobject_cast<TsDeviceDialog *>(mLoader.findWidget("tsdevicedialog"));
       
    93         TsTasksGrid *grid = qobject_cast<TsTasksGrid *>(mLoader.findWidget("taskgrid"));
       
    94         Q_ASSERT(dialog);
       
    95         Q_ASSERT(grid);
       
    96 
       
    97         dialog->changeOrientation(dialog->mainWindow()->orientation());
       
    98 
       
    99         grid->setItemPrototype(new TsTasksGridItem());
       
   100         grid->setModel(mModel);
       
   101 
       
   102         //static_cast<TsModel *>(mModel)->updateModel();
       
   103 
       
   104         // connect the grid and model
       
   105         qRegisterMetaType<QModelIndex>("QModelIndex");
       
   106         
       
   107         disconnect(grid, SIGNAL(activated(QModelIndex)), mModel, SLOT(openApplication(QModelIndex)));
       
   108         disconnect(grid, SIGNAL(activated(QModelIndex)), dialog, SLOT(close()));
       
   109         disconnect(grid, SIGNAL(deleteButtonClicked(QModelIndex)), mModel, SLOT(closeApplication(QModelIndex)));
       
   110         
       
   111         connect(grid, SIGNAL(activated(QModelIndex)), mModel, SLOT(openApplication(QModelIndex)));
       
   112         connect(grid, SIGNAL(activated(QModelIndex)), dialog, SLOT(close()));
       
   113         connect(grid, SIGNAL(deleteButtonClicked(QModelIndex)), mModel, SLOT(closeApplication(QModelIndex)), Qt::QueuedConnection);
       
   114     }
       
   115     return dialog;
       
   116 }
       
   117 
       
   118 /*!
       
   119     \reimp
       
   120  */
       
   121 bool TsDeviceDialogPlugin::deviceDialogInfo(const QString &deviceDialogType, const QVariantMap &parameters, DeviceDialogInfo *info) const
       
   122 {
       
   123     Q_UNUSED(parameters)
       
   124     Q_UNUSED(deviceDialogType)
       
   125 
       
   126     info->group = GenericDeviceDialogGroup;
       
   127     info->flags = NoDeviceDialogFlags;
       
   128     info->priority = DefaultPriority;
       
   129 
       
   130     return true;
       
   131 }
       
   132 
       
   133 /*!
       
   134     \reimp
       
   135  */
       
   136 QStringList TsDeviceDialogPlugin::deviceDialogTypes() const
       
   137 {
       
   138     return QStringList(KTsDialogType);
       
   139 }
       
   140 
       
   141 /*!
       
   142     \reimp
       
   143  */
       
   144 HbDeviceDialogPlugin::PluginFlags TsDeviceDialogPlugin::pluginFlags() const
       
   145 {
       
   146     return PluginFlags(PreloadPlugin | KeepPluginLoaded);
       
   147 }
       
   148 
       
   149 /*!
       
   150     \reimp
       
   151  */
       
   152 int TsDeviceDialogPlugin::error() const
       
   153 {
       
   154     return mError;
       
   155 }
       
   156 
       
   157 #ifdef COVERAGE_MEASUREMENT
       
   158 #pragma CTC SKIP
       
   159 #endif //COVERAGE_MEASUREMENT
       
   160 
       
   161 Q_EXPORT_PLUGIN2(tsdevicedialogplugin, TsDeviceDialogPlugin)
       
   162 
       
   163 #ifdef COVERAGE_MEASUREMENT
       
   164 #pragma CTC ENDSKIP
       
   165 #endif //COVERAGE_MEASUREMENT