| 1 | /* smplayer, GUI front-end for mplayer.
|
|---|
| 2 | Copyright (C) 2006-2010 Ricardo Villalba <rvm@escomposlinux.org>
|
|---|
| 3 |
|
|---|
| 4 | This program is free software; you can redistribute it and/or modify
|
|---|
| 5 | it under the terms of the GNU General Public License as published by
|
|---|
| 6 | the Free Software Foundation; either version 2 of the License, or
|
|---|
| 7 | (at your option) any later version.
|
|---|
| 8 |
|
|---|
| 9 | This program is distributed in the hope that it will be useful,
|
|---|
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 12 | GNU General Public License for more details.
|
|---|
| 13 |
|
|---|
| 14 | You should have received a copy of the GNU General Public License
|
|---|
| 15 | along with this program; if not, write to the Free Software
|
|---|
| 16 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|---|
| 17 | */
|
|---|
| 18 |
|
|---|
| 19 | #ifndef _MYSERVER_H_
|
|---|
| 20 | #define _MYSERVER_H_
|
|---|
| 21 |
|
|---|
| 22 | #include <QTcpServer>
|
|---|
| 23 | #include <QTcpSocket>
|
|---|
| 24 | #include <QStringList>
|
|---|
| 25 |
|
|---|
| 26 | //! Connection holds a connection from MyServer to a client.
|
|---|
| 27 |
|
|---|
| 28 | /*!
|
|---|
| 29 | Connection objects are created by MyServer every time a new
|
|---|
| 30 | connection is made.
|
|---|
| 31 | It reads the text sent by the client, parses it, respond, and send
|
|---|
| 32 | signals to the server to report client requests.
|
|---|
| 33 | This class is for private use by MyServer.
|
|---|
| 34 | */
|
|---|
| 35 |
|
|---|
| 36 | class Connection : public QObject
|
|---|
| 37 | {
|
|---|
| 38 | Q_OBJECT
|
|---|
| 39 |
|
|---|
| 40 | public:
|
|---|
| 41 | Connection(QTcpSocket * s);
|
|---|
| 42 | ~Connection();
|
|---|
| 43 |
|
|---|
| 44 | void setActionsList(QStringList l) { actions_list = l; };
|
|---|
| 45 | QStringList actionsList() { return actions_list; };
|
|---|
| 46 |
|
|---|
| 47 | signals:
|
|---|
| 48 | void receivedOpen(QString);
|
|---|
| 49 | void receivedOpenFiles(QStringList);
|
|---|
| 50 | void receivedAddFiles(QStringList);
|
|---|
| 51 | void receivedFunction(QString);
|
|---|
| 52 | void receivedLoadSubtitle(QString);
|
|---|
| 53 |
|
|---|
| 54 | protected slots:
|
|---|
| 55 | void readData();
|
|---|
| 56 |
|
|---|
| 57 | protected:
|
|---|
| 58 | void sendText(QString l);
|
|---|
| 59 | void parseLine(QString str);
|
|---|
| 60 |
|
|---|
| 61 | private:
|
|---|
| 62 | QTcpSocket * socket;
|
|---|
| 63 | QStringList actions_list;
|
|---|
| 64 | QStringList files_to_open;
|
|---|
| 65 | };
|
|---|
| 66 |
|
|---|
| 67 | //! MyServer listens a port and waits for connections from other instances.
|
|---|
| 68 |
|
|---|
| 69 | /*!
|
|---|
| 70 | MyServer will listen the specified port and will send signals
|
|---|
| 71 | when another instance request something.
|
|---|
| 72 | */
|
|---|
| 73 |
|
|---|
| 74 | class MyServer : public QTcpServer
|
|---|
| 75 | {
|
|---|
| 76 | Q_OBJECT
|
|---|
| 77 |
|
|---|
| 78 | public:
|
|---|
| 79 | MyServer( QObject * parent = 0 );
|
|---|
| 80 |
|
|---|
| 81 | //! Tells the server to listen for incoming connections on port \a port.
|
|---|
| 82 | bool listen( quint16 port );
|
|---|
| 83 |
|
|---|
| 84 | //! Sets the list of actions.
|
|---|
| 85 | //! The list is printed when the client requests it.
|
|---|
| 86 | void setActionsList(QStringList l) { actions_list = l; };
|
|---|
| 87 |
|
|---|
| 88 | //! Returns the list of actions.
|
|---|
| 89 | QStringList actionsList() { return actions_list; };
|
|---|
| 90 |
|
|---|
| 91 | signals:
|
|---|
| 92 | //! Emitted when the client request to open a new file.
|
|---|
| 93 | void receivedOpen(QString);
|
|---|
| 94 |
|
|---|
| 95 | //! Emitted when the client request to open a list of files.
|
|---|
| 96 | void receivedOpenFiles(QStringList);
|
|---|
| 97 |
|
|---|
| 98 | //! Emitted when the client request to add a list of files to the playlist.
|
|---|
| 99 | void receivedAddFiles(QStringList);
|
|---|
| 100 |
|
|---|
| 101 | //! Emitted when the client request to perform an action.
|
|---|
| 102 | void receivedFunction(QString);
|
|---|
| 103 |
|
|---|
| 104 | //! Emitted when the client requests to load an external subtitle file.
|
|---|
| 105 | void receivedLoadSubtitle(QString);
|
|---|
| 106 |
|
|---|
| 107 | protected slots:
|
|---|
| 108 | void newConnection_slot();
|
|---|
| 109 |
|
|---|
| 110 | private:
|
|---|
| 111 | QStringList actions_list;
|
|---|
| 112 | };
|
|---|
| 113 |
|
|---|
| 114 | #endif
|
|---|