From 73309d8b907278be98aa2dba6cf956c6780f7755 Mon Sep 17 00:00:00 2001 From: "Tux3 / Mlkj / !Lev.uXFMLA" Date: Sun, 31 Aug 2014 22:26:45 +0200 Subject: [PATCH] Fix #235, Fix #84 --- core.cpp | 32 ++++++++++++++++++++++++++++++++ core.h | 1 + settings.cpp | 20 ++++++++++++++++++++ settings.h | 12 ++++++------ widget/widget.cpp | 2 +- 5 files changed, 60 insertions(+), 7 deletions(-) diff --git a/core.cpp b/core.cpp index 658908066..d4241f88d 100644 --- a/core.cpp +++ b/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& 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& friendAddresses = Settings::getInstance().friendAddresses; + for (QString addr : friendAddresses) + if (addr.toUpper().contains(id)) + return addr; + + return id; +} diff --git a/core.h b/core.h index 154a18351..e22bd183d 100644 --- a/core.h +++ b/core.h @@ -118,6 +118,7 @@ public: int getGroupNumberPeers(int groupId) const; QString getGroupPeerName(int groupId, int peerId) const; QList 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; diff --git a/settings.cpp b/settings.cpp index b2193e453..f499e9e75 100644 --- a/settings.cpp +++ b/settings.cpp @@ -16,6 +16,7 @@ #include "settings.h" #include "smileypack.h" +#include "widget/widget.h" #include #include @@ -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); diff --git a/settings.h b/settings.h index c32203f41..819e89a21 100644 --- a/settings.h +++ b/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 friendAddresses; void save(); void save(QString path); void load(); - +private: + Settings(); + Settings(Settings &settings) = delete; + Settings& operator=(const Settings&) = delete; static const QString FILENAME; diff --git a/widget/widget.cpp b/widget/widget.cpp index 11a7fe97a..851502df0 100644 --- a/widget/widget.cpp +++ b/widget/widget.cpp @@ -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); } }