vnclauncher/dialog.cpp

73 linhas
2.4 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 = "tvnserver";
QStringList arguments;
if(connected)
{
arguments << "-controlservice" << "-disconnectall" << line;
QProcess *process = new QProcess();
process->start(command, arguments);
connected = false;
ui->buttonStart->setText("Start streaming");
return;
}
QFile file("clients.txt");
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
return;
QTextStream in(&file);
while (!in.atEnd()) {
line = in.readLine();
if (line != "")
{
arguments << "-controlservice" << "-connect" << line;
QProcess *process = new QProcess();
process->start(command, arguments);
}
}
connected = true;
ui->buttonStart->setText("Disconnect");
return;
}