Changeset View
Changeset View
Standalone View
Standalone View
src/file/extractor/result.cpp
Show All 15 Lines | |||||
16 | * Lesser General Public License for more details. | 16 | * Lesser General Public License for more details. | ||
17 | * | 17 | * | ||
18 | * You should have received a copy of the GNU Lesser General Public | 18 | * You should have received a copy of the GNU Lesser General Public | ||
19 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. | 19 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
20 | * | 20 | * | ||
21 | */ | 21 | */ | ||
22 | 22 | | |||
23 | #include "result.h" | 23 | #include "result.h" | ||
24 | #include "propertydata.h" | ||||
24 | 25 | | |||
25 | #include <QJsonDocument> | 26 | #include <QJsonDocument> | ||
26 | #include <QJsonObject> | 27 | #include <QJsonObject> | ||
27 | 28 | | |||
28 | #include <QDateTime> | 29 | #include <QDateTime> | ||
29 | #include <KFileMetaData/PropertyInfo> | 30 | #include <KFileMetaData/PropertyInfo> | ||
30 | #include <KFileMetaData/TypeInfo> | 31 | #include <KFileMetaData/TypeInfo> | ||
31 | 32 | | |||
Show All 9 Lines | 41 | Result::Result(const QString& url, const QString& mimetype, const Flags& flags) | |||
41 | : KFileMetaData::ExtractionResult(url, mimetype, flags) | 42 | : KFileMetaData::ExtractionResult(url, mimetype, flags) | ||
42 | , m_termGen(m_doc) | 43 | , m_termGen(m_doc) | ||
43 | , m_termGenForText(m_doc) | 44 | , m_termGenForText(m_doc) | ||
44 | { | 45 | { | ||
45 | } | 46 | } | ||
46 | 47 | | |||
47 | void Result::add(KFileMetaData::Property::Property property, const QVariant& value) | 48 | void Result::add(KFileMetaData::Property::Property property, const QVariant& value) | ||
48 | { | 49 | { | ||
49 | int propNum = static_cast<int>(property); | 50 | if (value.type() == QVariant::StringList) { | ||
50 | if (!value.isNull()) { | 51 | const auto valueList = value.toStringList(); | ||
51 | QString p = QString::number(propNum); | 52 | for (const auto& val : valueList) { | ||
52 | if (!m_map.contains(p)) { | 53 | m_map.insertMulti(property, val); | ||
53 | m_map.insert(p, value); | | |||
54 | } else { | | |||
55 | QVariant prev = m_map.value(p); | | |||
56 | QVariantList list; | | |||
57 | if (prev.type() == QVariant::List) { | | |||
58 | list = prev.toList(); | | |||
59 | } else { | | |||
60 | list << prev; | | |||
61 | } | | |||
62 | | ||||
63 | list << value; | | |||
64 | m_map.insert(p, QVariant(list)); | | |||
65 | } | 54 | } | ||
55 | } else { | ||||
56 | m_map.insertMulti(property, value); | ||||
66 | } | 57 | } | ||
67 | 58 | | |||
59 | int propNum = static_cast<int>(property); | ||||
68 | QByteArray prefix = 'X' + QByteArray::number(propNum) + '-'; | 60 | QByteArray prefix = 'X' + QByteArray::number(propNum) + '-'; | ||
69 | 61 | | |||
70 | if (value.type() == QVariant::Bool) { | 62 | if (value.type() == QVariant::Bool) { | ||
71 | m_doc.addTerm(prefix); | 63 | m_doc.addTerm(prefix); | ||
72 | } | 64 | } | ||
73 | else if (value.type() == QVariant::Int || value.type() == QVariant::UInt) { | 65 | else if (value.type() == QVariant::Int || value.type() == QVariant::UInt) { | ||
74 | const QByteArray term = prefix + value.toString().toUtf8(); | 66 | const QByteArray term = prefix + value.toString().toUtf8(); | ||
75 | m_doc.addTerm(term); | 67 | m_doc.addTerm(term); | ||
Show All 11 Lines | 77 | else if (value.type() == QVariant::StringList) { | |||
87 | const auto valueList = value.toStringList(); | 79 | const auto valueList = value.toStringList(); | ||
88 | for (const auto& val : valueList) | 80 | for (const auto& val : valueList) | ||
89 | { | 81 | { | ||
90 | if (val.isEmpty()) | 82 | if (val.isEmpty()) | ||
91 | continue; | 83 | continue; | ||
92 | m_termGen.indexText(val, prefix); | 84 | m_termGen.indexText(val, prefix); | ||
93 | if (shouldBeIndexed) | 85 | if (shouldBeIndexed) | ||
94 | m_termGen.indexText(val); | 86 | m_termGen.indexText(val); | ||
95 | | ||||
96 | } | 87 | } | ||
97 | } | 88 | } | ||
98 | else { | 89 | else { | ||
99 | const QString val = value.toString(); | 90 | const QString val = value.toString(); | ||
100 | if (val.isEmpty()) | 91 | if (val.isEmpty()) | ||
101 | return; | 92 | return; | ||
102 | 93 | | |||
103 | m_termGen.indexText(val, prefix); | 94 | m_termGen.indexText(val, prefix); | ||
Show All 16 Lines | |||||
120 | } | 111 | } | ||
121 | 112 | | |||
122 | void Result::finish() | 113 | void Result::finish() | ||
123 | { | 114 | { | ||
124 | if (m_map.isEmpty()) { | 115 | if (m_map.isEmpty()) { | ||
125 | m_doc.setData(QByteArray()); | 116 | m_doc.setData(QByteArray()); | ||
126 | return; | 117 | return; | ||
127 | } | 118 | } | ||
128 | QJsonObject jo = QJsonObject::fromVariantMap(m_map); | 119 | QJsonObject jo = Baloo::propertyMapToJson(m_map); | ||
129 | QJsonDocument jdoc; | 120 | QJsonDocument jdoc; | ||
130 | jdoc.setObject(jo); | 121 | jdoc.setObject(jo); | ||
131 | m_doc.setData(jdoc.toJson(QJsonDocument::JsonFormat::Compact)); | 122 | m_doc.setData(jdoc.toJson(QJsonDocument::JsonFormat::Compact)); | ||
132 | } | 123 | } | ||
133 | 124 | | |||
134 | void Result::setDocument(const Baloo::Document& doc) | 125 | void Result::setDocument(const Baloo::Document& doc) | ||
135 | { | 126 | { | ||
136 | m_doc = doc; | 127 | m_doc = doc; | ||
Show All 9 Lines |