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.

kstreamripper.cpp 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. /***************************************************************************
  2. * Copyright (C) 2003-2005 by Michael Goettsche *
  3. * mail@tuxipuxi.org *
  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 <tdeconfig.h>
  21. #include <tdeglobal.h>
  22. #include <kled.h>
  23. #include <tdefiledialog.h>
  24. #include <tdeaboutapplication.h>
  25. #include <tdeapplication.h>
  26. #include <tqpushbutton.h>
  27. #include <tqlistview.h>
  28. #include <tqlineedit.h>
  29. #include <tqdir.h>
  30. #include <tqstring.h>
  31. #include <tqstringlist.h>
  32. #include <tqbuttongroup.h>
  33. #include <tqcheckbox.h>
  34. #include <tqprocess.h>
  35. #include <tqtextedit.h>
  36. #include <tqframe.h>
  37. #include <tqtimer.h>
  38. #include <tdemessagebox.h>
  39. #include <kstandarddirs.h>
  40. #include <tdeversion.h>
  41. #include "kstreamripper.h"
  42. #include "addnewstreamimpl.h"
  43. #include "processlistviewitem.h"
  44. #include "processcontroller.h"
  45. KStreamRipper::KStreamRipper( TQWidget* parent, const char* name )
  46. : KStreamRipperBase( parent,name )
  47. #if KDE_IS_VERSION(3,3,90)
  48. , m_browser("_shoutcast._tcp",0,true)
  49. #endif
  50. {
  51. m_destEdit->setText( TQDir::homeDirPath() );
  52. m_streamsListView->addColumn( "Name" );
  53. m_streamsListView->addColumn( "Status" );
  54. m_streamsListView->addColumn( "Size" );
  55. //app config
  56. TDEConfig *appConfig = TDEGlobal::config();
  57. m_destEdit->setText( appConfig->readEntry( "Destination" , "" ) );
  58. m_timeEdit->setText( appConfig->readEntry( "Riptime", "0" ));
  59. m_tuneInEdit->setText( appConfig->readEntry( "Command", "xmms <url>" ));
  60. m_id3Checkbox->setChecked( appConfig->readBoolEntry( "Id3Tag", 1 ));
  61. //listview entrys
  62. TQStringList nameList,urlList,descList;
  63. nameList = appConfig->readListEntry( "names" );
  64. urlList = appConfig->readListEntry( "urls" );
  65. descList = appConfig->readListEntry( "descs" );
  66. TQStringList::iterator iter1, iter2, iter3;
  67. iter1 = nameList.begin();
  68. iter2 = urlList.begin();
  69. iter3 = descList.begin();
  70. for( ; iter1 != nameList.end() && iter2 != urlList.end() && iter3 != descList.end(); ++iter1, ++iter2, ++iter3 )
  71. {
  72. ProcessListViewItem * proc = new ProcessListViewItem( m_streamsListView, *iter1, "", "");
  73. proc->setRenameEnabled(0, true);
  74. proc->getProcessController()->setUrl( *iter2 );
  75. proc->getProcessController()->setDescription( *iter3 );
  76. }
  77. //CONNECTS
  78. //clicks
  79. connect(m_addStreamButton, TQT_SIGNAL(clicked()), this, TQT_SLOT(addStreamButtonClicked()));
  80. connect(m_deleteStreamButton, TQT_SIGNAL(clicked()), this, TQT_SLOT(deleteStreamButtonClicked()));
  81. connect(m_tuneInButton, TQT_SIGNAL(clicked()), this, TQT_SLOT(tuneInButtonClicked()));
  82. connect(m_ripButton, TQT_SIGNAL(clicked()), this, TQT_SLOT(ripButtonClicked()));
  83. connect(m_stopRipButton, TQT_SIGNAL(clicked()), this, TQT_SLOT(stopRipButtonClicked()));
  84. connect(m_browseButton, TQT_SIGNAL(clicked()), this, TQT_SLOT(browseButtonClicked()));
  85. connect(m_helpButton, TQT_SIGNAL(clicked()), this, TQT_SLOT(helpButtonClicked()));
  86. connect(m_aboutButton, TQT_SIGNAL(clicked()), this, TQT_SLOT(aboutButtonClicked()));
  87. connect(m_quitButton, TQT_SIGNAL(clicked()), this, TQT_SLOT(quitButtonClicked()));
  88. //other
  89. connect( m_streamsListView, TQT_SIGNAL(selectionChanged()), this, TQT_SLOT( selectedNewListItem()) );
  90. connect( m_DescriptionEdit, TQT_SIGNAL(textChanged(const TQString&)), this, TQT_SLOT( descriptionChanged()) );
  91. connect( m_UrlEdit, TQT_SIGNAL(textChanged(const TQString&)), this, TQT_SLOT( urlChanged()) );
  92. // zeroconf
  93. #if KDE_IS_VERSION(3,3,90)
  94. connect(&m_browser, TQT_SIGNAL(serviceAdded(DNSSD::RemoteService::Ptr)), this,
  95. TQT_SLOT(serviceAdded(DNSSD::RemoteService::Ptr)));
  96. connect(&m_browser, TQT_SIGNAL(serviceRemoved(DNSSD::RemoteService::Ptr)), this,
  97. TQT_SLOT(serviceRemoved(DNSSD::RemoteService::Ptr)));
  98. m_browser.startBrowse();
  99. #endif
  100. }
  101. KStreamRipper::~KStreamRipper()
  102. {
  103. }
  104. void KStreamRipper::closeEvent( TQCloseEvent *e )
  105. {
  106. TDEConfig *appConfig = TDEGlobal::config();
  107. appConfig->writeEntry( "Destination", m_destEdit->text());
  108. appConfig->writeEntry( "Riptime", m_timeEdit->text());
  109. appConfig->writeEntry( "Command", m_tuneInEdit->text());
  110. appConfig->writeEntry( "Id3Tag", m_id3Checkbox->isChecked());
  111. //save the listview entrys
  112. TQStringList nameList,urlList,descList;
  113. TQListViewItemIterator iter( m_streamsListView );
  114. while( iter.current() )
  115. {
  116. ProcessListViewItem * ProcItem = (ProcessListViewItem*)iter.current();
  117. if(ProcItem->getProcessController()->getAutomatic()) continue;
  118. nameList.append( iter.current()->text( 0 ));
  119. urlList.append( ProcItem->getProcessController()->getUrl() );
  120. descList.append( ProcItem->getProcessController()->getDescription() );
  121. ++iter;
  122. }
  123. appConfig->writeEntry( "names", nameList );
  124. appConfig->writeEntry( "urls" , urlList );
  125. appConfig->writeEntry( "descs", descList );
  126. appConfig->sync();
  127. e->accept();
  128. }
  129. //SLOTS
  130. void KStreamRipper::addStreamButtonClicked()
  131. {
  132. AddNewStreamImpl *test = new AddNewStreamImpl( this );
  133. connect( test, TQT_SIGNAL( finished( AddNewStreamImpl* )), this, TQT_SLOT( addStreamFinished( AddNewStreamImpl* )) );
  134. test->show();
  135. }
  136. void KStreamRipper::deleteStreamButtonClicked()
  137. {
  138. ProcessListViewItem * ProcItem = (ProcessListViewItem*)m_streamsListView->currentItem();
  139. stopRipButtonClicked();
  140. delete ProcItem;
  141. }
  142. void KStreamRipper::tuneInButtonClicked()
  143. {
  144. if( m_streamsListView->currentItem() )
  145. {
  146. TQString command = m_tuneInEdit->text().replace( "<url>", m_UrlEdit->text() );
  147. TQStringList commands = TQStringList::split( " ", command );
  148. TQProcess *process = new TQProcess( TQT_TQOBJECT(this) );
  149. process->setArguments( commands );
  150. process->start();
  151. }
  152. else ;
  153. }
  154. #if KDE_IS_VERSION(3,3,90)
  155. void KStreamRipper::serviceAdded(DNSSD::RemoteService::Ptr srv)
  156. {
  157. ProcessListViewItem * proc = new ProcessListViewItem( m_streamsListView, srv->serviceName(), "", "");
  158. proc->getProcessController()->setUrl( TQString("http://%1:%2%3").arg(srv->hostName()).arg(srv->port()).arg(srv->textData()["path"]) );
  159. proc->getProcessController()->setDescription( i18n("found by Zeroconf") );
  160. proc->getProcessController()->setAutomatic(true);
  161. proc->getProcessController()->setService(srv);
  162. }
  163. void KStreamRipper::serviceRemoved(DNSSD::RemoteService::Ptr srv)
  164. {
  165. TQListViewItemIterator iter( m_streamsListView );
  166. while( iter.current() ) {
  167. ProcessListViewItem * ProcItem = (ProcessListViewItem*)iter.current();
  168. if (ProcItem->getProcessController()->getAutomatic() &&
  169. srv==ProcItem->getProcessController()->getService()) {
  170. delete ProcItem;
  171. return;
  172. }
  173. ++iter;
  174. }
  175. }
  176. #endif
  177. void KStreamRipper::ripButtonClicked()
  178. {
  179. if (TDEStandardDirs::findExe("streamripper")) {
  180. ProcessListViewItem * ProcItem = (ProcessListViewItem*)m_streamsListView->currentItem();
  181. ProcItem->getProcessController()->startRip(m_destEdit->text(), m_timeEdit->text());
  182. m_ripButton->setEnabled( false );
  183. m_stopRipButton->setEnabled( true );
  184. } else {
  185. KMessageBox::error(this, "The streamripper executable wasn't found. Make sure "
  186. "it's in your path.", "streamripper not found");
  187. }
  188. }
  189. void KStreamRipper::stopRipButtonClicked()
  190. {
  191. ProcessListViewItem * ProcItem = (ProcessListViewItem*)m_streamsListView->currentItem();
  192. ProcItem->getProcessController()->stopRip();
  193. m_ripButton->setEnabled( true );
  194. m_stopRipButton->setEnabled( false );
  195. }
  196. void KStreamRipper::browseButtonClicked()
  197. {
  198. TQString openDest = KFileDialog::getExistingDirectory( TQDir::homeDirPath(),
  199. this,
  200. "Select Destination..." );
  201. m_destEdit->setText( openDest );
  202. }
  203. void KStreamRipper::helpButtonClicked()
  204. {
  205. kapp->invokeHelp( TQString(), "kstreamripper" );
  206. }
  207. void KStreamRipper::aboutButtonClicked()
  208. {
  209. TDEAboutApplication *aboutApp = new TDEAboutApplication();
  210. aboutApp->show();
  211. }
  212. void KStreamRipper::quitButtonClicked()
  213. {
  214. this->close();
  215. }
  216. void KStreamRipper::selectedNewListItem()
  217. {
  218. if ( !m_streamsListView->selectedItem() ) {
  219. m_deleteStreamButton->setEnabled( false );
  220. m_tuneInButton->setEnabled( false );
  221. m_ripButton->setEnabled( false );
  222. m_DescriptionEdit->setText( TQString() );
  223. m_DescriptionEdit->setEnabled(false);
  224. m_UrlEdit->setEnabled(false);
  225. m_UrlEdit->setText( TQString() );
  226. return;
  227. }
  228. ProcessController * ProcCtl = ((ProcessListViewItem*)m_streamsListView->currentItem())->getProcessController();
  229. // reconfigure what the user is allowed to do based on if this process is ripping
  230. m_ripButton->setEnabled( !ProcCtl->getStatus() );
  231. m_stopRipButton->setEnabled( ProcCtl->getStatus() );
  232. m_tuneInButton->setEnabled( true );
  233. m_deleteStreamButton->setEnabled( !ProcCtl->getAutomatic() );
  234. m_DescriptionEdit->setText(ProcCtl->getDescription());
  235. m_DescriptionEdit->setEnabled(true);
  236. m_UrlEdit->setText(ProcCtl->getUrl());
  237. m_UrlEdit->setEnabled( !ProcCtl->getAutomatic() );
  238. // maybe these are more elegant than the next two functions, assuming the slots are implemented in ProcessController
  239. //connect(m_DescriptionEdit, TQT_SIGNAL(textChanged(const TQString&)), (ProcessListViewItem*)m_streamsListView->currentItem()->getProcessController(), TQT_SIGNAL(descriptionChanged(const TQString&))
  240. //connect(m_UrlEdit, TQT_SIGNAL(textChanged(const TQString&)), (ProcessListViewItem*)m_streamsListView->currentItem()->getProcessController(), TQT_SIGNAL(urlChanged(const TQString&))
  241. }
  242. void KStreamRipper::descriptionChanged()
  243. {
  244. // maybe this should be deleted and the communication would be through a slot
  245. ProcessListViewItem * ProcItem = (ProcessListViewItem*)m_streamsListView->currentItem();
  246. ProcItem->getProcessController()->setDescription(m_DescriptionEdit->text());
  247. }
  248. void KStreamRipper::urlChanged()
  249. {
  250. // maybe this should be deleted and the communication would be through a slot
  251. ProcessListViewItem * ProcItem = (ProcessListViewItem*)m_streamsListView->currentItem();
  252. ProcItem->getProcessController()->setUrl(m_UrlEdit->text());
  253. }
  254. void KStreamRipper::addStreamFinished( AddNewStreamImpl *e )
  255. {
  256. ProcessListViewItem * proc = new ProcessListViewItem( m_streamsListView, e->d_nameEdit->text(), "", "");
  257. proc->getProcessController()->setUrl( e->d_urlEdit->text() );
  258. proc->getProcessController()->setDescription( e->d_descEdit->text() );
  259. }
  260. #include "kstreamripper.moc"