KOffice – TDE office suite
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

146 lines
4.5KB

  1. /* This file is part of the KDE project
  2. * Copyright (C) 2005 Laurent Montel <montel@kde.org>
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public
  6. * License as published by the Free Software Foundation version 2.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. * General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program; see the file COPYING. If not, write to
  15. * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  16. * Boston, MA 02110-1301, USA.
  17. *
  18. */
  19. #include <config.h>
  20. #include "tdefile_abiword.h"
  21. #include <tdelocale.h>
  22. #include <kgenericfactory.h>
  23. #include <kfilterdev.h>
  24. #include <tqdom.h>
  25. #include <tqfile.h>
  26. #include <tqdatetime.h>
  27. #include <kdebug.h>
  28. typedef KGenericFactory<AbiwordPlugin> AbiwordFactory;
  29. K_EXPORT_COMPONENT_FACTORY(tdefile_abiword, AbiwordFactory( "tdefile_abiword" ))
  30. AbiwordPlugin::AbiwordPlugin(TQObject *parent, const char *name,
  31. const TQStringList &args)
  32. : KFilePlugin(parent, name, args)
  33. {
  34. init();
  35. }
  36. void AbiwordPlugin::init()
  37. {
  38. KFileMimeTypeInfo* info = addMimeTypeInfo( "application/x-abiword" );
  39. KFileMimeTypeInfo::GroupInfo* group = 0L;
  40. group = addGroupInfo(info, "DocumentInfo", i18n("Document Information"));
  41. KFileMimeTypeInfo::ItemInfo* item;
  42. item = addItemInfo(group, "Author", i18n("Author"), TQVariant::String);
  43. setHint(item, KFileMimeTypeInfo::Author);
  44. item = addItemInfo(group, "Title", i18n("Title"), TQVariant::String);
  45. setHint(item, KFileMimeTypeInfo::Name);
  46. item = addItemInfo(group, "Abstract", i18n("Abstract"), TQVariant::String);
  47. setHint(item, KFileMimeTypeInfo::Description);
  48. }
  49. bool AbiwordPlugin::readInfo( KFileMetaInfo& info, uint what)
  50. {
  51. if ( info.path().isEmpty() ) // remote file
  52. return false;
  53. //Find the last extension
  54. TQString strExt;
  55. const int result=info.path().findRev('.');
  56. if (result>=0)
  57. {
  58. strExt=info.path().mid(result);
  59. }
  60. TQString strMime; // Mime type of the compressor (default: unknown)
  61. if ((strExt==".gz")||(strExt==".GZ") //in case of .abw.gz (logical extension)
  62. ||(strExt==".zabw")||(strExt==".ZABW")) //in case of .zabw (extension used prioritary with AbiWord)
  63. {
  64. // Compressed with gzip
  65. strMime="application/x-gzip";
  66. kdDebug() << "Compression: gzip" << endl;
  67. }
  68. else if ((strExt==".bz2")||(strExt==".BZ2") //in case of .abw.bz2 (logical extension)
  69. ||(strExt==".bzabw")||(strExt==".BZABW")) //in case of .bzabw (extension used prioritary with AbiWord)
  70. {
  71. // Compressed with bzip2
  72. strMime="application/x-bzip2";
  73. kdDebug() << "Compression: bzip2" << endl;
  74. }
  75. KFileMetaInfoGroup group = appendGroup(info, "DocumentInfo");
  76. TQIODevice* in = KFilterDev::deviceForFile(info.path(),strMime);
  77. if ( !in )
  78. {
  79. kdError() << "Cannot create device for uncompressing! Aborting!" << endl;
  80. return false;
  81. }
  82. if (!in->open(IO_ReadOnly))
  83. {
  84. kdError() << "Cannot open file for uncompressing! Aborting!" << endl;
  85. delete in;
  86. return false;
  87. }
  88. TQDomDocument doc;
  89. doc.setContent( in );
  90. in->close();
  91. TQDomElement docElem = doc.documentElement();
  92. TQDomNode summary = docElem.namedItem("metadata");
  93. TQDomNode m_item = summary.namedItem("m");
  94. TQString author;
  95. TQString title;
  96. TQString abstract;
  97. while( !m_item.isNull() )
  98. {
  99. kdDebug()<<" m_item.toElement().text: "<<m_item.toElement().text()<<endl;
  100. TQString key = m_item.toElement().attribute( "key" );
  101. if ( key.isEmpty() )
  102. continue;
  103. else if ( key=="dc.creator" )
  104. author=m_item.toElement().text();
  105. else if ( key=="dc.description" )
  106. abstract=m_item.toElement().text();
  107. else if ( key=="dc.title" )
  108. title=m_item.toElement().text();
  109. else
  110. kdDebug()<<" Other key :"<<key<<endl;
  111. m_item = m_item.nextSibling();
  112. }
  113. appendItem(group, "Author", stringItem( author ));
  114. appendItem(group, "Title", stringItem( title ));
  115. appendItem(group, "Abstract", stringItem( abstract ));
  116. delete in;
  117. return true;
  118. }
  119. TQString AbiwordPlugin::stringItem( const TQString &name )
  120. {
  121. return name.isEmpty() ? i18n("*Unknown*") : name;
  122. }
  123. #include "tdefile_abiword.moc"