void DkImageContainerT::checkForFileUpdates() { #ifdef WITH_QUAZIP if(isFromZip()) setFilePath(getZipData()->getZipFilePath()); #endif QDateTime modifiedBefore = fileInfo().lastModified(); mFileInfo.refresh(); bool changed = false; // if image exists_not don't do this if (!mFileInfo.exists() && mLoadState == loaded) { changed = true; } if (mFileInfo.lastModified() != modifiedBefore) mWaitForUpdate = true; #ifdef WITH_QUAZIP if(isFromZip()) setFilePath(getZipData()->getImageFileName()); #endif if (changed) { mFileUpdateTimer.stop(); if (DkSettings::global.askToSaveDeletedFiles) { mEdited = changed; emit fileLoadedSignal(true); } return; } // we use our own file watcher, since the qt watcher // uses locks to check for updates. this might // be more accurate. however, the locks are pretty nasty // if the user e.g. wants to delete the file while watching // it in nomacs if (mWaitForUpdate && mFileInfo.isReadable()) { mWaitForUpdate = false; getThumb()->setImage(QImage()); loadImageThreaded(true); } }
bool DkImageContainerT::loadImageThreaded(bool force) { #ifdef WITH_QUAZIP //zip archives: get zip file fileInfo for checks if(isFromZip()) setFilePath(getZipData()->getZipFilePath()); #endif // check file for updates QFileInfo fileInfo = filePath(); QDateTime modifiedBefore = fileInfo.lastModified(); fileInfo.refresh(); if (force || fileInfo.lastModified() != modifiedBefore || getLoader()->isDirty()) { qDebug() << "updating image..."; getThumb()->setImage(QImage()); clear(); } // null file? if (fileInfo.fileName().isEmpty() || !fileInfo.exists()) { QString msg = tr("Sorry, the file: %1 does not exist... ").arg(fileName()); emit showInfoSignal(msg); mLoadState = exists_not; return false; } else if (!fileInfo.permission(QFile::ReadUser)) { QString msg = tr("Sorry, you are not allowed to read: %1").arg(fileName()); emit showInfoSignal(msg); mLoadState = exists_not; return false; } #ifdef WITH_QUAZIP //zip archives: use the image file info from now on if(isFromZip()) setFilePath(getZipData()->getImageFileName()); #endif mLoadState = loading; fetchFile(); return true; }
bool DkImageContainer::exists() { #ifdef WITH_QUAZIP if (isFromZip()) return true; #endif return QFileInfo(mFilePath).exists(); }
bool DkImageContainer::exists() { #ifdef WITH_QUAZIP if (isFromZip()) return true; #endif fileInfo.refresh(); return fileInfo.exists(); }
void DkImageContainerT::checkForFileUpdates() { #ifdef WITH_QUAZIP if(isFromZip()) fileInfo = zipData->getZipFileInfo(); #endif QDateTime modifiedBefore = fileInfo.lastModified(); fileInfo.refresh(); // if image exists_not don't do this if (!fileInfo.exists() && loadState == loaded) { edited = true; emit fileLoadedSignal(true); } if (fileInfo.lastModified() != modifiedBefore) waitForUpdate = true; #ifdef WITH_QUAZIP if(isFromZip()) fileInfo = zipData->getImageFileInfo(); #endif if (edited) { fileUpdateTimer.stop(); return; } // we use our own file watcher, since the qt watcher // uses locks to check for updates. this might // be more accurate. however, the locks are pretty nasty // if the user e.g. wants to delete the file while watching // it in nomacs if (waitForUpdate && fileInfo.isReadable()) { waitForUpdate = false; thumb->setImage(QImage()); loadImageThreaded(true); } }
QSharedPointer<DkThumbNailT> DkImageContainer::getThumb() { if (!mThumb) { #ifdef WITH_QUAZIP if(isFromZip()) mThumb = QSharedPointer<DkThumbNailT>(new DkThumbNailT(getZipData()->getEncodedFilePath())); else mThumb = QSharedPointer<DkThumbNailT>(new DkThumbNailT(mFilePath)); #else mThumb = QSharedPointer<DkThumbNailT>(new DkThumbNailT(mFilePath)); #endif } return mThumb; }
QSharedPointer<QByteArray> DkImageContainer::loadFileToBuffer(const QFileInfo fileInfo) { QFileInfo fInfo = fileInfo.isSymLink() ? fileInfo.symLinkTarget() : fileInfo; #ifdef WITH_QUAZIP if (isFromZip()) return zipData->extractImage(zipData->getZipFileInfo(), zipData->getImageFileInfo()); #endif if (fInfo.suffix().contains("psd")) { // for now just psd's are not cached because their file might be way larger than the part we need to read return QSharedPointer<QByteArray>(new QByteArray()); } QFile file(fInfo.absoluteFilePath()); file.open(QIODevice::ReadOnly); QSharedPointer<QByteArray> ba(new QByteArray(file.readAll())); file.close(); return ba; }
// DkImageContainerT -------------------------------------------------------------------- DkImageContainerT::DkImageContainerT(const QFileInfo& file) : DkImageContainer(file) { thumb = QSharedPointer<DkThumbNailT>(new DkThumbNailT(file)); #ifdef WITH_QUAZIP if(isFromZip()) thumb = QSharedPointer<DkThumbNailT>(new DkThumbNailT(zipData->getEncodedFileInfo())); #endif fetchingImage = false; fetchingBuffer = false; // our file watcher fileUpdateTimer.setSingleShot(false); fileUpdateTimer.setInterval(500); waitForUpdate = false; connect(&fileUpdateTimer, SIGNAL(timeout()), this, SLOT(checkForFileUpdates())); connect(&saveImageWatcher, SIGNAL(finished()), this, SLOT(savingFinished())); connect(&bufferWatcher, SIGNAL(finished()), this, SLOT(bufferLoaded())); connect(&imageWatcher, SIGNAL(finished()), this, SLOT(imageLoaded())); connect(loader.data(), SIGNAL(errorDialogSignal(const QString&)), this, SIGNAL(errorDialogSignal(const QString&))); connect(thumb.data(), SIGNAL(thumbLoadedSignal(bool)), this, SIGNAL(thumbLoadedSignal(bool))); //connect(&metaDataWatcher, SIGNAL(finished()), this, SLOT(metaDataLoaded())); }