KIconThemes

kiconfinder.cpp
1 /* This file is part of the KDE project
2  Copyright (C) 2008 David Faure <[email protected]>
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License or ( at
7  your option ) version 3 or, at the discretion of KDE e.V. ( which shall
8  act as a proxy as in section 14 of the GPLv3 ), any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; see the file COPYING. If not, write to
17  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  Boston, MA 02110-1301, USA.
19 */
20 
21 #include <QGuiApplication>
22 #include <QCommandLineParser>
23 #include <kiconloader.h>
24 #include <../kiconthemes_version.h>
25 
26 #include <stdio.h>
27 
28 int main(int argc, char *argv[])
29 {
30  QGuiApplication app(argc, argv);
31  app.setApplicationName(QStringLiteral("kiconfinder"));
32  app.setApplicationVersion(QStringLiteral(KICONTHEMES_VERSION_STRING));
33  QCommandLineParser parser;
34  parser.setApplicationDescription(app.translate("main", "Finds an icon based on its name"));
35  parser.addPositionalArgument(QStringLiteral("iconname"), app.translate("main", "The icon name to look for"));
36  parser.addHelpOption();
37 
38  parser.process(app);
39  if(parser.positionalArguments().isEmpty())
40  parser.showHelp();
41 
42  for(const QString& iconName : parser.positionalArguments()) {
43  const QString icon = KIconLoader::global()->iconPath(iconName, KIconLoader::Desktop /*TODO configurable*/, true);
44  if ( !icon.isEmpty() ) {
45  printf("%s\n", icon.toLocal8Bit().constData());
46  } else {
47  return 1; // error
48  }
49  }
50 
51  return 0;
52 }
KICONTHEMES_EXPORT QIcon icon(const QString &iconName, KIconLoader *iconLoader=nullptr)
QStringList positionalArguments() const const
void addPositionalArgument(const QString &name, const QString &description, const QString &syntax)
Desktop icons.
Definition: kiconloader.h:133
bool isEmpty() const const
bool isEmpty() const const
const char * constData() const const
QCommandLineOption addHelpOption()
void setApplicationDescription(const QString &description)
static KIconLoader * global()
Returns the global icon loader initialized with the application name.
QByteArray toLocal8Bit() const const
void process(const QStringList &arguments)
void showHelp(int exitCode)
QString iconPath(const QString &name, int group_or_size, bool canReturnNull=false) const
Returns the path of an icon.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sun Jul 12 2020 22:41:33 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.