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.

undodialog.cpp 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /***************************************************************************
  2. undodialog.cpp - description
  3. -------------------
  4. begin : Mon Mai 27 20:08:19 CEST 2002
  5. copyright : (C) 2001 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 "undodialog.h"
  17. // TQt includes
  18. #include <tqlabel.h>
  19. #include <tqlayout.h>
  20. // KDE includes
  21. #include <tdefiledialog.h>
  22. #include <tdelocale.h>
  23. #include <tdemessagebox.h>
  24. #include <kprocess.h>
  25. #include <ktextbrowser.h>
  26. #include <kurlrequester.h>
  27. UndoDialog::UndoDialog( TQWidget* parent )
  28. : KDialogBase( KDialogBase::Plain, i18n("Undo Renaming"),
  29. KDialogBase::User1 | KDialogBase::Close, KDialogBase::User1, parent, 0, false, true )
  30. {
  31. UndoDialogLayout = new TQVBoxLayout( plainPage(), 11, 6, "UndoDialogLayout");
  32. TextLabel1 = new TQLabel( plainPage(), "TextLabel1" );
  33. TextLabel1->setText( i18n( "Undo script:" ) );
  34. UndoDialogLayout->addWidget( TextLabel1 );
  35. scriptname = new KURLRequester( plainPage(), "KURLRequester1" );
  36. scriptname->setMode( KFile::File | KFile::LocalOnly );
  37. scriptname->fileDialog()->setOperationMode( KFileDialog::Opening );
  38. scriptname->setFilter( i18n("*.krename|KRename undo scripts (*.krename)\n"
  39. "*|All Files (*)") );
  40. UndoDialogLayout->addWidget( scriptname );
  41. TextLabel2 = new TQLabel( plainPage(), "TextLabel2" );
  42. TextLabel2->setText( i18n( "<qt>Undo Scripts are normal shell scripts which can also be executed manually from the command line.</qt>" ) );
  43. UndoDialogLayout->addWidget( TextLabel2 );
  44. browser = new KTextBrowser( plainPage());
  45. browser->setWordWrap( TQTextEdit::NoWrap );
  46. browser->setTextFormat( TQt::RichText );
  47. UndoDialogLayout->addWidget( browser );
  48. setButtonText( KDialogBase::User1, i18n( "&Start" ) );
  49. connect( this, TQT_SIGNAL( user1Clicked() ), this, TQT_SLOT( start() ) );
  50. connect( scriptname, TQT_SIGNAL( textChanged( const TQString & ) ), this, TQT_SLOT( enableControls() ) );
  51. enableControls();
  52. }
  53. UndoDialog::~UndoDialog()
  54. { }
  55. void UndoDialog::start()
  56. {
  57. if( scriptname->url().right( 8 ) != ".krename" ) // EXTENSION
  58. if( KMessageBox::warningContinueCancel( this, i18n("This script does not seem "
  59. "to be a Krename undo script. Execution of this "
  60. "script can be dangerous. Continue ?") )
  61. == KMessageBox::Cancel )
  62. return;
  63. TDEProcess *proc = new TDEProcess;
  64. *proc << scriptname->url() << "--krename";
  65. enableButton( KDialogBase::User1, false );
  66. if( !proc->start( TDEProcess::NotifyOnExit, TDEProcess::AllOutput ) ) {
  67. KMessageBox::sorry( this, i18n("Unable to start the given undo script!") );
  68. enableButton( KDialogBase::User1, true );
  69. delete proc;
  70. return;
  71. }
  72. proc->resume();
  73. connect( proc, TQT_SIGNAL( receivedStdout( TDEProcess*, char*, int) ), this, TQT_SLOT( receive( TDEProcess*, char*, int ) ) );
  74. connect( proc, TQT_SIGNAL( receivedStderr( TDEProcess*, char*, int) ), this, TQT_SLOT( receiveErr( TDEProcess*, char*, int ) ) );
  75. connect( proc, TQT_SIGNAL( processExited( TDEProcess* ) ), this, TQT_SLOT( finished( TDEProcess* ) ) );
  76. }
  77. void UndoDialog::receive( TDEProcess*, char* buffer, int len )
  78. {
  79. TQString text;
  80. for( int i = 0; i < len; i++ )
  81. text.append( buffer[i] );
  82. browser->setText( browser->text() + text + "<br>");
  83. }
  84. void UndoDialog::receiveErr( TDEProcess*, char* buffer, int len )
  85. {
  86. TQString text = "<b>";
  87. for( int i = 0; i < len; i++ )
  88. text.append( buffer[i] );
  89. browser->setText( browser->text() + text + "</b><br>");
  90. }
  91. void UndoDialog::finished( TDEProcess* p )
  92. {
  93. delete p;
  94. KMessageBox::information( this, i18n("Finished successfully") );
  95. enableControls();
  96. }
  97. void UndoDialog::enableControls()
  98. {
  99. TQFileInfo fi( scriptname->url() );
  100. bool b = !scriptname->url().isEmpty() && fi.exists() && fi.isExecutable();
  101. enableButton( KDialogBase::User1, b );
  102. }
  103. void UndoDialog::setUndoScript( const TQString & filename )
  104. {
  105. scriptname->setURL( filename );
  106. }
  107. #include "undodialog.moc"