main/glxaiwservicehandler.cpp
changeset 41 ae07d189b490
parent 26 c499df2dbb33
child 33 1ee2af37811f
equal deleted inserted replaced
40:112f0ac2d1f0 41:ae07d189b490
    22 #include <hbtoolbar.h>
    22 #include <hbtoolbar.h>
    23 #include <hbstyleloader.h>
    23 #include <hbstyleloader.h>
    24 
    24 
    25 #include <QtDebug>
    25 #include <QtDebug>
    26 #include <Qt>
    26 #include <Qt>
    27 #include <qstringlist.h>
    27 #include <QDir>
    28 #include <qmessagebox.h>
    28 #include <QStringList>
    29 
    29 
    30 #include <glxmediamodel.h>
    30 #include <glxmediamodel.h>
    31 #include <glxviewsfactory.h>
    31 #include <glxviewsfactory.h>
    32 #include <glxviewids.h>
    32 #include <glxviewids.h>
    33 #include <glxview.h>
    33 #include <glxview.h>
    39 #include <xqserviceutil.h>
    39 #include <xqserviceutil.h>
    40 #include <glxstatemanager.h>
    40 #include <glxstatemanager.h>
    41 #include <glximageviewermanager.h>
    41 #include <glximageviewermanager.h>
    42 #include <glxexternalutility.h>
    42 #include <glxexternalutility.h>
    43 #include "glxlocalisationstrings.h"
    43 #include "glxlocalisationstrings.h"
       
    44 #include <xqaiwdeclplat.h>
       
    45 
       
    46 #define IMAGE_FETCHER_SERVICE_NAME QLatin1String("photos.com.nokia.symbian.IImageFetch")
       
    47 #define IMAGE_FETCHER_SERVICE_DEPINTERFACE_NAME QLatin1String("photos.Image")
       
    48 #define IMAGE_FETCHER_DEPSERVICE_DEPINTERFACE_NAME QLatin1String("com.nokia.services.media.Image")
       
    49 #define FILE_VIEWER_SERVICE_NAME QLatin1String("photos.com.nokia.symbian.IFileView")
       
    50 
    44 
    51 
    45 // ----------------------------------------------------------------------------
    52 // ----------------------------------------------------------------------------
    46 // GlxAiwServiceHandler()
    53 // GlxAiwServiceHandler()
    47 // ----------------------------------------------------------------------------
    54 // ----------------------------------------------------------------------------
    48 //
    55 //
    49 GlxAiwServiceHandler::GlxAiwServiceHandler() :
    56 GlxAiwServiceHandler::GlxAiwServiceHandler() :
    50     HbMainWindow(), mModel(NULL), mView(NULL), mService(NULL),
    57     HbMainWindow(), 
    51             mStateMgr(NULL),mFSView(NULL),mFetcherContextMenu(NULL)
    58     mModel(NULL),
    52     {
    59     mView(NULL),
    53     mService = new GlxGetImageService(this);
    60     mStateMgr(NULL),
       
    61     mFSView(NULL),
       
    62     mFetcherContextMenu(NULL),
       
    63     mFetcherService(NULL),
       
    64     mNSDIService(NULL),
       
    65     mDSDIService(NULL),
       
    66     mImageViewerService(NULL)
       
    67     {
       
    68     mFetcherService = new GlxGetImageService(this);
       
    69     mNSDIService = new GlxGetImageServiceNSDI(this);
       
    70     mDSDIService = new GlxGetImageServiceDSDI(this);
       
    71     
    54     mImageViewerService = new GlxImageViewerService(this);
    72     mImageViewerService = new GlxImageViewerService(this);
    55 
    73 
    56 #ifdef _DEBUG
    74 #ifdef _DEBUG
    57 	QString t;
    75 	QString t;
    58 	QStringList args = QApplication::arguments();
    76 	QStringList args = QApplication::arguments();
    73     HbStyleLoader::unregisterFilePath(":/data/photos.css");
    91     HbStyleLoader::unregisterFilePath(":/data/photos.css");
    74     if (mView)
    92     if (mView)
    75         {
    93         {
    76         removeView(mView);
    94         removeView(mView);
    77         }
    95         }
       
    96     delete mStateMgr;
    78     delete mView;
    97     delete mView;
    79 	delete mFSView;
    98 	delete mFSView;
    80     delete mModel;
    99     delete mModel;
    81     delete mService;
   100     delete mFetcherService;
       
   101     delete mNSDIService;
       
   102     delete mDSDIService;
       
   103     delete mImageViewerService;
    82     }
   104     }
    83 
   105 
    84 void GlxAiwServiceHandler::handleClientDisconnect()
   106 void GlxAiwServiceHandler::handleClientDisconnect()
    85     {
   107     {
    86     // Just quit application
   108     // Just quit application
    92 // ----------------------------------------------------------------------------
   114 // ----------------------------------------------------------------------------
    93 //
   115 //
    94 void GlxAiwServiceHandler::itemSelected(const QModelIndex & index)
   116 void GlxAiwServiceHandler::itemSelected(const QModelIndex & index)
    95     {
   117     {
    96     qDebug() << "GlxFetcher::itemSelected";
   118     qDebug() << "GlxFetcher::itemSelected";
    97     if (mService->isActive())
   119     
    98         {
   120     if (mFetcherService->isActive())
    99         qDebug() << "GlxFetcher::itemSelected :: SERVICE ACTIVE";
   121         {
       
   122         qDebug() << "GlxFetcher::itemSelected mFetcherService->isActive()";
   100         QVariant variant = mModel->data(index, GlxUriRole);
   123         QVariant variant = mModel->data(index, GlxUriRole);
   101         if (variant.isValid())
   124         if (variant.isValid())
   102             {
   125             {
   103             QString itemPath = variant.value<QString> ();
   126             QString itemPath = variant.value<QString> ();
   104             qDebug() << "GlxFetcher::itemSelected :: VALID URI -->" << itemPath;
       
   105             QStringList list = (QStringList() << itemPath);
   127             QStringList list = (QStringList() << itemPath);
   106             mService->complete(list);
   128             mFetcherService->complete(list);
   107             }
   129             }
   108         }
   130         }
       
   131     
       
   132     if (mNSDIService->isActive())
       
   133         {
       
   134     qDebug() << "GlxFetcher::itemSelected mNSDIService->isActive()";
       
   135         QVariant variant = mModel->data(index, GlxUriRole);
       
   136         if (variant.isValid())
       
   137             {
       
   138             QString itemPath = variant.value<QString> ();
       
   139             QStringList list = (QStringList() << itemPath);
       
   140             mNSDIService->complete(list);
       
   141             }
       
   142         }
       
   143     
       
   144     if (mDSDIService->isActive())
       
   145         {
       
   146     qDebug() << "GlxFetcher::itemSelected mDSDIService->isActive()";
       
   147         QVariant variant = mModel->data(index, GlxUriRole);
       
   148         if (variant.isValid())
       
   149             {
       
   150             QString itemPath = variant.value<QString> ();
       
   151             QStringList list = (QStringList() << itemPath);
       
   152             mDSDIService->complete(list);
       
   153             }
       
   154         }
   109     }	
   155     }	
   110 
   156 
   111 
   157 
   112 
   158 
   113 void GlxAiwServiceHandler::launchFetcher()
   159 void GlxAiwServiceHandler::launchFetcher()
   114     {
   160     {
       
   161     qDebug() << "GlxAiwServiceHandler::launchFetcher START";
   115     HbStyleLoader::registerFilePath(":/data/photos.css");
   162     HbStyleLoader::registerFilePath(":/data/photos.css");
   116     GlxModelParm modelParm(KGlxCollectionPluginAllImplementationUid, 0);
   163     GlxModelParm modelParm(KGlxCollectionPluginAllImplementationUid, 0);
   117     mModel = new GlxMediaModel(modelParm);
   164     mModel = new GlxMediaModel(modelParm);
   118 
   165 
   119     if ( this->orientation() == Qt::Horizontal ) {
   166     if ( this->orientation() == Qt::Horizontal ) {
   131             SLOT( itemSelected(const QModelIndex &)));
   178             SLOT( itemSelected(const QModelIndex &)));
   132 			
   179 			
   133 	connect ( mView, SIGNAL(itemSpecificMenuTriggered(qint32,QPointF ) ),
   180 	connect ( mView, SIGNAL(itemSpecificMenuTriggered(qint32,QPointF ) ),
   134 			this, SLOT( itemSpecificMenuTriggered(qint32,QPointF ) ),
   181 			this, SLOT( itemSpecificMenuTriggered(qint32,QPointF ) ),
   135 			Qt::QueuedConnection );
   182 			Qt::QueuedConnection );
       
   183 	qDebug() << "GlxAiwServiceHandler::launchFetcher END";
   136     }
   184     }
   137 
   185 
   138 void GlxAiwServiceHandler::itemSpecificMenuTriggered(qint32 viewId,QPointF pos)
   186 void GlxAiwServiceHandler::itemSpecificMenuTriggered(qint32 viewId,QPointF pos)
   139 	{
   187 	{
   140     mFetcherContextMenu = new HbMenu();
   188     mFetcherContextMenu = new HbMenu();
   200 // ----------------------------------------------------------------------------
   248 // ----------------------------------------------------------------------------
   201 // GlxGetImageService()
   249 // GlxGetImageService()
   202 // ----------------------------------------------------------------------------
   250 // ----------------------------------------------------------------------------
   203 //
   251 //
   204 GlxGetImageService::GlxGetImageService(GlxAiwServiceHandler* parent) :
   252 GlxGetImageService::GlxGetImageService(GlxAiwServiceHandler* parent) :
   205             XQServiceProvider(
   253             XQServiceProvider(IMAGE_FETCHER_SERVICE_NAME, parent),
   206                     QLatin1String("com.nokia.services.media.Image"), parent),
       
   207             mServiceApp(parent)
   254             mServiceApp(parent)
   208     {
   255     {
   209     mImageRequestIndex = -1;
   256     mImageRequestIndex = -1;
   210     publishAll();
   257     publishAll();
   211     connect(this, SIGNAL(clientDisconnected()), mServiceApp,
   258     connect(this, SIGNAL(clientDisconnected()), mServiceApp,
   265 
   312 
   266 // ----------------------------------------------------------------------------
   313 // ----------------------------------------------------------------------------
   267 // fetch()
   314 // fetch()
   268 // ----------------------------------------------------------------------------
   315 // ----------------------------------------------------------------------------
   269 //
   316 //
   270 void GlxGetImageService::fetch(QVariantMap filter, QVariant flag)
   317 void GlxGetImageService::fetch()
       
   318     {
       
   319     mImageRequestIndex = setCurrentRequestAsync();
       
   320     mServiceApp->launchFetcher();
       
   321     }
       
   322 
       
   323 // ----------------------------------------------------------------------------
       
   324 // GlxGetImageService()
       
   325 // ----------------------------------------------------------------------------
       
   326 //
       
   327 GlxGetImageServiceNSDI::GlxGetImageServiceNSDI(GlxAiwServiceHandler* parent) :
       
   328             XQServiceProvider(IMAGE_FETCHER_SERVICE_DEPINTERFACE_NAME, parent),
       
   329             mServiceApp(parent)
       
   330     {
       
   331     mImageRequestIndex = -1;
       
   332     publishAll();
       
   333     connect(this, SIGNAL(clientDisconnected()), mServiceApp,
       
   334             SLOT(handleClientDisconnect()));
       
   335     }
       
   336 
       
   337 // ----------------------------------------------------------------------------
       
   338 // ~GlxGetImageService()
       
   339 // ----------------------------------------------------------------------------
       
   340 //
       
   341 GlxGetImageServiceNSDI::~GlxGetImageServiceNSDI()
       
   342     {
       
   343     }
       
   344 
       
   345 // ----------------------------------------------------------------------------
       
   346 // fetchFailed()
       
   347 // ----------------------------------------------------------------------------
       
   348 //
       
   349 void GlxGetImageServiceNSDI::fetchFailed(int errorCode)
       
   350     {
       
   351     QStringList filesList;
       
   352     filesList.insert(0, QString::number(errorCode));//result
       
   353     doComplete(filesList);
       
   354     }
       
   355 
       
   356 // ----------------------------------------------------------------------------
       
   357 // complete()
       
   358 // ----------------------------------------------------------------------------
       
   359 //
       
   360 void GlxGetImageServiceNSDI::complete(QStringList filesList)
       
   361     {
       
   362     doComplete(filesList);
       
   363     }
       
   364 
       
   365 // ----------------------------------------------------------------------------
       
   366 // doComplete()
       
   367 // ----------------------------------------------------------------------------
       
   368 //
       
   369 void GlxGetImageServiceNSDI::doComplete(QStringList filesList)
       
   370     {
       
   371     if (isActive())
       
   372         {
       
   373         completeRequest(mImageRequestIndex, filesList);
       
   374         mImageRequestIndex = -1;
       
   375         connect(this, SIGNAL(returnValueDelivered()), qApp, SLOT(quit()));
       
   376         }
       
   377     }
       
   378 
       
   379 // ----------------------------------------------------------------------------
       
   380 // isActive()
       
   381 // ----------------------------------------------------------------------------
       
   382 //
       
   383 bool GlxGetImageServiceNSDI::isActive()
       
   384     {
       
   385     return mImageRequestIndex > -1;
       
   386     }
       
   387 
       
   388 // ----------------------------------------------------------------------------
       
   389 // fetch()
       
   390 // ----------------------------------------------------------------------------
       
   391 //
       
   392 void GlxGetImageServiceNSDI::fetch(QVariantMap filter, QVariant flag)
       
   393     {
       
   394     qDebug() << "GlxGetImageServiceNSDI::fetch WITH PARAMETER START";
       
   395     Q_UNUSED(filter)
       
   396     Q_UNUSED(flag)
       
   397     fetch();
       
   398     qDebug() << "GlxGetImageServiceNSDI::fetch WITH PARAMETER END";
       
   399     }
       
   400 
       
   401 // ----------------------------------------------------------------------------
       
   402 // fetch()
       
   403 // ----------------------------------------------------------------------------
       
   404 //
       
   405 void GlxGetImageServiceNSDI::fetch()
       
   406     {
       
   407     qDebug() << "GlxGetImageServiceNSDI::fetch START";
       
   408     mImageRequestIndex = setCurrentRequestAsync();
       
   409     mServiceApp->launchFetcher();
       
   410     qDebug() << "GlxGetImageServiceNSDI::fetch END";
       
   411     }
       
   412 
       
   413 //==============================================================================//
       
   414 // ----------------------------------------------------------------------------
       
   415 // GlxGetImageService()
       
   416 // ----------------------------------------------------------------------------
       
   417 //
       
   418 GlxGetImageServiceDSDI::GlxGetImageServiceDSDI(GlxAiwServiceHandler* parent) :
       
   419             XQServiceProvider(IMAGE_FETCHER_DEPSERVICE_DEPINTERFACE_NAME, parent),
       
   420             mServiceApp(parent)
       
   421     {
       
   422     mImageRequestIndex = -1;
       
   423     publishAll();
       
   424     connect(this, SIGNAL(clientDisconnected()), mServiceApp,
       
   425             SLOT(handleClientDisconnect()));
       
   426     }
       
   427 
       
   428 // ----------------------------------------------------------------------------
       
   429 // ~GlxGetImageService()
       
   430 // ----------------------------------------------------------------------------
       
   431 //
       
   432 GlxGetImageServiceDSDI::~GlxGetImageServiceDSDI()
       
   433     {
       
   434     }
       
   435 
       
   436 // ----------------------------------------------------------------------------
       
   437 // fetchFailed()
       
   438 // ----------------------------------------------------------------------------
       
   439 //
       
   440 void GlxGetImageServiceDSDI::fetchFailed(int errorCode)
       
   441     {
       
   442     QStringList filesList;
       
   443     filesList.insert(0, QString::number(errorCode));//result
       
   444     doComplete(filesList);
       
   445     }
       
   446 
       
   447 // ----------------------------------------------------------------------------
       
   448 // complete()
       
   449 // ----------------------------------------------------------------------------
       
   450 //
       
   451 void GlxGetImageServiceDSDI::complete(QStringList filesList)
       
   452     {
       
   453     doComplete(filesList);
       
   454     }
       
   455 
       
   456 // ----------------------------------------------------------------------------
       
   457 // doComplete()
       
   458 // ----------------------------------------------------------------------------
       
   459 //
       
   460 void GlxGetImageServiceDSDI::doComplete(QStringList filesList)
       
   461     {
       
   462     if (isActive())
       
   463         {
       
   464         completeRequest(mImageRequestIndex, filesList);
       
   465         mImageRequestIndex = -1;
       
   466         connect(this, SIGNAL(returnValueDelivered()), qApp, SLOT(quit()));
       
   467         }
       
   468     }
       
   469 
       
   470 // ----------------------------------------------------------------------------
       
   471 // isActive()
       
   472 // ----------------------------------------------------------------------------
       
   473 //
       
   474 bool GlxGetImageServiceDSDI::isActive()
       
   475     {
       
   476     return mImageRequestIndex > -1;
       
   477     }
       
   478 
       
   479 // ----------------------------------------------------------------------------
       
   480 // fetch()
       
   481 // ----------------------------------------------------------------------------
       
   482 //
       
   483 void GlxGetImageServiceDSDI::fetch(QVariantMap filter, QVariant flag)
   271     {
   484     {
   272     Q_UNUSED(filter)
   485     Q_UNUSED(filter)
   273     Q_UNUSED(flag)
   486     Q_UNUSED(flag)
   274     mImageRequestIndex = setCurrentRequestAsync();
   487     mImageRequestIndex = setCurrentRequestAsync();
   275     mServiceApp->launchFetcher();
   488     mServiceApp->launchFetcher();
   276     }
   489     }
   277 
   490 
   278 // ----------GlxImageViewerService---------------
   491 // ----------GlxImageViewerService---------------
   279 
   492 
   280 GlxImageViewerService::GlxImageViewerService(GlxAiwServiceHandler* parent) :
   493 GlxImageViewerService::GlxImageViewerService(GlxAiwServiceHandler* parent) :
   281     XQServiceProvider(QLatin1String(
   494     XQServiceProvider(FILE_VIEWER_SERVICE_NAME, parent),
   282             "com.nokia.services.media.com.nokia.symbian.IFileView"), parent),
       
   283             mServiceApp(parent), mAsyncReqId(-1), mAsyncRequest(false),
   495             mServiceApp(parent), mAsyncReqId(-1), mAsyncRequest(false),
   284             mImageViewerInstance(NULL)
   496             mImageViewerInstance(NULL)
   285 
   497 
   286     {
   498     {
   287     publishAll();
   499     publishAll();
   310     mAsyncRequest = !info.isSynchronous();
   522     mAsyncRequest = !info.isSynchronous();
   311     if (!mImageViewerInstance)
   523     if (!mImageViewerInstance)
   312         {
   524         {
   313         mImageViewerInstance = CGlxImageViewerManager::InstanceL();
   525         mImageViewerInstance = CGlxImageViewerManager::InstanceL();
   314         }
   526         }
   315     file.replace(QString("/"), QString("\\"));
   527     QString filepath(QDir::toNativeSeparators(file.at(0)));
   316     TPtrC16 str(reinterpret_cast<const TUint16*> (file.utf16()));
   528     TPtrC16 str(reinterpret_cast<const TUint16*> (filepath.utf16()));
   317     HBufC* uri = str.Alloc();
   529     HBufC* uri = str.Alloc();
   318 
   530 
   319     mImageViewerInstance->SetImageUriL(*uri);
   531     mImageViewerInstance->SetImageUriL(*uri);
   320     if (mAsyncRequest)
   532     if (mAsyncRequest)
   321         {
   533         {