KRename – powerful batch renamer
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

translitplugin.cpp 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. //
  2. // C++ Implementation: translitplugin
  3. //
  4. // Description:
  5. //
  6. //
  7. // Author: Dominik Seichter <domseichter@web.de>, (C) 2005
  8. //
  9. // Copyright: See COPYING file that comes with this distribution
  10. //
  11. //
  12. #include "translitplugin.h"
  13. const TQString TranslitPlugin::m_strUtf8[] = {"а","б","в","г","д","е","ё","ж","з","и",
  14. "й","к","л","м","н","о","п","р","с","т","у","ф","х","ц","ч","ш","щ","ъ","ы","ь",
  15. "э","ю","я",
  16. "А","Б","В","Г","Д","Е","Ё","Ж","З","И","Й","К","Л","М","Н","О","П",
  17. "Р","С","Т","У","Ф","Х","Ц","Ч","Ш","Щ","Ъ","Ы","Ь","Э","Ю","Я",
  18. "á","ä","č","ď","é","ě","í","ľ","ĺ","ň","ó","ô","ř","ŕ","š","ť","ú","ů","ý","ž",
  19. "Á","Ä","Č","Ď","É","Ě","Í","Ľ","Ĺ","Ň","Ó","Ô","Ř","Ŕ","Š","Ť","Ú","Ů","Ý","Ž",TQString()};
  20. const TQString TranslitPlugin::m_strEngl[]= {"a","b","v","g","d","e","yo","zh","z","i",
  21. "j","k","l","m","n","o","p","r","s","t","u","f","h","c","ch","sh","sh","","y","",
  22. "e","yu","ya",
  23. "A","B","V","G","D","E","Yo","Zh","Z","I","J","K","L","M","N","O","P",
  24. "R","S","T","U","F","H","C","Ch","Sh","Sh","","Y","","E","Yu","Ya",
  25. "a","a","c","d","e","e","i","l","l","n","o","o","r","r","s","t","u","u","y","z",
  26. "A","A","C","D","E","E","I","L","L","N","O","O","R","R","S","T","U","U","Y","Z",TQString()};
  27. const TQString TranslitPlugin::getName() const
  28. {
  29. return i18n("Transliteration Plugin");
  30. }
  31. const TQString TranslitPlugin::getAccelName() const
  32. {
  33. return i18n("&Transliteration Plugin");
  34. }
  35. const TQPixmap TranslitPlugin::getIcon() const
  36. {
  37. return kapp->iconLoader()->loadIcon( "fonts", TDEIcon::Small );
  38. }
  39. const int TranslitPlugin::type() const
  40. {
  41. return TYPE_FINAL_FILENAME;
  42. }
  43. void TranslitPlugin::drawInterface( TQWidget* w, TQVBoxLayout* l )
  44. {
  45. TQLabel* label = new TQLabel(
  46. i18n("<qt>This plugin transliterates names written with non-english characters.</qt>"), w );
  47. l->addWidget( label );
  48. label = new TQLabel( "<qt><b>WARNING! THIS PLUGIN IS EXPERIMENTAL AND MIGHT CAUSE LOSS OF DATA!</b></qt>", w );
  49. l->addWidget( label );
  50. }
  51. void TranslitPlugin::finished()
  52. {
  53. }
  54. void TranslitPlugin::fillStructure()
  55. {
  56. }
  57. bool TranslitPlugin::checkError()
  58. {
  59. return true;
  60. }
  61. TQString TranslitPlugin::processFile( BatchRenamer*, int, TQString token, int )
  62. {
  63. TQString output = translit( token );
  64. return output; // no error
  65. }
  66. TQString TranslitPlugin::translit(const TQString & unicoded)
  67. {
  68. int i;
  69. TQString transed = "";
  70. for (i=0; i<(int)unicoded.length(); i++) {
  71. TQString charIn = unicoded.mid(i, 1);
  72. if (!(m_mapFromUTF8[charIn.utf8()].isNull())) {
  73. TQString charTrans = m_mapFromUTF8[charIn.utf8()];
  74. transed.append(charTrans);
  75. } else {
  76. transed.append(charIn);
  77. }
  78. }
  79. return transed;
  80. }
  81. TranslitPlugin::TranslitPlugin() {
  82. // Initialize transliteration map
  83. int i;
  84. for (i=0; m_strUtf8[i]!=TQString(); i++) {
  85. TQString src = m_strUtf8[i];
  86. TQString dst = m_strEngl[i];
  87. m_mapFromUTF8[src] = dst;
  88. }
  89. }
  90. #include "translitplugin.moc"