diff --git a/imageringlist.cpp b/imageringlist.cpp index ee21eea..5dc6402 100644 --- a/imageringlist.cpp +++ b/imageringlist.cpp @@ -94,6 +94,7 @@ void Image::imageLoaded(QImage img) } ImageRingList::ImageRingList(QObject *parent) : QObject(parent) + , m_liveMode(false) { connect(&m_fileSystemWatcher, SIGNAL(directoryChanged(QString)), this, SLOT(dirChanged(QString))); } @@ -107,13 +108,13 @@ bool ImageRingList::setDir(const QString path, const QString ¤tFile) QStringList nameFilter; nameFilter << "*.jpg" << "*.png" << "*.cr2"; - QStringList list = dir.entryList(nameFilter, QDir::Files | QDir::Readable, QDir::Name); + QStringList list = dir.entryList(nameFilter, QDir::Files | QDir::Readable, m_liveMode ? QDir::Time : QDir::Name); QStringList absolutePaths; foreach(const QString &file, list) { absolutePaths.append(dir.absoluteFilePath(file)); } - setFiles(absolutePaths, currentFile); + setFiles(absolutePaths, m_liveMode ? list.first() : currentFile); m_fileSystemWatcher.removePaths(m_fileSystemWatcher.directories()); m_fileSystemWatcher.addPath(path); @@ -162,6 +163,11 @@ void ImageRingList::decrement() } } +void ImageRingList::setLiveMode(bool live) +{ + m_liveMode = live; +} + void ImageRingList::setFiles(const QStringList files, const QString ¤tFile) { m_images.clear(); diff --git a/imageringlist.h b/imageringlist.h index 6c516e1..96f93c9 100644 --- a/imageringlist.h +++ b/imageringlist.h @@ -37,6 +37,7 @@ class ImageRingList : public QObject QList::iterator m_currImage; QList::iterator m_lastImage; QFileSystemWatcher m_fileSystemWatcher; + bool m_liveMode; public: explicit ImageRingList(QObject *parent = 0); bool setDir(const QString path, const QString ¤tFile = QString()); @@ -44,6 +45,7 @@ public: ImagePtr currentImage(); void increment(); void decrement(); + void setLiveMode(bool live); protected: void setFiles(const QStringList files, const QString ¤tFile = QString()); QList::iterator increment(QList::iterator iter); diff --git a/mainwindow.cpp b/mainwindow.cpp index ac9a33c..68fd4cb 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -34,6 +34,8 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), QMenu *fileMenu = new QMenu(tr("File"), this); fileMenu->addAction(tr("Open"), this, SLOT(openFile()), QKeySequence("Ctrl+O")); fileMenu->addAction(tr("Copy marked files"), this, SLOT(copyMarked())); + QAction *liveModeAction = fileMenu->addAction(tr("Live mode"), this, SLOT(liveMode(bool))); + liveModeAction->setCheckable(true); fileMenu->addAction(tr("Exit"), this, SLOT(close())); menuBar()->addMenu(fileMenu); @@ -225,6 +227,11 @@ void MainWindow::copyMarked() } } +void MainWindow::liveMode(bool active) +{ + m_ringList->setLiveMode(active); +} + void MainWindow::updateWindowTitle() { ImagePtr ptr = m_ringList->currentImage(); diff --git a/mainwindow.h b/mainwindow.h index abb79ce..9caca6a 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -35,6 +35,7 @@ protected slots: void markAndNext(); void unmarkAndNext(); void copyMarked(); + void liveMode(bool active); }; #endif // MAINWINDOW_H