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

properly implement clearing contacts list

This commit is contained in:
dubslow 2014-10-09 00:58:35 -05:00
parent 2181313d37
commit 7ce7da0776
4 changed files with 21 additions and 8 deletions

View File

@ -66,3 +66,22 @@ void FriendListWidget::moveWidget(QWidget *w, Status s)
mainLayout->removeWidget(w);
getFriendLayout(s)->addWidget(w);
}
void clearLayout(QLayout *layout)
{
QLayoutItem *item;
while((item = layout->takeAt(0)))
{
if (item->layout()) {
clearLayout(item->layout());
delete item->layout();
}
delete item->widget();
delete item;
}
}
void FriendListWidget::clear()
{
clearLayout(mainLayout);
}

View File

@ -38,6 +38,7 @@ public:
signals:
public slots:
void clear();
private:
QHash<int, QLayout*> layouts;

View File

@ -137,7 +137,7 @@ Widget::Widget(QWidget *parent)
connect(core, SIGNAL(fileUploadFinished(const QString&)), &filesForm, SLOT(onFileUploadComplete(const QString&)));
connect(core, &Core::friendAdded, this, &Widget::addFriend);
connect(core, &Core::failedToAddFriend, this, &Widget::addFriendFailed);
connect(core, &Core::clearFriends, this, &Widget::clearFriends);
connect(core, &Core::clearFriends, contactListWidget, &FriendListWidget::clear);
connect(core, &Core::friendStatusChanged, this, &Widget::onFriendStatusChanged);
connect(core, &Core::friendUsernameChanged, this, &Widget::onFriendUsernameChanged);
connect(core, &Core::friendStatusChanged, this, &Widget::onFriendStatusChanged);
@ -637,12 +637,6 @@ void Widget::removeFriend(int friendId)
removeFriend(FriendList::findFriend(friendId));
}
void Widget::clearFriends()
{ // used for dynamic profile loading
for (Friend* f : FriendList::friendList)
removeFriend(f);
}
void Widget::copyFriendIdToClipboard(int friendId)
{
Friend* f = FriendList::findFriend(friendId);

View File

@ -98,7 +98,6 @@ private slots:
void onGroupMessageReceived(int groupnumber, const QString& message, const QString& author);
void onGroupNamelistChanged(int groupnumber, int peernumber, uint8_t change);
void removeFriend(int friendId);
void clearFriends();
void copyFriendIdToClipboard(int friendId);
void removeGroup(int groupId);
void setStatusOnline();