1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

refactor(settings, addfriendform): Changed type of friend requests

QPair<QString, QString> changed on new struct Request
This commit is contained in:
Diadlo 2016-04-21 00:36:02 +03:00
parent edc35ba9df
commit 9f01b662bf
No known key found for this signature in database
GPG Key ID: 5AF9F2E29107C727
3 changed files with 30 additions and 14 deletions

View File

@ -333,9 +333,10 @@ void Settings::loadPersonal(Profile* profile)
for (int i = 0; i < size; i ++) for (int i = 0; i < size; i ++)
{ {
ps.setArrayIndex(i); ps.setArrayIndex(i);
QPair<QString, QString> request; Request request;
request.first = ps.value("addr").toString(); request.address = ps.value("addr").toString();
request.second = ps.value("message").toString(); request.message = ps.value("message").toString();
request.read = ps.value("read").toBool();
friendRequests.push_back(request); friendRequests.push_back(request);
} }
ps.endArray(); ps.endArray();
@ -532,8 +533,9 @@ void Settings::savePersonal(QString profileName, QString password)
for (auto& request : friendRequests) for (auto& request : friendRequests)
{ {
ps.setArrayIndex(index); ps.setArrayIndex(index);
ps.setValue("addr", request.first); ps.setValue("addr", request.address);
ps.setValue("message", request.second); ps.setValue("message", request.message);
ps.setValue("read", request.read);
++index; ++index;
} }
@ -1674,14 +1676,19 @@ bool Settings::addFriendRequest(const QString &friendAddress, const QString &mes
for (auto queued : friendRequests) for (auto queued : friendRequests)
{ {
if (queued.first == friendAddress) if (queued.address == friendAddress)
{ {
queued.second = message; queued.message = message;
queued.read = false;
return false; return false;
} }
} }
QPair<QString, QString> request(friendAddress, message); Request request;
request.address = friendAddress;
request.message = message;
request.read = false;
friendRequests.push_back(request); friendRequests.push_back(request);
++unreadFriendRequests; ++unreadFriendRequests;
return true; return true;
@ -1693,7 +1700,7 @@ unsigned int Settings::getUnreadFriendRequests() const
return unreadFriendRequests; return unreadFriendRequests;
} }
QPair<QString, QString> Settings::getFriendRequest(int index) const Settings::Request Settings::getFriendRequest(int index) const
{ {
QMutexLocker locker{&bigLock}; QMutexLocker locker{&bigLock};
return friendRequests.at(index); return friendRequests.at(index);

View File

@ -57,6 +57,14 @@ public:
void loadPersonal(); void loadPersonal();
void loadPersonal(Profile *profile); void loadPersonal(Profile *profile);
struct Request
{
QString address;
QString message;
bool read;
};
public slots: public slots:
void saveGlobal(); ///< Asynchronous void saveGlobal(); ///< Asynchronous
void sync(); ///< Waits for all asynchronous operations to complete void sync(); ///< Waits for all asynchronous operations to complete
@ -299,7 +307,7 @@ public:
bool addFriendRequest(const QString &friendAddress, const QString &message); bool addFriendRequest(const QString &friendAddress, const QString &message);
unsigned int getUnreadFriendRequests() const; unsigned int getUnreadFriendRequests() const;
QPair<QString, QString> getFriendRequest(int index) const; Request getFriendRequest(int index) const;
int getFriendRequestSize() const; int getFriendRequestSize() const;
void clearUnreadFriendRequests(); void clearUnreadFriendRequests();
void removeFriendRequest(int index); void removeFriendRequest(int index);
@ -389,7 +397,7 @@ private:
bool autoSaveEnabled; bool autoSaveEnabled;
QString globalAutoAcceptDir; QString globalAutoAcceptDir;
QList<QPair<QString, QString>> friendRequests; QList<Request> friendRequests;
unsigned int unreadFriendRequests; unsigned int unreadFriendRequests;
// GUI // GUI

View File

@ -82,8 +82,8 @@ AddFriendForm::AddFriendForm()
for (int i = 0; i < size; ++i) for (int i = 0; i < size; ++i)
{ {
QPair<QString, QString> request = Settings::getInstance().getFriendRequest(i); Settings::Request request = Settings::getInstance().getFriendRequest(i);
addFriendRequestWidget(request.first, request.second); addFriendRequestWidget(request.address, request.message);
} }
} }
@ -228,7 +228,8 @@ void AddFriendForm::onFriendRequestAccepted()
QWidget* friendWidget = acceptButton->parentWidget(); QWidget* friendWidget = acceptButton->parentWidget();
int index = requestsLayout->indexOf(friendWidget); int index = requestsLayout->indexOf(friendWidget);
removeFriendRequestWidget(friendWidget); removeFriendRequestWidget(friendWidget);
emit friendRequestAccepted(Settings::getInstance().getFriendRequest(requestsLayout->count() - index - 1).first); Settings::Request request = Settings::getInstance().getFriendRequest(requestsLayout->count() - index - 1);
emit friendRequestAccepted(request.address);
Settings::getInstance().removeFriendRequest(requestsLayout->count() - index - 1); Settings::getInstance().removeFriendRequest(requestsLayout->count() - index - 1);
Settings::getInstance().savePersonal(); Settings::getInstance().savePersonal();
} }