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

feat(settings): save friend list sorting mode

This commit is contained in:
Anthony Bilinski 2019-05-17 00:09:40 -07:00
parent 08a646e456
commit c8b156b3a1
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C
5 changed files with 66 additions and 30 deletions

View File

@ -346,6 +346,7 @@ void Settings::loadPersonal(QString profileName, const ToxEncrypt* passKey)
ps.beginGroup("GUI");
{
compactLayout = ps.value("compactLayout", true).toBool();
sortingMode = static_cast<FriendListSortingMode>(ps.value("friendSortingMethod", static_cast<int>(FriendListSortingMode::Name)).toInt());
}
ps.endGroup();
@ -610,6 +611,7 @@ void Settings::savePersonal(QString profileName, const ToxEncrypt* passkey)
ps.beginGroup("GUI");
{
ps.setValue("compactLayout", compactLayout);
ps.setValue("friendSortingMethod", static_cast<int>(sortingMode));
}
ps.endGroup();
@ -2092,6 +2094,22 @@ void Settings::setCompactLayout(bool value)
}
}
Settings::FriendListSortingMode Settings::getFriendSortingMode() const
{
QMutexLocker locker{&bigLock};
return sortingMode;
}
void Settings::setFriendSortingMode(FriendListSortingMode mode)
{
QMutexLocker locker{&bigLock};
if (mode != sortingMode) {
sortingMode = mode;
emit sortingModeChanged(sortingMode);
}
}
bool Settings::getSeparateWindow() const
{
QMutexLocker locker{&bigLock};

View File

@ -133,6 +133,12 @@ public:
WITHOUT_CHARS = 2
};
enum class FriendListSortingMode
{
Name,
Activity,
};
public:
static Settings& getInstance();
static void destroyInstance();
@ -204,6 +210,7 @@ signals:
void styleChanged(const QString& style);
void themeColorChanged(int color);
void compactLayoutChanged(bool enabled);
void sortingModeChanged(FriendListSortingMode mode);
void showIdenticonsChanged(bool enabled);
// ChatView
@ -515,6 +522,9 @@ public:
bool getCompactLayout() const;
void setCompactLayout(bool compact);
FriendListSortingMode getFriendSortingMode() const;
void setFriendSortingMode(FriendListSortingMode mode);
bool getSeparateWindow() const;
void setSeparateWindow(bool value);
@ -592,6 +602,7 @@ private:
bool autoLogin;
bool fauxOfflineMessaging;
bool compactLayout;
FriendListSortingMode sortingMode;
bool groupchatPosition;
bool separateWindow;
bool dontGroupWindows;

View File

@ -99,9 +99,6 @@ qint64 timeUntilTomorrow()
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();
@ -115,7 +112,8 @@ FriendListWidget::FriendListWidget(Widget* parent, bool groupsOnTop)
listLayout->removeItem(listLayout->getLayoutOnline());
listLayout->removeItem(listLayout->getLayoutOffline());
setMode(Name);
mode = Settings::getInstance().getFriendSortingMode();
sortByMode(mode);
onGroupchatPositionChanged(groupsOnTop);
dayTimer = new QTimer(this);
@ -147,14 +145,20 @@ FriendListWidget::~FriendListWidget()
}
}
void FriendListWidget::setMode(Mode mode)
void FriendListWidget::setMode(SortingMode mode)
{
if (this->mode == mode)
return;
this->mode = mode;
Settings::getInstance().setFriendSortingMode(mode);
if (mode == Name) {
sortByMode(mode);
}
void FriendListWidget::sortByMode(SortingMode mode)
{
if (mode == SortingMode::Name) {
circleLayout = new GenericChatItemLayout;
circleLayout->getLayout()->setSpacing(0);
circleLayout->getLayout()->setMargin(0);
@ -195,7 +199,7 @@ void FriendListWidget::setMode(Mode mode)
}
reDraw();
} else if (mode == Activity) {
} else if (mode == SortingMode::Activity) {
QLocale ql(Settings::getInstance().getTranslation());
QDate today = QDate::currentDate();
#define COMMENT "Category for sorting friends by activity"
@ -226,7 +230,9 @@ void FriendListWidget::setMode(Mode mode)
moveFriends(listLayout->getLayoutOffline());
moveFriends(listLayout->getLayoutOnline());
moveFriends(circleLayout->getLayout());
if (circleLayout != nullptr) {
moveFriends(circleLayout->getLayout());
}
for (int i = 0; i < activityLayout->count(); ++i) {
QWidget* widget = activityLayout->itemAt(i)->widget();
@ -279,7 +285,7 @@ CategoryWidget* FriendListWidget::getTimeCategoryWidget(const Friend* frd) const
return qobject_cast<CategoryWidget*>(widget);
}
FriendListWidget::Mode FriendListWidget::getMode() const
FriendListWidget::SortingMode FriendListWidget::getMode() const
{
return mode;
}
@ -314,7 +320,8 @@ void FriendListWidget::removeGroupWidget(GroupWidget* w)
void FriendListWidget::removeFriendWidget(FriendWidget* w)
{
const Friend* contact = w->getFriend();
if (mode == Activity) {
if (mode == SortingMode::Activity) {
auto* categoryWidget = getTimeCategoryWidget(contact);
categoryWidget->removeFriendWidget(w, contact->getStatus());
categoryWidget->setVisible(categoryWidget->hasChatrooms());
@ -403,7 +410,7 @@ void FriendListWidget::onFriendWidgetRenamed(FriendWidget* friendWidget)
{
const Friend* contact = friendWidget->getFriend();
auto status = contact->getStatus();
if (mode == Activity) {
if (mode == SortingMode::Activity) {
auto* categoryWidget = getTimeCategoryWidget(contact);
categoryWidget->removeFriendWidget(friendWidget, status);
categoryWidget->addFriendWidget(friendWidget, status);
@ -425,7 +432,7 @@ void FriendListWidget::onGroupchatPositionChanged(bool top)
{
groupsOnTop = top;
if (mode != Name)
if (mode != SortingMode::Name)
return;
listLayout->removeItem(groupLayout.getLayout());
@ -447,7 +454,7 @@ void FriendListWidget::cycleContacts(GenericChatroomWidget* activeChatroomWidget
int index = -1;
FriendWidget* friendWidget = qobject_cast<FriendWidget*>(activeChatroomWidget);
if (mode == Activity) {
if (mode == SortingMode::Activity) {
if (!friendWidget) {
return;
}
@ -601,9 +608,9 @@ void FriendListWidget::dropEvent(QDropEvent* event)
void FriendListWidget::dayTimeout()
{
if (mode == Activity) {
setMode(Name);
setMode(Activity); // Refresh all.
if (mode == SortingMode::Activity) {
setMode(SortingMode::Name);
setMode(SortingMode::Activity); // Refresh all.
}
dayTimer->start(timeUntilTomorrow());
@ -611,7 +618,7 @@ void FriendListWidget::dayTimeout()
void FriendListWidget::moveWidget(FriendWidget* widget, Status::Status s, bool add)
{
if (mode == Name) {
if (mode == SortingMode::Name) {
const Friend* f = widget->getFriend();
int circleId = Settings::getInstance().getFriendCircleID(f->getPublicKey());
CircleWidget* circleWidget = CircleWidget::getFromID(circleId);
@ -635,7 +642,7 @@ void FriendListWidget::moveWidget(FriendWidget* widget, Status::Status s, bool a
void FriendListWidget::updateActivityTime(const QDateTime& time)
{
if (mode != Activity)
if (mode != SortingMode::Activity)
return;
int timeIndex = static_cast<int>(getTimeBucket(time));
@ -660,7 +667,7 @@ CircleWidget* FriendListWidget::createCircleWidget(int id)
id = Settings::getInstance().addCircle();
// Stop, after it has been created. Code after this is for displaying.
if (mode == Activity)
if (mode == SortingMode::Activity)
return nullptr;
assert(circleLayout != nullptr);

View File

@ -23,6 +23,7 @@
#include "genericchatitemlayout.h"
#include "src/core/core.h"
#include "src/model/status.h"
#include "src/persistence/settings.h"
#include <QWidget>
class QVBoxLayout;
@ -41,16 +42,11 @@ class FriendListWidget : public QWidget
{
Q_OBJECT
public:
enum Mode : uint8_t
{
Name,
Activity,
};
using SortingMode = Settings::FriendListSortingMode;
explicit FriendListWidget(Widget* parent, bool groupsOnTop = true);
~FriendListWidget();
void setMode(Mode mode);
Mode getMode() const;
void setMode(SortingMode mode);
SortingMode getMode() const;
void addGroupWidget(GroupWidget* widget);
void addFriendWidget(FriendWidget* w, Status::Status s, int circleIndex);
@ -89,8 +85,9 @@ private:
QLayout* nextLayout(QLayout* layout, bool forward) const;
void moveFriends(QLayout* layout);
CategoryWidget* getTimeCategoryWidget(const Friend* frd) const;
void sortByMode(SortingMode mode);
Mode mode;
SortingMode mode;
bool groupsOnTop;
FriendListLayout* listLayout;
GenericChatItemLayout* circleLayout = nullptr;

View File

@ -173,6 +173,9 @@ void Widget::init()
filterDisplayActivity->setCheckable(true);
filterDisplayGroup->addAction(filterDisplayActivity);
filterMenu->addAction(filterDisplayActivity);
settings.getFriendSortingMode() == FriendListWidget::SortingMode::Name ?
filterDisplayName->setChecked(true) :
filterDisplayActivity->setChecked(true);
filterMenu->addSeparator();
filterAllAction = new QAction(this);
@ -2268,9 +2271,9 @@ void Widget::changeDisplayMode()
filterDisplayGroup->setEnabled(false);
if (filterDisplayGroup->checkedAction() == filterDisplayActivity) {
contactListWidget->setMode(FriendListWidget::Activity);
contactListWidget->setMode(FriendListWidget::SortingMode::Activity);
} else if (filterDisplayGroup->checkedAction() == filterDisplayName) {
contactListWidget->setMode(FriendListWidget::Name);
contactListWidget->setMode(FriendListWidget::SortingMode::Name);
}
searchContacts();