summaryrefslogtreecommitdiffstats
path: root/kommander/widget/kommanderwidget.h
blob: d3116c8060850a15dcbe26086b121151d44c414c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/***************************************************************************
                    kommanderwidget.h - Text widget core functionality 
                             -------------------
    copyright          : (C) 2002-2003 Marc Britton <consume@optusnet.com.au>
                         (C) 2004      Michal Rudolf <mrudolf@kdewebdwev.org>
    
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/
 
#ifndef _HAVE_KOMMANDERWIDGET_H_
#define _HAVE_KOMMANDERWIDGET_H_

/* KDE INCLUDES */
#include <kprocess.h>

#include "kommander_export.h"
/* QT INCLUDES */
#include <tqmap.h>
#include <tqobject.h>
#include <tqpair.h>
#include <tqstring.h>
#include <tqstringlist.h>

class ParserData;

class KOMMANDER_EXPORT KommanderWidget
{
  friend class MyProcess;
public:
  KommanderWidget(TQObject *);
  virtual ~KommanderWidget();

  //List of available states. Most widgets have only one state, but f. e. radiobutton has both 
  // 'checked' and 'unchecked'
  virtual TQStringList states() const;
  virtual TQStringList displayStates() const;
  virtual TQString currentState() const = 0;

  virtual bool isKommanderWidget() const = 0;

  // Associated script
  virtual void setAssociatedText(const TQStringList& a_associations);
  virtual TQStringList associatedText() const;
  virtual bool hasAssociatedText();

  // Execute default script, expanding all @macros.
  virtual TQString evalAssociatedText();
  // Execute given script, expanding all @macros.
  virtual TQString evalAssociatedText(const TQString&);
  // Evaluate given Kommander function using given args.
  virtual TQString evalFunction(const TQString& function, const TQStringList& args);
  // Parse and evaluate function for given widget, converting it to appropriate DCOP call.
  virtual TQString evalWidgetFunction(const TQString& identifier, const TQString& s, int& pos);
  // Evaluate given array function using given args.
  virtual TQString evalArrayFunction(const TQString&, const TQStringList&);
  // Parse and evaluate given execBegin..execEnd block.
  virtual TQString evalExecBlock(const TQStringList&, const TQString& s, int& pos);
  // Parse and evaluate given forEach..end block.
  virtual TQString evalForEachBlock(const TQStringList&, const TQString& s, int& pos);
  // Parse and evaluate given for..end block.
  virtual TQString evalForBlock(const TQStringList&, const TQString& s, int& pos);
  // Parse and evaluate given switch..case..end block.
  virtual TQString evalSwitchBlock(const TQStringList&, const TQString& s, int& pos);
  // Parse and evaluate given if..endif block.
  virtual TQString evalIfBlock(const TQStringList&, const TQString& s, int& pos);
  // Population text. It will become widgetText after populate() is called
  virtual TQString populationText() const;
  virtual void setPopulationText(const TQString&);
  virtual void populate() = 0;

  // Handles all widget-specific DCOP calls 
  virtual TQString handleDCOP(int function, const TQStringList& args = TQStringList());
  // Checks if appropriate function is supported by widget. By default all functions
  // are reported as supported: use this to allow recognizing incorrect function calls.
  virtual bool isFunctionSupported(int function);
  // Checks if the function is common widget function (i. e. supported by all widgets)
  virtual bool isCommonFunction(int function);
  // Checks if the string is a valid widget name)
  virtual bool isWidget(const TQString& a_name) const;
  // Returns widget from name 
  virtual KommanderWidget* widgetByName(const TQString& a_name) const;
  // Returns current widget name;
  virtual TQString widgetName() const;
  // Returns filename associated with the dialog
  virtual TQString fileName();

  TQObject* object() { return m_thisObject;}


  // Recognizes editor vs executor mode
  static bool inEditor;
  // Prints errors in message boxes, not in stderr
  static bool showErrors;
  // Default parser
  static bool useInternalParser;
  // Return global variable value
  TQString global(const TQString& variableName);
  // Set global variable value
  void setGlobal(const TQString& variableName, const TQString& value);

protected:
  virtual void setStates(const TQStringList& a_states);
  virtual void setDisplayStates(const TQStringList& a_displayStates);

  // Execute DCOP query and return its result or null on failure
  // Only TQString and int are now handled
  TQString DCOPQuery(const TQStringList& args);
  TQString localDCOPQuery(const TQString function, const TQStringList& args = TQStringList());
  TQString localDCOPQuery(const TQString function, const TQString& arg1, 
     const TQString& arg2, const TQString& arg3 = TQString(),
     const TQString& arg4 = TQString());
  // Execute given command, return its result
  TQString execCommand(const TQString& a_command, const TQString& a_shell = TQString()) const;
  // Find and run dialog (with optional parameters)
  TQString runDialog(const TQString& a_dialog, const TQString& a_params = TQString());
  // Display error message a_error; display current class name if no other is given
  void printError(const TQString& a_error) const;
  // Auxiliary functions for parser
  // Find matching brackets starting from current position
  TQString parseBrackets(const TQString& s, int& from, bool& ok) const;
  // Return identifier: the longest string of letters and numbers starting from i
  TQString parseIdentifier(const TQString& s, int& from) const;
  // Parse arguments for given function. Returns list of arguments without quotations
  TQStringList parseArgs(const TQString& s, bool &ok);
  // Remove quotes from given identifier
  TQString parseQuotes(const TQString& s) const;
  // Parse function
  TQStringList parseFunction(const TQString& group, const TQString& function,
    const TQString& s, int& from, bool& ok);
  // Detect and return block boundary
  int parseBlockBoundary(const TQString& s, int from, const TQStringList& args) const;

  // Parse given identifier as widget name
  KommanderWidget* parseWidget(const TQString& name) const;
  // Return parent dialog of this widget
  TQWidget* parentDialog() const;
  TQString substituteVariable(TQString text, TQString variable, TQString value) const;

  ParserData* internalParserData() const;

  TQObject *m_thisObject;
  TQStringList m_states;
  TQStringList m_displayStates;
  TQStringList m_associatedText;
  TQString m_populationText;

  // Internal parser data
  static ParserData* m_parserData;
};


#define ESCCHAR '@'

#endif