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

View File

@ -24,6 +24,8 @@
#include <QObject>
#include "src/model/interface.h"
/**
* @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:
enum class Sound
{
@ -106,8 +107,8 @@ public:
virtual operator bool() const = 0;
signals:
void finishedPlaying();
void invalidated();
DECLARE_SIGNAL(finishedPlaying);
DECLARE_SIGNAL(invalidated);
};
#endif // IAUDIOSINK_H

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -17,6 +17,9 @@
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"
class Core;
@ -24,8 +27,9 @@ class QFile;
class QPoint;
class Profile;
class ProfileInfo : public IProfileInfo
class ProfileInfo : public QObject, public IProfileInfo
{
Q_OBJECT
public:
ProfileInfo(Core* core, Profile* profile);
@ -50,6 +54,10 @@ public:
SetAvatarResult setAvatar(const QString& path) 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:
IProfileInfo::SetAvatarResult createAvatarFromFile(QFile& file, QByteArray& avatar);
IProfileInfo::SetAvatarResult byteArrayToPng(QByteArray inData, QByteArray& outPng);

View File

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