hswidgetmodel/examples/helloworldwidgetprovider/src/helloworldwidgetprovider.cpp
changeset 86 e492551a0d54
parent 85 7feec50967db
child 87 9d806967057c
equal deleted inserted replaced
85:7feec50967db 86:e492551a0d54
     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: Example of home screen widget
       
    15 *
       
    16 */
       
    17 
       
    18 #include <hswidget.h>
       
    19 
       
    20 #include "helloworldwidgetprovider.h"
       
    21 #include "helloworldwidget.h"
       
    22 
       
    23 
       
    24 /*!
       
    25     \ingroup group_helloworld_widget
       
    26     \class HelloWorldWidgetProvider
       
    27     \brief Example implementation for home screen widget provider.
       
    28 
       
    29     @page page_creating_widget_provider Creating Home Screen Widget Provider
       
    30 
       
    31     Widgets are exposed to the home screen through widget provider plugins.
       
    32     A widget can be added to an existing provider or new one can be created.
       
    33     Widget provider plugins are implemented according to
       
    34     the <a href="http://doc.trolltech.com/4.4/plugins-howto.html">Qt plugin model</a>.
       
    35 
       
    36     See @ref page_developing_home_screen_widget for the instructions how to create widget for the home screen.
       
    37 
       
    38     The steps to create a widget provider are:
       
    39     <ol>
       
    40     <li> Declare a plugin class that inherits from QObject and from the \c IHsWidgetProvider interface.
       
    41     
       
    42     <li> Use the Q_INTERFACES() macro to tell Qt's meta-object system about the \c IHsWidgetProvider interface.
       
    43     
       
    44     <li> Export the plugin using the Q_EXPORT_PLUGIN2() macro.
       
    45     
       
    46     <li> Build the plugin using an suitable .pro file. See @ref page_deploying_widget_provider.
       
    47     </ol>
       
    48     
       
    49     An example (full example source code can be found from section @ref page_developing_home_screen_widget):
       
    50 
       
    51 
       
    52 Each widget provider plugin has a manifest file that allows searching widgets from the plugin without first loading it.
       
    53 The manifest file contains information on widgets inside the plugin:
       
    54 
       
    55 \li \c library The name of the provider plugin binary.
       
    56 \li \c uri     Uniquely identifies the widget.
       
    57 \li \c title   Widget's human-readable name.
       
    58 \li \c iconuri URI of the widget's icon image file.
       
    59 
       
    60 Example: Manifest for a widget provider.
       
    61 
       
    62 @code
       
    63 <?xml version="1.0" encoding="utf-8"?>
       
    64 <widgetprovider>
       
    65     <widget library="helloworldwidgetprovider.dll"
       
    66             uri="homescreen.nokia.com/widget/helloworld"
       
    67             title="HelloWorld"
       
    68             iconuri="helloworldwidgetprovider.png"/>
       
    69 </widgetprovider>
       
    70 @endcode
       
    71 
       
    72 
       
    73 @page page_deploying_widget_provider Deploying Home Screen Widget Provider
       
    74 
       
    75 Widget's binaries and manifest file(s) must be deployed to correct folders on emulator and in target. 
       
    76 Below are the needed .pro file for the \c helloworldwidgetprovider.
       
    77 
       
    78 For example:
       
    79 @code
       
    80 # helloworldwidgetprovider.pro
       
    81 
       
    82 TEMPLATE = lib
       
    83 
       
    84 CONFIG += plugin hb
       
    85 LIBS += -lhswidgetmodel
       
    86 
       
    87 HEADERS += ./inc/ *.h \
       
    88            ./helloworldwidget/inc/ *.h
       
    89 
       
    90 SOURCES += ./src/ *.cpp \
       
    91            ./helloworldwidget/src/ *.cpp
       
    92 
       
    93 DEPENDPATH += ./inc \
       
    94               ./src
       
    95 
       
    96 symbian: {
       
    97     INCLUDEPATH += $$APP_LAYER_SYSTEMINCLUDE
       
    98 
       
    99     # get your own symbian uid    
       
   100     TARGET.UID3 = 0xEABCFE12
       
   101     TARGET.EPOCALLOWDLLDATA=1
       
   102     TARGET.CAPABILITY = ALL -TCB
       
   103     
       
   104     # add your symbian uid here
       
   105     PLUGIN_SUBDIR = /private/20022F35/import/widgetregistry/EABCFE12
       
   106     
       
   107     pluginstub.sources = $${TARGET}.dll
       
   108     pluginstub.path = $$PLUGIN_SUBDIR
       
   109 
       
   110     DEPLOYMENT += pluginstub
       
   111 
       
   112     qtplugins.path = $$PLUGIN_SUBDIR
       
   113     qtplugins.sources += qmakepluginstubs/$${TARGET}.qtplugin
       
   114     qtplugins.sources += resource/$${TARGET}.manifest
       
   115     qtplugins.sources += resource/$${TARGET}.png
       
   116      
       
   117     for(qtplugin, qtplugins.sources):BLD_INF_RULES.prj_exports += "./$$qtplugin z:$$qtplugins.path/$$basename(qtplugin)" 
       
   118 }
       
   119 
       
   120 @endcode
       
   121 
       
   122 For detailed information on DEPLOYMENT macro, see <a HREF="http://pepper.troll.no/s60prereleases/doc/qmake-variable-reference.html#deployment">here</a>.
       
   123 
       
   124 */
       
   125 
       
   126 
       
   127 /*!
       
   128     Initialize token for hello world widget. Contains necessary information about 
       
   129     the hello world widget that can be loaded with this provider.
       
   130 */
       
   131 HelloWorldWidgetProvider::HelloWorldWidgetProvider()
       
   132 {
       
   133     mWidgetToken.mLibrary = QString("helloworldwidgetprovider.dll");
       
   134     mWidgetToken.mUri = QString("homescreen.nokia.com/widget/helloworld");
       
   135     mWidgetToken.mTitle = QString("HelloWorld");
       
   136     mWidgetToken.mIconUri = QString("helloworldwidgetprovider.png");
       
   137 }
       
   138 
       
   139 /*!
       
   140     Destructor
       
   141 */
       
   142 HelloWorldWidgetProvider::~HelloWorldWidgetProvider()
       
   143 {
       
   144 
       
   145 }
       
   146 
       
   147 /*!
       
   148     Returns list of loadable widgets' tokens.
       
   149 */
       
   150 QList<HsWidgetToken> HelloWorldWidgetProvider::widgets()
       
   151 {
       
   152     return QList<HsWidgetToken>() << mWidgetToken;
       
   153 }
       
   154 
       
   155 /*!
       
   156     Create widget based on uri \a token
       
   157 */
       
   158 HsWidget* HelloWorldWidgetProvider::createWidget(const HsWidgetToken& token)
       
   159 {
       
   160     HsWidget *widget = 0;
       
   161     if (token.mUri == mWidgetToken.mUri) {
       
   162         widget =  new HelloWorldWidget();
       
   163     }
       
   164     return widget;
       
   165 }
       
   166 
       
   167 Q_EXPORT_PLUGIN2(helloworldwidgetprovider, HelloWorldWidgetProvider)