|
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 engine implement for win32 |
|
17 */ |
|
18 |
|
19 #include "FmBkupEngine_p.h" |
|
20 #include <QThread> |
|
21 |
|
22 #include "fmbkupcommon.h" |
|
23 #include "fmbackupsettings.h" |
|
24 #include "fmrestoresettings.h" |
|
25 #include "fmdefine.h" |
|
26 |
|
27 #include <QSettings> |
|
28 |
|
29 FmBkupEnginePrivate::FmBkupEnginePrivate(FmBkupEngine* bkupEngine): q(bkupEngine), mError( FmErrNone ) |
|
30 { |
|
31 mBkupThread = new FmBkupThread( this ); |
|
32 |
|
33 connect( mBkupThread, SIGNAL( notifyPreparing( bool ) ), this, SLOT( onNotifyPreparing( bool ) ) ); |
|
34 connect( mBkupThread, SIGNAL( notifyStart( bool, int ) ), this, SLOT( onNotifyStart( bool, int ) ) ); |
|
35 connect( mBkupThread, SIGNAL( notifyUpdate(int) ), this, SLOT( onNotifyUpdate(int) ) ); |
|
36 connect( mBkupThread, SIGNAL( notifyFinish(int) ), |
|
37 this, SLOT( onNotifyFinish(int) ) ); |
|
38 connect( mBkupThread, SIGNAL( notifyMemoryLow(int, int& ) ), this, SLOT( onNotifyMemoryLow(int, int&) ) ); |
|
39 } |
|
40 |
|
41 FmBkupEnginePrivate::~FmBkupEnginePrivate() |
|
42 { |
|
43 |
|
44 } |
|
45 |
|
46 void FmBkupEnginePrivate::onNotifyPreparing( bool cancelable ) |
|
47 { |
|
48 emit notifyPreparing( cancelable ); |
|
49 } |
|
50 void FmBkupEnginePrivate::onNotifyStart( bool cancelable, int totalCount ) |
|
51 { |
|
52 emit notifyStart( cancelable, totalCount ); |
|
53 } |
|
54 void FmBkupEnginePrivate::onNotifyUpdate( int count ) |
|
55 { |
|
56 emit notifyUpdate( count ); |
|
57 } |
|
58 void FmBkupEnginePrivate::onNotifyFinish( int err ) |
|
59 { |
|
60 emit notifyFinish( err ); |
|
61 } |
|
62 void FmBkupEnginePrivate::onNotifyMemoryLow( int memoryValue, int &userError ) |
|
63 { |
|
64 emit notifyMemoryLow( memoryValue, userError ); |
|
65 } |
|
66 |
|
67 bool FmBkupEnginePrivate::startBackup( QList<FmBkupDrivesAndOperation* > drivesAndOperationList, |
|
68 QList<FmBkupBackupCategory*> backupCategoryList,QString drive, quint32 content ) |
|
69 { |
|
70 mError = mBkupThread->asyncBackup( drivesAndOperationList, backupCategoryList, drive, content ); |
|
71 return ( mError == FmErrNone ); |
|
72 } |
|
73 |
|
74 void FmBkupEnginePrivate::cancelBackup() |
|
75 { |
|
76 mBkupThread->stop(); |
|
77 } |
|
78 |
|
79 int FmBkupEnginePrivate::deleteBackup( QList<FmBkupDrivesAndOperation* > drivesAndOperationList ) |
|
80 { |
|
81 mError = FmErrNone; |
|
82 |
|
83 selection.clear(); |
|
84 FmRestoreSettings& rstSettings( *( q->RestoreSettingsL() ) ); |
|
85 rstSettings.GetSelectionL( selection ); |
|
86 QSettings settings("Nokia", "FileManager"); |
|
87 foreach( FmRestoreInfo restoreInfo, selection ) { |
|
88 switch( restoreInfo.content() ) |
|
89 { |
|
90 case FmBkupEngineCommon::EFileManagerBackupContentSettings: |
|
91 settings.beginGroup("BackupSettings"); |
|
92 settings.remove( QString( "" ) ); |
|
93 settings.endGroup(); |
|
94 break; |
|
95 case FmBkupEngineCommon::EFileManagerBackupContentMessages: |
|
96 settings.beginGroup("BackupMessages"); |
|
97 settings.remove( QString( "" ) ); |
|
98 settings.endGroup(); |
|
99 break; |
|
100 case FmBkupEngineCommon::EFileManagerBackupContentContacts: |
|
101 settings.beginGroup("BackupContacts"); |
|
102 settings.remove( QString( "" ) ); |
|
103 settings.endGroup(); |
|
104 break; |
|
105 case FmBkupEngineCommon::EFileManagerBackupContentCalendar: |
|
106 settings.beginGroup("BackupCalendar"); |
|
107 settings.remove( QString( "" ) ); |
|
108 settings.endGroup(); |
|
109 break; |
|
110 case FmBkupEngineCommon::EFileManagerBackupContentBookmarks: |
|
111 settings.beginGroup("BackupBookmarks"); |
|
112 settings.remove( QString( "" ) ); |
|
113 settings.endGroup(); |
|
114 break; |
|
115 case FmBkupEngineCommon::EFileManagerBackupContentUserFiles: |
|
116 settings.beginGroup("BackupUserFiles"); |
|
117 settings.remove( QString( "" ) ); |
|
118 settings.endGroup(); |
|
119 break; |
|
120 default: |
|
121 break; |
|
122 } |
|
123 } |
|
124 |
|
125 |
|
126 |
|
127 return mError; |
|
128 } |
|
129 |
|
130 // TUint32 FmgrToBkupMask( const TUint32 aFmrgMask ); |
|
131 int FmBkupEnginePrivate::error() |
|
132 { |
|
133 return mError; |
|
134 |
|
135 } |
|
136 |
|
137 // |
|
138 bool FmBkupEnginePrivate::StartRestoreL( QList<FmBkupDrivesAndOperation* > drivesAndOperationList ) |
|
139 { |
|
140 selection.clear(); |
|
141 FmRestoreSettings& rstSettings( *( q->RestoreSettingsL() ) ); |
|
142 rstSettings.GetSelectionL( selection ); |
|
143 |
|
144 mError = mBkupThread->asyncRestore( drivesAndOperationList,selection ); |
|
145 return ( mError == FmErrNone ); |
|
146 |
|
147 } |
|
148 |
|
149 |
|
150 void FmBkupEnginePrivate::GetRestoreInfoArray( QList<FmBkupDrivesAndOperation* > drivesAndOperationList, |
|
151 QList< FmRestoreInfo > &restoreInfoList, |
|
152 const QString& aDrive ) |
|
153 { |
|
154 restoreInfoList.clear(); |
|
155 QString debugString; |
|
156 QSettings settings("Nokia", "FileManager"); |
|
157 QDateTime dateTime; |
|
158 |
|
159 settings.beginGroup("BackupSettings"); |
|
160 quint32 content = (settings.value("content", 0).toUInt()); |
|
161 debugString = settings.value( "dateTime").toString(); |
|
162 dateTime.setTime_t( settings.value( "dateTime" ).toUInt() ); |
|
163 QString drive = settings.value( "drive" ).toString(); |
|
164 settings.endGroup(); |
|
165 if( content != 0 && ( drive.contains( aDrive, Qt::CaseInsensitive ) || aDrive.isEmpty() ) ) |
|
166 { |
|
167 FmRestoreInfo restoreInfo( content, dateTime, drive ); |
|
168 restoreInfoList.push_back( restoreInfo ); |
|
169 } |
|
170 |
|
171 settings.beginGroup("BackupMessages"); |
|
172 content = (settings.value("content", 0).toUInt()); |
|
173 dateTime.setTime_t( settings.value( "dateTime" ).toUInt() ); |
|
174 drive = settings.value( "drive" ).toString(); |
|
175 settings.endGroup(); |
|
176 if( content != 0 && ( drive.contains( aDrive, Qt::CaseInsensitive ) || aDrive.isEmpty() ) ) |
|
177 { |
|
178 FmRestoreInfo restoreInfo( content, dateTime, drive ); |
|
179 restoreInfoList.push_back( restoreInfo ); |
|
180 } |
|
181 |
|
182 settings.beginGroup("BackupContacts"); |
|
183 content = (settings.value("content", 0).toUInt()); |
|
184 dateTime.setTime_t( settings.value( "dateTime" ).toUInt() ); |
|
185 drive = settings.value( "drive" ).toString(); |
|
186 settings.endGroup(); |
|
187 if( content != 0 && ( drive.contains( aDrive, Qt::CaseInsensitive ) || aDrive.isEmpty() ) ) |
|
188 { |
|
189 FmRestoreInfo restoreInfo( content, dateTime, drive ); |
|
190 restoreInfoList.push_back( restoreInfo ); |
|
191 } |
|
192 |
|
193 settings.beginGroup("BackupCalendar"); |
|
194 content = (settings.value("content", 0).toUInt()); |
|
195 dateTime.setTime_t( settings.value( "dateTime" ).toUInt() ); |
|
196 drive = settings.value( "drive" ).toString(); |
|
197 settings.endGroup(); |
|
198 if( content != 0 && ( drive.contains( aDrive, Qt::CaseInsensitive ) || aDrive.isEmpty() ) ) |
|
199 { |
|
200 FmRestoreInfo restoreInfo( content, dateTime, drive ); |
|
201 restoreInfoList.push_back( restoreInfo ); |
|
202 } |
|
203 |
|
204 settings.beginGroup("BackupBookmarks"); |
|
205 content = (settings.value("content", 0).toUInt()); |
|
206 dateTime.setTime_t( settings.value( "dateTime" ).toUInt() ); |
|
207 drive = settings.value( "drive" ).toString(); |
|
208 settings.endGroup(); |
|
209 if( content != 0 && ( drive.contains( aDrive, Qt::CaseInsensitive ) || aDrive.isEmpty() ) ) |
|
210 { |
|
211 FmRestoreInfo restoreInfo( content, dateTime, drive ); |
|
212 restoreInfoList.push_back( restoreInfo ); |
|
213 } |
|
214 |
|
215 settings.beginGroup("BackupUserFiles"); |
|
216 content = (settings.value("content", 0).toUInt()); |
|
217 dateTime.setTime_t( settings.value( "dateTime" ).toUInt() ); |
|
218 drive = settings.value( "drive" ).toString(); |
|
219 settings.endGroup(); |
|
220 if( content != 0 && ( drive.contains( aDrive, Qt::CaseInsensitive ) || aDrive.isEmpty() ) ) |
|
221 { |
|
222 FmRestoreInfo restoreInfo( content, dateTime, drive ); |
|
223 restoreInfoList.push_back( restoreInfo ); |
|
224 } |
|
225 |
|
226 } |
|
227 |
|
228 |
|
229 |
|
230 |
|
231 FmBkupThread::FmBkupThread( QObject *parent ) : QThread( parent ), mRunType( RunTypeNone ), mStop( false ) |
|
232 { |
|
233 } |
|
234 |
|
235 FmBkupThread::~FmBkupThread() |
|
236 { |
|
237 |
|
238 } |
|
239 |
|
240 int FmBkupThread::asyncBackup( QList<FmBkupDrivesAndOperation* > drivesAndOperationList, |
|
241 QList<FmBkupBackupCategory*> backupCategoryList,QString drive, quint32 content ) |
|
242 { |
|
243 if( this->isRunning() ){ |
|
244 return FmErrAlreadyStarted; |
|
245 } |
|
246 |
|
247 if( drivesAndOperationList.count() == 0 || backupCategoryList.count() == 0 ){ |
|
248 return FmErrWrongParam; |
|
249 } |
|
250 |
|
251 mRunType = RunTypeBackup; |
|
252 mDrivesAndOperationList.clear(); |
|
253 mBackupCategoryList.clear(); |
|
254 |
|
255 foreach( FmBkupDrivesAndOperation* driversAndOperation , drivesAndOperationList ) { |
|
256 mDrivesAndOperationList.push_back( driversAndOperation ); |
|
257 } |
|
258 foreach( FmBkupBackupCategory* backupCategory , backupCategoryList ) { |
|
259 mBackupCategoryList.push_back( backupCategory ); |
|
260 } |
|
261 |
|
262 mDrive = drive; |
|
263 mContent = content; |
|
264 start(); |
|
265 return FmErrNone; |
|
266 } |
|
267 int FmBkupThread::asyncRestore( QList<FmBkupDrivesAndOperation* > drivesAndOperationList, QList< FmRestoreInfo > selection ) |
|
268 { |
|
269 if( this->isRunning() ) { |
|
270 return FmErrAlreadyStarted; |
|
271 } |
|
272 |
|
273 if( drivesAndOperationList.count() == 0 ){ |
|
274 return FmErrWrongParam; |
|
275 } |
|
276 |
|
277 mRunType = RunTypeRestore; |
|
278 mDrivesAndOperationList.clear(); |
|
279 foreach( FmBkupDrivesAndOperation* driversAndOperation , drivesAndOperationList ) { |
|
280 mDrivesAndOperationList.push_back( driversAndOperation ); |
|
281 } |
|
282 |
|
283 foreach( FmRestoreInfo info , selection ) { |
|
284 mSelection.push_back( info ); |
|
285 } |
|
286 start(); |
|
287 return FmErrNone; |
|
288 } |
|
289 |
|
290 |
|
291 |
|
292 void FmBkupThread::stop() |
|
293 { |
|
294 mStop = true; |
|
295 } |
|
296 |
|
297 |
|
298 |
|
299 |
|
300 void FmBkupThread::run() |
|
301 { |
|
302 mStop = false; |
|
303 |
|
304 |
|
305 if( mRunType == RunTypeBackup ) |
|
306 { |
|
307 emit notifyPreparing( true ); |
|
308 this->sleep( 1 ); |
|
309 emit notifyStart( true, 6 ); |
|
310 |
|
311 QSettings settings("Nokia", "FileManager"); |
|
312 |
|
313 if( mContent && FmBkupEngineCommon::EFileManagerBackupContentSettings ) { |
|
314 settings.beginGroup("BackupSettings"); |
|
315 settings.setValue( "content", FmBkupEngineCommon::EFileManagerBackupContentSettings ); |
|
316 settings.setValue( "dateTime", QDateTime::currentDateTime().toTime_t() ); |
|
317 settings.setValue( "drive", mDrive ); |
|
318 settings.endGroup(); |
|
319 this->msleep( 500 ); |
|
320 emit notifyUpdate( 1 ); |
|
321 if( mStop ) { |
|
322 emit notifyFinish( FmErrCancel ); |
|
323 return; |
|
324 } |
|
325 } |
|
326 if( mContent && FmBkupEngineCommon::EFileManagerBackupContentMessages ) { |
|
327 settings.beginGroup("BackupMessages"); |
|
328 settings.setValue( "content", FmBkupEngineCommon::EFileManagerBackupContentMessages ); |
|
329 settings.setValue( "dateTime", QDateTime::currentDateTime().toTime_t() ); |
|
330 settings.setValue( "drive", mDrive ); |
|
331 settings.endGroup(); |
|
332 this->msleep( 500 ); |
|
333 emit notifyUpdate( 2 ); |
|
334 if( mStop ) { |
|
335 emit notifyFinish( FmErrCancel ); |
|
336 return; |
|
337 } |
|
338 } |
|
339 if ( mContent && FmBkupEngineCommon::EFileManagerBackupContentContacts ) { |
|
340 settings.beginGroup("BackupContacts"); |
|
341 settings.setValue( "content", FmBkupEngineCommon::EFileManagerBackupContentContacts ); |
|
342 settings.setValue( "dateTime", QDateTime::currentDateTime().toTime_t() ); |
|
343 settings.setValue( "drive", mDrive ); |
|
344 settings.endGroup(); |
|
345 this->msleep( 500 ); |
|
346 emit notifyUpdate( 3 ); |
|
347 if( mStop ) { |
|
348 emit notifyFinish( FmErrCancel ); |
|
349 return; |
|
350 } |
|
351 } |
|
352 if ( mContent && FmBkupEngineCommon::EFileManagerBackupContentCalendar ) { |
|
353 settings.beginGroup("BackupCalendar"); |
|
354 settings.setValue( "content", FmBkupEngineCommon::EFileManagerBackupContentCalendar ); |
|
355 settings.setValue( "dateTime", QDateTime::currentDateTime().toTime_t() ); |
|
356 settings.setValue( "drive", mDrive ); |
|
357 settings.endGroup(); |
|
358 this->msleep( 500 ); |
|
359 emit notifyUpdate( 4 ); |
|
360 if( mStop ) { |
|
361 emit notifyFinish( FmErrCancel ); |
|
362 return; |
|
363 } |
|
364 } |
|
365 if ( mContent && FmBkupEngineCommon::EFileManagerBackupContentBookmarks ) { |
|
366 settings.beginGroup("BackupBookmarks"); |
|
367 settings.setValue( "content", FmBkupEngineCommon::EFileManagerBackupContentBookmarks ); |
|
368 settings.setValue( "dateTime", QDateTime::currentDateTime().toTime_t() ); |
|
369 settings.setValue( "drive", mDrive ); |
|
370 settings.endGroup(); |
|
371 this->msleep( 500 ); |
|
372 emit notifyUpdate( 5 ); |
|
373 if( mStop ) { |
|
374 emit notifyFinish( FmErrCancel ); |
|
375 return; |
|
376 } |
|
377 } |
|
378 if ( mContent && FmBkupEngineCommon::EFileManagerBackupContentUserFiles ) { |
|
379 settings.beginGroup("BackupUserFiles"); |
|
380 settings.setValue( "content", FmBkupEngineCommon::EFileManagerBackupContentUserFiles ); |
|
381 settings.setValue( "dateTime", QDateTime::currentDateTime().toTime_t() ); |
|
382 settings.setValue( "drive", mDrive ); |
|
383 settings.endGroup(); |
|
384 emit notifyUpdate( 6 ); |
|
385 if( mStop ) { |
|
386 emit notifyFinish( FmErrCancel ); |
|
387 return; |
|
388 } |
|
389 } |
|
390 } else if( mRunType == RunTypeRestore ) |
|
391 { |
|
392 |
|
393 emit notifyPreparing( false ); |
|
394 this->sleep( 1 ); |
|
395 emit notifyStart( false, 6 ); |
|
396 this->msleep( 500 ); |
|
397 emit notifyUpdate( 1 ); |
|
398 this->msleep( 500 ); |
|
399 emit notifyUpdate( 2 ); |
|
400 this->msleep( 500 ); |
|
401 emit notifyUpdate( 3 ); |
|
402 this->msleep( 500 ); |
|
403 emit notifyUpdate( 4 ); |
|
404 this->msleep( 500 ); |
|
405 emit notifyUpdate( 5 ); |
|
406 this->msleep( 500 ); |
|
407 emit notifyUpdate( 6 ); |
|
408 this->msleep( 500 ); |
|
409 } |
|
410 |
|
411 emit notifyFinish( FmErrNone ); |
|
412 } |
|
413 |
|
414 |
|
415 int FmBkupEnginePrivate::DriverNameToNumber( QString driverName ) |
|
416 { |
|
417 int drive = 0; |
|
418 drive = driverName[0].toUpper().toAscii() - 'A' + 0/*EDriveA*/; |
|
419 return drive; |
|
420 } |
|
421 QString FmBkupEnginePrivate::NumberToDriverName( int driver ) |
|
422 { |
|
423 QChar driverChar( driver - 0/*EDriveA*/ + 'A' ); |
|
424 QString driverName = QString( driverChar ) + ':'; |
|
425 return driverName; |
|
426 } |
|
427 |
|
428 void FmBkupEnginePrivate::getBackupDriveList( QStringList &driveList ) |
|
429 { |
|
430 driveList.append("E:/"); |
|
431 driveList.append("F:/"); |
|
432 } |
|
433 |