- Frontend finally learns how to create passworded room
authorunc0rr
Mon, 14 Oct 2013 23:57:31 +0400
changeset 9541 312bb4384f33
parent 9539 ab44d44a6177
child 9543 1826b5315369
- Frontend finally learns how to create passworded room - Refactor RoomNamePrompt and use it properly
QTfrontend/hwform.cpp
QTfrontend/net/newnetclient.cpp
QTfrontend/net/newnetclient.h
QTfrontend/ui/page/pageroomslist.cpp
QTfrontend/ui/page/pageroomslist.h
QTfrontend/ui/widget/roomnameprompt.cpp
QTfrontend/ui/widget/roomnameprompt.h
--- a/QTfrontend/hwform.cpp	Mon Oct 14 00:33:10 2013 -0400
+++ b/QTfrontend/hwform.cpp	Mon Oct 14 23:57:31 2013 +0400
@@ -1255,8 +1255,8 @@
     connect(hwnet, SIGNAL(serverMessage(const QString&)),
             ui.pageRoomsList->chatWidget, SLOT(onServerMessage(const QString&)), Qt::QueuedConnection);
 
-    connect(ui.pageRoomsList, SIGNAL(askForCreateRoom(const QString &)),
-            hwnet, SLOT(CreateRoom(const QString&)));
+    connect(ui.pageRoomsList, SIGNAL(askForCreateRoom(const QString &, const QString &)),
+            hwnet, SLOT(CreateRoom(const QString&, const QString &)));
     connect(ui.pageRoomsList, SIGNAL(askForJoinRoom(const QString &)),
             hwnet, SLOT(JoinRoom(const QString&)));
 //  connect(ui.pageRoomsList, SIGNAL(askForCreateRoom(const QString &)),
--- a/QTfrontend/net/newnetclient.cpp	Mon Oct 14 00:33:10 2013 -0400
+++ b/QTfrontend/net/newnetclient.cpp	Mon Oct 14 23:57:31 2013 +0400
@@ -94,7 +94,7 @@
     NetSocket.disconnectFromHost();
 }
 
-void HWNewNet::CreateRoom(const QString & room)
+void HWNewNet::CreateRoom(const QString & room, const QString & password)
 {
     if(netClientState != InLobby)
     {
@@ -104,7 +104,11 @@
 
     myroom = room;
 
-    RawSendNet(QString("CREATE_ROOM%1%2").arg(delimeter).arg(room));
+    if(password.isEmpty())
+        RawSendNet(QString("CREATE_ROOM%1%2").arg(delimeter).arg(room));
+    else
+        RawSendNet(QString("CREATE_ROOM%1%2%1%3").arg(delimeter).arg(room).arg(password));
+
     isChief = true;
 }
 
--- a/QTfrontend/net/newnetclient.h	Mon Oct 14 00:33:10 2013 -0400
+++ b/QTfrontend/net/newnetclient.h	Mon Oct 14 23:57:31 2013 +0400
@@ -154,7 +154,7 @@
         void askServerVars();
 
         void JoinRoom(const QString & room);
-        void CreateRoom(const QString & room);
+        void CreateRoom(const QString & room, const QString &password);
         void updateRoomName(const QString &);
         void askRoomsList();
         void gameFinished(bool correcly);
--- a/QTfrontend/ui/page/pageroomslist.cpp	Mon Oct 14 00:33:10 2013 -0400
+++ b/QTfrontend/ui/page/pageroomslist.cpp	Mon Oct 14 23:57:31 2013 +0400
@@ -531,17 +531,17 @@
 
 void PageRoomsList::onCreateClick()
 {
-    RoomNamePrompt prompt(parentWidget()->parentWidget(), m_gameSettings->value("frontend/lastroomname", QString()).toString());
-    connect(&prompt, SIGNAL(roomNameChosen(const QString &)), this, SLOT(onRoomNameChosen(const QString &)));
-    prompt.exec();
+    RoomNamePrompt prompt(this, m_gameSettings->value("frontend/lastroomname", QString()).toString());
+    if(prompt.exec())
+        onRoomNameChosen(prompt.getRoomName(), prompt.getPassword());
 }
 
-void PageRoomsList::onRoomNameChosen(const QString & roomName)
+void PageRoomsList::onRoomNameChosen(const QString & roomName, const QString & password)
 {
     if (!roomName.trimmed().isEmpty())
     {
         m_gameSettings->setValue("frontend/lastroomname", roomName);
-        emit askForCreateRoom(roomName);
+        emit askForCreateRoom(roomName, password);
     }
     else
     {
--- a/QTfrontend/ui/page/pageroomslist.h	Mon Oct 14 00:33:10 2013 -0400
+++ b/QTfrontend/ui/page/pageroomslist.h	Mon Oct 14 23:57:31 2013 +0400
@@ -70,7 +70,7 @@
         void updateNickCounter(int cnt);
 
     signals:
-        void askForCreateRoom(const QString &);
+        void askForCreateRoom(const QString &, const QString &);
         void askForJoinRoom(const QString &);
         void askForRoomList();
         void askJoinConfirmation(const QString &);
@@ -89,7 +89,7 @@
         void onSortIndicatorChanged(int logicalIndex, Qt::SortOrder order);
         void onFilterChanged();
         void saveHeaderState();
-        void onRoomNameChosen(const QString &);
+        void onRoomNameChosen(const QString &, const QString &password);
         void roomSelectionChanged(const QModelIndex &, const QModelIndex &);
         void moveSelectionUp();
         void moveSelectionDown();
--- a/QTfrontend/ui/widget/roomnameprompt.cpp	Mon Oct 14 00:33:10 2013 -0400
+++ b/QTfrontend/ui/widget/roomnameprompt.cpp	Mon Oct 14 23:57:31 2013 +0400
@@ -23,6 +23,7 @@
 #include <QLineEdit>
 #include <QLabel>
 #include <QDebug>
+#include <QCheckBox>
 
 #include "roomnameprompt.h"
 
@@ -32,24 +33,34 @@
     setWindowFlags(Qt::Sheet);
     setWindowModality(Qt::WindowModal);
     setMinimumSize(360, 130);
-    resize(360, 130);
+    resize(360, 180);
     setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
 
     // Layout
     QVBoxLayout * dialogLayout = new QVBoxLayout(this);
 
     // Label
-    label = new QLabel(tr("Enter a name for your room."));
+    label = new QLabel(tr("Enter a name for your room."), this);
     label->setWordWrap(true);
-    dialogLayout->addWidget(label, 0);
+    dialogLayout->addWidget(label);
 
     // Input box
-    editBox = new QLineEdit();
-    editBox->setText(roomName);
-    editBox->setMaxLength(59); // It didn't like 60 :(
-    editBox->setStyleSheet("QLineEdit { padding: 3px; }");
-    editBox->selectAll();
-    dialogLayout->addWidget(editBox, 1);
+    leRoomName = new QLineEdit(this);
+    leRoomName->setText(roomName);
+    leRoomName->setMaxLength(59); // It didn't like 60 :(
+    leRoomName->setStyleSheet("QLineEdit { padding: 3px; }");
+    leRoomName->selectAll();
+    dialogLayout->addWidget(leRoomName);
+
+    cbSetPassword = new QCheckBox(this);
+    cbSetPassword->setText(tr("set password"));
+    dialogLayout->addWidget(cbSetPassword);
+
+    lePassword = new QLineEdit(this);
+    //lePassword->setMaxLength(30);
+    //lePassword->setStyleSheet("QLineEdit { padding: 3px; }");
+    lePassword->setEnabled(false);
+    dialogLayout->addWidget(lePassword);
 
     dialogLayout->addStretch(1);
 
@@ -73,10 +84,20 @@
 
     setStyleSheet("QPushButton { padding: 5px; }");
 
-    connect(btnOkay, SIGNAL(clicked()), this, SLOT(setRoomName()));
+    connect(cbSetPassword, SIGNAL(toggled(bool)), this, SLOT(checkBoxToggled()));
+}
+
+QString RoomNamePrompt::getRoomName()
+{
+    return leRoomName->text();
 }
 
-void RoomNamePrompt::setRoomName()
+QString RoomNamePrompt::getPassword()
 {
-    emit roomNameChosen(editBox->text());
+    return lePassword->text();
 }
+
+void RoomNamePrompt::checkBoxToggled()
+{
+    lePassword->setEnabled(cbSetPassword->isChecked());
+}
--- a/QTfrontend/ui/widget/roomnameprompt.h	Mon Oct 14 00:33:10 2013 -0400
+++ b/QTfrontend/ui/widget/roomnameprompt.h	Mon Oct 14 23:57:31 2013 +0400
@@ -23,6 +23,7 @@
 
 class QLineEdit;
 class QLabel;
+class QCheckBox;
 
 class RoomNamePrompt : public QDialog
 {
@@ -30,16 +31,17 @@
 
     public:
         RoomNamePrompt(QWidget* parent, const QString & roomName);
+        QString getRoomName();
+        QString getPassword();
 
-    signals:
-        void roomNameChosen(const QString & roomName);
+    private:
+        QLineEdit * leRoomName;
+        QLabel * label;
+        QCheckBox * cbSetPassword;
+        QLineEdit * lePassword;
 
     private slots:
-        void setRoomName();
-
-    private:
-        QLineEdit * editBox;
-        QLabel * label;
+        void checkBoxToggled();
 };
 
 #endif // ROOMNAMEPROMPT_H