connector: Add method to find dir by path

This commit is contained in:
Martchus 2017-10-16 19:41:56 +02:00
parent 34924e011e
commit 40465a8abb
2 changed files with 28 additions and 2 deletions

View File

@ -520,7 +520,32 @@ SyncthingDir *SyncthingConnection::findDirInfo(const QString &dirId, int &row)
}
++row;
}
return nullptr; // TODO: dir is unknown, trigger refreshing the config
return nullptr;
}
/*!
* \brief Returns the directory info object for the directory with the specified \a path.
*
* If a corresponding Syncthing directory could be found, \a relativePath is set to the path of the item relative
* to the location of the corresponding Syncthing directory.
*
* \returns Returns a pointer to the object or nullptr if not found.
* \remarks The returned object becomes invalid when the newDirs() signal is emitted or the connection is destroyed.
*/
SyncthingDir *SyncthingConnection::findDirInfoByPath(const QString &path, QString &relativePath, int &row)
{
row = 0;
for (SyncthingDir &dir : m_dirs) {
if (path == dir.pathWithoutTrailingSlash()) {
relativePath.clear();
return &dir;
} else if (path.startsWith(dir.path)) {
relativePath = path.mid(dir.path.size());
return &dir;
}
++row;
}
return nullptr;
}
/*!
@ -559,7 +584,7 @@ SyncthingDev *SyncthingConnection::findDevInfo(const QString &devId, int &row)
}
++row;
}
return nullptr; // TODO: dev is unknown, trigger refreshing the config
return nullptr;
}
/*!

View File

@ -119,6 +119,7 @@ public:
QMetaObject::Connection requestLog(std::function<void(const std::vector<SyncthingLogEntry> &)> callback);
const QList<QSslError> &expectedSslErrors();
SyncthingDir *findDirInfo(const QString &dirId, int &row);
SyncthingDir *findDirInfoByPath(const QString &path, QString &relativePath, int &row);
SyncthingDev *findDevInfo(const QString &devId, int &row);
SyncthingDev *findDevInfoByName(const QString &devName, int &row);
const std::vector<SyncthingDir *> &completedDirs() const;