KDEGames

kgameerror.cpp
1 /*
2  This file is part of the KDE games library
3  SPDX-FileCopyrightText: 2001 Andreas Beckermann <[email protected]>
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 QByteArray KGameError::errVersion(int remoteVersion)
17 {
18  QByteArray b;
20  s << (qint32)KGameMessage::version();
21  s << (qint32)remoteVersion;
22  return b;
23 }
24 
25 QByteArray KGameError::errCookie(int localCookie, int remoteCookie)
26 {
27  QByteArray b;
29  s << (qint32)localCookie;
30  s << (qint32)remoteCookie;
31  return b;
32 }
33 
34 QString KGameError::errorText(int errorCode, const QByteArray& message)
35 {
36  QDataStream s(message);
37  return errorText(errorCode, s);
38 }
39 
40 QString KGameError::errorText(int errorCode, QDataStream& s)
41 {
42  QString text;
43  switch (errorCode) {
44  case Cookie:
45  {
46  qint32 cookie1;
47  qint32 cookie2;
48  s >> cookie1;
49  s >> cookie2;
50  text = i18n("Cookie mismatch!\nExpected Cookie: %1\nReceived Cookie: %2", cookie1, cookie2);
51  break;
52  }
53  case Version:
54  {
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 }
67 
QString i18n(const char *text, const TYPE &arg...)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Dec 7 2021 22:34:14 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.