19
|
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 "cpringtoneview.h"
|
|
18 |
#include <HbListWidget>
|
|
19 |
#include <QGraphicsLinearLayout>
|
|
20 |
#include <HbLabel>
|
|
21 |
#include <QList>
|
22
|
22 |
#include <QPair>
|
19
|
23 |
#include <QModelIndex>
|
|
24 |
#include <QStandardItemModel>
|
|
25 |
#include <QStandardItem>
|
|
26 |
#include <xqaiwrequest.h>
|
|
27 |
#include <cplogger.h>
|
22
|
28 |
#include <hbstyleloader.h>
|
|
29 |
#include <hbdataformmodel.h>
|
|
30 |
#include <hbdataformmodelitem.h>
|
|
31 |
#include <hbdataform.h>
|
|
32 |
#include <cpsettingformentryitemdata.h>
|
19
|
33 |
|
|
34 |
CpRingToneView::CpRingToneView( QGraphicsItem *parent ):
|
|
35 |
CpBaseSettingView(0, parent),
|
|
36 |
mToneTypeList( new HbListWidget(this) ),
|
40
|
37 |
mReq(0), mProcessing(false)
|
19
|
38 |
{
|
22
|
39 |
HbStyleLoader::registerFilePath(":/widgetml/cpdataformlistentryviewitem.css");
|
|
40 |
HbStyleLoader::registerFilePath(":/widgetml/cpdataformlistentryviewitem_color.css");
|
|
41 |
HbStyleLoader::registerFilePath(":/widgetml/cpdataformlistentryviewitem.widgetml");
|
|
42 |
|
|
43 |
HbDataForm *form = qobject_cast<HbDataForm*> ( widget() );
|
40
|
44 |
form->setHeading(hbTrId("txt_cp_subhead_select_tone_type"));
|
22
|
45 |
|
|
46 |
HbDataFormModel *model = new HbDataFormModel();
|
|
47 |
QList< QPair<QString,QString> > tonesTypeList;
|
|
48 |
tonesTypeList << qMakePair( QString("qtg_large_tone_off"), hbTrId("txt_cp_list_no_tone") )
|
|
49 |
<< qMakePair( QString("qtg_large_tone"), hbTrId("txt_cp_list_tone") )
|
|
50 |
<< qMakePair( QString("qtg_large_music"), hbTrId("txt_cp_list_music") )
|
|
51 |
<< qMakePair( QString("qtg_large_ovistore"), hbTrId("txt_cp_list_get_more_tones") );
|
|
52 |
|
|
53 |
for (int i = 0; i < tonesTypeList.count(); ++i) {
|
|
54 |
HbDataFormModelItem *itemData = new HbDataFormModelItem();
|
|
55 |
itemData->setType ( static_cast<HbDataFormModelItem::DataItemType> (CpSettingFormEntryItemData::ListEntryItem) );
|
|
56 |
itemData->setLabel(tonesTypeList.at(i).second);
|
|
57 |
itemData->setIcon(tonesTypeList.at(i).first);
|
|
58 |
model->appendDataFormItem(itemData, model->invisibleRootItem());
|
19
|
59 |
}
|
22
|
60 |
connect(form, SIGNAL(activated(QModelIndex)), this, SLOT(itemActivated(QModelIndex)));
|
|
61 |
form->setModel(model);
|
19
|
62 |
}
|
|
63 |
CpRingToneView::~CpRingToneView()
|
|
64 |
{
|
40
|
65 |
if (mReq) {
|
|
66 |
delete mReq;
|
|
67 |
}
|
19
|
68 |
}
|
40
|
69 |
|
22
|
70 |
void CpRingToneView::itemActivated( const QModelIndex &index )
|
19
|
71 |
{
|
40
|
72 |
//avoid responding to the second or later consecutive click
|
|
73 |
if (mProcessing) {
|
|
74 |
return;
|
|
75 |
}
|
|
76 |
mProcessing = true;
|
|
77 |
int nRow = index.row();
|
22
|
78 |
switch(nRow) {
|
19
|
79 |
case 0: //no tone, set default no sound
|
40
|
80 |
emit selOK(QString(""));
|
|
81 |
emit aboutToClose();
|
|
82 |
break;
|
|
83 |
case 1: { //tone
|
|
84 |
launchMediaFetcher( "com.nokia.symbian.IToneFetch", "fetch()" );
|
|
85 |
break;
|
|
86 |
}
|
|
87 |
case 2: { //music
|
|
88 |
XQRequestInfo requestInfo;
|
|
89 |
requestInfo.setInfo("WindowTitle", QVariant(hbTrId("txt_cp_title_control_panel")));
|
|
90 |
launchMediaFetcher("com.nokia.symbian.IMusicFetch", "fetch()", QList<QVariant>(), requestInfo );
|
|
91 |
break;
|
|
92 |
}
|
22
|
93 |
case 3: //get more tones
|
|
94 |
default:
|
40
|
95 |
break;
|
22
|
96 |
}
|
19
|
97 |
}
|
|
98 |
void CpRingToneView::handleOk(const QVariant &result)
|
|
99 |
{
|
40
|
100 |
mProcessing = false;
|
|
101 |
CPFW_LOG( "CpRingToneView::handleOk" );
|
19
|
102 |
if (!result.canConvert<QString>() || result.toString().length() == 0 ) //error result
|
|
103 |
{
|
|
104 |
return;
|
|
105 |
}
|
|
106 |
hide();
|
|
107 |
emit selOK( result.value<QString>() );
|
|
108 |
emit aboutToClose();
|
|
109 |
}
|
|
110 |
|
|
111 |
|
40
|
112 |
void CpRingToneView::handleError(int errorCode, const QString &errorMessage)
|
19
|
113 |
{
|
40
|
114 |
mProcessing = false;
|
19
|
115 |
emit(selError( errorCode, errorMessage ));
|
|
116 |
}
|
|
117 |
|
40
|
118 |
/*!
|
|
119 |
Launch media fetcher service.
|
|
120 |
\a strService, the service interface name.
|
|
121 |
\a srItface, the service operation name.
|
|
122 |
\a arguments, the request arguments, preserved.
|
|
123 |
\a info, the request info.
|
|
124 |
*/
|
|
125 |
void CpRingToneView::launchMediaFetcher( const QString &strService, const QString &strItface,\
|
|
126 |
const QList<QVariant> &arguments, const XQRequestInfo &info )
|
19
|
127 |
{
|
|
128 |
CPFW_LOG("CpRingToneView::launchMediaFetcher, START");
|
|
129 |
if(mReq)
|
|
130 |
{
|
|
131 |
delete mReq;
|
|
132 |
mReq = 0;
|
|
133 |
}
|
|
134 |
//launch media fetcher
|
|
135 |
mReq = mAppMgr.create(strService, strItface, true);
|
40
|
136 |
mReq->setSynchronous(false);
|
19
|
137 |
if (!mReq)
|
|
138 |
{
|
|
139 |
CPFW_LOG("CpRingToneView::launchMediaFetcher, Mediafetcher start failed");
|
|
140 |
return;
|
|
141 |
}
|
|
142 |
else
|
40
|
143 |
{ //use QueuedConnection so that requestError will not be emitted when selecting one tone
|
|
144 |
connect(mReq, SIGNAL(requestOk(QVariant)), SLOT( handleOk(QVariant)), Qt::QueuedConnection);
|
|
145 |
connect(mReq, SIGNAL(requestError(int, QString)), SLOT(handleError(int, QString)));
|
19
|
146 |
}
|
40
|
147 |
if (!arguments.isEmpty()) {
|
|
148 |
mReq->setArguments(arguments);
|
|
149 |
}
|
|
150 |
if (info.isValid()) {
|
|
151 |
mReq->setInfo(info);
|
|
152 |
}
|
19
|
153 |
// Make the request
|
|
154 |
if (!mReq->send())
|
|
155 |
{
|
|
156 |
CPFW_LOG("CpRingToneView::launchMediaFetcher, Mediafetcher calling failed");
|
|
157 |
}
|
|
158 |
CPFW_LOG("CpRingToneView::launchMediaFetcher, END");
|
|
159 |
}
|
|
160 |
|