summaryrefslogtreecommitdiffstats
path: root/src/kile/kileextensions.cpp
blob: b843900b62f000d026f75e290a7b7c8107300820 (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
/***************************************************************************
    begin                : Mar 12 2007
    copyright            : 2007 by Holger Danielsson
    email                : holger.danielsson@versanet.de
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/

#include "kileextensions.h"

#include <tqstring.h>
#include <tqstringlist.h>
#include <tqfileinfo.h>

#include <klocale.h>
#include "kiledebug.h"

namespace KileDocument 
{

//////////////////// Extensions ////////////////////

Extensions::Extensions()
{
	m_documents = ".tex .ltx .latex .dtx .ins";
	m_packages = ".cls .sty";
	m_bibtex = ".bib";
	m_metapost = ".mp";
	m_script = ".js";
	m_project = ".kilepr";
	//m_images = ".eps .pdf .dvi .ps .fig .gif .jpg .jpeg .png";
	m_images = ".eps .jpg .jpeg .png .pdf .ps .fig .gif";

	m_latexDefault = ".tex";
	m_bibtexDefault = ".bib";
	m_metapostDefault = ".mp";
	m_scriptDefault = ".js";
	m_projectDefault = ".kilepr";
}

//////////////////// file filter ////////////////////

TQString Extensions::fileFilter(uint type)
{
	TQString ext,text;
	switch ( type )
	{ 
		case LATEX_EXT_DOC:
			ext = m_documents;
			text = i18n("(La)TeX Source Files");
			break;
		case LATEX_EXT_PKG:
			ext = m_packages;
			text = i18n("(La)TeX Packages");
			break;
		case LATEX_EXT_BIB:
			ext = m_bibtex;
			text = i18n("BibTeX Files");
			break;
		case LATEX_EXT_MP:
			ext = m_metapost;
			text = i18n("Metapost Files");
			break;
		case LATEX_EXT_JS:
			ext = m_script;
			text = i18n("Kile Script Files");
			break;
		case LATEX_EXT_PROJ:
			ext = m_project;
			text = i18n("Kile Project Files");
			break;
		default:
			return TQString();
	}

	ext.replace(".","*.");
	return ext + '|' + text;
}

//////////////////// document type ////////////////////

bool Extensions::isTexFile(const TQString &fileName) const
{
	//TODO use mimetype
	TQString ext = '.' + TQFileInfo(fileName).extension(false);
	return isLatexDocument(ext) || isLatexPackage(ext);
}

bool Extensions::isBibFile(const TQString &fileName) const
{
	TQString ext = '.' + TQFileInfo(fileName).extension(false);
	return isBibtex(ext);
}

bool Extensions::isScriptFile(const TQString &fileName) const
{
	TQString ext = '.' + TQFileInfo(fileName).extension(false);
	return isScript(ext);
}

bool Extensions::isProjectFile(const TQString &fileName) const
{
	TQString ext = '.' + TQFileInfo(fileName).extension(false);
	return isProject(ext);
}

bool Extensions::validExtension(const TQString &ext, const TQString &extensions) const
{
	TQStringList extlist = TQStringList::split(" ",extensions);
	for ( TQStringList::ConstIterator it=extlist.begin(); it!=extlist.end(); ++it )
	{
		if ( (*it) == ext ) 
			return true;
	}

	return false;
}

Type Extensions::determineDocumentType(const KURL& url) const
{
	if ( isTexFile(url) )
	{
		return KileDocument::LaTeX;
	}
	else if ( isBibFile(url) )
	{
		return KileDocument::BibTeX;
	}
	else if ( isScriptFile(url) )
	{
		return KileDocument::Script;
	}
	else
	{
		return KileDocument::Text;
	}
}

TQString Extensions::defaultExtensionForDocumentType(KileDocument::Type type) const
{
	switch(type) {
		case KileDocument::LaTeX:
			return m_latexDefault;

		case KileDocument::BibTeX:
			return m_bibtexDefault;

		case KileDocument::Script:
			return m_scriptDefault;

		case KileDocument::Text:
			/* fall through */
		case KileDocument::Undefined:
			/* do nothing */
		break;
	}
	return TQString();
}

}