From 3d9fb0ac7490620a49a400b77ab8f851cdd4fcf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Bri=C3=A8re?= Date: Sat, 13 Jul 2019 17:50:36 -0400 Subject: Properly display and log warning messages in IdleSessionInhibitor --- src/gui/gui.cpp | 3 ++- src/gui/idlesession_inhibitor.cpp | 27 +++++++++++++++------------ src/gui/idlesession_inhibitor.h | 3 +++ src/gui/idlesession_manager.cpp | 7 +++++++ 4 files changed, 27 insertions(+), 13 deletions(-) diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index d96da2a..954d8e8 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -786,7 +786,6 @@ t_gui::t_gui(t_phone *_phone) : t_userintf(_phone), timerUpdateMessageSessions(N qRegisterMetaType>("std::list"); m_idle_session_manager = new IdleSessionManager(this); - updateInhibitIdleSession(); connect(this, &t_gui::update_state, this, &t_gui::updateIdleSessionState, Qt::QueuedConnection); @@ -825,6 +824,8 @@ void t_gui::run(void) { thr_process_events = new t_thread(process_events_main, NULL); MEMMAN_NEW(thr_process_events); + updateInhibitIdleSession(); + QString s; list user_list = phone->ref_users(); diff --git a/src/gui/idlesession_inhibitor.cpp b/src/gui/idlesession_inhibitor.cpp index ba89a10..9e4e1d4 100644 --- a/src/gui/idlesession_inhibitor.cpp +++ b/src/gui/idlesession_inhibitor.cpp @@ -20,6 +20,9 @@ #include "idlesession_inhibitor.h" +#include "log.h" +#include "userintf.h" + #include #include #include @@ -27,13 +30,6 @@ #include #include -#include - -// qUtf8Printable() was introduced in Qt 5.4 -#if QT_VERSION < 0x050400 -#define qUtf8Printable(string) QString(string).toUtf8().constData() -#endif - // There are various standards for session/power management out there. // Fortunately, most of them are either obsolete or redundant; the following // two should cover most, if not all, cases. @@ -72,7 +68,7 @@ IdleSessionInhibitor::IdleSessionInhibitor(QObject *parent) : QObject(parent) { if (!QDBusConnection::sessionBus().isConnected()) { - qWarning("D-Bus: Could not connect to session bus"); + issueWarning(tr("D-Bus: Could not connect to session bus")); m_state = error; return; } @@ -83,7 +79,7 @@ IdleSessionInhibitor::IdleSessionInhibitor(QObject *parent) } else if (interface->isServiceRegistered(GSM_SERVICE)) { m_use_gsm = true; } else { - qWarning("D-Bus: No supported session/power management service found"); + issueWarning(tr("D-Bus: No supported session/power management service found")); m_state = error; return; } @@ -158,7 +154,7 @@ void IdleSessionInhibitor::onAsyncReply(QDBusPendingCallWatcher *call) QDBusPendingReply<> reply = *call; if (reply.isError()) { - qWarning("D-Bus: Reply: Error: %s", qUtf8Printable(reply.error().message())); + issueWarning(tr("D-Bus: Reply: Error: %1").arg(reply.error().message())); m_state = error; } else { m_state = idle; @@ -173,7 +169,7 @@ void IdleSessionInhibitor::onAsyncReply(QDBusPendingCallWatcher *call) QDBusPendingReply reply = *call; if (reply.isError()) { - qWarning("D-Bus: Reply: Error: %s", qUtf8Printable(reply.error().message())); + issueWarning(tr("D-Bus: Reply: Error: %1").arg(reply.error().message())); m_state = error; } else { m_state = busy; @@ -185,9 +181,16 @@ void IdleSessionInhibitor::onAsyncReply(QDBusPendingCallWatcher *call) break; } default: - qWarning("D-Bus: Unexpected reply in state %d", m_state); + issueWarning(tr("D-Bus: Unexpected reply in state %1").arg(m_state)); m_state = error; } call->deleteLater(); } + +void IdleSessionInhibitor::issueWarning(const QString &msg) const +{ + log_file->write_report(msg.toStdString(), "IdleSessionInhibitor", + LOG_NORMAL, LOG_WARNING); + ui->cb_display_msg(msg.toStdString(), MSG_WARNING); +} diff --git a/src/gui/idlesession_inhibitor.h b/src/gui/idlesession_inhibitor.h index cd41494..812e0a0 100644 --- a/src/gui/idlesession_inhibitor.h +++ b/src/gui/idlesession_inhibitor.h @@ -67,6 +67,9 @@ private: // Send an (un)inhibit request via D-Bus void sendRequest(bool inhibit); + + // Display and log a warning + void issueWarning(const QString &msg) const; }; #endif // IDLESESSION_INHIBITOR_H diff --git a/src/gui/idlesession_manager.cpp b/src/gui/idlesession_manager.cpp index e1d5a81..5cc60b7 100644 --- a/src/gui/idlesession_manager.cpp +++ b/src/gui/idlesession_manager.cpp @@ -25,6 +25,10 @@ #include "idlesession_inhibitor.h" #endif +#include "log.h" + +#include + IdleSessionManager::IdleSessionManager(QObject *parent) : QObject(parent) { @@ -38,6 +42,9 @@ IdleSessionManager::IdleSessionManager(QObject *parent) void IdleSessionManager::setEnabled(bool enabled) { + // Make sure logging has been made available at this point + assert(log_file); + #ifdef HAVE_DBUS // Create our inhibitor if enabling for the first time if (enabled && !m_inhibitor) -- cgit v1.2.3