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