File indexing completed on 2024-03-03 15:47:11

0001 /*
0002    SPDX-FileCopyrightText: 2020-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "ownuserpreferences.h"
0008 
0009 #include <QJsonArray>
0010 #include <QJsonObject>
0011 
0012 OwnUserPreferences::OwnUserPreferences() = default;
0013 
0014 OwnUserPreferences::~OwnUserPreferences() = default;
0015 
0016 void OwnUserPreferences::parsePreferences(const QJsonObject &replyObject)
0017 {
0018     // qDebug() << " replyObject " << replyObject;
0019     const QJsonArray highlightsArray = replyObject.value(QLatin1String("highlights")).toArray();
0020     QStringList lstHighlightsWord;
0021     const int highlightsWordArrayCount = highlightsArray.count();
0022     lstHighlightsWord.reserve(highlightsWordArrayCount);
0023     for (int i = 0; i < highlightsWordArrayCount; ++i) {
0024         lstHighlightsWord << highlightsArray.at(i).toString();
0025     }
0026     setHighlightWords(lstHighlightsWord);
0027     setEmailNotificationMode(replyObject.value(QLatin1String("emailNotificationMode")).toString());
0028     setDesktopNotifications(replyObject.value(QLatin1String("desktopNotifications")).toString());
0029     setPushNotifications(replyObject.value(QLatin1String("pushNotifications")).toString());
0030     setConvertAsciiEmoji(replyObject.value(QLatin1String("convertAsciiEmoji")).toBool(true));
0031     setUseEmojis(replyObject.value(QLatin1String("useEmojis")).toBool(true));
0032     setHideRoles(replyObject.value(QLatin1String("hideRoles")).toBool(false));
0033     setDisplayAvatars(replyObject.value(QLatin1String("displayAvatars")).toBool(true));
0034     setIdleTimeLimit(replyObject.value(QLatin1String("idleTimeLimit")).toInt(-1));
0035     setEnableAutoAway(replyObject.value(QLatin1String("enableAutoAway")).toBool(false));
0036     setShowUnread(replyObject.value(QLatin1String("sidebarShowUnread")).toBool(false));
0037     const QString sidebarSortBy = replyObject.value(QLatin1String("sidebarSortby")).toString();
0038     if (sidebarSortBy == QLatin1String("activity")) {
0039         setRoomListSortOrder(OwnUserPreferences::RoomListSortOrder::ByLastMessage);
0040     } else if (sidebarSortBy == QLatin1String("alphabetical")) {
0041         setRoomListSortOrder(OwnUserPreferences::RoomListSortOrder::Alphabetically);
0042     }
0043     setShowRoomAvatar(replyObject.value(QLatin1String("sidebarDisplayAvatar")).toBool(false));
0044     setShowFavorite(replyObject.value(QLatin1String("sidebarShowFavorites")).toBool(false));
0045     setReceiveLoginDetectionEmail(replyObject.value(QLatin1String("receiveLoginDetectionEmail")).toBool(true));
0046 
0047     qDebug() << " replyObject " << replyObject;
0048 }
0049 
0050 bool OwnUserPreferences::operator==(const OwnUserPreferences &other) const
0051 {
0052     return mHighlightWords == other.highlightWords() && mEmailNotificationMode == other.emailNotificationMode()
0053         && mDesktopNotifications == other.desktopNotifications() && mUseEmojis == other.useEmojis() && mConvertAsciiEmoji == other.convertAsciiEmoji()
0054         && mHideRoles == other.hideRoles() && mDisplayAvatars == other.displayAvatars() && mIdleTimeLimit == other.idleTimeLimit()
0055         && mEnableAutoAway == other.enableAutoAway() && mPushNotifications == other.pushNotifications() && mShowUnread == other.showUnread()
0056         && mShowRoomAvatar == other.showRoomAvatar() && mShowFavorite == other.showFavorite() && mRoomListSortOrder == other.roomListSortOrder()
0057         && mReceiveLoginDetectionEmail == other.receiveLoginDetectionEmail();
0058 }
0059 
0060 QStringList OwnUserPreferences::highlightWords() const
0061 {
0062     return mHighlightWords;
0063 }
0064 
0065 void OwnUserPreferences::updateHighlightWords(const QJsonArray &highlightsArray)
0066 {
0067     QStringList lstHighlightsWord;
0068     const int highlightsWordArrayCount = highlightsArray.count();
0069     lstHighlightsWord.reserve(highlightsWordArrayCount);
0070     for (int i = 0; i < highlightsWordArrayCount; ++i) {
0071         lstHighlightsWord << highlightsArray.at(i).toString();
0072     }
0073     setHighlightWords(lstHighlightsWord);
0074 }
0075 
0076 void OwnUserPreferences::setHighlightWords(const QStringList &highlightWords)
0077 {
0078     mHighlightWords = highlightWords;
0079 }
0080 
0081 QString OwnUserPreferences::emailNotificationMode() const
0082 {
0083     return mEmailNotificationMode;
0084 }
0085 
0086 void OwnUserPreferences::setEmailNotificationMode(const QString &emailNotificationMode)
0087 {
0088     mEmailNotificationMode = emailNotificationMode;
0089 }
0090 
0091 QString OwnUserPreferences::desktopNotifications() const
0092 {
0093     return mDesktopNotifications;
0094 }
0095 
0096 void OwnUserPreferences::setDesktopNotifications(const QString &desktopNotifications)
0097 {
0098     mDesktopNotifications = desktopNotifications;
0099 }
0100 
0101 void OwnUserPreferences::setPushNotifications(const QString &pushNotifications)
0102 {
0103     mPushNotifications = pushNotifications;
0104 }
0105 
0106 QString OwnUserPreferences::pushNotifications() const
0107 {
0108     return mPushNotifications;
0109 }
0110 
0111 bool OwnUserPreferences::showUnread() const
0112 {
0113     return mShowUnread;
0114 }
0115 
0116 void OwnUserPreferences::setShowUnread(bool newShowUnread)
0117 {
0118     mShowUnread = newShowUnread;
0119 }
0120 
0121 OwnUserPreferences::RoomListSortOrder OwnUserPreferences::roomListSortOrder() const
0122 {
0123     return mRoomListSortOrder;
0124 }
0125 
0126 void OwnUserPreferences::setRoomListSortOrder(OwnUserPreferences::RoomListSortOrder roomListSortOrder)
0127 {
0128     mRoomListSortOrder = roomListSortOrder;
0129 }
0130 
0131 bool OwnUserPreferences::showRoomAvatar() const
0132 {
0133     return mShowRoomAvatar;
0134 }
0135 
0136 void OwnUserPreferences::setShowRoomAvatar(bool newShowRoomAvatar)
0137 {
0138     mShowRoomAvatar = newShowRoomAvatar;
0139 }
0140 
0141 bool OwnUserPreferences::showFavorite() const
0142 {
0143     return mShowFavorite;
0144 }
0145 
0146 void OwnUserPreferences::setShowFavorite(bool newShowFavorite)
0147 {
0148     mShowFavorite = newShowFavorite;
0149 }
0150 
0151 bool OwnUserPreferences::receiveLoginDetectionEmail() const
0152 {
0153     return mReceiveLoginDetectionEmail;
0154 }
0155 
0156 void OwnUserPreferences::setReceiveLoginDetectionEmail(bool newReceiveLoginDetectionEmail)
0157 {
0158     mReceiveLoginDetectionEmail = newReceiveLoginDetectionEmail;
0159 }
0160 
0161 bool OwnUserPreferences::convertAsciiEmoji() const
0162 {
0163     return mConvertAsciiEmoji;
0164 }
0165 
0166 void OwnUserPreferences::setConvertAsciiEmoji(bool convertAsciiEmoji)
0167 {
0168     mConvertAsciiEmoji = convertAsciiEmoji;
0169 }
0170 
0171 bool OwnUserPreferences::useEmojis() const
0172 {
0173     return mUseEmojis;
0174 }
0175 
0176 void OwnUserPreferences::setUseEmojis(bool useEmojis)
0177 {
0178     mUseEmojis = useEmojis;
0179 }
0180 
0181 bool OwnUserPreferences::hideRoles() const
0182 {
0183     return mHideRoles;
0184 }
0185 
0186 void OwnUserPreferences::setHideRoles(bool hideRoles)
0187 {
0188     mHideRoles = hideRoles;
0189 }
0190 
0191 bool OwnUserPreferences::displayAvatars() const
0192 {
0193     return mDisplayAvatars;
0194 }
0195 
0196 void OwnUserPreferences::setDisplayAvatars(bool hideAvatars)
0197 {
0198     mDisplayAvatars = hideAvatars;
0199 }
0200 
0201 int OwnUserPreferences::idleTimeLimit() const
0202 {
0203     return mIdleTimeLimit;
0204 }
0205 
0206 void OwnUserPreferences::setIdleTimeLimit(int newIdleTimeLimit)
0207 {
0208     mIdleTimeLimit = newIdleTimeLimit;
0209 }
0210 
0211 bool OwnUserPreferences::enableAutoAway() const
0212 {
0213     return mEnableAutoAway;
0214 }
0215 
0216 void OwnUserPreferences::setEnableAutoAway(bool newEnableAutoAway)
0217 {
0218     mEnableAutoAway = newEnableAutoAway;
0219 }
0220 
0221 QDebug operator<<(QDebug d, const OwnUserPreferences &t)
0222 {
0223     d << "mHighlightWords " << t.highlightWords();
0224     d << "mEmailNotificationMode " << t.emailNotificationMode();
0225     d << "mDesktopNotifications " << t.desktopNotifications();
0226     d << "mUseEmojis " << t.useEmojis();
0227     d << "mConvertAsciiEmoji " << t.convertAsciiEmoji();
0228     d << "mHideRoles " << t.hideRoles();
0229     d << "mDisplayAvatars " << t.displayAvatars();
0230     d << "mIdleTimeLimit " << t.idleTimeLimit();
0231     d << "mEnableAutoAway " << t.enableAutoAway();
0232     d << "mPushNotifications " << t.pushNotifications();
0233     d << "mShowUnread " << t.showUnread();
0234     d << "mRoomListSortOrder " << t.roomListSortOrder();
0235     d << "mShowRoomAvatar " << t.showRoomAvatar();
0236     d << "mShowFavorite " << t.showFavorite();
0237     d << "mReceiveLoginDetectionEmail " << t.receiveLoginDetectionEmail();
0238     return d;
0239 }
0240 
0241 #include "moc_ownuserpreferences.cpp"