diff --git a/autotests/CMakeLists.txt b/autotests/CMakeLists.txt --- a/autotests/CMakeLists.txt +++ b/autotests/CMakeLists.txt @@ -3,6 +3,7 @@ ecm_add_test(extractortest.cpp TEST_NAME "extractortest" LINK_LIBRARIES Qt5::Test + KF5::FileMetaData ) ecm_add_tests( filemetadatawidgettest.cpp diff --git a/autotests/extractortest.cpp b/autotests/extractortest.cpp --- a/autotests/extractortest.cpp +++ b/autotests/extractortest.cpp @@ -19,6 +19,9 @@ */ #include "extractortest.h" +#include + +#include #include #include @@ -32,6 +35,7 @@ void ExtractorTest::test() { + using namespace KFileMetaData::Property; QString fileUrl = QFINDTESTDATA("samplefiles/test.mp3"); QString exe = QStandardPaths::findExecutable(QLatin1String("baloo_filemetadata_temp_extractor")); @@ -46,14 +50,15 @@ qDebug() << process.readAllStandardError(); QByteArray bytearray = process.readAllStandardOutput(); - QVariantMap data; QDataStream in(&bytearray, QIODevice::ReadOnly); + + KFileMetaData::PropertyMap data; in >> data; - QCOMPARE(data.value(QLatin1String("channels")).toInt(), 2); - QCOMPARE(data.value(QLatin1String("sampleRate")).toInt(), 44100); + QCOMPARE(data.value(Property::Channels).toInt(), 2); + QCOMPARE(data.value(Property::SampleRate).toInt(), 44100); if (data.size() == 3) { - QCOMPARE(data.value(QLatin1String("bitRate")).toInt(), 255000); + QCOMPARE(data.value(Property::BitRate).toInt(), 255000); } else { QCOMPARE(data.size(), 2); } diff --git a/src/extractor.cpp b/src/extractor.cpp --- a/src/extractor.cpp +++ b/src/extractor.cpp @@ -20,7 +20,7 @@ * */ -#include "filemetadatautil_p.h" +#include "extractorutil_p.h" #include #include @@ -64,11 +64,7 @@ out.open(stdout, QIODevice::WriteOnly); QDataStream stream(&out); - QVariantMap map = Baloo::Private::toNamedVariantMap(result.properties()); - - stream << map; - - qDebug() << map; + stream << result.properties(); return 0; } diff --git a/src/extractorutil_p.h b/src/extractorutil_p.h new file mode 100644 --- /dev/null +++ b/src/extractorutil_p.h @@ -0,0 +1,41 @@ +/***************************************************************************** + * Copyright (C) 2019 by Stefan BrĂ¼ns * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public License * + * along with this library; see the file COPYING.LIB. If not, write to * + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * + * Boston, MA 02110-1301, USA. * + *****************************************************************************/ + +#include +#include + +/* + * Deserialize prop from QDataStream + */ +static inline QDataStream &operator>>(QDataStream &stream, KFileMetaData::Property::Property& prop) +{ + quint16 intProp; + stream >> intProp; + prop = static_cast(intProp); + return stream; +} + +/* + * Serialize prop for QDataStream + */ +static inline QDataStream &operator<<(QDataStream &stream, const KFileMetaData::Property::Property prop) +{ + stream << static_cast(prop); + return stream; +} diff --git a/src/indexeddataretriever.cpp b/src/indexeddataretriever.cpp --- a/src/indexeddataretriever.cpp +++ b/src/indexeddataretriever.cpp @@ -20,6 +20,7 @@ #include "indexeddataretriever.h" #include "filemetadatautil_p.h" +#include "extractorutil_p.h" #include #include @@ -56,7 +57,11 @@ } QByteArray data = m_process->readAllStandardOutput(); QDataStream in(&data, QIODevice::ReadOnly); - in >> m_data; + + KFileMetaData::PropertyMap properties; + in >> properties; + + m_data = Baloo::Private::toNamedVariantMap(properties); KFileMetaData::UserMetaData umd(m_url); QVariantMap attributes = Baloo::Private::convertUserMetaData(umd);