File: faviconfinder.cpp

package info (click to toggle)
kf6-kio 6.23.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 38,088 kB
  • sloc: cpp: 102,370; xml: 519; ansic: 215; python: 200; ruby: 60; sh: 21; makefile: 14
file content (41 lines) | stat: -rw-r--r-- 1,044 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*
 *  SPDX-FileCopyrightText: 2025 Nicolas Fella <nicolas.fella@gmx.de>
 *
 *  SPDX-License-Identifier: LGPL-2.0-or-later
 */

#include <QCommandLineParser>
#include <QGuiApplication>
#include <QUrl>

#include <KIO/FavIconRequestJob>

int main(int argc, char **argv)
{
    QGuiApplication app(argc, argv);

    QCommandLineParser parser;
    parser.addPositionalArgument("url", "URL to get the favicon for");
    parser.process(app);

    if (parser.positionalArguments().length() != 1) {
        qWarning() << "Wrong number of arguments";
        return 2;
    }

    KIO::FavIconRequestJob *job = new KIO::FavIconRequestJob(QUrl(parser.positionalArguments()[0]));

    QObject::connect(job, &KJob::finished, &app, [job, &app] {
        QTextStream out(stdout);

        if (job->error() != KJob::NoError) {
            out << "Error: " << job->error() << " " << job->errorText() << Qt::endl;
            app.exit(1);
            return;
        }

        out << "Favicon: " << job->iconFile() << Qt::endl;
    });

    return app.exec();
}