2011-12-06 20:27:09 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
2013-02-04 09:29:51 +00:00
|
|
|
# connection.py - connection window
|
|
|
|
#
|
2022-01-12 22:52:09 +00:00
|
|
|
# Copyright (C) 2011-2022 Sébastien Helleu <flashcode@flashtux.org>
|
2011-12-06 20:27:09 +00:00
|
|
|
#
|
|
|
|
# This file is part of QWeeChat, a Qt remote GUI for WeeChat.
|
|
|
|
#
|
|
|
|
# QWeeChat 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.
|
|
|
|
#
|
|
|
|
# QWeeChat 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 QWeeChat. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
|
2021-11-13 18:50:33 +00:00
|
|
|
"""Connection window."""
|
|
|
|
|
2024-02-08 20:37:58 +00:00
|
|
|
from qtpy import QtGui, QtWidgets
|
2011-12-06 20:27:09 +00:00
|
|
|
|
|
|
|
|
2021-06-01 04:02:25 +00:00
|
|
|
class ConnectionDialog(QtWidgets.QDialog):
|
2014-02-07 12:03:15 +00:00
|
|
|
"""Connection window."""
|
2011-12-06 20:27:09 +00:00
|
|
|
|
|
|
|
def __init__(self, values, *args):
|
2021-06-01 04:02:25 +00:00
|
|
|
super().__init__(*args)
|
2011-12-06 20:27:09 +00:00
|
|
|
self.values = values
|
|
|
|
self.setModal(True)
|
2021-11-14 17:40:26 +00:00
|
|
|
self.setWindowTitle('Connect to WeeChat')
|
2011-12-06 20:27:09 +00:00
|
|
|
|
2021-06-01 04:02:25 +00:00
|
|
|
grid = QtWidgets.QGridLayout()
|
2011-12-06 20:27:09 +00:00
|
|
|
grid.setSpacing(10)
|
|
|
|
|
|
|
|
self.fields = {}
|
2021-11-14 17:40:26 +00:00
|
|
|
focus = None
|
|
|
|
|
2021-11-14 17:54:48 +00:00
|
|
|
# hostname
|
|
|
|
grid.addWidget(QtWidgets.QLabel('<b>Hostname</b>'), 0, 0)
|
2021-11-14 17:40:26 +00:00
|
|
|
line_edit = QtWidgets.QLineEdit()
|
|
|
|
line_edit.setFixedWidth(200)
|
2021-11-14 17:54:48 +00:00
|
|
|
value = self.values.get('hostname', '')
|
2021-11-14 17:40:26 +00:00
|
|
|
line_edit.insert(value)
|
|
|
|
grid.addWidget(line_edit, 0, 1)
|
2021-11-14 17:54:48 +00:00
|
|
|
self.fields['hostname'] = line_edit
|
2021-11-14 17:40:26 +00:00
|
|
|
if not focus and not value:
|
2021-11-14 17:54:48 +00:00
|
|
|
focus = 'hostname'
|
2021-11-14 17:40:26 +00:00
|
|
|
|
|
|
|
# port / SSL
|
|
|
|
grid.addWidget(QtWidgets.QLabel('<b>Port</b>'), 1, 0)
|
|
|
|
line_edit = QtWidgets.QLineEdit()
|
|
|
|
line_edit.setFixedWidth(200)
|
|
|
|
value = self.values.get('port', '')
|
|
|
|
line_edit.insert(value)
|
|
|
|
grid.addWidget(line_edit, 1, 1)
|
|
|
|
self.fields['port'] = line_edit
|
|
|
|
if not focus and not value:
|
|
|
|
focus = 'port'
|
|
|
|
|
|
|
|
ssl = QtWidgets.QCheckBox('SSL')
|
|
|
|
ssl.setChecked(self.values['ssl'] == 'on')
|
|
|
|
grid.addWidget(ssl, 1, 2)
|
|
|
|
self.fields['ssl'] = ssl
|
|
|
|
|
|
|
|
# password
|
|
|
|
grid.addWidget(QtWidgets.QLabel('<b>Password</b>'), 2, 0)
|
|
|
|
line_edit = QtWidgets.QLineEdit()
|
|
|
|
line_edit.setFixedWidth(200)
|
|
|
|
line_edit.setEchoMode(QtWidgets.QLineEdit.Password)
|
|
|
|
value = self.values.get('password', '')
|
|
|
|
line_edit.insert(value)
|
|
|
|
grid.addWidget(line_edit, 2, 1)
|
|
|
|
self.fields['password'] = line_edit
|
|
|
|
if not focus and not value:
|
|
|
|
focus = 'password'
|
|
|
|
|
|
|
|
# TOTP (Time-Based One-Time Password)
|
|
|
|
label = QtWidgets.QLabel('TOTP')
|
|
|
|
label.setToolTip('Time-Based One-Time Password (6 digits)')
|
|
|
|
grid.addWidget(label, 3, 0)
|
|
|
|
line_edit = QtWidgets.QLineEdit()
|
|
|
|
line_edit.setPlaceholderText('6 digits')
|
|
|
|
validator = QtGui.QIntValidator(0, 999999, self)
|
|
|
|
line_edit.setValidator(validator)
|
|
|
|
line_edit.setFixedWidth(80)
|
|
|
|
value = self.values.get('totp', '')
|
|
|
|
line_edit.insert(value)
|
|
|
|
grid.addWidget(line_edit, 3, 1)
|
|
|
|
self.fields['totp'] = line_edit
|
|
|
|
if not focus and not value:
|
|
|
|
focus = 'totp'
|
|
|
|
|
|
|
|
# lines
|
|
|
|
grid.addWidget(QtWidgets.QLabel('Lines'), 4, 0)
|
|
|
|
line_edit = QtWidgets.QLineEdit()
|
|
|
|
line_edit.setFixedWidth(200)
|
|
|
|
validator = QtGui.QIntValidator(0, 2147483647, self)
|
|
|
|
line_edit.setValidator(validator)
|
|
|
|
line_edit.setFixedWidth(80)
|
|
|
|
value = self.values.get('lines', '')
|
|
|
|
line_edit.insert(value)
|
|
|
|
grid.addWidget(line_edit, 4, 1)
|
|
|
|
self.fields['lines'] = line_edit
|
|
|
|
if not focus and not value:
|
|
|
|
focus = 'lines'
|
2011-12-06 20:27:09 +00:00
|
|
|
|
2021-06-01 04:02:25 +00:00
|
|
|
self.dialog_buttons = QtWidgets.QDialogButtonBox()
|
2014-05-08 15:40:31 +00:00
|
|
|
self.dialog_buttons.setStandardButtons(
|
2021-06-01 04:02:25 +00:00
|
|
|
QtWidgets.QDialogButtonBox.Ok | QtWidgets.QDialogButtonBox.Cancel)
|
2011-12-06 20:27:09 +00:00
|
|
|
self.dialog_buttons.rejected.connect(self.close)
|
|
|
|
|
2021-11-14 17:40:26 +00:00
|
|
|
grid.addWidget(self.dialog_buttons, 5, 0, 1, 2)
|
2011-12-06 20:27:09 +00:00
|
|
|
self.setLayout(grid)
|
|
|
|
self.show()
|
2021-11-14 17:40:26 +00:00
|
|
|
|
|
|
|
if focus:
|
|
|
|
self.fields[focus].setFocus()
|