File indexing completed on 2024-12-22 04:45:43
0001 /* 0002 SPDX-FileCopyrightText: 2022-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 #include "messagesettingswidget.h" 0007 #include <QCheckBox> 0008 #include <QFormLayout> 0009 0010 #include <KLocalizedString> 0011 #include <QComboBox> 0012 #include <QLabel> 0013 #include <QLineEdit> 0014 #include <QSpinBox> 0015 0016 MessageSettingsWidget::MessageSettingsWidget(RocketChatAccount *account, QWidget *parent) 0017 : SettingsWidgetBase{account, parent} 0018 , mAllowMessageEditing(new QCheckBox(i18n("Allow Message Editing"), this)) 0019 , mAllowMessageDeleting(new QCheckBox(i18n("Allow Message Deleting"), this)) 0020 , mShowEditedStatus(new QCheckBox(i18n("Show Edited Status"), this)) 0021 , mShowDeletedStatus(new QCheckBox(i18n("Show Deleted Status"), this)) 0022 , mAllowMessagePinning(new QCheckBox(i18n("Allow Message Pinning"), this)) 0023 , mAllowMessageSnippeting(new QCheckBox(i18n("Allow Message Snippeting"), this)) 0024 , mAllowConvertingLongMessageAttachment(new QCheckBox(i18n("Allow converting long messages to attachment"), this)) 0025 , mVideoRecorderEnabled(new QCheckBox(i18n("Video Recorder Enabled"), this)) 0026 , mBlockMessageEditingAfterMinutes(new QSpinBox(this)) 0027 , mBlockMessageDeletingAfterMinutes(new QSpinBox(this)) 0028 , mMaximumAllowedCharactersPerMessage(new QSpinBox(this)) 0029 , mSafePort(new QLineEdit(this)) 0030 , mRemoveEXIFMetadata(new QCheckBox(i18n("Remove EXIF metadata from supported files"), this)) 0031 , mEnableImageThumbnails(new QCheckBox(i18n("Enable image thumbnails to save bandwidth"), this)) 0032 , mThumbnailMaxWidth(new QSpinBox(this)) 0033 , mThumbnailMaxHeight(new QSpinBox(this)) 0034 , mAudioRecorderEnabled(new QCheckBox(i18n("Audio Recorder Enabled"), this)) 0035 , mAudioMessageBitRate(new QSpinBox(this)) 0036 , mAutoTranslateEnabled(new QCheckBox(i18n("Enable Auto-Translate"), this)) 0037 , mAutoTranslateServiceProvider(new QComboBox(this)) 0038 , mDeeplApiKey(new QLineEdit(this)) 0039 , mGoogleApiKey(new QLineEdit(this)) 0040 , mMicrosoftApiKey(new QLineEdit(this)) 0041 , mGroupingPeriod(new QSpinBox(this)) 0042 , mDirectMessageMaxUsers(new QSpinBox(this)) 0043 , mMaximumNumberChainedQuotes(new QSpinBox(this)) 0044 , mMessageErasureType(new QComboBox(this)) 0045 , mApiEmbed(new QCheckBox(i18n("Embed Link Previews"), this)) 0046 , mEmbedCacheExpirationDays(new QSpinBox(this)) 0047 { 0048 mAllowMessageEditing->setObjectName(QStringLiteral("mAllowMessageEditing")); 0049 mMainLayout->addWidget(mAllowMessageEditing); 0050 connectCheckBox(mAllowMessageEditing, QStringLiteral("Message_AllowEditing")); 0051 0052 mBlockMessageEditingAfterMinutes->setObjectName(QStringLiteral("mBlockMessageEditingAfterMinutes")); 0053 mBlockMessageEditingAfterMinutes->setToolTip(i18n("Enter 0 to disable blocking.")); 0054 addSpinbox(i18n("Block Message Editing After (n) Minutes"), mBlockMessageEditingAfterMinutes, QStringLiteral("Message_AllowEditing_BlockEditInMinutes")); 0055 0056 mAllowMessageDeleting->setObjectName(QStringLiteral("mAllowMessageDeleting")); 0057 mMainLayout->addWidget(mAllowMessageDeleting); 0058 connectCheckBox(mAllowMessageDeleting, QStringLiteral("Message_AllowDeleting")); 0059 0060 mBlockMessageDeletingAfterMinutes->setObjectName(QStringLiteral("mBlockMessageDeletingAfterMinutes")); 0061 mBlockMessageDeletingAfterMinutes->setToolTip(i18n("Block Message Deleting After (n) Minutes.")); 0062 addSpinbox(i18n("Block Message Deleting After (n) Minutes"), 0063 mBlockMessageDeletingAfterMinutes, 0064 QStringLiteral("Message_AllowDeleting_BlockDeleteInMinutes")); 0065 0066 mShowEditedStatus->setObjectName(QStringLiteral("mShowEditedStatus")); 0067 mShowEditedStatus->setToolTip(i18n("This is a deprecated feature. It may not work as expected and will not get new updates.")); 0068 mMainLayout->addWidget(mShowEditedStatus); 0069 connectCheckBox(mShowEditedStatus, QStringLiteral("Message_ShowEditedStatus")); 0070 0071 mShowDeletedStatus->setObjectName(QStringLiteral("mShowDeletedStatus")); 0072 mMainLayout->addWidget(mShowDeletedStatus); 0073 connectCheckBox(mShowDeletedStatus, QStringLiteral("Message_ShowDeletedStatus")); 0074 0075 mAllowMessagePinning->setObjectName(QStringLiteral("mAllowMessagePinning")); 0076 mAllowMessagePinning->setToolTip(i18n("Allow Message Pinning")); 0077 mMainLayout->addWidget(mAllowMessagePinning); 0078 connectCheckBox(mAllowMessagePinning, QStringLiteral("Message_AllowPinning")); 0079 0080 mAllowMessageSnippeting->setObjectName(QStringLiteral("mAllowMessageSnippeting")); 0081 mMainLayout->addWidget(mAllowMessageSnippeting); 0082 connectCheckBox(mAllowMessageSnippeting, QStringLiteral("Message_AllowSnippeting")); 0083 0084 mAllowConvertingLongMessageAttachment->setObjectName(QStringLiteral("mAllowConvertingLongMessageAttachment")); 0085 mMainLayout->addWidget(mAllowConvertingLongMessageAttachment); 0086 connectCheckBox(mAllowConvertingLongMessageAttachment, QStringLiteral("Message_AllowConvertLongMessagesToAttachment")); 0087 0088 mVideoRecorderEnabled->setObjectName(QStringLiteral("mVideoRecorderEnabled")); 0089 mVideoRecorderEnabled->setToolTip(i18n("Requires 'video/webm' files to be an accepted media type within 'File Upload' settings.")); 0090 mMainLayout->addWidget(mVideoRecorderEnabled); 0091 connectCheckBox(mVideoRecorderEnabled, QStringLiteral("Message_VideoRecorderEnabled")); 0092 0093 mMaximumAllowedCharactersPerMessage->setObjectName(QStringLiteral("mMaximumAllowedCharactersPerMessage")); 0094 mMaximumAllowedCharactersPerMessage->setMaximum(99999); 0095 addSpinbox(i18n("Maximum Allowed Characters Per Message"), mMaximumAllowedCharactersPerMessage, QStringLiteral("Message_MaxAllowedSize")); 0096 0097 mSafePort->setObjectName(QStringLiteral("mSafePort")); 0098 addLineEdit(i18n("Safe Ports"), mSafePort, QStringLiteral("API_EmbedSafePorts")); 0099 0100 mMaximumNumberChainedQuotes->setObjectName(QStringLiteral("mMaximumNumberChainedQuotes")); 0101 addSpinbox(i18n("Maximum Number of Chained Quotes"), mMaximumNumberChainedQuotes, QStringLiteral("Message_QuoteChainLimit")); 0102 0103 mMessageErasureType->setObjectName(QStringLiteral("mMessageErasureType")); 0104 const QMap<QString, QString> messageErasureTypeMaps = { 0105 {QStringLiteral("Keep"), i18n("Keep Messages and User Name")}, 0106 {QStringLiteral("Delete"), i18n("Delete All Messages")}, 0107 {QStringLiteral("Unlink"), i18n("Remove Link Between User and Messages")}, 0108 }; 0109 mMessageErasureType->setToolTip( 0110 i18n("Determine what to do with messages of users who remove their account. Keep Messages and User Name: The message and files history of the user " 0111 "will be deleted from Direct Messages and will be kept in other rooms. Delete All Messages: All messages and files from the user will be deleted " 0112 "from the database and it will not be possible to locate the user anymore. Remove link between user and messages: This option will assign all " 0113 "messages and files of the user to Rocket.Chat bot and Direct Messages are going to be deleted.")); 0114 addComboBox(i18n("Message Erasure Type"), messageErasureTypeMaps, mMessageErasureType, QStringLiteral("Message_ErasureType")); 0115 0116 mGroupingPeriod->setObjectName(QStringLiteral("mGroupingPeriod")); 0117 mGroupingPeriod->setToolTip( 0118 i18n("Messages will be grouped with previous message if both are from the same user and the elapsed time was less than the informed time in seconds.")); 0119 addSpinbox(i18n("Grouping Period (in seconds)"), mGroupingPeriod, QStringLiteral("Message_GroupingPeriod")); 0120 0121 mDirectMessageMaxUsers->setObjectName(QStringLiteral("mDirectMessageMaxUsers")); 0122 // Typo in RC => 3 "s" 0123 addSpinbox(i18n("Direct Message Maximum Users"), mDirectMessageMaxUsers, QStringLiteral("DirectMesssage_maxUsers")); 0124 0125 auto messageAttachmentsLabel = createBoldLabel(i18n("Message Attachments")); 0126 messageAttachmentsLabel->setObjectName(QStringLiteral("messageAttachmentsLabel")); 0127 mMainLayout->addWidget(messageAttachmentsLabel); 0128 0129 mRemoveEXIFMetadata->setObjectName(QStringLiteral("mRemoveEXIFMetadata")); 0130 mRemoveEXIFMetadata->setToolTip(i18n( 0131 "Strips out EXIF metadata from image files (jpeg, tiff, etc). This setting is not retroactive, so files uploaded while disabled will have EXIF data")); 0132 mMainLayout->addWidget(mRemoveEXIFMetadata); 0133 connectCheckBox(mRemoveEXIFMetadata, QStringLiteral("Message_Attachments_Strip_Exif")); 0134 0135 mEnableImageThumbnails->setObjectName(QStringLiteral("mEnableImageThumbnails")); 0136 mEnableImageThumbnails->setToolTip(i18n( 0137 "Thumbnails will be served instead of the original image to reduce bandwidth usage. Images at original resolution can be downloaded using the icon " 0138 "next to the attachment's name.")); 0139 mMainLayout->addWidget(mEnableImageThumbnails); 0140 connectCheckBox(mEnableImageThumbnails, QStringLiteral("Message_Attachments_Thumbnails_Enabled")); 0141 0142 mThumbnailMaxWidth->setObjectName(QStringLiteral("mThumbnailMaxWidth")); 0143 addSpinbox(i18n("Thumbnail's max width (in pixels)"), mThumbnailMaxWidth, QStringLiteral("Message_Attachments_Thumbnails_Width")); 0144 0145 mThumbnailMaxHeight->setObjectName(QStringLiteral("mThumbnailMaxHeight")); 0146 addSpinbox(i18n("Thumbnail's max height (in pixels)"), mThumbnailMaxHeight, QStringLiteral("Message_Attachments_Thumbnails_Height")); 0147 0148 auto audioMessageLabel = createBoldLabel(i18n("Audio Message")); 0149 audioMessageLabel->setObjectName(QStringLiteral("audioMessageLabel")); 0150 mMainLayout->addWidget(audioMessageLabel); 0151 0152 mAudioRecorderEnabled->setObjectName(QStringLiteral("mAudioRecorderEnabled")); 0153 mMainLayout->addWidget(mAudioRecorderEnabled); 0154 connectCheckBox(mAudioRecorderEnabled, QStringLiteral("Message_AudioRecorderEnabled")); 0155 0156 mAudioMessageBitRate->setObjectName(QStringLiteral("mAudioMessageBitRate")); 0157 mAudioMessageBitRate->setMaximum(1000); 0158 addSpinbox(i18n("Audio Message Bit Rate"), mAudioMessageBitRate, QStringLiteral("Message_Audio_bitRate")); 0159 0160 auto autoTranslateLabel = createBoldLabel(i18n("Auto-Translate")); 0161 autoTranslateLabel->setObjectName(QStringLiteral("autoTranslateLabel")); 0162 mMainLayout->addWidget(autoTranslateLabel); 0163 0164 mAutoTranslateEnabled->setObjectName(QStringLiteral("mAutoTranslateEnabled")); 0165 mMainLayout->addWidget(mAutoTranslateEnabled); 0166 connectCheckBox(mAutoTranslateEnabled, QStringLiteral("AutoTranslate_Enabled")); 0167 0168 mAutoTranslateServiceProvider->setObjectName(QStringLiteral("mAutoTranslateServiceProvider")); 0169 const QMap<QString, QString> maps = { 0170 {QStringLiteral("google-translate"), i18n("Google")}, 0171 {QStringLiteral("deepl-translate"), i18n("Deepl")}, 0172 {QStringLiteral("microsoft-translate"), i18n("Microsoft")}, 0173 }; 0174 addComboBox(i18n("Service Provider"), maps, mAutoTranslateServiceProvider, QStringLiteral("AutoTranslate_ServiceProvider")); 0175 0176 mDeeplApiKey->setObjectName(QStringLiteral("mDeeplApiKey")); 0177 addLineEdit(i18n("DeepL API Key"), mDeeplApiKey, QStringLiteral("AutoTranslate_DeepLAPIKey")); 0178 0179 mGoogleApiKey->setObjectName(QStringLiteral("mGoogleApiKey")); 0180 addLineEdit(i18n("Google API Key"), mGoogleApiKey, QStringLiteral("AutoTranslate_GoogleAPIKey")); 0181 0182 mMicrosoftApiKey->setObjectName(QStringLiteral("mMicrosoftApiKey")); 0183 addLineEdit(i18n("Microsoft API Key"), mMicrosoftApiKey, QStringLiteral("AutoTranslate_MicrosoftAPIKey")); 0184 0185 mApiEmbed->setObjectName(QStringLiteral("mApiEmbed")); 0186 mApiEmbed->setToolTip(i18n("Whether embedded link previews are enabled or not when a user posts a link to a website.")); 0187 mMainLayout->addWidget(mApiEmbed); 0188 connectCheckBox(mApiEmbed, QStringLiteral("API_Embed")); 0189 0190 mEmbedCacheExpirationDays->setObjectName(QStringLiteral("mEmbedCacheExpirationDays")); 0191 addSpinbox(i18n("Embed Cache Expiration Days"), mEmbedCacheExpirationDays, QStringLiteral("API_EmbedCacheExpirationDays")); 0192 } 0193 0194 MessageSettingsWidget::~MessageSettingsWidget() = default; 0195 0196 void MessageSettingsWidget::initialize(const QMap<QString, QVariant> &mapSettings) 0197 { 0198 initializeWidget(mAllowMessageEditing, mapSettings, true); 0199 initializeWidget(mAllowMessageDeleting, mapSettings, true); 0200 initializeWidget(mShowEditedStatus, mapSettings, true); 0201 initializeWidget(mShowDeletedStatus, mapSettings, false); 0202 initializeWidget(mAllowMessagePinning, mapSettings, true); 0203 initializeWidget(mAllowMessageSnippeting, mapSettings, false); 0204 initializeWidget(mAllowConvertingLongMessageAttachment, mapSettings, true); 0205 initializeWidget(mVideoRecorderEnabled, mapSettings, true); 0206 initializeWidget(mBlockMessageEditingAfterMinutes, mapSettings, 0); 0207 initializeWidget(mBlockMessageDeletingAfterMinutes, mapSettings, 0); 0208 initializeWidget(mMaximumAllowedCharactersPerMessage, mapSettings, 5000); 0209 initializeWidget(mSafePort, mapSettings, QStringLiteral("80, 443")); 0210 initializeWidget(mThumbnailMaxHeight, mapSettings, false); 0211 initializeWidget(mEnableImageThumbnails, mapSettings, true); 0212 initializeWidget(mThumbnailMaxWidth, mapSettings, 480); 0213 initializeWidget(mThumbnailMaxHeight, mapSettings, 360); 0214 initializeWidget(mAudioRecorderEnabled, mapSettings, true); 0215 initializeWidget(mAudioMessageBitRate, mapSettings, 32); 0216 initializeWidget(mAutoTranslateEnabled, mapSettings, false); 0217 initializeWidget(mAutoTranslateServiceProvider, mapSettings, QStringLiteral("google-translate")); 0218 initializeWidget(mDeeplApiKey, mapSettings, {}); 0219 initializeWidget(mGoogleApiKey, mapSettings, {}); 0220 initializeWidget(mMicrosoftApiKey, mapSettings, {}); 0221 initializeWidget(mGroupingPeriod, mapSettings, 300); 0222 initializeWidget(mDirectMessageMaxUsers, mapSettings, 8); 0223 initializeWidget(mMaximumNumberChainedQuotes, mapSettings, 2); 0224 initializeWidget(mMessageErasureType, mapSettings, QStringLiteral("Delete")); 0225 initializeWidget(mApiEmbed, mapSettings, true); 0226 initializeWidget(mEmbedCacheExpirationDays, mapSettings, 30); 0227 } 0228 0229 #include "moc_messagesettingswidget.cpp"