1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
10 ** GNU Lesser General Public License Usage
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
31 **************************************************************************/
33 #include "tasklistplugin.h"
35 #include "stopmonitoringhandler.h"
37 #include "taskfilefactory.h"
38 #include "tasklistconstants.h"
40 #include <coreplugin/icore.h>
41 #include <coreplugin/mimedatabase.h>
42 #include <extensionsystem/pluginmanager.h>
43 #include <projectexplorer/project.h>
44 #include <projectexplorer/task.h>
45 #include <projectexplorer/taskhub.h>
47 #include <QtCore/QDir>
48 #include <QtCore/QStringList>
49 #include <QtCore/QtPlugin>
53 ProjectExplorer::Task::TaskType typeFrom(const QString &typeName)
55 ProjectExplorer::Task::TaskType type = ProjectExplorer::Task::Unknown;
56 QString tmp = typeName.toLower();
57 if (tmp.startsWith(QLatin1String("warn")))
58 type = ProjectExplorer::Task::Warning;
59 else if (tmp.startsWith(QLatin1String("err")))
60 type = ProjectExplorer::Task::Error;
66 using namespace TaskList;
68 TaskListPlugin *TaskListPlugin::m_instance = 0;
70 // --------------------------------------------------------------------------
71 // TaskListPluginPrivate
72 // --------------------------------------------------------------------------
74 class Internal::TaskListPluginPrivate {
76 bool parseTaskFile(ProjectExplorer::Project *context, const QString &name)
79 if (!tf.open(QIODevice::ReadOnly))
84 QStringList chunks = parseRawLine(tf.readLine());
90 ProjectExplorer::Task::TaskType type = ProjectExplorer::Task::Unknown;
93 if (chunks.count() == 1) {
94 description = chunks.at(0);
95 } else if (chunks.count() == 2) {
96 type = typeFrom(chunks.at(0));
97 description = chunks.at(1);
98 } else if (chunks.count() == 3) {
100 type = typeFrom(chunks.at(1));
101 description = chunks.at(2);
102 } else if (chunks.count() >= 4) {
105 line = chunks.at(1).toInt(&ok);
108 type = typeFrom(chunks.at(2));
109 description = chunks.at(3);
111 if (!file.isEmpty()) {
112 file = QDir::fromNativeSeparators(file);
114 if (fi.isRelative() && context) {
115 QString fullPath = context->projectDirectory() + '/' + file;
116 fi.setFile(fullPath);
117 file = fi.absoluteFilePath();
121 hub->addTask(ProjectExplorer::Task(type, description, file, line, QLatin1String(Constants::TASKLISTTASK_ID)));
126 QStringList parseRawLine(const QByteArray &raw)
129 QString line = QString::fromUtf8(raw.constData());
130 if (line.startsWith(QChar('#')))
133 result = line.split(QChar('\t'));
134 for (int i = 0; i < result.count(); ++i)
135 result[i] = unescape(result.at(i));
140 QString unescape(const QString &input) const
143 for (int i = 0; i < input.count(); ++i) {
144 if (input.at(i) == QChar('\\')) {
145 if (i == input.count() - 1)
147 if (input.at(i + 1) == QChar('n')) {
148 result.append(QChar('\n'));
151 } else if (input.at(i + 1) == QChar('t')) {
152 result.append(QChar('\t'));
155 } else if (input.at(i + 1) == QChar('\\')) {
156 result.append(QChar('\\'));
162 result.append(input.at(i));
167 ProjectExplorer::TaskHub *hub;
168 TaskFileFactory *fileFactory;
171 // --------------------------------------------------------------------------
173 // --------------------------------------------------------------------------
175 TaskListPlugin::TaskListPlugin() :
176 d(new Internal::TaskListPluginPrivate)
181 TaskListPlugin::~TaskListPlugin()
186 TaskListPlugin *TaskListPlugin::instance()
191 bool TaskListPlugin::initialize(const QStringList &arguments, QString *errorMessage)
195 ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
196 d->hub = pm->getObject<ProjectExplorer::TaskHub>();
198 //: Category under which tasklist tasks are listed in build issues view
199 d->hub->addCategory(QLatin1String(Constants::TASKLISTTASK_ID), tr("My Tasks"));
201 Core::ICore *core = Core::ICore::instance();
202 if (!core->mimeDatabase()->addMimeTypes(QLatin1String(":tasklist/TaskList.mimetypes.xml"), errorMessage))
205 d->fileFactory = new Internal::TaskFileFactory(this);
206 addAutoReleasedObject(d->fileFactory);
207 addAutoReleasedObject(new Internal::StopMonitoringHandler);
211 void TaskListPlugin::extensionsInitialized()
214 bool TaskListPlugin::loadFile(ProjectExplorer::Project *context, const QString &fileName)
217 return d->parseTaskFile(context, fileName);
220 bool TaskListPlugin::monitorFile(ProjectExplorer::Project *context, const QString &fileName)
222 return d->fileFactory->open(context, fileName);
225 void TaskListPlugin::stopMonitoring()
227 d->fileFactory->closeAllFiles();
230 void TaskListPlugin::clearTasks()
232 d->hub->clearTasks(QLatin1String(Constants::TASKLISTTASK_ID));
235 Q_EXPORT_PLUGIN(TaskListPlugin)