26 #include "fmdeletebackupview.h" |
26 #include "fmdeletebackupview.h" |
27 #include "fmsplitview.h" |
27 #include "fmsplitview.h" |
28 #include "fmoperationservice.h" |
28 #include "fmoperationservice.h" |
29 #include "fmoperationbase.h" |
29 #include "fmoperationbase.h" |
30 #include "fmdrivewatcher.h" |
30 #include "fmdrivewatcher.h" |
|
31 #include "fmdialog.h" |
|
32 #include "fmdlgutils.h" |
31 |
33 |
32 #include <hbview.h> |
34 #include <hbview.h> |
33 #include <hbmessagebox.h> |
35 #include <hbmainwindow.h> |
|
36 #include <hbapplication.h> |
|
37 #include <hbactivitymanager.h> |
34 #include <QFileSystemWatcher> |
38 #include <QFileSystemWatcher> |
35 #include <QFileInfo> |
39 #include <QFileInfo> |
36 #include <hbdialog.h> |
40 #include <QPixmap> |
37 |
41 |
38 FmViewManager *FmViewManager::mViewManager = 0; |
42 FmViewManager *FmViewManager::mViewManager = 0; |
39 |
43 |
40 |
44 |
41 FmDlgCloseUnit::FmDlgCloseUnit( HbDialog *dialog ) : mDialog( dialog ) |
45 FmDlgCloseUnit::FmDlgCloseUnit( FmDialog *dialog ) : mDialog( dialog ) |
42 { |
46 { |
43 } |
47 } |
44 FmDlgCloseUnit::~FmDlgCloseUnit() |
48 FmDlgCloseUnit::~FmDlgCloseUnit() |
45 { |
49 { |
46 } |
50 } |
62 QString FmDlgCloseUnit::associatedDrives() |
66 QString FmDlgCloseUnit::associatedDrives() |
63 { |
67 { |
64 return mAssociatedDrives; |
68 return mAssociatedDrives; |
65 } |
69 } |
66 |
70 |
67 HbDialog *FmDlgCloseUnit::dialog() |
71 FmDialog *FmDlgCloseUnit::dialog() |
68 { |
72 { |
69 return mDialog; |
73 return mDialog; |
70 } |
74 } |
71 |
75 |
72 FmViewManager::FmViewManager( FmMainWindow* mainWindow ) |
76 FmViewManager::FmViewManager( FmMainWindow* mainWindow ) : mOperationService( 0 ) |
73 { |
77 { |
74 mMainWindow = mainWindow; |
78 mMainWindow = mainWindow; |
75 mOperationService = new FmOperationService( this ); |
|
76 mOperationService->setObjectName( "operationService" ); |
|
77 |
|
78 mFsWatcher = new QFileSystemWatcher( this ); |
|
79 mFsWatcher->setObjectName( "fsWatcher" ); |
|
80 |
|
81 mDriveWatcher = new FmDriveWatcher( this ); |
79 mDriveWatcher = new FmDriveWatcher( this ); |
82 mDriveWatcher->setObjectName( "driveWatcher" ); |
80 mDriveWatcher->setObjectName( "driveWatcher" ); |
83 mDriveWatcher->startWatch(); |
81 mDriveWatcher->startWatch(); |
84 |
82 |
85 QMetaObject::connectSlotsByName( this ); |
83 QMetaObject::connectSlotsByName( this ); |
86 } |
84 } |
87 |
85 |
88 FmViewManager::~FmViewManager(void) |
86 FmViewManager::~FmViewManager(void) |
89 { |
87 { |
90 |
|
91 FmViewBase *view = static_cast<FmViewBase *>( mMainWindow->currentView() ); |
88 FmViewBase *view = static_cast<FmViewBase *>( mMainWindow->currentView() ); |
92 while( view ) { |
89 while( view ) { |
93 mMainWindow->removeView( view ); |
90 mMainWindow->removeView( view ); |
94 delete view; |
91 delete view; |
95 view = static_cast<FmViewBase *>( mMainWindow->currentView() ); |
92 view = static_cast<FmViewBase *>( mMainWindow->currentView() ); |
96 } |
93 } |
97 |
94 |
98 delete mOperationService; |
95 delete mOperationService; |
99 mOperationService = 0; |
96 mOperationService = 0; |
100 delete mFsWatcher; |
|
101 mFsWatcher = 0; |
|
102 |
97 |
103 mDriveWatcher->cancelWatch(); |
98 mDriveWatcher->cancelWatch(); |
104 delete mDriveWatcher; |
99 delete mDriveWatcher; |
105 mDriveWatcher = 0; |
100 mDriveWatcher = 0; |
106 |
101 |
125 return mViewManager; |
120 return mViewManager; |
126 } |
121 } |
127 |
122 |
128 FmOperationService *FmViewManager::operationService() |
123 FmOperationService *FmViewManager::operationService() |
129 { |
124 { |
|
125 if ( !mOperationService ) { |
|
126 mOperationService = new FmOperationService( this ); |
|
127 mOperationService->setObjectName( "operationService" ); |
|
128 } |
130 return mOperationService; |
129 return mOperationService; |
131 } |
130 } |
132 |
131 |
133 void FmViewManager::popViewAndShow() |
132 void FmViewManager::popViewAndShow() |
134 { |
133 { |
135 FmViewBase *view = static_cast<FmViewBase *>( mMainWindow->currentView() ); |
134 FmViewBase *view = static_cast<FmViewBase *>( mMainWindow->currentView() ); |
136 view->setNavigationAction( 0 ); |
135 view->setNavigationAction( 0 ); |
137 |
136 // grap the screen when only the drive view is in view stack. |
|
137 if( viewCount() == 1 ) { |
|
138 mScreenShot = QPixmap::grabWidget(mMainWindow, mMainWindow->rect()); |
|
139 } |
138 mMainWindow->removeView( view ); |
140 mMainWindow->removeView( view ); |
139 delete view; |
141 delete view; |
140 |
142 |
141 if( viewCount() < 1 ) |
143 if( viewCount() < 1 ) |
142 { |
144 { |
143 mMainWindow->close(); |
145 mMainWindow->close(); |
144 } |
146 } |
145 } |
147 } |
146 |
148 |
147 void FmViewManager::on_operationService_refreshModel( FmOperationBase *operationBase, const QString &path ) |
149 void FmViewManager::on_operationService_driveSpaceChanged( FmOperationBase *operationBase ) |
148 { |
150 { |
149 Q_UNUSED( operationBase ); |
151 Q_UNUSED( operationBase ); |
150 emit refreshModel( path ); |
152 // request drive view to refresh |
|
153 emit driveSpaceChanged(); |
|
154 } |
|
155 |
|
156 void FmViewManager::on_operationService_notifyFinish( FmOperationBase *operationBase ) |
|
157 { |
|
158 if( !operationBase ){ |
|
159 Q_ASSERT_X( false, "FmViewManager", |
|
160 "NULL is not accepted in on_operationService_notifyFinish()" ); |
|
161 return; |
|
162 } |
|
163 |
|
164 if( operationBase->operationType() == FmOperationService::EOperationTypeBackup ) |
|
165 { |
|
166 // after finish backup, we need refresh backup date in backup view. |
|
167 emit refreshBackupDate(); |
|
168 } |
151 } |
169 } |
152 |
170 |
153 |
171 |
154 int FmViewManager::viewCount() |
172 int FmViewManager::viewCount() |
155 { |
173 { |
156 return mMainWindow->viewCount(); |
174 return mMainWindow->views().count(); |
157 } |
175 } |
158 |
176 |
159 |
177 |
160 void FmViewManager::createDriverView() |
178 void FmViewManager::createDriverView() |
161 { |
179 { |
162 FmDriverView *driverView= new FmDriverView(); |
180 FmDriverView *driverView= new FmDriverView(); |
163 |
181 |
164 mMainWindow->addView( driverView ); |
182 mMainWindow->addView( driverView ); |
165 mMainWindow->setCurrentView( driverView ); |
183 mMainWindow->setCurrentView( driverView ); |
166 |
184 HbActivityManager* activityManager = qobject_cast<HbApplication*>(qApp)->activityManager(); |
167 connect( this, SIGNAL( refreshModel( QString ) ), |
185 bool ok = activityManager->removeActivity("FMMemoryStoragesList"); |
168 driverView, SLOT( refreshModel( QString ) ) ); |
186 |
|
187 connect( this, SIGNAL( driveSpaceChanged() ), |
|
188 driverView, SLOT( refreshDrive() ) ); |
|
189 // Refresh drive view when gaining foreground |
|
190 // ( switch back to filemanager from home screen or any other applications ) |
|
191 connect( mMainWindow, SIGNAL( revealed() ), |
|
192 driverView, SLOT( refreshDrive() ) ); |
|
193 |
|
194 // use Qt::QueuedConnection because synchronous refresh is not work well while |
|
195 // connected with another OTG device which have more than one external drive in it. |
|
196 // File server only give driveChanged event once, but two drive is inserted. |
|
197 // Synchronous refresh will miss another drive. |
|
198 // So use Qt::QueuedConnection to performance asynchronous refresh. |
|
199 connect( this, SIGNAL( driveChanged() ), |
|
200 driverView, SLOT( refreshDrive() ), Qt::QueuedConnection ); |
169 } |
201 } |
170 |
202 |
171 void FmViewManager::createFileView( const QString &path, |
203 void FmViewManager::createFileView( const QString &path, |
172 bool enableBackPathCheck, bool disableFind ) |
204 bool enableBackPathCheck, bool disableFind ) |
173 { |
205 { |
174 QFileInfo fileInfo( path ); |
206 QFileInfo fileInfo( path ); |
175 QString absolutePath = fileInfo.absoluteFilePath(); |
207 QString absolutePath = fileInfo.absoluteFilePath(); |
176 |
208 |
177 QString checkedPath = FmUtils::checkDriveToFolderFilter( absolutePath ); |
209 QString checkedPath = FmUtils::checkDriveToFolderFilter( absolutePath ); |
178 FmDriverInfo::DriveState driveState = FmUtils::queryDriverInfo( path ).driveState(); |
210 if( FmUtils::isDriveAvailable( path ) ) { |
179 if( driveState & FmDriverInfo::EDriveAvailable ) { |
211 if( FmErrNone != FmUtils::isPathAccessabel( checkedPath ) ) { |
180 if( !FmUtils::isPathAccessabel( checkedPath ) ) { |
|
181 checkedPath.clear(); |
212 checkedPath.clear(); |
182 } |
213 } |
183 } |
214 } |
184 |
215 |
185 if( checkedPath.isEmpty() ) { |
216 if( checkedPath.isEmpty() ) { |
186 HbMessageBox::information( QString( hbTrId("Path: %1 is unavailable!").arg( path )) ); |
217 FmDlgUtils::information( QString( hbTrId("Path: %1 is unavailable!").arg( path )) ); |
187 return; |
218 return; |
188 } |
219 } |
189 |
220 |
190 FmFileView *fileView= new FmFileView(); |
221 FmFileView *fileView= new FmFileView(); |
191 fileView->setRootPath( checkedPath ); |
222 fileView->setRootPath( checkedPath ); |
196 fileView->setFindDisabled( disableFind ); |
227 fileView->setFindDisabled( disableFind ); |
197 |
228 |
198 mMainWindow->addView( fileView ); |
229 mMainWindow->addView( fileView ); |
199 mMainWindow->setCurrentView( fileView ); |
230 mMainWindow->setCurrentView( fileView ); |
200 |
231 |
201 connect( this, SIGNAL( refreshModel( const QString& ) ), //emit when need refresh models |
232 connect( this, SIGNAL( driveChanged() ), //emit when drive changed. |
202 fileView, SLOT( refreshModel( const QString& ) ) ); |
233 fileView, SLOT( on_driveChanged() ) ); |
203 |
234 |
204 connect( fileView, SIGNAL( popViewAndShow() ), //emit when fileView need delete itself and pop&show view from stack. |
235 connect( fileView, SIGNAL( popViewAndShow() ), //emit when fileView need delete itself and pop&show view from stack. |
205 this, SLOT( popViewAndShow() ), Qt::QueuedConnection ); |
236 this, SLOT( popViewAndShow() ), Qt::QueuedConnection ); |
206 } |
237 } |
207 |
238 |
227 { |
258 { |
228 FmBackupView *backupView= new FmBackupView(); |
259 FmBackupView *backupView= new FmBackupView(); |
229 |
260 |
230 mMainWindow->addView( backupView ); |
261 mMainWindow->addView( backupView ); |
231 mMainWindow->setCurrentView( backupView ); |
262 mMainWindow->setCurrentView( backupView ); |
232 |
263 connect( this, SIGNAL( driveChanged() ), //emit when need refresh model |
|
264 backupView, SLOT( refreshModel() ) ); |
|
265 connect( this, SIGNAL( refreshBackupDate() ), //emit when need refresh backup date |
|
266 backupView, SLOT( refreshBackupDate() ) ); |
233 } |
267 } |
234 |
268 |
235 void FmViewManager::createRestoreView() |
269 void FmViewManager::createRestoreView() |
236 { |
270 { |
237 FmRestoreView *restoreView= new FmRestoreView(); |
271 FmRestoreView *restoreView= new FmRestoreView(); |
238 |
272 |
239 mMainWindow->addView( restoreView ); |
273 mMainWindow->addView( restoreView ); |
240 mMainWindow->setCurrentView( restoreView ); |
274 mMainWindow->setCurrentView( restoreView ); |
|
275 connect( this, SIGNAL( driveChanged() ), restoreView, SLOT( refreshRestoreView() ) ); |
241 |
276 |
242 } |
277 } |
243 |
278 |
244 void FmViewManager::createDeleteBackupView() |
279 void FmViewManager::createDeleteBackupView() |
245 { |
280 { |
246 FmDeleteBackupView *deleteBackupView= new FmDeleteBackupView(); |
281 FmDeleteBackupView *deleteBackupView= new FmDeleteBackupView(); |
247 |
282 |
248 mMainWindow->addView( deleteBackupView ); |
283 mMainWindow->addView( deleteBackupView ); |
249 mMainWindow->setCurrentView( deleteBackupView ); |
284 mMainWindow->setCurrentView( deleteBackupView ); |
|
285 connect( this, SIGNAL( driveChanged() ), deleteBackupView, SLOT( refreshDeleteBackupView() ) ); |
250 |
286 |
251 } |
287 } |
252 |
288 |
253 Qt::Orientation FmViewManager::orientation(){ |
289 Qt::Orientation FmViewManager::orientation(){ |
254 return mMainWindow->orientation(); |
290 return mMainWindow->orientation(); |
255 } |
291 } |
256 |
292 |
257 void FmViewManager::on_fsWatcher_fileChanged(const QString &path) |
|
258 { |
|
259 emit refreshModel( path ); |
|
260 } |
|
261 void FmViewManager::on_fsWatcher_directoryChanged(const QString &path) |
|
262 { |
|
263 emit refreshModel( path ); |
|
264 } |
|
265 void FmViewManager::addWatchPath( const QString &path ) |
|
266 { |
|
267 mFsWatcher->addPath( path ); |
|
268 } |
|
269 void FmViewManager::removeWatchPath( const QString &path ) |
|
270 { |
|
271 if( !mViewManager || !mFsWatcher ) { |
|
272 return; |
|
273 } |
|
274 mFsWatcher->removePath( path ); |
|
275 } |
|
276 |
|
277 |
|
278 void FmViewManager::on_driveWatcher_driveAddedOrChanged() |
293 void FmViewManager::on_driveWatcher_driveAddedOrChanged() |
279 { |
294 { |
280 FmLogger::log( QString( "FmViewManager::on_driveWatcher_driveAddedOrChanged start" ) ); |
295 FM_LOG( QString( "FmViewManager::on_driveWatcher_driveAddedOrChanged start" ) ); |
281 emit refreshModel( QString("") ); |
296 emit driveChanged(); |
282 checkDlgCloseUnit(); |
297 checkDlgCloseUnit(); |
283 FmLogger::log( QString( "FmViewManager::on_driveWatcher_driveAddedOrChanged end" ) ); |
298 FM_LOG( QString( "FmViewManager::on_driveWatcher_driveAddedOrChanged end" ) ); |
284 |
299 |
285 } |
300 } |
286 |
301 |
287 |
302 |
288 void FmViewManager::checkDlgCloseUnit() |
303 void FmViewManager::checkDlgCloseUnit() |
290 foreach( FmDlgCloseUnit* unit, mDlgCloseUnitList ) { |
305 foreach( FmDlgCloseUnit* unit, mDlgCloseUnitList ) { |
291 QString drives( unit->associatedDrives() ); |
306 QString drives( unit->associatedDrives() ); |
292 for( int i = 0; i < drives.length(); i++ ) { |
307 for( int i = 0; i < drives.length(); i++ ) { |
293 QString drive( drives[i] + QString( ":/" ) ); |
308 QString drive( drives[i] + QString( ":/" ) ); |
294 if( !FmUtils::isDriveAvailable( drive ) ) { |
309 if( !FmUtils::isDriveAvailable( drive ) ) { |
295 FmLogger::log( " close Dialog start " ); |
310 FM_LOG( " close Dialog start " ); |
296 unit->dialog()->close(); |
311 unit->dialog()->close(); |
297 FmLogger::log( " close Dialog end " ); |
312 FM_LOG( " close Dialog end " ); |
298 } |
313 } |
299 } |
314 } |
300 } |
315 } |
301 } |
316 } |
|
317 |
|
318 void FmViewManager::saveActivity() |
|
319 { |
|
320 //grap the screen when current view is drive view. |
|
321 FmDriverView *driveView = qobject_cast<FmDriverView *>(mMainWindow->currentView()); |
|
322 if ( ( driveView != 0 ) && ( driveView->viewType() == FmViewBase::EDriverView ) ) { |
|
323 mScreenShot = QPixmap::grabWidget(mMainWindow, mMainWindow->rect()); |
|
324 } |
|
325 QVariantHash metadata; |
|
326 metadata.insert("screenshot", mScreenShot); |
|
327 HbActivityManager* activityManager = qobject_cast<HbApplication*>(qApp)->activityManager(); |
|
328 // add the activity to the activity manager |
|
329 bool ok = activityManager->addActivity("FMMemoryStoragesList", QVariant(), metadata); |
|
330 if ( !ok ) |
|
331 { |
|
332 qFatal("Add failed" ); |
|
333 } |
|
334 |
|
335 } |
|
336 |
|
337 void FmViewManager::onAboutToChangeView(HbView * oldView, HbView *newView) |
|
338 { |
|
339 Q_UNUSED(newView); |
|
340 //grap the screen when oldView is drive view. |
|
341 FmDriverView *driveView = qobject_cast<FmDriverView *>(oldView); |
|
342 if ( ( driveView != 0 ) && ( driveView->viewType() == FmViewBase::EDriverView ) ) { |
|
343 mScreenShot = QPixmap::grabWidget(mMainWindow, mMainWindow->rect()); |
|
344 } |
|
345 } |