Baloo Widgets

extractor.cpp
1 /*
2  * This file is part of the KDE Baloo Project
3  * Copyright (C) 2014 Vishesh Handa <[email protected]>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) version 3, or any
9  * later version accepted by the membership of KDE e.V. (or its
10  * successor approved by the membership of KDE e.V.), which shall
11  * act as a proxy defined in Section 6 of version 3 of the license.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
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/>.
20  *
21  */
22 
23 #include "extractorutil_p.h"
24 
25 #include <QCoreApplication>
26 #include <QCommandLineParser>
27 #include <QMimeDatabase>
28 #include <QDataStream>
29 #include <QDebug>
30 #include <QFile>
31 
32 #include <KFileMetaData/SimpleExtractionResult>
33 #include <KFileMetaData/ExtractorCollection>
34 #include <KFileMetaData/Extractor>
35 #include <KFileMetaData/MimeUtils>
36 
37 #include <iostream>
38 
39 int main(int argc, char **argv)
40 {
41  QCoreApplication app(argc, argv);
42 
43  QCommandLineParser parser;
45  parser.process(app);
46 
47  if (parser.positionalArguments().size() != 1) {
48  parser.showHelp(1);
49  }
50 
51  const QString url = parser.positionalArguments().first();
52  const QString mimetype = KFileMetaData::MimeUtils::strictMimeType(url, QMimeDatabase()).name();
53 
54  KFileMetaData::SimpleExtractionResult result(url, mimetype, KFileMetaData::ExtractionResult::ExtractMetaData);
56 
57  const QList<KFileMetaData::Extractor *> exList = collection.fetchExtractors(mimetype);
58 
59  for (KFileMetaData::Extractor *ex : exList) {
60  ex->extract(&result);
61  }
62 
63  QFile out;
64  out.open(stdout, QIODevice::WriteOnly);
65  QDataStream stream(&out);
66 
67  stream << result.properties();
68 
69  return 0;
70 }
QStringList positionalArguments() const const
void addPositionalArgument(const QString &name, const QString &description, const QString &syntax)
QList< Extractor * > fetchExtractors(const QString &mimetype) const
int size() const const
KIOCORE_EXPORT MimetypeJob * mimetype(const QUrl &url, JobFlags flags=DefaultFlags)
T & first()
virtual bool open(QIODevice::OpenMode mode) override
void process(const QStringList &arguments)
void showHelp(int exitCode)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Mon Oct 18 2021 23:07:21 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.