homescreenapp/examples/contentpublishclient/src/contentpublishclient.cpp
changeset 39 4e8ebe173323
parent 36 cdae8c6c3876
child 61 2b1b11a301d2
equal deleted inserted replaced
36:cdae8c6c3876 39:4e8ebe173323
    24 #include "contentpublishclient.h"
    24 #include "contentpublishclient.h"
    25 
    25 
    26 /*!
    26 /*!
    27     \ingroup group_content_publish_client
    27     \ingroup group_content_publish_client
    28     \class ContentPublishClient
    28     \class ContentPublishClient
    29     \brief Example implementation for home screen content publish client.
    29     \brief Example implementation for home screen client api usage.
    30 
    30 
    31     ContentPublishClient is derived from QObject and implements 
    31     ContentPublishClient is derived from QObject and implements 
    32     needed functions for the home screen content publish client. 
    32     needed functions for the home screen content publish client. 
    33 */
    33 */
    34 
    34 
    61         QServiceManager::Error error = mManager->error();
    61         QServiceManager::Error error = mManager->error();
    62         return false;
    62         return false;
    63     }
    63     }
    64     qDebug() << interfaces.first().interfaceName()
    64     qDebug() << interfaces.first().interfaceName()
    65              << interfaces.first().serviceName()
    65              << interfaces.first().serviceName()
    66              <<  interfaces.first().isValid();
    66              << interfaces.first().isValid();
    67 
    67 
    68     mService = mManager->loadInterface(interfaces.first());
    68     mService = mManager->loadInterface(interfaces.first());
    69         
    69         
    70     return (mService);
    70     return (mService);
    71 }
    71 }
    72 
    72 
    73 /*!
    73 /*!
    74     Adds widget utilizing service interface and invoke call
    74     Adds hello world widget 
    75 */
    75 */
    76 void ContentPublishClient::addWidget()
    76 void ContentPublishClient::addHelloworldWidget()
       
    77 {
       
    78     if ( addWidget("helloworldwidgetplugin")) {
       
    79         qDebug() << "HelloWorld added"; 
       
    80     } else {
       
    81         qDebug() << "adding HelloWorld failed"; 
       
    82     }
       
    83 }
       
    84 
       
    85 /*!
       
    86     Adds clock world widget 
       
    87 */
       
    88 void ContentPublishClient::addClockWidget()
       
    89 {
       
    90     if ( addWidget("hsclockwidgetplugin")) {
       
    91         qDebug() << "Clock widget added"; 
       
    92     } else {
       
    93         qDebug() << "adding Clock widget failed"; 
       
    94     }
       
    95 }
       
    96 
       
    97 /*!
       
    98     Adds widget \a widgetUri utilizing service interface and invokeMethod call
       
    99 */
       
   100 // Start of snippet 1
       
   101 bool ContentPublishClient::addWidget(QString widgetUri)
    77 {   
   102 {   
    78     QByteArray signature = QMetaObject::normalizedSignature("addWidget(QString,QVariantHash)");
   103     // find interface IHomeScreenClient from service hshomescreenclientplugin 
       
   104     QServiceManager manager;
       
   105     QServiceFilter filter("com.nokia.symbian.IHomeScreenClient");
       
   106     filter.setServiceName("hshomescreenclientplugin");
       
   107     QList<QServiceInterfaceDescriptor> interfaces = manager.findInterfaces(filter);
       
   108 
       
   109     if(interfaces.isEmpty()) {
       
   110         QServiceManager::Error error = manager.error();
       
   111         return false;
       
   112     }
       
   113     
       
   114     QObject* service = manager.loadInterface(interfaces.first());
       
   115 
       
   116     // access service's addWidget function
       
   117     bool retVal = false;
       
   118     bool ret = QMetaObject::invokeMethod( 
       
   119         service, 
       
   120         "addWidget",
       
   121         Qt::DirectConnection,
       
   122         Q_RETURN_ARG(bool, retVal),
       
   123         Q_ARG(QString,widgetUri),
       
   124         Q_ARG(QVariantHash,QVariantHash()));
       
   125         
       
   126     if(!ret){
       
   127         // invokeMethod returned error
       
   128         return false;
       
   129     }
       
   130     if(!retVal){
       
   131         // addWidget returned error
       
   132         return false;
       
   133     }
       
   134     return true;
       
   135 }
       
   136 // End of snippet 1
       
   137 
       
   138 /*!
       
   139     Sets home screen wallpaper as testwallpaper.png 
       
   140 */
       
   141 void ContentPublishClient::setWallpaper1()
       
   142 {
       
   143     QString wallpaper = "c:/data/images/kqtihswallpapers/testwallpaper.jpg";
       
   144     setWallpaper(wallpaper);
       
   145 }
       
   146 
       
   147 /*!
       
   148     Sets home screen wallpaper as testwallpaper2.png 
       
   149 */
       
   150 void ContentPublishClient::setWallpaper2()
       
   151 {
       
   152     QString wallpaper = "c:/data/images/kqtihswallpapers/testwallpaper2.jpg";
       
   153     setWallpaper(wallpaper);
       
   154 }
       
   155 
       
   156 /*!
       
   157     Changes home screen wallpaper to \a wallpaper image.
       
   158     Note. load function needs to be called before this, it creates mService object.
       
   159     
       
   160 */
       
   161 // Start of snippet 2
       
   162 bool ContentPublishClient::setWallpaper(QString wallpaper)
       
   163 {   
       
   164     QByteArray signature = QMetaObject::normalizedSignature("setWallpaper(QString)");
    79     int methodIndex = mService->metaObject()->indexOfMethod(signature);   
   165     int methodIndex = mService->metaObject()->indexOfMethod(signature);   
       
   166     if (methodIndex<0) {
       
   167         return false;
       
   168     }
    80     QMetaMethod method = mService->metaObject()->method(methodIndex);
   169     QMetaMethod method = mService->metaObject()->method(methodIndex);
    81     bool retVal(false);
   170     bool retVal(false);
    82 
   171 
    83     QString widget = "hsclockwidgetplugin";
       
    84     
       
    85     bool ret = method.invoke( mService,
   172     bool ret = method.invoke( mService,
    86                               Qt::DirectConnection,
   173                               Qt::DirectConnection,
    87                               Q_RETURN_ARG(bool, retVal),
   174                               Q_RETURN_ARG(bool, retVal),
    88                               Q_ARG(QString,widget),
   175                               Q_ARG(QString,wallpaper));
    89                               Q_ARG(QVariantHash,QVariantHash()));
       
    90                     
   176                     
    91     if(!ret){
   177     if(!ret){
    92         qDebug()<< "method invoke failed!";
   178         // invokeMethod returned error
       
   179         return false;
    93     }
   180     }
    94     if(!retVal){
   181     if(!retVal){
    95         qDebug() << "addWidget() failed!!";
   182         // setWallpaper returned error
       
   183         return false;
    96     }
   184     }
       
   185     return true;
    97 }
   186 }
       
   187 
       
   188 // End of snippet 2