diff options
-rw-r--r-- | src/saverwidget.cpp | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/saverwidget.cpp b/src/saverwidget.cpp index 359c2bd..1a4a14c 100644 --- a/src/saverwidget.cpp +++ b/src/saverwidget.cpp @@ -113,12 +113,17 @@ void SaverWidget::reloadValues() connect(_unixSocket, &QLocalSocket::connected, [=]() { qDebug() << "Connected to daewmweon"; _unixSocket->write((QLatin1String("get ") + _display).toLocal8Bit()); - QTimer::singleShot(1000, [this]() { + QTimer::singleShot(2000, [this]() { _unixSocket->disconnectFromServer(); + this->parseDaemonData(); }); }); connect(_unixSocket, QOverload<QLocalSocket::LocalSocketError>::of(&QLocalSocket::error), [=](QLocalSocket::LocalSocketError err) { - qDebug() << "Local socket error:" << err; + if (err != QLocalSocket::PeerClosedError) { + qDebug() << "Local socket error:" << err; + } else { + this->parseDaemonData(); + } }); connect(_unixSocket, &QLocalSocket::disconnected, this, &SaverWidget::parseDaemonData); _unixSocket->connectToServer("/run/idle-daemon"); @@ -131,8 +136,9 @@ void SaverWidget::parseDaemonData() #define SEC_NONE 0 #define SEC_GENERAL 1 #define SEC_ME 2 -#define STORE(x) else if (key == QLatin1String( #x )) x = value.toString() +#define STORE(x) else if (key == QLatin1String( #x )) ok++, x = value.toString() int sec = SEC_NONE; + int ok = 0; QString nextAction, nextActionTime, logoutTime, locked; while (!ts.atEnd()) { line = ts.readLine(); @@ -142,8 +148,10 @@ void SaverWidget::parseDaemonData() // Section if (line == QLatin1String("[General]")) { sec = SEC_GENERAL; + ok++; } else if ( line == "[" + _display + "]") { sec = SEC_ME; + ok++; } else { sec = SEC_NONE; } @@ -165,6 +173,8 @@ void SaverWidget::parseDaemonData() } } } + if (ok < 3) + return; // Bad data received, ignore if (nextAction.isEmpty() || nextAction == QLatin1String("none") || nextActionTime.isEmpty()) { _shutdownDeadline = 0; } else { |