KRename – powerful batch renamer
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.

107 lines
3.1KB

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