66 //take the model out from view and delete it. |
68 //take the model out from view and delete it. |
67 //so that the model could be destroy earlier |
69 //so that the model could be destroy earlier |
68 //since there is a thread running in background |
70 //since there is a thread running in background |
69 //if the model destroy later, the thread might not quit properly. |
71 //if the model destroy later, the thread might not quit properly. |
70 |
72 |
71 QFileInfo oldFileInfo = mModel->fileInfo( mListView->rootIndex() ); |
73 if( mStyle == ListStyle || mStyle == TreeStyle ) { |
72 FmViewManager *viewManager = FmViewManager::viewManager(); |
74 QFileInfo oldFileInfo = mModel->fileInfo( mListView->rootIndex() ); |
73 if( viewManager ) { |
75 if( oldFileInfo.exists() ) { |
74 viewManager->removeWatchPath( oldFileInfo.absoluteFilePath() ); |
76 FmViewManager *viewManager = FmViewManager::viewManager(); |
|
77 if( viewManager ) { |
|
78 viewManager->removeWatchPath( oldFileInfo.absoluteFilePath() ); |
|
79 } |
|
80 } |
75 } |
81 } |
76 |
82 |
77 mTreeView->setModel( 0 ); |
83 mTreeView->setModel( 0 ); |
78 mListView->setModel( 0 ); |
84 mListView->setModel( 0 ); |
79 delete mModel; |
85 delete mModel; |
115 void FmFileBrowseWidget::setRootPath( const QString &pathName ) |
121 void FmFileBrowseWidget::setRootPath( const QString &pathName ) |
116 { |
122 { |
117 QString logString = "FmFileBrowseWidget::setRootPath(" + pathName + ')'; |
123 QString logString = "FmFileBrowseWidget::setRootPath(" + pathName + ')'; |
118 FmLogger::log( logString ); |
124 FmLogger::log( logString ); |
119 |
125 |
120 QModelIndex modelIndex = mModel->index( pathName ); |
126 if( checkPathAndSetStyle( pathName ) ) { |
121 bool i = QFileInfo(pathName).exists(); |
127 mListView->setModel(0); |
122 QString string2; |
128 mTreeView->setModel(0); |
123 if( i ) |
129 delete mModel; |
124 { |
130 mModel = new QDirModel(this); |
125 string2 = QString( "true" ) ; |
131 mListView->setModel(mModel); |
126 } |
132 mTreeView->setModel(mModel); |
127 else |
133 |
128 { |
134 mListView->setRootIndex( mModel->index( pathName ) ); |
129 string2 = QString( "false" ) ; |
135 mTreeView->setRootIndex( mModel->index( pathName ) ); |
130 } |
136 FmViewManager::viewManager()->addWatchPath( pathName ); |
131 |
137 } |
132 logString = "FmFileBrowseWidget::setRootPath exists(" + string2 + ')'; |
138 mCurrentDrive = pathName.left( 3 ); |
133 FmLogger::log( logString ); |
|
134 |
|
135 mModel->refresh(modelIndex); |
|
136 QString string = mModel->fileName( modelIndex ); |
|
137 logString = "FmFileBrowseWidget::setRootPath:filename(" + string + ')'; |
|
138 FmLogger::log( logString ); |
|
139 |
|
140 string = mModel->filePath( modelIndex ); |
|
141 logString = "FmFileBrowseWidget::setRootPath:filepath(" + string + ')'; |
|
142 FmLogger::log( logString ); |
|
143 |
|
144 |
|
145 FmViewManager::viewManager()->addWatchPath( pathName ); |
|
146 |
|
147 mListView->setRootIndex( mModel->index( pathName ) ); |
|
148 mTreeView->setRootIndex( mModel->index( pathName ) ); |
|
149 } |
139 } |
150 |
140 |
151 void FmFileBrowseWidget::setStyle( FmFileBrowseWidget::Style style ) |
141 void FmFileBrowseWidget::setStyle( FmFileBrowseWidget::Style style ) |
152 { |
142 { |
153 if ( mStyle == style ) { |
143 if ( mStyle == style ) { |
158 mLayout->removeItem( mListView ); |
148 mLayout->removeItem( mListView ); |
159 mListView->hide(); |
149 mListView->hide(); |
160 } else if ( mStyle == TreeStyle ) { |
150 } else if ( mStyle == TreeStyle ) { |
161 mLayout->removeItem( mTreeView ); |
151 mLayout->removeItem( mTreeView ); |
162 mTreeView->hide(); |
152 mTreeView->hide(); |
163 } |
153 } else if( mStyle == LabelStyle ){ |
|
154 mLayout->removeItem( mEmptyTipLabel ); |
|
155 mEmptyTipLabel->hide(); |
|
156 } |
164 |
157 |
165 if ( style == ListStyle ) { |
158 if ( style == ListStyle ) { |
166 mLayout->addItem( mListView ); |
159 mLayout->addItem( mListView ); |
167 mListView->show(); |
160 mListView->show(); |
|
161 mFileBrowseStyle = ListStyle; |
168 } else if ( style == TreeStyle ) { |
162 } else if ( style == TreeStyle ) { |
169 mLayout->addItem( mTreeView ); |
163 mLayout->addItem( mTreeView ); |
170 mTreeView->show(); |
164 mTreeView->show(); |
|
165 mFileBrowseStyle = TreeStyle; |
|
166 } else if ( style == LabelStyle ){ |
|
167 mLayout->addItem( mEmptyTipLabel ); |
|
168 mEmptyTipLabel->show(); |
171 } |
169 } |
172 |
170 |
173 mStyle = style; |
171 mStyle = style; |
174 } |
172 } |
175 |
173 |
260 HbMenu *contextMenu = new HbMenu(); |
261 HbMenu *contextMenu = new HbMenu(); |
261 mCurrentItem = item; |
262 mCurrentItem = item; |
262 |
263 |
263 HbAction *viewAction = new HbAction(); |
264 HbAction *viewAction = new HbAction(); |
264 viewAction->setObjectName( "viewAction" ); |
265 viewAction->setObjectName( "viewAction" ); |
265 viewAction->setText( tr( "View details" ) ); |
266 viewAction->setText( hbTrId( "txt_fmgr_menu_view_details_file" ) ); |
266 contextMenu->addAction( viewAction ); |
267 contextMenu->addAction( viewAction ); |
267 |
268 |
268 connect( viewAction, SIGNAL( triggered() ), |
269 connect( viewAction, SIGNAL( triggered() ), |
269 this, SLOT( on_viewAction_triggered() ) ); |
270 this, SLOT( on_viewAction_triggered() ) ); |
270 |
271 |
271 //copy |
272 //copy |
272 HbAction *copyAction = new HbAction(); |
273 HbAction *copyAction = new HbAction(); |
273 copyAction->setObjectName( "copyAction" ); |
274 copyAction->setObjectName( "copyAction" ); |
274 copyAction->setText( tr( "Copy" ) ); |
275 copyAction->setText( hbTrId( "txt_fmgr_menu_copy" ) ); |
275 contextMenu->addAction( copyAction ); |
276 contextMenu->addAction( copyAction ); |
276 |
277 |
277 connect( copyAction, SIGNAL( triggered() ), |
278 connect( copyAction, SIGNAL( triggered() ), |
278 this, SLOT( on_copyAction_triggered() ) ); |
279 this, SLOT( on_copyAction_triggered() ) ); |
279 |
280 |
280 //Move |
281 |
281 HbAction *moveAction = new HbAction(); |
282 QString filePath( mModel->filePath( item->modelIndex() ) ); |
282 moveAction->setObjectName( "moveAction" ); |
283 QString formatFilePath( FmUtils::formatPath( filePath ) ); |
283 moveAction->setText( tr( "Move" ) ); |
284 QFileInfo fileInfo( filePath ); |
284 contextMenu->addAction( moveAction ); |
285 |
285 |
286 if( ( fileInfo.isFile() ) || ( fileInfo.isDir() && !( FmUtils::isDefaultFolder( formatFilePath ) ) ) ){ |
286 connect( moveAction, SIGNAL( triggered() ), |
287 //Move |
287 this, SLOT( on_moveAction_triggered() ) ); |
288 HbAction *moveAction = new HbAction(); |
288 |
289 moveAction->setObjectName( "moveAction" ); |
289 //Delete |
290 moveAction->setText( hbTrId( "txt_fmgr_menu_move" ) ); |
290 HbAction *deleteAction = new HbAction(); |
291 contextMenu->addAction( moveAction ); |
291 deleteAction->setObjectName( "deleteAction" ); |
292 |
292 deleteAction->setText( tr( "Delete" ) ); |
293 connect( moveAction, SIGNAL( triggered() ), |
293 contextMenu->addAction( deleteAction ); |
294 this, SLOT( on_moveAction_triggered() ) ); |
294 |
295 |
295 connect( deleteAction, SIGNAL( triggered() ), |
296 //Delete |
296 this, SLOT( on_deleteAction_triggered() ) ); |
297 HbAction *deleteAction = new HbAction(); |
297 |
298 deleteAction->setObjectName( "deleteAction" ); |
298 //rename |
299 deleteAction->setText( hbTrId( "txt_fmgr_menu_delete" ) ); |
299 HbAction *renameAction = new HbAction(); |
300 contextMenu->addAction( deleteAction ); |
300 renameAction->setObjectName( "renameAction" ); |
301 |
301 renameAction->setText( tr( "Rename" ) ); |
302 connect( deleteAction, SIGNAL( triggered() ), |
302 contextMenu->addAction( renameAction ); |
303 this, SLOT( on_deleteAction_triggered() ) ); |
303 |
304 |
304 connect( renameAction, SIGNAL( triggered() ), |
305 //rename |
305 this, SLOT( on_renameAction_triggered() ) ); |
306 HbAction *renameAction = new HbAction(); |
306 |
307 renameAction->setObjectName( "renameAction" ); |
307 //remove send action as it can not be used |
308 renameAction->setText( hbTrId( "txt_fmgr_menu_rename" ) ); |
308 // HbAction *sendAction = new HbAction(); |
309 contextMenu->addAction( renameAction ); |
309 // sendAction->setObjectName( "sendAction" ); |
310 |
310 // sendAction->setText( tr( "Send" ) ); |
311 connect( renameAction, SIGNAL( triggered() ), |
311 // contextMenu->addAction( sendAction ); |
312 this, SLOT( on_renameAction_triggered() ) ); |
312 // |
313 } |
313 // connect( sendAction, SIGNAL( triggered() ), |
314 |
314 // this, SLOT( on_sendAction_triggered() ) ); |
315 // if( fileInfo.isFile() ){ |
|
316 // HbAction *sendAction = new HbAction(); |
|
317 // sendAction->setObjectName( "sendAction" ); |
|
318 // sendAction->setText( hbTrId( "txt_fmgr_menu_send" ) ); |
|
319 // contextMenu->addAction( sendAction ); |
|
320 // |
|
321 // connect( sendAction, SIGNAL( triggered() ), |
|
322 // this, SLOT( on_sendAction_triggered() ) ); |
|
323 // } |
315 |
324 |
316 contextMenu->exec( coords ); |
325 contextMenu->exec( coords ); |
317 } |
326 } |
318 |
327 |
319 void FmFileBrowseWidget::on_tree_longPressed( HbAbstractViewItem *item, const QPointF &coords ) |
328 void FmFileBrowseWidget::on_tree_longPressed( HbAbstractViewItem *item, const QPointF &coords ) |
435 mModel->setFilter( filters ); |
451 mModel->setFilter( filters ); |
436 } |
452 } |
437 |
453 |
438 void FmFileBrowseWidget::refreshModel( const QString& path ) |
454 void FmFileBrowseWidget::refreshModel( const QString& path ) |
439 { |
455 { |
440 if( !path.isEmpty() ) { |
456 QString currPath( currentPath().absoluteFilePath() ); |
441 mModel->refresh( mModel->index( path ) ); |
457 QString refreshPath( path ); |
442 } |
458 |
|
459 if( !currPath.isEmpty() ) { |
|
460 if( refreshPath.isEmpty() ) { |
|
461 refreshPath = currPath; |
|
462 } |
|
463 if( !FmUtils::isPathEqual( refreshPath, currPath ) ) { |
|
464 // no need refresh other path |
|
465 return; |
|
466 } |
|
467 if( checkPathAndSetStyle( refreshPath ) ) { |
|
468 mModel->refresh( mModel->index( refreshPath ) ); |
|
469 } else { |
|
470 FmViewManager *viewManager = FmViewManager::viewManager(); |
|
471 if( viewManager ) { |
|
472 viewManager->removeWatchPath( currentPath().absoluteFilePath() ); |
|
473 } |
|
474 } |
|
475 } else { |
|
476 // current path is empty, so change root path to Drive root. |
|
477 refreshPath = mCurrentDrive; |
|
478 setRootPath( refreshPath ); |
|
479 emit setTitle( FmUtils::fillDriveVolume( mCurrentDrive, true ) ); |
|
480 } |
|
481 } |
|
482 |
|
483 bool FmFileBrowseWidget::checkPathAndSetStyle( const QString& path ) |
|
484 { |
|
485 if( !FmUtils::isPathAccessabel( path ) ){ |
|
486 QString driveName = FmUtils::getDriveNameFromPath( path ); |
|
487 FmDriverInfo::DriveState state = FmUtils::queryDriverInfo( driveName ).driveState(); |
|
488 |
|
489 if( state & FmDriverInfo::EDriveLocked ) { |
|
490 mEmptyTipLabel->setPlainText( hbTrId( "Memory Card is locked" ) ); |
|
491 } else if( state & FmDriverInfo::EDriveNotPresent ) { |
|
492 mEmptyTipLabel->setPlainText( hbTrId( "Memory Card is not present" ) ); |
|
493 } else if( state & FmDriverInfo::EDriveCorrupted ) { |
|
494 mEmptyTipLabel->setPlainText( hbTrId( "Drive is Corrupted" ) ); |
|
495 } else { |
|
496 mEmptyTipLabel->setPlainText( hbTrId( "Drive can not be opened " ) ); |
|
497 } |
|
498 setStyle( LabelStyle ); |
|
499 emit setEmptyMenu( true ); |
|
500 return false; |
|
501 } else { |
|
502 setStyle( mFileBrowseStyle ); |
|
503 emit setEmptyMenu( false ); |
|
504 return true; |
|
505 } |
|
506 |
443 } |
507 } |
444 |
508 |
445 void FmFileBrowseWidget::sortFiles( TSortType sortType ) |
509 void FmFileBrowseWidget::sortFiles( TSortType sortType ) |
446 { |
510 { |
447 switch( sortType ){ |
511 switch( sortType ){ |
511 |
575 |
512 if( fileInfo.isDir() ){ |
576 if( fileInfo.isDir() ){ |
513 mOperationService->asyncViewFolderDetails( filePath ); |
577 mOperationService->asyncViewFolderDetails( filePath ); |
514 } |
578 } |
515 else if( fileInfo.isFile() ){ |
579 else if( fileInfo.isFile() ){ |
516 FmViewDetailsDialog::showFileViewDetailsDialog( filePath ); |
580 FmViewDetailsDialog::showFileViewDetailsDialog( filePath, FmUtils::getDriveLetterFromPath( filePath ) ); |
517 } |
581 } |
518 } |
582 } |
519 |
583 |
520 void FmFileBrowseWidget::on_deleteAction_triggered() |
584 void FmFileBrowseWidget::on_deleteAction_triggered() |
521 { |
585 { |
522 QStringList fileList; |
586 QStringList fileList; |
523 fileList.push_back( mModel->filePath( mCurrentItem->modelIndex() ) ); |
587 fileList.push_back( mModel->filePath( mCurrentItem->modelIndex() ) ); |
524 if ( HbMessageBox::question( tr("Confirm Deletion?" ) )) { |
588 if ( HbMessageBox::question( hbTrId("Confirm Deletion?" ) )) { |
525 int ret = mOperationService->asyncRemove( fileList ); |
589 int ret = mOperationService->asyncRemove( fileList ); |
526 switch( ret ) { |
590 switch( ret ) { |
527 case FmErrNone: |
591 case FmErrNone: |
528 // no error, do not show note to user |
592 // no error, do not show note to user |
529 break; |
593 break; |
530 case FmErrAlreadyStarted: |
594 case FmErrAlreadyStarted: |
531 // last operation have not finished |
595 // last operation have not finished |
532 HbMessageBox::information( tr( "Operatin already started!" ) ); |
596 HbMessageBox::information( hbTrId( "Operatin already started!" ) ); |
533 break; |
597 break; |
534 case FmErrWrongParam: |
598 case FmErrWrongParam: |
535 HbMessageBox::information( tr( "Wrong parameters!" ) ); |
599 HbMessageBox::information( hbTrId( "Wrong parameters!" ) ); |
536 break; |
600 break; |
537 default: |
601 default: |
538 HbMessageBox::information( tr( "Operation fail to start!" ) ); |
602 HbMessageBox::information( hbTrId( "Operation fail to start!" ) ); |
539 } |
603 } |
540 } |
604 } |
541 } |
605 } |
542 |
606 |
543 void FmFileBrowseWidget::on_copyAction_triggered() |
607 void FmFileBrowseWidget::on_copyAction_triggered() |
544 { |
608 { |
545 QStringList srcFileList; |
609 QStringList srcFileList; |
546 srcFileList.push_back( mModel->filePath( mCurrentItem->modelIndex() ) ); |
610 srcFileList.push_back( mModel->filePath( mCurrentItem->modelIndex() ) ); |
547 |
611 |
548 QString targetPathName = FmFileDialog::getExistingDirectory( 0, tr( "copy to" ), |
612 QString targetPathName = FmFileDialog::getExistingDirectory( 0, hbTrId( "copy to" ), |
549 QString(""), QStringList() ); |
613 QString(""), QStringList() ); |
550 if( !targetPathName.isEmpty() ) { |
614 if( !targetPathName.isEmpty() ) { |
551 targetPathName = FmUtils::fillPathWithSplash( targetPathName ); |
615 targetPathName = FmUtils::fillPathWithSplash( targetPathName ); |
552 |
616 |
553 int ret = mOperationService->asyncCopy( |
617 int ret = mOperationService->asyncCopy( |
605 QString filePath = mModel->filePath( mCurrentItem->modelIndex() ); |
669 QString filePath = mModel->filePath( mCurrentItem->modelIndex() ); |
606 QFileInfo fileInfo = mModel->fileInfo( mCurrentItem->modelIndex() ); |
670 QFileInfo fileInfo = mModel->fileInfo( mCurrentItem->modelIndex() ); |
607 |
671 |
608 QString newName( fileInfo.fileName() ); |
672 QString newName( fileInfo.fileName() ); |
609 |
673 |
610 while( FmDlgUtils::showTextQuery( tr( "Enter new name for %1" ).arg( newName ), newName ) ){ |
674 while( FmDlgUtils::showTextQuery( hbTrId( "Enter new name for %1" ).arg( newName ), newName, true ) ){ |
611 QString newTargetPath = FmUtils::fillPathWithSplash( |
675 QString newTargetPath = FmUtils::fillPathWithSplash( |
612 fileInfo.absolutePath() ) + newName; |
676 fileInfo.absolutePath() ) + newName; |
613 QFileInfo newFileInfo( newTargetPath ); |
677 QFileInfo newFileInfo( newTargetPath ); |
614 if( newFileInfo.exists() ) { |
678 if( newFileInfo.exists() ) { |
615 HbMessageBox::information( tr( "%1 already exist!" ).arg( newName ) ); |
679 HbMessageBox::information( hbTrId( "%1 already exist!" ).arg( newName ) ); |
616 continue; |
680 continue; |
617 } |
681 } |
618 |
682 |
619 if( !rename( fileInfo.absoluteFilePath(), newTargetPath ) ) { |
683 if( !rename( fileInfo.absoluteFilePath(), newTargetPath ) ) { |
620 HbMessageBox::information( tr("Rename failed!") ); |
684 HbMessageBox::information( hbTrId("Rename failed!") ); |
621 } |
685 } |
622 break; |
686 break; |
623 } |
687 } |
624 |
688 } |
625 |
|
626 } |
|