Skip to content

Commit db9e633

Browse files
committed
service/mpris: adopt bindable properties
1 parent 1955dee commit db9e633

File tree

3 files changed

+263
-250
lines changed

3 files changed

+263
-250
lines changed

src/core/util.hpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,3 +290,24 @@ bool setSimpleObjectHandle(auto* parent, auto* value) {
290290
[[nodiscard]] Type getter() { return this->member.value(); } \
291291
[[nodiscard]] QBindable<Type> bindable() { return &this->member; }
292292
// NOLINTEND
293+
294+
template <auto methodPtr>
295+
class MethodFunctor {
296+
using PtrMeta = MemberPointerTraits<decltype(methodPtr)>;
297+
using Class = PtrMeta::Class;
298+
299+
public:
300+
MethodFunctor(Class* obj): obj(obj) {}
301+
302+
void operator()() { (this->obj->*methodPtr)(); }
303+
304+
private:
305+
Class* obj;
306+
};
307+
308+
// NOLINTBEGIN
309+
#define QS_BINDING_SUBSCRIBE_METHOD(Class, bindable, method, strategy) \
310+
QPropertyChangeHandler<MethodFunctor<&Class::method>> \
311+
_qs_method_subscribe_##bindable##_##method = \
312+
(bindable).strategy(MethodFunctor<&Class::method>(this));
313+
// NOLINTEND

0 commit comments

Comments
 (0)