mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
parent
4b570c88f9
commit
73309d8b90
32
core.cpp
32
core.cpp
|
@ -437,6 +437,19 @@ void Core::requestFriendship(const QString& friendAddress, const QString& messag
|
|||
if (friendId < 0) {
|
||||
emit failedToAddFriend(userId);
|
||||
} else {
|
||||
// Update our friendAddresses
|
||||
bool found=false;
|
||||
QList<QString>& friendAddresses = Settings::getInstance().friendAddresses;
|
||||
for (QString& addr : friendAddresses)
|
||||
{
|
||||
if (addr.toUpper().contains(friendAddress))
|
||||
{
|
||||
addr = friendAddress;
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
friendAddresses.append(friendAddress);
|
||||
emit friendAdded(friendId, userId);
|
||||
}
|
||||
saveConfiguration();
|
||||
|
@ -878,6 +891,9 @@ void Core::saveConfiguration()
|
|||
configurationFile.commit();
|
||||
delete[] data;
|
||||
}
|
||||
|
||||
qDebug() << "Core: writing settings";
|
||||
Settings::getInstance().save();
|
||||
}
|
||||
|
||||
void Core::loadFriends()
|
||||
|
@ -1104,3 +1120,19 @@ void Core::createGroup()
|
|||
{
|
||||
emit emptyGroupCreated(tox_add_groupchat(tox));
|
||||
}
|
||||
|
||||
QString Core::getFriendAddress(int friendNumber) const
|
||||
{
|
||||
// If we don't know the full address of the client, return just the id, otherwise get the full address
|
||||
uint8_t rawid[TOX_CLIENT_ID_SIZE];
|
||||
tox_get_client_id(tox, friendNumber, rawid);
|
||||
QByteArray data((char*)rawid,TOX_CLIENT_ID_SIZE);
|
||||
QString id = data.toHex().toUpper();
|
||||
|
||||
QList<QString>& friendAddresses = Settings::getInstance().friendAddresses;
|
||||
for (QString addr : friendAddresses)
|
||||
if (addr.toUpper().contains(id))
|
||||
return addr;
|
||||
|
||||
return id;
|
||||
}
|
||||
|
|
1
core.h
1
core.h
|
@ -118,6 +118,7 @@ public:
|
|||
int getGroupNumberPeers(int groupId) const;
|
||||
QString getGroupPeerName(int groupId, int peerId) const;
|
||||
QList<QString> getGroupPeerNames(int groupId) const;
|
||||
QString getFriendAddress(int friendNumber) const;
|
||||
int joinGroupchat(int32_t friendnumber, const uint8_t* friend_group_public_key) const;
|
||||
void quitGroupChat(int groupId) const;
|
||||
void dispatchVideoFrame(vpx_image img) const;
|
||||
|
|
20
settings.cpp
20
settings.cpp
|
@ -16,6 +16,7 @@
|
|||
|
||||
#include "settings.h"
|
||||
#include "smileypack.h"
|
||||
#include "widget/widget.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QDir>
|
||||
|
@ -79,6 +80,16 @@ void Settings::load()
|
|||
s.endArray();
|
||||
s.endGroup();
|
||||
|
||||
friendAddresses.clear();
|
||||
s.beginGroup("Friends");
|
||||
int size = s.beginReadArray("fullAddresses");
|
||||
for (int i = 0; i < size; i ++) {
|
||||
s.setArrayIndex(i);
|
||||
friendAddresses.append(s.value("addr").toString());
|
||||
}
|
||||
s.endArray();
|
||||
s.endGroup();
|
||||
|
||||
s.beginGroup("General");
|
||||
enableIPv6 = s.value("enableIPv6", true).toBool();
|
||||
useTranslations = s.value("useTranslations", true).toBool();
|
||||
|
@ -147,6 +158,15 @@ void Settings::save(QString path)
|
|||
s.endArray();
|
||||
s.endGroup();
|
||||
|
||||
s.beginGroup("Friends");
|
||||
s.beginWriteArray("fullAddresses", friendAddresses.size());
|
||||
for (int i = 0; i < friendAddresses.size(); i ++) {
|
||||
s.setArrayIndex(i);
|
||||
s.setValue("addr", friendAddresses[i]);
|
||||
}
|
||||
s.endArray();
|
||||
s.endGroup();
|
||||
|
||||
s.beginGroup("General");
|
||||
s.setValue("enableIPv6", enableIPv6);
|
||||
s.setValue("useTranslations",useTranslations);
|
||||
|
|
12
settings.h
12
settings.h
|
@ -127,16 +127,16 @@ public:
|
|||
QByteArray getSplitterState() const;
|
||||
void setSplitterState(const QByteArray &value);
|
||||
|
||||
private:
|
||||
Settings();
|
||||
Settings(Settings &settings) = delete;
|
||||
Settings& operator=(const Settings&) = delete;
|
||||
|
||||
public:
|
||||
QList<QString> friendAddresses;
|
||||
void save();
|
||||
void save(QString path);
|
||||
void load();
|
||||
|
||||
|
||||
private:
|
||||
Settings();
|
||||
Settings(Settings &settings) = delete;
|
||||
Settings& operator=(const Settings&) = delete;
|
||||
|
||||
static const QString FILENAME;
|
||||
|
||||
|
|
|
@ -587,7 +587,7 @@ void Widget::copyFriendIdToClipboard(int friendId)
|
|||
if (f != nullptr)
|
||||
{
|
||||
QClipboard *clipboard = QApplication::clipboard();
|
||||
clipboard->setText(f->userId, QClipboard::Clipboard);
|
||||
clipboard->setText(core->getFriendAddress(f->friendId), QClipboard::Clipboard);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user