2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2011-09-08 16:04:27 +02:00
|
|
|
**
|
2013-01-28 17:12:19 +01:00
|
|
|
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
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
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
2011-09-08 16:04:27 +02:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2011-09-08 16:04:27 +02:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
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 "updateinfobutton.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>
|
|
|
|
|
#include <coreplugin/progressmanager/progressmanager.h>
|
|
|
|
|
#include <coreplugin/progressmanager/futureprogress.h>
|
2013-11-11 14:58:17 +01:00
|
|
|
#include <coreplugin/settingsdatabase.h>
|
2011-09-08 16:04:27 +02:00
|
|
|
|
|
|
|
|
#include <qtconcurrentrun.h>
|
|
|
|
|
|
2013-11-11 15:40:49 +01:00
|
|
|
#include <QBasicTimer>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QDomDocument>
|
2013-11-11 14:58:17 +01:00
|
|
|
#include <QFile>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QFutureWatcher>
|
2013-11-11 14:58:17 +01:00
|
|
|
#include <QMenu>
|
|
|
|
|
#include <QProcess>
|
2013-11-12 08:44:29 +01:00
|
|
|
#include <QtPlugin>
|
2011-09-08 16:04:27 +02:00
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
static const quint32 OneMinute = 60000;
|
|
|
|
|
}
|
|
|
|
|
|
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:
|
|
|
|
|
UpdateInfoPluginPrivate()
|
2013-11-11 14:58:17 +01:00
|
|
|
: progressUpdateInfoButton(0),
|
|
|
|
|
checkUpdateInfoWatcher(0),
|
|
|
|
|
m_settingsPage(0)
|
|
|
|
|
{
|
|
|
|
|
}
|
2011-09-08 16:04:27 +02:00
|
|
|
|
|
|
|
|
QString updaterProgram;
|
|
|
|
|
QString updaterRunUiArgument;
|
2013-11-11 14:58:17 +01:00
|
|
|
QString updaterCheckOnlyArgument;
|
|
|
|
|
|
2011-09-08 16:04:27 +02:00
|
|
|
QFuture<QDomDocument> lastCheckUpdateInfoTask;
|
2013-08-30 09:22:42 +02:00
|
|
|
QPointer<FutureProgress> updateInfoProgress;
|
2011-09-08 16:04:27 +02:00
|
|
|
UpdateInfoButton *progressUpdateInfoButton;
|
|
|
|
|
QFutureWatcher<QDomDocument> *checkUpdateInfoWatcher;
|
2013-11-11 14:58:17 +01:00
|
|
|
|
|
|
|
|
QBasicTimer m_timer;
|
|
|
|
|
QDate m_lastDayChecked;
|
|
|
|
|
QTime m_scheduledUpdateTime;
|
|
|
|
|
SettingsPage *m_settingsPage;
|
2011-09-08 16:04:27 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UpdateInfoPlugin::UpdateInfoPlugin()
|
|
|
|
|
: d(new UpdateInfoPluginPrivate)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UpdateInfoPlugin::~UpdateInfoPlugin()
|
|
|
|
|
{
|
|
|
|
|
delete d;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-11 14:58:17 +01:00
|
|
|
bool UpdateInfoPlugin::delayedInitialize()
|
2011-09-08 16:04:27 +02:00
|
|
|
{
|
2013-11-11 14:58:17 +01:00
|
|
|
d->checkUpdateInfoWatcher = new QFutureWatcher<QDomDocument>(this);
|
|
|
|
|
connect(d->checkUpdateInfoWatcher, SIGNAL(finished()), this, SLOT(parseUpdates()));
|
|
|
|
|
|
|
|
|
|
d->m_timer.start(OneMinute, this);
|
|
|
|
|
return true;
|
2011-09-08 16:04:27 +02:00
|
|
|
}
|
|
|
|
|
|
2013-11-11 14:58:17 +01:00
|
|
|
void UpdateInfoPlugin::extensionsInitialized()
|
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();
|
2011-10-20 16:39:44 +02:00
|
|
|
if (d->updaterProgram.isEmpty()) {
|
|
|
|
|
*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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!QFile::exists(d->updaterProgram)) {
|
|
|
|
|
*errorMessage = tr("Could not find maintenance tool at '%1'. Check your installation.")
|
2013-11-11 14:58:17 +01:00
|
|
|
.arg(d->updaterProgram);
|
2011-10-20 16:39:44 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-11 14:58:17 +01:00
|
|
|
d->m_settingsPage = new SettingsPage(this);
|
2013-11-13 12:31:51 +01:00
|
|
|
addAutoReleasedObject(d->m_settingsPage);
|
2011-09-08 16:04:27 +02:00
|
|
|
|
2013-11-11 14:58:17 +01:00
|
|
|
ActionContainer *const container = ActionManager::actionContainer(Core::Constants::M_HELP);
|
|
|
|
|
container->menu()->addAction(tr("Start Updater"), this, SLOT(startUpdaterUiApplication()));
|
2011-10-20 16:39:44 +02:00
|
|
|
|
2011-09-08 16:04:27 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-11 14:58:17 +01:00
|
|
|
void UpdateInfoPlugin::loadSettings()
|
2011-09-08 16:04:27 +02:00
|
|
|
{
|
2013-11-11 14:58:17 +01:00
|
|
|
QSettings *qs = ICore::settings();
|
|
|
|
|
if (qs->contains(QLatin1String("Updater/Application"))) {
|
|
|
|
|
settingsHelper(qs);
|
|
|
|
|
qs->remove(QLatin1String("Updater"));
|
|
|
|
|
saveSettings(); // update to the new settings location
|
|
|
|
|
} else {
|
|
|
|
|
settingsHelper(ICore::settingsDatabase());
|
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()
|
|
|
|
|
{
|
|
|
|
|
SettingsDatabase *settings = ICore::settingsDatabase();
|
|
|
|
|
if (settings) {
|
|
|
|
|
settings->beginGroup(QLatin1String("Updater"));
|
|
|
|
|
settings->setValue(QLatin1String("Application"), d->updaterProgram);
|
|
|
|
|
settings->setValue(QLatin1String("LastDayChecked"), d->m_lastDayChecked);
|
|
|
|
|
settings->setValue(QLatin1String("RunUiArgument"), d->updaterRunUiArgument);
|
|
|
|
|
settings->setValue(QLatin1String("CheckOnlyArgument"), d->updaterCheckOnlyArgument);
|
|
|
|
|
settings->setValue(QLatin1String("ScheduledUpdateTime"), d->m_scheduledUpdateTime);
|
|
|
|
|
settings->endGroup();
|
|
|
|
|
}
|
2011-09-08 16:04:27 +02:00
|
|
|
}
|
|
|
|
|
|
2013-11-11 14:58:17 +01:00
|
|
|
QTime UpdateInfoPlugin::scheduledUpdateTime() const
|
|
|
|
|
{
|
|
|
|
|
return d->m_scheduledUpdateTime;
|
|
|
|
|
}
|
2011-09-08 16:04:27 +02:00
|
|
|
|
2013-11-11 14:58:17 +01:00
|
|
|
void UpdateInfoPlugin::setScheduledUpdateTime(const QTime &time)
|
2011-09-08 16:04:27 +02:00
|
|
|
{
|
2013-11-11 14:58:17 +01:00
|
|
|
d->m_scheduledUpdateTime = time;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// -- protected
|
2011-09-08 16:04:27 +02:00
|
|
|
|
2013-11-11 14:58:17 +01:00
|
|
|
void UpdateInfoPlugin::timerEvent(QTimerEvent *event)
|
|
|
|
|
{
|
|
|
|
|
if (event->timerId() == d->m_timer.timerId()) {
|
|
|
|
|
const QDate today = QDate::currentDate();
|
|
|
|
|
if ((d->m_lastDayChecked == today) || (d->lastCheckUpdateInfoTask.isRunning()))
|
|
|
|
|
return; // we checked already or the update task is still running
|
|
|
|
|
|
|
|
|
|
bool check = false;
|
|
|
|
|
if (d->m_lastDayChecked <= today.addDays(-2))
|
|
|
|
|
check = true; // we haven't checked since some days, force check
|
|
|
|
|
|
|
|
|
|
if (QTime::currentTime() > d->m_scheduledUpdateTime)
|
|
|
|
|
check = true; // we are behind schedule, force check
|
|
|
|
|
|
|
|
|
|
if (check) {
|
|
|
|
|
d->lastCheckUpdateInfoTask = QtConcurrent::run(this, &UpdateInfoPlugin::update);
|
|
|
|
|
d->checkUpdateInfoWatcher->setFuture(d->lastCheckUpdateInfoTask);
|
|
|
|
|
}
|
2011-09-08 16:04:27 +02:00
|
|
|
} else {
|
2013-11-11 14:58:17 +01:00
|
|
|
// not triggered from our timer
|
|
|
|
|
ExtensionSystem::IPlugin::timerEvent(event);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// -- private slots
|
2011-09-08 16:04:27 +02:00
|
|
|
|
2013-11-11 14:58:17 +01:00
|
|
|
void UpdateInfoPlugin::parseUpdates()
|
|
|
|
|
{
|
|
|
|
|
QDomDocument updatesDomDocument = d->checkUpdateInfoWatcher->result();
|
|
|
|
|
if (updatesDomDocument.isNull() || !updatesDomDocument.firstChildElement().hasChildNodes())
|
|
|
|
|
return;
|
2011-09-08 16:04:27 +02:00
|
|
|
|
2013-11-11 14:58:17 +01:00
|
|
|
// add the finished task to the progress manager
|
|
|
|
|
d->updateInfoProgress = ProgressManager::addTask(d->lastCheckUpdateInfoTask, tr("Updates "
|
|
|
|
|
"available"), "Update.GetInfo", ProgressManager::KeepOnFinish);
|
|
|
|
|
d->updateInfoProgress->setKeepOnFinish(FutureProgress::KeepOnFinish);
|
2011-09-08 16:04:27 +02:00
|
|
|
|
2013-11-11 14:58:17 +01:00
|
|
|
d->progressUpdateInfoButton = new UpdateInfoButton();
|
|
|
|
|
d->updateInfoProgress->setWidget(d->progressUpdateInfoButton);
|
|
|
|
|
connect(d->progressUpdateInfoButton, SIGNAL(released()), this, SLOT(startUpdaterUiApplication()));
|
2011-09-08 16:04:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UpdateInfoPlugin::startUpdaterUiApplication()
|
|
|
|
|
{
|
|
|
|
|
QProcess::startDetached(d->updaterProgram, QStringList() << d->updaterRunUiArgument);
|
2013-11-11 14:58:17 +01:00
|
|
|
if (!d->updateInfoProgress.isNull()) //this is fading out the last update info
|
|
|
|
|
d->updateInfoProgress->setKeepOnFinish(FutureProgress::HideOnFinish);
|
2011-09-08 16:04:27 +02:00
|
|
|
}
|
|
|
|
|
|
2013-11-11 14:58:17 +01:00
|
|
|
// -- private
|
|
|
|
|
|
|
|
|
|
QDomDocument UpdateInfoPlugin::update()
|
2011-09-08 16:04:27 +02:00
|
|
|
{
|
2013-11-11 14:58:17 +01:00
|
|
|
if (QThread::currentThread() == QCoreApplication::instance()->thread()) {
|
|
|
|
|
qWarning() << Q_FUNC_INFO << " was not designed to run in main/ gui thread, it is using "
|
|
|
|
|
"QProcess::waitForFinished()";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// start
|
|
|
|
|
QProcess updater;
|
|
|
|
|
updater.start(d->updaterProgram, QStringList() << d->updaterCheckOnlyArgument);
|
|
|
|
|
updater.waitForFinished();
|
|
|
|
|
|
|
|
|
|
// process return value
|
|
|
|
|
QDomDocument updates;
|
|
|
|
|
if (updater.exitStatus() != QProcess::CrashExit) {
|
|
|
|
|
d->m_timer.stop();
|
|
|
|
|
d->m_lastDayChecked = QDate::currentDate();
|
|
|
|
|
updates.setContent(updater.readAllStandardOutput());
|
|
|
|
|
saveSettings(); // force writing out the last update date
|
|
|
|
|
} else {
|
|
|
|
|
qWarning() << "Updater application crashed.";
|
2011-09-08 16:04:27 +02:00
|
|
|
}
|
2013-11-11 14:58:17 +01:00
|
|
|
return updates;
|
2011-09-08 16:04:27 +02:00
|
|
|
}
|
|
|
|
|
|
2013-11-11 14:58:17 +01:00
|
|
|
template <typename T>
|
|
|
|
|
void UpdateInfoPlugin::settingsHelper(T *settings)
|
2011-09-08 16:04:27 +02:00
|
|
|
{
|
2013-11-11 14:58:17 +01:00
|
|
|
settings->beginGroup(QLatin1String("Updater"));
|
|
|
|
|
|
|
|
|
|
d->updaterProgram = settings->value(QLatin1String("Application")).toString();
|
|
|
|
|
d->m_lastDayChecked = settings->value(QLatin1String("LastDayChecked"), QDate()).toDate();
|
|
|
|
|
d->updaterRunUiArgument = settings->value(QLatin1String("RunUiArgument"),
|
|
|
|
|
QLatin1String("--updater")).toString();
|
|
|
|
|
d->updaterCheckOnlyArgument = settings->value(QLatin1String("CheckOnlyArgument"),
|
|
|
|
|
QLatin1String("--checkupdates")).toString();
|
|
|
|
|
d->m_scheduledUpdateTime = settings->value(QLatin1String("ScheduledUpdateTime"), QTime(12, 0))
|
|
|
|
|
.toTime();
|
|
|
|
|
|
|
|
|
|
settings->endGroup();
|
2011-09-08 16:04:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} //namespace Internal
|
|
|
|
|
} //namespace UpdateInfo
|
|
|
|
|
|
|
|
|
|
Q_EXPORT_PLUGIN(UpdateInfo::Internal::UpdateInfoPlugin)
|