mirror of
https://github.com/clementine-player/Clementine
synced 2025-01-31 19:45:31 +01:00
Update each provider's logged-in state in the global search settings dialog when returning to the global search page.
This commit is contained in:
parent
37166ca19d
commit
1946011919
@ -92,26 +92,37 @@ void GlobalSearchSettingsPage::AddProviderItem(GlobalSearch* engine,
|
||||
QTreeWidgetItem* item = new QTreeWidgetItem;
|
||||
item->setText(0, provider->name());
|
||||
item->setIcon(0, provider->icon());
|
||||
item->setData(0, Qt::UserRole, QVariant::fromValue(provider));
|
||||
|
||||
UpdateLoggedInState(engine, item, true);
|
||||
|
||||
ui_->sources->invisibleRootItem()->addChild(item);
|
||||
}
|
||||
|
||||
void GlobalSearchSettingsPage::UpdateLoggedInState(GlobalSearch* engine,
|
||||
QTreeWidgetItem* item,
|
||||
bool set_checked_state) {
|
||||
SearchProvider* provider = item->data(0, Qt::UserRole).value<SearchProvider*>();
|
||||
|
||||
const bool enabled = engine->is_provider_enabled(provider);
|
||||
const bool logged_in = provider->IsLoggedIn();
|
||||
|
||||
if (!logged_in) {
|
||||
item->setData(0, Qt::CheckStateRole, Qt::Unchecked);
|
||||
Qt::CheckState check_state = logged_in && enabled ? Qt::Checked : Qt::Unchecked;
|
||||
Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
||||
if (logged_in)
|
||||
flags |= Qt::ItemIsUserCheckable;
|
||||
|
||||
if (set_checked_state)
|
||||
item->setData(0, Qt::CheckStateRole, check_state);
|
||||
item->setFlags(flags);
|
||||
|
||||
if (logged_in) {
|
||||
item->setIcon(1, QIcon());
|
||||
item->setText(1, QString());
|
||||
} else {
|
||||
item->setIcon(1, warning_icon_);
|
||||
item->setText(1, tr("Not logged in") + " ");
|
||||
item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
|
||||
} else if (enabled) {
|
||||
item->setData(0, Qt::CheckStateRole, Qt::Checked);
|
||||
item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable);
|
||||
} else {
|
||||
item->setData(0, Qt::CheckStateRole, Qt::Unchecked);
|
||||
item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable);
|
||||
}
|
||||
|
||||
item->setData(0, Qt::UserRole, QVariant::fromValue(provider));
|
||||
|
||||
ui_->sources->invisibleRootItem()->addChild(item);
|
||||
}
|
||||
|
||||
void GlobalSearchSettingsPage::Save() {
|
||||
@ -186,3 +197,15 @@ void GlobalSearchSettingsPage::CurrentProviderChanged(QTreeWidgetItem* item) {
|
||||
ui_->down->setEnabled(row != root->childCount() - 1);
|
||||
ui_->configure->setEnabled(provider->can_show_config());
|
||||
}
|
||||
|
||||
void GlobalSearchSettingsPage::showEvent(QShowEvent* e) {
|
||||
QWidget::showEvent(e);
|
||||
|
||||
// Update the logged-in state of each item when we come back to this page in
|
||||
// the dialog.
|
||||
for (int i = 0 ; i < ui_->sources->invisibleRootItem()->childCount() ; ++i) {
|
||||
UpdateLoggedInState(dialog()->global_search(),
|
||||
ui_->sources->invisibleRootItem()->child(i),
|
||||
false);
|
||||
}
|
||||
}
|
||||
|
@ -39,6 +39,9 @@ public:
|
||||
void Load();
|
||||
void Save();
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent* e);
|
||||
|
||||
private slots:
|
||||
void MoveUp();
|
||||
void MoveDown();
|
||||
@ -48,6 +51,8 @@ private slots:
|
||||
|
||||
private:
|
||||
void AddProviderItem(GlobalSearch* engine, SearchProvider* provider);
|
||||
void UpdateLoggedInState(GlobalSearch* engine, QTreeWidgetItem* item,
|
||||
bool set_checked_state);
|
||||
void MoveCurrentItem(int d);
|
||||
|
||||
private:
|
||||
|
@ -2708,7 +2708,7 @@ msgstr ""
|
||||
msgid "Not installed"
|
||||
msgstr ""
|
||||
|
||||
#: globalsearch/globalsearchsettingspage.cpp:102
|
||||
#: globalsearch/globalsearchsettingspage.cpp:124
|
||||
msgid "Not logged in"
|
||||
msgstr ""
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user