kdirwatchtest.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. This file is part of the KDE libraries
  3. SPDX-FileCopyrightText: 1998 Sven Radej <sven@lisa.exp.univie.ac.at>
  4. SPDX-License-Identifier: LGPL-2.0-only
  5. */
  6. #include "kdirwatchtest.h"
  7. #include <QCoreApplication>
  8. #include <QStringList>
  9. #include <QDebug>
  10. // TODO debug crash when calling "./kdirwatchtest ./kdirwatchtest"
  11. int main(int argc, char **argv)
  12. {
  13. // TODO port to QCommandLineArguments once it exists
  14. // options.add("+[directory ...]", qi18n("Directory(ies) to watch"));
  15. QCoreApplication a(argc, argv);
  16. myTest testObject;
  17. KDirWatch *dirwatch1 = KDirWatch::self();
  18. KDirWatch *dirwatch2 = new KDirWatch;
  19. testObject.connect(dirwatch1, &KDirWatch::dirty, &myTest::dirty);
  20. testObject.connect(dirwatch1, &KDirWatch::created, &myTest::created);
  21. testObject.connect(dirwatch1, &KDirWatch::deleted, &myTest::deleted);
  22. // TODO port to QCommandLineArguments once it exists
  23. const QStringList args = a.arguments();
  24. for (int i = 1; i < args.count(); ++i) {
  25. const QString arg = args.at(i);
  26. if (!arg.startsWith("-")) {
  27. qDebug() << "Watching: " << arg;
  28. dirwatch2->addDir(arg);
  29. }
  30. }
  31. QString home = QString(getenv("HOME")) + '/';
  32. QString desk = home + "Desktop/";
  33. qDebug() << "Watching: " << home;
  34. dirwatch1->addDir(home);
  35. qDebug() << "Watching file: " << home << "foo ";
  36. dirwatch1->addFile(home + "foo");
  37. qDebug() << "Watching: " << desk;
  38. dirwatch1->addDir(desk);
  39. QString test = home + "test/";
  40. qDebug() << "Watching: (but skipped) " << test;
  41. dirwatch1->addDir(test);
  42. dirwatch1->startScan();
  43. dirwatch2->startScan();
  44. if (!dirwatch1->stopDirScan(home)) {
  45. qDebug() << "stopDirscan: " << home << " error!";
  46. }
  47. if (!dirwatch1->restartDirScan(home)) {
  48. qDebug() << "restartDirScan: " << home << "error!";
  49. }
  50. if (!dirwatch1->stopDirScan(test)) {
  51. qDebug() << "stopDirScan: error";
  52. }
  53. KDirWatch::statistics();
  54. delete dirwatch2;
  55. KDirWatch::statistics();
  56. return a.exec();
  57. }
  58. #include "moc_kdirwatchtest.cpp"