filemanager/src/filemanager/src/fmdriverlistwidget.cpp
changeset 24 1d0c87b42e2e
parent 18 edd66bde63a4
child 29 b3155376f2b4
--- a/filemanager/src/filemanager/src/fmdriverlistwidget.cpp	Thu May 27 12:45:43 2010 +0300
+++ b/filemanager/src/filemanager/src/fmdriverlistwidget.cpp	Fri Jun 11 13:29:48 2010 +0300
@@ -32,13 +32,12 @@
 #include <hblistview.h>
 #include <hbmenu.h>
 #include <hbaction.h>
-#include <hbmessagebox.h>
 #include <hbsearchpanel.h>
 
 FmDriverListWidget::FmDriverListWidget( QGraphicsItem *parent )
-: HbWidget( parent ),
-  mCurrentItem( 0 ),
-  mOperationService( 0 ), mListLongPressed( false )
+: HbWidget( parent ), mListView(0), mModel(0),
+  mCurrentItem(0), mSearchPanel(0),  mOperationService(0),
+  mFileSystemWatcher(0), mLayout(0), mContextMenu(0), mListLongPressed( false )
 {
 	init();
 	mOperationService = FmViewManager::viewManager()->operationService();
@@ -52,6 +51,9 @@
 
 FmDriverListWidget::~FmDriverListWidget()
 {
+	if (mContextMenu) {
+        mContextMenu->deleteLater();
+	}
 }
 
 void FmDriverListWidget::on_list_activated( const QModelIndex &index )
@@ -86,7 +88,7 @@
 	mSearchPanel->hide();
 //	mLayout->addItem( mSearchPanel );
     
-	mListView->setItemPrototype( new DiskListViewItem() );
+	mListView->setItemPrototype( new DiskListViewItem(this) );
 	connect( mListView, SIGNAL( activated( const QModelIndex & ) ),
 		     this, SLOT( on_list_activated( const QModelIndex & ) ) );
 	connect( mListView, SIGNAL( pressed( const QModelIndex & ) ),
@@ -96,7 +98,7 @@
         this, SLOT( on_list_longPressed( HbAbstractViewItem *, const QPointF & ) ) );
     
     connect( mSearchPanel, SIGNAL( searchOptionsClicked() ),
-        this, SLOT( on_searchPanel_searchOptionsClicked() ) );
+        this, SLOT( on_searchPanel_searchOptionsClicked() ), Qt::QueuedConnection );
     
     connect( mSearchPanel, SIGNAL( criteriaChanged( const QString & ) ),
         this, SLOT( on_searchPanel_criteriaChanged( const QString & ) ) );
@@ -119,22 +121,25 @@
     mListLongPressed = true;
     mCurrentItem = item;
     QString diskName = mModel->driveName( mCurrentItem->modelIndex() );
-    
-    FmDriverInfo driverInfo = FmUtils::queryDriverInfo( diskName );
+
+	if( !mContextMenu ) {
+		mContextMenu = new HbMenu();
+	} else {
+		mContextMenu->clearActions();
+	}
+	FmDriverInfo driverInfo = FmUtils::queryDriverInfo( diskName );
     FmDriverInfo::DriveState state = driverInfo.driveState();
     if( !( state & FmDriverInfo::EDriveNotPresent ) ) {
-        HbMenu *contextMenu = new HbMenu();
-        
         if( state & FmDriverInfo::EDriveAvailable ) {
             HbAction *viewAction = new HbAction();
             viewAction->setObjectName( "viewAction" );
             viewAction->setText( hbTrId( "txt_fmgr_menu_view_details_memory" ) );
-            contextMenu->addAction( viewAction );
+            mContextMenu->addAction( viewAction );
     
             //state = 0x210;
         
             connect( viewAction, SIGNAL( triggered() ),
-            this, SLOT( on_viewAction_triggered() ) );
+                this, SLOT( on_viewAction_triggered() ), Qt::QueuedConnection );
         }
     
         if( ( state & FmDriverInfo::EDriveAvailable ) && ( state & FmDriverInfo::EDriveRemovable ) && !( state & FmDriverInfo::EDriveMassStorage ) ){
@@ -143,45 +148,45 @@
                 HbAction *renameAction = new HbAction();
                 renameAction->setObjectName( "renameAction" );
                 renameAction->setText( hbTrId( "txt_fmgr_menu_rename" ) );
-                contextMenu->addAction( renameAction );
+                mContextMenu->addAction( renameAction );
     
                 connect( renameAction, SIGNAL( triggered() ),
-                 this, SLOT( on_renameAction_triggered() ) );
+                 this, SLOT( on_renameAction_triggered() ), Qt::QueuedConnection );
             }
             else{
                 HbAction *nameAction = new HbAction();
                 nameAction->setObjectName( "nameAction" );
                 nameAction->setText( hbTrId( "txt_fmgr_menu_name" ) );
-                contextMenu->addAction( nameAction );
+                mContextMenu->addAction( nameAction );
     
                 connect( nameAction, SIGNAL( triggered() ),
-                 this, SLOT( on_nameAction_triggered() ) );
+                 this, SLOT( on_nameAction_triggered() ), Qt::QueuedConnection );
             }
             if( !( state & FmDriverInfo::EDriveUsbMemory ) ) { // MMC
                 if( state & FmDriverInfo::EDrivePasswordProtected ){
                     HbAction *changePwdAction = new HbAction();
                     changePwdAction->setObjectName( "changePwdAction" );
                     changePwdAction->setText( hbTrId( "txt_fmgr_menu_change_password" ) );
-                    contextMenu->addAction( changePwdAction );
+                    mContextMenu->addAction( changePwdAction );
         
                     HbAction *removePwdAction = new HbAction();
                     removePwdAction->setObjectName( "removePwdAction" );
                     removePwdAction->setText( hbTrId( "txt_fmgr_menu_remove_password" ) );
-                    contextMenu->addAction( removePwdAction );
+                    mContextMenu->addAction( removePwdAction );
         
                     connect( changePwdAction, SIGNAL( triggered() ),
-                     this, SLOT( on_changePwdAction_triggered() ) );
+                     this, SLOT( on_changePwdAction_triggered() ), Qt::QueuedConnection );
                     connect( removePwdAction, SIGNAL( triggered() ),
-                     this, SLOT( on_removePwdAction_triggered() ) );
+                     this, SLOT( on_removePwdAction_triggered() ), Qt::QueuedConnection );
                 }
                 else{
                     HbAction *setPwdAction = new HbAction();
                     setPwdAction->setObjectName( "setPwdAction" );
                     setPwdAction->setText( hbTrId( "txt_fmgr_menu_set_password" ) );
-                    contextMenu->addAction( setPwdAction );
+                    mContextMenu->addAction( setPwdAction );
         
                     connect( setPwdAction, SIGNAL( triggered() ),
-                     this, SLOT( on_setPwdAction_triggered() ) );
+                     this, SLOT( on_setPwdAction_triggered() ), Qt::QueuedConnection );
                 }
             }
         }
@@ -190,10 +195,10 @@
             HbAction *ejectAction = new HbAction();
             ejectAction->setObjectName( "ejectAction" );
             ejectAction->setText( hbTrId( "txt_fmgr_menu_eject" ) );
-            contextMenu->addAction( ejectAction );
+            mContextMenu->addAction( ejectAction );
             
             connect( ejectAction, SIGNAL( triggered() ),
-            this, SLOT( on_ejectAction_triggered() ) );
+            this, SLOT( on_ejectAction_triggered() ), Qt::QueuedConnection );
         }  
         
     #ifndef _DEBUG_ENABLE_FORMATMENU_
@@ -203,10 +208,10 @@
                 HbAction *formatAction = new HbAction();
                 formatAction->setObjectName( "formatAction" );
                 formatAction->setText( hbTrId( "txt_fmgr_menu_format" ) );
-                contextMenu->addAction( formatAction );
+                mContextMenu->addAction( formatAction );
     
                 connect( formatAction, SIGNAL( triggered() ),
-                 this, SLOT( on_formatAction_triggered() ) );
+                    this, SLOT( on_formatAction_triggered() ), Qt::QueuedConnection );
     #ifndef _DEBUG_ENABLE_FORMATMENU_
         }
     #endif
@@ -215,15 +220,18 @@
             HbAction *unLockedAction = new HbAction();
             unLockedAction->setObjectName( "unLockedAction" );
             unLockedAction->setText( hbTrId( "Unlock" ) );
-            contextMenu->addAction( unLockedAction );
+            mContextMenu->addAction( unLockedAction );
     
             connect( unLockedAction, SIGNAL( triggered() ),
-             this, SLOT( on_unLockedAction_triggered() ) );
+             this, SLOT( on_unLockedAction_triggered() ), Qt::QueuedConnection );
         }
-        contextMenu->setPreferredPos( coords );
-        contextMenu->open();   
     }
-    
+	if( mContextMenu->actions().count() > 0 ) {
+		mContextMenu->setPreferredPos( coords );
+		mContextMenu->open();
+	} else {
+		emit activated( diskName );
+	}
 }
 
 void FmDriverListWidget::on_list_pressed( const QModelIndex &  index )
@@ -245,7 +253,7 @@
     FmDriverInfo driverInfo = FmUtils::queryDriverInfo( diskName );
 
     if ( state & FmDriverInfo::EDriveWriteProtected ){
-        HbMessageBox::information( hbTrId( "Unable to perform operation. Memory card is read only." ) );
+        FmDlgUtils::information( hbTrId( "Unable to perform operation. Memory card is read only." ) );
         return;
         }
 
@@ -256,13 +264,13 @@
     while( FmDlgUtils::showTextQuery( title, volumeName, false, FmMaxLengthofDriveName, associatedDrives ) ){
         int err = FmUtils::renameDrive( diskName, volumeName );
         if ( err == FmErrNone ){
-            HbMessageBox::information( hbTrId( "The name has been changed!" ) );
+            FmDlgUtils::information( hbTrId( "The name has been changed!" ) );
             mModel->refresh();
             break;
         } else if( err == FmErrBadName ) {
-            HbMessageBox::information( hbTrId( "Illegal characters! Use only letters and numbers." ) );
+            FmDlgUtils::information( hbTrId( "Illegal characters! Use only letters and numbers." ) );
         } else{
-            HbMessageBox::information( hbTrId( "Error occurred, operation cancelled!" ) );
+            FmDlgUtils::information( hbTrId( "Error occurred, operation cancelled!" ) );
             break;
         }                
     }
@@ -288,18 +296,18 @@
     QString associatedDrives( FmUtils::getDriveLetterFromPath( diskName ) );
     if( FmDlgUtils::showMultiPasswordQuery( firstLabel, secondLabel, newPwd, FmMaxLengthofDrivePassword, associatedDrives ) ) {
        if ( FmUtils::setDrivePwd( diskName, oldPwd, newPwd ) == 0 ){
-            HbMessageBox::information( hbTrId( "The password has been set!" ) );
+            FmDlgUtils::information( hbTrId( "The password has been set!" ) );
         }
         else{
-            HbMessageBox::information( hbTrId( "Error occurred, operation cancelled!" ) );
+            FmDlgUtils::information( hbTrId( "Error occurred, operation cancelled!" ) );
         }
     }
 }
 
 void FmDriverListWidget::on_changePwdAction_triggered()
 {
-    QString title( hbTrId( "Password: ")  );
-    QString firstLabel( hbTrId( "New Password: ") );
+    QString title( hbTrId( "txt_common_dialog_password")  );
+    QString firstLabel( hbTrId( "txt_common_dialog_new_password") );
     QString secondLabel( hbTrId( "Confirm new Password: ") );
 
     QString oldPwd;
@@ -312,9 +320,9 @@
        if ( FmUtils::checkDrivePwd( diskName, oldPwd ) == 0 ){
             if( FmDlgUtils::showMultiPasswordQuery( firstLabel, secondLabel, newPwd ) ){
                 if ( FmUtils::setDrivePwd( diskName, oldPwd, newPwd ) == 0 ){
-                    HbMessageBox::information( hbTrId( "The password has been changed!" ) );
+                    FmDlgUtils::information( hbTrId( "The password has been changed!" ) );
                 } else {
-                    HbMessageBox::information( hbTrId( "Error occurred, operation cancelled!" ) );
+                    FmDlgUtils::information( hbTrId( "Error occurred, operation cancelled!" ) );
                 }
                 break;
             } else {  
@@ -322,7 +330,7 @@
                 break;
             }
        } else {
-            HbMessageBox::information( hbTrId( "The password is incorrect, try again!" ) );
+            FmDlgUtils::information( hbTrId( "The password is incorrect, try again!" ) );
        }
          
     }
@@ -341,15 +349,15 @@
         while( FmDlgUtils::showSinglePasswordQuery( title, oldPwd, FmMaxLengthofDrivePassword, associatedDrives ) ) {
             if ( FmUtils::checkDrivePwd( diskName, oldPwd ) == 0 ) {
                 if ( FmUtils::removeDrivePwd( diskName, oldPwd ) == 0 ){
-                    HbMessageBox::information( hbTrId( "The password has been removed!" ) );
+                    FmDlgUtils::information( hbTrId( "The password has been removed!" ) );
                 }
                 else{
-                    HbMessageBox::information( hbTrId( "Error occurred, operation cancelled!" ) );
+                    FmDlgUtils::information( hbTrId( "Error occurred, operation cancelled!" ) );
                 }
                 break;
             }
             else {
-                HbMessageBox::information( hbTrId( "The password is incorrect, try again!" ) );
+                FmDlgUtils::information( hbTrId( "The password is incorrect, try again!" ) );
             }
             
         }
@@ -368,18 +376,18 @@
     while( FmDlgUtils::showSinglePasswordQuery( title, oldPwd ) ) {
         int err = FmUtils::unlockDrive( diskName, oldPwd );
         if( err == FmErrNone ) {
-            HbMessageBox::information( hbTrId( "The memory is unlocked!" ) );
+            FmDlgUtils::information( hbTrId( "The memory is unlocked!" ) );
             break;
         } else if ( err == FmErrAccessDenied ) {
-            HbMessageBox::information( hbTrId( "The password is incorrect, try again!" ) );
+            FmDlgUtils::information( hbTrId( "The password is incorrect, try again!" ) );
         } else if (err == FmErrAlreadyExists ) {
-            HbMessageBox::information( hbTrId( "The disk has already been unlocked!" ) );
+            FmDlgUtils::information( hbTrId( "The disk has already been unlocked!" ) );
             break;
         } else if( err == FmErrNotSupported ) {
-            HbMessageBox::information( hbTrId( "The media does not support password locking!" ) );
+            FmDlgUtils::information( hbTrId( "The media does not support password locking!" ) );
             break;
         } else {
-            HbMessageBox::information( hbTrId( "Error occurred, operation cancelled!" ) );
+            FmDlgUtils::information( hbTrId( "Error occurred, operation cancelled!" ) );
             break;
         }
     }
@@ -391,7 +399,7 @@
     
     if( FmDlgUtils::question( hbTrId( "Format? Data will be deleted during formatting." ) ) ){
         if( FmErrNone != mOperationService->asyncFormat( diskName ) )
-            HbMessageBox::information( hbTrId( "Formatting failed." ) );
+            FmDlgUtils::information( hbTrId( "Formatting failed." ) );
         }
 }
 
@@ -425,8 +433,8 @@
 
 void FmDriverListWidget::on_searchPanel_searchOptionsClicked()
 {
-    mFindTargetPath = FmFileDialog::getExistingDirectory( 0, hbTrId( "Look in:" ),
-        QString(""), QStringList() );
+    mFindTargetPath = FmUtils::fillPathWithSplash( FmFileDialog::getExistingDirectory( 0, hbTrId( "Look in:" ),
+        QString(""), QStringList() ) );
 }
 
 void FmDriverListWidget::on_searchPanel_criteriaChanged( const QString &criteria )