hswidgetmodel/src/hswidgetfactory.cpp
author hgs
Fri, 11 Jun 2010 16:13:51 +0300
changeset 98 d2f833ab7940
parent 85 7feec50967db
permissions -rw-r--r--
201023
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
85
7feec50967db 201003_02
hgs
parents:
diff changeset
     1
/*
7feec50967db 201003_02
hgs
parents:
diff changeset
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
7feec50967db 201003_02
hgs
parents:
diff changeset
     3
* All rights reserved.
7feec50967db 201003_02
hgs
parents:
diff changeset
     4
* This component and the accompanying materials are made available
7feec50967db 201003_02
hgs
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
7feec50967db 201003_02
hgs
parents:
diff changeset
     6
* which accompanies this distribution, and is available
7feec50967db 201003_02
hgs
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
7feec50967db 201003_02
hgs
parents:
diff changeset
     8
*
7feec50967db 201003_02
hgs
parents:
diff changeset
     9
* Initial Contributors:
7feec50967db 201003_02
hgs
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
7feec50967db 201003_02
hgs
parents:
diff changeset
    11
*
7feec50967db 201003_02
hgs
parents:
diff changeset
    12
* Contributors:
7feec50967db 201003_02
hgs
parents:
diff changeset
    13
*
7feec50967db 201003_02
hgs
parents:
diff changeset
    14
* Description:  HsWidget factory.
7feec50967db 201003_02
hgs
parents:
diff changeset
    15
*
7feec50967db 201003_02
hgs
parents:
diff changeset
    16
*/
7feec50967db 201003_02
hgs
parents:
diff changeset
    17
7feec50967db 201003_02
hgs
parents:
diff changeset
    18
7feec50967db 201003_02
hgs
parents:
diff changeset
    19
#include <QStringList>
7feec50967db 201003_02
hgs
parents:
diff changeset
    20
#include <QDir>
7feec50967db 201003_02
hgs
parents:
diff changeset
    21
#include <QPluginLoader>
7feec50967db 201003_02
hgs
parents:
diff changeset
    22
7feec50967db 201003_02
hgs
parents:
diff changeset
    23
#include "hswidgetfactory.h"
7feec50967db 201003_02
hgs
parents:
diff changeset
    24
#include "hswidgetfactory_p.h"
7feec50967db 201003_02
hgs
parents:
diff changeset
    25
#include "hswidget.h"
7feec50967db 201003_02
hgs
parents:
diff changeset
    26
#include "hswidgetprovidermanifest.h"
7feec50967db 201003_02
hgs
parents:
diff changeset
    27
#include "hstest_global.h"
7feec50967db 201003_02
hgs
parents:
diff changeset
    28
7feec50967db 201003_02
hgs
parents:
diff changeset
    29
7feec50967db 201003_02
hgs
parents:
diff changeset
    30
98
hgs
parents: 85
diff changeset
    31
/*DEPRECATED
85
7feec50967db 201003_02
hgs
parents:
diff changeset
    32
    \class HsPluginUnloader
7feec50967db 201003_02
hgs
parents:
diff changeset
    33
    \ingroup group_hswidgetmodel
7feec50967db 201003_02
hgs
parents:
diff changeset
    34
    \brief Unloads plugin and deletes plugin loader.
7feec50967db 201003_02
hgs
parents:
diff changeset
    35
7feec50967db 201003_02
hgs
parents:
diff changeset
    36
    Holds plugin loader instance and unloads and destroys plugin
7feec50967db 201003_02
hgs
parents:
diff changeset
    37
    on it's destructor. 
7feec50967db 201003_02
hgs
parents:
diff changeset
    38
 
7feec50967db 201003_02
hgs
parents:
diff changeset
    39
*/
7feec50967db 201003_02
hgs
parents:
diff changeset
    40
7feec50967db 201003_02
hgs
parents:
diff changeset
    41
7feec50967db 201003_02
hgs
parents:
diff changeset
    42
/*!
7feec50967db 201003_02
hgs
parents:
diff changeset
    43
    \fn HsPluginUnloader::HsPluginUnloader(QPluginLoader *pluginLoader,QObject *parent)
7feec50967db 201003_02
hgs
parents:
diff changeset
    44
7feec50967db 201003_02
hgs
parents:
diff changeset
    45
    Constructs plugin unloader object. When this object is destroyed it 
7feec50967db 201003_02
hgs
parents:
diff changeset
    46
    unloads it's pointed \a pluginLoader instance.
7feec50967db 201003_02
hgs
parents:
diff changeset
    47
*/
7feec50967db 201003_02
hgs
parents:
diff changeset
    48
HsPluginUnloader::HsPluginUnloader(QPluginLoader *pluginLoader,QObject *parent)
7feec50967db 201003_02
hgs
parents:
diff changeset
    49
    :QObject(parent),mPluginLoader(pluginLoader)
7feec50967db 201003_02
hgs
parents:
diff changeset
    50
{
7feec50967db 201003_02
hgs
parents:
diff changeset
    51
}
7feec50967db 201003_02
hgs
parents:
diff changeset
    52
7feec50967db 201003_02
hgs
parents:
diff changeset
    53
/*!
7feec50967db 201003_02
hgs
parents:
diff changeset
    54
    \fn HsPluginUnloader::~HsPluginUnloader()
7feec50967db 201003_02
hgs
parents:
diff changeset
    55
7feec50967db 201003_02
hgs
parents:
diff changeset
    56
    Unloads it's plugin loader instance.
7feec50967db 201003_02
hgs
parents:
diff changeset
    57
*/
7feec50967db 201003_02
hgs
parents:
diff changeset
    58
HsPluginUnloader::~HsPluginUnloader()
7feec50967db 201003_02
hgs
parents:
diff changeset
    59
{
7feec50967db 201003_02
hgs
parents:
diff changeset
    60
    if(mPluginLoader) {
7feec50967db 201003_02
hgs
parents:
diff changeset
    61
        mPluginLoader->unload();
7feec50967db 201003_02
hgs
parents:
diff changeset
    62
        delete mPluginLoader; 
7feec50967db 201003_02
hgs
parents:
diff changeset
    63
    }
7feec50967db 201003_02
hgs
parents:
diff changeset
    64
}
7feec50967db 201003_02
hgs
parents:
diff changeset
    65
98
hgs
parents: 85
diff changeset
    66
/*DEPRECATED
85
7feec50967db 201003_02
hgs
parents:
diff changeset
    67
    \class HsWidgetFactory 
7feec50967db 201003_02
hgs
parents:
diff changeset
    68
    \ingroup group_hswidgetmodel
7feec50967db 201003_02
hgs
parents:
diff changeset
    69
    \brief Finds and creates home screen widgets.
7feec50967db 201003_02
hgs
parents:
diff changeset
    70
7feec50967db 201003_02
hgs
parents:
diff changeset
    71
    HsWidget factory creates an instance of
7feec50967db 201003_02
hgs
parents:
diff changeset
    72
    a widget base on a widget token that is given to it.
7feec50967db 201003_02
hgs
parents:
diff changeset
    73
 
7feec50967db 201003_02
hgs
parents:
diff changeset
    74
*/
7feec50967db 201003_02
hgs
parents:
diff changeset
    75
7feec50967db 201003_02
hgs
parents:
diff changeset
    76
7feec50967db 201003_02
hgs
parents:
diff changeset
    77
HsWidgetFactoryPrivate::HsWidgetFactoryPrivate(HsWidgetFactory *factory):
7feec50967db 201003_02
hgs
parents:
diff changeset
    78
    mPublic(factory)
7feec50967db 201003_02
hgs
parents:
diff changeset
    79
{
7feec50967db 201003_02
hgs
parents:
diff changeset
    80
7feec50967db 201003_02
hgs
parents:
diff changeset
    81
}
7feec50967db 201003_02
hgs
parents:
diff changeset
    82
7feec50967db 201003_02
hgs
parents:
diff changeset
    83
7feec50967db 201003_02
hgs
parents:
diff changeset
    84
HsWidgetFactoryPrivate::~HsWidgetFactoryPrivate()
7feec50967db 201003_02
hgs
parents:
diff changeset
    85
{
7feec50967db 201003_02
hgs
parents:
diff changeset
    86
7feec50967db 201003_02
hgs
parents:
diff changeset
    87
}
7feec50967db 201003_02
hgs
parents:
diff changeset
    88
7feec50967db 201003_02
hgs
parents:
diff changeset
    89
7feec50967db 201003_02
hgs
parents:
diff changeset
    90
7feec50967db 201003_02
hgs
parents:
diff changeset
    91
HsWidget* HsWidgetFactoryPrivate::createWidget(const HsWidgetToken &token)
7feec50967db 201003_02
hgs
parents:
diff changeset
    92
{
7feec50967db 201003_02
hgs
parents:
diff changeset
    93
   QPluginLoader* loader = new QPluginLoader(token.mLibrary);
7feec50967db 201003_02
hgs
parents:
diff changeset
    94
   QObject* plugin = loader->instance();
7feec50967db 201003_02
hgs
parents:
diff changeset
    95
   IHsWidgetProvider* provider = qobject_cast<IHsWidgetProvider*>(plugin);
7feec50967db 201003_02
hgs
parents:
diff changeset
    96
   HsWidget* widget(0);
7feec50967db 201003_02
hgs
parents:
diff changeset
    97
   
7feec50967db 201003_02
hgs
parents:
diff changeset
    98
   if (provider) {
7feec50967db 201003_02
hgs
parents:
diff changeset
    99
       widget = provider->createWidget(token);
7feec50967db 201003_02
hgs
parents:
diff changeset
   100
       
7feec50967db 201003_02
hgs
parents:
diff changeset
   101
       if (!widget) {
7feec50967db 201003_02
hgs
parents:
diff changeset
   102
          HSDEBUG("Widget creation failed.")
7feec50967db 201003_02
hgs
parents:
diff changeset
   103
          loader->unload();
7feec50967db 201003_02
hgs
parents:
diff changeset
   104
          delete loader;
7feec50967db 201003_02
hgs
parents:
diff changeset
   105
       }
7feec50967db 201003_02
hgs
parents:
diff changeset
   106
       else {
7feec50967db 201003_02
hgs
parents:
diff changeset
   107
           HsPluginUnloader* p = new HsPluginUnloader(loader);
7feec50967db 201003_02
hgs
parents:
diff changeset
   108
           p->connect(widget,SIGNAL(destroyed()),SLOT(deleteLater()));
7feec50967db 201003_02
hgs
parents:
diff changeset
   109
       }
7feec50967db 201003_02
hgs
parents:
diff changeset
   110
    }
7feec50967db 201003_02
hgs
parents:
diff changeset
   111
7feec50967db 201003_02
hgs
parents:
diff changeset
   112
   else {
7feec50967db 201003_02
hgs
parents:
diff changeset
   113
        HSDEBUG("Widget creation failed - No provider.")
7feec50967db 201003_02
hgs
parents:
diff changeset
   114
        loader->unload();
7feec50967db 201003_02
hgs
parents:
diff changeset
   115
        delete loader;
7feec50967db 201003_02
hgs
parents:
diff changeset
   116
   }
7feec50967db 201003_02
hgs
parents:
diff changeset
   117
7feec50967db 201003_02
hgs
parents:
diff changeset
   118
   
7feec50967db 201003_02
hgs
parents:
diff changeset
   119
    return widget;
7feec50967db 201003_02
hgs
parents:
diff changeset
   120
}
7feec50967db 201003_02
hgs
parents:
diff changeset
   121
7feec50967db 201003_02
hgs
parents:
diff changeset
   122
/*!
7feec50967db 201003_02
hgs
parents:
diff changeset
   123
    Constructor
7feec50967db 201003_02
hgs
parents:
diff changeset
   124
*/
7feec50967db 201003_02
hgs
parents:
diff changeset
   125
HsWidgetFactory::HsWidgetFactory(QObject *parent)
7feec50967db 201003_02
hgs
parents:
diff changeset
   126
    : QObject(parent),mD(new HsWidgetFactoryPrivate(this))
7feec50967db 201003_02
hgs
parents:
diff changeset
   127
{
7feec50967db 201003_02
hgs
parents:
diff changeset
   128
}
7feec50967db 201003_02
hgs
parents:
diff changeset
   129
/*!
7feec50967db 201003_02
hgs
parents:
diff changeset
   130
    Destructor
7feec50967db 201003_02
hgs
parents:
diff changeset
   131
*/
7feec50967db 201003_02
hgs
parents:
diff changeset
   132
HsWidgetFactory::~HsWidgetFactory()
7feec50967db 201003_02
hgs
parents:
diff changeset
   133
{
7feec50967db 201003_02
hgs
parents:
diff changeset
   134
    delete mD;
7feec50967db 201003_02
hgs
parents:
diff changeset
   135
}
7feec50967db 201003_02
hgs
parents:
diff changeset
   136
7feec50967db 201003_02
hgs
parents:
diff changeset
   137
7feec50967db 201003_02
hgs
parents:
diff changeset
   138
/*!
7feec50967db 201003_02
hgs
parents:
diff changeset
   139
    Creates and returns a widget based on given \a token
7feec50967db 201003_02
hgs
parents:
diff changeset
   140
*/
7feec50967db 201003_02
hgs
parents:
diff changeset
   141
HsWidget* HsWidgetFactory::createWidget(const HsWidgetToken &token)
7feec50967db 201003_02
hgs
parents:
diff changeset
   142
{
7feec50967db 201003_02
hgs
parents:
diff changeset
   143
    return mD->createWidget(token);
7feec50967db 201003_02
hgs
parents:
diff changeset
   144
}
7feec50967db 201003_02
hgs
parents:
diff changeset
   145
7feec50967db 201003_02
hgs
parents:
diff changeset
   146