summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorFrédéric Brière <fbriere@fbriere.net>2019-07-13 17:50:36 -0400
committerFrédéric Brière <fbriere@fbriere.net>2019-07-13 17:50:36 -0400
commit3d9fb0ac7490620a49a400b77ab8f851cdd4fcf5 (patch)
treede1749e6c2b5c2eeec0f089798939aa1ace4152c /src/gui
parent1e9f091f39a32193b0671e9dfbfb657dd45fec3e (diff)
downloadtwinkle-3d9fb0ac7490620a49a400b77ab8f851cdd4fcf5.tar
twinkle-3d9fb0ac7490620a49a400b77ab8f851cdd4fcf5.tar.gz
twinkle-3d9fb0ac7490620a49a400b77ab8f851cdd4fcf5.tar.lz
twinkle-3d9fb0ac7490620a49a400b77ab8f851cdd4fcf5.tar.xz
twinkle-3d9fb0ac7490620a49a400b77ab8f851cdd4fcf5.zip
Properly display and log warning messages in IdleSessionInhibitor
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/gui.cpp3
-rw-r--r--src/gui/idlesession_inhibitor.cpp27
-rw-r--r--src/gui/idlesession_inhibitor.h3
-rw-r--r--src/gui/idlesession_manager.cpp7
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<std::string>>("std::list<std::string>");
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<t_user *> 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 <QDBusConnection>
#include <QDBusConnectionInterface>
#include <QDBusMessage>
@@ -27,13 +30,6 @@
#include <QDBusPendingCallWatcher>
#include <QDBusPendingReply>
-#include <QtGlobal>
-
-// 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<uint> 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 <assert.h>
+
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)