forked from qt-creator/qt-creator
UpdateInfo: Adapt SettingsPage to new patterns
Change-Id: I19c40c7447720a19d9db359192353677ce5e2237 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -25,35 +25,29 @@
|
|||||||
|
|
||||||
#include "settingspage.h"
|
#include "settingspage.h"
|
||||||
|
|
||||||
|
#include "ui_settingspage.h"
|
||||||
|
#include "updateinfoplugin.h"
|
||||||
|
|
||||||
#include <coreplugin/coreconstants.h>
|
#include <coreplugin/coreconstants.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/progressindicator.h>
|
#include <utils/progressindicator.h>
|
||||||
|
|
||||||
#include <QDate>
|
#include <QDate>
|
||||||
|
|
||||||
using namespace UpdateInfo;
|
namespace UpdateInfo {
|
||||||
using namespace UpdateInfo::Internal;
|
namespace Internal {
|
||||||
|
|
||||||
namespace {
|
const char FILTER_OPTIONS_PAGE_ID[] = "Update";
|
||||||
|
|
||||||
static const char FILTER_OPTIONS_PAGE_ID[] = "Update";
|
class UpdateInfoSettingsPageWidget final : public Core::IOptionsPageWidget
|
||||||
static const char FILTER_OPTIONS_PAGE[] = QT_TRANSLATE_NOOP("Update", "Update");
|
{
|
||||||
|
Q_DECLARE_TR_FUNCTIONS(UpdateInfo::Internal::UpdateInfoSettingsPage)
|
||||||
|
|
||||||
}
|
public:
|
||||||
|
UpdateInfoSettingsPageWidget(UpdateInfoPlugin *plugin)
|
||||||
SettingsPage::SettingsPage(UpdateInfoPlugin *plugin)
|
|
||||||
: m_plugin(plugin)
|
: m_plugin(plugin)
|
||||||
{
|
{
|
||||||
setId(FILTER_OPTIONS_PAGE_ID);
|
m_ui.setupUi(this);
|
||||||
setCategory(Core::Constants::SETTINGS_CATEGORY_CORE);
|
|
||||||
setDisplayName(QCoreApplication::translate("Update", FILTER_OPTIONS_PAGE));
|
|
||||||
}
|
|
||||||
|
|
||||||
QWidget *SettingsPage::widget()
|
|
||||||
{
|
|
||||||
if (!m_widget) {
|
|
||||||
m_widget = new QWidget;
|
|
||||||
m_ui.setupUi(m_widget);
|
|
||||||
m_ui.m_checkIntervalComboBox->addItem(tr("Daily"), UpdateInfoPlugin::DailyCheck);
|
m_ui.m_checkIntervalComboBox->addItem(tr("Daily"), UpdateInfoPlugin::DailyCheck);
|
||||||
m_ui.m_checkIntervalComboBox->addItem(tr("Weekly"), UpdateInfoPlugin::WeeklyCheck);
|
m_ui.m_checkIntervalComboBox->addItem(tr("Weekly"), UpdateInfoPlugin::WeeklyCheck);
|
||||||
m_ui.m_checkIntervalComboBox->addItem(tr("Monthly"), UpdateInfoPlugin::MonthlyCheck);
|
m_ui.m_checkIntervalComboBox->addItem(tr("Monthly"), UpdateInfoPlugin::MonthlyCheck);
|
||||||
@@ -74,47 +68,51 @@ QWidget *SettingsPage::widget()
|
|||||||
m_plugin, &UpdateInfoPlugin::startCheckForUpdates);
|
m_plugin, &UpdateInfoPlugin::startCheckForUpdates);
|
||||||
connect(m_ui.m_checkIntervalComboBox,
|
connect(m_ui.m_checkIntervalComboBox,
|
||||||
QOverload<int>::of(&QComboBox::currentIndexChanged),
|
QOverload<int>::of(&QComboBox::currentIndexChanged),
|
||||||
this, &SettingsPage::updateNextCheckDate);
|
this, &UpdateInfoSettingsPageWidget::updateNextCheckDate);
|
||||||
connect(m_plugin, &UpdateInfoPlugin::lastCheckDateChanged,
|
connect(m_plugin, &UpdateInfoPlugin::lastCheckDateChanged,
|
||||||
this, &SettingsPage::updateLastCheckDate);
|
this, &UpdateInfoSettingsPageWidget::updateLastCheckDate);
|
||||||
connect(m_plugin, &UpdateInfoPlugin::checkForUpdatesRunningChanged,
|
connect(m_plugin, &UpdateInfoPlugin::checkForUpdatesRunningChanged,
|
||||||
this, &SettingsPage::checkRunningChanged);
|
this, &UpdateInfoSettingsPageWidget::checkRunningChanged);
|
||||||
connect(m_plugin, &UpdateInfoPlugin::newUpdatesAvailable,
|
connect(m_plugin, &UpdateInfoPlugin::newUpdatesAvailable,
|
||||||
this, &SettingsPage::newUpdatesAvailable);
|
this, &UpdateInfoSettingsPageWidget::newUpdatesAvailable);
|
||||||
}
|
}
|
||||||
return m_widget;
|
|
||||||
}
|
|
||||||
|
|
||||||
UpdateInfoPlugin::CheckUpdateInterval SettingsPage::currentCheckInterval() const
|
void apply() final;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void newUpdatesAvailable(bool available);
|
||||||
|
void checkRunningChanged(bool running);
|
||||||
|
void updateLastCheckDate();
|
||||||
|
void updateNextCheckDate();
|
||||||
|
UpdateInfoPlugin::CheckUpdateInterval currentCheckInterval() const;
|
||||||
|
|
||||||
|
QPointer<Utils::ProgressIndicator> m_progressIndicator;
|
||||||
|
Ui::SettingsWidget m_ui;
|
||||||
|
UpdateInfoPlugin *m_plugin;
|
||||||
|
};
|
||||||
|
|
||||||
|
UpdateInfoPlugin::CheckUpdateInterval UpdateInfoSettingsPageWidget::currentCheckInterval() const
|
||||||
{
|
{
|
||||||
QTC_ASSERT(m_widget, return UpdateInfoPlugin::WeeklyCheck);
|
|
||||||
|
|
||||||
return static_cast<UpdateInfoPlugin::CheckUpdateInterval>
|
return static_cast<UpdateInfoPlugin::CheckUpdateInterval>
|
||||||
(m_ui.m_checkIntervalComboBox->itemData(m_ui.m_checkIntervalComboBox->currentIndex()).toInt());
|
(m_ui.m_checkIntervalComboBox->itemData(m_ui.m_checkIntervalComboBox->currentIndex()).toInt());
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingsPage::newUpdatesAvailable(bool available)
|
void UpdateInfoSettingsPageWidget::newUpdatesAvailable(bool available)
|
||||||
{
|
{
|
||||||
if (!m_widget)
|
|
||||||
return;
|
|
||||||
|
|
||||||
const QString message = available
|
const QString message = available
|
||||||
? tr("New updates are available.")
|
? tr("New updates are available.")
|
||||||
: tr("No new updates are available.");
|
: tr("No new updates are available.");
|
||||||
m_ui.m_messageLabel->setText(message);
|
m_ui.m_messageLabel->setText(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingsPage::checkRunningChanged(bool running)
|
void UpdateInfoSettingsPageWidget::checkRunningChanged(bool running)
|
||||||
{
|
{
|
||||||
if (!m_widget)
|
|
||||||
return;
|
|
||||||
|
|
||||||
m_ui.m_checkNowButton->setDisabled(running);
|
m_ui.m_checkNowButton->setDisabled(running);
|
||||||
|
|
||||||
if (running) {
|
if (running) {
|
||||||
if (!m_progressIndicator) {
|
if (!m_progressIndicator) {
|
||||||
m_progressIndicator = new Utils::ProgressIndicator(Utils::ProgressIndicatorSize::Large);
|
m_progressIndicator = new Utils::ProgressIndicator(Utils::ProgressIndicatorSize::Large);
|
||||||
m_progressIndicator->attachToWidget(m_widget);
|
m_progressIndicator->attachToWidget(this);
|
||||||
}
|
}
|
||||||
m_progressIndicator->show();
|
m_progressIndicator->show();
|
||||||
} else {
|
} else {
|
||||||
@@ -128,11 +126,8 @@ void SettingsPage::checkRunningChanged(bool running)
|
|||||||
m_ui.m_messageLabel->setText(message);
|
m_ui.m_messageLabel->setText(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingsPage::updateLastCheckDate()
|
void UpdateInfoSettingsPageWidget::updateLastCheckDate()
|
||||||
{
|
{
|
||||||
if (!m_widget)
|
|
||||||
return;
|
|
||||||
|
|
||||||
const QDate date = m_plugin->lastCheckDate();
|
const QDate date = m_plugin->lastCheckDate();
|
||||||
QString lastCheckDateString;
|
QString lastCheckDateString;
|
||||||
if (date.isValid())
|
if (date.isValid())
|
||||||
@@ -145,11 +140,8 @@ void SettingsPage::updateLastCheckDate()
|
|||||||
updateNextCheckDate();
|
updateNextCheckDate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingsPage::updateNextCheckDate()
|
void UpdateInfoSettingsPageWidget::updateNextCheckDate()
|
||||||
{
|
{
|
||||||
if (!m_widget)
|
|
||||||
return;
|
|
||||||
|
|
||||||
QDate date = m_plugin->nextCheckDate(currentCheckInterval());
|
QDate date = m_plugin->nextCheckDate(currentCheckInterval());
|
||||||
if (!date.isValid() || date < QDate::currentDate())
|
if (!date.isValid() || date < QDate::currentDate())
|
||||||
date = QDate::currentDate();
|
date = QDate::currentDate();
|
||||||
@@ -157,16 +149,21 @@ void SettingsPage::updateNextCheckDate()
|
|||||||
m_ui.m_nextCheckDateLabel->setText(date.toString());
|
m_ui.m_nextCheckDateLabel->setText(date.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingsPage::apply()
|
void UpdateInfoSettingsPageWidget::apply()
|
||||||
{
|
{
|
||||||
if (!m_widget)
|
|
||||||
return;
|
|
||||||
|
|
||||||
m_plugin->setCheckUpdateInterval(currentCheckInterval());
|
m_plugin->setCheckUpdateInterval(currentCheckInterval());
|
||||||
m_plugin->setAutomaticCheck(m_ui.m_updatesGroupBox->isChecked());
|
m_plugin->setAutomaticCheck(m_ui.m_updatesGroupBox->isChecked());
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingsPage::finish()
|
// SettingsPage
|
||||||
|
|
||||||
|
SettingsPage::SettingsPage(UpdateInfoPlugin *plugin)
|
||||||
{
|
{
|
||||||
delete m_widget;
|
setId(FILTER_OPTIONS_PAGE_ID);
|
||||||
|
setCategory(Core::Constants::SETTINGS_CATEGORY_CORE);
|
||||||
|
setDisplayName(UpdateInfoSettingsPageWidget::tr("Update", "Update"));
|
||||||
|
setWidgetCreator([plugin] { return new UpdateInfoSettingsPageWidget(plugin); });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // Internal
|
||||||
|
} // UpdateInfoPlugin
|
||||||
|
|||||||
@@ -25,15 +25,8 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "ui_settingspage.h"
|
|
||||||
#include "updateinfoplugin.h"
|
|
||||||
|
|
||||||
#include <coreplugin/dialogs/ioptionspage.h>
|
#include <coreplugin/dialogs/ioptionspage.h>
|
||||||
|
|
||||||
#include <QPointer>
|
|
||||||
|
|
||||||
namespace Utils { class ProgressIndicator; }
|
|
||||||
|
|
||||||
namespace UpdateInfo {
|
namespace UpdateInfo {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
@@ -45,22 +38,6 @@ class SettingsPage : public Core::IOptionsPage
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
explicit SettingsPage(UpdateInfoPlugin *plugin);
|
explicit SettingsPage(UpdateInfoPlugin *plugin);
|
||||||
|
|
||||||
QWidget *widget() override;
|
|
||||||
void apply() override;
|
|
||||||
void finish() override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
void newUpdatesAvailable(bool available);
|
|
||||||
void checkRunningChanged(bool running);
|
|
||||||
void updateLastCheckDate();
|
|
||||||
void updateNextCheckDate();
|
|
||||||
UpdateInfoPlugin::CheckUpdateInterval currentCheckInterval() const;
|
|
||||||
|
|
||||||
QPointer<QWidget> m_widget;
|
|
||||||
QPointer<Utils::ProgressIndicator> m_progressIndicator;
|
|
||||||
Ui::SettingsWidget m_ui;
|
|
||||||
UpdateInfoPlugin *m_plugin;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|||||||
@@ -40,6 +40,7 @@
|
|||||||
#include <QDomDocument>
|
#include <QDomDocument>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
|
#include <QLabel>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QMetaEnum>
|
#include <QMetaEnum>
|
||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
|
|||||||
Reference in New Issue
Block a user