filemanager/src/filemanager/src/fmfileview.cpp
changeset 25 b7bfdea70ca2
parent 16 ada7962b4308
child 27 df183af6b92f
equal deleted inserted replaced
16:ada7962b4308 25:b7bfdea70ca2
    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 ),
   107 	action->setObjectName( "rotateAction" );
   106 	action->setObjectName( "rotateAction" );
   108 	action->setText( hbTrId( "Change orientation" ) );
   107 	action->setText( hbTrId( "Change orientation" ) );
   109 	menu()->addAction( action );
   108 	menu()->addAction( action );
   110 #endif
   109 #endif
   111 
   110 
   112 	mStyleAction = new HbAction( this );
   111 //	mStyleAction = new HbAction();
   113 	mStyleAction->setObjectName( "switchStyle" );
   112 //	mStyleAction->setObjectName( "switchStyle" );
   114 //	menu()->addAction( mStyleAction );
   113 //	menu()->addAction( mStyleAction );
   115 
   114 
   116 	mSelectableAction = new HbAction( this );
   115 	mSelectableAction = new HbAction();
   117 	mSelectableAction->setObjectName( "setSelectable" );
   116 	mSelectableAction->setObjectName( "setSelectable" );
   118 	menu()->addAction( mSelectableAction );
   117 	menu()->addAction( mSelectableAction );
   119 
   118     connect( mSelectableAction, SIGNAL( triggered() ),
   120 	action = new HbAction( this );
   119         this, SLOT( on_setSelectable_triggered() ), Qt::QueuedConnection );
       
   120 
       
   121 
       
   122 	action = new HbAction();
   121 	action->setObjectName( "delete" );
   123 	action->setObjectName( "delete" );
   122 	action->setText( hbTrId( "txt_fmgr_menu_delete" ) );
   124 	action->setText( hbTrId( "txt_fmgr_menu_delete" ) );
   123 	menu()->addAction( action );
   125 	menu()->addAction( action );
   124 
   126     connect( action, SIGNAL( triggered() ),
   125     action = new HbAction( this );
   127         this, SLOT( on_delete_triggered() ), Qt::QueuedConnection );
       
   128 
       
   129     action = new HbAction();
   126     action->setObjectName( "copy" );
   130     action->setObjectName( "copy" );
   127     action->setText( hbTrId( "txt_fmgr_menu_copy" ) );
   131     action->setText( hbTrId( "txt_fmgr_menu_copy" ) );
   128     menu()->addAction( action );
   132     menu()->addAction( action );
   129 
   133     connect( action, SIGNAL( triggered() ),
   130     action = new HbAction( this );
   134         this, SLOT( on_copy_triggered() ), Qt::QueuedConnection );
       
   135 
       
   136     action = new HbAction();
   131     action->setObjectName( "move" );
   137     action->setObjectName( "move" );
   132     action->setText( hbTrId( "txt_fmgr_menu_move" ) );
   138     action->setText( hbTrId( "txt_fmgr_menu_move" ) );
   133     menu()->addAction( action );
   139     menu()->addAction( action );
   134     
   140     connect( action, SIGNAL( triggered() ),
   135     action = new HbAction( this );
   141         this, SLOT( on_move_triggered() ), Qt::QueuedConnection );
       
   142     
       
   143     action = new HbAction();
   136     action->setObjectName( "newFolder" );
   144     action->setObjectName( "newFolder" );
   137     action->setText( hbTrId( "New Folder" ) );
   145     action->setText( hbTrId( "txt_fmgr_opt_new_folder" ) );
   138     menu()->addAction( action );
   146     menu()->addAction( action );
       
   147     connect( action, SIGNAL( triggered() ),
       
   148         this, SLOT( on_newFolder_triggered() ), Qt::QueuedConnection );
   139     
   149     
   140     HbMenu *subMenu = new HbMenu( hbTrId( "Sort" ) );
   150     HbMenu *subMenu = new HbMenu( hbTrId( "Sort" ) );
   141     HbAction *sortNameAction = new HbAction( subMenu );
   151     HbAction *sortNameAction = new HbAction( subMenu );
   142     sortNameAction->setObjectName( "sortNameAction" );
   152     sortNameAction->setObjectName( "sortNameAction" );
   143     sortNameAction->setText( hbTrId( "Sort by name" ) );
   153     sortNameAction->setText( hbTrId( "Sort by name" ) );
   159     subMenu->addAction( sortTypeAction );
   169     subMenu->addAction( sortTypeAction );
   160     
   170     
   161     menu()->addMenu( subMenu );
   171     menu()->addMenu( subMenu );
   162 	
   172 	
   163     connect( sortNameAction, SIGNAL( triggered() ),
   173     connect( sortNameAction, SIGNAL( triggered() ),
   164              this, SLOT( on_sortNameAction_triggered() ) );
   174              this, SLOT( on_sortNameAction_triggered() ), Qt::QueuedConnection );
   165     connect( sortTimeAction, SIGNAL( triggered() ),
   175     connect( sortTimeAction, SIGNAL( triggered() ),
   166              this, SLOT( on_sortTimeAction_triggered() ) );
   176              this, SLOT( on_sortTimeAction_triggered() ), Qt::QueuedConnection );
   167     connect( sortSizeAction, SIGNAL( triggered() ),
   177     connect( sortSizeAction, SIGNAL( triggered() ),
   168              this, SLOT( on_sortSizeAction_triggered() ) );
   178              this, SLOT( on_sortSizeAction_triggered() ), Qt::QueuedConnection );
   169     connect( sortTypeAction, SIGNAL( triggered() ),
   179     connect( sortTypeAction, SIGNAL( triggered() ),
   170              this, SLOT( on_sortTypeAction_triggered() ) );
   180              this, SLOT( on_sortTypeAction_triggered() ), Qt::QueuedConnection );
   171     
   181     
   172     mMenu = takeMenu();
   182     mMenu = takeMenu();
   173 }
   183 }
   174 
   184 
   175 void FmFileView::initMainWidget()
   185 void FmFileView::initMainWidget()
   213     
   223     
   214     //mToolBar = takeToolBar();
   224     //mToolBar = takeToolBar();
   215     connect( mFindAction, SIGNAL( triggered() ),
   225     connect( mFindAction, SIGNAL( triggered() ),
   216                  this, SLOT( on_leftAction_triggered() ) );
   226                  this, SLOT( on_leftAction_triggered() ) );
   217     connect( mToolBarRightAction, SIGNAL( triggered() ),
   227     connect( mToolBarRightAction, SIGNAL( triggered() ),
   218              this, SLOT( on_rightAction_triggered() ) );
   228              this, SLOT( on_rightAction_triggered() ), Qt::QueuedConnection );
   219     
   229     
   220 }
   230 }
   221 
   231 
   222 void FmFileView::setStyle( FmFileBrowseWidget::Style style )
   232 void FmFileView::setStyle( FmFileBrowseWidget::Style style )
   223 {
   233 {
       
   234     /*
   224 	if ( style == FmFileBrowseWidget::ListStyle ) {
   235 	if ( style == FmFileBrowseWidget::ListStyle ) {
   225 		mStyleAction->setText( hbTrId("Tree") );
   236 		mStyleAction->setText( hbTrId("Tree") );
   226 	} else if ( style == FmFileBrowseWidget::TreeStyle ) {
   237 	} else if ( style == FmFileBrowseWidget::TreeStyle ) {
   227 		mStyleAction->setText( hbTrId("List") );
   238 		mStyleAction->setText( hbTrId("List") );
   228 	}
   239 	}
   229 	
   240 	*/
   230 	mWidget->setStyle( style );
   241 	mWidget->setStyle( style );
   231 }
   242 }
   232 
   243 
   233 void FmFileView::setSelectable( bool enable )
   244 void FmFileView::setSelectable( bool enable )
   234 {
   245 {
   241 	mWidget->setSelectable( enable );
   252 	mWidget->setSelectable( enable );
   242 }
   253 }
   243 
   254 
   244 void FmFileView::infoNoFileSelected()
   255 void FmFileView::infoNoFileSelected()
   245 {
   256 {
   246 	HbMessageBox::information( tr("No File/Folder selected" ) );
   257 	FmDlgUtils::information( hbTrId("No File/Folder selected" ) );
   247 }
   258 }
   248 
   259 
   249 #ifdef FM_CHANGE_ORIENT_ENABLE
   260 #ifdef FM_CHANGE_ORIENT_ENABLE
   250 void FmFileView::on_rotateAction_triggered()
   261 void FmFileView::on_rotateAction_triggered()
   251 {
   262 {
   276 {
   287 {
   277 	QList<QFileInfo> files = mWidget->checkedItems();
   288 	QList<QFileInfo> files = mWidget->checkedItems();
   278     if (files.size() == 0) {
   289     if (files.size() == 0) {
   279 		infoNoFileSelected();
   290 		infoNoFileSelected();
   280     } else {
   291     } else {
   281         if (HbMessageBox::question( tr("Confirm Deletion?" ) )) {
   292         if (FmDlgUtils::question( hbTrId("Confirm Deletion?" ) )) {
   282             QStringList fileList;
   293             QStringList fileList;
   283             for (int i = 0; i < files.size(); ++i) {
   294             for (int i = 0; i < files.size(); ++i) {
   284                 fileList.push_back( files[i].absoluteFilePath() );
   295                 fileList.push_back( files[i].absoluteFilePath() );
   285                 }
   296                 }
   286             int ret = mOperationService->asyncRemove( fileList );
   297             int ret = mOperationService->asyncRemove( fileList );
   288                 case FmErrNone:
   299                 case FmErrNone:
   289                     // no error, do not show note to user
   300                     // no error, do not show note to user
   290                     break;
   301                     break;
   291                 case FmErrAlreadyStarted:
   302                 case FmErrAlreadyStarted:
   292                     // last operation have not finished
   303                     // last operation have not finished
   293                     HbMessageBox::information( hbTrId( "Operatin already started!" ) );
   304                     FmDlgUtils::information( hbTrId( "Operatin already started!" ) );
   294                     break;
   305                     break;
   295                 case FmErrWrongParam:
   306                 case FmErrWrongParam:
   296                     HbMessageBox::information( hbTrId( "Wrong parameters!" ) );
   307                     FmDlgUtils::information( hbTrId( "Wrong parameters!" ) );
   297                     break;
   308                     break;
   298                 default:
   309                 default:
   299                     HbMessageBox::information( hbTrId( "Operation fail to start!" ) );
   310                     FmDlgUtils::information( hbTrId( "Operation fail to start!" ) );
   300             }
   311             }
   301             setSelectable( false );
   312             setSelectable( false );
   302         }
   313         }
   303     }
   314     }
   304 }
   315 }
   326                 case FmErrNone:
   337                 case FmErrNone:
   327                     // no error, do not show note to user
   338                     // no error, do not show note to user
   328                     break;
   339                     break;
   329                 case FmErrAlreadyStarted:
   340                 case FmErrAlreadyStarted:
   330                     // last operation have not finished
   341                     // last operation have not finished
   331                     HbMessageBox::information( hbTrId( "Operatin already started!" ) );
   342                     FmDlgUtils::information( hbTrId( "Operatin already started!" ) );
   332                     break;
   343                     break;
   333                 case FmErrWrongParam:
   344                 case FmErrWrongParam:
   334                     HbMessageBox::information( hbTrId( "Wrong parameters!" ) );
   345                     FmDlgUtils::information( hbTrId( "Wrong parameters!" ) );
   335                     break;
   346                     break;
   336                 default:
   347                 default:
   337                     HbMessageBox::information( hbTrId( "Operation fail to start!" ) );
   348                     FmDlgUtils::information( hbTrId( "Operation fail to start!" ) );
   338             }
   349             }
   339             setSelectable( false );
   350             setSelectable( false );
   340         }
   351         }
   341     }
   352     }
   342 
   353 
   347     QList<QFileInfo> files = mWidget->checkedItems();
   358     QList<QFileInfo> files = mWidget->checkedItems();
   348 
   359 
   349     if (files.size() == 0) {
   360     if (files.size() == 0) {
   350         infoNoFileSelected();
   361         infoNoFileSelected();
   351     } else {
   362     } else {
   352         QString targetPathName = FmFileDialog::getExistingDirectory( 0, tr( "move to" ),
   363         QString targetPathName = FmFileDialog::getExistingDirectory( 0, hbTrId( "move to" ),
   353             QString(""), QStringList() );
   364             QString(""), QStringList() );
   354 
   365 
   355         if( !targetPathName.isEmpty() && files.size() > 0 ) {
   366         if( !targetPathName.isEmpty() && files.size() > 0 ) {
   356             targetPathName = FmUtils::fillPathWithSplash( targetPathName );
   367             targetPathName = FmUtils::fillPathWithSplash( targetPathName );
   357 
   368 
   364                 case FmErrNone:
   375                 case FmErrNone:
   365                     // no error, do not show note to user
   376                     // no error, do not show note to user
   366                     break;
   377                     break;
   367                 case FmErrAlreadyStarted:
   378                 case FmErrAlreadyStarted:
   368                     // last operation have not finished
   379                     // last operation have not finished
   369                     HbMessageBox::information( tr( "Operatin already started!" ) );
   380                     FmDlgUtils::information( hbTrId( "Operatin already started!" ) );
   370                     break;
   381                     break;
   371                 case FmErrWrongParam:
   382                 case FmErrWrongParam:
   372                     HbMessageBox::information( tr( "Wrong parameters!" ) );
   383                     FmDlgUtils::information( hbTrId( "Wrong parameters!" ) );
   373                     break;
   384                     break;
   374                 default:
   385                 default:
   375                     HbMessageBox::information( tr( "Operation fail to start!" ) );
   386                     FmDlgUtils::information( hbTrId( "Operation fail to start!" ) );
   376             }
   387             }
   377             setSelectable( false );
   388             setSelectable( false );
   378         }
   389         }
   379     }
   390     }
   380 }
   391 }
   381 
   392 
   382 void FmFileView::on_newFolder_triggered()
   393 void FmFileView::on_newFolder_triggered()
   383 {
   394 {
   384     QString dirName;
   395     int maxFileNameLength = FmUtils::getMaxFileNameLength();
       
   396     QString associatedDrive = FmUtils::getDriveLetterFromPath( mWidget->currentPath().absoluteFilePath() );
   385     QString path = FmUtils::fillPathWithSplash( mWidget->currentPath().absoluteFilePath() );
   397     QString path = FmUtils::fillPathWithSplash( mWidget->currentPath().absoluteFilePath() );
   386     QDir dir( path );
   398     QString dirName = createDefaultFolderName( path );
       
   399     
       
   400     QDir dir( path );  
   387     if( dir.exists() ) {
   401     if( dir.exists() ) {
   388         while( FmDlgUtils::showTextQuery( hbTrId( "Enter name for " ), dirName, true ) ){
   402         while( FmDlgUtils::showTextQuery( hbTrId( "txt_fmgr_title_new_folder" ), dirName,
   389                 QString newTargetPath = FmUtils::fillPathWithSplash(
   403             true, maxFileNameLength, associatedDrive , false ) ){
   390                     dir.absolutePath() ) + dirName;
   404             // remove whitespace from the start and the end.
   391                 QFileInfo newFileInfo( newTargetPath );
   405             dirName = dirName.trimmed();
   392                 if( newFileInfo.exists() ) {
   406             QString newTargetPath = FmUtils::fillPathWithSplash(
   393                     HbMessageBox::information( hbTrId( "%1 already exist!" ).arg( dirName ) );
   407                 dir.absolutePath() ) + dirName;
   394                     continue;
   408             QString errString;
   395                 }
   409             // check if name/path is available for use
   396     
   410             if( !FmUtils::checkNewFolderOrFile( newTargetPath, errString ) ) {
   397                 if( !dir.mkdir( dirName ) ) {
   411                 FmDlgUtils::information( errString );
   398                     HbMessageBox::information( hbTrId("Operation failed!") );
   412                 continue;
   399                 }
   413             }
   400                 refreshModel( path );
   414             if( !dir.mkdir( dirName ) ) {
   401                 break;
   415                 FmDlgUtils::information( hbTrId("Operation failed!") );
   402             }
   416             }
       
   417             refreshModel( path );
       
   418             break;
       
   419         }
   403         
   420         
   404     }
   421     }
   405 }
   422 }
       
   423 
   406 void FmFileView::on_upAction_triggered()
   424 void FmFileView::on_upAction_triggered()
   407 {
   425 {
   408 	mWidget->cdUp();
   426 	mWidget->cdUp();
   409 }
   427 }
   410 
   428 
   411 void FmFileView::on_leftAction_triggered()
   429 void FmFileView::on_leftAction_triggered()
   412 {
   430 {
   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();
   431     mWidget->activeSearchPanel();
   421 }
   432 }
   422 
   433 
   423 void FmFileView::on_rightAction_triggered()
   434 void FmFileView::on_rightAction_triggered()
   424 {
   435 {
   491 
   502 
   492 void FmFileView::on_mainWidget_setTitle( const QString &title )
   503 void FmFileView::on_mainWidget_setTitle( const QString &title )
   493 {
   504 {
   494     this->setTitle( title );
   505     this->setTitle( title );
   495 }
   506 }
       
   507 
       
   508 QString FmFileView::createDefaultFolderName( const QString &path )
       
   509 {
       
   510     // create new folder name, for example, New folder(01), New folder(02)
       
   511     QString checkedPath( FmUtils::fillPathWithSplash( path ) );
       
   512     QString dirName( hbTrId( "txt_fmgr_dialog_entry_new_folder" ) );
       
   513     QString dirAbsolutePath( checkedPath + dirName );
       
   514     QFileInfo fileInfo( dirAbsolutePath );
       
   515     int i = 0;    
       
   516     while ( fileInfo.exists() ) {
       
   517         ++i;
       
   518 		QString numName;
       
   519         if ( i < 10 ) {
       
   520             numName.append( QString::number(0) );                        
       
   521         }
       
   522         numName.append( QString::number(i) );
       
   523         // txt_fmgr_dialog_entry_new_folder_l1 is not available now. use actual text instead of it.
       
   524         dirName = hbTrId( "New folder (%L1)" ).arg( numName );
       
   525         dirAbsolutePath = checkedPath + dirName;
       
   526         fileInfo.setFile( dirAbsolutePath );
       
   527     }
       
   528     return dirName;
       
   529 }