summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSateallia <mail@satealliasdomain.net>2023-04-13 11:45:00 +0000
committerNicolas Werner <nicolas.werner@hotmail.de>2023-04-14 18:59:06 +0200
commit4b2bf9680cbde81ba3fd66272a3f29a7715d1bd4 (patch)
treeb437578205ad1235a79e0cb00247a0ba49799f3e
parenta7524bee709b5cb610e1652bef12b0501259595e (diff)
Alphabetical ordering option
-rw-r--r--src/UserSettingsPage.cpp42
-rw-r--r--src/UserSettingsPage.h11
-rw-r--r--src/timeline/RoomlistModel.cpp37
-rw-r--r--src/timeline/RoomlistModel.h1
4 files changed, 77 insertions, 14 deletions
diff --git a/src/UserSettingsPage.cpp b/src/UserSettingsPage.cpp
index dac9aef2..e4af4b56 100644
--- a/src/UserSettingsPage.cpp
+++ b/src/UserSettingsPage.cpp
@@ -79,6 +79,7 @@ UserSettings::load(std::optional<QString> profile)
typingNotifications_ =
settings.value(QStringLiteral("user/typing_notifications"), true).toBool();
sortByImportance_ = settings.value(QStringLiteral("user/sort_by_unread"), true).toBool();
+ sortByAlphabet_ = settings.value(QStringLiteral("user/sort_by_alphabet"), false).toBool();
readReceipts_ = settings.value(QStringLiteral("user/read_receipts"), true).toBool();
theme_ = settings.value(QStringLiteral("user/theme"), defaultTheme_).toString();
@@ -383,7 +384,17 @@ UserSettings::setSortByImportance(bool state)
if (state == sortByImportance_)
return;
sortByImportance_ = state;
- emit roomSortingChanged(state);
+ emit roomSortingChangedImportance(state);
+ save();
+}
+
+void
+UserSettings::setSortByAlphabet(bool state)
+{
+ if (state == sortByAlphabet_)
+ return;
+ sortByAlphabet_ = state;
+ emit roomSortingChangedAlphabetical(state);
save();
}
@@ -882,6 +893,7 @@ UserSettings::save()
settings.setValue(QStringLiteral("font_size"), baseFontSize_);
settings.setValue(QStringLiteral("typing_notifications"), typingNotifications_);
settings.setValue(QStringLiteral("sort_by_unread"), sortByImportance_);
+ settings.setValue(QStringLiteral("sort_by_alphabet"), sortByAlphabet_);
settings.setValue(QStringLiteral("minor_events"), sortByImportance_);
settings.setValue(QStringLiteral("read_receipts"), readReceipts_);
settings.setValue(QStringLiteral("group_view"), groupView_);
@@ -1010,6 +1022,8 @@ UserSettingsModel::data(const QModelIndex &index, int role) const
return tr("Typing notifications");
case SortByImportance:
return tr("Sort rooms by unreads");
+ case SortByAlphabet:
+ return tr("Sort rooms by alphabetical order instead of last message time");
case ButtonsInTimeline:
return tr("Show buttons in timeline");
case TimelineMaxWidth:
@@ -1156,6 +1170,8 @@ UserSettingsModel::data(const QModelIndex &index, int role) const
return i->typingNotifications();
case SortByImportance:
return i->sortByImportance();
+ case SortByAlphabet:
+ return i->sortByAlphabet();
case ButtonsInTimeline:
return i->buttonsInTimeline();
case TimelineMaxWidth:
@@ -1312,11 +1328,18 @@ UserSettingsModel::data(const QModelIndex &index, int role) const
case SortByImportance:
return tr(
"Display rooms with new messages first.\nIf this is off, the list of rooms will only "
- "be sorted by the timestamp of the last message in a room.\nIf this is on, rooms "
+ "be sorted by the preferred sorting order.\nIf this is on, rooms "
"which "
"have active notifications (the small circle with a number in it) will be sorted on "
- "top. Rooms that you have muted will still be sorted by timestamp, since you don't "
+ "top. Rooms that you have muted will still be sorted by the preferred sorting order, "
+ "since you don't "
"seem to consider them as important as the other rooms.");
+ case SortByAlphabet:
+ return tr(
+ "Sort rooms alphabetically.\nIf this is off, the list of rooms will be sorted by the "
+ "timestamp of the last message in a room.\nIf this is on, rooms that come first "
+ "alphabetically "
+ "will be sorted earlier than ones that come later.");
case ButtonsInTimeline:
return tr(
"Show buttons to quickly reply, react or access additional options next to each "
@@ -1460,6 +1483,7 @@ UserSettingsModel::data(const QModelIndex &index, int role) const
case AnimateImagesOnHover:
case TypingNotifications:
case SortByImportance:
+ case SortByAlphabet:
case ButtonsInTimeline:
case ReadReceipts:
case DesktopNotifications:
@@ -1733,6 +1757,13 @@ UserSettingsModel::setData(const QModelIndex &index, const QVariant &value, int
} else
return false;
}
+ case SortByAlphabet: {
+ if (value.userType() == QMetaType::Bool) {
+ i->setSortByAlphabet(value.toBool());
+ return true;
+ } else
+ return false;
+ }
case ButtonsInTimeline: {
if (value.userType() == QMetaType::Bool) {
i->setButtonsInTimeline(value.toBool());
@@ -2150,9 +2181,12 @@ UserSettingsModel::UserSettingsModel(QObject *p)
connect(s.get(), &UserSettings::scrollbarsInRoomlistChanged, this, [this]() {
emit dataChanged(index(ScrollbarsInRoomlist), index(ScrollbarsInRoomlist), {Value});
});
- connect(s.get(), &UserSettings::roomSortingChanged, this, [this]() {
+ connect(s.get(), &UserSettings::roomSortingChangedImportance, this, [this]() {
emit dataChanged(index(SortByImportance), index(SortByImportance), {Value});
});
+ connect(s.get(), &UserSettings::roomSortingChangedAlphabetical, this, [this]() {
+ emit dataChanged(index(SortByAlphabet), index(SortByAlphabet), {Value});
+ });
connect(s.get(), &UserSettings::decryptSidebarChanged, this, [this]() {
emit dataChanged(index(DecryptSidebar), index(DecryptSidebar), {Value});
});
diff --git a/src/UserSettingsPage.h b/src/UserSettingsPage.h
index 8477818b..5c05b143 100644
--- a/src/UserSettingsPage.h
+++ b/src/UserSettingsPage.h
@@ -44,7 +44,9 @@ class UserSettings final : public QObject
Q_PROPERTY(bool typingNotifications READ typingNotifications WRITE setTypingNotifications NOTIFY
typingNotificationsChanged)
Q_PROPERTY(bool sortByImportance READ sortByImportance WRITE setSortByImportance NOTIFY
- roomSortingChanged)
+ roomSortingChangedImportance)
+ Q_PROPERTY(bool sortByAlphabet READ sortByAlphabet WRITE setSortByAlphabet NOTIFY
+ roomSortingChangedAlphabetical)
Q_PROPERTY(bool buttonsInTimeline READ buttonsInTimeline WRITE setButtonsInTimeline NOTIFY
buttonInTimelineChanged)
Q_PROPERTY(bool readReceipts READ readReceipts WRITE setReadReceipts NOTIFY readReceiptsChanged)
@@ -163,6 +165,7 @@ public:
void setReadReceipts(bool state);
void setTypingNotifications(bool state);
void setSortByImportance(bool state);
+ void setSortByAlphabet(bool state);
void setButtonsInTimeline(bool state);
void setTimelineMaxWidth(int state);
void setCommunityListWidth(int state);
@@ -231,6 +234,7 @@ public:
bool animateImagesOnHover() const { return animateImagesOnHover_; }
bool typingNotifications() const { return typingNotifications_; }
bool sortByImportance() const { return sortByImportance_; }
+ bool sortByAlphabet() const { return sortByAlphabet_; }
bool buttonsInTimeline() const { return buttonsInTimeline_; }
bool mobileMode() const { return mobileMode_; }
bool readReceipts() const { return readReceipts_; }
@@ -285,7 +289,8 @@ public:
signals:
void groupViewStateChanged(bool state);
void scrollbarsInRoomlistChanged(bool state);
- void roomSortingChanged(bool state);
+ void roomSortingChangedImportance(bool state);
+ void roomSortingChangedAlphabetical(bool state);
void themeChanged(QString state);
void messageHoverHighlightChanged(bool state);
void enlargeEmojiOnlyMessagesChanged(bool state);
@@ -366,6 +371,7 @@ private:
bool animateImagesOnHover_;
bool typingNotifications_;
bool sortByImportance_;
+ bool sortByAlphabet_;
bool buttonsInTimeline_;
bool readReceipts_;
bool hasDesktopNotifications_;
@@ -469,6 +475,7 @@ class UserSettingsModel final : public QAbstractListModel
SidebarSection,
GroupView,
SortByImportance,
+ SortByAlphabet,
DecryptSidebar,
SpaceNotifications,
diff --git a/src/timeline/RoomlistModel.cpp b/src/timeline/RoomlistModel.cpp
index 12fee262..0801289c 100644
--- a/src/timeline/RoomlistModel.cpp
+++ b/src/timeline/RoomlistModel.cpp
@@ -886,15 +886,26 @@ FilteredRoomlistModel::lessThan(const QModelIndex &left, const QModelIndex &righ
return a_importance > b_importance;
}
- // Now sort by recency
+ // Now sort by recency or room name
// Zero if empty, otherwise the time that the event occured
- uint64_t a_recency = sourceModel()->data(left_idx, RoomlistModel::Timestamp).toULongLong();
- uint64_t b_recency = sourceModel()->data(right_idx, RoomlistModel::Timestamp).toULongLong();
- if (a_recency != b_recency)
- return a_recency > b_recency;
- else
- return left.row() < right.row();
+ if (!this->sortByAlphabet) {
+ uint64_t a_order = sourceModel()->data(left_idx, RoomlistModel::Timestamp).toULongLong();
+ uint64_t b_order = sourceModel()->data(right_idx, RoomlistModel::Timestamp).toULongLong();
+
+ if (a_order != b_order)
+ return a_order > b_order;
+ } else {
+ QString a_order =
+ sourceModel()->data(left_idx, RoomlistModel::RoomName).toString().toLower();
+ QString b_order =
+ sourceModel()->data(right_idx, RoomlistModel::RoomName).toString().toLower();
+
+ if (a_order != b_order)
+ return a_order < b_order;
+ }
+
+ return left.row() < right.row();
}
FilteredRoomlistModel::FilteredRoomlistModel(RoomlistModel *model, QObject *parent)
@@ -902,17 +913,27 @@ FilteredRoomlistModel::FilteredRoomlistModel(RoomlistModel *model, QObject *pare
, roomlistmodel(model)
{
this->sortByImportance = UserSettings::instance()->sortByImportance();
+ this->sortByAlphabet = UserSettings::instance()->sortByAlphabet();
setSourceModel(model);
setDynamicSortFilter(true);
+ setSortCaseSensitivity(Qt::CaseInsensitive);
QObject::connect(UserSettings::instance().get(),
- &UserSettings::roomSortingChanged,
+ &UserSettings::roomSortingChangedImportance,
this,
[this](bool sortByImportance_) {
this->sortByImportance = sortByImportance_;
invalidate();
});
+ QObject::connect(UserSettings::instance().get(),
+ &UserSettings::roomSortingChangedAlphabetical,
+ this,
+ [this](bool sortByAlphabet_) {
+ this->sortByAlphabet = sortByAlphabet_;
+ invalidate();
+ });
+
connect(roomlistmodel,
&RoomlistModel::currentRoomChanged,
this,
diff --git a/src/timeline/RoomlistModel.h b/src/timeline/RoomlistModel.h
index cd1cdcaf..9aaafc06 100644
--- a/src/timeline/RoomlistModel.h
+++ b/src/timeline/RoomlistModel.h
@@ -230,6 +230,7 @@ private:
short int calculateImportance(const QModelIndex &idx) const;
RoomlistModel *roomlistmodel;
bool sortByImportance = true;
+ bool sortByAlphabet = false;
enum class FilterBy
{