taskswitcherapp/tsdevicedialogplugin/src/tsdevicedialogplugin.cpp
changeset 51 4785f57bf3d4
parent 39 4e8ebe173323
child 55 03646e8da489
equal deleted inserted replaced
46:23b5d6a29cce 51:4785f57bf3d4
    24 #include "tsdevicedialog.h"
    24 #include "tsdevicedialog.h"
    25 #include "tstasksgrid.h"
    25 #include "tstasksgrid.h"
    26 #include "tstasksgriditem.h"
    26 #include "tstasksgriditem.h"
    27 #include "tsdocumentloader.h"
    27 #include "tsdocumentloader.h"
    28 #include "tsmodel.h"
    28 #include "tsmodel.h"
    29 #include <caservice.h>
       
    30 
    29 
    31 /*!
    30 /*!
    32     \class TsDeviceDialogPlugin
    31     \class TsDeviceDialogPlugin
    33     \ingroup group_tsdevicedialogplugin
    32     \ingroup group_tsdevicedialogplugin
    34     \brief TaskSwitcher Device Dialog Plug-in.
    33     \brief TaskSwitcher Device Dialog Plug-in.
    37 const QString KTsDialogType = "com.nokia.taskswitcher.tsdevicedialogplugin/1.0";
    36 const QString KTsDialogType = "com.nokia.taskswitcher.tsdevicedialogplugin/1.0";
    38 
    37 
    39 /*!
    38 /*!
    40     Constructor.
    39     Constructor.
    41  */
    40  */
    42 TsDeviceDialogPlugin::TsDeviceDialogPlugin() : mError(0), mModel(0), mStorage(CaService::instance()), mLongPressed(false)
    41 TsDeviceDialogPlugin::TsDeviceDialogPlugin() : mError(0), mModel(0), mStorage(0)
    43 {
    42 {
    44 }
    43 }
    45 
    44 
    46 TsDeviceDialogPlugin::~TsDeviceDialogPlugin()
    45 TsDeviceDialogPlugin::~TsDeviceDialogPlugin()
    47 {
    46 {
    68 {
    67 {
    69     Q_UNUSED(parameters)
    68     Q_UNUSED(parameters)
    70     TsDeviceDialog *dialog(0);
    69     TsDeviceDialog *dialog(0);
    71     if (deviceDialogType == KTsDialogType) {
    70     if (deviceDialogType == KTsDialogType) {
    72         if (0 == mModel) {
    71         if (0 == mModel) {
       
    72             mStorage = new TsTaskMonitor(this);
       
    73             if (0 == mStorage) {
       
    74                 return 0;
       
    75             }
    73             QtMobility::QServiceManager serviceManager;
    76             QtMobility::QServiceManager serviceManager;
    74             QObject *objPtr(serviceManager.loadInterface("com.nokia.qt.activities.ActivityManager"));
    77             QObject *objPtr(serviceManager.loadInterface("com.nokia.qt.activities.ActivityManager"));
    75             if (objPtr) {
    78             if (objPtr) {
    76                 objPtr->setParent(this);//make it autodestucted
    79                 objPtr->setParent(this);//make it autodestucted
    77             } else {
    80             } else {
    94         dialog->changeOrientation(dialog->mainWindow()->orientation());
    97         dialog->changeOrientation(dialog->mainWindow()->orientation());
    95 
    98 
    96         grid->setItemPrototype(new TsTasksGridItem());
    99         grid->setItemPrototype(new TsTasksGridItem());
    97         grid->setModel(mModel);
   100         grid->setModel(mModel);
    98 
   101 
    99         static_cast<TsModel *>(mModel)->updateModel();
   102         //static_cast<TsModel *>(mModel)->updateModel();
   100 
   103 
   101         // connect the grid and model
   104         // connect the grid and model
   102         qRegisterMetaType<QModelIndex>("QModelIndex");
   105         qRegisterMetaType<QModelIndex>("QModelIndex");
   103         
   106         
   104         disconnect(grid, SIGNAL(activated(QModelIndex)), this, SLOT(activated(QModelIndex)));
   107         disconnect(grid, SIGNAL(activated(QModelIndex)), mModel, SLOT(openApplication(QModelIndex)));
   105         disconnect(grid, SIGNAL(pressed(QModelIndex)), this, SLOT(pressed()));
   108         disconnect(grid, SIGNAL(activated(QModelIndex)), dialog, SLOT(close()));
   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)));
   109         disconnect(grid, SIGNAL(deleteButtonClicked(QModelIndex)), mModel, SLOT(closeApplication(QModelIndex)));
   110         
   110         
   111         connect(grid, SIGNAL(activated(QModelIndex)), this, SLOT(activated(QModelIndex)));
   111         connect(grid, SIGNAL(activated(QModelIndex)), mModel, SLOT(openApplication(QModelIndex)));
   112         connect(grid, SIGNAL(pressed(QModelIndex)), this, SLOT(pressed()));
   112         connect(grid, SIGNAL(activated(QModelIndex)), dialog, SLOT(close()));
   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);
   113         connect(grid, SIGNAL(deleteButtonClicked(QModelIndex)), mModel, SLOT(closeApplication(QModelIndex)), Qt::QueuedConnection);
   117     }
   114     }
   118     return dialog;
   115     return dialog;
   119 }
   116 }
   120 
   117 
   155 int TsDeviceDialogPlugin::error() const
   152 int TsDeviceDialogPlugin::error() const
   156 {
   153 {
   157     return mError;
   154     return mError;
   158 }
   155 }
   159 
   156 
   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)
   157 Q_EXPORT_PLUGIN2(tsdevicedialogplugin, TsDeviceDialogPlugin)