Skip to content

Commit ecc4a12

Browse files
committed
all: mask various useless dbus errors
1 parent 6572a7f commit ecc4a12

File tree

6 files changed

+106
-61
lines changed

6 files changed

+106
-61
lines changed

src/dbus/dbusmenu/dbusmenu.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,8 @@ void DBusMenu::prepareToShow(qint32 item, qint32 depth) {
312312
auto responseCallback = [this, item, depth](QDBusPendingCallWatcher* call) {
313313
const QDBusPendingReply<bool> reply = *call;
314314
if (reply.isError()) {
315-
qCWarning(logDbusMenu) << "Error in AboutToShow, but showing anyway for menu" << item << "of"
316-
<< this << reply.error();
315+
qCDebug(logDbusMenu) << "Error in AboutToShow, but showing anyway for menu" << item << "of"
316+
<< this << reply.error();
317317
}
318318

319319
this->updateLayout(item, depth);

src/dbus/properties.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,13 @@ void DBusPropertyGroup::requestPropertyUpdate(DBusPropertyCore* property) {
246246
const QDBusPendingReply<QDBusVariant> reply = *call;
247247

248248
if (reply.isError()) {
249-
qCWarning(logDbusProperties).noquote() << "Error updating property" << propStr;
250-
qCWarning(logDbusProperties) << reply.error();
249+
if (!property->isRequired() && reply.error().type() == QDBusError::InvalidArgs) {
250+
qCDebug(logDbusProperties) << "Error updating non-required property" << propStr;
251+
qCDebug(logDbusProperties) << reply.error();
252+
} else {
253+
qCWarning(logDbusProperties).noquote() << "Error updating property" << propStr;
254+
qCWarning(logDbusProperties) << reply.error();
255+
}
251256
} else {
252257
this->tryUpdateProperty(property, reply.value().variant());
253258
}

src/services/mpris/player.cpp

Lines changed: 47 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <qcontainerfwd.h>
44
#include <qdatetime.h>
55
#include <qdbusconnection.h>
6+
#include <qdbuserror.h>
67
#include <qdbusextratypes.h>
78
#include <qlist.h>
89
#include <qlogging.h>
@@ -101,41 +102,10 @@ MprisPlayer::MprisPlayer(const QString& address, QObject* parent): QObject(paren
101102

102103
this->bLengthSupported.setBinding([this]() { return this->bInternalLength != -1; });
103104

104-
this->bPlaybackState.setBinding([this]() {
105-
const auto& status = this->bpPlaybackStatus.value();
106-
107-
if (status == "Playing") {
108-
return MprisPlaybackState::Playing;
109-
} else if (status == "Paused") {
110-
this->pausedTime = QDateTime::currentDateTimeUtc();
111-
return MprisPlaybackState::Paused;
112-
} else if (status == "Stopped") {
113-
return MprisPlaybackState::Stopped;
114-
} else {
115-
qWarning() << "Received unexpected PlaybackStatus for" << this << status;
116-
return MprisPlaybackState::Stopped;
117-
}
118-
});
119-
120105
this->bIsPlaying.setBinding([this]() {
121106
return this->bPlaybackState == MprisPlaybackState::Playing;
122107
});
123108

124-
this->bLoopState.setBinding([this]() {
125-
const auto& status = this->bpLoopStatus.value();
126-
127-
if (status == "None") {
128-
return MprisLoopState::None;
129-
} else if (status == "Track") {
130-
return MprisLoopState::Track;
131-
} else if (status == "Playlist") {
132-
return MprisLoopState::Playlist;
133-
} else {
134-
qWarning() << "Received unexpected LoopStatus for" << this << status;
135-
return MprisLoopState::None;
136-
}
137-
});
138-
139109
// clang-format off
140110
QObject::connect(this->player, &DBusMprisPlayer::Seeked, this, &MprisPlayer::onSeek);
141111
QObject::connect(&this->playerProperties, &DBusPropertyGroup::getAllFinished, this, &MprisPlayer::onGetAllFinished);
@@ -432,18 +402,11 @@ void MprisPlayer::setLoopState(MprisLoopState::Enum loopState) {
432402
}
433403

434404
if (loopState == this->bLoopState) return;
435-
436-
QString loopStatusStr;
437-
switch (loopState) {
438-
case MprisLoopState::None: loopStatusStr = "None"; break;
439-
case MprisLoopState::Track: loopStatusStr = "Track"; break;
440-
case MprisLoopState::Playlist: loopStatusStr = "Playlist"; break;
441-
default:
405+
if (loopState < MprisLoopState::None || loopState > MprisLoopState::Playlist) {
442406
qWarning() << "Cannot set loopState of" << this << "to unknown value" << loopState;
443-
return;
444407
}
445408

446-
this->bpLoopStatus = loopStatusStr;
409+
this->bLoopState = loopState;
447410
this->pLoopStatus.write();
448411
}
449412

@@ -496,3 +459,47 @@ void MprisPlayer::onGetAllFinished() {
496459
}
497460

498461
} // namespace qs::service::mpris
462+
463+
namespace qs::dbus {
464+
465+
using namespace qs::service::mpris;
466+
467+
DBusResult<MprisPlaybackState::Enum>
468+
DBusDataTransform<MprisPlaybackState::Enum>::fromWire(const QString& wire) {
469+
if (wire == "Playing") return MprisPlaybackState::Playing;
470+
if (wire == "Paused") return MprisPlaybackState::Paused;
471+
if (wire == "Stopped") return MprisPlaybackState::Stopped;
472+
return QDBusError(QDBusError::InvalidArgs, QString("Invalid MprisPlaybackState: %1").arg(wire));
473+
}
474+
475+
QString DBusDataTransform<MprisPlaybackState::Enum>::toWire(MprisPlaybackState::Enum data) {
476+
switch (data) {
477+
case MprisPlaybackState::Playing: return "Playing";
478+
case MprisPlaybackState::Paused: return "Paused";
479+
case MprisPlaybackState::Stopped: return "Stopped";
480+
default:
481+
qFatal() << "Tried to convert an invalid MprisPlaybackState to String";
482+
return QString();
483+
}
484+
}
485+
486+
DBusResult<MprisLoopState::Enum>
487+
DBusDataTransform<MprisLoopState::Enum>::fromWire(const QString& wire) {
488+
if (wire == "None") return MprisLoopState::None;
489+
if (wire == "Track") return MprisLoopState::Track;
490+
if (wire == "Playlist") return MprisLoopState::Playlist;
491+
return QDBusError(QDBusError::InvalidArgs, QString("Invalid MprisLoopState: %1").arg(wire));
492+
}
493+
494+
QString DBusDataTransform<MprisLoopState::Enum>::toWire(MprisLoopState::Enum data) {
495+
switch (data) {
496+
case MprisLoopState::None: return "None";
497+
case MprisLoopState::Track: return "Track";
498+
case MprisLoopState::Playlist: return "Playlist";
499+
default:
500+
qFatal() << "Tried to convert an invalid MprisLoopState to String";
501+
return QString();
502+
}
503+
}
504+
505+
} // namespace qs::dbus

src/services/mpris/player.hpp

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,30 @@ class MprisLoopState: public QObject {
5151
Q_INVOKABLE static QString toString(qs::service::mpris::MprisLoopState::Enum status);
5252
};
5353

54+
}; // namespace qs::service::mpris
55+
56+
namespace qs::dbus {
57+
58+
template <>
59+
struct DBusDataTransform<qs::service::mpris::MprisPlaybackState::Enum> {
60+
using Wire = QString;
61+
using Data = qs::service::mpris::MprisPlaybackState::Enum;
62+
static DBusResult<Data> fromWire(const QString& wire);
63+
static QString toWire(Data data);
64+
};
65+
66+
template <>
67+
struct DBusDataTransform<qs::service::mpris::MprisLoopState::Enum> {
68+
using Wire = QString;
69+
using Data = qs::service::mpris::MprisLoopState::Enum;
70+
static DBusResult<Data> fromWire(const QString& wire);
71+
static QString toWire(Data data);
72+
};
73+
74+
}; // namespace qs::dbus
75+
76+
namespace qs::service::mpris {
77+
5478
///! A media player exposed over MPRIS.
5579
/// A media player exposed over MPRIS.
5680
///
@@ -404,13 +428,13 @@ private slots:
404428

405429
QS_DBUS_BINDABLE_PROPERTY_GROUP(MprisPlayer, appProperties);
406430
QS_DBUS_PROPERTY_BINDING(MprisPlayer, pIdentity, bIdentity, appProperties, "Identity");
407-
QS_DBUS_PROPERTY_BINDING(MprisPlayer, pDesktopEntry, bDesktopEntry, appProperties, "DesktopEntry");
408-
QS_DBUS_PROPERTY_BINDING(MprisPlayer, pCanQuit, bCanQuit, appProperties, "CanQuit");
409-
QS_DBUS_PROPERTY_BINDING(MprisPlayer, pCanRaise, bCanRaise, appProperties, "CanRaise");
431+
QS_DBUS_PROPERTY_BINDING(MprisPlayer, pDesktopEntry, bDesktopEntry, appProperties, "DesktopEntry", false);
432+
QS_DBUS_PROPERTY_BINDING(MprisPlayer, pCanQuit, bCanQuit, appProperties, "CanQuit", false);
433+
QS_DBUS_PROPERTY_BINDING(MprisPlayer, pCanRaise, bCanRaise, appProperties, "CanRaise", false);
410434
QS_DBUS_PROPERTY_BINDING(MprisPlayer, pFullscreen, bFullscreen, appProperties, "Fullscreen", false);
411435
QS_DBUS_PROPERTY_BINDING(MprisPlayer, pCanSetFullscreen, bCanSetFullscreen, appProperties, "CanSetFullscreen", false);
412-
QS_DBUS_PROPERTY_BINDING(MprisPlayer, pSupportedUriSchemes, bSupportedUriSchemes, appProperties, "SupportedUriSchemes");
413-
QS_DBUS_PROPERTY_BINDING(MprisPlayer, pSupportedMimeTypes, bSupportedMimeTypes, appProperties, "SupportedMimeTypes");
436+
QS_DBUS_PROPERTY_BINDING(MprisPlayer, pSupportedUriSchemes, bSupportedUriSchemes, appProperties, "SupportedUriSchemes", false);
437+
QS_DBUS_PROPERTY_BINDING(MprisPlayer, pSupportedMimeTypes, bSupportedMimeTypes, appProperties, "SupportedMimeTypes", false);
414438

415439
Q_OBJECT_BINDABLE_PROPERTY(MprisPlayer, bool, bpCanPlay);
416440
Q_OBJECT_BINDABLE_PROPERTY(MprisPlayer, bool, bpCanPause);
@@ -420,8 +444,6 @@ private slots:
420444
Q_OBJECT_BINDABLE_PROPERTY(MprisPlayer, QVariantMap, bpMetadata);
421445
QS_BINDING_SUBSCRIBE_METHOD(MprisPlayer, bpMetadata, onMetadataChanged, onValueChanged);
422446
Q_OBJECT_BINDABLE_PROPERTY_WITH_ARGS(MprisPlayer, qlonglong, bpPosition, -1, &MprisPlayer::positionChanged);
423-
Q_OBJECT_BINDABLE_PROPERTY(MprisPlayer, QString, bpPlaybackStatus);
424-
Q_OBJECT_BINDABLE_PROPERTY(MprisPlayer, QString, bpLoopStatus);
425447

426448
Q_OBJECT_BINDABLE_PROPERTY(MprisPlayer, bool, bCanControl, &MprisPlayer::canControlChanged);
427449
Q_OBJECT_BINDABLE_PROPERTY(MprisPlayer, bool, bCanPlay, &MprisPlayer::canPlayChanged);
@@ -460,8 +482,8 @@ private slots:
460482
QS_DBUS_PROPERTY_BINDING(MprisPlayer, qlonglong, pPosition, bpPosition, onPositionUpdated, playerProperties, "Position", false);
461483
QS_DBUS_PROPERTY_BINDING(MprisPlayer, pVolume, bVolume, playerProperties, "Volume", false);
462484
QS_DBUS_PROPERTY_BINDING(MprisPlayer, pMetadata, bpMetadata, playerProperties, "Metadata");
463-
QS_DBUS_PROPERTY_BINDING(MprisPlayer, void, pPlaybackStatus, bpPlaybackStatus, onPlaybackStatusUpdated, playerProperties, "PlaybackStatus", true);
464-
QS_DBUS_PROPERTY_BINDING(MprisPlayer, pLoopStatus, bpLoopStatus, playerProperties, "LoopStatus", false);
485+
QS_DBUS_PROPERTY_BINDING(MprisPlayer, void, pPlaybackStatus, bPlaybackState, onPlaybackStatusUpdated, playerProperties, "PlaybackStatus", true);
486+
QS_DBUS_PROPERTY_BINDING(MprisPlayer, pLoopStatus, bLoopState, playerProperties, "LoopStatus", false);
465487
QS_DBUS_PROPERTY_BINDING(MprisPlayer, pRate, bRate, playerProperties, "Rate", false);
466488
QS_DBUS_PROPERTY_BINDING(MprisPlayer, pMinRate, bMinRate, playerProperties, "MinimumRate", false);
467489
QS_DBUS_PROPERTY_BINDING(MprisPlayer, pMaxRate, bMaxRate, playerProperties, "MaximumRate", false);

src/services/notifications/server.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
namespace qs::service::notifications {
2222

2323
// NOLINTNEXTLINE(misc-use-internal-linkage)
24-
QS_LOGGING_CATEGORY(logNotifications, "quickshell.service.notifications");
24+
QS_LOGGING_CATEGORY(logNotifications, "quickshell.service.notifications", QtWarningMsg);
2525

2626
NotificationServer::NotificationServer() {
2727
qDBusRegisterMetaType<DBusNotificationImage>();

src/services/status_notifier/item.cpp

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,14 @@ void StatusNotifierItem::activate() {
222222
const QDBusPendingReply<> reply = *call;
223223

224224
if (reply.isError()) {
225-
qCWarning(logStatusNotifierItem).noquote()
226-
<< "Error calling Activate method of StatusNotifierItem" << this->properties.toString();
227-
qCWarning(logStatusNotifierItem) << reply.error();
225+
if (reply.error().type() == QDBusError::UnknownMethod) {
226+
qCDebug(logStatusNotifierItem) << "Tried to call Activate method of StatusNotifierItem"
227+
<< this->properties.toString() << "but it does not exist.";
228+
} else {
229+
qCWarning(logStatusNotifierItem).noquote()
230+
<< "Error calling Activate method of StatusNotifierItem" << this->properties.toString();
231+
qCWarning(logStatusNotifierItem) << reply.error();
232+
}
228233
}
229234

230235
delete call;
@@ -241,10 +246,16 @@ void StatusNotifierItem::secondaryActivate() {
241246
const QDBusPendingReply<> reply = *call;
242247

243248
if (reply.isError()) {
244-
qCWarning(logStatusNotifierItem).noquote()
245-
<< "Error calling SecondaryActivate method of StatusNotifierItem"
246-
<< this->properties.toString();
247-
qCWarning(logStatusNotifierItem) << reply.error();
249+
if (reply.error().type() == QDBusError::UnknownMethod) {
250+
qCDebug(logStatusNotifierItem)
251+
<< "Tried to call SecondaryActivate method of StatusNotifierItem"
252+
<< this->properties.toString() << "but it does not exist.";
253+
} else {
254+
qCWarning(logStatusNotifierItem).noquote()
255+
<< "Error calling SecondaryActivate method of StatusNotifierItem"
256+
<< this->properties.toString();
257+
qCWarning(logStatusNotifierItem) << reply.error();
258+
}
248259
}
249260

250261
delete call;

0 commit comments

Comments
 (0)