File: kdirwatchtest.cpp

package info (click to toggle)
kcoreaddons 5.116.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 25,660 kB
  • sloc: cpp: 23,523; xml: 3,284; sh: 34; makefile: 7
file content (78 lines) | stat: -rw-r--r-- 2,122 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
    This file is part of the KDE libraries

    SPDX-FileCopyrightText: 1998 Sven Radej <sven@lisa.exp.univie.ac.at>

    SPDX-License-Identifier: LGPL-2.0-only
*/

#include "kdirwatchtest.h"

#include <QCoreApplication>
#include <QStringList>

#include <QDebug>

// TODO debug crash when calling "./kdirwatchtest ./kdirwatchtest"

int main(int argc, char **argv)
{
    // TODO port to QCommandLineArguments once it exists
    // options.add("+[directory ...]", qi18n("Directory(ies) to watch"));

    QCoreApplication a(argc, argv);

    myTest testObject;

    KDirWatch *dirwatch1 = KDirWatch::self();
    KDirWatch *dirwatch2 = new KDirWatch;

    testObject.connect(dirwatch1, &KDirWatch::dirty, &myTest::dirty);
    testObject.connect(dirwatch1, &KDirWatch::created, &myTest::created);
    testObject.connect(dirwatch1, &KDirWatch::deleted, &myTest::deleted);

    // TODO port to QCommandLineArguments once it exists
    const QStringList args = a.arguments();
    for (int i = 1; i < args.count(); ++i) {
        const QString arg = args.at(i);
        if (!arg.startsWith("-")) {
            qDebug() << "Watching: " << arg;
            dirwatch2->addDir(arg);
        }
    }

    QString home = QString(getenv("HOME")) + '/';
    QString desk = home + "Desktop/";
    qDebug() << "Watching: " << home;
    dirwatch1->addDir(home);
    qDebug() << "Watching file: " << home << "foo ";
    dirwatch1->addFile(home + "foo");
    qDebug() << "Watching: " << desk;
    dirwatch1->addDir(desk);
    QString test = home + "test/";
    qDebug() << "Watching: (but skipped) " << test;
    dirwatch1->addDir(test);

    dirwatch1->startScan();
    dirwatch2->startScan();

    if (!dirwatch1->stopDirScan(home)) {
        qDebug() << "stopDirscan: " << home << " error!";
    }
    if (!dirwatch1->restartDirScan(home)) {
        qDebug() << "restartDirScan: " << home << "error!";
    }
    if (!dirwatch1->stopDirScan(test)) {
        qDebug() << "stopDirScan: error";
    }

    KDirWatch::statistics();

    delete dirwatch2;

    KDirWatch::statistics();

    return a.exec();
}

#include "moc_kdirwatchtest.cpp"