File indexing completed on 2024-05-12 04:04:16
0001 /*************************************************************************** 0002 File : textprotocol.h 0003 Project : Knights 0004 Description : Base class for text protocols 0005 -------------------------------------------------------------------- 0006 SPDX-FileCopyrightText: 2017 Alexander Semke (alexander.semke@web.de) 0007 SPDX-FileCopyrightText: 2009-2011 Miha Čančula (miha@noughmad.eu) 0008 0009 ***************************************************************************/ 0010 0011 /*************************************************************************** 0012 * * 0013 * SPDX-License-Identifier: GPL-2.0-or-later 0014 * * 0015 * This program is distributed in the hope that it will be useful, * 0016 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0018 * GNU General Public License for more details. * 0019 * * 0020 * You should have received a copy of the GNU General Public License * 0021 * along with this program; if not, write to the Free Software * 0022 * Foundation, Inc., 51 Franklin Street, Fifth Floor, * 0023 * Boston, MA 02110-1301 USA * 0024 * * 0025 ***************************************************************************/ 0026 0027 #ifndef KNIGHTS_TEXTPROTOCOL_H 0028 #define KNIGHTS_TEXTPROTOCOL_H 0029 0030 #include <proto/protocol.h> 0031 #include "chatwidget.h" 0032 0033 #include <QList> 0034 #include <QTextStream> 0035 0036 namespace Knights { 0037 0038 class TextProtocol : public Protocol { 0039 Q_OBJECT 0040 public: 0041 explicit TextProtocol(QObject* parent = nullptr); 0042 ~TextProtocol() override; 0043 0044 protected: 0045 void setDevice(QIODevice*); 0046 QIODevice* device() const; 0047 0048 void setConsole(ChatWidget*); 0049 ChatWidget* console() const; 0050 0051 void writeToConsole(const QString&, ChatWidget::MessageType); 0052 0053 virtual bool parseLine(const QString&) = 0; 0054 virtual bool parseStub(const QString&) = 0; 0055 0056 protected Q_SLOTS: 0057 void readFromDevice(); 0058 void write(const QString&); 0059 void write(const char*); 0060 void writeCheckMoves(const QString&); 0061 0062 private: 0063 QTextStream stream; 0064 QPointer<ChatWidget> m_console; 0065 QList<ChatWidget::Message> messages; 0066 QString line; 0067 }; 0068 0069 } 0070 0071 #endif // KNIGHTS_TEXTPROTOCOL_H