TDE core libraries
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.

kbuildimageiofactory.cpp 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /* This file is part of the KDE libraries
  2. * Copyright (C) 2000 Waldo Bastian <bastian@kde.org>
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Library General Public
  6. * License version 2 as published by the Free Software Foundation.
  7. *
  8. * This library 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. * Library General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU Library General Public License
  14. * along with this library; see the file COPYING.LIB. If not, write to
  15. * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  16. * Boston, MA 02110-1301, USA.
  17. **/
  18. #include "tdesycoca.h"
  19. #include "tdesycocadict.h"
  20. #include "kresourcelist.h"
  21. #include <tdeglobal.h>
  22. #include <kstandarddirs.h>
  23. #include <kdebug.h>
  24. #include <tdelocale.h>
  25. #include <assert.h>
  26. #include <kimageiofactory.h>
  27. #include <kbuildimageiofactory.h>
  28. KBuildImageIOFactory::KBuildImageIOFactory() :
  29. KImageIOFactory()
  30. {
  31. m_resourceList = new KSycocaResourceList();
  32. m_resourceList->add( "services", "*.kimgio" );
  33. }
  34. // return all service types for this factory
  35. // i.e. first arguments to m_resourceList->add() above
  36. TQStringList KBuildImageIOFactory::resourceTypes()
  37. {
  38. return TQStringList() << "services";
  39. }
  40. KBuildImageIOFactory::~KBuildImageIOFactory()
  41. {
  42. delete m_resourceList;
  43. }
  44. KSycocaEntry *
  45. KBuildImageIOFactory::createEntry( const TQString& file, const char *resource )
  46. {
  47. TQString fullPath = locate( resource, file);
  48. KImageIOFormat *format = new KImageIOFormat(fullPath);
  49. return format;
  50. }
  51. void
  52. KBuildImageIOFactory::addEntry(KSycocaEntry *newEntry, const char *resource)
  53. {
  54. KSycocaFactory::addEntry(newEntry, resource);
  55. KImageIOFormat *format = (KImageIOFormat *) newEntry;
  56. rPath += format->rPaths;
  57. // Since Qt doesn't allow us to unregister image formats
  58. // we have to make sure not to add them a second time.
  59. // This typically happens when the sycoca database is updated
  60. // incremenatally
  61. for( KImageIOFormatList::ConstIterator it = formatList->begin();
  62. it != formatList->end();
  63. ++it )
  64. {
  65. KImageIOFormat *_format = (*it);
  66. if (format->mType == _format->mType)
  67. {
  68. // Already in list
  69. format = 0;
  70. break;
  71. }
  72. }
  73. if (format)
  74. formatList->append( format );
  75. }
  76. void
  77. KBuildImageIOFactory::saveHeader(TQDataStream &str)
  78. {
  79. KSycocaFactory::saveHeader(str);
  80. str << mReadPattern << mWritePattern << rPath;
  81. }
  82. void
  83. KBuildImageIOFactory::save(TQDataStream &str)
  84. {
  85. rPath.sort();
  86. // Remove duplicates from rPath:
  87. TQString last;
  88. for(TQStringList::Iterator it = rPath.begin();
  89. it != rPath.end(); )
  90. {
  91. TQStringList::Iterator it2 = it++;
  92. if (*it2 == last)
  93. {
  94. // remove duplicate
  95. rPath.remove(it2);
  96. }
  97. else
  98. {
  99. last = *it2;
  100. }
  101. }
  102. mReadPattern = createPattern( KImageIO::Reading );
  103. mWritePattern = createPattern( KImageIO::Writing );
  104. KSycocaFactory::save(str);
  105. }