Save provider enabled/disabled state and order

This commit is contained in:
David Sansome 2011-10-30 23:30:47 +00:00
parent 85ea3fe37f
commit 246b14d677
4 changed files with 46 additions and 7 deletions

View File

@ -261,10 +261,18 @@ void GlobalSearch::ReloadSettings() {
s.beginGroup(kSettingsGroup);
foreach (SearchProvider* provider, providers_.keys()) {
QVariant value = s.value(provider->id());
if (value.isValid()) {
providers_state_preference_.insert(provider->id(), value.toBool());
providers_[provider].enabled_ = value.toBool() && provider->IsLoggedIn();
QVariant value = s.value("enabled_" + provider->id());
if (!value.isValid())
continue;
providers_state_preference_.insert(provider->id(), value.toBool());
const bool old_state = providers_[provider].enabled_;
const bool new_state = value.toBool() && provider->IsLoggedIn();
if (old_state != new_state) {
providers_[provider].enabled_ = new_state;
emit ProviderToggled(provider, new_state);
}
}
}
@ -273,6 +281,6 @@ void GlobalSearch::SaveProvidersSettings() {
QSettings s;
s.beginGroup(kSettingsGroup);
foreach (SearchProvider* provider, providers_.keys()) {
s.setValue(provider->id(), providers_[provider].enabled_);
s.setValue("enabled_" + provider->id(), providers_[provider].enabled_);
}
}

View File

@ -115,7 +115,27 @@ void GlobalSearchSettingsPage::AddProviderItem(GlobalSearch* engine,
}
void GlobalSearchSettingsPage::Save() {
QSettings s;
s.beginGroup(GlobalSearch::kSettingsGroup);
QStringList provider_order;
for (int i=0 ; i<ui_->sources->invisibleRootItem()->childCount() ; ++i) {
const QTreeWidgetItem* item = ui_->sources->invisibleRootItem()->child(i);
const SearchProvider* provider = item->data(0, Qt::UserRole).value<SearchProvider*>();
provider_order << provider->id();
s.setValue("enabled_" + provider->id(),
item->data(0, Qt::CheckStateRole).toInt() == Qt::Checked);
}
s.setValue("provider_order", provider_order);
s.setValue("show_globalsearch", ui_->show_globalsearch->isChecked());
s.setValue("hide_others", ui_->hide_others->isChecked() && ui_->show_globalsearch->isChecked());
s.setValue("combine_identical_results", ui_->combine->isChecked());
s.setValue("tooltip", ui_->tooltip->isChecked());
s.setValue("tooltip_help", ui_->tooltip_help->isChecked());
}
void GlobalSearchSettingsPage::MoveUp() {

View File

@ -148,6 +148,8 @@ void GlobalSearchWidget::Init(GlobalSearch* engine) {
SLOT(ProviderAdded(const SearchProvider*)));
connect(engine_, SIGNAL(ProviderRemoved(const SearchProvider*)),
SLOT(ProviderRemoved(const SearchProvider*)));
connect(engine_, SIGNAL(ProviderToggled(const SearchProvider*,bool)),
SLOT(ProviderToggled(const SearchProvider*,bool)));
// Take all the ProviderAdded signals we missed.
foreach (const SearchProvider* provider, engine_->providers()) {
@ -728,7 +730,7 @@ void GlobalSearchWidget::ProviderAdded(const SearchProvider* provider) {
// Find the appropriate insertion point.
bool inserted = false;
for (int i = 0; i < ui_->provider_layout->count(); ++i) {
const QToolButton* item_button = static_cast<QToolButton*>(
QToolButton* item_button = static_cast<QToolButton*>(
ui_->provider_layout->itemAt(i)->widget());
if (!item_button) {
@ -776,3 +778,11 @@ void GlobalSearchWidget::ProviderButtonToggled(bool on) {
button->toggle();
}
}
void GlobalSearchWidget::ProviderToggled(const SearchProvider* provider, bool on) {
QToolButton* button = provider_buttons_.left.find(provider)->second;
if (!button)
return;
button->setChecked(on);
}

View File

@ -98,6 +98,7 @@ private slots:
void ProviderAdded(const SearchProvider* provider);
void ProviderRemoved(const SearchProvider* provider);
void ProviderButtonToggled(bool on);
void ProviderToggled(const SearchProvider* provider, bool on);
private:
// Return values from CanCombineResults
@ -161,7 +162,7 @@ private:
QAction* replace_and_play_;
QList<QAction*> actions_;
typedef boost::bimap<const SearchProvider*, const QToolButton*> ProviderButtonMap;
typedef boost::bimap<const SearchProvider*, QToolButton*> ProviderButtonMap;
typedef ProviderButtonMap::value_type ProviderButton;
ProviderButtonMap provider_buttons_;
};