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.

102 lines
2.4KB

  1. /* This file is part of the KDE project
  2. Copyright (C) 2002, Dirk Schönberger <dirk.schoenberger@sz-online.de>
  3. This library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Library General Public
  5. License as published by the Free Software Foundation; either
  6. version 2 of the License, or (at your option) any later version.
  7. This library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Library General Public License for more details.
  11. You should have received a copy of the GNU Library General Public License
  12. along with this library; see the file COPYING.LIB. If not, write to
  13. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  14. * Boston, MA 02110-1301, USA.
  15. */
  16. #include <tqdom.h>
  17. #include <tqcstring.h>
  18. #include <tqfile.h>
  19. #include <tqstring.h>
  20. #include <kgenericfactory.h>
  21. #include <KoFilterChain.h>
  22. #include <KoStore.h>
  23. #include <kdebug.h>
  24. #include "aiimport.h"
  25. #include "karbonaiparserbase.h"
  26. class AiImportFactory : KGenericFactory<AiImport, KoFilter>
  27. {
  28. public:
  29. AiImportFactory( void )
  30. : KGenericFactory<AiImport, KoFilter>( "karbonaiimport" )
  31. {}
  32. protected:
  33. virtual void setupTranslations( void )
  34. {
  35. TDEGlobal::locale()->insertCatalogue( "kofficefilters" );
  36. }
  37. };
  38. K_EXPORT_COMPONENT_FACTORY( libkarbonaiimport, AiImportFactory() )
  39. AiImport::AiImport( KoFilter*, const char*, const TQStringList& )
  40. : KoFilter()
  41. {
  42. }
  43. AiImport::~AiImport()
  44. {
  45. }
  46. KoFilter::ConversionStatus
  47. AiImport::convert( const TQCString& from, const TQCString& to )
  48. {
  49. if ( from != "application/illustrator" || to != "application/x-karbon" )
  50. {
  51. return KoFilter::NotImplemented;
  52. }
  53. TQFile fileIn( m_chain->inputFile() );
  54. if( !fileIn.open( IO_ReadOnly ) )
  55. {
  56. fileIn.close();
  57. return KoFilter::FileNotFound;
  58. }
  59. TQDomDocument doc ("DOC");
  60. KarbonAIParserBase parser;
  61. if (!parser.parse (*TQT_TQIODEVICE(&fileIn), doc))
  62. {
  63. fileIn.close();
  64. return KoFilter::CreationError;
  65. }
  66. TQString result = doc.toString();
  67. kdDebug() << result << endl;
  68. KoStoreDevice* storeOut = m_chain->storageFile( "root", KoStore::Write );
  69. if( !storeOut )
  70. {
  71. fileIn.close();
  72. return KoFilter::StorageCreationError;
  73. }
  74. TQCString cStr = result.latin1();
  75. storeOut->writeBlock( cStr, cStr.size() - 1 );
  76. return KoFilter::OK;
  77. }
  78. #include "aiimport.moc"