diff options
| author | manuel <manuel@mausz.at> | 2011-05-05 20:14:34 +0200 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2011-05-05 20:14:34 +0200 |
| commit | a8b2bc4fb37d1649ac91f0b0ea2dfe05ca5e3a14 (patch) | |
| tree | b94132013ecb183018891b634731af38327adf2f | |
| parent | ce48af53646cd9e7ec762fc1ac176b3aa620b11d (diff) | |
| download | foop-a8b2bc4fb37d1649ac91f0b0ea2dfe05ca5e3a14.tar.gz foop-a8b2bc4fb37d1649ac91f0b0ea2dfe05ca5e3a14.tar.bz2 foop-a8b2bc4fb37d1649ac91f0b0ea2dfe05ca5e3a14.zip | |
- the last fixes for new build setup
- better connect dialog
| -rw-r--r-- | .gitignore | 2 | ||||
| -rw-r--r-- | pacman-c++/client/client.cpp | 58 | ||||
| -rw-r--r-- | pacman-c++/client/client.pro | 4 | ||||
| -rw-r--r-- | pacman-c++/common.pri | 11 | ||||
| -rw-r--r-- | pacman-c++/common/common.pro | 1 | ||||
| -rwxr-xr-x | pacman-c++/rebuild.sh | 4 | ||||
| -rw-r--r-- | pacman-c++/server/server.cpp | 10 | ||||
| -rw-r--r-- | pacman-c++/server/server.pro | 4 |
8 files changed, 66 insertions, 28 deletions
| @@ -1,7 +1,7 @@ | |||
| 1 | pacman-c++/*.pro.user | 1 | pacman-c++/*.pro.user |
| 2 | pacman-c++/pacman | 2 | pacman-c++/pacman |
| 3 | pacman-c++/build | ||
| 3 | pacman-c++/enet | 4 | pacman-c++/enet |
| 4 | pacman-c++/Makefile | ||
| 5 | pacman-c++/qrc_* | 5 | pacman-c++/qrc_* |
| 6 | pacman-c++/*.o | 6 | pacman-c++/*.o |
| 7 | pacman-c++/*.moc | 7 | pacman-c++/*.moc |
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 | ||
| 228 | bool Constants::server = false; | 252 | bool 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 | ||
| 11 | include(../common.pri) | 11 | include(../common.pri) |
| 12 | PRE_TARGETDEPS += ../common/libcommon.a | 12 | PRE_TARGETDEPS += ../libcommon.a |
| 13 | |||
| 14 | win32:RC_FILE = ../common/pacman.rc | ||
diff --git a/pacman-c++/common.pri b/pacman-c++/common.pri index fed2973..51db8ac 100644 --- a/pacman-c++/common.pri +++ b/pacman-c++/common.pri | |||
| @@ -1,20 +1,21 @@ | |||
| 1 | LANGUAGE = C++ | 1 | LANGUAGE = C++ |
| 2 | VERSION = 0.1 | 2 | VERSION = 0.1 |
| 3 | 3 | ||
| 4 | OBJECTS_DIR = .obj | ||
| 5 | MOC_DIR = .moc | ||
| 6 | |||
| 7 | QT += phonon network | 4 | QT += phonon network |
| 8 | 5 | ||
| 6 | DESTDIR = ../ | ||
| 7 | |||
| 9 | INCLUDEPATH += ../common | 8 | INCLUDEPATH += ../common |
| 10 | DEPENDPATH += ../common | 9 | DEPENDPATH += ../common |
| 11 | LIBS += -L../common -lcommon | 10 | LIBS += -L.. -lcommon |
| 12 | 11 | ||
| 13 | INCLUDEPATH += $$OUT_PWD/../proto | 12 | INCLUDEPATH += $$OUT_PWD/../proto |
| 14 | LIBS += -L../proto -lproto -lprotobuf | 13 | LIBS += -L.. -lproto -lprotobuf |
| 15 | 14 | ||
| 16 | INCLUDEPATH += ../enet/include | 15 | INCLUDEPATH += ../enet/include |
| 17 | LIBS += -L$$PWD/enet/.libs -lenet | 16 | LIBS += -L$$PWD/enet/.libs -lenet |
| 17 | # enable this if you want to link the archive | ||
| 18 | #win32:LIBS += -lws2_32 -lwinmm | ||
| 18 | 19 | ||
| 19 | CONFIG(release, debug|release) { | 20 | CONFIG(release, debug|release) { |
| 20 | DEFINES += QT_NO_DEBUG_OUTPUT | 21 | DEFINES += QT_NO_DEBUG_OUTPUT |
diff --git a/pacman-c++/common/common.pro b/pacman-c++/common/common.pro index 5903f9d..ca82382 100644 --- a/pacman-c++/common/common.pro +++ b/pacman-c++/common/common.pro | |||
| @@ -27,4 +27,3 @@ OTHER_FILES += style.qss \ | |||
| 27 | pacman.rc | 27 | pacman.rc |
| 28 | 28 | ||
| 29 | RESOURCES += pacman.qrc | 29 | RESOURCES += pacman.qrc |
| 30 | RC_FILE = pacman.rc | ||
diff --git a/pacman-c++/rebuild.sh b/pacman-c++/rebuild.sh index 58ec7c4..01454ed 100755 --- a/pacman-c++/rebuild.sh +++ b/pacman-c++/rebuild.sh | |||
| @@ -1,4 +1,6 @@ | |||
| 1 | #!/bin/sh | 1 | #!/bin/sh |
| 2 | mkdir -p build | ||
| 3 | cd build | ||
| 2 | #make distclean | 4 | #make distclean |
| 3 | qmake CONFIG+=debug pacman.pro | 5 | qmake CONFIG+=debug ../pacman.pro |
| 4 | make -j2 | 6 | make -j2 |
diff --git a/pacman-c++/server/server.cpp b/pacman-c++/server/server.cpp index c9e4fff..65db87d 100644 --- a/pacman-c++/server/server.cpp +++ b/pacman-c++/server/server.cpp | |||
| @@ -38,7 +38,7 @@ Server::~Server() | |||
| 38 | break; | 38 | break; |
| 39 | case ENET_EVENT_TYPE_DISCONNECT: | 39 | case ENET_EVENT_TYPE_DISCONNECT: |
| 40 | m_clientConnections.remove(event.peer); | 40 | m_clientConnections.remove(event.peer); |
| 41 | return; | 41 | break; |
| 42 | default: | 42 | default: |
| 43 | break; | 43 | break; |
| 44 | } | 44 | } |
| @@ -949,6 +949,12 @@ int main(int argc, char **argv) | |||
| 949 | */ | 949 | */ |
| 950 | GOOGLE_PROTOBUF_VERIFY_VERSION; | 950 | GOOGLE_PROTOBUF_VERIFY_VERSION; |
| 951 | 951 | ||
| 952 | if (enet_initialize () != 0) | ||
| 953 | { | ||
| 954 | qCritical() << "An error occurred while initializing ENet"; | ||
| 955 | return EXIT_FAILURE; | ||
| 956 | } | ||
| 957 | |||
| 952 | QApplication app(argc, argv, false); | 958 | QApplication app(argc, argv, false); |
| 953 | app.setApplicationName("Pacman Server"); | 959 | app.setApplicationName("Pacman Server"); |
| 954 | app.setWindowIcon(QIcon(":/appicon")); | 960 | app.setWindowIcon(QIcon(":/appicon")); |
| @@ -964,6 +970,8 @@ int main(int argc, char **argv) | |||
| 964 | if (!ret) | 970 | if (!ret) |
| 965 | ret = app.exec(); | 971 | ret = app.exec(); |
| 966 | 972 | ||
| 973 | enet_deinitialize(); | ||
| 974 | |||
| 967 | /* Delete all global objects allocated by libprotobuf */ | 975 | /* Delete all global objects allocated by libprotobuf */ |
| 968 | google::protobuf::ShutdownProtobufLibrary(); | 976 | google::protobuf::ShutdownProtobufLibrary(); |
| 969 | 977 | ||
diff --git a/pacman-c++/server/server.pro b/pacman-c++/server/server.pro index 05d5c9d..b5a9952 100644 --- a/pacman-c++/server/server.pro +++ b/pacman-c++/server/server.pro | |||
| @@ -7,4 +7,6 @@ HEADERS += anyoption.h \ | |||
| 7 | server.h | 7 | server.h |
| 8 | 8 | ||
| 9 | include(../common.pri) | 9 | include(../common.pri) |
| 10 | PRE_TARGETDEPS += ../common/libcommon.a | 10 | PRE_TARGETDEPS += ../libcommon.a |
| 11 | |||
| 12 | win32:RC_FILE = ../common/pacman.rc | ||
