Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge remote-tracking branch 'remotes/origin/master' into savegame-re…
…factor
  • Loading branch information
danij-deng committed Mar 8, 2014
2 parents df918ff + 06ddcd5 commit 59830a3
Show file tree
Hide file tree
Showing 10 changed files with 137 additions and 40 deletions.
3 changes: 1 addition & 2 deletions doomsday/client/include/ui/styledlogsinkformatter.h
Expand Up @@ -42,8 +42,7 @@ class StyledLogSinkFormatter : public de::LogSink::IFormatter
void setOmitSectionIfNonDev(bool omit);

private:
de::LogEntry::Flags _format;
bool _omitSectionIfNonDev;
DENG2_PRIVATE(d)
};

#endif // DENG_CLIENT_STYLEDLOGSINKFORMATTER_H
3 changes: 2 additions & 1 deletion doomsday/client/modules/appconfig.de
Expand Up @@ -35,7 +35,8 @@ def setDefaults(d)
gui.setDefaults(d)

# Additional Log defaults.
d.log.filterBySubsystem = False
d.log.filterBySubsystem = False
d.log.showMetadata = False
record d.alert
d.alert.generic = Log.WARNING
d.alert.resource = Log.WARNING
Expand Down
9 changes: 8 additions & 1 deletion doomsday/client/src/ui/dialogs/logsettingsdialog.cpp
Expand Up @@ -48,6 +48,7 @@ DENG2_PIMPL(LogSettingsDialog)
{
ui::ListData levels;
VariableToggleWidget *separately;
VariableToggleWidget *metadata;
FoldPanelWidget *fold;
GridLayout foldLayout;
IndirectRule *columnWidth; ///< Sync column width in and out of the fold.
Expand All @@ -72,6 +73,10 @@ DENG2_PIMPL(LogSettingsDialog)
new VariableToggleWidget(tr("Filter by Subsystem"),
App::config()["log.filterBySubsystem"]));

self.area().add(metadata =
new VariableToggleWidget(tr("Show Metadata"),
App::config()["log.showMetadata"]));

levels << new ChoiceItem( tr("1 - X.Verbose"), LogEntry::XVerbose)
<< new ChoiceItem( tr("2 - Verbose"), LogEntry::Verbose )
<< new ChoiceItem( tr("3 - Message"), LogEntry::Message )
Expand Down Expand Up @@ -230,7 +235,9 @@ LogSettingsDialog::LogSettingsDialog(String const &name)
<< *d->domWidgets[0].alert
<< Const(0);
layout.append(*d->separately, 3);
layout.append(*d->fold, 4);
layout.append(*d->fold, 4)
<< Const(0);
layout.append(*d->metadata, 3);

// Fold's layout is complete.
d->fold->content().rule().setSize(d->foldLayout.width(), d->foldLayout.height());
Expand Down
68 changes: 55 additions & 13 deletions doomsday/client/src/ui/styledlogsinkformatter.cpp
Expand Up @@ -17,29 +17,71 @@
*/

#include "ui/styledlogsinkformatter.h"
#include <de/Variable>
#include <de/Value>
#include <de/App>

using namespace de;

StyledLogSinkFormatter::StyledLogSinkFormatter()
: _omitSectionIfNonDev(true)
static char const *VAR_METADATA = "log.showMetadata";

DENG2_PIMPL(StyledLogSinkFormatter)
, DENG2_OBSERVES(Variable, Change)
{
_format = LogEntry::Styled | LogEntry::OmitLevel;
LogEntry::Flags format;
bool observe;
bool omitSectionIfNonDev;
bool showMetadata;

Instance(Public *i, bool observeVars)
: Base(i)
, observe(observeVars)
, omitSectionIfNonDev(true)
, showMetadata(false)
{
if(observe)
{
showMetadata = App::config().getb(VAR_METADATA);
App::config()[VAR_METADATA].audienceForChange() += this;
}
}

#ifndef _DEBUG
// No metadata in release builds.
_format |= LogEntry::Simple | LogEntry::OmitDomain;
#endif
~Instance()
{
if(observe)
{
App::config()[VAR_METADATA].audienceForChange() -= this;
}
}

void variableValueChanged(Variable &, Value const &newValue)
{
showMetadata = newValue.isTrue();
}
};

StyledLogSinkFormatter::StyledLogSinkFormatter()
: d(new Instance(this, true /*observe*/))
{
d->format = LogEntry::Styled | LogEntry::OmitLevel;
}

StyledLogSinkFormatter::StyledLogSinkFormatter(LogEntry::Flags const &formatFlags)
: _format(formatFlags),
_omitSectionIfNonDev(true)
{}
: d(new Instance(this, false /*don't observe*/))
{
d->format = formatFlags;
}

LogSink::IFormatter::Lines StyledLogSinkFormatter::logEntryToTextLines(LogEntry const &entry)
{
LogEntry::Flags form = _format;
if(_omitSectionIfNonDev && !(entry.context() & LogEntry::Dev))
LogEntry::Flags form = d->format;

if(!d->showMetadata)
{
form |= LogEntry::Simple | LogEntry::OmitDomain;
}

if(d->omitSectionIfNonDev && !(entry.context() & LogEntry::Dev))
{
// The sections refer to names of native code functions, etc.
// These are relevant only to developers. Non-dev messages must be
Expand All @@ -54,5 +96,5 @@ LogSink::IFormatter::Lines StyledLogSinkFormatter::logEntryToTextLines(LogEntry

void StyledLogSinkFormatter::setOmitSectionIfNonDev(bool omit)
{
_omitSectionIfNonDev = omit;
d->omitSectionIfNonDev = omit;
}
2 changes: 2 additions & 0 deletions doomsday/libdeng2/include/de/core/app.h
Expand Up @@ -234,6 +234,8 @@ class DENG2_PUBLIC App : DENG2_OBSERVES(Clock, TimeChange)
*/
static Archive &persistentData();

static bool hasPersistentData();

/**
* Returns the application's current native working directory.
*/
Expand Down
11 changes: 9 additions & 2 deletions doomsday/libdeng2/include/de/core/logbuffer.h
Expand Up @@ -150,12 +150,19 @@ class DENG2_PUBLIC LogBuffer : public QObject, public Lockable, DENG2_OBSERVES(F
*/
void enableFlushing(bool yes = true);

enum OutputChangeBehavior {
FlushFirstToOldOutputs,
DontFlush
};

/**
* Sets the path of the file used for writing log entries to.
*
* @param path Path of the file.
* @param path Path of the file.
* @param behavior What to do with existing unflushed entries.
*/
void setOutputFile(String const &path);
void setOutputFile(String const &path,
OutputChangeBehavior behavior = FlushFirstToOldOutputs);

/**
* Returns the path of the file used for log output.
Expand Down
5 changes: 5 additions & 0 deletions doomsday/libdeng2/src/core/app.cpp
Expand Up @@ -446,6 +446,11 @@ Archive &App::persistentData()
return *persist;
}

bool App::hasPersistentData()
{
return DENG2_APP->d->persistentData != 0;
}

NativePath App::currentWorkPath()
{
return NativePath::workPath();
Expand Down
24 changes: 16 additions & 8 deletions doomsday/libdeng2/src/core/config.cpp
Expand Up @@ -93,19 +93,27 @@ void Config::read()
LOG_DEBUG("Found serialized Config:\n") << names();

// If the saved config is from a different version, rerun the script.
Value const &oldVersion = names()["__version__"].value();
d->setOldVersion(oldVersion);
if(oldVersion.compare(*version))
if(names().has("__version__"))
{
// Version mismatch: store the old version in a separate variable.
d->config.globals().add(new Variable("__oldversion__", oldVersion.duplicate(),
Value const &oldVersion = names()["__version__"].value();
d->setOldVersion(oldVersion);
if(oldVersion.compare(*version))
{
// Version mismatch: store the old version in a separate variable.
d->config.globals().add(new Variable("__oldversion__", oldVersion.duplicate(),
Variable::AllowArray | Variable::ReadOnly));
shouldRunScript = true;
shouldRunScript = true;
}
else
{
// Versions match.
LOG_MSG("") << d->refuge.path() << " matches version " << version->asText();
}
}
else
{
// Versions match.
LOG_MSG("") << d->refuge.path() << " matches version " << version->asText();
// Don't know what version this is, run script to be sure.
shouldRunScript = true;
}

// Also check the timestamp of written config vs. the config script.
Expand Down
36 changes: 26 additions & 10 deletions doomsday/libdeng2/src/core/logbuffer.cpp
Expand Up @@ -80,6 +80,7 @@ DENG2_PIMPL_NOREF(LogBuffer)
, outSink(QtDebugMsg)
, errSink(QtWarningMsg)
#endif
, lastFlushedAt(Time::invalidTime())
, autoFlushTimer(0)
{
// Standard output enabled by default.
Expand All @@ -96,6 +97,23 @@ DENG2_PIMPL_NOREF(LogBuffer)
delete fileLogSink;
}

void enableAutoFlush(bool yes)
{
DENG2_ASSERT(qApp);
if(yes)
{
if(!autoFlushTimer->isActive())
{
// Every now and then the buffer will be flushed.
autoFlushTimer->start(FLUSH_INTERVAL * 1000);
}
}
else
{
autoFlushTimer->stop();
}
}

void disposeFileLogSink()
{
if(fileLogSink)
Expand Down Expand Up @@ -190,20 +208,13 @@ void LogBuffer::add(LogEntry *entry)

// We will not flush the new entry as it likely has not yet been given
// all its arguments.
if(d->lastFlushedAt.since() > FLUSH_INTERVAL)
if(d->lastFlushedAt.isValid() && d->lastFlushedAt.since() > FLUSH_INTERVAL)
{
flush();
}

d->entries.push_back(entry);
d->toBeFlushed.push_back(entry);

// Should we start autoflush?
if(!d->autoFlushTimer->isActive() && qApp)
{
// Every now and then the buffer will be flushed.
d->autoFlushTimer->start(FLUSH_INTERVAL * 1000);
}
}

void LogBuffer::enableStandardOutput(bool yes)
Expand All @@ -219,13 +230,18 @@ void LogBuffer::enableStandardOutput(bool yes)
void LogBuffer::enableFlushing(bool yes)
{
d->flushingEnabled = yes;
d->enableAutoFlush(true);
}

void LogBuffer::setOutputFile(String const &path)
void LogBuffer::setOutputFile(String const &path, OutputChangeBehavior behavior)
{
DENG2_GUARD(this);

flush();
if(behavior == FlushFirstToOldOutputs)
{
flush();
}

d->disposeFileLogSink();

if(d->outputFile)
Expand Down
16 changes: 13 additions & 3 deletions doomsday/libdeng2/src/data/refuge.cpp
Expand Up @@ -66,17 +66,27 @@ Refuge::~Refuge()

void Refuge::read()
{
Reader(App::persistentData().entryBlock(d->persistentPath)).withHeader() >> d->names;
if(App::hasPersistentData())
{
Reader(App::persistentData().entryBlock(d->persistentPath)).withHeader() >> d->names;
}
}

void Refuge::write() const
{
Writer(App::persistentData().entryBlock(d->persistentPath)).withHeader() << d->names;
if(App::hasPersistentData())
{
Writer(App::persistentData().entryBlock(d->persistentPath)).withHeader() << d->names;
}
}

Time Refuge::lastWrittenAt() const
{
return App::persistentData().entryStatus(d->persistentPath).modifiedAt;
if(App::hasPersistentData())
{
return App::persistentData().entryStatus(d->persistentPath).modifiedAt;
}
return Time::invalidTime();
}

Record &Refuge::names()
Expand Down

0 comments on commit 59830a3

Please sign in to comment.