2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2010-08-26 12:27:16 +02:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** Copyright (C) 2015 The Qt Company Ltd.
|
|
|
|
|
** Contact: http://www.qt.io/licensing
|
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
|
2015-01-14 18:07:15 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms and
|
|
|
|
|
** conditions see http://www.qt.io/terms-conditions. For further information
|
2014-10-01 13:21:18 +02:00
|
|
|
** use the contact form at http://www.qt.io/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
|
2014-10-01 13:21:18 +02:00
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2012-10-02 09:12:39 +02:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** In addition, as a special exception, The Qt Company gives you certain additional
|
|
|
|
|
** rights. These rights are described in The Qt Company 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"
|
|
|
|
|
#include "tasklistconstants.h"
|
2010-08-26 12:27:16 +02:00
|
|
|
|
|
|
|
|
#include <coreplugin/icore.h>
|
2014-06-27 23:42:28 +02:00
|
|
|
#include <coreplugin/idocumentfactory.h>
|
|
|
|
|
#include <coreplugin/documentmanager.h>
|
2014-11-19 17:58:33 +01:00
|
|
|
#include <projectexplorer/projecttree.h>
|
2010-08-27 16:26:16 +02:00
|
|
|
#include <projectexplorer/project.h>
|
2013-09-23 14:25:32 +02:00
|
|
|
#include <projectexplorer/session.h>
|
2010-08-27 16:26:16 +02:00
|
|
|
#include <projectexplorer/task.h>
|
|
|
|
|
#include <projectexplorer/taskhub.h>
|
2015-02-04 09:32:46 +01:00
|
|
|
#include <utils/mimetypes/mimedatabase.h>
|
2010-08-26 12:27:16 +02:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QDir>
|
2014-06-27 23:42:28 +02:00
|
|
|
#include <QMessageBox>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QStringList>
|
|
|
|
|
#include <QtPlugin>
|
2010-08-26 12:27:16 +02:00
|
|
|
|
2014-06-27 23:42:28 +02:00
|
|
|
using namespace Core;
|
2013-08-29 18:25:59 +02:00
|
|
|
using namespace ProjectExplorer;
|
2010-08-26 12:27:16 +02:00
|
|
|
|
2013-09-23 14:25:32 +02:00
|
|
|
static const char SESSION_FILE_KEY[] = "TaskList.File";
|
2013-09-24 09:56:27 +02:00
|
|
|
static const char SESSION_BASE_KEY[] = "TaskList.BaseDir";
|
2013-09-23 14:25:32 +02:00
|
|
|
|
2013-08-29 18:25:59 +02:00
|
|
|
namespace TaskList {
|
2014-06-27 23:42:28 +02:00
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
static TaskListPlugin *m_instance;
|
2013-08-29 18:25:59 +02:00
|
|
|
|
|
|
|
|
static Task::TaskType typeFrom(const QString &typeName)
|
2010-08-27 16:26:16 +02:00
|
|
|
{
|
2013-08-29 18:25:59 +02:00
|
|
|
Task::TaskType type = Task::Unknown;
|
2010-08-27 16:26:16 +02:00
|
|
|
QString tmp = typeName.toLower();
|
|
|
|
|
if (tmp.startsWith(QLatin1String("warn")))
|
2013-08-29 18:25:59 +02:00
|
|
|
type = Task::Warning;
|
2010-08-27 16:26:16 +02:00
|
|
|
else if (tmp.startsWith(QLatin1String("err")))
|
2013-08-29 18:25:59 +02:00
|
|
|
type = Task::Error;
|
2010-08-27 16:26:16 +02:00
|
|
|
return type;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-29 18:25:59 +02:00
|
|
|
static QStringList parseRawLine(const QByteArray &raw)
|
|
|
|
|
{
|
|
|
|
|
QStringList result;
|
|
|
|
|
QString line = QString::fromUtf8(raw.constData());
|
|
|
|
|
if (line.startsWith(QLatin1Char('#')))
|
|
|
|
|
return result;
|
2010-08-27 16:26:16 +02:00
|
|
|
|
2013-08-29 18:25:59 +02:00
|
|
|
return line.split(QLatin1Char('\t'));
|
|
|
|
|
}
|
2010-08-27 16:26:16 +02:00
|
|
|
|
2013-08-29 18:25:59 +02:00
|
|
|
static QString unescape(const QString &input)
|
|
|
|
|
{
|
|
|
|
|
QString result;
|
|
|
|
|
for (int i = 0; i < input.count(); ++i) {
|
|
|
|
|
if (input.at(i) == QLatin1Char('\\')) {
|
|
|
|
|
if (i == input.count() - 1)
|
|
|
|
|
continue;
|
|
|
|
|
if (input.at(i + 1) == QLatin1Char('n')) {
|
|
|
|
|
result.append(QLatin1Char('\n'));
|
|
|
|
|
++i;
|
|
|
|
|
continue;
|
|
|
|
|
} else if (input.at(i + 1) == QLatin1Char('t')) {
|
|
|
|
|
result.append(QLatin1Char('\t'));
|
|
|
|
|
++i;
|
|
|
|
|
continue;
|
|
|
|
|
} else if (input.at(i + 1) == QLatin1Char('\\')) {
|
|
|
|
|
result.append(QLatin1Char('\\'));
|
|
|
|
|
++i;
|
2010-08-27 16:26:16 +02:00
|
|
|
continue;
|
|
|
|
|
}
|
2013-08-29 18:25:59 +02:00
|
|
|
continue;
|
2010-08-27 16:26:16 +02:00
|
|
|
}
|
2013-08-29 18:25:59 +02:00
|
|
|
result.append(input.at(i));
|
2010-08-27 16:26:16 +02:00
|
|
|
}
|
2013-08-29 18:25:59 +02:00
|
|
|
return result;
|
|
|
|
|
}
|
2010-08-27 16:26:16 +02:00
|
|
|
|
2013-09-24 09:56:27 +02:00
|
|
|
static bool parseTaskFile(QString *errorString, const QString &base, const QString &name)
|
2013-08-29 18:25:59 +02:00
|
|
|
{
|
|
|
|
|
QFile tf(name);
|
|
|
|
|
if (!tf.open(QIODevice::ReadOnly)) {
|
|
|
|
|
*errorString = TaskListPlugin::tr("Cannot open task file %1: %2").arg(
|
|
|
|
|
QDir::toNativeSeparators(name), tf.errorString());
|
|
|
|
|
return false;
|
2010-08-27 16:26:16 +02:00
|
|
|
}
|
|
|
|
|
|
2013-08-29 18:25:59 +02:00
|
|
|
while (!tf.atEnd()) {
|
|
|
|
|
QStringList chunks = parseRawLine(tf.readLine());
|
|
|
|
|
if (chunks.isEmpty())
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
QString description;
|
|
|
|
|
QString file;
|
|
|
|
|
Task::TaskType type = 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()) {
|
|
|
|
|
file = QDir::fromNativeSeparators(file);
|
|
|
|
|
QFileInfo fi(file);
|
2013-09-24 09:56:27 +02:00
|
|
|
if (fi.isRelative() && !base.isEmpty()) {
|
|
|
|
|
QString fullPath = base + QLatin1Char('/') + file;
|
2013-08-29 18:25:59 +02:00
|
|
|
fi.setFile(fullPath);
|
|
|
|
|
file = fi.absoluteFilePath();
|
2010-08-27 16:26:16 +02:00
|
|
|
}
|
|
|
|
|
}
|
2013-08-29 18:25:59 +02:00
|
|
|
description = unescape(description);
|
2010-08-27 16:26:16 +02:00
|
|
|
|
2013-08-29 18:25:59 +02:00
|
|
|
TaskHub::addTask(type, description, Constants::TASKLISTTASK_ID,
|
|
|
|
|
Utils::FileName::fromUserInput(file), line);
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2010-08-27 16:26:16 +02:00
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
// TaskListPlugin
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
2015-02-03 23:56:02 +02:00
|
|
|
IDocument *TaskListPlugin::openTasks(const QString &base, const QString &fileName)
|
2014-06-27 23:42:28 +02:00
|
|
|
{
|
|
|
|
|
foreach (TaskFile *doc, m_openFiles) {
|
2014-12-21 21:54:30 +02:00
|
|
|
if (doc->filePath().toString() == fileName)
|
2014-06-27 23:42:28 +02:00
|
|
|
return doc;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-22 13:51:30 +01:00
|
|
|
auto file = new TaskFile(this);
|
2014-06-27 23:42:28 +02:00
|
|
|
file->setBaseDir(base);
|
|
|
|
|
|
|
|
|
|
QString errorString;
|
2015-06-04 15:21:02 +02:00
|
|
|
if (!file->load(&errorString, fileName)) {
|
2015-02-03 23:56:02 +02:00
|
|
|
QMessageBox::critical(ICore::mainWindow(), tr("File Error"), errorString);
|
2014-06-27 23:42:28 +02:00
|
|
|
delete file;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_openFiles.append(file);
|
|
|
|
|
|
|
|
|
|
// Register with filemanager:
|
2015-02-03 23:56:02 +02:00
|
|
|
DocumentManager::addDocument(file);
|
2014-06-27 23:42:28 +02:00
|
|
|
|
|
|
|
|
return file;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TaskListPlugin::TaskListPlugin()
|
|
|
|
|
{
|
|
|
|
|
m_instance = this;
|
|
|
|
|
}
|
2010-08-27 16:26:16 +02:00
|
|
|
|
2010-08-26 12:27:16 +02:00
|
|
|
bool TaskListPlugin::initialize(const QStringList &arguments, QString *errorMessage)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(arguments)
|
2015-02-04 09:32:46 +01:00
|
|
|
Q_UNUSED(errorMessage)
|
2010-08-26 12:27:16 +02:00
|
|
|
|
2011-10-21 16:39:14 +02:00
|
|
|
//: Category under which tasklist tasks are listed in Issues view
|
2013-08-29 18:25:59 +02:00
|
|
|
TaskHub::addCategory(Constants::TASKLISTTASK_ID, tr("My Tasks"));
|
2010-08-27 16:26:16 +02:00
|
|
|
|
2015-02-04 09:32:46 +01:00
|
|
|
Utils::MimeDatabase::addMimeTypes(QLatin1String(":tasklist/TaskList.mimetypes.xml"));
|
2010-08-26 12:27:16 +02:00
|
|
|
|
2014-06-27 23:42:28 +02:00
|
|
|
m_fileFactory = new IDocumentFactory;
|
|
|
|
|
m_fileFactory->addMimeType(QLatin1String("text/x-tasklist"));
|
|
|
|
|
m_fileFactory->setOpener([this](const QString &fileName) -> IDocument * {
|
2015-02-03 23:56:02 +02:00
|
|
|
Project *project = ProjectTree::currentProject();
|
2014-06-27 23:42:28 +02:00
|
|
|
return this->openTasks(project ? project->projectDirectory().toString() : QString(), fileName);
|
|
|
|
|
});
|
|
|
|
|
|
2013-08-29 18:25:59 +02:00
|
|
|
addAutoReleasedObject(m_fileFactory);
|
|
|
|
|
addAutoReleasedObject(new StopMonitoringHandler);
|
2013-09-23 14:25:32 +02:00
|
|
|
|
|
|
|
|
connect(SessionManager::instance(), SIGNAL(sessionLoaded(QString)),
|
|
|
|
|
this, SLOT(loadDataFromSession()));
|
|
|
|
|
|
2010-08-26 12:27:16 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-24 09:56:27 +02:00
|
|
|
bool TaskListPlugin::loadFile(QString *errorString, const QString &context, const QString &fileName)
|
2010-08-27 16:26:16 +02:00
|
|
|
{
|
|
|
|
|
clearTasks();
|
|
|
|
|
|
2013-09-23 14:25:32 +02:00
|
|
|
bool result = parseTaskFile(errorString, context, fileName);
|
|
|
|
|
if (result) {
|
2013-09-24 09:56:27 +02:00
|
|
|
SessionManager::setValue(QLatin1String(SESSION_BASE_KEY), context);
|
2013-09-23 14:25:32 +02:00
|
|
|
SessionManager::setValue(QLatin1String(SESSION_FILE_KEY), fileName);
|
|
|
|
|
} else {
|
|
|
|
|
stopMonitoring();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
2010-08-27 16:26:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TaskListPlugin::stopMonitoring()
|
|
|
|
|
{
|
2013-09-24 09:56:27 +02:00
|
|
|
SessionManager::setValue(QLatin1String(SESSION_BASE_KEY), QString());
|
2013-09-23 14:25:32 +02:00
|
|
|
SessionManager::setValue(QLatin1String(SESSION_FILE_KEY), QString());
|
|
|
|
|
|
2014-06-27 23:42:28 +02:00
|
|
|
foreach (TaskFile *document, m_instance->m_openFiles)
|
|
|
|
|
document->deleteLater();
|
|
|
|
|
m_instance->m_openFiles.clear();
|
2010-08-27 16:26:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TaskListPlugin::clearTasks()
|
|
|
|
|
{
|
2013-08-29 18:25:59 +02:00
|
|
|
TaskHub::clearTasks(Constants::TASKLISTTASK_ID);
|
2010-08-27 16:26:16 +02:00
|
|
|
}
|
|
|
|
|
|
2013-09-23 14:25:32 +02:00
|
|
|
void TaskListPlugin::loadDataFromSession()
|
|
|
|
|
{
|
|
|
|
|
const QString fileName = SessionManager::value(QLatin1String(SESSION_FILE_KEY)).toString();
|
|
|
|
|
if (fileName.isEmpty())
|
|
|
|
|
return;
|
2014-06-27 23:42:28 +02:00
|
|
|
openTasks(SessionManager::value(QLatin1String(SESSION_BASE_KEY)).toString(), fileName);
|
2013-09-23 14:25:32 +02:00
|
|
|
}
|
|
|
|
|
|
2014-06-27 23:42:28 +02:00
|
|
|
} // namespace Internal
|
2013-08-29 18:25:59 +02:00
|
|
|
} // namespace TaskList
|