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