]> jfr.im git - irc/weechat/qweechat.git/blob - qweechat/connection.py
aad350a9c5a301c1354c9eaaca9f5f6496d754e9
[irc/weechat/qweechat.git] / qweechat / connection.py
1 # -*- coding: utf-8 -*-
2 #
3 # connection.py - connection window
4 #
5 # Copyright (C) 2011-2021 Sébastien Helleu <flashcode@flashtux.org>
6 #
7 # This file is part of QWeeChat, a Qt remote GUI for WeeChat.
8 #
9 # QWeeChat is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 3 of the License, or
12 # (at your option) any later version.
13 #
14 # QWeeChat is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with QWeeChat. If not, see <http://www.gnu.org/licenses/>.
21 #
22
23 """Connection window."""
24
25 from PySide6 import QtGui, QtWidgets
26
27
28 class ConnectionDialog(QtWidgets.QDialog):
29 """Connection window."""
30
31 def __init__(self, values, *args):
32 super().__init__(*args)
33 self.values = values
34 self.setModal(True)
35 self.setWindowTitle('Connect to WeeChat')
36
37 grid = QtWidgets.QGridLayout()
38 grid.setSpacing(10)
39
40 self.fields = {}
41 focus = None
42
43 # server
44 grid.addWidget(QtWidgets.QLabel('<b>Server</b>'), 0, 0)
45 line_edit = QtWidgets.QLineEdit()
46 line_edit.setFixedWidth(200)
47 value = self.values.get('server', '')
48 line_edit.insert(value)
49 grid.addWidget(line_edit, 0, 1)
50 self.fields['server'] = line_edit
51 if not focus and not value:
52 focus = 'server'
53
54 # port / SSL
55 grid.addWidget(QtWidgets.QLabel('<b>Port</b>'), 1, 0)
56 line_edit = QtWidgets.QLineEdit()
57 line_edit.setFixedWidth(200)
58 value = self.values.get('port', '')
59 line_edit.insert(value)
60 grid.addWidget(line_edit, 1, 1)
61 self.fields['port'] = line_edit
62 if not focus and not value:
63 focus = 'port'
64
65 ssl = QtWidgets.QCheckBox('SSL')
66 ssl.setChecked(self.values['ssl'] == 'on')
67 grid.addWidget(ssl, 1, 2)
68 self.fields['ssl'] = ssl
69
70 # password
71 grid.addWidget(QtWidgets.QLabel('<b>Password</b>'), 2, 0)
72 line_edit = QtWidgets.QLineEdit()
73 line_edit.setFixedWidth(200)
74 line_edit.setEchoMode(QtWidgets.QLineEdit.Password)
75 value = self.values.get('password', '')
76 line_edit.insert(value)
77 grid.addWidget(line_edit, 2, 1)
78 self.fields['password'] = line_edit
79 if not focus and not value:
80 focus = 'password'
81
82 # TOTP (Time-Based One-Time Password)
83 label = QtWidgets.QLabel('TOTP')
84 label.setToolTip('Time-Based One-Time Password (6 digits)')
85 grid.addWidget(label, 3, 0)
86 line_edit = QtWidgets.QLineEdit()
87 line_edit.setPlaceholderText('6 digits')
88 validator = QtGui.QIntValidator(0, 999999, self)
89 line_edit.setValidator(validator)
90 line_edit.setFixedWidth(80)
91 value = self.values.get('totp', '')
92 line_edit.insert(value)
93 grid.addWidget(line_edit, 3, 1)
94 self.fields['totp'] = line_edit
95 if not focus and not value:
96 focus = 'totp'
97
98 # lines
99 grid.addWidget(QtWidgets.QLabel('Lines'), 4, 0)
100 line_edit = QtWidgets.QLineEdit()
101 line_edit.setFixedWidth(200)
102 validator = QtGui.QIntValidator(0, 2147483647, self)
103 line_edit.setValidator(validator)
104 line_edit.setFixedWidth(80)
105 value = self.values.get('lines', '')
106 line_edit.insert(value)
107 grid.addWidget(line_edit, 4, 1)
108 self.fields['lines'] = line_edit
109 if not focus and not value:
110 focus = 'lines'
111
112 self.dialog_buttons = QtWidgets.QDialogButtonBox()
113 self.dialog_buttons.setStandardButtons(
114 QtWidgets.QDialogButtonBox.Ok | QtWidgets.QDialogButtonBox.Cancel)
115 self.dialog_buttons.rejected.connect(self.close)
116
117 grid.addWidget(self.dialog_buttons, 5, 0, 1, 2)
118 self.setLayout(grid)
119 self.show()
120
121 if focus:
122 self.fields[focus].setFocus()