Skip to content

Commit

Permalink
Merge pull request #989 from kiwix/autoOnline
Browse files Browse the repository at this point in the history
  • Loading branch information
mgautierfr authored Sep 11, 2023
2 parents 7557378 + ad1648a commit 8159343
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/contentmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<QPair<QString, QString>> LanguageList;
Expand Down Expand Up @@ -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);
Expand Down
16 changes: 11 additions & 5 deletions src/contentmanagerside.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<QAbstractButton *>::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"));
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions src/contentmanagerside.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ class ContentManagerSide : public QWidget
Q_OBJECT

public:
enum CatalogButtonId {
ALL = 0,
LOCAL = 1
};
explicit ContentManagerSide(QWidget *parent = 0);
~ContentManagerSide();

Expand Down
9 changes: 9 additions & 0 deletions src/contentmanagerside.ui
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@
<property name="text">
<string>All Files</string>
</property>
<attribute name="buttonGroup">
<string notr="true">buttonGroup</string>
</attribute>
</widget>
</item>
<item>
Expand All @@ -95,6 +98,9 @@
<property name="checked">
<bool>true</bool>
</property>
<attribute name="buttonGroup">
<string notr="true">buttonGroup</string>
</attribute>
</widget>
</item>
<item>
Expand Down Expand Up @@ -258,4 +264,7 @@
</widget>
<resources/>
<connections/>
<buttongroups>
<buttongroup name="buttonGroup"/>
</buttongroups>
</ui>
1 change: 1 addition & 0 deletions src/kiwixapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ void KiwixApp::init()
gt("error-downloader-launch-message") + "<br><br>" + 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");
Expand Down

0 comments on commit 8159343

Please sign in to comment.