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 | |
15 | using namespace KFileMetaData; |
16 | |
17 | ExtractorPlugin::ExtractorPlugin(QObject* parent): QObject(parent) |
18 | { |
19 | } |
20 | |
21 | ExtractorPlugin::~ExtractorPlugin() |
22 | { |
23 | } |
24 | |
25 | // |
26 | // Helper functions |
27 | // |
28 | |
29 | QDateTime ExtractorPlugin::dateTimeFromString(const QString& dateString) |
30 | { |
31 | return KFileMetaData::Parser::dateTimeFromString(dateString); |
32 | } |
33 | |
34 | QStringList ExtractorPlugin::contactsFromString(const QString& string) |
35 | { |
36 | QString cleanedString = string; |
37 | cleanedString = cleanedString.remove(c: QLatin1Char('{')); |
38 | cleanedString = cleanedString.remove(c: QLatin1Char('}')); |
39 | |
40 | QStringList contactStrings = string.split(sep: QLatin1Char(','), behavior: Qt::SkipEmptyParts); |
41 | if (contactStrings.size() == 1) { |
42 | contactStrings = string.split(sep: QLatin1Char(';'), behavior: Qt::SkipEmptyParts); |
43 | } |
44 | |
45 | if (contactStrings.size() == 1) { |
46 | contactStrings = string.split(QStringLiteral(" ft "), behavior: Qt::SkipEmptyParts); |
47 | } |
48 | |
49 | if (contactStrings.size() == 1) { |
50 | contactStrings = string.split(QStringLiteral(" feat. "), behavior: Qt::SkipEmptyParts); |
51 | } |
52 | |
53 | if (contactStrings.size() == 1) { |
54 | contactStrings = string.split(QStringLiteral(" feat "), behavior: Qt::SkipEmptyParts); |
55 | } |
56 | |
57 | QStringList list; |
58 | list.reserve(asize: contactStrings.count()); |
59 | for (const QString& contactName : std::as_const(t&: contactStrings)) { |
60 | list << contactName.trimmed(); |
61 | } |
62 | |
63 | return list; |
64 | } |
65 | |
66 | QString ExtractorPlugin::getSupportedMimeType(const QString& mimetype) const |
67 | { |
68 | const QStringList allTypes = mimetypes(); |
69 | if (allTypes.contains(str: mimetype)) { |
70 | return mimetype; |
71 | } |
72 | |
73 | QMimeDatabase db; |
74 | auto type = db.mimeTypeForName(nameOrAlias: mimetype); |
75 | const QStringList ancestors = type.allAncestors(); |
76 | for (auto ancestor : ancestors) { |
77 | if (allTypes.contains(str: ancestor)) { |
78 | return ancestor; |
79 | } |
80 | } |
81 | |
82 | return QString(); |
83 | } |
84 | |
85 | #include "moc_extractorplugin.cpp" |
86 |