Qt: Initial logging throughout

This commit is contained in:
Jeffrey Pfau 2015-07-04 01:24:37 -07:00
parent ebca878c31
commit 016b64bf15
11 changed files with 44 additions and 1 deletions

View File

@ -5,6 +5,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "AudioDevice.h"
#include "LogController.h"
extern "C" {
#include "gba/gba.h"
#include "gba/audio.h"
@ -24,6 +26,7 @@ AudioDevice::AudioDevice(QObject* parent)
void AudioDevice::setFormat(const QAudioFormat& format) {
if (!m_context || !GBAThreadIsActive(m_context)) {
LOG(INFO) << tr("Can't set format of context-less audio device");
return;
}
#if RESAMPLE_LIBRARY == RESAMPLE_NN
@ -49,6 +52,7 @@ qint64 AudioDevice::readData(char* data, qint64 maxSize) {
}
if (!m_context->gba) {
LOG(WARN) << tr("Audio device is missing its GBA");
return 0;
}
@ -68,5 +72,6 @@ qint64 AudioDevice::readData(char* data, qint64 maxSize) {
}
qint64 AudioDevice::writeData(const char*, qint64) {
LOG(WARN) << tr("Writing data to read-only audio device");
return 0;
}

View File

@ -6,6 +6,7 @@
#include "AudioProcessorQt.h"
#include "AudioDevice.h"
#include "LogController.h"
#include <QAudioOutput>
@ -34,6 +35,7 @@ void AudioProcessorQt::setInput(GBAThread* input) {
void AudioProcessorQt::start() {
if (!input()) {
LOG(WARN) << tr("Can't start an audio processor without input");
return;
}

View File

@ -5,6 +5,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "AudioProcessorSDL.h"
#include "LogController.h"
extern "C" {
#include "gba/supervisor/thread.h"
}
@ -23,6 +25,7 @@ AudioProcessorSDL::~AudioProcessorSDL() {
void AudioProcessorSDL::start() {
if (!input()) {
LOG(WARN) << tr("Can't start an audio processor without input");
return;
}

View File

@ -5,6 +5,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "CheatsModel.h"
#include "LogController.h"
#include "VFileDevice.h"
#include <QFont>
@ -203,6 +204,7 @@ void CheatsModel::endAppendRow() {
void CheatsModel::loadFile(const QString& path) {
VFile* vf = VFileDevice::open(path, O_RDONLY);
if (!vf) {
LOG(WARN) << tr("Failed to open cheats file: %1").arg(path);
return;
}
beginResetModel();

View File

@ -8,6 +8,7 @@
#ifdef USE_MAGICK
#include "GBAApp.h"
#include "LogController.h"
#include <QMap>
@ -34,6 +35,7 @@ GIFView::~GIFView() {
void GIFView::startRecording() {
if (!ImageMagickGIFEncoderOpen(&m_encoder, m_filename.toUtf8().constData())) {
LOG(ERROR) << tr("Failed to open output GIF file: %1").arg(m_filename);
return;
}
m_ui.start->setEnabled(false);

View File

@ -224,6 +224,7 @@ void GameController::loadGame(const QString& path, bool dirmode) {
if (!dirmode) {
QFile file(path);
if (!file.open(QIODevice::ReadOnly)) {
postLog(GBA_LOG_ERROR, tr("Failed to open game file: %1").arg(path));
return;
}
file.close();
@ -338,6 +339,7 @@ void GameController::importSharkport(const QString& path) {
}
VFile* vf = VFileDevice::open(path, O_RDONLY);
if (!vf) {
postLog(GBA_LOG_ERROR, tr("Failed to open snapshot file for reading: %1").arg(path));
return;
}
threadInterrupt();
@ -352,6 +354,7 @@ void GameController::exportSharkport(const QString& path) {
}
VFile* vf = VFileDevice::open(path, O_WRONLY | O_CREAT | O_TRUNC);
if (!vf) {
postLog(GBA_LOG_ERROR, tr("Failed to open snapshot file for writing: %1").arg(path));
return;
}
threadInterrupt();

View File

@ -7,10 +7,22 @@
using namespace QGBA;
LogController LogController::s_global(GBA_LOG_ALL);
LogController::LogController(int levels, QObject* parent)
: QObject(parent)
, m_logLevel(levels)
{
if (this != &s_global) {
connect(&s_global, SIGNAL(logPosted(int, const QString&)), this, SLOT(postLog(int, const QString&)));
connect(this, SIGNAL(levelsSet(int)), &s_global, SLOT(setLevels(int)));
connect(this, SIGNAL(levelsEnabled(int)), &s_global, SLOT(enableLevels(int)));
connect(this, SIGNAL(levelsDisabled(int)), &s_global, SLOT(disableLevels(int)));
}
}
LogController::Stream LogController::operator()(int level) {
return Stream(this, level);
}
void LogController::postLog(int level, const QString& string) {
@ -35,6 +47,10 @@ void LogController::disableLevels(int levels) {
emit levelsDisabled(levels);
}
LogController* LogController::global() {
return &s_global;
}
QString LogController::toString(int level) {
switch (level) {
case GBA_LOG_DEBUG:

View File

@ -40,6 +40,7 @@ public:
Stream operator()(int level);
static LogController* global();
static QString toString(int level);
signals:
@ -56,8 +57,12 @@ public slots:
private:
int m_logLevel;
static LogController s_global;
};
#define LOG(L) (*LogController::global())(GBA_LOG_ ## L)
}
#endif

View File

@ -7,6 +7,7 @@
#include "GBAApp.h"
#include "GameController.h"
#include "LogController.h"
#include <QAction>
#include <QApplication>
@ -153,7 +154,7 @@ void MemoryModel::save() {
}
QFile outfile(filename);
if (!outfile.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
// TODO: Log
LOG(WARN) << tr("Failed to open output file: %1").arg(filename);
return;
}
QDataStream stream(&outfile);

View File

@ -6,6 +6,7 @@
#include "PaletteView.h"
#include "GBAApp.h"
#include "LogController.h"
#include "VFileDevice.h"
#include <QFileDialog>
@ -93,6 +94,7 @@ void PaletteView::exportPalette(int start, int length) {
QString filename = dialog->selectedFiles()[0];
VFile* vf = VFileDevice::open(filename, O_WRONLY | O_CREAT | O_TRUNC);
if (!vf) {
LOG(ERROR) << tr("Failed to open output palette file: %1").arg(filename);
m_controller->threadContinue();
return;
}

View File

@ -8,6 +8,7 @@
#ifdef USE_FFMPEG
#include "GBAApp.h"
#include "LogController.h"
#include <QMap>
@ -198,6 +199,7 @@ void VideoView::startRecording() {
return;
}
if (!FFmpegEncoderOpen(&m_encoder, m_filename.toUtf8().constData())) {
LOG(ERROR) << tr("Failed to open output video file: %1").arg(m_filename);
return;
}
m_ui.start->setEnabled(false);