indexfile.cc 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: indexfile.cc,v 1.2.2.1 2003/12/24 23:09:17 mdz Exp $
  4. /* ######################################################################
  5. Index File - Abstraction for an index of archive/souce file.
  6. ##################################################################### */
  7. /*}}}*/
  8. // Include Files /*{{{*/
  9. #ifdef __GNUG__
  10. #pragma implementation "apt-pkg/indexfile.h"
  11. #endif
  12. #include <apt-pkg/configuration.h>
  13. #include <apt-pkg/indexfile.h>
  14. #include <apt-pkg/error.h>
  15. #include <clocale>
  16. /*}}}*/
  17. // Global list of Item supported
  18. static pkgIndexFile::Type *ItmList[10];
  19. pkgIndexFile::Type **pkgIndexFile::Type::GlobalList = ItmList;
  20. unsigned long pkgIndexFile::Type::GlobalListLen = 0;
  21. // Type::Type - Constructor /*{{{*/
  22. // ---------------------------------------------------------------------
  23. /* */
  24. pkgIndexFile::Type::Type()
  25. {
  26. ItmList[GlobalListLen] = this;
  27. GlobalListLen++;
  28. }
  29. /*}}}*/
  30. // Type::GetType - Locate the type by name /*{{{*/
  31. // ---------------------------------------------------------------------
  32. /* */
  33. pkgIndexFile::Type *pkgIndexFile::Type::GetType(const char *Type)
  34. {
  35. for (unsigned I = 0; I != GlobalListLen; I++)
  36. if (strcmp(GlobalList[I]->Label,Type) == 0)
  37. return GlobalList[I];
  38. return 0;
  39. }
  40. /*}}}*/
  41. // IndexFile::ArchiveInfo - Stub /*{{{*/
  42. // ---------------------------------------------------------------------
  43. /* */
  44. string pkgIndexFile::ArchiveInfo(pkgCache::VerIterator Ver) const
  45. {
  46. return string();
  47. }
  48. /*}}}*/
  49. // IndexFile::FindInCache - Stub /*{{{*/
  50. // ---------------------------------------------------------------------
  51. /* */
  52. pkgCache::PkgFileIterator pkgIndexFile::FindInCache(pkgCache &Cache) const
  53. {
  54. return pkgCache::PkgFileIterator(Cache);
  55. }
  56. /*}}}*/
  57. // IndexFile::SourceIndex - Stub /*{{{*/
  58. // ---------------------------------------------------------------------
  59. /* */
  60. string pkgIndexFile::SourceInfo(pkgSrcRecords::Parser const &Record,
  61. pkgSrcRecords::File const &File) const
  62. {
  63. return string();
  64. }
  65. /*}}}*/
  66. // IndexFile::TranslationsAvailable - Check if will use Translation /*{{{*/
  67. // ---------------------------------------------------------------------
  68. /* */
  69. bool pkgIndexFile::TranslationsAvailable()
  70. {
  71. const string Translation = _config->Find("APT::Acquire::Translation");
  72. if (Translation.compare("none") != 0)
  73. return CheckLanguageCode(LanguageCode().c_str());
  74. else
  75. return false;
  76. }
  77. /*}}}*/
  78. // IndexFile::CheckLanguageCode - Check the Language Code /*{{{*/
  79. // ---------------------------------------------------------------------
  80. /* */
  81. /* common cases: de_DE, de_DE@euro, de_DE.UTF-8, de_DE.UTF-8@euro,
  82. de_DE.ISO8859-1, tig_ER
  83. more in /etc/gdm/locale.conf
  84. */
  85. bool pkgIndexFile::CheckLanguageCode(const char *Lang)
  86. {
  87. if (strlen(Lang) == 2 || (strlen(Lang) == 5 && Lang[2] == '_'))
  88. return true;
  89. if (strcmp(Lang,"C") != 0)
  90. _error->Warning("Wrong language code %s", Lang);
  91. return false;
  92. }
  93. /*}}}*/
  94. // IndexFile::LanguageCode - Return the Language Code /*{{{*/
  95. // ---------------------------------------------------------------------
  96. /* return the language code */
  97. string pkgIndexFile::LanguageCode()
  98. {
  99. const string Translation = _config->Find("APT::Acquire::Translation");
  100. if (Translation.compare("environment") == 0)
  101. {
  102. string lang = std::setlocale(LC_MESSAGES,NULL);
  103. // FIXME: this needs to be added
  104. // we have a mapping of the language codes that contains all the language
  105. // codes that need the country code as well
  106. // (like pt_BR, pt_PT, sv_SE, zh_*, en_*)
  107. if(lang.size() > 2)
  108. return lang.substr(0,2);
  109. else
  110. return lang;
  111. }
  112. else
  113. return Translation;
  114. }
  115. /*}}}*/