KDEGames

kgameerror.cpp
1/*
2 This file is part of the KDE games library
3 SPDX-FileCopyrightText: 2001 Andreas Beckermann <b_mann@gmx.de>
4 SPDX-FileCopyrightText: 2001 Martin Heni <kde at heni-online.de>
5
6 SPDX-License-Identifier: LGPL-2.0-only
7*/
8
9#include "kgameerror.h"
10
11// own
12#include "kgamemessage.h"
13// KF
14#include <KLocalizedString>
15
16#include <QIODevice>
17
18QByteArray KGameError::errVersion(int remoteVersion)
19{
20 QByteArray b;
22 s << (qint32)KGameMessage::version();
23 s << (qint32)remoteVersion;
24 return b;
25}
26
27QByteArray KGameError::errCookie(int localCookie, int remoteCookie)
28{
29 QByteArray b;
31 s << (qint32)localCookie;
32 s << (qint32)remoteCookie;
33 return b;
34}
35
36QString KGameError::errorText(int errorCode, const QByteArray &message)
37{
38 QDataStream s(message);
39 return errorText(errorCode, s);
40}
41
42QString KGameError::errorText(int errorCode, QDataStream &s)
43{
44 QString text;
45 switch (errorCode) {
46 case Cookie: {
47 qint32 cookie1;
48 qint32 cookie2;
49 s >> cookie1;
50 s >> cookie2;
51 text = i18n("Cookie mismatch!\nExpected Cookie: %1\nReceived Cookie: %2", cookie1, cookie2);
52 break;
53 }
54 case Version: {
55 qint32 version1;
56 qint32 version2;
57 s >> version1;
58 s >> version2;
59 text = i18n("KGame Version mismatch!\nExpected Version: %1\nReceived Version: %2\n", version1, version2);
60 break;
61 }
62 default:
63 text = i18n("Unknown error code %1", errorCode);
64 }
65 return text;
66}
static int version()
QString i18n(const char *text, const TYPE &arg...)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:16:50 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.