tsdevicedialog/tsdevicedialogplugin/src/tsdevicedialogplugin.cpp
author hgs
Mon, 20 Sep 2010 10:22:22 +0300
changeset 119 50e220be30d1
parent 116 305818acdca4
permissions -rw-r--r--
201037
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
99
hgs
parents:
diff changeset
     1
/*
hgs
parents:
diff changeset
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
hgs
parents:
diff changeset
     3
* All rights reserved.
hgs
parents:
diff changeset
     4
* This component and the accompanying materials are made available
hgs
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
hgs
parents:
diff changeset
     6
* which accompanies this distribution, and is available
hgs
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
hgs
parents:
diff changeset
     8
*
hgs
parents:
diff changeset
     9
* Initial Contributors:
hgs
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
hgs
parents:
diff changeset
    11
*
hgs
parents:
diff changeset
    12
* Contributors:
hgs
parents:
diff changeset
    13
*
hgs
parents:
diff changeset
    14
* Description:
hgs
parents:
diff changeset
    15
*
hgs
parents:
diff changeset
    16
*/
hgs
parents:
diff changeset
    17
112
hgs
parents: 107
diff changeset
    18
#include "tsdevicedialogplugin.h"
hgs
parents: 107
diff changeset
    19
99
hgs
parents:
diff changeset
    20
#include <QTranslator>
hgs
parents:
diff changeset
    21
#include <QCoreApplication>
hgs
parents:
diff changeset
    22
#include <QLocale>
hgs
parents:
diff changeset
    23
#include <QtPlugin>
112
hgs
parents: 107
diff changeset
    24
hgs
parents: 107
diff changeset
    25
#include <QValueSpacePublisher>
hgs
parents: 107
diff changeset
    26
hgs
parents: 107
diff changeset
    27
#include <HbDeviceDialog>
99
hgs
parents:
diff changeset
    28
#include <HbMainWindow>
hgs
parents:
diff changeset
    29
112
hgs
parents: 107
diff changeset
    30
#include <tspropertydefs.h>
hgs
parents: 107
diff changeset
    31
99
hgs
parents:
diff changeset
    32
#include "tsdevicedialogcontainer.h"
hgs
parents:
diff changeset
    33
#include "tstasksgrid.h"
hgs
parents:
diff changeset
    34
#include "tstasksgriditem.h"
hgs
parents:
diff changeset
    35
#include "tsdocumentloader.h"
hgs
parents:
diff changeset
    36
#include "tsmodel.h"
hgs
parents:
diff changeset
    37
112
hgs
parents: 107
diff changeset
    38
QTM_USE_NAMESPACE
hgs
parents: 107
diff changeset
    39
99
hgs
parents:
diff changeset
    40
/*!
hgs
parents:
diff changeset
    41
    \class TsDeviceDialogPlugin
hgs
parents:
diff changeset
    42
    \ingroup group_tsdevicedialogplugin
hgs
parents:
diff changeset
    43
    \brief TaskSwitcher Device Dialog Plug-in.
hgs
parents:
diff changeset
    44
 */
hgs
parents:
diff changeset
    45
hgs
parents:
diff changeset
    46
namespace
hgs
parents:
diff changeset
    47
{
hgs
parents:
diff changeset
    48
    const char KTranslationPath[] = "resource/qt/translations";
hgs
parents:
diff changeset
    49
    const char KTsDialogType[] = "com.nokia.taskswitcher.tsdevicedialogplugin/1.0";
116
hgs
parents: 112
diff changeset
    50
}
hgs
parents: 112
diff changeset
    51
99
hgs
parents:
diff changeset
    52
/*!
hgs
parents:
diff changeset
    53
    Constructor.
hgs
parents:
diff changeset
    54
 */
107
hgs
parents: 102
diff changeset
    55
TsDeviceDialogPlugin::TsDeviceDialogPlugin()
116
hgs
parents: 112
diff changeset
    56
    :
hgs
parents: 112
diff changeset
    57
    mModel(0),
hgs
parents: 112
diff changeset
    58
    mStorage(0),
hgs
parents: 112
diff changeset
    59
    mTriedToLoadTranslation(false)
99
hgs
parents:
diff changeset
    60
{
119
hgs
parents: 116
diff changeset
    61
    // ensure the visibility property is set to false, so the TaskSwitcher
hgs
parents: 116
diff changeset
    62
    // in case when hbdevicedialogappserver crashes when TS is visible.
hgs
parents: 116
diff changeset
    63
    QValueSpacePublisher visibilityPublisher(TsProperty::KTsPath);
hgs
parents: 116
diff changeset
    64
    visibilityPublisher.setValue(TsProperty::KVisibilityPath, static_cast<int>(false));
hgs
parents: 116
diff changeset
    65
    visibilityPublisher.sync();
99
hgs
parents:
diff changeset
    66
}
hgs
parents:
diff changeset
    67
hgs
parents:
diff changeset
    68
TsDeviceDialogPlugin::~TsDeviceDialogPlugin()
hgs
parents:
diff changeset
    69
{
hgs
parents:
diff changeset
    70
}
hgs
parents:
diff changeset
    71
/*!
hgs
parents:
diff changeset
    72
    \reimp
hgs
parents:
diff changeset
    73
 */
116
hgs
parents: 112
diff changeset
    74
bool TsDeviceDialogPlugin::accessAllowed(const QString &deviceDialogType,
hgs
parents: 112
diff changeset
    75
                                         const QVariantMap &parameters,
107
hgs
parents: 102
diff changeset
    76
                                         const QVariantMap &securityInfo) const
99
hgs
parents:
diff changeset
    77
{
hgs
parents:
diff changeset
    78
    Q_UNUSED(deviceDialogType)
hgs
parents:
diff changeset
    79
    Q_UNUSED(parameters)
hgs
parents:
diff changeset
    80
    Q_UNUSED(securityInfo)
hgs
parents:
diff changeset
    81
hgs
parents:
diff changeset
    82
    // This plugin doesn't perform operations that may compromise security.
hgs
parents:
diff changeset
    83
    // All clients are allowed to use it.
hgs
parents:
diff changeset
    84
    return true;
hgs
parents:
diff changeset
    85
}
hgs
parents:
diff changeset
    86
hgs
parents:
diff changeset
    87
/*!
hgs
parents:
diff changeset
    88
    \reimp
hgs
parents:
diff changeset
    89
 */
116
hgs
parents: 112
diff changeset
    90
HbDeviceDialogInterface *
hgs
parents: 112
diff changeset
    91
TsDeviceDialogPlugin::createDeviceDialog(const QString &deviceDialogType,
107
hgs
parents: 102
diff changeset
    92
                                         const QVariantMap &parameters)
99
hgs
parents:
diff changeset
    93
{
hgs
parents:
diff changeset
    94
    Q_UNUSED(parameters)
hgs
parents:
diff changeset
    95
    HbDeviceDialogInterface *dialogInterface(0);
hgs
parents:
diff changeset
    96
    if (deviceDialogType == QString(KTsDialogType)) {
hgs
parents:
diff changeset
    97
        // lazy loading of translation
hgs
parents:
diff changeset
    98
        if (!mTriedToLoadTranslation) {
hgs
parents:
diff changeset
    99
            mTriedToLoadTranslation = true;
hgs
parents:
diff changeset
   100
hgs
parents:
diff changeset
   101
            QTranslator *translator = new QTranslator(this);
116
hgs
parents: 112
diff changeset
   102
            QString translationFile =
107
hgs
parents: 102
diff changeset
   103
                QString("taskswitcher_%1").arg(QLocale::system().name());
116
hgs
parents: 112
diff changeset
   104
99
hgs
parents:
diff changeset
   105
            bool translationLoaded(false);
116
hgs
parents: 112
diff changeset
   106
#ifdef Q_OS_SYMBIAN
hgs
parents: 112
diff changeset
   107
            translationLoaded =
hgs
parents: 112
diff changeset
   108
                translator->load(translationFile,
hgs
parents: 112
diff changeset
   109
                                 QString("z:/") + KTranslationPath);
hgs
parents: 112
diff changeset
   110
            if (!translationLoaded) {
hgs
parents: 112
diff changeset
   111
                translationLoaded =
hgs
parents: 112
diff changeset
   112
                    translator->load(translationFile,
hgs
parents: 112
diff changeset
   113
                                     QString("c:/") + KTranslationPath);
hgs
parents: 112
diff changeset
   114
            }
hgs
parents: 112
diff changeset
   115
#else
hgs
parents: 112
diff changeset
   116
            translationLoaded =
hgs
parents: 112
diff changeset
   117
                translator->load(translationFile,
hgs
parents: 112
diff changeset
   118
                                 QString(KTranslationPath));
hgs
parents: 112
diff changeset
   119
#endif //Q_OS_SYMBIAN
99
hgs
parents:
diff changeset
   120
hgs
parents:
diff changeset
   121
            Q_ASSERT(translationLoaded);
hgs
parents:
diff changeset
   122
            qApp->installTranslator(translator);
hgs
parents:
diff changeset
   123
        }
116
hgs
parents: 112
diff changeset
   124
99
hgs
parents:
diff changeset
   125
        // lazy loading of model
112
hgs
parents: 107
diff changeset
   126
        if (!mModel) {
99
hgs
parents:
diff changeset
   127
            mStorage = new TsTaskMonitor(this);
119
hgs
parents: 116
diff changeset
   128
            mModel = new TsModel(*mStorage, this);
99
hgs
parents:
diff changeset
   129
        }
116
hgs
parents: 112
diff changeset
   130
112
hgs
parents: 107
diff changeset
   131
        // ensure the dismiss request property is set to false
hgs
parents: 107
diff changeset
   132
hgs
parents: 107
diff changeset
   133
        QValueSpacePublisher dismissRequestPublisher(TsProperty::KTsPath);
hgs
parents: 107
diff changeset
   134
        dismissRequestPublisher.setValue(TsProperty::KDismissRequestPath, static_cast<int>(false));
hgs
parents: 107
diff changeset
   135
        dismissRequestPublisher.sync();
hgs
parents: 107
diff changeset
   136
116
hgs
parents: 112
diff changeset
   137
112
hgs
parents: 107
diff changeset
   138
        // create device dialog
99
hgs
parents:
diff changeset
   139
        dialogInterface = new TsDeviceDialogContainer(mModel);
hgs
parents:
diff changeset
   140
    }
hgs
parents:
diff changeset
   141
    return dialogInterface;
hgs
parents:
diff changeset
   142
}
hgs
parents:
diff changeset
   143
hgs
parents:
diff changeset
   144
/*!
hgs
parents:
diff changeset
   145
    \reimp
hgs
parents:
diff changeset
   146
 */
116
hgs
parents: 112
diff changeset
   147
bool TsDeviceDialogPlugin::deviceDialogInfo(const QString &deviceDialogType,
hgs
parents: 112
diff changeset
   148
                                            const QVariantMap &parameters,
107
hgs
parents: 102
diff changeset
   149
                                            DeviceDialogInfo *info) const
99
hgs
parents:
diff changeset
   150
{
hgs
parents:
diff changeset
   151
    Q_UNUSED(parameters)
hgs
parents:
diff changeset
   152
    Q_UNUSED(deviceDialogType)
hgs
parents:
diff changeset
   153
hgs
parents:
diff changeset
   154
    info->group = GenericDeviceDialogGroup;
102
hgs
parents: 99
diff changeset
   155
    info->flags = SingleInstance;
99
hgs
parents:
diff changeset
   156
    info->priority = DefaultPriority;
hgs
parents:
diff changeset
   157
hgs
parents:
diff changeset
   158
    return true;
hgs
parents:
diff changeset
   159
}
hgs
parents:
diff changeset
   160
hgs
parents:
diff changeset
   161
/*!
hgs
parents:
diff changeset
   162
    \reimp
hgs
parents:
diff changeset
   163
 */
hgs
parents:
diff changeset
   164
QStringList TsDeviceDialogPlugin::deviceDialogTypes() const
hgs
parents:
diff changeset
   165
{
hgs
parents:
diff changeset
   166
    return QStringList(QString(KTsDialogType));
hgs
parents:
diff changeset
   167
}
hgs
parents:
diff changeset
   168
hgs
parents:
diff changeset
   169
/*!
hgs
parents:
diff changeset
   170
    \reimp
hgs
parents:
diff changeset
   171
 */
hgs
parents:
diff changeset
   172
HbDeviceDialogPlugin::PluginFlags TsDeviceDialogPlugin::pluginFlags() const
hgs
parents:
diff changeset
   173
{
hgs
parents:
diff changeset
   174
    return PluginFlags(PreloadPlugin | KeepPluginLoaded);
hgs
parents:
diff changeset
   175
}
hgs
parents:
diff changeset
   176
hgs
parents:
diff changeset
   177
/*!
hgs
parents:
diff changeset
   178
    \reimp
hgs
parents:
diff changeset
   179
 */
hgs
parents:
diff changeset
   180
int TsDeviceDialogPlugin::error() const
hgs
parents:
diff changeset
   181
{
107
hgs
parents: 102
diff changeset
   182
    return 0;
99
hgs
parents:
diff changeset
   183
}
hgs
parents:
diff changeset
   184
hgs
parents:
diff changeset
   185
#ifdef COVERAGE_MEASUREMENT
hgs
parents:
diff changeset
   186
#pragma CTC SKIP
hgs
parents:
diff changeset
   187
#endif //COVERAGE_MEASUREMENT
hgs
parents:
diff changeset
   188
hgs
parents:
diff changeset
   189
Q_EXPORT_PLUGIN2(tsdevicedialogplugin, TsDeviceDialogPlugin)
hgs
parents:
diff changeset
   190
hgs
parents:
diff changeset
   191
#ifdef COVERAGE_MEASUREMENT
hgs
parents:
diff changeset
   192
#pragma CTC ENDSKIP
hgs
parents:
diff changeset
   193
#endif //COVERAGE_MEASUREMENT