summaryrefslogtreecommitdiffstats
path: root/pacman-c++/client
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2011-05-05 20:14:34 +0200
committermanuel <manuel@mausz.at>2011-05-05 20:14:34 +0200
commita8b2bc4fb37d1649ac91f0b0ea2dfe05ca5e3a14 (patch)
treeb94132013ecb183018891b634731af38327adf2f /pacman-c++/client
parentce48af53646cd9e7ec762fc1ac176b3aa620b11d (diff)
downloadfoop-a8b2bc4fb37d1649ac91f0b0ea2dfe05ca5e3a14.tar.gz
foop-a8b2bc4fb37d1649ac91f0b0ea2dfe05ca5e3a14.tar.bz2
foop-a8b2bc4fb37d1649ac91f0b0ea2dfe05ca5e3a14.zip
- the last fixes for new build setup
- better connect dialog
Diffstat (limited to 'pacman-c++/client')
-rw-r--r--pacman-c++/client/client.cpp58
-rw-r--r--pacman-c++/client/client.pro4
2 files changed, 44 insertions, 18 deletions
diff --git a/pacman-c++/client/client.cpp b/pacman-c++/client/client.cpp
index d064d9e..96ee59a 100644
--- a/pacman-c++/client/client.cpp
+++ b/pacman-c++/client/client.cpp
@@ -185,14 +185,14 @@ void Client::showConnectDialog()
185 QGridLayout *layout = new QGridLayout(m_dialog); 185 QGridLayout *layout = new QGridLayout(m_dialog);
186 layout->setSizeConstraint(QLayout::SetFixedSize); 186 layout->setSizeConstraint(QLayout::SetFixedSize);
187 187
188 QLabel *srvLabel = new QLabel("Address:", m_dialog); 188 QLabel *srvLabel = new QLabel("Server address:", m_dialog);
189 QLineEdit *srv = new QLineEdit(m_settings->value("address", "127.0.0.1").toString(), m_dialog); 189
190 QLabel *portLabel = new QLabel("Port:", m_dialog); 190 QComboBox *srv = new QComboBox(m_dialog);
191 QDoubleSpinBox *port = new QDoubleSpinBox(m_dialog); 191 srv->setEditable(true);
192 port->setDecimals(0); 192 srv->setInsertPolicy(QComboBox::InsertAtTop);
193 port->setMinimum(1); 193 QString defentry = QString("127.0.0.1:%1").arg(Constants::Networking::port);
194 port->setMaximum(65535); 194 QStringList srvlist = m_settings->value("srvlist", QStringList(defentry)).toStringList();
195 port->setValue(m_settings->value("port", Constants::Networking::port).toUInt()); 195 srv->addItems(srvlist);
196 196
197 QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, 197 QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
198 Qt::Horizontal, m_dialog); 198 Qt::Horizontal, m_dialog);
@@ -201,15 +201,12 @@ void Client::showConnectDialog()
201 buttonBox->addButton(okButton, QDialogButtonBox::ButtonRole(QDialogButtonBox::AcceptRole)); 201 buttonBox->addButton(okButton, QDialogButtonBox::ButtonRole(QDialogButtonBox::AcceptRole));
202 buttonBox->addButton(cancelButton, QDialogButtonBox::ButtonRole(QDialogButtonBox::RejectRole)); 202 buttonBox->addButton(cancelButton, QDialogButtonBox::ButtonRole(QDialogButtonBox::RejectRole));
203 connect(buttonBox, SIGNAL(rejected()), m_dialog, SLOT(reject())); 203 connect(buttonBox, SIGNAL(rejected()), m_dialog, SLOT(reject()));
204 connect(buttonBox, SIGNAL(accepted()), m_dialog, SLOT(accept())); 204 connect(buttonBox, SIGNAL(accepted()), this, SLOT(onAcceptConnectDialog()));
205 205
206 layout->addWidget(srvLabel, 0, 0); 206 layout->addWidget(srvLabel, 0, 0);
207 layout->addWidget(srv, 0, 1); 207 layout->addWidget(srv, 0, 1);
208 layout->addWidget(portLabel, 1, 0);
209 layout->addWidget(port, 1, 1);
210 layout->addWidget(buttonBox, 4, 0, 1, 5); 208 layout->addWidget(buttonBox, 4, 0, 1, 5);
211 209
212 connect(m_dialog, SIGNAL(accepted()), this, SLOT(onAcceptConnectDialog()));
213 m_dialog->show(); 210 m_dialog->show();
214} 211}
215 212
@@ -218,11 +215,38 @@ void Client::onAcceptConnectDialog()
218 if (m_dialog == NULL) 215 if (m_dialog == NULL)
219 return; 216 return;
220 QGridLayout *layout = static_cast<QGridLayout *>(m_dialog->layout()); 217 QGridLayout *layout = static_cast<QGridLayout *>(m_dialog->layout());
221 QLineEdit *srv = static_cast<QLineEdit *>(layout->itemAtPosition(0, 1)->widget()); 218 QComboBox *srv = static_cast<QComboBox *>(layout->itemAtPosition(0, 1)->widget());
222 QDoubleSpinBox *port = static_cast<QDoubleSpinBox *>(layout->itemAtPosition(1, 1)->widget()); 219 QStringList selected = srv->currentText().split(':');
223 m_settings->setValue("address", srv->text()); 220 QString errormsg;
224 m_settings->setValue("port", int(port->value())); 221 if (errormsg.isNull() && selected.count() < 2)
225 m_mainWidget->doConnect(srv->text(), int(port->value())); 222 errormsg = "Invalid Syntax.\nUse: <address>:<port>";
223
224 /* port */
225 QString portstr = selected.takeLast();
226 bool ok;
227 unsigned int port = portstr.toUInt(&ok);
228 if (!ok || port < 1 || port > 65535)
229 errormsg = "Invalid port number. Must be between 1 and 65535";
230
231 /* address */
232 QString address = selected.join(":");
233
234 if (!errormsg.isNull())
235 {
236 QMessageBox::critical(this, "Error", errormsg);
237 return;
238 }
239
240 emit m_dialog->accept();
241
242 QStringList srvlist = m_settings->value("srvlist").toStringList();
243 srvlist.insert(0, srv->currentText());
244 srvlist.removeDuplicates();
245 while (srvlist.count() > 20)
246 srvlist.removeAt(20 - 1);
247 m_settings->setValue("srvlist", srvlist);
248
249 m_mainWidget->doConnect(address, port);
226} 250}
227 251
228bool Constants::server = false; 252bool Constants::server = false;
diff --git a/pacman-c++/client/client.pro b/pacman-c++/client/client.pro
index 849cca2..4b326fe 100644
--- a/pacman-c++/client/client.pro
+++ b/pacman-c++/client/client.pro
@@ -9,4 +9,6 @@ HEADERS += clicklabel.h \
9 mainwidget.h 9 mainwidget.h
10 10
11include(../common.pri) 11include(../common.pri)
12PRE_TARGETDEPS += ../common/libcommon.a 12PRE_TARGETDEPS += ../libcommon.a
13
14win32:RC_FILE = ../common/pacman.rc