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