File indexing completed on 2024-03-24 15:43:28

0001 /***************************************************************************
0002                           ctextprocessor.h  -  text processor
0003     This file is a part of KMuddy distribution.
0004                              -------------------
0005     begin                : Po oct 14 2002
0006     copyright            : (C) 2002 by Tomas Mecir
0007     email                : kmuddy@kmuddy.com
0008  ***************************************************************************/
0009 
0010 /***************************************************************************
0011  *                                                                         *
0012  *   This program is free software; you can redistribute it and/or modify  *
0013  *   it under the terms of the GNU General Public License as published by  *
0014  *   the Free Software Foundation; either version 2 of the License, or     *
0015  *   (at your option) any later version.                                   *
0016  *                                                                         *
0017  ***************************************************************************/
0018 
0019 #ifndef CTEXTPROCESSOR_H
0020 #define CTEXTPROCESSOR_H
0021 
0022 #include <qobject.h>
0023 #include <qcolor.h>
0024 
0025 #include <list>
0026 
0027 #include "cactionbase.h"
0028 #include "ctextchunk.h"
0029 
0030 using namespace std;
0031 
0032 class cTextChunk;
0033 
0034 class QTimer;
0035 
0036 /**
0037 Text processor - handles trigger execution and such...
0038   *@author Tomas Mecir
0039   */
0040 
0041 class cTextProcessor : public QObject, public cActionBase {
0042    Q_OBJECT
0043 public: 
0044   cTextProcessor (int sess);
0045   ~cTextProcessor () override;
0046   int linesReceived () { return lines; };
0047 
0048   /** recolorize the line - used by color triggers */
0049   void recolorize (list<colorChange> &changes);
0050   /** this line should be gagged - called by gagging triggers */
0051   void gagLine () { gag = true; };
0052   /** this line should be gagged in primary window */
0053   void gagLineInPrimary () { primarygag = true; };
0054   void setHavePrompt () { haveprompt = true; };
0055   /** handle some issued when sending a command */
0056   void sendingCommand ();
0057 
0058   void setOutputWindow(QString winname) { wname = winname; };
0059   
0060   void eventStringHandler (QString event, int session, QString &par1, const QString &) override;
0061   void eventNothingHandler (QString event, int session) override;
0062 
0063 public slots:
0064   // processing of various received items...
0065   
0066   /** process this text */
0067   void gotNewText (const QString &text);
0068   /** process fg color */
0069   void gotFgColor (QColor color);
0070   /** process bg color */
0071   void gotBgColor (QColor color);
0072   /** process attribute */
0073   void gotAttrib (int a);
0074   /** process A-link */
0075   void gotALink (const QString &name, const QString &url, const QString &text,
0076       const QString &hint);
0077   /** process SEND-link */
0078   void gotSENDLink (const QString &name, const QString &command, const QString &text,
0079       const QString &hint, bool toprompt, bool ismenu);
0080   /** process newline */
0081   void gotNewLine ();
0082   /** process tag expiration */
0083   void gotExpire (const QString &name);
0084     
0085 signals:
0086   /** we got this plain text - ANSI parser should be connected here */
0087   void plainText (const QString &text);
0088   
0089   void textLine (const QString &text);
0090 protected slots:
0091   /** used by prompt-detection timer */
0092   void timeout ();
0093 protected:
0094 
0095   /** parse this text, pass it to MXP parser if needed and so... */
0096   void parseText (const QString &text);
0097   void receivedGA ();
0098   void flush ();
0099   /** used to display partial lines in the status bar */
0100   void moreTextHere ();
0101 
0102   /** create a new chunk */
0103   void createChunk ();
0104 
0105   /** a timer used to auto-detect prompts */
0106   QTimer *pdtimer;
0107   int elapsedticks;
0108 
0109   cTextChunk *chunk;
0110   
0111   int lines;
0112 
0113   /** gagging */
0114   bool gag, primarygag;
0115   /** prompt detection */
0116   bool haveprompt, gotprompt;
0117 
0118   bool owin;
0119   QString wname;
0120   
0121   //current text attributes, used to set startpos correctly when breaking lines
0122   QColor fg, bg;
0123   int attrib;
0124 };
0125 
0126 #endif