FilesystemChangesRunnable::~FilesystemChangesRunnable() { stopWatching(); delete m_section; m_section = NULL; }
bool NodeMonitor::watch(MString nodeName) { // if already watching another object, release the callbacks. stopWatching(); fNodeName = nodeName; return attachCallbacks(); }
void GeometryResourceWatcher::setResource(GeometryResource::Pointer resource) { if (_resource) { stopWatching(); } _resource = resource; if (_resource) { if (_resource->isLoaded()) { resourceFinished(true); } else { startWatching(); } } }
// Remove any DAG object not in the selectedObjects list. void ShapeMonitor::stopWatchingUnselectedDagObjects(MSelectionList& selectedObjects) { // For each monitored object... for (int i = monitoredObjectsPtrArray.length()-1; i >= 0; i--) { MonitoredObject *pMonObject = monitoredObjectsPtrArray[i]; MStatus stat; // Get an MObject for the MonitoredObject->mayaNodeName. MDagPath dagpath; MSelectionList selList; selList.add(pMonObject->mayaNodeName); stat = selList.getDagPath(0, dagpath); // If the MObject is a DAG node... if (stat) { bool found = false; // Check if the dag path is included in the selectedObjects list. // For example, say that dagpath = "|group1|group2|pSphere|pSphereShape", // selectedObjects contains "|group1|group2". // We first check if dagpath is included in selectedObjects. If that's not the // case, we pop() one component, so that dagpath = "|group1|group2|pSphere", then // check again. We do that until either the dagpath is found to be included in // the selectedObjects list, or until there's no component left in dagpath. while (!found && dagpath.length() > 0) { // Since we store the shape name (as opposed to the parent transform dagpath), // we need to pop() to get the parent transform dagpath. dagpath.pop(); MObject component; // Check if the dag path is included in the objects list. if (selectedObjects.hasItemPartly(dagpath, component)) found = true; } // If the object was not in the selectedObjects list, stop watching it. if (!found) stopWatching(pMonObject->mayaNodeName); } } }
void DBusWatch::startWatching() { if(!dbus_watch_get_enabled(libdbusWatch_)) stopWatching(); unsigned int channelFlags_ = dbus_watch_get_flags(libdbusWatch_); short int pollFlags = POLLERR | POLLHUP; if(channelFlags_ & DBUS_WATCH_READABLE) { pollFlags |= POLLIN; } if(channelFlags_ & DBUS_WATCH_WRITABLE) { pollFlags |= POLLOUT; } pollFileDescriptor_.fd = dbus_watch_get_unix_fd(libdbusWatch_); pollFileDescriptor_.events = pollFlags; pollFileDescriptor_.revents = 0; auto lockedContext = mainLoopContext_.lock(); assert(lockedContext); lockedContext->registerWatch(this); }
// @Runner thread void FilesystemChangesRunnable::run() { while ( !m_stop ) { if ( m_restartPending ) { stopWatching(); startWatching(); m_restartPending = false; } if ( m_initialized ) { processChanges(); } // let the other threads do some processing Thread::yield(); } }
bool NodeMonitor::watch(MObject nodeObj) { MString newNodeName = getNameFromObj(nodeObj); // If already watching another object, release the callbacks. stopWatching(); // Get the name of the given object... since an MObject is not // persistent. We'll use the name of the object to attach/re-attach // callbacks when necessary. if (newNodeName == "") { // This is bad. We've been given an invalid node object. // return false to indicate that an error occured. return false; } fNodeName = newNodeName; return attachCallbacks(); }
bool ModList::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) { if (action == Qt::IgnoreAction) return true; // check if the action is supported if (!data || !(action & supportedDropActions())) return false; if (parent.isValid()) { row = parent.row(); column = parent.column(); } if (row > rowCount()) row = rowCount(); if (row == -1) row = rowCount(); if (column == -1) column = 0; QLOG_INFO() << "Drop row: " << row << " column: " << column; // files dropped from outside? if (data->hasUrls()) { bool was_watching = is_watching; if (was_watching) stopWatching(); auto urls = data->urls(); for (auto url : urls) { // only local files may be dropped... if (!url.isLocalFile()) continue; QString filename = url.toLocalFile(); installMod(filename, row); QLOG_INFO() << "installing: " << filename; // if there is no ordering, re-sort the list if (m_list_file.isEmpty()) { beginResetModel(); std::sort(mods.begin(), mods.end(), [](const Mod & left, const Mod & right) { return left.name().localeAwareCompare(right.name()) <= 0; }); endResetModel(); } } if (was_watching) startWatching(); return true; } else if (data->hasText()) { QString sourcestr = data->text(); auto list = sourcestr.split('|'); if (list.size() != 2) return false; QString remoteId = list[0]; int remoteIndex = list[1].toInt(); QLOG_INFO() << "move: " << sourcestr; // no moving of things between two lists if (remoteId != m_list_id) return false; // no point moving to the same place... if (row == remoteIndex) return false; // otherwise, move the mod :D moveModTo(remoteIndex, row); return true; } return false; }
GenericWatcher::~GenericWatcher() { stopWatching(); }
NodeMonitor::~NodeMonitor() { stopWatching(); }
void IconList::directoryChanged(const QString &path) { QDir new_dir (path); if(m_dir.absolutePath() != new_dir.absolutePath()) { m_dir.setPath(path); m_dir.refresh(); if(is_watching) stopWatching(); startWatching(); } if(!m_dir.exists()) if(!ensureFolderPathExists(m_dir.absolutePath())) return; m_dir.refresh(); auto new_list = m_dir.entryList(QDir::Files, QDir::Name); for (auto it = new_list.begin(); it != new_list.end(); it++) { QString &foo = (*it); foo = m_dir.filePath(foo); } auto new_set = new_list.toSet(); QList<QString> current_list; for (auto &it : icons) { if (!it.has(MMCIcon::FileBased)) continue; current_list.push_back(it.m_images[MMCIcon::FileBased].filename); } QSet<QString> current_set = current_list.toSet(); QSet<QString> to_remove = current_set; to_remove -= new_set; QSet<QString> to_add = new_set; to_add -= current_set; for (auto remove : to_remove) { QLOG_INFO() << "Removing " << remove; QFileInfo rmfile(remove); QString key = rmfile.baseName(); int idx = getIconIndex(key); if (idx == -1) continue; icons[idx].remove(MMCIcon::FileBased); if (icons[idx].type() == MMCIcon::ToBeDeleted) { beginRemoveRows(QModelIndex(), idx, idx); icons.remove(idx); reindex(); endRemoveRows(); } else { dataChanged(index(idx), index(idx)); } m_watcher->removePath(remove); emit iconUpdated(key); } for (auto add : to_add) { QLOG_INFO() << "Adding " << add; QFileInfo addfile(add); QString key = addfile.baseName(); if (addIcon(key, QString(), addfile.filePath(), MMCIcon::FileBased)) { m_watcher->addPath(add); emit iconUpdated(key); } } }