controlpanelui/src/cpplugins/ringtoneplugin/src/cppersonalizationentryitemdata.cpp
changeset 12 624337f114fe
child 14 23411a3be0db
equal deleted inserted replaced
11:10d0dd0e43f1 12:624337f114fe
       
     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:
       
    15  *
       
    16  */
       
    17 #include "cppersonalizationentryitemdata.h"
       
    18 #include <xqaiwrequest.h>
       
    19 #include <cpitemdatahelper.h>
       
    20 #include <cpprofilemodel.h>
       
    21 #include <cplogger.h>
       
    22 #include <qdir.h>
       
    23 
       
    24 CpPersonalizationEntryItemData::CpPersonalizationEntryItemData(CpItemDataHelper &itemDataHelper,
       
    25                 const QString &text,
       
    26                 const QString &description,
       
    27                 const HbIcon &icon,
       
    28                 const HbDataFormModelItem *parent)
       
    29                 :CpSettingFormEntryItemData(itemDataHelper,text,description,
       
    30                                             icon,parent),mReq(0),mProfileModel(0)
       
    31 {
       
    32     CPFW_LOG("CpPersonalizationEntryItemData::CpPersonalizationEntryItemData(), START");
       
    33     mProfileModel = new CpProfileModel();
       
    34     if(mProfileModel)
       
    35     {
       
    36         setDescription( mProfileModel->ringTone().section(QDir::separator (),-1) );
       
    37     }
       
    38     else
       
    39     {
       
    40         CPFW_LOG("CpPersonalizationEntryItemData::mProfileModel:NULL!");
       
    41     }
       
    42 }
       
    43 CpPersonalizationEntryItemData::~CpPersonalizationEntryItemData()
       
    44 {
       
    45     if( mProfileModel )
       
    46     {
       
    47         delete mProfileModel;
       
    48         mProfileModel = NULL;
       
    49     }
       
    50 }
       
    51 void CpPersonalizationEntryItemData::onLaunchView()
       
    52 {
       
    53     CPFW_LOG("CpPersonalizationEntryItemData::onLaunchView, START");
       
    54 
       
    55     //launch media fetcher
       
    56     if (!mReq)
       
    57     {
       
    58         mReq = mAppMgr.create("com.nokia.services.media.Music", "fetch(QString)", true);
       
    59 
       
    60         if (!mReq)
       
    61         {
       
    62           CPFW_LOG("CpPersonalizationEntryItemData::onLaunchView, Mediafetcher start failed");
       
    63           return;
       
    64         }
       
    65         else
       
    66         {
       
    67             connect(mReq, SIGNAL(requestOk(const QVariant&)), SLOT(handleOk(const QVariant&)));
       
    68             connect(mReq, SIGNAL(requestError(int,const QString&)), SLOT(handleError(int,const QString&)));
       
    69         }
       
    70     }
       
    71 
       
    72     // Set arguments for request (music fetcher application title)
       
    73     QList<QVariant> args;
       
    74     args << QVariant( text() );
       
    75     mReq->setArguments(args);
       
    76 
       
    77     // Make the request
       
    78     if (!mReq->send())
       
    79     {
       
    80         CPFW_LOG("CpPersonalizationEntryItemData::onLaunchView, Mediafetcher calling failed");
       
    81         //report error
       
    82         return;
       
    83     }
       
    84     CPFW_LOG("CpPersonalizationEntryItemData::onLaunchView, successful END");
       
    85 
       
    86 }
       
    87 void CpPersonalizationEntryItemData::handleOk(const QVariant &result)
       
    88 {
       
    89     CPFW_LOG("CpPersonalizationEntryItemData::handleOk");
       
    90     if (!result.canConvert<QString>())
       
    91     {
       
    92         setDescription( "Corrupt result" );
       
    93     }
       
    94     else
       
    95     {
       
    96         QString strRet = result.value<QString>();
       
    97         if(strRet.length())
       
    98         {
       
    99             setDescription( strRet.section(QDir::separator (),-1) );
       
   100         }
       
   101         else
       
   102         {
       
   103             setDescription( "No tone" );
       
   104         }
       
   105         mProfileModel->setRingTone( strRet );
       
   106     }
       
   107 }
       
   108 void CpPersonalizationEntryItemData::handleError(int errorCode, const QString& errorMessage)
       
   109 {
       
   110     CPFW_LOG("CpPersonalizationEntryItemData::handleError");
       
   111     //handling error return
       
   112     Q_UNUSED(errorCode);
       
   113     Q_UNUSED(errorMessage);
       
   114     setDescription("Error media fetcher");
       
   115 }
       
   116 
       
   117 CpBaseSettingView *CpPersonalizationEntryItemData::createSettingView() const
       
   118 {
       
   119     return NULL;
       
   120 }