|
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 #include <QPair> |
|
23 #include <QModelIndex> |
|
24 #include <QStandardItemModel> |
|
25 #include <QStandardItem> |
|
26 #include <xqaiwrequest.h> |
|
27 #include <cplogger.h> |
|
28 #include <hbstyleloader.h> |
|
29 #include <hbdataformmodel.h> |
|
30 #include <hbdataformmodelitem.h> |
|
31 #include <hbdataform.h> |
|
32 #include <cpsettingformentryitemdata.h> |
|
33 |
|
34 CpRingToneView::CpRingToneView( QGraphicsItem *parent ): |
|
35 CpBaseSettingView(0, parent), |
|
36 mToneTypeList( new HbListWidget(this) ), |
|
37 mReq(0), mProcessing(false) |
|
38 { |
|
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() ); |
|
44 form->setHeading(hbTrId("txt_cp_subhead_select_tone_type")); |
|
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()); |
|
59 } |
|
60 connect(form, SIGNAL(activated(QModelIndex)), this, SLOT(itemActivated(QModelIndex))); |
|
61 form->setModel(model); |
|
62 } |
|
63 CpRingToneView::~CpRingToneView() |
|
64 { |
|
65 if (mReq) { |
|
66 delete mReq; |
|
67 } |
|
68 } |
|
69 |
|
70 void CpRingToneView::itemActivated( const QModelIndex &index ) |
|
71 { |
|
72 //avoid responding to the second or later consecutive click |
|
73 if (mProcessing) { |
|
74 return; |
|
75 } |
|
76 mProcessing = true; |
|
77 int nRow = index.row(); |
|
78 |
|
79 switch(nRow) { |
|
80 case 0: //no tone, set default no sound |
|
81 emit selOK(QString("")); |
|
82 emit aboutToClose(); |
|
83 break; |
|
84 case 1: //tone |
|
85 launchMediaFetcher( "com.nokia.symbian.IToneFetch", "fetch()" ); |
|
86 break; |
|
87 case 2: //music |
|
88 launchMediaFetcher("com.nokia.symbian.IMusicFetch", "fetch()" ); |
|
89 break; |
|
90 case 3: //get more tones |
|
91 default: |
|
92 break; |
|
93 } |
|
94 } |
|
95 void CpRingToneView::handleOk(const QVariant &result) |
|
96 { |
|
97 mProcessing = false; |
|
98 CPFW_LOG( "CpRingToneView::handleOk" ); |
|
99 if (!result.canConvert<QString>() || result.toString().length() == 0 ) //error result |
|
100 { |
|
101 return; |
|
102 } |
|
103 hide(); |
|
104 emit selOK( result.value<QString>() ); |
|
105 emit aboutToClose(); |
|
106 } |
|
107 |
|
108 |
|
109 void CpRingToneView::handleError(int errorCode, const QString& errorMessage) |
|
110 { |
|
111 mProcessing = false; |
|
112 emit(selError( errorCode, errorMessage )); |
|
113 } |
|
114 |
|
115 void CpRingToneView::launchMediaFetcher( const QString &strService, const QString &strItface ) |
|
116 { |
|
117 CPFW_LOG("CpRingToneView::launchMediaFetcher, START"); |
|
118 if(mReq) |
|
119 { |
|
120 delete mReq; |
|
121 mReq = 0; |
|
122 } |
|
123 //launch media fetcher |
|
124 mReq = mAppMgr.create(strService, strItface, true); |
|
125 mReq->setSynchronous(false); |
|
126 if (!mReq) |
|
127 { |
|
128 CPFW_LOG("CpRingToneView::launchMediaFetcher, Mediafetcher start failed"); |
|
129 return; |
|
130 } |
|
131 else |
|
132 { //use QueuedConnection so that requestError will not be emitted when selecting one tone |
|
133 connect(mReq, SIGNAL(requestOk(QVariant)), SLOT( handleOk(QVariant)), Qt::QueuedConnection); |
|
134 connect(mReq, SIGNAL(requestError(int, QString)), SLOT(handleError(int, QString))); |
|
135 } |
|
136 |
|
137 QList<QVariant> args; |
|
138 args << QVariant(QString("<app_name>")); |
|
139 mReq->setArguments(args); |
|
140 // Make the request |
|
141 if (!mReq->send()) |
|
142 { |
|
143 CPFW_LOG("CpRingToneView::launchMediaFetcher, Mediafetcher calling failed"); |
|
144 } |
|
145 CPFW_LOG("CpRingToneView::launchMediaFetcher, END"); |
|
146 } |
|
147 |