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 * |
|
15 * Description: |
|
16 * The source file of the backup settings of file manager |
|
17 */ |
|
18 |
|
19 #include "fmbackupsettings.h" |
|
20 #include "fmbkupengine.h" |
|
21 #include "fmcommon.h" |
|
22 |
|
23 #include <QString> |
|
24 #include <QStringList> |
|
25 #include <QTime> |
|
26 #include <QSettings> |
|
27 |
|
28 #include <hbglobal.h> |
|
29 |
|
30 FmBackupSettings::FmBackupSettings( FmBkupEngine *aFmBkupEngine ) : mBkupEngine( aFmBkupEngine ) |
|
31 { |
|
32 |
|
33 } |
|
34 |
|
35 FmBackupSettings::~FmBackupSettings( void ) |
|
36 { |
|
37 resetAndDestoryBackupEntry(); |
|
38 } |
|
39 |
|
40 void FmBackupSettings::setContent( const quint32 aContent ) |
|
41 { |
|
42 mContent = aContent; |
|
43 save(); |
|
44 } |
|
45 |
|
46 void FmBackupSettings::setScheduling( const TFileManagerBackupSchedule aScheduling ) |
|
47 { |
|
48 mScheduling = aScheduling; |
|
49 save(); |
|
50 } |
|
51 |
|
52 void FmBackupSettings::setWeekday( const TFileManagerBackupWeekday weekday ) |
|
53 { |
|
54 mWeekday = weekday; |
|
55 save(); |
|
56 } |
|
57 |
|
58 void FmBackupSettings::setTime( const QTime &aTime ) |
|
59 { |
|
60 mTime = aTime; |
|
61 save(); |
|
62 } |
|
63 |
|
64 void FmBackupSettings::setTargetDrive( const QString &aDrive ) |
|
65 { |
|
66 mTargetDrive = aDrive; |
|
67 save(); |
|
68 } |
|
69 |
|
70 quint32 FmBackupSettings::content() const |
|
71 { |
|
72 return mContent; |
|
73 } |
|
74 |
|
75 FmBackupSettings::TFileManagerBackupSchedule FmBackupSettings::scheduling() const |
|
76 { |
|
77 return mScheduling; |
|
78 } |
|
79 |
|
80 FmBackupSettings::TFileManagerBackupWeekday FmBackupSettings::weekday() const |
|
81 { |
|
82 return mWeekday; |
|
83 } |
|
84 |
|
85 const QTime& FmBackupSettings::time() const |
|
86 { |
|
87 return mTime; |
|
88 } |
|
89 |
|
90 QString FmBackupSettings::targetDrive() const |
|
91 { |
|
92 return mTargetDrive; |
|
93 } |
|
94 |
|
95 QString FmBackupSettings::availableTargetDrive() const |
|
96 { |
|
97 QString targetDrive; |
|
98 QStringList driveList; |
|
99 mBkupEngine->getBackupDriveList( driveList ); |
|
100 if( !driveList.isEmpty() ) { |
|
101 if( driveList.contains( mTargetDrive ) ) { |
|
102 targetDrive = mTargetDrive; |
|
103 } else { |
|
104 targetDrive = driveList.first(); |
|
105 } |
|
106 } |
|
107 return targetDrive; |
|
108 } |
|
109 |
|
110 int FmBackupSettings::contentsSelected() const |
|
111 { |
|
112 int ret( 0 ); |
|
113 // Count selected only |
|
114 quint32 mask( mContent ); |
|
115 while ( mask ){ |
|
116 if ( mask & 1 ){ |
|
117 ++ret; |
|
118 } |
|
119 mask >>= 1; |
|
120 } |
|
121 return ret; |
|
122 } |
|
123 |
|
124 FmBackupEntry* FmBackupSettings::CreateEntry( const QString &title, const QString &tips, const FmBackupEntry::TSettingType type ) |
|
125 { |
|
126 FmBackupEntry *entry = new FmBackupEntry( title, tips, type ); |
|
127 return entry; |
|
128 } |
|
129 |
|
130 FmBackupEntry* FmBackupSettings::createContentsEntry() |
|
131 { |
|
132 QString title; |
|
133 QString tips; |
|
134 |
|
135 title = hbTrId( "Backup Contents" ); |
|
136 |
|
137 int selected( contentsSelected() ); |
|
138 if ( !( mContent & EFileManagerBackupContentAll ) && selected > 1 ){ |
|
139 // create text as " 5 selected" |
|
140 tips = QString( QString::number(selected) + " selected" ); |
|
141 } |
|
142 else |
|
143 { |
|
144 // create single content name |
|
145 tips = contentToString( mContent ); |
|
146 } |
|
147 |
|
148 return CreateEntry( title, tips, FmBackupEntry::EContents ); |
|
149 } |
|
150 |
|
151 FmBackupEntry* FmBackupSettings::createSchedulingEntry() |
|
152 { |
|
153 QString title; |
|
154 QString tips; |
|
155 |
|
156 title = hbTrId( "Backup scheduling" ); |
|
157 tips = schedulingToString( mScheduling ); |
|
158 |
|
159 return CreateEntry( title, tips, FmBackupEntry::EScheduling ); |
|
160 } |
|
161 |
|
162 FmBackupEntry* FmBackupSettings::createWeekdayEntry() |
|
163 { |
|
164 QString title; |
|
165 QString tips; |
|
166 |
|
167 title = hbTrId( "Weekday" ); |
|
168 tips = weekdayToString( mWeekday ); |
|
169 |
|
170 return CreateEntry( title, tips, FmBackupEntry::EWeekday ); |
|
171 } |
|
172 |
|
173 FmBackupEntry* FmBackupSettings::createTimeEntry() |
|
174 { |
|
175 QString title; |
|
176 QString tips; |
|
177 |
|
178 title = hbTrId( "Time" ); |
|
179 tips = mTime.toString( "hh:mm" ); |
|
180 |
|
181 return CreateEntry( title, tips, FmBackupEntry::ETime ); |
|
182 } |
|
183 |
|
184 FmBackupEntry* FmBackupSettings::createTargetDriveEntry() |
|
185 { |
|
186 QString title; |
|
187 QString tips; |
|
188 |
|
189 title = hbTrId( "Backup destination" ); |
|
190 tips = targetDriveToString( mTargetDrive ); |
|
191 |
|
192 return CreateEntry( title, tips, FmBackupEntry::ETarget ); |
|
193 } |
|
194 |
|
195 FmBackupEntry* FmBackupSettings::createBackupDateEntry() |
|
196 { |
|
197 QString tips; |
|
198 if( mDate.isNull() ) |
|
199 { |
|
200 tips = hbTrId( "No previous backups created"); |
|
201 } |
|
202 else |
|
203 { |
|
204 tips = hbTrId( "Backup Created " ) + mDate.toString( "dd.MM.yyyy" ); |
|
205 } |
|
206 return CreateEntry( QString(""), tips, FmBackupEntry::EBackupdate); |
|
207 } |
|
208 QString FmBackupSettings::contentToString( const quint32 content ) |
|
209 { |
|
210 QString ret( hbTrId( "All" ) ); |
|
211 |
|
212 if ( content & EFileManagerBackupContentAll ){ |
|
213 ret = hbTrId( "All" ); |
|
214 } |
|
215 else if ( content & EFileManagerBackupContentSettings ){ |
|
216 ret = hbTrId( "Settings" ); |
|
217 } |
|
218 else if ( content & EFileManagerBackupContentMessages ){ |
|
219 ret = hbTrId( "Messages" ); |
|
220 } |
|
221 else if ( content & EFileManagerBackupContentContacts ){ |
|
222 ret = hbTrId( "Contacts" ); |
|
223 } |
|
224 else if ( content & EFileManagerBackupContentCalendar ){ |
|
225 ret = hbTrId( "Calendar" ); |
|
226 } |
|
227 else if ( content & EFileManagerBackupContentBookmarks ){ |
|
228 ret = hbTrId( "Bookmarks" ); |
|
229 } |
|
230 else if ( content & EFileManagerBackupContentUserFiles ){ |
|
231 ret = hbTrId( "Files" ); |
|
232 } |
|
233 return ret; |
|
234 } |
|
235 |
|
236 QString FmBackupSettings::weekdayToString( const TFileManagerBackupWeekday weekday ) |
|
237 { |
|
238 QString ret = ""; |
|
239 switch (weekday) |
|
240 { |
|
241 case EFileManagerBackupWeekdayMonday: |
|
242 ret = hbTrId( "Monday" ); |
|
243 break; |
|
244 case EFileManagerBackupWeekdayTuesday: |
|
245 ret = hbTrId( "Tuesday" ); |
|
246 break; |
|
247 case EFileManagerBackupWeekdayWednesday: |
|
248 ret = hbTrId( "Wednesday" ); |
|
249 break; |
|
250 case EFileManagerBackupWeekdayThursday: |
|
251 ret = hbTrId( "Thursday" ); |
|
252 break; |
|
253 case EFileManagerBackupWeekdayFriday: |
|
254 ret = hbTrId( "Friday" ); |
|
255 break; |
|
256 case EFileManagerBackupWeekdaySaturday: |
|
257 ret = hbTrId( "Saturday" ); |
|
258 break; |
|
259 case EFileManagerBackupWeekdaySunday: |
|
260 ret = hbTrId( "Sunday" ); |
|
261 break; |
|
262 } |
|
263 return ret; |
|
264 } |
|
265 |
|
266 |
|
267 QString FmBackupSettings::schedulingToString( const TFileManagerBackupSchedule scheduling ) |
|
268 { |
|
269 QString ret = ""; |
|
270 switch (scheduling) |
|
271 { |
|
272 case EFileManagerBackupScheduleNever: |
|
273 ret = hbTrId( "Never" ); |
|
274 break; |
|
275 case EFileManagerBackupScheduleDaily: |
|
276 ret = hbTrId ("Daily" ); |
|
277 break; |
|
278 case EFileManagerBackupScheduleWeekly: |
|
279 ret = hbTrId( "Weekly" ); |
|
280 break; |
|
281 } |
|
282 return ret; |
|
283 } |
|
284 |
|
285 QString FmBackupSettings::targetDriveToString( const QString &targetDrive ) |
|
286 { |
|
287 //TODO: Get Volume Name and append to return value |
|
288 return targetDrive; |
|
289 } |
|
290 |
|
291 QList< FmBackupEntry* > FmBackupSettings::backupEntryList() |
|
292 { |
|
293 return mBackupEntryList; |
|
294 } |
|
295 |
|
296 void FmBackupSettings::refreshList() |
|
297 { |
|
298 resetAndDestoryBackupEntry(); |
|
299 FmBackupEntry* entry = 0; |
|
300 |
|
301 entry = createContentsEntry(); |
|
302 mBackupEntryList.push_back( entry ); |
|
303 |
|
304 entry = createSchedulingEntry(); |
|
305 mBackupEntryList.push_back( entry ); |
|
306 |
|
307 if ( mScheduling == EFileManagerBackupScheduleWeekly ) |
|
308 { |
|
309 entry = createWeekdayEntry(); |
|
310 mBackupEntryList.push_back( entry ); |
|
311 } |
|
312 |
|
313 if ( mScheduling == EFileManagerBackupScheduleWeekly || |
|
314 mScheduling == EFileManagerBackupScheduleDaily ) |
|
315 { |
|
316 entry = createTimeEntry(); |
|
317 mBackupEntryList.push_back( entry ); |
|
318 } |
|
319 |
|
320 QStringList driveList; |
|
321 mBkupEngine->getBackupDriveList( driveList ); |
|
322 |
|
323 if( driveList.count() > 1 ) { |
|
324 entry = createTargetDriveEntry(); |
|
325 mBackupEntryList.push_back( entry ); |
|
326 } |
|
327 |
|
328 entry = createBackupDateEntry(); |
|
329 mBackupEntryList.push_back( entry ); |
|
330 } |
|
331 |
|
332 void FmBackupSettings::resetAndDestoryBackupEntry() |
|
333 { |
|
334 for( QList< FmBackupEntry* >::iterator it = mBackupEntryList.begin(); |
|
335 it!= mBackupEntryList.end(); ++it ){ |
|
336 delete *it; |
|
337 } |
|
338 mBackupEntryList.clear(); |
|
339 } |
|
340 |
|
341 |
|
342 |
|
343 // load and save |
|
344 |
|
345 void FmBackupSettings::load() |
|
346 { |
|
347 |
|
348 QStringList driveList; |
|
349 mBkupEngine->getBackupDriveList( driveList ); |
|
350 QString defaultDrive( driveList.first() ); |
|
351 |
|
352 QDate date; |
|
353 QSettings settings("Nokia", "FileManager"); |
|
354 |
|
355 settings.beginGroup("BackupConfigure"); |
|
356 |
|
357 mContent = (settings.value("content", 1).toUInt()); // All for default value |
|
358 mScheduling = (TFileManagerBackupSchedule)(settings.value("scheduling", EFileManagerBackupScheduleNever ).toInt()); // Never schedule for default value |
|
359 mWeekday = (TFileManagerBackupWeekday)(settings.value("weekday", EFileManagerBackupWeekdayMonday ).toInt()); // monday for default value |
|
360 mTime = (settings.value("time", QTime::currentTime() ).toTime()); // empty for default |
|
361 mTargetDrive = (settings.value("targetDrive", defaultDrive ) ).toString(); // C for default |
|
362 mDate = (settings.value("backupDate", date)).toDate(); |
|
363 settings.endGroup(); |
|
364 refreshList(); |
|
365 } |
|
366 |
|
367 |
|
368 void FmBackupSettings::save() |
|
369 { |
|
370 |
|
371 QSettings settings( "Nokia", "FileManager" ); |
|
372 settings.beginGroup( "BackupConfigure" ); |
|
373 |
|
374 settings.setValue( "content", mContent ); |
|
375 settings.setValue( "scheduling", mScheduling ); |
|
376 settings.setValue( "weekday", mWeekday ); |
|
377 settings.setValue( "time", mTime.toString() ); |
|
378 settings.setValue( "targetDrive", mTargetDrive ); |
|
379 settings.setValue( "backupDate", mDate.toString( Qt::ISODate ) ); |
|
380 settings.endGroup(); |
|
381 |
|
382 refreshList(); |
|
383 } |
|
384 |
|
385 void FmBackupSettings::updateBackupDate() |
|
386 { |
|
387 mDate.setDate( QDate::currentDate().year(), QDate::currentDate().month(), QDate::currentDate().day() ); |
|
388 save(); |
|
389 } |
|