21#include <xsltexportdia.h>
25#include <tqcombobox.h>
27#include <tdeapplication.h>
31#include <tdeversion.h>
32#include <kstandarddirs.h>
33#include <tderecentdocument.h>
34#include <tdetempfile.h>
35#include <tdefiledialog.h>
37#include <KoFilterManager.h>
38#include <KoStoreDevice.h>
51XSLTExportDia::XSLTExportDia(KoStoreDevice* in,
const TQCString &format, TQWidget* parent,
const char* name_,
bool modal, WFlags fl )
52 : XSLTDialog( parent, name_, modal, fl )
57 setCaption(i18n(
"Export XSLT Configuration"));
59 kapp->restoreOverrideCursor();
62 _config =
new TDEConfig(
"xsltdialog");
63 _config->setGroup(
"XSLT export filter" );
67 value = _config->readPathEntry( TQString(
"Recent%1").arg(i) );
68 kdDebug() <<
"recent : " << value << endl;
71 _recentList.append( value );
72 recentBox->insertItem(value);
80 TQString appName = (
const char*) TDEGlobal::instance()->instanceName();
81 kdDebug() <<
"app name = " << appName << endl;
83 TQString filenames = TQString(
"xsltfilter") + TQDir::separator() + TQString(
"export") +
84 TQDir::separator() + appName + TQDir::separator() +
"*/*.xsl";
85 TQStringList commonFilesList = TDEGlobal::dirs()->findAllResources(
"data", filenames,
true);
86 kdDebug() <<
"There are " << commonFilesList.size() <<
" entries like " << filenames << endl;
88 TQStringList tempList;
92 for(TQStringList::Iterator it = commonFilesList.begin(); it != commonFilesList.end(); ++it)
94 tempList = TQStringList::split(
"/", (*it));
95 file = tempList.last();
97 name = tempList.last();
99 kdDebug() << name <<
" " << file << endl;
100 if(!_namesList.contains(name) && file ==
"main.xsl")
102 _filesList.append(file);
103 _namesList.append(name);
104 _dirsList.append(tempList.join(
"/"));
105 kdDebug() << file <<
" get" << endl;
109 xsltList->insertStringList(_namesList);
115XSLTExportDia::~XSLTExportDia()
124void XSLTExportDia::cancelSlot()
126 kdDebug() <<
"export cancelled" << endl;
135void XSLTExportDia::chooseSlot()
139 TQString dir = TQString();
140 if ( _currentFile.isLocalFile() && TQFile::exists( _currentFile.path() ) )
141 dir = TQFileInfo( _currentFile.path() ).absFilePath();
143 KFileDialog *dialog =
new KFileDialog(dir, TQString(), 0L,
"file dialog",
true);
144 dialog->setCaption( i18n(
"Open Document") );
145 dialog->setMimeFilter( KoFilterManager::mimeFilter( _format, KoFilterManager::Export ) );
148 if(dialog->exec() == TQDialog::Accepted)
150 u = dialog->selectedURL();
151 TDERecentDocument::add(dialog->selectedURL().url(), !dialog->selectedURL().isLocalFile());
160 TQString filename = u.path();
161 TQString url = u.url();
162 bool local = u.isLocalFile();
164 bool ok = !url.isEmpty();
166 ok = ok && (TQFileInfo( filename ).isFile() ||
167 (TQFileInfo( filename ).isSymLink() &&
168 !TQFileInfo( filename ).readLink().isEmpty() &&
169 TQFileInfo( TQFileInfo( filename ).readLink() ).isFile() ) );
182void XSLTExportDia::chooseRecentSlot()
184 kdDebug() <<
"recent slot : " << recentBox->currentText() << endl;
185 _currentFile = recentBox->currentText();
192void XSLTExportDia::chooseCommonSlot()
194 int num = xsltList->currentItem();
195 _currentFile = TQDir::separator() + _dirsList[num] + TQDir::separator() +
196 xsltList->currentText() + TQDir::separator() + _filesList[num];
197 kdDebug() <<
"common slot : " << _currentFile.url() << endl;
204void XSLTExportDia::okSlot()
207 if(_currentFile.url().isEmpty())
209 kdDebug() <<
"XSLT FILTER --> BEGIN" << endl;
210 TQString stylesheet = _currentFile.directory() + TQDir::separator() + _currentFile.fileName();
213 if(_recentList.contains(stylesheet) == 0)
215 kdDebug() <<
"Style sheet add to recent list" << endl;
217 if(_recentList.size() >= 10)
218 _recentList.pop_back();
221 _recentList.prepend(stylesheet);
224 kdDebug() <<
"Recent list save " << _recentList.size() <<
" entrie(s)" << endl;
226 while(_recentList.size() > 0)
228 kdDebug() <<
"save : " << _recentList.first() << endl;
229#if KDE_IS_VERSION(3,1,3)
230 _config->writePathEntry( TQString(
"Recent%1").arg(i), _recentList.first());
232 _config->writeEntry( TQString(
"Recent%1").arg(i), _recentList.first());
234 _recentList.pop_front();
242 KTempFile temp(
"xsltexport-",
"kwd");
243 temp.setAutoDelete(
true);
244 TQFile* tempFile = temp.file();
246 const TQ_LONG buflen = 4096;
247 char buffer[ buflen ];
248 TQ_LONG readBytes = _in->readBlock( buffer, buflen );
250 while ( readBytes > 0 )
252 tempFile->writeBlock( buffer, readBytes );
253 readBytes = _in->readBlock( buffer, buflen );
257 kdDebug() << stylesheet << endl;
258 XSLTProc* xsltproc =
new XSLTProc(temp.name(), _fileOut, stylesheet);
263 kdDebug() <<
"XSLT FILTER --> END" << endl;
267#include <xsltexportdia.moc>