Commit 0c4e6f84 authored by Hugo Beauzee-Luyssen's avatar Hugo Beauzee-Luyssen Committed by Ludovic Fauvet

Added simple directory watching.

parent 504484b5
......@@ -55,10 +55,17 @@ FileBrowser::FileBrowser( QWidget* parent ) : QWidget( parent )
m_ui.treeViewBrowser->setColumnHidden( 3, true );
m_ui.pushButtonBackward->setEnabled( false );
m_ui.pushButtonForward->setEnabled( false );
m_fsWatcher = new QFileSystemWatcher;
m_fsWatcher->addPath( QDir::homePath() );
m_currentlyWatchedDir = QDir::homePath();
connect( m_fsWatcher, SIGNAL( directoryChanged(QString) ), m_DirsModel, SLOT( refresh() ) );
connect( m_fsWatcher, SIGNAL( directoryChanged(QString) ), m_FilesModel, SLOT( refresh() ) );
}
FileBrowser::~FileBrowser()
{
delete m_fsWatcher;
delete m_DirsModel;
delete m_FilesModel;
delete m_forwadEntries;
......@@ -85,6 +92,7 @@ void FileBrowser::TreeViewBrowserDirectoryChanged( QModelIndex& index, bool hist
{
if ( m_DirsModel->isDir( index ) )
{
updateFsWatcher( m_DirsModel->filePath( index ) );
if ( history == true )
addElementToHistory();
m_ui.listViewBrowser->setRootIndex( m_FilesModel->index( m_DirsModel->filePath( index ) ) );
......@@ -102,11 +110,12 @@ void FileBrowser::on_listViewBrowser_doubleClicked( QModelIndex index )
{
if ( m_FilesModel->isDir( index ) )
{
updateFsWatcher( m_FilesModel->filePath( index ) );
ListViewBrowserDirectoryChanged( index );
m_forwadEntries->clear();
m_ui.pushButtonForward->setEnabled( false );
}
else
else //TODO: this should be a signal.
Library::getInstance()->newMediaLoadingAsked( m_FilesModel->filePath( index ) );
}
......@@ -145,3 +154,10 @@ void FileBrowser::on_pushButtonParent_clicked()
m_ui.treeViewBrowser->setCurrentIndex( m_DirsModel->index( m_FilesModel->filePath( m_ui.listViewBrowser->rootIndex() ) ) );
}
}
void FileBrowser::updateFsWatcher( const QString& newPath )
{
m_fsWatcher->removePath( m_currentlyWatchedDir );
m_currentlyWatchedDir = newPath;
m_fsWatcher->addPath( newPath );
}
......@@ -26,6 +26,7 @@
#include <QWidget>
#include <QDirModel>
#include <QStack>
#include <QFileSystemWatcher>
#include "ui_FileBrowser.h"
class FileBrowser : public QWidget
......@@ -38,11 +39,15 @@ private:
void addElementToHistory();
void ListViewBrowserDirectoryChanged( QModelIndex& index, bool history = true );
void TreeViewBrowserDirectoryChanged( QModelIndex& index, bool history = true );
void updateFsWatcher( const QString& newPath );
private:
Ui::FileBrowser m_ui;
QDirModel* m_DirsModel;
QDirModel* m_FilesModel;
QStack<QModelIndex>* m_previousEntries;
QStack<QModelIndex>* m_forwadEntries;
QFileSystemWatcher* m_fsWatcher;
QString m_currentlyWatchedDir;
private slots:
void on_pushButtonParent_clicked();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment