summaryrefslogtreecommitdiffstats
path: root/filters/generic_wrapper
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-01-20 01:29:50 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-01-20 01:29:50 +0000
commit8362bf63dea22bbf6736609b0f49c152f975eb63 (patch)
tree0eea3928e39e50fae91d4e68b21b1e6cbae25604 /filters/generic_wrapper
downloadkoffice-8362bf63dea22bbf6736609b0f49c152f975eb63.tar.gz
koffice-8362bf63dea22bbf6736609b0f49c152f975eb63.zip
Added old abandoned KDE3 version of koffice
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/koffice@1077364 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'filters/generic_wrapper')
-rw-r--r--filters/generic_wrapper/Makefile.am18
-rw-r--r--filters/generic_wrapper/README40
-rw-r--r--filters/generic_wrapper/generic_filter.cc127
-rw-r--r--filters/generic_wrapper/generic_filter.desktop58
-rw-r--r--filters/generic_wrapper/generic_filter.h47
5 files changed, 290 insertions, 0 deletions
diff --git a/filters/generic_wrapper/Makefile.am b/filters/generic_wrapper/Makefile.am
new file mode 100644
index 00000000..ecb0bf0c
--- /dev/null
+++ b/filters/generic_wrapper/Makefile.am
@@ -0,0 +1,18 @@
+####### General stuff
+
+INCLUDES= -I$(srcdir) $(KOFFICE_INCLUDES) $(all_includes)
+
+####### Files
+kde_module_LTLIBRARIES = libgenerickofilter.la
+
+
+libgenerickofilter_la_SOURCES = generic_filter.cc
+libgenerickofilter_la_LDFLAGS = $(all_libraries) -module -avoid-version -no-undefined
+libgenerickofilter_la_LIBADD = $(KOFFICE_LIBS) $(LIB_KIO)
+
+METASOURCES = AUTO
+
+noinst_HEADERS = generic_filter.h
+
+service_DATA = generic_filter.desktop
+servicedir = $(kde_servicesdir)
diff --git a/filters/generic_wrapper/README b/filters/generic_wrapper/README
new file mode 100644
index 00000000..102f7a30
--- /dev/null
+++ b/filters/generic_wrapper/README
@@ -0,0 +1,40 @@
+KOffice Filter Wrapper
+======================
+
+This is a generic framework for developing KOffice import and export
+filters in a scripting language of your choice (Python, Perl, etc).
+
+Requirements for your filter:
+-----------------------------
+- do whatever you want with your script, it just has to take two
+ parameters, the input file and the output file
+- provide a .desktop files, containing these mandatory fields:
+
+Name=My cool filter in Perl
+Type=Service
+ServiceTypes=KOfficeGenericFilter
+Exec=my_filter.pl
+X-KDE-Wrapper-Export=<MIME type of the exported file>
+X-KDE-Wrapper-Import=<MIME type of the imported file>
+
+- write a suitable Makefile.am
+
+bin_SCRIPTS = my_filter.pl
+service_DATA = my_filter.desktop
+servicedir = $(kde_servicesdir)
+
+- if not already present, write a .desktop file for the external MIME
+ type
+
+In doubt, have a look at an example filter in
+filters/kpresenter/magicpoint.
+
+The only shortcoming at the moment is that you have to add these MIME
+types to filters/generic_wrapper/generic_filter.desktop file (in the
+fields X-KDE-Export resp. X-KDE-Import).
+
+---
+That's it, have fun :-)
+
+Lukas Tinkl <lukas@kde.org>
+SuSE Labs, Czech Republic
diff --git a/filters/generic_wrapper/generic_filter.cc b/filters/generic_wrapper/generic_filter.cc
new file mode 100644
index 00000000..14830762
--- /dev/null
+++ b/filters/generic_wrapper/generic_filter.cc
@@ -0,0 +1,127 @@
+/* This file is part of the KDE project
+ Copyright (C) 2002, 2003 Lukas Tinkl <lukas@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+*/
+
+#include <stdlib.h>
+
+#include <qtextcodec.h>
+#include <qfile.h>
+
+#include <kdebug.h>
+#include <KoFilterChain.h>
+#include <kgenericfactory.h>
+#include <kglobal.h>
+#include <klocale.h>
+#include <ktrader.h>
+#include <kservice.h>
+#include <ktempfile.h>
+
+#include "generic_filter.h"
+
+typedef KGenericFactory<GenericFilter, KoFilter> GenericFilterFactory;
+K_EXPORT_COMPONENT_FACTORY( libgenerickofilter, GenericFilterFactory )
+
+
+GenericFilter::GenericFilter(KoFilter *, const char *, const QStringList&) :
+ KoFilter() {
+}
+
+KoFilter::ConversionStatus GenericFilter::convert( const QCString &from, const QCString &to )
+{
+
+ //find the right script to use
+ KTrader::OfferList offers = KTrader::self()->query("KOfficeGenericFilter",
+ "(Type == 'Service') and ('KOfficeGenericFilter' in ServiceTypes) and (exist Exec)");
+
+ if (offers.isEmpty())
+ return KoFilter::NotImplemented;
+
+ KTrader::OfferList::ConstIterator it;
+ for (it=offers.begin(); it!=offers.end(); ++it)
+ {
+ kdDebug() << "Got a filter script, exec: " << (*it)->exec() <<
+ ", imports: " << (*it)->property("X-KDE-Wrapper-Import").toString() <<
+ ", exports: " << (*it)->property("X-KDE-Wrapper-Export").toString() << endl;
+ if ((*it)->property("X-KDE-Wrapper-Import").toCString()==from
+ && (*it)->property("X-KDE-Wrapper-Export").toCString()==to)
+ {
+ m_exec=(*it)->exec();
+ m_from=from;
+ m_to=to;
+ break;
+ }
+ }
+
+ //decide between import/export
+ if( m_to == "application/x-kword" || m_to == "application/x-karbon" ||
+ m_to == "application/x-kspread" || m_to == "application/x-kivio" ||
+ m_to == "application/x-kchart" || m_to == "application/x-kpresenter" )
+ return doImport();
+ else if ( m_from == "application/x-kword" || m_from == "application/x-karbon" ||
+ m_from == "application/x-kspread" || m_from == "application/x-kivio" ||
+ m_from == "application/x-kchart" || m_from == "application/x-kpresenter" )
+ return doExport();
+ else
+ return KoFilter::NotImplemented;
+}
+
+KoFilter::ConversionStatus GenericFilter::doImport()
+{
+ KTempFile temp(QString("genericfilter-"));
+ temp.setAutoDelete(true);
+
+ QFile tempFile(temp.name());
+
+ m_out = KoStore::createStore(&tempFile, KoStore::Write);
+
+ if (!m_out || !m_out->open("root"))
+ {
+ kdError() << "Unable to create output store!" << endl;
+ m_out->close();
+ return KoFilter::StorageCreationError;
+ }
+ else
+ {
+ QString exec = m_exec + " " + KProcess::quote(m_chain->inputFile()) + " "
+ + KProcess::quote(m_chain->outputFile());
+ system(QFile::encodeName(exec));
+
+ kdDebug() << "Executing: " << exec << endl;
+
+ QFile outFile(m_chain->outputFile());
+ outFile.open(IO_ReadOnly);
+ QByteArray outData = outFile.readAll();
+ if (outData.size()==0) {
+ m_out->close();
+ return KoFilter::UnexpectedEOF;
+ }
+ else {
+ m_out->write(outData);
+ m_out->close();
+ }
+ }
+
+ return KoFilter::OK;
+}
+
+KoFilter::ConversionStatus GenericFilter::doExport()
+{
+ return KoFilter::NotImplemented;
+}
+
+#include "generic_filter.moc"
diff --git a/filters/generic_wrapper/generic_filter.desktop b/filters/generic_wrapper/generic_filter.desktop
new file mode 100644
index 00000000..1a7c6961
--- /dev/null
+++ b/filters/generic_wrapper/generic_filter.desktop
@@ -0,0 +1,58 @@
+[Desktop Entry]
+Name=Generic KOffice Filter
+Name[ar]=مِرْشَح نوعيّ لـ KOffice
+Name[bg]=Общ филтър за KOffice
+Name[br]=Sil KOffice rummel
+Name[ca]=Filtre genèric de KOffice
+Name[cs]=Obecný filtr KOffice
+Name[cy]=Hidlen generig KOffice
+Name[da]=Generisk KOffice-filter
+Name[de]=Generischer KOffice-Filter
+Name[el]=Γενικευμένο φίλτρο του KOffice
+Name[eo]=Komuna KOffice-Filtrilo
+Name[es]=Filtro genérico de KOffice
+Name[et]=KOffice'i üldine filter
+Name[eu]=KOffice-en iragazki generikoa
+Name[fa]=پالایۀ عمومی KOffice
+Name[fi]=Yleinen KOffice-suodin
+Name[fr]=Filtre générique de KOffice
+Name[fy]=Algemiene KOffice filter
+Name[ga]=Scagaire Ginearálta KOffice
+Name[gl]=Filtro xenérico de KOffice
+Name[he]=מסנן גנרי של KOffice
+Name[hr]=Generički KOffice filtar
+Name[hu]=Általános KOffice-szűrő
+Name[is]=Almenn KOffice sía
+Name[it]=Filtro generico di KOffice
+Name[ja]=KOffice ジェネリックフィルタ
+Name[km]=តម្រង KOffice ទូទៅ
+Name[lt]=Bendras KOffice filtras
+Name[lv]=Vispārējs KOffice filtrs
+Name[ms]=Penapis KOffice Biasa
+Name[nb]=Alment KOffice-filter
+Name[nds]=Allgemeen KOffice-Filter
+Name[ne]=जेनेरिक केडीई कार्यालय फिल्टर
+Name[nl]=Generiek KOffice-filter
+Name[nn]=Generelt KOffice-filter
+Name[pl]=Ogólny filtr KOffice
+Name[pt]=Filtro Genérico do KOffice
+Name[pt_BR]=Filtro genérico do KOffice
+Name[ro]=Filtru generic KOffice
+Name[ru]=Фильтр KOffice
+Name[se]=Oppalaš KOffice-silli
+Name[sk]=Všeobecný filter KOffice
+Name[sl]=Generični filter za KOffice
+Name[sr]=KOffice-ов генерички филтер
+Name[sr@Latn]=KOffice-ov generički filter
+Name[sv]=Generellt Koffice-filter
+Name[uk]=Загальний фільтр KOffice
+Name[uz]=KOffice umumiy filteri
+Name[uz@cyrillic]=KOffice умумий филтери
+Name[zh_CN]=KOffice 通用过滤器
+Name[zh_TW]=通用 KOffice 過濾器
+X-KDE-Export=application/x-kpresenter
+X-KDE-Import=application/x-magicpoint
+X-KDE-Weight=1
+Type=Service
+ServiceTypes=KOfficeFilter
+X-KDE-Library=libgenerickofilter
diff --git a/filters/generic_wrapper/generic_filter.h b/filters/generic_wrapper/generic_filter.h
new file mode 100644
index 00000000..21cc7311
--- /dev/null
+++ b/filters/generic_wrapper/generic_filter.h
@@ -0,0 +1,47 @@
+/* This file is part of the KDE project
+ Copyright (C) 2002 Lukas Tinkl <lukas@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+*/
+
+#ifndef __GENERICFILTER_H__
+#define __GENERICFILTER_H__
+
+#include <qcstring.h>
+#include <qstringlist.h>
+
+#include <kprocess.h>
+#include <KoFilter.h>
+#include <KoStore.h>
+
+class GenericFilter : public KoFilter
+{
+ Q_OBJECT
+
+public:
+ GenericFilter(KoFilter *parent, const char *name, const QStringList&);
+ virtual ~GenericFilter() {}
+
+ virtual KoFilter::ConversionStatus convert( const QCString& from,
+ const QCString& to );
+private:
+ KoFilter::ConversionStatus doImport();
+ KoFilter::ConversionStatus doExport();
+ QString m_to, m_from, m_exec;
+ KoStore* m_out;
+};
+
+#endif /* __GENERICFILTER_H__ */