~kubuntu-members/libkdegames/4.11

« back to all changes in this revision

Viewing changes to libkdegamesprivate/kgame/kgameerror.cpp

  • Committer: Stefan Majewsky
  • Date: 2012-05-01 15:34:35 UTC
  • Revision ID: git-v1:82376fb5ca6f29f862641b6ca68603cb76258831
Begin to move stuff into libkdegamesprivate.

The build is now broken because I'm moving stuff without adjusting the
CMake files. But I figured it's cleaner to have the move in one commit
and the various edits in CMake and source files in the next commits.

svn path=/trunk/KDE/kdegames/libkdegames/; revision=1292461

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    This file is part of the KDE games library
 
3
    Copyright (C) 2001 Andreas Beckermann (b_mann@gmx.de)
 
4
    Copyright (C) 2001 Martin Heni (kde at heni-online.de)
 
5
 
 
6
    This library is free software; you can redistribute it and/or
 
7
    modify it under the terms of the GNU Library General Public
 
8
    License version 2 as published by the Free Software Foundation.
 
9
 
 
10
    This library is distributed in the hope that it will be useful,
 
11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
13
    Library General Public License for more details.
 
14
 
 
15
    You should have received a copy of the GNU Library General Public License
 
16
    along with this library; see the file COPYING.LIB.  If not, write to
 
17
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
18
    Boston, MA 02110-1301, USA.
 
19
*/
 
20
 
 
21
#include "kgameerror.h"
 
22
#include "kgamemessage.h"
 
23
 
 
24
#include <klocale.h>
 
25
 
 
26
QByteArray KGameError::errVersion(int remoteVersion)
 
27
{
 
28
 QByteArray b;
 
29
 QDataStream s(&b, QIODevice::WriteOnly);
 
30
 s << (qint32)KGameMessage::version();
 
31
 s << (qint32)remoteVersion;
 
32
 return b;
 
33
}
 
34
 
 
35
QByteArray KGameError::errCookie(int localCookie, int remoteCookie)
 
36
{
 
37
 QByteArray b;
 
38
 QDataStream s(&b, QIODevice::WriteOnly);
 
39
 s << (qint32)localCookie;
 
40
 s << (qint32)remoteCookie;
 
41
 return b;
 
42
}
 
43
 
 
44
QString KGameError::errorText(int errorCode, const QByteArray& message)
 
45
{
 
46
 QDataStream s(message);
 
47
 return errorText(errorCode, s);
 
48
}
 
49
 
 
50
QString KGameError::errorText(int errorCode, QDataStream& s)
 
51
{
 
52
 QString text;
 
53
 switch (errorCode) {
 
54
        case Cookie:
 
55
        {
 
56
                qint32 cookie1; 
 
57
                qint32 cookie2;
 
58
                s >> cookie1;
 
59
                s >> cookie2;
 
60
                text = i18n("Cookie mismatch!\nExpected Cookie: %1\nReceived Cookie: %2", cookie1, cookie2);
 
61
                break;
 
62
        }
 
63
        case Version:
 
64
        {
 
65
                qint32 version1;
 
66
                qint32 version2;
 
67
                s >> version1;
 
68
                s >> version2;
 
69
                text = i18n("KGame Version mismatch!\nExpected Version: %1\nReceived Version: %2\n", version1, version2);
 
70
                break;
 
71
        }
 
72
        default:
 
73
                text = i18n("Unknown error code %1", errorCode);
 
74
 }
 
75
 return text;
 
76
}
 
77