31
|
1 |
/*
|
|
2 |
* Copyright (c) 2010 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 |
* A class which takes care of reading the possible new
|
|
16 |
* service centres from SIM and adds them to pda-side Sms Settings.
|
|
17 |
*
|
|
18 |
*/
|
|
19 |
|
|
20 |
// SYSTEM INCLUDES
|
|
21 |
#include <pathinfo.h>
|
|
22 |
#include <f32file.h>
|
|
23 |
#include <hbmessagebox.h>
|
|
24 |
|
|
25 |
// USER INCLUDES
|
|
26 |
#include "ringbc_p.h"
|
|
27 |
#include "ringbctoneconverter.h"
|
|
28 |
#include "s60qconversions.h"
|
|
29 |
#include "debugtraces.h"
|
|
30 |
|
|
31 |
//CONSTANTS
|
|
32 |
_LIT(KRingingToneFileExtension,".rng");
|
|
33 |
|
|
34 |
|
|
35 |
// ----------------------------------------------------------------------------
|
|
36 |
// RingBcPrivate::RingBcPrivate
|
|
37 |
// @see ringbc_p.h
|
|
38 |
// ----------------------------------------------------------------------------
|
|
39 |
RingBcPrivate::RingBcPrivate()
|
|
40 |
|
|
41 |
{
|
|
42 |
QDEBUG_WRITE("RingBcPrivate::RingBcPrivate : Enter")
|
|
43 |
|
|
44 |
TRAP_IGNORE(initL());
|
|
45 |
|
|
46 |
QDEBUG_WRITE("RingBcPrivate::RingBcPrivate : Exit")
|
|
47 |
|
|
48 |
}
|
|
49 |
|
|
50 |
// ----------------------------------------------------------------------------
|
|
51 |
// RingBcPrivate::~RingBcPrivate
|
|
52 |
// @see ringbc_p.h
|
|
53 |
// ----------------------------------------------------------------------------
|
|
54 |
RingBcPrivate::~RingBcPrivate()
|
|
55 |
{
|
|
56 |
QDEBUG_WRITE("RingBcPrivate::~RingBcPrivate : Enter")
|
|
57 |
|
|
58 |
delete mConverter;
|
|
59 |
|
|
60 |
QDEBUG_WRITE("RingBcPrivate::~RingBcPrivate : Exit")
|
|
61 |
}
|
|
62 |
|
|
63 |
// ----------------------------------------------------------------------------
|
|
64 |
// RingBcPrivate::initL
|
|
65 |
// @see ringbc_p.h
|
|
66 |
// ----------------------------------------------------------------------------
|
|
67 |
void RingBcPrivate::initL()
|
|
68 |
{
|
|
69 |
QDEBUG_WRITE("RingBcPrivate::initL : Enter")
|
|
70 |
|
|
71 |
mConverter = RingBCNSMConverter::NewL();
|
|
72 |
|
|
73 |
QDEBUG_WRITE("RingBcPrivate::initL : Exit")
|
|
74 |
}
|
|
75 |
|
|
76 |
// ----------------------------------------------------------------------------
|
|
77 |
// RingBcPrivate::saveTone
|
|
78 |
// @see ringbc_p.h
|
|
79 |
// ----------------------------------------------------------------------------
|
|
80 |
void RingBcPrivate::saveTone(const QString &path)
|
|
81 |
{
|
|
82 |
QDEBUG_WRITE("RingBcPrivate::saveTone : Enter")
|
|
83 |
|
|
84 |
int error(KErrNone);
|
|
85 |
|
|
86 |
TRAP(error, saveToneL(path));
|
|
87 |
if (error)
|
|
88 |
{
|
|
89 |
QDEBUG_WRITE_FORMAT("RingBcPrivate::saveTone Error code =",error)
|
|
90 |
|
|
91 |
if(error == KErrCorrupt)
|
|
92 |
{
|
|
93 |
HbMessageBox::information("Ringing Tone Corrupted");
|
|
94 |
QDEBUG_WRITE("RingBcPrivate::saveTone : Ringing tone corrupted")
|
|
95 |
}
|
|
96 |
else if(error == KErrNoMemory || error == KErrDiskFull)
|
|
97 |
{
|
|
98 |
HbMessageBox::information("No memory to save");
|
|
99 |
QDEBUG_WRITE("RingBcPrivate::saveTone : Low memory")
|
|
100 |
}
|
|
101 |
else
|
|
102 |
{
|
|
103 |
HbMessageBox::information("Error in Saving");
|
|
104 |
QDEBUG_WRITE("RingBcPrivate::saveTone : Error in Saving")
|
|
105 |
}
|
|
106 |
}
|
|
107 |
else
|
|
108 |
{
|
|
109 |
HbMessageBox::information("Saved succesfully");
|
|
110 |
QDEBUG_WRITE("RingBcPrivate::saveTone : Ringing tone saved successfully")
|
|
111 |
}
|
|
112 |
|
|
113 |
QDEBUG_WRITE("RingBcPrivate::saveTone : Exit")
|
|
114 |
}
|
|
115 |
|
|
116 |
// ----------------------------------------------------------------------------
|
|
117 |
// RingBcPrivate::saveToneL
|
|
118 |
// @see ringbc_p.h
|
|
119 |
// ----------------------------------------------------------------------------
|
|
120 |
void RingBcPrivate::saveToneL(const QString& path)
|
|
121 |
{
|
|
122 |
QDEBUG_WRITE("RingBcPrivate::saveToneL : Enter")
|
|
123 |
|
|
124 |
QStringList pathList = path.split(".");
|
|
125 |
QString extension = QString(".") + pathList.at(pathList.count() - 1);
|
|
126 |
|
|
127 |
RFs fsSession;
|
|
128 |
User::LeaveIfError(fsSession.Connect());
|
|
129 |
|
|
130 |
CleanupClosePushL(fsSession);
|
|
131 |
|
|
132 |
HBufC* fileName = S60QConversions::qStringToS60Desc(path);
|
|
133 |
|
|
134 |
RFile file;
|
|
135 |
User::LeaveIfError(file.Open(fsSession, fileName->Des(),
|
|
136 |
EFileShareReadersOnly));
|
|
137 |
|
|
138 |
CleanupClosePushL(file);
|
|
139 |
TInt size;
|
|
140 |
User::LeaveIfError(file.Size(size));
|
|
141 |
|
|
142 |
HBufC8* dataBuf = HBufC8::NewLC(size);
|
|
143 |
TPtr8 data(dataBuf->Des());
|
|
144 |
User::LeaveIfError(file.Read(data, size));
|
|
145 |
CleanupStack::PopAndDestroy(&file);
|
|
146 |
|
|
147 |
TBool valid = mConverter->IsRingToneMimeTypeL(data);
|
|
148 |
|
|
149 |
if (valid)
|
|
150 |
{
|
|
151 |
HBufC* title = mConverter->TitleLC(data);
|
|
152 |
TFileName path = PathInfo::PhoneMemoryRootPath();
|
|
153 |
path.Append(PathInfo::SimpleSoundsPath());
|
|
154 |
path.Append(*title);
|
|
155 |
HBufC* fileExtension = S60QConversions::qStringToS60Desc(extension);
|
|
156 |
path.Append(fileExtension->Des());
|
|
157 |
|
|
158 |
CFileMan* fileMan = CFileMan::NewL(fsSession);
|
|
159 |
CleanupStack::PushL(fileMan);
|
|
160 |
if(fileMan)
|
|
161 |
{
|
|
162 |
TInt err = fileMan->Copy(fileName->Des(), path, CFileMan::ECopy | CFileMan::EOverWrite);
|
|
163 |
User::LeaveIfError(err);
|
|
164 |
}
|
|
165 |
CleanupStack::PopAndDestroy(2); // title,fileMan
|
|
166 |
}
|
|
167 |
|
|
168 |
CleanupStack::PopAndDestroy(); // dataBuf
|
|
169 |
CleanupStack::PopAndDestroy(); //fsSession
|
|
170 |
|
|
171 |
|
|
172 |
QDEBUG_WRITE("RingBcPrivate::saveToneL : Exit")
|
|
173 |
}
|
|
174 |
|
|
175 |
// ----------------------------------------------------------------------------
|
|
176 |
// RingBcPrivate::toneTitle
|
|
177 |
// @see ringbc_p.h
|
|
178 |
// ----------------------------------------------------------------------------
|
|
179 |
QString RingBcPrivate::toneTitle(const QString &path)
|
|
180 |
{
|
|
181 |
QDEBUG_WRITE("RingBcPrivate::toneTitle : Enter")
|
|
182 |
|
|
183 |
QString title;
|
|
184 |
QStringList pathList = path.split(".");
|
|
185 |
QString extension = pathList.at(pathList.count() - 1);
|
|
186 |
|
|
187 |
HBufC* fileName = S60QConversions::qStringToS60Desc(path);
|
|
188 |
TRAP_IGNORE( title = titleL(*fileName));
|
|
189 |
|
|
190 |
title.append(QChar('.'));
|
|
191 |
title.append(extension);
|
|
192 |
|
|
193 |
QDEBUG_WRITE("RingBcPrivate::toneTitle : Exit")
|
|
194 |
return title;
|
|
195 |
}
|
|
196 |
|
|
197 |
// ----------------------------------------------------------------------------
|
|
198 |
// RingBcPrivate::titleL
|
|
199 |
// @see ringbc_p.h
|
|
200 |
// ----------------------------------------------------------------------------
|
|
201 |
QString RingBcPrivate::titleL(const TDesC& aFileName)
|
|
202 |
{
|
|
203 |
QDEBUG_WRITE("RingBcPrivate::titleL : Enter")
|
|
204 |
|
|
205 |
QString title; // initialize to null string
|
|
206 |
RFs fsSession;
|
|
207 |
TInt error = fsSession.Connect();
|
|
208 |
if (error == KErrNone)
|
|
209 |
{
|
|
210 |
CleanupClosePushL(fsSession);
|
|
211 |
|
|
212 |
RFile file;
|
|
213 |
error = file.Open(fsSession, aFileName, EFileRead);
|
|
214 |
|
|
215 |
if (error == KErrNone)
|
|
216 |
{
|
|
217 |
CleanupClosePushL(file);
|
|
218 |
TInt size;
|
|
219 |
User::LeaveIfError(file.Size(size));
|
|
220 |
if (size)
|
|
221 |
{
|
|
222 |
HBufC8* dataBuf = HBufC8::NewLC(size);
|
|
223 |
TPtr8 data(dataBuf->Des());
|
|
224 |
User::LeaveIfError(file.Read(data, size));
|
|
225 |
|
|
226 |
TBool valid = mConverter->IsRingToneMimeTypeL(data);
|
|
227 |
if (valid)
|
|
228 |
{
|
|
229 |
HBufC* toneTitle = mConverter->TitleLC(data);
|
|
230 |
title = S60QConversions::s60DescToQString(*toneTitle);
|
|
231 |
CleanupStack::PopAndDestroy(); //title
|
|
232 |
}
|
|
233 |
CleanupStack::PopAndDestroy(); //dataBuf
|
|
234 |
}
|
|
235 |
CleanupStack::PopAndDestroy(); //file
|
|
236 |
}
|
|
237 |
CleanupStack::PopAndDestroy(); //fsSession
|
|
238 |
}
|
|
239 |
QDEBUG_WRITE("RingBcPrivate::titleL : Exit")
|
|
240 |
return title;
|
|
241 |
}
|
|
242 |
|
|
243 |
// End of File
|