Option to send message by pressing enter

This commit is contained in:
Sebastian J. Wolf 2020-09-16 22:04:02 +02:00
parent b5f39f78c0
commit 4d573f1f43
8 changed files with 154 additions and 1 deletions

View file

@ -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 \

View file

@ -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 = "";

View file

@ -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 {

View file

@ -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 <http://www.gnu.org/licenses/>.
*/
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 {}
}
}
}

View file

@ -30,7 +30,7 @@
#include <QDBusConnection>
#include <QDBusInterface>
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();

View file

@ -24,6 +24,7 @@
#include <QDebug>
#include <QJsonDocument>
#include <QStandardPaths>
#include <QSettings>
#include <td/telegram/td_json_client.h>
#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();

View file

@ -374,6 +374,29 @@
<source>Mute Chat</source>
<translation>Chat stummschalten</translation>
</message>
<message>
<source>Settings</source>
<translation>Einstellungen</translation>
</message>
</context>
<context>
<name>SettingsPage</name>
<message>
<source>Settings</source>
<translation>Einstellungen</translation>
</message>
<message>
<source>Behavior</source>
<translation>Verhalten</translation>
</message>
<message>
<source>Send message by enter</source>
<translation>Nachricht mit Enter senden</translation>
</message>
<message>
<source>Send your message by pressing the enter key</source>
<translation>Senden Sie Ihre Nachricht, indem Sie die Enter-Taste drücken</translation>
</message>
</context>
<context>
<name>VideoPage</name>

View file

@ -374,6 +374,29 @@
<source>Mute Chat</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Settings</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>SettingsPage</name>
<message>
<source>Settings</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Behavior</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Send message by enter</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Send your message by pressing the enter key</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>VideoPage</name>