~kubuntu-members/libkdegames/4.11

« back to all changes in this revision

Viewing changes to kgame/dialogs/kgameerrordialog.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 "kgameerrordialog.h"
22
 
 
23
 
#include <kmessagebox.h>
24
 
#include <klocale.h>
25
 
#include <kdebug.h>
26
 
 
27
 
#include "kgame.h"
28
 
 
29
 
class KGameErrorDialogPrivate
30
 
{
31
 
public:
32
 
        KGameErrorDialogPrivate()
33
 
        {
34
 
                mGame = 0;
35
 
        }
36
 
 
37
 
        const KGame* mGame;
38
 
};
39
 
 
40
 
KGameErrorDialog::KGameErrorDialog(QWidget* parent) : QObject(parent)
41
 
{
42
 
 d = new KGameErrorDialogPrivate;
43
 
}
44
 
 
45
 
KGameErrorDialog::~KGameErrorDialog()
46
 
{
47
 
 delete d;
48
 
}
49
 
 
50
 
void KGameErrorDialog::setKGame(const KGame* g)
51
 
{
52
 
 slotUnsetKGame();
53
 
 d->mGame = g;
54
 
 
55
 
 connect(d->mGame, SIGNAL(destroyed()), this, SLOT(slotUnsetKGame()));
56
 
 
57
 
// the error signals:
58
 
 connect(d->mGame, SIGNAL(signalNetworkErrorMessage(int,QString)), 
59
 
                this, SLOT(slotError(int,QString)));
60
 
 connect(d->mGame, SIGNAL(signalConnectionBroken()), 
61
 
                this, SLOT(slotServerConnectionLost()));
62
 
 connect(d->mGame, SIGNAL(signalClientDisconnected(quint32,bool)), 
63
 
                this, SLOT(slotClientConnectionLost(quint32,bool)));
64
 
}
65
 
 
66
 
void KGameErrorDialog::slotUnsetKGame()
67
 
{
68
 
 if (d->mGame) {
69
 
        disconnect(d->mGame, 0, this, 0);
70
 
 }
71
 
 d->mGame = 0;
72
 
}
73
 
 
74
 
void KGameErrorDialog::error(const QString& errorText, QWidget* parent)
75
 
{ KMessageBox::error(parent, errorText); }
76
 
 
77
 
void KGameErrorDialog::slotServerConnectionLost()
78
 
{
79
 
// TODO: add IP/port of the server
80
 
 QString message = i18n("Connection to the server has been lost!");
81
 
 error(message, (QWidget*)parent());
82
 
}
83
 
 
84
 
void KGameErrorDialog::slotClientConnectionLost(quint32 /*id*/,bool)
85
 
{
86
 
//TODO: add IP/port of the client
87
 
 QString message;
88
 
// if (c) {
89
 
//      message = i18n("Connection to client has been lost!\nID: %1\nIP: %2").arg(c->id()).arg(c->IP());
90
 
// } else {
91
 
//      message = i18n("Connection to client has been lost!");
92
 
// }
93
 
 message = i18n("Connection to client has been lost!");
94
 
 error(message, (QWidget*)parent());
95
 
}
96
 
 
97
 
void KGameErrorDialog::slotError(int errorNo, const QString& text)
98
 
{
99
 
 QString message = i18n("Received a network error!\nError number: %1\nError message: %2", errorNo, text);
100
 
 error(message, (QWidget*)parent());
101
 
}
102
 
 
103
 
void KGameErrorDialog::connectionError(const QString& s)
104
 
{
105
 
 QString message;
106
 
 if (s.isNull()) {
107
 
        message = i18n("No connection could be created.");
108
 
 } else {
109
 
        message = i18n("No connection could be created.\nThe error message was:\n%1", s);
110
 
 }
111
 
 error(message, (QWidget*)parent());
112
 
}
113
 
 
114
 
 
115
 
 
116
 
// should become the real dialog - currently we just use messageboxes 
117
 
// -> maybe unused forever
118
 
KGameErrorMessageDialog::KGameErrorMessageDialog(QWidget* parent) 
119
 
                : KDialog(parent)
120
 
{
121
 
        setCaption(i18n("Error"));
122
 
        setButtons(Ok);
123
 
        setDefaultButton(Ok);
124
 
        setModal(true);
125
 
        showButtonSeparator(true);
126
 
}
127
 
 
128
 
KGameErrorMessageDialog::~KGameErrorMessageDialog()
129
 
{
130
 
}
131
 
 
132
 
 
133
 
 
134
 
#include "kgameerrordialog.moc"