~bzoltan/kubuntu-packaging/decouple_cmake_plugin

« back to all changes in this revision

Viewing changes to src/plugins/texteditor/generichighlighter/manager.cpp

  • Committer: Timo Jyrinki
  • Date: 2013-11-15 12:25:23 UTC
  • mfrom: (1.1.28)
  • Revision ID: timo.jyrinki@canonical.com-20131115122523-i2kyamsu4gs2mu1m
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
#include "highlighterexception.h"
34
34
#include "definitiondownloader.h"
35
35
#include "highlightersettings.h"
36
 
#include "plaintexteditorfactory.h"
37
 
#include "texteditorconstants.h"
38
 
#include "texteditorplugin.h"
39
 
#include "texteditorsettings.h"
 
36
#include <texteditor/plaintexteditorfactory.h>
 
37
#include <texteditor/texteditorconstants.h>
 
38
#include <texteditor/texteditorplugin.h>
 
39
#include <texteditor/texteditorsettings.h>
40
40
 
41
41
#include <coreplugin/icore.h>
42
42
#include <coreplugin/progressmanager/progressmanager.h>
64
64
#include <QNetworkRequest>
65
65
#include <QNetworkReply>
66
66
 
67
 
using namespace TextEditor;
68
 
using namespace Internal;
 
67
using namespace Core;
 
68
 
 
69
namespace TextEditor {
 
70
namespace Internal {
69
71
 
70
72
const char kPriority[] = "priority";
71
73
const char kName[] = "name";
157
159
    return m_isBuildingDefinition.contains(id);
158
160
}
159
161
 
160
 
namespace TextEditor {
161
 
namespace Internal {
162
 
 
163
162
class ManagerProcessor : public QObject
164
163
{
165
164
    Q_OBJECT
166
165
public:
167
166
    ManagerProcessor();
168
167
    void process(QFutureInterface<QPair<Manager::RegisterData,
169
 
                                        QList<Core::MimeType> > > &future);
 
168
                                        QList<MimeType> > > &future);
170
169
 
171
170
    QStringList m_definitionsPaths;
172
171
    QSet<QString> m_knownMimeTypes;
173
172
    QSet<QString> m_knownSuffixes;
174
 
    QHash<QString, Core::MimeType> m_userModified;
 
173
    QHash<QString, MimeType> m_userModified;
175
174
    static const int kMaxProgress;
176
175
};
177
176
 
184
183
const int ManagerProcessor::kMaxProgress = 200;
185
184
 
186
185
ManagerProcessor::ManagerProcessor()
187
 
    : m_knownSuffixes(QSet<QString>::fromList(Core::ICore::mimeDatabase()->suffixes()))
 
186
    : m_knownSuffixes(QSet<QString>::fromList(MimeDatabase::suffixes()))
188
187
{
189
 
    const HighlighterSettings &settings = TextEditorSettings::instance()->highlighterSettings();
 
188
    const HighlighterSettings &settings = TextEditorSettings::highlighterSettings();
190
189
    m_definitionsPaths.append(settings.definitionFilesPath());
191
190
    if (settings.useFallbackLocation())
192
191
        m_definitionsPaths.append(settings.fallbackDefinitionFilesPath());
193
192
 
194
 
    Core::MimeDatabase *mimeDatabase = Core::ICore::mimeDatabase();
195
 
    foreach (const Core::MimeType &userMimeType, mimeDatabase->readUserModifiedMimeTypes())
 
193
    foreach (const MimeType &userMimeType, MimeDatabase::readUserModifiedMimeTypes())
196
194
        m_userModified.insert(userMimeType.type(), userMimeType);
197
 
    foreach (const Core::MimeType &mimeType, mimeDatabase->mimeTypes())
 
195
    foreach (const MimeType &mimeType, MimeDatabase::mimeTypes())
198
196
        m_knownMimeTypes.insert(mimeType.type());
199
197
}
200
198
 
201
199
void ManagerProcessor::process(QFutureInterface<QPair<Manager::RegisterData,
202
 
                                                      QList<Core::MimeType> > > &future)
 
200
                                                      QList<MimeType> > > &future)
203
201
{
204
202
    future.setProgressRange(0, kMaxProgress);
205
203
 
215
213
    // is a change in the generic highlighter settings.
216
214
 
217
215
    Manager::RegisterData data;
218
 
    QList<Core::MimeType> newMimeTypes;
 
216
    QList<MimeType> newMimeTypes;
219
217
 
220
218
    foreach (const QString &path, m_definitionsPaths) {
221
219
        if (path.isEmpty())
253
251
 
254
252
            // A definition can specify multiple MIME types and file extensions/patterns,
255
253
            // but all on a single string. So associate all patterns with all MIME types.
256
 
            QList<Core::MimeGlobPattern> globPatterns;
 
254
            QList<MimeGlobPattern> globPatterns;
257
255
            foreach (const QString &type, metaData->mimeTypes) {
258
256
                if (data.m_idByMimeType.contains(type))
259
257
                    continue;
262
260
                if (!m_knownMimeTypes.contains(type)) {
263
261
                    m_knownMimeTypes.insert(type);
264
262
 
265
 
                    Core::MimeType mimeType;
 
263
                    MimeType mimeType;
266
264
                    mimeType.setType(type);
267
265
                    mimeType.setSubClassesOf(textPlain);
268
266
                    mimeType.setComment(metaData->name);
270
268
                    // If there's a user modification for this mime type, we want to use the
271
269
                    // modified patterns and rule-based matchers. If not, just consider what
272
270
                    // is specified in the definition file.
273
 
                    QHash<QString, Core::MimeType>::const_iterator it =
 
271
                    QHash<QString, MimeType>::const_iterator it =
274
272
                        m_userModified.find(mimeType.type());
275
273
                    if (it == m_userModified.end()) {
276
274
                        if (globPatterns.isEmpty()) {
283
281
                                    else
284
282
                                        continue;
285
283
                                }
286
 
                                globPatterns.append(Core::MimeGlobPattern(pattern, 50));
 
284
                                globPatterns.append(MimeGlobPattern(pattern, 50));
287
285
                            }
288
286
                        }
289
287
                        mimeType.setGlobPatterns(globPatterns);
301
299
    future.reportResult(qMakePair(data, newMimeTypes));
302
300
}
303
301
 
304
 
} // Internal
305
 
} // TextEditor
306
 
 
307
 
 
308
302
void Manager::registerMimeTypes()
309
303
{
310
304
    if (!m_registeringWatcher.isRunning()) {
311
305
        clear();
312
306
 
313
307
        ManagerProcessor *processor = new ManagerProcessor;
314
 
        QFuture<QPair<RegisterData, QList<Core::MimeType> > > future =
 
308
        QFuture<QPair<RegisterData, QList<MimeType> > > future =
315
309
            QtConcurrent::run(&ManagerProcessor::process, processor);
316
310
        connect(&m_registeringWatcher, SIGNAL(finished()), processor, SLOT(deleteLater()));
317
311
        m_registeringWatcher.setFuture(future);
318
312
 
319
 
        Core::ICore::progressManager()->addTask(future,
320
 
                                                            tr("Registering definitions"),
321
 
                                                            QLatin1String(Constants::TASK_REGISTER_DEFINITIONS));
 
313
        ProgressManager::addTask(future, tr("Registering definitions"), "TextEditor.Task.Register");
322
314
    } else {
323
315
        m_hasQueuedRegistration = true;
324
316
        m_registeringWatcher.cancel();
331
323
        m_hasQueuedRegistration = false;
332
324
        registerMimeTypes();
333
325
    } else if (!m_registeringWatcher.isCanceled()) {
334
 
        const QPair<RegisterData, QList<Core::MimeType> > &result = m_registeringWatcher.result();
 
326
        const QPair<RegisterData, QList<MimeType> > &result = m_registeringWatcher.result();
335
327
        m_register = result.first;
336
328
 
337
329
        PlainTextEditorFactory *factory = TextEditorPlugin::instance()->editorFactory();
338
330
        const QSet<QString> &inFactory = factory->mimeTypes().toSet();
339
 
        foreach (const Core::MimeType &mimeType, result.second) {
340
 
            Core::ICore::mimeDatabase()->addMimeType(mimeType);
 
331
        foreach (const MimeType &mimeType, result.second) {
 
332
            MimeDatabase::addMimeType(mimeType);
341
333
            if (!inFactory.contains(mimeType.type()))
342
334
                factory->addMimeType(mimeType.type());
343
335
        }
451
443
    m_isDownloadingDefinitionsSpec = true;
452
444
    QFuture<void> future = QtConcurrent::map(m_downloaders, DownloaderStarter());
453
445
    m_downloadWatcher.setFuture(future);
454
 
    Core::ICore::progressManager()->addTask(future,
455
 
                                                        tr("Downloading definitions"),
456
 
                                                        QLatin1String(Constants::TASK_DOWNLOAD_DEFINITIONS));
 
446
    ProgressManager::addTask(future, tr("Downloading definitions"), "TextEditor.Task.Download");
457
447
}
458
448
 
459
449
void Manager::downloadDefinitionsFinished()
497
487
    m_definitions.clear();
498
488
}
499
489
 
 
490
} // namespace Internal
 
491
} // namespace TextEditor
 
492
 
500
493
#include "manager.moc"