vnclauncher/dialog.cpp

74 行
2.6 KiB
C++

/*************************************************************************
* Copyright (C) 2014 by Andrius Štikonas <andrius@stikonas.eu> *
* *
* This program 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. *
* *
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.*
*************************************************************************/
#include <QFile>
#include <QProcess>
#include <QTextStream>
#include "dialog.h"
#include "ui_dialog.h"
Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog)
{
ui->setupUi(this);
QObject::connect(ui->buttonQuit, &QPushButton::clicked, this, &Dialog::reject);
QObject::connect(ui->buttonStart, &QPushButton::clicked, this, &Dialog::connectToClients);
}
Dialog::~Dialog()
{
delete ui;
}
void Dialog::connectToClients()
{
QString line, command = QStringLiteral("tvnserver");
if(connected)
{
QStringList arguments;
arguments << QStringLiteral("-controlservice") << QStringLiteral("-disconnectall") << line;
QProcess *process = new QProcess();
process->start(command, arguments);
connected = false;
ui->buttonStart->setText(QStringLiteral("Start streaming"));
return;
}
QFile file(QStringLiteral("clients.txt"));
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
return;
QTextStream in(&file);
while (!in.atEnd()) {
line = in.readLine();
if (line != QString())
{
QStringList arguments;
arguments << QStringLiteral("-controlservice") << QStringLiteral("-connect") << line;
QProcess *process = new QProcess();
process->start(command, arguments);
}
}
connected = true;
ui->buttonStart->setText(QStringLiteral("Disconnect"));
return;
}