From 25c6fd726dd13012c437b555158fe11d2d0f7302 Mon Sep 17 00:00:00 2001 From: Linas Valiukas Date: Sat, 2 Jun 2012 00:00:14 +0300 Subject: [PATCH] updater now works fine --- Fervor.pri | 12 +- fvavailableupdate.cpp | 97 ++++++++++++++++ fvavailableupdate.h | 51 +++++++++ fvupdateconfirmdialog.cpp | 30 +++++ fvupdateconfirmdialog.h | 5 +- fvupdateconfirmdialog.ui | 35 +----- fvupdater.cpp | 231 +++++++++++++++++++++++++++++--------- fvupdater.h | 120 ++++++++++++++------ fvupdatewindow.cpp | 46 ++++---- fvupdatewindow.h | 12 +- 10 files changed, 483 insertions(+), 156 deletions(-) create mode 100644 fvavailableupdate.cpp create mode 100644 fvavailableupdate.h diff --git a/Fervor.pri b/Fervor.pri index 2c583bd..77b4b2a 100644 --- a/Fervor.pri +++ b/Fervor.pri @@ -15,7 +15,6 @@ HEADERS += tests/fvversioncomparatortest.h - DEPENDPATH += "$$PWD" INCLUDEPATH += "$$PWD" @@ -23,15 +22,20 @@ SOURCES += fvupdatewindow.cpp \ fvupdater.cpp \ fvversioncomparator.cpp \ fvplatform.cpp \ - fvignoredversions.cpp + fvignoredversions.cpp \ + fvavailableupdate.cpp \ + fvupdateconfirmdialog.cpp HEADERS += fvupdatewindow.h \ fvupdater.h \ fvversioncomparator.h \ fvplatform.h \ - fvignoredversions.h + fvignoredversions.h \ + fvavailableupdate.h \ + fvupdateconfirmdialog.h -FORMS += fvupdatewindow.ui +FORMS += fvupdatewindow.ui \ + fvupdateconfirmdialog.ui TRANSLATIONS += fervor_lt.ts CODECFORTR = UTF-8 diff --git a/fvavailableupdate.cpp b/fvavailableupdate.cpp new file mode 100644 index 0000000..f0f6cb9 --- /dev/null +++ b/fvavailableupdate.cpp @@ -0,0 +1,97 @@ +#include "fvavailableupdate.h" + +FvAvailableUpdate::FvAvailableUpdate(QObject *parent) : + QObject(parent) +{ + // noop +} + +QString FvAvailableUpdate::GetTitle() +{ + return m_title; +} + +void FvAvailableUpdate::SetTitle(QString title) +{ + m_title = title; +} + +QUrl FvAvailableUpdate::GetReleaseNotesLink() +{ + return m_releaseNotesLink; +} + +void FvAvailableUpdate::SetReleaseNotesLink(QUrl releaseNotesLink) +{ + m_releaseNotesLink = releaseNotesLink; +} + +void FvAvailableUpdate::SetReleaseNotesLink(QString releaseNotesLink) +{ + SetReleaseNotesLink(QUrl(releaseNotesLink)); +} + +QString FvAvailableUpdate::GetPubDate() +{ + return m_pubDate; +} + +void FvAvailableUpdate::SetPubDate(QString pubDate) +{ + m_pubDate = pubDate; +} + +QUrl FvAvailableUpdate::GetEnclosureUrl() +{ + return m_enclosureUrl; +} + +void FvAvailableUpdate::SetEnclosureUrl(QUrl enclosureUrl) +{ + m_enclosureUrl = enclosureUrl; +} + +void FvAvailableUpdate::SetEnclosureUrl(QString enclosureUrl) +{ + SetEnclosureUrl(QUrl(enclosureUrl)); +} + +QString FvAvailableUpdate::GetEnclosureVersion() +{ + return m_enclosureVersion; +} + +void FvAvailableUpdate::SetEnclosureVersion(QString enclosureVersion) +{ + m_enclosureVersion = enclosureVersion; +} + +QString FvAvailableUpdate::GetEnclosurePlatform() +{ + return m_enclosurePlatform; +} + +void FvAvailableUpdate::SetEnclosurePlatform(QString enclosurePlatform) +{ + m_enclosurePlatform = enclosurePlatform; +} + +unsigned long FvAvailableUpdate::GetEnclosureLength() +{ + return m_enclosureLength; +} + +void FvAvailableUpdate::SetEnclosureLength(unsigned long enclosureLength) +{ + m_enclosureLength = enclosureLength; +} + +QString FvAvailableUpdate::GetEnclosureType() +{ + return m_enclosureType; +} + +void FvAvailableUpdate::SetEnclosureType(QString enclosureType) +{ + m_enclosureType = enclosureType; +} diff --git a/fvavailableupdate.h b/fvavailableupdate.h new file mode 100644 index 0000000..6bf3cf9 --- /dev/null +++ b/fvavailableupdate.h @@ -0,0 +1,51 @@ +#ifndef FVAVAILABLEUPDATE_H +#define FVAVAILABLEUPDATE_H + +#include +#include + +class FvAvailableUpdate : public QObject +{ + Q_OBJECT +public: + explicit FvAvailableUpdate(QObject *parent = 0); + + QString GetTitle(); + void SetTitle(QString title); + + QUrl GetReleaseNotesLink(); + void SetReleaseNotesLink(QUrl releaseNotesLink); + void SetReleaseNotesLink(QString releaseNotesLink); + + QString GetPubDate(); + void SetPubDate(QString pubDate); + + QUrl GetEnclosureUrl(); + void SetEnclosureUrl(QUrl enclosureUrl); + void SetEnclosureUrl(QString enclosureUrl); + + QString GetEnclosureVersion(); + void SetEnclosureVersion(QString enclosureVersion); + + QString GetEnclosurePlatform(); + void SetEnclosurePlatform(QString enclosurePlatform); + + unsigned long GetEnclosureLength(); + void SetEnclosureLength(unsigned long enclosureLength); + + QString GetEnclosureType(); + void SetEnclosureType(QString enclosureType); + +private: + QString m_title; + QUrl m_releaseNotesLink; + QString m_pubDate; + QUrl m_enclosureUrl; + QString m_enclosureVersion; + QString m_enclosurePlatform; + unsigned long m_enclosureLength; + QString m_enclosureType; + +}; + +#endif // FVAVAILABLEUPDATE_H diff --git a/fvupdateconfirmdialog.cpp b/fvupdateconfirmdialog.cpp index fba02b4..2029d7b 100644 --- a/fvupdateconfirmdialog.cpp +++ b/fvupdateconfirmdialog.cpp @@ -1,14 +1,44 @@ #include "fvupdateconfirmdialog.h" +#include "fvavailableupdate.h" +#include "fvupdater.h" #include "ui_fvupdateconfirmdialog.h" + FvUpdateConfirmDialog::FvUpdateConfirmDialog(QWidget *parent) : QDialog(parent), m_ui(new Ui::FvUpdateConfirmDialog) { m_ui->setupUi(this); + + // Delete on close + setAttribute(Qt::WA_DeleteOnClose, true); + + // Set the "close app, then reopen" string + QString closeReopenString = m_ui->downloadThisUpdateLabel->text().arg(QApplication::applicationName()); + m_ui->downloadThisUpdateLabel->setText(closeReopenString); + + // Connect buttons + connect(m_ui->confirmButtonBox, SIGNAL(accepted()), + FvUpdater::sharedUpdater(), SLOT(UpdateInstallationConfirmed())); + connect(m_ui->confirmButtonBox, SIGNAL(rejected()), + FvUpdater::sharedUpdater(), SLOT(UpdateInstallationNotConfirmed())); } FvUpdateConfirmDialog::~FvUpdateConfirmDialog() { delete m_ui; } + +bool FvUpdateConfirmDialog::UpdateWindowWithCurrentProposedUpdate() +{ + FvAvailableUpdate* proposedUpdate = FvUpdater::sharedUpdater()->GetProposedUpdate(); + if (! proposedUpdate) { + return false; + } + + QString downloadLinkString = m_ui->updateFileLinkLabel->text() + .arg(proposedUpdate->GetEnclosureUrl().toString()); + m_ui->updateFileLinkLabel->setText(downloadLinkString); + + return true; +} diff --git a/fvupdateconfirmdialog.h b/fvupdateconfirmdialog.h index a781ea7..5f72035 100644 --- a/fvupdateconfirmdialog.h +++ b/fvupdateconfirmdialog.h @@ -14,7 +14,10 @@ class FvUpdateConfirmDialog : public QDialog public: explicit FvUpdateConfirmDialog(QWidget *parent = 0); ~FvUpdateConfirmDialog(); - + + // Update the current update proposal from FvUpdater + bool UpdateWindowWithCurrentProposedUpdate(); + private: Ui::FvUpdateConfirmDialog* m_ui; }; diff --git a/fvupdateconfirmdialog.ui b/fvupdateconfirmdialog.ui index 925daf5..ebb081b 100644 --- a/fvupdateconfirmdialog.ui +++ b/fvupdateconfirmdialog.ui @@ -61,38 +61,5 @@ - - - confirmButtonBox - accepted() - FvUpdateConfirmDialog - accept() - - - 248 - 254 - - - 157 - 274 - - - - - confirmButtonBox - rejected() - FvUpdateConfirmDialog - reject() - - - 316 - 260 - - - 286 - 274 - - - - + diff --git a/fvupdater.cpp b/fvupdater.cpp index fe645ff..431b69b 100644 --- a/fvupdater.cpp +++ b/fvupdater.cpp @@ -1,10 +1,13 @@ #include "fvupdater.h" #include "fvupdatewindow.h" +#include "fvupdateconfirmdialog.h" #include "fvplatform.h" #include "fvignoredversions.h" +#include "fvavailableupdate.h" #include #include #include +#include #include #ifndef FV_APP_NAME @@ -16,8 +19,8 @@ #ifdef FV_DEBUG -// Unit tests -#include "fvversioncomparatortest.h" + // Unit tests +# include "fvversioncomparatortest.h" #endif @@ -52,6 +55,11 @@ void FvUpdater::drop() FvUpdater::FvUpdater() : QObject(0) { m_updaterWindow = 0; + m_updateConfirmationDialog = 0; + m_proposedUpdate = 0; + + // Translation mechanism + installTranslator(); #ifdef FV_DEBUG // Unit tests @@ -64,18 +72,72 @@ FvUpdater::FvUpdater() : QObject(0) FvUpdater::~FvUpdater() { - destroyUpdaterWindow(); + if (m_proposedUpdate) { + delete m_proposedUpdate; + m_proposedUpdate = 0; + } + + hideUpdateConfirmationDialog(); + hideUpdaterWindow(); +} + +void FvUpdater::installTranslator() +{ + QTranslator translator; + QString locale = QLocale::system().name(); + translator.load(QString("fervor_") + locale); + QTextCodec::setCodecForTr(QTextCodec::codecForName("utf8")); + qApp->installTranslator(&translator); +} + +void FvUpdater::showUpdaterWindowUpdatedWithCurrentUpdateProposal() +{ + // Destroy window if already exists + hideUpdaterWindow(); + + // Create a new window + m_updaterWindow = new FvUpdateWindow(); + m_updaterWindow->UpdateWindowWithCurrentProposedUpdate(); + m_updaterWindow->show(); } -void FvUpdater::destroyUpdaterWindow() +void FvUpdater::hideUpdaterWindow() { if (m_updaterWindow) { - m_updaterWindow->hide(); - delete m_updaterWindow; + if (! m_updaterWindow->close()) { + qWarning() << "Update window didn't close, leaking memory from now on"; + } + + // not deleting because of Qt::WA_DeleteOnClose + m_updaterWindow = 0; } } +void FvUpdater::showUpdateConfirmationDialogUpdatedWithCurrentUpdateProposal() +{ + // Destroy dialog if already exists + hideUpdateConfirmationDialog(); + + // Create a new window + m_updateConfirmationDialog = new FvUpdateConfirmDialog(); + m_updateConfirmationDialog->UpdateWindowWithCurrentProposedUpdate(); + m_updateConfirmationDialog->show(); +} + +void FvUpdater::hideUpdateConfirmationDialog() +{ + if (m_updateConfirmationDialog) { + if (! m_updateConfirmationDialog->close()) { + qWarning() << "Update confirmation dialog didn't close, leaking memory from now on"; + } + + // not deleting because of Qt::WA_DeleteOnClose + + m_updateConfirmationDialog = 0; + } +} + void FvUpdater::SetFeedURL(QString feedURL) { @@ -87,6 +149,72 @@ QString FvUpdater::GetFeedURL() return m_feedURL.toString(); } +FvAvailableUpdate* FvUpdater::GetProposedUpdate() +{ + return m_proposedUpdate; +} + + +void FvUpdater::InstallUpdate() +{ + qDebug() << "Install update"; + + showUpdateConfirmationDialogUpdatedWithCurrentUpdateProposal(); +} + +void FvUpdater::SkipUpdate() +{ + qDebug() << "Skip update"; + + FvAvailableUpdate* proposedUpdate = GetProposedUpdate(); + if (! proposedUpdate) { + qWarning() << "Proposed update is NULL (shouldn't be at this point)"; + return; + } + + // Start ignoring this particular version + FVIgnoredVersions::IgnoreVersion(proposedUpdate->GetEnclosureVersion()); + + hideUpdaterWindow(); + hideUpdateConfirmationDialog(); // if any; shouldn't be shown at this point, but who knows +} + +void FvUpdater::RemindMeLater() +{ + qDebug() << "Remind me later"; + + hideUpdaterWindow(); + hideUpdateConfirmationDialog(); // if any; shouldn't be shown at this point, but who knows +} + +void FvUpdater::UpdateInstallationConfirmed() +{ + qDebug() << "Confirm update installation"; + + FvAvailableUpdate* proposedUpdate = GetProposedUpdate(); + if (! proposedUpdate) { + qWarning() << "Proposed update is NULL (shouldn't be at this point)"; + return; + } + + // Open a link + if (! QDesktopServices::openUrl(proposedUpdate->GetEnclosureUrl())) { + showErrorDialog("Unable to open this link in a browser. Please do it manually."); + return; + } + + hideUpdaterWindow(); + hideUpdateConfirmationDialog(); +} + +void FvUpdater::UpdateInstallationNotConfirmed() +{ + qDebug() << "Do not confirm update installation"; + + hideUpdateConfirmationDialog(); // if any; shouldn't be shown at this point, but who knows + // leave the "update proposal window" inact +} + bool FvUpdater::CheckForUpdates(bool notifyAboutUpToDateApplication) { @@ -155,12 +283,12 @@ void FvUpdater::httpFeedReadyRead() void FvUpdater::httpFeedUpdateDataReadProgress(qint64 bytesRead, qint64 totalBytes) { + Q_UNUSED(bytesRead); + Q_UNUSED(totalBytes); + if (m_httpRequestAborted) { return; } - - Q_UNUSED(bytesRead); - Q_UNUSED(totalBytes); } void FvUpdater::httpFeedDownloadFinished() @@ -188,7 +316,7 @@ void FvUpdater::httpFeedDownloadFinished() } else { // Done. - parseFeedXML(); + xmlParseFeed(); } @@ -196,7 +324,7 @@ void FvUpdater::httpFeedDownloadFinished() m_reply = 0; } -bool FvUpdater::parseFeedXML() +bool FvUpdater::xmlParseFeed() { QString currentTag, currentQualifiedTag; @@ -231,22 +359,22 @@ bool FvUpdater::parseFeedXML() QXmlStreamAttributes attribs = m_xml.attributes(); if (attribs.hasAttribute("fervor:platform")) { - xmlEnclosurePlatform = attribs.value("fervor:platform").toString(); + xmlEnclosurePlatform = attribs.value("fervor:platform").toString().trimmed(); if (FvPlatform::CurrentlyRunningOnPlatform(xmlEnclosurePlatform)) { if (attribs.hasAttribute("url")) { - xmlEnclosureUrl = attribs.value("url").toString(); + xmlEnclosureUrl = attribs.value("url").toString().trimmed(); } else { xmlEnclosureUrl = ""; } if (attribs.hasAttribute("fervor:version")) { - xmlEnclosureVersion = attribs.value("fervor:version").toString(); + xmlEnclosureVersion = attribs.value("fervor:version").toString().trimmed(); } else { xmlEnclosureVersion = ""; } if (attribs.hasAttribute("sparkle:version")) { - xmlEnclosureVersion = attribs.value("sparkle:version").toString(); + xmlEnclosureVersion = attribs.value("sparkle:version").toString().trimmed(); } else { xmlEnclosureVersion = ""; } @@ -256,7 +384,7 @@ bool FvUpdater::parseFeedXML() xmlEnclosureLength = 0; } if (attribs.hasAttribute("type")) { - xmlEnclosureType = attribs.value("type").toString(); + xmlEnclosureType = attribs.value("type").toString().trimmed(); } else { xmlEnclosureType = ""; } @@ -275,7 +403,6 @@ bool FvUpdater::parseFeedXML() // here (because the topmost is the most recent one, and thus // the newest version. - return searchDownloadedFeedForUpdates(xmlTitle, xmlLink, xmlReleaseNotesLink, @@ -291,16 +418,16 @@ bool FvUpdater::parseFeedXML() } else if (m_xml.isCharacters() && ! m_xml.isWhitespace()) { if (currentTag == "title") { - xmlTitle += m_xml.text().toString(); + xmlTitle += m_xml.text().toString().trimmed(); } else if (currentTag == "link") { - xmlLink += m_xml.text().toString(); + xmlLink += m_xml.text().toString().trimmed(); } else if (currentQualifiedTag == "sparkle:releaseNotesLink") { - xmlReleaseNotesLink += m_xml.text().toString(); + xmlReleaseNotesLink += m_xml.text().toString().trimmed(); } else if (currentTag == "pubDate") { - xmlPubDate += m_xml.text().toString(); + xmlPubDate += m_xml.text().toString().trimmed(); } @@ -328,6 +455,11 @@ bool FvUpdater::searchDownloadedFeedForUpdates(QString xmlTitle, unsigned long xmlEnclosureLength, QString xmlEnclosureType) { + Q_UNUSED(xmlTitle); + Q_UNUSED(xmlPubDate); + Q_UNUSED(xmlEnclosureLength); + Q_UNUSED(xmlEnclosureType); + // Validate if (xmlReleaseNotesLink.isEmpty()) { if (xmlLink.isEmpty()) { @@ -361,37 +493,27 @@ bool FvUpdater::searchDownloadedFeedForUpdates(QString xmlTitle, return true; // Things have succeeded when you think of it. } - // Success! - - // Destroy window if already exists - destroyUpdaterWindow(); - m_updaterWindow = new FvUpdateWindow(); - m_updaterWindow->SetSuggestedApplicationVersion(xmlEnclosureVersion); - m_updaterWindow->SetReleaseNotesURL(xmlLink); - m_updaterWindow->show(); + // + // Success! At this point, we have found an update that can be proposed + // to the user. + // - /* - showErrorDialog(QString("Done!\n\n" - "xmlTitle = %1\n" - "xmlLink = %2\n" - "xmlReleaseNotesLink = %3\n" - "xmlPubDate = %4\n" - "xmlEnclosureUrl = %5\n" - "xmlEnclosureVersion = %6\n" - "xmlEnclosurePlatform = %7\n" - "xmlEnclosureLength = %8\n" - "xmlEnclosureType = %9") - .arg(xmlTitle, - xmlLink, - xmlReleaseNotesLink, - xmlPubDate, - xmlEnclosureUrl, - xmlEnclosureVersion, - xmlEnclosurePlatform, - QString::number(xmlEnclosureLength), - xmlEnclosureType)); - */ + if (m_proposedUpdate) { + delete m_proposedUpdate; m_proposedUpdate = 0; + } + m_proposedUpdate = new FvAvailableUpdate(); + m_proposedUpdate->SetTitle(xmlTitle); + m_proposedUpdate->SetReleaseNotesLink(xmlReleaseNotesLink); + m_proposedUpdate->SetPubDate(xmlPubDate); + m_proposedUpdate->SetEnclosureUrl(xmlEnclosureUrl); + m_proposedUpdate->SetEnclosureVersion(xmlEnclosureVersion); + m_proposedUpdate->SetEnclosurePlatform(xmlEnclosurePlatform); + m_proposedUpdate->SetEnclosureLength(xmlEnclosureLength); + m_proposedUpdate->SetEnclosureType(xmlEnclosureType); + + // Show "look, there's an update" window + showUpdaterWindowUpdatedWithCurrentUpdateProposal(); return true; } @@ -405,3 +527,12 @@ void FvUpdater::showErrorDialog(QString message) dlFailedMsgBox.setInformativeText(message); dlFailedMsgBox.exec(); } + +void FvUpdater::showInformationDialog(QString message) +{ + QMessageBox dlInformationMsgBox; + dlInformationMsgBox.setIcon(QMessageBox::Information); + dlInformationMsgBox.setText(tr("Information")); + dlInformationMsgBox.setInformativeText(message); + dlInformationMsgBox.exec(); +} diff --git a/fvupdater.h b/fvupdater.h index 736776c..722a938 100644 --- a/fvupdater.h +++ b/fvupdater.h @@ -7,6 +7,8 @@ #include #include class FvUpdateWindow; +class FvUpdateConfirmDialog; +class FvAvailableUpdate; class FvUpdater : public QObject @@ -18,49 +20,107 @@ class FvUpdater : public QObject // Singleton static FvUpdater* sharedUpdater(); static void drop(); - -public slots: // Set feed URL void SetFeedURL(QString feedURL); QString GetFeedURL(); + +public slots: // Check for updates bool CheckForUpdates(bool notifyAboutUpToDateApplication = false); + + // + // --------------------------------------------------- + // --------------------------------------------------- + // --------------------------------------------------- + // --------------------------------------------------- + // + +protected: + + friend class FvUpdateWindow; // Uses GetProposedUpdate() + friend class FvUpdateConfirmDialog; // Uses GetProposedUpdate() + FvAvailableUpdate* GetProposedUpdate(); + + +protected slots: + + // Update window button slots + void InstallUpdate(); + void SkipUpdate(); + void RemindMeLater(); + + // Update confirmation dialog button slots + void UpdateInstallationConfirmed(); + void UpdateInstallationNotConfirmed(); + private: - // Hide main constructor - FvUpdater(); - ~FvUpdater(); + // + // Singleton business + // + // (we leave just the declarations, so the compiler will warn us if we try + // to use those two functions by accident) + FvUpdater(); // Hide main constructor + ~FvUpdater(); // Hide main destructor + FvUpdater(const FvUpdater&); // Hide copy constructor + FvUpdater& operator=(const FvUpdater&); // Hide assign op + + static FvUpdater* m_Instance; // Singleton instance - // Hide copy constructor - FvUpdater(const FvUpdater&); - // Hide assign op - // we leave just the declarations, so the compiler will warn us - // if we try to use those two functions by accident - FvUpdater& operator=(const FvUpdater&); + // + // Windows / dialogs + // + FvUpdateWindow* m_updaterWindow; // Updater window (NULL if not shown) + void showUpdaterWindowUpdatedWithCurrentUpdateProposal(); // Show updater window + void hideUpdaterWindow(); // Hide + destroy m_updaterWindow - // Singleton instance - static FvUpdater* m_Instance; + FvUpdateConfirmDialog* m_updateConfirmationDialog; // Update confirmation dialog (NULL if not shown) + void showUpdateConfirmationDialogUpdatedWithCurrentUpdateProposal(); // Show update confirmation dialog + void hideUpdateConfirmationDialog(); // Hide + destroy m_updateConfirmationDialog - // Updater window - FvUpdateWindow* m_updaterWindow; + // Available update (NULL if not fetched) + FvAvailableUpdate* m_proposedUpdate; + + // "No updates" dialog was requested and should be shown even if no update was found + // (notifyAboutUpToDateApplication from CheckForUpdates() goes here) + bool m_showDialogEvenIfNoUpdatesWereFound; - // HTTP fetcher - QUrl m_feedURL; + // Dialogs (notifications) + void showErrorDialog(QString message); // Show an error message + void showInformationDialog(QString message); // Show an informational message + + + // + // HTTP feed fetcher infrastructure + // + QUrl m_feedURL; // Feed URL that is currently being fetched QNetworkAccessManager m_qnam; QNetworkReply* m_reply; int m_httpGetId; bool m_httpRequestAborted; - void startDownloadFeed(QUrl url); - void cancelDownloadFeed(); + void startDownloadFeed(QUrl url); // Start downloading feed + void cancelDownloadFeed(); // Stop downloading the current feed + +private slots: + void httpFeedReadyRead(); + void httpFeedUpdateDataReadProgress(qint64 bytesRead, + qint64 totalBytes); + void httpFeedDownloadFinished(); + + +private: + + // // XML parser - QXmlStreamReader m_xml; - bool parseFeedXML(); + // + QXmlStreamReader m_xml; // XML data collector and parser + bool xmlParseFeed(); // Parse feed in m_xml bool searchDownloadedFeedForUpdates(QString xmlTitle, QString xmlLink, QString xmlReleaseNotesLink, @@ -71,21 +131,11 @@ public slots: unsigned long xmlEnclosureLength, QString xmlEnclosureType); - // "No updates" dialog was requested - bool m_showDialogEvenIfNoUpdatesWereFound; - - void destroyUpdaterWindow(); - - // Show an error message - void showErrorDialog(QString message); - - -private slots: - void httpFeedReadyRead(); - void httpFeedUpdateDataReadProgress(qint64 bytesRead, - qint64 totalBytes); - void httpFeedDownloadFinished(); + // + // Helpers + // + void installTranslator(); // Initialize translation mechanism }; diff --git a/fvupdatewindow.cpp b/fvupdatewindow.cpp index 6825553..5b2e549 100644 --- a/fvupdatewindow.cpp +++ b/fvupdatewindow.cpp @@ -1,11 +1,11 @@ #include "fvupdatewindow.h" #include "ui_fvupdatewindow.h" -#include -#include +#include "fvupdater.h" +#include "fvavailableupdate.h" #include -#include #include #include +#include FvUpdateWindow::FvUpdateWindow(QWidget *parent) : @@ -14,44 +14,46 @@ FvUpdateWindow::FvUpdateWindow(QWidget *parent) : { m_ui->setupUi(this); - // Initialize translation - installTranslator(); + // Delete on close + setAttribute(Qt::WA_DeleteOnClose, true); // Set application icon QIcon appIcon = QApplication::windowIcon(); QGraphicsScene appIconScene; appIconScene.addPixmap(appIcon.pixmap(m_ui->appIconGraphicsView->size())); + // Set the "new version is available" string QString newVersString = m_ui->newVersionIsAvailableLabel->text().arg(QApplication::applicationName()); m_ui->newVersionIsAvailableLabel->setText(newVersString); + + // Connect buttons + connect(m_ui->installUpdateButton, SIGNAL(clicked()), + FvUpdater::sharedUpdater(), SLOT(InstallUpdate())); + connect(m_ui->skipThisVersionButton, SIGNAL(clicked()), + FvUpdater::sharedUpdater(), SLOT(SkipUpdate())); + connect(m_ui->remindMeLaterButton, SIGNAL(clicked()), + FvUpdater::sharedUpdater(), SLOT(RemindMeLater())); } FvUpdateWindow::~FvUpdateWindow() { + m_ui->releaseNotesWebView->stop(); delete m_ui; } -void FvUpdateWindow::SetSuggestedApplicationVersion(QString suggestedApplicationVersion) +bool FvUpdateWindow::UpdateWindowWithCurrentProposedUpdate() { - m_suggestedApplicationVersion = suggestedApplicationVersion; + FvAvailableUpdate* proposedUpdate = FvUpdater::sharedUpdater()->GetProposedUpdate(); + if (! proposedUpdate) { + return false; + } - QString downloadString = m_ui->wouldYouLikeToDownloadLabel->text().arg(QApplication::applicationName(), suggestedApplicationVersion, QApplication::applicationVersion()); + QString downloadString = m_ui->wouldYouLikeToDownloadLabel->text() + .arg(QApplication::applicationName(), proposedUpdate->GetEnclosureVersion(), QApplication::applicationVersion()); m_ui->wouldYouLikeToDownloadLabel->setText(downloadString); -} - -void FvUpdateWindow::SetReleaseNotesURL(QString releaseNotesUrl) -{ - m_releaseNotesUrl = QUrl(releaseNotesUrl); m_ui->releaseNotesWebView->stop(); - m_ui->releaseNotesWebView->load(m_releaseNotesUrl); -} + m_ui->releaseNotesWebView->load(proposedUpdate->GetReleaseNotesLink()); -void FvUpdateWindow::installTranslator() -{ - QTranslator translator; - QString locale = QLocale::system().name(); - translator.load(QString("fervor_") + locale); - QTextCodec::setCodecForTr(QTextCodec::codecForName("utf8")); - qApp->installTranslator(&translator); + return true; } diff --git a/fvupdatewindow.h b/fvupdatewindow.h index bade8dd..36dee00 100644 --- a/fvupdatewindow.h +++ b/fvupdatewindow.h @@ -2,7 +2,6 @@ #define FVUPDATEWINDOW_H #include -#include namespace Ui { class FvUpdateWindow; @@ -16,19 +15,12 @@ class FvUpdateWindow : public QWidget explicit FvUpdateWindow(QWidget *parent = 0); ~FvUpdateWindow(); - // Property setters for the dialog - void SetSuggestedApplicationVersion(QString suggestedApplicationVersion); - void SetReleaseNotesURL(QString releaseNotesUrl); + // Update the current update proposal from FvUpdater + bool UpdateWindowWithCurrentProposedUpdate(); private: Ui::FvUpdateWindow* m_ui; - // Dialog properties - QString m_suggestedApplicationVersion; - QUrl m_releaseNotesUrl; - - // Helpers - void installTranslator(); }; #endif // FVUPDATEWINDOW_H