9 #include <QGuiApplication>
13 #include "../util/util.h"
14 #include "../../shared/util.h"
39 QString ret(len, Qt::Uninitialized);
40 for (
int i = 0; i < len; ++i)
41 ret[i] = QChar(43 +
slxrand() % 80);
49 static void msleep(
unsigned long msecs) { QThread::msleep(msecs); }
64 QDir::root().mkpath(dir.absolutePath());
65 QString str(dir.absoluteFilePath(
"vncpass"));
66 QSharedPointer<QFile> file = QSharedPointer<QFile>(
new QFile(str));
70 file->open(QIODevice::WriteOnly);
90 if (!pwhandle->isOpen()) {
93 if (!pwhandle->isOpen()) {
94 qDebug() <<
"Could not open " << pwhandle->fileName() <<
" for writing";
98 pwhandle->setPermissions(QFile::ReadOwner | QFile::WriteOwner);
99 pwhandle->write(
_rwpass.toUtf8().constData());
100 pwhandle->write(
"\n");
101 pwhandle->write(
_ropass.toUtf8().constData());
102 pwhandle->write(
"\n");
109 connect(
_process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
114 args <<
"-display" <<
":0";
115 args <<
"-passwdfile" << (QStringLiteral(
"rm:") + pwhandle->fileName());
118 args <<
"-autoport" << QString::number(54112);
121 const QRect primaryRect = QGuiApplication::primaryScreen()->geometry();
126 rect = QString::number(primaryRect.width())
127 +
"x" + QString::number(primaryRect.height())
128 +
"+" + QString::number(primaryRect.x())
129 +
"+" + QString::number(primaryRect.y());
132 qDebug() <<
"Arguments are: " << args;
133 _process->start(
"x11vnc", args, QIODevice::ReadOnly);
147 qDebug(
"Stopping old VNC server.");
153 process->terminate();
154 for (
int i = 0; i < 10 && process->state() != QProcess::NotRunning; ++i)
156 if (process->state() == QProcess::Running)
158 for (
int i = 0; i < 10 && process->state() != QProcess::NotRunning; ++i)
160 process->deleteLater();
193 qDebug(
"VncServer::onStdOut() called in bad state.");
196 QByteArray data(
_process->readAllStandardOutput());
197 qDebug() <<
"x11vnc: " << data;
199 const int pos = data.indexOf(
"PORT=", 0);
201 _port = atoi(data.constData() + pos + 5);
219 qDebug(
"VncServer::onStdErr() called in bad state.");
void stop()
VncServer::stop.
void started(int port, const QString &ropass, const QString &rwpass)
void onStdOut()
VncServer::onStdOut.
void onFinished(int exitCode, QProcess::ExitStatus exitStatus)
VncServer::onFinished.
~VncServer() override
VncServer::~VncServer.
Ugly hack to get an el-cheapo platform independent sleep.
void start()
VncServer::start.
static QSharedPointer< QFile > createPwFile(const QDir &dir)
void timerEvent(QTimerEvent *event) override
Timer event, currently only used to assume VNC server setup failed after 3 seconds...
void onStdErr()
VncServer::onStdErr.
static QString makePassword(int len=10)
makePassword
void onError(QProcess::ProcessError error)
VncServer::onError.
static void msleep(unsigned long msecs)
VncServer()
VncServer::VncServer.
static VncServer * instance()
VncServer::instance.