More readable access to the settings manager

This commit is contained in:
Veloman Yunkan 2024-02-18 17:41:50 +04:00
parent d196ceb063
commit 98f4064c26

View File

@ -26,6 +26,12 @@
namespace namespace
{ {
SettingsManager* getSettingsManager()
{
return KiwixApp::instance()->getSettingsManager();
}
class ContentManagerError : public std::runtime_error class ContentManagerError : public std::runtime_error
{ {
public: public:
@ -108,9 +114,9 @@ ContentManager::ContentManager(Library* library, kiwix::Downloader* downloader,
treeView->setColumnWidth(5, 120); treeView->setColumnWidth(5, 120);
// TODO: set width for all columns based on viewport // TODO: set width for all columns based on viewport
setCurrentLanguage(KiwixApp::instance()->getSettingsManager()->getLanguageList()); setCurrentLanguage(getSettingsManager()->getLanguageList());
setCurrentCategoryFilter(KiwixApp::instance()->getSettingsManager()->getCategoryList()); setCurrentCategoryFilter(getSettingsManager()->getCategoryList());
setCurrentContentTypeFilter(KiwixApp::instance()->getSettingsManager()->getContentType()); setCurrentContentTypeFilter(getSettingsManager()->getContentType());
connect(mp_library, &Library::booksChanged, this, [=]() {emit(this->booksChanged());}); connect(mp_library, &Library::booksChanged, this, [=]() {emit(this->booksChanged());});
connect(this, &ContentManager::filterParamsChanged, this, &ContentManager::updateLibrary); connect(this, &ContentManager::filterParamsChanged, this, &ContentManager::updateLibrary);
connect(this, &ContentManager::booksChanged, this, [=]() { connect(this, &ContentManager::booksChanged, this, [=]() {
@ -534,7 +540,7 @@ const kiwix::Book& ContentManager::getRemoteOrLocalBook(const QString &id)
std::string ContentManager::startDownload(const kiwix::Book& book) std::string ContentManager::startDownload(const kiwix::Book& book)
{ {
auto downloadPath = KiwixApp::instance()->getSettingsManager()->getDownloadDir(); auto downloadPath = getSettingsManager()->getDownloadDir();
checkEnoughStorageAvailable(book, downloadPath); checkEnoughStorageAvailable(book, downloadPath);
typedef std::vector<std::pair<std::string, std::string>> DownloadOptions; typedef std::vector<std::pair<std::string, std::string>> DownloadOptions;
@ -601,7 +607,7 @@ void ContentManager::reallyEraseBook(const QString& id, bool moveToTrash)
} else { } else {
emit(oneBookChanged(id)); emit(oneBookChanged(id));
} }
KiwixApp::instance()->getSettingsManager()->deleteSettings(id); getSettingsManager()->deleteSettings(id);
emit booksChanged(); emit booksChanged();
} }
@ -609,7 +615,7 @@ void ContentManager::eraseBook(const QString& id)
{ {
auto text = gt("delete-book-text"); auto text = gt("delete-book-text");
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) #if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
const auto moveToTrash = KiwixApp::instance()->getSettingsManager()->getMoveToTrash(); const auto moveToTrash = getSettingsManager()->getMoveToTrash();
#else #else
const auto moveToTrash = false; // we do not support move to trash functionality for qt versions below 5.15 const auto moveToTrash = false; // we do not support move to trash functionality for qt versions below 5.15
#endif #endif
@ -712,7 +718,7 @@ void ContentManager::setCurrentLanguage(FilterList langPairList)
if (m_currentLanguage == newLanguage) if (m_currentLanguage == newLanguage)
return; return;
m_currentLanguage = newLanguage; m_currentLanguage = newLanguage;
KiwixApp::instance()->getSettingsManager()->setLanguage(langPairList); getSettingsManager()->setLanguage(langPairList);
emit(currentLangChanged()); emit(currentLangChanged());
emit(filterParamsChanged()); emit(filterParamsChanged());
} }
@ -727,7 +733,7 @@ void ContentManager::setCurrentCategoryFilter(FilterList categoryPairList)
if (m_categoryFilter == categoryList.join(",")) if (m_categoryFilter == categoryList.join(","))
return; return;
m_categoryFilter = categoryList.join(","); m_categoryFilter = categoryList.join(",");
KiwixApp::instance()->getSettingsManager()->setCategory(categoryPairList); getSettingsManager()->setCategory(categoryPairList);
emit(filterParamsChanged()); emit(filterParamsChanged());
} }
@ -738,7 +744,7 @@ void ContentManager::setCurrentContentTypeFilter(FilterList contentTypeFiltersPa
contentTypeFilters.append(ctfPair.second); contentTypeFilters.append(ctfPair.second);
} }
m_contentTypeFilters = contentTypeFilters; m_contentTypeFilters = contentTypeFilters;
KiwixApp::instance()->getSettingsManager()->setContentType(contentTypeFiltersPairList); getSettingsManager()->setContentType(contentTypeFiltersPairList);
emit(filterParamsChanged()); emit(filterParamsChanged());
} }