EntryProvider: Introduce isSavable() to avoid code duplicates

This commit is contained in:
Albert S. 2020-10-08 22:39:41 +02:00
parent 38cc87fbcd
commit ac5498990b
2 changed files with 8 additions and 2 deletions

View File

@ -13,6 +13,11 @@ EntryProvider::EntryProvider(QStringList userEntriesDirsPaths, QStringList syste
<< "%u";
}
bool EntryProvider::isSavable(const EntryConfig &config) const
{
return ! config.entryPath.isEmpty() && (config.type == EntryType::USER || config.type == EntryType::INHERIT);
}
EntryConfig EntryProvider::readFromDesktopFile(const QString &path)
{
EntryConfig result;
@ -285,7 +290,7 @@ QVector<EntryConfig> EntryProvider::getSystemEntries()
void EntryProvider::saveUserEntry(const EntryConfig &config)
{
if(config.type == EntryType::SYSTEM || config.entryPath.isEmpty())
if(!isSavable(config))
{
throw std::runtime_error("Only user/inherited entries can be saved");
}
@ -339,7 +344,7 @@ void EntryProvider::saveUserEntry(const EntryConfig &config)
bool EntryProvider::deleteUserEntry(const EntryConfig &config)
{
if(config.type == EntryType::SYSTEM || config.entryPath.isEmpty())
if(!isSavable(config))
{
throw std::runtime_error("Only user/inherited entries can be deleted");
}

View File

@ -55,6 +55,7 @@ class EntryProvider
public:
EntryProvider(QStringList userEntriesDirsPaths, QStringList systemEntriesDirsPaths);
bool isSavable(const EntryConfig &config) const;
QVector<EntryConfig> getUserEntries();
QVector<EntryConfig> getSystemEntries();
void saveUserEntry(const EntryConfig &config);