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.

147 lines
4.5KB

  1. /***************************************************************************
  2. encodingplugin.cpp - description
  3. -------------------
  4. begin : Tue Jul 06 2004
  5. copyright : (C) 2004 by Dominik Seichter
  6. email : domseichter@web.de
  7. ***************************************************************************/
  8. /***************************************************************************
  9. * *
  10. * This program is free software; you can redistribute it and/or modify *
  11. * it under the terms of the GNU General Public License as published by *
  12. * the Free Software Foundation; either version 2 of the License, or *
  13. * (at your option) any later version. *
  14. * *
  15. ***************************************************************************/
  16. #include "encodingplugin.h"
  17. // QT includes
  18. #include <tqcheckbox.h>
  19. #include <tqlabel.h>
  20. #include <tqlayout.h>
  21. #include <tqtextcodec.h>
  22. #include <tqvgroupbox.h>
  23. // KDE includes
  24. #include <tdeapplication.h>
  25. #include <kcombobox.h>
  26. #include <kiconloader.h>
  27. #include <tdelocale.h>
  28. #include <tdemessagebox.h>
  29. const TQString EncodingPlugin::getName() const
  30. {
  31. return i18n("Encoding Conversion Plugin");
  32. }
  33. const TQString EncodingPlugin::getAccelName() const
  34. {
  35. return i18n("&Encoding Conversion Plugin");
  36. }
  37. const int EncodingPlugin::type() const
  38. {
  39. return TYPE_FINAL_FILENAME;
  40. }
  41. void EncodingPlugin::drawInterface( TQWidget* w, TQVBoxLayout* l )
  42. {
  43. // build a list of all available TextCodecs
  44. TQStringList codecs;
  45. TQTextCodec *codec;
  46. for( int i=0; (codec = TQTextCodec::codecForIndex(i));i++)
  47. codecs.append( codec->name() );
  48. m_widget = w;
  49. codec = TQTextCodec::codecForLocale();
  50. m_locale_codec = codec->name();
  51. TQLabel* label = new TQLabel(
  52. i18n("<qt>This plugin is able to convert filenames between different "
  53. "encodings. For example you can convert filenames from KOI8-R "
  54. "to UTF-8 encoding.</qt>"), w );
  55. l->addWidget( label );
  56. TQVGroupBox* groupInput = new TQVGroupBox( i18n("Encoding of Input Files:"), w );
  57. checkInput = new TQCheckBox( i18n("&Use local encoding: %1").arg( m_locale_codec), groupInput );
  58. comboInput = new KComboBox( false, groupInput );
  59. comboInput->insertStringList( codecs );
  60. TQVGroupBox* groupOutput = new TQVGroupBox( i18n("Encoding of Output Files:"), w );
  61. checkOutput = new TQCheckBox( i18n("&Use local encoding: %1").arg( m_locale_codec), groupOutput );
  62. checkOutput->setChecked( true );
  63. comboOutput = new KComboBox( false, groupOutput );
  64. comboOutput->insertStringList( codecs );
  65. l->addWidget( groupInput );
  66. l->addWidget( groupOutput );
  67. connect( checkInput, TQT_SIGNAL( clicked() ), this, TQT_SLOT( enableControls() ) );
  68. connect( checkOutput, TQT_SIGNAL( clicked() ), this, TQT_SLOT( enableControls() ) );
  69. connect( comboOutput, TQT_SIGNAL( activated(int) ),this, TQT_SLOT( updatePreview() ) );
  70. connect( comboInput, TQT_SIGNAL( activated(int) ),this, TQT_SLOT( updatePreview() ) );
  71. setLocale( comboInput );
  72. setLocale( comboOutput );
  73. enableControls();
  74. }
  75. void EncodingPlugin::fillStructure()
  76. {
  77. m_input_codec = (checkInput->isChecked() ? m_locale_codec : comboInput->currentText() );
  78. m_output_codec = (checkOutput->isChecked() ? m_locale_codec : comboOutput->currentText() );
  79. }
  80. bool EncodingPlugin::checkError()
  81. {
  82. return true;
  83. }
  84. TQString EncodingPlugin::processFile( BatchRenamer*, int, TQString token, int )
  85. {
  86. TQString input = token;
  87. TQString unicode = TQString();
  88. TQTextCodec* toUnicode = TQTextCodec::codecForName(m_input_codec.ascii()); // get the codec for KOI8-R
  89. TQTextCodec* fromUnicode = TQTextCodec::codecForName(m_output_codec.ascii());
  90. unicode = toUnicode->toUnicode( input.ascii() );
  91. return fromUnicode->fromUnicode( unicode.ascii() );
  92. }
  93. void EncodingPlugin::finished()
  94. {
  95. }
  96. const TQPixmap EncodingPlugin::getIcon() const
  97. {
  98. return kapp->iconLoader()->loadIcon( "fonts", TDEIcon::Small );
  99. }
  100. void EncodingPlugin::enableControls()
  101. {
  102. comboInput->setEnabled( !checkInput->isChecked() );
  103. comboOutput->setEnabled( !checkOutput->isChecked() );
  104. //updatePreview();
  105. }
  106. void EncodingPlugin::setLocale( KComboBox* combo )
  107. {
  108. for(int i=0;i<combo->count();i++)
  109. if( combo->text(i) == m_locale_codec )
  110. {
  111. combo->setCurrentItem( i );
  112. break;
  113. }
  114. }
  115. #include "encodingplugin.moc"