mirror of
https://github.com/Palm1r/QodeAssist.git
synced 2025-07-18 04:54:30 -04:00
refactor: Simplify update mechanism (#159)
This commit is contained in:
@ -23,6 +23,8 @@
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
#include <extensionsystem/pluginspec.h>
|
||||
#include <QDesktopServices>
|
||||
#include <QHBoxLayout>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
namespace QodeAssist {
|
||||
|
||||
@ -32,7 +34,7 @@ UpdateDialog::UpdateDialog(QWidget *parent)
|
||||
{
|
||||
setWindowTitle(tr("QodeAssist Update"));
|
||||
setMinimumWidth(400);
|
||||
setMinimumHeight(500);
|
||||
setMinimumHeight(300);
|
||||
|
||||
m_layout = new QVBoxLayout(this);
|
||||
m_layout->setSpacing(12);
|
||||
@ -61,34 +63,24 @@ UpdateDialog::UpdateDialog(QWidget *parent)
|
||||
m_layout->addWidget(m_titleLabel);
|
||||
|
||||
m_versionLabel = new QLabel(
|
||||
tr("Version %1 is now available - you have %2").arg(m_updater->currentVersion()), this);
|
||||
tr("Version %1 is now available - you have %2").arg("", m_updater->currentVersion()), this);
|
||||
m_versionLabel->setAlignment(Qt::AlignCenter);
|
||||
m_layout->addWidget(m_versionLabel);
|
||||
|
||||
m_releaseLink = new QLabel(this);
|
||||
m_releaseLink->setOpenExternalLinks(true);
|
||||
m_releaseLink->setTextFormat(Qt::RichText);
|
||||
m_releaseLink->setAlignment(Qt::AlignCenter);
|
||||
m_layout->addWidget(m_releaseLink);
|
||||
m_changelogLabel = new QLabel(tr("Release Notes:"), this);
|
||||
m_layout->addWidget(m_changelogLabel);
|
||||
|
||||
if (!m_changelogLabel) {
|
||||
m_changelogLabel = new QLabel(tr("Release Notes:"), this);
|
||||
m_layout->addWidget(m_changelogLabel);
|
||||
|
||||
m_changelogText = new QTextEdit(this);
|
||||
m_changelogText->setReadOnly(true);
|
||||
m_changelogText->setMinimumHeight(100);
|
||||
m_layout->addWidget(m_changelogText);
|
||||
}
|
||||
|
||||
m_progress = new QProgressBar(this);
|
||||
m_progress->setVisible(false);
|
||||
m_layout->addWidget(m_progress);
|
||||
m_changelogText = new QTextEdit(this);
|
||||
m_changelogText->setReadOnly(true);
|
||||
m_changelogText->setMinimumHeight(100);
|
||||
m_layout->addWidget(m_changelogText);
|
||||
|
||||
auto *buttonLayout = new QHBoxLayout;
|
||||
m_downloadButton = new QPushButton(tr("Download"), this);
|
||||
m_downloadButton->setEnabled(false);
|
||||
buttonLayout->addWidget(m_downloadButton);
|
||||
m_buttonOpenReleasePage = new QPushButton(tr("Open Release Page"), this);
|
||||
buttonLayout->addWidget(m_buttonOpenReleasePage);
|
||||
|
||||
m_buttonOpenPluginFolder = new QPushButton(tr("Open Plugin Folder"), this);
|
||||
buttonLayout->addWidget(m_buttonOpenPluginFolder);
|
||||
|
||||
m_closeButton = new QPushButton(tr("Close"), this);
|
||||
buttonLayout->addWidget(m_closeButton);
|
||||
@ -96,11 +88,8 @@ UpdateDialog::UpdateDialog(QWidget *parent)
|
||||
m_layout->addLayout(buttonLayout);
|
||||
|
||||
connect(m_updater, &PluginUpdater::updateCheckFinished, this, &UpdateDialog::handleUpdateInfo);
|
||||
connect(m_updater, &PluginUpdater::downloadProgress, this, &UpdateDialog::updateProgress);
|
||||
connect(m_updater, &PluginUpdater::downloadFinished, this, &UpdateDialog::handleDownloadFinished);
|
||||
connect(m_updater, &PluginUpdater::downloadError, this, &UpdateDialog::handleDownloadError);
|
||||
|
||||
connect(m_downloadButton, &QPushButton::clicked, this, &UpdateDialog::startDownload);
|
||||
connect(m_buttonOpenReleasePage, &QPushButton::clicked, this, &UpdateDialog::openReleasePage);
|
||||
connect(m_buttonOpenPluginFolder, &QPushButton::clicked, this, &UpdateDialog::openPluginFolder);
|
||||
connect(m_closeButton, &QPushButton::clicked, this, &QDialog::reject);
|
||||
|
||||
m_updater->checkForUpdates();
|
||||
@ -115,22 +104,12 @@ void UpdateDialog::checkForUpdatesAndShow(QWidget *parent)
|
||||
|
||||
void UpdateDialog::handleUpdateInfo(const PluginUpdater::UpdateInfo &info)
|
||||
{
|
||||
m_releaseLink->setText(
|
||||
tr("<a href='https://github.com/Palm1r/QodeAssist/releases'>You can also download "
|
||||
"from GitHub Releases</a>"));
|
||||
|
||||
if (info.incompatibleIdeVersion) {
|
||||
m_titleLabel->setText(tr("Incompatible Qt Creator Version"));
|
||||
m_versionLabel->setText(tr("This update requires Qt Creator %1, current is %2.\n"
|
||||
"Please upgrade Qt Creator to use this version of QodeAssist.")
|
||||
.arg(info.targetIdeVersion, info.currentIdeVersion));
|
||||
m_downloadButton->setEnabled(false);
|
||||
return;
|
||||
}
|
||||
m_updateInfo = info;
|
||||
|
||||
if (!info.isUpdateAvailable) {
|
||||
m_titleLabel->setText(tr("QodeAssist is up to date"));
|
||||
m_downloadButton->setEnabled(false);
|
||||
m_versionLabel->setText(
|
||||
tr("You are using the latest version: %1").arg(m_updater->currentVersion()));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -139,72 +118,31 @@ void UpdateDialog::handleUpdateInfo(const PluginUpdater::UpdateInfo &info)
|
||||
.arg(info.version, m_updater->currentVersion()));
|
||||
|
||||
if (!info.changeLog.isEmpty()) {
|
||||
if (!m_changelogLabel) {
|
||||
m_changelogLabel = new QLabel(tr("Release Notes:"), this);
|
||||
m_layout->insertWidget(2, m_changelogLabel);
|
||||
|
||||
m_changelogText = new QTextEdit(this);
|
||||
m_changelogText->setReadOnly(true);
|
||||
m_changelogText->setMaximumHeight(200);
|
||||
m_layout->insertWidget(3, m_changelogText);
|
||||
}
|
||||
m_changelogText->setText(info.changeLog);
|
||||
} else {
|
||||
m_changelogText->setText(
|
||||
tr("No release notes available. Check the release page for more information."));
|
||||
}
|
||||
|
||||
m_downloadButton->setEnabled(true);
|
||||
m_updateInfo = info;
|
||||
}
|
||||
|
||||
void UpdateDialog::startDownload()
|
||||
void UpdateDialog::openReleasePage()
|
||||
{
|
||||
m_downloadButton->setEnabled(false);
|
||||
m_progress->setVisible(true);
|
||||
m_updater->downloadUpdate(m_updateInfo.downloadUrl);
|
||||
QDesktopServices::openUrl(QUrl("https://github.com/Palm1r/QodeAssist/releases/latest"));
|
||||
accept();
|
||||
}
|
||||
|
||||
void UpdateDialog::updateProgress(qint64 received, qint64 total)
|
||||
void UpdateDialog::openPluginFolder()
|
||||
{
|
||||
m_progress->setMaximum(total);
|
||||
m_progress->setValue(received);
|
||||
}
|
||||
|
||||
void UpdateDialog::handleDownloadFinished(const QString &path)
|
||||
{
|
||||
m_progress->setVisible(false);
|
||||
|
||||
QMessageBox msgBox(this);
|
||||
msgBox.setWindowTitle(tr("Update Downloaded"));
|
||||
msgBox.setText(tr("The update has been downloaded successfully.\n"
|
||||
"Would you like to close Qt Creator now and open the plugin folder?"));
|
||||
msgBox.setInformativeText(tr("To complete the update:\n\n"
|
||||
"1. Close Qt Creator completely\n"
|
||||
"2. Navigate to the plugin folder\n"
|
||||
"3. Remove the old version of QodeAssist plugin\n"
|
||||
"4. Install plugin as usual via About plugin menu"));
|
||||
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
|
||||
msgBox.setDefaultButton(QMessageBox::Yes);
|
||||
msgBox.setIcon(QMessageBox::Information);
|
||||
|
||||
if (msgBox.exec() == QMessageBox::Yes) {
|
||||
const auto pluginSpecs = ExtensionSystem::PluginManager::plugins();
|
||||
for (const ExtensionSystem::PluginSpec *spec : pluginSpecs) {
|
||||
if (spec->name() == QLatin1String("QodeAssist")) {
|
||||
const auto pluginPath = spec->filePath().path();
|
||||
QFileInfo fileInfo(pluginPath);
|
||||
QDesktopServices::openUrl(QUrl::fromLocalFile(fileInfo.absolutePath()));
|
||||
Core::ICore::exit();
|
||||
break;
|
||||
}
|
||||
const auto pluginSpecs = ExtensionSystem::PluginManager::plugins();
|
||||
for (const ExtensionSystem::PluginSpec *spec : pluginSpecs) {
|
||||
if (spec->name() == QLatin1String("QodeAssist")) {
|
||||
const auto pluginPath = spec->filePath().path();
|
||||
QFileInfo fileInfo(pluginPath);
|
||||
QDesktopServices::openUrl(QUrl::fromLocalFile(fileInfo.absolutePath()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
accept();
|
||||
}
|
||||
|
||||
void UpdateDialog::handleDownloadError(const QString &error)
|
||||
{
|
||||
m_progress->setVisible(false);
|
||||
m_downloadButton->setEnabled(true);
|
||||
QMessageBox::critical(this, tr("Update Error"), tr("Failed to update: %1").arg(error));
|
||||
}
|
||||
|
||||
} // namespace QodeAssist
|
||||
|
Reference in New Issue
Block a user