Baloo Widgets

extractor.cpp
1 /*
2  SPDX-FileCopyrightText: 2014 Vishesh Handa <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5 */
6 
7 #include "extractorutil_p.h"
8 
9 #include <QCommandLineParser>
10 #include <QCoreApplication>
11 #include <QDataStream>
12 #include <QDebug>
13 #include <QFile>
14 #include <QMimeDatabase>
15 
16 #include <KFileMetaData/Extractor>
17 #include <KFileMetaData/ExtractorCollection>
18 #include <KFileMetaData/MimeUtils>
19 #include <KFileMetaData/SimpleExtractionResult>
20 
21 #include <iostream>
22 
23 int main(int argc, char **argv)
24 {
25  QCoreApplication app(argc, argv);
26 
27  QCommandLineParser parser;
29  parser.process(app);
30 
31  if (parser.positionalArguments().size() != 1) {
32  parser.showHelp(1);
33  }
34 
35  const QString url = parser.positionalArguments().constFirst();
36  const QString mimetype = KFileMetaData::MimeUtils::strictMimeType(url, QMimeDatabase()).name();
37 
38  KFileMetaData::SimpleExtractionResult result(url, mimetype, KFileMetaData::ExtractionResult::ExtractMetaData);
40 
41  const QList<KFileMetaData::Extractor *> exList = collection.fetchExtractors(mimetype);
42 
43  for (KFileMetaData::Extractor *ex : exList) {
44  ex->extract(&result);
45  }
46 
47  QFile out;
48  out.open(stdout, QIODevice::WriteOnly);
49  QDataStream stream(&out);
50 
51  stream << result.properties();
52 
53  return 0;
54 }
virtual bool open(QIODevice::OpenMode mode) override
void addPositionalArgument(const QString &name, const QString &description, const QString &syntax)
QStringList positionalArguments() const const
KIOCORE_EXPORT MimetypeJob * mimetype(const QUrl &url, JobFlags flags=DefaultFlags)
void showHelp(int exitCode)
int size() const const
void process(const QStringList &arguments)
QList< Extractor * > fetchExtractors(const QString &mimetype) const
const T & constFirst() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu Aug 11 2022 04:13:42 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.