15 * The source file of the operation thread of file manager |
15 * The source file of the operation thread of file manager |
16 * |
16 * |
17 */ |
17 */ |
18 |
18 |
19 #include "fmoperationthread.h" |
19 #include "fmoperationthread.h" |
20 #include "fmoperationbase.h" |
20 #include "fmbackuprestorehandler.h" |
21 #include "fmdrivedetailstype.h" |
|
22 #include "fmcommon.h" |
|
23 #include "fmoperationcopy.h" |
|
24 #include "fmoperationmove.h" |
|
25 #include "fmoperationremove.h" |
|
26 #include "fmoperationformat.h" |
|
27 |
21 |
28 #include <QDir> |
22 #include <QDir> |
29 #include <QStack> |
23 #include <QStack> |
30 |
24 |
31 FmOperationThread::FmOperationThread( QObject *parent ) : QThread( parent ), mOperationBase( 0 ) |
25 /* |
|
26 * Constructs the operation thread with \a parent. |
|
27 */ |
|
28 FmOperationThread::FmOperationThread( QObject *parent ) : QThread( parent ), |
|
29 mStop( false), mOperationBase( 0 ) |
32 { |
30 { |
33 |
31 setPriority( LowestPriority ); |
34 |
|
35 } |
32 } |
36 |
33 |
|
34 /* |
|
35 * Destructs the operation thread. |
|
36 */ |
37 FmOperationThread::~FmOperationThread() |
37 FmOperationThread::~FmOperationThread() |
38 { |
38 { |
39 } |
39 } |
40 |
40 |
41 int FmOperationThread::asyncCopy( FmOperationBase* operationBase ) |
41 /* |
42 { |
42 * Prepare some conditions before starts the operation. |
43 if( isRunning() ){ |
43 * Returns the error id. |
44 return FmErrAlreadyStarted; |
44 * \a operationBase the operation to be prepared. |
|
45 */ |
|
46 int FmOperationThread::prepareOperationAndStart( FmOperationBase* operationBase ) |
|
47 { |
|
48 if ( isRunning() ) { |
|
49 return FmErrAlreadyStarted; |
45 } |
50 } |
46 |
|
47 mOperationBase = operationBase; |
51 mOperationBase = operationBase; |
48 mOperationBase->setObjectName( "operationElement" ); |
52 int ret = mOperationBase->prepare(); |
49 QMetaObject::connectSlotsByName( this ); |
53 if ( ret == FmErrNone ) { |
50 connect( mOperationBase, SIGNAL( askForRename( QString, QString* ) ), |
54 mStop = false; |
51 this, SLOT( onAskForRename( QString, QString* )), Qt::BlockingQueuedConnection ); |
55 start(); |
52 connect( mOperationBase, SIGNAL( askForReplace( QString, QString, bool* ) ), |
56 } |
53 this, SLOT( onAskForReplace( QString, QString, bool* )), Qt::BlockingQueuedConnection ); |
57 return ret; |
54 |
|
55 start(); |
|
56 return FmErrNone; |
|
57 } |
58 } |
58 |
59 |
59 int FmOperationThread::asyncMove( FmOperationBase* operationBase ) |
60 /* Stops the current thread. |
60 { |
61 * Caused by user interaction. |
61 if( isRunning() ){ |
62 */ |
62 return FmErrAlreadyStarted; |
|
63 } |
|
64 |
|
65 mOperationBase = operationBase; |
|
66 mOperationBase->setObjectName( "operationElement" ); |
|
67 QMetaObject::connectSlotsByName( this ); |
|
68 connect( mOperationBase, SIGNAL( askForRename( QString, QString* ) ), |
|
69 this, SLOT( onAskForRename( QString, QString* )), Qt::BlockingQueuedConnection ); |
|
70 connect( mOperationBase, SIGNAL( askForReplace( QString, QString, bool* ) ), |
|
71 this, SLOT( onAskForReplace( QString, QString, bool* )), Qt::BlockingQueuedConnection ); |
|
72 |
|
73 |
|
74 start(); |
|
75 return FmErrNone; |
|
76 } |
|
77 |
|
78 int FmOperationThread::asyncRemove( FmOperationBase* operationBase ) |
|
79 { |
|
80 if( isRunning() ){ |
|
81 return FmErrAlreadyStarted; |
|
82 } |
|
83 |
|
84 mOperationBase = operationBase; |
|
85 mOperationBase->setObjectName( "operationElement" ); |
|
86 QMetaObject::connectSlotsByName( this ); |
|
87 |
|
88 start(); |
|
89 return FmErrNone; |
|
90 } |
|
91 |
|
92 int FmOperationThread::asyncFormat( FmOperationBase* operationBase ) |
|
93 { |
|
94 if( isRunning() ){ |
|
95 return FmErrAlreadyStarted; |
|
96 } |
|
97 |
|
98 mOperationBase = operationBase; |
|
99 mOperationBase->setObjectName( "operationElement" ); |
|
100 QMetaObject::connectSlotsByName( this ); |
|
101 |
|
102 start(); |
|
103 return FmErrNone; |
|
104 } |
|
105 int FmOperationThread::asyncViewDriveDetails( FmOperationBase* operationBase ) |
|
106 { |
|
107 if( isRunning() ){ |
|
108 return FmErrAlreadyStarted; |
|
109 } |
|
110 |
|
111 mOperationBase = operationBase; |
|
112 mOperationBase->setObjectName( "operationElement" ); |
|
113 QMetaObject::connectSlotsByName( this ); |
|
114 |
|
115 start(); |
|
116 return FmErrNone; |
|
117 } |
|
118 |
|
119 int FmOperationThread::asyncViewFolderDetails( FmOperationBase* operationBase ) |
|
120 { |
|
121 if( isRunning() ){ |
|
122 return FmErrAlreadyStarted; |
|
123 } |
|
124 |
|
125 mOperationBase = operationBase; |
|
126 mOperationBase->setObjectName( "operationElement" ); |
|
127 QMetaObject::connectSlotsByName( this ); |
|
128 |
|
129 start(); |
|
130 return FmErrNone; |
|
131 } |
|
132 |
|
133 |
|
134 void FmOperationThread::stop() |
63 void FmOperationThread::stop() |
135 { |
64 { |
136 mStop = true; |
65 mStop = true; |
137 } |
66 } |
138 |
67 |
139 void FmOperationThread::onAskForRename( const QString &srcFile, QString *destFile ) |
68 /* |
140 { |
69 * reimp |
141 emit askForRename( srcFile, destFile ); |
70 */ |
142 } |
71 void FmOperationThread::run() |
143 void FmOperationThread::onAskForReplace( const QString &srcFile, const QString &destFile, bool *isAccepted ) |
72 { |
144 { |
73 mOperationBase->start( &mStop ); |
145 emit askForReplace( srcFile, destFile, isAccepted ); |
|
146 } |
|
147 void FmOperationThread::on_operationElement_notifyPreparing( bool cancelable ) |
|
148 { |
|
149 emit notifyPreparing( cancelable ); |
|
150 } |
|
151 void FmOperationThread::on_operationElement_notifyStart( bool cancelable, int maxSteps ) |
|
152 { |
|
153 emit notifyStart( cancelable, maxSteps ); |
|
154 } |
|
155 void FmOperationThread::on_operationElement_notifyProgress( int currentStep ) |
|
156 { |
|
157 emit notifyProgress( currentStep ); |
|
158 } |
74 } |
159 |
75 |
160 void FmOperationThread::run() |
|
161 { |
|
162 mStop = false; |
|
163 this->setPriority( LowestPriority ); |
|
164 switch( mOperationBase->operationType() ) |
|
165 { |
|
166 case FmOperationService::EOperationTypeCopy: |
|
167 { |
|
168 mErrString.clear(); |
|
169 FmOperationCopy *operationCopy = static_cast<FmOperationCopy*>(mOperationBase); |
|
170 |
|
171 int ret = operationCopy->start( &mStop, &mErrString ); |
|
172 switch( ret ) |
|
173 { |
|
174 case FmErrCancel: |
|
175 emit notifyCanceled(); |
|
176 break; |
|
177 case FmErrNone: |
|
178 emit notifyFinish(); |
|
179 break; |
|
180 default: |
|
181 emit notifyError( ret, mErrString ); |
|
182 break; |
|
183 } |
|
184 // refresh driveview no care if cancel, error or finished. |
|
185 emit refreshModel( QString("") ); |
|
186 break; |
|
187 } |
|
188 case FmOperationService::EOperationTypeMove: |
|
189 { |
|
190 mErrString.clear(); |
|
191 FmOperationMove *operationMove = static_cast<FmOperationMove*>(mOperationBase); |
|
192 |
|
193 QString refreshSrcPath = QFileInfo( operationMove->sourceList().front() ).dir().absolutePath(); |
|
194 |
|
195 int ret = operationMove->start( &mStop, &mErrString ); |
|
196 switch( ret ) |
|
197 { |
|
198 case FmErrCancel: |
|
199 emit notifyCanceled(); |
|
200 break; |
|
201 case FmErrNone: |
|
202 emit notifyFinish(); |
|
203 emit refreshModel( refreshSrcPath ); |
|
204 emit refreshModel( operationMove->targetPath() ); |
|
205 break; |
|
206 default: |
|
207 emit notifyError( ret, mErrString ); |
|
208 } |
|
209 // refresh driveview no care if cancel, error or finished. |
|
210 emit refreshModel( QString("") ); |
|
211 break; |
|
212 } |
|
213 case FmOperationService::EOperationTypeRemove: |
|
214 { |
|
215 mErrString.clear(); |
|
216 FmOperationRemove *operationRemove = static_cast<FmOperationRemove*>(mOperationBase); |
|
217 |
|
218 QString refreshSrcPath = QFileInfo( operationRemove->pathList().front() ).dir().absolutePath(); |
|
219 |
|
220 int ret = operationRemove->start( &mStop, &mErrString ); |
|
221 switch( ret ) |
|
222 { |
|
223 case FmErrCancel: |
|
224 emit notifyCanceled(); |
|
225 break; |
|
226 case FmErrNone: |
|
227 emit notifyFinish(); |
|
228 break; |
|
229 default: |
|
230 emit notifyError( ret, mErrString ); |
|
231 } |
|
232 // refresh driveview no care if cancel, error or finished. |
|
233 emit refreshModel( QString("") ); |
|
234 break; |
|
235 } |
|
236 case FmOperationService::EOperationTypeFormat: |
|
237 { |
|
238 // emit notifyWaiting( false ); |
|
239 FmLogger::log(QString("start format")); |
|
240 FmOperationFormat *operationFormat = static_cast<FmOperationFormat*>( mOperationBase ); |
|
241 FmLogger::log(QString("get param and start format")); |
|
242 |
|
243 QString refreshSrcPath = operationFormat->driverName(); |
|
244 // if ( FmErrNone != FmUtils::formatDrive( operationFormat->driverName() ) ) { |
|
245 if ( FmErrNone != operationFormat->start() ) { |
|
246 emit notifyError( FmErrTypeFormatFailed, operationFormat->driverName() ); |
|
247 return; |
|
248 } |
|
249 FmLogger::log(QString("format done")); |
|
250 emit notifyFinish(); |
|
251 emit refreshModel( refreshSrcPath ); |
|
252 FmLogger::log(QString("format done and emit finish")); |
|
253 break; |
|
254 } |
|
255 case FmOperationService::EOperationTypeDriveDetails: |
|
256 { |
|
257 emit notifyWaiting( true ); |
|
258 |
|
259 FmOperationDriveDetails *operationDriverDetails = static_cast<FmOperationDriveDetails*>( mOperationBase ); |
|
260 int ret = FmDriveDetailsContent::querySizeofContent( |
|
261 operationDriverDetails->driverName(), operationDriverDetails->detailsSizeList(), &mStop ); |
|
262 if( ret == FmErrNone ) { |
|
263 emit notifyFinish(); |
|
264 } else if( ret == FmErrCancel ) { |
|
265 emit notifyCanceled(); |
|
266 } |
|
267 |
|
268 break; |
|
269 } |
|
270 case FmOperationService::EOperationTypeFolderDetails: |
|
271 { |
|
272 emit notifyWaiting( true ); |
|
273 |
|
274 FmOperationFolderDetails *operationFolderDetails = static_cast<FmOperationFolderDetails*>( mOperationBase ); |
|
275 int ret = FmFolderDetails::getNumofSubfolders( operationFolderDetails->folderPath(), operationFolderDetails->numofSubFolders(), |
|
276 operationFolderDetails->numofFiles(), operationFolderDetails->sizeofFolder(), |
|
277 &mStop ); |
|
278 if( ret == FmErrNone ) { |
|
279 emit notifyFinish(); |
|
280 } else if( ret == FmErrCancel ) { |
|
281 emit notifyCanceled(); |
|
282 } |
|
283 |
|
284 break; |
|
285 |
|
286 } |
|
287 default: |
|
288 Q_ASSERT( false ); |
|
289 |
|
290 } |
|
291 } |
|
292 |
|