main/glxaiwservicehandler.cpp
changeset 54 0f0f3f26f787
parent 50 a0f57508af73
child 65 ccee5c4b0de4
equal deleted inserted replaced
52:a3a4c0de738e 54:0f0f3f26f787
    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 	mView->deActivate();
       
   242     mFSView->activate();
       
   243     mFSView->setModel(mModel);
       
   244     addView(mFSView);
       
   245     setCurrentView(mFSView,false);
       
   246 	}
       
   247 
       
   248 
       
   249 void GlxAiwServiceHandler::handleFSSelect()
       
   250 	{
       
   251 	QModelIndex selectedIndex = mModel->index(mModel->data(mModel->index(0,0),GlxFocusIndexRole).value<int>(),0);
       
   252 	itemSelected(selectedIndex);
       
   253     }
       
   254 
       
   255 void GlxAiwServiceHandler::launchImageViewer()
       
   256     {
       
   257     qApp->setApplicationName("Image Viewer");
       
   258     GlxExternalUtility* util = GlxExternalUtility::instance();
       
   259     util->setMainWindow(this);
       
   260     delete mStateMgr;
       
   261     mStateMgr = NULL;
       
   262     mStateMgr = new GlxStateManager();
   174     mStateMgr = new GlxStateManager();
   263     mStateMgr->launchFromExternal();
   175     mStateMgr->launchFromExternal();
   264     if (mImageViewerService && mImageViewerService->asyncRequest())
   176     if (mImageViewerService && mImageViewerService->asyncRequest())
   265         {
   177         {
   266         connect(mImageViewerService, SIGNAL(returnValueDelivered()), this,
   178         connect(mImageViewerService, SIGNAL(returnValueDelivered()), this,
   287 // ~GlxGetImageService()
   199 // ~GlxGetImageService()
   288 // ----------------------------------------------------------------------------
   200 // ----------------------------------------------------------------------------
   289 //
   201 //
   290 GlxGetImageService::~GlxGetImageService()
   202 GlxGetImageService::~GlxGetImageService()
   291     {
   203     {
       
   204     qDebug() << "GlxGetImageService::~GlxGetImageService()";
   292     }
   205     }
   293 
   206 
   294 // ----------------------------------------------------------------------------
   207 // ----------------------------------------------------------------------------
   295 // fetchFailed()
   208 // fetchFailed()
   296 // ----------------------------------------------------------------------------
   209 // ----------------------------------------------------------------------------
   339 // ----------------------------------------------------------------------------
   252 // ----------------------------------------------------------------------------
   340 //
   253 //
   341 void GlxGetImageService::fetch()
   254 void GlxGetImageService::fetch()
   342     {
   255     {
   343     mImageRequestIndex = setCurrentRequestAsync();
   256     mImageRequestIndex = setCurrentRequestAsync();
   344     QString title = requestInfo().info("WindowTitle").toString();
   257     QString title =  GLX_TITLE;
   345     if(title.isNull()){
       
   346         title = QString("Image Fetcher");
       
   347     }
       
   348     mServiceApp->launchFetcher(title);
   258     mServiceApp->launchFetcher(title);
   349     }
   259     }
   350 
   260 
   351 // ----------------------------------------------------------------------------
   261 // ----------------------------------------------------------------------------
   352 // GlxGetImageService()
   262 // GlxGetImageService()
   432 //
   342 //
   433 void GlxGetImageServiceNSDI::fetch()
   343 void GlxGetImageServiceNSDI::fetch()
   434     {
   344     {
   435     qDebug() << "GlxGetImageServiceNSDI::fetch START";
   345     qDebug() << "GlxGetImageServiceNSDI::fetch START";
   436     mImageRequestIndex = setCurrentRequestAsync();
   346     mImageRequestIndex = setCurrentRequestAsync();
   437     QString title = requestInfo().info("WindowTitle").toString();
   347     QString title = GLX_TITLE;
   438     if(title.isNull()){
       
   439         title = QString("Image Fetcher");
       
   440     }
       
   441     mServiceApp->launchFetcher(title);
   348     mServiceApp->launchFetcher(title);
   442     qDebug() << "GlxGetImageServiceNSDI::fetch END";
   349     qDebug() << "GlxGetImageServiceNSDI::fetch END";
   443     }
   350     }
   444 
   351 
   445 //==============================================================================//
   352 //==============================================================================//
   515 void GlxGetImageServiceDSDI::fetch(QVariantMap filter, QVariant flag)
   422 void GlxGetImageServiceDSDI::fetch(QVariantMap filter, QVariant flag)
   516     {
   423     {
   517     Q_UNUSED(filter)
   424     Q_UNUSED(filter)
   518     Q_UNUSED(flag)
   425     Q_UNUSED(flag)
   519     mImageRequestIndex = setCurrentRequestAsync();
   426     mImageRequestIndex = setCurrentRequestAsync();
   520     QString title = requestInfo().info("WindowTitle").toString();
   427     QString title  = GLX_TITLE;    
   521     if(title.isNull()){
       
   522         title = QString("Image Fetcher");
       
   523     }
       
   524     mServiceApp->launchFetcher(title);
   428     mServiceApp->launchFetcher(title);
   525     }
   429     }
   526 
   430 
   527 // ----------GlxImageViewerService---------------
   431 // ----------GlxImageViewerService---------------
   528 
   432 
   581     mImageViewerInstance->SetImageUriL(*uri);
   485     mImageViewerInstance->SetImageUriL(*uri);
   582     if (mAsyncRequest)
   486     if (mAsyncRequest)
   583         {
   487         {
   584         mAsyncReqId = setCurrentRequestAsync();
   488         mAsyncReqId = setCurrentRequestAsync();
   585         }
   489         }
   586     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);
   587     return true;
   497     return true;
   588     }
   498     }
   589 
   499 
   590 bool GlxImageViewerService::view(XQSharableFile sf)
   500 bool GlxImageViewerService::view(XQSharableFile sf)
   591     {
   501     {
   598     if (ok)
   508     if (ok)
   599         {
   509         {
   600         mImageViewerInstance->SetImageFileHandleL(file);
   510         mImageViewerInstance->SetImageFileHandleL(file);
   601         sf.close();
   511         sf.close();
   602         }
   512         }
   603     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);
   604     mAsyncRequest = !XQServiceUtil::isEmbedded();
   520     mAsyncRequest = !XQServiceUtil::isEmbedded();
   605 
   521 
   606     if (mAsyncRequest)
   522     if (mAsyncRequest)
   607         {
   523         {
   608         mAsyncReqId = setCurrentRequestAsync();
   524         mAsyncReqId = setCurrentRequestAsync();