2010-08-26 12:27:16 +02:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
|
|
|
|
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
|
|
|
|
**
|
|
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
|
|
|
**
|
|
|
|
|
** Commercial Usage
|
|
|
|
|
**
|
|
|
|
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
|
|
|
|
** accordance with the Qt Commercial License Agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Nokia.
|
|
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
**
|
|
|
|
|
** 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.
|
|
|
|
|
**
|
|
|
|
|
** If you are unsure which license is appropriate for your use, please
|
|
|
|
|
** contact the sales department at http://qt.nokia.com/contact.
|
|
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
|
#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
|
|
|
|
|
|
|
|
#include <QtCore/QStringList>
|
|
|
|
|
#include <QtCore/QtPlugin>
|
|
|
|
|
|
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:
|
|
|
|
|
bool parseTaskFile(ProjectExplorer::Project *context, const QString &name)
|
|
|
|
|
{
|
|
|
|
|
QFile tf(name);
|
|
|
|
|
if (!tf.open(QIODevice::ReadOnly))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
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()) {
|
|
|
|
|
QFileInfo fi(file);
|
|
|
|
|
if (fi.isRelative() && context) {
|
|
|
|
|
QString fullPath = context->projectDirectory() + '/' + file;
|
|
|
|
|
fi.setFile(fullPath);
|
|
|
|
|
file = fi.absoluteFilePath();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hub->addTask(ProjectExplorer::Task(type, description, file, line, QLatin1String(Constants::TASKLISTTASK_ID)));
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QStringList parseRawLine(const QByteArray &raw)
|
|
|
|
|
{
|
|
|
|
|
QStringList result;
|
|
|
|
|
QString line = QString::fromUtf8(raw.constData());
|
|
|
|
|
if (line.startsWith(QChar('#')))
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
|
|
result = line.split(QChar('\t'));
|
|
|
|
|
for (int i = 0; i < result.count(); ++i)
|
|
|
|
|
result[i] = unescape(result.at(i));
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString unescape(const QString &input) const
|
|
|
|
|
{
|
|
|
|
|
QString result;
|
|
|
|
|
for (int i = 0; i < input.count(); ++i) {
|
|
|
|
|
if (input.at(i) == QChar('\\')) {
|
|
|
|
|
if (i == input.count() - 1)
|
|
|
|
|
continue;
|
|
|
|
|
if (input.at(i + 1) == QChar('n')) {
|
|
|
|
|
result.append(QChar('\n'));
|
|
|
|
|
++i;
|
|
|
|
|
continue;
|
|
|
|
|
} else if (input.at(i + 1) == QChar('t')) {
|
|
|
|
|
result.append(QChar('\t'));
|
|
|
|
|
++i;
|
|
|
|
|
continue;
|
|
|
|
|
} else if (input.at(i + 1) == QChar('\\')) {
|
|
|
|
|
result.append(QChar('\\'));
|
|
|
|
|
++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)
|
|
|
|
|
|
2010-08-27 16:26:16 +02:00
|
|
|
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
|
|
|
|
d->hub = pm->getObject<ProjectExplorer::TaskHub>();
|
|
|
|
|
|
|
|
|
|
//: Category under which tasklist tasks are listed in build issues view
|
2010-09-09 12:55:55 +02:00
|
|
|
d->hub->addCategory(QLatin1String(Constants::TASKLISTTASK_ID), tr("My Tasks"));
|
2010-08-27 16:26:16 +02:00
|
|
|
|
2010-08-26 12:27:16 +02:00
|
|
|
Core::ICore *core = Core::ICore::instance();
|
|
|
|
|
if (!core->mimeDatabase()->addMimeTypes(QLatin1String(":tasklist/TaskList.mimetypes.xml"), errorMessage))
|
|
|
|
|
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()
|
|
|
|
|
{ }
|
|
|
|
|
|
2010-08-27 16:26:16 +02:00
|
|
|
bool TaskListPlugin::loadFile(ProjectExplorer::Project *context, const QString &fileName)
|
|
|
|
|
{
|
|
|
|
|
clearTasks();
|
|
|
|
|
return d->parseTaskFile(context, fileName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TaskListPlugin::monitorFile(ProjectExplorer::Project *context, const QString &fileName)
|
|
|
|
|
{
|
|
|
|
|
return d->fileFactory->open(context, fileName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TaskListPlugin::stopMonitoring()
|
|
|
|
|
{
|
|
|
|
|
d->fileFactory->closeAllFiles();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TaskListPlugin::clearTasks()
|
|
|
|
|
{
|
|
|
|
|
d->hub->clearTasks(QLatin1String(Constants::TASKLISTTASK_ID));
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-26 12:27:16 +02:00
|
|
|
Q_EXPORT_PLUGIN(TaskListPlugin)
|