Skip to content

Commit

Permalink
UI|Client: Cleanup and fixes in the Log Filter settings dialog
Browse files Browse the repository at this point in the history
Now the App’s LogFilter is updated when values are changed in the
widgets.
  • Loading branch information
skyjake committed Jan 7, 2014
1 parent 2daa256 commit fb03a38
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 20 deletions.
1 change: 1 addition & 0 deletions doomsday/client/include/ui/dialogs/logsettingsdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class LogSettingsDialog : public DialogWidget

public slots:
void resetToDefaults();
void updateLogFilter();

private:
DENG2_PRIVATE(d)
Expand Down
3 changes: 1 addition & 2 deletions doomsday/client/src/ui/dialogs/alertdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,7 @@ void AlertDialog::showLogFilterSettings()
st->setAnchorAndOpeningDirection(buttonWidget(DialogWidget::Id1)->rule(), ui::Left);
st->setDeleteAfterDismissed(true);
connect(this, SIGNAL(closed()), st, SLOT(close()));
root().add(st);
st->open();
st->exec(root());
}

void AlertDialog::finish(int result)
Expand Down
66 changes: 48 additions & 18 deletions doomsday/client/src/ui/dialogs/logsettingsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ DENG2_PIMPL(LogSettingsDialog)
VariableToggleWidget *separately;
FoldPanelWidget *fold;
GridLayout foldLayout;
IndirectRule *columnWidth; ///< Sync column width in and out of the fold.
struct DomainWidgets
{
LabelWidget *label;
Expand All @@ -65,17 +66,19 @@ DENG2_PIMPL(LogSettingsDialog)
{
zap(domWidgets);

columnWidth = new IndirectRule;

self.area().add(separately =
new VariableToggleWidget(tr("Filter by Subsystem"),
App::config()["log.filterBySubsystem"]));

levels << new ChoiceItem( tr("1 - XVerbose"), LogEntry::XVerbose)
<< new ChoiceItem( tr("2 - Verbose"), LogEntry::Verbose )
<< new ChoiceItem( tr("3 - Message"), LogEntry::Message )
<< new ChoiceItem( tr("4 - Note"), LogEntry::Note )
<< new ChoiceItem(_E(D) + tr("5 - Warning"), LogEntry::Warning )
<< new ChoiceItem(_E(D) + tr("6 - Error"), LogEntry::Error )
<< new ChoiceItem(_E(D) + tr("7 - Critical"), LogEntry::Critical);
levels << new ChoiceItem(_E(C) + tr("1 - X.Verbose"), LogEntry::XVerbose)
<< new ChoiceItem(_E(C) + tr("2 - Verbose"), LogEntry::Verbose )
<< new ChoiceItem( tr("3 - Message"), LogEntry::Message )
<< new ChoiceItem( tr("4 - Note"), LogEntry::Note )
<< new ChoiceItem(_E(D) + tr("5 - Warning"), LogEntry::Warning )
<< new ChoiceItem(_E(D) + tr("6 - Error"), LogEntry::Error )
<< new ChoiceItem(_E(D) + tr("7 - Critical"), LogEntry::Critical);

// Folding panel for the per-domain settings.
self.area().add(fold = new FoldPanelWidget);
Expand All @@ -85,6 +88,7 @@ DENG2_PIMPL(LogSettingsDialog)
foldLayout.setLeftTop(fold->content().rule().left(),
fold->content().rule().top());
foldLayout.setGridSize(4, 0);
foldLayout.setColumnFixedWidth(1, *columnWidth);
foldLayout.setColumnAlignment(0, ui::AlignRight);

for(uint i = 0; i < NUM_DOMAINS; ++i)
Expand All @@ -94,6 +98,9 @@ DENG2_PIMPL(LogSettingsDialog)
i == 0? &self.area() : &fold->content());
}

// This'll keep the dialog's size fixed even though the choices change size.
columnWidth->setSource(domWidgets[0].level->maximumWidth());

separately->audienceForToggle += this;
}
catch(Error const &er)
Expand All @@ -104,6 +111,12 @@ DENG2_PIMPL(LogSettingsDialog)
}
}

~Instance()
{
deinit();
releaseRef(columnWidth);
}

void initDomain(DomainText const &dom, DomainWidgets &wgt, GuiWidget *parent)
{
// Text label.
Expand All @@ -112,12 +125,16 @@ DENG2_PIMPL(LogSettingsDialog)
// Minimum level for log entries.
parent->add(wgt.level =
new VariableChoiceWidget(App::config()[String("log.filter.%1.minLevel").arg(dom.name)]));
wgt.level->popup().menu().setItems(levels);
wgt.level->setItems(levels);
wgt.level->updateFromVariable();
QObject::connect(wgt.level, SIGNAL(selectionChangedByUser(uint)),
thisPublic, SLOT(updateLogFilter()));

// Developer messages?
parent->add(wgt.dev =
new VariableToggleWidget(tr("Dev"), App::config()[String("log.filter.%1.allowDev").arg(dom.name)]));
QObject::connect(wgt.dev, SIGNAL(stateChangedByUser(ToggleWidget::ToggleState)),
thisPublic, SLOT(updateLogFilter()));

// Raise alerts?
parent->add(wgt.alert =
Expand All @@ -132,19 +149,14 @@ DENG2_PIMPL(LogSettingsDialog)
}
}

~Instance()
{
deinit();
}

void deinit()
{
// The common 'levels' will be deleted soon.
for(uint i = 0; i < NUM_DOMAINS; ++i)
{
if(domWidgets[i].level)
{
domWidgets[i].level->popup().menu().useDefaultItems();
domWidgets[i].level->useDefaultItems();
}
}
}
Expand All @@ -155,9 +167,9 @@ DENG2_PIMPL(LogSettingsDialog)
LogFilter &logf = App::logFilter();

// Check the generic filter settings.
LogEntry::Level minLevel = logf.minLevel(0);
bool allowDev = logf.allowDev(0);
bool alerts = cfg.getb("alert.generic");
LogEntry::Level minLevel = LogEntry::Level(domWidgets[0].level->selectedItem().data().toInt());
bool allowDev = domWidgets[0].dev->isActive();
bool alerts = domWidgets[0].alert->isActive();

// Override the individual filters with the generic one.
logf.setMinLevel(LogEntry::AllDomains, minLevel);
Expand All @@ -168,14 +180,15 @@ DENG2_PIMPL(LogSettingsDialog)
for(uint i = 0; i < NUM_DOMAINS; ++i)
{
char const *name = domainText[i].name;
cfg.set(String("alert.") + name, alerts);
cfg.set(String("alert.") + name, int(alerts? LogEntry::Warning : LogEntry::MAX_LOG_LEVELS));
}
}

void toggleStateChanged(ToggleWidget &toggle)
{
if(toggle.isActive())
{
overrideWithGeneric();
fold->open();
}
else
Expand All @@ -184,6 +197,17 @@ DENG2_PIMPL(LogSettingsDialog)
overrideWithGeneric();
}
}

void updateLogFilter()
{
if(separately->isInactive())
{
overrideWithGeneric();
}

// Re-read from Config, which has been changed via the widgets.
App::logFilter().read(App::config().names().subrecord("log.filter"));
}
};

LogSettingsDialog::LogSettingsDialog(String const &name)
Expand All @@ -194,6 +218,7 @@ LogSettingsDialog::LogSettingsDialog(String const &name)
// Layout.
GridLayout layout(area().contentRule().left(), area().contentRule().top());
layout.setGridSize(4, 0);
layout.setColumnFixedWidth(1, *d->columnWidth);
layout.setColumnAlignment(0, ui::AlignRight);

layout << *d->domWidgets[0].label
Expand Down Expand Up @@ -221,3 +246,8 @@ LogSettingsDialog::LogSettingsDialog(String const &name)
void LogSettingsDialog::resetToDefaults()
{
}

void LogSettingsDialog::updateLogFilter()
{
d->updateLogFilter();
}

0 comments on commit fb03a38

Please sign in to comment.