diff --git a/src/contentmanager.h b/src/contentmanager.h index ad3bfe92..ae283a2e 100644 --- a/src/contentmanager.h +++ b/src/contentmanager.h @@ -16,6 +16,7 @@ class ContentManager : public QObject Q_PROPERTY(QStringList bookIds READ getBookIds NOTIFY booksChanged) Q_PROPERTY(QStringList downloadIds READ getDownloadIds NOTIFY downloadsChanged) Q_PROPERTY(QString currentLanguage MEMBER m_currentLanguage WRITE setCurrentLanguage NOTIFY currentLangChanged) + Q_PROPERTY(bool isLocal MEMBER m_local READ isLocal WRITE setLocal NOTIFY localChanged) public: typedef QList> LanguageList; @@ -66,6 +67,7 @@ class ContentManager : public QObject void pendingRequest(const bool); void categoriesLoaded(QStringList); void languagesLoaded(LanguageList); + void localChanged(const bool); public slots: QStringList getTranslations(const QStringList &keys); diff --git a/src/contentmanagerside.cpp b/src/contentmanagerside.cpp index 4dfe5752..d2da4bc5 100644 --- a/src/contentmanagerside.cpp +++ b/src/contentmanagerside.cpp @@ -12,17 +12,19 @@ ContentManagerSide::ContentManagerSide(QWidget *parent) : mp_ui(new Ui::contentmanagerside) { mp_ui->setupUi(this); - connect(mp_ui->allFileButton, &QRadioButton::toggled, - this, [=](bool checked) { this->mp_contentManager->setLocal(!checked); }); - connect(mp_ui->localFileButton, &QRadioButton::toggled, - this, [=](bool checked) { this->mp_contentManager->setLocal(checked); }); + mp_ui->buttonGroup->setId(mp_ui->allFileButton, CatalogButtonId::ALL); + mp_ui->buttonGroup->setId(mp_ui->localFileButton, CatalogButtonId::LOCAL); + connect(mp_ui->buttonGroup, QOverload::of(&QButtonGroup::buttonClicked), [=](QAbstractButton *btn) { + const auto id = mp_ui->buttonGroup->id(btn); + mp_contentManager->setLocal(id == CatalogButtonId::LOCAL); + }); + connect(mp_ui->allFileButton, &QRadioButton::toggled, this, [=](bool checked) { mp_ui->allFileButton->setStyleSheet( checked ? "*{font-weight: bold}" : "");}); connect(mp_ui->localFileButton, &QRadioButton::toggled, this, [=](bool checked) { mp_ui->localFileButton->setStyleSheet( checked ?"*{font-weight: bold}" : "");}); - mp_ui->localFileButton->setStyleSheet("*{font-weight: bold}"); mp_ui->allFileButton->setText(gt("online-files")); mp_ui->localFileButton ->setText(gt("local-files")); @@ -105,6 +107,10 @@ ContentManagerSide::~ContentManagerSide() void ContentManagerSide::setContentManager(ContentManager *contentManager) { mp_contentManager = contentManager; + const auto isLocal = mp_contentManager->isLocal(); + const auto checkedButton = mp_ui->buttonGroup->button(isLocal == CatalogButtonId::LOCAL); + checkedButton->setChecked(true); + checkedButton->setStyleSheet("*{font-weight: bold}"); connect(mp_languageSelector, &QListWidget::itemSelectionChanged, this, [=]() { auto item = mp_languageSelector->selectedItems().at(0); diff --git a/src/contentmanagerside.h b/src/contentmanagerside.h index bc21494a..5af981d9 100644 --- a/src/contentmanagerside.h +++ b/src/contentmanagerside.h @@ -16,6 +16,10 @@ class ContentManagerSide : public QWidget Q_OBJECT public: + enum CatalogButtonId { + ALL = 0, + LOCAL = 1 + }; explicit ContentManagerSide(QWidget *parent = 0); ~ContentManagerSide(); diff --git a/src/contentmanagerside.ui b/src/contentmanagerside.ui index 4136b90e..9dfd13b4 100644 --- a/src/contentmanagerside.ui +++ b/src/contentmanagerside.ui @@ -79,6 +79,9 @@ All Files + + buttonGroup + @@ -95,6 +98,9 @@ true + + buttonGroup + @@ -258,4 +264,7 @@ + + + diff --git a/src/kiwixapp.cpp b/src/kiwixapp.cpp index 568b7d57..eff5b07c 100644 --- a/src/kiwixapp.cpp +++ b/src/kiwixapp.cpp @@ -64,6 +64,7 @@ void KiwixApp::init() gt("error-downloader-launch-message") + "

" + e.what()); } mp_manager = new ContentManager(&m_library, mp_downloader); + mp_manager->setLocal(!m_library.getBookIds().isEmpty()); auto icon = QIcon(); icon.addFile(":/icons/kiwix-app-icons-square.svg");