main/glxaiwservicehandler.cpp
changeset 55 fb37077c270f
parent 49 f291796e213d
child 70 a91aa46552be
equal deleted inserted replaced
49:f291796e213d 55:fb37077c270f
    17 
    17 
    18 #include <hbapplication.h>
    18 #include <hbapplication.h>
    19 #include <hbview.h>
    19 #include <hbview.h>
    20 #include <hbmenu.h>
    20 #include <hbmenu.h>
    21 #include <hbaction.h>
    21 #include <hbaction.h>
    22 #include <hbtoolbar.h>
       
    23 #include <hbstyleloader.h>
       
    24 #include <hbnotificationdialog.h>
    22 #include <hbnotificationdialog.h>
    25 
    23 
    26 #include <QtDebug>
    24 #include <QtDebug>
    27 #include <Qt>
    25 #include <Qt>
    28 #include <QDir>
    26 #include <QDir>
    29 #include <QStringList>
    27 #include <QStringList>
    30 
    28 
    31 #include <glxmediamodel.h>
    29 #include <xqserviceutil.h>
    32 #include <glxviewsfactory.h>
    30 #include <xqaiwdeclplat.h>
    33 #include <glxviewids.h>
    31 #include <xqappmgr.h>
    34 #include <glxview.h>
    32 
    35 #include <glxgridview.h>
    33 #include <glxmodelroles.h>
    36 #include <glxmodelparm.h>
       
    37 #include <glxaiwservicehandler.h>
    34 #include <glxaiwservicehandler.h>
    38 #include <glxcollectionpluginall.hrh>
       
    39 #include <glxcollectionpluginimageviewer.hrh>
       
    40 #include <xqserviceutil.h>
       
    41 #include <glxstatemanager.h>
    35 #include <glxstatemanager.h>
    42 #include <glximageviewermanager.h>
    36 #include <glximageviewermanager.h>
    43 #include <glxexternalutility.h>
    37 #include <glxexternalutility.h>
    44 #include "glxlocalisationstrings.h"
    38 #include "glxlocalisationstrings.h"
    45 #include <xqaiwdeclplat.h>
       
    46 #include <xqappmgr.h>
       
    47 
    39 
    48 #define IMAGE_FETCHER_SERVICE_NAME QLatin1String("photos.com.nokia.symbian.IImageFetch")
    40 #define IMAGE_FETCHER_SERVICE_NAME QLatin1String("photos.com.nokia.symbian.IImageFetch")
    49 #define IMAGE_FETCHER_SERVICE_DEPINTERFACE_NAME QLatin1String("photos.Image")
    41 #define IMAGE_FETCHER_SERVICE_DEPINTERFACE_NAME QLatin1String("photos.Image")
    50 #define IMAGE_FETCHER_DEPSERVICE_DEPINTERFACE_NAME QLatin1String("com.nokia.services.media.Image")
    42 #define IMAGE_FETCHER_DEPSERVICE_DEPINTERFACE_NAME QLatin1String("com.nokia.services.media.Image")
    51 #define FILE_VIEWER_SERVICE_NAME QLatin1String("photos.com.nokia.symbian.IFileView")
    43 #define FILE_VIEWER_SERVICE_NAME QLatin1String("photos.com.nokia.symbian.IFileView")
    55 // GlxAiwServiceHandler()
    47 // GlxAiwServiceHandler()
    56 // ----------------------------------------------------------------------------
    48 // ----------------------------------------------------------------------------
    57 //
    49 //
    58 GlxAiwServiceHandler::GlxAiwServiceHandler() :
    50 GlxAiwServiceHandler::GlxAiwServiceHandler() :
    59     HbMainWindow(), 
    51     HbMainWindow(), 
    60     mModel(NULL),
       
    61     mView(NULL),
       
    62     mStateMgr(NULL),
    52     mStateMgr(NULL),
    63     mFSView(NULL),
       
    64     mFetcherContextMenu(NULL),
       
    65     mFetcherService(NULL),
    53     mFetcherService(NULL),
    66     mNSDIService(NULL),
    54     mNSDIService(NULL),
    67     mDSDIService(NULL),
    55     mDSDIService(NULL),
    68     mImageViewerService(NULL)
    56     mImageViewerService(NULL)
    69     {
    57     {
    99 // ~GlxAiwServiceHandler()
    87 // ~GlxAiwServiceHandler()
   100 // ----------------------------------------------------------------------------
    88 // ----------------------------------------------------------------------------
   101 //
    89 //
   102 GlxAiwServiceHandler::~GlxAiwServiceHandler()
    90 GlxAiwServiceHandler::~GlxAiwServiceHandler()
   103     {
    91     {
   104     HbStyleLoader::unregisterFilePath(":/data/photos.css");
       
   105     if (mView)
       
   106         {
       
   107         removeView(mView);
       
   108         }
       
   109     delete mStateMgr;
    92     delete mStateMgr;
   110     delete mView;
       
   111 	delete mFSView;
       
   112     delete mModel;
       
   113     delete mFetcherService;
    93     delete mFetcherService;
   114     delete mNSDIService;
    94     delete mNSDIService;
   115     delete mDSDIService;
    95     delete mDSDIService;
   116     delete mImageViewerService;
    96     delete mImageViewerService;
   117     }
    97     }
   124 
   104 
   125 // ----------------------------------------------------------------------------
   105 // ----------------------------------------------------------------------------
   126 // itemSelected()
   106 // itemSelected()
   127 // ----------------------------------------------------------------------------
   107 // ----------------------------------------------------------------------------
   128 //
   108 //
   129 void GlxAiwServiceHandler::itemSelected(const QModelIndex & index)
   109 void GlxAiwServiceHandler::itemSelected(const QModelIndex & index,QAbstractItemModel & model)
   130     {
   110     {
   131     qDebug() << "GlxFetcher::itemSelected";
   111     qDebug() << "GlxFetcher::itemSelected";
   132     
       
   133     if (mFetcherService && mFetcherService->isActive())
   112     if (mFetcherService && mFetcherService->isActive())
   134         {
   113         {
   135         qDebug() << "GlxFetcher::itemSelected mFetcherService->isActive()";
   114         qDebug() << "GlxFetcher::itemSelected mFetcherService->isActive()";
   136         QVariant variant = mModel->data(index, GlxUriRole);
   115         QVariant variant = model.data(index, GlxUriRole);
   137         if (variant.isValid())
   116         if (variant.isValid())
   138             {
   117             {
   139             QString itemPath = variant.value<QString> ();
   118             QString itemPath = variant.value<QString> ();
       
   119             qDebug() << "GlxFetcher::itemSelected mFetcherService->isActive()::PATH = " << itemPath;
   140             QStringList list = (QStringList() << itemPath);
   120             QStringList list = (QStringList() << itemPath);
   141             mFetcherService->complete(list);
   121             mFetcherService->complete(list);
   142             }
   122             }
   143         }
   123         }
   144     
   124     
   145     else if (mNSDIService && mNSDIService->isActive())
   125     else if (mNSDIService && mNSDIService->isActive())
   146         {
   126         {
   147     qDebug() << "GlxFetcher::itemSelected mNSDIService->isActive()";
   127     qDebug() << "GlxFetcher::itemSelected mNSDIService->isActive()";
   148         QVariant variant = mModel->data(index, GlxUriRole);
   128         QVariant variant = model.data(index, GlxUriRole);
   149         if (variant.isValid())
   129         if (variant.isValid())
   150             {
   130             {
   151             QString itemPath = variant.value<QString> ();
   131             QString itemPath = variant.value<QString> ();
   152             QStringList list = (QStringList() << itemPath);
   132             QStringList list = (QStringList() << itemPath);
   153             mNSDIService->complete(list);
   133             mNSDIService->complete(list);
   155         }
   135         }
   156     
   136     
   157     else if (mDSDIService && mDSDIService->isActive())
   137     else if (mDSDIService && mDSDIService->isActive())
   158         {
   138         {
   159     qDebug() << "GlxFetcher::itemSelected mDSDIService->isActive()";
   139     qDebug() << "GlxFetcher::itemSelected mDSDIService->isActive()";
   160         QVariant variant = mModel->data(index, GlxUriRole);
   140         QVariant variant = model.data(index, GlxUriRole);
   161         if (variant.isValid())
   141         if (variant.isValid())
   162             {
   142             {
   163             QString itemPath = variant.value<QString> ();
   143             QString itemPath = variant.value<QString> ();
   164             QStringList list = (QStringList() << itemPath);
   144             QStringList list = (QStringList() << itemPath);
   165             mDSDIService->complete(list);
   145             mDSDIService->complete(list);
   166             }
   146             }
   167         }
   147         }
   168     }	
   148     }	
   169 
   149 
   170 
   150 
   171 
       
   172 void GlxAiwServiceHandler::launchFetcher(QString viewTitle)
   151 void GlxAiwServiceHandler::launchFetcher(QString viewTitle)
   173     {
   152     {
   174     qDebug() << "GlxAiwServiceHandler::launchFetcher START";
   153     qDebug() << "GlxAiwServiceHandler::launchFetcher START";
   175     qApp->setApplicationName(viewTitle);
   154     qApp->setApplicationName(viewTitle);
   176     HbStyleLoader::registerFilePath(":/data/photos.css");
   155 
   177     GlxModelParm modelParm(KGlxCollectionPluginAllImplementationUid, 0);
   156     mUtil = GlxExternalUtility::instance();
   178     mModel = new GlxMediaModel(modelParm);
   157     mUtil->setMainWindow(this);
   179 
   158 
   180     if ( this->orientation() == Qt::Horizontal ) {
   159     mStateMgr = new GlxStateManager();
   181         mModel->setData(QModelIndex(), (int)GlxContextLsGrid, GlxContextRole );
   160 	int err = connect(mStateMgr, SIGNAL(gridItemSelected(const QModelIndex &,QAbstractItemModel &)), this,
   182     }
   161             SLOT( itemSelected(const QModelIndex &,QAbstractItemModel &)));
   183     else {
   162 	qDebug() << "GlxAiwServiceHandler::launchFetcher err = "<< err;
   184         mModel->setData(QModelIndex(), (int)GlxContextPtGrid, GlxContextRole );
       
   185     }    
       
   186 
       
   187     mView = GlxViewsFactory::createView(GLX_GRIDVIEW_ID, this);
       
   188     mView->activate();
       
   189     mView->setModel(mModel);
       
   190     addView(mView);
       
   191     connect(mView, SIGNAL(gridItemSelected(const QModelIndex &)), this,
       
   192             SLOT( itemSelected(const QModelIndex &)));
       
   193 			
       
   194 	connect ( mView, SIGNAL(itemSpecificMenuTriggered(qint32,QPointF ) ),
       
   195 			this, SLOT( itemSpecificMenuTriggered(qint32,QPointF ) ),
       
   196 			Qt::QueuedConnection );
       
   197 	qDebug() << "GlxAiwServiceHandler::launchFetcher END";
       
   198     }
       
   199 
       
   200 void GlxAiwServiceHandler::itemSpecificMenuTriggered(qint32 viewId,QPointF pos)
       
   201 {
       
   202     mFetcherContextMenu = new HbMenu();
       
   203 	HbAction *action = mFetcherContextMenu->addAction(GLX_MENU_OPEN);
       
   204 	action->setObjectName( "Menu Open" );
       
   205 	connect(action, SIGNAL(triggered()), this, SLOT(openFSView()));
       
   206 	connect(this, SIGNAL(aboutToChangeOrientation ()), mFetcherContextMenu, SLOT(close()));
       
   207 	connect( mFetcherContextMenu, SIGNAL( aboutToClose () ), this, SLOT( closeContextMenu() ) );
       
   208 	mFetcherContextMenu->setPreferredPos( pos );
       
   209 	mFetcherContextMenu->show();
       
   210 }
       
   211 
       
   212 void GlxAiwServiceHandler::closeContextMenu()
       
   213     {
       
   214     disconnect( this, SIGNAL( aboutToChangeOrientation () ), mFetcherContextMenu, SLOT( close() ) );
       
   215     disconnect( mFetcherContextMenu, SIGNAL( aboutToClose () ), this, SLOT( closeContextMenu() ) ); 
       
   216     mFetcherContextMenu->deleteLater();
       
   217     mFetcherContextMenu = NULL;
       
   218     }
       
   219 	
   163 	
   220 void GlxAiwServiceHandler::openFSView()
   164     mStateMgr->launchFetcher();
   221 	{
   165     return;
   222     if ( this->orientation() == Qt::Horizontal ) {
   166     }
   223         mModel->setData(QModelIndex(), (int)GlxContextLsFs, GlxContextRole );
   167 
   224     }
   168 void GlxAiwServiceHandler::launchImageViewer(QString viewTitle)
   225     else {
   169     {
   226         mModel->setData(QModelIndex(), (int)GlxContextPtFs, GlxContextRole );
   170     qApp->setApplicationName(viewTitle);
   227     }    
   171     mUtil = GlxExternalUtility::instance();
   228     HbAction* selectAction = new HbAction(GLX_BUTTON_SELECT);
   172     mUtil->setMainWindow(this);
   229     selectAction->setObjectName( "FS Select" );
   173 
   230     
       
   231 	connect(selectAction, SIGNAL(triggered()), this, SLOT(handleFSSelect()));
       
   232     HbToolBar* toolBar = new HbToolBar();
       
   233     toolBar->setOrientation( Qt::Horizontal );
       
   234     toolBar->setVisible(true);
       
   235 	toolBar->addAction(selectAction);
       
   236 	
       
   237 	mModel->setData( QModelIndex(), FETCHER_S, GlxSubStateRole );
       
   238     mFSView = GlxViewsFactory::createView(GLX_FULLSCREENVIEW_ID, this);
       
   239     //ownership transfered to view
       
   240 	mFSView->setToolBar(toolBar);
       
   241     mFSView->activate();
       
   242     mFSView->setModel(mModel);
       
   243     addView(mFSView);
       
   244     setCurrentView(mFSView,false);
       
   245 	}
       
   246 
       
   247 
       
   248 void GlxAiwServiceHandler::handleFSSelect()
       
   249 	{
       
   250 	QModelIndex selectedIndex = mModel->index(mModel->data(mModel->index(0,0),GlxFocusIndexRole).value<int>(),0);
       
   251 	itemSelected(selectedIndex);
       
   252     }
       
   253 
       
   254 void GlxAiwServiceHandler::launchImageViewer()
       
   255     {
       
   256     qApp->setApplicationName("Image Viewer");
       
   257     GlxExternalUtility* util = GlxExternalUtility::instance();
       
   258     util->setMainWindow(this);
       
   259     delete mStateMgr;
       
   260     mStateMgr = NULL;
       
   261     mStateMgr = new GlxStateManager();
   174     mStateMgr = new GlxStateManager();
   262     mStateMgr->launchFromExternal();
   175     mStateMgr->launchFromExternal();
   263     if (mImageViewerService && mImageViewerService->asyncRequest())
   176     if (mImageViewerService && mImageViewerService->asyncRequest())
   264         {
   177         {
   265         connect(mImageViewerService, SIGNAL(returnValueDelivered()), this,
   178         connect(mImageViewerService, SIGNAL(returnValueDelivered()), this,
   286 // ~GlxGetImageService()
   199 // ~GlxGetImageService()
   287 // ----------------------------------------------------------------------------
   200 // ----------------------------------------------------------------------------
   288 //
   201 //
   289 GlxGetImageService::~GlxGetImageService()
   202 GlxGetImageService::~GlxGetImageService()
   290     {
   203     {
       
   204     qDebug() << "GlxGetImageService::~GlxGetImageService()";
   291     }
   205     }
   292 
   206 
   293 // ----------------------------------------------------------------------------
   207 // ----------------------------------------------------------------------------
   294 // fetchFailed()
   208 // fetchFailed()
   295 // ----------------------------------------------------------------------------
   209 // ----------------------------------------------------------------------------
   338 // ----------------------------------------------------------------------------
   252 // ----------------------------------------------------------------------------
   339 //
   253 //
   340 void GlxGetImageService::fetch()
   254 void GlxGetImageService::fetch()
   341     {
   255     {
   342     mImageRequestIndex = setCurrentRequestAsync();
   256     mImageRequestIndex = setCurrentRequestAsync();
   343     QString title = requestInfo().info("WindowTitle").toString();
   257     QString title =  GLX_TITLE;
   344     if(title.isNull()){
       
   345         title = QString("Image Fetcher");
       
   346     }
       
   347     mServiceApp->launchFetcher(title);
   258     mServiceApp->launchFetcher(title);
   348     }
   259     }
   349 
   260 
   350 // ----------------------------------------------------------------------------
   261 // ----------------------------------------------------------------------------
   351 // GlxGetImageService()
   262 // GlxGetImageService()
   431 //
   342 //
   432 void GlxGetImageServiceNSDI::fetch()
   343 void GlxGetImageServiceNSDI::fetch()
   433     {
   344     {
   434     qDebug() << "GlxGetImageServiceNSDI::fetch START";
   345     qDebug() << "GlxGetImageServiceNSDI::fetch START";
   435     mImageRequestIndex = setCurrentRequestAsync();
   346     mImageRequestIndex = setCurrentRequestAsync();
   436     QString title = requestInfo().info("WindowTitle").toString();
   347     QString title = GLX_TITLE;
   437     if(title.isNull()){
       
   438         title = QString("Image Fetcher");
       
   439     }
       
   440     mServiceApp->launchFetcher(title);
   348     mServiceApp->launchFetcher(title);
   441     qDebug() << "GlxGetImageServiceNSDI::fetch END";
   349     qDebug() << "GlxGetImageServiceNSDI::fetch END";
   442     }
   350     }
   443 
   351 
   444 //==============================================================================//
   352 //==============================================================================//
   514 void GlxGetImageServiceDSDI::fetch(QVariantMap filter, QVariant flag)
   422 void GlxGetImageServiceDSDI::fetch(QVariantMap filter, QVariant flag)
   515     {
   423     {
   516     Q_UNUSED(filter)
   424     Q_UNUSED(filter)
   517     Q_UNUSED(flag)
   425     Q_UNUSED(flag)
   518     mImageRequestIndex = setCurrentRequestAsync();
   426     mImageRequestIndex = setCurrentRequestAsync();
   519     QString title = requestInfo().info("WindowTitle").toString();
   427     QString title  = GLX_TITLE;    
   520     if(title.isNull()){
       
   521         title = QString("Image Fetcher");
       
   522     }
       
   523     mServiceApp->launchFetcher(title);
   428     mServiceApp->launchFetcher(title);
   524     }
   429     }
   525 
   430 
   526 // ----------GlxImageViewerService---------------
   431 // ----------GlxImageViewerService---------------
   527 
   432 
   580     mImageViewerInstance->SetImageUriL(*uri);
   485     mImageViewerInstance->SetImageUriL(*uri);
   581     if (mAsyncRequest)
   486     if (mAsyncRequest)
   582         {
   487         {
   583         mAsyncReqId = setCurrentRequestAsync();
   488         mAsyncReqId = setCurrentRequestAsync();
   584         }
   489         }
   585     mServiceApp->launchImageViewer();
   490 
       
   491     QString title = requestInfo().info("WindowTitle").toString();
       
   492     if(title.isNull()){
       
   493         title =GLX_IMAGE_VIEWER;
       
   494     }
       
   495     
       
   496     mServiceApp->launchImageViewer(title);
   586     return true;
   497     return true;
   587     }
   498     }
   588 
   499 
   589 bool GlxImageViewerService::view(XQSharableFile sf)
   500 bool GlxImageViewerService::view(XQSharableFile sf)
   590     {
   501     {
   597     if (ok)
   508     if (ok)
   598         {
   509         {
   599         mImageViewerInstance->SetImageFileHandleL(file);
   510         mImageViewerInstance->SetImageFileHandleL(file);
   600         sf.close();
   511         sf.close();
   601         }
   512         }
   602     mServiceApp->launchImageViewer();
   513 
       
   514     QString title = requestInfo().info("WindowTitle").toString();
       
   515     if(title.isNull()){
       
   516         title = GLX_IMAGE_VIEWER;
       
   517     }
       
   518     
       
   519     mServiceApp->launchImageViewer(title);
   603     mAsyncRequest = !XQServiceUtil::isEmbedded();
   520     mAsyncRequest = !XQServiceUtil::isEmbedded();
   604 
   521 
   605     if (mAsyncRequest)
   522     if (mAsyncRequest)
   606         {
   523         {
   607         mAsyncReqId = setCurrentRequestAsync();
   524         mAsyncReqId = setCurrentRequestAsync();