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:
parent
08a646e456
commit
c8b156b3a1
@ -346,6 +346,7 @@ void Settings::loadPersonal(QString profileName, const ToxEncrypt* passKey)
|
|||||||
ps.beginGroup("GUI");
|
ps.beginGroup("GUI");
|
||||||
{
|
{
|
||||||
compactLayout = ps.value("compactLayout", true).toBool();
|
compactLayout = ps.value("compactLayout", true).toBool();
|
||||||
|
sortingMode = static_cast<FriendListSortingMode>(ps.value("friendSortingMethod", static_cast<int>(FriendListSortingMode::Name)).toInt());
|
||||||
}
|
}
|
||||||
ps.endGroup();
|
ps.endGroup();
|
||||||
|
|
||||||
@ -610,6 +611,7 @@ void Settings::savePersonal(QString profileName, const ToxEncrypt* passkey)
|
|||||||
ps.beginGroup("GUI");
|
ps.beginGroup("GUI");
|
||||||
{
|
{
|
||||||
ps.setValue("compactLayout", compactLayout);
|
ps.setValue("compactLayout", compactLayout);
|
||||||
|
ps.setValue("friendSortingMethod", static_cast<int>(sortingMode));
|
||||||
}
|
}
|
||||||
ps.endGroup();
|
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
|
bool Settings::getSeparateWindow() const
|
||||||
{
|
{
|
||||||
QMutexLocker locker{&bigLock};
|
QMutexLocker locker{&bigLock};
|
||||||
|
@ -133,6 +133,12 @@ public:
|
|||||||
WITHOUT_CHARS = 2
|
WITHOUT_CHARS = 2
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum class FriendListSortingMode
|
||||||
|
{
|
||||||
|
Name,
|
||||||
|
Activity,
|
||||||
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static Settings& getInstance();
|
static Settings& getInstance();
|
||||||
static void destroyInstance();
|
static void destroyInstance();
|
||||||
@ -204,6 +210,7 @@ signals:
|
|||||||
void styleChanged(const QString& style);
|
void styleChanged(const QString& style);
|
||||||
void themeColorChanged(int color);
|
void themeColorChanged(int color);
|
||||||
void compactLayoutChanged(bool enabled);
|
void compactLayoutChanged(bool enabled);
|
||||||
|
void sortingModeChanged(FriendListSortingMode mode);
|
||||||
void showIdenticonsChanged(bool enabled);
|
void showIdenticonsChanged(bool enabled);
|
||||||
|
|
||||||
// ChatView
|
// ChatView
|
||||||
@ -515,6 +522,9 @@ public:
|
|||||||
bool getCompactLayout() const;
|
bool getCompactLayout() const;
|
||||||
void setCompactLayout(bool compact);
|
void setCompactLayout(bool compact);
|
||||||
|
|
||||||
|
FriendListSortingMode getFriendSortingMode() const;
|
||||||
|
void setFriendSortingMode(FriendListSortingMode mode);
|
||||||
|
|
||||||
bool getSeparateWindow() const;
|
bool getSeparateWindow() const;
|
||||||
void setSeparateWindow(bool value);
|
void setSeparateWindow(bool value);
|
||||||
|
|
||||||
@ -592,6 +602,7 @@ private:
|
|||||||
bool autoLogin;
|
bool autoLogin;
|
||||||
bool fauxOfflineMessaging;
|
bool fauxOfflineMessaging;
|
||||||
bool compactLayout;
|
bool compactLayout;
|
||||||
|
FriendListSortingMode sortingMode;
|
||||||
bool groupchatPosition;
|
bool groupchatPosition;
|
||||||
bool separateWindow;
|
bool separateWindow;
|
||||||
bool dontGroupWindows;
|
bool dontGroupWindows;
|
||||||
|
@ -99,9 +99,6 @@ qint64 timeUntilTomorrow()
|
|||||||
|
|
||||||
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();
|
||||||
@ -115,7 +112,8 @@ FriendListWidget::FriendListWidget(Widget* parent, bool groupsOnTop)
|
|||||||
listLayout->removeItem(listLayout->getLayoutOnline());
|
listLayout->removeItem(listLayout->getLayoutOnline());
|
||||||
listLayout->removeItem(listLayout->getLayoutOffline());
|
listLayout->removeItem(listLayout->getLayoutOffline());
|
||||||
|
|
||||||
setMode(Name);
|
mode = Settings::getInstance().getFriendSortingMode();
|
||||||
|
sortByMode(mode);
|
||||||
|
|
||||||
onGroupchatPositionChanged(groupsOnTop);
|
onGroupchatPositionChanged(groupsOnTop);
|
||||||
dayTimer = new QTimer(this);
|
dayTimer = new QTimer(this);
|
||||||
@ -147,14 +145,20 @@ FriendListWidget::~FriendListWidget()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FriendListWidget::setMode(Mode mode)
|
void FriendListWidget::setMode(SortingMode mode)
|
||||||
{
|
{
|
||||||
if (this->mode == mode)
|
if (this->mode == mode)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
this->mode = mode;
|
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 = new GenericChatItemLayout;
|
||||||
circleLayout->getLayout()->setSpacing(0);
|
circleLayout->getLayout()->setSpacing(0);
|
||||||
circleLayout->getLayout()->setMargin(0);
|
circleLayout->getLayout()->setMargin(0);
|
||||||
@ -195,7 +199,7 @@ void FriendListWidget::setMode(Mode mode)
|
|||||||
}
|
}
|
||||||
|
|
||||||
reDraw();
|
reDraw();
|
||||||
} else if (mode == Activity) {
|
} else if (mode == SortingMode::Activity) {
|
||||||
QLocale ql(Settings::getInstance().getTranslation());
|
QLocale ql(Settings::getInstance().getTranslation());
|
||||||
QDate today = QDate::currentDate();
|
QDate today = QDate::currentDate();
|
||||||
#define COMMENT "Category for sorting friends by activity"
|
#define COMMENT "Category for sorting friends by activity"
|
||||||
@ -226,7 +230,9 @@ void FriendListWidget::setMode(Mode mode)
|
|||||||
|
|
||||||
moveFriends(listLayout->getLayoutOffline());
|
moveFriends(listLayout->getLayoutOffline());
|
||||||
moveFriends(listLayout->getLayoutOnline());
|
moveFriends(listLayout->getLayoutOnline());
|
||||||
|
if (circleLayout != nullptr) {
|
||||||
moveFriends(circleLayout->getLayout());
|
moveFriends(circleLayout->getLayout());
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < activityLayout->count(); ++i) {
|
for (int i = 0; i < activityLayout->count(); ++i) {
|
||||||
QWidget* widget = activityLayout->itemAt(i)->widget();
|
QWidget* widget = activityLayout->itemAt(i)->widget();
|
||||||
@ -279,7 +285,7 @@ CategoryWidget* FriendListWidget::getTimeCategoryWidget(const Friend* frd) const
|
|||||||
return qobject_cast<CategoryWidget*>(widget);
|
return qobject_cast<CategoryWidget*>(widget);
|
||||||
}
|
}
|
||||||
|
|
||||||
FriendListWidget::Mode FriendListWidget::getMode() const
|
FriendListWidget::SortingMode FriendListWidget::getMode() const
|
||||||
{
|
{
|
||||||
return mode;
|
return mode;
|
||||||
}
|
}
|
||||||
@ -314,7 +320,8 @@ void FriendListWidget::removeGroupWidget(GroupWidget* w)
|
|||||||
void FriendListWidget::removeFriendWidget(FriendWidget* w)
|
void FriendListWidget::removeFriendWidget(FriendWidget* w)
|
||||||
{
|
{
|
||||||
const Friend* contact = w->getFriend();
|
const Friend* contact = w->getFriend();
|
||||||
if (mode == Activity) {
|
|
||||||
|
if (mode == SortingMode::Activity) {
|
||||||
auto* categoryWidget = getTimeCategoryWidget(contact);
|
auto* categoryWidget = getTimeCategoryWidget(contact);
|
||||||
categoryWidget->removeFriendWidget(w, contact->getStatus());
|
categoryWidget->removeFriendWidget(w, contact->getStatus());
|
||||||
categoryWidget->setVisible(categoryWidget->hasChatrooms());
|
categoryWidget->setVisible(categoryWidget->hasChatrooms());
|
||||||
@ -403,7 +410,7 @@ void FriendListWidget::onFriendWidgetRenamed(FriendWidget* friendWidget)
|
|||||||
{
|
{
|
||||||
const Friend* contact = friendWidget->getFriend();
|
const Friend* contact = friendWidget->getFriend();
|
||||||
auto status = contact->getStatus();
|
auto status = contact->getStatus();
|
||||||
if (mode == Activity) {
|
if (mode == SortingMode::Activity) {
|
||||||
auto* categoryWidget = getTimeCategoryWidget(contact);
|
auto* categoryWidget = getTimeCategoryWidget(contact);
|
||||||
categoryWidget->removeFriendWidget(friendWidget, status);
|
categoryWidget->removeFriendWidget(friendWidget, status);
|
||||||
categoryWidget->addFriendWidget(friendWidget, status);
|
categoryWidget->addFriendWidget(friendWidget, status);
|
||||||
@ -425,7 +432,7 @@ void FriendListWidget::onGroupchatPositionChanged(bool top)
|
|||||||
{
|
{
|
||||||
groupsOnTop = top;
|
groupsOnTop = top;
|
||||||
|
|
||||||
if (mode != Name)
|
if (mode != SortingMode::Name)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
listLayout->removeItem(groupLayout.getLayout());
|
listLayout->removeItem(groupLayout.getLayout());
|
||||||
@ -447,7 +454,7 @@ void FriendListWidget::cycleContacts(GenericChatroomWidget* activeChatroomWidget
|
|||||||
int index = -1;
|
int index = -1;
|
||||||
FriendWidget* friendWidget = qobject_cast<FriendWidget*>(activeChatroomWidget);
|
FriendWidget* friendWidget = qobject_cast<FriendWidget*>(activeChatroomWidget);
|
||||||
|
|
||||||
if (mode == Activity) {
|
if (mode == SortingMode::Activity) {
|
||||||
if (!friendWidget) {
|
if (!friendWidget) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -601,9 +608,9 @@ void FriendListWidget::dropEvent(QDropEvent* event)
|
|||||||
|
|
||||||
void FriendListWidget::dayTimeout()
|
void FriendListWidget::dayTimeout()
|
||||||
{
|
{
|
||||||
if (mode == Activity) {
|
if (mode == SortingMode::Activity) {
|
||||||
setMode(Name);
|
setMode(SortingMode::Name);
|
||||||
setMode(Activity); // Refresh all.
|
setMode(SortingMode::Activity); // Refresh all.
|
||||||
}
|
}
|
||||||
|
|
||||||
dayTimer->start(timeUntilTomorrow());
|
dayTimer->start(timeUntilTomorrow());
|
||||||
@ -611,7 +618,7 @@ void FriendListWidget::dayTimeout()
|
|||||||
|
|
||||||
void FriendListWidget::moveWidget(FriendWidget* widget, Status::Status s, bool add)
|
void FriendListWidget::moveWidget(FriendWidget* widget, Status::Status s, bool add)
|
||||||
{
|
{
|
||||||
if (mode == Name) {
|
if (mode == SortingMode::Name) {
|
||||||
const Friend* f = widget->getFriend();
|
const Friend* f = widget->getFriend();
|
||||||
int circleId = Settings::getInstance().getFriendCircleID(f->getPublicKey());
|
int circleId = Settings::getInstance().getFriendCircleID(f->getPublicKey());
|
||||||
CircleWidget* circleWidget = CircleWidget::getFromID(circleId);
|
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)
|
void FriendListWidget::updateActivityTime(const QDateTime& time)
|
||||||
{
|
{
|
||||||
if (mode != Activity)
|
if (mode != SortingMode::Activity)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int timeIndex = static_cast<int>(getTimeBucket(time));
|
int timeIndex = static_cast<int>(getTimeBucket(time));
|
||||||
@ -660,7 +667,7 @@ CircleWidget* FriendListWidget::createCircleWidget(int id)
|
|||||||
id = Settings::getInstance().addCircle();
|
id = Settings::getInstance().addCircle();
|
||||||
|
|
||||||
// Stop, after it has been created. Code after this is for displaying.
|
// Stop, after it has been created. Code after this is for displaying.
|
||||||
if (mode == Activity)
|
if (mode == SortingMode::Activity)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
assert(circleLayout != nullptr);
|
assert(circleLayout != nullptr);
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#include "genericchatitemlayout.h"
|
#include "genericchatitemlayout.h"
|
||||||
#include "src/core/core.h"
|
#include "src/core/core.h"
|
||||||
#include "src/model/status.h"
|
#include "src/model/status.h"
|
||||||
|
#include "src/persistence/settings.h"
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
class QVBoxLayout;
|
class QVBoxLayout;
|
||||||
@ -41,16 +42,11 @@ class FriendListWidget : public QWidget
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
enum Mode : uint8_t
|
using SortingMode = Settings::FriendListSortingMode;
|
||||||
{
|
|
||||||
Name,
|
|
||||||
Activity,
|
|
||||||
};
|
|
||||||
|
|
||||||
explicit FriendListWidget(Widget* parent, bool groupsOnTop = true);
|
explicit FriendListWidget(Widget* parent, bool groupsOnTop = true);
|
||||||
~FriendListWidget();
|
~FriendListWidget();
|
||||||
void setMode(Mode mode);
|
void setMode(SortingMode mode);
|
||||||
Mode getMode() const;
|
SortingMode getMode() const;
|
||||||
|
|
||||||
void addGroupWidget(GroupWidget* widget);
|
void addGroupWidget(GroupWidget* widget);
|
||||||
void addFriendWidget(FriendWidget* w, Status::Status s, int circleIndex);
|
void addFriendWidget(FriendWidget* w, Status::Status s, int circleIndex);
|
||||||
@ -89,8 +85,9 @@ private:
|
|||||||
QLayout* nextLayout(QLayout* layout, bool forward) const;
|
QLayout* nextLayout(QLayout* layout, bool forward) const;
|
||||||
void moveFriends(QLayout* layout);
|
void moveFriends(QLayout* layout);
|
||||||
CategoryWidget* getTimeCategoryWidget(const Friend* frd) const;
|
CategoryWidget* getTimeCategoryWidget(const Friend* frd) const;
|
||||||
|
void sortByMode(SortingMode mode);
|
||||||
|
|
||||||
Mode mode;
|
SortingMode mode;
|
||||||
bool groupsOnTop;
|
bool groupsOnTop;
|
||||||
FriendListLayout* listLayout;
|
FriendListLayout* listLayout;
|
||||||
GenericChatItemLayout* circleLayout = nullptr;
|
GenericChatItemLayout* circleLayout = nullptr;
|
||||||
|
@ -173,6 +173,9 @@ void Widget::init()
|
|||||||
filterDisplayActivity->setCheckable(true);
|
filterDisplayActivity->setCheckable(true);
|
||||||
filterDisplayGroup->addAction(filterDisplayActivity);
|
filterDisplayGroup->addAction(filterDisplayActivity);
|
||||||
filterMenu->addAction(filterDisplayActivity);
|
filterMenu->addAction(filterDisplayActivity);
|
||||||
|
settings.getFriendSortingMode() == FriendListWidget::SortingMode::Name ?
|
||||||
|
filterDisplayName->setChecked(true) :
|
||||||
|
filterDisplayActivity->setChecked(true);
|
||||||
filterMenu->addSeparator();
|
filterMenu->addSeparator();
|
||||||
|
|
||||||
filterAllAction = new QAction(this);
|
filterAllAction = new QAction(this);
|
||||||
@ -2268,9 +2271,9 @@ void Widget::changeDisplayMode()
|
|||||||
filterDisplayGroup->setEnabled(false);
|
filterDisplayGroup->setEnabled(false);
|
||||||
|
|
||||||
if (filterDisplayGroup->checkedAction() == filterDisplayActivity) {
|
if (filterDisplayGroup->checkedAction() == filterDisplayActivity) {
|
||||||
contactListWidget->setMode(FriendListWidget::Activity);
|
contactListWidget->setMode(FriendListWidget::SortingMode::Activity);
|
||||||
} else if (filterDisplayGroup->checkedAction() == filterDisplayName) {
|
} else if (filterDisplayGroup->checkedAction() == filterDisplayName) {
|
||||||
contactListWidget->setMode(FriendListWidget::Name);
|
contactListWidget->setMode(FriendListWidget::SortingMode::Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
searchContacts();
|
searchContacts();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user