Custom Room Sort Order
Add the ability to sort rooms by a custom set of parameters.
This commit is contained in:
@@ -3,6 +3,11 @@
|
||||
|
||||
#include "roomsortparameter.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "neochatconfig.h"
|
||||
#include "neochatroom.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
template<typename T>
|
||||
@@ -16,6 +21,78 @@ int typeCompare<QString>(QString left, QString right)
|
||||
{
|
||||
return left.localeAwareCompare(right);
|
||||
}
|
||||
|
||||
static const QList<RoomSortParameter::Parameter> allSortPriorities = {
|
||||
RoomSortParameter::AlphabeticalAscending,
|
||||
RoomSortParameter::AlphabeticalDescending,
|
||||
RoomSortParameter::HasUnread,
|
||||
RoomSortParameter::MostUnread,
|
||||
RoomSortParameter::HasHighlight,
|
||||
RoomSortParameter::MostHighlights,
|
||||
RoomSortParameter::LastActive,
|
||||
};
|
||||
|
||||
static const QList<RoomSortParameter::Parameter> alphabeticalSortPriorities = {
|
||||
RoomSortParameter::AlphabeticalAscending,
|
||||
};
|
||||
|
||||
static const QList<RoomSortParameter::Parameter> activitySortPriorities = {
|
||||
RoomSortParameter::HasHighlight,
|
||||
RoomSortParameter::MostHighlights,
|
||||
RoomSortParameter::HasUnread,
|
||||
RoomSortParameter::MostUnread,
|
||||
RoomSortParameter::LastActive,
|
||||
};
|
||||
|
||||
static const QList<RoomSortParameter::Parameter> lastMessageSortPriorities = {
|
||||
RoomSortParameter::LastActive,
|
||||
};
|
||||
}
|
||||
|
||||
QList<RoomSortParameter::Parameter> RoomSortParameter::allParameterList()
|
||||
{
|
||||
return allSortPriorities;
|
||||
}
|
||||
|
||||
QList<RoomSortParameter::Parameter> RoomSortParameter::currentParameterList()
|
||||
{
|
||||
QList<RoomSortParameter::Parameter> configParamList;
|
||||
switch (static_cast<NeoChatConfig::EnumSortOrder::type>(NeoChatConfig::sortOrder())) {
|
||||
case NeoChatConfig::EnumSortOrder::Activity:
|
||||
configParamList = activitySortPriorities;
|
||||
break;
|
||||
case NeoChatConfig::EnumSortOrder::Alphabetical:
|
||||
configParamList = alphabeticalSortPriorities;
|
||||
break;
|
||||
case NeoChatConfig::EnumSortOrder::LastMessage:
|
||||
configParamList = lastMessageSortPriorities;
|
||||
break;
|
||||
case NeoChatConfig::EnumSortOrder::Custom: {
|
||||
const auto intList = NeoChatConfig::customSortOrder();
|
||||
std::transform(intList.constBegin(), intList.constEnd(), std::back_inserter(configParamList), [](int param) {
|
||||
return static_cast<Parameter>(param);
|
||||
});
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (configParamList.isEmpty()) {
|
||||
return activitySortPriorities;
|
||||
}
|
||||
return configParamList;
|
||||
}
|
||||
|
||||
void RoomSortParameter::saveNewParameterList(const QList<Parameter> &newList)
|
||||
{
|
||||
QList<int> intList;
|
||||
std::transform(newList.constBegin(), newList.constEnd(), std::back_inserter(intList), [](Parameter param) {
|
||||
return static_cast<int>(param);
|
||||
});
|
||||
NeoChatConfig::setCustomSortOrder(intList);
|
||||
NeoChatConfig::setSortOrder(NeoChatConfig::EnumSortOrder::Custom);
|
||||
NeoChatConfig::self()->save();
|
||||
}
|
||||
|
||||
int RoomSortParameter::compareParameter(Parameter parameter, NeoChatRoom *leftRoom, NeoChatRoom *rightRoom)
|
||||
@@ -36,7 +113,7 @@ int RoomSortParameter::compareParameter(Parameter parameter, NeoChatRoom *leftRo
|
||||
case LastActive:
|
||||
return compareParameter<LastActive>(leftRoom, rightRoom);
|
||||
default:
|
||||
return false;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,12 +3,13 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "neochatroom.h"
|
||||
#include <QObject>
|
||||
#include <QQmlEngine>
|
||||
|
||||
#include <KLocalizedString>
|
||||
|
||||
class NeoChatRoom;
|
||||
|
||||
/**
|
||||
* @class RoomSortParameter
|
||||
*
|
||||
@@ -23,15 +24,19 @@ class RoomSortParameter : public QObject
|
||||
public:
|
||||
/**
|
||||
* @brief Defines the available sort parameters.
|
||||
*
|
||||
* @note All values are specifically numbered as they should never change even
|
||||
* if new options are later added. This is because they are stored in
|
||||
* the config as ints and changing would break someones config on upgrade.
|
||||
*/
|
||||
enum Parameter {
|
||||
AlphabeticalAscending,
|
||||
AlphabeticalDescending,
|
||||
HasUnread,
|
||||
MostUnread,
|
||||
HasHighlight,
|
||||
MostHighlights,
|
||||
LastActive,
|
||||
AlphabeticalAscending = 0,
|
||||
AlphabeticalDescending = 1,
|
||||
HasUnread = 2,
|
||||
MostUnread = 3,
|
||||
HasHighlight = 4,
|
||||
MostHighlights = 5,
|
||||
LastActive = 6,
|
||||
};
|
||||
Q_ENUM(Parameter)
|
||||
|
||||
@@ -40,7 +45,7 @@ public:
|
||||
*
|
||||
* @sa Parameter
|
||||
*/
|
||||
static QString parameterName(Parameter parameter)
|
||||
Q_INVOKABLE static QString parameterName(Parameter parameter)
|
||||
{
|
||||
switch (parameter) {
|
||||
case Parameter::AlphabeticalAscending:
|
||||
@@ -67,7 +72,7 @@ public:
|
||||
*
|
||||
* @sa Parameter
|
||||
*/
|
||||
static QString parameterDescription(Parameter parameter)
|
||||
Q_INVOKABLE static QString parameterDescription(Parameter parameter)
|
||||
{
|
||||
switch (parameter) {
|
||||
case Parameter::AlphabeticalAscending:
|
||||
@@ -89,6 +94,21 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief List of all available Parameter sort orders.
|
||||
*/
|
||||
static QList<Parameter> allParameterList();
|
||||
|
||||
/**
|
||||
* @brief The current Parameter sort order list.
|
||||
*/
|
||||
static QList<Parameter> currentParameterList();
|
||||
|
||||
/**
|
||||
* @brief Save the give Parameter sort order list as the custom sort order.
|
||||
*/
|
||||
static void saveNewParameterList(const QList<Parameter> &newList);
|
||||
|
||||
/**
|
||||
* @brief Compare the given parameter of the two given rooms.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user