main/glxfetcher.cpp
changeset 26 c499df2dbb33
parent 24 99ad1390cd33
child 27 0d818da5a659
child 29 2c833fc9e98f
child 40 112f0ac2d1f0
equal deleted inserted replaced
24:99ad1390cd33 26:c499df2dbb33
     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 
       
    21 #include <QtDebug>
       
    22 #include <Qt>
       
    23 #include <qstringlist.h>
       
    24 #include <qmessagebox.h>
       
    25 
       
    26 #include <glxmediamodel.h>
       
    27 #include <glxviewsfactory.h>
       
    28 #include <glxviewids.h>
       
    29 #include <glxview.h>
       
    30 #include <glxgridview.h>
       
    31 #include <glxmodelparm.h>
       
    32 #include <glxfetcher.h>
       
    33 #include <glxcollectionpluginall.hrh>
       
    34 
       
    35 #include <xqserviceutil.h>
       
    36 
       
    37 // ----------------------------------------------------------------------------
       
    38 // GlxFetcher()
       
    39 // ----------------------------------------------------------------------------
       
    40 //
       
    41 GlxFetcher::GlxFetcher():HbMainWindow() ,mModel(NULL),mView(NULL),mService(NULL)
       
    42 {
       
    43     mService = new GlxGetImageService( this);
       
    44 
       
    45 #ifdef _DEBUG
       
    46 	QString t;
       
    47 	QStringList args = QApplication::arguments();
       
    48     foreach (QString arg, args)
       
    49     {
       
    50 	t += "GlxFetcher::cmdline arg=" + arg + "\n";
       
    51     }
       
    52 	qDebug()<< t;
       
    53 #endif
       
    54 }
       
    55 
       
    56 // ----------------------------------------------------------------------------
       
    57 // ~GlxFetcher()
       
    58 // ----------------------------------------------------------------------------
       
    59 //
       
    60 GlxFetcher::~GlxFetcher()
       
    61 {
       
    62     if(mView){
       
    63         removeView(mView);
       
    64     }
       
    65     delete mView;
       
    66     delete mModel;
       
    67     delete mService;
       
    68 }
       
    69 
       
    70 // ----------------------------------------------------------------------------
       
    71 // itemSelected()
       
    72 // ----------------------------------------------------------------------------
       
    73 //
       
    74 void GlxFetcher::itemSelected(const QModelIndex &  index)
       
    75 {
       
    76     qDebug()<< "GlxFetcher::itemSelected" ;
       
    77     if ( mService->isActive() ){
       
    78         qDebug()<< "GlxFetcher::itemSelected :: SERVICE ACTIVE" ;
       
    79         QVariant variant = mModel->data( index, GlxUriRole );
       
    80         if ( variant.isValid()  ) {
       
    81             QString itemPath = variant.value<QString>();
       
    82             qDebug()<< "GlxFetcher::itemSelected :: VALID URI -->" << itemPath;
       
    83             QStringList list = (QStringList() << itemPath );
       
    84             mService->complete( list );
       
    85         }
       
    86     }
       
    87 }	
       
    88 
       
    89 void GlxFetcher::launchFetcher()
       
    90 {
       
    91     GlxModelParm modelParm (KGlxCollectionPluginAllImplementationUid, 0);
       
    92     mModel = new GlxMediaModel (modelParm);
       
    93 
       
    94     mView = GlxViewsFactory::createView(GLX_GRIDVIEW_ID, this);
       
    95     mView->activate();
       
    96     mView->setModel(mModel);
       
    97     addView(mView);
       
    98     connect(mView, SIGNAL(gridItemSelected(const QModelIndex &)), this, SLOT( itemSelected(const QModelIndex &)));
       
    99 
       
   100 }
       
   101 // ----------------------------------------------------------------------------
       
   102 // GlxGetImageService()
       
   103 // ----------------------------------------------------------------------------
       
   104 //
       
   105 GlxGetImageService::GlxGetImageService(GlxFetcher* parent)
       
   106 : XQServiceProvider(QLatin1String("com.nokia.services.media.Image"),parent),mServiceApp(parent)
       
   107 {
       
   108     mImageRequestIndex=-1;
       
   109     publishAll();
       
   110 }
       
   111 
       
   112 // ----------------------------------------------------------------------------
       
   113 // ~GlxGetImageService()
       
   114 // ----------------------------------------------------------------------------
       
   115 //
       
   116 GlxGetImageService::~GlxGetImageService()
       
   117 {
       
   118 }
       
   119 
       
   120 // ----------------------------------------------------------------------------
       
   121 // fetchFailed()
       
   122 // ----------------------------------------------------------------------------
       
   123 //
       
   124 void GlxGetImageService::fetchFailed( int errorCode )
       
   125 {
       
   126     QStringList filesList;
       
   127     filesList.insert(0, QString::number( errorCode ));//result
       
   128     doComplete(filesList);
       
   129 }
       
   130 
       
   131 // ----------------------------------------------------------------------------
       
   132 // complete()
       
   133 // ----------------------------------------------------------------------------
       
   134 //
       
   135 void GlxGetImageService::complete( QStringList filesList )
       
   136 {
       
   137     doComplete(filesList);
       
   138 }
       
   139     
       
   140 // ----------------------------------------------------------------------------
       
   141 // doComplete()
       
   142 // ----------------------------------------------------------------------------
       
   143 //
       
   144 void GlxGetImageService::doComplete( QStringList filesList)
       
   145 {
       
   146     if ( isActive() ){
       
   147         completeRequest(mImageRequestIndex, filesList);
       
   148         mImageRequestIndex=-1;
       
   149         connect(this, SIGNAL(returnValueDelivered()), qApp, SLOT(quit()));
       
   150         }
       
   151 }
       
   152 
       
   153 // ----------------------------------------------------------------------------
       
   154 // isActive()
       
   155 // ----------------------------------------------------------------------------
       
   156 //
       
   157 bool GlxGetImageService::isActive()
       
   158 {
       
   159     return mImageRequestIndex> -1;
       
   160 }
       
   161 
       
   162 // ----------------------------------------------------------------------------
       
   163 // fetch()
       
   164 // ----------------------------------------------------------------------------
       
   165 //
       
   166 void GlxGetImageService::fetch( QVariantMap filter, QVariant flag)
       
   167 {
       
   168     Q_UNUSED(filter)
       
   169     Q_UNUSED(flag)
       
   170 	mImageRequestIndex  = setCurrentRequestAsync();
       
   171 	mServiceApp->launchFetcher();
       
   172     }