forked from quickshell/quickshell
		
	core/util: add experimental member macros
An experiment that should reduce boilerplate for properties that just access a backing value. Code also exists for using it as an interface for other properties as well, but isn't currently in use.
This commit is contained in:
		
							parent
							
								
									8873a06962
								
							
						
					
					
						commit
						ba1e535f9c
					
				
					 6 changed files with 236 additions and 185 deletions
				
			
		| 
						 | 
				
			
			@ -3,8 +3,8 @@
 | 
			
		|||
#include <qdebug.h>
 | 
			
		||||
#include <qnamespace.h>
 | 
			
		||||
#include <qpoint.h>
 | 
			
		||||
#include <qrect.h>
 | 
			
		||||
#include <qqmlintegration.h>
 | 
			
		||||
#include <qrect.h>
 | 
			
		||||
#include <qtmetamacros.h>
 | 
			
		||||
 | 
			
		||||
class Box {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,4 +1,5 @@
 | 
			
		|||
#pragma once
 | 
			
		||||
#include <type_traits>
 | 
			
		||||
 | 
			
		||||
// NOLINTBEGIN
 | 
			
		||||
#define DROP_EMIT(object, func)                                                                    \
 | 
			
		||||
| 
						 | 
				
			
			@ -14,34 +15,6 @@
 | 
			
		|||
		object->member = local;                                                                        \
 | 
			
		||||
		signal = DROP_EMIT(object, signal);                                                            \
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
// generic accessor declarations
 | 
			
		||||
 | 
			
		||||
#define GDECL_GETTER(type, name) [[nodiscard]] type name() const
 | 
			
		||||
 | 
			
		||||
#define GDEF_GETTER(class, type, member, name)                                                     \
 | 
			
		||||
	type class::name() const { return this->member; }
 | 
			
		||||
 | 
			
		||||
#define GDECL_SETTER(type, name) DropEmitter name(type value)
 | 
			
		||||
 | 
			
		||||
#define GDEF_SETTER(class, type, member, name, signal)                                             \
 | 
			
		||||
	DropEmitter class ::name(type value) {                                                           \
 | 
			
		||||
		if (value == this->member) return DropEmitter();                                               \
 | 
			
		||||
		this->member = value;                                                                          \
 | 
			
		||||
		return DROP_EMIT(this, signal);                                                                \
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
#define GDECL_MEMBER(type, getter, setter)                                                         \
 | 
			
		||||
	GDECL_GETTER(type, getter)                                                             \
 | 
			
		||||
	GDECL_SETTER(type, setter)
 | 
			
		||||
 | 
			
		||||
#define GDEF_MEMBER(class, type, member, getter, setter, signal)                                   \
 | 
			
		||||
	GDEF_GETTER(class, type, member, getter)                                               \
 | 
			
		||||
	GDEF_SETTER(class, type, member, setter, signal)
 | 
			
		||||
 | 
			
		||||
#define GDEF_MEMBER_S(class, type, lower, upper)                                         \
 | 
			
		||||
	GDEF_MEMBER(class, type, m##upper, lower, set##upper, lower##Changed)
 | 
			
		||||
 | 
			
		||||
// NOLINTEND
 | 
			
		||||
 | 
			
		||||
class DropEmitter {
 | 
			
		||||
| 
						 | 
				
			
			@ -75,7 +48,125 @@ public:
 | 
			
		|||
		this->object = nullptr;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// orders calls for multiple emitters (instead of reverse definition order)
 | 
			
		||||
	template <typename... Args>
 | 
			
		||||
	static void call(Args&... args) {
 | 
			
		||||
		(args.call(), ...);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
	void* object = nullptr;
 | 
			
		||||
	void (*signal)(void*) = nullptr;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// NOLINTBEGIN
 | 
			
		||||
#define DECLARE_MEMBER(class, name, member, signal)                                                \
 | 
			
		||||
	using M_##name = MemberMetadata<&class ::member, &class ::signal>
 | 
			
		||||
 | 
			
		||||
#define DECLARE_MEMBER_NS(class, name, member) using M_##name = MemberMetadata<&class ::member>
 | 
			
		||||
 | 
			
		||||
#define DECLARE_MEMBER_GET(name) [[nodiscard]] M_##name::Ref name() const
 | 
			
		||||
#define DECLARE_MEMBER_SET(name, setter) M_##name::Ret setter(M_##name::Ref value)
 | 
			
		||||
 | 
			
		||||
#define DECLARE_MEMBER_GETSET(name, setter)                                                        \
 | 
			
		||||
	DECLARE_MEMBER_GET(name);                                                                        \
 | 
			
		||||
	DECLARE_MEMBER_SET(name, setter)
 | 
			
		||||
 | 
			
		||||
#define DECLARE_MEMBER_FULL(class, name, setter, member, signal)                                   \
 | 
			
		||||
	DECLARE_MEMBER(class, name, member, signal);                                                     \
 | 
			
		||||
	DECLARE_MEMBER_GETSET(name, setter)
 | 
			
		||||
 | 
			
		||||
#define DECLARE_MEMBER_WITH_GET(class, name, member, signal)                                       \
 | 
			
		||||
	DECLARE_MEMBER(class, name, member, signal);                                                     \
 | 
			
		||||
                                                                                                   \
 | 
			
		||||
public:                                                                                            \
 | 
			
		||||
	DECLARE_MEMBER_GET(name);                                                                        \
 | 
			
		||||
                                                                                                   \
 | 
			
		||||
private:
 | 
			
		||||
 | 
			
		||||
#define DECLARE_PRIVATE_MEMBER(class, name, setter, member, signal)                                \
 | 
			
		||||
	DECLARE_MEMBER_WITH_GET(class, name, member, signal);                                            \
 | 
			
		||||
	DECLARE_MEMBER_SET(name, setter);
 | 
			
		||||
 | 
			
		||||
#define DECLARE_PMEMBER(type, name) using M_##name = PseudomemberMetadata<type, true>;
 | 
			
		||||
#define DECLARE_PMEMBER_NS(type, name) using M_##name = PseudomemberMetadata<type, false>;
 | 
			
		||||
 | 
			
		||||
#define DECLARE_PMEMBER_FULL(type, name, setter)                                                   \
 | 
			
		||||
	DECLARE_PMEMBER(type, name);                                                                     \
 | 
			
		||||
	DECLARE_MEMBER_GETSET(name, setter)
 | 
			
		||||
 | 
			
		||||
#define DECLARE_PMEMBER_WITH_GET(type, name)                                                       \
 | 
			
		||||
	DECLARE_PMEMBER(type, name);                                                                     \
 | 
			
		||||
                                                                                                   \
 | 
			
		||||
public:                                                                                            \
 | 
			
		||||
	DECLARE_MEMBER_GET(name);                                                                        \
 | 
			
		||||
                                                                                                   \
 | 
			
		||||
private:
 | 
			
		||||
 | 
			
		||||
#define DECLARE_PRIVATE_PMEMBER(type, name, setter)                                                \
 | 
			
		||||
	DECLARE_PMEMBER_WITH_GET(type, name);                                                            \
 | 
			
		||||
	DECLARE_MEMBER_SET(name, setter);
 | 
			
		||||
 | 
			
		||||
#define DEFINE_PMEMBER_GET_M(Class, Member, name) Member::Ref Class::name() const
 | 
			
		||||
#define DEFINE_PMEMBER_GET(Class, name) DEFINE_PMEMBER_GET_M(Class, Class::M_##name, name)
 | 
			
		||||
 | 
			
		||||
#define DEFINE_MEMBER_GET_M(Class, Member, name)                                                   \
 | 
			
		||||
	DEFINE_PMEMBER_GET_M(Class, Member, name) { return Member::get(this); }
 | 
			
		||||
 | 
			
		||||
#define DEFINE_MEMBER_GET(Class, name) DEFINE_MEMBER_GET_M(Class, Class::M_##name, name)
 | 
			
		||||
 | 
			
		||||
#define DEFINE_MEMBER_SET_M(Class, Member, setter)                                                 \
 | 
			
		||||
	Member::Ret Class::setter(Member::Ref value) { return Member::set(this, value); }
 | 
			
		||||
 | 
			
		||||
#define DEFINE_MEMBER_SET(Class, name, setter) DEFINE_MEMBER_SET_M(Class, Class::M_##name, setter)
 | 
			
		||||
 | 
			
		||||
#define DEFINE_MEMBER_GETSET(Class, name, setter)                                                  \
 | 
			
		||||
	DEFINE_MEMBER_GET(Class, name)                                                                   \
 | 
			
		||||
	DEFINE_MEMBER_SET(Class, name, setter)
 | 
			
		||||
// NOLINTEND
 | 
			
		||||
 | 
			
		||||
template <typename T>
 | 
			
		||||
class MemberPointerTraits;
 | 
			
		||||
 | 
			
		||||
template <typename T, typename C>
 | 
			
		||||
class MemberPointerTraits<T C::*> {
 | 
			
		||||
public:
 | 
			
		||||
	using Class = C;
 | 
			
		||||
	using Type = T;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
template <auto member, auto signal = nullptr>
 | 
			
		||||
class MemberMetadata {
 | 
			
		||||
	using Traits = MemberPointerTraits<decltype(member)>;
 | 
			
		||||
	using Class = Traits::Class;
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
	using Type = Traits::Type;
 | 
			
		||||
	using Ref = const Type&;
 | 
			
		||||
	using Ret = std::conditional_t<signal == nullptr, void, DropEmitter>;
 | 
			
		||||
 | 
			
		||||
	static Ref get(const Class* obj) { return obj->*member; }
 | 
			
		||||
 | 
			
		||||
	static Ret set(Class* obj, Ref value) {
 | 
			
		||||
		if constexpr (signal == nullptr) {
 | 
			
		||||
			if (MemberMetadata::get(obj) == value) return;
 | 
			
		||||
			obj->*member = value;
 | 
			
		||||
		} else {
 | 
			
		||||
			if (MemberMetadata::get(obj) == value) return DropEmitter();
 | 
			
		||||
			obj->*member = value;
 | 
			
		||||
			return DropEmitter(obj, &MemberMetadata::emitForObject);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
	static void emitForObject(Class* obj) { (obj->*signal)(); }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// allows use of member macros without an actual field backing them
 | 
			
		||||
template <typename T, bool hasSignal>
 | 
			
		||||
class PseudomemberMetadata {
 | 
			
		||||
public:
 | 
			
		||||
	using Type = T;
 | 
			
		||||
	using Ref = const Type&;
 | 
			
		||||
	using Ret = std::conditional_t<hasSignal, DropEmitter, void>;
 | 
			
		||||
};
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,5 +1,4 @@
 | 
			
		|||
#include "player.hpp"
 | 
			
		||||
#include <utility>
 | 
			
		||||
 | 
			
		||||
#include <qcontainerfwd.h>
 | 
			
		||||
#include <qdatetime.h>
 | 
			
		||||
| 
						 | 
				
			
			@ -12,7 +11,7 @@
 | 
			
		|||
#include <qtmetamacros.h>
 | 
			
		||||
#include <qtypes.h>
 | 
			
		||||
 | 
			
		||||
#include "../../core/types.hpp"
 | 
			
		||||
#include "../../core/util.hpp"
 | 
			
		||||
#include "../../dbus/properties.hpp"
 | 
			
		||||
#include "dbus_player.h"
 | 
			
		||||
#include "dbus_player_app.h"
 | 
			
		||||
| 
						 | 
				
			
			@ -167,8 +166,8 @@ bool MprisPlayer::canQuit() const { return this->pCanQuit.get(); }
 | 
			
		|||
bool MprisPlayer::canRaise() const { return this->pCanRaise.get(); }
 | 
			
		||||
bool MprisPlayer::canSetFullscreen() const { return this->pCanSetFullscreen.get(); }
 | 
			
		||||
 | 
			
		||||
QString MprisPlayer::identity() const { return this->pIdentity.get(); }
 | 
			
		||||
QString MprisPlayer::desktopEntry() const { return this->pDesktopEntry.get(); }
 | 
			
		||||
const QString& MprisPlayer::identity() const { return this->pIdentity.get(); }
 | 
			
		||||
const QString& MprisPlayer::desktopEntry() const { return this->pDesktopEntry.get(); }
 | 
			
		||||
 | 
			
		||||
qlonglong MprisPlayer::positionMs() const {
 | 
			
		||||
	if (!this->positionSupported()) return 0; // unsupported
 | 
			
		||||
| 
						 | 
				
			
			@ -256,13 +255,7 @@ void MprisPlayer::setVolume(qreal volume) {
 | 
			
		|||
	this->pVolume.write();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
quint32 MprisPlayer::uniqueId() const { return this->mUniqueId; }
 | 
			
		||||
QVariantMap MprisPlayer::metadata() const { return this->pMetadata.get(); }
 | 
			
		||||
QString MprisPlayer::trackTitle() const { return this->mTrackTitle; }
 | 
			
		||||
QString MprisPlayer::trackAlbum() const { return this->mTrackAlbum; }
 | 
			
		||||
QString MprisPlayer::trackAlbumArtist() const { return this->mTrackAlbumArtist; }
 | 
			
		||||
QVector<QString> MprisPlayer::trackArtists() const { return this->mTrackArtists; }
 | 
			
		||||
QString MprisPlayer::trackArtUrl() const { return this->mTrackArtUrl; }
 | 
			
		||||
const QVariantMap& MprisPlayer::metadata() const { return this->pMetadata.get(); }
 | 
			
		||||
 | 
			
		||||
void MprisPlayer::onMetadataChanged() {
 | 
			
		||||
	emit this->metadataChanged();
 | 
			
		||||
| 
						 | 
				
			
			@ -273,7 +266,7 @@ void MprisPlayer::onMetadataChanged() {
 | 
			
		|||
		length = lengthVariant.value<qlonglong>();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	auto emitLengthChanged = this->setLength(length);
 | 
			
		||||
	auto lengthChanged = this->setLength(length);
 | 
			
		||||
 | 
			
		||||
	auto trackChanged = false;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -298,45 +291,20 @@ void MprisPlayer::onMetadataChanged() {
 | 
			
		|||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	DropEmitter emitTrackTitle;
 | 
			
		||||
	auto trackTitle = this->pMetadata.get().value("xesam:title");
 | 
			
		||||
	if (trackTitle.isValid() && trackTitle.canConvert<QString>()) {
 | 
			
		||||
		emitTrackTitle = this->setTrackTitle(trackTitle.toString());
 | 
			
		||||
	} else if (trackChanged) {
 | 
			
		||||
		emitTrackTitle = this->setTrackTitle("Unknown Track");
 | 
			
		||||
	}
 | 
			
		||||
	auto trackTitle = this->pMetadata.get().value("xesam:title").toString();
 | 
			
		||||
	auto trackTitleChanged = this->setTrackTitle(trackTitle.isNull() ? "Unknown Track" : trackTitle);
 | 
			
		||||
 | 
			
		||||
	DropEmitter emitTrackAlbum;
 | 
			
		||||
	auto trackAlbum = this->pMetadata.get().value("xesam:album");
 | 
			
		||||
	if (trackAlbum.isValid() && trackAlbum.canConvert<QString>()) {
 | 
			
		||||
		emitTrackAlbum = this->setTrackAlbum(trackAlbum.toString());
 | 
			
		||||
	} else if (trackChanged) {
 | 
			
		||||
		emitTrackAlbum = this->setTrackAlbum("Unknown Album");
 | 
			
		||||
	}
 | 
			
		||||
	auto trackArtists = this->pMetadata.get().value("xesam:artist").value<QVector<QString>>();
 | 
			
		||||
	auto trackArtistsChanged = this->setTrackArtists(trackArtists);
 | 
			
		||||
 | 
			
		||||
	DropEmitter emitTrackAlbumArtist;
 | 
			
		||||
	auto trackAlbumArtist = this->pMetadata.get().value("xesam:albumArtist");
 | 
			
		||||
	if (trackAlbumArtist.isValid() && trackAlbumArtist.canConvert<QString>()) {
 | 
			
		||||
		emitTrackAlbumArtist = this->setTrackAlbumArtist(trackAlbumArtist.toString());
 | 
			
		||||
	} else if (trackChanged) {
 | 
			
		||||
		emitTrackAlbumArtist = this->setTrackAlbumArtist("Unknown Artist");
 | 
			
		||||
	}
 | 
			
		||||
	auto trackAlbum = this->pMetadata.get().value("xesam:album").toString();
 | 
			
		||||
	auto trackAlbumChanged = this->setTrackAlbum(trackAlbum.isNull() ? "Unknown Album" : trackAlbum);
 | 
			
		||||
 | 
			
		||||
	DropEmitter emitTrackArtists;
 | 
			
		||||
	auto trackArtists = this->pMetadata.get().value("xesam:artist");
 | 
			
		||||
	if (trackArtists.isValid() && trackArtists.canConvert<QVector<QString>>()) {
 | 
			
		||||
		emitTrackArtists = this->setTrackArtists(trackArtists.value<QVector<QString>>());
 | 
			
		||||
	} else if (trackChanged) {
 | 
			
		||||
		emitTrackArtists = this->setTrackArtists({});
 | 
			
		||||
	}
 | 
			
		||||
	auto trackAlbumArtist = this->pMetadata.get().value("xesam:albumArtist").toString();
 | 
			
		||||
	auto trackAlbumArtistChanged = this->setTrackAlbumArtist(trackAlbumArtist);
 | 
			
		||||
 | 
			
		||||
	DropEmitter emitTrackArtUrl;
 | 
			
		||||
	auto trackArtUrl = this->pMetadata.get().value("mpris:artUrl");
 | 
			
		||||
	if (trackArtUrl.isValid() && trackArtUrl.canConvert<QString>()) {
 | 
			
		||||
		emitTrackArtUrl = this->setTrackArtUrl(trackArtUrl.toString());
 | 
			
		||||
	} else if (trackChanged) {
 | 
			
		||||
		emitTrackArtUrl = this->setTrackArtUrl("");
 | 
			
		||||
	}
 | 
			
		||||
	auto trackArtUrl = this->pMetadata.get().value("mpris:artUrl").toString();
 | 
			
		||||
	auto trackArtUrlChanged = this->setTrackArtUrl(trackArtUrl);
 | 
			
		||||
 | 
			
		||||
	if (trackChanged) {
 | 
			
		||||
		this->mUniqueId++;
 | 
			
		||||
| 
						 | 
				
			
			@ -344,49 +312,25 @@ void MprisPlayer::onMetadataChanged() {
 | 
			
		|||
		this->pPosition.update();
 | 
			
		||||
		emit this->trackChanged();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	DropEmitter::call(
 | 
			
		||||
	    trackTitleChanged,
 | 
			
		||||
	    trackArtistsChanged,
 | 
			
		||||
	    trackAlbumChanged,
 | 
			
		||||
	    trackAlbumArtistChanged,
 | 
			
		||||
	    trackArtUrlChanged,
 | 
			
		||||
	    lengthChanged
 | 
			
		||||
	);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
DropEmitter MprisPlayer::setLength(qlonglong length) {
 | 
			
		||||
	if (length == this->mLength) return DropEmitter();
 | 
			
		||||
DEFINE_MEMBER_GET(MprisPlayer, uniqueId);
 | 
			
		||||
DEFINE_MEMBER_SET(MprisPlayer, length, setLength);
 | 
			
		||||
 | 
			
		||||
	this->mLength = length;
 | 
			
		||||
	return DROP_EMIT(this, lengthChanged);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
DropEmitter MprisPlayer::setTrackTitle(QString title) {
 | 
			
		||||
	if (title == this->mTrackTitle) return DropEmitter();
 | 
			
		||||
 | 
			
		||||
	this->mTrackTitle = std::move(title);
 | 
			
		||||
	return DROP_EMIT(this, trackTitleChanged);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
DropEmitter MprisPlayer::setTrackAlbum(QString album) {
 | 
			
		||||
	if (album == this->mTrackAlbum) return DropEmitter();
 | 
			
		||||
 | 
			
		||||
	this->mTrackAlbum = std::move(album);
 | 
			
		||||
	return DROP_EMIT(this, trackAlbumChanged);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
DropEmitter MprisPlayer::setTrackAlbumArtist(QString albumArtist) {
 | 
			
		||||
	if (albumArtist == this->mTrackAlbumArtist) return DropEmitter();
 | 
			
		||||
 | 
			
		||||
	this->mTrackAlbumArtist = std::move(albumArtist);
 | 
			
		||||
	return DROP_EMIT(this, trackAlbumArtistChanged);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
DropEmitter MprisPlayer::setTrackArtists(QVector<QString> artists) {
 | 
			
		||||
	if (artists == this->mTrackArtists) return DropEmitter();
 | 
			
		||||
 | 
			
		||||
	this->mTrackArtists = std::move(artists);
 | 
			
		||||
	return DROP_EMIT(this, trackArtistsChanged);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
DropEmitter MprisPlayer::setTrackArtUrl(QString artUrl) {
 | 
			
		||||
	if (artUrl == this->mTrackArtUrl) return DropEmitter();
 | 
			
		||||
 | 
			
		||||
	this->mTrackArtUrl = std::move(artUrl);
 | 
			
		||||
	return DROP_EMIT(this, trackArtUrlChanged);
 | 
			
		||||
}
 | 
			
		||||
DEFINE_MEMBER_GETSET(MprisPlayer, trackTitle, setTrackTitle);
 | 
			
		||||
DEFINE_MEMBER_GETSET(MprisPlayer, trackArtists, setTrackArtists);
 | 
			
		||||
DEFINE_MEMBER_GETSET(MprisPlayer, trackAlbum, setTrackAlbum);
 | 
			
		||||
DEFINE_MEMBER_GETSET(MprisPlayer, trackAlbumArtist, setTrackAlbumArtist);
 | 
			
		||||
DEFINE_MEMBER_GETSET(MprisPlayer, trackArtUrl, setTrackArtUrl);
 | 
			
		||||
 | 
			
		||||
MprisPlaybackState::Enum MprisPlayer::playbackState() const { return this->mPlaybackState; }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -426,9 +370,7 @@ void MprisPlayer::setPlaybackState(MprisPlaybackState::Enum playbackState) {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
void MprisPlayer::play() { this->setPlaybackState(MprisPlaybackState::Playing); }
 | 
			
		||||
 | 
			
		||||
void MprisPlayer::pause() { this->setPlaybackState(MprisPlaybackState::Paused); }
 | 
			
		||||
 | 
			
		||||
void MprisPlayer::stop() { this->setPlaybackState(MprisPlaybackState::Stopped); }
 | 
			
		||||
 | 
			
		||||
void MprisPlayer::togglePlaying() {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -7,7 +7,7 @@
 | 
			
		|||
#include <qtypes.h>
 | 
			
		||||
 | 
			
		||||
#include "../../core/doc.hpp"
 | 
			
		||||
#include "../../core/types.hpp"
 | 
			
		||||
#include "../../core/util.hpp"
 | 
			
		||||
#include "../../dbus/properties.hpp"
 | 
			
		||||
#include "dbus_player.h"
 | 
			
		||||
#include "dbus_player_app.h"
 | 
			
		||||
| 
						 | 
				
			
			@ -239,8 +239,8 @@ public:
 | 
			
		|||
	[[nodiscard]] bool canRaise() const;
 | 
			
		||||
	[[nodiscard]] bool canSetFullscreen() const;
 | 
			
		||||
 | 
			
		||||
	[[nodiscard]] QString identity() const;
 | 
			
		||||
	[[nodiscard]] QString desktopEntry() const;
 | 
			
		||||
	[[nodiscard]] const QString& identity() const;
 | 
			
		||||
	[[nodiscard]] const QString& desktopEntry() const;
 | 
			
		||||
 | 
			
		||||
	[[nodiscard]] qlonglong positionMs() const;
 | 
			
		||||
	[[nodiscard]] qreal position() const;
 | 
			
		||||
| 
						 | 
				
			
			@ -254,13 +254,7 @@ public:
 | 
			
		|||
	[[nodiscard]] bool volumeSupported() const;
 | 
			
		||||
	void setVolume(qreal volume);
 | 
			
		||||
 | 
			
		||||
	[[nodiscard]] quint32 uniqueId() const;
 | 
			
		||||
	[[nodiscard]] QVariantMap metadata() const;
 | 
			
		||||
	[[nodiscard]] QString trackTitle() const;
 | 
			
		||||
	[[nodiscard]] QString trackAlbum() const;
 | 
			
		||||
	[[nodiscard]] QString trackAlbumArtist() const;
 | 
			
		||||
	[[nodiscard]] QVector<QString> trackArtists() const;
 | 
			
		||||
	[[nodiscard]] QString trackArtUrl() const;
 | 
			
		||||
	[[nodiscard]] const QVariantMap& metadata() const;
 | 
			
		||||
 | 
			
		||||
	[[nodiscard]] MprisPlaybackState::Enum playbackState() const;
 | 
			
		||||
	void setPlaybackState(MprisPlaybackState::Enum playbackState);
 | 
			
		||||
| 
						 | 
				
			
			@ -338,13 +332,6 @@ private slots:
 | 
			
		|||
	void onLoopStatusChanged();
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
	DropEmitter setLength(qlonglong length);
 | 
			
		||||
	DropEmitter setTrackTitle(QString title);
 | 
			
		||||
	DropEmitter setTrackAlbum(QString album);
 | 
			
		||||
	DropEmitter setTrackAlbumArtist(QString albumArtist);
 | 
			
		||||
	DropEmitter setTrackArtists(QVector<QString> artists);
 | 
			
		||||
	DropEmitter setTrackArtUrl(QString artUrl);
 | 
			
		||||
 | 
			
		||||
	// clang-format off
 | 
			
		||||
	dbus::DBusPropertyGroup appProperties;
 | 
			
		||||
	dbus::DBusProperty<QString> pIdentity {this->appProperties, "Identity"};
 | 
			
		||||
| 
						 | 
				
			
			@ -386,10 +373,26 @@ private:
 | 
			
		|||
	QString mTrackId;
 | 
			
		||||
	QString mTrackUrl;
 | 
			
		||||
	QString mTrackTitle;
 | 
			
		||||
	QVector<QString> mTrackArtists;
 | 
			
		||||
	QString mTrackAlbum;
 | 
			
		||||
	QString mTrackAlbumArtist;
 | 
			
		||||
	QVector<QString> mTrackArtists;
 | 
			
		||||
	QString mTrackArtUrl;
 | 
			
		||||
 | 
			
		||||
	DECLARE_MEMBER_NS(MprisPlayer, uniqueId, mUniqueId);
 | 
			
		||||
 | 
			
		||||
	DECLARE_MEMBER(MprisPlayer, length, mLength, lengthChanged);
 | 
			
		||||
	DECLARE_MEMBER_SET(length, setLength);
 | 
			
		||||
 | 
			
		||||
	// clang-format off
 | 
			
		||||
	DECLARE_PRIVATE_MEMBER(MprisPlayer, trackTitle, setTrackTitle, mTrackTitle, trackTitleChanged);
 | 
			
		||||
	DECLARE_PRIVATE_MEMBER(MprisPlayer, trackArtists, setTrackArtists, mTrackArtists, trackArtistsChanged);
 | 
			
		||||
	DECLARE_PRIVATE_MEMBER(MprisPlayer, trackAlbum, setTrackAlbum, mTrackAlbum, trackAlbumChanged);
 | 
			
		||||
	DECLARE_PRIVATE_MEMBER(MprisPlayer, trackAlbumArtist, setTrackAlbumArtist, mTrackAlbumArtist, trackAlbumArtistChanged);
 | 
			
		||||
	DECLARE_PRIVATE_MEMBER(MprisPlayer, trackArtUrl, setTrackArtUrl, mTrackArtUrl, trackArtUrlChanged);
 | 
			
		||||
	// clang-format on
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
	DECLARE_MEMBER_GET(uniqueId);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
} // namespace qs::service::mpris
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -8,9 +8,9 @@
 | 
			
		|||
#include <qtmetamacros.h>
 | 
			
		||||
#include <qtypes.h>
 | 
			
		||||
 | 
			
		||||
#include "../../core/util.hpp"
 | 
			
		||||
#include "../../core/desktopentry.hpp"
 | 
			
		||||
#include "../../core/iconimageprovider.hpp"
 | 
			
		||||
#include "../../core/util.hpp"
 | 
			
		||||
#include "dbusimage.hpp"
 | 
			
		||||
#include "server.hpp"
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -47,7 +47,7 @@ void NotificationAction::invoke() {
 | 
			
		|||
 | 
			
		||||
	NotificationServer::instance()->ActionInvoked(this->notification->id(), this->mIdentifier);
 | 
			
		||||
 | 
			
		||||
	if (!this->notification->isResident()) {
 | 
			
		||||
	if (!this->notification->resident()) {
 | 
			
		||||
		this->notification->close(NotificationCloseReason::Dismissed);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -88,8 +88,8 @@ void Notification::updateProperties(
 | 
			
		|||
	                                         : NotificationUrgency::Normal;
 | 
			
		||||
 | 
			
		||||
	auto hasActionIcons = hints.value("action-icons").value<bool>();
 | 
			
		||||
	auto isResident = hints.value("resident").value<bool>();
 | 
			
		||||
	auto isTransient = hints.value("transient").value<bool>();
 | 
			
		||||
	auto resident = hints.value("resident").value<bool>();
 | 
			
		||||
	auto transient = hints.value("transient").value<bool>();
 | 
			
		||||
	auto desktopEntry = hints.value("desktop-entry").value<QString>();
 | 
			
		||||
 | 
			
		||||
	QString imageDataName;
 | 
			
		||||
| 
						 | 
				
			
			@ -131,20 +131,18 @@ void Notification::updateProperties(
 | 
			
		|||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	DROP_EMIT_SET(this, appName, mAppName, appNameChanged);
 | 
			
		||||
	DROP_EMIT_SET(this, appIcon, mAppIcon, appIconChanged);
 | 
			
		||||
	DROP_EMIT_SET(this, summary, mSummary, summaryChanged);
 | 
			
		||||
	DROP_EMIT_SET(this, body, mBody, bodyChanged);
 | 
			
		||||
	DROP_EMIT_SET(this, expireTimeout, mExpireTimeout, expireTimeoutChanged);
 | 
			
		||||
	DEFINE_DROP_EMIT_IF(urgency != this->mUrgency, this, urgencyChanged);
 | 
			
		||||
	DROP_EMIT_SET(this, hasActionIcons, mHasActionIcons, hasActionIconsChanged);
 | 
			
		||||
	DROP_EMIT_SET(this, isResident, mIsResident, isResidentChanged);
 | 
			
		||||
	DROP_EMIT_SET(this, isTransient, mIsTransient, isTransientChanged);
 | 
			
		||||
	DROP_EMIT_SET(this, desktopEntry, mDesktopEntry, desktopEntryChanged);
 | 
			
		||||
	auto expireTimeoutChanged = this->setExpireTimeout(expireTimeout);
 | 
			
		||||
	auto appNameChanged = this->setAppName(appName);
 | 
			
		||||
	auto appIconChanged = this->setAppIcon(appIcon);
 | 
			
		||||
	auto summaryChanged = this->setSummary(summary);
 | 
			
		||||
	auto bodyChanged = this->setBody(body);
 | 
			
		||||
	auto urgencyChanged = this->setUrgency(static_cast<NotificationUrgency::Enum>(urgency));
 | 
			
		||||
	auto hasActionIconsChanged = this->setHasActionIcons(hasActionIcons);
 | 
			
		||||
	auto residentChanged = this->setResident(resident);
 | 
			
		||||
	auto transientChanged = this->setTransient(transient);
 | 
			
		||||
	auto desktopEntryChanged = this->setDesktopEntry(desktopEntry);
 | 
			
		||||
	DEFINE_DROP_EMIT_IF(imagePixmap || imagePath != this->mImagePath, this, imageChanged);
 | 
			
		||||
	DROP_EMIT_SET(this, hints, mHints, hintsChanged);
 | 
			
		||||
 | 
			
		||||
	if (urgencyChanged) this->mUrgency = static_cast<NotificationUrgency::Enum>(urgency);
 | 
			
		||||
	auto hintsChanged = this->setHints(hints);
 | 
			
		||||
 | 
			
		||||
	NotificationImage* oldImage = nullptr;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -154,8 +152,6 @@ void Notification::updateProperties(
 | 
			
		|||
		this->mImagePath = imagePath;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (hintsChanged) this->mHints = hints;
 | 
			
		||||
 | 
			
		||||
	bool actionsChanged = false;
 | 
			
		||||
	auto deletedActions = QVector<NotificationAction*>();
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -195,6 +191,21 @@ void Notification::updateProperties(
 | 
			
		|||
		                            << "sent an action set of an invalid length.";
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	DropEmitter::call(
 | 
			
		||||
	    expireTimeoutChanged,
 | 
			
		||||
	    appNameChanged,
 | 
			
		||||
	    appIconChanged,
 | 
			
		||||
	    summaryChanged,
 | 
			
		||||
	    bodyChanged,
 | 
			
		||||
	    urgencyChanged,
 | 
			
		||||
	    hasActionIconsChanged,
 | 
			
		||||
	    residentChanged,
 | 
			
		||||
	    transientChanged,
 | 
			
		||||
	    desktopEntryChanged,
 | 
			
		||||
	    imageChanged,
 | 
			
		||||
	    hintsChanged
 | 
			
		||||
	);
 | 
			
		||||
 | 
			
		||||
	if (actionsChanged) emit this->actionsChanged();
 | 
			
		||||
 | 
			
		||||
	for (auto* action: deletedActions) {
 | 
			
		||||
| 
						 | 
				
			
			@ -217,17 +228,17 @@ void Notification::setTracked(bool tracked) {
 | 
			
		|||
bool Notification::isLastGeneration() const { return this->mLastGeneration; }
 | 
			
		||||
void Notification::setLastGeneration() { this->mLastGeneration = true; }
 | 
			
		||||
 | 
			
		||||
qreal Notification::expireTimeout() const { return this->mExpireTimeout; }
 | 
			
		||||
QString Notification::appName() const { return this->mAppName; }
 | 
			
		||||
QString Notification::appIcon() const { return this->mAppIcon; }
 | 
			
		||||
QString Notification::summary() const { return this->mSummary; }
 | 
			
		||||
QString Notification::body() const { return this->mBody; }
 | 
			
		||||
NotificationUrgency::Enum Notification::urgency() const { return this->mUrgency; }
 | 
			
		||||
QVector<NotificationAction*> Notification::actions() const { return this->mActions; }
 | 
			
		||||
bool Notification::hasActionIcons() const { return this->mHasActionIcons; }
 | 
			
		||||
bool Notification::isResident() const { return this->mIsResident; }
 | 
			
		||||
bool Notification::isTransient() const { return this->mIsTransient; }
 | 
			
		||||
QString Notification::desktopEntry() const { return this->mDesktopEntry; }
 | 
			
		||||
DEFINE_MEMBER_GETSET(Notification, expireTimeout, setExpireTimeout);
 | 
			
		||||
DEFINE_MEMBER_GETSET(Notification, appName, setAppName);
 | 
			
		||||
DEFINE_MEMBER_GETSET(Notification, appIcon, setAppIcon);
 | 
			
		||||
DEFINE_MEMBER_GETSET(Notification, summary, setSummary);
 | 
			
		||||
DEFINE_MEMBER_GETSET(Notification, body, setBody);
 | 
			
		||||
DEFINE_MEMBER_GETSET(Notification, urgency, setUrgency);
 | 
			
		||||
DEFINE_MEMBER_GET(Notification, actions);
 | 
			
		||||
DEFINE_MEMBER_GETSET(Notification, hasActionIcons, setHasActionIcons);
 | 
			
		||||
DEFINE_MEMBER_GETSET(Notification, resident, setResident);
 | 
			
		||||
DEFINE_MEMBER_GETSET(Notification, transient, setTransient);
 | 
			
		||||
DEFINE_MEMBER_GETSET(Notification, desktopEntry, setDesktopEntry);
 | 
			
		||||
 | 
			
		||||
QString Notification::image() const {
 | 
			
		||||
	if (this->mImagePixmap) {
 | 
			
		||||
| 
						 | 
				
			
			@ -237,6 +248,6 @@ QString Notification::image() const {
 | 
			
		|||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QVariantMap Notification::hints() const { return this->mHints; }
 | 
			
		||||
DEFINE_MEMBER_GETSET(Notification, hints, setHints);
 | 
			
		||||
 | 
			
		||||
} // namespace qs::service::notifications
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -9,6 +9,7 @@
 | 
			
		|||
#include <qtmetamacros.h>
 | 
			
		||||
 | 
			
		||||
#include "../../core/retainable.hpp"
 | 
			
		||||
#include "../../core/util.hpp"
 | 
			
		||||
 | 
			
		||||
namespace qs::service::notifications {
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -94,9 +95,9 @@ class Notification
 | 
			
		|||
	/// See @@NotificationAction.identifier for details.
 | 
			
		||||
	Q_PROPERTY(bool hasActionIcons READ hasActionIcons NOTIFY hasActionIconsChanged);
 | 
			
		||||
	/// If true, the notification will not be destroyed after an action is invoked.
 | 
			
		||||
	Q_PROPERTY(bool resident READ isResident NOTIFY isResidentChanged);
 | 
			
		||||
	Q_PROPERTY(bool resident READ resident NOTIFY residentChanged);
 | 
			
		||||
	/// If true, the notification should skip any kind of persistence function like a notification area.
 | 
			
		||||
	Q_PROPERTY(bool transient READ isTransient NOTIFY isTransientChanged);
 | 
			
		||||
	Q_PROPERTY(bool transient READ transient NOTIFY transientChanged);
 | 
			
		||||
	/// The name of the sender's desktop entry or "" if none was supplied.
 | 
			
		||||
	Q_PROPERTY(QString desktopEntry READ desktopEntry NOTIFY desktopEntryChanged);
 | 
			
		||||
	/// An image associated with the notification.
 | 
			
		||||
| 
						 | 
				
			
			@ -140,19 +141,7 @@ public:
 | 
			
		|||
	[[nodiscard]] bool isLastGeneration() const;
 | 
			
		||||
	void setLastGeneration();
 | 
			
		||||
 | 
			
		||||
	[[nodiscard]] qreal expireTimeout() const;
 | 
			
		||||
	[[nodiscard]] QString appName() const;
 | 
			
		||||
	[[nodiscard]] QString appIcon() const;
 | 
			
		||||
	[[nodiscard]] QString summary() const;
 | 
			
		||||
	[[nodiscard]] QString body() const;
 | 
			
		||||
	[[nodiscard]] NotificationUrgency::Enum urgency() const;
 | 
			
		||||
	[[nodiscard]] QVector<NotificationAction*> actions() const;
 | 
			
		||||
	[[nodiscard]] bool hasActionIcons() const;
 | 
			
		||||
	[[nodiscard]] bool isResident() const;
 | 
			
		||||
	[[nodiscard]] bool isTransient() const;
 | 
			
		||||
	[[nodiscard]] QString desktopEntry() const;
 | 
			
		||||
	[[nodiscard]] QString image() const;
 | 
			
		||||
	[[nodiscard]] QVariantMap hints() const;
 | 
			
		||||
 | 
			
		||||
signals:
 | 
			
		||||
	/// Sent when a notification has been closed.
 | 
			
		||||
| 
						 | 
				
			
			@ -169,8 +158,8 @@ signals:
 | 
			
		|||
	void urgencyChanged();
 | 
			
		||||
	void actionsChanged();
 | 
			
		||||
	void hasActionIconsChanged();
 | 
			
		||||
	void isResidentChanged();
 | 
			
		||||
	void isTransientChanged();
 | 
			
		||||
	void residentChanged();
 | 
			
		||||
	void transientChanged();
 | 
			
		||||
	void desktopEntryChanged();
 | 
			
		||||
	void imageChanged();
 | 
			
		||||
	void hintsChanged();
 | 
			
		||||
| 
						 | 
				
			
			@ -187,12 +176,27 @@ private:
 | 
			
		|||
	NotificationUrgency::Enum mUrgency = NotificationUrgency::Normal;
 | 
			
		||||
	QVector<NotificationAction*> mActions;
 | 
			
		||||
	bool mHasActionIcons = false;
 | 
			
		||||
	bool mIsResident = false;
 | 
			
		||||
	bool mIsTransient = false;
 | 
			
		||||
	bool mResident = false;
 | 
			
		||||
	bool mTransient = false;
 | 
			
		||||
	QString mImagePath;
 | 
			
		||||
	NotificationImage* mImagePixmap = nullptr;
 | 
			
		||||
	QString mDesktopEntry;
 | 
			
		||||
	QVariantMap mHints;
 | 
			
		||||
 | 
			
		||||
	// clang-format off
 | 
			
		||||
	DECLARE_PRIVATE_MEMBER(Notification, expireTimeout, setExpireTimeout, mExpireTimeout, expireTimeoutChanged);
 | 
			
		||||
	DECLARE_PRIVATE_MEMBER(Notification, appName, setAppName, mAppName, appNameChanged);
 | 
			
		||||
	DECLARE_PRIVATE_MEMBER(Notification, appIcon, setAppIcon, mAppIcon, appIconChanged);
 | 
			
		||||
	DECLARE_PRIVATE_MEMBER(Notification, summary, setSummary, mSummary, summaryChanged);
 | 
			
		||||
	DECLARE_PRIVATE_MEMBER(Notification, body, setBody, mBody, bodyChanged);
 | 
			
		||||
	DECLARE_PRIVATE_MEMBER(Notification, urgency, setUrgency, mUrgency, urgencyChanged);
 | 
			
		||||
	DECLARE_MEMBER_WITH_GET(Notification, actions, mActions, actionsChanged);
 | 
			
		||||
	DECLARE_PRIVATE_MEMBER(Notification, hasActionIcons, setHasActionIcons, mHasActionIcons, hasActionIconsChanged);
 | 
			
		||||
	DECLARE_PRIVATE_MEMBER(Notification, resident, setResident, mResident, residentChanged);
 | 
			
		||||
	DECLARE_PRIVATE_MEMBER(Notification, transient, setTransient, mTransient, transientChanged);
 | 
			
		||||
	DECLARE_PRIVATE_MEMBER(Notification, desktopEntry, setDesktopEntry, mDesktopEntry, desktopEntryChanged);
 | 
			
		||||
	DECLARE_PRIVATE_MEMBER(Notification, hints, setHints, mHints, hintsChanged);
 | 
			
		||||
	// clang-format on
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
///! An action associated with a Notification.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue