Allow sending messages as plain text

This commit is contained in:
Nicolas Werner 2020-01-27 15:59:25 +01:00
parent 0d22da6288
commit e2f547149a
6 changed files with 90 additions and 61 deletions

View file

@ -116,7 +116,7 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent)
contentLayout_->setMargin(0); contentLayout_->setMargin(0);
top_bar_ = new TopRoomBar(this); top_bar_ = new TopRoomBar(this);
view_manager_ = new TimelineViewManager(this); view_manager_ = new TimelineViewManager(userSettings_, this);
contentLayout_->addWidget(top_bar_); contentLayout_->addWidget(top_bar_);
contentLayout_->addWidget(view_manager_->getWidget()); contentLayout_->addWidget(view_manager_->getWidget());

View file

@ -50,6 +50,7 @@ UserSettings::load()
hasDesktopNotifications_ = settings.value("user/desktop_notifications", true).toBool(); hasDesktopNotifications_ = settings.value("user/desktop_notifications", true).toBool();
isStartInTrayEnabled_ = settings.value("user/window/start_in_tray", false).toBool(); isStartInTrayEnabled_ = settings.value("user/window/start_in_tray", false).toBool();
isGroupViewEnabled_ = settings.value("user/group_view", true).toBool(); isGroupViewEnabled_ = settings.value("user/group_view", true).toBool();
isMarkdownEnabled_ = settings.value("user/markdown_enabled", true).toBool();
isTypingNotificationsEnabled_ = settings.value("user/typing_notifications", true).toBool(); isTypingNotificationsEnabled_ = settings.value("user/typing_notifications", true).toBool();
isReadReceiptsEnabled_ = settings.value("user/read_receipts", true).toBool(); isReadReceiptsEnabled_ = settings.value("user/read_receipts", true).toBool();
theme_ = settings.value("user/theme", defaultTheme_).toString(); theme_ = settings.value("user/theme", defaultTheme_).toString();
@ -126,6 +127,7 @@ UserSettings::save()
settings.setValue("typing_notifications", isTypingNotificationsEnabled_); settings.setValue("typing_notifications", isTypingNotificationsEnabled_);
settings.setValue("read_receipts", isReadReceiptsEnabled_); settings.setValue("read_receipts", isReadReceiptsEnabled_);
settings.setValue("group_view", isGroupViewEnabled_); settings.setValue("group_view", isGroupViewEnabled_);
settings.setValue("markdown_enabled", isMarkdownEnabled_);
settings.setValue("desktop_notifications", hasDesktopNotifications_); settings.setValue("desktop_notifications", hasDesktopNotifications_);
settings.setValue("theme", theme()); settings.setValue("theme", theme());
settings.setValue("font_family", font_); settings.setValue("font_family", font_);
@ -167,70 +169,46 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
topBarLayout_->addWidget(backBtn_, 1, Qt::AlignLeft | Qt::AlignVCenter); topBarLayout_->addWidget(backBtn_, 1, Qt::AlignLeft | Qt::AlignVCenter);
topBarLayout_->addStretch(1); topBarLayout_->addStretch(1);
auto trayOptionLayout_ = new QHBoxLayout; auto addSetting = [this, &font](QString labelText) {
trayOptionLayout_->setContentsMargins(0, OptionMargin, 0, OptionMargin); auto layout = new QHBoxLayout;
auto trayLabel = new QLabel(tr("Minimize to tray"), this); layout->setContentsMargins(0, OptionMargin, 0, OptionMargin);
trayLabel->setFont(font);
trayToggle_ = new Toggle(this);
trayOptionLayout_->addWidget(trayLabel); auto label = new QLabel(labelText, this);
trayOptionLayout_->addWidget(trayToggle_, 0, Qt::AlignRight); label->setFont(font);
auto startInTrayOptionLayout_ = new QHBoxLayout; auto toggle = new Toggle(this);
startInTrayOptionLayout_->setContentsMargins(0, OptionMargin, 0, OptionMargin);
auto startInTrayLabel = new QLabel(tr("Start in tray"), this); layout->addWidget(label);
startInTrayLabel->setFont(font); layout->addWidget(toggle, 0, Qt::AlignRight);
startInTrayToggle_ = new Toggle(this);
return std::pair{layout, toggle};
};
QHBoxLayout *trayOptionLayout_ = nullptr;
std::tie(trayOptionLayout_, trayToggle_) = addSetting(tr("Minimize to tray"));
QHBoxLayout *startInTrayOptionLayout_ = nullptr;
std::tie(startInTrayOptionLayout_, startInTrayToggle_) = addSetting(tr("Start in tray"));
if (!settings_->isTrayEnabled()) if (!settings_->isTrayEnabled())
startInTrayToggle_->setDisabled(true); startInTrayToggle_->setDisabled(true);
startInTrayOptionLayout_->addWidget(startInTrayLabel); QHBoxLayout *groupViewLayout = nullptr;
startInTrayOptionLayout_->addWidget(startInTrayToggle_, 0, Qt::AlignRight); std::tie(groupViewLayout, groupViewToggle_) = addSetting(tr("Group's sidebar"));
auto groupViewLayout = new QHBoxLayout; QHBoxLayout *avatarViewLayout = nullptr;
groupViewLayout->setContentsMargins(0, OptionMargin, 0, OptionMargin); std::tie(avatarViewLayout, avatarCircles_) = addSetting(tr("Circular Avatars"));
auto groupViewLabel = new QLabel(tr("Group's sidebar"), this);
groupViewLabel->setFont(font);
groupViewToggle_ = new Toggle(this);
groupViewLayout->addWidget(groupViewLabel); QHBoxLayout *typingLayout = nullptr;
groupViewLayout->addWidget(groupViewToggle_, 0, Qt::AlignRight); std::tie(typingLayout, typingNotifications_) = addSetting(tr("Typing notifications"));
auto avatarViewLayout = new QHBoxLayout; QHBoxLayout *receiptsLayout = nullptr;
avatarViewLayout->setContentsMargins(0, OptionMargin, 0, OptionMargin); std::tie(receiptsLayout, readReceipts_) = addSetting(tr("Read receipts"));
auto avatarViewLabel = new QLabel(tr("Circular Avatars"), this);
avatarViewLabel->setFont(font);
avatarCircles_ = new Toggle(this);
avatarViewLayout->addWidget(avatarViewLabel); QHBoxLayout *markdownLayout = nullptr;
avatarViewLayout->addWidget(avatarCircles_, 0, Qt::AlignRight); std::tie(markdownLayout, markdownEnabled_) = addSetting(tr("Send messages as markdown"));
auto typingLayout = new QHBoxLayout; QHBoxLayout *desktopLayout = nullptr;
typingLayout->setContentsMargins(0, OptionMargin, 0, OptionMargin); std::tie(desktopLayout, desktopNotifications_) = addSetting(tr("Desktop notifications"));
auto typingLabel = new QLabel(tr("Typing notifications"), this);
typingLabel->setFont(font);
typingNotifications_ = new Toggle(this);
typingLayout->addWidget(typingLabel);
typingLayout->addWidget(typingNotifications_, 0, Qt::AlignRight);
auto receiptsLayout = new QHBoxLayout;
receiptsLayout->setContentsMargins(0, OptionMargin, 0, OptionMargin);
auto receiptsLabel = new QLabel(tr("Read receipts"), this);
receiptsLabel->setFont(font);
readReceipts_ = new Toggle(this);
receiptsLayout->addWidget(receiptsLabel);
receiptsLayout->addWidget(readReceipts_, 0, Qt::AlignRight);
auto desktopLayout = new QHBoxLayout;
desktopLayout->setContentsMargins(0, OptionMargin, 0, OptionMargin);
auto desktopLabel = new QLabel(tr("Desktop notifications"), this);
desktopLabel->setFont(font);
desktopNotifications_ = new Toggle(this);
desktopLayout->addWidget(desktopLabel);
desktopLayout->addWidget(desktopNotifications_, 0, Qt::AlignRight);
auto scaleFactorOptionLayout = new QHBoxLayout; auto scaleFactorOptionLayout = new QHBoxLayout;
scaleFactorOptionLayout->setContentsMargins(0, OptionMargin, 0, OptionMargin); scaleFactorOptionLayout->setContentsMargins(0, OptionMargin, 0, OptionMargin);
@ -385,6 +363,7 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
mainLayout_->addWidget(new HorizontalLine(this)); mainLayout_->addWidget(new HorizontalLine(this));
mainLayout_->addLayout(typingLayout); mainLayout_->addLayout(typingLayout);
mainLayout_->addLayout(receiptsLayout); mainLayout_->addLayout(receiptsLayout);
mainLayout_->addLayout(markdownLayout);
mainLayout_->addLayout(desktopLayout); mainLayout_->addLayout(desktopLayout);
mainLayout_->addWidget(new HorizontalLine(this)); mainLayout_->addWidget(new HorizontalLine(this));
@ -466,6 +445,10 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
settings_->setAvatarCircles(!isDisabled); settings_->setAvatarCircles(!isDisabled);
}); });
connect(markdownEnabled_, &Toggle::toggled, this, [this](bool isDisabled) {
settings_->setMarkdownEnabled(!isDisabled);
});
connect(typingNotifications_, &Toggle::toggled, this, [this](bool isDisabled) { connect(typingNotifications_, &Toggle::toggled, this, [this](bool isDisabled) {
settings_->setTypingNotifications(!isDisabled); settings_->setTypingNotifications(!isDisabled);
}); });
@ -496,8 +479,10 @@ UserSettingsPage::showEvent(QShowEvent *)
trayToggle_->setState(!settings_->isTrayEnabled()); trayToggle_->setState(!settings_->isTrayEnabled());
startInTrayToggle_->setState(!settings_->isStartInTrayEnabled()); startInTrayToggle_->setState(!settings_->isStartInTrayEnabled());
groupViewToggle_->setState(!settings_->isGroupViewEnabled()); groupViewToggle_->setState(!settings_->isGroupViewEnabled());
avatarCircles_->setState(!settings_->isAvatarCirclesEnabled());
typingNotifications_->setState(!settings_->isTypingNotificationsEnabled()); typingNotifications_->setState(!settings_->isTypingNotificationsEnabled());
readReceipts_->setState(!settings_->isReadReceiptsEnabled()); readReceipts_->setState(!settings_->isReadReceiptsEnabled());
markdownEnabled_->setState(!settings_->isMarkdownEnabled());
desktopNotifications_->setState(!settings_->hasDesktopNotifications()); desktopNotifications_->setState(!settings_->hasDesktopNotifications());
deviceIdValue_->setText(QString::fromStdString(http::client()->device_id())); deviceIdValue_->setText(QString::fromStdString(http::client()->device_id()));

View file

@ -68,6 +68,12 @@ public:
save(); save();
} }
void setMarkdownEnabled(bool state)
{
isMarkdownEnabled_ = state;
save();
}
void setReadReceipts(bool state) void setReadReceipts(bool state)
{ {
isReadReceiptsEnabled_ = state; isReadReceiptsEnabled_ = state;
@ -96,6 +102,8 @@ public:
bool isTrayEnabled() const { return isTrayEnabled_; } bool isTrayEnabled() const { return isTrayEnabled_; }
bool isStartInTrayEnabled() const { return isStartInTrayEnabled_; } bool isStartInTrayEnabled() const { return isStartInTrayEnabled_; }
bool isGroupViewEnabled() const { return isGroupViewEnabled_; } bool isGroupViewEnabled() const { return isGroupViewEnabled_; }
bool isAvatarCirclesEnabled() const { return avatarCircles_; }
bool isMarkdownEnabled() const { return isMarkdownEnabled_; }
bool isTypingNotificationsEnabled() const { return isTypingNotificationsEnabled_; } bool isTypingNotificationsEnabled() const { return isTypingNotificationsEnabled_; }
bool isReadReceiptsEnabled() const { return isReadReceiptsEnabled_; } bool isReadReceiptsEnabled() const { return isReadReceiptsEnabled_; }
bool hasDesktopNotifications() const { return hasDesktopNotifications_; } bool hasDesktopNotifications() const { return hasDesktopNotifications_; }
@ -116,6 +124,7 @@ private:
bool isTrayEnabled_; bool isTrayEnabled_;
bool isStartInTrayEnabled_; bool isStartInTrayEnabled_;
bool isGroupViewEnabled_; bool isGroupViewEnabled_;
bool isMarkdownEnabled_;
bool isTypingNotificationsEnabled_; bool isTypingNotificationsEnabled_;
bool isReadReceiptsEnabled_; bool isReadReceiptsEnabled_;
bool hasDesktopNotifications_; bool hasDesktopNotifications_;
@ -168,6 +177,7 @@ private:
Toggle *groupViewToggle_; Toggle *groupViewToggle_;
Toggle *typingNotifications_; Toggle *typingNotifications_;
Toggle *readReceipts_; Toggle *readReceipts_;
Toggle *markdownEnabled_;
Toggle *desktopNotifications_; Toggle *desktopNotifications_;
Toggle *avatarCircles_; Toggle *avatarCircles_;
QLabel *deviceFingerprintValue_; QLabel *deviceFingerprintValue_;

24
src/install-debian.txt Normal file
View file

@ -0,0 +1,24 @@
sudo apt install cmake
sudo apt install gcc make automake
sudo apt install qt5-default
sudo apt install liblmdb-dev
sudo apt install qttools5-dev-tools
sudo apt install qttools5-dev-tools
sudo apt install qttools5
sudo apt install qt5-qmltooling-plugins qml-module-qtgstreamer
sudo apt install libqt5webview5-dev
sudo apt install libqt5quickcontrols2-5
sudo apt install qtquickcontrols2-5-dev
sudo apt install libssl-dev
sudo apt install qml-module-qtgraphicaleffects
sudo apt install qml-module-qtquick-controls2
sudo apt install qml-module-qtquick-layouts
sudo apt install qml-module-qtmultimedia
sudo apt install qml-module-qt-labs-settings qml-module-qt-labs-sharedimage
sudo apt install qttools5-dev
sudo apt install libqt5svg5-dev
sudo apt install qt5multimedia
sudo apt install libqt5multimedia5
sudo apt install libqt5multimedia5-plugins libqt5multimediagsttools5 libqt5multimediaquick5 libqt5multimediawidgets5
sudo apt install qt5ct
sudo apt install qtmultimedia5-dev

View file

@ -18,8 +18,7 @@ Q_DECLARE_METATYPE(mtx::events::collections::TimelineEvents)
void void
TimelineViewManager::updateColorPalette() TimelineViewManager::updateColorPalette()
{ {
UserSettings settings; if (settings->theme() == "light") {
if (settings.theme() == "light") {
QPalette lightActive(/*windowText*/ QColor("#333"), QPalette lightActive(/*windowText*/ QColor("#333"),
/*button*/ QColor("#333"), /*button*/ QColor("#333"),
/*light*/ QColor(), /*light*/ QColor(),
@ -31,7 +30,7 @@ TimelineViewManager::updateColorPalette()
/*window*/ QColor("white")); /*window*/ QColor("white"));
view->rootContext()->setContextProperty("currentActivePalette", lightActive); view->rootContext()->setContextProperty("currentActivePalette", lightActive);
view->rootContext()->setContextProperty("currentInactivePalette", lightActive); view->rootContext()->setContextProperty("currentInactivePalette", lightActive);
} else if (settings.theme() == "dark") { } else if (settings->theme() == "dark") {
QPalette darkActive(/*windowText*/ QColor("#caccd1"), QPalette darkActive(/*windowText*/ QColor("#caccd1"),
/*button*/ QColor("#caccd1"), /*button*/ QColor("#caccd1"),
/*light*/ QColor(), /*light*/ QColor(),
@ -50,9 +49,10 @@ TimelineViewManager::updateColorPalette()
} }
} }
TimelineViewManager::TimelineViewManager(QWidget *parent) TimelineViewManager::TimelineViewManager(QSharedPointer<UserSettings> userSettings, QWidget *parent)
: imgProvider(new MxcImageProvider()) : imgProvider(new MxcImageProvider())
, colorImgProvider(new ColorImageProvider()) , colorImgProvider(new ColorImageProvider())
, settings(userSettings)
{ {
qmlRegisterUncreatableMetaObject(qml_mtx_events::staticMetaObject, qmlRegisterUncreatableMetaObject(qml_mtx_events::staticMetaObject,
"im.nheko", "im.nheko",
@ -207,6 +207,11 @@ TimelineViewManager::queueTextMessage(const QString &msg, const std::optional<Re
text.relates_to.in_reply_to.event_id = related->related_event; text.relates_to.in_reply_to.event_id = related->related_event;
} }
if (!settings->isMarkdownEnabled()) {
text.format = "";
text.formatted_body = "";
}
if (timeline_) if (timeline_)
timeline_->sendMessage(text); timeline_->sendMessage(text);
} }
@ -219,8 +224,10 @@ TimelineViewManager::queueEmoteMessage(const QString &msg)
mtx::events::msg::Emote emote; mtx::events::msg::Emote emote;
emote.body = msg.trimmed().toStdString(); emote.body = msg.trimmed().toStdString();
if (html != msg.trimmed().toHtmlEscaped()) if (html != msg.trimmed().toHtmlEscaped() && settings->isMarkdownEnabled()) {
emote.formatted_body = html.toStdString(); emote.formatted_body = html.toStdString();
emote.format = "org.matrix.custom.html";
}
if (timeline_) if (timeline_)
timeline_->sendMessage(emote); timeline_->sendMessage(emote);

View file

@ -15,6 +15,7 @@
class MxcImageProvider; class MxcImageProvider;
class ColorImageProvider; class ColorImageProvider;
class UserSettings;
class TimelineViewManager : public QObject class TimelineViewManager : public QObject
{ {
@ -26,7 +27,7 @@ class TimelineViewManager : public QObject
bool isInitialSync MEMBER isInitialSync_ READ isInitialSync NOTIFY initialSyncChanged) bool isInitialSync MEMBER isInitialSync_ READ isInitialSync NOTIFY initialSyncChanged)
public: public:
TimelineViewManager(QWidget *parent = 0); TimelineViewManager(QSharedPointer<UserSettings> userSettings, QWidget *parent = 0);
QWidget *getWidget() const { return container; } QWidget *getWidget() const { return container; }
void sync(const mtx::responses::Rooms &rooms); void sync(const mtx::responses::Rooms &rooms);
@ -97,4 +98,6 @@ private:
QHash<QString, QSharedPointer<TimelineModel>> models; QHash<QString, QSharedPointer<TimelineModel>> models;
TimelineModel *timeline_ = nullptr; TimelineModel *timeline_ = nullptr;
bool isInitialSync_ = true; bool isInitialSync_ = true;
QSharedPointer<UserSettings> settings;
}; };