start moving to qt5 style logging

This commit is contained in:
arcan1s
2015-08-29 00:58:39 +03:00
parent 466faf53fa
commit aacb50c946
44 changed files with 598 additions and 516 deletions

View File

@ -20,7 +20,6 @@
#include <KI18n/KLocalizedString>
#include <QDebug>
#include <QDir>
#include <QJsonDocument>
#include <QJsonParseError>
@ -28,18 +27,21 @@
#include <QNetworkRequest>
#include <QSettings>
#include <pdebug/pdebug.h>
#include <qreplytimeout/qreplytimeout.h>
#include "awdebug.h"
#include "version.h"
ExtWeather::ExtWeather(QWidget *parent, const QString weatherName,
const QStringList directories, const bool debugCmd)
: AbstractExtItem(parent, weatherName, directories, debugCmd),
debug(debugCmd),
ui(new Ui::ExtWeather)
{
// logging
const_cast<QLoggingCategory &>(LOG_ESM()).setEnabled(QtMsgType::QtDebugMsg, debugCmd);
qSetMessagePattern(LOG_FORMAT);
readConfiguration();
ui->setupUi(this);
translate();
@ -58,7 +60,7 @@ ExtWeather::ExtWeather(QWidget *parent, const QString weatherName,
ExtWeather::~ExtWeather()
{
if (debug) qDebug() << PDEBUG;
qCDebug(LOG_ESM);
disconnect(manager, SIGNAL(finished(QNetworkReply *)),
this, SLOT(weatherReplyReceived(QNetworkReply *)));
@ -70,10 +72,10 @@ ExtWeather::~ExtWeather()
ExtWeather *ExtWeather::copy(const QString fileName, const int number)
{
if (debug) qDebug() << PDEBUG;
qCDebug(LOG_ESM);
ExtWeather *item = new ExtWeather(static_cast<QWidget *>(parent()), fileName,
directories(), debug);
directories(), LOG_ESM().isDebugEnabled());
item->setActive(isActive());
item->setApiVersion(apiVersion());
item->setCity(city());
@ -90,8 +92,8 @@ ExtWeather *ExtWeather::copy(const QString fileName, const int number)
QString ExtWeather::weatherFromInt(const int _id) const
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "ID" << _id;
qCDebug(LOG_ESM);
qCDebug(LOG_ESM) << "ID" << _id;
// refer to http://openweathermap.org/weather-conditions
QString weather;
@ -190,7 +192,7 @@ QString ExtWeather::weatherFromInt(const int _id) const
QString ExtWeather::city() const
{
if (debug) qDebug() << PDEBUG;
qCDebug(LOG_ESM);
return m_city;
}
@ -198,7 +200,7 @@ QString ExtWeather::city() const
QString ExtWeather::country() const
{
if (debug) qDebug() << PDEBUG;
qCDebug(LOG_ESM);
return m_country;
}
@ -206,7 +208,7 @@ QString ExtWeather::country() const
int ExtWeather::ts() const
{
if (debug) qDebug() << PDEBUG;
qCDebug(LOG_ESM);
return m_ts;
}
@ -214,7 +216,7 @@ int ExtWeather::ts() const
QString ExtWeather::uniq() const
{
if (debug) qDebug() << PDEBUG;
qCDebug(LOG_ESM);
return QString("%1 (%2) at %3").arg(m_city).arg(m_country).arg(m_ts);
}
@ -222,8 +224,8 @@ QString ExtWeather::uniq() const
void ExtWeather::setCity(const QString _city)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "City" << _city;
qCDebug(LOG_ESM);
qCDebug(LOG_ESM) << "City" << _city;
m_city = _city;
}
@ -231,8 +233,8 @@ void ExtWeather::setCity(const QString _city)
void ExtWeather::setCountry(const QString _country)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Country" << _country;
qCDebug(LOG_ESM);
qCDebug(LOG_ESM) << "Country" << _country;
m_country = _country;
}
@ -240,8 +242,8 @@ void ExtWeather::setCountry(const QString _country)
void ExtWeather::setTs(const int _ts)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Timestamp" << _ts;
qCDebug(LOG_ESM);
qCDebug(LOG_ESM) << "Timestamp" << _ts;
m_ts = _ts;
}
@ -249,7 +251,7 @@ void ExtWeather::setTs(const int _ts)
void ExtWeather::readConfiguration()
{
if (debug) qDebug() << PDEBUG;
qCDebug(LOG_ESM);
AbstractExtItem::readConfiguration();
for (int i=directories().count()-1; i>=0; i--) {
@ -273,11 +275,11 @@ void ExtWeather::readConfiguration()
QVariantHash ExtWeather::run()
{
if (debug) qDebug() << PDEBUG;
qCDebug(LOG_ESM);
if ((!isActive()) || (isRunning)) return values;
if (times == 1) {
if (debug) qDebug() << PDEBUG << ":" << "Send request";
qCDebug(LOG_ESM) << "Send request";
isRunning = true;
QNetworkReply *reply = manager->get(QNetworkRequest(QUrl(url(m_ts != 0))));
new QReplyTimeout(reply, 1000);
@ -294,7 +296,7 @@ QVariantHash ExtWeather::run()
int ExtWeather::showConfiguration(const QVariant args)
{
Q_UNUSED(args)
if (debug) qDebug() << PDEBUG;
qCDebug(LOG_ESM);
ui->lineEdit_name->setText(name());
ui->lineEdit_comment->setText(comment());
@ -324,11 +326,11 @@ int ExtWeather::showConfiguration(const QVariant args)
void ExtWeather::writeConfiguration() const
{
if (debug) qDebug() << PDEBUG;
qCDebug(LOG_ESM);
AbstractExtItem::writeConfiguration();
QSettings settings(QString("%1/%2").arg(directories().first()).arg(fileName()), QSettings::IniFormat);
if (debug) qDebug() << PDEBUG << ":" << "Configuration file" << settings.fileName();
qCDebug(LOG_ESM) << "Configuration file" << settings.fileName();
settings.beginGroup(QString("Desktop Entry"));
settings.setValue(QString("X-AW-City"), m_city);
@ -342,24 +344,24 @@ void ExtWeather::writeConfiguration() const
void ExtWeather::weatherReplyReceived(QNetworkReply *reply)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Return code" << reply->error();
if (debug) qDebug() << PDEBUG << ":" << "Reply error message" << reply->errorString();
qCDebug(LOG_ESM);
qCDebug(LOG_ESM) << "Return code" << reply->error();
qCDebug(LOG_ESM) << "Reply error message" << reply->errorString();
isRunning = false;
QJsonParseError error;
QJsonDocument jsonDoc = QJsonDocument::fromJson(reply->readAll(), &error);
reply->deleteLater();
if (debug) qDebug() << PDEBUG << ":" << "Json parse error" << error.errorString();
if ((reply->error() != QNetworkReply::NoError) ||
(error.error != QJsonParseError::NoError)) {
qCWarning(LOG_ESM) << "Parse error" << error.errorString();
return;
}
// convert to map
QVariantMap json = jsonDoc.toVariant().toMap();
if (json[QString("cod")].toInt() != 200) {
if (debug) qDebug() << PDEBUG << ":" << "Invalid return code";
qCWarning(LOG_ESM) << "Invalid return code";
return;
}
@ -376,7 +378,7 @@ void ExtWeather::weatherReplyReceived(QNetworkReply *reply)
QVariantHash ExtWeather::parseSingleJson(const QVariantMap json) const
{
if (debug) qDebug() << PDEBUG;
qCDebug(LOG_ESM);
QVariantHash output;
@ -402,7 +404,7 @@ QVariantHash ExtWeather::parseSingleJson(const QVariantMap json) const
void ExtWeather::translate()
{
if (debug) qDebug() << PDEBUG;
qCDebug(LOG_ESM);
ui->label_name->setText(i18n("Name"));
ui->label_comment->setText(i18n("Comment"));
@ -417,13 +419,13 @@ void ExtWeather::translate()
QString ExtWeather::url(const bool isForecast) const
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << "Is forecast" << isForecast;
qCDebug(LOG_ESM);
qCDebug(LOG_ESM) << "Is forecast" << isForecast;
QString apiUrl = isForecast ? QString(OWM_FORECAST_URL) : QString(OWM_URL);
apiUrl.replace(QString("$CITY"), m_city);
apiUrl.replace(QString("$COUNTRY"), m_country);
if (debug) qDebug() << PDEBUG << ":" << "API url" << apiUrl;
qCDebug(LOG_ESM) << "API url" << apiUrl;
return apiUrl;
}