![]() |
|
Filters for KOffice |
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
1. Do we really need filters? 2. Which filters are there? 3. Which filters are most wanted? 4. How to use a filter? 5. Developing Filters for KOffice 5.1. Prepare the Environment 5.2. Behind the Scenes 5.3. How to Develop a Filter? 5.4. Remaining Questions? 5.5. File Formats - Doctype Definitions 5.6. Special Filters 5.7. Add Documentation 5.8. Links for Developers
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3. Which filters are most wanted?
At the moment I think the "most wanted" filter would be a RTF import and export filter for KWord as you can exchange RTF documents with nearly all office suites. Obviously there is more need for KWord and KSpread filters than for KPresenter filters.
Here is a first list:MIF Info:
MIF files are an predecesser to XML, used only by Adobe Framemaker.
It is a tag based, ascii only file. Since framemaker can use pictures it can
also embed pictures
into the file. Still in use and it has a new file-format in the new
Framemaker 6 that is (according to Adobe) not downwards compatible
(Frame 5.5 can not load Frame 6.0 mifs)
4. How to use a filter?
The Koffice Library Developers have done a magnificent job and you
will not even notice when you use a filter to convert a file to the
part's native format. Ok, you can see it (debug output), but there is no
difference for you at all. Just select
File -> Open... for import or
File -> Save or
File -> Save As...
for export
and choose
the extension which should be used.
Select (or name) the file and off you go :)
5. Developing Filters for KOffice
5.1. Prepare the Environment
As KOffice needs KDE 2 it's necessary to install at least parts of
KDE 2 (Qt, kdesupport, kdelibs, kdebase - exactly in this
order) and - of course - KOffice. I recommend
looking for
further information on
how to install it. To get some help from real KOffice experts please
join the KOffice mailing list
(koffice@kde.org or koffice-devel@kde.org). There is an archive of
those lists and you can find them all at
http://lists.kde.org.
One final hint: Add -debug to your
./configure options for Qt and
--enable-debug to your
./configure options for all KDE packages.
The resulting
binaries are quite large and a little bit slower, but nonetheless this
is an enormous help if you are developing (=debugging :) something.
Oh, and use gdb-5.0
or later, because gdb-4.x always crashed on KOffice stuff (at least for
me).
5.2. Behind the Scenes
There are several ways for programming a filter depending on your needs. However, unless you really need a non-standard filtering method (e.g. because you'd like to import huge amounts of data and the performance is bad) we recommend using the plain and easy standard method. All the following descriptions are based on the assumption that you use the standard filtering method. The gory details about the optimized (read: hacky) methods of filtering are provided at the bottom of this page (Note: I didn't add a link, because you have to scroll the standard description, at least :).
KOffice uses a quite straightforward approach to convert files to the native format of the matching KOffice part. I'll try to explain this via a simple example (from the user's point of view) before providing further (more detailed) information:
File -> Open...
Ok
When saving documents the filtering works nearly identical. The whole process of looking for available filters,... is done by the KOffice Libraries so you don't have to care about that. As you can see there is no magic involved and as we now know the basics let's have a look how this really works!
After the user clicked File -> Open... the
part queries the KoFilterManager
(koffice/lib/kofficecore/koFilterManager.cc) to prepare the file dialog.
The filter manager (=KoFilterManager) queries
the trader for information on the supported filter types (e.g. HTML,
TXT,...) and configuration dialogs. Then it prepares the KFD (K File
Dialog) to show all this stuff. The file dialog pops up and now the user
can select a specific filter (e.g. '*.csv'). After selecting a file (with
the correct extension - the file dialog ensures that) the user might have
to set some configuration options (Note: You don't have to
provide such a dialog, it's just a nifty feature for some obscure
filters which need passwords and so on (i.e. some kind of user input)!),
clicks Ok and the filename is returned to the
part. The part
passes the filename to the filter manager. The filter manager checks
whether the file is native or not. If if is native, the filter manager
returns the name and the part opens it. If it is not, the filter manager
returns another filename - this is the name of the converted file (a
temporary file somewhere in /tmp). Finally the part opens the converted
(=native) file.
But when does the real converting occur? Let's see... the filter manager gets the filename (and the mimetype of the calling part). It tries to find out the mimetype of the file which should be opened. Then the trader is queried if there is a filter which is able to handle those two mimetypes (the one of the file to convert and the native format of the application, e.g. HTML -> KWord). If such a filter is found the filter manager loads it and passes the information of the optional configuration dialog.
Filters are shared libs which are opened on demand (via
KLibLoader, which is a wrapper for dlopen) and closed after a few
minutes of inactivity
(so that we don't waste too much memory). All the filters have to inherit
KoFilter (koffice/lib/kofficecore/koFilter.h)
and they have to override the pure virtual method filter(...)
. This
method is called by the filter manager (for details see below) and the
filter starts to convert the file (i.e. opens the file, reads it,
converts the contents, writes it).
5.3. How to Develop a Filter?
Please have a look at koffice/filters/kword/ascii/asciiimport* if you want to write an import filter, at koffice/filters/kword/ascii/asciiexport* if you want to write an export filter. (and exchange "import" by "export" below).
To create a filter you have to:ASCII,
Ascii, and ascii stuff has to be
replaced by YOURFILTER
, YourFilter, and yourfilter).
KoFilter. Look
at 'asciiimport.cc' and 'asciiimport.h' how this is done. Don't
forget that you have to include or link the moc file - otherwise
the filter won't work! (the classname is needed during
"incarnation," and all this information is stored in those nifty
little moc files).
make -f Makefile.cvs in the
top directory (koffice/) (or use create_makefile(s) from
kdesdk/scripts) ./configure the whole stuff again.
If it compiles you've won :) . make install) To create an optional configuration dialog you have to:
KoFilterDialog.
Of course you have to override the pure virtual method
state(). This method returns a
QString
which contains the configuration information.
You might want to use some Qt geometry management magic to make
the dialog look nice.
make -f Makefile.cvs ./configure.
Ok and/or
Cancel buttons, nor menubars/toolbars.
Shortly put:
Make it really simple.
Ok
button, at least) and embed your configuration dialog (i.e. the
real dialog is the parent of your dialog widget). Then wait for
the user to click Ok and use the
dialog's status() method to read the information.
Wow - you wrote a filter! But what now? You don't have a CVS account and you want to check it in? No problem. Please send all the files to me, Werner Trobin, <trobin@kde.org>. Note: It's no problem whatsoever if you send your "drafts" - that's what CVS is good for!
5.4. Remaining Questions?
Feel free to ask me if there are any remaining questions. BTW: It's generally a good idea to ask on koffice@kde.org whether anyone works on a filter before starting to implement it :)
5.5. File Formats - Doctype Definitions
This section contains some useful documentation (I'll add more stuff here, soon):
5.6. Special Filters
As I already said above sometimes the standard filter interface is just a little bit to slow, complicated(?!?), annoying,... To prevent you from trying to circumvent our interface we've done it for you, already. It's not clean, it's not save, but it should at least be fast. Once again I'd like to warn you, but I'm sure you won't listen to me, anyways.
If you read the definiton of the KoFilter
class, you can see that there are more pure virtual methods, than just
filter(...):
virtual const bool I_filter(const QCString &file,
const QCString &from,
QDomDocument &doc, const QCString &to, const QString
&config=QString::null);virtual const bool I_filter(const QCString &file,
KoDocument *document, const QCString &from, const QCString &to,
const QString &config=QString::null);virtual const bool E_filter(const QCString &file,
const KoDocument * const document, const QCString &from, const
QCString &to, const QString &config=QString::null);
If you need some inspiration how to implement these kinds of methods, just have a look at koffice/filters/kspread/csv. You surely already know, that you can even use a configuration dialog with these filtering methods, too.
5.7. Add Documentation
So if you have done your filter please add some information.
At least add a statusfile status.html. Inside
of that file you should insert
Whenever you obtain any information about the filter
update the status.html file.
The status file may contain the result of a
finished investigation (e.g. can code be reused from another open source
project if yes how, if no why not) or even the experience of a not
finished investigation, and of course the possibilities the filter
currently provides.
If you have done your documentation and the tables are looking right mail it.
If you are doing some update don't forget to update your documentation too!
5.8. Links for Developers
During all the hours on the net searching for information on file formats and stuff like that, I came across some very interesting homepages:
| http://www.wotsit.org | Information on various file formats |
| http://msdn.microsoft.com | The MS Developer's Network Library |
| http://arturo.directmail.org/filtersweb/ | - |
| http://snake.cs.tu-berlin.de:8081/~schwartz/pmh/index.html | LAOLA: The famous LAOLA homepage |
| http://skynet.csn.ul.ie/~caolan | wv-library: The wv-library from CaolanMcNamara (old link) |
| http://sourceforge.net/projects/wvware | wv-library: The wv-library from Caolan McNamara (new link) |
| http://www.btinternet.com/~shaheedhaque/ | Word 97: Information to Word Filters (Shaheed Haque) |
| http://xml.openoffice.org/ | StarOffice: The future-format for StarOffice (open office) (XML) |
| http://www.corel.com/partners_developers/ds/wpsdks.htm | WordPerfect, Presentations, Quattro Pro... Fileformat Description of Version 7.0 |
| ftp://www.thekompany.com/pub/KOffice/filters/ | Lotus API of WordPro |
| http://www-106.ibm.com/developerworks/library/buildappl/writedtd.html | Doctype Description |
| http://www.openoffice.org/source/browse/sw/sw/source/filter/ | StarOffice filters via webcvs: sw6 (StarWord 6), ww8 (WinWord8), ascii, excel, html, lotus, rtf, xml, ... |