KFileMetaData

extractorplugin.cpp
1/*
2 SPDX-FileCopyrightText: 2012 Vishesh Handa <me@vhanda.in>
3 SPDX-FileCopyrightText: 2012 Jörg Ehrichs <joerg.ehrichs@gmx.de>
4
5 SPDX-License-Identifier: LGPL-2.1-or-later
6*/
7
8
9#include "extractorplugin.h"
10
11#include "datetimeparser_p.h"
12
13#include <QMimeDatabase>
14
15using namespace KFileMetaData;
16
17ExtractorPlugin::ExtractorPlugin(QObject* parent): QObject(parent)
18{
19}
20
21ExtractorPlugin::~ExtractorPlugin()
22{
23}
24
25//
26// Helper functions
27//
28
30{
31 return KFileMetaData::Parser::dateTimeFromString(dateString);
32}
33
35{
36 QString cleanedString = string;
37 cleanedString = cleanedString.remove(QLatin1Char('{'));
38 cleanedString = cleanedString.remove(QLatin1Char('}'));
39
40 QStringList contactStrings = string.split(QLatin1Char(','), Qt::SkipEmptyParts);
41 if (contactStrings.size() == 1) {
42 contactStrings = string.split(QLatin1Char(';'), Qt::SkipEmptyParts);
43 }
44
45 if (contactStrings.size() == 1) {
46 contactStrings = string.split(QStringLiteral(" ft "), Qt::SkipEmptyParts);
47 }
48
49 if (contactStrings.size() == 1) {
50 contactStrings = string.split(QStringLiteral(" feat. "), Qt::SkipEmptyParts);
51 }
52
53 if (contactStrings.size() == 1) {
54 contactStrings = string.split(QStringLiteral(" feat "), Qt::SkipEmptyParts);
55 }
56
57 QStringList list;
58 list.reserve(contactStrings.count());
59 for (const QString& contactName : std::as_const(contactStrings)) {
60 list << contactName.trimmed();
61 }
62
63 return list;
64}
65
67{
68 const QStringList allTypes = mimetypes();
69 if (allTypes.contains(mimetype)) {
70 return mimetype;
71 }
72
74 auto type = db.mimeTypeForName(mimetype);
75 const QStringList ancestors = type.allAncestors();
76 for (auto ancestor : ancestors) {
77 if (allTypes.contains(ancestor)) {
78 return ancestor;
79 }
80 }
81
82 return QString();
83}
84
85#include "moc_extractorplugin.cpp"
static QStringList contactsFromString(const QString &string)
Tries to split the string into names.
static QDateTime dateTimeFromString(const QString &dateString)
Tries to extract a valid date time from the string provided.
virtual QStringList mimetypes() const =0
Provide a list of MIME types which are supported by this plugin.
QString getSupportedMimeType(const QString &mimetype) const
Return the inherited MIME type which the extractor directly supports.
The KFileMetaData namespace.
qsizetype count() const const
void reserve(qsizetype size)
qsizetype size() const const
QMimeType mimeTypeForName(const QString &nameOrAlias) const const
QString & remove(QChar ch, Qt::CaseSensitivity cs)
bool contains(QLatin1StringView str, Qt::CaseSensitivity cs) const const
SkipEmptyParts
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:15:13 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.