filters
xsltexportdia.cc00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <xsltexportdia.h>
00022 #include <xsltproc.h>
00023
00024 #include <qdir.h>
00025 #include <qcombobox.h>
00026
00027 #include <kapplication.h>
00028 #include <kglobal.h>
00029 #include <klocale.h>
00030 #include <kconfig.h>
00031 #include <kdeversion.h>
00032 #include <kstandarddirs.h>
00033 #include <krecentdocument.h>
00034 #include <ktempfile.h>
00035 #include <kfiledialog.h>
00036 #include <kdebug.h>
00037 #include <KoFilterManager.h>
00038 #include <KoStoreDevice.h>
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051 XSLTExportDia::XSLTExportDia(KoStoreDevice* in, const QCString &format, QWidget* parent, const char* name_, bool modal, WFlags fl )
00052 : XSLTDialog( parent, name_, modal, fl )
00053 {
00054 int i = 0;
00055 _in = in;
00056 _format = format;
00057 setCaption(i18n("Export XSLT Configuration"));
00058
00059 kapp->restoreOverrideCursor();
00060
00061
00062 _config = new KConfig("xsltdialog");
00063 _config->setGroup( "XSLT export filter" );
00064 QString value;
00065 while(i < 10)
00066 {
00067 value = _config->readPathEntry( QString("Recent%1").arg(i) );
00068 kdDebug() << "recent : " << value << endl;
00069 if(!value.isEmpty())
00070 {
00071 _recentList.append( value );
00072 recentBox->insertItem(value);
00073 }
00074 else
00075 i = 10;
00076 i = i + 1;
00077 }
00078
00079
00080 QString appName = (const char*) KGlobal::instance()->instanceName();
00081 kdDebug() << "app name = " << appName << endl;
00082
00083 QString filenames = QString("xsltfilter") + QDir::separator() + QString("export") +
00084 QDir::separator() + appName + QDir::separator() + "*/*.xsl";
00085 QStringList commonFilesList = KGlobal::dirs()->findAllResources("data", filenames, true);
00086 kdDebug() << "There are " << commonFilesList.size() << " entries like " << filenames << endl;
00087
00088 QStringList tempList;
00089 QString name;
00090 QString file;
00091
00092 for(QStringList::Iterator it = commonFilesList.begin(); it != commonFilesList.end(); ++it)
00093 {
00094 tempList = QStringList::split("/", (*it));
00095 file = tempList.last();
00096 tempList.pop_back();
00097 name = tempList.last();
00098 tempList.pop_back();
00099 kdDebug() << name << " " << file << endl;
00100 if(!_namesList.contains(name) && file == "main.xsl")
00101 {
00102 _filesList.append(file);
00103 _namesList.append(name);
00104 _dirsList.append(tempList.join("/"));
00105 kdDebug() << file << " get" << endl;
00106 }
00107 }
00108
00109 xsltList->insertStringList(_namesList);
00110 }
00111
00112
00113
00114
00115 XSLTExportDia::~XSLTExportDia()
00116 {
00117 delete _config;
00118 }
00119
00124 void XSLTExportDia::cancelSlot()
00125 {
00126 kdDebug() << "export cancelled" << endl;
00127 reject();
00128 }
00129
00135 void XSLTExportDia::chooseSlot()
00136 {
00137
00138
00139 QString dir = QString::null;
00140 if ( _currentFile.isLocalFile() && QFile::exists( _currentFile.path() ) )
00141 dir = QFileInfo( _currentFile.path() ).absFilePath();
00142
00143 KFileDialog *dialog = new KFileDialog(dir, QString::null, 0L, "file dialog", true);
00144 dialog->setCaption( i18n("Open Document") );
00145 dialog->setMimeFilter( KoFilterManager::mimeFilter( _format, KoFilterManager::Export ) );
00146 KURL u;
00147
00148 if(dialog->exec() == QDialog::Accepted)
00149 {
00150 u = dialog->selectedURL();
00151 KRecentDocument::add(dialog->selectedURL().url(), !dialog->selectedURL().isLocalFile());
00152 } else
00153 {
00154
00155
00156 }
00157
00158 delete dialog;
00159
00160 QString filename = u.path();
00161 QString url = u.url();
00162 bool local = u.isLocalFile();
00163
00164 bool ok = !url.isEmpty();
00165 if (local)
00166 ok = ok && (QFileInfo( filename ).isFile() ||
00167 (QFileInfo( filename ).isSymLink() &&
00168 !QFileInfo( filename ).readLink().isEmpty() &&
00169 QFileInfo( QFileInfo( filename ).readLink() ).isFile() ) );
00170
00171 if ( ok )
00172 {
00173 _currentFile = u;
00174 okSlot();
00175 }
00176 }
00177
00182 void XSLTExportDia::chooseRecentSlot()
00183 {
00184 kdDebug() << "recent slot : " << recentBox->currentText() << endl;
00185 _currentFile = recentBox->currentText();
00186 }
00187
00192 void XSLTExportDia::chooseCommonSlot()
00193 {
00194 int num = xsltList->currentItem();
00195 _currentFile = QDir::separator() + _dirsList[num] + QDir::separator() +
00196 xsltList->currentText() + QDir::separator() + _filesList[num];
00197 kdDebug() << "common slot : " << _currentFile.url() << endl;
00198 }
00199
00204 void XSLTExportDia::okSlot()
00205 {
00206 hide();
00207 if(_currentFile.url().isEmpty())
00208 return;
00209 kdDebug() << "XSLT FILTER --> BEGIN" << endl;
00210 QString stylesheet = _currentFile.directory() + QDir::separator() + _currentFile.fileName();
00211
00212
00213 if(_recentList.contains(stylesheet) == 0)
00214 {
00215 kdDebug() << "Style sheet add to recent list" << endl;
00216
00217 if(_recentList.size() >= 10)
00218 _recentList.pop_back();
00219
00220
00221 _recentList.prepend(stylesheet);
00222
00223
00224 kdDebug() << "Recent list save " << _recentList.size() << " entrie(s)" << endl;
00225 int i = 0;
00226 while(_recentList.size() > 0)
00227 {
00228 kdDebug() << "save : " << _recentList.first() << endl;
00229 #if KDE_IS_VERSION(3,1,3)
00230 _config->writePathEntry( QString("Recent%1").arg(i), _recentList.first());
00231 #else
00232 _config->writeEntry( QString("Recent%1").arg(i), _recentList.first());
00233 #endif
00234 _recentList.pop_front();
00235 i = i + 1;
00236 }
00237
00238 _config->sync();
00239 }
00240
00241
00242 KTempFile temp("xsltexport-", "kwd");
00243 temp.setAutoDelete(true);
00244 QFile* tempFile = temp.file();
00245
00246 const Q_LONG buflen = 4096;
00247 char buffer[ buflen ];
00248 Q_LONG readBytes = _in->readBlock( buffer, buflen );
00249
00250 while ( readBytes > 0 )
00251 {
00252 tempFile->writeBlock( buffer, readBytes );
00253 readBytes = _in->readBlock( buffer, buflen );
00254 }
00255 temp.close();
00256
00257 kdDebug() << stylesheet << endl;
00258 XSLTProc* xsltproc = new XSLTProc(temp.name(), _fileOut, stylesheet);
00259 xsltproc->parse();
00260
00261 delete xsltproc;
00262
00263 kdDebug() << "XSLT FILTER --> END" << endl;
00264 reject();
00265 }
00266
00267 #include <xsltexportdia.moc>
|