[atlantik-cvs] CVS: kdegames/atlantik/libatlantikclient atlantik_network.cpp,1.65,1.65.4.1 atlantik_network.h,1.34,1.34.4.1

[email protected]
Newsgroups gmane.comp.kde.devel.atlantik
Message-ID <[email protected]>
Update of /home/kde/kdegames/atlantik/libatlantikclient
In directory office:/tmp/cvs-serv22746/libatlantikclient

Modified Files:
      Tag: KDE_3_1_BRANCH
	atlantik_network.cpp atlantik_network.h 
Log Message:
bugfix wrt utf-8 handling (#52644)

Index: atlantik_network.cpp
===================================================================
RCS file: /home/kde/kdegames/atlantik/libatlantikclient/atlantik_network.cpp,v
retrieving revision 1.65
retrieving revision 1.65.4.1
diff -u -d -r1.65 -r1.65.4.1
--- atlantik_network.cpp	4 Nov 2002 19:33:02 -0000	1.65
+++ atlantik_network.cpp	6 Jan 2003 01:45:17 -0000	1.65.4.1
@@ -1,4 +1,4 @@
-// Copyright (c) 2002 Rob Kaper <[email protected]>
+// Copyright (c) 2002-2003 Rob Kaper <[email protected]>
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -16,6 +16,8 @@
 
 #include <iostream>
 
+#include <qtextcodec.h>
+#include <qtextstream.h>
 #include <qtimer.h>
 
 #include <kdebug.h>
@@ -37,12 +39,18 @@
 AtlantikNetwork::AtlantikNetwork(AtlanticCore *atlanticCore, QObject *parent, const char *name) : KExtendedSocket(0, 0, KExtendedSocket::inputBufferedSocket)
 {
 	m_atlanticCore = atlanticCore;
-	m_parent = parent;
+	m_textStream = new QTextStream(this);
+	m_textStream->setCodec(QTextCodec::codecForName("utf8"));
 	m_playerId = -1;
 
 	QObject::connect(this, SIGNAL(readyRead()), this, SLOT(slotRead()));
 }
 
+AtlantikNetwork::~AtlantikNetwork(void)
+{
+	delete m_textStream;
+}
+
 void AtlantikNetwork::rollDice()
 {	writeData(".r");
 }
@@ -205,7 +213,7 @@
 {
 	msg.append("\n");
 	if (socketStatus() == KExtendedSocket::connected)
-		writeBlock(msg.latin1(), strlen(msg.latin1()));
+		*m_textStream << msg;
 	else
 		kdDebug() << "could not send [" << msg << "]" << endl;
 }
@@ -214,11 +222,7 @@
 {
 	if (canReadLine())
 	{
-		char *tmp = new char[1024 * 32];
-		readLine(tmp, 1024 * 32);
-		processMsg(tmp);
-		delete[] tmp;
-
+		processMsg(m_textStream->readLine());
 		// There might be more data
 		QTimer::singleShot(0, this, SLOT(slotRead()));
 	}

Index: atlantik_network.h
===================================================================
RCS file: /home/kde/kdegames/atlantik/libatlantikclient/atlantik_network.h,v
retrieving revision 1.34
retrieving revision 1.34.4.1
diff -u -d -r1.34 -r1.34.4.1
--- atlantik_network.h	23 Oct 2002 19:18:19 -0000	1.34
+++ atlantik_network.h	6 Jan 2003 01:45:17 -0000	1.34.4.1
@@ -1,4 +1,4 @@
-// Copyright (c) 2002 Rob Kaper <[email protected]>
+// Copyright (c) 2002-2003 Rob Kaper <[email protected]>
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -30,12 +30,15 @@
 class Trade;
 class Auction;
 
+class QTextStream;
+
 class AtlantikNetwork : public KExtendedSocket
 {
 Q_OBJECT
 
 public:
 	AtlantikNetwork(AtlanticCore *atlanticCore, QObject *parent=0, const char *name=0);
+	virtual ~AtlantikNetwork(void);
 	void setName(QString name);
 	void cmdGamesList();
 	void cmdChat(QString msg);
@@ -164,7 +167,7 @@
 	void processNode(QDomNode);
 
 	AtlanticCore *m_atlanticCore;
-	QObject *m_parent;
+	QTextStream *m_textStream;
 	QDomDocument msg;
 
 	int m_playerId;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.