kgameerror.cpp

00001 /*
00002     This file is part of the KDE games library
00003     Copyright (C) 2001 Andreas Beckermann (b_mann@gmx.de)
00004     Copyright (C) 2001 Martin Heni (martin@heni-online.de)
00005 
00006     This library is free software; you can redistribute it and/or
00007     modify it under the terms of the GNU Library General Public
00008     License version 2 as published by the Free Software Foundation.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Library General Public License for more details.
00014 
00015     You should have received a copy of the GNU Library General Public License
00016     along with this library; see the file COPYING.LIB.  If not, write to
00017     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018     Boston, MA 02110-1301, USA.
00019 */
00020 /*
00021     $Id: kgameerror.cpp 465369 2005-09-29 14:33:08Z mueller $
00022 */
00023 
00024 #include "kgameerror.h"
00025 #include "kgamemessage.h"
00026 
00027 #include <klocale.h>
00028 
00029 QByteArray KGameError::errVersion(int remoteVersion)
00030 {
00031  QByteArray b;
00032  QDataStream s(b, IO_WriteOnly);
00033  s << (Q_INT32)KGameMessage::version();
00034  s << (Q_INT32)remoteVersion;
00035  return b;
00036 }
00037 
00038 QByteArray KGameError::errCookie(int localCookie, int remoteCookie)
00039 {
00040  QByteArray b;
00041  QDataStream s(b, IO_WriteOnly);
00042  s << (Q_INT32)localCookie;
00043  s << (Q_INT32)remoteCookie;
00044  return b;
00045 }
00046 
00047 QString KGameError::errorText(int errorCode, const QByteArray& message)
00048 {
00049  QDataStream s(message, IO_ReadOnly);
00050  return errorText(errorCode, s);
00051 }
00052 
00053 QString KGameError::errorText(int errorCode, QDataStream& s)
00054 {
00055  QString text;
00056  switch (errorCode) {
00057     case Cookie:
00058     {
00059         Q_INT32 cookie1; 
00060         Q_INT32 cookie2;
00061         s >> cookie1;
00062         s >> cookie2;
00063         text = i18n("Cookie mismatch!\nExpected Cookie: %1\nReceived Cookie: %2").arg(cookie1).arg(cookie2);
00064         break;
00065     }
00066     case Version:
00067     {
00068         Q_INT32 version1;
00069         Q_INT32 version2;
00070         s >> version1;
00071         s >> version2;
00072         text = i18n("KGame Version mismatch!\nExpected Version: %1\nReceived Version: %2\n").arg(version1).arg(version2);
00073         break;
00074     }
00075     default:
00076         text = i18n("Unknown error code %1").arg(errorCode);
00077  }
00078  return text;
00079 }
00080 
KDE Home | KDE Accessibility Home | Description of Access Keys