File indexing completed on 2024-09-08 12:14:34
0001 /* 0002 This file is part of the KDE libraries 0003 0004 SPDX-FileCopyrightText: 1998 Sven Radej <sven@lisa.exp.univie.ac.at> 0005 0006 SPDX-License-Identifier: LGPL-2.0-only 0007 */ 0008 0009 #include "kdirwatchtest.h" 0010 0011 #include <QCoreApplication> 0012 #include <QStringList> 0013 0014 #include <QDebug> 0015 0016 // TODO debug crash when calling "./kdirwatchtest ./kdirwatchtest" 0017 0018 int main(int argc, char **argv) 0019 { 0020 // TODO port to QCommandLineArguments once it exists 0021 // options.add("+[directory ...]", qi18n("Directory(ies) to watch")); 0022 0023 QCoreApplication a(argc, argv); 0024 0025 myTest testObject; 0026 0027 KDirWatch *dirwatch1 = KDirWatch::self(); 0028 KDirWatch *dirwatch2 = new KDirWatch; 0029 0030 testObject.connect(dirwatch1, &KDirWatch::dirty, &myTest::dirty); 0031 testObject.connect(dirwatch1, &KDirWatch::created, &myTest::created); 0032 testObject.connect(dirwatch1, &KDirWatch::deleted, &myTest::deleted); 0033 0034 // TODO port to QCommandLineArguments once it exists 0035 const QStringList args = a.arguments(); 0036 for (int i = 1; i < args.count(); ++i) { 0037 const QString arg = args.at(i); 0038 if (!arg.startsWith("-")) { 0039 qDebug() << "Watching: " << arg; 0040 dirwatch2->addDir(arg); 0041 } 0042 } 0043 0044 QString home = QString(getenv("HOME")) + '/'; 0045 QString desk = home + "Desktop/"; 0046 qDebug() << "Watching: " << home; 0047 dirwatch1->addDir(home); 0048 qDebug() << "Watching file: " << home << "foo "; 0049 dirwatch1->addFile(home + "foo"); 0050 qDebug() << "Watching: " << desk; 0051 dirwatch1->addDir(desk); 0052 QString test = home + "test/"; 0053 qDebug() << "Watching: (but skipped) " << test; 0054 dirwatch1->addDir(test); 0055 0056 dirwatch1->startScan(); 0057 dirwatch2->startScan(); 0058 0059 if (!dirwatch1->stopDirScan(home)) { 0060 qDebug() << "stopDirscan: " << home << " error!"; 0061 } 0062 if (!dirwatch1->restartDirScan(home)) { 0063 qDebug() << "restartDirScan: " << home << "error!"; 0064 } 0065 if (!dirwatch1->stopDirScan(test)) { 0066 qDebug() << "stopDirScan: error"; 0067 } 0068 0069 KDirWatch::statistics(); 0070 0071 delete dirwatch2; 0072 0073 KDirWatch::statistics(); 0074 0075 return a.exec(); 0076 } 0077 0078 #include "moc_kdirwatchtest.cpp"