homescreenapp/examples/helloworldwidgetplugin/src/helloworldwidgetplugin.cpp
changeset 61 2b1b11a301d2
parent 60 30f14686fb04
equal deleted inserted replaced
60:30f14686fb04 61:2b1b11a301d2
    21 
    21 
    22 #include "helloworldwidgetplugin.h"
    22 #include "helloworldwidgetplugin.h"
    23 #include "helloworldwidget.h"
    23 #include "helloworldwidget.h"
    24 
    24 
    25 /*!
    25 /*!
    26     @page page_creatingwidgetplugin Creating Home Screen Widget Plugin
       
    27 
       
    28     Widgets are exposed to the home screen through QT Service Framework.
       
    29     Widget plugins are implemented according to
       
    30     <a href="http://qt.nokia.com/doc/qtmobility-1.0-tp/service-frameworks.html">Qt service framework plugin model</a>.
       
    31 
       
    32     See @ref page_nativewidgetmodel for the instructions how to create widget for the home screen.
       
    33 
       
    34     The steps to create a widget plugin are:
       
    35     <ol>
       
    36     <li> Declare a plugin class that inherits from QObject and from the \c QServicePluginInterface interface.
       
    37     
       
    38     <li> Use the Q_INTERFACES() macro to tell Qt's meta-object system about the \c QServicePluginInterface interface.
       
    39     
       
    40     <li> Export the plugin using the Q_EXPORT_PLUGIN2() macro.
       
    41     
       
    42     <li> Build the plugin using an suitable .pro file. See @ref page_deploying_widget_plugin
       
    43     </ol>
       
    44     
       
    45     An example (full example source code can be found from section @ref page_nativewidgetmodel):
       
    46 
       
    47     Each widget plugin has a XML file that allows searching widgets through QT service framework without first loading it.
       
    48     The XML file contains information on widgets inside the plugin:
       
    49     
       
    50     \li \c name             The name of the plugin binary.
       
    51     \li \c filepath         The absolute path and name of plugin without suffix
       
    52     \li \c interface name   Uniquely identifies the widget.
       
    53     \li \c title            Widget's human-readable name.
       
    54     \li \c iconuri          URI of the widget's icon image file.
       
    55     
       
    56     Example: XML for a widget plugin.
       
    57     
       
    58     @code
       
    59     <?xml version="1.0" encoding="UTF-8"?>
       
    60     <service>
       
    61         <name>helloworldwidgetplugin</name>
       
    62         <filepath>helloworldwidgetplugin</filepath>
       
    63         <description>Example widget</description>
       
    64         <interface>
       
    65             <name>com.nokia.symbian.IHomeScreenWidget</name>
       
    66             <version>1.0</version>
       
    67             <description>Example of home screen widget</description>
       
    68             <capabilities></capabilities>
       
    69             <customproperty key="iconuri">helloworldwidgetplugin.png</customproperty>
       
    70             <customproperty key="title">HelloWorld</customproperty>
       
    71         </interface>
       
    72     </service>
       
    73     @endcode
       
    74 */
       
    75 
       
    76 /*!
       
    77     @page page_deployingwidgetplugin Deploying Home Screen Widget Plugin
       
    78     
       
    79     Widget's binaries and xml file(s) must be deployed to correct folders on emulator and in target. 
       
    80     Below are the needed .pro file for the \c helloworldwidgetplugin.
       
    81     
       
    82     For example:
       
    83     
       
    84     @code
       
    85     # helloworldwidgetplugin.pro
       
    86 
       
    87     TEMPLATE = lib
       
    88     CONFIG += plugin mobility hb
       
    89     MOBILITY = serviceframework
       
    90     
       
    91     HEADERS += ./inc/ .h
       
    92     SOURCES += ./src/ .cpp
       
    93     
       
    94     INCLUDEPATH += ./inc               
       
    95     
       
    96     symbian: {
       
    97 
       
    98         DESTDIR = /private/20022F35/import/widgetregistry/20022F7E
       
    99         INCLUDEPATH += $$APP_LAYER_SYSTEMINCLUDE
       
   100     
       
   101         TARGET.UID3 = 0x20022F7E
       
   102         TARGET.EPOCALLOWDLLDATA=1
       
   103         TARGET.CAPABILITY = ALL -TCB
       
   104         
       
   105         plugins.path = $${DESTDIR}
       
   106         plugins.sources = $${TARGET}.dll 
       
   107         
       
   108         widgetResources.path = $${DESTDIR}
       
   109         widgetResources.sources += resource/$${TARGET}.xml    
       
   110         widgetResources.sources += resource/$${TARGET}.manifest
       
   111         widgetResources.sources += resource/$${TARGET}.png
       
   112             
       
   113         DEPLOYMENT += plugins \
       
   114                       widgetResources
       
   115     }
       
   116 
       
   117     @endcode
       
   118     
       
   119     For detailed information on DEPLOYMENT macro, see <a HREF="http://pepper.troll.no/s60prereleases/doc/qmake-variable-reference.html#deployment">here</a>.
       
   120 */
       
   121 
       
   122 /*!
       
   123     \ingroup group_helloworld_widget
    26     \ingroup group_helloworld_widget
   124     \class HelloWorldWidgetPlugin
    27     \class HelloWorldWidgetPlugin
   125     \brief Example implementation for home screen widget plugin.
    28     \brief Example implementation for home screen widget plugin.
   126 */    
    29 */    
   127     
    30     
   128 /*!
    31 /*!
   129     Initialize plugin for hello world widget. Contains necessary information about 
    32     Initialize plugin for hello world widget. Contains necessary information about 
   130     the hello world widget that it can be loaded through QT Service Framework.
    33     the hello world widget that it can be loaded through QT Service Framework.
   131 */
    34 */
       
    35 // Start of snippet 1
   132 QObject *HelloWorldWidgetPlugin::createInstance(const QServiceInterfaceDescriptor &descriptor,
    36 QObject *HelloWorldWidgetPlugin::createInstance(const QServiceInterfaceDescriptor &descriptor,
   133                                              QServiceContext *context,
    37                                              QServiceContext *context,
   134                                              QAbstractSecuritySession *session)
    38                                              QAbstractSecuritySession *session)
   135 {
    39 {
   136     Q_UNUSED(context);
    40     Q_UNUSED(context);
   140         return new HelloWorldWidget();
    44         return new HelloWorldWidget();
   141     } else {
    45     } else {
   142         return 0;
    46         return 0;
   143     }
    47     }
   144 }
    48 }
       
    49 // End of snippet 1
   145 
    50 
       
    51 // Start of snippet 2
   146 Q_EXPORT_PLUGIN2(helloworldwidgetplugin, HelloWorldWidgetPlugin)
    52 Q_EXPORT_PLUGIN2(helloworldwidgetplugin, HelloWorldWidgetPlugin)
       
    53 // End of snippet 2