summaryrefslogtreecommitdiffstats
path: root/tools/kfile-plugins
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 /tools/kfile-plugins
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 'tools/kfile-plugins')
-rw-r--r--tools/kfile-plugins/Makefile.am1
-rw-r--r--tools/kfile-plugins/RETURNED_ITEMS11
-rw-r--r--tools/kfile-plugins/abiword/Makefile.am22
-rw-r--r--tools/kfile-plugins/abiword/kfile_abiword.cpp145
-rw-r--r--tools/kfile-plugins/abiword/kfile_abiword.desktop49
-rw-r--r--tools/kfile-plugins/abiword/kfile_abiword.h42
-rw-r--r--tools/kfile-plugins/gnumeric/Makefile.am22
-rw-r--r--tools/kfile-plugins/gnumeric/kfile_gnumeric.cpp123
-rw-r--r--tools/kfile-plugins/gnumeric/kfile_gnumeric.desktop49
-rw-r--r--tools/kfile-plugins/gnumeric/kfile_gnumeric.h42
-rw-r--r--tools/kfile-plugins/koffice/Makefile.am22
-rw-r--r--tools/kfile-plugins/koffice/kfile_koffice.cpp116
-rw-r--r--tools/kfile-plugins/koffice/kfile_koffice.desktop66
-rw-r--r--tools/kfile-plugins/koffice/kfile_koffice.h42
-rw-r--r--tools/kfile-plugins/ooo/Makefile.am22
-rw-r--r--tools/kfile-plugins/ooo/kfile_ooo.cpp588
-rw-r--r--tools/kfile-plugins/ooo/kfile_ooo.desktop57
-rw-r--r--tools/kfile-plugins/ooo/kfile_ooo.h77
18 files changed, 1496 insertions, 0 deletions
diff --git a/tools/kfile-plugins/Makefile.am b/tools/kfile-plugins/Makefile.am
new file mode 100644
index 00000000..9632d298
--- /dev/null
+++ b/tools/kfile-plugins/Makefile.am
@@ -0,0 +1 @@
+SUBDIRS=koffice ooo gnumeric abiword
diff --git a/tools/kfile-plugins/RETURNED_ITEMS b/tools/kfile-plugins/RETURNED_ITEMS
new file mode 100644
index 00000000..62aea9bd
--- /dev/null
+++ b/tools/kfile-plugins/RETURNED_ITEMS
@@ -0,0 +1,11 @@
+Currently just
+
+Author
+Title
+Abstract
+
+as these are the most interesting of the documentinfo.xml properties.
+
+It would be nice to have other, autogenerated things too. Like number of pages.
+To avoid horrible loading times, we should wait until we use the thumbnail managing standard,
+then store stuff like #pages in preview.png.
diff --git a/tools/kfile-plugins/abiword/Makefile.am b/tools/kfile-plugins/abiword/Makefile.am
new file mode 100644
index 00000000..b24e4e14
--- /dev/null
+++ b/tools/kfile-plugins/abiword/Makefile.am
@@ -0,0 +1,22 @@
+## Makefile.am for gnumeric file meta info plugin
+
+# set the include path for X, qt and KDE
+INCLUDES = $(KOFFICE_INCLUDES) $(all_includes)
+
+# these are the headers for your project
+noinst_HEADERS = kfile_abiword.h
+
+kde_module_LTLIBRARIES = kfile_abiword.la
+
+kfile_abiword_la_SOURCES = kfile_abiword.cpp
+kfile_abiword_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN)
+kfile_abiword_la_LIBADD = $(LIB_KOFFICECORE)
+
+# let automoc handle all of the meta source files (moc)
+METASOURCES = AUTO
+
+services_DATA = kfile_abiword.desktop
+servicesdir = $(kde_servicesdir)
+
+messages:
+ $(XGETTEXT) *.cpp -o $(podir)/kfile_abiword.pot
diff --git a/tools/kfile-plugins/abiword/kfile_abiword.cpp b/tools/kfile-plugins/abiword/kfile_abiword.cpp
new file mode 100644
index 00000000..2b1b0cad
--- /dev/null
+++ b/tools/kfile-plugins/abiword/kfile_abiword.cpp
@@ -0,0 +1,145 @@
+/* This file is part of the KDE project
+ * Copyright (C) 2005 Laurent Montel <montel@kde.org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation version 2.
+ *
+ * This program 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include <config.h>
+#include "kfile_abiword.h"
+
+#include <klocale.h>
+#include <kgenericfactory.h>
+#include <kfilterdev.h>
+
+#include <qdom.h>
+#include <qfile.h>
+#include <qdatetime.h>
+#include <kdebug.h>
+
+typedef KGenericFactory<AbiwordPlugin> AbiwordFactory;
+
+K_EXPORT_COMPONENT_FACTORY(kfile_abiword, AbiwordFactory( "kfile_abiword" ))
+
+AbiwordPlugin::AbiwordPlugin(QObject *parent, const char *name,
+ const QStringList &args)
+
+ : KFilePlugin(parent, name, args)
+{
+ init();
+}
+
+void AbiwordPlugin::init()
+{
+ KFileMimeTypeInfo* info = addMimeTypeInfo( "application/x-abiword" );
+
+ KFileMimeTypeInfo::GroupInfo* group = 0L;
+
+ group = addGroupInfo(info, "DocumentInfo", i18n("Document Information"));
+
+ KFileMimeTypeInfo::ItemInfo* item;
+
+ item = addItemInfo(group, "Author", i18n("Author"), QVariant::String);
+ setHint(item, KFileMimeTypeInfo::Author);
+ item = addItemInfo(group, "Title", i18n("Title"), QVariant::String);
+ setHint(item, KFileMimeTypeInfo::Name);
+ item = addItemInfo(group, "Abstract", i18n("Abstract"), QVariant::String);
+ setHint(item, KFileMimeTypeInfo::Description);
+}
+
+bool AbiwordPlugin::readInfo( KFileMetaInfo& info, uint what)
+{
+ if ( info.path().isEmpty() ) // remote file
+ return false;
+
+ //Find the last extension
+ QString strExt;
+ const int result=info.path().findRev('.');
+ if (result>=0)
+ {
+ strExt=info.path().mid(result);
+ }
+ QString strMime; // Mime type of the compressor (default: unknown)
+ if ((strExt==".gz")||(strExt==".GZ") //in case of .abw.gz (logical extension)
+ ||(strExt==".zabw")||(strExt==".ZABW")) //in case of .zabw (extension used prioritary with AbiWord)
+ {
+ // Compressed with gzip
+ strMime="application/x-gzip";
+ kdDebug() << "Compression: gzip" << endl;
+ }
+ else if ((strExt==".bz2")||(strExt==".BZ2") //in case of .abw.bz2 (logical extension)
+ ||(strExt==".bzabw")||(strExt==".BZABW")) //in case of .bzabw (extension used prioritary with AbiWord)
+ {
+ // Compressed with bzip2
+ strMime="application/x-bzip2";
+ kdDebug() << "Compression: bzip2" << endl;
+ }
+
+ KFileMetaInfoGroup group = appendGroup(info, "DocumentInfo");
+ QIODevice* in = KFilterDev::deviceForFile(info.path(),strMime);
+ if ( !in )
+ {
+ kdError() << "Cannot create device for uncompressing! Aborting!" << endl;
+ return false;
+ }
+
+ if (!in->open(IO_ReadOnly))
+ {
+ kdError() << "Cannot open file for uncompressing! Aborting!" << endl;
+ delete in;
+ return false;
+ }
+ QDomDocument doc;
+ doc.setContent( in );
+ in->close();
+ QDomElement docElem = doc.documentElement();
+ QDomNode summary = docElem.namedItem("metadata");
+ QDomNode m_item = summary.namedItem("m");
+
+ QString author;
+ QString title;
+ QString abstract;
+
+ while( !m_item.isNull() )
+ {
+ kdDebug()<<" m_item.toElement().text: "<<m_item.toElement().text()<<endl;
+ QString key = m_item.toElement().attribute( "key" );
+ if ( key.isEmpty() )
+ continue;
+ else if ( key=="dc.creator" )
+ author=m_item.toElement().text();
+ else if ( key=="dc.description" )
+ abstract=m_item.toElement().text();
+ else if ( key=="dc.title" )
+ title=m_item.toElement().text();
+ else
+ kdDebug()<<" Other key :"<<key<<endl;
+ m_item = m_item.nextSibling();
+ }
+ appendItem(group, "Author", stringItem( author ));
+ appendItem(group, "Title", stringItem( title ));
+ appendItem(group, "Abstract", stringItem( abstract ));
+
+ delete in;
+ return true;
+}
+
+QString AbiwordPlugin::stringItem( const QString &name )
+{
+ return name.isEmpty() ? i18n("*Unknown*") : name;
+}
+
+
+#include "kfile_abiword.moc"
diff --git a/tools/kfile-plugins/abiword/kfile_abiword.desktop b/tools/kfile-plugins/abiword/kfile_abiword.desktop
new file mode 100644
index 00000000..805aad4a
--- /dev/null
+++ b/tools/kfile-plugins/abiword/kfile_abiword.desktop
@@ -0,0 +1,49 @@
+[Desktop Entry]
+Type=Service
+Name=Abiword Info
+Name[bg]=Информация за Abiword
+Name[br]=Titouroù Abiword
+Name[ca]=Informació Abiword
+Name[cy]=Gwybodaeth Abiword
+Name[da]=Abiword-info
+Name[el]=Πληροφορίες Abiword
+Name[eo]=Abiword-informo
+Name[es]=Información de Abiword
+Name[et]=Abiword'i info
+Name[fa]=اطلاعات Abiword
+Name[fi]=Abiword-tiedot
+Name[fr]=Informations sur Abiword
+Name[fy]=Abiword ynfo
+Name[ga]=Eolas faoi Abiword
+Name[gl]=Información de Abiword
+Name[he]=מידע של Abiword
+Name[hu]=Abiword-információ
+Name[is]=Abiword upplýsingar
+Name[it]=Informazioni su Abiword
+Name[ja]=Abiword 情報
+Name[km]=ព័ត៌មាន Abiword
+Name[lt]=Abiword informacija
+Name[lv]=Abiword informācija
+Name[nb]=Abiword-info
+Name[nds]=Abiword-Info
+Name[ne]=एबीआई वर्ड सूचना
+Name[nl]=Abiword-info
+Name[pl]=Informacje o Abiword
+Name[pt]=Informação do Abiword
+Name[pt_BR]=Informação do Abiword
+Name[ru]=Информация AbiWord
+Name[se]=Abiword-dieđut
+Name[sl]=Informacije o Abiword
+Name[sr]=Информације Abiword-а
+Name[sr@Latn]=Informacije Abiword-a
+Name[sv]=Abiword-information
+Name[uk]=Інформація Abiword
+Name[uz]=Abiword hujjati haqida maʼlumot
+Name[uz@cyrillic]=Abiword ҳужжати ҳақида маълумот
+Name[zh_CN]=Abiword 信息
+Name[zh_TW]=Abiword 資訊
+ServiceTypes=KFilePlugin
+X-KDE-Library=kfile_abiword
+MimeType=application/x-abiword
+PreferredGroups=DocumentInfo
+PreferredItems=Author,Title,Abstract
diff --git a/tools/kfile-plugins/abiword/kfile_abiword.h b/tools/kfile-plugins/abiword/kfile_abiword.h
new file mode 100644
index 00000000..33ee9c63
--- /dev/null
+++ b/tools/kfile-plugins/abiword/kfile_abiword.h
@@ -0,0 +1,42 @@
+/* This file is part of the KDE project
+ * Copyright (C) 2005 Laurent Montel montel@kde.org
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation version 2.
+ *
+ * This program 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef __KFILE_ABIWORD_H__
+#define __KFILE_ABIWORD_H__
+
+#include <kfilemetainfo.h>
+
+class QStringList;
+class QDomNode;
+
+class AbiwordPlugin: public KFilePlugin
+{
+ Q_OBJECT
+
+public:
+ AbiwordPlugin( QObject *parent, const char *name, const QStringList& args );
+
+ virtual bool readInfo( KFileMetaInfo& info, uint what);
+
+private:
+ void init();
+ QString stringItem( const QString &name );
+};
+
+#endif
diff --git a/tools/kfile-plugins/gnumeric/Makefile.am b/tools/kfile-plugins/gnumeric/Makefile.am
new file mode 100644
index 00000000..8f8f7af6
--- /dev/null
+++ b/tools/kfile-plugins/gnumeric/Makefile.am
@@ -0,0 +1,22 @@
+## Makefile.am for gnumeric file meta info plugin
+
+# set the include path for X, qt and KDE
+INCLUDES = $(KOFFICE_INCLUDES) $(all_includes)
+
+# these are the headers for your project
+noinst_HEADERS = kfile_gnumeric.h
+
+kde_module_LTLIBRARIES = kfile_gnumeric.la
+
+kfile_gnumeric_la_SOURCES = kfile_gnumeric.cpp
+kfile_gnumeric_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN)
+kfile_gnumeric_la_LIBADD = $(LIB_KOFFICECORE)
+
+# let automoc handle all of the meta source files (moc)
+METASOURCES = AUTO
+
+services_DATA = kfile_gnumeric.desktop
+servicesdir = $(kde_servicesdir)
+
+messages:
+ $(XGETTEXT) *.cpp -o $(podir)/kfile_gnumeric.pot
diff --git a/tools/kfile-plugins/gnumeric/kfile_gnumeric.cpp b/tools/kfile-plugins/gnumeric/kfile_gnumeric.cpp
new file mode 100644
index 00000000..8d4b7928
--- /dev/null
+++ b/tools/kfile-plugins/gnumeric/kfile_gnumeric.cpp
@@ -0,0 +1,123 @@
+/* This file is part of the KDE project
+ * Copyright (C) 2005 Laurent Montel <montel@kde.org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation version 2.
+ *
+ * This program 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include <config.h>
+#include "kfile_gnumeric.h"
+
+#include <klocale.h>
+#include <kgenericfactory.h>
+#include <kfilterdev.h>
+
+#include <qdom.h>
+#include <qfile.h>
+#include <qdatetime.h>
+#include <kdebug.h>
+
+typedef KGenericFactory<GnumericPlugin> GnumericFactory;
+
+K_EXPORT_COMPONENT_FACTORY(kfile_gnumeric, GnumericFactory( "kfile_gnumeric" ))
+
+GnumericPlugin::GnumericPlugin(QObject *parent, const char *name,
+ const QStringList &args)
+
+ : KFilePlugin(parent, name, args)
+{
+ init();
+}
+
+void GnumericPlugin::init()
+{
+ KFileMimeTypeInfo* info = addMimeTypeInfo( "application/x-gnumeric" );
+
+ KFileMimeTypeInfo::GroupInfo* group = 0L;
+
+ group = addGroupInfo(info, "DocumentInfo", i18n("Document Information"));
+
+ KFileMimeTypeInfo::ItemInfo* item;
+
+ item = addItemInfo(group, "Author", i18n("Author"), QVariant::String);
+ setHint(item, KFileMimeTypeInfo::Author);
+ item = addItemInfo(group, "Title", i18n("Title"), QVariant::String);
+ setHint(item, KFileMimeTypeInfo::Name);
+ item = addItemInfo(group, "Abstract", i18n("Abstract"), QVariant::String);
+ setHint(item, KFileMimeTypeInfo::Description);
+}
+
+bool GnumericPlugin::readInfo( KFileMetaInfo& info, uint what)
+{
+ if ( info.path().isEmpty() ) // remote file
+ return false;
+
+ KFileMetaInfoGroup group = appendGroup(info, "DocumentInfo");
+ QIODevice* in = KFilterDev::deviceForFile(info.path(),"application/x-gzip");
+ if ( !in )
+ {
+ kdError() << "Cannot create device for uncompressing! Aborting!" << endl;
+ return false;
+ }
+
+ if (!in->open(IO_ReadOnly))
+ {
+ kdError() << "Cannot open file for uncompressing! Aborting!" << endl;
+ delete in;
+ return false;
+ }
+ QDomDocument doc;
+ doc.setContent( in );
+ in->close();
+ QDomElement docElem = doc.documentElement();
+ QDomNode summary = docElem.namedItem("gmr:Summary");
+ QDomNode gmr_item = summary.namedItem("gmr:Item");
+ QString author;
+ QString title;
+ QString abstract;
+
+ while( !gmr_item.isNull() )
+ {
+ QDomNode gmr_name = gmr_item.namedItem("gmr:name");
+ QDomNode gmr_value = gmr_item.namedItem("gmr:val-string");
+ if (gmr_name.toElement().text() == "title")
+ {
+ title=gmr_value.toElement().text();
+ }
+ else if (gmr_name.toElement().text() == "author")
+ {
+ author=gmr_value.toElement().text();
+ }
+ else if (gmr_name.toElement().text() == "comments")
+ {
+ abstract=gmr_value.toElement().text();
+ }
+ gmr_item = gmr_item.nextSibling();
+ }
+ appendItem(group, "Author", stringItem( author ));
+ appendItem(group, "Title", stringItem( title ));
+ appendItem(group, "Abstract", stringItem( abstract ));
+
+ delete in;
+ return true;
+}
+
+QString GnumericPlugin::stringItem( const QString &name )
+{
+ return name.isEmpty() ? i18n("*Unknown*") : name;
+}
+
+
+#include "kfile_gnumeric.moc"
diff --git a/tools/kfile-plugins/gnumeric/kfile_gnumeric.desktop b/tools/kfile-plugins/gnumeric/kfile_gnumeric.desktop
new file mode 100644
index 00000000..9a99d138
--- /dev/null
+++ b/tools/kfile-plugins/gnumeric/kfile_gnumeric.desktop
@@ -0,0 +1,49 @@
+[Desktop Entry]
+Type=Service
+Name=Gnumeric Info
+Name[bg]=Информация за Gnumeric
+Name[br]=Titouroù Gnumeric
+Name[ca]=Informació GNUmeric
+Name[cy]=Gwybodaeth Gnumeric
+Name[da]=Gnumeric info
+Name[el]=Πληροφορίες Gnumeric
+Name[eo]=Gnumeric-informo
+Name[es]=Información de Gnumeric
+Name[et]=Gnumeric'i info
+Name[fa]=اطلاعات Gnumeric
+Name[fi]=Gnumeric-tiedot
+Name[fr]=Informations sur Gnumeric
+Name[fy]=Gnumeric ynfo
+Name[ga]=Ginearálta
+Name[gl]=Información de Gnumeric
+Name[he]=מידע של Gnumeric
+Name[hu]=Gnumeric-információ
+Name[is]=Gnumeric upplýsingar
+Name[it]=Informazioni su Gnumeric
+Name[ja]=Gnumeric 情報
+Name[km]=ព័ត៌មាន Gnumeric
+Name[lt]=Gnumeric informacija
+Name[lv]=Gnumeric informācija
+Name[nb]=Gnumeric-info
+Name[nds]=Gnumeric-Info
+Name[ne]=जीन्यूमेरिक सूचना
+Name[nl]=Gnumeric-info
+Name[pl]=Informacje o Gnumeric
+Name[pt]=Informação do Gnumeric
+Name[pt_BR]=Informação do Gnumeric
+Name[ru]=Информация Gnumeric
+Name[se]=Gnumeric-dieđut
+Name[sl]=Informacije o Gnumeric
+Name[sr]=Информације Gnumeric-а
+Name[sr@Latn]=Informacije Gnumeric-a
+Name[sv]=Gnumeric-information
+Name[uk]=Інформація Gnumeric
+Name[uz]=Gnumeric hujjati haqida maʼlumot
+Name[uz@cyrillic]=Gnumeric ҳужжати ҳақида маълумот
+Name[zh_CN]=Gnumeric 信息
+Name[zh_TW]=Gnumeric 資訊
+ServiceTypes=KFilePlugin
+X-KDE-Library=kfile_gnumeric
+MimeType=application/x-gnumeric
+PreferredGroups=DocumentInfo
+PreferredItems=Author,Title,Abstract
diff --git a/tools/kfile-plugins/gnumeric/kfile_gnumeric.h b/tools/kfile-plugins/gnumeric/kfile_gnumeric.h
new file mode 100644
index 00000000..2df2d200
--- /dev/null
+++ b/tools/kfile-plugins/gnumeric/kfile_gnumeric.h
@@ -0,0 +1,42 @@
+/* This file is part of the KDE project
+ * Copyright (C) 2005 Laurent Montel montel@kde.org
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation version 2.
+ *
+ * This program 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef __KFILE_GNUMERIC_H__
+#define __KFILE_GNUMERIC_H__
+
+#include <kfilemetainfo.h>
+
+class QStringList;
+class QDomNode;
+
+class GnumericPlugin: public KFilePlugin
+{
+ Q_OBJECT
+
+public:
+ GnumericPlugin( QObject *parent, const char *name, const QStringList& args );
+
+ virtual bool readInfo( KFileMetaInfo& info, uint what);
+
+private:
+ void init();
+ QString stringItem( const QString &name );
+};
+
+#endif
diff --git a/tools/kfile-plugins/koffice/Makefile.am b/tools/kfile-plugins/koffice/Makefile.am
new file mode 100644
index 00000000..ab34443c
--- /dev/null
+++ b/tools/kfile-plugins/koffice/Makefile.am
@@ -0,0 +1,22 @@
+## Makefile.am for koffice file meta info plugin
+
+# set the include path for X, qt and KDE
+INCLUDES = $(KOFFICE_INCLUDES) $(all_includes)
+
+# these are the headers for your project
+noinst_HEADERS = kfile_koffice.h
+
+kde_module_LTLIBRARIES = kfile_koffice.la
+
+kfile_koffice_la_SOURCES = kfile_koffice.cpp
+kfile_koffice_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN)
+kfile_koffice_la_LIBADD = $(LIB_KOFFICECORE)
+
+# let automoc handle all of the meta source files (moc)
+METASOURCES = AUTO
+
+services_DATA = kfile_koffice.desktop
+servicesdir = $(kde_servicesdir)
+
+messages:
+ $(XGETTEXT) *.cpp -o $(podir)/kfile_koffice.pot
diff --git a/tools/kfile-plugins/koffice/kfile_koffice.cpp b/tools/kfile-plugins/koffice/kfile_koffice.cpp
new file mode 100644
index 00000000..03274251
--- /dev/null
+++ b/tools/kfile-plugins/koffice/kfile_koffice.cpp
@@ -0,0 +1,116 @@
+/* This file is part of the KDE project
+ * Copyright (C) 2002 Simon MacMullen
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation version 2.
+ *
+ * This program 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include <config.h>
+#include "kfile_koffice.h"
+
+#include <klocale.h>
+#include <kgenericfactory.h>
+#include <KoStore.h>
+#include <KoStoreDevice.h>
+
+#include <qdom.h>
+#include <qfile.h>
+#include <qdatetime.h>
+
+typedef KGenericFactory<KOfficePlugin> KOfficeFactory;
+
+K_EXPORT_COMPONENT_FACTORY(kfile_koffice, KOfficeFactory( "kfile_koffice" ))
+
+KOfficePlugin::KOfficePlugin(QObject *parent, const char *name,
+ const QStringList &args)
+
+ : KFilePlugin(parent, name, args)
+{
+ makeMimeTypeInfo( "application/x-kword" );
+ makeMimeTypeInfo( "application/x-kpresenter" );
+ makeMimeTypeInfo( "application/x-kspread" );
+ makeMimeTypeInfo( "application/x-karbon" );
+ makeMimeTypeInfo( "application/x-kontour" );
+ makeMimeTypeInfo( "application/x-kchart" );
+ makeMimeTypeInfo( "application/x-kivio" );
+ makeMimeTypeInfo( "application/x-krita" );
+ makeMimeTypeInfo( "application/x-kformula" );
+
+ /*makeMimeTypeInfo( "application/vnd.kde.kword" );
+ makeMimeTypeInfo( "application/vnd.kde.kpresenter" );
+ makeMimeTypeInfo( "application/vnd.kde.kspread" );
+ makeMimeTypeInfo( "application/vnd.kde.karbon" );
+ makeMimeTypeInfo( "application/vnd.kde.kontour" );*/
+}
+
+void KOfficePlugin::makeMimeTypeInfo(const QString& mimeType)
+{
+ KFileMimeTypeInfo* info = addMimeTypeInfo( mimeType );
+
+ KFileMimeTypeInfo::GroupInfo* group = 0L;
+
+ group = addGroupInfo(info, "DocumentInfo", i18n("Document Information"));
+
+ KFileMimeTypeInfo::ItemInfo* item;
+
+ item = addItemInfo(group, "Author", i18n("Author"), QVariant::String);
+ setHint(item, KFileMimeTypeInfo::Author);
+ item = addItemInfo(group, "Title", i18n("Title"), QVariant::String);
+ setHint(item, KFileMimeTypeInfo::Name);
+ item = addItemInfo(group, "Abstract", i18n("Abstract"), QVariant::String);
+ setHint(item, KFileMimeTypeInfo::Description);
+}
+
+bool KOfficePlugin::readInfo( KFileMetaInfo& info, uint what)
+{
+ if ( info.path().isEmpty() ) // remote file
+ return false;
+
+ KFileMetaInfoGroup group = appendGroup(info, "DocumentInfo");
+
+ KoStore* store = KoStore::createStore(info.path(), KoStore::Read);
+ if ( store && store->open( QString("documentinfo.xml") ) )
+ {
+ KoStoreDevice dev( store );
+ QDomDocument doc;
+ doc.setContent( &dev );
+
+ QDomNode authorNode = doc.namedItem("document-info").namedItem("author");
+ QDomNode aboutNode = doc.namedItem("document-info").namedItem("about");
+
+ QString author = stringFromNode(authorNode, "full-name");
+ QString title = stringFromNode(aboutNode, "title");
+ QString abstract = stringFromNode(aboutNode, "abstract");
+
+ appendItem(group, "Author", author);
+ appendItem(group, "Title", title);
+ appendItem(group, "Abstract", abstract);
+
+ store->close();
+ delete store;
+ return true;
+ }
+ delete store;
+ return false;
+}
+
+QString KOfficePlugin::stringFromNode(const QDomNode &node, const QString &name)
+{
+ QString value = node.namedItem(name).toElement().text();
+ return value.isEmpty() ? i18n("*Unknown*") : value;
+}
+
+
+#include "kfile_koffice.moc"
diff --git a/tools/kfile-plugins/koffice/kfile_koffice.desktop b/tools/kfile-plugins/koffice/kfile_koffice.desktop
new file mode 100644
index 00000000..8c8449aa
--- /dev/null
+++ b/tools/kfile-plugins/koffice/kfile_koffice.desktop
@@ -0,0 +1,66 @@
+[Desktop Entry]
+Type=Service
+Name=KOffice Info
+Name[af]=Koffice Inligting
+Name[ar]=معلومات KOffice
+Name[bg]=Информация за KOffice
+Name[br]=Titouroù diwar-benn KOffice
+Name[ca]=Informació KOffice
+Name[cs]=KOffice info
+Name[cy]=Gwybodaeth KOffice
+Name[da]=KOffice-information
+Name[el]=Πληροφορίες KOffice
+Name[eo]=KOffice informo
+Name[es]=Información de KOffice
+Name[et]=KOffice'i info
+Name[eu]=KOffice-en informazioa
+Name[fa]=اطلاعات KOffice
+Name[fi]=KOffice-tiedot
+Name[fo]=KSkrivstovu-upplýsingar
+Name[fr]=Informations sur KOffice
+Name[fy]=KOffice ynfo
+Name[ga]=Eolas faoi KOffice
+Name[gl]=Información de KOffice
+Name[he]=מידע KOffice
+Name[hi]=केऑफ़िस जानकारी
+Name[hu]=KOffice-információ
+Name[is]=KOffice upplýsingar
+Name[it]=Informazioni KOffice
+Name[ja]=KOffice 情報
+Name[km]=ព័ត៌មាន KOffice
+Name[lo]=ຂໍ້ມູນໂປຣແກມຊຸດສໍານັກງານ
+Name[lt]=KOffice informacija
+Name[lv]=KOffice informācija
+Name[ms]=Maklumat KOffice
+Name[mt]=Info. KOffice
+Name[nb]=KOffice-info
+Name[nds]=KOffice-Info
+Name[ne]=केडीई कार्यालय सूचना
+Name[nl]=Koffice-info
+Name[nn]=KOffice-info
+Name[pa]=KOffice ਜਾਣਕਾਰੀ
+Name[pl]=Informacje o KOffice
+Name[pt]=Informação do KOffice
+Name[pt_BR]=Informações do KOffice
+Name[ru]=Информация KOffice
+Name[se]=KOffice-dieđut
+Name[sk]=Informácie o KOffice
+Name[sl]=Informacije o KOffice
+Name[sr]=Информације KOffice-а
+Name[sr@Latn]=Informacije KOffice-a
+Name[sv]=Koffice-information
+Name[tg]=KOffice Ахборот
+Name[th]=ข้อมูลโปรแกรมชุดสำนักงาน
+Name[tr]=KOffice Bilgisi
+Name[uk]=Інформація KOffice
+Name[uz]=KOffice maʼlumot
+Name[uz@cyrillic]=KOffice маълумот
+Name[wa]=Informåcion KOffice
+Name[xh]=Ulwazi lwe KOffice
+Name[zh_CN]=KOffice 信息
+Name[zh_TW]=KOffice 資訊
+ServiceTypes=KFilePlugin
+X-KDE-Library=kfile_koffice
+MimeType=application/x-kword;application/x-kpresenter;application/x-kspread;application/x-karbon
+PreferredGroups=DocumentInfo
+PreferredItems=Author,Title,Abstract
diff --git a/tools/kfile-plugins/koffice/kfile_koffice.h b/tools/kfile-plugins/koffice/kfile_koffice.h
new file mode 100644
index 00000000..e5a60c1a
--- /dev/null
+++ b/tools/kfile-plugins/koffice/kfile_koffice.h
@@ -0,0 +1,42 @@
+/* This file is part of the KDE project
+ * Copyright (C) 2002 Simon MacMullen
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation version 2.
+ *
+ * This program 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef __KFILE_KOFFICE_H__
+#define __KFILE_KOFFICE_H__
+
+#include <kfilemetainfo.h>
+
+class QStringList;
+class QDomNode;
+
+class KOfficePlugin: public KFilePlugin
+{
+ Q_OBJECT
+
+public:
+ KOfficePlugin( QObject *parent, const char *name, const QStringList& args );
+
+ virtual bool readInfo( KFileMetaInfo& info, uint what);
+
+private:
+ void makeMimeTypeInfo(const QString& mimeType);
+ QString stringFromNode(const QDomNode &node, const QString &name);
+};
+
+#endif
diff --git a/tools/kfile-plugins/ooo/Makefile.am b/tools/kfile-plugins/ooo/Makefile.am
new file mode 100644
index 00000000..0dbd2f75
--- /dev/null
+++ b/tools/kfile-plugins/ooo/Makefile.am
@@ -0,0 +1,22 @@
+## Makefile.am for OpenOffice.org file meta info plugin
+
+# set the include path for X, qt and KDE
+INCLUDES = $(KOFFICE_INCLUDES) $(all_includes)
+
+# these are the headers for your project
+noinst_HEADERS = kfile_ooo.h
+
+kde_module_LTLIBRARIES = kfile_ooo.la
+
+kfile_ooo_la_SOURCES = kfile_ooo.cpp
+kfile_ooo_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN)
+kfile_ooo_la_LIBADD = $(LIB_KOFFICECORE)
+
+# let automoc handle all of the meta source files (moc)
+METASOURCES = AUTO
+
+services_DATA = kfile_ooo.desktop
+servicesdir = $(kde_servicesdir)
+
+messages:
+ $(XGETTEXT) *.cpp -o $(podir)/kfile_ooo.pot
diff --git a/tools/kfile-plugins/ooo/kfile_ooo.cpp b/tools/kfile-plugins/ooo/kfile_ooo.cpp
new file mode 100644
index 00000000..4f16a0af
--- /dev/null
+++ b/tools/kfile-plugins/ooo/kfile_ooo.cpp
@@ -0,0 +1,588 @@
+/* This file is part of the KDE project
+ * Copyright (C) 2003 Pierre Souchay <pierre@souchay.net>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation version 2.
+ *
+ * This program 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+/**
+ * CHANGES
+ * v1.7 to 1.9
+ * Added the editing duration analysis.
+ * v1.6 to 1.7
+ * Changed the incorrect meta:date to dc:date
+ * Now parse date instead of simply print the ISO date
+ * Fixes bug with keywords, now properly handled
+ * Changed the deprecated upload method to the new one.
+ * v1.5 to 1.6
+ * Correction for bug 68112: http://bugs.kde.org/show_bug.cgi?id=68112
+ * OOo 1.1 does not support garbages in zip files. We now recreate the zip
+ * file from scratch. It is slower, but we don't have the choice :(
+ * v1.1 to v1.2
+ * Added support for KFileMimeTypeInfo::Hints (Name, Author, Description)
+ * Added some Advanced Attributes and Statistics according to DTD of OOo
+ * No more duplicated strings of same contents to facilitate changes
+ */
+
+#include <config.h>
+#include "kfile_ooo.h"
+
+#include <klocale.h>
+#include <kgenericfactory.h>
+#include <KoStore.h>
+#include <KoStoreDevice.h>
+#include <kzip.h>
+#include <ktempfile.h>
+#include <qptrstack.h>
+
+#include <qdom.h>
+#include <qfile.h>
+#include <qdatetime.h>
+#include <qvalidator.h>
+#include <kdebug.h>
+#include <kio/netaccess.h>
+
+typedef KGenericFactory<KOfficePlugin> KOfficeFactory;
+
+K_EXPORT_COMPONENT_FACTORY(kfile_ooo, KOfficeFactory( "kfile_ooo" ))
+
+static const char * const mimetypes[] =
+{ "application/vnd.sun.xml.calc", "application/vnd.sun.xml.calc.template",
+ "application/vnd.sun.xml.draw", "application/vnd.sun.xml.draw.template",
+ "application/vnd.sun.xml.impress","application/vnd.sun.xml.impress.template",
+ "application/vnd.sun.xml.writer", "application/vnd.sun.xml.writer.global",
+ "application/vnd.sun.xml.writer.math",
+ "application/vnd.sun.xml.writer.template",
+ "application/vnd.oasis.opendocument.chart",
+ "application/vnd.oasis.opendocument.formula",
+ "application/vnd.oasis.opendocument.graphics",
+ "application/vnd.oasis.opendocument.graphics-template",
+ "application/vnd.oasis.opendocument.presentation",
+ "application/vnd.oasis.opendocument.presentation-template",
+ "application/vnd.oasis.opendocument.spreadsheet",
+ "application/vnd.oasis.opendocument.spreadsheet-template",
+ "application/vnd.oasis.opendocument.text",
+ "application/vnd.oasis.opendocument.text-template",
+ 0};
+
+static const char * const Advanced[] =
+ {
+ "meta:printed-by" , I18N_NOOP("Printed By"),
+ "meta:print-date" , I18N_NOOP("Print Date"),
+ "dc:date" , I18N_NOOP("Date"),
+ "meta:creation-date" , I18N_NOOP("Creation Date"),
+ "meta:initial-creator", I18N_NOOP("Creator"),
+ "meta:generator" , I18N_NOOP("Generator"),
+ "meta:editing-cycles" , I18N_NOOP("Editing Cycles"),
+ "meta:editing-duration" , I18N_NOOP("Editing Duration"),
+ 0};
+
+static const char * dclanguage = "dc:language";
+
+static const char * const Information[] =
+ {"dc:title" , I18N_NOOP("Title") ,
+ "dc:creator" , I18N_NOOP("Author") ,
+ "dc:description", I18N_NOOP("Description"),
+ "dc:subject" , I18N_NOOP("Subject") ,
+ dclanguage , I18N_NOOP("Language") ,
+ 0};
+
+static const char * const Statistics[] =
+ {"meta:draw-count" , I18N_NOOP("Draws"),
+ "meta:table-count" , I18N_NOOP("Tables"),
+ "meta:image-count" , I18N_NOOP("Images"),
+ "meta:object-count" , I18N_NOOP("Objects"),
+ "meta:ole-object-count", I18N_NOOP("OLE Objects"),
+ "meta:page-count" , I18N_NOOP("Pages"),
+ "meta:paragraph-count" , I18N_NOOP("Paragraphs"),
+ "meta:word-count" , I18N_NOOP("Words"),
+ "meta:cell-count" , I18N_NOOP("Cells"),
+ "meta:character-count" , I18N_NOOP("Characters"),
+ "meta:row-count" , I18N_NOOP("Rows"),
+ 0};
+
+static const char * metakeywords = "meta:keywords";
+static const char * metakeyword = "meta:keyword" ;
+static const char * DocumentInfo = "DocumentInfo" ;
+static const char * UserDefined = "UserDefined" ;
+static const char * DocAdvanced = "Advanced" ;
+static const char * DocStatistics = "Statistics" ;
+static const char * metadocstat = "meta:document-statistic";
+static const char * metaname = "meta:name" ;
+static const char * metauserdef = "meta:user-defined";
+static const char * metafile = "meta.xml" ;
+KOfficePlugin::KOfficePlugin(QObject *parent, const char *name,
+ const QStringList &args)
+
+ : KFilePlugin(parent, name, args)
+{
+ int i = 0;
+ while (mimetypes[i])
+ makeMimeTypeInfo( mimetypes[i++] );
+}
+
+void KOfficePlugin::makeMimeTypeInfo(const QString& mimeType)
+{
+ KFileMimeTypeInfo* info = addMimeTypeInfo( mimeType );
+
+ userdefined = addGroupInfo(info, UserDefined, i18n("User Defined"));
+ addVariableInfo(userdefined, QVariant::String,
+ KFileMimeTypeInfo::Addable |
+ KFileMimeTypeInfo::Removable |
+ KFileMimeTypeInfo::Modifiable);
+
+ KFileMimeTypeInfo::GroupInfo* group = 0L;
+ group = addGroupInfo(info, DocumentInfo, i18n("Document Information"));
+ KFileMimeTypeInfo::ItemInfo* item;
+ int i = 0;
+ for (i = 0; Information[i]; i+=2){
+ item = addItemInfo(group, Information[i], i18n(Information[i+1]),
+ QVariant::String);
+ setAttributes(item, KFileMimeTypeInfo::Modifiable);
+ switch (i){
+ case 0:
+ setHint(item, KFileMimeTypeInfo::Name);
+ break;
+ case 1:
+ setHint(item, KFileMimeTypeInfo::Author);
+ break;
+ case 2:
+ setHint(item, KFileMimeTypeInfo::Description);
+ default:;
+ }
+ }
+
+ item = addItemInfo(group, metakeyword, i18n("Keywords"),
+ QVariant::String);
+ setHint(item, KFileMimeTypeInfo::Description);
+ setAttributes(item, KFileMimeTypeInfo::Modifiable);
+
+ group = addGroupInfo(info, DocAdvanced, i18n("Document Advanced"));
+ for (i = 0; Advanced[i]; i+=2){
+ // I should add the isDate property instead of testing the index, but it works well, who cares ? :-)
+ QVariant::Type typ = QVariant::String;
+ if (i > 1 && i < 8)
+ typ = QVariant::DateTime;
+ if (i == 14)
+ typ = QVariant::String;
+ item = addItemInfo(group, Advanced[i], i18n(Advanced[i+1]), typ);
+ setHint(item, KFileMimeTypeInfo::Description);
+ }
+
+ group = addGroupInfo(info, DocStatistics, i18n("Document Statistics"));
+ for (i = 0; Statistics[i]; i+=2){
+ item = addItemInfo(group, Statistics[i], i18n(Statistics[i+1]),
+ QVariant::Int);
+ setHint(item, KFileMimeTypeInfo::Length);
+ }
+}
+
+/**
+ * Gets a number in the string and update the position next character which
+ * is not a number
+ * @param str The string to check
+ * @param the position to start to, updated to the next character NAN
+ * @return the number parsed, 0 if number was not valid
+ */
+int getNumber(QString &str, int * pos){
+ int k = *pos;
+ for (int len = str.length() ;
+ str.at(k).isNumber() && k < len ;
+ k++);
+ bool result = false;
+ int num = str.mid( *pos, k-(*pos)).toInt(&result);
+ *pos = k;
+ if (!result)
+ return 0;
+ return num;
+}
+
+void KOfficePlugin::getEditingTime(KFileMetaInfoGroup group1,
+ const char * labelid, QString & txt){
+ QString t;
+ int days = 0;
+ int hours = 0;
+ int minutes = 0;
+ int seconds = 0;
+ if (txt.at(0) != 'P'){
+ kdDebug(7034) << labelid << "=" << txt <<
+ " does not seems to be a valid duration" << endl;
+ return;
+ }
+ int pos = 1;
+ if (txt.at(pos).isNumber()){
+ days = getNumber(txt, &pos);
+ if (txt.at(pos++)!='D'){
+ days=0;
+ kdDebug(7034) << labelid <<
+ " First arg was not a day in " << txt << endl;
+ }
+ }
+ if (txt.at(pos)!= 'T'){
+ kdDebug(7034) << labelid << "=" << txt <<
+ " does not seems to contain time information" << endl;
+ return;
+ }
+ pos++;
+ int len = txt.length();
+ while (pos < len){
+ int res = getNumber(txt, &pos);
+ if (pos >= len)
+ return;
+ switch (txt.at(pos).latin1()){
+ case 'H':
+ hours = res;
+ break;
+ case 'M':
+ minutes = res;
+ break;
+ case 'S':
+ seconds = res;
+ break;
+ default:
+ kdDebug(7034) << "Unknown unit at pos " << pos << " while parsing " <<
+ labelid << "="<< txt << endl;
+ }
+ pos++;
+ }
+ hours += days * 24;
+ appendItem(group1, labelid,
+ i18n("%1:%2.%3").arg(hours).arg(minutes, 2).arg(seconds,2 ));
+}
+
+void KOfficePlugin::getDateTime(KFileMetaInfoGroup group1,
+ const char * labelid, QString & txt)
+{
+ QDateTime dt = QDateTime::fromString( txt, Qt::ISODate);
+ appendItem( group1, labelid, dt);
+}
+
+bool KOfficePlugin::readInfo( KFileMetaInfo& info, uint /*what*/)
+{
+ if ( info.path().isEmpty() ) // remote file
+ return false;
+
+ KFileMetaInfoGroup group = appendGroup(info, DocumentInfo);
+ QDomDocument doc = getMetaDocument(info.path());
+ if (doc.isNull())
+ return false;
+ QDomElement base = getBaseNode(doc).toElement();
+ if (base.isNull())
+ return false;
+ for (int i = 0; Information[i]; i+=2)
+ appendItem(group, Information[i],
+ stringFromNode(base, Information[i]));
+ // Special case for keyword
+ QDomNodeList keywordList = base.elementsByTagName( metakeyword );
+ QString allKeywords;
+ for (uint i = 0; i < keywordList.length(); i++){
+ QDomNode node = keywordList.item(i);
+ if (node.isElement()){
+ if (i>0)
+ allKeywords += ", ";
+ allKeywords += node.toElement().text();
+ }
+ }
+ appendItem(group, metakeyword,
+ allKeywords);
+
+ KFileMetaInfoGroup group1 = appendGroup(info, DocAdvanced);
+ for (int i = 0; Advanced[i]; i+=2){
+ QString txt = stringFromNode(base, Advanced[i]);
+ if (!txt.isEmpty()){
+ // A silly way to do it...
+ switch (i){
+ case 2:
+ case 4:
+ case 6:
+ getDateTime(group1, Advanced[i], txt);
+ break;
+ case 14:
+ getEditingTime(group1, Advanced[i], txt);
+ break;
+ default:
+ appendItem(group1, Advanced[i], txt);}
+ }
+ }
+
+ QDomNode dstat = base.namedItem(metadocstat);
+
+ KFileMetaInfoGroup group2 = appendGroup(info, DocStatistics);
+ if (!dstat.isNull() && dstat.isElement()){
+ QDomElement dinfo = dstat.toElement();
+ for (int i = 0; Statistics[i]; i+=2)
+ addAttributeInfo(dinfo, group2, Statistics[i] );
+ }
+
+
+ QDomNodeList userList = base.elementsByTagName( metauserdef );
+
+ KFileMetaInfoGroup groupuser = appendGroup(info, UserDefined);
+
+ for (uint i = 0; i < userList.length(); i++){
+ QDomNode node = userList.item(i);
+ if (node.isElement()){
+ appendItem(groupuser,
+ node.toElement().attribute(metaname,
+ QString("User %1").arg(i)),
+ node.toElement().text());
+ }
+ }
+ return true;
+}
+
+QString KOfficePlugin::stringFromNode(const QDomNode &node, const QString &name)
+{
+ QString value = node.namedItem(name).toElement().text();
+ return value.isEmpty() ? QString::null : value;
+}
+
+void KOfficePlugin::addAttributeInfo(const QDomElement & elem, KFileMetaInfoGroup & group, const QString &attributeName)
+{
+ if (!elem.hasAttribute(attributeName)){
+ return;
+ }
+ QString m_attribute = elem.attribute(attributeName, "0");
+ if (m_attribute == "0")
+ return;
+ appendItem(group, attributeName, m_attribute);
+}
+
+bool KOfficePlugin::writeTextNode(QDomDocument & doc,
+ QDomNode & parentNode,
+ const QString &nodeName,
+ const QString &value) const
+{
+ if (parentNode.toElement().isNull()){
+ kdDebug(7034) << "Parent node is Null or not an Element, cannot write node "
+ << nodeName << endl;
+ return false;
+ }
+
+ // If the node does not exist, we create it...
+ if (parentNode.namedItem(nodeName).isNull())
+ QDomNode ex = parentNode.appendChild(doc.createElement(nodeName));
+
+ // Now, we are sure we have a node
+ QDomElement nodeA = parentNode.namedItem(nodeName).toElement();
+
+ // Ooops... existing node were not of the good type...
+ if (nodeA.isNull()){
+ kdDebug(7034) << "Wrong type of node " << nodeName << ", should be Element"
+ << endl;
+ return false;
+ }
+
+ QDomText txtNode = doc.createTextNode(value);
+
+ // If the node has already Text Child, we replace it.
+ if (nodeA.firstChild().isNull())
+ nodeA.appendChild(txtNode);
+ else
+ nodeA.replaceChild( txtNode, nodeA.firstChild());
+ return true;
+}
+
+bool KOfficePlugin::writeInfo( const KFileMetaInfo& info) const
+{
+ bool no_errors = true;
+ QDomDocument doc = getMetaDocument(info.path());
+ QDomElement base = getBaseNode(doc).toElement();
+ if (base.isNull())
+ return false;
+ for (int i = 0; Information[i]; i+=2)
+ no_errors = no_errors &&
+ writeTextNode(doc, base, Information[i],
+ info[DocumentInfo][Information[i]].value().toString());
+ // If we need a meta:keywords container, we create it.
+ if (base.namedItem(metakeywords).isNull())
+ base.appendChild(doc.createElement(metakeywords));
+ QDomNode metaKeyNode = base.namedItem(metakeywords);
+
+ QDomNodeList childs = doc.elementsByTagName(metakeyword);
+ for (int i = childs.length(); i >= 0; --i){
+ metaKeyNode.removeChild( childs.item(i) );
+ }
+ QStringList keywordList = QStringList::split(",", info[DocumentInfo][metakeyword].value().toString().stripWhiteSpace(), false);
+ for ( QStringList::Iterator it = keywordList.begin(); it != keywordList.end(); ++it ) {
+ QDomElement elem = doc.createElement(metakeyword);
+ metaKeyNode.appendChild(elem);
+ elem.appendChild(doc.createTextNode((*it).stripWhiteSpace()));
+ }
+
+ // Now, we store the user-defined data
+ QDomNodeList theElements = base.elementsByTagName(metauserdef);
+ for (uint i = 0; i < theElements.length(); i++)
+ {
+ QDomElement el = theElements.item(i).toElement();
+ if (el.isNull()){
+ kdDebug(7034) << metauserdef << " is not an Element" << endl;
+ no_errors = false;
+ }
+
+ QString s = info[UserDefined][el.attribute(metaname)].value().toString();
+ if (s != el.text()){
+ QDomText txt = doc.createTextNode(s);
+ if (!el.firstChild().isNull())
+ el.replaceChild(txt, el.firstChild());
+ else
+ el.appendChild(txt);
+ }
+ }
+
+ if (!no_errors){
+ kdDebug(7034) << "Errors were found while building " << metafile
+ << " for file " << info.path() << endl;
+ // It is safer to avoid to manipulate meta.xml if errors, we abort.
+ return false;
+ }
+ writeMetaData(info.path(), doc);
+ return true;
+}
+
+/**
+ * This function recreate a zip in dest with all files from src
+ * except meta.xml
+ */
+bool copyZipToZip( const KZip * src, KZip * dest)
+{
+ KArchiveDirectory * src_dir;
+ KArchiveFile * input_file;
+ QPtrStack<KArchiveDirectory> src_dirStack ;
+ QStringList dirEntries;
+ QStringList curDirName;
+ QStringList::Iterator it;
+ KArchiveEntry* curEntry;
+ QString filename = QString::null;
+
+ src_dirStack.push ( src->directory() );
+
+ do {
+ src_dir = src_dirStack.pop();
+ curDirName.append(src_dir->name());
+ dirEntries = src_dir->entries();
+
+ /* We now iterate over all entries and create entries in dest */
+ for ( it = dirEntries.begin(); it != dirEntries.end(); ++it ) {
+ if ( *it == metafile )
+ continue;
+ curEntry = src_dir->entry( *it );
+
+ if (curEntry->isFile()) {
+ input_file = dynamic_cast<KArchiveFile*>( curEntry );
+ QByteArray b = input_file->data();
+ if (curDirName.isEmpty() || src_dir->name()=="/"){
+ filename = *it;
+ } else {
+ filename = curDirName.join("/") + "/" + *it;
+ }
+ dest->writeFile(filename , QString::null, QString::null, b.count(), b.data() );
+ } else
+ if (curEntry->isDirectory()) {
+ src_dirStack.push( dynamic_cast<KArchiveDirectory*>( curEntry ) );
+ }
+ else {
+ kdDebug(7034) << *it << " is a unknown type. Aborting." << endl;
+ return false;
+ }
+ }
+ curDirName.pop_back();
+ } while ( ! src_dirStack.isEmpty() );
+ return true;
+}
+
+bool KOfficePlugin::writeMetaData(const QString & path,
+ const QDomDocument &doc) const
+{
+ KTempFile tmp_file;
+ tmp_file.setAutoDelete(true);
+ KZip * m_zip = new KZip(tmp_file.name());
+ KZip * current= new KZip(path);
+ /* To correct problem with OOo 1.1, we have to recreate the file from scratch */
+ if (!m_zip->open(IO_WriteOnly) || !current->open(IO_ReadOnly) )
+ return false;
+ QCString text = doc.toCString();
+ m_zip->setCompression(KZip::DeflateCompression);
+ if (!copyZipToZip(current, m_zip))
+ return false;
+ m_zip->writeFile(metafile, QString::null, QString::null,text.length(),
+ text);
+ delete current;
+ delete m_zip;
+ // NULL as third parameter is not good, but I don't know the Window ID
+ // That is only to avoid the deprecated warning at compile time
+ if (!KIO::NetAccess::upload( tmp_file.name(), KURL(path), NULL)){
+ kdDebug(7034) << "Error while saving " << tmp_file.name() << " as " << path << endl;
+ return false;
+ }
+ return true;
+}
+
+
+QIODevice* KOfficePlugin::getData(KArchive &m_zip, int fileMode) const
+{
+
+ if ( !m_zip.open(fileMode) || !m_zip.directory())
+ return 0;
+
+ const KArchiveEntry* entry = m_zip.directory()->entry( metafile );
+ if (!entry || entry->isDirectory())
+ return 0;
+
+ const KZipFileEntry* f = static_cast<const KZipFileEntry *>(entry);
+ if (!f)
+ return 0;
+ return f->device();
+}
+
+QDomDocument KOfficePlugin::getMetaDocument(const QString &path) const
+{
+ QDomDocument doc;
+ KZip m_zip(path);
+ QIODevice * io = getData(m_zip, IO_ReadOnly);
+ if (!io || !io->isReadable())
+ return doc;
+ QString errorMsg;
+ int errorLine, errorColumn;
+ if ( !doc.setContent( io, &errorMsg, &errorLine, &errorColumn ) ){
+ kdDebug(7034) << "Error " << errorMsg.latin1()
+ << "while getting XML content at line "
+ << errorLine << ", column "<< errorColumn << endl;
+ delete io;
+ return doc;
+ }
+ delete io;
+ return doc;
+}
+
+QDomNode KOfficePlugin::getBaseNode(const QDomDocument &doc) const
+{
+ return
+ doc.namedItem("office:document-meta").namedItem("office:meta");
+}
+
+QValidator * KOfficePlugin::createValidator(const QString &, /* mimetype */
+ const QString & , /* group */
+ const QString &key,
+ QObject * parent,
+ const char * name ) const
+{
+ if (key == dclanguage)
+ return new QRegExpValidator(QRegExp("[a-zA-Z-]{1,5}"),
+ parent, name);
+ return 0;
+}
+
+#include "kfile_ooo.moc"
diff --git a/tools/kfile-plugins/ooo/kfile_ooo.desktop b/tools/kfile-plugins/ooo/kfile_ooo.desktop
new file mode 100644
index 00000000..1dcca275
--- /dev/null
+++ b/tools/kfile-plugins/ooo/kfile_ooo.desktop
@@ -0,0 +1,57 @@
+[Desktop Entry]
+Type=Service
+Name=OpenOffice.org Info
+Name[bg]=Информация за OpenOffice.org
+Name[br]=Titouriñ diwar-benn OpenOffice.org
+Name[ca]=Informació OpenOffice.org
+Name[cs]=OpenOffice.org info
+Name[cy]=Gwybodaeth OpenOffice.org
+Name[el]=Πληροφορίες OpenOffice.org
+Name[eo]=OpenOffice.org informo
+Name[es]=Información de OpenOffice.org
+Name[et]=OpenOffice.org-i info
+Name[eu]=OpenOffice.org-en informazioa
+Name[fa]=اطلاعات OpenOffice.org
+Name[fi]=OpenOffice.org-tiedot
+Name[fr]=Informations sur OpenOffice.org
+Name[fy]=OpenOffice.org ynfo
+Name[ga]=Eolas faoi OpenOffice.org
+Name[gl]=Información de OpenOffice.org
+Name[he]=מידע OpenOffice.org
+Name[hi]=स्टारआफिस.ऑर्ग जानकारी
+Name[hu]=OpenOffice.org-információ
+Name[is]=OpenOffice.org upplýsingar
+Name[it]=Informazioni OpenOffice.org
+Name[ja]=OpenOffice.org 情報
+Name[km]=ព័ត៌មាន​ OpenOffice.org
+Name[lt]=OpenOffice.org informacija
+Name[lv]=OpenOffice.org informācija
+Name[ms]=Maklumat OpenOffice.org
+Name[nb]=OpenOffice.org-info
+Name[nds]=OpenOffice.org-Info
+Name[ne]=ओपनअफिस डट अर्ग इन्फो
+Name[nl]=OpenOffice.org Informatie
+Name[nn]=OpenOffice.org-info
+Name[pa]=OpenOffice.org ਜਾਣਕਾਰੀ
+Name[pl]=Informacje o OpenOffice.org
+Name[pt]=Informação do OpenOffice.org
+Name[pt_BR]=Informações do OpenOffice.org
+Name[ru]=Информация OpenOffice.org
+Name[se]=OpenOffice.org-dieđut
+Name[sk]=Informácie o OpenOffice.org
+Name[sl]=Informacije o OpenOffice.org
+Name[sr]=Информације OpenOffice.org-а
+Name[sr@Latn]=Informacije OpenOffice.org-a
+Name[sv]=Information om OpenOffice.org
+Name[tg]=OpenOffice.org Ахборот
+Name[uk]=Інформація про OpenOffice.org
+Name[uz]=OpenOffice.org maʼlumot
+Name[uz@cyrillic]=OpenOffice.org маълумот
+Name[wa]=Informåcion OpenOffice.org
+Name[zh_CN]=OpenOffice.org 信息
+Name[zh_TW]=OpenOffice.org 資訊
+ServiceTypes=KFilePlugin
+X-KDE-Library=kfile_ooo
+MimeType=application/vnd.sun.xml.calc;application/vnd.sun.xml.calc.template;application/vnd.sun.xml.draw;application/vnd.sun.xml.draw.template;application/vnd.sun.xml.impress;application/vnd.sun.xml.impress.template;application/vnd.sun.xml.writer;application/vnd.sun.xml.writer.global;application/vnd.sun.xml.writer.math;application/vnd.sun.xml.writer.template;application/vnd.oasis.opendocument.chart;application/vnd.oasis.opendocument.formula;application/vnd.oasis.opendocument.graphics;application/vnd.oasis.opendocument.graphics-template;application/vnd.oasis.opendocument.image;application/vnd.oasis.opendocument.presentation;application/vnd.oasis.opendocument.presentation-template;application/vnd.oasis.opendocument.spreadsheet;application/vnd.oasis.opendocument.spreadsheet-template;application/vnd.oasis.opendocument.text;application/vnd.oasis.opendocument.text-template
+PreferredGroups=DocumentInfo
+PreferredItems=Author,Title,Abstract
diff --git a/tools/kfile-plugins/ooo/kfile_ooo.h b/tools/kfile-plugins/ooo/kfile_ooo.h
new file mode 100644
index 00000000..11bff4ac
--- /dev/null
+++ b/tools/kfile-plugins/ooo/kfile_ooo.h
@@ -0,0 +1,77 @@
+/* This file is part of the KDE project
+ * Copyright (C) 2003 Pierre Souchay <pierre@souchay.net>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation version 2.
+ *
+ * This program 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef __KFILE_OOO_H__
+#define __KFILE_OOO_H__
+
+#include <kfilemetainfo.h>
+#include <qiodevice.h>
+#include <qdom.h>
+#include <karchive.h>
+class QStringList;
+class QDomNode;
+class QDomElement;
+
+class KOfficePlugin: public KFilePlugin
+{
+ Q_OBJECT
+
+public:
+ /**
+ * Constructor */
+ KOfficePlugin( QObject *parent, const char *name, const QStringList& args );
+ /**
+ * Read informations from files and store info in KFileMetaInfo.
+ * We currently only parse meta.xml in OOo files.
+ * @param info informations to modify about current file
+ * @param what What kind of parsing is needed ?
+ */
+ virtual bool readInfo( KFileMetaInfo& info, uint what);
+ /**
+ * Write modified informations in meta.xml
+ * @param info Informations modified
+ */
+ virtual bool writeInfo( const KFileMetaInfo& info) const;
+ /**
+ * We need a validator, for the langage
+ */
+ virtual QValidator* createValidator( const QString& mimetype,
+ const QString &group,
+ const QString &key,
+ QObject* parent,
+ const char* name) const;
+private:
+ bool writeTextNode(QDomDocument & doc,
+ QDomNode & parentNode,
+ const QString &nodeName,
+ const QString &value) const;
+ KFileMimeTypeInfo::GroupInfo* userdefined;
+ void addAttributeInfo(const QDomElement & elem, KFileMetaInfoGroup & group,
+ const QString &attributeName);
+ QIODevice* getData(KArchive &m_zip, int fileMode) const;
+ bool writeMetaData(const QString & path, const QDomDocument &doc) const;
+ QDomDocument getMetaDocument(const QString &path) const;
+ QDomNode getBaseNode(const QDomDocument &doc) const;
+ void makeMimeTypeInfo(const QString& mimeType);
+ QString stringFromNode(const QDomNode &node, const QString &name);
+ void getEditingTime(KFileMetaInfoGroup group1, const char *, QString & txt);
+ void getDateTime(KFileMetaInfoGroup group1, const char *, QString & txt);
+};
+
+#endif