Watching current dir for changes to reload file list
This commit is contained in:
+43
-28
@@ -70,6 +70,7 @@ void Image::imageLoaded(QImage img)
|
||||
|
||||
ImageRingList::ImageRingList(QObject *parent) : QObject(parent)
|
||||
{
|
||||
connect(&m_fileSystemWatcher, SIGNAL(directoryChanged(QString)), this, SLOT(dirChanged(QString)));
|
||||
}
|
||||
|
||||
bool ImageRingList::setDir(const QString path, const QString ¤tFile)
|
||||
@@ -88,39 +89,14 @@ bool ImageRingList::setDir(const QString path, const QString ¤tFile)
|
||||
absolutePaths.append(dir.absoluteFilePath(file));
|
||||
}
|
||||
setFiles(absolutePaths, currentFile);
|
||||
|
||||
m_fileSystemWatcher.removePaths(m_fileSystemWatcher.directories());
|
||||
m_fileSystemWatcher.addPath(path);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void ImageRingList::setFiles(const QStringList files, const QString ¤tFile)
|
||||
{
|
||||
m_images.clear();
|
||||
foreach(const QString &file, files)
|
||||
{
|
||||
ImagePtr ptr = make_shared<Image>(file);
|
||||
connect(ptr.get(), SIGNAL(pixmapLoaded(Image*)), this, SLOT(imageLoaded(Image*)));
|
||||
m_images.append(ptr);
|
||||
}
|
||||
|
||||
int index = files.indexOf(currentFile);
|
||||
if(index < 0)
|
||||
index = 0;
|
||||
|
||||
m_firstImage = m_currImage = m_lastImage = m_images.begin()+index;
|
||||
(*m_currImage)->load();
|
||||
|
||||
m_width = DEFAULT_WIDTH<m_images.size()/2 ? DEFAULT_WIDTH : m_images.size()/2;
|
||||
|
||||
for(int i=0; i<m_width; i++)
|
||||
{
|
||||
m_firstImage = decrement(m_firstImage);
|
||||
(*m_firstImage)->load();
|
||||
m_lastImage = increment(m_lastImage);
|
||||
(*m_lastImage)->load();
|
||||
}
|
||||
}
|
||||
|
||||
void ImageRingList::setFile(const QString &file)
|
||||
{
|
||||
QFileInfo info(file);
|
||||
@@ -161,6 +137,34 @@ void ImageRingList::decrement()
|
||||
}
|
||||
}
|
||||
|
||||
void ImageRingList::setFiles(const QStringList files, const QString ¤tFile)
|
||||
{
|
||||
m_images.clear();
|
||||
foreach(const QString &file, files)
|
||||
{
|
||||
ImagePtr ptr = make_shared<Image>(file);
|
||||
connect(ptr.get(), SIGNAL(pixmapLoaded(Image*)), this, SLOT(imageLoaded(Image*)));
|
||||
m_images.append(ptr);
|
||||
}
|
||||
|
||||
int index = files.indexOf(currentFile);
|
||||
if(index < 0)
|
||||
index = 0;
|
||||
|
||||
m_firstImage = m_currImage = m_lastImage = m_images.begin()+index;
|
||||
(*m_currImage)->load();
|
||||
|
||||
m_width = DEFAULT_WIDTH<m_images.size()/2 ? DEFAULT_WIDTH : m_images.size()/2;
|
||||
|
||||
for(int i=0; i<m_width; i++)
|
||||
{
|
||||
m_firstImage = decrement(m_firstImage);
|
||||
(*m_firstImage)->load();
|
||||
m_lastImage = increment(m_lastImage);
|
||||
(*m_lastImage)->load();
|
||||
}
|
||||
}
|
||||
|
||||
QList<ImagePtr>::iterator ImageRingList::increment(QList<ImagePtr>::iterator iter)
|
||||
{
|
||||
iter++;
|
||||
@@ -184,3 +188,14 @@ void ImageRingList::imageLoaded(Image *image)
|
||||
emit pixmapLoaded(image->pixmap());
|
||||
}
|
||||
}
|
||||
|
||||
void ImageRingList::dirChanged(QString dir)
|
||||
{
|
||||
QString currentFile;
|
||||
|
||||
if(m_images.size())
|
||||
currentFile = (*m_currImage)->name();
|
||||
|
||||
setDir(dir, currentFile);
|
||||
emit currentImageChanged();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user