Commit 1320da67 authored by Tobias Hunger's avatar Tobias Hunger
Browse files

Improve TaskList plugin

 * Automatically reload task lists.
 * Add task handler to stop the reloading
 * Add some really simple API for other plugins to use.
parent 7b5b60ff
/**************************************************************************
**
** 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;
}
......@@ -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
/**************************************************************************
**
** 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;
}
/**************************************************************************
**
** 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
......@@ -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();
}
......@@ -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
......
......@@ -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
......
/**************************************************************************
**
** 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
/**************************************************************************
**
** 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
/**************************************************************************
**
** 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;