forked from qt-creator/qt-creator
UpdateInfo: Do not save defaults to settings
Task-number: QTCREATORBUG-24762 Change-Id: Ie5fb6492847532b659fd7e0799b30f716c2c15fe Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
@@ -35,6 +35,7 @@
|
|||||||
#include <utils/algorithm.h>
|
#include <utils/algorithm.h>
|
||||||
#include <utils/fileutils.h>
|
#include <utils/fileutils.h>
|
||||||
#include <utils/infobar.h>
|
#include <utils/infobar.h>
|
||||||
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/synchronousprocess.h>
|
#include <utils/synchronousprocess.h>
|
||||||
|
|
||||||
#include <QDate>
|
#include <QDate>
|
||||||
@@ -73,8 +74,12 @@ public:
|
|||||||
QString m_collectedOutput;
|
QString m_collectedOutput;
|
||||||
QTimer *m_checkUpdatesTimer = nullptr;
|
QTimer *m_checkUpdatesTimer = nullptr;
|
||||||
|
|
||||||
bool m_automaticCheck = true;
|
struct Settings
|
||||||
UpdateInfoPlugin::CheckUpdateInterval m_checkInterval = UpdateInfoPlugin::WeeklyCheck;
|
{
|
||||||
|
bool automaticCheck = true;
|
||||||
|
UpdateInfoPlugin::CheckUpdateInterval checkInterval = UpdateInfoPlugin::WeeklyCheck;
|
||||||
|
};
|
||||||
|
Settings m_settings;
|
||||||
QDate m_lastCheckDate;
|
QDate m_lastCheckDate;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -273,49 +278,59 @@ bool UpdateInfoPlugin::initialize(const QStringList & /* arguments */, QString *
|
|||||||
|
|
||||||
void UpdateInfoPlugin::loadSettings() const
|
void UpdateInfoPlugin::loadSettings() const
|
||||||
{
|
{
|
||||||
|
UpdateInfoPluginPrivate::Settings def;
|
||||||
QSettings *settings = ICore::settings();
|
QSettings *settings = ICore::settings();
|
||||||
const QString updaterKey = QLatin1String(UpdaterGroup) + QLatin1Char('/');
|
const QString updaterKey = QLatin1String(UpdaterGroup) + '/';
|
||||||
d->m_maintenanceTool = settings->value(updaterKey + QLatin1String(MaintenanceToolKey)).toString();
|
d->m_maintenanceTool = settings->value(updaterKey + MaintenanceToolKey).toString();
|
||||||
d->m_lastCheckDate = settings->value(updaterKey + QLatin1String(LastCheckDateKey), QDate()).toDate();
|
d->m_lastCheckDate = settings->value(updaterKey + LastCheckDateKey, QDate()).toDate();
|
||||||
d->m_automaticCheck = settings->value(updaterKey + QLatin1String(AutomaticCheckKey), true).toBool();
|
d->m_settings.automaticCheck
|
||||||
const QString checkInterval = settings->value(updaterKey + QLatin1String(CheckIntervalKey)).toString();
|
= settings->value(updaterKey + AutomaticCheckKey, def.automaticCheck).toBool();
|
||||||
const QMetaObject *mo = metaObject();
|
const QMetaObject *mo = metaObject();
|
||||||
const QMetaEnum me = mo->enumerator(mo->indexOfEnumerator(CheckIntervalKey));
|
const QMetaEnum me = mo->enumerator(mo->indexOfEnumerator(CheckIntervalKey));
|
||||||
if (me.isValid()) {
|
if (QTC_GUARD(me.isValid())) {
|
||||||
|
const QString checkInterval = settings
|
||||||
|
->value(updaterKey + CheckIntervalKey,
|
||||||
|
me.valueToKey(def.checkInterval))
|
||||||
|
.toString();
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
const int newValue = me.keyToValue(checkInterval.toUtf8(), &ok);
|
const int newValue = me.keyToValue(checkInterval.toUtf8(), &ok);
|
||||||
if (ok)
|
if (ok)
|
||||||
d->m_checkInterval = static_cast<CheckUpdateInterval>(newValue);
|
d->m_settings.checkInterval = static_cast<CheckUpdateInterval>(newValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateInfoPlugin::saveSettings()
|
void UpdateInfoPlugin::saveSettings()
|
||||||
{
|
{
|
||||||
QSettings *settings = ICore::settings();
|
UpdateInfoPluginPrivate::Settings def;
|
||||||
settings->beginGroup(QLatin1String(UpdaterGroup));
|
Utils::QtcSettings *settings = ICore::settings();
|
||||||
settings->setValue(QLatin1String(LastCheckDateKey), d->m_lastCheckDate);
|
settings->beginGroup(UpdaterGroup);
|
||||||
settings->setValue(QLatin1String(AutomaticCheckKey), d->m_automaticCheck);
|
settings->setValueWithDefault(LastCheckDateKey, d->m_lastCheckDate, QDate());
|
||||||
|
settings->setValueWithDefault(AutomaticCheckKey,
|
||||||
|
d->m_settings.automaticCheck,
|
||||||
|
def.automaticCheck);
|
||||||
// Note: don't save MaintenanceToolKey on purpose! This setting may be set only by installer.
|
// Note: don't save MaintenanceToolKey on purpose! This setting may be set only by installer.
|
||||||
// If creator is run not from installed SDK, the setting can be manually created here:
|
// If creator is run not from installed SDK, the setting can be manually created here:
|
||||||
// [CREATOR_INSTALLATION_LOCATION]/share/qtcreator/QtProject/QtCreator.ini or
|
// [CREATOR_INSTALLATION_LOCATION]/share/qtcreator/QtProject/QtCreator.ini or
|
||||||
// [CREATOR_INSTALLATION_LOCATION]/Qt Creator.app/Contents/Resources/QtProject/QtCreator.ini on OS X
|
// [CREATOR_INSTALLATION_LOCATION]/Qt Creator.app/Contents/Resources/QtProject/QtCreator.ini on OS X
|
||||||
const QMetaObject *mo = metaObject();
|
const QMetaObject *mo = metaObject();
|
||||||
const QMetaEnum me = mo->enumerator(mo->indexOfEnumerator(CheckIntervalKey));
|
const QMetaEnum me = mo->enumerator(mo->indexOfEnumerator(CheckIntervalKey));
|
||||||
settings->setValue(QLatin1String(CheckIntervalKey), QLatin1String(me.valueToKey(d->m_checkInterval)));
|
settings->setValueWithDefault(CheckIntervalKey,
|
||||||
|
QString::fromUtf8(me.valueToKey(d->m_settings.checkInterval)),
|
||||||
|
QString::fromUtf8(me.valueToKey(def.checkInterval)));
|
||||||
settings->endGroup();
|
settings->endGroup();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool UpdateInfoPlugin::isAutomaticCheck() const
|
bool UpdateInfoPlugin::isAutomaticCheck() const
|
||||||
{
|
{
|
||||||
return d->m_automaticCheck;
|
return d->m_settings.automaticCheck;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateInfoPlugin::setAutomaticCheck(bool on)
|
void UpdateInfoPlugin::setAutomaticCheck(bool on)
|
||||||
{
|
{
|
||||||
if (d->m_automaticCheck == on)
|
if (d->m_settings.automaticCheck == on)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
d->m_automaticCheck = on;
|
d->m_settings.automaticCheck = on;
|
||||||
if (on)
|
if (on)
|
||||||
startAutoCheckForUpdates();
|
startAutoCheckForUpdates();
|
||||||
else
|
else
|
||||||
@@ -324,15 +339,15 @@ void UpdateInfoPlugin::setAutomaticCheck(bool on)
|
|||||||
|
|
||||||
UpdateInfoPlugin::CheckUpdateInterval UpdateInfoPlugin::checkUpdateInterval() const
|
UpdateInfoPlugin::CheckUpdateInterval UpdateInfoPlugin::checkUpdateInterval() const
|
||||||
{
|
{
|
||||||
return d->m_checkInterval;
|
return d->m_settings.checkInterval;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateInfoPlugin::setCheckUpdateInterval(UpdateInfoPlugin::CheckUpdateInterval interval)
|
void UpdateInfoPlugin::setCheckUpdateInterval(UpdateInfoPlugin::CheckUpdateInterval interval)
|
||||||
{
|
{
|
||||||
if (d->m_checkInterval == interval)
|
if (d->m_settings.checkInterval == interval)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
d->m_checkInterval = interval;
|
d->m_settings.checkInterval = interval;
|
||||||
}
|
}
|
||||||
|
|
||||||
QDate UpdateInfoPlugin::lastCheckDate() const
|
QDate UpdateInfoPlugin::lastCheckDate() const
|
||||||
@@ -351,7 +366,7 @@ void UpdateInfoPlugin::setLastCheckDate(const QDate &date)
|
|||||||
|
|
||||||
QDate UpdateInfoPlugin::nextCheckDate() const
|
QDate UpdateInfoPlugin::nextCheckDate() const
|
||||||
{
|
{
|
||||||
return nextCheckDate(d->m_checkInterval);
|
return nextCheckDate(d->m_settings.checkInterval);
|
||||||
}
|
}
|
||||||
|
|
||||||
QDate UpdateInfoPlugin::nextCheckDate(CheckUpdateInterval interval) const
|
QDate UpdateInfoPlugin::nextCheckDate(CheckUpdateInterval interval) const
|
||||||
|
Reference in New Issue
Block a user