strawberry-audio-player-win.../3rdparty/taglib/toolkit/tdebuglistener.cpp

81 lines
2.7 KiB
C++
Raw Normal View History

2018-05-10 15:29:28 +02:00
/***************************************************************************
copyright : (C) 2013 by Tsuda Kageyu
email : tsuda.kageyu@gmail.com
***************************************************************************/
/***************************************************************************
* This library is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License version *
* 2.1 as published by the Free Software Foundation. *
* *
* This library is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library; if not, write to the Free Software *
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA *
* 02110-1301 USA *
* *
* Alternatively, this file is available under the Mozilla Public *
* License Version 1.1. You may obtain a copy of the License at *
* http://www.mozilla.org/MPL/ *
***************************************************************************/
#include "tdebuglistener.h"
#include <iostream>
#include <bitset>
#ifdef _WIN32
2020-06-13 19:02:42 +02:00
# include <windows.h>
2018-05-10 15:29:28 +02:00
#endif
using namespace Strawberry_TagLib::TagLib;
2018-05-10 15:29:28 +02:00
2020-06-13 19:02:42 +02:00
namespace {
class DefaultListener : public DebugListener {
public:
2020-06-15 21:55:05 +02:00
void printMessage(const String &msg) override {
2018-05-10 15:29:28 +02:00
#ifdef _WIN32
2020-06-13 19:02:42 +02:00
const wstring wstr = msg.toWString();
const int len = WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), -1, NULL, 0, NULL, NULL);
if (len != 0) {
std::vector<char> buf(len);
WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), -1, &buf[0], len, NULL, NULL);
2018-05-10 15:29:28 +02:00
2020-06-13 19:02:42 +02:00
std::cerr << std::string(&buf[0]);
}
2018-05-10 15:29:28 +02:00
#else
2020-06-13 19:02:42 +02:00
std::cerr << msg;
2018-05-10 15:29:28 +02:00
2020-06-13 19:02:42 +02:00
#endif
}
};
2018-05-10 15:29:28 +02:00
2020-06-13 19:02:42 +02:00
DefaultListener defaultListener;
} // namespace
2018-05-10 15:29:28 +02:00
2019-04-26 01:12:42 +02:00
namespace Strawberry_TagLib {
2020-06-13 19:02:42 +02:00
namespace TagLib {
DebugListener *debugListener = &defaultListener;
2018-05-10 15:29:28 +02:00
DebugListener::DebugListener() {}
2018-05-10 15:29:28 +02:00
DebugListener::~DebugListener() {}
2020-06-13 19:02:42 +02:00
void setDebugListener(DebugListener *listener) {
2020-06-13 19:02:42 +02:00
if (listener)
debugListener = listener;
else
debugListener = &defaultListener;
2019-04-26 01:12:42 +02:00
}
2020-06-13 19:02:42 +02:00
} // namespace TagLib
} // namespace Strawberry_TagLib