kdirwatchtest_gui.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. SPDX-FileCopyrightText: 2006 Dirk Stoecker <kde@dstoecker.de>
  3. SPDX-License-Identifier: LGPL-2.0-only
  4. */
  5. #include "kdirwatchtest_gui.h"
  6. #include <QApplication>
  7. #include <QDir>
  8. #include <QLabel>
  9. #include <QLineEdit>
  10. #include <QPushButton>
  11. #include <QTextBrowser>
  12. #include <QVBoxLayout>
  13. #include <kdirwatch.h>
  14. #include <qplatformdefs.h>
  15. int main(int argc, char **argv)
  16. {
  17. QApplication app(argc, argv);
  18. KDirWatchTest_GUI *mainWin = new KDirWatchTest_GUI();
  19. mainWin->show();
  20. return app.exec();
  21. }
  22. KDirWatchTest_GUI::KDirWatchTest_GUI()
  23. : QWidget()
  24. {
  25. QPushButton *e;
  26. QPushButton *f;
  27. QVBoxLayout *lay = new QVBoxLayout(this);
  28. lay->setContentsMargins(0, 0, 0, 0);
  29. lay->addWidget(l1 = new QLineEdit(QLatin1String("Test 1"), this));
  30. lay->addWidget(l2 = new QLineEdit(QLatin1String("Test 2"), this));
  31. lay->addWidget(l3 = new QLineEdit(QLatin1String("Test 3"), this));
  32. lay->addWidget(m_eventBrowser = new QTextBrowser(this));
  33. lay->addWidget(d = new QLineEdit(QLatin1String("Status"), this));
  34. lay->addWidget(e = new QPushButton(QLatin1String("new file"), this));
  35. lay->addWidget(f = new QPushButton(QLatin1String("delete file"), this));
  36. dir = QDir::currentPath();
  37. file = dir + QLatin1String("/testfile_kdirwatchtest_gui");
  38. w1 = new KDirWatch();
  39. w1->setObjectName(QLatin1String("w1"));
  40. w2 = new KDirWatch();
  41. w2->setObjectName(QLatin1String("w2"));
  42. w3 = new KDirWatch();
  43. w3->setObjectName(QLatin1String("w3"));
  44. connect(w1, &KDirWatch::dirty, this, &KDirWatchTest_GUI::slotDir1);
  45. connect(w2, &KDirWatch::dirty, this, &KDirWatchTest_GUI::slotDir2);
  46. connect(w3, &KDirWatch::dirty, this, &KDirWatchTest_GUI::slotDir3);
  47. w1->addDir(dir);
  48. w2->addDir(dir);
  49. w3->addDir(dir);
  50. KDirWatch *w4 = new KDirWatch(this);
  51. w4->setObjectName(QLatin1String("w4"));
  52. w4->addDir(dir, KDirWatch::WatchFiles | KDirWatch::WatchSubDirs);
  53. connect(w1, &KDirWatch::dirty, this, &KDirWatchTest_GUI::slotDirty);
  54. connect(w1, &KDirWatch::created, this, &KDirWatchTest_GUI::slotCreated);
  55. connect(w1, &KDirWatch::deleted, this, &KDirWatchTest_GUI::slotDeleted);
  56. KDirWatch *w5 = new KDirWatch(this);
  57. w5->setObjectName(QLatin1String(QLatin1String("w5")));
  58. w5->addFile(file);
  59. connect(w5, &KDirWatch::dirty, this, &KDirWatchTest_GUI::slotDirty);
  60. connect(w5, &KDirWatch::created, this, &KDirWatchTest_GUI::slotCreated);
  61. connect(w5, &KDirWatch::deleted, this, &KDirWatchTest_GUI::slotDeleted);
  62. lay->addWidget(new QLabel(QLatin1String("Directory = ") + dir, this));
  63. lay->addWidget(new QLabel(QLatin1String("File = ") + file, this));
  64. connect(e, &QPushButton::clicked, this, &KDirWatchTest_GUI::slotNewClicked);
  65. connect(f, &QPushButton::clicked, this, &KDirWatchTest_GUI::slotDeleteClicked);
  66. setMinimumWidth(800);
  67. setMinimumHeight(400);
  68. }
  69. void KDirWatchTest_GUI::slotDir1(const QString &a)
  70. {
  71. l1->setText(QLatin1String("Test 1 changed ") + a + QLatin1String(" at ") + QTime::currentTime().toString());
  72. }
  73. void KDirWatchTest_GUI::slotDir2(const QString &a)
  74. {
  75. // This used to cause bug #119341, fixed now
  76. #if 1
  77. w2->stopDirScan(QLatin1String(a.toLatin1().constData()));
  78. w2->restartDirScan(QLatin1String(a.toLatin1().constData()));
  79. #endif
  80. l2->setText(QLatin1String("Test 2 changed ") + a + QLatin1String(" at ") + QTime::currentTime().toString());
  81. }
  82. void KDirWatchTest_GUI::slotDir3(const QString &a)
  83. {
  84. l3->setText(QLatin1String("Test 3 changed ") + a + QLatin1String(" at )") + QTime::currentTime().toString());
  85. }
  86. void KDirWatchTest_GUI::slotDeleteClicked()
  87. {
  88. remove(file.toLatin1().constData());
  89. d->setText(QLatin1String("Delete clicked at ") + QTime::currentTime().toString());
  90. }
  91. void KDirWatchTest_GUI::slotNewClicked()
  92. {
  93. fclose(QT_FOPEN(file.toLatin1().constData(), "wb"));
  94. d->setText(QLatin1String("New clicked at ") + QTime::currentTime().toString());
  95. }
  96. void KDirWatchTest_GUI::slotDirty(const QString &path)
  97. {
  98. m_eventBrowser->append(QLatin1String("Dirty(") + sender()->objectName() + QLatin1String("): ") + path + QLatin1Char('\n'));
  99. }
  100. void KDirWatchTest_GUI::slotCreated(const QString &path)
  101. {
  102. m_eventBrowser->append(QLatin1String("Created(") + sender()->objectName() + QLatin1String("): ") + path + QLatin1Char('\n'));
  103. }
  104. void KDirWatchTest_GUI::slotDeleted(const QString &path)
  105. {
  106. m_eventBrowser->append(QLatin1String("Deleted(") + sender()->objectName() + QLatin1String("): ") + path + QLatin1Char('\n'));
  107. }
  108. #include "moc_kdirwatchtest_gui.cpp"