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

refactor(settings): Deleted unreadFriendRequests field

Replaced unreadFriendRequests on work with "read" field of struct Request
This commit is contained in:
Diadlo 2016-04-21 01:31:42 +03:00
parent 9f01b662bf
commit 5966c84b84
No known key found for this signature in database
GPG Key ID: 5AF9F2E29107C727
2 changed files with 15 additions and 5 deletions

View File

@ -326,7 +326,6 @@ void Settings::loadPersonal(Profile* profile)
ps.endGroup();
ps.beginGroup("Requests");
unreadFriendRequests = ps.value("unread", 0).toUInt();
size = ps.beginReadArray("Request");
friendRequests.clear();
friendRequests.reserve(size);
@ -527,7 +526,6 @@ void Settings::savePersonal(QString profileName, QString password)
ps.endGroup();
ps.beginGroup("Requests");
ps.setValue("unread", unreadFriendRequests);
ps.beginWriteArray("Request", friendRequests.size());
index = 0;
for (auto& request : friendRequests)
@ -1690,13 +1688,17 @@ bool Settings::addFriendRequest(const QString &friendAddress, const QString &mes
request.read = false;
friendRequests.push_back(request);
++unreadFriendRequests;
return true;
}
unsigned int Settings::getUnreadFriendRequests() const
{
QMutexLocker locker{&bigLock};
unsigned int unreadFriendRequests = 0;
for (auto request : friendRequests)
if (!request.read)
unreadFriendRequests++;
return unreadFriendRequests;
}
@ -1715,7 +1717,9 @@ int Settings::getFriendRequestSize() const
void Settings::clearUnreadFriendRequests()
{
QMutexLocker locker{&bigLock};
unreadFriendRequests = 0;
for (auto& request : friendRequests)
request.read = true;
}
void Settings::removeFriendRequest(int index)
@ -1724,6 +1728,12 @@ void Settings::removeFriendRequest(int index)
friendRequests.removeAt(index);
}
void Settings::readFriendRequest(int index)
{
QMutexLocker locker{&bigLock};
friendRequests[index].read = true;
}
int Settings::removeCircle(int id)
{
// Replace index with last one and remove last one instead.

View File

@ -311,6 +311,7 @@ public:
int getFriendRequestSize() const;
void clearUnreadFriendRequests();
void removeFriendRequest(int index);
void readFriendRequest(int index);
// Assume all widgets have unique names
// Don't use it to save every single thing you want to save, use it
@ -398,7 +399,6 @@ private:
QString globalAutoAcceptDir;
QList<Request> friendRequests;
unsigned int unreadFriendRequests;
// GUI
QString smileyPack;