Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
fix(model): stop interfaces from inheriting from QObject
Browse files Browse the repository at this point in the history
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 82a4f1b)
  • Loading branch information
anthonybilinski committed Mar 20, 2020
1 parent 40e4358 commit b7062b2
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 34 deletions.
16 changes: 10 additions & 6 deletions src/audio/backend/alsink.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -38,16 +39,19 @@ class AlSink : public IAudioSink
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;
Expand Down
9 changes: 5 additions & 4 deletions src/audio/iaudiosink.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

#include <QObject>

#include "src/model/interface.h"

/**
* @brief The IAudioSink class represents an interface to devices that can play audio.
*
Expand Down Expand Up @@ -65,9 +67,8 @@
*
*/

class IAudioSink : public QObject
class IAudioSink
{
Q_OBJECT
public:
enum class Sound
{
Expand Down Expand Up @@ -106,8 +107,8 @@ class IAudioSink : public QObject
virtual operator bool() const = 0;

signals:
void finishedPlaying();
void invalidated();
DECLARE_SIGNAL(finishedPlaying);
DECLARE_SIGNAL(invalidated);
};

#endif // IAUDIOSINK_H
11 changes: 3 additions & 8 deletions src/core/toxcall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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});
Expand Down
4 changes: 3 additions & 1 deletion src/core/toxcall.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/model/about/aboutfriend.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
#define ABOUT_FRIEND_H

#include "iaboutfriend.h"

#include "src/model/interface.h"
#include "src/persistence/ifriendsettings.h"

#include <QObject>

class Friend;
class IFriendSettings;

class AboutFriend : public IAboutFriend
class AboutFriend : public QObject, public IAboutFriend
{
Q_OBJECT

Expand Down
5 changes: 2 additions & 3 deletions src/model/about/iaboutfriend.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions src/model/profile/iprofileinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -58,8 +59,7 @@ class IProfileInfo : public QObject
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&);
};
10 changes: 9 additions & 1 deletion src/model/profile/profileinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,19 @@
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;
class QFile;
class QPoint;
class Profile;

class ProfileInfo : public IProfileInfo
class ProfileInfo : public QObject, public IProfileInfo
{
Q_OBJECT
public:
ProfileInfo(Core* core, Profile* profile);

Expand All @@ -50,6 +54,10 @@ class ProfileInfo : public IProfileInfo
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);
Expand Down
6 changes: 3 additions & 3 deletions src/util/strongtype.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down Expand Up @@ -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

0 comments on commit b7062b2

Please sign in to comment.