File indexing completed on 2024-06-09 04:58:55
0001 /* 0002 SPDX-FileCopyrightText: 2022-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "generalsettingswidget.h" 0008 0009 #include <KLocalizedString> 0010 0011 #include <QCheckBox> 0012 #include <QComboBox> 0013 #include <QFormLayout> 0014 #include <QLabel> 0015 #include <QLineEdit> 0016 #include <QSpinBox> 0017 0018 GeneralSettingsWidget::GeneralSettingsWidget(RocketChatAccount *account, QWidget *parent) 0019 : SettingsWidgetBase(account, parent) 0020 , mEnableFavoriteRooms(new QCheckBox(i18n("Enable Favorite Rooms"), this)) 0021 , mSiteUrl(new QLineEdit(this)) 0022 , mSiteName(new QLineEdit(this)) 0023 , mUTF8UsernamesValidation(new QLineEdit(this)) 0024 , mUTF8ChannelNamesValidation(new QLineEdit(this)) 0025 , mUTF8NamesSlugify(new QCheckBox(i18n("UTF8 Names Slugify"), this)) 0026 , mFirstChannelAfterLogin(new QLineEdit(this)) 0027 , mDeepLinkUrl(new QLineEdit(this)) 0028 , mCDNPrefix(new QLineEdit(this)) 0029 , mUnreadCount(new QComboBox(this)) 0030 , mUnreadCountDirectMessages(new QComboBox(this)) 0031 , mEnableUpdateChecker(new QCheckBox(i18n("Enable the Update Checker"), this)) 0032 , mDefaultTimeZone(new QComboBox(this)) 0033 , mSendStatisticsRocketChat(new QCheckBox(i18n("Send Statistics to Rocket.Chat"), this)) 0034 , mMaxRoomMembersDisablingMessageNotifications(new QSpinBox(this)) 0035 , mUpdateLatestAvailableVersion(new QLineEdit(this)) 0036 , mStreamCastAddress(new QLineEdit(this)) 0037 { 0038 mEnableFavoriteRooms->setObjectName(QStringLiteral("mEnableFavoriteRooms")); 0039 mMainLayout->addWidget(mEnableFavoriteRooms); 0040 connectCheckBox(mEnableFavoriteRooms, QStringLiteral("Favorite_Rooms")); 0041 0042 mSiteUrl->setObjectName(QStringLiteral("mSiteUrl")); 0043 addLineEdit(i18n("Site URL"), mSiteUrl, QStringLiteral("Site_Url")); 0044 0045 mSiteName->setObjectName(QStringLiteral("mSiteName")); 0046 addLineEdit(i18n("Site Name"), mSiteName, QStringLiteral("Site_Name")); 0047 0048 auto utf8Label = createBoldLabel(i18n("UTF8")); 0049 utf8Label->setObjectName(QStringLiteral("utf8Label")); 0050 mMainLayout->addWidget(utf8Label); 0051 0052 mUTF8UsernamesValidation->setObjectName(QStringLiteral("mUTF8UsernamesValidation")); 0053 mUTF8UsernamesValidation->setToolTip(i18n("RegExp that will be used to validate usernames")); 0054 addLineEdit(i18n("UTF8 Usernames Validation"), mUTF8UsernamesValidation, QStringLiteral("UTF8_User_Names_Validation")); 0055 0056 mUTF8ChannelNamesValidation->setObjectName(QStringLiteral("mUTF8ChannelNamesValidation")); 0057 mUTF8ChannelNamesValidation->setToolTip(i18n("RegExp that will be used to validate channel names")); 0058 addLineEdit(i18n("UTF8 Channel Names Validation"), mUTF8ChannelNamesValidation, QStringLiteral("UTF8_Channel_Names_Validation")); 0059 0060 mUTF8NamesSlugify->setObjectName(QStringLiteral("mUTF8NamesSlugify")); 0061 mMainLayout->addWidget(mUTF8NamesSlugify); 0062 connectCheckBox(mUTF8NamesSlugify, QStringLiteral("UTF8_Names_Slugify")); 0063 0064 mFirstChannelAfterLogin->setObjectName(QStringLiteral("mFirstChannelAfterLogin")); 0065 addLineEdit(i18n("First Channel After Login"), mFirstChannelAfterLogin, QStringLiteral("First_Channel_After_Login")); 0066 0067 mDeepLinkUrl->setObjectName(QStringLiteral("mDeepLinkUrl")); 0068 addLineEdit(i18n("Deep Link Url"), mDeepLinkUrl, QStringLiteral("DeepLink_Url")); 0069 0070 mCDNPrefix->setObjectName(QStringLiteral("mCDNPrefix")); 0071 addLineEdit(i18n("CDN Prefix"), mCDNPrefix, QStringLiteral("CDN_PREFIX")); 0072 0073 mUnreadCount->setObjectName(QStringLiteral("mUnreadCount")); 0074 QMap<QString, QString> maps; 0075 maps = { 0076 {QStringLiteral("all_messages"), i18n("All messages")}, 0077 {QStringLiteral("user_mentions_only"), i18n("User mentions only")}, 0078 {QStringLiteral("group_mentions_only"), i18n("Group mentions only")}, 0079 {QStringLiteral("user_and_group_mentions_only"), i18n("User and group mentions only")}, 0080 }; 0081 addComboBox(i18n("Unread Count"), maps, mUnreadCount, QStringLiteral("Unread_Count")); 0082 0083 mUnreadCountDirectMessages->setObjectName(QStringLiteral("mUnreadCountDirectMessages")); 0084 maps = { 0085 {QStringLiteral("all_messages"), i18n("All messages")}, 0086 {QStringLiteral("mentions_only"), i18n("Mentions only")}, 0087 }; 0088 addComboBox(i18n("Unread Count for Direct Messages"), maps, mUnreadCountDirectMessages, QStringLiteral("Unread_Count_DM")); 0089 0090 auto updateLabel = createBoldLabel(i18n("Update")); 0091 updateLabel->setObjectName(QStringLiteral("updateLabel")); 0092 mMainLayout->addWidget(updateLabel); 0093 0094 mUpdateLatestAvailableVersion->setObjectName(QStringLiteral("mUpdateLatestAvailableVersion")); 0095 addLineEdit(i18n("Update Latest Available Version"), mUpdateLatestAvailableVersion, QStringLiteral("Update_LatestAvailableVersion"), true); 0096 0097 mEnableUpdateChecker->setObjectName(QStringLiteral("mEnableUpdateChecker")); 0098 mMainLayout->addWidget(mEnableUpdateChecker); 0099 connectCheckBox(mEnableUpdateChecker, QStringLiteral("Update_EnableChecker")); 0100 mEnableUpdateChecker->setToolTip( 0101 i18n("Checks automatically for new updates / important messages from the Rocket.Chat developers and receives notifications when available.\n" 0102 "The notification appears once per new version as a clickable banner and as a message from the Rocket.Cat bot,\n" 0103 "both visible only for administrators.")); 0104 0105 auto timeZoneLabel = createBoldLabel(i18n("TimeZone")); 0106 timeZoneLabel->setObjectName(QStringLiteral("timeZoneLabel")); 0107 mMainLayout->addWidget(timeZoneLabel); 0108 0109 mDefaultTimeZone->setObjectName(QStringLiteral("mDefaultTimeZone")); 0110 mDefaultTimeZone->setToolTip(i18n("Sets the default timezone that will be used when showing dashboards or sending emails")); 0111 maps = { 0112 {QStringLiteral("server"), i18n("Server Timezone")}, 0113 {QStringLiteral("custom"), i18n("Custom Timezone")}, 0114 {QStringLiteral("user"), i18n("User's current Timezone")}, 0115 }; 0116 addComboBox(i18n("Default timezone for reporting"), maps, mDefaultTimeZone, QStringLiteral("Default_Timezone_For_Reporting")); 0117 // TODO add custom time zone 0118 0119 auto reportingLabel = createBoldLabel(i18n("Reporting")); 0120 reportingLabel->setObjectName(QStringLiteral("reportingLabel")); 0121 mMainLayout->addWidget(reportingLabel); 0122 0123 mSendStatisticsRocketChat->setObjectName(QStringLiteral("mSendStatisticsRocketChat")); 0124 mMainLayout->addWidget(mSendStatisticsRocketChat); 0125 connectCheckBox(mSendStatisticsRocketChat, QStringLiteral("Statistics_reporting")); 0126 0127 auto notificationLabel = createBoldLabel(i18n("Notifications")); 0128 notificationLabel->setObjectName(QStringLiteral("notificationLabel")); 0129 mMainLayout->addWidget(notificationLabel); 0130 0131 mMaxRoomMembersDisablingMessageNotifications->setObjectName(QStringLiteral("mMaxRoomMembersDisablingMessageNotifications")); 0132 mMaxRoomMembersDisablingMessageNotifications->setToolTip( 0133 i18n("Max number of members in room when notifications for all messages gets disabled. Users can still change per room setting to receive all " 0134 "notifications on an individual basis. (0 to disable)")); 0135 mMaxRoomMembersDisablingMessageNotifications->setMaximum(999); 0136 addSpinbox(i18n("Max Room Members Before Disabling All Message Notifications"), 0137 mMaxRoomMembersDisablingMessageNotifications, 0138 QStringLiteral("Notifications_Max_Room_Members")); 0139 0140 auto streamCastLabel = createBoldLabel(i18n("Stream Cast")); 0141 streamCastLabel->setObjectName(QStringLiteral("streamCastLabel")); 0142 mMainLayout->addWidget(streamCastLabel); 0143 0144 mStreamCastAddress->setObjectName(QStringLiteral("mStreamCastAddress")); 0145 addLineEdit(i18n("Stream Cast Address"), mStreamCastAddress, QStringLiteral("Stream_Cast_Address")); 0146 mStreamCastAddress->setToolTip(i18n("IP or Host of your Rocket.Chat central Stream Cast. E.g. 192.168.1.1:3000 or localhost:4000")); 0147 } 0148 0149 GeneralSettingsWidget::~GeneralSettingsWidget() = default; 0150 0151 void GeneralSettingsWidget::initialize(const QMap<QString, QVariant> &mapSettings) 0152 { 0153 initializeWidget(mEnableFavoriteRooms, mapSettings, true); 0154 initializeWidget(mSiteUrl, mapSettings, QString()); 0155 initializeWidget(mSiteName, mapSettings, QString()); 0156 initializeWidget(mUTF8UsernamesValidation, mapSettings, QStringLiteral("[0-9a-zA-Z-_.]+")); 0157 initializeWidget(mUTF8ChannelNamesValidation, mapSettings, QStringLiteral("[0-9a-zA-Z-_.]+")); 0158 initializeWidget(mFirstChannelAfterLogin, mapSettings); 0159 initializeWidget(mDeepLinkUrl, mapSettings, QStringLiteral("https://go.rocket.chat")); 0160 initializeWidget(mCDNPrefix, mapSettings, QString()); 0161 initializeWidget(mUnreadCount, mapSettings, QStringLiteral("user_and_group_mentions_only")); 0162 initializeWidget(mUnreadCountDirectMessages, mapSettings, QStringLiteral("all_messages")); 0163 initializeWidget(mEnableUpdateChecker, mapSettings, true); 0164 initializeWidget(mDefaultTimeZone, mapSettings, QStringLiteral("server")); 0165 initializeWidget(mUTF8NamesSlugify, mapSettings, true); 0166 initializeWidget(mSendStatisticsRocketChat, mapSettings, true); 0167 initializeWidget(mMaxRoomMembersDisablingMessageNotifications, mapSettings, 100); 0168 initializeWidget(mUpdateLatestAvailableVersion, mapSettings, QStringLiteral("0.0.0")); 0169 initializeWidget(mStreamCastAddress, mapSettings, QString()); 0170 } 0171 0172 #include "moc_generalsettingswidget.cpp"