TaskHub: Add convenience function to add a task and clean up users

Change-Id: I5c76f8af720092d4e47b1a9fa889fb3a7010f21f
Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
This commit is contained in:
hjk
2013-08-29 18:25:59 +02:00
parent fc6ff05472
commit 99f22de6ba
9 changed files with 179 additions and 209 deletions

View File

@@ -150,6 +150,7 @@ enum HandleLocalsFlags
*/ */
using namespace ProjectExplorer; using namespace ProjectExplorer;
using namespace Utils;
namespace Debugger { namespace Debugger {
namespace Internal { namespace Internal {
@@ -315,7 +316,7 @@ static inline bool validMode(DebuggerStartMode sm)
// Accessed by RunControlFactory // Accessed by RunControlFactory
DebuggerEngine *createCdbEngine(const DebuggerStartParameters &sp, QString *errorMessage) DebuggerEngine *createCdbEngine(const DebuggerStartParameters &sp, QString *errorMessage)
{ {
if (Utils::HostOsInfo::isWindowsHost()) { if (HostOsInfo::isWindowsHost()) {
if (validMode(sp.startMode)) if (validMode(sp.startMode))
return new CdbEngine(sp); return new CdbEngine(sp);
*errorMessage = QLatin1String("Internal error: Invalid start parameters passed for thee CDB engine."); *errorMessage = QLatin1String("Internal error: Invalid start parameters passed for thee CDB engine.");
@@ -327,7 +328,7 @@ DebuggerEngine *createCdbEngine(const DebuggerStartParameters &sp, QString *erro
void addCdbOptionPages(QList<Core::IOptionsPage *> *opts) void addCdbOptionPages(QList<Core::IOptionsPage *> *opts)
{ {
if (Utils::HostOsInfo::isWindowsHost()) { if (HostOsInfo::isWindowsHost()) {
opts->push_back(new CdbOptionsPage); opts->push_back(new CdbOptionsPage);
opts->push_back(new CdbPathsPage); opts->push_back(new CdbPathsPage);
} }
@@ -413,7 +414,7 @@ void CdbEngine::init()
} }
// update source path maps from debugger start params // update source path maps from debugger start params
mergeStartParametersSourcePathMap(); mergeStartParametersSourcePathMap();
QTC_ASSERT(m_process.state() != QProcess::Running, Utils::SynchronousProcess::stopProcess(m_process)); QTC_ASSERT(m_process.state() != QProcess::Running, SynchronousProcess::stopProcess(m_process));
} }
CdbEngine::~CdbEngine() CdbEngine::~CdbEngine()
@@ -538,8 +539,8 @@ bool CdbEngine::startConsole(const DebuggerStartParameters &sp, QString *errorMe
{ {
if (debug) if (debug)
qDebug("startConsole %s", qPrintable(sp.executable)); qDebug("startConsole %s", qPrintable(sp.executable));
m_consoleStub.reset(new Utils::ConsoleProcess); m_consoleStub.reset(new ConsoleProcess);
m_consoleStub->setMode(Utils::ConsoleProcess::Suspend); m_consoleStub->setMode(ConsoleProcess::Suspend);
connect(m_consoleStub.data(), SIGNAL(processError(QString)), connect(m_consoleStub.data(), SIGNAL(processError(QString)),
SLOT(consoleStubError(QString))); SLOT(consoleStubError(QString)));
connect(m_consoleStub.data(), SIGNAL(processStarted()), connect(m_consoleStub.data(), SIGNAL(processStarted()),
@@ -701,8 +702,7 @@ bool CdbEngine::launchCDB(const DebuggerStartParameters &sp, QString *errorMessa
case StartExternal: case StartExternal:
if (!nativeArguments.isEmpty()) if (!nativeArguments.isEmpty())
nativeArguments.push_back(blank); nativeArguments.push_back(blank);
Utils::QtcProcess::addArgs(&nativeArguments, QtcProcess::addArgs(&nativeArguments, QStringList(QDir::toNativeSeparators(sp.executable)));
QStringList(QDir::toNativeSeparators(sp.executable)));
break; break;
case AttachToRemoteServer: case AttachToRemoteServer:
break; break;
@@ -941,7 +941,7 @@ void CdbEngine::shutdownEngine()
} else { } else {
// Remote process. No can do, currently // Remote process. No can do, currently
m_notifyEngineShutdownOnTermination = true; m_notifyEngineShutdownOnTermination = true;
Utils::SynchronousProcess::stopProcess(m_process); SynchronousProcess::stopProcess(m_process);
return; return;
} }
// Lost debuggee, debugger should quit anytime now // Lost debuggee, debugger should quit anytime now
@@ -2470,13 +2470,12 @@ void CdbEngine::handleExtensionMessage(char t, int token, const QByteArray &what
&& exception.exceptionCode != winExceptionSetThreadName) { && exception.exceptionCode != winExceptionSetThreadName) {
const Task::TaskType type = const Task::TaskType type =
isFatalWinException(exception.exceptionCode) ? Task::Error : Task::Warning; isFatalWinException(exception.exceptionCode) ? Task::Error : Task::Warning;
const Utils::FileName fileName = exception.file.isEmpty() ? const FileName fileName = exception.file.isEmpty() ?
Utils::FileName() : FileName() :
Utils::FileName::fromUserInput(QString::fromLocal8Bit(exception.file)); FileName::fromUserInput(QString::fromLocal8Bit(exception.file));
const Task task(type, exception.toString(false).trimmed(), TaskHub::addTask(type, exception.toString(false).trimmed(),
fileName, exception.lineNumber, Debugger::Constants::TASK_CATEGORY_DEBUGGER_RUNTIME,
Core::Id(Debugger::Constants::TASK_CATEGORY_DEBUGGER_RUNTIME)); fileName, exception.lineNumber);
TaskHub::addTask(task);
} }
return; return;
} }
@@ -2706,7 +2705,7 @@ static CPlusPlus::Document::Ptr getParsedDocument(const QString &fileName,
if (workingCopy.contains(fileName)) { if (workingCopy.contains(fileName)) {
src = workingCopy.source(fileName); src = workingCopy.source(fileName);
} else { } else {
Utils::FileReader reader; FileReader reader;
if (reader.fetch(fileName)) // ### FIXME error reporting if (reader.fetch(fileName)) // ### FIXME error reporting
src = QString::fromLocal8Bit(reader.data()); // ### FIXME encoding src = QString::fromLocal8Bit(reader.data()); // ### FIXME encoding
} }

View File

@@ -687,9 +687,7 @@ void GdbEngine::handleResponse(const QByteArray &buff)
m_lastWinException = msgWinException(data, &exCode); m_lastWinException = msgWinException(data, &exCode);
showMessage(m_lastWinException, LogMisc); showMessage(m_lastWinException, LogMisc);
const Task::TaskType type = isFatalWinException(exCode) ? Task::Error : Task::Warning; const Task::TaskType type = isFatalWinException(exCode) ? Task::Error : Task::Warning;
const Task task(type, m_lastWinException, Utils::FileName(), 0, TaskHub::addTask(type, m_lastWinException, Constants::TASK_CATEGORY_DEBUGGER_RUNTIME);
Core::Id(Debugger::Constants::TASK_CATEGORY_DEBUGGER_RUNTIME));
TaskHub::addTask(task);
} }
if (data.startsWith("QMLBP:")) { if (data.startsWith("QMLBP:")) {

View File

@@ -34,7 +34,7 @@
using namespace ProjectExplorer; using namespace ProjectExplorer;
TaskHub *TaskHub::m_instance = 0; TaskHub *m_instance = 0;
class TaskMark : public TextEditor::BaseTextMark class TaskMark : public TextEditor::BaseTextMark
{ {
@@ -107,6 +107,11 @@ TaskHub *TaskHub::instance()
return m_instance; return m_instance;
} }
void TaskHub::addTask(Task::TaskType type, const QString &description, Core::Id category, const Utils::FileName &file, int line)
{
addTask(Task(type, description, file, line, category));
}
void TaskHub::addTask(Task task) void TaskHub::addTask(Task task)
{ {
if (task.line != -1 && !task.file.isEmpty()) { if (task.line != -1 && !task.file.isEmpty()) {

View File

@@ -38,7 +38,6 @@
namespace ProjectExplorer { namespace ProjectExplorer {
class ProjectExplorerPlugin; class ProjectExplorerPlugin;
class Task;
class PROJECTEXPLORER_EXPORT TaskHub : public QObject class PROJECTEXPLORER_EXPORT TaskHub : public QObject
{ {
@@ -46,6 +45,12 @@ class PROJECTEXPLORER_EXPORT TaskHub : public QObject
public: public:
static TaskHub *instance(); static TaskHub *instance();
// Convenience overload
static void addTask(Task::TaskType type, const QString &description,
Core::Id category,
const Utils::FileName &file = Utils::FileName(),
int line = -1);
public slots: public slots:
static void addTask(ProjectExplorer::Task task); static void addTask(ProjectExplorer::Task task);
static void clearTasks(Core::Id categoryId = Core::Id()); static void clearTasks(Core::Id categoryId = Core::Id());
@@ -82,8 +87,6 @@ private:
const QIcon m_errorIcon; const QIcon m_errorIcon;
const QIcon m_warningIcon; const QIcon m_warningIcon;
static TaskHub *m_instance;
friend class ProjectExplorerPlugin; friend class ProjectExplorerPlugin;
}; };

View File

@@ -268,7 +268,7 @@ TaskWindow::TaskWindow() : d(new TaskWindowPrivate)
d->m_categoriesButton->setMenu(d->m_categoriesMenu); d->m_categoriesButton->setMenu(d->m_categoriesMenu);
TaskHub *hub = TaskHub::instance(); QObject *hub = TaskHub::instance();
connect(hub, SIGNAL(categoryAdded(Core::Id,QString,bool)), connect(hub, SIGNAL(categoryAdded(Core::Id,QString,bool)),
this, SLOT(addCategory(Core::Id,QString,bool))); this, SLOT(addCategory(Core::Id,QString,bool)));
connect(hub, SIGNAL(taskAdded(ProjectExplorer::Task)), connect(hub, SIGNAL(taskAdded(ProjectExplorer::Task)),

View File

@@ -67,6 +67,8 @@
#include <QFileInfo> #include <QFileInfo>
using namespace Core; using namespace Core;
using namespace ProjectExplorer;
using namespace Utils;
namespace QbsProjectManager { namespace QbsProjectManager {
namespace Internal { namespace Internal {
@@ -145,12 +147,12 @@ QbsManager *QbsProject::projectManager() const
return m_manager; return m_manager;
} }
ProjectExplorer::ProjectNode *QbsProject::rootProjectNode() const ProjectNode *QbsProject::rootProjectNode() const
{ {
return m_rootProjectNode; return m_rootProjectNode;
} }
QStringList QbsProject::files(ProjectExplorer::Project::FilesMode fileMode) const QStringList QbsProject::files(Project::FilesMode fileMode) const
{ {
Q_UNUSED(fileMode); Q_UNUSED(fileMode);
QSet<QString> result; QSet<QString> result;
@@ -212,7 +214,7 @@ qbs::InstallJob *QbsProject::install(const qbs::InstallOptions &opts)
return qbsProject()->installAllProducts(opts); return qbsProject()->installAllProducts(opts);
} }
QString QbsProject::profileForTarget(const ProjectExplorer::Target *t) const QString QbsProject::profileForTarget(const Target *t) const
{ {
return m_manager->profileForKit(t->kit()); return m_manager->profileForKit(t->kit());
} }
@@ -227,11 +229,11 @@ bool QbsProject::hasParseResult() const
return qbsProject(); return qbsProject();
} }
Utils::FileName QbsProject::defaultBuildDirectory() const FileName QbsProject::defaultBuildDirectory() const
{ {
QFileInfo fi(m_fileName); QFileInfo fi(m_fileName);
const QString buildDir = QDir(fi.canonicalPath()).absoluteFilePath(QString::fromLatin1("../%1-build").arg(fi.baseName())); const QString buildDir = QDir(fi.canonicalPath()).absoluteFilePath(QString::fromLatin1("../%1-build").arg(fi.baseName()));
return Utils::FileName::fromString(buildDir); return FileName::fromString(buildDir);
} }
const qbs::Project *QbsProject::qbsProject() const const qbs::Project *QbsProject::qbsProject() const
@@ -279,7 +281,7 @@ void QbsProject::handleQbsParsingDone(bool success)
updateCppCodeModel(m_rootProjectNode->qbsProjectData()); updateCppCodeModel(m_rootProjectNode->qbsProjectData());
updateQmlJsCodeModel(m_rootProjectNode->qbsProjectData()); updateQmlJsCodeModel(m_rootProjectNode->qbsProjectData());
foreach (ProjectExplorer::Target *t, targets()) foreach (Target *t, targets())
t->updateDefaultRunConfigurations(); t->updateDefaultRunConfigurations();
emit fileListChanged(); emit fileListChanged();
@@ -301,22 +303,22 @@ void QbsProject::handleQbsParsingTaskSetup(const QString &description, int maxim
} }
} }
void QbsProject::targetWasAdded(ProjectExplorer::Target *t) void QbsProject::targetWasAdded(Target *t)
{ {
connect(t, SIGNAL(activeBuildConfigurationChanged(ProjectExplorer::BuildConfiguration*)), connect(t, SIGNAL(activeBuildConfigurationChanged(ProjectExplorer::BuildConfiguration*)),
this, SLOT(delayForcedParsing())); this, SLOT(delayForcedParsing()));
connect(t, SIGNAL(buildDirectoryChanged()), this, SLOT(delayForcedParsing())); connect(t, SIGNAL(buildDirectoryChanged()), this, SLOT(delayForcedParsing()));
} }
void QbsProject::changeActiveTarget(ProjectExplorer::Target *t) void QbsProject::changeActiveTarget(Target *t)
{ {
ProjectExplorer::BuildConfiguration *bc = 0; BuildConfiguration *bc = 0;
if (t && t->kit()) if (t && t->kit())
bc = t->activeBuildConfiguration(); bc = t->activeBuildConfiguration();
buildConfigurationChanged(bc); buildConfigurationChanged(bc);
} }
void QbsProject::buildConfigurationChanged(ProjectExplorer::BuildConfiguration *bc) void QbsProject::buildConfigurationChanged(BuildConfiguration *bc)
{ {
if (m_currentBc) if (m_currentBc)
disconnect(m_currentBc, SIGNAL(qbsConfigurationChanged()), this, SLOT(delayParsing())); disconnect(m_currentBc, SIGNAL(qbsConfigurationChanged()), this, SLOT(delayParsing()));
@@ -358,9 +360,9 @@ bool QbsProject::fromMap(const QVariantMap &map)
if (!Project::fromMap(map)) if (!Project::fromMap(map))
return false; return false;
ProjectExplorer::Kit *defaultKit = ProjectExplorer::KitManager::defaultKit(); Kit *defaultKit = KitManager::defaultKit();
if (!activeTarget() && defaultKit) { if (!activeTarget() && defaultKit) {
ProjectExplorer::Target *t = new ProjectExplorer::Target(this, defaultKit); Target *t = new Target(this, defaultKit);
t->updateDefaultBuildConfigurations(); t->updateDefaultBuildConfigurations();
t->updateDefaultDeployConfigurations(); t->updateDefaultDeployConfigurations();
t->updateDefaultRunConfigurations(); t->updateDefaultRunConfigurations();
@@ -373,15 +375,14 @@ bool QbsProject::fromMap(const QVariantMap &map)
void QbsProject::generateErrors(const qbs::ErrorInfo &e) void QbsProject::generateErrors(const qbs::ErrorInfo &e)
{ {
foreach (const qbs::ErrorItem &item, e.items()) foreach (const qbs::ErrorItem &item, e.items())
ProjectExplorer::TaskHub::addTask( TaskHub::addTask(Task::Error, item.description(),
ProjectExplorer::Task(ProjectExplorer::Task::Error, ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM,
item.description(), FileName::fromString(item.codeLocation().fileName()),
Utils::FileName::fromString(item.codeLocation().fileName()), item.codeLocation().line());
item.codeLocation().line(),
ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM));
} }
void QbsProject::parse(const QVariantMap &config, const Utils::Environment &env, const QString &dir) void QbsProject::parse(const QVariantMap &config, const Environment &env, const QString &dir)
{ {
QTC_ASSERT(!dir.isNull(), return); QTC_ASSERT(!dir.isNull(), return);
@@ -441,7 +442,7 @@ void QbsProject::prepareForParsing()
{ {
m_forceParsing = false; m_forceParsing = false;
ProjectExplorer::TaskHub::clearTasks(ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM); TaskHub::clearTasks(ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM);
if (m_qbsUpdateFutureInterface) if (m_qbsUpdateFutureInterface)
m_qbsUpdateFutureInterface->reportCanceled(); m_qbsUpdateFutureInterface->reportCanceled();
delete m_qbsUpdateFutureInterface; delete m_qbsUpdateFutureInterface;
@@ -492,12 +493,12 @@ void QbsProject::updateCppCodeModel(const qbs::ProjectData &prj)
if (!prj.isValid()) if (!prj.isValid())
return; return;
ProjectExplorer::Kit *k = 0; Kit *k = 0;
QtSupport::BaseQtVersion *qtVersion = 0; QtSupport::BaseQtVersion *qtVersion = 0;
if (ProjectExplorer::Target *target = activeTarget()) if (Target *target = activeTarget())
k = target->kit(); k = target->kit();
else else
k = ProjectExplorer::KitManager::defaultKit(); k = KitManager::defaultKit();
qtVersion = QtSupport::QtKitInformation::qtVersion(k); qtVersion = QtSupport::QtKitInformation::qtVersion(k);
CppTools::CppModelManagerInterface *modelmanager = CppTools::CppModelManagerInterface *modelmanager =
@@ -547,7 +548,7 @@ void QbsProject::updateCppCodeModel(const qbs::ProjectData &prj)
QLatin1String(CONFIG_INCLUDEPATHS)); QLatin1String(CONFIG_INCLUDEPATHS));
QStringList grpIncludePaths; QStringList grpIncludePaths;
foreach (const QString &p, list) { foreach (const QString &p, list) {
const QString cp = Utils::FileName::fromUserInput(p).toString(); const QString cp = FileName::fromUserInput(p).toString();
grpIncludePaths.append(cp); grpIncludePaths.append(cp);
} }
@@ -555,7 +556,7 @@ void QbsProject::updateCppCodeModel(const qbs::ProjectData &prj)
QLatin1String(CONFIG_FRAMEWORKPATHS)); QLatin1String(CONFIG_FRAMEWORKPATHS));
QStringList grpFrameworkPaths; QStringList grpFrameworkPaths;
foreach (const QString &p, list) { foreach (const QString &p, list) {
const QString cp = Utils::FileName::fromUserInput(p).toString(); const QString cp = FileName::fromUserInput(p).toString();
grpFrameworkPaths.append(cp); grpFrameworkPaths.append(cp);
} }
@@ -563,10 +564,10 @@ void QbsProject::updateCppCodeModel(const qbs::ProjectData &prj)
QLatin1String(CONFIG_PRECOMPILEDHEADER)).toString(); QLatin1String(CONFIG_PRECOMPILEDHEADER)).toString();
CppTools::ProjectPart::Ptr part(new CppTools::ProjectPart); CppTools::ProjectPart::Ptr part(new CppTools::ProjectPart);
part->evaluateToolchain(ProjectExplorer::ToolChainKitInformation::toolChain(k), part->evaluateToolchain(ToolChainKitInformation::toolChain(k),
cxxFlags, cxxFlags,
cFlags, cFlags,
ProjectExplorer::SysRootKitInformation::sysRoot(k)); SysRootKitInformation::sysRoot(k));
CppTools::ProjectFileAdder adder(part->files); CppTools::ProjectFileAdder adder(part->files);
foreach (const QString &file, grp.allFilePaths()) { foreach (const QString &file, grp.allFilePaths()) {
@@ -618,8 +619,7 @@ void QbsProject::updateQmlJsCodeModel(const qbs::ProjectData &prj)
QString QbsProject::qbsBuildDir() const QString QbsProject::qbsBuildDir() const
{ {
QString buildDir = Utils::Environment::systemEnvironment() QString buildDir = Environment::systemEnvironment().value(QLatin1String("QBS_BUILD_DIR"));
.value(QLatin1String("QBS_BUILD_DIR"));
if (buildDir.isEmpty()) if (buildDir.isEmpty())
buildDir = ICore::resourcePath() + QLatin1String("/qbs"); buildDir = ICore::resourcePath() + QLatin1String("/qbs");
return buildDir; return buildDir;

View File

@@ -43,11 +43,12 @@
#include <QAction> #include <QAction>
#include <QToolBar> #include <QToolBar>
using namespace Qnx; using namespace ProjectExplorer;
using namespace Qnx::Internal;
namespace Qnx {
namespace Internal {
BarDescriptorEditor::BarDescriptorEditor(BarDescriptorEditorWidget *editorWidget) BarDescriptorEditor::BarDescriptorEditor(BarDescriptorEditorWidget *editorWidget)
: Core::IEditor()
{ {
setWidget(editorWidget); setWidget(editorWidget);
@@ -128,14 +129,13 @@ void BarDescriptorEditor::setActivePage(BarDescriptorEditor::EditorPage page)
if (page == Source) { if (page == Source) {
editorWidget->setXmlSource(m_file->xmlSource()); editorWidget->setXmlSource(m_file->xmlSource());
} else if (prevPage == Source) { } else if (prevPage == Source) {
ProjectExplorer::TaskHub::clearTasks(Constants::QNX_TASK_CATEGORY_BARDESCRIPTOR); TaskHub::clearTasks(Constants::QNX_TASK_CATEGORY_BARDESCRIPTOR);
QString errorMsg; QString errorMsg;
int errorLine; int errorLine;
if (!m_file->loadContent(editorWidget->xmlSource(), &errorMsg, &errorLine)) { if (!m_file->loadContent(editorWidget->xmlSource(), &errorMsg, &errorLine)) {
const ProjectExplorer::Task task(ProjectExplorer::Task::Error, errorMsg, Utils::FileName::fromString(m_file->filePath()), TaskHub::addTask(Task::Error, errorMsg, Constants::QNX_TASK_CATEGORY_BARDESCRIPTOR,
errorLine, Constants::QNX_TASK_CATEGORY_BARDESCRIPTOR); Utils::FileName::fromString(m_file->filePath()), errorLine);
ProjectExplorer::TaskHub::addTask(task); TaskHub::requestPopup();
ProjectExplorer::TaskHub::requestPopup();
foreach (QAction *action, m_actionGroup->actions()) foreach (QAction *action, m_actionGroup->actions())
if (action->data().toInt() == Source) if (action->data().toInt() == Source)
@@ -147,3 +147,6 @@ void BarDescriptorEditor::setActivePage(BarDescriptorEditor::EditorPage page)
editorWidget->setCurrentIndex(page); editorWidget->setCurrentIndex(page);
} }
} // namespace Internal
} // namespace Qnx

View File

@@ -45,181 +45,156 @@
#include <QStringList> #include <QStringList>
#include <QtPlugin> #include <QtPlugin>
namespace { using namespace ProjectExplorer;
using namespace TaskList::Internal;
ProjectExplorer::Task::TaskType typeFrom(const QString &typeName) namespace TaskList {
static Task::TaskType typeFrom(const QString &typeName)
{ {
ProjectExplorer::Task::TaskType type = ProjectExplorer::Task::Unknown; Task::TaskType type = Task::Unknown;
QString tmp = typeName.toLower(); QString tmp = typeName.toLower();
if (tmp.startsWith(QLatin1String("warn"))) if (tmp.startsWith(QLatin1String("warn")))
type = ProjectExplorer::Task::Warning; type = Task::Warning;
else if (tmp.startsWith(QLatin1String("err"))) else if (tmp.startsWith(QLatin1String("err")))
type = ProjectExplorer::Task::Error; type = Task::Error;
return type; return type;
} }
} // namespace static QStringList parseRawLine(const QByteArray &raw)
{
using namespace TaskList; QStringList result;
QString line = QString::fromUtf8(raw.constData());
TaskListPlugin *TaskListPlugin::m_instance = 0; if (line.startsWith(QLatin1Char('#')))
// --------------------------------------------------------------------------
// TaskListPluginPrivate
// --------------------------------------------------------------------------
class Internal::TaskListPluginPrivate {
public:
bool parseTaskFile(QString *errorString, ProjectExplorer::Project *context, const QString &name)
{
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;
}
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()) {
file = QDir::fromNativeSeparators(file);
QFileInfo fi(file);
if (fi.isRelative() && context) {
QString fullPath = context->projectDirectory() + QLatin1Char('/') + file;
fi.setFile(fullPath);
file = fi.absoluteFilePath();
}
}
description = unescape(description);
ProjectExplorer::TaskHub::addTask(
ProjectExplorer::Task(type, description,
Utils::FileName::fromUserInput(file), line,
Core::Id(Constants::TASKLISTTASK_ID)));
}
return true;
}
QStringList parseRawLine(const QByteArray &raw)
{
QStringList result;
QString line = QString::fromUtf8(raw.constData());
if (line.startsWith(QLatin1Char('#')))
return result;
return line.split(QLatin1Char('\t'));
}
QString unescape(const QString &input) const
{
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;
continue;
}
continue;
}
result.append(input.at(i));
}
return result; return result;
return line.split(QLatin1Char('\t'));
}
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;
continue;
}
continue;
}
result.append(input.at(i));
}
return result;
}
static bool parseTaskFile(QString *errorString, Project *context, const QString &name)
{
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;
} }
TaskFileFactory *fileFactory; 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);
if (fi.isRelative() && context) {
QString fullPath = context->projectDirectory() + QLatin1Char('/') + file;
fi.setFile(fullPath);
file = fi.absoluteFilePath();
}
}
description = unescape(description);
TaskHub::addTask(type, description, Constants::TASKLISTTASK_ID,
Utils::FileName::fromUserInput(file), line);
}
return true;
}
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
// TaskListPlugin // TaskListPlugin
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
TaskListPlugin::TaskListPlugin() : static TaskFileFactory *m_fileFactory = 0;
d(new Internal::TaskListPluginPrivate)
{
m_instance = this;
}
TaskListPlugin::~TaskListPlugin()
{
delete d;
}
bool TaskListPlugin::initialize(const QStringList &arguments, QString *errorMessage) bool TaskListPlugin::initialize(const QStringList &arguments, QString *errorMessage)
{ {
Q_UNUSED(arguments) Q_UNUSED(arguments)
//: Category under which tasklist tasks are listed in Issues view //: Category under which tasklist tasks are listed in Issues view
ProjectExplorer::TaskHub::addCategory(Core::Id(Constants::TASKLISTTASK_ID), tr("My Tasks")); TaskHub::addCategory(Constants::TASKLISTTASK_ID, tr("My Tasks"));
if (!Core::ICore::mimeDatabase()->addMimeTypes(QLatin1String(":tasklist/TaskList.mimetypes.xml"), errorMessage)) if (!Core::ICore::mimeDatabase()->addMimeTypes(QLatin1String(":tasklist/TaskList.mimetypes.xml"), errorMessage))
return false; return false;
d->fileFactory = new Internal::TaskFileFactory(this); m_fileFactory = new TaskFileFactory(this);
addAutoReleasedObject(d->fileFactory); addAutoReleasedObject(m_fileFactory);
addAutoReleasedObject(new Internal::StopMonitoringHandler); addAutoReleasedObject(new StopMonitoringHandler);
return true; return true;
} }
void TaskListPlugin::extensionsInitialized() bool TaskListPlugin::loadFile(QString *errorString, Project *context, const QString &fileName)
{ }
bool TaskListPlugin::loadFile(QString *errorString, ProjectExplorer::Project *context, const QString &fileName)
{ {
clearTasks(); clearTasks();
return m_instance->d->parseTaskFile(errorString, context, fileName); return parseTaskFile(errorString, context, fileName);
} }
bool TaskListPlugin::monitorFile(ProjectExplorer::Project *context, const QString &fileName) bool TaskListPlugin::monitorFile(Project *context, const QString &fileName)
{ {
return m_instance->d->fileFactory->open(context, fileName); return m_fileFactory->open(context, fileName);
} }
void TaskListPlugin::stopMonitoring() void TaskListPlugin::stopMonitoring()
{ {
m_instance->d->fileFactory->closeAllFiles(); m_fileFactory->closeAllFiles();
} }
void TaskListPlugin::clearTasks() void TaskListPlugin::clearTasks()
{ {
ProjectExplorer::TaskHub::clearTasks(Core::Id(Constants::TASKLISTTASK_ID)); TaskHub::clearTasks(Constants::TASKLISTTASK_ID);
} }
} // namespace TaskList
Q_EXPORT_PLUGIN(TaskListPlugin) Q_EXPORT_PLUGIN(TaskListPlugin)

View File

@@ -32,14 +32,9 @@
#include <extensionsystem/iplugin.h> #include <extensionsystem/iplugin.h>
namespace ProjectExplorer { namespace ProjectExplorer { class Project; }
class Project;
} // namespace ProjectExplorer
namespace TaskList { namespace TaskList {
namespace Internal {
class TaskListPluginPrivate;
} // namespace
class TaskListPlugin : public ExtensionSystem::IPlugin class TaskListPlugin : public ExtensionSystem::IPlugin
{ {
@@ -47,22 +42,14 @@ class TaskListPlugin : public ExtensionSystem::IPlugin
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "TaskList.json") Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "TaskList.json")
public: public:
TaskListPlugin();
~TaskListPlugin();
bool initialize(const QStringList &arguments, QString *errorMessage); bool initialize(const QStringList &arguments, QString *errorMessage);
void extensionsInitialized() {}
void extensionsInitialized();
static bool loadFile(QString *errorString, ProjectExplorer::Project *context, const QString &fileName); static bool loadFile(QString *errorString, ProjectExplorer::Project *context, const QString &fileName);
static bool monitorFile(ProjectExplorer::Project *context, const QString &fileName); static bool monitorFile(ProjectExplorer::Project *context, const QString &fileName);
static void stopMonitoring(); static void stopMonitoring();
static void clearTasks(); static void clearTasks();
private:
static TaskListPlugin *m_instance;
Internal::TaskListPluginPrivate * const d;
}; };
} // namespace TaskList } // namespace TaskList