filemanager/src/filemanager/src/fmfileview.cpp
changeset 37 15bc28c9dd51
parent 16 ada7962b4308
child 46 d58987eac7e8
equal deleted inserted replaced
16:ada7962b4308 37:15bc28c9dd51
    32 #include <hbinstance.h>
    32 #include <hbinstance.h>
    33 #include <hbmenu.h>
    33 #include <hbmenu.h>
    34 #include <hbaction.h>
    34 #include <hbaction.h>
    35 #include <hbtoolbar.h>
    35 #include <hbtoolbar.h>
    36 #include <hblineedit.h>
    36 #include <hblineedit.h>
    37 #include <hbmessagebox.h>
       
    38 #include <hbpushbutton.h>
    37 #include <hbpushbutton.h>
    39 #include <hbmainwindow.h>
    38 #include <hbmainwindow.h>
    40 
    39 
    41 FmFileView::FmFileView() : FmViewBase( EFileView ), mWidget( 0 ),
    40 FmFileView::FmFileView() : FmViewBase( EFileView ), mWidget( 0 ),
    42     mUpButton( 0 ), mStyleAction( 0 ), mSelectableAction( 0 ),
    41     mUpButton( 0 ), mStyleAction( 0 ), mSelectableAction( 0 ),
    43     mFindAction( 0 ), mOperationService( 0 ), mMenu( 0 ) 
    42     mFindAction( 0 ), mOperationService( 0 ), mMenu( 0 ), mIsFindDisabled( false )
    44 {
    43 {
    45     mOperationService = FmViewManager::viewManager()->operationService();
    44     mOperationService = FmViewManager::viewManager()->operationService();
    46 	initMenu();
    45 	initMenu();
    47 	initMainWidget();
    46 	initMainWidget();
    48     initToolBar();
    47     initToolBar();
    92     rootLevelPath = FmUtils::fillPathWithSplash( pathName );
    91     rootLevelPath = FmUtils::fillPathWithSplash( pathName );
    93 }
    92 }
    94 
    93 
    95 void FmFileView::setFindDisabled( bool disable )
    94 void FmFileView::setFindDisabled( bool disable )
    96 {
    95 {
       
    96     mIsFindDisabled = disable;
    97     if( mFindAction ) {
    97     if( mFindAction ) {
    98         mFindAction->setDisabled( disable );
    98         mFindAction->setDisabled( mIsFindDisabled );
    99     }
    99     }
   100 }
   100 }
   101 
   101 
   102 void FmFileView::initMenu()
   102 void FmFileView::initMenu()
   103 {
   103 {
   107 	action->setObjectName( "rotateAction" );
   107 	action->setObjectName( "rotateAction" );
   108 	action->setText( hbTrId( "Change orientation" ) );
   108 	action->setText( hbTrId( "Change orientation" ) );
   109 	menu()->addAction( action );
   109 	menu()->addAction( action );
   110 #endif
   110 #endif
   111 
   111 
   112 	mStyleAction = new HbAction( this );
   112 //	mStyleAction = new HbAction();
   113 	mStyleAction->setObjectName( "switchStyle" );
   113 //	mStyleAction->setObjectName( "switchStyle" );
   114 //	menu()->addAction( mStyleAction );
   114 //	menu()->addAction( mStyleAction );
   115 
   115 
   116 	mSelectableAction = new HbAction( this );
   116 	mSelectableAction = new HbAction();
   117 	mSelectableAction->setObjectName( "setSelectable" );
   117 	mSelectableAction->setObjectName( "setSelectable" );
   118 	menu()->addAction( mSelectableAction );
   118 	menu()->addAction( mSelectableAction );
   119 
   119     connect( mSelectableAction, SIGNAL( triggered() ),
   120 	action = new HbAction( this );
   120         this, SLOT( on_setSelectable_triggered() ), Qt::QueuedConnection );
       
   121 
       
   122 
       
   123 	action = new HbAction();
   121 	action->setObjectName( "delete" );
   124 	action->setObjectName( "delete" );
   122 	action->setText( hbTrId( "txt_fmgr_menu_delete" ) );
   125 	action->setText( hbTrId( "txt_fmgr_menu_delete" ) );
   123 	menu()->addAction( action );
   126 	menu()->addAction( action );
   124 
   127     connect( action, SIGNAL( triggered() ),
   125     action = new HbAction( this );
   128         this, SLOT( on_delete_triggered() ), Qt::QueuedConnection );
       
   129 
       
   130     action = new HbAction();
   126     action->setObjectName( "copy" );
   131     action->setObjectName( "copy" );
   127     action->setText( hbTrId( "txt_fmgr_menu_copy" ) );
   132     action->setText( hbTrId( "txt_fmgr_menu_copy" ) );
   128     menu()->addAction( action );
   133     menu()->addAction( action );
   129 
   134     connect( action, SIGNAL( triggered() ),
   130     action = new HbAction( this );
   135         this, SLOT( on_copy_triggered() ), Qt::QueuedConnection );
       
   136 
       
   137     action = new HbAction();
   131     action->setObjectName( "move" );
   138     action->setObjectName( "move" );
   132     action->setText( hbTrId( "txt_fmgr_menu_move" ) );
   139     action->setText( hbTrId( "txt_fmgr_menu_move" ) );
   133     menu()->addAction( action );
   140     menu()->addAction( action );
   134     
   141     connect( action, SIGNAL( triggered() ),
   135     action = new HbAction( this );
   142         this, SLOT( on_move_triggered() ), Qt::QueuedConnection );
       
   143     
       
   144     action = new HbAction();
   136     action->setObjectName( "newFolder" );
   145     action->setObjectName( "newFolder" );
   137     action->setText( hbTrId( "New Folder" ) );
   146     action->setText( hbTrId( "txt_fmgr_opt_new_folder" ) );
   138     menu()->addAction( action );
   147     menu()->addAction( action );
       
   148     connect( action, SIGNAL( triggered() ),
       
   149         this, SLOT( on_newFolder_triggered() ), Qt::QueuedConnection );
   139     
   150     
   140     HbMenu *subMenu = new HbMenu( hbTrId( "Sort" ) );
   151     HbMenu *subMenu = new HbMenu( hbTrId( "Sort" ) );
   141     HbAction *sortNameAction = new HbAction( subMenu );
   152     HbAction *sortNameAction = new HbAction( subMenu );
   142     sortNameAction->setObjectName( "sortNameAction" );
   153     sortNameAction->setObjectName( "sortNameAction" );
   143     sortNameAction->setText( hbTrId( "Sort by name" ) );
   154     sortNameAction->setText( hbTrId( "Sort by name" ) );
   159     subMenu->addAction( sortTypeAction );
   170     subMenu->addAction( sortTypeAction );
   160     
   171     
   161     menu()->addMenu( subMenu );
   172     menu()->addMenu( subMenu );
   162 	
   173 	
   163     connect( sortNameAction, SIGNAL( triggered() ),
   174     connect( sortNameAction, SIGNAL( triggered() ),
   164              this, SLOT( on_sortNameAction_triggered() ) );
   175              this, SLOT( on_sortNameAction_triggered() ), Qt::QueuedConnection );
   165     connect( sortTimeAction, SIGNAL( triggered() ),
   176     connect( sortTimeAction, SIGNAL( triggered() ),
   166              this, SLOT( on_sortTimeAction_triggered() ) );
   177              this, SLOT( on_sortTimeAction_triggered() ), Qt::QueuedConnection );
   167     connect( sortSizeAction, SIGNAL( triggered() ),
   178     connect( sortSizeAction, SIGNAL( triggered() ),
   168              this, SLOT( on_sortSizeAction_triggered() ) );
   179              this, SLOT( on_sortSizeAction_triggered() ), Qt::QueuedConnection );
   169     connect( sortTypeAction, SIGNAL( triggered() ),
   180     connect( sortTypeAction, SIGNAL( triggered() ),
   170              this, SLOT( on_sortTypeAction_triggered() ) );
   181              this, SLOT( on_sortTypeAction_triggered() ), Qt::QueuedConnection );
   171     
   182     
   172     mMenu = takeMenu();
   183     mMenu = takeMenu();
   173 }
   184 }
   174 
   185 
   175 void FmFileView::initMainWidget()
   186 void FmFileView::initMainWidget()
   200 {
   211 {
   201     toolBar()->clearActions();
   212     toolBar()->clearActions();
   202     mFindAction = new HbAction( this );
   213     mFindAction = new HbAction( this );
   203     mFindAction->setObjectName( "leftAction" );
   214     mFindAction->setObjectName( "leftAction" );
   204     mFindAction->setText( hbTrId("txt_fmgr_opt_find") );
   215     mFindAction->setText( hbTrId("txt_fmgr_opt_find") );
       
   216     mFindAction->setDisabled( mIsFindDisabled );
   205     toolBar()->addAction( mFindAction );
   217     toolBar()->addAction( mFindAction );
   206 
   218 
   207     mToolBarRightAction = new HbAction( this );
   219     mToolBarRightAction = new HbAction( this );
   208     mToolBarRightAction->setObjectName( "rightAction" );
   220     mToolBarRightAction->setObjectName( "rightAction" );
   209     mToolBarRightAction->setText( hbTrId( "up" ) );
   221     mToolBarRightAction->setText( hbTrId( "up" ) );
   213     
   225     
   214     //mToolBar = takeToolBar();
   226     //mToolBar = takeToolBar();
   215     connect( mFindAction, SIGNAL( triggered() ),
   227     connect( mFindAction, SIGNAL( triggered() ),
   216                  this, SLOT( on_leftAction_triggered() ) );
   228                  this, SLOT( on_leftAction_triggered() ) );
   217     connect( mToolBarRightAction, SIGNAL( triggered() ),
   229     connect( mToolBarRightAction, SIGNAL( triggered() ),
   218              this, SLOT( on_rightAction_triggered() ) );
   230              this, SLOT( on_rightAction_triggered() ), Qt::QueuedConnection );
   219     
   231     
   220 }
   232 }
   221 
   233 
   222 void FmFileView::setStyle( FmFileBrowseWidget::Style style )
   234 void FmFileView::setStyle( FmFileBrowseWidget::Style style )
   223 {
   235 {
       
   236     /*
   224 	if ( style == FmFileBrowseWidget::ListStyle ) {
   237 	if ( style == FmFileBrowseWidget::ListStyle ) {
   225 		mStyleAction->setText( hbTrId("Tree") );
   238 		mStyleAction->setText( hbTrId("Tree") );
   226 	} else if ( style == FmFileBrowseWidget::TreeStyle ) {
   239 	} else if ( style == FmFileBrowseWidget::TreeStyle ) {
   227 		mStyleAction->setText( hbTrId("List") );
   240 		mStyleAction->setText( hbTrId("List") );
   228 	}
   241 	}
   229 	
   242 	*/
   230 	mWidget->setStyle( style );
   243 	mWidget->setStyle( style );
   231 }
   244 }
   232 
   245 
   233 void FmFileView::setSelectable( bool enable )
   246 void FmFileView::setSelectable( bool enable )
   234 {
   247 {
   241 	mWidget->setSelectable( enable );
   254 	mWidget->setSelectable( enable );
   242 }
   255 }
   243 
   256 
   244 void FmFileView::infoNoFileSelected()
   257 void FmFileView::infoNoFileSelected()
   245 {
   258 {
   246 	HbMessageBox::information( tr("No File/Folder selected" ) );
   259 	FmDlgUtils::information( hbTrId("No File/Folder selected" ) );
   247 }
   260 }
   248 
   261 
   249 #ifdef FM_CHANGE_ORIENT_ENABLE
   262 #ifdef FM_CHANGE_ORIENT_ENABLE
   250 void FmFileView::on_rotateAction_triggered()
   263 void FmFileView::on_rotateAction_triggered()
   251 {
   264 {
   276 {
   289 {
   277 	QList<QFileInfo> files = mWidget->checkedItems();
   290 	QList<QFileInfo> files = mWidget->checkedItems();
   278     if (files.size() == 0) {
   291     if (files.size() == 0) {
   279 		infoNoFileSelected();
   292 		infoNoFileSelected();
   280     } else {
   293     } else {
   281         if (HbMessageBox::question( tr("Confirm Deletion?" ) )) {
   294         if (FmDlgUtils::question( hbTrId("Confirm Deletion?" ) )) {
   282             QStringList fileList;
   295             QStringList fileList;
   283             for (int i = 0; i < files.size(); ++i) {
   296             for (int i = 0; i < files.size(); ++i) {
   284                 fileList.push_back( files[i].absoluteFilePath() );
   297                 fileList.push_back( files[i].absoluteFilePath() );
   285                 }
   298                 }
   286             int ret = mOperationService->asyncRemove( fileList );
   299             int ret = mOperationService->asyncRemove( fileList );
   288                 case FmErrNone:
   301                 case FmErrNone:
   289                     // no error, do not show note to user
   302                     // no error, do not show note to user
   290                     break;
   303                     break;
   291                 case FmErrAlreadyStarted:
   304                 case FmErrAlreadyStarted:
   292                     // last operation have not finished
   305                     // last operation have not finished
   293                     HbMessageBox::information( hbTrId( "Operatin already started!" ) );
   306                     FmDlgUtils::information( hbTrId( "Operatin already started!" ) );
   294                     break;
   307                     break;
   295                 case FmErrWrongParam:
   308                 case FmErrWrongParam:
   296                     HbMessageBox::information( hbTrId( "Wrong parameters!" ) );
   309                     FmDlgUtils::information( hbTrId( "Wrong parameters!" ) );
   297                     break;
   310                     break;
   298                 default:
   311                 default:
   299                     HbMessageBox::information( hbTrId( "Operation fail to start!" ) );
   312                     FmDlgUtils::information( hbTrId( "Operation fail to start!" ) );
   300             }
   313             }
   301             setSelectable( false );
   314             setSelectable( false );
   302         }
   315         }
   303     }
   316     }
   304 }
   317 }
   326                 case FmErrNone:
   339                 case FmErrNone:
   327                     // no error, do not show note to user
   340                     // no error, do not show note to user
   328                     break;
   341                     break;
   329                 case FmErrAlreadyStarted:
   342                 case FmErrAlreadyStarted:
   330                     // last operation have not finished
   343                     // last operation have not finished
   331                     HbMessageBox::information( hbTrId( "Operatin already started!" ) );
   344                     FmDlgUtils::information( hbTrId( "Operatin already started!" ) );
   332                     break;
   345                     break;
   333                 case FmErrWrongParam:
   346                 case FmErrWrongParam:
   334                     HbMessageBox::information( hbTrId( "Wrong parameters!" ) );
   347                     FmDlgUtils::information( hbTrId( "Wrong parameters!" ) );
   335                     break;
   348                     break;
   336                 default:
   349                 default:
   337                     HbMessageBox::information( hbTrId( "Operation fail to start!" ) );
   350                     FmDlgUtils::information( hbTrId( "Operation fail to start!" ) );
   338             }
   351             }
   339             setSelectable( false );
   352             setSelectable( false );
   340         }
   353         }
   341     }
   354     }
   342 
   355 
   347     QList<QFileInfo> files = mWidget->checkedItems();
   360     QList<QFileInfo> files = mWidget->checkedItems();
   348 
   361 
   349     if (files.size() == 0) {
   362     if (files.size() == 0) {
   350         infoNoFileSelected();
   363         infoNoFileSelected();
   351     } else {
   364     } else {
   352         QString targetPathName = FmFileDialog::getExistingDirectory( 0, tr( "move to" ),
   365         QString targetPathName = FmFileDialog::getExistingDirectory( 0, hbTrId( "move to" ),
   353             QString(""), QStringList() );
   366             QString(""), QStringList() );
   354 
   367 
   355         if( !targetPathName.isEmpty() && files.size() > 0 ) {
   368         if( !targetPathName.isEmpty() && files.size() > 0 ) {
   356             targetPathName = FmUtils::fillPathWithSplash( targetPathName );
   369             targetPathName = FmUtils::fillPathWithSplash( targetPathName );
   357 
   370 
   364                 case FmErrNone:
   377                 case FmErrNone:
   365                     // no error, do not show note to user
   378                     // no error, do not show note to user
   366                     break;
   379                     break;
   367                 case FmErrAlreadyStarted:
   380                 case FmErrAlreadyStarted:
   368                     // last operation have not finished
   381                     // last operation have not finished
   369                     HbMessageBox::information( tr( "Operatin already started!" ) );
   382                     FmDlgUtils::information( hbTrId( "Operatin already started!" ) );
   370                     break;
   383                     break;
   371                 case FmErrWrongParam:
   384                 case FmErrWrongParam:
   372                     HbMessageBox::information( tr( "Wrong parameters!" ) );
   385                     FmDlgUtils::information( hbTrId( "Wrong parameters!" ) );
   373                     break;
   386                     break;
   374                 default:
   387                 default:
   375                     HbMessageBox::information( tr( "Operation fail to start!" ) );
   388                     FmDlgUtils::information( hbTrId( "Operation fail to start!" ) );
   376             }
   389             }
   377             setSelectable( false );
   390             setSelectable( false );
   378         }
   391         }
   379     }
   392     }
   380 }
   393 }
   381 
   394 
   382 void FmFileView::on_newFolder_triggered()
   395 void FmFileView::on_newFolder_triggered()
   383 {
   396 {
   384     QString dirName;
   397     int maxFileNameLength = FmUtils::getMaxFileNameLength();
       
   398     QString associatedDrive = FmUtils::getDriveLetterFromPath( mWidget->currentPath().absoluteFilePath() );
   385     QString path = FmUtils::fillPathWithSplash( mWidget->currentPath().absoluteFilePath() );
   399     QString path = FmUtils::fillPathWithSplash( mWidget->currentPath().absoluteFilePath() );
   386     QDir dir( path );
   400     QString dirName = createDefaultFolderName( path );
       
   401     QStringList regExpList = (QStringList() << Regex_ValidFileFolderName << Regex_ValidNotEndWithDot );
       
   402 
       
   403     QDir dir( path );  
   387     if( dir.exists() ) {
   404     if( dir.exists() ) {
   388         while( FmDlgUtils::showTextQuery( hbTrId( "Enter name for " ), dirName, true ) ){
   405         while( FmDlgUtils::showTextQuery( hbTrId( "txt_fmgr_title_new_folder" ), dirName,
   389                 QString newTargetPath = FmUtils::fillPathWithSplash(
   406             regExpList, maxFileNameLength, associatedDrive , false ) ){
   390                     dir.absolutePath() ) + dirName;
   407             // remove whitespace from the start and the end.
   391                 QFileInfo newFileInfo( newTargetPath );
   408             dirName = dirName.trimmed();
   392                 if( newFileInfo.exists() ) {
   409             QString newTargetPath = FmUtils::fillPathWithSplash(
   393                     HbMessageBox::information( hbTrId( "%1 already exist!" ).arg( dirName ) );
   410                 dir.absolutePath() ) + dirName;
   394                     continue;
   411             QString errString;
   395                 }
   412             // check if name/path is available for use
   396     
   413             if( !FmUtils::checkNewFolderOrFile( dirName, newTargetPath, errString ) ) {
   397                 if( !dir.mkdir( dirName ) ) {
   414                 FmDlgUtils::information( errString );
   398                     HbMessageBox::information( hbTrId("Operation failed!") );
   415                 continue;
   399                 }
   416             }
   400                 refreshModel( path );
   417             if( !dir.mkdir( dirName ) ) {
   401                 break;
   418                 FmDlgUtils::information( hbTrId("Operation failed!") );
   402             }
   419             }
       
   420             break;
       
   421         }
   403         
   422         
   404     }
   423     }
   405 }
   424 }
       
   425 
   406 void FmFileView::on_upAction_triggered()
   426 void FmFileView::on_upAction_triggered()
   407 {
   427 {
   408 	mWidget->cdUp();
   428 	mWidget->cdUp();
   409 }
   429 }
   410 
   430 
   411 void FmFileView::on_leftAction_triggered()
   431 void FmFileView::on_leftAction_triggered()
   412 {
   432 {
   413 //    FmFindDialog findDialog;
       
   414 //    QString keyword;
       
   415 //    QString findFolder;
       
   416 //    bool ret = findDialog.exec( keyword, findFolder );
       
   417 //
       
   418 //    if ( ret && !keyword.isEmpty() && !findFolder.isEmpty() )
       
   419 //        FmViewManager::viewManager()->createFindView( keyword, findFolder );
       
   420     mWidget->activeSearchPanel();
   433     mWidget->activeSearchPanel();
   421 }
   434 }
   422 
   435 
   423 void FmFileView::on_rightAction_triggered()
   436 void FmFileView::on_rightAction_triggered()
   424 {
   437 {
   431 		//hbInstance->allMainWindows()[0]->softKeyAction(Hb::SecondarySoftKey)->trigger();
   444 		//hbInstance->allMainWindows()[0]->softKeyAction(Hb::SecondarySoftKey)->trigger();
   432         emit popViewAndShow();
   445         emit popViewAndShow();
   433 	}
   446 	}
   434 }
   447 }
   435 
   448 
   436 void FmFileView::refreshModel( const QString &path )
   449 void FmFileView::on_driveChanged()
   437 {
   450 {
   438     mWidget->refreshModel( path );  
   451     mWidget->on_driveChanged();  
   439 }
   452 }
   440 
   453 
   441 void FmFileView::on_sortNameAction_triggered()
   454 void FmFileView::on_sortNameAction_triggered()
   442 {
   455 {
   443     mWidget->sortFiles( FmFileBrowseWidget::ESortByName );
   456     mWidget->sortFiles( FmFileBrowseWidget::ESortByName );
   471 }
   484 }
   472 
   485 
   473 void FmFileView::on_mainWidget_setEmptyMenu( bool isMenuEmpty )
   486 void FmFileView::on_mainWidget_setEmptyMenu( bool isMenuEmpty )
   474 {
   487 {
   475     if( isMenuEmpty ){
   488     if( isMenuEmpty ){
   476         FmLogger::log( "setEmptyMenu true" );
   489         FM_LOG( "setEmptyMenu true" );
   477         if( !mMenu ) {
   490         if( !mMenu ) {
   478             mMenu = takeMenu();
   491             mMenu = takeMenu();
   479         }
   492         }
   480         toolBar()->clearActions();
   493         toolBar()->clearActions();
   481     }
   494     }
   482     else {
   495     else {
   483         FmLogger::log( "setEmptyMenu false" );
   496         FM_LOG( "setEmptyMenu false" );
   484         if( mMenu ) {
   497         if( mMenu ) {
   485             setMenu( mMenu );
   498             setMenu( mMenu );
   486             mMenu = 0;
   499             mMenu = 0;
   487         }
   500         }
   488         initToolBar();
   501         initToolBar();
   491 
   504 
   492 void FmFileView::on_mainWidget_setTitle( const QString &title )
   505 void FmFileView::on_mainWidget_setTitle( const QString &title )
   493 {
   506 {
   494     this->setTitle( title );
   507     this->setTitle( title );
   495 }
   508 }
       
   509 
       
   510 QString FmFileView::createDefaultFolderName( const QString &path )
       
   511 {
       
   512     // create new folder name, for example, New folder(01), New folder(02)
       
   513     QString checkedPath( FmUtils::fillPathWithSplash( path ) );
       
   514     QString dirName( hbTrId( "txt_fmgr_dialog_entry_new_folder" ) );
       
   515     QString dirAbsolutePath( checkedPath + dirName );
       
   516     QFileInfo fileInfo( dirAbsolutePath );
       
   517     int i = 0;    
       
   518     while ( fileInfo.exists() ) {
       
   519         ++i;
       
   520 		QString numName;
       
   521         if ( i < 10 ) {
       
   522             numName.append( QString::number(0) );                        
       
   523         }
       
   524         numName.append( QString::number(i) );
       
   525         // txt_fmgr_dialog_entry_new_folder_l1 is not available now. use actual text instead of it.
       
   526         dirName = hbTrId( "New folder (%L1)" ).arg( numName );
       
   527         dirAbsolutePath = checkedPath + dirName;
       
   528         fileInfo.setFile( dirAbsolutePath );
       
   529     }
       
   530     return dirName;
       
   531 }