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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
|
/*
SPDX-FileCopyrightText: 2007 Urs Wolfer <uwolfer@kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "vnchostpreferences.h"
#include "settings.h"
#include <QScreen>
#include <QWindow>
#include <QGuiApplication>
static const char quality_config_key[] = "quality";
static const char use_ssh_tunnel_config_key[] = "use_ssh_tunnel";
static const char use_ssh_tunnel_loopback_config_key[] = "use_ssh_tunnel_loopback";
static const char ssh_tunnel_port_config_key[] = "ssh_tunnel_port";
static const char ssh_tunnel_user_name_config_key[] = "ssh_tunnel_user_name";
static const char dont_copy_passwords_config_key[] = "dont_copy_passwords";
VncHostPreferences::VncHostPreferences(KConfigGroup configGroup, QObject *parent)
: HostPreferences(configGroup, parent)
{
}
VncHostPreferences::~VncHostPreferences()
{
}
QWidget* VncHostPreferences::createProtocolSpecificConfigPage()
{
QWidget *vncPage = new QWidget();
vncUi.setupUi(vncPage);
vncUi.kcfg_Quality->setCurrentIndex(quality() - 1);
vncUi.kcfg_Scaling->setChecked(windowedScale());
vncUi.kcfg_ScalingWidth->setValue(width());
vncUi.kcfg_ScalingHeight->setValue(height());
connect(vncUi.resolutionComboBox, SIGNAL(currentIndexChanged(int)), SLOT(updateScalingWidthHeight(int)));
connect(vncUi.kcfg_Scaling, SIGNAL(toggled(bool)), SLOT(updateScaling(bool)));
const QString resolutionString = QString::number(width()) + QLatin1Char('x') + QString::number(height());
const int resolutionIndex = vncUi.resolutionComboBox->findText(resolutionString, Qt::MatchContains);
vncUi.resolutionComboBox->setCurrentIndex((resolutionIndex == -1) ? vncUi.resolutionComboBox->count() - 1 : resolutionIndex);
updateScaling(windowedScale());
#ifdef LIBSSH_FOUND
connect(vncUi.use_ssh_tunnel, &QCheckBox::toggled, vncUi.ssh_groupBox, &QWidget::setVisible);
vncUi.ssh_groupBox->setVisible(useSshTunnel());
vncUi.use_ssh_tunnel->setChecked(useSshTunnel());
vncUi.use_loopback->setChecked(useSshTunnelLoopback());
vncUi.ssh_tunnel_port->setValue(sshTunnelPort());
vncUi.ssh_tunnel_user_name->setText(sshTunnelUserName());
#else
vncUi.ssh_groupBox->hide();
vncUi.use_ssh_tunnel->hide();
#endif
vncUi.dont_copy_passwords->setChecked(dontCopyPasswords());
return vncPage;
}
void VncHostPreferences::updateScalingWidthHeight(int index)
{
switch (index) {
case 0:
vncUi.kcfg_ScalingHeight->setValue(480);
vncUi.kcfg_ScalingWidth->setValue(640);
break;
case 1:
vncUi.kcfg_ScalingHeight->setValue(600);
vncUi.kcfg_ScalingWidth->setValue(800);
break;
case 2:
vncUi.kcfg_ScalingHeight->setValue(768);
vncUi.kcfg_ScalingWidth->setValue(1024);
break;
case 3:
vncUi.kcfg_ScalingHeight->setValue(1024);
vncUi.kcfg_ScalingWidth->setValue(1280);
break;
case 4:
vncUi.kcfg_ScalingHeight->setValue(1200);
vncUi.kcfg_ScalingWidth->setValue(1600);
break;
case 5: {
QWindow *window = vncUi.kcfg_ScalingWidth->window()->windowHandle();
QScreen *screen = window ? window->screen() : qGuiApp->primaryScreen();
const QSize size = screen->size() * screen->devicePixelRatio();
vncUi.kcfg_ScalingWidth->setValue(size.width());
vncUi.kcfg_ScalingHeight->setValue(size.height());
break;
}
case 6:
default:
break;
}
checkEnableCustomSize(index);
}
void VncHostPreferences::updateScaling(bool enabled)
{
vncUi.resolutionComboBox->setEnabled(enabled);
if(enabled) {
checkEnableCustomSize(vncUi.resolutionComboBox->currentIndex());
} else {
checkEnableCustomSize(-1);
}
}
void VncHostPreferences::checkEnableCustomSize(int index)
{
const bool enabled = (index == 6);
vncUi.kcfg_ScalingHeight->setEnabled(enabled);
vncUi.kcfg_ScalingWidth->setEnabled(enabled);
vncUi.heightLabel->setEnabled(enabled);
vncUi.widthLabel->setEnabled(enabled);
}
void VncHostPreferences::acceptConfig()
{
HostPreferences::acceptConfig();
setQuality((RemoteView::Quality)(vncUi.kcfg_Quality->currentIndex() + 1));
setWindowedScale(vncUi.kcfg_Scaling->isChecked());
if(vncUi.kcfg_Scaling->isChecked()) {
setHeight(vncUi.kcfg_ScalingHeight->value());
setWidth(vncUi.kcfg_ScalingWidth->value());
}
setUseSshTunnel(vncUi.use_ssh_tunnel->isChecked());
setUseSshTunnelLoopback(vncUi.use_loopback->isChecked());
setSshTunnelPort(vncUi.ssh_tunnel_port->value());
setSshTunnelUserName(vncUi.ssh_tunnel_user_name->text());
setDontCopyPasswords(vncUi.dont_copy_passwords->isChecked());
}
void VncHostPreferences::setQuality(RemoteView::Quality quality)
{
if (quality >= 0 && quality <= 3)
m_configGroup.writeEntry(quality_config_key, (int) quality);
}
RemoteView::Quality VncHostPreferences::quality()
{
return (RemoteView::Quality) m_configGroup.readEntry(quality_config_key, (int) Settings::quality() + 1);
}
bool VncHostPreferences::useSshTunnel() const
{
return m_configGroup.readEntry(use_ssh_tunnel_config_key, false);
}
void VncHostPreferences::setUseSshTunnel(bool useSshTunnel)
{
m_configGroup.writeEntry(use_ssh_tunnel_config_key, useSshTunnel);
}
bool VncHostPreferences::useSshTunnelLoopback() const
{
return m_configGroup.readEntry(use_ssh_tunnel_loopback_config_key, false);
}
void VncHostPreferences::setUseSshTunnelLoopback(bool useSshTunnelLoopback)
{
m_configGroup.writeEntry(use_ssh_tunnel_loopback_config_key, useSshTunnelLoopback);
}
int VncHostPreferences::sshTunnelPort() const
{
return m_configGroup.readEntry(ssh_tunnel_port_config_key, 22);
}
void VncHostPreferences::setSshTunnelPort(int port)
{
m_configGroup.writeEntry(ssh_tunnel_port_config_key, port);
}
QString VncHostPreferences::sshTunnelUserName() const
{
return m_configGroup.readEntry(ssh_tunnel_user_name_config_key, QString());
}
void VncHostPreferences::setSshTunnelUserName(const QString &userName)
{
m_configGroup.writeEntry(ssh_tunnel_user_name_config_key, userName);
}
bool VncHostPreferences::dontCopyPasswords() const
{
return m_configGroup.readEntry(dont_copy_passwords_config_key, false);
}
void VncHostPreferences::setDontCopyPasswords(bool dontCopyPasswords)
{
m_configGroup.writeEntry(dont_copy_passwords_config_key, dontCopyPasswords);
}
|