From 4d573f1f439046ef385dfb0f930143ef6e3f38fc Mon Sep 17 00:00:00 2001 From: "Sebastian J. Wolf" Date: Wed, 16 Sep 2020 22:04:02 +0200 Subject: [PATCH] Option to send message by pressing enter --- harbour-fernschreiber.pro | 1 + qml/pages/ChatPage.qml | 29 ++++++++++++ qml/pages/OverviewPage.qml | 4 ++ qml/pages/SettingsPage.qml | 59 ++++++++++++++++++++++++ src/tdlibwrapper.cpp | 12 ++++- src/tdlibwrapper.h | 4 ++ translations/harbour-fernschreiber-de.ts | 23 +++++++++ translations/harbour-fernschreiber.ts | 23 +++++++++ 8 files changed, 154 insertions(+), 1 deletion(-) create mode 100644 qml/pages/SettingsPage.qml diff --git a/harbour-fernschreiber.pro b/harbour-fernschreiber.pro index 8fe5463..13995ca 100644 --- a/harbour-fernschreiber.pro +++ b/harbour-fernschreiber.pro @@ -39,6 +39,7 @@ DISTFILES += qml/harbour-fernschreiber.qml \ qml/pages/InitializationPage.qml \ qml/pages/OverviewPage.qml \ qml/pages/AboutPage.qml \ + qml/pages/SettingsPage.qml \ qml/pages/VideoPage.qml \ rpm/harbour-fernschreiber.changes.in \ rpm/harbour-fernschreiber.changes.run.in \ diff --git a/qml/pages/ChatPage.qml b/qml/pages/ChatPage.qml index afd95aa..c9cf9f9 100644 --- a/qml/pages/ChatPage.qml +++ b/qml/pages/ChatPage.qml @@ -675,6 +675,34 @@ Page { newMessageInReplyToRow.inReplyToMessage = null; } } + EnterKey.onClicked: { + if (tdLibWrapper.getSendByEnter()) { + tdLibWrapper.sendTextMessage(chatInformation.id, newMessageTextField.text, newMessageColumn.replyToMessageId); + newMessageTextField.text = ""; + newMessageTextField.focus = false; + } + } + + Component.onCompleted: { + if (tdLibWrapper.getSendByEnter()) { + EnterKey.iconSource = "image://theme/icon-m-chat"; + EnterKey.enabled = false; + } + } + + onTextChanged: { + if (text.length === 0) { + newMessageSendButton.enabled = false; + if (tdLibWrapper.getSendByEnter()) { + EnterKey.enabled = false; + } + } else { + newMessageSendButton.enabled = true; + if (tdLibWrapper.getSendByEnter()) { + EnterKey.enabled = true; + } + } + } } } @@ -686,6 +714,7 @@ Page { id: newMessageSendButton icon.source: "image://theme/icon-m-chat" anchors.horizontalCenter: parent.horizontalCenter + enabled: false onClicked: { tdLibWrapper.sendTextMessage(chatInformation.id, newMessageTextField.text, newMessageColumn.replyToMessageId); newMessageTextField.text = ""; diff --git a/qml/pages/OverviewPage.qml b/qml/pages/OverviewPage.qml index a5b8e03..f866ec7 100644 --- a/qml/pages/OverviewPage.qml +++ b/qml/pages/OverviewPage.qml @@ -166,6 +166,10 @@ Page { text: qsTr("About Fernschreiber") onClicked: pageStack.push(Qt.resolvedUrl("../pages/AboutPage.qml")) } + MenuItem { + text: qsTr("Settings") + onClicked: pageStack.push(Qt.resolvedUrl("../pages/SettingsPage.qml")) + } } Column { diff --git a/qml/pages/SettingsPage.qml b/qml/pages/SettingsPage.qml new file mode 100644 index 0000000..1e8d2e1 --- /dev/null +++ b/qml/pages/SettingsPage.qml @@ -0,0 +1,59 @@ +/* + Copyright (C) 2020 Sebastian J. Wolf + + This file is part of Fernschreiber. + + Fernschreiber is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Fernschreiber is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Fernschreiber. If not, see . +*/ +import QtQuick 2.0 +import Sailfish.Silica 1.0 +import "../js/functions.js" as Functions + + +Page { + id: settingsPage + allowedOrientations: Orientation.All + + SilicaFlickable { + id: settingsContainer + contentHeight: column.height + anchors.fill: parent + + Column { + id: column + width: settingsPage.width + spacing: Theme.paddingLarge + + PageHeader { + title: qsTr("Settings") + } + + SectionHeader { + text: qsTr("Behavior") + } + + TextSwitch { + checked: tdLibWrapper.getSendByEnter() + text: qsTr("Send message by enter") + description: qsTr("Send your message by pressing the enter key") + onCheckedChanged: { + tdLibWrapper.setSendByEnter(checked); + } + } + + VerticalScrollDecorator {} + } + + } +} diff --git a/src/tdlibwrapper.cpp b/src/tdlibwrapper.cpp index 45fd1ad..d20e64e 100644 --- a/src/tdlibwrapper.cpp +++ b/src/tdlibwrapper.cpp @@ -30,7 +30,7 @@ #include #include -TDLibWrapper::TDLibWrapper(QObject *parent) : QObject(parent) +TDLibWrapper::TDLibWrapper(QObject *parent) : QObject(parent), settings("harbour-fernschreiber", "settings") { qDebug() << "[TDLibWrapper] Initializing TD Lib..."; this->tdLibClient = td_json_client_create(); @@ -333,6 +333,16 @@ void TDLibWrapper::controlScreenSaver(const bool &enabled) } } +void TDLibWrapper::setSendByEnter(const bool &sendByEnter) +{ + settings.setValue("sendByEnter", sendByEnter); +} + +bool TDLibWrapper::getSendByEnter() +{ + return settings.value("sendByEnter", false).toBool(); +} + DBusAdaptor *TDLibWrapper::getDBusAdaptor() { return this->dbusInterface->getDBusAdaptor(); diff --git a/src/tdlibwrapper.h b/src/tdlibwrapper.h index d4e5a38..c58e65a 100644 --- a/src/tdlibwrapper.h +++ b/src/tdlibwrapper.h @@ -24,6 +24,7 @@ #include #include #include +#include #include #include "tdlibreceiver.h" #include "dbusadaptor.h" @@ -73,6 +74,8 @@ public: Q_INVOKABLE void copyFileToDownloads(const QString &filePath); Q_INVOKABLE void openFileOnDevice(const QString &filePath); Q_INVOKABLE void controlScreenSaver(const bool &enabled); + Q_INVOKABLE void setSendByEnter(const bool &sendByEnter); + Q_INVOKABLE bool getSendByEnter(); DBusAdaptor *getDBusAdaptor(); @@ -162,6 +165,7 @@ private: QVariantMap unreadChatInformation; QVariantMap basicGroups; QVariantMap superGroups; + QSettings settings; void setInitialParameters(); void setEncryptionKey(); diff --git a/translations/harbour-fernschreiber-de.ts b/translations/harbour-fernschreiber-de.ts index b1b3961..a93441a 100644 --- a/translations/harbour-fernschreiber-de.ts +++ b/translations/harbour-fernschreiber-de.ts @@ -374,6 +374,29 @@ Mute Chat Chat stummschalten + + Settings + Einstellungen + + + + SettingsPage + + Settings + Einstellungen + + + Behavior + Verhalten + + + Send message by enter + Nachricht mit Enter senden + + + Send your message by pressing the enter key + Senden Sie Ihre Nachricht, indem Sie die Enter-Taste drücken + VideoPage diff --git a/translations/harbour-fernschreiber.ts b/translations/harbour-fernschreiber.ts index c20bc13..b541914 100644 --- a/translations/harbour-fernschreiber.ts +++ b/translations/harbour-fernschreiber.ts @@ -374,6 +374,29 @@ Mute Chat + + Settings + + + + + SettingsPage + + Settings + + + + Behavior + + + + Send message by enter + + + + Send your message by pressing the enter key + + VideoPage