videocollection/tsrc/videoservicestestapp/src/videoservicestestappview.cpp
changeset 39 f6d44a0cd476
child 41 229f037ce963
equal deleted inserted replaced
38:ff53afa8ad05 39:f6d44a0cd476
       
     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:
       
    15 *
       
    16 */
       
    17 
       
    18 #include <xqaiwrequest.h>
       
    19 #include <QGraphicsLinearLayout>
       
    20 #include <hbpushbutton.h>
       
    21 #include <hblineedit.h>
       
    22 #include <hblabel.h>
       
    23 #include <hbaction.h>
       
    24 #include <hbinputdialog.h>
       
    25 #include <qdebug>
       
    26 #include <vcxmyvideosdefs.h>
       
    27 #include <xqaiwdecl.h>
       
    28 #include "videoservicestestappview.h"
       
    29 
       
    30 VideoServicesTestAppView::VideoServicesTestAppView(QGraphicsItem *parent) :
       
    31     HbView(parent),
       
    32     mReq(0),
       
    33     mResultEdit(0),
       
    34     mErrorCodeEdit(0),
       
    35     mErrorEdit(0)
       
    36 {
       
    37     qDebug() << "VideoServicesTestAppView::VideoServicesTestAppView";
       
    38     createLayout();
       
    39 }
       
    40 
       
    41 
       
    42 VideoServicesTestAppView::~VideoServicesTestAppView()
       
    43 {
       
    44     qDebug() << "VideoServicesTestAppView::~VideoServicesTestAppView";
       
    45     delete mReq;
       
    46 }
       
    47 
       
    48 
       
    49 void VideoServicesTestAppView::handleOk(const QVariant &result)
       
    50 {
       
    51     qDebug() << "VideoServicesTestAppView::handleOk";
       
    52 
       
    53     if (!result.canConvert<QStringList>())
       
    54     {
       
    55         mErrorEdit->setText("Corrupt result");
       
    56     }
       
    57     else
       
    58     {
       
    59         QString text = result.value<QString>();
       
    60         if (text.isEmpty())
       
    61         {
       
    62             text = "No result available in this service";
       
    63         }
       
    64         mResultEdit->setText(text);
       
    65         qDebug() << "VideoServicesTestAppView::handleOk" << ": result=" << text;
       
    66     }
       
    67 
       
    68 }
       
    69 
       
    70 
       
    71 void VideoServicesTestAppView::handleError(int errorCode, const QString& errorMessage)
       
    72 {
       
    73     qDebug() << "VideoServicesTestAppView::handleError" << ": errorCode=" << errorCode << ", msg:" << errorMessage;
       
    74     mErrorEdit->setText(errorMessage);
       
    75     mErrorCodeEdit->setText(QString::number(errorCode));
       
    76 }
       
    77 
       
    78 
       
    79 void VideoServicesTestAppView::createLayout()
       
    80 {
       
    81     qDebug() <<  "VideoServicesTestAppView::createLayout";
       
    82 
       
    83     QGraphicsLinearLayout* layout = new QGraphicsLinearLayout(Qt::Vertical);
       
    84 
       
    85     if (layout)
       
    86     {
       
    87         QGraphicsLinearLayout *topLayout = new QGraphicsLinearLayout(Qt::Vertical);
       
    88 
       
    89         if (topLayout)
       
    90         {
       
    91         	//topLayout->addStretch(5);
       
    92 
       
    93             mResultEdit = new HbLineEdit;
       
    94             HbLabel* label = new HbLabel("Result:");
       
    95             if (mResultEdit && label)
       
    96             {
       
    97                 topLayout->addItem(label);
       
    98                 mResultEdit->setMaxRows(5);
       
    99                 topLayout->addItem(mResultEdit);
       
   100             }
       
   101 
       
   102             mErrorCodeEdit = new HbLineEdit;
       
   103             label = new HbLabel("Error code:");
       
   104             if (mErrorCodeEdit && label)
       
   105             {
       
   106                 topLayout->addItem(label);
       
   107                 topLayout->addItem(mErrorCodeEdit);
       
   108             }
       
   109 
       
   110             mErrorEdit = new HbLineEdit;
       
   111             label = new HbLabel("Error description:");
       
   112             if (mErrorEdit && label)
       
   113             {
       
   114                 topLayout->addItem(label);
       
   115                 mErrorEdit->setMaxRows(5);
       
   116                 topLayout->addItem(mErrorEdit);
       
   117             }
       
   118 
       
   119             layout->addItem(topLayout);
       
   120             //layout->setStretchFactor(topLayout, 5);
       
   121         }
       
   122 
       
   123         QGraphicsLinearLayout *bottomLayout = new QGraphicsLinearLayout(Qt::Vertical);
       
   124 
       
   125         if (bottomLayout)
       
   126         {
       
   127             //bottomLayout->addStretch();
       
   128 /*
       
   129             HbPushButton* button = new HbPushButton("Fetch video OLD IF OLD S");
       
   130             if (button)
       
   131             {
       
   132                 connect(button, SIGNAL(clicked()), this, SLOT(fetchVideoDeprecatedOldService()));
       
   133                 bottomLayout->addItem(button);
       
   134             }
       
   135 */
       
   136             HbPushButton* button = new HbPushButton("Fetch video OLD IF NEW S");
       
   137             if (button)
       
   138             {
       
   139                 connect(button, SIGNAL(clicked()), this, SLOT(fetchVideoDeprecatedNewService()));
       
   140                 bottomLayout->addItem(button);
       
   141             }
       
   142 
       
   143             button = new HbPushButton("Fetch video NEW IF NEW S");
       
   144             if (button)
       
   145             {
       
   146                 connect(button, SIGNAL(clicked()), this, SLOT(fetchVideo()));
       
   147                 bottomLayout->addItem(button);
       
   148             }
       
   149 
       
   150 /*
       
   151             button = new HbPushButton("Browse \"Captured\" videos OLD IF OLD S");
       
   152             if (button)
       
   153             {
       
   154                 connect(button, SIGNAL(clicked()), this, SLOT(browseCapturedVideosDeprecatedOldService()));
       
   155                 bottomLayout->addItem(button);
       
   156             }
       
   157 */
       
   158             button = new HbPushButton("Browse \"Captured\" videos OLD IF NEW S");
       
   159             if (button)
       
   160             {
       
   161                 connect(button, SIGNAL(clicked()), this, SLOT(browseCapturedVideosDeprecatedNewService()));
       
   162                 bottomLayout->addItem(button);
       
   163             }
       
   164 
       
   165 
       
   166             button = new HbPushButton("Browse \"Captured\" videos NEW IF");
       
   167             if (button)
       
   168             {
       
   169                 connect(button, SIGNAL(clicked()), this, SLOT(browseCapturedVideos()));
       
   170                 bottomLayout->addItem(button);
       
   171             }
       
   172 
       
   173             layout->addItem(bottomLayout);
       
   174         }
       
   175 
       
   176         setLayout(layout); // Takes ownership of layout
       
   177     }
       
   178 }
       
   179 
       
   180 
       
   181 void VideoServicesTestAppView::fetchVideo()
       
   182 {
       
   183     qDebug() <<  "VideoServicesTestAppView::fetchVideo START";
       
   184 
       
   185     mResultEdit->setText("");
       
   186     mErrorEdit->setText("");
       
   187     mErrorCodeEdit->setText("");
       
   188 
       
   189     delete mReq;
       
   190     mReq = 0;
       
   191     mReq = mAppMgr.create(XQI_VIDEO_FETCH, "fetch()", true);
       
   192 
       
   193     qDebug() <<  "VideoServicesTestAppView::fetchVideo: mReq=" << mReq;
       
   194 
       
   195     if (!mReq)
       
   196     {
       
   197         mErrorEdit->setText("Failed to create REQ");
       
   198         return;
       
   199     }
       
   200     else
       
   201     {
       
   202         connect(mReq, SIGNAL(requestOk(const QVariant&)), SLOT(handleOk(const QVariant&)));
       
   203         connect(mReq, SIGNAL(requestError(int,const QString&)), SLOT(handleError(int,const QString&)));
       
   204     }
       
   205 
       
   206     // Set arguments for request (application title)
       
   207     XQRequestInfo info;
       
   208     info.setInfo("WindowTitle", "<NEW IF app_name>");
       
   209     mReq->setInfo(info);
       
   210 
       
   211     // Make the request
       
   212     if (!mReq->send())
       
   213     {
       
   214         mErrorEdit->setText("Failed to send REQ");
       
   215         qDebug() <<  "VideoServicesTestAppView::fetchVideo: XQAiwRequest::send returned false";
       
   216     }
       
   217 
       
   218     qDebug() <<  "VideoServicesTestAppView::fetchVideo END";
       
   219 }
       
   220 
       
   221 
       
   222 void VideoServicesTestAppView::browseCapturedVideos()
       
   223 {
       
   224     qDebug() <<  "VideoServicesTestAppView::browseCapturedVideos START";
       
   225 
       
   226     mResultEdit->setText("");
       
   227     mErrorEdit->setText("");
       
   228     mErrorCodeEdit->setText("");
       
   229 
       
   230     delete mReq;
       
   231     mReq = 0;
       
   232 
       
   233     mReq = mAppMgr.create("com.nokia.symbian.IVideoBrowse", "browseVideos(int,int)", true);
       
   234 
       
   235     qDebug() <<  "VideoServicesTestAppView::browseCapturedVideos: mReq=" << mReq;
       
   236 
       
   237     if (!mReq)
       
   238     {
       
   239         mErrorEdit->setText("Failed to create REQ");
       
   240         return;
       
   241     }
       
   242     else
       
   243     {
       
   244         connect(mReq, SIGNAL(requestOk(QVariant)), SLOT(handleOk(QVariant)));
       
   245         connect(mReq, SIGNAL(requestError(int,QString)), SLOT(handleError(int,QString)));
       
   246     }
       
   247 
       
   248     // - title
       
   249     XQRequestInfo info;
       
   250     info.setInfo("WindowTitle", "<NEW IF app name>");
       
   251     mReq->setInfo(info);
       
   252 
       
   253     HbInputDialog *dialog = new HbInputDialog();
       
   254     dialog->setAttribute(Qt::WA_DeleteOnClose);
       
   255     dialog->setAdditionalRowVisible(true);
       
   256     dialog->setInputMode(HbInputDialog::IntInput, 0);
       
   257     dialog->setInputMode(HbInputDialog::IntInput, 1);
       
   258     dialog->setPromptText("Enter category", 0);
       
   259     dialog->setPromptText("Enter sort role", 1);
       
   260 	dialog->setValue(3, 0);
       
   261 	dialog->setValue(0, 1);
       
   262     dialog->open(this, SLOT(browseCapturedVideosFinished(HbAction *)));
       
   263 
       
   264     qDebug() <<  "VideoServicesTestAppView::browseCapturedVideos END";
       
   265 }
       
   266 
       
   267 void VideoServicesTestAppView::browseCapturedVideosFinished(HbAction *action)
       
   268 {
       
   269     HbInputDialog *dialog = static_cast<HbInputDialog*>(sender());
       
   270 
       
   271     int category = dialog->value(0).toInt();
       
   272     int sortRole = dialog->value(1).toInt();
       
   273 
       
   274     if(dialog->actions().first() == action)
       
   275     {
       
   276     	// set arguments
       
   277         QList<QVariant> args;
       
   278         args.append(QVariant(category));
       
   279         args.append(QVariant(sortRole));
       
   280         mReq->setArguments(args);
       
   281 
       
   282         // Make the request
       
   283         if (!mReq->send())
       
   284         {
       
   285             mErrorEdit->setText("Failed to send REQ");
       
   286             qDebug() <<  "VideoServicesTestAppView::browseCapturedVideosFinished: XQAiwRequest::send returned false";
       
   287         }
       
   288     }
       
   289 }
       
   290 
       
   291 void VideoServicesTestAppView::fetchVideoDeprecatedOldService()
       
   292 {
       
   293     qDebug() <<  "VideoServicesTestAppView::fetchVideo START";
       
   294 
       
   295     mResultEdit->setText("");
       
   296     mErrorEdit->setText("");
       
   297     mErrorCodeEdit->setText("");
       
   298 
       
   299     delete mReq;
       
   300     mReq = 0;
       
   301     mReq = mAppMgr.create("com.nokia.Videos", "IVideoFetch", "fetch(QString)", true);
       
   302 
       
   303     qDebug() <<  "VideoServicesTestAppView::fetchVideo: mReq=" << mReq;
       
   304 
       
   305     if (!mReq)
       
   306     {
       
   307         mErrorEdit->setText("Failed to create REQ");
       
   308         return;
       
   309     }
       
   310     else
       
   311     {
       
   312         connect(mReq, SIGNAL(requestOk(const QVariant&)), SLOT(handleOk(const QVariant&)));
       
   313         connect(mReq, SIGNAL(requestError(int,const QString&)), SLOT(handleError(int,const QString&)));
       
   314     }
       
   315 
       
   316     // Set arguments for request (application title)
       
   317     QList<QVariant> args;
       
   318     args << QVariant(QString("<OLD-IF-OLD-S app_name>"));
       
   319     mReq->setArguments(args);
       
   320 
       
   321     // Make the request
       
   322     if (!mReq->send())
       
   323     {
       
   324         mErrorEdit->setText("Failed to send REQ");
       
   325         qDebug() <<  "VideoServicesTestAppView::fetchVideo: XQAiwRequest::send returned false";
       
   326     }
       
   327 
       
   328     qDebug() <<  "VideoServicesTestAppView::fetchVideo END";
       
   329 }
       
   330 
       
   331 void VideoServicesTestAppView::fetchVideoDeprecatedNewService()
       
   332 {
       
   333     qDebug() <<  "VideoServicesTestAppView::fetchVideo START";
       
   334 
       
   335     mResultEdit->setText("");
       
   336     mErrorEdit->setText("");
       
   337     mErrorCodeEdit->setText("");
       
   338 
       
   339     delete mReq;
       
   340     mReq = 0;
       
   341     mReq = mAppMgr.create("videoplayer", "IVideoFetch", "fetch(QString)", true);
       
   342 
       
   343     qDebug() <<  "VideoServicesTestAppView::fetchVideo: mReq=" << mReq;
       
   344 
       
   345     if (!mReq)
       
   346     {
       
   347         mErrorEdit->setText("Failed to create REQ");
       
   348         return;
       
   349     }
       
   350     else
       
   351     {
       
   352         connect(mReq, SIGNAL(requestOk(const QVariant&)), SLOT(handleOk(const QVariant&)));
       
   353         connect(mReq, SIGNAL(requestError(int,const QString&)), SLOT(handleError(int,const QString&)));
       
   354     }
       
   355 
       
   356     // Set arguments for request (application title)
       
   357     QList<QVariant> args;
       
   358     args << QVariant(QString("<OLD-IF-NEW-S app_name>"));
       
   359     mReq->setArguments(args);
       
   360 
       
   361     // Make the request
       
   362     if (!mReq->send())
       
   363     {
       
   364         mErrorEdit->setText("Failed to send REQ");
       
   365         qDebug() <<  "VideoServicesTestAppView::fetchVideo: XQAiwRequest::send returned false";
       
   366     }
       
   367 
       
   368     qDebug() <<  "VideoServicesTestAppView::fetchVideo END";
       
   369 }
       
   370 
       
   371 
       
   372 void VideoServicesTestAppView::browseCapturedVideosDeprecatedOldService()
       
   373 {
       
   374     qDebug() <<  "VideoServicesTestAppView::browseCapturedVideos START";
       
   375 
       
   376     mResultEdit->setText("");
       
   377     mErrorEdit->setText("");
       
   378     mErrorCodeEdit->setText("");
       
   379 
       
   380     delete mReq;
       
   381     mReq = 0;
       
   382     mReq = mAppMgr.create("com.nokia.Videos", "IVideoBrowse", "browseVideos(QString,int,int)", true);
       
   383 
       
   384     qDebug() <<  "VideoServicesTestAppView::browseCapturedVideos: mReq=" << mReq;
       
   385 
       
   386     if (!mReq)
       
   387     {
       
   388         mErrorEdit->setText("Failed to create REQ");
       
   389         return;
       
   390     }
       
   391     else
       
   392     {
       
   393         connect(mReq, SIGNAL(requestOk(QVariant)), SLOT(handleOk(QVariant)));
       
   394         connect(mReq, SIGNAL(requestError(int,QString)), SLOT(handleError(int,QString)));
       
   395     }
       
   396 
       
   397     HbInputDialog *dialog = new HbInputDialog();
       
   398     dialog->setAttribute(Qt::WA_DeleteOnClose);
       
   399     dialog->setAdditionalRowVisible(true);
       
   400     dialog->setInputMode(HbInputDialog::IntInput, 0);
       
   401     dialog->setInputMode(HbInputDialog::IntInput, 1);
       
   402     dialog->setPromptText("Enter category", 0);
       
   403     dialog->setPromptText("Enter sort role", 1);
       
   404 	dialog->setValue(3, 0);
       
   405 	dialog->setValue(0, 1);
       
   406     dialog->open(this, SLOT(browseCapturedVideosDeprecatedOldServiceFinished(HbAction *)));
       
   407 
       
   408     qDebug() <<  "VideoServicesTestAppView::browseCapturedVideos END";
       
   409 }
       
   410 
       
   411 void VideoServicesTestAppView::browseCapturedVideosDeprecatedOldServiceFinished(HbAction *action)
       
   412 {
       
   413     HbInputDialog *dialog = static_cast<HbInputDialog*>(sender());
       
   414 
       
   415     const QString title = "<OLD-IF-OLD-S app name>";
       
   416 
       
   417     int category = dialog->value(0).toInt();
       
   418     int sortRole = dialog->value(1).toInt();
       
   419 
       
   420     if(dialog->actions().first() == action)
       
   421     {
       
   422     	// set arguments
       
   423         QList<QVariant> args;
       
   424         args.append(title);
       
   425         args.append(QVariant(category));
       
   426         args.append(QVariant(sortRole));
       
   427         mReq->setArguments(args);
       
   428 
       
   429         // Make the request
       
   430         if (!mReq->send())
       
   431         {
       
   432             mErrorEdit->setText("Failed to send REQ");
       
   433             qDebug() <<  "VideoServicesTestAppView::browseCapturedVideosFinished: XQAiwRequest::send returned false";
       
   434         }
       
   435     }
       
   436 }
       
   437 
       
   438 void VideoServicesTestAppView::browseCapturedVideosDeprecatedNewService()
       
   439 {
       
   440     qDebug() <<  "VideoServicesTestAppView::browseCapturedVideos START";
       
   441 
       
   442     mResultEdit->setText("");
       
   443     mErrorEdit->setText("");
       
   444     mErrorCodeEdit->setText("");
       
   445 
       
   446     delete mReq;
       
   447     mReq = 0;
       
   448     mReq = mAppMgr.create("videoplayer", "IVideoBrowse", "browseVideos(QString,int,int)", true);
       
   449 
       
   450     qDebug() <<  "VideoServicesTestAppView::browseCapturedVideos: mReq=" << mReq;
       
   451 
       
   452     if (!mReq)
       
   453     {
       
   454         mErrorEdit->setText("Failed to create REQ");
       
   455         return;
       
   456     }
       
   457     else
       
   458     {
       
   459         connect(mReq, SIGNAL(requestOk(QVariant)), SLOT(handleOk(QVariant)));
       
   460         connect(mReq, SIGNAL(requestError(int,QString)), SLOT(handleError(int,QString)));
       
   461     }
       
   462 
       
   463     HbInputDialog *dialog = new HbInputDialog();
       
   464     dialog->setAttribute(Qt::WA_DeleteOnClose);
       
   465     dialog->setAdditionalRowVisible(true);
       
   466     dialog->setInputMode(HbInputDialog::IntInput, 0);
       
   467     dialog->setInputMode(HbInputDialog::IntInput, 1);
       
   468     dialog->setPromptText("Enter category", 0);
       
   469     dialog->setPromptText("Enter sort role", 1);
       
   470 	dialog->setValue(3, 0);
       
   471 	dialog->setValue(0, 1);
       
   472     dialog->open(this, SLOT(browseCapturedVideosDeprecatedNewServiceFinished(HbAction *)));
       
   473 
       
   474     qDebug() <<  "VideoServicesTestAppView::browseCapturedVideos END";
       
   475 }
       
   476 
       
   477 void VideoServicesTestAppView::browseCapturedVideosDeprecatedNewServiceFinished(HbAction *action)
       
   478 {
       
   479     HbInputDialog *dialog = static_cast<HbInputDialog*>(sender());
       
   480 
       
   481     const QString title = "<OLD-IF-NEW-S app name>";
       
   482 
       
   483     int category = dialog->value(0).toInt();
       
   484     int sortRole = dialog->value(1).toInt();
       
   485 
       
   486     if(dialog->actions().first() == action)
       
   487     {
       
   488     	// set arguments
       
   489         QList<QVariant> args;
       
   490         args.append(title);
       
   491         args.append(QVariant(category));
       
   492         args.append(QVariant(sortRole));
       
   493         mReq->setArguments(args);
       
   494 
       
   495         // Make the request
       
   496         if (!mReq->send())
       
   497         {
       
   498             mErrorEdit->setText("Failed to send REQ");
       
   499             qDebug() <<  "VideoServicesTestAppView::browseCapturedVideosFinished: XQAiwRequest::send returned false";
       
   500         }
       
   501     }
       
   502 }
       
   503 
       
   504 // end of file