controlpanelui/src/cpringtoneview/src/cpringtoneview.cpp
changeset 40 593f946f4fec
parent 22 a5692c68d772
--- a/controlpanelui/src/cpringtoneview/src/cpringtoneview.cpp	Fri Jun 25 17:12:20 2010 +0800
+++ b/controlpanelui/src/cpringtoneview/src/cpringtoneview.cpp	Wed Sep 29 10:09:58 2010 +0800
@@ -34,14 +34,14 @@
 CpRingToneView::CpRingToneView( QGraphicsItem *parent ):
                               CpBaseSettingView(0, parent),
                               mToneTypeList( new HbListWidget(this) ),
-                              mReq(0)
+                              mReq(0), mProcessing(false)
 {
     HbStyleLoader::registerFilePath(":/widgetml/cpdataformlistentryviewitem.css");
     HbStyleLoader::registerFilePath(":/widgetml/cpdataformlistentryviewitem_color.css");
     HbStyleLoader::registerFilePath(":/widgetml/cpdataformlistentryviewitem.widgetml");
     
     HbDataForm *form = qobject_cast<HbDataForm*> ( widget() );
-    form->setHeading("txt_cp_subhead_select_tone_type");   
+    form->setHeading(hbTrId("txt_cp_subhead_select_tone_type"));   
     
     HbDataFormModel *model = new HbDataFormModel();  
     QList< QPair<QString,QString> > tonesTypeList;
@@ -62,31 +62,43 @@
 }
 CpRingToneView::~CpRingToneView()
 {
-    if(mReq)    delete mReq;
+    if (mReq) {
+        delete mReq;
+    }    
 }
+
 void CpRingToneView::itemActivated( const QModelIndex &index )
 {
-    int nRow = index.row();
-
+    //avoid responding to the second or later consecutive click
+	if (mProcessing) {
+		return;
+	}
+	mProcessing = true;
+    int nRow = index.row();        
     switch(nRow) {
         case 0:         //no tone, set default no sound
-                emit selOK(QString(""));
-                emit aboutToClose();
-                break;
-        case 1:         //tone
-                launchMediaFetcher( "com.nokia.symbian.IToneFetch", "fetch()" );
-                break;
-        case 2:         //music
-                launchMediaFetcher("com.nokia.symbian.IMusicFetch", "fetch()" );
-                break;
+            emit selOK(QString(""));
+            emit aboutToClose();
+            break;
+        case 1: {        //tone
+            launchMediaFetcher( "com.nokia.symbian.IToneFetch", "fetch()" );
+            break;
+        }
+        case 2: {        //music            
+            XQRequestInfo requestInfo;            
+            requestInfo.setInfo("WindowTitle", QVariant(hbTrId("txt_cp_title_control_panel")));
+            launchMediaFetcher("com.nokia.symbian.IMusicFetch", "fetch()", QList<QVariant>(), requestInfo );
+            break;
+        }
         case 3:         //get more tones
 		default:
-		        break;
+            break;
 	 }
 }
 void CpRingToneView::handleOk(const QVariant &result)
 {
-    CPFW_LOG( "CpPersonalizationEntryItemData::handleOk" );
+    mProcessing = false;
+    CPFW_LOG( "CpRingToneView::handleOk" );
     if (!result.canConvert<QString>() || result.toString().length() == 0 )  //error result
     {
         return;
@@ -97,12 +109,21 @@
 }
 
 
-void CpRingToneView::handleError(int errorCode, const QString& errorMessage)
+void CpRingToneView::handleError(int errorCode, const QString &errorMessage)
 {
+    mProcessing = false;
     emit(selError( errorCode, errorMessage ));
 }
 
-void CpRingToneView::launchMediaFetcher( const QString &strService, const QString &strItface )
+/*!
+    Launch media fetcher service.
+    \a strService, the service interface name.
+    \a srItface, the service operation name.
+    \a arguments, the request arguments, preserved.
+    \a info, the request info.
+*/
+void CpRingToneView::launchMediaFetcher( const QString &strService, const QString &strItface,\
+                                        const QList<QVariant> &arguments, const XQRequestInfo &info )
 {
     CPFW_LOG("CpRingToneView::launchMediaFetcher, START");
     if(mReq)
@@ -112,20 +133,23 @@
     }
         //launch media fetcher
     mReq = mAppMgr.create(strService, strItface, true);
+    mReq->setSynchronous(false);
     if (!mReq)
     {
       CPFW_LOG("CpRingToneView::launchMediaFetcher, Mediafetcher start failed");
       return;
     }
     else
-    {
-        connect(mReq, SIGNAL( requestOk( const QVariant&)), SLOT( handleOk(const QVariant&)) );
-        connect(mReq, SIGNAL( requestError( int,const QString&)), SLOT(handleError(int,const QString&)) );
+    {   //use QueuedConnection so that requestError will not be emitted when selecting one tone
+        connect(mReq, SIGNAL(requestOk(QVariant)), SLOT( handleOk(QVariant)), Qt::QueuedConnection);
+        connect(mReq, SIGNAL(requestError(int, QString)), SLOT(handleError(int, QString)));
     }
-    
-    QList<QVariant> args;
-    args << QVariant(QString("<app_name>"));
-    mReq->setArguments(args);
+    if (!arguments.isEmpty()) {
+        mReq->setArguments(arguments);
+    }
+    if (info.isValid()) {
+        mReq->setInfo(info);
+    }
     // Make the request
     if (!mReq->send())
     {