Close project on disconnect
[dashstudio.git] / src / shell / networkhandler.h
blob8f08c4809ae53130e6812c8d5f0953741c2cb94d
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 Dash::Network::Socket *socket() const;
82 void reset();
84 void showChatWindow();
86 protected:
87 virtual void readed(const QString &txt);
88 virtual void dataReaded(const QByteArray &data);
90 private slots:
91 void onReceiverFinished(const QString &fileName);
92 void onDisconnected();
94 private:
95 ProjectManager *m_manager;
96 Dash::Network::Socket *m_socket;
97 Dash::Network::FileReceiver *m_receiver;
99 QString m_sign;
101 Dash::Network::Package::Dispatcher *m_dispatcher;
103 YAMF::Command::Processor *m_processor;
105 QQueue<YAMF::Command::Base *> m_commands;
106 bool m_waitingResponse;
108 QString m_currentPackage;
110 Comm *m_comm;
113 #endif