File: listjobtest.cpp

package info (click to toggle)
kio 5.116.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 41,496 kB
  • sloc: cpp: 123,468; xml: 528; ansic: 466; ruby: 60; sh: 21; makefile: 13
file content (41 lines) | stat: -rw-r--r-- 1,126 bytes parent folder | download | duplicates (3)
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: 2014 Frank Reininghaus <frank78ac@googlemail.com>

    SPDX-License-Identifier: GPL-2.0-or-later
*/

#include <kio/listjob.h>

#include <iostream>

#include <QCoreApplication>
#include <QDebug>
#include <QDir>
#include <QUrl>

int main(int argc, char **argv)
{
    if (argc < 2) {
        qWarning() << "Expected a path or URL.";
        return 1;
    }

    QCoreApplication app(argc, argv);
    quint64 entriesListed = 0;

    for (int i = 1; i < argc; ++i) {
        QUrl url = QUrl::fromUserInput(QString::fromLocal8Bit(argv[i]), QDir::currentPath());
        qDebug() << "Starting listJob for the URL:" << url;

        KIO::ListJob *job = KIO::listDir(url, KIO::HideProgressInfo);
        job->setUiDelegate(nullptr);
        job->addMetaData(QStringLiteral("statDetails"), QString::number(KIO::StatDefaultDetails));

        QObject::connect(job, &KIO::ListJob::entries, [&entriesListed](KIO::Job *, const KIO::UDSEntryList &entries) {
            entriesListed += entries.size();
            qDebug() << "Listed" << entriesListed << "files.";
        });
    }

    return app.exec();
}