/***************************************************************************
- * Copyright (C) 2005-08 by the Quassel Project *
+ * Copyright (C) 2005-09 by the Quassel Project *
* devel@quassel-irc.org *
* *
* This program is free software; you can redistribute it and/or modify *
#include "settingsdlg.h"
+#include "client.h"
+#include "iconloader.h"
+
SettingsDlg::SettingsDlg(QWidget *parent)
: QDialog(parent),
_currentPage(0)
{
+ ui.setupUi(this);
setModal(true);
setAttribute(Qt::WA_DeleteOnClose, true);
- ui.setupUi(this);
+ setWindowIcon(SmallIcon("configure"));
updateGeometry();
connect(ui.settingsTree, SIGNAL(itemSelectionChanged()), this, SLOT(itemSelected()));
connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton *)), this, SLOT(buttonClicked(QAbstractButton *)));
+
+ connect(Client::instance(), SIGNAL(coreConnectionStateChanged(bool)), SLOT(coreConnectionStateChanged()));
+
+ setButtonStates();
+}
+
+void SettingsDlg::coreConnectionStateChanged() {
+ for(int i = 0; i < ui.settingsTree->topLevelItemCount(); i++) {
+ QTreeWidgetItem *catItem = ui.settingsTree->topLevelItem(i);
+ for(int j = 0; j < catItem->childCount(); j++) {
+ QTreeWidgetItem *item = catItem->child(j);
+ setItemState(item);
+ }
+ setItemState(catItem);
+ }
+}
+
+void SettingsDlg::setItemState(QTreeWidgetItem *item) {
+ SettingsPage *sp = qobject_cast<SettingsPage *>(item->data(0, SettingsPageRole).value<QObject *>());
+ Q_ASSERT(sp);
+ item->setDisabled(!Client::isConnected() && sp->needsCoreConnection());
}
void SettingsDlg::registerSettingsPage(SettingsPage *sp) {
if(!cats.count()) {
cat = new QTreeWidgetItem(ui.settingsTree, QStringList(sp->category()));
cat->setExpanded(true);
- cat->setFlags(Qt::ItemIsEnabled);
+ cat->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
} else {
cat = cats[0];
}
- QTreeWidgetItem *item = new QTreeWidgetItem(cat, QStringList(sp->title()));
- item->setData(0, SettingsPageRole, qVariantFromValue<QObject *>(sp));
+
+ QTreeWidgetItem *item;
+ if(sp->title().isEmpty())
+ item = cat;
+ else
+ item = new QTreeWidgetItem(cat, QStringList(sp->title()));
+
+ item->setData(0, SettingsPageRole, QVariant::fromValue<QObject *>(sp));
+ ui.settingsTree->setMinimumWidth(ui.settingsTree->header()->sectionSizeHint(0) + 5);
pageIsLoaded[sp] = false;
+ if(!ui.settingsTree->selectedItems().count())
+ ui.settingsTree->setCurrentItem(item);
+
+ setItemState(item);
}
void SettingsDlg::selectPage(SettingsPage *sp) {
}
if(sp != currentPage()) {
- ui.pageTitle->setText(sp->title());
+ if(sp->title().isEmpty()) {
+ ui.pageTitle->setText(sp->category());
+ setWindowTitle(tr("Configure %1").arg(sp->category()));
+ }
+ else {
+ ui.pageTitle->setText(sp->title());
+ setWindowTitle(tr("Configure %1").arg(sp->title()));
+ }
+
ui.settingsStack->setCurrentWidget(sp);
_currentPage = sp;
}