Browse Source

MdEditor: close the temporary file explicitly after writing

Le Tan 7 years ago
parent
commit
dc9c9f6bbd
4 changed files with 10 additions and 4 deletions
  1. 2 1
      src/vdownloader.cpp
  2. 1 0
      src/vdownloader.h
  3. 7 2
      src/vmdeditor.cpp
  4. 0 1
      src/vpreviewmanager.cpp

+ 2 - 1
src/vdownloader.cpp

@@ -17,7 +17,8 @@ void VDownloader::handleDownloadFinished(QNetworkReply *reply)
 
     data = reply->readAll();
     reply->deleteLater();
-    emit downloadFinished(data, reply->url().toString());
+    // The url() of the reply may be redirected and different from that of the request.
+    emit downloadFinished(data, reply->request().url().toString());
 }
 
 static QNetworkRequest networkRequest(const QUrl &p_url)

+ 1 - 0
src/vdownloader.h

@@ -18,6 +18,7 @@ public:
     static QByteArray downloadSync(const QUrl &p_url);
 
 signals:
+    // Url is the original url of the request.
     void downloadFinished(const QByteArray &data, const QString &url);
 
 private slots:

+ 7 - 2
src/vmdeditor.cpp

@@ -1719,6 +1719,7 @@ void VMdEditor::exportGraphAndCopy(const QString &p_lang,
     }
 
     if (out.isEmpty() || m_exportTempFile->write(out) == -1) {
+        m_exportTempFile->close();
         VUtils::showMessage(QMessageBox::Warning,
                             tr("Warning"),
                             tr("Fail to export graph."),
@@ -1727,8 +1728,11 @@ void VMdEditor::exportGraphAndCopy(const QString &p_lang,
                             QMessageBox::Ok,
                             this);
     } else {
+        m_exportTempFile->close();
+
         QClipboard *clipboard = QApplication::clipboard();
         clipboard->clear();
+
         QImage img;
         img.loadFromData(out, p_format.toLocal8Bit().data());
         if (!img.isNull()) {
@@ -1741,8 +1745,6 @@ void VMdEditor::exportGraphAndCopy(const QString &p_lang,
             emit m_object->statusMessage(tr("Fail to read exported image: %1").arg(filePath));
         }
     }
-
-    m_exportTempFile->close();
 }
 
 void VMdEditor::parseAndPaste()
@@ -2064,6 +2066,9 @@ void VMdEditor::replaceTextWithLocalImages(QString &p_text)
                 if (tmpFile->open() && tmpFile->write(data) > -1) {
                     srcImagePath = tmpFile->fileName();
                 }
+
+                // Need to close it explicitly to flush cache of small file.
+                tmpFile->close();
             }
         }
 

+ 0 - 1
src/vpreviewmanager.cpp

@@ -59,7 +59,6 @@ void VPreviewManager::imageDownloaded(const QByteArray &p_data, const QString &p
 
     QPixmap image;
     image.loadFromData(p_data);
-
     if (!image.isNull()) {
         m_editor->addImage(name, image);
         emit requestUpdateImageLinks();