10#include <QFileSystemWatcher>
11#include <QRandomGenerator>
12#include <QApplication>
102 if (QFileInfo(path).exists()) {
108 if (oldState ==
Lost) {
136 const bool shouldSpitWarning =
137 absenceTimeMSec <= 600000 &&
138 ((absenceTimeMSec >= 60000 && (absenceTimeMSec % 60000 == 0)) ||
139 (absenceTimeMSec >= 10000 && (absenceTimeMSec % 10000 == 0)));
141 if (shouldSpitWarning) {
143 QTextStream log(&message);
146 log <<
"WARNING: couldn't reconnect to a removed file layer's file (" << path <<
"). File is not available for " << absenceTimeMSec / 1000 <<
" seconds";
148 qWarning() << message;
151 if (absenceTimeMSec == 600000) {
155 log <<
"Giving up... :( No more reports about " << path;
157 qWarning() << message;
170 if (it.value().state ==
Lost)
189 return QFileInfo(path).absoluteFilePath();
211 QScopedPointer<KisDocument>
doc;
213 bool isLoading =
false;
214 bool fileChangedFlag =
false;
218 qint64 initialFileSize {0};
221 int failureCount {0};
243 s_fileSystemWatcher->removePath(
m_d->
path);
251 if (path.isEmpty())
return;
254 s_fileSystemWatcher->removePath(
m_d->
path);
258 s_fileSystemWatcher->addPath(
m_d->
path);
288 QFileInfo initialFileInfo(
m_d->
path);
300 QDir::tempPath() +
'/' +
301 QString(
"krita_file_layer_copy_%1_%2.%3")
302 .arg(QApplication::applicationPid())
303 .arg(QRandomGenerator::global()->generate())
304 .arg(initialFileInfo.suffix());
312 QApplication::processEvents();
319 QFileInfo originalInfo(
m_d->
path);
321 bool successfullyLoaded =
false;
329 m_d->
doc->setFileBatchMode(
true);
331 if (
m_d->
path.toLower().endsWith(
"ora") ||
m_d->
path.toLower().endsWith(
"kra")) {
333 if (store && !store->bad()) {
334 if (store->open(QString(
"mergedimage.png"))) {
335 QByteArray bytes = store->read(store->size());
338 mergedImage.loadFromData(bytes);
339 Q_ASSERT(!mergedImage.isNull());
342 constexpr double DOTS_PER_METER_TO_DOTS_PER_INCH = 0.00035285815102328864;
343 double xres = mergedImage.dotsPerMeterX() * DOTS_PER_METER_TO_DOTS_PER_INCH;
344 double yres = mergedImage.dotsPerMeterY() * DOTS_PER_METER_TO_DOTS_PER_INCH;
351 m_d->
doc->setCurrentImage(image);
352 successfullyLoaded =
true;
355 qWarning() <<
"delayedLoadStart: Could not open mergedimage.png";
359 qWarning() <<
"delayedLoadStart: Store was bad";
366 if (successfullyLoaded) {
369 m_d->
doc->image()->waitForDone();
373 dbgKrita <<
"File was modified externally. Restarting.";
385 if (!successfullyLoaded) {
400 m_d->
doc->image()->xRes(),
401 m_d->
doc->image()->yRes(),
402 m_d->
doc->image()->size());
408#include "kis_safe_document_loader.moc"
Q_GLOBAL_STATIC(KisStoragePluginRegistry, s_instance)
const quint8 OPACITY_OPAQUE_U8
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
QHash< QString, int > m_pathCount
static QString unifyFilePath(const QString &path)
QStringList files() const
bool addPath(const QString &file)
QHash< QString, FileEntry > m_fileEntries
KisSignalCompressor m_reattachmentCompressor
void slotFileChanged(const QString &path)
FileSystemWatcherWrapper()
void fileExistsStateChanged(const QString &path, bool exists)
QFileSystemWatcher m_watcher
KisSignalCompressor m_lostCompressor
bool removePath(const QString &file)
void fileChanged(const QString &path)
QHash< QString, int > m_lostFilesAbsenceCounter
KisGroupLayerSP rootLayer() const
void initialRefreshGraph()
void setResolution(double xres, double yres)
void convertFromQImage(const QImage &image, const KoColorProfile *profile, qint32 offsetX=0, qint32 offsetY=0)
void makeCloneFrom(KisPaintDeviceSP src, const QRect &rect)
static KisPart * instance()
~KisSafeDocumentLoader() override
void fileChangedCompressed(bool sync=false)
void fileChanged(QString)
void fileExistsStateChanged(bool fileExists)
void setPath(const QString &path)
void loadingFinished(KisPaintDeviceSP paintDevice, qreal xRes, qreal yRes, const QSize &size)
void slotFileExistsStateChanged(const QString &path, bool fileExists)
KisSafeDocumentLoader(const QString &path="", QObject *parent=0)
static void log(const QString &message)
Logs with date/time.
static KoStore * createStore(const QString &fileName, Mode mode, const QByteArray &appIdentification=QByteArray(), Backend backend=Auto, bool writeMimetype=true)
#define KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(cond, val)
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
void forceAllDelayedNodesUpdate(KisNodeSP root)
void setUtf8OnStream(QTextStream &stream)
bool addNode(KisNodeSP node, KisNodeSP parent=KisNodeSP(), KisNodeAdditionFlags flags=KisNodeAdditionFlag::None)
KisPaintDeviceSP paintDevice
QDateTime initialFileTimeStamp
KisSignalCompressor fileChangedSignalCompressor
QScopedPointer< KisDocument > doc
static KoColorSpaceRegistry * instance()
const KoColorSpace * rgb8(const QString &profileName=QString())