Some work on players lists context menus
authorunc0rr
Wed, 04 Mar 2009 16:35:36 +0000 (2009-03-04)
changeset 1860 ce140b2b928a
parent 1859 e071284b118e
child 1861 98de5dc5fda7
Some work on players lists context menus
QTfrontend/chatwidget.cpp
QTfrontend/chatwidget.h
QTfrontend/hwform.cpp
QTfrontend/newnetclient.cpp
QTfrontend/newnetclient.h
--- a/QTfrontend/chatwidget.cpp	Wed Mar 04 13:55:53 2009 +0000
+++ b/QTfrontend/chatwidget.cpp	Wed Mar 04 16:35:36 2009 +0000
@@ -57,12 +57,13 @@
 	chatNicks->setContextMenuPolicy(Qt::ActionsContextMenu);
 	mainLayout.addWidget(chatNicks, 0, 1);
 
-	QAction * acBan = new QAction(QAction::tr("Kick"), chatNicks);
-	connect(acBan, SIGNAL(triggered(bool)), this, SLOT(onKick()));
-	chatNicks->insertAction(0, acBan);
-
-	QAction * acInfo = new QAction(QAction::tr("Info"), chatNicks);
+	acInfo = new QAction(QAction::tr("Info"), chatNicks);
 	connect(acInfo, SIGNAL(triggered(bool)), this, SLOT(onInfo()));
+	acKick = new QAction(QAction::tr("Kick"), chatNicks);
+	connect(acKick, SIGNAL(triggered(bool)), this, SLOT(onKick()));
+	acBan = new QAction(QAction::tr("Ban"), chatNicks);
+	connect(acBan, SIGNAL(triggered(bool)), this, SLOT(onBan()));
+	
 	chatNicks->insertAction(0, acInfo);
 }
 
@@ -129,6 +130,13 @@
 		emit kick(curritem->text());
 }
 
+void HWChatWidget::onBan()
+{
+	QListWidgetItem * curritem = chatNicks->currentItem();
+	if (curritem)
+		emit ban(curritem->text());
+}
+
 void HWChatWidget::onInfo()
 {
 	QListWidgetItem * curritem = chatNicks->currentItem();
@@ -150,3 +158,15 @@
 	else
 		items[0]->setIcon(QIcon(":/res/lightbulb_off.png"));
 }
+
+void HWChatWidget::adminAccess(bool b)
+{
+	chatNicks->removeAction(acKick);
+	chatNicks->removeAction(acBan);
+	
+	if(b)
+	{
+		chatNicks->insertAction(0, acKick);
+		chatNicks->insertAction(0, acBan);
+	}
+}
--- a/QTfrontend/chatwidget.h	Wed Mar 04 13:55:53 2009 +0000
+++ b/QTfrontend/chatwidget.h	Wed Mar 04 16:35:36 2009 +0000
@@ -41,10 +41,12 @@
   void nickRemoved(const QString& nick);
   void clear();
   void setReadyStatus(const QString & nick, bool isReady);
+  void adminAccess(bool);
 
  signals:
   void chatLine(const QString& str);
   void kick(const QString & str);
+  void ban(const QString & str);
   void info(const QString & str);
 
  private:
@@ -53,9 +55,13 @@
   QStringList chatStrings;
   QListWidget* chatNicks;
   QLineEdit* chatEditLine;
+  QAction * acInfo;
+  QAction * acKick;
+  QAction * acBan;
 
  private slots:
   void returnPressed();
+  void onBan();
   void onKick();
   void onInfo();
 };
--- a/QTfrontend/hwform.cpp	Wed Mar 04 13:55:53 2009 +0000
+++ b/QTfrontend/hwform.cpp	Wed Mar 04 16:35:36 2009 +0000
@@ -484,6 +484,8 @@
 		ui.pageRoomsList, SLOT(setRoomsList(const QStringList&)));
 	connect(hwnet, SIGNAL(adminAccess(bool)),
 		ui.pageRoomsList, SLOT(setAdmin(bool)));
+	connect(hwnet, SIGNAL(adminAccess(bool)),
+		ui.pageRoomsList->chatWidget, SLOT(adminAccess(bool)));
 	
 	connect(hwnet, SIGNAL(serverMessage(const QString&)),
 		ui.pageRoomsList->chatWidget, SLOT(onServerMessage(const QString&)));
@@ -505,6 +507,8 @@
 		ui.pageNetGame->pChatWidget, SLOT(setReadyStatus(const QString &, bool)));
 	connect(hwnet, SIGNAL(chatStringFromMe(const QString&)),
 		ui.pageNetGame->pChatWidget, SLOT(onChatString(const QString&)));
+	connect(hwnet, SIGNAL(roomMaster(bool)),
+		ui.pageNetGame->pChatWidget, SLOT(adminAccess(bool)));
 	connect(ui.pageNetGame->pChatWidget, SIGNAL(chatLine(const QString&)),
 		hwnet, SLOT(chatLineToNet(const QString&)));
 	connect(ui.pageNetGame->BtnGo, SIGNAL(clicked()), hwnet, SLOT(ToggleReady()));
@@ -513,8 +517,14 @@
 
 	connect(ui.pageNetGame->pChatWidget, SIGNAL(kick(const QString&)),
 		hwnet, SLOT(kickPlayer(const QString&)));
+	connect(ui.pageNetGame->pChatWidget, SIGNAL(ban(const QString&)),
+		hwnet, SLOT(banPlayer(const QString&)));
 	connect(ui.pageNetGame->pChatWidget, SIGNAL(info(const QString&)),
 		hwnet, SLOT(infoPlayer(const QString&)));
+	connect(ui.pageRoomsList->chatWidget, SIGNAL(kick(const QString&)),
+		hwnet, SLOT(kickPlayer(const QString&)));
+	connect(ui.pageRoomsList->chatWidget, SIGNAL(ban(const QString&)),
+		hwnet, SLOT(banPlayer(const QString&)));
 	connect(ui.pageRoomsList->chatWidget, SIGNAL(info(const QString&)),
 		hwnet, SLOT(infoPlayer(const QString&)));
 
--- a/QTfrontend/newnetclient.cpp	Wed Mar 04 13:55:53 2009 +0000
+++ b/QTfrontend/newnetclient.cpp	Wed Mar 04 16:35:36 2009 +0000
@@ -357,6 +357,7 @@
 			{
 				netClientState = 3;
 				emit EnteredGame();
+				emit roomMaster(isChief);
 				if (isChief)
 					ConfigAsked();
 			}
@@ -734,6 +735,11 @@
 		return QString("%1: %2").arg(nick).arg(msg);
 }
 
+void HWNewNet::banPlayer(const QString & nick)
+{
+	RawSendNet(QString("BAN%1%2").arg(delimeter).arg(nick));
+}
+
 void HWNewNet::kickPlayer(const QString & nick)
 {
 	RawSendNet(QString("KICK%1%2").arg(delimeter).arg(nick));
--- a/QTfrontend/newnetclient.h	Wed Mar 04 13:55:53 2009 +0000
+++ b/QTfrontend/newnetclient.h	Wed Mar 04 16:35:36 2009 +0000
@@ -100,6 +100,7 @@
   void nickRemovedLobby(const QString& nick);
   void FromNet(const QByteArray & buf);
   void adminAccess(bool);
+  void roomMaster(bool);
 
   void AddNetTeam(const HWTeam&);
   void seedChanged(const QString & seed);
@@ -155,6 +156,7 @@
   void CreateRoom(const QString & room);
   void askRoomsList();
   void gameFinished();
+  void banPlayer(const QString &);
   void kickPlayer(const QString &);
   void infoPlayer(const QString &);
   void startGame();