Allow referencing directories by their labels in syncthingctl
This commit is contained in:
parent
f865d1ffbc
commit
818b40801a
|
@ -1118,7 +1118,7 @@ RelevantDir Application::findDirectory(const QString &dirIdentifier)
|
|||
// check whether the specified identifier is a known Syncthing directory or a relative path to an item in a
|
||||
// known Syncthing directory
|
||||
auto firstSlash = dirIdentifier.indexOf(QChar('/'));
|
||||
relevantDir.dirObj = m_connection.findDirInfo(firstSlash >= 0 ? dirIdentifier.mid(0, firstSlash) : dirIdentifier, dummy);
|
||||
relevantDir.dirObj = m_connection.findDirInfoConsideringLabels(firstSlash >= 0 ? dirIdentifier.mid(0, firstSlash) : dirIdentifier, dummy);
|
||||
if (relevantDir) {
|
||||
if (firstSlash >= 0) {
|
||||
relevantDir.subDir = dirIdentifier.mid(firstSlash + 1);
|
||||
|
|
|
@ -528,6 +528,28 @@ SyncthingDir *SyncthingConnection::findDirInfo(const QString &dirId, int &row)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Returns the directory info object for the directory with the specified ID or label.
|
||||
* \returns Returns a pointer to the object or nullptr if not found.
|
||||
* \remarks
|
||||
* - IDs have precedence, labels are checked as fallback.
|
||||
* - The returned object becomes invalid when the newDirs() signal is emitted or the connection is destroyed.
|
||||
*/
|
||||
SyncthingDir *SyncthingConnection::findDirInfoConsideringLabels(const QString &dirIdOrLabel, int &row)
|
||||
{
|
||||
if (auto *const dir = findDirInfo(dirIdOrLabel, row)) {
|
||||
return dir;
|
||||
}
|
||||
row = 0;
|
||||
for (SyncthingDir &d : m_dirs) {
|
||||
if (d.label == dirIdOrLabel) {
|
||||
return &d;
|
||||
}
|
||||
++row;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Returns the directory info object for the directory with the ID stored in the specified \a object with the specified \a key.
|
||||
*/
|
||||
|
|
|
@ -181,6 +181,7 @@ public:
|
|||
std::vector<const SyncthingDev *> connectedDevices() const;
|
||||
const QJsonObject &rawConfig() const;
|
||||
SyncthingDir *findDirInfo(const QString &dirId, int &row);
|
||||
SyncthingDir *findDirInfoConsideringLabels(const QString &dirIdOrLabel, int &row);
|
||||
const SyncthingDir *findDirInfo(const QString &dirId, int &row) const;
|
||||
SyncthingDir *findDirInfo(QLatin1String key, const QJsonObject &object, int *row = nullptr);
|
||||
SyncthingDir *findDirInfoByPath(const QString &path, QString &relativePath, int &row);
|
||||
|
|
Loading…
Reference in New Issue