Exemplo n.º 1
0
void DefinitionWatcher::startWatchingPath(const DefinitionNode *root, const string &path, bool init_diff) {
    DefinitionNode *node = root->findByPath(path);
    if (node) {
        startWatching(node, init_diff);
    } else {
        Logs::warning("Definition") << "Node not found for watching : " << path << endl;
    }
}
Exemplo n.º 2
0
void GeometryResourceWatcher::setResource(GeometryResource::Pointer resource) {
    if (_resource) {
        stopWatching();
    }
    _resource = resource;
    if (_resource) {
        if (_resource->isLoaded()) {
            resourceFinished(true);
        } else {
            startWatching();
        }
    }
}
Exemplo n.º 3
0
ModelerCameras::ModelerCameras(MainModelerWindow *parent)
    : QObject(parent), DefinitionWatcher("ModelerCameras"), parent(parent) {
    render = new CameraDefinition();
    topdown = new CameraDefinition();
    current = new CameraDefinition();
    tool = new CameraDefinition();
    previous = render;
    active = render;
    tool_mode = TOOL_NONE;

    // Watch GUI choice
    parent->connectQmlSignal("camera_choice", SIGNAL(stateChanged(QString)), this, SLOT(changeActiveCamera(QString)));
    parent->connectQmlSignal("ui", SIGNAL(mainToolChanged(QString)), this, SLOT(toolChanged(QString)));

    // Watch definition changes
    startWatching(parent->getScenery(), "/atmosphere/sun/phi");
    startWatching(parent->getScenery(), "/atmosphere/sun/theta");

    // Validate to apply initial camera to scenery
    validate();

    // Start update timer
    startTimer(50);
}
Exemplo n.º 4
0
// @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();
   }
}
Exemplo n.º 5
0
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;
}
Exemplo n.º 6
0
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);
		}
	}
}