TDE frontend for streamripper
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.

processcontroller.cpp 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /***************************************************************************
  2. * Copyright (C) 2005 by Will Entriken *
  3. * william.entriken@villanova.edu *
  4. * *
  5. * This program is free software; you can redistribute it and/or modify *
  6. * it under the terms of the GNU General Public License as published by *
  7. * the Free Software Foundation; either version 2 of the License, or *
  8. * (at your option) any later version. *
  9. * *
  10. * This program is distributed in the hope that it will be useful, *
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  13. * GNU General Public License for more details. *
  14. * *
  15. * You should have received a copy of the GNU General Public License *
  16. * along with this program; if not, write to the *
  17. * Free Software Foundation, Inc., *
  18. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
  19. ***************************************************************************/
  20. #include "processcontroller.h"
  21. #include "processlistviewitem.h"
  22. ProcessController::ProcessController(ProcessListViewItem * parent)
  23. : TQObject((TQObject *)parent), myParent(parent), myStatus(false), myAutomatic(false), myProcess(new TQProcess(this))
  24. {
  25. connect (myProcess, TQT_SIGNAL( readyReadStdout() ), (ProcessController *) this, TQT_SLOT( readStdout()) );
  26. // connect (myProcess, TQT_SIGNAL( destroyed() ), myProcess, TQT_SLOT( kill()) );
  27. // this should work, according to http://doc.trolltech.com/3.2/qobject.html#~TQObject but it doesn't
  28. }
  29. ProcessController::~ProcessController()
  30. {
  31. myProcess->kill();
  32. }
  33. void ProcessController::readStdout()
  34. {
  35. TQString tempOutput = myProcess->readStdout();
  36. if( tempOutput.contains( "ripping..." ))
  37. {
  38. TQString songname = tempOutput.mid( tempOutput.find( "]" )+1, tempOutput.findRev( "[" ) - tempOutput.find( "]" ) - 1);
  39. myParent->setText( 1, songname.stripWhiteSpace() );
  40. TQString bytesR = tempOutput.mid( tempOutput.findRev( "[" )+1, tempOutput.findRev( "]" ) - tempOutput.findRev( "[" ) - 1);
  41. myParent->setText( 2, bytesR.stripWhiteSpace() );
  42. }
  43. if( tempOutput.contains( "Connecting..." ))
  44. {
  45. myParent->setText( 1, "Connecting..." );
  46. myParent->setText( 2, "" );
  47. }
  48. if( tempOutput.contains( "buffering" ))
  49. {
  50. myParent->setText( 1, "Buffering..." );
  51. myParent->setText( 2, "" );
  52. }
  53. if( tempOutput.contains( "Time to stop is here" ))
  54. {
  55. myParent->setText( 1, "Complete" );
  56. myParent->setText( 2, "" );
  57. //TQTimer::singleShot( 1500, myParent, TQT_SLOT( setEmptyText(3) ));
  58. }
  59. }
  60. void ProcessController::startRip(TQString destination, TQString time)
  61. {
  62. myStatus = true;
  63. myParent->setText( 1, "Ripping" );
  64. myProcess->clearArguments();
  65. myProcess->addArgument( "streamripper" );
  66. myProcess->addArgument( myUrl );
  67. myProcess->addArgument( "-d " );
  68. myProcess->addArgument( destination );
  69. if( time.toInt() )
  70. {
  71. myProcess->addArgument( "-l " );
  72. myProcess->addArgument( time );
  73. }
  74. myProcess->setCommunication( TQProcess::Stdout | TQProcess::Stderr | TQProcess::DupStderr );
  75. myProcess->start();
  76. }
  77. void ProcessController::stopRip()
  78. {
  79. myStatus = false;
  80. myParent->setText( 1, "" );
  81. myParent->setText( 2, "" );
  82. myProcess->tryTerminate();
  83. TQTimer::singleShot( 2000, myProcess, TQT_SLOT( kill() ) );
  84. }
  85. bool ProcessController::getStatus()
  86. {
  87. return myStatus;
  88. }
  89. TQString ProcessController::getUrl()
  90. {
  91. return myUrl;
  92. }
  93. void ProcessController::setAutomatic(bool a)
  94. {
  95. myAutomatic = a;
  96. }
  97. bool ProcessController::getAutomatic()
  98. {
  99. return myAutomatic;
  100. }
  101. #if KDE_IS_VERSION(3,3,90)
  102. void ProcessController::setService(DNSSD::RemoteService::Ptr service)
  103. {
  104. myService = service;
  105. }
  106. DNSSD::RemoteService::Ptr ProcessController::getService()
  107. {
  108. return myService;
  109. }
  110. #endif
  111. TQString ProcessController::getDescription()
  112. {
  113. return myDescription;
  114. }
  115. void ProcessController::setUrl(TQString Url)
  116. {
  117. myUrl = Url;
  118. }
  119. void ProcessController::setDescription(TQString Description)
  120. {
  121. myDescription = Description;
  122. }
  123. #include "processcontroller.moc"