Browse Source

Fix friend list when day changes

pull/2045/head
TheSpiritXIII 10 years ago
parent
commit
e574af7a5e
  1. 24
      src/widget/friendlistwidget.cpp
  2. 4
      src/widget/friendlistwidget.h

24
src/widget/friendlistwidget.cpp

@ -31,6 +31,7 @@ @@ -31,6 +31,7 @@
#include <QMimeData>
#include <QDragEnterEvent>
#include <QDragLeaveEvent>
#include <QTimer>
#include <cassert>
enum Time : int
@ -114,6 +115,14 @@ QDate getDateFriend(Friend* contact) @@ -114,6 +115,14 @@ QDate getDateFriend(Friend* contact)
return Settings::getInstance().getFriendActivity(contact->getToxId());
}
qint64 timeUntilTomorrow()
{
QDateTime now = QDateTime::currentDateTime();
QDateTime tomorrow = now.addDays(1); // Tomorrow.
tomorrow.setTime(QTime()); // Midnight.
return now.msecsTo(tomorrow);
}
FriendListWidget::FriendListWidget(Widget* parent, bool groupsOnTop)
: QWidget(parent)
// Prevent Valgrind from complaining. We're changing this to Name here.
@ -135,6 +144,10 @@ FriendListWidget::FriendListWidget(Widget* parent, bool groupsOnTop) @@ -135,6 +144,10 @@ FriendListWidget::FriendListWidget(Widget* parent, bool groupsOnTop)
setMode(Name);
onGroupchatPositionChanged(groupsOnTop);
dayTimer = new QTimer(this);
dayTimer->setTimerType(Qt::VeryCoarseTimer);
connect(dayTimer, &QTimer::timeout, this, &FriendListWidget::dayTimeout);
dayTimer->start(timeUntilTomorrow());
setAcceptDrops(true);
}
@ -621,6 +634,17 @@ void FriendListWidget::dropEvent(QDropEvent* event) @@ -621,6 +634,17 @@ void FriendListWidget::dropEvent(QDropEvent* event)
}
}
void FriendListWidget::dayTimeout()
{
if (mode == Activity)
{
setMode(Name);
setMode(Activity); // Refresh all.
}
dayTimer->start(timeUntilTomorrow());
}
void FriendListWidget::moveWidget(FriendWidget* w, Status s, bool add)
{
if (mode == Name)

4
src/widget/friendlistwidget.h

@ -76,6 +76,9 @@ protected: @@ -76,6 +76,9 @@ protected:
void dragEnterEvent(QDragEnterEvent* event) override;
void dropEvent(QDropEvent* event) override;
private slots:
void dayTimeout();
private:
CircleWidget* createCircleWidget(int id = -1);
QLayout* nextLayout(QLayout* layout, bool forward) const;
@ -86,6 +89,7 @@ private: @@ -86,6 +89,7 @@ private:
GenericChatItemLayout* circleLayout = nullptr;
GenericChatItemLayout groupLayout;
QVBoxLayout* activityLayout = nullptr;
QTimer* dayTimer;
};
#endif // FRIENDLISTWIDGET_H

Loading…
Cancel
Save