diff options
Diffstat (limited to 'tools/kfile-plugins/abiword')
-rw-r--r-- | tools/kfile-plugins/abiword/Makefile.am | 22 | ||||
-rw-r--r-- | tools/kfile-plugins/abiword/kfile_abiword.cpp | 145 | ||||
-rw-r--r-- | tools/kfile-plugins/abiword/kfile_abiword.desktop | 49 | ||||
-rw-r--r-- | tools/kfile-plugins/abiword/kfile_abiword.h | 42 |
4 files changed, 258 insertions, 0 deletions
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 <[email protected]> + * + * 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 [email protected] + * + * 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 |