File: kgameerror.cpp

package info (click to toggle)
libkdegames 4%3A20.12.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 35,316 kB
  • sloc: cpp: 13,600; perl: 5,276; sh: 56; makefile: 13
file content (77 lines) | stat: -rw-r--r-- 2,075 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
    This file is part of the KDE games library
    Copyright (C) 2001 Andreas Beckermann (b_mann@gmx.de)
    Copyright (C) 2001 Martin Heni (kde at heni-online.de)

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License version 2 as published by the Free Software Foundation.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
    Boston, MA 02110-1301, USA.
*/

#include "kgameerror.h"
#include "kgamemessage.h"

#include <KLocalizedString>

QByteArray KGameError::errVersion(int remoteVersion)
{
 QByteArray b;
 QDataStream s(&b, QIODevice::WriteOnly);
 s << (qint32)KGameMessage::version();
 s << (qint32)remoteVersion;
 return b;
}

QByteArray KGameError::errCookie(int localCookie, int remoteCookie)
{
 QByteArray b;
 QDataStream s(&b, QIODevice::WriteOnly);
 s << (qint32)localCookie;
 s << (qint32)remoteCookie;
 return b;
}

QString KGameError::errorText(int errorCode, const QByteArray& message)
{
 QDataStream s(message);
 return errorText(errorCode, s);
}

QString KGameError::errorText(int errorCode, QDataStream& s)
{
 QString text;
 switch (errorCode) {
	case Cookie:
	{
		qint32 cookie1; 
		qint32 cookie2;
		s >> cookie1;
		s >> cookie2;
		text = i18n("Cookie mismatch!\nExpected Cookie: %1\nReceived Cookie: %2", cookie1, cookie2);
		break;
	}
	case Version:
	{
		qint32 version1;
		qint32 version2;
		s >> version1;
		s >> version2;
		text = i18n("KGame Version mismatch!\nExpected Version: %1\nReceived Version: %2\n", version1, version2);
		break;
	}
	default:
		text = i18n("Unknown error code %1", errorCode);
 }
 return text;
}