Warning, file /frameworks/kservice/tests/kmimeassociations_dumper.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 SPDX-FileCopyrightText: 2016 David Faure <faure@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-only 0005 */ 0006 0007 #include <QCommandLineParser> 0008 #include <QCoreApplication> 0009 #include <QTextStream> 0010 #include <kmimeassociations_p.h> 0011 #include <kservice.h> 0012 #include <ksycoca_p.h> 0013 0014 int main(int argc, char *argv[]) 0015 { 0016 QCoreApplication app(argc, argv); 0017 0018 QCommandLineParser parser; 0019 parser.setApplicationDescription(QStringLiteral("Parses mimeapps.list files and reports results for a mimetype")); 0020 parser.addHelpOption(); 0021 parser.addVersionOption(); 0022 parser.addPositionalArgument(QStringLiteral("mime"), QStringLiteral("mimetype name")); 0023 parser.process(app); 0024 0025 if (parser.positionalArguments().count() != 1) { 0026 QTextStream(stderr) << "Exactly one mimetype required\n"; 0027 parser.showHelp(1); 0028 } 0029 0030 const QString mime = parser.positionalArguments().at(0); 0031 0032 // To see which files are being parsed, run this command: 0033 // strace -e file ./kmimeassociations_dumper inode/directory |& grep mimeapps 0034 0035 // It should be the same as the output of these commands (assuming $XDG_CURRENT_DESKTOP=KDE) 0036 // qtpaths --locate-files GenericConfigLocation kde-mimeapps.list 0037 // qtpaths --locate-files GenericConfigLocation mimeapps.list 0038 // qtpaths --locate-files ApplicationsLocation kde-mimeapps.list 0039 // qtpaths --locate-files ApplicationsLocation mimeapps.list 0040 0041 KOfferHash offers; 0042 KMimeAssociations mimeAppsParser(offers, KSycocaPrivate::self()->serviceFactory()); 0043 mimeAppsParser.parseAllMimeAppsList(); 0044 0045 QTextStream output(stdout); 0046 const auto list = offers.offersFor(mime); 0047 for (const KServiceOffer &offer : list) { 0048 output << offer.service()->desktopEntryName() << " " << offer.service()->entryPath() << "\n"; 0049 } 0050 0051 return 0; 0052 }