- Implemented query and update project
[dashstudio.git] / src / dashserver / com / commanager.cpp
blob98b644ba13d49b55c33d9dc0c02f091f3bf59005
1 /***************************************************************************
2 * Copyright (C) 2007 by Jorge Cuadrado *
3 * kuadrosxx@gmail.com *
4 * *
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. *
9 * *
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. *
14 * *
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"
23 //base
24 #include "package.h"
25 #include "logger.h"
27 //Qt
28 #include <QVariant>
29 #include <QXmlStreamReader>
30 #include <QXmlStreamWriter>
32 //server/core
33 #include "server.h"
34 #include "connection.h"
36 //server/users
37 #include "users/user.h"
39 #include "project/store.h"
40 #include "project/projectmanager.h"
42 namespace DashServer {
43 namespace Com {
45 struct Manager::Private
47 QString writeFromAttribute(const QString &pkg, const QString &from);
50 QString Manager::Private::writeFromAttribute(const QString &pkg, const QString &from)
52 QString xml;
54 QXmlStreamReader reader(pkg);
55 QXmlStreamWriter writer(&xml);
57 while(!reader.atEnd() )
59 reader.readNext();
60 writer.writeCurrentToken(reader);
62 if( reader.tokenType() == QXmlStreamReader::StartElement)
64 if( reader.name().toString() == "message" )
66 writer.writeAttribute("from", from);
71 return xml;
74 Manager::Manager()
75 : DashServer::Observer(), d(new Private)
80 Manager::~Manager()
82 delete d;
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()));
98 pkg->accept();
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()));
108 pkg->accept();
111 else if( pkg->root() == "wall" )
113 cnn->sendToAll(d->writeFromAttribute(pkg->xml(), cnn->user()->login()), true);
114 pkg->accept();