2014-11-15 04:16:00 +02:00
|
|
|
/* This file is part of the KDE project
|
|
|
|
Copyright (C) 2008 David Faure <faure@kde.org>
|
2015-09-26 03:07:31 +00:00
|
|
|
Copyright (C) 2015 Ivailo Monev <xakepa10@gmail.com>
|
2014-11-15 04:16:00 +02:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License or ( at
|
|
|
|
your option ) version 3 or, at the discretion of KDE e.V. ( which shall
|
|
|
|
act as a proxy as in section 14 of the GPLv3 ), any later version.
|
|
|
|
|
|
|
|
This program 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
|
|
|
|
General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; see the file COPYING. If not, write to
|
|
|
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <kcmdlineargs.h>
|
|
|
|
#include <kiconloader.h>
|
|
|
|
#include <kdeversion.h>
|
|
|
|
#include <klocale.h>
|
2022-09-24 18:42:57 +03:00
|
|
|
|
2015-09-26 03:07:31 +00:00
|
|
|
#include <iostream>
|
2022-09-24 18:42:57 +03:00
|
|
|
#include <stdio.h>
|
2014-11-15 04:16:00 +02:00
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2023-08-31 17:54:50 +03:00
|
|
|
KCmdLineArgs::init(
|
|
|
|
argc, argv,
|
|
|
|
"kiconfinder",
|
|
|
|
0,
|
|
|
|
ki18n("Icon Finder"),
|
|
|
|
KDE_VERSION_STRING,
|
|
|
|
ki18n("Finds an icon based on its name")
|
|
|
|
);
|
2014-11-15 04:16:00 +02:00
|
|
|
|
|
|
|
KCmdLineOptions options;
|
|
|
|
options.add("+iconname", ki18n("The icon name to look for"));
|
2015-09-26 03:07:31 +00:00
|
|
|
options.add("icongroup <group>", ki18n("The icon group to look in"), "desktop");
|
2014-11-15 04:16:00 +02:00
|
|
|
KCmdLineArgs::addCmdLineOptions( options );
|
|
|
|
|
|
|
|
KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
|
2015-09-26 03:07:31 +00:00
|
|
|
|
2023-08-31 17:54:50 +03:00
|
|
|
if (args->count() < 1) {
|
2015-09-26 03:07:31 +00:00
|
|
|
args->usage();
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList iconArgs;
|
2023-08-31 17:57:21 +03:00
|
|
|
iconArgs.reserve(args->count());
|
|
|
|
for (int i = 0; i < args->count(); i++) {
|
2015-09-26 03:07:31 +00:00
|
|
|
iconArgs << args->arg(i);
|
|
|
|
}
|
|
|
|
const QString groupArg = args->getOption("icongroup");
|
|
|
|
|
|
|
|
KIconLoader::Group iconGroup;
|
2023-08-31 17:57:21 +03:00
|
|
|
if (groupArg == QLatin1String("none")) {
|
2015-09-26 03:07:31 +00:00
|
|
|
iconGroup = KIconLoader::NoGroup;
|
2023-08-31 17:57:21 +03:00
|
|
|
} else if (groupArg == QLatin1String("desktop")) {
|
2015-09-26 03:07:31 +00:00
|
|
|
iconGroup = KIconLoader::Desktop;
|
2023-08-31 17:57:21 +03:00
|
|
|
} else if(groupArg == QLatin1String("first")) {
|
2015-09-26 03:07:31 +00:00
|
|
|
iconGroup = KIconLoader::FirstGroup;
|
2023-08-31 17:57:21 +03:00
|
|
|
} else if(groupArg == QLatin1String("toolbar")) {
|
2015-09-26 03:07:31 +00:00
|
|
|
iconGroup = KIconLoader::MainToolbar;
|
2023-08-31 17:57:21 +03:00
|
|
|
} else if(groupArg == QLatin1String("small")) {
|
2015-09-26 03:07:31 +00:00
|
|
|
iconGroup = KIconLoader::Small;
|
2023-08-31 17:57:21 +03:00
|
|
|
} else if(groupArg == QLatin1String("panel")) {
|
2015-09-26 03:07:31 +00:00
|
|
|
iconGroup = KIconLoader::Panel;
|
2023-08-31 17:57:21 +03:00
|
|
|
} else if(groupArg == QLatin1String("dialog")) {
|
2015-09-26 03:07:31 +00:00
|
|
|
iconGroup = KIconLoader::Dialog;
|
2023-08-31 17:57:21 +03:00
|
|
|
} else if(groupArg == QLatin1String("last")) {
|
2015-09-26 03:07:31 +00:00
|
|
|
iconGroup = KIconLoader::LastGroup;
|
2023-08-31 17:57:21 +03:00
|
|
|
} else if(groupArg == QLatin1String("user")) {
|
2015-09-26 03:07:31 +00:00
|
|
|
iconGroup = KIconLoader::User;
|
2023-08-31 17:54:50 +03:00
|
|
|
} else {
|
|
|
|
std::cerr << "Invalid icon group '" << groupArg.toLatin1().constData() << "," << std::endl;
|
2015-09-26 03:07:31 +00:00
|
|
|
std::cerr << "Choose one of: none, desktop, first, toolbar, small, panel, dialog, last, user." << std::endl;
|
2014-11-15 04:16:00 +02:00
|
|
|
return 1;
|
|
|
|
}
|
2015-09-26 03:07:31 +00:00
|
|
|
|
|
|
|
int rv = 0;
|
2023-08-31 17:57:21 +03:00
|
|
|
foreach (const QString &iconName, iconArgs) {
|
2015-09-26 03:07:31 +00:00
|
|
|
const QString icon = KIconLoader::global()->iconPath(iconName, iconGroup, true);
|
|
|
|
if (!icon.isEmpty()) {
|
2023-08-31 17:58:34 +03:00
|
|
|
const QByteArray iconBytes = icon.toLatin1();
|
2023-08-31 18:00:22 +03:00
|
|
|
::printf("%s\n", iconBytes.constData());
|
2015-09-26 03:07:31 +00:00
|
|
|
} else {
|
2023-08-31 17:58:34 +03:00
|
|
|
const QByteArray iconNameBytes = iconName.toLatin1();
|
|
|
|
std::cerr << "Icon '" << iconNameBytes.constData() << "' not found" << std::endl;
|
2015-09-26 03:07:31 +00:00
|
|
|
rv = 1;
|
|
|
|
}
|
2014-11-15 04:16:00 +02:00
|
|
|
}
|
|
|
|
|
2015-09-26 03:07:31 +00:00
|
|
|
return rv;
|
2014-11-15 04:16:00 +02:00
|
|
|
}
|