Resolved issue #612. Valentina crashes when network is disabled on Linux.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2017-01-24 15:47:25 +02:00
parent 55509e523d
commit 1014cc86ca
8 changed files with 56 additions and 28 deletions

View File

@ -49,6 +49,7 @@
- [#595] GapWidth affecting to the margins.
- [#589] Valentina lock up if not enough space for label.
- [#606] Mac OS X. Cant 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.

View File

@ -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();
});

View File

@ -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();

View File

@ -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();
});

View File

@ -61,12 +61,7 @@ FvUpdater* FvUpdater::sharedUpdater()
if (m_Instance.isNull())
{
mutex.lock();
if (m_Instance.isNull())
{
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<FvAvailableUpdate> 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;
}
m_proposedUpdate = new FvAvailableUpdate(this);
m_proposedUpdate->SetEnclosureUrl(xmlEnclosureUrl);
m_proposedUpdate->SetEnclosureVersion(xmlEnclosureVersion);

View File

@ -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);
@ -104,8 +107,9 @@ private:
//
QUrl m_feedURL; // Feed URL that will be fetched
QNetworkAccessManager m_qnam;
QNetworkReply* m_reply;
QPointer<QNetworkReply> m_reply;
bool m_httpRequestAborted;
bool m_dropOnFinnish;
QXmlStreamReader m_xml; // XML data collector and parser

View File

@ -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);

View File

@ -51,8 +51,6 @@ private:
Q_DISABLE_COPY(FvUpdateWindow)
Ui::FvUpdateWindow* m_ui;
QGraphicsScene* m_appIconScene;
};
#endif // FVUPDATEWINDOW_H