main/glxaiwservicehandler.cpp
branchRCL_3
changeset 59 8e5f6eea9c9f
equal deleted inserted replaced
57:ea65f74e6de4 59:8e5f6eea9c9f
       
     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:   ?Description
       
    15 *
       
    16 */
       
    17 
       
    18 #include <hbapplication.h>
       
    19 #include <hbview.h>
       
    20 #include <hbmenu.h>
       
    21 #include <hbaction.h>
       
    22 #include <hbnotificationdialog.h>
       
    23 
       
    24 #include <QtDebug>
       
    25 #include <Qt>
       
    26 #include <QDir>
       
    27 #include <QStringList>
       
    28 
       
    29 #include <xqserviceutil.h>
       
    30 #include <xqaiwdeclplat.h>
       
    31 #include <xqappmgr.h>
       
    32 
       
    33 #include <glxmodelroles.h>
       
    34 #include <glxaiwservicehandler.h>
       
    35 #include <glxstatemanager.h>
       
    36 #include <glximageviewermanager.h>
       
    37 #include <glxexternalutility.h>
       
    38 #include "glxlocalisationstrings.h"
       
    39 
       
    40 #define IMAGE_FETCHER_SERVICE_NAME QLatin1String("photos.com.nokia.symbian.IImageFetch")
       
    41 #define IMAGE_FETCHER_SERVICE_DEPINTERFACE_NAME QLatin1String("photos.Image")
       
    42 #define IMAGE_FETCHER_DEPSERVICE_DEPINTERFACE_NAME QLatin1String("com.nokia.services.media.Image")
       
    43 #define FILE_VIEWER_SERVICE_NAME QLatin1String("photos.com.nokia.symbian.IFileView")
       
    44 
       
    45 
       
    46 // ----------------------------------------------------------------------------
       
    47 // GlxAiwServiceHandler()
       
    48 // ----------------------------------------------------------------------------
       
    49 //
       
    50 GlxAiwServiceHandler::GlxAiwServiceHandler() :
       
    51     HbMainWindow(), 
       
    52     mStateMgr(NULL),
       
    53     mFetcherService(NULL),
       
    54     mNSDIService(NULL),
       
    55     mDSDIService(NULL),
       
    56     mImageViewerService(NULL)
       
    57     {
       
    58     QString currentInterfaceName = XQServiceUtil::interfaceName();
       
    59     if( 0 == currentInterfaceName.compare(QLatin1String("com.nokia.symbian.IImageFetch")))
       
    60         {
       
    61         mFetcherService = new GlxGetImageService(this);
       
    62         }
       
    63     else if( 0 == currentInterfaceName.compare(QLatin1String("Image")))
       
    64         {
       
    65         mNSDIService = new GlxGetImageServiceNSDI(this);
       
    66         mDSDIService = new GlxGetImageServiceDSDI(this);
       
    67         }
       
    68     else if( 0 == currentInterfaceName.compare(QLatin1String("com.nokia.symbian.IFileView")))
       
    69         {
       
    70 		viewport()->setAttribute(Qt::WA_AcceptTouchEvents);
       
    71 		viewport()->grabGesture(Qt::PinchGesture);
       
    72         mImageViewerService = new GlxImageViewerService(this);
       
    73         }
       
    74 
       
    75 #ifdef _DEBUG
       
    76 	QString t;
       
    77 	QStringList args = QApplication::arguments();
       
    78     foreach (QString arg, args)
       
    79         {
       
    80         t += "GlxAiwServiceHandler::cmdline arg=" + arg + "\n";
       
    81         }
       
    82 	qDebug()<< t;
       
    83 #endif
       
    84     }
       
    85 
       
    86 // ----------------------------------------------------------------------------
       
    87 // ~GlxAiwServiceHandler()
       
    88 // ----------------------------------------------------------------------------
       
    89 //
       
    90 GlxAiwServiceHandler::~GlxAiwServiceHandler()
       
    91     {
       
    92     delete mStateMgr;
       
    93     delete mFetcherService;
       
    94     delete mNSDIService;
       
    95     delete mDSDIService;
       
    96     delete mImageViewerService;
       
    97     }
       
    98 
       
    99 void GlxAiwServiceHandler::handleClientDisconnect()
       
   100     {
       
   101     // Just quit application
       
   102     qApp->quit();
       
   103     }
       
   104 
       
   105 // ----------------------------------------------------------------------------
       
   106 // itemSelected()
       
   107 // ----------------------------------------------------------------------------
       
   108 //
       
   109 void GlxAiwServiceHandler::itemSelected(const QModelIndex & index,QAbstractItemModel & model)
       
   110     {
       
   111     qDebug() << "GlxFetcher::itemSelected";
       
   112     if (mFetcherService && mFetcherService->isActive())
       
   113         {
       
   114         qDebug() << "GlxFetcher::itemSelected mFetcherService->isActive()";
       
   115         QVariant variant = model.data(index, GlxUriRole);
       
   116         if (variant.isValid())
       
   117             {
       
   118             QString itemPath = variant.value<QString> ();
       
   119             qDebug() << "GlxFetcher::itemSelected mFetcherService->isActive()::PATH = " << itemPath;
       
   120             QStringList list = (QStringList() << itemPath);
       
   121             mFetcherService->complete(list);
       
   122             }
       
   123         }
       
   124     
       
   125     else if (mNSDIService && mNSDIService->isActive())
       
   126         {
       
   127     qDebug() << "GlxFetcher::itemSelected mNSDIService->isActive()";
       
   128         QVariant variant = model.data(index, GlxUriRole);
       
   129         if (variant.isValid())
       
   130             {
       
   131             QString itemPath = variant.value<QString> ();
       
   132             QStringList list = (QStringList() << itemPath);
       
   133             mNSDIService->complete(list);
       
   134             }
       
   135         }
       
   136     
       
   137     else if (mDSDIService && mDSDIService->isActive())
       
   138         {
       
   139     qDebug() << "GlxFetcher::itemSelected mDSDIService->isActive()";
       
   140         QVariant variant = model.data(index, GlxUriRole);
       
   141         if (variant.isValid())
       
   142             {
       
   143             QString itemPath = variant.value<QString> ();
       
   144             QStringList list = (QStringList() << itemPath);
       
   145             mDSDIService->complete(list);
       
   146             }
       
   147         }
       
   148     }	
       
   149 
       
   150 
       
   151 void GlxAiwServiceHandler::launchFetcher(QString viewTitle)
       
   152     {
       
   153     qDebug() << "GlxAiwServiceHandler::launchFetcher START";
       
   154     qApp->setApplicationName(viewTitle);
       
   155 
       
   156     mUtil = GlxExternalUtility::instance();
       
   157     mUtil->setMainWindow(this);
       
   158 
       
   159     mStateMgr = new GlxStateManager();
       
   160 	int err = connect(mStateMgr, SIGNAL(gridItemSelected(const QModelIndex &,QAbstractItemModel &)), this,
       
   161             SLOT( itemSelected(const QModelIndex &,QAbstractItemModel &)));
       
   162 	qDebug() << "GlxAiwServiceHandler::launchFetcher err = "<< err;
       
   163 	
       
   164     mStateMgr->launchFetcher();
       
   165     return;
       
   166     }
       
   167 
       
   168 void GlxAiwServiceHandler::launchImageViewer(QString viewTitle)
       
   169     {
       
   170     qApp->setApplicationName(viewTitle);
       
   171     mUtil = GlxExternalUtility::instance();
       
   172     mUtil->setMainWindow(this);
       
   173 
       
   174     mStateMgr = new GlxStateManager();
       
   175     mStateMgr->launchFromExternal();
       
   176     if (mImageViewerService && mImageViewerService->asyncRequest())
       
   177         {
       
   178         connect(mImageViewerService, SIGNAL(returnValueDelivered()), this,
       
   179                 SLOT(handleAnswerDelivered()));
       
   180         mImageViewerService->complete(true);
       
   181         }
       
   182     return;
       
   183     }
       
   184 // ----------------------------------------------------------------------------
       
   185 // GlxGetImageService()
       
   186 // ----------------------------------------------------------------------------
       
   187 //
       
   188 GlxGetImageService::GlxGetImageService(GlxAiwServiceHandler* parent) :
       
   189             XQServiceProvider(IMAGE_FETCHER_SERVICE_NAME, parent),
       
   190             mServiceApp(parent)
       
   191     {
       
   192     mImageRequestIndex = -1;
       
   193     publishAll();
       
   194     connect(this, SIGNAL(clientDisconnected()), mServiceApp,
       
   195             SLOT(handleClientDisconnect()));
       
   196     }
       
   197 
       
   198 // ----------------------------------------------------------------------------
       
   199 // ~GlxGetImageService()
       
   200 // ----------------------------------------------------------------------------
       
   201 //
       
   202 GlxGetImageService::~GlxGetImageService()
       
   203     {
       
   204     qDebug() << "GlxGetImageService::~GlxGetImageService()";
       
   205     }
       
   206 
       
   207 // ----------------------------------------------------------------------------
       
   208 // fetchFailed()
       
   209 // ----------------------------------------------------------------------------
       
   210 //
       
   211 void GlxGetImageService::fetchFailed(int errorCode)
       
   212     {
       
   213     QStringList filesList;
       
   214     filesList.insert(0, QString::number(errorCode));//result
       
   215     doComplete(filesList);
       
   216     }
       
   217 
       
   218 // ----------------------------------------------------------------------------
       
   219 // complete()
       
   220 // ----------------------------------------------------------------------------
       
   221 //
       
   222 void GlxGetImageService::complete(QStringList filesList)
       
   223     {
       
   224     doComplete(filesList);
       
   225     }
       
   226 
       
   227 // ----------------------------------------------------------------------------
       
   228 // doComplete()
       
   229 // ----------------------------------------------------------------------------
       
   230 //
       
   231 void GlxGetImageService::doComplete(QStringList filesList)
       
   232     {
       
   233     if (isActive())
       
   234         {
       
   235         completeRequest(mImageRequestIndex, filesList);
       
   236         mImageRequestIndex = -1;
       
   237         connect(this, SIGNAL(returnValueDelivered()), qApp, SLOT(quit()));
       
   238         }
       
   239     }
       
   240 
       
   241 // ----------------------------------------------------------------------------
       
   242 // isActive()
       
   243 // ----------------------------------------------------------------------------
       
   244 //
       
   245 bool GlxGetImageService::isActive()
       
   246     {
       
   247     return mImageRequestIndex > -1;
       
   248     }
       
   249 
       
   250 // ----------------------------------------------------------------------------
       
   251 // fetch()
       
   252 // ----------------------------------------------------------------------------
       
   253 //
       
   254 void GlxGetImageService::fetch()
       
   255     {
       
   256     mImageRequestIndex = setCurrentRequestAsync();
       
   257     QString title =  GLX_TITLE;
       
   258     mServiceApp->launchFetcher(title);
       
   259     }
       
   260 
       
   261 // ----------------------------------------------------------------------------
       
   262 // GlxGetImageService()
       
   263 // ----------------------------------------------------------------------------
       
   264 //
       
   265 GlxGetImageServiceNSDI::GlxGetImageServiceNSDI(GlxAiwServiceHandler* parent) :
       
   266             XQServiceProvider(IMAGE_FETCHER_SERVICE_DEPINTERFACE_NAME, parent),
       
   267             mServiceApp(parent)
       
   268     {
       
   269     mImageRequestIndex = -1;
       
   270     publishAll();
       
   271     connect(this, SIGNAL(clientDisconnected()), mServiceApp,
       
   272             SLOT(handleClientDisconnect()));
       
   273     }
       
   274 
       
   275 // ----------------------------------------------------------------------------
       
   276 // ~GlxGetImageService()
       
   277 // ----------------------------------------------------------------------------
       
   278 //
       
   279 GlxGetImageServiceNSDI::~GlxGetImageServiceNSDI()
       
   280     {
       
   281     }
       
   282 
       
   283 // ----------------------------------------------------------------------------
       
   284 // fetchFailed()
       
   285 // ----------------------------------------------------------------------------
       
   286 //
       
   287 void GlxGetImageServiceNSDI::fetchFailed(int errorCode)
       
   288     {
       
   289     QStringList filesList;
       
   290     filesList.insert(0, QString::number(errorCode));//result
       
   291     doComplete(filesList);
       
   292     }
       
   293 
       
   294 // ----------------------------------------------------------------------------
       
   295 // complete()
       
   296 // ----------------------------------------------------------------------------
       
   297 //
       
   298 void GlxGetImageServiceNSDI::complete(QStringList filesList)
       
   299     {
       
   300     doComplete(filesList);
       
   301     }
       
   302 
       
   303 // ----------------------------------------------------------------------------
       
   304 // doComplete()
       
   305 // ----------------------------------------------------------------------------
       
   306 //
       
   307 void GlxGetImageServiceNSDI::doComplete(QStringList filesList)
       
   308     {
       
   309     if (isActive())
       
   310         {
       
   311         completeRequest(mImageRequestIndex, filesList);
       
   312         mImageRequestIndex = -1;
       
   313         connect(this, SIGNAL(returnValueDelivered()), qApp, SLOT(quit()));
       
   314         }
       
   315     }
       
   316 
       
   317 // ----------------------------------------------------------------------------
       
   318 // isActive()
       
   319 // ----------------------------------------------------------------------------
       
   320 //
       
   321 bool GlxGetImageServiceNSDI::isActive()
       
   322     {
       
   323     return mImageRequestIndex > -1;
       
   324     }
       
   325 
       
   326 // ----------------------------------------------------------------------------
       
   327 // fetch()
       
   328 // ----------------------------------------------------------------------------
       
   329 //
       
   330 void GlxGetImageServiceNSDI::fetch(QVariantMap filter, QVariant flag)
       
   331     {
       
   332     qDebug() << "GlxGetImageServiceNSDI::fetch WITH PARAMETER START";
       
   333     Q_UNUSED(filter)
       
   334     Q_UNUSED(flag)
       
   335     fetch();
       
   336     qDebug() << "GlxGetImageServiceNSDI::fetch WITH PARAMETER END";
       
   337     }
       
   338 
       
   339 // ----------------------------------------------------------------------------
       
   340 // fetch()
       
   341 // ----------------------------------------------------------------------------
       
   342 //
       
   343 void GlxGetImageServiceNSDI::fetch()
       
   344     {
       
   345     qDebug() << "GlxGetImageServiceNSDI::fetch START";
       
   346     mImageRequestIndex = setCurrentRequestAsync();
       
   347     QString title = GLX_TITLE;
       
   348     mServiceApp->launchFetcher(title);
       
   349     qDebug() << "GlxGetImageServiceNSDI::fetch END";
       
   350     }
       
   351 
       
   352 //==============================================================================//
       
   353 // ----------------------------------------------------------------------------
       
   354 // GlxGetImageService()
       
   355 // ----------------------------------------------------------------------------
       
   356 //
       
   357 GlxGetImageServiceDSDI::GlxGetImageServiceDSDI(GlxAiwServiceHandler* parent) :
       
   358             XQServiceProvider(IMAGE_FETCHER_DEPSERVICE_DEPINTERFACE_NAME, parent),
       
   359             mServiceApp(parent)
       
   360     {
       
   361     mImageRequestIndex = -1;
       
   362     publishAll();
       
   363     connect(this, SIGNAL(clientDisconnected()), mServiceApp,
       
   364             SLOT(handleClientDisconnect()));
       
   365     }
       
   366 
       
   367 // ----------------------------------------------------------------------------
       
   368 // ~GlxGetImageService()
       
   369 // ----------------------------------------------------------------------------
       
   370 //
       
   371 GlxGetImageServiceDSDI::~GlxGetImageServiceDSDI()
       
   372     {
       
   373     }
       
   374 
       
   375 // ----------------------------------------------------------------------------
       
   376 // fetchFailed()
       
   377 // ----------------------------------------------------------------------------
       
   378 //
       
   379 void GlxGetImageServiceDSDI::fetchFailed(int errorCode)
       
   380     {
       
   381     QStringList filesList;
       
   382     filesList.insert(0, QString::number(errorCode));//result
       
   383     doComplete(filesList);
       
   384     }
       
   385 
       
   386 // ----------------------------------------------------------------------------
       
   387 // complete()
       
   388 // ----------------------------------------------------------------------------
       
   389 //
       
   390 void GlxGetImageServiceDSDI::complete(QStringList filesList)
       
   391     {
       
   392     doComplete(filesList);
       
   393     }
       
   394 
       
   395 // ----------------------------------------------------------------------------
       
   396 // doComplete()
       
   397 // ----------------------------------------------------------------------------
       
   398 //
       
   399 void GlxGetImageServiceDSDI::doComplete(QStringList filesList)
       
   400     {
       
   401     if (isActive())
       
   402         {
       
   403         completeRequest(mImageRequestIndex, filesList);
       
   404         mImageRequestIndex = -1;
       
   405         connect(this, SIGNAL(returnValueDelivered()), qApp, SLOT(quit()));
       
   406         }
       
   407     }
       
   408 
       
   409 // ----------------------------------------------------------------------------
       
   410 // isActive()
       
   411 // ----------------------------------------------------------------------------
       
   412 //
       
   413 bool GlxGetImageServiceDSDI::isActive()
       
   414     {
       
   415     return mImageRequestIndex > -1;
       
   416     }
       
   417 
       
   418 // ----------------------------------------------------------------------------
       
   419 // fetch()
       
   420 // ----------------------------------------------------------------------------
       
   421 //
       
   422 void GlxGetImageServiceDSDI::fetch(QVariantMap filter, QVariant flag)
       
   423     {
       
   424     Q_UNUSED(filter)
       
   425     Q_UNUSED(flag)
       
   426     mImageRequestIndex = setCurrentRequestAsync();
       
   427     QString title  = GLX_TITLE;    
       
   428     mServiceApp->launchFetcher(title);
       
   429     }
       
   430 
       
   431 // ----------GlxImageViewerService---------------
       
   432 
       
   433 GlxImageViewerService::GlxImageViewerService(GlxAiwServiceHandler* parent) :
       
   434     XQServiceProvider(FILE_VIEWER_SERVICE_NAME, parent),
       
   435             mServiceApp(parent), mAsyncReqId(-1), mAsyncRequest(false),
       
   436             mImageViewerInstance(NULL)
       
   437 
       
   438     {
       
   439     publishAll();
       
   440     connect(this, SIGNAL(clientDisconnected()), mServiceApp,
       
   441             SLOT(handleClientDisconnect()));
       
   442     }
       
   443 
       
   444 GlxImageViewerService::~GlxImageViewerService()
       
   445     {
       
   446     if (mImageViewerInstance)
       
   447         {
       
   448         mImageViewerInstance->Close();
       
   449         }
       
   450     }
       
   451 
       
   452 void GlxImageViewerService::complete(bool ok)
       
   453     {
       
   454     if (mAsyncReqId == -1)
       
   455         return;
       
   456     completeRequest(mAsyncReqId, QVariant(ok));
       
   457     }
       
   458 
       
   459 bool GlxImageViewerService::view(QString file)
       
   460     {
       
   461     XQApplicationManager appmgr;
       
   462     QFile tempfile(file);
       
   463     QVariantList attrValues;
       
   464 	QList<int> attrNames;
       
   465 	attrNames.append(XQApplicationManager::IsProtected);
       
   466     bool ok = appmgr.getDrmAttributes(tempfile, attrNames, attrValues);
       
   467     if(attrValues.at(0).toBool()){
       
   468 		HbNotificationDialog::launchDialog("NOT SUPPORTED");
       
   469         connect(this, SIGNAL(returnValueDelivered()), mServiceApp,
       
   470                 SLOT(handleAnswerDelivered()));
       
   471 		complete(true);
       
   472 		return false;
       
   473     }
       
   474 	
       
   475     XQRequestInfo info = requestInfo();
       
   476     mAsyncRequest = !info.isSynchronous();
       
   477     if (!mImageViewerInstance)
       
   478         {
       
   479         mImageViewerInstance = CGlxImageViewerManager::InstanceL();
       
   480         }
       
   481     QString filepath(QDir::toNativeSeparators(file));
       
   482     TPtrC16 str(reinterpret_cast<const TUint16*> (filepath.utf16()));
       
   483     HBufC* uri = str.Alloc();
       
   484 
       
   485     mImageViewerInstance->SetImageUriL(*uri);
       
   486     if (mAsyncRequest)
       
   487         {
       
   488         mAsyncReqId = setCurrentRequestAsync();
       
   489         }
       
   490 
       
   491     QString title = requestInfo().info("WindowTitle").toString();
       
   492     if(title.isNull()){
       
   493         title =GLX_IMAGE_VIEWER;
       
   494     }
       
   495     
       
   496     mServiceApp->launchImageViewer(title);
       
   497     return true;
       
   498     }
       
   499 
       
   500 bool GlxImageViewerService::view(XQSharableFile sf)
       
   501     {
       
   502     if (!mImageViewerInstance)
       
   503         {
       
   504         mImageViewerInstance = CGlxImageViewerManager::InstanceL();
       
   505         }
       
   506     RFile file;
       
   507     bool ok = sf.getHandle(file);
       
   508     if (ok)
       
   509         {
       
   510         mImageViewerInstance->SetImageFileHandleL(file);
       
   511         sf.close();
       
   512         }
       
   513 
       
   514     QString title = requestInfo().info("WindowTitle").toString();
       
   515     if(title.isNull()){
       
   516         title = GLX_IMAGE_VIEWER;
       
   517     }
       
   518     
       
   519     mServiceApp->launchImageViewer(title);
       
   520     mAsyncRequest = !XQServiceUtil::isEmbedded();
       
   521 
       
   522     if (mAsyncRequest)
       
   523         {
       
   524         mAsyncReqId = setCurrentRequestAsync();
       
   525         connect(this, SIGNAL(clientDisconnected()), this,
       
   526                 SLOT(handleClientDisconnect()));
       
   527         }
       
   528     return true;
       
   529     }
       
   530 
       
   531 
       
   532