QFileSystemWatcher* KFileSystemWatcher::availableWatcher() { QFileSystemWatcher* watcher = m_recentWatcher; if (!watcher || m_usedObjects.value(watcher) >= MAXIMUM_WAIT_OBJECTS) { uint i = 0; watcher = 0; for (QList<QFileSystemWatcher*>::ConstIterator watchersIt(m_watchers.constBegin()); watchersIt!=m_watchers.constEnd(); ++watchersIt, i++) { if (m_usedObjects.value(*watchersIt) < MAXIMUM_WAIT_OBJECTS) { watcher = *watchersIt; m_recentWatcher = watcher; return watcher; } } } if (!watcher) { //new one needed watcher = new QFileSystemWatcher(); connect(watcher, SIGNAL(directoryChanged(QString)), this, SIGNAL(directoryChanged(QString))); connect(watcher, SIGNAL(fileChanged(QString)), this, SIGNAL(fileChanged(QString))); m_watchers.append( watcher ); m_usedObjects.insert(watcher, 0); m_recentWatcher = watcher; } return watcher; }
void QInotifyFileSystemWatcherEngine::readFromInotify() { // qDebug() << "QInotifyFileSystemWatcherEngine::readFromInotify"; int buffSize = 0; ioctl(inotifyFd, FIONREAD, (char *) &buffSize); QVarLengthArray<char, 4096> buffer(buffSize); buffSize = read(inotifyFd, buffer.data(), buffSize); char *at = buffer.data(); char * const end = at + buffSize; QHash<int, inotify_event *> eventForId; while (at < end) { inotify_event *event = reinterpret_cast<inotify_event *>(at); if (eventForId.contains(event->wd)) eventForId[event->wd]->mask |= event->mask; else eventForId.insert(event->wd, event); at += sizeof(inotify_event) + event->len; } QHash<int, inotify_event *>::const_iterator it = eventForId.constBegin(); while (it != eventForId.constEnd()) { const inotify_event &event = **it; ++it; // qDebug() << "inotify event, wd" << event.wd << "mask" << hex << event.mask; int id = event.wd; QString path = getPathFromID(id); if (path.isEmpty()) { // perhaps a directory? id = -id; path = getPathFromID(id); if (path.isEmpty()) continue; } // qDebug() << "event for path" << path; if ((event.mask & (IN_DELETE_SELF | IN_MOVE_SELF | IN_UNMOUNT)) != 0) { pathToID.remove(path); idToPath.remove(id, getPathFromID(id)); if (!idToPath.contains(id)) inotify_rm_watch(inotifyFd, event.wd); if (id < 0) emit directoryChanged(path, true); else emit fileChanged(path, true); } else { if (id < 0) emit directoryChanged(path, false); else emit fileChanged(path, false); } } }
Condition4DirMonitorAll::Condition4DirMonitorAll(void) { m_QFileSystemWatcher = new QFileSystemWatcher; connect(m_QFileSystemWatcher, SIGNAL(directoryChanged(QString)), this, SLOT(directoryChanged(QString)), Qt::QueuedConnection); m_xmlEleName = "MonitorDirAll"; }
LocalFileMonitor::LocalFileMonitor(QObject *parent) : QObject(parent) { this->refreshTimer.start(30000000); this->fsWatch = new QFileSystemWatcher(this); connect(&refreshTimer, SIGNAL(timeout()), this, SLOT(refreshTimerEvent())); connect(this->fsWatch, SIGNAL(fileChanged(QString)), this, SLOT(fileChanged(QString))); connect(this->fsWatch, SIGNAL(directoryChanged(QString)), this, SLOT(directoryChanged(QString))); }
PicManager::PicManager(QWidget *parent) : ImageViewer(parent), curImage(ImageFactory::getImageWrapper(QString::null)), listMode(FileNameListMode), currentIndex(-1), fsWatcher(this) { // state = NoFileNoPicture; connect(&fsWatcher, SIGNAL(directoryChanged(QString)), SLOT(directoryChanged())); connect(&fsWatcher, SIGNAL(fileChanged(QString)), SLOT(fileChanged(QString))); }
MFileDataStore::MFileDataStore(const QString &filePath) : d_ptr(new MFileDataStorePrivate(filePath)) { Q_D(MFileDataStore); takeSnapshot(); addPathsToWatcher(filePath, d->watcher); connect(d->watcher.data(), SIGNAL(fileChanged(QString)), this, SLOT(fileChanged(QString))); connect(d->watcher.data(), SIGNAL(directoryChanged(QString)), this, SLOT(directoryChanged(QString))); }
ModList::ModList ( const QString& dir, const QString& list_file ) : QAbstractListModel(), m_dir(dir), m_list_file(list_file) { m_dir.setFilter(QDir::Readable | QDir::NoDotAndDotDot | QDir::Files | QDir::Dirs | QDir::NoSymLinks); m_dir.setSorting(QDir::Name); m_list_id = QUuid::createUuid().toString(); m_watcher = new QFileSystemWatcher(this); is_watching = false; connect(m_watcher,SIGNAL(directoryChanged(QString)), this, SLOT(directoryChanged(QString))); update(); }
void MainWindow::start(bool isTrue) { if (isTrue) { isStart_ = true; pbStart_->setText(tr("Stop")); connect(watcher_, SIGNAL(fileChanged(QString)), this, SLOT(slotFileChanged(QString))); connect(watcher_, SIGNAL(directoryChanged(QString)), this, SLOT(slotDirectoryChanged(QString))); Common::asyncCopy(leFrom_->text(), leTo_->text()); } else { isStart_ = false; pbStart_->setText(tr("Start")); disconnect(watcher_, SIGNAL(fileChanged(QString)), this, SLOT(slotFileChanged(QString))); disconnect(watcher_, SIGNAL(directoryChanged(QString)), this, SLOT(slotDirectoryChanged(QString))); } }
void Ut_MApplicationExtensionManager::testMonitorRemoveExtension() { gDesktopEntryList.clear(); // Fire up a couple of extensions gDesktopEntryList << "test1.desktop" << "test2.desktop"; gDefaultMApplicationExtensionMetaDataStub.stubSetReturnValue("isValid", true); gDefaultMApplicationExtensionMetaDataStub.stubSetReturnValue("interface", interfaceName); gDefaultMApplicationExtensionMetaDataStub.stubSetExtensionBinaryMultiple("test1"); gDefaultMApplicationExtensionMetaDataStub.stubSetExtensionBinaryMultiple("test2"); setupGoodExtension(true, NULL, "1st extension"); setupGoodExtension(true, NULL, "2nd extension"); setupTestSubject(); // Remove one extension from the file system gDesktopEntryList.clear(); gDesktopEntryList << "test1.desktop"; // The test subject asks the library name from the removed meta data gDefaultMApplicationExtensionMetaDataStub.stubSetReturnValue("extensionBinary", QString("test2")); // Notify about a file system change emit directoryChanged(APPLICATION_EXTENSION_DATA_DIR); // Observe that the correct extension was removed QCOMPARE(signalListener.removedExtensions.count(), 1); QCOMPARE(signalListener.removedExtensions.at(0).second, QString("2nd extension")); }
XdgMenuPrivate::XdgMenuPrivate(XdgMenu *parent): mOutDated(true), q_ptr(parent) { this->connect(&mWatcher, SIGNAL(fileChanged(QString)), this, SLOT(fileChanged(QString))); this->connect(&mWatcher, SIGNAL(directoryChanged(QString)), this, SLOT(fileChanged(QString))); }
void Ut_MApplicationExtensionManager::setupTestSubject(const QString &inProcessFilter, const QString &outOfProcessFilter, const QStringList &order) { delete manager; manager = new MApplicationExtensionManager(interfaceName); if (!inProcessFilter.isEmpty()) { manager->setInProcessFilter(QRegExp(inProcessFilter)); } if (!outOfProcessFilter.isEmpty()) { manager->setOutOfProcessFilter(QRegExp(outOfProcessFilter)); } if (!order.isEmpty()) { manager->setOrder(order); } manager->init(); connect(this, SIGNAL(directoryChanged(QString)), manager, SLOT(updateAvailableExtensions(QString))); connect(manager, SIGNAL(extensionInstantiated(MApplicationExtensionInterface *)), &signalListener, SLOT(extensionInstantiated(MApplicationExtensionInterface *))); connect(manager, SIGNAL(extensionRemoved(MApplicationExtensionInterface *)), &signalListener, SLOT(extensionRemoved(MApplicationExtensionInterface *))); connect(manager, SIGNAL(widgetCreated(QGraphicsWidget*, MDataStore&)), &signalListener, SLOT(widgetCreated(QGraphicsWidget*, MDataStore&))); connect(manager, SIGNAL(widgetRemoved(QGraphicsWidget*)), &signalListener, SLOT(widgetRemoved(QGraphicsWidget*))); connect(this, SIGNAL(extensionChanged( const MDesktopEntry &)), manager, SLOT(updateExtension( const MDesktopEntry &))); }
FsWatcher::FsWatcher(boost::asio::io_service& io, QString dirPath, LocalFile_Change_Callback onChange, LocalFile_Change_Callback onDelete, QObject* parent) : QObject(parent) , m_watcher(new QFileSystemWatcher(this)) , m_scheduler(io) , m_dirPath(dirPath) , m_onChange(onChange) , m_onDelete(onDelete) { _LOG_DEBUG("Monitor dir: " << m_dirPath.toStdString()); // add main directory to monitor initFileStateDb(); m_watcher->addPath(m_dirPath); // register signals(callback functions) connect(m_watcher, SIGNAL(directoryChanged(QString)), this, SLOT(DidDirectoryChanged(QString))); connect(m_watcher, SIGNAL(fileChanged(QString)), this, SLOT(DidFileChanged(QString))); rescheduleEvent("rescan", m_dirPath.toStdString(), time::seconds(0), bind(&FsWatcher::ScanDirectory_NotifyUpdates_Execute, this, m_dirPath)); rescheduleEvent("rescan-r", m_dirPath.toStdString(), time::seconds(0), bind(&FsWatcher::ScanDirectory_NotifyRemovals_Execute, this, m_dirPath)); }
Directory_watcher::Directory_watcher(Core *c) : QObject(0) , Core_ally(c) { connect(&watcher, SIGNAL(directoryChanged(QString)), this, SIGNAL(directory_changed(QString))); fs = core->get_file_system_engine(); }
/*! Creates thread */ RemoteFileInfoGatherer::RemoteFileInfoGatherer(QObject *parent) : AbstractFileInfoGatherer(parent), abort(false) #ifndef QT_NO_FILESYSTEMWATCHER , watcher(0) #endif { qDebug() << "new RemoteFileInfoGatherer"; #ifndef QT_NO_FILESYSTEMWATCHER watcher = new QFileSystemWatcher(this); connect(watcher, SIGNAL(directoryChanged(QString)), this, SLOT(list(QString))); connect(watcher, SIGNAL(fileChanged(QString)), this, SLOT(updateFile(QString))); # if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) const QVariant listener = watcher->property("_q_driveListener"); if (listener.canConvert<QObject *>()) { if (QObject *driveListener = listener.value<QObject *>()) { connect(driveListener, SIGNAL(driveAdded()), this, SLOT(driveAdded())); connect(driveListener, SIGNAL(driveRemoved()), this, SLOT(driveRemoved())); } } # endif // Q_OS_WIN && !Q_OS_WINRT #endif start(LowPriority); emit initialized(); }
void OutputDirectory::selectDir() { QString dir = cDir->currentText(); QString startDir = dir; QString params; int i = dir.indexOf( QRegExp("%[aAbBcCdDfFgGnNpPtTyY]{1,1}") ); if( i != -1 && cMode->currentIndex() == 0 ) { i = dir.lastIndexOf( "/", i ); startDir = dir.left( i ); params = dir.mid( i ); } QString directory = KFileDialog::getExistingDirectory( startDir, this, i18n("Choose an output directory") ); if( !directory.isEmpty() ) { if( i != -1 && cMode->currentIndex() == 0 ) { cDir->setEditText( directory + params ); } else { cDir->setEditText( directory ); } emit directoryChanged( cDir->currentText() ); } }
AppDockWidget::AppDockWidget(MainWindow *main_window, QWidget *parent) : QDockWidget(parent) { ui.setupUi(this); mainwindow = main_window; // 获取当前工作路径 workPath = mainwindow->GetCurrentWorkDir(); // 初始化所有表格和文件 clearAll(); QString signalThreadInfoFile = workPath + "/test/info_threads.txt"; signalThreadInfoWatcher = new QFileSystemWatcher; signalThreadInfoWatcher->addPath(signalThreadInfoFile); connect(signalThreadInfoWatcher, SIGNAL(fileChanged(QString)), this, SLOT(loadThreadInfoData(QString))); connect(signalThreadInfoWatcher, SIGNAL(directoryChanged(QString)), this, SLOT(loadThreadInfoData(QString))); QString signalfromepdb = workPath + "/test/sigtogui.txt"; signalEpdbWatcher = new QFileSystemWatcher; signalEpdbWatcher->addPath(signalfromepdb); connect(signalEpdbWatcher, SIGNAL(fileChanged(QString)), this, SLOT(recieveEpdbSigData(QString))); connect(ui.tabWidget, SIGNAL(currentChanged(int)), this, SLOT(loadTabWidgetData(int))); connect(ui.variableTableWidget, SIGNAL(itemChanged(QTableWidgetItem*)), this, SLOT(modifyVariable(QTableWidgetItem*))); connect(ui.registerTableWidget, SIGNAL(itemChanged(QTableWidgetItem*)), this, SLOT(modifyRegister(QTableWidgetItem*))); signalLoadData = false; datacanread = 0; showtabwidgetclickable = 0; reactvariable = 1; reactregister = 1; }
GlobalShortcutX::GlobalShortcutX() { iXIopcode = -1; bRunning = false; display = XOpenDisplay(NULL); if (! display) { qWarning("GlobalShortcutX: Unable to open dedicated display connection."); return; } #ifdef Q_OS_LINUX if (g.s.bEnableEvdev) { QString dir = QLatin1String("/dev/input"); QFileSystemWatcher *fsw = new QFileSystemWatcher(QStringList(dir), this); connect(fsw, SIGNAL(directoryChanged(const QString &)), this, SLOT(directoryChanged(const QString &))); directoryChanged(dir); if (qsKeyboards.isEmpty()) { foreach(QFile *f, qmInputDevices) delete f; qmInputDevices.clear(); delete fsw; qWarning("GlobalShortcutX: Unable to open any keyboard input devices under /dev/input, falling back to XInput"); } else { return; } }
void Ut_MApplicationExtensionManager::testMonitorRemoveExtensionWithTwoExtensionInstancesFromTheSameExtension() { gDesktopEntryList.clear(); // Fire up a couple of extensions gDesktopEntryList << "test1.desktop" << "test2.desktop"; gDefaultMApplicationExtensionMetaDataStub.stubSetReturnValue("isValid", true); gDefaultMApplicationExtensionMetaDataStub.stubSetReturnValue("interface", interfaceName); gMApplicationExtensionMetaDataStub->stubSetReturnValue("extensionBinary", QString("test")); setupGoodExtension(true, NULL, "extension"); // Put the same extension a second time to the list gQPluginLoaderInstances.append(gQPluginLoaderInstances.first()); setupTestSubject(); // Remove one extension from the file system gDesktopEntryList.clear(); gDesktopEntryList << "test1.desktop"; // Notify about a file system change emit directoryChanged(APPLICATION_EXTENSION_DATA_DIR); // Observe that the correct extension was removed QCOMPARE(signalListener.removedExtensions.count(), 1); QCOMPARE(signalListener.removedExtensions.at(0).second, QString("extension")); }
void IconList::settingChanged(const Setting &setting, QVariant value) { if(setting.id() != "IconsDir") return; directoryChanged(value.toString()); }
void LocalProcess::processError(QProcess::ProcessError t_e) { m_fileCheckTimer.stop(); QFileInfo qfi(toQString(m_tool.localBinPath)); QFileInfo outdirfi(toQString(m_outdir)); LOG(Error, "LocalProcess processError: " << t_e << " exe: " << toString(m_tool.localBinPath) << " workingdir: " << toString(m_outdir) << " fileexists: " << qfi.isFile() << " fileexecutable: " << qfi.isExecutable() << " ErrorValue: " << t_e << " outdirexists: " << outdirfi.isFile() << " outdirisdirectory: " << outdirfi.isDir()); QCoreApplication::processEvents(); directoryChanged(openstudio::toQString(m_outdir)); QProcess::ProcessState state = m_process.state(); if (state != QProcess::Running && t_e == QProcess::WriteError) { LOG(Info, "WriteError occured when process was not running, ignoring it"); } else { //directoryChanged(openstudio::toQString(m_outdir)); emit error(t_e); } }
DriveManager::DriveManager() { fileWatcher = std::make_shared<QFileSystemWatcher>(); fileWatcher->addPath(mediaFolder); QObject::connect(fileWatcher.get(), SIGNAL(directoryChanged(QString)), SLOT(UpdateDriveList())); }
SystemFlagWatcher::SystemFlagWatcher() { CDT = QDateTime::currentDateTime(); watcher = new QFileSystemWatcher(this); connect(watcher, SIGNAL(directoryChanged(QString)), this, SLOT(watcherNotification()) ); connect(watcher, SIGNAL(fileChanged(QString)), this, SLOT(watcherNotification()) ); QTimer::singleShot(1, this, SLOT(watchFlagDir()) ); }
TransferEnginePrivate::TransferEnginePrivate(TransferEngine *parent): m_notificationsEnabled(true), m_settings(CONFIG_PATH, QSettings::IniFormat), q_ptr(parent) { m_fileWatcherTimer = new QTimer(this); m_fileWatcherTimer->setSingleShot(true); connect(m_fileWatcherTimer, SIGNAL(timeout()), this, SLOT(enabledPluginsCheck())); m_fileWatcher = new QFileSystemWatcher(this); m_fileWatcher->addPath(SHARE_PLUGINS_PATH); connect(m_fileWatcher, SIGNAL(directoryChanged(QString)), this, SLOT(pluginDirChanged())); m_accountManager = new Accounts::Manager("sharing", this); connect(m_accountManager, SIGNAL(accountCreated(Accounts::AccountId)), this, SLOT(enabledPluginsCheck())); connect(m_accountManager, SIGNAL(accountRemoved(Accounts::AccountId)), this, SLOT(enabledPluginsCheck())); connect(m_accountManager, SIGNAL(accountUpdated(Accounts::AccountId)), this, SLOT(enabledPluginsCheck())); // Exit safely stuff if we recieve certain signal or there are no active transfers Q_Q(TransferEngine); connect(TransferEngineSignalHandler::instance(), SIGNAL(exitSafely()), this, SLOT(exitSafely())); connect(q, SIGNAL(statusChanged(int,int)), this, SLOT(exitSafely())); // Monitor expired transfers and cleanup them if required m_activityMonitor = new ClientActivityMonitor(this); connect(m_activityMonitor, SIGNAL(transfersExpired(QList<int>)), this, SLOT(cleanupExpiredTransfers(QList<int>))); }
void OwncloudSyncd::addPathsToWatchlist(){ m_watcher = new QFileSystemWatcher(this); QMapIterator<QString, QString> i(m_folderMap); while (i.hasNext()) { i.next(); //qDebug() << i.key() << ": " << i.value() << endl; if(QDir(i.key()).exists()){ m_watcher->addPath(i.key()); //m_watcher->removePath(i.key() + "/.csync_journal.db"); qDebug() << "Directory: " << i.key() << " Added to watchlist"; }else{ qDebug() << "Directory: " << i.key() << " Doesn't exist"; } } int dirs = m_watcher->directories().length(); if(!dirs){ qDebug() << " No Directories Configured - Quitting"; return; //QCoreApplication::quit(); } qDebug() << QString::number(dirs) << " Directories added to watchlist"; connect(m_watcher, SIGNAL(directoryChanged(QString)), this, SLOT(syncFolder(QString))); }
void Folder::checkLocalPath() { QFileInfo fi(_path); if( fi.isDir() && fi.isReadable() ) { qDebug() << "Checked local path ok"; } else { if( !fi.exists() ) { // try to create the local dir QDir d(_path); if( d.mkpath(_path) ) { qDebug() << "Successfully created the local dir " << _path; } } // Check directory again if( !fi.exists() ) { _syncResult.setErrorString(tr("Local folder %1 does not exist.").arg(_path)); _syncResult.setStatus( SyncResult::SetupError ); } else if( !fi.isDir() ) { _syncResult.setErrorString(tr("%1 should be a directory but is not.").arg(_path)); _syncResult.setStatus( SyncResult::SetupError ); } else if( !fi.isReadable() ) { _syncResult.setErrorString(tr("%1 is not readable.").arg(_path)); _syncResult.setStatus( SyncResult::SetupError ); } } // if all is fine, connect a FileSystemWatcher if( _syncResult.status() != SyncResult::SetupError ) { _pathWatcher = new QFileSystemWatcher(this); _pathWatcher->addPath( _path ); connect(_pathWatcher, SIGNAL(directoryChanged(QString)), SLOT(slotLocalPathChanged(QString))); } }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- RimUiTreeModelPdm::RimUiTreeModelPdm(QObject* parent) : caf::UiTreeModelPdm(parent) { m_scriptChangeDetector = new QFileSystemWatcher(this); this->updateScriptPaths(); connect(m_scriptChangeDetector, SIGNAL(directoryChanged(QString)), this, SLOT(slotRefreshScriptTree(QString))); connect(m_scriptChangeDetector, SIGNAL(fileChanged(QString)), this, SLOT(slotRefreshScriptTree(QString))); }
void LocalProcess::processReadyReadStandardOutput() { directoryChanged(openstudio::toQString(m_outdir)); if (!stopped()) { handleOutput(m_process.readAllStandardOutput(), false); } }
AppMenu::AppMenu(QWidget* parent) : QMenu(parent){ appstorelink = "/usr/local/share/applications/softmanager.desktop"; //Default application "store" to display (AppCafe in PC-BSD) APPS.clear(); watcher = new QFileSystemWatcher(this); connect(watcher, SIGNAL(directoryChanged(QString)), this, SLOT(watcherUpdate()) ); QTimer::singleShot(200, this, SLOT(start()) ); //Now start filling the menu this->setTitle(tr("Applications")); }
void fs::watcher(const QString &path){ QFileInfo PATH(path); if(PATH.exists()){ WATCH.addPath(path); connect(&WATCH,SIGNAL(fileChanged(QString)),this,SLOT(SLOT_WATCH(QString))); connect(&WATCH,SIGNAL(directoryChanged(QString)),this,SLOT(SLOT_WATCH(QString))); } }
void FcitxQtConnectionPrivate::finalize() { m_serviceWatcher->removeWatchedService(m_serviceName); m_watcher->removePaths(m_watcher->files()); m_watcher->removePaths(m_watcher->directories()); m_watcher->disconnect(SIGNAL(fileChanged(QString))); m_watcher->disconnect(SIGNAL(directoryChanged(QString))); m_initialized = false; }