contentstorage/caclient/stub/src/hswidgetregistryservice.cpp
branchRCL_3
changeset 113 0efa10d348c0
equal deleted inserted replaced
111:053c6c7c14f3 113:0efa10d348c0
       
     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:  Manages installed widgets information
       
    15 *
       
    16 */
       
    17 
       
    18 #include <QDir>
       
    19 #include <QPluginLoader>
       
    20 #include <QDebug>
       
    21 
       
    22 #include "hswidgetregistryservice.h"
       
    23 #include "hswidgetregistryservice_p.h"
       
    24 #include "hswidgetcomponentdescriptor.h"
       
    25 #include "hswidgetcomponentparser.h"
       
    26 
       
    27 
       
    28 /*!
       
    29     ?Qt_style_documentation
       
    30 */
       
    31 HsWidgetRegistryServicePrivate::HsWidgetRegistryServicePrivate(
       
    32     const QString &installationPath, HsWidgetRegistryService *ptrToPublic,
       
    33     QObject *parent) : QObject(parent)
       
    34 {
       
    35     Q_UNUSED(ptrToPublic);
       
    36     QStringList manifestPaths;
       
    37 
       
    38     this->mInstallationPath = installationPath;
       
    39     QDir currentDir = QDir::current();
       
    40     QString currentPath = currentDir.absolutePath();
       
    41 
       
    42     //Check widget installation dirs from root of different drives
       
    43     QFileInfoList drives = QDir::drives();
       
    44 
       
    45     // ?
       
    46     for (int i=0; i < drives.count(); i++) {
       
    47         QFileInfo drive = drives.at(i);
       
    48         QString driveLetter = drive.absolutePath();
       
    49         QString path = currentPath + "/" + mInstallationPath;
       
    50         QDir registryDir(path);
       
    51 
       
    52         if (registryDir.exists()) {
       
    53             // ?
       
    54             mManifestDirectories[path] = readManifestDirectories(path);
       
    55         }
       
    56     }
       
    57 }
       
    58 
       
    59 /*!
       
    60     ?Qt_style_documentation
       
    61 */
       
    62 HsWidgetRegistryServicePrivate::~HsWidgetRegistryServicePrivate()
       
    63 {
       
    64 
       
    65 }
       
    66 
       
    67 /*!
       
    68     ?Qt_style_documentation
       
    69 */
       
    70 QList<HsWidgetComponentDescriptor> HsWidgetRegistryServicePrivate::widgets()
       
    71 {
       
    72     QList<HsWidgetComponentDescriptor> widgets;
       
    73     QMapIterator<QString, QStringList> i(mManifestDirectories);
       
    74 
       
    75     while (i.hasNext()) {
       
    76         i.next();
       
    77         QStringList manifestFileList = i.value();
       
    78         QDir manifestDir(i.key());
       
    79 
       
    80         // ?
       
    81         for (int h=0; h < manifestFileList.count(); h++) {
       
    82             widgets << readManifestFile(manifestDir.absoluteFilePath(manifestFileList.at(h)));
       
    83         }
       
    84     }
       
    85     return widgets;
       
    86 }
       
    87 
       
    88 /*!
       
    89     ?Qt_style_documentation
       
    90 */
       
    91 /*
       
    92 IHsWidgetProvider *HsWidgetRegistryServicePrivate::loadProviderFromPlugin(
       
    93     const QString &pluginName)
       
    94 {
       
    95     QPluginLoader loader(pluginName);
       
    96     QObject *plugin = loader.instance();
       
    97     IHsWidgetProvider *provider = qobject_cast<IHsWidgetProvider *>(plugin);
       
    98 
       
    99     if (provider) {
       
   100         // ?
       
   101         return provider;
       
   102     }
       
   103 
       
   104     // Don't leak memory if provider not IHsWidgetProvider
       
   105     if (plugin) {
       
   106         //qDebug("Widget provider load - !provider, deleting plugin.")
       
   107         delete plugin;
       
   108     }
       
   109 
       
   110     // qDebug("Widget provider load failed - Not found.")
       
   111     return 0;
       
   112 }
       
   113 */
       
   114 
       
   115 /*!
       
   116     ?Qt_style_documentation
       
   117 */
       
   118 QStringList HsWidgetRegistryServicePrivate::readManifestDirectories(const QString &path)
       
   119 {
       
   120     QStringList widgetDirPaths;
       
   121     QDir registryDir(path);
       
   122     QStringList widgetDirs = registryDir.entryList(QDir::AllDirs);
       
   123 
       
   124     // ?
       
   125     for (int i=0; i < widgetDirs.count(); ++i) {
       
   126         widgetDirPaths << registryDir.absoluteFilePath(widgetDirs.at(i));
       
   127     }
       
   128     return widgetDirPaths;
       
   129 }
       
   130 
       
   131 /*!
       
   132     ?Qt_style_documentation
       
   133 */
       
   134 void HsWidgetRegistryServicePrivate::doWidgetRemove(const QString &path,
       
   135         const QStringList &originalList, const QStringList &currentList)
       
   136 {
       
   137     Q_UNUSED(path);
       
   138     const int originalCount = originalList.count();
       
   139 
       
   140     // ?
       
   141     for (int i=0; i<originalCount; i++) {
       
   142         QString widgetDir = originalList.at(i);
       
   143 
       
   144         if (!currentList.contains(widgetDir)) {
       
   145             // ?
       
   146             QDir dir(widgetDir);
       
   147             int widgetUid = dir.dirName().toUInt(0, 16);
       
   148             mPublic->emitWidgetRemovedFromRegistry(widgetUid);
       
   149         }
       
   150     }
       
   151 }
       
   152 
       
   153 /*!
       
   154     ?Qt_style_documentation
       
   155 */
       
   156 QList<HsWidgetComponentDescriptor> HsWidgetRegistryServicePrivate::readManifestFile(
       
   157     const QString &manifestFilePath)
       
   158 {
       
   159     QList<HsWidgetComponentDescriptor> widgets;
       
   160     QStringList filters("*.manifest");
       
   161     QDir dir(manifestFilePath);
       
   162     QStringList manifestDir = dir.entryList(filters, QDir::Files);
       
   163 
       
   164     if (!manifestDir.isEmpty()) {
       
   165         // ?
       
   166         QString fileName = manifestDir.first();
       
   167         HsWidgetComponentParser componentParser(dir.absoluteFilePath(fileName));
       
   168         if ( !componentParser.error() ) {
       
   169             
       
   170             HsWidgetComponentDescriptor widgetDescriptor = componentParser.widgetComponentDescriptor();            
       
   171             widgetDescriptor.library = manifestFilePath + "/" + widgetDescriptor.uri + ".dll";
       
   172             if (widgetDescriptor.iconUri.length() > 0 ) {
       
   173                 widgetDescriptor.iconUri = manifestFilePath + "/" + widgetDescriptor.iconUri;
       
   174             }            
       
   175             if (widgetDescriptor.previewImage.length() > 0 ) {
       
   176                 widgetDescriptor.previewImage = manifestFilePath + "/" + widgetDescriptor.previewImage;
       
   177             }            
       
   178 
       
   179             int widgetUid = dir.dirName().toUInt(0, 16);
       
   180             widgetDescriptor.uid = widgetUid;
       
   181             widgets << widgetDescriptor;
       
   182             qDebug() << "HsWidgetRegistryServicePrivate::readManifestFile - " \
       
   183                      "widget added: " << fileName;
       
   184         }
       
   185     }
       
   186     return widgets;
       
   187 }
       
   188 
       
   189 /*!
       
   190     ?Qt_style_documentation
       
   191 */
       
   192 void HsWidgetRegistryServicePrivate::ensureWidgetRegistryPaths()
       
   193 {
       
   194     /*
       
   195     mFileSystemWatcher.disconnect();
       
   196     QStringList pathList = mManifestDirectories.keys();
       
   197 
       
   198     // ?
       
   199     for(int i=0; i < pathList.count(); i++) {
       
   200         QDir registryDir(pathList.at(i));
       
   201 
       
   202         if(!registryDir.exists()) {
       
   203             // ?
       
   204             registryDir.mkpath(pathList.at(i));
       
   205         }
       
   206     }
       
   207 
       
   208     mFileSystemWatcher.removePaths(QStringList(mManifestDirectories.keys()));
       
   209     mFileSystemWatcher.addPaths(QStringList(mManifestDirectories.keys()));
       
   210     connect(&mFileSystemWatcher,SIGNAL(directoryChanged(const QString&)),SLOT(directoryChanged(const QString&)));
       
   211     */
       
   212 }
       
   213 
       
   214 /*!
       
   215     ?Qt_style_documentation
       
   216 */
       
   217 void HsWidgetRegistryServicePrivate::directoryChanged(const QString &path)
       
   218 {
       
   219     Q_UNUSED(path);
       
   220     /*
       
   221     int installationStatus = mInstallerObserver.value();
       
   222 
       
   223     if ((installationStatus & KSASwisOperationMask) == ESASwisNone) {
       
   224         // ?
       
   225         QStringList originalList = mManifestDirectories.value(path);
       
   226         QStringList currentList = readManifestDirectories(path);
       
   227         doWidgetAdd(path, originalList, currentList);
       
   228         doWidgetRemove(path, originalList, currentList);
       
   229         mManifestDirectories[path] = currentList;
       
   230         ensureWidgetRegistryPaths();
       
   231     } else {
       
   232         // ?
       
   233         mFileSystemWatcher.disconnect();
       
   234         connect(&mInstallerObserver,SIGNAL(valueChanged(int)),SLOT(installerStateChanged(int)));
       
   235         mInstallerObserver.subscribe();
       
   236         mLatestChangedDirectory = path;
       
   237     }
       
   238     */
       
   239 }
       
   240 
       
   241 /*!
       
   242     ?Qt_style_documentation
       
   243 */
       
   244 void HsWidgetRegistryServicePrivate::installerStateChanged(int newValue)
       
   245 {
       
   246     Q_UNUSED(newValue);
       
   247     /*
       
   248     if ((newValue & KSASwisOperationMask) == ESASwisNone) {
       
   249         // ?
       
   250         mInstallerObserver.unSubscribe();
       
   251         mInstallerObserver.disconnect();
       
   252         QStringList originalList = mManifestDirectories.value(mLatestChangedDirectory);
       
   253         QStringList currentList = readManifestDirectories(mLatestChangedDirectory);
       
   254         doWidgetAdd(mLatestChangedDirectory, originalList, currentList);
       
   255         doWidgetRemove(mLatestChangedDirectory, originalList, currentList);
       
   256         connect(&mFileSystemWatcher,SIGNAL(directoryChanged(const QString&)),SLOT(directoryChanged(const QString&)));
       
   257         mManifestDirectories[mLatestChangedDirectory] = currentList;
       
   258         ensureWidgetRegistryPaths();
       
   259     }
       
   260     */
       
   261 }
       
   262 
       
   263 
       
   264 /*!
       
   265     \class HsWidgetRegistryService
       
   266     \ingroup group_hsruntimeservices
       
   267     \brief Manages installed widgets information
       
   268 
       
   269     Manages information on available widgets and inform observers on
       
   270     registry modifications, i.e installing and uninstalling widgets.
       
   271 
       
   272 */
       
   273 
       
   274 /*!
       
   275     Constructor.
       
   276     \a installationPath is the path where the widget is installed
       
   277     and the \a parent is the parent object.
       
   278 */
       
   279 HsWidgetRegistryService::HsWidgetRegistryService(
       
   280     const QString &installationPath,
       
   281     QObject *parent)
       
   282     :QObject(parent),
       
   283      mPrivate(new HsWidgetRegistryServicePrivate(installationPath, this, this))
       
   284 {
       
   285 
       
   286 }
       
   287 
       
   288 /*!
       
   289     Destructor.
       
   290 */
       
   291 HsWidgetRegistryService::~HsWidgetRegistryService()
       
   292 {
       
   293 
       
   294 }
       
   295 
       
   296 /*!
       
   297     Fetch available widgets information
       
   298     Return List of widget tokens.
       
   299 */
       
   300 QList<HsWidgetComponentDescriptor> HsWidgetRegistryService::widgets()
       
   301 {
       
   302     return mPrivate->widgets();
       
   303 }
       
   304 
       
   305 /*!
       
   306     \fn HsWidgetRegistryService::widgetAddedToRegistry(const QList<HsWidgetToken> &widgetTokenList);
       
   307     Emitted when new widgets are added to registry. \a widgetTokenList
       
   308     contains list of widget tokens.
       
   309 */
       
   310 
       
   311 /*!
       
   312     \fn HsWidgetRegistryService::widgetRemovedFromRegistry(int uid)
       
   313     Emitted when a widget is removed from registry
       
   314 
       
   315 */
       
   316 
       
   317 
       
   318 /*!
       
   319     \fn HsWidgetRegistryService::posterWidgetRemovedFromRegistry(int posterWidgetId)
       
   320     Emitted when a poster widget publisher is removed from cps
       
   321     \a posterWidgetId Poster widget id.
       
   322 */
       
   323 
       
   324 /*!
       
   325     Emits the widgetAddedToRegistry() signal
       
   326     \a widgetsAdded Identifies the added widgets.
       
   327 */
       
   328 void HsWidgetRegistryService::emitWidgetAddedToRegistry(const QList<HsWidgetComponentDescriptor> &widgetsAdded)
       
   329 {
       
   330     emit widgetAddedToRegistry(widgetsAdded);
       
   331 }
       
   332 
       
   333 
       
   334 /*!
       
   335     Emits the widgetRemovedFromRegistry() signal
       
   336     \a uid HsWidget uid.
       
   337 */
       
   338 void HsWidgetRegistryService::emitWidgetRemovedFromRegistry(int uid)
       
   339 {
       
   340     emit widgetRemovedFromRegistry(uid);
       
   341 }