-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSessionConfigDialog.cpp
More file actions
292 lines (233 loc) · 9.99 KB
/
SessionConfigDialog.cpp
File metadata and controls
292 lines (233 loc) · 9.99 KB
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
#include "SessionConfigDialog.h"
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QLabel>
#include <QDialogButtonBox>
#include <QGroupBox>
#include <QFormLayout>
#include <QComboBox>
#include <QSpinBox>
#include <QCheckBox>
#include <QTabWidget>
#include <QFontComboBox>
#include <QFileDialog> // Add this include
SessionConfigDialog::SessionConfigDialog(QWidget *parent, const QString &sessionName)
: QDialog(parent)
{
setWindowTitle("Session Properties");
setModal(true);
resize(650, 450); // Provide a reasonable starting size
// Main layout
auto mainLayout = new QVBoxLayout(this);
// Create splitter for left and right panels
mainSplitter = new QSplitter(Qt::Horizontal, this);
// Left panel with categories
categoryList = new QListWidget();
categoryList->addItem("Connection");
categoryList->addItem("Terminal");
categoryList->addItem("Appearance");
categoryList->addItem("Advanced");
categoryList->setFixedWidth(150); // Set fixed width for category list
categoryList->setCurrentRow(0); // Select first item by default
// Right panel with stacked pages
settingsStack = new QStackedWidget();
settingsStack->addWidget(createConnectionPage());
settingsStack->addWidget(createTerminalPage());
settingsStack->addWidget(createAppearancePage());
settingsStack->addWidget(createAdvancedPage());
// Add widgets to splitter
mainSplitter->addWidget(categoryList);
mainSplitter->addWidget(settingsStack);
mainSplitter->setStretchFactor(1, 1); // Make the settings panel take more space
// Button box
auto buttonBox = new QDialogButtonBox(
QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
Qt::Horizontal, this);
// Add to main layout
mainLayout->addWidget(mainSplitter);
mainLayout->addWidget(buttonBox);
// Set session name
sessionNameInput->setText(sessionName);
// Connect signals
connect(categoryList, &QListWidget::currentRowChanged, this, &SessionConfigDialog::changePage);
connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
// Connect auth type change signal AFTER authTypeCombo is created in createConnectionPage
// connect(authTypeCombo, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &SessionConfigDialog::updateAuthFields); // Moved connection
}
void SessionConfigDialog::changePage(int row)
{
if (row >= 0 && row < settingsStack->count()) {
settingsStack->setCurrentIndex(row);
}
}
QWidget* SessionConfigDialog::createConnectionPage()
{
QWidget *page = new QWidget();
QVBoxLayout *layout = new QVBoxLayout(page);
// Basic connection group
QGroupBox *connectionGroup = new QGroupBox("Connection Settings");
QFormLayout *connectionLayout = new QFormLayout(connectionGroup);
sessionNameInput = new QLineEdit();
hostInput = new QLineEdit();
userInput = new QLineEdit();
connectionLayout->addRow("Session Name:", sessionNameInput);
connectionLayout->addRow("Host/IP:", hostInput);
connectionLayout->addRow("Username:", userInput);
// Authentication group
QGroupBox *authGroup = new QGroupBox("Authentication");
QFormLayout *authLayout = new QFormLayout(authGroup);
authTypeCombo = new QComboBox(); // Initialize here
authTypeCombo->addItem("Password");
authTypeCombo->addItem("Private Key");
// authTypeCombo->addItem("Keyboard Interactive"); // Keep it simple for now
passwordLabel = new QLabel("Password:"); // Create password label
passwordInput = new QLineEdit();
passwordInput->setEchoMode(QLineEdit::Password);
privateKeyLabel = new QLabel("Private Key:"); // Create key label
QHBoxLayout *keyLayout = new QHBoxLayout(); // Layout for key path and browse button
privateKeyPathInput = new QLineEdit();
browseKeyButton = new QPushButton("Browse...");
keyLayout->addWidget(privateKeyPathInput);
keyLayout->addWidget(browseKeyButton);
authLayout->addRow("Authentication Type:", authTypeCombo);
authLayout->addRow(passwordLabel, passwordInput);
authLayout->addRow(privateKeyLabel, keyLayout);
// Connect signals for auth fields
connect(browseKeyButton, &QPushButton::clicked, this, &SessionConfigDialog::browsePrivateKey);
connect(authTypeCombo, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &SessionConfigDialog::updateAuthFields);
// Initial field visibility
updateAuthFields(authTypeCombo->currentIndex());
// Additional connection options
QGroupBox *optionsGroup = new QGroupBox("Connection Options");
QFormLayout *optionsLayout = new QFormLayout(optionsGroup);
QSpinBox *portSpin = new QSpinBox();
portSpin->setRange(1, 65535);
portSpin->setValue(22); // Default SSH port
QCheckBox *compressCheck = new QCheckBox("Enable Compression");
QCheckBox *keepAliveCheck = new QCheckBox("Enable Keep Alive");
keepAliveCheck->setChecked(true);
optionsLayout->addRow("Port:", portSpin);
// optionsLayout->addRow("Authentication Type:", authTypeCombo); // Moved to Auth Group
optionsLayout->addRow("", compressCheck);
optionsLayout->addRow("", keepAliveCheck);
// Add groups to the page
layout->addWidget(connectionGroup);
layout->addWidget(authGroup); // Add auth group
layout->addWidget(optionsGroup);
layout->addStretch(); // Push everything to the top
return page;
}
// Add implementation for browsePrivateKey slot
void SessionConfigDialog::browsePrivateKey()
{
QString filePath = QFileDialog::getOpenFileName(this, tr("Select Private Key"),
QDir::homePath(),
tr("SSH Private Keys (*.pem *.key *.rsa *.dsa *);;All Files (*)"));
if (!filePath.isEmpty()) {
privateKeyPathInput->setText(filePath);
}
}
// Add implementation for updateAuthFields slot
void SessionConfigDialog::updateAuthFields(int index)
{
bool isPasswordAuth = (authTypeCombo->itemText(index) == "Password");
passwordLabel->setVisible(isPasswordAuth);
passwordInput->setVisible(isPasswordAuth);
privateKeyLabel->setVisible(!isPasswordAuth);
privateKeyPathInput->setVisible(!isPasswordAuth);
browseKeyButton->setVisible(!isPasswordAuth);
}
// Add implementation for getAuthType
QString SessionConfigDialog::getAuthType() const
{
return authTypeCombo->currentText();
}
// Add implementation for setAuthType
void SessionConfigDialog::setAuthType(const QString &authType)
{
int index = authTypeCombo->findText(authType);
if (index != -1) {
authTypeCombo->setCurrentIndex(index);
}
updateAuthFields(authTypeCombo->currentIndex()); // Ensure fields update
}
QWidget* SessionConfigDialog::createTerminalPage()
{
QWidget *page = new QWidget();
QVBoxLayout *layout = new QVBoxLayout(page);
// Terminal settings group
QGroupBox *terminalGroup = new QGroupBox("Terminal Settings");
QFormLayout *terminalLayout = new QFormLayout(terminalGroup);
QComboBox *termTypeCombo = new QComboBox();
termTypeCombo->addItem("xterm");
termTypeCombo->addItem("xterm-256color");
termTypeCombo->addItem("linux");
termTypeCombo->addItem("vt100");
QSpinBox *scrollbackSpin = new QSpinBox();
scrollbackSpin->setRange(100, 10000);
scrollbackSpin->setSingleStep(100);
scrollbackSpin->setValue(1000);
QCheckBox *bellCheck = new QCheckBox("Enable Bell");
QCheckBox *cursorBlinkCheck = new QCheckBox("Cursor Blink");
cursorBlinkCheck->setChecked(true);
terminalLayout->addRow("Terminal Type:", termTypeCombo);
terminalLayout->addRow("Scrollback Lines:", scrollbackSpin);
terminalLayout->addRow("", bellCheck);
terminalLayout->addRow("", cursorBlinkCheck);
// Add groups to the page
layout->addWidget(terminalGroup);
layout->addStretch();
return page;
}
QWidget* SessionConfigDialog::createAppearancePage()
{
QWidget *page = new QWidget();
QVBoxLayout *layout = new QVBoxLayout(page);
// Font settings group
QGroupBox *fontGroup = new QGroupBox("Font Settings");
QFormLayout *fontLayout = new QFormLayout(fontGroup);
QFontComboBox *fontCombo = new QFontComboBox();
fontCombo->setFontFilters(QFontComboBox::MonospacedFonts);
fontCombo->setCurrentText("Monospace");
QSpinBox *fontSizeSpin = new QSpinBox();
fontSizeSpin->setRange(6, 24);
fontSizeSpin->setValue(10);
fontLayout->addRow("Font:", fontCombo);
fontLayout->addRow("Size:", fontSizeSpin);
// Color settings group
QGroupBox *colorGroup = new QGroupBox("Color Scheme");
QVBoxLayout *colorLayout = new QVBoxLayout(colorGroup);
QComboBox *colorSchemeCombo = new QComboBox();
colorSchemeCombo->addItem("Linux");
colorSchemeCombo->addItem("Tango");
colorSchemeCombo->addItem("Solarized Dark");
colorSchemeCombo->addItem("Solarized Light");
colorSchemeCombo->addItem("Green on Black");
colorLayout->addWidget(colorSchemeCombo);
// Add groups to the page
layout->addWidget(fontGroup);
layout->addWidget(colorGroup);
layout->addStretch();
return page;
}
QWidget* SessionConfigDialog::createAdvancedPage()
{
QWidget *page = new QWidget();
QVBoxLayout *layout = new QVBoxLayout(page);
// SSH settings
QGroupBox *sshGroup = new QGroupBox("SSH Options");
QFormLayout *sshLayout = new QFormLayout(sshGroup);
QLineEdit *sshOptionsEdit = new QLineEdit();
QLineEdit *forwardingEdit = new QLineEdit();
QCheckBox *x11Check = new QCheckBox("Enable X11 Forwarding");
QCheckBox *agentCheck = new QCheckBox("Enable SSH Agent Forwarding");
sshLayout->addRow("SSH Options:", sshOptionsEdit);
sshLayout->addRow("Port Forwarding:", forwardingEdit);
sshLayout->addRow("", x11Check);
sshLayout->addRow("", agentCheck);
// Add groups to the page
layout->addWidget(sshGroup);
layout->addStretch();
return page;
}