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
|
|
|
|
|
|
|
|
#include "updateinfoplugin.h"
|
|
|
|
|
#include "updateinfobutton.h"
|
|
|
|
|
|
|
|
|
|
#include <coreplugin/actionmanager/actionmanager.h>
|
|
|
|
|
#include <coreplugin/actionmanager/actioncontainer.h>
|
|
|
|
|
#include <coreplugin/coreconstants.h>
|
|
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
#include <coreplugin/modemanager.h>
|
|
|
|
|
#include <coreplugin/progressmanager/progressmanager.h>
|
|
|
|
|
#include <coreplugin/progressmanager/futureprogress.h>
|
|
|
|
|
|
|
|
|
|
#include <qtconcurrentrun.h>
|
|
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QtPlugin>
|
|
|
|
|
#include <QProcess>
|
|
|
|
|
#include <QTimer>
|
|
|
|
|
#include <QTimerEvent>
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
#include <QFile>
|
|
|
|
|
#include <QThread>
|
|
|
|
|
#include <QCoreApplication>
|
|
|
|
|
#include <QDomDocument>
|
|
|
|
|
#include <QMessageBox>
|
|
|
|
|
#include <QMenu>
|
|
|
|
|
#include <QFutureWatcher>
|
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()
|
|
|
|
|
: startUpdaterAction(0),
|
|
|
|
|
currentTimerId(0),
|
|
|
|
|
progressUpdateInfoButton(0),
|
|
|
|
|
checkUpdateInfoWatcher(0)
|
|
|
|
|
{}
|
|
|
|
|
~UpdateInfoPluginPrivate()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QAction *startUpdaterAction;
|
|
|
|
|
QString updaterProgram;
|
|
|
|
|
QString updaterCheckOnlyArgument;
|
|
|
|
|
QString updaterRunUiArgument;
|
|
|
|
|
int currentTimerId;
|
|
|
|
|
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;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UpdateInfoPlugin::UpdateInfoPlugin()
|
|
|
|
|
: d(new UpdateInfoPluginPrivate)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UpdateInfoPlugin::~UpdateInfoPlugin()
|
|
|
|
|
{
|
|
|
|
|
delete d;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UpdateInfoPlugin::startCheckTimer(uint milliseconds)
|
|
|
|
|
{
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (d->currentTimerId != 0)
|
2011-09-08 16:04:27 +02:00
|
|
|
stopCurrentCheckTimer();
|
|
|
|
|
d->currentTimerId = startTimer(milliseconds);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UpdateInfoPlugin::stopCurrentCheckTimer()
|
|
|
|
|
{
|
|
|
|
|
killTimer(d->currentTimerId);
|
2011-12-19 10:56:01 +01:00
|
|
|
d->currentTimerId = 0;
|
2011-09-08 16:04:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*! Initializes the plugin. Returns true on success.
|
|
|
|
|
Plugins want to register objects with the plugin manager here.
|
|
|
|
|
|
2011-09-21 13:05:15 +02:00
|
|
|
\a errorMessage can be used to pass an error message to the plugin system,
|
2011-09-08 16:04:27 +02:00
|
|
|
if there was any.
|
|
|
|
|
*/
|
2011-10-20 16:39:44 +02:00
|
|
|
bool UpdateInfoPlugin::initialize(const QStringList & /* arguments */, QString *errorMessage)
|
2011-09-08 16:04:27 +02:00
|
|
|
{
|
|
|
|
|
d->checkUpdateInfoWatcher = new QFutureWatcher<QDomDocument>(this);
|
|
|
|
|
connect(d->checkUpdateInfoWatcher, SIGNAL(finished()), this, SLOT(reactOnUpdaterOutput()));
|
|
|
|
|
|
2013-08-30 09:22:42 +02:00
|
|
|
QSettings *settings = ICore::settings();
|
2011-09-08 16:04:27 +02:00
|
|
|
d->updaterProgram = settings->value(QLatin1String("Updater/Application")).toString();
|
|
|
|
|
d->updaterCheckOnlyArgument = settings->value(QLatin1String("Updater/CheckOnlyArgument")).toString();
|
|
|
|
|
d->updaterRunUiArgument = settings->value(QLatin1String("Updater/RunUiArgument")).toString();
|
|
|
|
|
|
2011-10-20 16:39:44 +02:00
|
|
|
if (d->updaterProgram.isEmpty()) {
|
|
|
|
|
*errorMessage = tr("Could not determine location of maintenance tool. Please check "
|
|
|
|
|
"your installation if you did not enable this plugin manually.");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!QFile::exists(d->updaterProgram)) {
|
|
|
|
|
*errorMessage = tr("Could not find maintenance tool at '%1'. Check your installation.")
|
|
|
|
|
.arg(d->updaterProgram);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-30 09:22:42 +02:00
|
|
|
ActionContainer *const helpActionContainer = ActionManager::actionContainer(Core::Constants::M_HELP);
|
2011-09-08 16:04:27 +02:00
|
|
|
helpActionContainer->menu()->addAction(tr("Start Updater"), this, SLOT(startUpdaterUiApplication()));
|
|
|
|
|
|
|
|
|
|
//wait some time before we want to have the first check
|
2011-10-20 16:39:44 +02:00
|
|
|
startCheckTimer(OneMinute / 10);
|
|
|
|
|
|
2011-09-08 16:04:27 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QDomDocument UpdateInfoPlugin::checkForUpdates()
|
|
|
|
|
{
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (QThread::currentThread() == QCoreApplication::instance()->thread())
|
2011-09-08 16:04:27 +02:00
|
|
|
qWarning() << Q_FUNC_INFO << " Was not designed to run in main/gui thread -> it is using updaterProcess.waitForFinished()";
|
|
|
|
|
|
|
|
|
|
//starting
|
|
|
|
|
QProcess updaterProcess;
|
|
|
|
|
|
|
|
|
|
updaterProcess.start(d->updaterProgram,
|
|
|
|
|
QStringList() << d->updaterCheckOnlyArgument);
|
|
|
|
|
updaterProcess.waitForFinished();
|
|
|
|
|
|
|
|
|
|
//process return value
|
|
|
|
|
if (updaterProcess.exitStatus() == QProcess::CrashExit) {
|
|
|
|
|
qWarning() << "Get update info application crashed.";
|
|
|
|
|
//return; //maybe there is some output
|
|
|
|
|
}
|
2012-11-26 20:44:10 +02:00
|
|
|
QByteArray updaterOutput = updaterProcess.readAllStandardOutput();
|
2011-09-08 16:04:27 +02:00
|
|
|
QDomDocument updatesDomDocument;
|
|
|
|
|
updatesDomDocument.setContent(updaterOutput);
|
|
|
|
|
|
|
|
|
|
return updatesDomDocument;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void UpdateInfoPlugin::reactOnUpdaterOutput()
|
|
|
|
|
{
|
|
|
|
|
QDomDocument updatesDomDocument = d->checkUpdateInfoWatcher->result();
|
|
|
|
|
|
|
|
|
|
if (updatesDomDocument.isNull() ||
|
|
|
|
|
!updatesDomDocument.firstChildElement().hasChildNodes())
|
|
|
|
|
{ // no updates are available
|
|
|
|
|
startCheckTimer(60 * OneMinute);
|
|
|
|
|
} else {
|
|
|
|
|
//added the current almost finished task to the progressmanager
|
2013-08-30 09:22:42 +02:00
|
|
|
d->updateInfoProgress = ProgressManager::addTask(
|
2013-09-03 15:18:37 +02:00
|
|
|
d->lastCheckUpdateInfoTask, tr("Update"), "Update.GetInfo", ProgressManager::KeepOnFinish);
|
2011-09-08 16:04:27 +02:00
|
|
|
|
2013-08-30 09:22:42 +02:00
|
|
|
d->updateInfoProgress->setKeepOnFinish(FutureProgress::KeepOnFinish);
|
2011-09-08 16:04:27 +02:00
|
|
|
|
|
|
|
|
d->progressUpdateInfoButton = new UpdateInfoButton();
|
|
|
|
|
//the old widget is deleted inside this function
|
|
|
|
|
//and the current widget becomes a child of updateInfoProgress
|
|
|
|
|
d->updateInfoProgress->setWidget(d->progressUpdateInfoButton);
|
|
|
|
|
|
|
|
|
|
//d->progressUpdateInfoButton->setText(tr("Update")); //we have this information over the progressbar
|
|
|
|
|
connect(d->progressUpdateInfoButton, SIGNAL(released()),
|
|
|
|
|
this, SLOT(startUpdaterUiApplication()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UpdateInfoPlugin::startUpdaterUiApplication()
|
|
|
|
|
{
|
|
|
|
|
QProcess::startDetached(d->updaterProgram, QStringList() << d->updaterRunUiArgument);
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (!d->updateInfoProgress.isNull())
|
2013-08-30 09:22:42 +02:00
|
|
|
d->updateInfoProgress->setKeepOnFinish(FutureProgress::HideOnFinish); //this is fading out the last updateinfo
|
2011-09-08 16:04:27 +02:00
|
|
|
startCheckTimer(OneMinute);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UpdateInfoPlugin::timerEvent(QTimerEvent *event)
|
|
|
|
|
{
|
|
|
|
|
if (event->timerId() == d->currentTimerId && !d->lastCheckUpdateInfoTask.isRunning())
|
|
|
|
|
{
|
|
|
|
|
stopCurrentCheckTimer();
|
|
|
|
|
d->lastCheckUpdateInfoTask = QtConcurrent::run(this, &UpdateInfoPlugin::checkForUpdates);
|
|
|
|
|
d->checkUpdateInfoWatcher->setFuture(d->lastCheckUpdateInfoTask);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UpdateInfoPlugin::extensionsInitialized()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} //namespace Internal
|
|
|
|
|
} //namespace UpdateInfo
|
|
|
|
|
|
|
|
|
|
Q_EXPORT_PLUGIN(UpdateInfo::Internal::UpdateInfoPlugin)
|