| 1 | // -*- c-basic-offset: 2 -*- |
|---|
| 2 | /* |
|---|
| 3 | * This file is part of Licq, an instant messaging client for UNIX. |
|---|
| 4 | * Copyright (C) 2007 Licq developers |
|---|
| 5 | * |
|---|
| 6 | * Licq is free software; you can redistribute it and/or modify |
|---|
| 7 | * it under the terms of the GNU General Public License as published by |
|---|
| 8 | * the Free Software Foundation; either version 2 of the License, or |
|---|
| 9 | * (at your option) any later version. |
|---|
| 10 | * |
|---|
| 11 | * Licq is distributed in the hope that it will be useful, |
|---|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 14 | * GNU General Public License for more details. |
|---|
| 15 | * |
|---|
| 16 | * You should have received a copy of the GNU General Public License |
|---|
| 17 | * along with Licq; if not, write to the Free Software |
|---|
| 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
|---|
| 19 | */ |
|---|
| 20 | |
|---|
| 21 | #include "network.h" |
|---|
| 22 | |
|---|
| 23 | #include "config.h" |
|---|
| 24 | |
|---|
| 25 | #include <QCheckBox> |
|---|
| 26 | #include <QComboBox> |
|---|
| 27 | #include <QGridLayout> |
|---|
| 28 | #include <QGroupBox> |
|---|
| 29 | #include <QLabel> |
|---|
| 30 | #include <QLineEdit> |
|---|
| 31 | #include <QSpinBox> |
|---|
| 32 | #include <QVBoxLayout> |
|---|
| 33 | |
|---|
| 34 | #include <licq_constants.h> |
|---|
| 35 | #include <licq_icqd.h> |
|---|
| 36 | |
|---|
| 37 | #include "settingsdlg.h" |
|---|
| 38 | |
|---|
| 39 | using namespace LicqQtGui; |
|---|
| 40 | /* TRANSLATOR LicqQtGui::Settings::Network */ |
|---|
| 41 | |
|---|
| 42 | Settings::Network::Network(SettingsDlg* parent) |
|---|
| 43 | : QObject(parent) |
|---|
| 44 | { |
|---|
| 45 | parent->addPage(SettingsDlg::NetworkPage, createPageNetwork(parent), |
|---|
| 46 | tr("Network")); |
|---|
| 47 | parent->addPage(SettingsDlg::IcqPage, createPageIcq(parent), |
|---|
| 48 | tr("ICQ"), SettingsDlg::NetworkPage); |
|---|
| 49 | |
|---|
| 50 | load(); |
|---|
| 51 | } |
|---|
| 52 | |
|---|
| 53 | QWidget* Settings::Network::createPageNetwork(QWidget* parent) |
|---|
| 54 | { |
|---|
| 55 | QWidget* w = new QWidget(parent); |
|---|
| 56 | myPageNetworkLayout = new QVBoxLayout(w); |
|---|
| 57 | myPageNetworkLayout->setContentsMargins(0, 0, 0, 0); |
|---|
| 58 | |
|---|
| 59 | myFirewallBox = new QGroupBox(tr("Firewall")); |
|---|
| 60 | myFirewallLayout = new QGridLayout(myFirewallBox); |
|---|
| 61 | |
|---|
| 62 | myFirewallCheck = new QCheckBox(tr("I am behind a firewall")); |
|---|
| 63 | connect(myFirewallCheck, SIGNAL(toggled(bool)), SLOT(useFirewallToggled(bool))); |
|---|
| 64 | myFirewallLayout->addWidget(myFirewallCheck, 0, 0); |
|---|
| 65 | |
|---|
| 66 | myTcpEnabledCheck = new QCheckBox(tr("I can receive direct connections")); |
|---|
| 67 | connect(myTcpEnabledCheck, SIGNAL(toggled(bool)), SLOT(usePortRangeToggled(bool))); |
|---|
| 68 | myFirewallLayout->addWidget(myTcpEnabledCheck, 1, 0); |
|---|
| 69 | |
|---|
| 70 | QHBoxLayout* myPortsInLayout = new QHBoxLayout(); |
|---|
| 71 | myPortsInLayout->addStretch(1); |
|---|
| 72 | myPortsInLabel = new QLabel(tr("Port range:")); |
|---|
| 73 | myPortsInLabel->setToolTip(tr("TCP port range for incoming connections.")); |
|---|
| 74 | myPortsInLayout->addWidget(myPortsInLabel); |
|---|
| 75 | myPortLowSpin = new QSpinBox(); |
|---|
| 76 | myPortLowSpin->setRange(0, 0xFFFF); |
|---|
| 77 | myPortLowSpin->setSpecialValueText(tr("Auto")); |
|---|
| 78 | myPortsInLabel->setBuddy(myPortLowSpin); |
|---|
| 79 | myPortsInLayout->addWidget(myPortLowSpin); |
|---|
| 80 | myPortsIn2Label = new QLabel(tr("to")); |
|---|
| 81 | myPortsInLayout->addWidget(myPortsIn2Label); |
|---|
| 82 | myPortHighSpin = new QSpinBox(); |
|---|
| 83 | myPortHighSpin->setRange(0, 0xFFFF); |
|---|
| 84 | myPortHighSpin->setSpecialValueText(tr("Auto")); |
|---|
| 85 | myPortsIn2Label->setBuddy(myPortHighSpin); |
|---|
| 86 | myPortsInLayout->addWidget(myPortHighSpin); |
|---|
| 87 | myFirewallLayout->addLayout(myPortsInLayout, 1, 1); |
|---|
| 88 | |
|---|
| 89 | |
|---|
| 90 | myProxyBox = new QGroupBox(tr("Proxy")); |
|---|
| 91 | myProxyLayout = new QGridLayout(myProxyBox); |
|---|
| 92 | |
|---|
| 93 | myProxyEnabledCheck = new QCheckBox(tr("Use proxy server")); |
|---|
| 94 | connect(myProxyEnabledCheck, SIGNAL(toggled(bool)), SLOT(useProxyToggled(bool))); |
|---|
| 95 | myProxyLayout->addWidget(myProxyEnabledCheck, 0, 0); |
|---|
| 96 | |
|---|
| 97 | QHBoxLayout* myProxyTypeLayout = new QHBoxLayout(); |
|---|
| 98 | myProxyTypeLayout->addStretch(1); |
|---|
| 99 | myProxyTypeLabel = new QLabel(tr("Proxy type:")); |
|---|
| 100 | myProxyTypeLayout->addWidget(myProxyTypeLabel); |
|---|
| 101 | myProxyTypeCombo = new QComboBox(); |
|---|
| 102 | myProxyTypeCombo->setFixedWidth(80); |
|---|
| 103 | myProxyTypeCombo->addItem(tr("HTTPS")); |
|---|
| 104 | myProxyTypeLabel->setBuddy(myProxyTypeCombo); |
|---|
| 105 | myProxyTypeLayout->addWidget(myProxyTypeCombo); |
|---|
| 106 | myProxyLayout->addLayout(myProxyTypeLayout, 0, 1); |
|---|
| 107 | |
|---|
| 108 | myProxyHostLabel = new QLabel(tr("Proxy server:")); |
|---|
| 109 | myProxyLayout->addWidget(myProxyHostLabel, 1, 0); |
|---|
| 110 | |
|---|
| 111 | myProxyHostEdit = new QLineEdit(); |
|---|
| 112 | myProxyHostLabel->setBuddy(myProxyHostEdit); |
|---|
| 113 | myProxyLayout->addWidget(myProxyHostEdit, 1, 1); |
|---|
| 114 | |
|---|
| 115 | myProxyPortLabel = new QLabel(tr("Proxy server port:")); |
|---|
| 116 | myProxyLayout->addWidget(myProxyPortLabel, 2, 0); |
|---|
| 117 | |
|---|
| 118 | myProxyPortSpin = new QSpinBox(); |
|---|
| 119 | myProxyPortSpin->setRange(0, 0xFFFF); |
|---|
| 120 | myProxyPortLabel->setBuddy(myProxyPortSpin); |
|---|
| 121 | myProxyLayout->addWidget(myProxyPortSpin, 2, 1); |
|---|
| 122 | |
|---|
| 123 | myProxyAuthEnabledCheck = new QCheckBox(tr("Use authorization")); |
|---|
| 124 | myProxyLayout->addWidget(myProxyAuthEnabledCheck, 3, 0); |
|---|
| 125 | |
|---|
| 126 | myProxyLoginLabel = new QLabel(tr("Username:")); |
|---|
| 127 | myProxyLayout->addWidget(myProxyLoginLabel, 4, 0); |
|---|
| 128 | |
|---|
| 129 | myProxyLoginEdit = new QLineEdit(); |
|---|
| 130 | myProxyLoginLabel->setBuddy(myProxyLoginEdit); |
|---|
| 131 | myProxyLayout->addWidget(myProxyLoginEdit, 4, 1); |
|---|
| 132 | |
|---|
| 133 | myProxyPasswdLabel = new QLabel(tr("Password:")); |
|---|
| 134 | myProxyLayout->addWidget(myProxyPasswdLabel, 5, 0); |
|---|
| 135 | |
|---|
| 136 | myProxyPasswdEdit = new QLineEdit(); |
|---|
| 137 | myProxyPasswdEdit->setEchoMode(QLineEdit::Password); |
|---|
| 138 | myProxyPasswdLabel->setBuddy(myProxyPasswdEdit); |
|---|
| 139 | myProxyLayout->addWidget(myProxyPasswdEdit, 5, 1); |
|---|
| 140 | |
|---|
| 141 | connect(myProxyAuthEnabledCheck, SIGNAL(toggled(bool)), myProxyLoginEdit, SLOT(setEnabled(bool))); |
|---|
| 142 | connect(myProxyAuthEnabledCheck, SIGNAL(toggled(bool)), myProxyPasswdEdit, SLOT(setEnabled(bool))); |
|---|
| 143 | |
|---|
| 144 | |
|---|
| 145 | myPageNetworkLayout->addWidget(myFirewallBox); |
|---|
| 146 | myPageNetworkLayout->addWidget(myProxyBox); |
|---|
| 147 | myPageNetworkLayout->addStretch(1); |
|---|
| 148 | |
|---|
| 149 | return w; |
|---|
| 150 | } |
|---|
| 151 | |
|---|
| 152 | QWidget* Settings::Network::createPageIcq(QWidget* parent) |
|---|
| 153 | { |
|---|
| 154 | QWidget* w = new QWidget(parent); |
|---|
| 155 | myPageIcqLayout = new QVBoxLayout(w); |
|---|
| 156 | myPageIcqLayout->setContentsMargins(0, 0, 0, 0); |
|---|
| 157 | |
|---|
| 158 | myIcqServerBox = new QGroupBox(tr("Server Settings")); |
|---|
| 159 | myIcqServerLayout = new QGridLayout(myIcqServerBox); |
|---|
| 160 | |
|---|
| 161 | |
|---|
| 162 | myIcqServerLabel = new QLabel(tr("ICQ server:")); |
|---|
| 163 | myIcqServerLayout->addWidget(myIcqServerLabel, 0, 0); |
|---|
| 164 | |
|---|
| 165 | myIcqServerEdit = new QLineEdit(); |
|---|
| 166 | myIcqServerLabel->setBuddy(myIcqServerEdit); |
|---|
| 167 | myIcqServerLayout->addWidget(myIcqServerEdit, 0, 1); |
|---|
| 168 | |
|---|
| 169 | myIcqServerPortLabel = new QLabel(tr("ICQ server port:")); |
|---|
| 170 | myIcqServerLayout->addWidget(myIcqServerPortLabel, 1, 0); |
|---|
| 171 | |
|---|
| 172 | myIcqServerPortSpin = new QSpinBox(); |
|---|
| 173 | myIcqServerPortSpin->setRange(0, 0xFFFF); |
|---|
| 174 | myIcqServerPortLabel->setBuddy(myIcqServerPortSpin); |
|---|
| 175 | myIcqServerLayout->addWidget(myIcqServerPortSpin, 1, 1); |
|---|
| 176 | |
|---|
| 177 | |
|---|
| 178 | myIcqConnectionBox = new QGroupBox(tr("Connection")); |
|---|
| 179 | myIcqConnectionLayout = new QVBoxLayout(myIcqConnectionBox); |
|---|
| 180 | |
|---|
| 181 | myReconnectAfterUinClashCheck = new QCheckBox(tr("Reconnect after Uin clash")); |
|---|
| 182 | myReconnectAfterUinClashCheck->setToolTip(tr("Licq can reconnect you when you got " |
|---|
| 183 | "disconnected because your Uin was used " |
|---|
| 184 | "from another location. Check this if you " |
|---|
| 185 | "want Licq to reconnect automatically.")); |
|---|
| 186 | |
|---|
| 187 | myIcqConnectionLayout->addWidget(myReconnectAfterUinClashCheck); |
|---|
| 188 | |
|---|
| 189 | |
|---|
| 190 | myPageIcqLayout->addWidget(myIcqServerBox); |
|---|
| 191 | myPageIcqLayout->addWidget(myIcqConnectionBox); |
|---|
| 192 | myPageIcqLayout->addStretch(1); |
|---|
| 193 | |
|---|
| 194 | return w; |
|---|
| 195 | } |
|---|
| 196 | |
|---|
| 197 | void Settings::Network::useFirewallToggled(bool useFirewall) |
|---|
| 198 | { |
|---|
| 199 | myTcpEnabledCheck->setEnabled(useFirewall); |
|---|
| 200 | usePortRangeToggled(useFirewall && myTcpEnabledCheck->isChecked()); |
|---|
| 201 | } |
|---|
| 202 | |
|---|
| 203 | void Settings::Network::usePortRangeToggled(bool usePortRange) |
|---|
| 204 | { |
|---|
| 205 | myPortLowSpin->setEnabled(usePortRange); |
|---|
| 206 | myPortHighSpin->setEnabled(usePortRange); |
|---|
| 207 | } |
|---|
| 208 | |
|---|
| 209 | void Settings::Network::useProxyToggled(bool useProxy) |
|---|
| 210 | { |
|---|
| 211 | if (useProxy) |
|---|
| 212 | { |
|---|
| 213 | myProxyTypeCombo->setEnabled(true); |
|---|
| 214 | myProxyHostEdit->setEnabled(true); |
|---|
| 215 | myProxyPortSpin->setEnabled(true); |
|---|
| 216 | myProxyAuthEnabledCheck->setEnabled(true); |
|---|
| 217 | if (myProxyAuthEnabledCheck->isChecked()) |
|---|
| 218 | { |
|---|
| 219 | myProxyLoginEdit->setEnabled(true); |
|---|
| 220 | myProxyPasswdEdit->setEnabled(true); |
|---|
| 221 | } |
|---|
| 222 | myIcqServerPortSpin->setValue(DEFAULT_SSL_PORT); |
|---|
| 223 | } |
|---|
| 224 | else |
|---|
| 225 | { |
|---|
| 226 | myProxyTypeCombo->setEnabled(false); |
|---|
| 227 | myProxyHostEdit->setEnabled(false); |
|---|
| 228 | myProxyPortSpin->setEnabled(false); |
|---|
| 229 | myProxyAuthEnabledCheck->setEnabled(false); |
|---|
| 230 | myProxyLoginEdit->setEnabled(false); |
|---|
| 231 | myProxyPasswdEdit->setEnabled(false); |
|---|
| 232 | myIcqServerPortSpin->setValue(DEFAULT_SERVER_PORT); |
|---|
| 233 | } |
|---|
| 234 | } |
|---|
| 235 | |
|---|
| 236 | void Settings::Network::load() |
|---|
| 237 | { |
|---|
| 238 | myIcqServerEdit->setText(QString(gLicqDaemon->ICQServer())); |
|---|
| 239 | myFirewallCheck->setChecked(gLicqDaemon->Firewall()); |
|---|
| 240 | myTcpEnabledCheck->setChecked(gLicqDaemon->TCPEnabled()); |
|---|
| 241 | myPortLowSpin->setValue(gLicqDaemon->TCPPortsLow()); |
|---|
| 242 | myPortHighSpin->setValue(gLicqDaemon->TCPPortsHigh()); |
|---|
| 243 | |
|---|
| 244 | if (!gLicqDaemon->Firewall()) |
|---|
| 245 | { |
|---|
| 246 | myTcpEnabledCheck->setEnabled(false); |
|---|
| 247 | myPortLowSpin->setEnabled(false); |
|---|
| 248 | myPortHighSpin->setEnabled(false); |
|---|
| 249 | } |
|---|
| 250 | else |
|---|
| 251 | { |
|---|
| 252 | if (!gLicqDaemon->TCPEnabled()) |
|---|
| 253 | { |
|---|
| 254 | myPortLowSpin->setEnabled(false); |
|---|
| 255 | myPortHighSpin->setEnabled(false); |
|---|
| 256 | } |
|---|
| 257 | } |
|---|
| 258 | |
|---|
| 259 | myProxyEnabledCheck->setChecked(gLicqDaemon->ProxyEnabled()); |
|---|
| 260 | myProxyTypeCombo->setCurrentIndex(gLicqDaemon->ProxyType() - 1); |
|---|
| 261 | myProxyHostEdit->setText(QString(gLicqDaemon->ProxyHost())); |
|---|
| 262 | myProxyPortSpin->setValue(gLicqDaemon->ProxyPort()); |
|---|
| 263 | myProxyAuthEnabledCheck->setChecked(gLicqDaemon->ProxyAuthEnabled()); |
|---|
| 264 | myProxyLoginEdit->setText(QString(gLicqDaemon->ProxyLogin())); |
|---|
| 265 | myProxyPasswdEdit->setText(QString(gLicqDaemon->ProxyPasswd())); |
|---|
| 266 | |
|---|
| 267 | // Set server port after myProxyEnabledCheck as it will trigger useProxyToggled |
|---|
| 268 | // which overwrites server port field. |
|---|
| 269 | myIcqServerPortSpin->setValue(gLicqDaemon->ICQServerPort()); |
|---|
| 270 | |
|---|
| 271 | myReconnectAfterUinClashCheck->setChecked(gLicqDaemon->ReconnectAfterUinClash()); |
|---|
| 272 | |
|---|
| 273 | if (!gLicqDaemon->ProxyEnabled()) |
|---|
| 274 | { |
|---|
| 275 | myProxyTypeCombo->setEnabled(false); |
|---|
| 276 | myProxyHostEdit->setEnabled(false); |
|---|
| 277 | myProxyPortSpin->setEnabled(false); |
|---|
| 278 | myProxyAuthEnabledCheck->setEnabled(false); |
|---|
| 279 | myProxyLoginEdit->setEnabled(false); |
|---|
| 280 | myProxyPasswdEdit->setEnabled(false); |
|---|
| 281 | } else if (!gLicqDaemon->ProxyAuthEnabled()) |
|---|
| 282 | { |
|---|
| 283 | myProxyLoginEdit->setEnabled(false); |
|---|
| 284 | myProxyPasswdEdit->setEnabled(false); |
|---|
| 285 | } |
|---|
| 286 | } |
|---|
| 287 | |
|---|
| 288 | void Settings::Network::apply() |
|---|
| 289 | { |
|---|
| 290 | gLicqDaemon->SetICQServer(myIcqServerEdit->text().toLocal8Bit()); |
|---|
| 291 | gLicqDaemon->SetICQServerPort(myIcqServerPortSpin->value()); |
|---|
| 292 | gLicqDaemon->SetTCPPorts(myPortLowSpin->value(), myPortHighSpin->value()); |
|---|
| 293 | gLicqDaemon->SetTCPEnabled(myTcpEnabledCheck->isChecked()); |
|---|
| 294 | gLicqDaemon->SetFirewall(myFirewallCheck->isChecked()); |
|---|
| 295 | gLicqDaemon->SetProxyEnabled(myProxyEnabledCheck->isChecked()); |
|---|
| 296 | gLicqDaemon->SetProxyType(myProxyTypeCombo->currentIndex() + 1); |
|---|
| 297 | gLicqDaemon->SetProxyHost(myProxyHostEdit->text().toLocal8Bit()); |
|---|
| 298 | gLicqDaemon->SetProxyPort(myProxyPortSpin->value()); |
|---|
| 299 | gLicqDaemon->SetProxyAuthEnabled(myProxyAuthEnabledCheck->isChecked()); |
|---|
| 300 | gLicqDaemon->SetProxyLogin(myProxyLoginEdit->text().toLocal8Bit()); |
|---|
| 301 | gLicqDaemon->SetProxyPasswd(myProxyPasswdEdit->text().toLocal8Bit()); |
|---|
| 302 | |
|---|
| 303 | gLicqDaemon->setReconnectAfterUinClash(myReconnectAfterUinClashCheck->isChecked()); |
|---|
| 304 | } |
|---|