filemanager/src/fmfiledialog/src/fmfilewidget.cpp
changeset 16 ada7962b4308
parent 14 1957042d8c7e
child 18 edd66bde63a4
child 25 b7bfdea70ca2
child 37 15bc28c9dd51
--- a/filemanager/src/fmfiledialog/src/fmfilewidget.cpp	Fri Apr 16 14:53:38 2010 +0300
+++ b/filemanager/src/fmfiledialog/src/fmfilewidget.cpp	Mon May 03 12:24:39 2010 +0300
@@ -19,9 +19,10 @@
 #include "fmfilewidget.h"
 #include "fmutils.h"
 #include "fmdrivemodel.h"
+#include "fmdrivewatcher.h"
 
-#include <hbstyle.h>
-#include <hbabstractitemview.h>
+#include "hbstyle.h"
+#include "hbabstractitemview.h"
 #include <hblistview.h>
 
 #include <QModelIndex>
@@ -43,6 +44,10 @@
     setModel( 0 );
     delete mDirModel;
     delete mDriveModel;
+    
+    mDriveWatcher->cancelWatch();
+    delete mDriveWatcher;
+    mDriveWatcher = 0;
 }
 
 QFileInfo FmFileWidget::currentPath() const
@@ -142,9 +147,18 @@
     qDebug("setmodel");
     qDebug( QTime::currentTime().toString().toUtf8().data() );
 
+    mDriveWatcher = new FmDriveWatcher( this );
+    mDriveWatcher->setObjectName( "driveWatcher" );
+    mDriveWatcher->startWatch();
+    
 //    QMetaObject::connectSlotsByName( this );
     connect( mListView, SIGNAL( activated( QModelIndex ) ),
         this, SLOT( on_list_activated( QModelIndex ) ) );
+    
+    connect( mDriveWatcher, SIGNAL( driveAddedOrChanged() ),
+            this, SLOT( on_driveWatcher_driveAddedOrChanged() ) );
+    
+
 }
 
 void FmFileWidget::setModel( QAbstractItemModel *model )
@@ -178,3 +192,23 @@
     setRootPath( FmUtils::fillPathWithSplash( cdUpPath ) );
     return true;
 }
+
+void FmFileWidget::on_driveWatcher_driveAddedOrChanged()
+{
+    FmLogger::log( QString( "FmFileDialog_FmFileWidget::on_driveWatcher_driveAddedOrChanged start" ) );
+    mDriveModel->refresh();
+    if( currentViewType() == DriveView ) {
+        setModel( 0 );
+        setModel( mDriveModel );
+        emit pathChanged( QString() );
+    } else if( currentViewType() == DirView ) {
+        if( !FmUtils::isPathAccessabel( currentPath().absoluteFilePath() ) ) {
+            // path not available, set model to drive
+            FmLogger::log( QString( "FmFileDialog_FmFileWidget::on_driveWatcher_driveAddedOrChanged path not availeable, set drivemodel:"
+                    + currentPath().absoluteFilePath() ) );
+            setModel( mDriveModel );
+            emit pathChanged( QString() );
+        }
+    }
+    FmLogger::log( QString( "FmFileDialog_FmFileWidget::on_driveWatcher_driveAddedOrChanged end" ) );
+}