EntryProvider: Introduce isSavable() to avoid code duplicates

Este commit está contenido en:
Albert S. 2020-10-08 22:39:41 +02:00
padre 38cc87fbcd
commit ac5498990b
Se han modificado 2 ficheros con 8 adiciones y 2 borrados

Ver fichero

@ -13,6 +13,11 @@ EntryProvider::EntryProvider(QStringList userEntriesDirsPaths, QStringList syste
<< "%u"; << "%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 EntryProvider::readFromDesktopFile(const QString &path)
{ {
EntryConfig result; EntryConfig result;
@ -285,7 +290,7 @@ QVector<EntryConfig> EntryProvider::getSystemEntries()
void EntryProvider::saveUserEntry(const EntryConfig &config) 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"); 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) 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"); throw std::runtime_error("Only user/inherited entries can be deleted");
} }

Ver fichero

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