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 <cpitemdatahelper.h> |
|
19 #include <cpprofilemodel.h> |
|
20 #include <cplogger.h> |
|
21 #include <qdir.h> |
|
22 #include <xqsettingsmanager.h> |
|
23 #include <xqcentralrepositoryutils.h> |
|
24 #include <xqcentralrepositorysearchcriteria.h> |
|
25 #include <ProfileEngineInternalCRKeys.h> |
|
26 |
|
27 #include "cpringtoneview.h" |
|
28 |
|
29 |
|
30 const QString g_strNoTone("Z:\\resource\\No_Sound.wav"); |
|
31 CpPersonalizationEntryItemData::CpPersonalizationEntryItemData(CpItemDataHelper &itemDataHelper, |
|
32 const QString &text, |
|
33 const QString &description, |
|
34 const QString &icon, |
|
35 Profile_Tone_Types toneType, |
|
36 int profileId, |
|
37 const HbDataFormModelItem *parent) |
|
38 :CpSettingFormEntryItemData(CpSettingFormEntryItemData::ListEntryItem, itemDataHelper,text,description,icon,parent), |
|
39 mProfileModel(0), |
|
40 m_profileID(profileId), |
|
41 mToneType(toneType), |
|
42 mSettingManager(0) |
|
43 { |
|
44 Q_UNUSED(itemDataHelper); //reserve for future |
|
45 CPFW_LOG("CpPersonalizationEntryItemData::CpPersonalizationEntryItemData(), START"); |
|
46 mProfileModel = new CpProfileModel(); |
|
47 if( mProfileModel ) |
|
48 { |
|
49 QString strRing = loadStringValue(); |
|
50 if( QFileInfo(strRing) == QFileInfo(g_strNoTone) ) |
|
51 { |
|
52 setDescription( hbTrId("txt_cp_list_no_tone" ) ); //sepcial handling about NoTone |
|
53 } |
|
54 else |
|
55 { |
|
56 setDescription( QFileInfo(strRing).baseName() ); |
|
57 } |
|
58 } |
|
59 else |
|
60 { |
|
61 CPFW_LOG("CpPersonalizationEntryItemData::mProfileModel:NULL!"); |
|
62 } |
|
63 mSettingManager = new XQSettingsManager(); |
|
64 XQCentralRepositorySettingsKey key(KCRUidProfileEngine.iUid,KProEngSilenceMode); |
|
65 |
|
66 //Monitoring the active ring tone |
|
67 XQCentralRepositorySettingsKey keyForActiveRingTone(KCRUidProfileEngine.iUid,KProEngActiveRingTone); |
|
68 |
|
69 QVariant silenceMode = mSettingManager->readItemValue( key,XQSettingsManager::TypeInt ); |
|
70 setEnabled( !silenceMode.toInt() ); |
|
71 mSettingManager->startMonitoring( key,XQSettingsManager::TypeInt ); |
|
72 mSettingManager->startMonitoring(keyForActiveRingTone, XQSettingsManager::TypeString); |
|
73 connect(mSettingManager, SIGNAL(valueChanged (XQSettingsKey, QVariant)), |
|
74 this, SLOT(settingValueChanged(XQSettingsKey, QVariant))); |
|
75 |
|
76 } |
|
77 void CpPersonalizationEntryItemData::settingValueChanged( const XQSettingsKey& key, const QVariant& value ) |
|
78 { |
|
79 switch (key.key()) { |
|
80 case KProEngActiveRingTone: |
|
81 { |
|
82 QString strRing = loadStringValue(); |
|
83 if( QFileInfo(strRing) == QFileInfo(g_strNoTone) ) |
|
84 { |
|
85 setDescription( hbTrId("txt_cp_list_no_tone" ) ); //sepcial handling about NoTone |
|
86 } |
|
87 else |
|
88 { |
|
89 setDescription( QFileInfo(strRing).baseName() ); |
|
90 } |
|
91 break; |
|
92 } |
|
93 case KProEngSilenceMode: |
|
94 { |
|
95 setEnabled( !value.toInt() ); |
|
96 break; |
|
97 |
|
98 } |
|
99 default: |
|
100 break; |
|
101 } |
|
102 } |
|
103 |
|
104 CpPersonalizationEntryItemData::~CpPersonalizationEntryItemData() |
|
105 { |
|
106 if( mProfileModel ) |
|
107 { |
|
108 delete mProfileModel; |
|
109 mProfileModel = 0; |
|
110 } |
|
111 if( mSettingManager ) |
|
112 { |
|
113 delete mSettingManager; |
|
114 } |
|
115 } |
|
116 |
|
117 QString CpPersonalizationEntryItemData::loadStringValue() const |
|
118 { |
|
119 QString strRing; |
|
120 switch( mToneType ) |
|
121 { |
|
122 case TONE_Message: |
|
123 if( m_profileID>=0 ) |
|
124 { |
|
125 strRing = mProfileModel->messageTone( m_profileID ); |
|
126 } |
|
127 break; |
|
128 case TONE_Email: |
|
129 if( m_profileID >=0 ) |
|
130 { |
|
131 strRing = mProfileModel->emailTone( m_profileID ); |
|
132 } |
|
133 break; |
|
134 case TONE_Reminder: |
|
135 if( m_profileID >=0 ) |
|
136 { |
|
137 strRing = mProfileModel->reminderTone( m_profileID ); |
|
138 } |
|
139 break; |
|
140 case TONE_Ring: |
|
141 default: |
|
142 if( m_profileID <0 ) |
|
143 { |
|
144 |
|
145 strRing = mProfileModel->ringTone(); |
|
146 } |
|
147 else |
|
148 { |
|
149 strRing = mProfileModel->ringTone( m_profileID ); |
|
150 } |
|
151 break; |
|
152 } |
|
153 |
|
154 return strRing; |
|
155 } |
|
156 void CpPersonalizationEntryItemData::storeStringValue( const QString &strValue ) const |
|
157 { |
|
158 QString strInput = strValue; |
|
159 if( strInput.length() == 0 ) |
|
160 { |
|
161 strInput = g_strNoTone; |
|
162 } |
|
163 switch( mToneType ) |
|
164 { |
|
165 case TONE_Message: |
|
166 if( m_profileID >=0 ) |
|
167 { |
|
168 mProfileModel->setMessageTone( m_profileID, strInput ); |
|
169 } |
|
170 break; |
|
171 case TONE_Email: |
|
172 if( m_profileID >=0 ) |
|
173 { |
|
174 mProfileModel->setEmailTone( m_profileID, strInput ); |
|
175 } |
|
176 break; |
|
177 case TONE_Reminder: |
|
178 if( m_profileID >=0 ) |
|
179 { |
|
180 mProfileModel->setReminderTone( m_profileID, strInput ); |
|
181 } |
|
182 break; |
|
183 case TONE_Ring: |
|
184 default: |
|
185 if( m_profileID <0 ) |
|
186 { |
|
187 mProfileModel->setRingTone( strInput ); |
|
188 } |
|
189 else |
|
190 { |
|
191 mProfileModel->setRingTone( m_profileID, strInput ); |
|
192 } |
|
193 break; |
|
194 } |
|
195 } |
|
196 |
|
197 void CpPersonalizationEntryItemData::handleOk(const QString &strFname) |
|
198 { |
|
199 if(strFname.length()) |
|
200 { |
|
201 //lower level services(tone fetcher or music fetcher) |
|
202 //will guarantee strFname is a valid absolute file path. |
|
203 setDescription(QFileInfo(strFname).baseName()); |
|
204 } |
|
205 else |
|
206 { |
|
207 setDescription( hbTrId("txt_cp_list_no_tone" ) ); |
|
208 } |
|
209 storeStringValue(strFname); |
|
210 } |
|
211 |
|
212 |
|
213 void CpPersonalizationEntryItemData::handleError(int errorCode, const QString& errorMessage) |
|
214 { |
|
215 Q_UNUSED(errorCode); |
|
216 Q_UNUSED(errorMessage); |
|
217 } |
|
218 |
|
219 CpBaseSettingView *CpPersonalizationEntryItemData::createSettingView() const |
|
220 { |
|
221 CpRingToneView *pView = new CpRingToneView( ); |
|
222 connect( pView, SIGNAL( selOK( const QString&)),SLOT(handleOk(const QString &)) ); |
|
223 connect( pView, SIGNAL( selError( int, const QString& ) ), SLOT( handleOk(const QString &)) ); |
|
224 return pView; |
|
225 } |
|