summaryrefslogtreecommitdiffstats
path: root/src/kile/kiletool.h
blob: a60a32b3ed580204fdf0c72a3c2406e89db1843a (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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
/***************************************************************************
    begin                : mon 3-11 20:40:00 CEST 2003
    copyright            : (C) 2003 by Jeroen Wijnhout
    email                : Jeroen.Wijnhout@kdemail.net
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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 KILETOOL_H
#define KILETOOL_H

#include "kilelauncher.h"

#include <tqobject.h>
#include <tqmap.h>
#include <tqstring.h>
#include <tqdict.h>
#include <tqstringlist.h>

class KConfig;
class KileInfo;
class KShellProcess;
class KileProject;

namespace KileTool
{
	typedef TQMap<TQString,TQString> Config;

	class Manager;
	
	/**
 	* A class that defines a general tool (latex, dvips etc.) to be launched from
	* within Kile.
	*
	* @author Jeroen Wijnhout
	**/

	class Base : public TQObject
	{
		Q_OBJECT
  

	public:
		Base(const TQString &name, Manager *manager, bool prepare = true);
		~Base();

		/**
		 * Sets the KileInfo object, this is already taken care of by the Manager.
		 **/
		void setInfo(KileInfo *ki) { m_ki = ki; }
		
		/**
		 * Sets the KConfig object, this is already taken care of by the Manager.
		 **/
		void setConfig(KConfig *config) { m_config = config; }
		
		/**
		 * @returns the Manager object for this tool.
		 **/
		Manager* manager() const { return m_manager; }
		
		/**
		 * @returns a short descriptive name for this tool.
		 **/
		const TQString& name() const { return m_name; }
		
		/**
		 * Allows you to set the source file explicitly (absolute path).
		 **/
		virtual void setSource(const TQString & source);
		
		/**
		 * @returns the source file that is used to run the tool on.
		 **/
		const TQString source(bool absolute = true) const;
		
		const TQString S() const { return m_S; }
		const TQString baseDir() const { return m_basedir; }
		const TQString relativeDir() const { return m_relativedir; }
		const TQString targetDir() const { return m_targetdir; }
		const TQString from() const { return m_from; }
		const TQString to() const { return m_to; }
		const TQString target() const { return m_target; }
		const TQString options() const { return m_options; }

		void setOptions(const TQString &opt) { m_options = opt; }

		virtual bool isViewer() { return false; }

		void setQuickie() { m_quickie = true; }
		bool isQuickie() { return m_quickie; }

		/**
		 * Allows you to set the target file explicitly (filename only).
		 **/
		virtual void setTarget(const TQString & target);
		virtual void setTargetDir(const TQString & target);
		virtual void setTargetPath(const TQString & target);

		/**
		 * Sets the target directory relative to the source directory.
		 **/
		void setRelativeBaseDir(const TQString & dir) { m_relativedir = dir; }

		/**
		 * Installs a launcher object that will be responsible for actually starting the tool. The
		 * tool can be a command-line tool or a kpart, the KileTool class doesn't need to know
		 * about the specifics of the launcher.
		 **/
		void installLauncher(Launcher *lr );
		
		/**
		 * Installs a launcher as indicated by the tool type. This creates a launcher object.
		 **/
		bool installLauncher();

		/**
		 * @returns a pointer to the launcher object, returns 0 if no launcher is installed.
		 **/
		Launcher *launcher() { return m_launcher; }

		/**
		 * @returns the working dir for this tool.
		 **/
		const TQString &workingDir() const { return m_basedir; }

		/**
		 * @returns the dictionary that translates the following keys
		 * %dir_base : the directory of the root file
		 * %dir_target : same as %dir_base, except when the relativeDir has been set explicitly, then %dir_target= %dir_base/relativedir
		 * %source : the source file (no path)
		 * %S : the source filename without an extension (no path)
		 **/
		TQDict<TQString>* paramDict() { return &m_dictParams; }

		bool addDict(const TQString & key, const TQString & value);

		void translate(TQString &str);

		void setFlags(uint flags) { m_flags = flags; }
		uint flags() { return m_flags; }

		void setMsg(long n, const TQString & msg);
		TQString msg(long n) const { return m_messages[n]; }

	protected:
		bool needsUpdate(const TQString &target, const TQString &source);

	public slots:
		void sendMessage(int, const TQString &);
		virtual void filterOutput(const TQString &);

	signals:
		void message(int, const TQString &, const TQString &);
		void output(const TQString &);

		void start(Base*);
		void done(Base*, int);

		void requestSaveAll(bool amAutoSaving = false, bool disUntitled= false);

	public:
		void setEntryMap(Config map) { m_entryMap = map; }
		const TQString readEntry(const TQString & key) { return m_entryMap[key]; }

	public:
		virtual void prepareToRun(const TQString &cfg = TQString());
    		bool isPrepared() { return m_bPrepared; }
		bool needsToBePrepared() { return m_bPrepareToRun; }

	protected:
		/**
		 * Checks if the prerequisites are in order.
		 * @returns true if everything is ok, false otherwise.
		 **/
		virtual bool checkPrereqs();

		/**
		 * Determines on which file to run the tool.
		 **/
		virtual bool determineSource();
		
		/**
		 * Determines the target of the tool (i.e. a DVI for latex, PS for dvips) and
		 * checks if the target file can be written to the specified location.
		 **/
		virtual bool determineTarget();

		/**
		 * Check if the target dir and file have the correct permissions (according to the flags set).
		 **/
		virtual bool checkTarget();
		
		virtual bool checkSource();

  public:
		/**
		 * Configures the tool object.
		 **/
		 virtual bool configure(const TQString & cfg = TQString());

	public slots:
		/**
		 * Starts the tool. First it performs basic checks (checkPrereqs()),
		 * if all is well it launches the tool (launch()). After the process has
		 * exited it calls finish().
		 * @return the exit code of the tool (if available)
		 **/
		virtual int run();

		/**
		 * Terminates the running process.
		 **/
		virtual void stop();

		/**
		 * Clean up after the process/lib has finished.
		 **/
		virtual bool finish(int);

	private:
		Manager			*m_manager;
		KileInfo		*m_ki;
		KConfig			*m_config;

		TQString			m_name, m_from, m_to;
		TQString			m_target, m_basedir, m_relativedir, m_targetdir, m_source, m_S, m_options;
		TQString			m_resolution;

		TQString			m_message;

		bool			m_buildPrereqs;

	protected:
		Launcher			*m_launcher;
		bool m_quickie;

	private:
		TQDict<TQString>		m_dictParams;
		Config				m_entryMap;

		uint		    	m_flags;
		int					m_nPreparationResult;
		bool				m_bPrepared;
        bool                m_bPrepareToRun;

		//messages
		TQMap<long,TQString>	m_messages;
	};

	/**
	 * A class that represents a compile tool (such as latex, pdflatex).
	 **/
	class Compile : public Base
	{
	public:
		Compile(const TQString &name, Manager * manager, bool prepare = true);
		~Compile();
		
	protected:
		bool checkSource();
	};

	/**
	 * A class that represents a view tool (such as KDVI, gv, etc.).
	 **/
	class View : public Base
	{
	public:
		View(const TQString &name, Manager * manager, bool prepare = true);
		~View();

		bool isViewer() { return true; }
	};

	/**
	 * A class that represents a conversion tool (such as dvips).
	 **/
	class Convert : public Base
	{
	public:
		Convert(const TQString &name, Manager * manager, bool prepare = true);
		~Convert();
		
		bool determineSource();
	};

	/**
	 * A class that represents a tool like tar, from multiple files to one file
	 **/
	class Archive: public Base
	{
		Q_OBJECT
  
 
	public:
		Archive(const TQString &name, Manager * manager, bool prepare = true);
		~Archive();
		bool checkPrereqs();
 		void setSource(const TQString & source);
	private:
		KileProject *m_project;
		TQString m_fileList;
	};
	
	class Sequence : public Base
	{
		Q_OBJECT
  
		
	public:
		Sequence(const TQString &name, Manager * manager, bool prepare = true);

	public slots:
		int run();
	};
}

#endif