Skip to content

Commit

Permalink
Refactor assigning folder type using hash map
Browse files Browse the repository at this point in the history
  • Loading branch information
Martchus committed Jul 16, 2024
1 parent 9b38569 commit c0217f8
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions syncthingconnector/syncthingdir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,17 +154,16 @@ bool SyncthingDir::assignStatus(const QString &statusStr, SyncthingEventId event

bool SyncthingDir::assignDirType(const QString &dirTypeStr)
{
if (dirTypeStr == QLatin1String("sendreceive") || dirTypeStr == QLatin1String("readwrite")) {
dirType = SyncthingDirType::SendReceive;
} else if (dirTypeStr == QLatin1String("sendonly") || dirTypeStr == QLatin1String("readonly")) {
dirType = SyncthingDirType::SendOnly;
} else if (dirTypeStr == QLatin1String("receiveonly")) {
dirType = SyncthingDirType::ReceiveOnly;
} else {
dirType = SyncthingDirType::Unknown;
return false;
}
return true;
static const auto typeMapping = QHash<QString, SyncthingDirType>{
{QStringLiteral("sendreceive"), SyncthingDirType::SendReceive},
{QStringLiteral("readwrite"), SyncthingDirType::SendReceive},
{QStringLiteral("sendonly"), SyncthingDirType::SendOnly},
{QStringLiteral("readonly"), SyncthingDirType::SendOnly},
{QStringLiteral("receiveonly"), SyncthingDirType::ReceiveOnly},
};
const auto i = typeMapping.find(dirTypeStr);
dirType = i != typeMapping.cend() ? *i : SyncthingDirType::Unknown;
return dirType != SyncthingDirType::Unknown;
}

QString SyncthingDir::statusString() const
Expand Down

0 comments on commit c0217f8

Please sign in to comment.