mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Merge pull request #3169
Diadlo (3): refactor(settings, addfriendform): Changed type of friend requests refactor(settings): Deleted unreadFriendRequests field fix(addfriendform, widget): Remove Accepted Request
This commit is contained in:
commit
2c809154b2
|
@ -326,16 +326,16 @@ 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);
|
||||
for (int i = 0; i < size; i ++)
|
||||
{
|
||||
ps.setArrayIndex(i);
|
||||
QPair<QString, QString> request;
|
||||
request.first = ps.value("addr").toString();
|
||||
request.second = ps.value("message").toString();
|
||||
Request request;
|
||||
request.address = ps.value("addr").toString();
|
||||
request.message = ps.value("message").toString();
|
||||
request.read = ps.value("read").toBool();
|
||||
friendRequests.push_back(request);
|
||||
}
|
||||
ps.endArray();
|
||||
|
@ -526,14 +526,14 @@ 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)
|
||||
{
|
||||
ps.setArrayIndex(index);
|
||||
ps.setValue("addr", request.first);
|
||||
ps.setValue("message", request.second);
|
||||
ps.setValue("addr", request.address);
|
||||
ps.setValue("message", request.message);
|
||||
ps.setValue("read", request.read);
|
||||
|
||||
++index;
|
||||
}
|
||||
|
@ -1674,26 +1674,35 @@ bool Settings::addFriendRequest(const QString &friendAddress, const QString &mes
|
|||
|
||||
for (auto queued : friendRequests)
|
||||
{
|
||||
if (queued.first == friendAddress)
|
||||
if (queued.address == friendAddress)
|
||||
{
|
||||
queued.second = message;
|
||||
queued.message = message;
|
||||
queued.read = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
QPair<QString, QString> request(friendAddress, message);
|
||||
Request request;
|
||||
request.address = friendAddress;
|
||||
request.message = message;
|
||||
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;
|
||||
}
|
||||
|
||||
QPair<QString, QString> Settings::getFriendRequest(int index) const
|
||||
Settings::Request Settings::getFriendRequest(int index) const
|
||||
{
|
||||
QMutexLocker locker{&bigLock};
|
||||
return friendRequests.at(index);
|
||||
|
@ -1708,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)
|
||||
|
@ -1717,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.
|
||||
|
|
|
@ -57,6 +57,14 @@ public:
|
|||
void loadPersonal();
|
||||
void loadPersonal(Profile *profile);
|
||||
|
||||
struct Request
|
||||
{
|
||||
QString address;
|
||||
QString message;
|
||||
bool read;
|
||||
};
|
||||
|
||||
|
||||
public slots:
|
||||
void saveGlobal(); ///< Asynchronous
|
||||
void sync(); ///< Waits for all asynchronous operations to complete
|
||||
|
@ -299,10 +307,11 @@ public:
|
|||
|
||||
bool addFriendRequest(const QString &friendAddress, const QString &message);
|
||||
unsigned int getUnreadFriendRequests() const;
|
||||
QPair<QString, QString> getFriendRequest(int index) const;
|
||||
Request getFriendRequest(int index) const;
|
||||
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
|
||||
|
@ -389,8 +398,7 @@ private:
|
|||
bool autoSaveEnabled;
|
||||
QString globalAutoAcceptDir;
|
||||
|
||||
QList<QPair<QString, QString>> friendRequests;
|
||||
unsigned int unreadFriendRequests;
|
||||
QList<Request> friendRequests;
|
||||
|
||||
// GUI
|
||||
QString smileyPack;
|
||||
|
|
|
@ -82,8 +82,8 @@ AddFriendForm::AddFriendForm()
|
|||
|
||||
for (int i = 0; i < size; ++i)
|
||||
{
|
||||
QPair<QString, QString> request = Settings::getInstance().getFriendRequest(i);
|
||||
addFriendRequestWidget(request.first, request.second);
|
||||
Settings::Request request = Settings::getInstance().getFriendRequest(i);
|
||||
addFriendRequestWidget(request.address, request.message);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -173,6 +173,7 @@ void AddFriendForm::onSendTriggered()
|
|||
id = toxId.toString();
|
||||
}
|
||||
|
||||
deleteFriendRequest(id);
|
||||
if (id.toUpper() == Core::getInstance()->getSelfId().toString().toUpper())
|
||||
GUI::showWarning(tr("Couldn't add friend"), tr("You can't add yourself as a friend!","When trying to add your own Tox ID as friend"));
|
||||
else
|
||||
|
@ -222,13 +223,28 @@ void AddFriendForm::setIdFromClipboard()
|
|||
}
|
||||
}
|
||||
|
||||
void AddFriendForm::deleteFriendRequest(const QString& toxId)
|
||||
{
|
||||
int size = Settings::getInstance().getFriendRequestSize();
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
Settings::Request request = Settings::getInstance().getFriendRequest(i);
|
||||
if (ToxId(toxId) == ToxId(request.address))
|
||||
{
|
||||
Settings::getInstance().removeFriendRequest(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AddFriendForm::onFriendRequestAccepted()
|
||||
{
|
||||
QPushButton* acceptButton = static_cast<QPushButton*>(sender());
|
||||
QWidget* friendWidget = acceptButton->parentWidget();
|
||||
int index = requestsLayout->indexOf(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().savePersonal();
|
||||
}
|
||||
|
|
|
@ -75,9 +75,10 @@ private:
|
|||
void removeFriendRequestWidget(QWidget *friendWidget);
|
||||
void retranslateAcceptButton(QPushButton* acceptButton);
|
||||
void retranslateRejectButton(QPushButton* rejectButton);
|
||||
void deleteFriendRequest(const QString &toxId);
|
||||
void setIdFromClipboard();
|
||||
|
||||
private:
|
||||
void setIdFromClipboard();
|
||||
QLabel headLabel, toxIdLabel, messageLabel;
|
||||
QPushButton sendButton;
|
||||
QLineEdit toxId;
|
||||
|
|
|
@ -392,6 +392,7 @@ void Widget::init()
|
|||
groupInvitesButton = nullptr;
|
||||
unreadGroupInvites = 0;
|
||||
|
||||
connect(addFriendForm, &AddFriendForm::friendRequested, this, &Widget::friendRequestsUpdate);
|
||||
connect(addFriendForm, &AddFriendForm::friendRequestsSeen, this, &Widget::friendRequestsUpdate);
|
||||
connect(addFriendForm, &AddFriendForm::friendRequestAccepted, this, &Widget::friendRequestAccepted);
|
||||
connect(groupInviteForm, &GroupInviteForm::groupInvitesSeen, this, &Widget::groupInvitesClear);
|
||||
|
|
Loading…
Reference in New Issue
Block a user