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

fix(model): stop interfaces from inheriting from QObject

Qt doesn't support QObject multiple inheritance, so use our existing interface
macros to declare signals in the interface without QObject, and implement them
in child classes.

(cherry picked from commit 82a4f1b412)
This commit is contained in:
Anthony Bilinski 2019-10-10 02:48:06 -07:00
parent 40e43586f1
commit b7062b2518
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C
9 changed files with 43 additions and 34 deletions

View File

@ -23,11 +23,12 @@
#include <QMutex> #include <QMutex>
#include <QObject> #include <QObject>
#include "src/model/interface.h"
#include "src/audio/iaudiosink.h" #include "src/audio/iaudiosink.h"
class OpenAL; class OpenAL;
class QMutex; class QMutex;
class AlSink : public IAudioSink class AlSink : public QObject, public IAudioSink
{ {
Q_OBJECT Q_OBJECT
public: public:
@ -38,16 +39,19 @@ public:
AlSink& operator=(AlSink&& other) = delete; AlSink& operator=(AlSink&& other) = delete;
~AlSink(); ~AlSink();
void playAudioBuffer(const int16_t* data, int samples, unsigned channels, int sampleRate) const; void playAudioBuffer(const int16_t* data, int samples, unsigned channels, int sampleRate) const override;
void playMono16Sound(const IAudioSink::Sound& sound); void playMono16Sound(const IAudioSink::Sound& sound) override;
void startLoop(); void startLoop() override;
void stopLoop(); void stopLoop() override;
operator bool() const; operator bool() const override;
uint getSourceId() const; uint getSourceId() const;
void kill(); void kill();
SIGNAL_IMPL(AlSink, finishedPlaying)
SIGNAL_IMPL(AlSink, invalidated)
private: private:
OpenAL& audio; OpenAL& audio;
uint sourceId; uint sourceId;

View File

@ -24,6 +24,8 @@
#include <QObject> #include <QObject>
#include "src/model/interface.h"
/** /**
* @brief The IAudioSink class represents an interface to devices that can play audio. * @brief The IAudioSink class represents an interface to devices that can play audio.
* *
@ -65,9 +67,8 @@
* *
*/ */
class IAudioSink : public QObject class IAudioSink
{ {
Q_OBJECT
public: public:
enum class Sound enum class Sound
{ {
@ -106,8 +107,8 @@ public:
virtual operator bool() const = 0; virtual operator bool() const = 0;
signals: signals:
void finishedPlaying(); DECLARE_SIGNAL(finishedPlaying);
void invalidated(); DECLARE_SIGNAL(invalidated);
}; };
#endif // IAUDIOSINK_H #endif // IAUDIOSINK_H

View File

@ -139,9 +139,7 @@ ToxFriendCall::ToxFriendCall(uint32_t FriendNum, bool VideoEnabled, CoreAV& av,
qDebug() << "Audio input connection not working"; qDebug() << "Audio input connection not working";
} }
audioSinkInvalid = QObject::connect(sink.get(), &IAudioSink::invalidated, audioSinkInvalid = sink->connectTo_invalidated([this]() { this->onAudioSinkInvalidated(); });
[this]() { this->onAudioSinkInvalidated(); });
// register video // register video
if (videoEnabled) { if (videoEnabled) {
@ -185,8 +183,7 @@ void ToxFriendCall::onAudioSinkInvalidated()
{ {
auto newSink = audio.makeSink(); auto newSink = audio.makeSink();
audioSinkInvalid = QObject::connect(newSink.get(), &IAudioSink::invalidated, audioSinkInvalid = newSink->connectTo_invalidated([this]() { this->onAudioSinkInvalidated(); });
[this]() { this->onAudioSinkInvalidated(); });
sink = std::move(newSink); sink = std::move(newSink);
} }
@ -272,9 +269,7 @@ void ToxGroupCall::removePeer(ToxPk peerId)
void ToxGroupCall::addPeer(ToxPk peerId) void ToxGroupCall::addPeer(ToxPk peerId)
{ {
std::unique_ptr<IAudioSink> newSink = audio.makeSink(); std::unique_ptr<IAudioSink> newSink = audio.makeSink();
QMetaObject::Connection con = QMetaObject::Connection con = newSink->connectTo_invalidated([this, peerId]() { this->onAudioSinkInvalidated(peerId); });
QObject::connect(newSink.get(), &IAudioSink::invalidated,
[this, peerId]() { this->onAudioSinkInvalidated(peerId); });
peers.emplace(peerId, std::move(newSink)); peers.emplace(peerId, std::move(newSink));
sinkInvalid.insert({peerId, con}); sinkInvalid.insert({peerId, con});

View File

@ -38,8 +38,10 @@ class AudioFilterer;
class CoreVideoSource; class CoreVideoSource;
class CoreAV; class CoreAV;
class ToxCall class ToxCall : public QObject
{ {
Q_OBJECT
protected: protected:
ToxCall() = delete; ToxCall() = delete;
ToxCall(bool VideoEnabled, CoreAV& av, IAudioControl& audio); ToxCall(bool VideoEnabled, CoreAV& av, IAudioControl& audio);

View File

@ -21,7 +21,7 @@
#define ABOUT_FRIEND_H #define ABOUT_FRIEND_H
#include "iaboutfriend.h" #include "iaboutfriend.h"
#include "src/model/interface.h"
#include "src/persistence/ifriendsettings.h" #include "src/persistence/ifriendsettings.h"
#include <QObject> #include <QObject>
@ -29,7 +29,7 @@
class Friend; class Friend;
class IFriendSettings; class IFriendSettings;
class AboutFriend : public IAboutFriend class AboutFriend : public QObject, public IAboutFriend
{ {
Q_OBJECT Q_OBJECT

View File

@ -22,12 +22,11 @@
#include "src/model/interface.h" #include "src/model/interface.h"
#include "src/persistence/ifriendsettings.h" #include "src/persistence/ifriendsettings.h"
#include <QObject> #include <QObject>
class IAboutFriend : public QObject class IAboutFriend
{ {
Q_OBJECT
public: public:
virtual QString getName() const = 0; virtual QString getName() const = 0;
virtual QString getStatusMessage() const = 0; virtual QString getStatusMessage() const = 0;

View File

@ -17,13 +17,14 @@
along with qTox. If not, see <http://www.gnu.org/licenses/>. along with qTox. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "src/model/interface.h"
#include <QObject> #include <QObject>
class ToxId; class ToxId;
class IProfileInfo : public QObject class IProfileInfo
{ {
Q_OBJECT
public: public:
enum class RenameResult { enum class RenameResult {
OK, EmptyName, ProfileAlreadyExists, Error OK, EmptyName, ProfileAlreadyExists, Error
@ -58,8 +59,7 @@ public:
virtual SetAvatarResult setAvatar(const QString& path) = 0; virtual SetAvatarResult setAvatar(const QString& path) = 0;
virtual void removeAvatar() = 0; virtual void removeAvatar() = 0;
signals: DECLARE_SIGNAL(idChanged, const ToxId&);
void idChanged(const ToxId& id); DECLARE_SIGNAL(usernameChanged, const QString&);
void usernameChanged(const QString& username); DECLARE_SIGNAL(statusMessageChanged, const QString&);
void statusMessageChanged(const QString& message);
}; };

View File

@ -17,6 +17,9 @@
along with qTox. If not, see <http://www.gnu.org/licenses/>. along with qTox. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <QObject>
#include "src/model/interface.h"
#include "src/core/toxpk.h"
#include "iprofileinfo.h" #include "iprofileinfo.h"
class Core; class Core;
@ -24,8 +27,9 @@ class QFile;
class QPoint; class QPoint;
class Profile; class Profile;
class ProfileInfo : public IProfileInfo class ProfileInfo : public QObject, public IProfileInfo
{ {
Q_OBJECT
public: public:
ProfileInfo(Core* core, Profile* profile); ProfileInfo(Core* core, Profile* profile);
@ -50,6 +54,10 @@ public:
SetAvatarResult setAvatar(const QString& path) override; SetAvatarResult setAvatar(const QString& path) override;
void removeAvatar() override; void removeAvatar() override;
SIGNAL_IMPL(ProfileInfo, idChanged, const ToxId& id)
SIGNAL_IMPL(ProfileInfo, usernameChanged, const QString& name)
SIGNAL_IMPL(ProfileInfo, statusMessageChanged, const QString& message)
private: private:
IProfileInfo::SetAvatarResult createAvatarFromFile(QFile& file, QByteArray& avatar); IProfileInfo::SetAvatarResult createAvatarFromFile(QFile& file, QByteArray& avatar);
IProfileInfo::SetAvatarResult byteArrayToPng(QByteArray inData, QByteArray& outPng); IProfileInfo::SetAvatarResult byteArrayToPng(QByteArray inData, QByteArray& outPng);

View File

@ -17,8 +17,8 @@
along with qTox. If not, see <http://www.gnu.org/licenses/>. along with qTox. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef STORNGTYPE_H #ifndef STRONGTYPE_H
#define STORNGTYPE_H #define STRONGTYPE_H
#include <QHash> #include <QHash>
@ -129,4 +129,4 @@ uint qHash(const NamedType<T, Tag, Properties...>& key, uint seed = 0)
{ {
return qHash(key.get(), seed); return qHash(key.get(), seed);
} }
#endif // STORNGTYPE_H #endif // STRONGTYPE_H