Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

So/server box #49

Merged
merged 8 commits into from
Aug 13, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Added server box. Still some bugs, so wont merge with master
  • Loading branch information
Feqzz committed Aug 11, 2020
commit 7c6519093fc912c36aa04e16f443fdf7c2524031
101 changes: 101 additions & 0 deletions components/ServerDialog.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import QtQuick 2.12
import QtQuick.Window 2.12
import QtMultimedia 5.15
import QtQuick.Controls 2.5
import QtQuick.Layouts 1.15
import QtQuick.Dialogs 1.3
import "../components" as C

Dialog {
id: dialogId
width: 600
height: 600
//modal: true
title: "Server Information"
//anchors.centerIn: parent
standardButtons: Dialog.Close | Dialog.Apply

Rectangle{
//anchors.fill: parent

ColumnLayout {
//anchors.fill: parent
spacing: 10
Text {
text: qsTr("We couldn't find a server to connect to! \n Please fill in the details below.")
anchors.horizontalCenter: dialogId.horizontalCenter
}

RowLayout {
Text {
id: hostAddressText
text: qsTr("Host Address:");
}
TextField {
id: hostAddressTextField
placeholderText: "Host Address"
cursorVisible: false
maximumLength: 20
}
}

RowLayout {
Text {
text: qsTr("TCP Port:");
}
TextField {
id: tcpPortTextField
placeholderText: "1337"
cursorVisible: false
maximumLength: 20
}
}

RowLayout {
Text {
//id: udpPortTextField
text: qsTr("UDP Port:");
}
TextField {
id: udpPortTextField
placeholderText: "1338"
cursorVisible: false
maximumLength: 20
}
}

RowLayout {
Text {
//id: hostAddressText
text: qsTr("SQL TCP Port:");
}
TextField {
id: sqlTcpPortTextField
placeholderText: "1339"
cursorVisible: false
maximumLength: 20
}
}

Text {
id: error
visible: false
color: "red"
}

}
}
onRejected: console.log("Close clicked")
onApply: {
if (udpPortTextField.text.length > 0 && sqlTcpPortTextField.text.length > 0 && tcpPortTextField.text.length > 0 && hostAddressTextField.text.length > 0) {
backendSettings.setServerIpAddress(hostAddressTextField.text);
backendSettings.setTcpPort(tcpPortTextField.text);
backendSettings.setUdpPort(udpPortTextField.text);
backendSettings.setSqlTcpPort(sqlTcpPortTextField.text);
dialogId.close()
} else {
error.text = "Please fill in all the fields"
error.visible = true
}
}
}
67 changes: 65 additions & 2 deletions components/Settings.qml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ Dialog {
videoOn.checked = backendSettings.getVideoOn();
saveLastRoom.checked = backendSettings.getSaveLastRoom();
displayName.text = backendSettings.getDisplayName();
hostAddressTextField.text = backendSettings.getServerIpAddress();
tcpPortTextField.text = backendSettings.getTcpPort();
udpPortTextField.text = backendSettings.getUdpPort();
sqlTcpPortTextField.text = backendSettings.getSqlTcpPort();

}

Expand All @@ -35,7 +39,7 @@ Dialog {
id: settings
visible: false
width: 400
height: 300
height: 500
//modal: true
title: "Settings"
//anchors.centerIn: parent
Expand All @@ -50,17 +54,72 @@ Dialog {
}
TextField {
id: displayName
placeholderText: "UserName"
placeholderText: "Visible name"
cursorVisible: false
maximumLength: 20
}
}

RowLayout {
Text {
text: qsTr("Host Address:");
}
TextField {
id: hostAddressTextField
placeholderText: "Host Address"
cursorVisible: false
maximumLength: 20
readOnly: sessionHandler.getSessionIsActive()
}
}

RowLayout {
Text {
text: qsTr("TCP Port:");
}
TextField {
id: tcpPortTextField
placeholderText: "1337"
cursorVisible: false
maximumLength: 20
readOnly: sessionHandler.getSessionIsActive()
}
}

RowLayout {
Text {
//id: udpPortTextField
text: qsTr("UDP Port:");
}
TextField {
id: udpPortTextField
placeholderText: "1338"
cursorVisible: false
maximumLength: 20
readOnly: sessionHandler.getSessionIsActive()
}
}

RowLayout {
Text {
//id: hostAddressText
text: qsTr("SQL TCP Port:");
}
TextField {
id: sqlTcpPortTextField
placeholderText: "1339"
cursorVisible: false
maximumLength: 20
readOnly: sessionHandler.getSessionIsActive()
}
}

CheckBox {
id: audioOn
checked: true
text: qsTr("Audio on when joining meeting")
}

CheckBox {
id: videoOn
checked: true
Expand Down Expand Up @@ -92,6 +151,10 @@ Dialog {
backendSettings.setVideoOn(videoOn.checked);
backendSettings.setSaveLastRoom(saveLastRoom.checked);
backendSettings.setDefaultAudioInput(defaultAudioInput.currentText);
backendSettings.setServerIpAddress(hostAddressTextField.text);
backendSettings.setTcpPort(tcpPortTextField.text);
backendSettings.setUdpPort(udpPortTextField.text);
backendSettings.setSqlTcpPort(sqlTcpPortTextField.text);

if (displayName.text !== backendSettings.getDisplayName()) {
backendSettings.setDisplayName(displayName.text === "" ? "UserName" : displayName.text);
Expand Down
13 changes: 10 additions & 3 deletions core/servertcpqueries.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#include "servertcpqueries.h"

ServerTcpQueries::ServerTcpQueries(int _port, QHostAddress serverAddress, QObject* parent): QTcpSocket(parent)
ServerTcpQueries::ServerTcpQueries(Settings* settings, QObject* parent): QTcpSocket(parent)
{
mServerAddress = serverAddress;
mPortNumber = _port;
mSettings = settings;
mMillisWait = 2000;
}
/**
Expand All @@ -13,10 +12,14 @@ ServerTcpQueries::ServerTcpQueries(int _port, QHostAddress serverAddress, QObjec
*/
bool ServerTcpQueries::connect()
{
mServerAddress = (mSettings->getServerIpAddress() == "Localhost") ?
QHostAddress::LocalHost : QHostAddress(mSettings->getServerIpAddress());
mPortNumber = mSettings->getSqlTcpPort();
this->connectToHost(mServerAddress, mPortNumber);
if(!this->waitForConnected(mMillisWait))
{
qDebug() << "TcpSocketError: " << this->errorString() << Q_FUNC_INFO;
qDebug() << mServerAddress << mPortNumber;
return false;
}
return true;
Expand Down Expand Up @@ -78,6 +81,10 @@ int ServerTcpQueries::CUDQuery(int code, const QVariantList& vars)
numberOfRowsAffected = response[0];
}
}
else
{
return numberOfRowsAffected;
}
disconnect();
return numberOfRowsAffected;
}
Expand Down
4 changes: 3 additions & 1 deletion core/servertcpqueries.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
#define SERVERTCPQUERIES_H
#include <QTcpSocket>
#include <QHostAddress>
#include "settings.h"

class ServerTcpQueries : public QTcpSocket
{
public:
ServerTcpQueries(int port, QHostAddress address, QObject* parent = nullptr);
ServerTcpQueries(Settings* settings, QObject* parent = nullptr);
/*QVariantList query0SelectFromRoom(QString _roomId, QString _roomPassword);
int query1InsertIntoRoomSession(QString _roomId, QString _userId);
int query2InsertIntoRoom(QString _roomId, QString _host, QString _roomPassword);
Expand All @@ -27,6 +28,7 @@ class ServerTcpQueries : public QTcpSocket
int mPortNumber;
int mMillisWait;
QHostAddress mServerAddress;
Settings* mSettings;
};

#endif // SERVERTCPQUERIES_H
52 changes: 52 additions & 0 deletions core/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ void Settings::loadSettings()
mDisplayName = settings.value("displayName").toString();
mDefaultAudioInput = settings.value("defaultAudioInput").toString();
mSaveLastRoom = settings.value("saveLastRoom").toBool();
mServerIpAddress = settings.value("serverIpAddress").toString();
mTcpPort = settings.value("tcpPort").toInt();
mUdpPort = settings.value("udpPort").toInt();
mSqlTcpPort = settings.value("sqlTcpPort").toInt();
if (mSaveLastRoom)
{
mLastRoomId = settings.value("lastRoomId").toString();
Expand Down Expand Up @@ -49,6 +53,10 @@ void Settings::loadAndSaveDefaultSettings(const QString& displayName)
mSaveLastRoom = true;
mLastRoomId = "";
mLastRoomPassword = "";
mServerIpAddress = "";
mTcpPort = 1337;
mUdpPort = 1338;
mSqlTcpPort = 1339;
saveSettings();
}

Expand All @@ -63,6 +71,10 @@ void Settings::saveSettings()
object.insert("displayName", QJsonValue::fromVariant(mDisplayName));
object.insert("defaultAudioInput", QJsonValue::fromVariant(mDefaultAudioInput));
object.insert("saveLastRoom", QJsonValue::fromVariant(mSaveLastRoom));
object.insert("serverIpAddress", QJsonValue::fromVariant(mServerIpAddress));
object.insert("tcpPort", QJsonValue::fromVariant(mTcpPort));
object.insert("udpPort", QJsonValue::fromVariant(mUdpPort));
object.insert("sqlTcpPort", QJsonValue::fromVariant(mSqlTcpPort));
if (mSaveLastRoom)
{
object.insert("lastRoomId", QJsonValue::fromVariant(mLastRoomId));
Expand Down Expand Up @@ -108,6 +120,46 @@ QString Settings::getLastRoomPassword() const
return mLastRoomPassword;
}

int Settings::getTcpPort() const
{
return mTcpPort;
}

int Settings::getUdpPort() const
{
return mUdpPort;
}

int Settings::getSqlTcpPort() const
{
return mSqlTcpPort;
}

QString Settings::getServerIpAddress() const
{
return mServerIpAddress;
}

void Settings::setServerIpAddress(const QString &serverIpAddress)
{
mServerIpAddress = serverIpAddress;
}

void Settings::setSqlTcpPort(int sqlTcpPort)
{
mSqlTcpPort = sqlTcpPort;
}

void Settings::setUdpPort(int udpPort)
{
mUdpPort = udpPort;
}

void Settings::setTcpPort(int tcpPort)
{
mTcpPort = tcpPort;
}

void Settings::setAudioOn(bool val)
{
mAudioOn = val;
Expand Down
12 changes: 12 additions & 0 deletions core/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,26 @@ class Settings : public QObject
Q_INVOKABLE void setSaveLastRoom(bool val);
Q_INVOKABLE void setLastRoomId(const QString& val);
Q_INVOKABLE void setLastRoomPassword(const QString& val);
Q_INVOKABLE void setServerIpAddress(const QString &serverIpAddress);
Q_INVOKABLE void setSqlTcpPort(int sqlTcpPort);
Q_INVOKABLE void setUdpPort(int udpPort);
Q_INVOKABLE void setTcpPort(int tcpPort);
Q_INVOKABLE int getTcpPort() const;
Q_INVOKABLE int getUdpPort() const;
Q_INVOKABLE int getSqlTcpPort() const;
Q_INVOKABLE bool getAudioOn() const;
Q_INVOKABLE bool getVideoOn() const;
Q_INVOKABLE bool getSaveLastRoom() const;
Q_INVOKABLE QString getDisplayName() const;
Q_INVOKABLE QString getDefaultAudioInput() const;
Q_INVOKABLE QString getLastRoomId() const;
Q_INVOKABLE QString getLastRoomPassword() const;
Q_INVOKABLE QString getServerIpAddress() const;

private:
int mTcpPort;
int mUdpPort;
int mSqlTcpPort;
bool mAudioOn;
bool mVideoOn;
bool mSaveLastRoom;
Expand All @@ -39,6 +50,7 @@ class Settings : public QObject
QString mSettingsFile = "./settings.json";
QString mLastRoomId;
QString mLastRoomPassword;
QString mServerIpAddress;
};

#endif // SETTINGS_H
Loading