Improved socket read/write
[dashstudio.git] / src / shell / networkhandler.h
blob78ab734a829b72267da8bef95a38fcf4ac282e7f
1 /***************************************************************************
2 * Copyright (C) 2007 by David Cuadrado *
3 * krawek@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 #ifndef NETWORKHANDLER_H
22 #define NETWORKHANDLER_H
24 #include <QObject>
25 #include <QQueue>
27 #include <dash/network/socketobserver.h>
28 #include <dash/network/package/dispatcher.h>
30 class Comm;
31 class ProjectManager;
32 class ProjectParams;
34 namespace YAMF {
35 namespace Command {
36 class Processor;
37 class Base;
41 namespace Dash {
42 namespace Network {
43 class Socket;
44 class FileReceiver;
46 namespace Package {
47 class Observer;
53 /**
54 * @author David Cuadrado <krawek@gmail.com>
56 class NetworkHandler : public QObject, Dash::Network::SocketObserver
58 Q_OBJECT;
60 public:
61 NetworkHandler(ProjectManager *manager, QObject *parent = 0);
62 ~NetworkHandler();
64 void connectToHost(const QString &host, quint16 port, const QString &login, const QString &password);
65 bool send(const QString &xml);
67 void addObserver(Dash::Network::Package::Observer *observer);
68 void removeObserver(Dash::Network::Package::Observer *observer);
70 void execute(YAMF::Command::Base *cmd);
72 void newProject(const ProjectParams *params);
74 void openProject();
75 void openProject(const QString &projectName);
77 bool isOpen() const;
78 bool isValid() const;
80 void showChatWindow();
82 protected:
83 virtual void readed(const QString &txt);
84 virtual void dataReaded(const QByteArray &data);
86 private slots:
87 void onReceiverFinished(const QString &fileName);
89 private:
90 ProjectManager *m_manager;
91 Dash::Network::Socket *m_socket;
92 Dash::Network::FileReceiver *m_receiver;
94 QString m_sign;
96 Dash::Network::Package::Dispatcher *m_dispatcher;
98 YAMF::Command::Processor *m_processor;
100 QQueue<YAMF::Command::Base *> m_commands;
101 bool m_waitingResponse;
103 QString m_currentPackage;
105 Comm *m_comm;
108 #endif