|
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 <QModelIndex> |
|
23 #include <QStandardItemModel> |
|
24 #include <QStandardItem> |
|
25 #include <xqaiwrequest.h> |
|
26 #include <cplogger.h> |
|
27 |
|
28 CpRingToneView::CpRingToneView( QGraphicsItem *parent ): |
|
29 CpBaseSettingView(0, parent), |
|
30 mToneTypeList( new HbListWidget(this) ), |
|
31 mReq(0) |
|
32 { |
|
33 HbWidget* contentWidget = new HbWidget(this); |
|
34 QGraphicsLinearLayout* layout = new QGraphicsLinearLayout(Qt::Vertical); |
|
35 |
|
36 //setup the heading. |
|
37 HbLabel* label = new HbLabel( hbTrId("txt_cp_subhead_select_tone_type"), contentWidget ); |
|
38 layout->addItem(label); |
|
39 //handling user click |
|
40 bool bret = connect(mToneTypeList, SIGNAL( activated(HbListWidgetItem *) ), |
|
41 this, SLOT(onTypeSelected(HbListWidgetItem *))); |
|
42 //initialize the list contents |
|
43 QList<QString> tonesTypeList; |
|
44 tonesTypeList << |
|
45 hbTrId("txt_cp_list_no_tone")<< |
|
46 hbTrId("txt_cp_list_tone")<< |
|
47 hbTrId("txt_cp_list_music")<< |
|
48 hbTrId("txt_cp_list_recording")<< |
|
49 hbTrId("txt_cp_list_get_more_tones"); |
|
50 for ( int i = 0; i < tonesTypeList.count(); i++ ) |
|
51 { |
|
52 mToneTypeList->addItem(tonesTypeList.at(i)); |
|
53 } |
|
54 //add the list to layout. |
|
55 layout->addItem(mToneTypeList); |
|
56 |
|
57 contentWidget->setLayout(layout); |
|
58 |
|
59 setWidget(contentWidget); |
|
60 } |
|
61 CpRingToneView::~CpRingToneView() |
|
62 { |
|
63 if(mReq) delete mReq; |
|
64 } |
|
65 void CpRingToneView::onTypeSelected(HbListWidgetItem *item) |
|
66 { |
|
67 int nRow = mToneTypeList->row( item ); |
|
68 switch(nRow) |
|
69 { |
|
70 case 0: //no tone, set default no sound |
|
71 emit selOK(QString("")); |
|
72 emit aboutToClose(); |
|
73 break; |
|
74 case 1: //tone |
|
75 launchMediaFetcher( "com.nokia.symbian.IToneFetch", "fetch()" ); |
|
76 break; |
|
77 case 2: //music |
|
78 launchMediaFetcher("com.nokia.symbian.IMusicFetch", "fetch()" ); |
|
79 break; |
|
80 case 3: //recording |
|
81 case 4: //get more tones |
|
82 default: |
|
83 break; |
|
84 } |
|
85 } |
|
86 void CpRingToneView::handleOk(const QVariant &result) |
|
87 { |
|
88 CPFW_LOG( "CpPersonalizationEntryItemData::handleOk" ); |
|
89 if (!result.canConvert<QString>() || result.toString().length() == 0 ) //error result |
|
90 { |
|
91 return; |
|
92 } |
|
93 hide(); |
|
94 emit selOK( result.value<QString>() ); |
|
95 emit aboutToClose(); |
|
96 } |
|
97 |
|
98 |
|
99 void CpRingToneView::handleError(int errorCode, const QString& errorMessage) |
|
100 { |
|
101 emit(selError( errorCode, errorMessage )); |
|
102 } |
|
103 |
|
104 void CpRingToneView::launchMediaFetcher( const QString &strService, const QString &strItface ) |
|
105 { |
|
106 CPFW_LOG("CpRingToneView::launchMediaFetcher, START"); |
|
107 if(mReq) |
|
108 { |
|
109 delete mReq; |
|
110 mReq = 0; |
|
111 } |
|
112 //launch media fetcher |
|
113 mReq = mAppMgr.create(strService, strItface, true); |
|
114 if (!mReq) |
|
115 { |
|
116 CPFW_LOG("CpRingToneView::launchMediaFetcher, Mediafetcher start failed"); |
|
117 return; |
|
118 } |
|
119 else |
|
120 { |
|
121 connect(mReq, SIGNAL( requestOk( const QVariant&)), SLOT( handleOk(const QVariant&)) ); |
|
122 connect(mReq, SIGNAL( requestError( int,const QString&)), SLOT(handleError(int,const QString&)) ); |
|
123 } |
|
124 |
|
125 QList<QVariant> args; |
|
126 args << QVariant(QString("<app_name>")); |
|
127 mReq->setArguments(args); |
|
128 // Make the request |
|
129 if (!mReq->send()) |
|
130 { |
|
131 CPFW_LOG("CpRingToneView::launchMediaFetcher, Mediafetcher calling failed"); |
|
132 } |
|
133 CPFW_LOG("CpRingToneView::launchMediaFetcher, END"); |
|
134 } |
|
135 |