2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2010-08-26 12:27:16 +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
|
2010-08-26 12:27:16 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2010-08-26 12:27:16 +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.
|
2010-08-26 12:27:16 +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
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2010-08-26 12:27:16 +02:00
|
|
|
|
|
|
|
|
#include "tasklistplugin.h"
|
|
|
|
|
|
2010-08-27 16:26:16 +02:00
|
|
|
#include "stopmonitoringhandler.h"
|
|
|
|
|
#include "taskfile.h"
|
2010-08-26 12:27:16 +02:00
|
|
|
#include "taskfilefactory.h"
|
2010-08-27 16:26:16 +02:00
|
|
|
#include "tasklistconstants.h"
|
2010-08-26 12:27:16 +02:00
|
|
|
|
|
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
#include <coreplugin/mimedatabase.h>
|
2010-08-27 16:26:16 +02:00
|
|
|
#include <extensionsystem/pluginmanager.h>
|
|
|
|
|
#include <projectexplorer/project.h>
|
|
|
|
|
#include <projectexplorer/task.h>
|
|
|
|
|
#include <projectexplorer/taskhub.h>
|
2010-08-26 12:27:16 +02:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QDir>
|
|
|
|
|
#include <QStringList>
|
|
|
|
|
#include <QtPlugin>
|
2010-08-26 12:27:16 +02:00
|
|
|
|
2010-08-27 16:26:16 +02:00
|
|
|
namespace {
|
2010-08-26 12:27:16 +02:00
|
|
|
|
2010-08-27 16:26:16 +02:00
|
|
|
ProjectExplorer::Task::TaskType typeFrom(const QString &typeName)
|
|
|
|
|
{
|
|
|
|
|
ProjectExplorer::Task::TaskType type = ProjectExplorer::Task::Unknown;
|
|
|
|
|
QString tmp = typeName.toLower();
|
|
|
|
|
if (tmp.startsWith(QLatin1String("warn")))
|
|
|
|
|
type = ProjectExplorer::Task::Warning;
|
|
|
|
|
else if (tmp.startsWith(QLatin1String("err")))
|
|
|
|
|
type = ProjectExplorer::Task::Error;
|
|
|
|
|
return type;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
using namespace TaskList;
|
|
|
|
|
|
|
|
|
|
TaskListPlugin *TaskListPlugin::m_instance = 0;
|
|
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
// TaskListPluginPrivate
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
class Internal::TaskListPluginPrivate {
|
|
|
|
|
public:
|
2011-04-04 15:24:13 +02:00
|
|
|
bool parseTaskFile(QString *errorString, ProjectExplorer::Project *context, const QString &name)
|
2010-08-27 16:26:16 +02:00
|
|
|
{
|
|
|
|
|
QFile tf(name);
|
2011-04-04 15:24:13 +02:00
|
|
|
if (!tf.open(QIODevice::ReadOnly)) {
|
|
|
|
|
*errorString = TaskListPlugin::tr("Cannot open task file %1: %2").arg(
|
|
|
|
|
QDir::toNativeSeparators(name), tf.errorString());
|
2010-08-27 16:26:16 +02:00
|
|
|
return false;
|
2011-04-04 15:24:13 +02:00
|
|
|
}
|
2010-08-27 16:26:16 +02:00
|
|
|
|
|
|
|
|
while (!tf.atEnd())
|
|
|
|
|
{
|
|
|
|
|
QStringList chunks = parseRawLine(tf.readLine());
|
|
|
|
|
if (chunks.isEmpty())
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
QString description;
|
|
|
|
|
QString file;
|
|
|
|
|
ProjectExplorer::Task::TaskType type = ProjectExplorer::Task::Unknown;
|
|
|
|
|
int line = -1;
|
|
|
|
|
|
|
|
|
|
if (chunks.count() == 1) {
|
|
|
|
|
description = chunks.at(0);
|
|
|
|
|
} else if (chunks.count() == 2) {
|
|
|
|
|
type = typeFrom(chunks.at(0));
|
|
|
|
|
description = chunks.at(1);
|
|
|
|
|
} else if (chunks.count() == 3) {
|
|
|
|
|
file = chunks.at(0);
|
|
|
|
|
type = typeFrom(chunks.at(1));
|
|
|
|
|
description = chunks.at(2);
|
|
|
|
|
} else if (chunks.count() >= 4) {
|
|
|
|
|
file = chunks.at(0);
|
|
|
|
|
bool ok;
|
|
|
|
|
line = chunks.at(1).toInt(&ok);
|
|
|
|
|
if (!ok)
|
|
|
|
|
line = -1;
|
|
|
|
|
type = typeFrom(chunks.at(2));
|
|
|
|
|
description = chunks.at(3);
|
|
|
|
|
}
|
|
|
|
|
if (!file.isEmpty()) {
|
2010-10-20 12:56:06 +02:00
|
|
|
file = QDir::fromNativeSeparators(file);
|
2010-08-27 16:26:16 +02:00
|
|
|
QFileInfo fi(file);
|
|
|
|
|
if (fi.isRelative() && context) {
|
2012-11-26 20:44:02 +02:00
|
|
|
QString fullPath = context->projectDirectory() + QLatin1Char('/') + file;
|
2010-08-27 16:26:16 +02:00
|
|
|
fi.setFile(fullPath);
|
|
|
|
|
file = fi.absoluteFilePath();
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-12-22 13:46:26 +01:00
|
|
|
description = unescape(description);
|
2010-08-27 16:26:16 +02:00
|
|
|
|
2012-01-26 13:38:25 +01:00
|
|
|
hub->addTask(ProjectExplorer::Task(type, description,
|
|
|
|
|
Utils::FileName::fromUserInput(file), line,
|
|
|
|
|
Core::Id(Constants::TASKLISTTASK_ID)));
|
2010-08-27 16:26:16 +02:00
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QStringList parseRawLine(const QByteArray &raw)
|
|
|
|
|
{
|
|
|
|
|
QStringList result;
|
|
|
|
|
QString line = QString::fromUtf8(raw.constData());
|
2012-11-26 20:44:02 +02:00
|
|
|
if (line.startsWith(QLatin1Char('#')))
|
2010-08-27 16:26:16 +02:00
|
|
|
return result;
|
|
|
|
|
|
2012-11-26 20:44:02 +02:00
|
|
|
return line.split(QLatin1Char('\t'));
|
2010-08-27 16:26:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString unescape(const QString &input) const
|
|
|
|
|
{
|
|
|
|
|
QString result;
|
|
|
|
|
for (int i = 0; i < input.count(); ++i) {
|
2012-11-26 20:44:02 +02:00
|
|
|
if (input.at(i) == QLatin1Char('\\')) {
|
2010-08-27 16:26:16 +02:00
|
|
|
if (i == input.count() - 1)
|
|
|
|
|
continue;
|
2012-11-26 20:44:02 +02:00
|
|
|
if (input.at(i + 1) == QLatin1Char('n')) {
|
|
|
|
|
result.append(QLatin1Char('\n'));
|
2010-08-27 16:26:16 +02:00
|
|
|
++i;
|
|
|
|
|
continue;
|
2012-11-26 20:44:02 +02:00
|
|
|
} else if (input.at(i + 1) == QLatin1Char('t')) {
|
|
|
|
|
result.append(QLatin1Char('\t'));
|
2010-08-27 16:26:16 +02:00
|
|
|
++i;
|
|
|
|
|
continue;
|
2012-11-26 20:44:02 +02:00
|
|
|
} else if (input.at(i + 1) == QLatin1Char('\\')) {
|
|
|
|
|
result.append(QLatin1Char('\\'));
|
2010-08-27 16:26:16 +02:00
|
|
|
++i;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
result.append(input.at(i));
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ProjectExplorer::TaskHub *hub;
|
|
|
|
|
TaskFileFactory *fileFactory;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
// TaskListPlugin
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
TaskListPlugin::TaskListPlugin() :
|
|
|
|
|
d(new Internal::TaskListPluginPrivate)
|
|
|
|
|
{
|
|
|
|
|
m_instance = this;
|
|
|
|
|
}
|
2010-08-26 12:27:16 +02:00
|
|
|
|
|
|
|
|
TaskListPlugin::~TaskListPlugin()
|
2010-08-27 16:26:16 +02:00
|
|
|
{
|
|
|
|
|
delete d;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TaskListPlugin *TaskListPlugin::instance()
|
|
|
|
|
{
|
|
|
|
|
return m_instance;
|
|
|
|
|
}
|
2010-08-26 12:27:16 +02:00
|
|
|
|
|
|
|
|
bool TaskListPlugin::initialize(const QStringList &arguments, QString *errorMessage)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(arguments)
|
|
|
|
|
|
2012-06-18 11:34:15 +02:00
|
|
|
d->hub = ExtensionSystem::PluginManager::getObject<ProjectExplorer::TaskHub>();
|
2010-08-27 16:26:16 +02:00
|
|
|
|
2011-10-21 16:39:14 +02:00
|
|
|
//: Category under which tasklist tasks are listed in Issues view
|
2012-01-26 13:38:25 +01:00
|
|
|
d->hub->addCategory(Core::Id(Constants::TASKLISTTASK_ID), tr("My Tasks"));
|
2010-08-27 16:26:16 +02:00
|
|
|
|
2012-01-24 15:36:40 +01:00
|
|
|
if (!Core::ICore::mimeDatabase()->addMimeTypes(QLatin1String(":tasklist/TaskList.mimetypes.xml"), errorMessage))
|
2010-08-26 12:27:16 +02:00
|
|
|
return false;
|
|
|
|
|
|
2010-08-27 16:26:16 +02:00
|
|
|
d->fileFactory = new Internal::TaskFileFactory(this);
|
|
|
|
|
addAutoReleasedObject(d->fileFactory);
|
|
|
|
|
addAutoReleasedObject(new Internal::StopMonitoringHandler);
|
2010-08-26 12:27:16 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TaskListPlugin::extensionsInitialized()
|
|
|
|
|
{ }
|
|
|
|
|
|
2011-04-04 15:24:13 +02:00
|
|
|
bool TaskListPlugin::loadFile(QString *errorString, ProjectExplorer::Project *context, const QString &fileName)
|
2010-08-27 16:26:16 +02:00
|
|
|
{
|
|
|
|
|
clearTasks();
|
2011-04-04 15:24:13 +02:00
|
|
|
return d->parseTaskFile(errorString, context, fileName);
|
2010-08-27 16:26:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TaskListPlugin::monitorFile(ProjectExplorer::Project *context, const QString &fileName)
|
|
|
|
|
{
|
|
|
|
|
return d->fileFactory->open(context, fileName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TaskListPlugin::stopMonitoring()
|
|
|
|
|
{
|
|
|
|
|
d->fileFactory->closeAllFiles();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TaskListPlugin::clearTasks()
|
|
|
|
|
{
|
2012-01-26 13:38:25 +01:00
|
|
|
d->hub->clearTasks(Core::Id(Constants::TASKLISTTASK_ID));
|
2010-08-27 16:26:16 +02:00
|
|
|
}
|
|
|
|
|
|
2010-08-26 12:27:16 +02:00
|
|
|
Q_EXPORT_PLUGIN(TaskListPlugin)
|