Exemplo n.º 1
0
void VncView::updateImage(int x, int y, int w, int h)
{
//     kDebug(5011) << "got update" << width() << height();

    m_x = x;
    m_y = y;
    m_w = w;
    m_h = h;

    if (m_horizontalFactor != 1.0 || m_verticalFactor != 1.0) {
        // If the view is scaled, grow the update rectangle to avoid artifacts
        m_x-=1;
        m_y-=1;
        m_w+=2;
        m_h+=2;
    }

    m_frame = vncThread.image();

    if (!m_initDone) {
        if (!vncThread.username().isEmpty()) {
            m_url.setUserName(vncThread.username());
        }
        setAttribute(Qt::WA_StaticContents);
        setAttribute(Qt::WA_OpaquePaintEvent);
        installEventFilter(this);

        setCursor(((m_dotCursorState == CursorOn) || m_forceLocalCursor) ? localDotCursor() : Qt::BlankCursor);

        setMouseTracking(true); // get mouse events even when there is no mousebutton pressed
        setFocusPolicy(Qt::WheelFocus);
        setStatus(Connected);
        emit connected();
        
        if (m_scale) {
#ifndef QTONLY
            kDebug(5011) << "Setting initial size w:" <<m_hostPreferences->width() << " h:" << m_hostPreferences->height();
            emit framebufferSizeChanged(m_hostPreferences->width(), m_hostPreferences->height());
            scaleResize(m_hostPreferences->width(), m_hostPreferences->height());
            kDebug() << "m_frame.size():" << m_frame.size() << "size()" << size();
#else
//TODO: qtonly alternative
#endif
        }

        m_initDone = true;

#ifndef QTONLY
        if (m_hostPreferences->walletSupport()) {
            saveWalletPassword(vncThread.password());
        }
#endif
    }

    if ((y == 0 && x == 0) && (m_frame.size() != size())) {
        kDebug(5011) << "Updating framebuffer size";
        if (m_scale) {
            setMaximumSize(QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX));
            if (parentWidget())
                scaleResize(parentWidget()->width(), parentWidget()->height());
        } else {
            kDebug(5011) << "Resizing: " << m_frame.width() << m_frame.height();
            resize(m_frame.width(), m_frame.height());
            setMaximumSize(m_frame.width(), m_frame.height()); //This is a hack to force Qt to center the view in the scroll area
            setMinimumSize(m_frame.width(), m_frame.height());
            emit framebufferSizeChanged(m_frame.width(), m_frame.height());
        }
    }

    m_repaint = true;
    repaint(qRound(m_x * m_horizontalFactor), qRound(m_y * m_verticalFactor), qRound(m_w * m_horizontalFactor), qRound(m_h * m_verticalFactor));
    m_repaint = false;
}
Exemplo n.º 2
0
Arquivo: rdpview.cpp Projeto: KDE/krdc
bool RdpView::start()
{
    m_containerWidget->show();

    if (m_url.userName().isEmpty()) {
        QString userName;
        bool ok = false;

        userName = QInputDialog::getText(this, i18n("Enter Username"),
                                         i18n("Please enter the username you would like to use for login."),
                                         QLineEdit::Normal, Settings::defaultRdpUserName(), &ok);

        if (ok) {
            m_url.setUserName(userName);
        }
    }

    if (!m_url.userName().isEmpty()) {
        const bool useLdapLogin = Settings::recognizeLdapLogins() && m_url.userName().contains(QLatin1Char('\\'));
        qCDebug(KRDC) << "Is LDAP login:"******"Access to the system requires a password."));
            if (dialog.exec() == KPasswordDialog::Accepted) {
                m_url.setPassword(dialog.password());

                if (m_hostPreferences->walletSupport()) {
                    saveWalletPassword(dialog.password(), useLdapLogin);
                }
            }
        }
    }

    // Check the version of FreeRDP so we can use pre-1.1 switches if needed
    QProcess *xfreeRDPVersionCheck = new QProcess(this);
    xfreeRDPVersionCheck->start(QStringLiteral("xfreerdp"), QStringList(QStringLiteral("--version")));
    xfreeRDPVersionCheck->waitForFinished();
    QString versionOutput = QString::fromUtf8(xfreeRDPVersionCheck->readAllStandardOutput().constData());
    xfreeRDPVersionCheck->deleteLater();

    m_process = new QProcess(m_container);

    QStringList arguments;

    int width, height;
    if (m_hostPreferences->width() > 0) {
        width = m_hostPreferences->width();
        height = m_hostPreferences->height();
    } else {
        width = this->parentWidget()->size().width();
        height = this->parentWidget()->size().height();
    }
    m_containerWidget->setFixedWidth(width);
    m_containerWidget->setFixedHeight(height);
    setMaximumSize(width, height);
    if (versionOutput.contains(QLatin1String(" 1.0"))) {
        qCDebug(KRDC) << "Use FreeRDP 1.0 compatible arguments";

        arguments << QStringLiteral("-g") << QString::number(width) + QLatin1Char('x') + QString::number(height);

        arguments << QStringLiteral("-k") << keymapToXfreerdp(m_hostPreferences->keyboardLayout());

        if (!m_url.userName().isEmpty()) {
            // if username contains a domain, it needs to be set with another parameter
            if (m_url.userName().contains(QLatin1Char('\\'))) {
                const QStringList splittedName = m_url.userName().split(QLatin1Char('\\'));
                arguments << QStringLiteral("-d") << splittedName.at(0);
                arguments << QStringLiteral("-u") << splittedName.at(1);
            } else {
                arguments << QStringLiteral("-u") << m_url.userName();
            }
        } else {
            arguments << QStringLiteral("-u") << QStringLiteral("");
        }

        arguments << QStringLiteral("-D");  // request the window has no decorations
        arguments << QStringLiteral("-X") << QString::number(m_container->winId());
        arguments << QStringLiteral("-a") << QString::number((m_hostPreferences->colorDepth() + 1) * 8);

        switch (m_hostPreferences->sound()) {
        case 1:
            arguments << QStringLiteral("-o");
            break;
        case 0:
            arguments << QStringLiteral("--plugin") << QStringLiteral("rdpsnd");
            break;
        case 2:
        default:
            break;
        }

        if (!m_hostPreferences->shareMedia().isEmpty()) {
            QStringList shareMedia;
            shareMedia << QStringLiteral("--plugin") << QStringLiteral("rdpdr")
                       << QStringLiteral("--data") << QStringLiteral("disk:media:")
                       + m_hostPreferences->shareMedia() << QStringLiteral("--");
            arguments += shareMedia;
        }

        QString performance;
        switch (m_hostPreferences->performance()) {
        case 0:
            performance = QLatin1Char('m');
            break;
        case 1:
            performance = QLatin1Char('b');
            break;
        case 2:
            performance = QLatin1Char('l');
            break;
        default:
            break;
        }

        arguments << QStringLiteral("-x") << performance;

        if (m_hostPreferences->console()) {
            arguments << QStringLiteral("-0");
        }

        if (m_hostPreferences->remoteFX()) {
            arguments << QStringLiteral("--rfx");
        }

        if (!m_hostPreferences->extraOptions().isEmpty()) {
            const QStringList additionalArguments = KShell::splitArgs(m_hostPreferences->extraOptions());
            arguments += additionalArguments;
        }

        // krdc has no support for certificate management yet; it would not be possbile to connect to any host:
        // "The host key for example.com has changed" ...
        // "Add correct host key in ~/.freerdp/known_hosts to get rid of this message."
        arguments << QStringLiteral("--ignore-certificate");

        // clipboard sharing is activated in KRDC; user can disable it at runtime
        arguments << QStringLiteral("--plugin") << QStringLiteral("cliprdr");

        arguments << QStringLiteral("-t") << QString::number(m_port);
        arguments << m_host;

        qCDebug(KRDC) << "Starting xfreerdp with arguments: " << arguments.join(QStringLiteral(" "));

        arguments.removeLast(); // host must be last, remove and re-add it after the password
        if (!m_url.password().isNull())
            arguments << QStringLiteral("-p") << m_url.password();
        arguments << m_host;

    } else {
        qCDebug(KRDC) << "Use FreeRDP 1.1+ compatible arguments";

        arguments << QStringLiteral("-decorations");
        arguments << QStringLiteral("/w:") + QString::number(width);
        arguments << QStringLiteral("/h:") + QString::number(height);

        arguments << QStringLiteral("/kbd:") + keymapToXfreerdp(m_hostPreferences->keyboardLayout());

        if (!m_url.userName().isEmpty()) {
            // if username contains a domain, it needs to be set with another parameter
            if (m_url.userName().contains(QLatin1Char('\\'))) {
                const QStringList splittedName = m_url.userName().split(QLatin1Char('\\'));
                arguments << QStringLiteral("/d:") + splittedName.at(0);
                arguments << QStringLiteral("/u:") + splittedName.at(1);
            } else {
                arguments << QStringLiteral("/u:") + m_url.userName();
            }
        } else {
            arguments << QStringLiteral("/u:");
        }

        arguments << QStringLiteral("/parent-window:") + QString::number(m_container->winId());
        arguments << QStringLiteral("/bpp:") + QString::number((m_hostPreferences->colorDepth() + 1) * 8);

        arguments << QStringLiteral("/audio-mode:") + QString::number(m_hostPreferences->sound());
        switch (m_hostPreferences->soundSystem()) {
        case 0:
            arguments << QStringLiteral("/sound:sys:alsa");
            break;
        case 1:
            arguments << QStringLiteral("/sound:sys:pulse");
            break;
        default:
            break;
        }

        if (!m_hostPreferences->shareMedia().isEmpty()) {
            QStringList shareMedia;
            shareMedia << QStringLiteral("/drive:media,") + m_hostPreferences->shareMedia();
            arguments += shareMedia;
        }

        QString performance;
        switch (m_hostPreferences->performance()) {
        case 0:
            performance = QStringLiteral("modem");
            break;
        case 1:
            performance = QStringLiteral("broadband");
            break;
        case 2:
            performance = QStringLiteral("lan");
            break;
        default:
            break;
        }

        arguments << QStringLiteral("/network:") + performance;

        if (m_hostPreferences->console()) {
            arguments << QStringLiteral("/admin");
        }

        if (m_hostPreferences->remoteFX()) {
            arguments << QStringLiteral("/rfx");
        }

        if (!m_hostPreferences->extraOptions().isEmpty()) {
            const QStringList additionalArguments = KShell::splitArgs(m_hostPreferences->extraOptions());
            arguments += additionalArguments;
        }

        // krdc has no support for certificate management yet; it would not be possbile to connect to any host:
        // "The host key for example.com has changed" ...
        // "Add correct host key in ~/.freerdp/known_hosts to get rid of this message."
        arguments << QStringLiteral("/cert-ignore");

        // clipboard sharing is activated in KRDC; user can disable it at runtime
        arguments << QStringLiteral("+clipboard");

        arguments << QStringLiteral("/port:") + QString::number(m_port);
        arguments << QStringLiteral("/v:") + m_host;

        qCDebug(KRDC) << "Starting xfreerdp with arguments: " << arguments.join(QStringLiteral(" "));

        //avoid printing the password in debug
        if (!m_url.password().isNull()) {
            arguments << QStringLiteral("/p:") + m_url.password();
        }
    }

    setStatus(Connecting);

    connect(m_process, SIGNAL(error(QProcess::ProcessError)), SLOT(processError(QProcess::ProcessError)));
    connect(m_process, SIGNAL(readyReadStandardError()), SLOT(receivedStandardError()));
    connect(m_process, SIGNAL(readyReadStandardOutput()), SLOT(receivedStandardOutput()));
    connect(m_process, SIGNAL(finished(int, QProcess::ExitStatus)), SLOT(connectionClosed()));
    connect(m_process, SIGNAL(started()), SLOT(connectionOpened()));

    m_process->start(QStringLiteral("xfreerdp"), arguments);

    return true;
}