tsrc/mpfetchertestapp/src/mpfetchertestappview.cpp
changeset 22 ecf06a08d4d9
parent 20 82baf59ce8dd
child 29 8192e5b5c935
equal deleted inserted replaced
20:82baf59ce8dd 22:ecf06a08d4d9
    14 * Description:
    14 * Description:
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 #include <xqaiwrequest.h>
    18 #include <xqaiwrequest.h>
       
    19 #include <xqservicerequest.h>
    19 #include <QGraphicsLinearLayout>
    20 #include <QGraphicsLinearLayout>
    20 #include <hbpushbutton.h>
    21 #include <hbpushbutton.h>
    21 #include <hblineedit.h>
    22 #include <hblineedit.h>
    22 #include <hblabel.h>
    23 #include <hblabel.h>
    23 #include <qdebug>
    24 #include <qdebug>
   117             if (button)
   118             if (button)
   118             {
   119             {
   119                 connect(button, SIGNAL(clicked()), SLOT(fetchSong()));
   120                 connect(button, SIGNAL(clicked()), SLOT(fetchSong()));
   120                 bottomLayout->addItem(button);
   121                 bottomLayout->addItem(button);
   121             }
   122             }
       
   123             HbPushButton* playButton = new HbPushButton("Play song");
       
   124             if (playButton)
       
   125             {
       
   126                 connect(playButton, SIGNAL(clicked()), SLOT(viewSong()));
       
   127                 bottomLayout->addItem(playButton);
       
   128             }
       
   129             HbPushButton* viewButton = new HbPushButton("Play song caged");
       
   130             if (viewButton)
       
   131             {
       
   132                 connect(viewButton, SIGNAL(clicked()), SLOT(viewSongCaged()));
       
   133                 bottomLayout->addItem(viewButton);
       
   134             }
   122             layout->addItem(bottomLayout);
   135             layout->addItem(bottomLayout);
   123         }
   136         }
   124 
   137 
   125         setLayout(layout); // Takes ownership of layout
   138         setLayout(layout); // Takes ownership of layout
   126     }
   139     }
   131     qDebug() <<  "MpFetcherTestAppView::fetchSong START";
   144     qDebug() <<  "MpFetcherTestAppView::fetchSong START";
   132 
   145 
   133     mResultEdit->setText("");
   146     mResultEdit->setText("");
   134     mErrorEdit->setText("");
   147     mErrorEdit->setText("");
   135     mErrorCodeEdit->setText("");
   148     mErrorCodeEdit->setText("");
   136 
   149     if(mReq){
       
   150         delete mReq;
       
   151         mReq = 0;
       
   152     }
       
   153     
   137     if (!mReq)
   154     if (!mReq)
   138     {
   155     {
   139         mReq = mAppMgr.create("com.nokia.services.media.Music", "fetch(QString)", true);
   156         mReq = mAppMgr.create("com.nokia.symbian.IMusicFetch", "fetch()", true);
   140 
   157 
   141         qDebug() <<  "MpFetcherTestAppView::fetchSong: mReq=" << mReq;
   158         qDebug() <<  "MpFetcherTestAppView::fetchSong: mReq=" << mReq;
   142 
   159 
   143         if (!mReq)
   160         if (!mReq)
   144         {
   161         {
   151             connect(mReq, SIGNAL(requestError(int,const QString&)), SLOT(handleError(int,const QString&)));
   168             connect(mReq, SIGNAL(requestError(int,const QString&)), SLOT(handleError(int,const QString&)));
   152         }
   169         }
   153     }
   170     }
   154 
   171 
   155     // Set arguments for request (application title)
   172     // Set arguments for request (application title)
   156     QList<QVariant> args;
   173 //    QList<QVariant> args;
   157     args << QVariant(QString("<app_name>"));
   174 //    args << QVariant(QString("<app_name>"));
   158     mReq->setArguments(args);
   175 //    mReq->setArguments(args);
   159 
   176     QString title("WindowTitle");
       
   177     QVariant title2(QString("app_name"));
       
   178     XQRequestInfo info;
       
   179     info.setInfo(title, title2);
       
   180     mReq->setInfo(info);
   160     // Make the request
   181     // Make the request
   161     if (!mReq->send())
   182     if (!mReq->send())
   162     {
   183     {   
   163         mErrorEdit->setText("Failed to send REQ");
   184         mErrorEdit->setText("Failed to send REQ");
   164         qDebug() <<  "MpFetcherTestAppView::fetchSong: XQAiwRequest::send returned false";
   185         qDebug() <<  "MpFetcherTestAppView::fetchSong: XQAiwRequest::send returned false";
   165     }
   186     }
   166 
   187 
   167     qDebug() <<  "MpFetcherTestAppView::fetchSong END";
   188     qDebug() <<  "MpFetcherTestAppView::fetchSong END";
   168 }
   189 }
       
   190 
       
   191 void MpFetcherTestAppView::playSong()
       
   192 {
       
   193     qDebug() <<  "MpFetcherTestAppView::playSong START";
       
   194 
       
   195     if(mReq){
       
   196         delete mReq;
       
   197         mReq = 0;
       
   198     }
       
   199     if (!mReq)
       
   200     {
       
   201         mReq = mAppMgr.create("com.nokia.symbian.IFileViewMusic", "playMedia(QString,QString)", true);
       
   202 
       
   203         qDebug() <<  "MpFetcherTestAppView::playSong: mReq=" << mReq;
       
   204 
       
   205         if (!mReq)
       
   206         {
       
   207             mErrorEdit->setText("Failed to create REQ");
       
   208             return;
       
   209         }
       
   210         else
       
   211         {
       
   212             connect(mReq, SIGNAL(requestOk(const QVariant&)), SLOT(handleOk(const QVariant&)));
       
   213             connect(mReq, SIGNAL(requestError(int,const QString&)), SLOT(handleError(int,const QString&)));
       
   214         }
       
   215     }
       
   216 
       
   217     // Set arguments for request (application title)
       
   218     QList<QVariant> args;
       
   219     args << QString("<app_name>");
       
   220     args << mResultEdit->text();
       
   221     
       
   222     mReq->setArguments(args);
       
   223 
       
   224     // Make the request
       
   225     if (!mReq->send())
       
   226     {
       
   227         mErrorEdit->setText("Failed to send REQ");
       
   228         qDebug() <<  "MpFetcherTestAppView::playSong: XQAiwRequest::send returned false";
       
   229     }
       
   230 
       
   231     qDebug() <<  "MpFetcherTestAppView::playSong END";
       
   232 }
       
   233 
       
   234 void MpFetcherTestAppView::viewSong()
       
   235 {
       
   236     
       
   237     if(mReq){
       
   238         delete mReq;
       
   239         mReq = 0;
       
   240     }
       
   241     QFile file(mResultEdit->text());
       
   242 
       
   243     mReq = mAppMgr.create(file);
       
   244     if (mReq == NULL)
       
   245     {
       
   246            // No handlers for the URI
       
   247            return;
       
   248      }
       
   249     // By default operation is "view(QString)"
       
   250 
       
   251     // Set function parameters
       
   252    QList<QVariant> args;
       
   253    args << file.fileName();
       
   254    mReq->setArguments(args);
       
   255    QString title("WindowTitle");
       
   256    QVariant title2(QString("<app_name>View"));
       
   257    XQRequestInfo info;
       
   258    info.setInfo(title, title2);
       
   259    mReq->setInfo(info);
       
   260    // Send the request
       
   261    bool res = mReq->send();
       
   262    if  (!res) 
       
   263    {
       
   264        // Request failed. 
       
   265       int error = mReq->lastError();
       
   266 
       
   267       // Handle error
       
   268    }
       
   269  
       
   270    // If making multiple requests to same service, you can save the request as member variable
       
   271    // In this example all done.
       
   272 
       
   273 
       
   274 }
       
   275 
       
   276 void MpFetcherTestAppView::viewSongCaged()
       
   277 {
       
   278     if(mReq){
       
   279         delete mReq;
       
   280         mReq = 0;
       
   281     }
       
   282     XQSharableFile sf;
       
   283     // Open the file for sharing from own private  directory
       
   284     // If you have handle available, just set it by "setHandle()" function
       
   285     if (!sf.open(mResultEdit->text()))
       
   286     {
       
   287         // Failed to open sharable file
       
   288         return;
       
   289     }
       
   290 
       
   291     // Create request for the sharable file
       
   292     mReq = mAppMgr.create(sf);
       
   293     if (!mReq)
       
   294    {
       
   295          // No viewer app found for the file
       
   296          // As we opened the handle, we need to close it !
       
   297          sf.close(); 
       
   298          return;  
       
   299    }
       
   300     // By default operation is "view(XQSharableFile)"
       
   301 
       
   302     // Set function parameters
       
   303     // Not only one sharable handle supported,  otherwise upon send EArgumentError error occurs
       
   304     QList<QVariant> args;
       
   305     args << qVariantFromValue(sf);  
       
   306     mReq->setArguments(args);
       
   307     QString title("WindowTitle");
       
   308    QVariant title2(QString("<app_name>Caged"));
       
   309    XQRequestInfo info;
       
   310    info.setInfo(title, title2);
       
   311    mReq->setInfo(info);
       
   312    // Send the request
       
   313    bool res = mReq->send();
       
   314    if  (!res) 
       
   315    {
       
   316        // Request failed. 
       
   317       int error = mReq->lastError();
       
   318       // Handle error
       
   319    }
       
   320 
       
   321     // As we opened the handle, we need to close it !
       
   322     sf.close(); 
       
   323 
       
   324    // If making multiple requests to same service, you can save the mReq as member variable
       
   325    // In this example all done.
       
   326 
       
   327 
       
   328 }