File indexing completed on 2024-04-14 04:00:13

0001 /***************************************************************************
0002                           csaveablefield.h  -  alias/trigger baseclass
0003     This file is a part of KMuddy distribution.
0004                              -------------------
0005     begin                : So sep 7 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 CSAVEABLEFIELD_H
0020 #define CSAVEABLEFIELD_H
0021 
0022 #include <QString>
0023 #include <QStringList>
0024 
0025 #include "cpattern.h"
0026 
0027 class KConfig;
0028 
0029 /**
0030 Abstract base-class for alias / trigger objects (and more).
0031 Knows how to save itself.
0032 
0033 This class is arranged in a double-linked list.
0034 
0035   *@author Tomas Mecir
0036   */
0037 
0038 //object types
0039 #define TYPE_ALIAS 1
0040 #define TYPE_TRIGGER 2
0041 #define TYPE_ACTION 3
0042 #define TYPE_GROUP 4
0043 #define TYPE_SCRIPT 5
0044 #define TYPE_TIMER 6
0045 #define TYPE_SHORTCUT 7
0046 #define TYPE_VARIABLE 8
0047 #define TYPE_VARTRIG 9
0048 #define TYPE_TIMERTICK 10
0049 #define TYPE_GAUGE 11
0050 #define TYPE_STATUSVAR 12
0051 
0052 class cSaveableField {
0053 public:
0054   friend class cSaveableList;
0055 
0056   /** constructor */
0057   cSaveableField ();
0058   /** destructor */
0059   virtual ~cSaveableField ();
0060 
0061   /** creates a new instance of the class; this is needed because I need to
0062   create instances of childclasses from within this class, but I don't know
0063   the exact type of that instance... */
0064   virtual cSaveableField *newInstance () = 0;
0065 
0066   /** abstract; load data from a config file*/
0067   virtual void load (KConfig *config, const QString &group) = 0;
0068 
0069   /** abstract; returns type of item (light-weight RTTI) */
0070   virtual int itemType () = 0;
0071 
0072   /** set alias/trigger text */
0073   void setText (const QString &_text) { p.setPattern (_text); };
0074   /** returns current alias/trigger text */
0075   QString getText () { return p.pattern(); };
0076 
0077   /** set alias/trigger replacement(s)/command(s) */
0078   void setNewText (const QStringList &_text) { newtext = _text; } ;
0079   /** returns current alias/trigger replacement/command */
0080   QStringList getNewText () { return newtext; };
0081 
0082   void setGlobal (bool g) { globalmatch = g; };
0083   bool global () { return globalmatch; };
0084 
0085   /** set a new condition for matching */
0086   void setCond (const QString &c);
0087   /** return the condition */
0088   QString cond () { return condition; };
0089 
0090   void setCaseSensitive (bool cs) { p.setCaseSensitive (cs); };
0091   bool caseSensitive () { return p.caseSensitive(); };
0092 
0093   /** set comparison type */
0094   void setType (int t) { p.setMatching ((cPattern::PatternType) t); };
0095   /** returns comparison type */
0096   int getType () { return (int) p.matching(); };
0097   /** possible types of comparison */
0098   enum compType { exact, substring, begin, end, regexp };
0099   #define TYPES 5
0100 protected:
0101   cPattern p;
0102 
0103   /** fields form a double-linked list. These are some other entries... */
0104   cSaveableField *prev, *next;
0105 
0106   /** alias replacement(s) or triggered command(s) */
0107   QStringList newtext;
0108   /** condition to match */
0109   QString condition;
0110 
0111   /** global matching */
0112   bool globalmatch;
0113 };
0114 
0115 #endif