activityfw/orbitintegration/hb/src/hbcore/activity/hbactivitymanager.cpp
changeset 117 c63ee96dbe5f
equal deleted inserted replaced
115:3ab5c078b490 117:c63ee96dbe5f
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (developer.feedback@nokia.com)
       
     6 **
       
     7 ** This file is part of the HbCore module of the UI Extensions for Mobile.
       
     8 **
       
     9 ** GNU Lesser General Public License Usage
       
    10 ** This file may be used under the terms of the GNU Lesser General Public
       
    11 ** License version 2.1 as published by the Free Software Foundation and
       
    12 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
       
    13 ** Please review the following information to ensure the GNU Lesser General
       
    14 ** Public License version 2.1 requirements will be met:
       
    15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    16 **
       
    17 ** In addition, as a special exception, Nokia gives you certain additional
       
    18 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    20 **
       
    21 ** If you have questions regarding the use of this file, please contact
       
    22 ** Nokia at developer.feedback@nokia.com.
       
    23 **
       
    24 ****************************************************************************/
       
    25 
       
    26 #include "hbactivitymanager.h"
       
    27 #include "hbactivitymanager_p.h"
       
    28 
       
    29 #include <QPluginLoader>
       
    30 #include <QLibrary>
       
    31 #include <QDir>
       
    32 
       
    33 #include "hbmainwindow.h"
       
    34 #include "hbinstance.h"
       
    35 #include "hbactivityplugininterface_p.h"
       
    36 
       
    37 /*!
       
    38     @beta
       
    39     @hbcore
       
    40     \class HbActivityManager
       
    41     \brief HbActivityManager is an access point for Activities features.
       
    42     
       
    43     Activities can be described as stored application states (for example bookmarks
       
    44     in web browser) or actions that can be performed using application (play next
       
    45     song, start new game).
       
    46     
       
    47     The HbActivityManager class allows to use Activities features in Hb application.
       
    48     It can be used to access, add, remove and modify activities. It also notifies the
       
    49     application about activity change requests from other applications.
       
    50 */
       
    51 
       
    52 /*!
       
    53 \internal
       
    54 */
       
    55 HbActivityManagerPrivate::HbActivityManagerPrivate(HbActivityManager *q) : q(q), mActivityPlugin(0)
       
    56 {
       
    57 }
       
    58 
       
    59 /*!
       
    60 \internal
       
    61 */
       
    62 HbActivityManagerPrivate::~HbActivityManagerPrivate()
       
    63 {
       
    64 }
       
    65 
       
    66 /*!
       
    67 \internal
       
    68 */
       
    69 HbActivityPluginInterface *HbActivityManagerPrivate::activityPlugin() const
       
    70 {
       
    71     if (!mActivityPlugin) {
       
    72         foreach (const QString &path, QCoreApplication::libraryPaths()) {
       
    73             QString pluginPath;
       
    74             
       
    75             QString libPath = QDir::toNativeSeparators(path) + QDir::separator() + QLatin1String("hbactivityplugin");
       
    76 #ifdef Q_OS_SYMBIAN
       
    77             libPath += QLatin1String(".qtplugin");
       
    78             QLibrary library(libPath);           
       
    79             if (QFile::exists(libPath) && library.load()) {
       
    80                 library.unload();
       
    81                 pluginPath = libPath;
       
    82             }
       
    83 #else       
       
    84             QLibrary library(libPath);           
       
    85             if (library.load()) {
       
    86                 library.unload();
       
    87                 pluginPath = library.fileName();
       
    88             }     
       
    89 #endif      
       
    90             
       
    91             QPluginLoader loader(pluginPath);
       
    92             QObject *pluginInstance = loader.instance();
       
    93             if (pluginInstance) {
       
    94                 mActivityPlugin = qobject_cast<HbActivityPluginInterface*>(pluginInstance);
       
    95                 if (mActivityPlugin) {
       
    96                     q->connect(pluginInstance, SIGNAL(activityRequested(QString)), q, SIGNAL(activityRequested(QString)));
       
    97                 } else {
       
    98 #if defined(Q_OS_SYMBIAN)
       
    99                     qWarning("Cannot load activity plugin. Features related to activities won't be available.");
       
   100 #endif
       
   101                     loader.unload();
       
   102                 }
       
   103             }
       
   104         }
       
   105     }
       
   106     return mActivityPlugin;
       
   107 }
       
   108 
       
   109 /*!
       
   110 \internal
       
   111 */
       
   112 bool HbActivityManagerPrivate::addActivity(const QString &activityId, const QVariant &data, const QVariantHash &parameters)
       
   113 {
       
   114     bool result(false);
       
   115     HbActivityPluginInterface *plugin = activityPlugin();
       
   116     if (plugin) {
       
   117         result = plugin->addActivity(activityId, data, parameters);
       
   118     }
       
   119     return result;
       
   120 }
       
   121 
       
   122 /*!
       
   123 \internal
       
   124 */
       
   125 bool HbActivityManagerPrivate::removeActivity(const QString &activityId)
       
   126 {
       
   127     bool result(false);
       
   128     HbActivityPluginInterface *plugin = activityPlugin();
       
   129     if (plugin) {
       
   130         result = plugin->removeActivity(activityId);
       
   131     }
       
   132     return result;
       
   133 }
       
   134 
       
   135 /*!
       
   136 \internal
       
   137 */
       
   138 QList<QVariantHash> HbActivityManagerPrivate::activities() const
       
   139 {
       
   140     HbActivityPluginInterface *plugin = activityPlugin();
       
   141     if (plugin) {
       
   142         return plugin->activities();
       
   143     } else {
       
   144         return QList<QVariantHash>();
       
   145     }
       
   146 }
       
   147 
       
   148 /*!
       
   149 \internal
       
   150 */
       
   151 bool HbActivityManagerPrivate::updateActivity(const QString &activityId, const QVariant &data, const QVariantHash &parameters)
       
   152 {
       
   153     bool result(false);
       
   154     HbActivityPluginInterface *plugin = activityPlugin();
       
   155     if (plugin) {
       
   156         result = plugin->updateActivity(activityId, data, parameters);
       
   157     }
       
   158     return result;
       
   159 }
       
   160 
       
   161 /*!
       
   162 \internal
       
   163 */
       
   164 QVariant HbActivityManagerPrivate::activityData(const QString &activityId) const
       
   165 {
       
   166     QVariant result;
       
   167     HbActivityPluginInterface *plugin = activityPlugin();
       
   168     if (plugin) {
       
   169         result = plugin->activityData(activityId);
       
   170     }
       
   171     return result;
       
   172 }
       
   173 
       
   174 /*!
       
   175 \internal
       
   176 */
       
   177 bool HbActivityManagerPrivate::waitActivity()
       
   178 {
       
   179     bool result(false);
       
   180     HbActivityPluginInterface *plugin = activityPlugin();
       
   181     if (plugin) {
       
   182         result = plugin->waitActivity();
       
   183     }
       
   184     return result;
       
   185 }
       
   186 
       
   187 /*!
       
   188 \internal
       
   189 */
       
   190 void HbActivityManagerPrivate::parseCommandLine(const QStringList &commandLineParams, Hb::ActivationReason &reason, QString &id, QVariantHash &params) const
       
   191 {
       
   192     HbActivityPluginInterface *plugin = activityPlugin();
       
   193     if (plugin) {
       
   194         QVariantHash activityParams = plugin->parseCommandLine(commandLineParams);
       
   195         if (!activityParams.isEmpty()) {
       
   196             reason = Hb::ActivationReasonActivity;
       
   197             id = activityParams.value("activityname").toString();
       
   198             params = activityParams;
       
   199         }
       
   200     }
       
   201 }
       
   202 
       
   203 /*!
       
   204     Constructor
       
   205     \a parent. Parent of this object.
       
   206  */
       
   207 HbActivityManager::HbActivityManager(QObject *parent) : QObject(parent), d_ptr(new HbActivityManagerPrivate(this))
       
   208 {
       
   209 }
       
   210 
       
   211 /*!
       
   212     Destructor
       
   213  */
       
   214 HbActivityManager::~HbActivityManager()
       
   215 {
       
   216     delete d_ptr;
       
   217 }
       
   218 
       
   219 /*!
       
   220     Allows to save activity.
       
   221     \a activityId. Activity name used as identifier of activities
       
   222     \a data. Activity data that should be stored. It will allow application to restore its state later 
       
   223     \a parameters. Activity properties: screenshot, localized name, hidden flag, etc.
       
   224     Returns true if activity was succesfully saved, otherwise returns false.
       
   225  */
       
   226 bool HbActivityManager::addActivity(const QString &activityId, const QVariant &data, const QVariantHash &parameters)
       
   227 {
       
   228     Q_D(HbActivityManager);
       
   229     return d->addActivity(activityId, data, parameters);
       
   230 }
       
   231 
       
   232 /*!
       
   233     Allows to delete activity.
       
   234     \a activityId. Activity name used as identifier of activities
       
   235     Returns true if activity was succesfully deleted, otherwise returns false.
       
   236  */
       
   237 bool HbActivityManager::removeActivity(const QString &activityId)
       
   238 {
       
   239     Q_D(HbActivityManager);
       
   240     return d->removeActivity(activityId);
       
   241 }
       
   242 
       
   243 /*!
       
   244     Allows to update saved activity.
       
   245     \a activityId. Activity name used as identifier of activities
       
   246     \a data. Activity data that should be stored. It will allow application to restore its state later 
       
   247     \a parameters. Activity properties: screenshot, localized name, hidden flag, etc.
       
   248     Returns true if activity was succesfully updated, otherwise returns false.
       
   249  */
       
   250 bool HbActivityManager::updateActivity(const QString &activityId, const QVariant &data, const QVariantHash &parameters)
       
   251 {
       
   252     Q_D(HbActivityManager);
       
   253     return d->updateActivity(activityId, data, parameters);
       
   254 }
       
   255 
       
   256 /*!
       
   257     Returns activities list. It returns activities as name and screenshot.
       
   258  */
       
   259 QList<QVariantHash> HbActivityManager::activities() const
       
   260 {
       
   261     Q_D(const HbActivityManager);
       
   262     return d->activities();
       
   263 }
       
   264 
       
   265 /*!
       
   266     Returns data of activity specified by \a activityId
       
   267  */
       
   268 QVariant HbActivityManager::activityData(const QString &activityId) const
       
   269 {
       
   270     Q_D(const HbActivityManager);
       
   271     return d->activityData(activityId);
       
   272 }
       
   273 
       
   274 /*!
       
   275     Subscribes to activity manager
       
   276  */
       
   277 bool HbActivityManager::waitActivity() 
       
   278 {
       
   279     Q_D(HbActivityManager);
       
   280     return d->waitActivity();
       
   281 }
       
   282 
       
   283 /*!
       
   284     Searches \a commandLineArguments for pair of "-activity" marker and
       
   285     activity URI, which should have following syntax:
       
   286 
       
   287     appto://UID3?activityname=activity-name-value&key1=value
       
   288 
       
   289     If both marker and valid URI are found, \a reason is set to
       
   290     Hb::ActivationReasonActivity, and \a activityId and \a parameters are
       
   291     filled with parsed values.
       
   292 */
       
   293 void HbActivityManager::parseCommandLine(const QStringList &commandLineParams, Hb::ActivationReason &reason, QString &id, QVariantHash &params) const
       
   294 {
       
   295     Q_D(const HbActivityManager);
       
   296     d->parseCommandLine(commandLineParams, reason, id, params);
       
   297 }