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.

mydirplugin.cpp 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /***************************************************************************
  2. mydirplugin.cpp - description
  3. -------------------
  4. begin : Tue Jan 29 2002
  5. copyright : (C) 2002 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. // Own includes
  17. #include "mydirplugin.h"
  18. // KDE includes
  19. #include <tdeapplication.h>
  20. #include <kiconloader.h>
  21. #include <tdefiledialog.h>
  22. #include <tdelocale.h>
  23. // QT includes
  24. #include <tqlabel.h>
  25. #include <tqlayout.h>
  26. #include <tqlineedit.h>
  27. #include <tqpushbutton.h>
  28. #include <tqgroupbox.h>
  29. #include <tqspinbox.h>
  30. const TQString MyDirPlugin::getName() const
  31. {
  32. return i18n("Dir Plugin");
  33. }
  34. const TQString MyDirPlugin::getAccelName() const
  35. {
  36. return i18n("&Dir Plugin");
  37. }
  38. const int MyDirPlugin::type() const
  39. {
  40. return TYPE_FINAL_FILE;
  41. }
  42. bool MyDirPlugin::checkError()
  43. {
  44. return true;
  45. }
  46. const TQPixmap MyDirPlugin::getIcon() const
  47. {
  48. return kapp->iconLoader()->loadIcon( "folder", TDEIcon::Small );
  49. }
  50. void MyDirPlugin::drawInterface( TQWidget* w, TQVBoxLayout* l )
  51. {
  52. TQSpacerItem* spacer = new TQSpacerItem( 20, 20, TQSizePolicy::Expanding, TQSizePolicy::Minimum );
  53. TQSpacerItem* spacer2 = new TQSpacerItem( 20, 20, TQSizePolicy::Minimum, TQSizePolicy::Expanding );
  54. TQVBoxLayout* LayoutA = new TQVBoxLayout( 0, 6, 6 );
  55. TQVBoxLayout* LayoutB = new TQVBoxLayout( 0, 6, 6 );
  56. m_widget = w;
  57. TQLabel* la = new TQLabel( w );
  58. la->setText( i18n("<qt>This plugin sorts files after renaming in subdirectories.</qt>") );
  59. l->addWidget( la );
  60. groupNumber = new TQGroupBox( w );
  61. groupNumber->setTitle( i18n( "&Options" ) );
  62. groupNumber->setColumnLayout(0, Qt::Vertical );
  63. groupNumber->layout()->setSpacing( 6 );
  64. groupNumber->layout()->setMargin( 11 );
  65. groupNumberLayout = new TQHBoxLayout( groupNumber->layout() );
  66. groupNumberLayout->setAlignment( TQt::AlignTop );
  67. TQLabel* la2 = new TQLabel( groupNumber );
  68. la2->setText( i18n( "Files per directory:" ) );
  69. spinFiles = new TQSpinBox( groupNumber );
  70. spinFiles->setRange( 1, 60000 );
  71. spinFiles->setValue( 10 );
  72. TQLabel* la3 = new TQLabel( groupNumber );
  73. la3->setText( i18n( "Start index:" ) );
  74. spinStart = new TQSpinBox( groupNumber );
  75. spinFiles->setRange( 0, 60000 );
  76. LayoutA->addWidget( la2 );
  77. LayoutA->addWidget( la3 );
  78. LayoutB->addWidget( spinFiles );
  79. LayoutB->addWidget( spinStart );
  80. groupNumberLayout->addLayout( LayoutA );
  81. groupNumberLayout->addLayout( LayoutB );
  82. groupNumberLayout->addItem( spacer );
  83. groupOutput = new TQGroupBox( w );
  84. groupOutput->setTitle( i18n( "Output &Directory" ) );
  85. groupOutput->setColumnLayout(0, Qt::Vertical );
  86. groupOutput->layout()->setSpacing( 6 );
  87. groupOutput->layout()->setMargin( 11 );
  88. groupOutputLayout = new TQHBoxLayout( groupOutput->layout() );
  89. groupOutputLayout->setAlignment( TQt::AlignTop );
  90. outputdir = new TQLineEdit( groupOutput );
  91. buttonDir = new TQPushButton( groupOutput );
  92. buttonDir->setText( "..." );
  93. groupOutputLayout->addWidget( outputdir );
  94. groupOutputLayout->addWidget( buttonDir );
  95. l->addWidget( groupNumber );
  96. l->addWidget( groupOutput );
  97. l->addItem( spacer2 );
  98. connect( buttonDir, TQT_SIGNAL(clicked()), this, TQT_SLOT(chooseDir()));
  99. }
  100. void MyDirPlugin::fillStructure()
  101. {
  102. fpd = spinFiles->value();
  103. fpd--;
  104. dir = outputdir->text();
  105. filecounter = 0;
  106. dircounter = spinStart->value();
  107. curdir = dir + TQString("/%1/").arg( dircounter );
  108. d = new TQDir( dir );
  109. d->mkdir( curdir );
  110. }
  111. TQString MyDirPlugin::processFile( BatchRenamer*, int, TQString token, int )
  112. {
  113. TQString newname;
  114. // token = filename
  115. if( filecounter == fpd ) {
  116. filecounter = 0;
  117. dircounter++;
  118. curdir = dir + TQString("/%1/").arg( dircounter );
  119. d->mkdir( curdir );
  120. }
  121. TQFileInfo f( token );
  122. newname = curdir + f.fileName();
  123. d->rename( token, newname );
  124. filecounter++;
  125. return TQString();
  126. }
  127. void MyDirPlugin::finished()
  128. {
  129. filecounter = dircounter = 0;
  130. }
  131. void MyDirPlugin::chooseDir()
  132. {
  133. TQString s (KFileDialog::getExistingDirectory ( TQString() ));
  134. if(!s.isEmpty())
  135. outputdir->setText( s );
  136. }
  137. #include "mydirplugin.moc"