filemanager/src/filemanager/src/fmfileview.cpp
changeset 37 15bc28c9dd51
parent 16 ada7962b4308
child 46 d58987eac7e8
--- a/filemanager/src/filemanager/src/fmfileview.cpp	Mon May 03 12:24:39 2010 +0300
+++ b/filemanager/src/filemanager/src/fmfileview.cpp	Tue Aug 24 10:24:14 2010 +0800
@@ -34,13 +34,12 @@
 #include <hbaction.h>
 #include <hbtoolbar.h>
 #include <hblineedit.h>
-#include <hbmessagebox.h>
 #include <hbpushbutton.h>
 #include <hbmainwindow.h>
 
 FmFileView::FmFileView() : FmViewBase( EFileView ), mWidget( 0 ),
     mUpButton( 0 ), mStyleAction( 0 ), mSelectableAction( 0 ),
-    mFindAction( 0 ), mOperationService( 0 ), mMenu( 0 ) 
+    mFindAction( 0 ), mOperationService( 0 ), mMenu( 0 ), mIsFindDisabled( false )
 {
     mOperationService = FmViewManager::viewManager()->operationService();
 	initMenu();
@@ -94,8 +93,9 @@
 
 void FmFileView::setFindDisabled( bool disable )
 {
+    mIsFindDisabled = disable;
     if( mFindAction ) {
-        mFindAction->setDisabled( disable );
+        mFindAction->setDisabled( mIsFindDisabled );
     }
 }
 
@@ -109,33 +109,44 @@
 	menu()->addAction( action );
 #endif
 
-	mStyleAction = new HbAction( this );
-	mStyleAction->setObjectName( "switchStyle" );
+//	mStyleAction = new HbAction();
+//	mStyleAction->setObjectName( "switchStyle" );
 //	menu()->addAction( mStyleAction );
 
-	mSelectableAction = new HbAction( this );
+	mSelectableAction = new HbAction();
 	mSelectableAction->setObjectName( "setSelectable" );
 	menu()->addAction( mSelectableAction );
+    connect( mSelectableAction, SIGNAL( triggered() ),
+        this, SLOT( on_setSelectable_triggered() ), Qt::QueuedConnection );
 
-	action = new HbAction( this );
+
+	action = new HbAction();
 	action->setObjectName( "delete" );
 	action->setText( hbTrId( "txt_fmgr_menu_delete" ) );
 	menu()->addAction( action );
+    connect( action, SIGNAL( triggered() ),
+        this, SLOT( on_delete_triggered() ), Qt::QueuedConnection );
 
-    action = new HbAction( this );
+    action = new HbAction();
     action->setObjectName( "copy" );
     action->setText( hbTrId( "txt_fmgr_menu_copy" ) );
     menu()->addAction( action );
+    connect( action, SIGNAL( triggered() ),
+        this, SLOT( on_copy_triggered() ), Qt::QueuedConnection );
 
-    action = new HbAction( this );
+    action = new HbAction();
     action->setObjectName( "move" );
     action->setText( hbTrId( "txt_fmgr_menu_move" ) );
     menu()->addAction( action );
+    connect( action, SIGNAL( triggered() ),
+        this, SLOT( on_move_triggered() ), Qt::QueuedConnection );
     
-    action = new HbAction( this );
+    action = new HbAction();
     action->setObjectName( "newFolder" );
-    action->setText( hbTrId( "New Folder" ) );
+    action->setText( hbTrId( "txt_fmgr_opt_new_folder" ) );
     menu()->addAction( action );
+    connect( action, SIGNAL( triggered() ),
+        this, SLOT( on_newFolder_triggered() ), Qt::QueuedConnection );
     
     HbMenu *subMenu = new HbMenu( hbTrId( "Sort" ) );
     HbAction *sortNameAction = new HbAction( subMenu );
@@ -161,13 +172,13 @@
     menu()->addMenu( subMenu );
 	
     connect( sortNameAction, SIGNAL( triggered() ),
-             this, SLOT( on_sortNameAction_triggered() ) );
+             this, SLOT( on_sortNameAction_triggered() ), Qt::QueuedConnection );
     connect( sortTimeAction, SIGNAL( triggered() ),
-             this, SLOT( on_sortTimeAction_triggered() ) );
+             this, SLOT( on_sortTimeAction_triggered() ), Qt::QueuedConnection );
     connect( sortSizeAction, SIGNAL( triggered() ),
-             this, SLOT( on_sortSizeAction_triggered() ) );
+             this, SLOT( on_sortSizeAction_triggered() ), Qt::QueuedConnection );
     connect( sortTypeAction, SIGNAL( triggered() ),
-             this, SLOT( on_sortTypeAction_triggered() ) );
+             this, SLOT( on_sortTypeAction_triggered() ), Qt::QueuedConnection );
     
     mMenu = takeMenu();
 }
@@ -202,6 +213,7 @@
     mFindAction = new HbAction( this );
     mFindAction->setObjectName( "leftAction" );
     mFindAction->setText( hbTrId("txt_fmgr_opt_find") );
+    mFindAction->setDisabled( mIsFindDisabled );
     toolBar()->addAction( mFindAction );
 
     mToolBarRightAction = new HbAction( this );
@@ -215,18 +227,19 @@
     connect( mFindAction, SIGNAL( triggered() ),
                  this, SLOT( on_leftAction_triggered() ) );
     connect( mToolBarRightAction, SIGNAL( triggered() ),
-             this, SLOT( on_rightAction_triggered() ) );
+             this, SLOT( on_rightAction_triggered() ), Qt::QueuedConnection );
     
 }
 
 void FmFileView::setStyle( FmFileBrowseWidget::Style style )
 {
+    /*
 	if ( style == FmFileBrowseWidget::ListStyle ) {
 		mStyleAction->setText( hbTrId("Tree") );
 	} else if ( style == FmFileBrowseWidget::TreeStyle ) {
 		mStyleAction->setText( hbTrId("List") );
 	}
-	
+	*/
 	mWidget->setStyle( style );
 }
 
@@ -243,7 +256,7 @@
 
 void FmFileView::infoNoFileSelected()
 {
-	HbMessageBox::information( tr("No File/Folder selected" ) );
+	FmDlgUtils::information( hbTrId("No File/Folder selected" ) );
 }
 
 #ifdef FM_CHANGE_ORIENT_ENABLE
@@ -278,7 +291,7 @@
     if (files.size() == 0) {
 		infoNoFileSelected();
     } else {
-        if (HbMessageBox::question( tr("Confirm Deletion?" ) )) {
+        if (FmDlgUtils::question( hbTrId("Confirm Deletion?" ) )) {
             QStringList fileList;
             for (int i = 0; i < files.size(); ++i) {
                 fileList.push_back( files[i].absoluteFilePath() );
@@ -290,13 +303,13 @@
                     break;
                 case FmErrAlreadyStarted:
                     // last operation have not finished
-                    HbMessageBox::information( hbTrId( "Operatin already started!" ) );
+                    FmDlgUtils::information( hbTrId( "Operatin already started!" ) );
                     break;
                 case FmErrWrongParam:
-                    HbMessageBox::information( hbTrId( "Wrong parameters!" ) );
+                    FmDlgUtils::information( hbTrId( "Wrong parameters!" ) );
                     break;
                 default:
-                    HbMessageBox::information( hbTrId( "Operation fail to start!" ) );
+                    FmDlgUtils::information( hbTrId( "Operation fail to start!" ) );
             }
             setSelectable( false );
         }
@@ -328,13 +341,13 @@
                     break;
                 case FmErrAlreadyStarted:
                     // last operation have not finished
-                    HbMessageBox::information( hbTrId( "Operatin already started!" ) );
+                    FmDlgUtils::information( hbTrId( "Operatin already started!" ) );
                     break;
                 case FmErrWrongParam:
-                    HbMessageBox::information( hbTrId( "Wrong parameters!" ) );
+                    FmDlgUtils::information( hbTrId( "Wrong parameters!" ) );
                     break;
                 default:
-                    HbMessageBox::information( hbTrId( "Operation fail to start!" ) );
+                    FmDlgUtils::information( hbTrId( "Operation fail to start!" ) );
             }
             setSelectable( false );
         }
@@ -349,7 +362,7 @@
     if (files.size() == 0) {
         infoNoFileSelected();
     } else {
-        QString targetPathName = FmFileDialog::getExistingDirectory( 0, tr( "move to" ),
+        QString targetPathName = FmFileDialog::getExistingDirectory( 0, hbTrId( "move to" ),
             QString(""), QStringList() );
 
         if( !targetPathName.isEmpty() && files.size() > 0 ) {
@@ -366,13 +379,13 @@
                     break;
                 case FmErrAlreadyStarted:
                     // last operation have not finished
-                    HbMessageBox::information( tr( "Operatin already started!" ) );
+                    FmDlgUtils::information( hbTrId( "Operatin already started!" ) );
                     break;
                 case FmErrWrongParam:
-                    HbMessageBox::information( tr( "Wrong parameters!" ) );
+                    FmDlgUtils::information( hbTrId( "Wrong parameters!" ) );
                     break;
                 default:
-                    HbMessageBox::information( tr( "Operation fail to start!" ) );
+                    FmDlgUtils::information( hbTrId( "Operation fail to start!" ) );
             }
             setSelectable( false );
         }
@@ -381,28 +394,35 @@
 
 void FmFileView::on_newFolder_triggered()
 {
-    QString dirName;
+    int maxFileNameLength = FmUtils::getMaxFileNameLength();
+    QString associatedDrive = FmUtils::getDriveLetterFromPath( mWidget->currentPath().absoluteFilePath() );
     QString path = FmUtils::fillPathWithSplash( mWidget->currentPath().absoluteFilePath() );
-    QDir dir( path );
+    QString dirName = createDefaultFolderName( path );
+    QStringList regExpList = (QStringList() << Regex_ValidFileFolderName << Regex_ValidNotEndWithDot );
+
+    QDir dir( path );  
     if( dir.exists() ) {
-        while( FmDlgUtils::showTextQuery( hbTrId( "Enter name for " ), dirName, true ) ){
-                QString newTargetPath = FmUtils::fillPathWithSplash(
-                    dir.absolutePath() ) + dirName;
-                QFileInfo newFileInfo( newTargetPath );
-                if( newFileInfo.exists() ) {
-                    HbMessageBox::information( hbTrId( "%1 already exist!" ).arg( dirName ) );
-                    continue;
-                }
-    
-                if( !dir.mkdir( dirName ) ) {
-                    HbMessageBox::information( hbTrId("Operation failed!") );
-                }
-                refreshModel( path );
-                break;
+        while( FmDlgUtils::showTextQuery( hbTrId( "txt_fmgr_title_new_folder" ), dirName,
+            regExpList, maxFileNameLength, associatedDrive , false ) ){
+            // remove whitespace from the start and the end.
+            dirName = dirName.trimmed();
+            QString newTargetPath = FmUtils::fillPathWithSplash(
+                dir.absolutePath() ) + dirName;
+            QString errString;
+            // check if name/path is available for use
+            if( !FmUtils::checkNewFolderOrFile( dirName, newTargetPath, errString ) ) {
+                FmDlgUtils::information( errString );
+                continue;
             }
+            if( !dir.mkdir( dirName ) ) {
+                FmDlgUtils::information( hbTrId("Operation failed!") );
+            }
+            break;
+        }
         
     }
 }
+
 void FmFileView::on_upAction_triggered()
 {
 	mWidget->cdUp();
@@ -410,13 +430,6 @@
 
 void FmFileView::on_leftAction_triggered()
 {
-//    FmFindDialog findDialog;
-//    QString keyword;
-//    QString findFolder;
-//    bool ret = findDialog.exec( keyword, findFolder );
-//
-//    if ( ret && !keyword.isEmpty() && !findFolder.isEmpty() )
-//        FmViewManager::viewManager()->createFindView( keyword, findFolder );
     mWidget->activeSearchPanel();
 }
 
@@ -433,9 +446,9 @@
 	}
 }
 
-void FmFileView::refreshModel( const QString &path )
+void FmFileView::on_driveChanged()
 {
-    mWidget->refreshModel( path );  
+    mWidget->on_driveChanged();  
 }
 
 void FmFileView::on_sortNameAction_triggered()
@@ -473,14 +486,14 @@
 void FmFileView::on_mainWidget_setEmptyMenu( bool isMenuEmpty )
 {
     if( isMenuEmpty ){
-        FmLogger::log( "setEmptyMenu true" );
+        FM_LOG( "setEmptyMenu true" );
         if( !mMenu ) {
             mMenu = takeMenu();
         }
         toolBar()->clearActions();
     }
     else {
-        FmLogger::log( "setEmptyMenu false" );
+        FM_LOG( "setEmptyMenu false" );
         if( mMenu ) {
             setMenu( mMenu );
             mMenu = 0;
@@ -493,3 +506,26 @@
 {
     this->setTitle( title );
 }
+
+QString FmFileView::createDefaultFolderName( const QString &path )
+{
+    // create new folder name, for example, New folder(01), New folder(02)
+    QString checkedPath( FmUtils::fillPathWithSplash( path ) );
+    QString dirName( hbTrId( "txt_fmgr_dialog_entry_new_folder" ) );
+    QString dirAbsolutePath( checkedPath + dirName );
+    QFileInfo fileInfo( dirAbsolutePath );
+    int i = 0;    
+    while ( fileInfo.exists() ) {
+        ++i;
+		QString numName;
+        if ( i < 10 ) {
+            numName.append( QString::number(0) );                        
+        }
+        numName.append( QString::number(i) );
+        // txt_fmgr_dialog_entry_new_folder_l1 is not available now. use actual text instead of it.
+        dirName = hbTrId( "New folder (%L1)" ).arg( numName );
+        dirAbsolutePath = checkedPath + dirName;
+        fileInfo.setFile( dirAbsolutePath );
+    }
+    return dirName;
+}