QTfrontend/hwform.cpp
changeset 2821 67815ee123d7
parent 2820 389e8b286afe
child 2822 0533562bc3a4
--- a/QTfrontend/hwform.cpp	Wed Feb 17 17:38:32 2010 +0000
+++ b/QTfrontend/hwform.cpp	Wed Feb 17 19:50:22 2010 +0000
@@ -54,6 +54,7 @@
 #include "input_ip.h"
 #include "ammoSchemeModel.h"
 #include "bgwidget.h"
+#include "xfire.h"
 
 #ifdef __APPLE__
 #include "CocoaInitializer.h"
@@ -71,6 +72,7 @@
 HWForm::HWForm(QWidget *parent)
   : QMainWindow(parent), pnetserver(0), pRegisterServer(0), editedTeam(0), hwnet(0)
 {
+	xfire_init();
     gameSettings = new QSettings(cfgdir->absolutePath() + "/hedgewars.ini", QSettings::IniFormat);
     frontendEffects = gameSettings->value("video/frontendeffects", true).toBool();
 
@@ -205,6 +207,53 @@
 	GoBack();
 }
 
+void HWForm::updateXfire(void)
+{
+//	xfire_setvalue(XFIRE_ROOM, "None");
+//	xfire_setvalue(XFIRE_GAMEMODE, "Multiplayer");
+//	xfire_setvalue(XFIRE_NICKNAME, ui.pageOptions->editNetNick->text().toAscii());
+//	if(!host.compare("netserver.hedgewars.org"))
+//		xfire_setvalue(XFIRE_SERVER, "Official server");
+//	else
+//		xfire_setvalue(XFIRE_SERVER, "Custom or local LAN server");
+	if(hwnet)
+	{
+		xfire_setvalue(XFIRE_SERVER, !hwnet->getHost().compare("netserver.hedgewars.org:46631") ? "Official server" : hwnet->getHost().toAscii());
+		switch(hwnet->getClientState())
+		{
+			case 1: // Connecting
+			xfire_setvalue(XFIRE_STATUS, "Connecting");
+			xfire_setvalue(XFIRE_NICKNAME, "-");
+			xfire_setvalue(XFIRE_ROOM, "-");
+			case 2: // In lobby
+			xfire_setvalue(XFIRE_STATUS, "Online");
+			xfire_setvalue(XFIRE_NICKNAME, hwnet->getNick().toAscii());
+			xfire_setvalue(XFIRE_ROOM, "In game lobby");
+			break;
+			case 3: // In room
+			xfire_setvalue(XFIRE_STATUS, "Online");
+			xfire_setvalue(XFIRE_NICKNAME, hwnet->getNick().toAscii());
+			xfire_setvalue(XFIRE_ROOM, (hwnet->getRoom() + " (waiting for players)").toAscii());
+			break;
+			case 5: // In game
+			xfire_setvalue(XFIRE_STATUS, "Online");
+			xfire_setvalue(XFIRE_NICKNAME, hwnet->getNick().toAscii());
+			xfire_setvalue(XFIRE_ROOM, (hwnet->getRoom() + " (playing or spectating)").toAscii());
+			break;
+			default:
+			break;
+		}
+	}
+	else
+	{
+		xfire_setvalue(XFIRE_STATUS, "Offline");
+		xfire_setvalue(XFIRE_NICKNAME, "-");
+		xfire_setvalue(XFIRE_ROOM, "-");
+		xfire_setvalue(XFIRE_SERVER, "-");
+	}
+	xfire_update();
+}
+
 void HWForm::onFrontendFullscreen(bool value)
 {
   if (value)
@@ -359,6 +408,7 @@
 
 void HWForm::OnPageShown(quint8 id, quint8 lastid)
 {
+	updateXfire();
 	if (id == ID_PAGE_MULTIPLAYER || id == ID_PAGE_NETGAME) {
 		QStringList tmNames = config->GetTeamsList();
 		TeamSelWidget* curTeamSelWidget;
@@ -891,6 +941,7 @@
 
 void HWForm::closeEvent(QCloseEvent *event)
 {
+	xfire_free();
 	config->SaveOptions();
 	event->accept();
 }