1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

refactor(interface): Add connectTo_* virtual method instead of signals

This commit is contained in:
Diadlo 2017-09-05 23:28:51 +03:00
parent 918cdf1368
commit a626888daa
No known key found for this signature in database
GPG Key ID: 5AF9F2E29107C727
4 changed files with 53 additions and 10 deletions

View File

@ -89,7 +89,7 @@ void AboutFriend::setAutoGroupInvite(bool enabled)
const ToxPk pk = f->getPublicKey();
Settings::getInstance().setAutoGroupInvite(pk, enabled);
Settings::getInstance().savePersonal();
emit autoGroupInviteChaged(enabled);
emit autoGroupInviteChanged(enabled);
}
bool AboutFriend::clearHistory()

View File

@ -34,6 +34,29 @@ public:
bool clearHistory() override;
CHANGED_SIGNAL_IMPL(QString, AboutFriend, name)
CHANGED_SIGNAL_IMPL(QString, AboutFriend, status)
CHANGED_SIGNAL_IMPL(QString, AboutFriend, publicKey)
CHANGED_SIGNAL_IMPL(QPixmap, AboutFriend, avatar)
CHANGED_SIGNAL_IMPL(QString, AboutFriend, note)
CHANGED_SIGNAL_IMPL(QString, AboutFriend, autoAcceptDir)
CHANGED_SIGNAL_IMPL(AutoAcceptCallFlags, AboutFriend, autoAcceptCall)
CHANGED_SIGNAL_IMPL(bool, AboutFriend, autoGroupInvite)
signals:
void nameChanged(const QString& name);
void statusChanged(const QString& status);
void publicKeyChanged(const QString& pk);
void avatarChanged(const QPixmap& avatar);
void noteChanged(const QString& val);
void autoAcceptDirChanged(const QString& path);
void autoAcceptCallChanged(const AutoAcceptCallFlags& flag);
void autoGroupInviteChanged(const bool& enabled);
private:
const Friend* const f;
};

View File

@ -1,6 +1,7 @@
#ifndef I_ABOUT_FRIEND_H
#define I_ABOUT_FRIEND_H
#include "src/model/interface.h"
#include <QObject>
class IAboutFriend : public QObject
@ -37,17 +38,17 @@ public:
virtual bool clearHistory() = 0;
signals:
void nameChanged(const QString& name) const;
void statusChanged(const QString& status) const;
void publicKeyChanged(const QString& pk) const;
/* signals */
CHANGED_SIGNAL(QString, name);
CHANGED_SIGNAL(QString, status);
CHANGED_SIGNAL(QString, publicKey);
void avatarChanged(const QPixmap& avatar) const;
void noteChanged(const QString& note) const;
CHANGED_SIGNAL(QPixmap, avatar);
CHANGED_SIGNAL(QString, note);
void autoAcceptDirChanged(const QString& dir);
void autoAcceptCallChanged(AutoAcceptCall flag);
void autoGroupInviteChaged(bool enabled);
CHANGED_SIGNAL(QString, autoAcceptDir);
CHANGED_SIGNAL(AutoAcceptCallFlags, autoAcceptCall);
CHANGED_SIGNAL(bool, autoGroupInvite);
};
#endif // I_ABOUT_FRIEND_H

19
src/model/interface.h Normal file
View File

@ -0,0 +1,19 @@
#ifndef INTERFACE_H
#define INTERFACE_H
#include <functional>
#define CHANGED_SIGNAL(type, name) \
using Slot_##name = std::function<void (const type& val)>; \
virtual void connectTo_##name##Changed(Slot_##name slot) = 0; \
virtual void connectTo_##name##Changed(QObject* handler, Slot_##name slot) = 0
#define CHANGED_SIGNAL_IMPL(type, classname, name) \
void connectTo_##name##Changed(Slot_##name slot) override { \
connect(this, &classname::name##Changed, slot); \
} \
void connectTo_##name##Changed(QObject* handler, Slot_##name slot) override { \
connect(this, &classname::name##Changed, handler, slot); \
}
#endif // INTERFACE_H