diff --git a/src/plugins/tasklist/stopmonitoringhandler.cpp b/src/plugins/tasklist/stopmonitoringhandler.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5aad51cb21f8acd91faf7579405642e6ccabd4ff --- /dev/null +++ b/src/plugins/tasklist/stopmonitoringhandler.cpp @@ -0,0 +1,69 @@ +/************************************************************************** +** +** 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 "stopmonitoringhandler.h" + +#include "tasklistconstants.h" +#include "tasklistplugin.h" + +#include <projectexplorer/task.h> + +#include <QtGui/QAction> + +using namespace TaskList; +using namespace TaskList::Internal; + +// -------------------------------------------------------------------------- +// StopMonitoringHandler +// -------------------------------------------------------------------------- + +StopMonitoringHandler::StopMonitoringHandler() : + ProjectExplorer::ITaskHandler(QLatin1String("TaskList.StopMonitoringHandler")) +{ } + +StopMonitoringHandler::~StopMonitoringHandler() +{ } + +bool StopMonitoringHandler::canHandle(const ProjectExplorer::Task &task) +{ + return task.category == QLatin1String(Constants::TASKLISTTASK_ID); +} + +void StopMonitoringHandler::handle(const ProjectExplorer::Task &task) +{ + Q_ASSERT(canHandle(task)); + TaskList::TaskListPlugin::instance()->stopMonitoring(); +} + +QAction *StopMonitoringHandler::createAction(QObject *parent) +{ + QAction *stopMonitoringAction = new QAction(tr("Stop monitoring"), parent); + stopMonitoringAction->setToolTip(tr("Stop monitoring task files.")); + return stopMonitoringAction; +} diff --git a/src/plugins/tasklist/tasklistmanager.h b/src/plugins/tasklist/stopmonitoringhandler.h similarity index 68% rename from src/plugins/tasklist/tasklistmanager.h rename to src/plugins/tasklist/stopmonitoringhandler.h index c51f698a910245993d3ff84d0636fe7566dad026..32c19783f99c68f9f837bed984382f548d9d8f44 100644 --- a/src/plugins/tasklist/tasklistmanager.h +++ b/src/plugins/tasklist/stopmonitoringhandler.h @@ -27,40 +27,26 @@ ** **************************************************************************/ -#ifndef TASKLISTMANAGER_H -#define TASKLISTMANAGER_H +#ifndef STOPMONITORINGHANDLER_H +#define STOPMONITORINGHANDLER_H -#include <QtCore/QByteArray> -#include <QtCore/QObject> -#include <QtCore/QStringList> - -namespace ProjectExplorer { -class TaskHub; -} // namespace ProjectExplorer +#include <projectexplorer/itaskhandler.h> namespace TaskList { namespace Internal { -class TaskListManager : public QObject +class StopMonitoringHandler : public ProjectExplorer::ITaskHandler { - Q_OBJECT - public: - TaskListManager(QObject *parent = 0); - ~TaskListManager(); - -public slots: - void setTaskFile(const QString &name); - -private: - void parseTaskFile(const QString &name); - QStringList parseRawLine(const QByteArray &raw); - QString unescape(const QString &input) const; + StopMonitoringHandler(); + ~StopMonitoringHandler(); - ProjectExplorer::TaskHub *m_hub; + bool canHandle(const ProjectExplorer::Task &); + void handle(const ProjectExplorer::Task &); + QAction *createAction(QObject *parent = 0); }; } // namespace Internal } // namespace TaskList -#endif // TASKLISTMANAGER_H +#endif // STOPMONITORINGHANDLER_H diff --git a/src/plugins/tasklist/taskfile.cpp b/src/plugins/tasklist/taskfile.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2e8d53cbb5ec5a2ea0870979c4301683fafa561f --- /dev/null +++ b/src/plugins/tasklist/taskfile.cpp @@ -0,0 +1,128 @@ +/************************************************************************** +** +** 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 "taskfile.h" + +#include "tasklistplugin.h" + +using namespace TaskList; +using namespace TaskList::Internal; + +// -------------------------------------------------------------------------- +// TaskFile +// -------------------------------------------------------------------------- + +TaskFile::TaskFile(QObject *parent) : Core::IFile(parent), + m_context(0) +{ } + +TaskFile::~TaskFile() +{ } + +bool TaskFile::save(const QString &fileName) +{ + Q_UNUSED(fileName); + return false; +} + +QString TaskFile::fileName() const +{ + return m_fileName; +} + +QString TaskFile::defaultPath() const +{ + return QString(); +} + +QString TaskFile::suggestedFileName() const +{ + return QString(); +} + +QString TaskFile::mimeType() const +{ + return QString(); +} + +bool TaskFile::isModified() const +{ + return false; +} + +bool TaskFile::isReadOnly() const +{ + return true; +} + +bool TaskFile::isSaveAsAllowed() const +{ + return false; +} + +Core::IFile::ReloadBehavior TaskFile::reloadBehavior(ChangeTrigger state, ChangeType type) const +{ + Q_UNUSED(state); + if (type != TypePermissions) + return BehaviorSilent; + return BehaviorAsk; +} + +void TaskFile::reload(ReloadFlag flag, ChangeType type) +{ + Q_UNUSED(flag); + + if (type == TypePermissions) + return; + open(m_fileName); + if (type == TypeRemoved) + deleteLater(); +} + +void TaskFile::rename(const QString &newName) +{ + Q_UNUSED(newName); +} + +bool TaskFile::open(const QString &fileName) +{ + m_fileName = fileName; + return TaskList::TaskListPlugin::instance()->loadFile(m_context, m_fileName); +} + +ProjectExplorer::Project *TaskFile::context() const +{ + return m_context; +} + +void TaskFile::setContext(ProjectExplorer::Project *context) +{ + m_context = context; +} + diff --git a/src/plugins/tasklist/taskfile.h b/src/plugins/tasklist/taskfile.h new file mode 100644 index 0000000000000000000000000000000000000000..a79b75ce56e2ccee2aaffde965405870bc8eb543 --- /dev/null +++ b/src/plugins/tasklist/taskfile.h @@ -0,0 +1,76 @@ +/************************************************************************** +** +** 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. +** +**************************************************************************/ + +#ifndef TASKFILE_H +#define TASKFILE_H + +#include <coreplugin/ifile.h> + +namespace ProjectExplorer { +class Project; +} // namespace ProjectExplorer + +namespace TaskList { +namespace Internal { + +class TaskFile : public Core::IFile +{ +public: + TaskFile(QObject *parent); + ~TaskFile(); + + bool save(const QString &fileName = QString()); + QString fileName() const; + + QString defaultPath() const; + QString suggestedFileName() const; + QString mimeType() const; + + bool isModified() const; + bool isReadOnly() const; + bool isSaveAsAllowed() const; + + ReloadBehavior reloadBehavior(ChangeTrigger state, ChangeType type) const; + void reload(ReloadFlag flag, ChangeType type); + void rename(const QString &newName); + + bool open(const QString &fileName); + + ProjectExplorer::Project *context() const; + void setContext(ProjectExplorer::Project *context); + +private: + QString m_fileName; + ProjectExplorer::Project *m_context; +}; + +} // namespace Internal +} // namespace TaskList + +#endif // TASKFILE_H diff --git a/src/plugins/tasklist/taskfilefactory.cpp b/src/plugins/tasklist/taskfilefactory.cpp index 8665afd8b050483554389ab94f59bf43a03ddcc5..fc43880071c71032a36b5b046a583115bd81f0b5 100644 --- a/src/plugins/tasklist/taskfilefactory.cpp +++ b/src/plugins/tasklist/taskfilefactory.cpp @@ -29,13 +29,20 @@ #include "taskfilefactory.h" -#include "tasklistmanager.h" +#include "taskfile.h" + +#include <projectexplorer/projectexplorer.h> +#include <coreplugin/icore.h> +#include <coreplugin/filemanager.h> using namespace TaskList::Internal; -TaskFileFactory::TaskFileFactory(TaskListManager *manager) : - Core::IFileFactory(0), - m_manager(manager), +// -------------------------------------------------------------------------- +// TaskFileFactory +// -------------------------------------------------------------------------- + +TaskFileFactory::TaskFileFactory(QObject * parent) : + Core::IFileFactory(parent), m_mimeTypes(QStringList() << QLatin1String("text/x-tasklist")) { } @@ -59,7 +66,32 @@ QString TaskFileFactory::displayName() const Core::IFile *TaskFileFactory::open(const QString &fileName) { - Core::IFile *file = 0; - m_manager->setTaskFile(fileName); + ProjectExplorer::Project * context = + ProjectExplorer::ProjectExplorerPlugin::instance()->currentProject(); + return open(context, fileName); +} + +Core::IFile *TaskFileFactory::open(ProjectExplorer::Project *context, const QString &fileName) +{ + TaskFile *file = new TaskFile(this); + file->setContext(context); + + if (!file->open(fileName)) { + delete file; + return 0; + } + + m_openFiles.append(file); + + // Register with filemanager: + Core::ICore::instance()->fileManager()->addFile(file); + return file; } + +void TaskFileFactory::closeAllFiles() +{ + foreach(Core::IFile *file, m_openFiles) + file->deleteLater(); + m_openFiles.clear(); +} diff --git a/src/plugins/tasklist/taskfilefactory.h b/src/plugins/tasklist/taskfilefactory.h index 93607324098ef263bd667d61df31d633c9be7ada..3c650e544651d047c7092ce684757e84c6e05e36 100644 --- a/src/plugins/tasklist/taskfilefactory.h +++ b/src/plugins/tasklist/taskfilefactory.h @@ -32,18 +32,22 @@ #include <coreplugin/ifilefactory.h> +#include <coreplugin/ifile.h> + #include <QtCore/QStringList> +namespace ProjectExplorer { +class Project; +} // namespace ProjectExplorer + namespace TaskList { namespace Internal { -class TaskListManager; - class TaskFileFactory : public Core::IFileFactory { Q_OBJECT public: - TaskFileFactory(TaskListManager *manager); + TaskFileFactory(QObject *parent = 0); ~TaskFileFactory(); QStringList mimeTypes() const; @@ -52,10 +56,13 @@ public: QString displayName() const; Core::IFile *open(const QString &fileName); + Core::IFile *open(ProjectExplorer::Project *context, const QString &fileName); + + void closeAllFiles(); private: - TaskListManager * m_manager; QStringList m_mimeTypes; + QList<Core::IFile *> m_openFiles; }; } // namespace Internal diff --git a/src/plugins/tasklist/tasklist.pro b/src/plugins/tasklist/tasklist.pro index 6aaa721ae76b4c7f7b656d646fdf221be2f6ac44..388800a0003c44570c994cfece95ebb7eb6823bb 100644 --- a/src/plugins/tasklist/tasklist.pro +++ b/src/plugins/tasklist/tasklist.pro @@ -6,12 +6,16 @@ include(../../plugins/coreplugin/coreplugin.pri) include(../../plugins/projectexplorer/projectexplorer.pri) HEADERS += tasklistplugin.h \ + tasklist_export.h \ + tasklistconstants.h \ + stopmonitoringhandler.h \ + taskfile.h \ taskfilefactory.h \ - tasklistmanager.h SOURCES += tasklistplugin.cpp \ + stopmonitoringhandler.cpp \ + taskfile.cpp \ taskfilefactory.cpp \ - tasklistmanager.cpp RESOURCES += tasklist.qrc diff --git a/src/plugins/tasklist/tasklist_export.h b/src/plugins/tasklist/tasklist_export.h new file mode 100644 index 0000000000000000000000000000000000000000..4b3b06c8ad38c16429c1f879dc497a157a2cdaa1 --- /dev/null +++ b/src/plugins/tasklist/tasklist_export.h @@ -0,0 +1,41 @@ +/************************************************************************** +** +** 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. +** +**************************************************************************/ + +#ifndef TASKLIST_TASKLIST_EXPORT_H +#define TASKLIST_TASKLIST_EXPORT_H + +#include <QtCore/qglobal.h> + +#if defined(TASKLIST_LIBRARY) +# define TASKLIST_EXPORT Q_DECL_EXPORT +#else +# define TASKLIST_EXPORT Q_DECL_IMPORT +#endif + +#endif // TASKLIST_TASKLIST_EXPORT_H diff --git a/src/plugins/tasklist/tasklistconstants.h b/src/plugins/tasklist/tasklistconstants.h new file mode 100644 index 0000000000000000000000000000000000000000..7141a230789631b338e150746492f7103a8965c3 --- /dev/null +++ b/src/plugins/tasklist/tasklistconstants.h @@ -0,0 +1,41 @@ +/************************************************************************** +** +** 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. +** +**************************************************************************/ + +#ifndef TASKLIST_TASKLISTCONSTANTS_H +#define TASKLIST_TASKLISTCONSTANTS_H + +namespace TaskList { +namespace Constants { + +const char * const TASKLISTTASK_ID = "TaskList.TaskListTaskId"; + +} // namespace Constants +} // namespace TaskList + +#endif // TASKLIST_TASKLISTCONSTANTS_H diff --git a/src/plugins/tasklist/tasklistmanager.cpp b/src/plugins/tasklist/tasklistmanager.cpp deleted file mode 100644 index ccccefe6d6e9202e4c10bc02d0f84656256f307d..0000000000000000000000000000000000000000 --- a/src/plugins/tasklist/tasklistmanager.cpp +++ /dev/null @@ -1,150 +0,0 @@ -/************************************************************************** -** -** 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 "tasklistmanager.h" - -#include <extensionsystem/pluginmanager.h> -#include <projectexplorer/taskhub.h> - -#include <QtCore/QDebug> -#include <QtCore/QFile> - -namespace { -const char * const TASKLIST_ID = "TaskList.ListId"; - -ProjectExplorer::Task::TaskType typeFrom(const QString &taskType) -{ - QString type = taskType.toLower(); - if (type.startsWith("warn")) - return ProjectExplorer::Task::Warning; - else if (type.startsWith("err")) - return ProjectExplorer::Task::Error; - return ProjectExplorer::Task::Unknown; -} - -} // namespace - -using namespace TaskList::Internal; - -TaskListManager::TaskListManager(QObject *parent) : - QObject(parent), - m_hub(0) -{ - ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); - m_hub = pm->getObject<ProjectExplorer::TaskHub>(); - m_hub->addCategory(QLatin1String(TASKLIST_ID), tr("My tasks")); -} - -TaskListManager::~TaskListManager() -{ } - -void TaskListManager::setTaskFile(const QString &name) -{ - m_hub->clearTasks(QLatin1String(TASKLIST_ID)); - parseTaskFile(name); -} - -void TaskListManager::parseTaskFile(const QString &name) -{ - QFile tf(name); - if (!tf.open(QIODevice::ReadOnly)) - return; - 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); - } - m_hub->addTask(ProjectExplorer::Task(type, description, file, line, QLatin1String(TASKLIST_ID))); - } -} - -QStringList TaskListManager::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 TaskListManager::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; -} diff --git a/src/plugins/tasklist/tasklistplugin.cpp b/src/plugins/tasklist/tasklistplugin.cpp index 97bb43b43a09d08099fef0a7b1fd702ba38d9e14..950ae96639c75a9fbbabc36575d6a07483ec6de4 100644 --- a/src/plugins/tasklist/tasklistplugin.cpp +++ b/src/plugins/tasklist/tasklistplugin.cpp @@ -29,38 +29,202 @@ #include "tasklistplugin.h" +#include "stopmonitoringhandler.h" +#include "taskfile.h" #include "taskfilefactory.h" -#include "tasklistmanager.h" +#include "tasklistconstants.h" #include <coreplugin/icore.h> #include <coreplugin/mimedatabase.h> +#include <extensionsystem/pluginmanager.h> +#include <projectexplorer/project.h> +#include <projectexplorer/task.h> +#include <projectexplorer/taskhub.h> -#include <QtCore/QDebug> #include <QtCore/QStringList> #include <QtCore/QtPlugin> -using namespace TaskList::Internal; +namespace { -TaskListPlugin::TaskListPlugin() -{ } +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; +} TaskListPlugin::~TaskListPlugin() -{ } +{ + delete d; +} + +TaskListPlugin *TaskListPlugin::instance() +{ + return m_instance; +} bool TaskListPlugin::initialize(const QStringList &arguments, QString *errorMessage) { Q_UNUSED(arguments) + ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); + d->hub = pm->getObject<ProjectExplorer::TaskHub>(); + + //: Category under which tasklist tasks are listed in build issues view + d->hub->addCategory(QLatin1String(Constants::TASKLISTTASK_ID), tr("My tasks")); + Core::ICore *core = Core::ICore::instance(); if (!core->mimeDatabase()->addMimeTypes(QLatin1String(":tasklist/TaskList.mimetypes.xml"), errorMessage)) return false; - TaskListManager * manager = new TaskListManager(this); - addAutoReleasedObject(new TaskFileFactory(manager)); + d->fileFactory = new Internal::TaskFileFactory(this); + addAutoReleasedObject(d->fileFactory); + addAutoReleasedObject(new Internal::StopMonitoringHandler); return true; } void TaskListPlugin::extensionsInitialized() { } +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)); +} + Q_EXPORT_PLUGIN(TaskListPlugin) diff --git a/src/plugins/tasklist/tasklistplugin.h b/src/plugins/tasklist/tasklistplugin.h index d28e59c821a5e617eb5b97fb8fd76a8c1884e879..76e1de86da9f8100109d51d56fd252930505f358 100644 --- a/src/plugins/tasklist/tasklistplugin.h +++ b/src/plugins/tasklist/tasklistplugin.h @@ -32,8 +32,14 @@ #include <extensionsystem/iplugin.h> +namespace ProjectExplorer { +class Project; +} // namespace ProjectExplorer + namespace TaskList { namespace Internal { +class TaskListPluginPrivate; +} // namespace class TaskListPlugin : public ExtensionSystem::IPlugin { @@ -43,12 +49,23 @@ public: TaskListPlugin(); ~TaskListPlugin(); + static TaskListPlugin *instance(); + bool initialize(const QStringList &arguments, QString *errorMessage); void extensionsInitialized(); + + bool loadFile(ProjectExplorer::Project *context, const QString &fileName); + bool monitorFile(ProjectExplorer::Project *context, const QString &fileName); + + void stopMonitoring(); + void clearTasks(); + +private: + static TaskListPlugin *m_instance; + Internal::TaskListPluginPrivate * const d; }; -} // namespace Internal } // namespace TaskList #endif // TASKLISTPLUGIN_H