21#include <xsltexportdia.h>
25#include <tqcombobox.h>
27#include <tdeapplication.h>
31#include <kstandarddirs.h>
32#include <tderecentdocument.h>
33#include <tdetempfile.h>
34#include <tdefiledialog.h>
36#include <KoFilterManager.h>
37#include <KoStoreDevice.h>
50XSLTExportDia::XSLTExportDia(KoStoreDevice* in,
const TQCString &format, TQWidget* parent,
const char* name_,
bool modal, WFlags fl )
51 : XSLTDialog( parent, name_, modal, fl )
56 setCaption(i18n(
"Export XSLT Configuration"));
58 kapp->restoreOverrideCursor();
61 _config =
new TDEConfig(
"xsltdialog");
62 _config->setGroup(
"XSLT export filter" );
66 value = _config->readPathEntry( TQString(
"Recent%1").arg(i) );
67 kdDebug() <<
"recent : " << value << endl;
70 _recentList.append( value );
71 recentBox->insertItem(value);
79 TQString appName = (
const char*) TDEGlobal::instance()->instanceName();
80 kdDebug() <<
"app name = " << appName << endl;
82 TQString filenames = TQString(
"xsltfilter") + TQDir::separator() + TQString(
"export") +
83 TQDir::separator() + appName + TQDir::separator() +
"*/*.xsl";
84 TQStringList commonFilesList = TDEGlobal::dirs()->findAllResources(
"data", filenames,
true);
85 kdDebug() <<
"There are " << commonFilesList.size() <<
" entries like " << filenames << endl;
87 TQStringList tempList;
91 for(TQStringList::Iterator it = commonFilesList.begin(); it != commonFilesList.end(); ++it)
93 tempList = TQStringList::split(
"/", (*it));
94 file = tempList.last();
96 name = tempList.last();
98 kdDebug() << name <<
" " << file << endl;
99 if(!_namesList.contains(name) && file ==
"main.xsl")
101 _filesList.append(file);
102 _namesList.append(name);
103 _dirsList.append(tempList.join(
"/"));
104 kdDebug() << file <<
" get" << endl;
108 xsltList->insertStringList(_namesList);
114XSLTExportDia::~XSLTExportDia()
123void XSLTExportDia::cancelSlot()
125 kdDebug() <<
"export cancelled" << endl;
134void XSLTExportDia::chooseSlot()
138 TQString dir = TQString();
139 if ( _currentFile.isLocalFile() && TQFile::exists( _currentFile.path() ) )
140 dir = TQFileInfo( _currentFile.path() ).absFilePath();
142 KFileDialog *dialog =
new KFileDialog(dir, TQString(), 0L,
"file dialog",
true);
143 dialog->setCaption( i18n(
"Open Document") );
144 dialog->setMimeFilter( KoFilterManager::mimeFilter( _format, KoFilterManager::Export ) );
147 if(dialog->exec() == TQDialog::Accepted)
149 u = dialog->selectedURL();
150 TDERecentDocument::add(dialog->selectedURL().url(), !dialog->selectedURL().isLocalFile());
159 TQString filename = u.path();
160 TQString url = u.url();
161 bool local = u.isLocalFile();
163 bool ok = !url.isEmpty();
165 ok = ok && (TQFileInfo( filename ).isFile() ||
166 (TQFileInfo( filename ).isSymLink() &&
167 !TQFileInfo( filename ).readLink().isEmpty() &&
168 TQFileInfo( TQFileInfo( filename ).readLink() ).isFile() ) );
181void XSLTExportDia::chooseRecentSlot()
183 kdDebug() <<
"recent slot : " << recentBox->currentText() << endl;
184 _currentFile = recentBox->currentText();
191void XSLTExportDia::chooseCommonSlot()
193 int num = xsltList->currentItem();
194 _currentFile = TQDir::separator() + _dirsList[num] + TQDir::separator() +
195 xsltList->currentText() + TQDir::separator() + _filesList[num];
196 kdDebug() <<
"common slot : " << _currentFile.url() << endl;
203void XSLTExportDia::okSlot()
206 if(_currentFile.url().isEmpty())
208 kdDebug() <<
"XSLT FILTER --> BEGIN" << endl;
209 TQString stylesheet = _currentFile.directory() + TQDir::separator() + _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(
"xsltexport-",
"kwd");
238 temp.setAutoDelete(
true);
239 TQFile* tempFile = temp.file();
241 const TQ_LONG buflen = 4096;
242 char buffer[ buflen ];
243 TQ_LONG readBytes = _in->readBlock( buffer, buflen );
245 while ( readBytes > 0 )
247 tempFile->writeBlock( buffer, readBytes );
248 readBytes = _in->readBlock( buffer, buflen );
252 kdDebug() << stylesheet << endl;
253 XSLTProc* xsltproc =
new XSLTProc(temp.name(), _fileOut, stylesheet);
258 kdDebug() <<
"XSLT FILTER --> END" << endl;
262#include <xsltexportdia.moc>