From 1014cc86ca9b3210dc2bbd232b5998d279115587 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Tue, 24 Jan 2017 15:47:25 +0200 Subject: [PATCH] Resolved issue #612. Valentina crashes when network is disabled on Linux. --HG-- branch : develop --- ChangeLog.txt | 1 + src/app/tape/dialogs/dialogabouttape.cpp | 2 + src/app/tape/main.cpp | 3 -- src/app/valentina/dialogs/dialogaboutapp.cpp | 5 +- src/libs/fervor/fvupdater.cpp | 56 ++++++++++++++------ src/libs/fervor/fvupdater.h | 12 +++-- src/libs/fervor/fvupdatewindow.cpp | 3 +- src/libs/fervor/fvupdatewindow.h | 2 - 8 files changed, 56 insertions(+), 28 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 55a8e3a1d..0539717c8 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -49,6 +49,7 @@ - [#595] GapWidth affecting to the margins. - [#589] Valentina lock up if not enough space for label. - [#606] Mac OS X. Can’t type in measurements due to digit count limitation. +- [#612] Valentina crashes when network is disabled on Linux. # Version 0.4.6 - [#594] Broken export on Mac. diff --git a/src/app/tape/dialogs/dialogabouttape.cpp b/src/app/tape/dialogs/dialogabouttape.cpp index dbf3e2340..ad42e2855 100644 --- a/src/app/tape/dialogs/dialogabouttape.cpp +++ b/src/app/tape/dialogs/dialogabouttape.cpp @@ -60,6 +60,8 @@ DialogAboutTape::DialogAboutTape(QWidget *parent) connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &DialogAboutTape::close); connect(ui->pushButtonCheckUpdate, &QPushButton::clicked, []() { + // Set feed URL before doing anything else + FvUpdater::sharedUpdater()->SetFeedURL(defaultFeedURL); FvUpdater::sharedUpdater()->CheckForUpdatesNotSilent(); }); diff --git a/src/app/tape/main.cpp b/src/app/tape/main.cpp index b5ed4d63d..1cccb6535 100644 --- a/src/app/tape/main.cpp +++ b/src/app/tape/main.cpp @@ -56,9 +56,6 @@ int main(int argc, char *argv[]) MApplication app(argc, argv); app.InitOptions(); - // Set feed URL before doing anything else - FvUpdater::sharedUpdater()->SetFeedURL(defaultFeedURL); - QTimer::singleShot(0, &app, SLOT(ProcessCMD())); return app.exec(); diff --git a/src/app/valentina/dialogs/dialogaboutapp.cpp b/src/app/valentina/dialogs/dialogaboutapp.cpp index 8439083c4..4d4fb5f94 100644 --- a/src/app/valentina/dialogs/dialogaboutapp.cpp +++ b/src/app/valentina/dialogs/dialogaboutapp.cpp @@ -69,7 +69,10 @@ DialogAboutApp::DialogAboutApp(QWidget *parent) : } }); - connect(ui->pushButtonCheckUpdate, &QPushButton::clicked, [](){ + connect(ui->pushButtonCheckUpdate, &QPushButton::clicked, []() + { + // Set feed URL before doing anything else + FvUpdater::sharedUpdater()->SetFeedURL(defaultFeedURL); FvUpdater::sharedUpdater()->CheckForUpdatesNotSilent(); }); diff --git a/src/libs/fervor/fvupdater.cpp b/src/libs/fervor/fvupdater.cpp index e245bbbc6..2767e58f5 100644 --- a/src/libs/fervor/fvupdater.cpp +++ b/src/libs/fervor/fvupdater.cpp @@ -61,12 +61,7 @@ FvUpdater* FvUpdater::sharedUpdater() if (m_Instance.isNull()) { mutex.lock(); - - if (m_Instance.isNull()) - { - m_Instance = new FvUpdater; - } - + m_Instance = new FvUpdater; mutex.unlock(); } @@ -92,6 +87,7 @@ FvUpdater::FvUpdater() m_qnam(), m_reply(nullptr), m_httpRequestAborted(false), + m_dropOnFinnish(true), m_xml() { // noop @@ -101,6 +97,7 @@ FvUpdater::FvUpdater() FvUpdater::~FvUpdater() { hideUpdaterWindow(); + delete m_reply; } //--------------------------------------------------------------------------------------------------------------------- @@ -142,6 +139,18 @@ QString FvUpdater::GetFeedURL() const return m_feedURL.toString(); } +//--------------------------------------------------------------------------------------------------------------------- +bool FvUpdater::IsDropOnFinnish() const +{ + return m_dropOnFinnish; +} + +//--------------------------------------------------------------------------------------------------------------------- +void FvUpdater::SetDropOnFinnish(bool value) +{ + m_dropOnFinnish = value; +} + //--------------------------------------------------------------------------------------------------------------------- QPointer FvUpdater::GetProposedUpdate() { @@ -255,10 +264,19 @@ bool FvUpdater::CheckForUpdatesSilent() { if (qApp->Settings()->GetDateOfLastRemind().daysTo(QDate::currentDate()) >= 1) { - return CheckForUpdates(true); + const bool success = CheckForUpdates(true); + if (m_dropOnFinnish && not success) + { + drop(); + } + return success; } else { + if (m_dropOnFinnish) + { + drop(); + } return true; } } @@ -266,7 +284,12 @@ bool FvUpdater::CheckForUpdatesSilent() //--------------------------------------------------------------------------------------------------------------------- bool FvUpdater::CheckForUpdatesNotSilent() { - return CheckForUpdates(false); + const bool success = CheckForUpdates(false); + if (m_dropOnFinnish && not success) + { + drop(); + } + return success; } //--------------------------------------------------------------------------------------------------------------------- @@ -281,7 +304,7 @@ void FvUpdater::startDownloadFeed(const QUrl &url) m_reply = m_qnam.get(request); - connect(m_reply, &QNetworkReply::readyRead, RECEIVER(this)[this]() + connect(m_reply.data(), &QNetworkReply::readyRead, RECEIVER(this)[this]() { // this slot gets called every time the QNetworkReply has new data. // We read all of its new data and write it into the file. @@ -289,7 +312,7 @@ void FvUpdater::startDownloadFeed(const QUrl &url) // signal of the QNetworkReply m_xml.addData(m_reply->readAll()); }); - connect(m_reply, &QNetworkReply::downloadProgress, RECEIVER(this)[this](qint64 bytesRead, qint64 totalBytes) + connect(m_reply.data(), &QNetworkReply::downloadProgress, RECEIVER(this)[this](qint64 bytesRead, qint64 totalBytes) { Q_UNUSED(bytesRead) Q_UNUSED(totalBytes) @@ -299,7 +322,7 @@ void FvUpdater::startDownloadFeed(const QUrl &url) return; } }); - connect(m_reply, &QNetworkReply::finished, this, &FvUpdater::httpFeedDownloadFinished); + connect(m_reply.data(), &QNetworkReply::finished, this, &FvUpdater::httpFeedDownloadFinished); } //--------------------------------------------------------------------------------------------------------------------- @@ -344,7 +367,11 @@ void FvUpdater::httpFeedDownloadFinished() } m_reply->deleteLater(); - m_reply = 0; + + if (m_dropOnFinnish) + { + drop(); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -460,10 +487,7 @@ bool FvUpdater::searchDownloadedFeedForUpdates(const QString &xmlEnclosureUrl, // to the user. // - if (m_proposedUpdate) - { - delete m_proposedUpdate; - } + delete m_proposedUpdate; m_proposedUpdate = new FvAvailableUpdate(this); m_proposedUpdate->SetEnclosureUrl(xmlEnclosureUrl); m_proposedUpdate->SetEnclosureVersion(xmlEnclosureVersion); diff --git a/src/libs/fervor/fvupdater.h b/src/libs/fervor/fvupdater.h index c8a4ae477..c24a09d34 100644 --- a/src/libs/fervor/fvupdater.h +++ b/src/libs/fervor/fvupdater.h @@ -55,6 +55,9 @@ public: void SetFeedURL(const QString &feedURL); QString GetFeedURL() const; + bool IsDropOnFinnish() const; + void SetDropOnFinnish(bool value); + public slots: // Check for updates bool CheckForUpdates(bool silentAsMuchAsItCouldGet = true); @@ -102,10 +105,11 @@ private: // // HTTP feed fetcher infrastructure // - QUrl m_feedURL; // Feed URL that will be fetched - QNetworkAccessManager m_qnam; - QNetworkReply* m_reply; - bool m_httpRequestAborted; + QUrl m_feedURL; // Feed URL that will be fetched + QNetworkAccessManager m_qnam; + QPointer m_reply; + bool m_httpRequestAborted; + bool m_dropOnFinnish; QXmlStreamReader m_xml; // XML data collector and parser diff --git a/src/libs/fervor/fvupdatewindow.cpp b/src/libs/fervor/fvupdatewindow.cpp index d02c43c3c..964369a53 100644 --- a/src/libs/fervor/fvupdatewindow.cpp +++ b/src/libs/fervor/fvupdatewindow.cpp @@ -36,8 +36,7 @@ class QWidget; //--------------------------------------------------------------------------------------------------------------------- FvUpdateWindow::FvUpdateWindow(QWidget *parent) : QDialog(parent), - m_ui(new Ui::FvUpdateWindow), - m_appIconScene(nullptr) + m_ui(new Ui::FvUpdateWindow) { m_ui->setupUi(this); diff --git a/src/libs/fervor/fvupdatewindow.h b/src/libs/fervor/fvupdatewindow.h index 64926f9d3..b27378f54 100644 --- a/src/libs/fervor/fvupdatewindow.h +++ b/src/libs/fervor/fvupdatewindow.h @@ -51,8 +51,6 @@ private: Q_DISABLE_COPY(FvUpdateWindow) Ui::FvUpdateWindow* m_ui; - QGraphicsScene* m_appIconScene; - }; #endif // FVUPDATEWINDOW_H