-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
53 lines (47 loc) · 1.6 KB
/
mainwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// SPDX-License-Identifier: MIT
// Copyright (c) 2024 Pedro López-Cabanillas <plcl@users.sf.net>
#include <QDebug>
#include <QHostAddress>
#include <QHostInfo>
#include <QMenu>
#include <QMenuBar>
#include "ConsoleWidget.h"
#include "fluidcompleter.h"
#include "mainwindow.h"
#include "netclient.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow{parent}
{
m_client = new NetClient(this);
m_completer = new FluidCompleter(this);
m_console = new ConsoleWidget(this);
m_console->setCompleter(m_completer);
m_console->setFont(QFont("Monospace"));
m_console->writeStdOut("Type 'help' for help topics.\n");
setCentralWidget(m_console);
setWindowTitle("FluidSynth network interface");
QMenu *file = menuBar()->addMenu("&File");
file->addAction("E&xit", QKeySequence::Quit, this, &MainWindow::close);
connect(m_client, &NetClient::dataRead, this, &MainWindow::consoleOutput);
connect(m_console->device(), &QIODevice::readyRead, this, &MainWindow::consoleInput);
}
bool MainWindow::openConnection(const QString &host, const QString &port)
{
QHostInfo hostInfo = QHostInfo::fromName(host);
QHostAddress hostAddress = hostInfo.addresses().first();
int portNumber = port.toInt();
return m_client->connectToHost(hostAddress, portNumber);
}
void MainWindow::consoleOutput(const QByteArray &data)
{
m_console->writeStdOut(QString::fromUtf8(data));
m_console->setMode(ConsoleWidget::Input);
}
void MainWindow::consoleInput()
{
QByteArray text = m_console->device()->readAll();
m_client->writeToSocket(text);
if (text == "quit\n") {
close();
}
}