2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2011-09-08 16:04:27 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2011-09-08 16:04:27 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2011-09-08 16:04:27 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2011-09-08 16:04:27 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2011-09-08 16:04:27 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2011-09-08 16:04:27 +02:00
|
|
|
|
2013-11-11 14:58:17 +01:00
|
|
|
#include "settingspage.h"
|
2011-09-08 16:04:27 +02:00
|
|
|
#include "updateinfoplugin.h"
|
|
|
|
|
|
|
|
|
|
#include <coreplugin/actionmanager/actioncontainer.h>
|
2013-11-11 14:58:17 +01:00
|
|
|
#include <coreplugin/actionmanager/actionmanager.h>
|
2011-09-08 16:04:27 +02:00
|
|
|
#include <coreplugin/coreconstants.h>
|
|
|
|
|
#include <coreplugin/icore.h>
|
2013-11-11 14:58:17 +01:00
|
|
|
#include <coreplugin/settingsdatabase.h>
|
2015-05-19 15:15:15 +02:00
|
|
|
#include <coreplugin/shellcommand.h>
|
2020-09-24 14:39:46 +02:00
|
|
|
#include <utils/algorithm.h>
|
2015-05-19 15:15:15 +02:00
|
|
|
#include <utils/fileutils.h>
|
2020-06-17 12:23:44 +02:00
|
|
|
#include <utils/infobar.h>
|
2016-04-25 11:48:06 +02:00
|
|
|
#include <utils/synchronousprocess.h>
|
2011-09-08 16:04:27 +02:00
|
|
|
|
2015-05-19 15:15:15 +02:00
|
|
|
#include <QDate>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QDomDocument>
|
2013-11-11 14:58:17 +01:00
|
|
|
#include <QFile>
|
2015-05-19 15:15:15 +02:00
|
|
|
#include <QFileInfo>
|
2020-01-16 17:03:53 +01:00
|
|
|
#include <QLabel>
|
2013-11-11 14:58:17 +01:00
|
|
|
#include <QMenu>
|
2015-05-19 15:15:15 +02:00
|
|
|
#include <QMetaEnum>
|
2017-11-08 09:40:38 +01:00
|
|
|
#include <QPointer>
|
2015-05-19 15:15:15 +02:00
|
|
|
#include <QProcessEnvironment>
|
|
|
|
|
#include <QTimer>
|
2011-09-08 16:04:27 +02:00
|
|
|
|
|
|
|
|
namespace {
|
2015-05-19 15:15:15 +02:00
|
|
|
static const char UpdaterGroup[] = "Updater";
|
|
|
|
|
static const char MaintenanceToolKey[] = "MaintenanceTool";
|
|
|
|
|
static const char AutomaticCheckKey[] = "AutomaticCheck";
|
|
|
|
|
static const char CheckIntervalKey[] = "CheckUpdateInterval";
|
|
|
|
|
static const char LastCheckDateKey[] = "LastCheckDate";
|
2011-09-08 16:04:27 +02:00
|
|
|
static const quint32 OneMinute = 60000;
|
2015-05-19 15:15:15 +02:00
|
|
|
static const quint32 OneHour = 3600000;
|
2019-08-08 13:19:40 +02:00
|
|
|
static const char InstallUpdates[] = "UpdateInfo.InstallUpdates";
|
2011-09-08 16:04:27 +02:00
|
|
|
}
|
|
|
|
|
|
2013-08-30 09:22:42 +02:00
|
|
|
using namespace Core;
|
|
|
|
|
|
2011-09-08 16:04:27 +02:00
|
|
|
namespace UpdateInfo {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
class UpdateInfoPluginPrivate
|
|
|
|
|
{
|
|
|
|
|
public:
|
2015-05-19 15:15:15 +02:00
|
|
|
QString m_maintenanceTool;
|
2017-11-08 09:40:38 +01:00
|
|
|
QPointer<ShellCommand> m_checkUpdatesCommand;
|
2019-03-29 13:48:25 +01:00
|
|
|
QPointer<FutureProgress> m_progress;
|
2015-05-19 15:15:15 +02:00
|
|
|
QString m_collectedOutput;
|
2018-12-10 00:32:49 +01:00
|
|
|
QTimer *m_checkUpdatesTimer = nullptr;
|
2013-11-11 14:58:17 +01:00
|
|
|
|
2015-05-19 15:15:15 +02:00
|
|
|
bool m_automaticCheck = true;
|
|
|
|
|
UpdateInfoPlugin::CheckUpdateInterval m_checkInterval = UpdateInfoPlugin::WeeklyCheck;
|
|
|
|
|
QDate m_lastCheckDate;
|
2011-09-08 16:04:27 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
UpdateInfoPlugin::UpdateInfoPlugin()
|
|
|
|
|
: d(new UpdateInfoPluginPrivate)
|
|
|
|
|
{
|
2015-05-19 15:15:15 +02:00
|
|
|
d->m_checkUpdatesTimer = new QTimer(this);
|
|
|
|
|
d->m_checkUpdatesTimer->setTimerType(Qt::VeryCoarseTimer);
|
|
|
|
|
d->m_checkUpdatesTimer->setInterval(OneHour);
|
|
|
|
|
connect(d->m_checkUpdatesTimer, &QTimer::timeout,
|
|
|
|
|
this, &UpdateInfoPlugin::doAutoCheckForUpdates);
|
2011-09-08 16:04:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UpdateInfoPlugin::~UpdateInfoPlugin()
|
|
|
|
|
{
|
2015-05-19 15:15:15 +02:00
|
|
|
stopCheckForUpdates();
|
|
|
|
|
if (!d->m_maintenanceTool.isEmpty())
|
|
|
|
|
saveSettings();
|
2013-12-11 15:17:22 +01:00
|
|
|
|
2011-09-08 16:04:27 +02:00
|
|
|
delete d;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-19 15:15:15 +02:00
|
|
|
void UpdateInfoPlugin::startAutoCheckForUpdates()
|
|
|
|
|
{
|
|
|
|
|
doAutoCheckForUpdates();
|
|
|
|
|
|
|
|
|
|
d->m_checkUpdatesTimer->start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UpdateInfoPlugin::stopAutoCheckForUpdates()
|
|
|
|
|
{
|
|
|
|
|
d->m_checkUpdatesTimer->stop();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UpdateInfoPlugin::doAutoCheckForUpdates()
|
|
|
|
|
{
|
|
|
|
|
if (d->m_checkUpdatesCommand)
|
|
|
|
|
return; // update task is still running (might have been run manually just before)
|
|
|
|
|
|
|
|
|
|
if (nextCheckDate().isValid() && nextCheckDate() > QDate::currentDate())
|
|
|
|
|
return; // not a time for check yet
|
|
|
|
|
|
|
|
|
|
startCheckForUpdates();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UpdateInfoPlugin::startCheckForUpdates()
|
|
|
|
|
{
|
|
|
|
|
stopCheckForUpdates();
|
|
|
|
|
|
2016-11-10 09:30:02 +01:00
|
|
|
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
|
2016-04-25 12:27:48 +02:00
|
|
|
env.insert(QLatin1String("QT_LOGGING_RULES"), QLatin1String("*=false"));
|
2016-04-24 15:28:02 +03:00
|
|
|
d->m_checkUpdatesCommand = new ShellCommand(QString(), env);
|
2019-03-29 13:48:25 +01:00
|
|
|
d->m_checkUpdatesCommand->setDisplayName(tr("Checking for Updates"));
|
2015-05-19 15:15:15 +02:00
|
|
|
connect(d->m_checkUpdatesCommand, &ShellCommand::stdOutText, this, &UpdateInfoPlugin::collectCheckForUpdatesOutput);
|
|
|
|
|
connect(d->m_checkUpdatesCommand, &ShellCommand::finished, this, &UpdateInfoPlugin::checkForUpdatesFinished);
|
2019-06-07 15:27:50 +02:00
|
|
|
d->m_checkUpdatesCommand->addJob({Utils::FilePath::fromFileInfo(d->m_maintenanceTool), {"--checkupdates"}},
|
2017-04-27 11:15:45 +02:00
|
|
|
60 * 3, // 3 minutes timeout
|
2016-04-25 14:40:42 +02:00
|
|
|
/*workingDirectory=*/QString(),
|
|
|
|
|
[](int /*exitCode*/) { return Utils::SynchronousProcessResponse::Finished; });
|
2015-05-19 15:15:15 +02:00
|
|
|
d->m_checkUpdatesCommand->execute();
|
2019-03-29 13:48:25 +01:00
|
|
|
d->m_progress = d->m_checkUpdatesCommand->futureProgress();
|
|
|
|
|
if (d->m_progress) {
|
|
|
|
|
d->m_progress->setKeepOnFinish(FutureProgress::KeepOnFinishTillUserInteraction);
|
|
|
|
|
d->m_progress->setSubtitleVisibleInStatusBar(true);
|
|
|
|
|
}
|
2015-05-19 15:15:15 +02:00
|
|
|
emit checkForUpdatesRunningChanged(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UpdateInfoPlugin::stopCheckForUpdates()
|
|
|
|
|
{
|
|
|
|
|
if (!d->m_checkUpdatesCommand)
|
|
|
|
|
return;
|
|
|
|
|
|
2015-06-16 13:40:40 +02:00
|
|
|
d->m_collectedOutput.clear();
|
2015-05-19 15:15:15 +02:00
|
|
|
d->m_checkUpdatesCommand->disconnect();
|
|
|
|
|
d->m_checkUpdatesCommand->cancel();
|
2018-12-10 00:32:49 +01:00
|
|
|
d->m_checkUpdatesCommand = nullptr;
|
2015-05-19 15:15:15 +02:00
|
|
|
emit checkForUpdatesRunningChanged(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UpdateInfoPlugin::collectCheckForUpdatesOutput(const QString &contents)
|
|
|
|
|
{
|
|
|
|
|
d->m_collectedOutput += contents;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-24 14:39:46 +02:00
|
|
|
struct Update
|
|
|
|
|
{
|
|
|
|
|
QString name;
|
|
|
|
|
QString version;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static QList<Update> availableUpdates(const QDomDocument &document)
|
2019-08-08 14:40:42 +02:00
|
|
|
{
|
|
|
|
|
if (document.isNull() || !document.firstChildElement().hasChildNodes())
|
|
|
|
|
return {};
|
2020-09-24 14:39:46 +02:00
|
|
|
QList<Update> result;
|
2019-08-08 14:40:42 +02:00
|
|
|
const QDomNodeList updates = document.firstChildElement().elementsByTagName("update");
|
|
|
|
|
for (int i = 0; i < updates.size(); ++i) {
|
|
|
|
|
const QDomNode node = updates.item(i);
|
|
|
|
|
if (node.isElement()) {
|
|
|
|
|
const QDomElement element = node.toElement();
|
|
|
|
|
if (element.hasAttribute("name"))
|
2020-09-24 14:39:46 +02:00
|
|
|
result.append({element.attribute("name"), element.attribute("version")});
|
2019-08-08 14:40:42 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-19 15:15:15 +02:00
|
|
|
void UpdateInfoPlugin::checkForUpdatesFinished()
|
|
|
|
|
{
|
|
|
|
|
setLastCheckDate(QDate::currentDate());
|
|
|
|
|
|
|
|
|
|
QDomDocument document;
|
|
|
|
|
document.setContent(d->m_collectedOutput);
|
|
|
|
|
|
|
|
|
|
stopCheckForUpdates();
|
|
|
|
|
|
|
|
|
|
if (!document.isNull() && document.firstChildElement().hasChildNodes()) {
|
2019-08-08 13:19:40 +02:00
|
|
|
// progress details are shown until user interaction for the "no updates" case,
|
|
|
|
|
// so we can show the "No updates found" text, but if we have updates we don't
|
|
|
|
|
// want to keep it around
|
|
|
|
|
if (d->m_progress)
|
|
|
|
|
d->m_progress->setKeepOnFinish(FutureProgress::HideOnFinish);
|
2015-05-19 15:15:15 +02:00
|
|
|
emit newUpdatesAvailable(true);
|
2020-06-17 12:23:44 +02:00
|
|
|
Utils::InfoBarEntry info(InstallUpdates, tr("New updates are available. Start the update?"));
|
2019-08-08 13:19:40 +02:00
|
|
|
info.setCustomButtonInfo(tr("Start Update"), [this] {
|
|
|
|
|
Core::ICore::infoBar()->removeInfo(InstallUpdates);
|
2015-05-19 15:15:15 +02:00
|
|
|
startUpdater();
|
2019-08-08 13:19:40 +02:00
|
|
|
});
|
2020-09-24 14:39:46 +02:00
|
|
|
const QList<Update> updates = availableUpdates(document);
|
2019-08-08 14:40:42 +02:00
|
|
|
info.setDetailsWidgetCreator([updates]() -> QWidget * {
|
2020-09-24 14:39:46 +02:00
|
|
|
const QString updateText = Utils::transform(updates, [](const Update &u) {
|
|
|
|
|
return u.version.isEmpty()
|
|
|
|
|
? u.name
|
|
|
|
|
: tr("%1 (%2)", "Package name and version")
|
|
|
|
|
.arg(u.name, u.version);
|
|
|
|
|
}).join("</li><li>");
|
2019-08-08 14:40:42 +02:00
|
|
|
auto label = new QLabel;
|
2019-10-28 16:22:49 +01:00
|
|
|
label->setText("<qt><p>" + tr("Available updates:") + "<ul><li>" + updateText
|
2019-08-08 14:40:42 +02:00
|
|
|
+ "</li></ul></p></qt>");
|
|
|
|
|
label->setContentsMargins(0, 0, 0, 8);
|
|
|
|
|
return label;
|
|
|
|
|
});
|
2019-12-17 11:07:23 +01:00
|
|
|
Core::ICore::infoBar()->removeInfo(InstallUpdates); // remove any existing notifications
|
2019-08-08 13:19:40 +02:00
|
|
|
Core::ICore::infoBar()->unsuppressInfo(InstallUpdates);
|
|
|
|
|
Core::ICore::infoBar()->addInfo(info);
|
2015-05-19 15:15:15 +02:00
|
|
|
} else {
|
|
|
|
|
emit newUpdatesAvailable(false);
|
2019-03-29 13:48:25 +01:00
|
|
|
if (d->m_progress)
|
|
|
|
|
d->m_progress->setSubtitle(tr("No updates found."));
|
2015-05-19 15:15:15 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool UpdateInfoPlugin::isCheckForUpdatesRunning() const
|
|
|
|
|
{
|
|
|
|
|
return d->m_checkUpdatesCommand;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-28 10:16:13 +02:00
|
|
|
void UpdateInfoPlugin::extensionsInitialized()
|
2011-09-08 16:04:27 +02:00
|
|
|
{
|
2015-05-19 15:15:15 +02:00
|
|
|
if (isAutomaticCheck())
|
|
|
|
|
QTimer::singleShot(OneMinute, this, &UpdateInfoPlugin::startAutoCheckForUpdates);
|
2011-09-08 16:04:27 +02:00
|
|
|
}
|
|
|
|
|
|
2011-10-20 16:39:44 +02:00
|
|
|
bool UpdateInfoPlugin::initialize(const QStringList & /* arguments */, QString *errorMessage)
|
2011-09-08 16:04:27 +02:00
|
|
|
{
|
2013-11-11 14:58:17 +01:00
|
|
|
loadSettings();
|
2015-05-19 15:15:15 +02:00
|
|
|
|
|
|
|
|
if (d->m_maintenanceTool.isEmpty()) {
|
2011-10-20 16:39:44 +02:00
|
|
|
*errorMessage = tr("Could not determine location of maintenance tool. Please check "
|
2013-11-11 14:58:17 +01:00
|
|
|
"your installation if you did not enable this plugin manually.");
|
2011-10-20 16:39:44 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-19 15:15:15 +02:00
|
|
|
if (!QFileInfo(d->m_maintenanceTool).isExecutable()) {
|
|
|
|
|
*errorMessage = tr("The maintenance tool at \"%1\" is not an executable. Check your installation.")
|
|
|
|
|
.arg(d->m_maintenanceTool);
|
2015-06-16 13:40:40 +02:00
|
|
|
d->m_maintenanceTool.clear();
|
2011-10-20 16:39:44 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-19 15:15:15 +02:00
|
|
|
connect(ICore::instance(), &ICore::saveSettingsRequested,
|
|
|
|
|
this, &UpdateInfoPlugin::saveSettings);
|
|
|
|
|
|
2018-02-08 10:43:24 +01:00
|
|
|
(void) new SettingsPage(this);
|
2011-09-08 16:04:27 +02:00
|
|
|
|
2015-05-19 15:15:15 +02:00
|
|
|
QAction *checkForUpdatesAction = new QAction(tr("Check for Updates"), this);
|
2017-06-15 14:17:08 -07:00
|
|
|
checkForUpdatesAction->setMenuRole(QAction::ApplicationSpecificRole);
|
2015-05-19 15:15:15 +02:00
|
|
|
Core::Command *checkForUpdatesCommand = Core::ActionManager::registerAction(checkForUpdatesAction, "Updates.CheckForUpdates");
|
|
|
|
|
connect(checkForUpdatesAction, &QAction::triggered, this, &UpdateInfoPlugin::startCheckForUpdates);
|
|
|
|
|
ActionContainer *const helpContainer = ActionManager::actionContainer(Core::Constants::M_HELP);
|
|
|
|
|
helpContainer->addAction(checkForUpdatesCommand, Constants::G_HELP_UPDATES);
|
2011-10-20 16:39:44 +02:00
|
|
|
|
2011-09-08 16:04:27 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-19 15:15:15 +02:00
|
|
|
void UpdateInfoPlugin::loadSettings() const
|
2011-09-08 16:04:27 +02:00
|
|
|
{
|
2015-05-19 15:15:15 +02:00
|
|
|
QSettings *settings = ICore::settings();
|
|
|
|
|
const QString updaterKey = QLatin1String(UpdaterGroup) + QLatin1Char('/');
|
|
|
|
|
d->m_maintenanceTool = settings->value(updaterKey + QLatin1String(MaintenanceToolKey)).toString();
|
|
|
|
|
d->m_lastCheckDate = settings->value(updaterKey + QLatin1String(LastCheckDateKey), QDate()).toDate();
|
|
|
|
|
d->m_automaticCheck = settings->value(updaterKey + QLatin1String(AutomaticCheckKey), true).toBool();
|
|
|
|
|
const QString checkInterval = settings->value(updaterKey + QLatin1String(CheckIntervalKey)).toString();
|
|
|
|
|
const QMetaObject *mo = metaObject();
|
|
|
|
|
const QMetaEnum me = mo->enumerator(mo->indexOfEnumerator(CheckIntervalKey));
|
|
|
|
|
if (me.isValid()) {
|
|
|
|
|
bool ok = false;
|
|
|
|
|
const int newValue = me.keyToValue(checkInterval.toUtf8(), &ok);
|
|
|
|
|
if (ok)
|
|
|
|
|
d->m_checkInterval = static_cast<CheckUpdateInterval>(newValue);
|
2011-09-08 16:04:27 +02:00
|
|
|
}
|
2013-11-11 14:58:17 +01:00
|
|
|
}
|
2011-09-08 16:04:27 +02:00
|
|
|
|
2013-11-11 14:58:17 +01:00
|
|
|
void UpdateInfoPlugin::saveSettings()
|
|
|
|
|
{
|
2015-05-19 15:15:15 +02:00
|
|
|
QSettings *settings = ICore::settings();
|
|
|
|
|
settings->beginGroup(QLatin1String(UpdaterGroup));
|
|
|
|
|
settings->setValue(QLatin1String(LastCheckDateKey), d->m_lastCheckDate);
|
|
|
|
|
settings->setValue(QLatin1String(AutomaticCheckKey), d->m_automaticCheck);
|
|
|
|
|
// 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:
|
|
|
|
|
// [CREATOR_INSTALLATION_LOCATION]/share/qtcreator/QtProject/QtCreator.ini or
|
|
|
|
|
// [CREATOR_INSTALLATION_LOCATION]/Qt Creator.app/Contents/Resources/QtProject/QtCreator.ini on OS X
|
|
|
|
|
const QMetaObject *mo = metaObject();
|
|
|
|
|
const QMetaEnum me = mo->enumerator(mo->indexOfEnumerator(CheckIntervalKey));
|
|
|
|
|
settings->setValue(QLatin1String(CheckIntervalKey), QLatin1String(me.valueToKey(d->m_checkInterval)));
|
|
|
|
|
settings->endGroup();
|
2011-09-08 16:04:27 +02:00
|
|
|
}
|
|
|
|
|
|
2015-05-19 15:15:15 +02:00
|
|
|
bool UpdateInfoPlugin::isAutomaticCheck() const
|
2013-11-11 14:58:17 +01:00
|
|
|
{
|
2015-05-19 15:15:15 +02:00
|
|
|
return d->m_automaticCheck;
|
2013-11-11 14:58:17 +01:00
|
|
|
}
|
2011-09-08 16:04:27 +02:00
|
|
|
|
2015-05-19 15:15:15 +02:00
|
|
|
void UpdateInfoPlugin::setAutomaticCheck(bool on)
|
2011-09-08 16:04:27 +02:00
|
|
|
{
|
2015-05-19 15:15:15 +02:00
|
|
|
if (d->m_automaticCheck == on)
|
|
|
|
|
return;
|
2013-11-11 14:58:17 +01:00
|
|
|
|
2015-05-19 15:15:15 +02:00
|
|
|
d->m_automaticCheck = on;
|
|
|
|
|
if (on)
|
|
|
|
|
startAutoCheckForUpdates();
|
|
|
|
|
else
|
|
|
|
|
stopAutoCheckForUpdates();
|
|
|
|
|
}
|
2011-09-08 16:04:27 +02:00
|
|
|
|
2015-05-19 15:15:15 +02:00
|
|
|
UpdateInfoPlugin::CheckUpdateInterval UpdateInfoPlugin::checkUpdateInterval() const
|
2013-11-11 14:58:17 +01:00
|
|
|
{
|
2015-05-19 15:15:15 +02:00
|
|
|
return d->m_checkInterval;
|
2013-11-11 14:58:17 +01:00
|
|
|
}
|
|
|
|
|
|
2015-05-19 15:15:15 +02:00
|
|
|
void UpdateInfoPlugin::setCheckUpdateInterval(UpdateInfoPlugin::CheckUpdateInterval interval)
|
2013-11-11 14:58:17 +01:00
|
|
|
{
|
2015-05-19 15:15:15 +02:00
|
|
|
if (d->m_checkInterval == interval)
|
2013-11-11 14:58:17 +01:00
|
|
|
return;
|
2011-09-08 16:04:27 +02:00
|
|
|
|
2015-05-19 15:15:15 +02:00
|
|
|
d->m_checkInterval = interval;
|
2011-09-08 16:04:27 +02:00
|
|
|
}
|
|
|
|
|
|
2015-05-19 15:15:15 +02:00
|
|
|
QDate UpdateInfoPlugin::lastCheckDate() const
|
2011-09-08 16:04:27 +02:00
|
|
|
{
|
2015-05-19 15:15:15 +02:00
|
|
|
return d->m_lastCheckDate;
|
2011-09-08 16:04:27 +02:00
|
|
|
}
|
|
|
|
|
|
2015-05-19 15:15:15 +02:00
|
|
|
void UpdateInfoPlugin::setLastCheckDate(const QDate &date)
|
2011-09-08 16:04:27 +02:00
|
|
|
{
|
2015-05-19 15:15:15 +02:00
|
|
|
if (d->m_lastCheckDate == date)
|
|
|
|
|
return;
|
2013-12-11 14:33:04 +01:00
|
|
|
|
2015-05-19 15:15:15 +02:00
|
|
|
d->m_lastCheckDate = date;
|
|
|
|
|
emit lastCheckDateChanged(date);
|
2011-09-08 16:04:27 +02:00
|
|
|
}
|
|
|
|
|
|
2015-05-19 15:15:15 +02:00
|
|
|
QDate UpdateInfoPlugin::nextCheckDate() const
|
2011-09-08 16:04:27 +02:00
|
|
|
{
|
2015-05-19 15:15:15 +02:00
|
|
|
return nextCheckDate(d->m_checkInterval);
|
|
|
|
|
}
|
2013-11-11 14:58:17 +01:00
|
|
|
|
2015-05-19 15:15:15 +02:00
|
|
|
QDate UpdateInfoPlugin::nextCheckDate(CheckUpdateInterval interval) const
|
|
|
|
|
{
|
|
|
|
|
if (!d->m_lastCheckDate.isValid())
|
|
|
|
|
return QDate();
|
|
|
|
|
|
|
|
|
|
if (interval == DailyCheck)
|
|
|
|
|
return d->m_lastCheckDate.addDays(1);
|
|
|
|
|
if (interval == WeeklyCheck)
|
|
|
|
|
return d->m_lastCheckDate.addDays(7);
|
|
|
|
|
return d->m_lastCheckDate.addMonths(1);
|
|
|
|
|
}
|
2013-11-11 14:58:17 +01:00
|
|
|
|
2015-05-19 15:15:15 +02:00
|
|
|
void UpdateInfoPlugin::startUpdater()
|
|
|
|
|
{
|
|
|
|
|
QProcess::startDetached(d->m_maintenanceTool, QStringList(QLatin1String("--updater")));
|
2011-09-08 16:04:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} //namespace Internal
|
|
|
|
|
} //namespace UpdateInfo
|