Browse Source

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.
reviewable/pr5545/r2
Anthony Bilinski 6 years ago
parent
commit
82a4f1b412
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C
  1. 16
      src/audio/backend/alsink.h
  2. 9
      src/audio/iaudiosink.h
  3. 11
      src/core/toxcall.cpp
  4. 4
      src/core/toxcall.h
  5. 4
      src/model/about/aboutfriend.h
  6. 5
      src/model/about/iaboutfriend.h
  7. 12
      src/model/profile/iprofileinfo.h
  8. 10
      src/model/profile/profileinfo.h
  9. 6
      src/util/strongtype.h

16
src/audio/backend/alsink.h

@ -23,11 +23,12 @@ @@ -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: @@ -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;

9
src/audio/iaudiosink.h

@ -24,6 +24,8 @@ @@ -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 @@ @@ -65,9 +67,8 @@
*
*/
class IAudioSink : public QObject
class IAudioSink
{
Q_OBJECT
public:
enum class Sound
{
@ -106,8 +107,8 @@ public: @@ -106,8 +107,8 @@ public:
virtual operator bool() const = 0;
signals:
void finishedPlaying();
void invalidated();
DECLARE_SIGNAL(finishedPlaying);
DECLARE_SIGNAL(invalidated);
};
#endif // IAUDIOSINK_H

11
src/core/toxcall.cpp

@ -139,9 +139,7 @@ ToxFriendCall::ToxFriendCall(uint32_t FriendNum, bool VideoEnabled, CoreAV& av, @@ -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() @@ -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) @@ -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});

4
src/core/toxcall.h

@ -38,8 +38,10 @@ class AudioFilterer; @@ -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);

4
src/model/about/aboutfriend.h

@ -21,7 +21,7 @@ @@ -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 @@ @@ -29,7 +29,7 @@
class Friend;
class IFriendSettings;
class AboutFriend : public IAboutFriend
class AboutFriend : public QObject, public IAboutFriend
{
Q_OBJECT

5
src/model/about/iaboutfriend.h

@ -22,12 +22,11 @@ @@ -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;

12
src/model/profile/iprofileinfo.h

@ -17,13 +17,14 @@ @@ -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: @@ -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&);
};

10
src/model/profile/profileinfo.h

@ -17,6 +17,9 @@ @@ -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; @@ -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: @@ -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);

6
src/util/strongtype.h

@ -17,8 +17,8 @@ @@ -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) @@ -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

Loading…
Cancel
Save