qTox  Version: nightly | Commit: bc751c8e1cac455f9690654fcfe0f560d2d7dfdd
aboutfriend.cpp
Go to the documentation of this file.
1 /*
2  Copyright © 2019 by The qTox Project Contributors
3 
4  This file is part of qTox, a Qt-based graphical interface for Tox.
5 
6  qTox is libre software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  qTox is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with qTox. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #include "aboutfriend.h"
21 
22 #include "src/model/friend.h"
23 #include "src/nexus.h"
26 
28  : f{f}
29  , settings{s}
30 {
31  s->connectTo_contactNoteChanged(this, [=](const ToxPk& pk, const QString& note) {
32  emit noteChanged(note);
33  });
34  s->connectTo_autoAcceptCallChanged(this,
35  [=](const ToxPk& pk, IFriendSettings::AutoAcceptCallFlags flag) {
36  emit autoAcceptCallChanged(flag);
37  });
38  s->connectTo_autoAcceptDirChanged(this, [=](const ToxPk& pk, const QString& dir) {
39  emit autoAcceptDirChanged(dir);
40  });
41  s->connectTo_autoGroupInviteChanged(this, [=](const ToxPk& pk, bool enable) {
42  emit autoGroupInviteChanged(enable);
43  });
44 }
45 
46 QString AboutFriend::getName() const
47 {
48  return f->getDisplayedName();
49 }
50 
52 {
53  return f->getStatusMessage();
54 }
55 
57 {
58  return f->getPublicKey();
59 }
60 
61 QPixmap AboutFriend::getAvatar() const
62 {
63  const ToxPk pk = f->getPublicKey();
64  const QPixmap avatar = Nexus::getProfile()->loadAvatar(pk);
65  return avatar.isNull() ? QPixmap(QStringLiteral(":/img/contact_dark.svg"))
66  : avatar;
67 }
68 
69 QString AboutFriend::getNote() const
70 {
71  const ToxPk pk = f->getPublicKey();
72  return settings->getContactNote(pk);
73 }
74 
75 void AboutFriend::setNote(const QString& note)
76 {
77  const ToxPk pk = f->getPublicKey();
78  settings->setContactNote(pk, note);
80 }
81 
83 {
84  const ToxPk pk = f->getPublicKey();
85  return settings->getAutoAcceptDir(pk);
86 }
87 
88 void AboutFriend::setAutoAcceptDir(const QString& path)
89 {
90  const ToxPk pk = f->getPublicKey();
91  settings->setAutoAcceptDir(pk, path);
93 }
94 
95 IFriendSettings::AutoAcceptCallFlags AboutFriend::getAutoAcceptCall() const
96 {
97  const ToxPk pk = f->getPublicKey();
98  return settings->getAutoAcceptCall(pk);
99 }
100 
101 void AboutFriend::setAutoAcceptCall(IFriendSettings::AutoAcceptCallFlags flag)
102 {
103  const ToxPk pk = f->getPublicKey();
104  settings->setAutoAcceptCall(pk, flag);
106 }
107 
109 {
110  const ToxPk pk = f->getPublicKey();
111  return settings->getAutoGroupInvite(pk);
112 }
113 
115 {
116  const ToxPk pk = f->getPublicKey();
117  settings->setAutoGroupInvite(pk, enabled);
119 }
120 
122 {
123  const ToxPk pk = f->getPublicKey();
124  History* const history = Nexus::getProfile()->getHistory();
125  if (history) {
126  history->removeFriendHistory(pk);
127  return true;
128  }
129 
130  return false;
131 }
132 
134 {
135  History* const history = Nexus::getProfile()->getHistory();
136  if (history) {
137  const ToxPk pk = f->getPublicKey();
138  return history->historyExists(pk);
139  }
140 
141  return false;
142 }
AboutFriend::isHistoryExistence
bool isHistoryExistence() override
Definition: aboutfriend.cpp:133
profile.h
AboutFriend::setAutoAcceptCall
void setAutoAcceptCall(IFriendSettings::AutoAcceptCallFlags flag) override
Definition: aboutfriend.cpp:101
friend.h
AboutFriend::getAutoAcceptDir
QString getAutoAcceptDir() const override
Definition: aboutfriend.cpp:82
IFriendSettings::getAutoGroupInvite
virtual bool getAutoGroupInvite(const ToxPk &pk) const =0
aboutfriend.h
History::removeFriendHistory
void removeFriendHistory(const ToxPk &friendPk)
Erases the chat history with one friend.
Definition: history.cpp:792
ifriendsettings.h
Profile::loadAvatar
QPixmap loadAvatar()
Get our avatar from cache.
Definition: profile.cpp:556
IFriendSettings::setAutoGroupInvite
virtual void setAutoGroupInvite(const ToxPk &pk, bool accept)=0
IFriendSettings::getAutoAcceptDir
virtual QString getAutoAcceptDir(const ToxPk &pk) const =0
AboutFriend::setNote
void setNote(const QString &note) override
Definition: aboutfriend.cpp:75
History::historyExists
bool historyExists(const ToxPk &friendPk)
Checks if a friend has chat history.
Definition: history.cpp:759
Nexus::getProfile
static Profile * getProfile()
Get current user profile.
Definition: nexus.cpp:290
AboutFriend::setAutoGroupInvite
void setAutoGroupInvite(bool enabled) override
Definition: aboutfriend.cpp:114
AboutFriend::getName
QString getName() const override
Definition: aboutfriend.cpp:46
ToxPk
This class represents a Tox Public Key, which is a part of Tox ID.
Definition: toxpk.h:26
Friend
Definition: friend.h:31
AboutFriend::clearHistory
bool clearHistory() override
Definition: aboutfriend.cpp:121
IFriendSettings::setAutoAcceptDir
virtual void setAutoAcceptDir(const ToxPk &pk, const QString &dir)=0
IFriendSettings::getAutoAcceptCall
virtual AutoAcceptCallFlags getAutoAcceptCall(const ToxPk &pk) const =0
AboutFriend::setAutoAcceptDir
void setAutoAcceptDir(const QString &path) override
Definition: aboutfriend.cpp:88
AboutFriend::getAutoGroupInvite
bool getAutoGroupInvite() const override
Definition: aboutfriend.cpp:108
Friend::getDisplayedName
QString getDisplayedName() const override
Friend::getDisplayedName Gets the name that should be displayed for a user.
Definition: friend.cpp:112
AboutFriend::settings
IFriendSettings *const settings
Definition: aboutfriend.h:72
IFriendSettings
Definition: ifriendsettings.h:29
AboutFriend::getPublicKey
ToxPk getPublicKey() const override
Definition: aboutfriend.cpp:56
Profile::getHistory
History * getHistory()
Get chat history.
Definition: profile.cpp:785
History
Interacts with the profile database to save the chat history.
Definition: history.h:135
IFriendSettings::setAutoAcceptCall
virtual void setAutoAcceptCall(const ToxPk &pk, AutoAcceptCallFlags accept)=0
AboutFriend::getStatusMessage
QString getStatusMessage() const override
Definition: aboutfriend.cpp:51
AboutFriend::getNote
QString getNote() const override
Definition: aboutfriend.cpp:69
Friend::getPublicKey
const ToxPk & getPublicKey() const
Definition: friend.cpp:131
IFriendSettings::getContactNote
virtual QString getContactNote(const ToxPk &pk) const =0
Friend::getStatusMessage
QString getStatusMessage() const
Definition: friend.cpp:101
AboutFriend::f
const Friend *const f
Definition: aboutfriend.h:71
IFriendSettings::saveFriendSettings
virtual void saveFriendSettings(const ToxPk &pk)=0
IFriendSettings::setContactNote
virtual void setContactNote(const ToxPk &pk, const QString &note)=0
AboutFriend::getAutoAcceptCall
IFriendSettings::AutoAcceptCallFlags getAutoAcceptCall() const override
Definition: aboutfriend.cpp:95
AboutFriend::getAvatar
QPixmap getAvatar() const override
Definition: aboutfriend.cpp:61
AboutFriend::AboutFriend
AboutFriend(const Friend *f, IFriendSettings *const settings)
Definition: aboutfriend.cpp:27
nexus.h