mirror of https://github.com/qTox/qTox.git
5 changed files with 200 additions and 0 deletions
@ -0,0 +1,101 @@
@@ -0,0 +1,101 @@
|
||||
#include "aboutfriend.h" |
||||
|
||||
#include "src/nexus.h" |
||||
#include "src/persistence/profile.h" |
||||
#include "src/persistence/settings.h" |
||||
|
||||
AboutFriend::AboutFriend(const Friend* f) |
||||
: f{f} |
||||
{ |
||||
} |
||||
|
||||
QString AboutFriend::getName() const |
||||
{ |
||||
return f->getDisplayedName(); |
||||
} |
||||
|
||||
QString AboutFriend::getStatusMessage() const |
||||
{ |
||||
return f->getStatusMessage(); |
||||
} |
||||
|
||||
QString AboutFriend::getPublicKey() const |
||||
{ |
||||
return f->getPublicKey().toString(); |
||||
} |
||||
|
||||
QPixmap AboutFriend::getAvatar() const |
||||
{ |
||||
const QString pk = f->getPublicKey().toString(); |
||||
const QPixmap avatar = Nexus::getProfile()->loadAvatar(pk); |
||||
return avatar.isNull() ? QPixmap(QStringLiteral(":/img/contact_dark.svg")) |
||||
: avatar; |
||||
} |
||||
|
||||
QString AboutFriend::getNote() const |
||||
{ |
||||
const ToxPk pk = f->getPublicKey(); |
||||
return Settings::getInstance().getContactNote(pk); |
||||
} |
||||
|
||||
void AboutFriend::setNote(const QString& note) |
||||
{ |
||||
const ToxPk pk = f->getPublicKey(); |
||||
Settings::getInstance().setContactNote(pk, note); |
||||
Settings::getInstance().savePersonal(); |
||||
emit noteChanged(note); |
||||
} |
||||
|
||||
QString AboutFriend::getAutoAcceptDir() const |
||||
{ |
||||
const ToxPk pk = f->getPublicKey(); |
||||
return Settings::getInstance().getAutoAcceptDir(pk); |
||||
} |
||||
|
||||
void AboutFriend::setAutoAcceptDir(const QString& path) |
||||
{ |
||||
const ToxPk pk = f->getPublicKey(); |
||||
Settings::getInstance().setAutoAcceptDir(pk, path); |
||||
Settings::getInstance().savePersonal(); |
||||
emit autoAcceptDirChanged(path); |
||||
} |
||||
|
||||
IAboutFriend::AutoAcceptCallFlags AboutFriend::getAutoAcceptCall() const |
||||
{ |
||||
const ToxPk pk = f->getPublicKey(); |
||||
const int value = static_cast<int>(Settings::getInstance().getAutoAcceptCall(pk)); |
||||
return static_cast<IAboutFriend::AutoAcceptCallFlags>(value); |
||||
} |
||||
|
||||
void AboutFriend::setAutoAcceptCall(AutoAcceptCallFlags flag) |
||||
{ |
||||
const ToxPk pk = f->getPublicKey(); |
||||
const int value = static_cast<int>(flag); |
||||
const Settings::AutoAcceptCallFlags sFlag(value); |
||||
Settings::getInstance().setAutoAcceptCall(pk, sFlag); |
||||
Settings::getInstance().savePersonal(); |
||||
emit autoAcceptCallChanged(flag); |
||||
} |
||||
|
||||
bool AboutFriend::getAutoGroupInvite() const |
||||
{ |
||||
const ToxPk pk = f->getPublicKey(); |
||||
return Settings::getInstance().getAutoGroupInvite(pk); |
||||
} |
||||
|
||||
void AboutFriend::setAutoGroupInvite(bool enabled) |
||||
{ |
||||
const ToxPk pk = f->getPublicKey(); |
||||
Settings::getInstance().setAutoGroupInvite(pk, enabled); |
||||
Settings::getInstance().savePersonal(); |
||||
emit autoGroupInviteChaged(enabled); |
||||
} |
||||
|
||||
bool AboutFriend::clearHistory() |
||||
{ |
||||
const ToxPk pk = f->getPublicKey(); |
||||
History* const history = Nexus::getProfile()->getHistory(); |
||||
if (history) { |
||||
history->removeFriendHistory(pk.toString()); |
||||
} |
||||
} |
@ -0,0 +1,40 @@
@@ -0,0 +1,40 @@
|
||||
#ifndef ABOUT_FRIEND_H |
||||
#define ABOUT_FRIEND_H |
||||
|
||||
#include "iaboutfriend.h" |
||||
#include "src/model/friend.h" |
||||
|
||||
#include <QObject> |
||||
|
||||
class AboutFriend : public IAboutFriend |
||||
{ |
||||
Q_OBJECT |
||||
|
||||
public: |
||||
explicit AboutFriend(const Friend* f); |
||||
|
||||
QString getName() const override; |
||||
QString getStatusMessage() const override; |
||||
QString getPublicKey() const override; |
||||
|
||||
QPixmap getAvatar() const override; |
||||
|
||||
QString getNote() const override; |
||||
void setNote(const QString& note) override; |
||||
|
||||
QString getAutoAcceptDir() const override; |
||||
void setAutoAcceptDir(const QString& path) override; |
||||
|
||||
AutoAcceptCallFlags getAutoAcceptCall() const override; |
||||
void setAutoAcceptCall(AutoAcceptCallFlags flag) override; |
||||
|
||||
bool getAutoGroupInvite() const override; |
||||
void setAutoGroupInvite(bool enabled) override; |
||||
|
||||
bool clearHistory() override; |
||||
|
||||
private: |
||||
const Friend* const f; |
||||
}; |
||||
|
||||
#endif // ABOUT_FRIEND_H
|
@ -0,0 +1,53 @@
@@ -0,0 +1,53 @@
|
||||
#ifndef I_ABOUT_FRIEND_H |
||||
#define I_ABOUT_FRIEND_H |
||||
|
||||
#include <QObject> |
||||
|
||||
class IAboutFriend : public QObject |
||||
{ |
||||
Q_OBJECT |
||||
|
||||
public: |
||||
enum class AutoAcceptCall |
||||
{ |
||||
None = 0x00, |
||||
Audio = 0x01, |
||||
Video = 0x02, |
||||
AV = Audio | Video |
||||
}; |
||||
using AutoAcceptCallFlags = QFlags<AutoAcceptCall>; |
||||
|
||||
virtual QString getName() const = 0; |
||||
virtual QString getStatusMessage() const = 0; |
||||
virtual QString getPublicKey() const = 0; |
||||
|
||||
virtual QPixmap getAvatar() const = 0; |
||||
|
||||
virtual QString getNote() const = 0; |
||||
virtual void setNote(const QString& note) = 0; |
||||
|
||||
virtual QString getAutoAcceptDir() const = 0; |
||||
virtual void setAutoAcceptDir(const QString& path) = 0; |
||||
|
||||
virtual AutoAcceptCallFlags getAutoAcceptCall() const = 0; |
||||
virtual void setAutoAcceptCall(AutoAcceptCallFlags flag) = 0; |
||||
|
||||
virtual bool getAutoGroupInvite() const = 0; |
||||
virtual void setAutoGroupInvite(bool enabled) = 0; |
||||
|
||||
virtual bool clearHistory() = 0; |
||||
|
||||
signals: |
||||
void nameChanged(const QString& name) const; |
||||
void statusChanged(const QString& status) const; |
||||
void publicKeyChanged(const QString& pk) const; |
||||
|
||||
void avatarChanged(const QPixmap& avatar) const; |
||||
void noteChanged(const QString& note) const; |
||||
|
||||
void autoAcceptDirChanged(const QString& dir); |
||||
void autoAcceptCallChanged(AutoAcceptCall flag); |
||||
void autoGroupInviteChaged(bool enabled); |
||||
}; |
||||
|
||||
#endif // I_ABOUT_FRIEND_H
|
Loading…
Reference in new issue