summaryrefslogtreecommitdiffstats
path: root/src/kile/templates.h
blob: 76a7121cb60679b5599b957e72a3e5eff3a21c7b (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
/***************************************************************************************
    begin                : Sat Apr 26 2003
    copyright            : (C) 2003 by Jeroen Wijnhout (wijnhout@science.uva.nl)
                               2007 by Michel Ludwig (michel.ludwig@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 TEMPLATES_H
#define TEMPLATES_H


/**
  *@author Jeroen Wijnhout
  */

#include <kstandarddirs.h>
#include <kiconview.h>
#include <klocale.h>
#include <kprocess.h>
#include <kurl.h>

#include <tqobject.h>
#include <tqvaluelist.h>

#include "kileconstants.h"

#define DEFAULT_EMPTY_ICON "type_Empty"

class KileInfo;

namespace KileTemplate {

struct Info {
	public:
		Info();

		TQString name;
		TQString path;
		TQString icon;
		KileDocument::Type type;
		
		bool operator==(const Info ti) const;
};

typedef TQValueList<Info> TemplateList;
typedef TQValueListIterator<Info> TemplateListIterator;
typedef TQValueListConstIterator<Info> TemplateListConstIterator;

class Manager : public TQObject {
	Q_OBJECT
  TQ_OBJECT
	
	public:
		Manager(KileInfo *info, TQObject* tqparent = NULL, const char* name = NULL);
		virtual ~Manager();

		void scanForTemplates();

		/**
		* Get all the templates.
		**/
		TemplateList getAllTemplates() const;

		/**
		* Get all the templates of a certain type.
		*
		* @param type The type of the templates that should be returned. You can pass "KileDocument::Undefined" to
		*             retrieve every template.
		**/
		TemplateList getTemplates(KileDocument::Type type) const;

		/**
		 * Checks whether a template with a given name and type exists.
		 *
		 * @return true iff a template with the given name and type could be found
		 **/
		bool searchForTemplate(const TQString& name, KileDocument::Type& type) const;

		//add a template in $HOME/kile/templates/
		bool add(const KURL& templateSourceURL, const TQString& name, const KURL& icon);
		
		//remove a template from $HOME/kile/templates/
		bool remove(KileTemplate::Info ti);

		//replaces a template
		bool replace(const KileTemplate::Info& toBeReplaced, const KURL& newTemplateSourceURL, const TQString& newName, const KURL& newIcon);

	protected:
		KileInfo* m_kileInfo;

	private:
		bool copyAppData(const KURL& src, const TQString& subdir, const TQString& fileName);
		bool removeAppData(const TQString &file);

		/**
		 * Adds a new template. This method differs from the other add method in that it does not try to determine
		 * the type of the template from the passed source URL.
		 **/
		bool add(const KURL& templateSourceURL, KileDocument::Type type, const TQString& name, const KURL& icon);


	private:
		TemplateList m_TemplateList;
};

}

const TQString DEFAULT_EMPTY_CAPTION = i18n("Empty Document");
const TQString DEFAULT_EMPTY_LATEX_CAPTION = i18n("Empty LaTeX Document");
const TQString DEFAULT_EMPTY_BIBTEX_CAPTION = i18n("Empty BibTeX Document");

class TemplateItem : public TQIconViewItem
{
public:
	TemplateItem( TQIconView * tqparent, const KileTemplate::Info & info);
	~TemplateItem() {}

	int compare( TQIconViewItem *i ) const;
	
	TQString name() { return m_info.name; }
	TQString path() { return m_info.path; }
	TQString icon() { return m_info.icon; }
	KileDocument::Type type() { return m_info.type; }

private:
	KileTemplate::Info m_info;
};

class TemplateIconView : public KIconView {
	Q_OBJECT
  TQ_OBJECT
	
	public:
		TemplateIconView(TQWidget *tqparent=0, const char *name=0, WFlags f=0);
		virtual ~TemplateIconView();

		void setTemplateManager(KileTemplate::Manager *templateManager);

		void fillWithTemplates(KileDocument::Type type);

	signals:
		void classFileSearchFinished();

	protected:
		KileTemplate::Manager *m_templateManager;
		TQString m_output;
		TQString m_selicon;
		KProcess *m_proc;

		void addTemplateIcons(KileDocument::Type type);
		void searchLaTeXClassFiles();

	protected slots:
		void slotProcessOutput(KProcess*,char* buf,int len);
		void slotProcessExited (KProcess *proc);
};

#endif