1 /***************************************************************************
2 * Copyright (C) 2007 by Jorge Cuadrado *
3 * kuadrosxx@gmail.com *
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 ***************************************************************************/
21 #include "commanager.h"
29 #include <QXmlStreamReader>
30 #include <QXmlStreamWriter>
34 #include "connection.h"
37 #include "users/user.h"
39 #include "project/store.h"
40 #include "project/projectmanager.h"
42 namespace DashServer
{
45 struct Manager::Private
47 QString
writeFromAttribute(const QString
&pkg
, const QString
&from
);
50 QString
Manager::Private::writeFromAttribute(const QString
&pkg
, const QString
&from
)
54 QXmlStreamReader
reader(pkg
);
55 QXmlStreamWriter
writer(&xml
);
57 while(!reader
.atEnd() )
60 writer
.writeCurrentToken(reader
);
62 if( reader
.tokenType() == QXmlStreamReader::StartElement
)
64 if( reader
.name().toString() == "message" )
66 writer
.writeAttribute("from", from
);
75 : DashServer::Observer(), d(new Private
)
85 void Manager::handlePackage(DashServer::Package
*const pkg
)
88 DashServer::Connection
*cnn
= pkg
->source();
89 DashServer::TcpServer
*server
= cnn
->server();
91 if( pkg
->root() == "chat" )
93 QString projectName
= cnn
->data(Project::Store::ProjectName
).toString();
95 if( !projectName
.isEmpty() )
97 server
->projectManager()->sendToMembers(projectName
, d
->writeFromAttribute(pkg
->xml(), cnn
->user()->login()));
101 else if( pkg
->root() == "notice" )
103 QString projectName
= cnn
->data(Project::Store::ProjectName
).toString();
105 if( !projectName
.isEmpty() )
107 server
->projectManager()->sendToMembers(projectName
, d
->writeFromAttribute(pkg
->xml(), cnn
->user()->login()));
111 else if( pkg
->root() == "wall" )
113 cnn
->sendToAll(d
->writeFromAttribute(pkg
->xml(), cnn
->user()->login()), true);