filemanager/src/fmfiledialog/src/fmfilewidget.cpp
changeset 16 ada7962b4308
parent 14 1957042d8c7e
child 18 edd66bde63a4
child 25 b7bfdea70ca2
child 37 15bc28c9dd51
equal deleted inserted replaced
14:1957042d8c7e 16:ada7962b4308
    17 *
    17 *
    18 */
    18 */
    19 #include "fmfilewidget.h"
    19 #include "fmfilewidget.h"
    20 #include "fmutils.h"
    20 #include "fmutils.h"
    21 #include "fmdrivemodel.h"
    21 #include "fmdrivemodel.h"
    22 
    22 #include "fmdrivewatcher.h"
    23 #include <hbstyle.h>
    23 
    24 #include <hbabstractitemview.h>
    24 #include "hbstyle.h"
       
    25 #include "hbabstractitemview.h"
    25 #include <hblistview.h>
    26 #include <hblistview.h>
    26 
    27 
    27 #include <QModelIndex>
    28 #include <QModelIndex>
    28 #include <QGraphicsLinearLayout>
    29 #include <QGraphicsLinearLayout>
    29 #include <QDirModel>
    30 #include <QDirModel>
    41 FmFileWidget::~FmFileWidget()
    42 FmFileWidget::~FmFileWidget()
    42 {
    43 {
    43     setModel( 0 );
    44     setModel( 0 );
    44     delete mDirModel;
    45     delete mDirModel;
    45     delete mDriveModel;
    46     delete mDriveModel;
       
    47     
       
    48     mDriveWatcher->cancelWatch();
       
    49     delete mDriveWatcher;
       
    50     mDriveWatcher = 0;
    46 }
    51 }
    47 
    52 
    48 QFileInfo FmFileWidget::currentPath() const
    53 QFileInfo FmFileWidget::currentPath() const
    49 {
    54 {
    50     QModelIndex index( mListView->rootIndex() );
    55     QModelIndex index( mListView->rootIndex() );
   140     qDebug( QTime::currentTime().toString().toUtf8().data() );
   145     qDebug( QTime::currentTime().toString().toUtf8().data() );
   141     setModel( mDriveModel );
   146     setModel( mDriveModel );
   142     qDebug("setmodel");
   147     qDebug("setmodel");
   143     qDebug( QTime::currentTime().toString().toUtf8().data() );
   148     qDebug( QTime::currentTime().toString().toUtf8().data() );
   144 
   149 
       
   150     mDriveWatcher = new FmDriveWatcher( this );
       
   151     mDriveWatcher->setObjectName( "driveWatcher" );
       
   152     mDriveWatcher->startWatch();
       
   153     
   145 //    QMetaObject::connectSlotsByName( this );
   154 //    QMetaObject::connectSlotsByName( this );
   146     connect( mListView, SIGNAL( activated( QModelIndex ) ),
   155     connect( mListView, SIGNAL( activated( QModelIndex ) ),
   147         this, SLOT( on_list_activated( QModelIndex ) ) );
   156         this, SLOT( on_list_activated( QModelIndex ) ) );
       
   157     
       
   158     connect( mDriveWatcher, SIGNAL( driveAddedOrChanged() ),
       
   159             this, SLOT( on_driveWatcher_driveAddedOrChanged() ) );
       
   160     
       
   161 
   148 }
   162 }
   149 
   163 
   150 void FmFileWidget::setModel( QAbstractItemModel *model )
   164 void FmFileWidget::setModel( QAbstractItemModel *model )
   151 {
   165 {
   152     mListView->setModel( model );
   166     mListView->setModel( model );
   176         cdUpPath = fileInfo.dir().absolutePath();
   190         cdUpPath = fileInfo.dir().absolutePath();
   177     }
   191     }
   178     setRootPath( FmUtils::fillPathWithSplash( cdUpPath ) );
   192     setRootPath( FmUtils::fillPathWithSplash( cdUpPath ) );
   179     return true;
   193     return true;
   180 }
   194 }
       
   195 
       
   196 void FmFileWidget::on_driveWatcher_driveAddedOrChanged()
       
   197 {
       
   198     FmLogger::log( QString( "FmFileDialog_FmFileWidget::on_driveWatcher_driveAddedOrChanged start" ) );
       
   199     mDriveModel->refresh();
       
   200     if( currentViewType() == DriveView ) {
       
   201         setModel( 0 );
       
   202         setModel( mDriveModel );
       
   203         emit pathChanged( QString() );
       
   204     } else if( currentViewType() == DirView ) {
       
   205         if( !FmUtils::isPathAccessabel( currentPath().absoluteFilePath() ) ) {
       
   206             // path not available, set model to drive
       
   207             FmLogger::log( QString( "FmFileDialog_FmFileWidget::on_driveWatcher_driveAddedOrChanged path not availeable, set drivemodel:"
       
   208                     + currentPath().absoluteFilePath() ) );
       
   209             setModel( mDriveModel );
       
   210             emit pathChanged( QString() );
       
   211         }
       
   212     }
       
   213     FmLogger::log( QString( "FmFileDialog_FmFileWidget::on_driveWatcher_driveAddedOrChanged end" ) );
       
   214 }