1 /***************************************************************************
2 * Copyright (C) 2007 by David Cuadrado *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program 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 *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
26 #include <dash/network/package/source.h>
27 #include <dash/network/package/chat.h>
28 #include <dash/network/package/notice.h>
29 #include <dash/network/package/wall.h>
31 #include <dash/network/parser/commparser.h>
33 #include "networkhandler.h"
34 #include "components/network/chatwindow.h"
36 Comm::Comm(NetworkHandler
*handler
)
37 : Dash::Network::Package::Observer(), m_handler(handler
)
39 m_chatWindow
= new Dash::Component::Network::ChatWindow
;
40 connect(m_chatWindow
, SIGNAL(sendText(const QString
&, int)), this, SLOT(onSendChat(const QString
&, int)));
49 void Comm::handlePackage(Dash::Network::Package::Source
*const pkg
)
51 QString root
= pkg
->root();
55 Dash::Network::Parser::Comm parser
;
57 if( parser
.parse(pkg
->xml()) )
59 m_chatWindow
->addMessage(parser
.from(), parser
.message());
62 else if(root
== "notice" )
64 Dash::Network::Parser::Comm parser
;
66 if( parser
.parse(pkg
->xml()) )
68 m_chatWindow
->addNotice(parser
.from(), parser
.message());
71 else if( root
== "wall" )
73 Dash::Network::Parser::Comm parser
;
75 if( parser
.parse(pkg
->xml()) )
77 DGui::Osd::self()->display(tr("%1 says: %2").arg(parser
.from()).arg(parser
.message()));
78 m_chatWindow
->addWall(parser
.from(), parser
.message());
83 Dash::Component::Network::ChatWindow
*Comm::chatWindow() const
88 void Comm::onSendChat(const QString
&text
, int type
)
92 case Dash::Component::Network::ChatWindow::Chat
:
94 Dash::Network::Package::Chat
chat(text
);
95 m_handler
->send(chat
.toString());
98 case Dash::Component::Network::ChatWindow::Notice
:
100 Dash::Network::Package::Notice
notice(text
);
101 m_handler
->send(notice
.toString());
104 case Dash::Component::Network::ChatWindow::Wall
:
106 Dash::Network::Package::Wall
wall(text
);
107 m_handler
->send(wall
.toString());