mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Circles: Fix memory leaks and extraneous saving
This commit is contained in:
parent
9dd277623a
commit
858b005567
|
@ -364,7 +364,6 @@ void Core::start()
|
||||||
if (isReady())
|
if (isReady())
|
||||||
GUI::setEnabled(true);
|
GUI::setEnabled(true);
|
||||||
|
|
||||||
|
|
||||||
process(); // starts its own timer
|
process(); // starts its own timer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -157,8 +157,6 @@ signals:
|
||||||
void connected();
|
void connected();
|
||||||
void disconnected();
|
void disconnected();
|
||||||
|
|
||||||
void blockingClearContacts();
|
|
||||||
|
|
||||||
void friendRequestReceived(const QString& userId, const QString& message);
|
void friendRequestReceived(const QString& userId, const QString& message);
|
||||||
void friendMessageReceived(uint32_t friendId, const QString& message, bool isAction);
|
void friendMessageReceived(uint32_t friendId, const QString& message, bool isAction);
|
||||||
|
|
||||||
|
|
|
@ -1312,7 +1312,6 @@ void Settings::setFriendCircleID(const ToxId &id, int circleID)
|
||||||
fp.circleID = circleID;
|
fp.circleID = circleID;
|
||||||
friendLst[key] = fp;
|
friendLst[key] = fp;
|
||||||
}
|
}
|
||||||
savePersonal();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QDate Settings::getFriendActivity(const ToxId &id) const
|
QDate Settings::getFriendActivity(const ToxId &id) const
|
||||||
|
@ -1426,7 +1425,6 @@ bool Settings::getCircleExpanded(int id) const
|
||||||
void Settings::setCircleExpanded(int id, bool expanded)
|
void Settings::setCircleExpanded(int id, bool expanded)
|
||||||
{
|
{
|
||||||
circleLst[id].expanded = expanded;
|
circleLst[id].expanded = expanded;
|
||||||
savePersonal();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int Settings::removeCircle(int id)
|
int Settings::removeCircle(int id)
|
||||||
|
|
|
@ -26,6 +26,8 @@
|
||||||
#include <QBoxLayout>
|
#include <QBoxLayout>
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
|
|
||||||
|
#include <QApplication>
|
||||||
|
|
||||||
void emitChatroomWidget(QLayout* layout, int index)
|
void emitChatroomWidget(QLayout* layout, int index)
|
||||||
{
|
{
|
||||||
GenericChatroomWidget* chatWidget = dynamic_cast<GenericChatroomWidget*>(layout->itemAt(index)->widget());
|
GenericChatroomWidget* chatWidget = dynamic_cast<GenericChatroomWidget*>(layout->itemAt(index)->widget());
|
||||||
|
@ -68,7 +70,7 @@ CategoryWidget::CategoryWidget(QWidget* parent)
|
||||||
|
|
||||||
onCompactChanged(isCompact());
|
onCompactChanged(isCompact());
|
||||||
|
|
||||||
setExpanded(true);
|
setExpanded(true, false);
|
||||||
updateStatus();
|
updateStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,37 +79,40 @@ bool CategoryWidget::isExpanded() const
|
||||||
return expanded;
|
return expanded;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CategoryWidget::setExpanded(bool isExpanded)
|
void CategoryWidget::setExpanded(bool isExpanded, bool save)
|
||||||
{
|
{
|
||||||
expanded = isExpanded;
|
expanded = isExpanded;
|
||||||
|
setMouseTracking(true);
|
||||||
listWidget->setVisible(isExpanded);
|
listWidget->setVisible(isExpanded);
|
||||||
listWidget->move(1000, 1000);
|
|
||||||
if (isExpanded)
|
if (isExpanded)
|
||||||
{
|
|
||||||
statusPic.setPixmap(QPixmap(":/ui/chatArea/scrollBarDownArrow.svg"));
|
statusPic.setPixmap(QPixmap(":/ui/chatArea/scrollBarDownArrow.svg"));
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
statusPic.setPixmap(QPixmap(":/ui/chatArea/scrollBarRightArrow.svg"));
|
statusPic.setPixmap(QPixmap(":/ui/chatArea/scrollBarRightArrow.svg"));
|
||||||
}
|
|
||||||
|
|
||||||
// The listWidget will recieve a enterEvent for some reason if now visible.
|
// The listWidget will recieve a enterEvent for some reason if now visible.
|
||||||
// Using the following, we prevent that.
|
// Using the following, we prevent that.
|
||||||
hide();
|
QApplication::processEvents(QEventLoop::ExcludeSocketNotifiers);
|
||||||
show();
|
container->hide();
|
||||||
|
container->show();
|
||||||
// However, the above also removes the hover, so we need to reenable it.
|
|
||||||
if (underMouse())
|
|
||||||
setContainerAttribute(Qt::WA_UnderMouse, true); // Simulate hover.
|
|
||||||
|
|
||||||
|
if (save)
|
||||||
onExpand();
|
onExpand();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CategoryWidget::setName(const QString &name)
|
void CategoryWidget::leaveEvent(QEvent *event)
|
||||||
|
{
|
||||||
|
event->ignore();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CategoryWidget::setName(const QString &name, bool save)
|
||||||
{
|
{
|
||||||
nameLabel->setText(name);
|
nameLabel->setText(name);
|
||||||
|
|
||||||
if (isCompact())
|
if (isCompact())
|
||||||
nameLabel->minimizeMaximumWidth();
|
nameLabel->minimizeMaximumWidth();
|
||||||
|
|
||||||
|
if (save)
|
||||||
onSetName();
|
onSetName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,8 +36,8 @@ public:
|
||||||
CategoryWidget(QWidget* parent = 0);
|
CategoryWidget(QWidget* parent = 0);
|
||||||
|
|
||||||
bool isExpanded() const;
|
bool isExpanded() const;
|
||||||
void setExpanded(bool isExpanded);
|
void setExpanded(bool isExpanded, bool save = true);
|
||||||
void setName(const QString &name);
|
void setName(const QString &name, bool save = true);
|
||||||
|
|
||||||
void addFriendWidget(FriendWidget* w, Status s);
|
void addFriendWidget(FriendWidget* w, Status s);
|
||||||
void removeFriendWidget(FriendWidget* w, Status s);
|
void removeFriendWidget(FriendWidget* w, Status s);
|
||||||
|
@ -52,6 +52,7 @@ public slots:
|
||||||
void onCompactChanged(bool compact);
|
void onCompactChanged(bool compact);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
virtual void leaveEvent(QEvent* event) final override;
|
||||||
virtual void mouseReleaseEvent(QMouseEvent* event) final override;
|
virtual void mouseReleaseEvent(QMouseEvent* event) final override;
|
||||||
|
|
||||||
void editName();
|
void editName();
|
||||||
|
|
|
@ -39,7 +39,7 @@ CircleWidget::CircleWidget(FriendListWidget* parent, int id)
|
||||||
: CategoryWidget(parent)
|
: CategoryWidget(parent)
|
||||||
, id(id)
|
, id(id)
|
||||||
{
|
{
|
||||||
setName(Settings::getInstance().getCircleName(id));
|
setName(Settings::getInstance().getCircleName(id), false);
|
||||||
circleList[id] = this;
|
circleList[id] = this;
|
||||||
|
|
||||||
connect(nameLabel, &CroppingLabel::editFinished, [this](const QString &newName)
|
connect(nameLabel, &CroppingLabel::editFinished, [this](const QString &newName)
|
||||||
|
@ -54,7 +54,7 @@ CircleWidget::CircleWidget(FriendListWidget* parent, int id)
|
||||||
nameLabel->minimizeMaximumWidth();
|
nameLabel->minimizeMaximumWidth();
|
||||||
});
|
});
|
||||||
|
|
||||||
setExpanded(Settings::getInstance().getCircleExpanded(id));
|
setExpanded(Settings::getInstance().getCircleExpanded(id), false);
|
||||||
updateStatus();
|
updateStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,7 +118,7 @@ void CircleWidget::dropEvent(QDropEvent* event)
|
||||||
{
|
{
|
||||||
if (event->mimeData()->hasFormat("friend"))
|
if (event->mimeData()->hasFormat("friend"))
|
||||||
{
|
{
|
||||||
setExpanded(true);
|
setExpanded(true, false);
|
||||||
|
|
||||||
int friendId = event->mimeData()->data("friend").toInt();
|
int friendId = event->mimeData()->data("friend").toInt();
|
||||||
Friend* f = FriendList::findFriend(friendId);
|
Friend* f = FriendList::findFriend(friendId);
|
||||||
|
@ -131,6 +131,7 @@ void CircleWidget::dropEvent(QDropEvent* event)
|
||||||
CircleWidget* circleWidget = getFromID(Settings::getInstance().getFriendCircleID(f->getToxId()));
|
CircleWidget* circleWidget = getFromID(Settings::getInstance().getFriendCircleID(f->getToxId()));
|
||||||
|
|
||||||
addFriendWidget(widget, f->getStatus());
|
addFriendWidget(widget, f->getStatus());
|
||||||
|
Settings::getInstance().savePersonal();
|
||||||
|
|
||||||
if (circleWidget != nullptr)
|
if (circleWidget != nullptr)
|
||||||
{
|
{
|
||||||
|
@ -150,6 +151,7 @@ void CircleWidget::onSetName()
|
||||||
void CircleWidget::onExpand()
|
void CircleWidget::onExpand()
|
||||||
{
|
{
|
||||||
Settings::getInstance().setCircleExpanded(id, isExpanded());
|
Settings::getInstance().setCircleExpanded(id, isExpanded());
|
||||||
|
Settings::getInstance().savePersonal();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CircleWidget::onAddFriendWidget(FriendWidget* w)
|
void CircleWidget::onAddFriendWidget(FriendWidget* w)
|
||||||
|
|
|
@ -99,19 +99,11 @@ Time getTime(const QDate date)
|
||||||
return LongAgo;
|
return LongAgo;
|
||||||
}
|
}
|
||||||
|
|
||||||
int toIndex(Time time)
|
|
||||||
{
|
|
||||||
if (time < ThisMonth)
|
|
||||||
return time;
|
|
||||||
|
|
||||||
if (!last7DaysWasLastMonth())
|
|
||||||
return time - 1;
|
|
||||||
|
|
||||||
return time;
|
|
||||||
}
|
|
||||||
|
|
||||||
FriendListWidget::FriendListWidget(Widget* parent, bool groupsOnTop)
|
FriendListWidget::FriendListWidget(Widget* parent, bool groupsOnTop)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
|
// Prevent Valgrind from complaining. We're changing this to Name here.
|
||||||
|
// Must be Activity for change to take effect.
|
||||||
|
, mode(Activity)
|
||||||
, groupsOnTop(groupsOnTop)
|
, groupsOnTop(groupsOnTop)
|
||||||
{
|
{
|
||||||
listLayout = new FriendListLayout();
|
listLayout = new FriendListLayout();
|
||||||
|
@ -121,6 +113,10 @@ FriendListWidget::FriendListWidget(Widget* parent, bool groupsOnTop)
|
||||||
groupLayout.getLayout()->setSpacing(0);
|
groupLayout.getLayout()->setSpacing(0);
|
||||||
groupLayout.getLayout()->setMargin(0);
|
groupLayout.getLayout()->setMargin(0);
|
||||||
|
|
||||||
|
// Prevent QLayout's add child warning before setting the mode.
|
||||||
|
listLayout->removeItem(listLayout->getLayoutOnline());
|
||||||
|
listLayout->removeItem(listLayout->getLayoutOffline());
|
||||||
|
|
||||||
setMode(Name);
|
setMode(Name);
|
||||||
|
|
||||||
onGroupchatPositionChanged(groupsOnTop);
|
onGroupchatPositionChanged(groupsOnTop);
|
||||||
|
@ -128,6 +124,31 @@ FriendListWidget::FriendListWidget(Widget* parent, bool groupsOnTop)
|
||||||
setAcceptDrops(true);
|
setAcceptDrops(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FriendListWidget::~FriendListWidget()
|
||||||
|
{
|
||||||
|
if (activityLayout != nullptr)
|
||||||
|
{
|
||||||
|
QLayoutItem* item;
|
||||||
|
while ((item = activityLayout->takeAt(0)) != nullptr)
|
||||||
|
{
|
||||||
|
delete item->widget();
|
||||||
|
delete item;
|
||||||
|
}
|
||||||
|
delete activityLayout;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (circleLayout != nullptr)
|
||||||
|
{
|
||||||
|
QLayoutItem* item;
|
||||||
|
while ((item = circleLayout->getLayout()->takeAt(0)) != nullptr)
|
||||||
|
{
|
||||||
|
delete item->widget();
|
||||||
|
delete item;
|
||||||
|
}
|
||||||
|
delete circleLayout;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void FriendListWidget::setMode(Mode mode)
|
void FriendListWidget::setMode(Mode mode)
|
||||||
{
|
{
|
||||||
if (this->mode == mode)
|
if (this->mode == mode)
|
||||||
|
@ -160,12 +181,15 @@ void FriendListWidget::setMode(Mode mode)
|
||||||
|
|
||||||
if (activityLayout != nullptr)
|
if (activityLayout != nullptr)
|
||||||
{
|
{
|
||||||
while (activityLayout->count() > 0)
|
QLayoutItem* item;
|
||||||
delete activityLayout->takeAt(0)->widget();
|
while ((item = activityLayout->takeAt(0)) != nullptr)
|
||||||
|
{
|
||||||
|
delete item->widget();
|
||||||
|
delete item;
|
||||||
}
|
}
|
||||||
|
|
||||||
delete activityLayout;
|
delete activityLayout;
|
||||||
activityLayout = nullptr;
|
activityLayout = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
reDraw();
|
reDraw();
|
||||||
}
|
}
|
||||||
|
@ -174,6 +198,7 @@ void FriendListWidget::setMode(Mode mode)
|
||||||
activityLayout = new QVBoxLayout();
|
activityLayout = new QVBoxLayout();
|
||||||
|
|
||||||
CategoryWidget* categoryToday = new CategoryWidget(this);
|
CategoryWidget* categoryToday = new CategoryWidget(this);
|
||||||
|
categoryToday->setObjectName("Todddd");
|
||||||
categoryToday->setName(tr("Today", "Category for sorting friends by activity"));
|
categoryToday->setName(tr("Today", "Category for sorting friends by activity"));
|
||||||
activityLayout->addWidget(categoryToday);
|
activityLayout->addWidget(categoryToday);
|
||||||
|
|
||||||
|
@ -241,22 +266,25 @@ void FriendListWidget::setMode(Mode mode)
|
||||||
categoryWidget->setVisible(categoryWidget->hasChatrooms());
|
categoryWidget->setVisible(categoryWidget->hasChatrooms());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (circleLayout != nullptr)
|
|
||||||
{
|
|
||||||
while (circleLayout->getLayout()->count() > 0)
|
|
||||||
delete circleLayout->getLayout()->takeAt(0)->widget();
|
|
||||||
}
|
|
||||||
|
|
||||||
listLayout->removeItem(listLayout->getLayoutOnline());
|
listLayout->removeItem(listLayout->getLayoutOnline());
|
||||||
listLayout->removeItem(listLayout->getLayoutOffline());
|
listLayout->removeItem(listLayout->getLayoutOffline());
|
||||||
listLayout->removeItem(circleLayout->getLayout());
|
listLayout->removeItem(circleLayout->getLayout());
|
||||||
listLayout->insertLayout(1, activityLayout);
|
listLayout->insertLayout(1, activityLayout);
|
||||||
|
|
||||||
reDraw();
|
if (circleLayout != nullptr)
|
||||||
|
{
|
||||||
|
QLayoutItem* item;
|
||||||
|
while ((item = circleLayout->getLayout()->takeAt(0)) != nullptr)
|
||||||
|
{
|
||||||
|
delete item->widget();
|
||||||
|
delete item;
|
||||||
|
}
|
||||||
delete circleLayout;
|
delete circleLayout;
|
||||||
circleLayout = nullptr;
|
circleLayout = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
reDraw();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FriendListWidget::Mode FriendListWidget::getMode() const
|
FriendListWidget::Mode FriendListWidget::getMode() const
|
||||||
|
|
|
@ -45,6 +45,7 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
explicit FriendListWidget(Widget* parent, bool groupsOnTop = true);
|
explicit FriendListWidget(Widget* parent, bool groupsOnTop = true);
|
||||||
|
~FriendListWidget();
|
||||||
void setMode(Mode mode);
|
void setMode(Mode mode);
|
||||||
Mode getMode() const;
|
Mode getMode() const;
|
||||||
|
|
||||||
|
|
|
@ -198,6 +198,7 @@ void FriendWidget::contextMenuEvent(QContextMenuEvent * event)
|
||||||
circle->addFriendWidget(this, FriendList::findFriend(friendId)->getStatus());
|
circle->addFriendWidget(this, FriendList::findFriend(friendId)->getStatus());
|
||||||
circle->setExpanded(true);
|
circle->setExpanded(true);
|
||||||
Widget::getInstance()->searchCircle(circle);
|
Widget::getInstance()->searchCircle(circle);
|
||||||
|
Settings::getInstance().savePersonal();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
Settings::getInstance().setFriendCircleID(id, circleActions[selectedItem]);
|
Settings::getInstance().setFriendCircleID(id, circleActions[selectedItem]);
|
||||||
|
|
|
@ -18,6 +18,7 @@ QToolButton {
|
||||||
QToolButton:pressed {
|
QToolButton:pressed {
|
||||||
background-color: @themeMediumDark;
|
background-color: @themeMediumDark;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
|
color: white;
|
||||||
}
|
}
|
||||||
|
|
||||||
QToolButton::menu-indicator {
|
QToolButton::menu-indicator {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user