20#include "xsltimportdia.h"
21#include "xsltimportdia.moc"
25#include <tqcombobox.h>
27#include <tqstringlist.h>
30#include <tdeapplication.h>
32#include <kstandarddirs.h>
34#include <tderecentdocument.h>
35#include <KoFilterManager.h>
36#include <tdetempfile.h>
48XSLTImportDia::XSLTImportDia(KoStore* out,
const TQCString &format, TQWidget* parent,
const char* name_,
bool modal, WFlags fl )
49 : XSLTDialog( parent, name_, modal, fl )
54 setCaption(i18n(
"Import XSLT Configuration"));
57 _config =
new TDEConfig(
"xsltdialog");
58 _config->setGroup(
"XSLT import filter" );
62 value = _config->readPathEntry( TQString(
"Recent%1").arg(i) );
63 kdDebug() <<
"recent : " << value << endl;
66 _recentList.append( value );
67 recentBox->insertItem(value);
75 TQString appName = (
const char*) TDEGlobal::instance()->instanceName();
76 kdDebug() <<
"app name = " << appName << endl;
78 TQString filenames = TQString(
"xsltfilter") + TQDir::separator() + TQString(
"import") +
79 TQDir::separator() + appName + TQDir::separator() +
"*/*.xsl";
80 TQStringList commonFilesList = TDEGlobal::dirs()->findAllResources(
"data", filenames,
true);
81 kdDebug() <<
"There are " << commonFilesList.size() <<
" entries like " << filenames << endl;
83 TQStringList tempList;
87 for(TQStringList::Iterator it = commonFilesList.begin(); it != commonFilesList.end(); ++it)
89 tempList = TQStringList::split(
"/", (*it));
90 file = tempList.last();
92 name = tempList.last();
94 kdDebug() << name <<
" " << file << endl;
95 if(!_namesList.contains(name) && file ==
"main.xsl")
97 _filesList.append(file);
98 _namesList.append(name);
99 _dirsList.append(tempList.join(
"/"));
100 kdDebug() << file <<
" get" << endl;
104 xsltList->insertStringList(_namesList);
105 kapp->restoreOverrideCursor();
111XSLTImportDia::~XSLTImportDia()
121void XSLTImportDia::cancelSlot()
123 kdDebug() <<
"import cancelled" << endl;
132void XSLTImportDia::chooseSlot()
136 TQString dir = TQString();
137 if ( _currentFile.isLocalFile() && TQFile::exists( _currentFile.path() ) )
138 dir = TQFileInfo( _currentFile.path() ).absFilePath();
140 KFileDialog *dialog =
new KFileDialog(dir, TQString(), 0L,
"file dialog",
true);
141 dialog->setCaption( i18n(
"Open Document") );
142 dialog->setMimeFilter( KoFilterManager::mimeFilter( _format, KoFilterManager::Import ) );
145 if(dialog->exec() == TQDialog::Accepted)
147 u = dialog->selectedURL();
148 TDERecentDocument::add(dialog->selectedURL().url(), !dialog->selectedURL().isLocalFile());
157 TQString filename = u.path();
158 TQString url = u.url();
159 bool local = u.isLocalFile();
161 bool ok = !url.isEmpty();
163 ok = ok && (TQFileInfo( filename ).isFile() ||
164 (TQFileInfo( filename ).isSymLink() &&
165 !TQFileInfo( filename ).readLink().isEmpty() &&
166 TQFileInfo( TQFileInfo( filename ).readLink() ).isFile() ) );
179void XSLTImportDia::chooseRecentSlot()
181 kdDebug() <<
"recent slot : " << recentBox->currentText() << endl;
182 _currentFile = recentBox->currentText();
189void XSLTImportDia::chooseCommonSlot()
191 int num = xsltList->currentItem();
192 _currentFile = TQDir::separator() + _dirsList[num] + TQDir::separator() +
193 xsltList->currentText() + TQDir::separator() + _filesList[num];
194 kdDebug() <<
"common slot : " << _currentFile.url() << endl;
201void XSLTImportDia::okSlot()
203 kapp->setOverrideCursor(TQCursor(TQt::WaitCursor));
205 if(_currentFile.url().isEmpty())
207 kdDebug() <<
"XSLT FILTER --> BEGIN" << endl;
209 TQString stylesheet = _currentFile.directory() +
"/" + _currentFile.fileName();
212 if(_recentList.contains(stylesheet) == 0)
214 kdDebug() <<
"Style sheet add to recent list" << endl;
216 if(_recentList.size() >= 10)
217 _recentList.pop_back();
220 _recentList.prepend(stylesheet);
223 kdDebug() <<
"Recent list save " << _recentList.size() <<
" entrie(s)" << endl;
225 while(_recentList.size() > 0)
227 kdDebug() <<
"save : " << _recentList.first() << endl;
228 _config->writePathEntry( TQString(
"Recent%1").arg(i), _recentList.first());
229 _recentList.pop_front();
237 KTempFile temp(
"xsltimport-",
"kwd");
238 temp.setAutoDelete(
true);
240 TQFile* tempFile = temp.file();
241 tempFile->open(IO_WriteOnly);
244 XSLTProc* xsltproc =
new XSLTProc(_fileIn, temp.name(), stylesheet);
248 tempFile->open(IO_ReadOnly);
249 _out->write(tempFile->readAll());
257 kdDebug() <<
"XSLT FILTER --> END" << endl;