taskswitcherapp/tsdevicedialogplugin/src/tsdevicedialogplugin.cpp
changeset 60 30f14686fb04
parent 55 03646e8da489
equal deleted inserted replaced
55:03646e8da489 60:30f14686fb04
    13 *
    13 *
    14 * Description:
    14 * Description:
    15 *
    15 *
    16 */
    16 */
    17 
    17 
       
    18 #include <QTranslator>
       
    19 #include <QCoreApplication>
       
    20 #include <QLocale>
    18 #include <QtPlugin>
    21 #include <QtPlugin>
       
    22 
       
    23 #include <qservicemanager.h>
       
    24 
    19 #include <hbdevicedialog.h>
    25 #include <hbdevicedialog.h>
    20 #include <HbMainWindow>
    26 #include <HbMainWindow>
    21 #include <qservicemanager.h>
       
    22 
    27 
    23 #include "tsdevicedialogplugin.h"
    28 #include "tsdevicedialogplugin.h"
    24 #include "tsdevicedialog.h"
    29 #include "tsdevicedialogcontainer.h"
    25 #include "tstasksgrid.h"
    30 #include "tstasksgrid.h"
    26 #include "tstasksgriditem.h"
    31 #include "tstasksgriditem.h"
    27 #include "tsdocumentloader.h"
    32 #include "tsdocumentloader.h"
    28 #include "tsmodel.h"
    33 #include "tsmodel.h"
    29 
    34 
    31     \class TsDeviceDialogPlugin
    36     \class TsDeviceDialogPlugin
    32     \ingroup group_tsdevicedialogplugin
    37     \ingroup group_tsdevicedialogplugin
    33     \brief TaskSwitcher Device Dialog Plug-in.
    38     \brief TaskSwitcher Device Dialog Plug-in.
    34  */
    39  */
    35 
    40 
    36 const QString KTsDialogType = "com.nokia.taskswitcher.tsdevicedialogplugin/1.0";
    41 namespace
    37 
    42 {
       
    43     const char KTranslationPath[] = "resource/qt/translations";
       
    44     const char KTsDialogType[] = "com.nokia.taskswitcher.tsdevicedialogplugin/1.0";
       
    45 } 
       
    46  
    38 /*!
    47 /*!
    39     Constructor.
    48     Constructor.
    40  */
    49  */
    41 TsDeviceDialogPlugin::TsDeviceDialogPlugin() : mError(0), mModel(0), mStorage(0)
    50 TsDeviceDialogPlugin::TsDeviceDialogPlugin() : mError(0), mModel(0), mStorage(0), mTriedToLoadTranslation(false)
    42 {
    51 {
    43 }
    52 }
    44 
    53 
    45 TsDeviceDialogPlugin::~TsDeviceDialogPlugin()
    54 TsDeviceDialogPlugin::~TsDeviceDialogPlugin()
    46 {
    55 {
    54     Q_UNUSED(deviceDialogType)
    63     Q_UNUSED(deviceDialogType)
    55     Q_UNUSED(parameters)
    64     Q_UNUSED(parameters)
    56     Q_UNUSED(securityInfo)
    65     Q_UNUSED(securityInfo)
    57 
    66 
    58     // This plugin doesn't perform operations that may compromise security.
    67     // This plugin doesn't perform operations that may compromise security.
    59     // All clients are allowed to use.
    68     // All clients are allowed to use it.
    60     return true;
    69     return true;
    61 }
    70 }
    62 
    71 
    63 /*!
    72 /*!
    64     \reimp
    73     \reimp
    65  */
    74  */
    66 HbDeviceDialogInterface *TsDeviceDialogPlugin::createDeviceDialog(const QString &deviceDialogType, const QVariantMap &parameters)
    75 HbDeviceDialogInterface *TsDeviceDialogPlugin::createDeviceDialog(const QString &deviceDialogType, const QVariantMap &parameters)
    67 {
    76 {
    68     Q_UNUSED(parameters)
    77     Q_UNUSED(parameters)
    69     TsDeviceDialog *dialog(0);
    78     HbDeviceDialogInterface *dialogInterface(0);
    70     if (deviceDialogType == KTsDialogType) {
    79     if (deviceDialogType == QString(KTsDialogType)) {
       
    80         // lazy loading of translation
       
    81         if (!mTriedToLoadTranslation) {
       
    82             mTriedToLoadTranslation = true;
       
    83 
       
    84             QTranslator *translator = new QTranslator(this);
       
    85             QString translationFile = QString("taskswitcher_%1").arg(QLocale::system().name());
       
    86     
       
    87             bool translationLoaded(false);
       
    88             #ifdef Q_OS_SYMBIAN
       
    89                 translationLoaded = translator->load(translationFile, QString("z:/") + KTranslationPath);
       
    90                 if (!translationLoaded) {
       
    91                     translationLoaded = translator->load(translationFile, QString("c:/") + KTranslationPath);
       
    92                 }
       
    93             #else
       
    94                 translationLoaded = translator->load(translationFile, QString(KTranslationPath));
       
    95             #endif //Q_OS_SYMBIAN
       
    96 
       
    97             Q_ASSERT(translationLoaded);
       
    98             qApp->installTranslator(translator);
       
    99         }
       
   100     
       
   101         // lazy loading of model
    71         if (0 == mModel) {
   102         if (0 == mModel) {
    72             mStorage = new TsTaskMonitor(this);
   103             mStorage = new TsTaskMonitor(this);
    73             if (0 == mStorage) {
   104             if (0 == mStorage) {
    74                 return 0;
   105                 return 0; // provider of running application list is critical
    75             }
   106             }
       
   107             
    76             QtMobility::QServiceManager serviceManager;
   108             QtMobility::QServiceManager serviceManager;
    77             QObject *objPtr(serviceManager.loadInterface("com.nokia.qt.activities.ActivityManager"));
   109             QObject *activityManager(serviceManager.loadInterface("com.nokia.qt.activities.ActivityManager"));
    78             if (objPtr) {
   110             if (activityManager) {
    79                 objPtr->setParent(this);//make it autodestucted
   111                 activityManager->setParent(this); //make it autodestructed
    80             } else {
   112             } else {
    81                 objPtr = this;//activity plugin is not present. provide invalid instance because its not critical functionality.
   113                 activityManager = 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.
   114                 //QMetaObject::invokeMethod is safe to use in such a case.
    83             }
   115             }
    84             mModel = new TsModel(*mStorage, *objPtr);
   116             mModel = new TsModel(*mStorage, *activityManager);
    85         }
   117         }
    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         
   118         
   107         disconnect(grid, SIGNAL(activated(QModelIndex)), mModel, SLOT(openApplication(QModelIndex)));
   119         dialogInterface = new TsDeviceDialogContainer(mModel);
   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     }
   120     }
   115     return dialog;
   121     return dialogInterface;
   116 }
   122 }
   117 
   123 
   118 /*!
   124 /*!
   119     \reimp
   125     \reimp
   120  */
   126  */
   133 /*!
   139 /*!
   134     \reimp
   140     \reimp
   135  */
   141  */
   136 QStringList TsDeviceDialogPlugin::deviceDialogTypes() const
   142 QStringList TsDeviceDialogPlugin::deviceDialogTypes() const
   137 {
   143 {
   138     return QStringList(KTsDialogType);
   144     return QStringList(QString(KTsDialogType));
   139 }
   145 }
   140 
   146 
   141 /*!
   147 /*!
   142     \reimp
   148     \reimp
   143  */
   149  */