File indexing completed on 2024-09-08 06:40:02
0001 /* 0002 SPDX-FileCopyrightText: 2006 Dirk Stoecker <kde@dstoecker.de> 0003 0004 SPDX-License-Identifier: LGPL-2.0-only 0005 */ 0006 0007 #include "kdirwatchtest_gui.h" 0008 0009 #include <QApplication> 0010 #include <QDir> 0011 #include <QLabel> 0012 #include <QLineEdit> 0013 #include <QPushButton> 0014 #include <QTextBrowser> 0015 #include <QVBoxLayout> 0016 #include <kdirwatch.h> 0017 #include <qplatformdefs.h> 0018 0019 int main(int argc, char **argv) 0020 { 0021 QApplication app(argc, argv); 0022 0023 KDirWatchTest_GUI *mainWin = new KDirWatchTest_GUI(); 0024 mainWin->show(); 0025 return app.exec(); 0026 } 0027 0028 KDirWatchTest_GUI::KDirWatchTest_GUI() 0029 : QWidget() 0030 { 0031 QPushButton *e; 0032 QPushButton *f; 0033 0034 QVBoxLayout *lay = new QVBoxLayout(this); 0035 lay->setContentsMargins(0, 0, 0, 0); 0036 lay->addWidget(l1 = new QLineEdit(QLatin1String("Test 1"), this)); 0037 lay->addWidget(l2 = new QLineEdit(QLatin1String("Test 2"), this)); 0038 lay->addWidget(l3 = new QLineEdit(QLatin1String("Test 3"), this)); 0039 lay->addWidget(m_eventBrowser = new QTextBrowser(this)); 0040 lay->addWidget(d = new QLineEdit(QLatin1String("Status"), this)); 0041 lay->addWidget(e = new QPushButton(QLatin1String("new file"), this)); 0042 lay->addWidget(f = new QPushButton(QLatin1String("delete file"), this)); 0043 0044 dir = QDir::currentPath(); 0045 file = dir + QLatin1String("/testfile_kdirwatchtest_gui"); 0046 0047 w1 = new KDirWatch(); 0048 w1->setObjectName(QLatin1String("w1")); 0049 w2 = new KDirWatch(); 0050 w2->setObjectName(QLatin1String("w2")); 0051 w3 = new KDirWatch(); 0052 w3->setObjectName(QLatin1String("w3")); 0053 connect(w1, &KDirWatch::dirty, this, &KDirWatchTest_GUI::slotDir1); 0054 connect(w2, &KDirWatch::dirty, this, &KDirWatchTest_GUI::slotDir2); 0055 connect(w3, &KDirWatch::dirty, this, &KDirWatchTest_GUI::slotDir3); 0056 w1->addDir(dir); 0057 w2->addDir(dir); 0058 w3->addDir(dir); 0059 0060 KDirWatch *w4 = new KDirWatch(this); 0061 w4->setObjectName(QLatin1String("w4")); 0062 w4->addDir(dir, KDirWatch::WatchFiles | KDirWatch::WatchSubDirs); 0063 connect(w1, &KDirWatch::dirty, this, &KDirWatchTest_GUI::slotDirty); 0064 connect(w1, &KDirWatch::created, this, &KDirWatchTest_GUI::slotCreated); 0065 connect(w1, &KDirWatch::deleted, this, &KDirWatchTest_GUI::slotDeleted); 0066 0067 KDirWatch *w5 = new KDirWatch(this); 0068 w5->setObjectName(QLatin1String(QLatin1String("w5"))); 0069 w5->addFile(file); 0070 connect(w5, &KDirWatch::dirty, this, &KDirWatchTest_GUI::slotDirty); 0071 connect(w5, &KDirWatch::created, this, &KDirWatchTest_GUI::slotCreated); 0072 connect(w5, &KDirWatch::deleted, this, &KDirWatchTest_GUI::slotDeleted); 0073 0074 lay->addWidget(new QLabel(QLatin1String("Directory = ") + dir, this)); 0075 lay->addWidget(new QLabel(QLatin1String("File = ") + file, this)); 0076 0077 connect(e, &QPushButton::clicked, this, &KDirWatchTest_GUI::slotNewClicked); 0078 connect(f, &QPushButton::clicked, this, &KDirWatchTest_GUI::slotDeleteClicked); 0079 0080 setMinimumWidth(800); 0081 setMinimumHeight(400); 0082 } 0083 0084 void KDirWatchTest_GUI::slotDir1(const QString &a) 0085 { 0086 l1->setText(QLatin1String("Test 1 changed ") + a + QLatin1String(" at ") + QTime::currentTime().toString()); 0087 } 0088 0089 void KDirWatchTest_GUI::slotDir2(const QString &a) 0090 { 0091 // This used to cause bug #119341, fixed now 0092 #if 1 0093 w2->stopDirScan(QLatin1String(a.toLatin1().constData())); 0094 w2->restartDirScan(QLatin1String(a.toLatin1().constData())); 0095 #endif 0096 l2->setText(QLatin1String("Test 2 changed ") + a + QLatin1String(" at ") + QTime::currentTime().toString()); 0097 } 0098 0099 void KDirWatchTest_GUI::slotDir3(const QString &a) 0100 { 0101 l3->setText(QLatin1String("Test 3 changed ") + a + QLatin1String(" at )") + QTime::currentTime().toString()); 0102 } 0103 0104 void KDirWatchTest_GUI::slotDeleteClicked() 0105 { 0106 remove(file.toLatin1().constData()); 0107 d->setText(QLatin1String("Delete clicked at ") + QTime::currentTime().toString()); 0108 } 0109 0110 void KDirWatchTest_GUI::slotNewClicked() 0111 { 0112 fclose(QT_FOPEN(file.toLatin1().constData(), "wb")); 0113 d->setText(QLatin1String("New clicked at ") + QTime::currentTime().toString()); 0114 } 0115 0116 void KDirWatchTest_GUI::slotDirty(const QString &path) 0117 { 0118 m_eventBrowser->append(QLatin1String("Dirty(") + sender()->objectName() + QLatin1String("): ") + path + QLatin1Char('\n')); 0119 } 0120 0121 void KDirWatchTest_GUI::slotCreated(const QString &path) 0122 { 0123 m_eventBrowser->append(QLatin1String("Created(") + sender()->objectName() + QLatin1String("): ") + path + QLatin1Char('\n')); 0124 } 0125 0126 void KDirWatchTest_GUI::slotDeleted(const QString &path) 0127 { 0128 m_eventBrowser->append(QLatin1String("Deleted(") + sender()->objectName() + QLatin1String("): ") + path + QLatin1Char('\n')); 0129 } 0130 0131 #include "moc_kdirwatchtest_gui.cpp"