Commit 662c29b3 authored by Martin Tobias Holmedahl Sandsmark's avatar Martin Tobias Holmedahl Sandsmark
Browse files

Make it possible to shut up gwenview with e.g. kdebugdialog

exiv2 lets us register a log handler, so it's fairly straight forward to
put our own that maps it to qC{Warning,Debug,Info} with a proper
category. This allows people who're not interested in exiv2 spam turn it
off.

It only shows "Critical" by default, so supress everything, the warning
messages aren't really useful and the "real" error messages are already
stored in Exiv2ImageLoader.

Differential Revision: https://phabricator.kde.org/D28376
parent 1dda9f48
......@@ -181,6 +181,7 @@ set(gwenviewlib_SRCS
)
ecm_qt_declare_logging_category(gwenviewlib_SRCS HEADER gwenview_lib_debug.h IDENTIFIER GWENVIEW_LIB_LOG CATEGORY_NAME org.kde.kdegraphics.gwenview.lib)
ecm_qt_declare_logging_category(gwenviewlib_SRCS HEADER gwenview_exiv2_debug.h IDENTIFIER GWENVIEW_EXIV2_LOG CATEGORY_NAME org.kde.kdegraphics.gwenview.exiv2 DEFAULT_SEVERITY Critical)
if(HAVE_QTDBUS)
set(gwenviewlib_SRCS
......
......@@ -32,6 +32,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include <exiv2/exiv2.hpp>
// Local
#include "gwenview_exiv2_debug.h"
namespace Gwenview
{
......@@ -42,9 +43,37 @@ struct Exiv2ImageLoaderPrivate
QString mErrorMessage;
};
struct Exiv2LogHandler {
static void handleMessage(int level, const char *message) {
switch(level) {
case Exiv2::LogMsg::debug:
qCDebug(GWENVIEW_EXIV2_LOG) << message;
break;
case Exiv2::LogMsg::info:
qCInfo(GWENVIEW_EXIV2_LOG) << message;
break;
case Exiv2::LogMsg::warn:
case Exiv2::LogMsg::error:
case Exiv2::LogMsg::mute:
qCWarning(GWENVIEW_EXIV2_LOG) << message;
break;
default:
qCWarning(GWENVIEW_EXIV2_LOG) << "unhandled log level" << level << message;
break;
}
}
Exiv2LogHandler() {
Exiv2::LogMsg::setHandler(&Exiv2LogHandler::handleMessage);
}
};
Exiv2ImageLoader::Exiv2ImageLoader()
: d(new Exiv2ImageLoaderPrivate)
{
// This is a threadsafe way to ensure that we only register it once
static Exiv2LogHandler handler;
}
Exiv2ImageLoader::~Exiv2ImageLoader()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment