2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2010-08-26 12:27:16 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://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
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2010-08-26 12:27:16 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
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>
|
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>
|
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>
|
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;
|
2015-12-06 14:56:36 +02:00
|
|
|
using namespace Utils;
|
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-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
|
|
|
|
2018-02-02 15:00:52 +01:00
|
|
|
class TaskListPluginPrivate
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
QList<TaskFile *> m_openFiles;
|
|
|
|
|
Core::IDocumentFactory m_fileFactory;
|
|
|
|
|
StopMonitoringHandler m_stopMonitoringHandler;
|
|
|
|
|
};
|
|
|
|
|
|
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
|
|
|
|
2019-05-28 13:49:26 +02:00
|
|
|
static bool parseTaskFile(QString *errorString, const FilePath &name)
|
2013-08-29 18:25:59 +02:00
|
|
|
{
|
2015-12-06 14:56:36 +02:00
|
|
|
QFile tf(name.toString());
|
2013-08-29 18:25:59 +02:00
|
|
|
if (!tf.open(QIODevice::ReadOnly)) {
|
|
|
|
|
*errorString = TaskListPlugin::tr("Cannot open task file %1: %2").arg(
|
2015-12-06 14:56:36 +02:00
|
|
|
name.toUserOutput(), tf.errorString());
|
2013-08-29 18:25:59 +02:00
|
|
|
return false;
|
2010-08-27 16:26:16 +02:00
|
|
|
}
|
|
|
|
|
|
2019-05-28 13:49:26 +02:00
|
|
|
const FilePath parentDir = name.parentDir();
|
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);
|
2015-12-06 15:03:58 +02:00
|
|
|
if (fi.isRelative())
|
2019-05-17 12:32:05 +02:00
|
|
|
file = parentDir.pathAppended(file).toString();
|
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
|
|
|
|
2020-01-15 08:56:11 +01:00
|
|
|
TaskHub::addTask(Task(type, description, FilePath::fromUserInput(file), line,
|
|
|
|
|
Constants::TASKLISTTASK_ID));
|
2013-08-29 18:25:59 +02:00
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2010-08-27 16:26:16 +02:00
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
// TaskListPlugin
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
2019-05-28 13:49:26 +02:00
|
|
|
IDocument *TaskListPlugin::openTasks(const FilePath &fileName)
|
2014-06-27 23:42:28 +02:00
|
|
|
{
|
2018-02-02 15:00:52 +01:00
|
|
|
foreach (TaskFile *doc, d->m_openFiles) {
|
2015-12-06 14:56:36 +02:00
|
|
|
if (doc->filePath() == 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
|
|
|
|
|
|
|
|
QString errorString;
|
2015-06-04 15:21:02 +02:00
|
|
|
if (!file->load(&errorString, fileName)) {
|
2020-06-02 09:10:40 +02:00
|
|
|
QMessageBox::critical(ICore::dialogParent(), tr("File Error"), errorString);
|
2014-06-27 23:42:28 +02:00
|
|
|
delete file;
|
2018-02-02 15:00:52 +01:00
|
|
|
return nullptr;
|
2014-06-27 23:42:28 +02:00
|
|
|
}
|
|
|
|
|
|
2018-02-02 15:00:52 +01:00
|
|
|
d->m_openFiles.append(file);
|
2014-06-27 23:42:28 +02:00
|
|
|
|
|
|
|
|
// 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
|
|
|
|
2018-02-02 15:00:52 +01:00
|
|
|
TaskListPlugin::~TaskListPlugin()
|
|
|
|
|
{
|
|
|
|
|
delete d;
|
|
|
|
|
m_instance = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
2018-02-02 15:00:52 +01:00
|
|
|
d = new TaskListPluginPrivate;
|
|
|
|
|
|
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
|
|
|
|
2018-02-02 15:00:52 +01:00
|
|
|
d->m_fileFactory.addMimeType(QLatin1String("text/x-tasklist"));
|
|
|
|
|
d->m_fileFactory.setOpener([this](const QString &fileName) {
|
2019-05-28 13:49:26 +02:00
|
|
|
return openTasks(FilePath::fromString(fileName));
|
2014-06-27 23:42:28 +02:00
|
|
|
});
|
|
|
|
|
|
2015-11-19 16:51:47 +01:00
|
|
|
connect(SessionManager::instance(), &SessionManager::sessionLoaded,
|
|
|
|
|
this, &TaskListPlugin::loadDataFromSession);
|
2013-09-23 14:25:32 +02:00
|
|
|
|
2010-08-26 12:27:16 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-28 13:49:26 +02:00
|
|
|
bool TaskListPlugin::loadFile(QString *errorString, const FilePath &fileName)
|
2010-08-27 16:26:16 +02:00
|
|
|
{
|
|
|
|
|
clearTasks();
|
|
|
|
|
|
2015-12-06 15:03:58 +02:00
|
|
|
bool result = parseTaskFile(errorString, fileName);
|
2020-03-06 15:16:39 +01:00
|
|
|
if (result) {
|
|
|
|
|
if (!SessionManager::isDefaultSession(SessionManager::activeSession()))
|
|
|
|
|
SessionManager::setValue(QLatin1String(SESSION_FILE_KEY), fileName.toString());
|
|
|
|
|
} else {
|
2013-09-23 14:25:32 +02:00
|
|
|
stopMonitoring();
|
2020-03-06 15:16:39 +01:00
|
|
|
}
|
2013-09-23 14:25:32 +02:00
|
|
|
|
|
|
|
|
return result;
|
2010-08-27 16:26:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TaskListPlugin::stopMonitoring()
|
|
|
|
|
{
|
2013-09-23 14:25:32 +02:00
|
|
|
SessionManager::setValue(QLatin1String(SESSION_FILE_KEY), QString());
|
|
|
|
|
|
2018-02-02 15:00:52 +01:00
|
|
|
foreach (TaskFile *document, m_instance->d->m_openFiles)
|
2014-06-27 23:42:28 +02:00
|
|
|
document->deleteLater();
|
2018-02-02 15:00:52 +01:00
|
|
|
m_instance->d->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()
|
|
|
|
|
{
|
2019-05-28 13:49:26 +02:00
|
|
|
const FilePath fileName = FilePath::fromString(
|
2015-12-06 14:56:36 +02:00
|
|
|
SessionManager::value(QLatin1String(SESSION_FILE_KEY)).toString());
|
2015-12-06 15:03:58 +02:00
|
|
|
if (!fileName.isEmpty())
|
|
|
|
|
openTasks(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
|