MythTV  master
cdrip.cpp
Go to the documentation of this file.
1 // ANSI C includes
2 #include <cstdio>
3 #include <cstring>
4 
5 // Unix C includes
6 #include <sys/types.h>
7 #include <fcntl.h>
8 
9 #include "config.h"
10 
11 // C++ includes
12 #include <iostream>
13 #include <memory>
14 using namespace std;
15 
16 // Qt includes
17 #include <QApplication>
18 #include <QDir>
19 #include <QEvent>
20 #include <QFile>
21 #include <QKeyEvent>
22 #include <QRegExp>
23 #include <QTimer>
24 #include <QUrl>
25 #include <utility>
26 
27 // MythTV plugin includes
28 #include <mythcontext.h>
29 #include <mythdb.h>
30 #include <lcddevice.h>
31 #include <mythmediamonitor.h>
32 #include <mythdirs.h>
33 
34 // MythUI
35 #include <mythdialogbox.h>
36 #include <mythuitext.h>
37 #include <mythuicheckbox.h>
38 #include <mythuitextedit.h>
39 #include <mythuibutton.h>
40 #include <mythuiprogressbar.h>
41 #include <mythuibuttonlist.h>
42 #include <mythsystemlegacy.h>
43 #include <storagegroup.h>
44 #include <remotefile.h>
45 
46 // MythUI headers
47 #include <mythtv/libmythui/mythscreenstack.h>
48 #include <mythtv/libmythui/mythprogressdialog.h>
49 
50 // MythMusic includes
51 #include "cdrip.h"
52 #ifdef HAVE_CDIO
53 #include "cddecoder.h"
54 #endif // HAVE_CDIO
55 #include "encoder.h"
56 #include "vorbisencoder.h"
57 #include "lameencoder.h"
58 #include "flacencoder.h"
59 #include "genres.h"
60 #include "editmetadata.h"
61 #include "mythlogging.h"
62 #include "musicutils.h"
63 
64 #ifdef HAVE_CDIO
65 // libparanoia compatibility
66 #ifndef cdrom_paranoia
67 #define cdrom_paranoia cdrom_paranoia_t
68 #endif // cdrom_paranoia
69 
70 #ifndef CD_FRAMESIZE_RAW
71 # define CD_FRAMESIZE_RAW CDIO_CD_FRAMESIZE_RAW
72 #endif // CD_FRAMESIZE_RAW
73 #endif // HAVE_CDIO
74 
76  (QEvent::Type) QEvent::registerEventType();
78  (QEvent::Type) QEvent::registerEventType();
80  (QEvent::Type) QEvent::registerEventType();
82  (QEvent::Type) QEvent::registerEventType();
84  (QEvent::Type) QEvent::registerEventType();
86  (QEvent::Type) QEvent::registerEventType();
88  (QEvent::Type) QEvent::registerEventType();
90  (QEvent::Type) QEvent::registerEventType();
92  (QEvent::Type) QEvent::registerEventType();
94  (QEvent::Type) QEvent::registerEventType();
95 QEvent::Type RipStatusEvent::kCopyEndEvent =
96  (QEvent::Type) QEvent::registerEventType();
97 QEvent::Type RipStatusEvent::kFinishedEvent =
98  (QEvent::Type) QEvent::registerEventType();
100  (QEvent::Type) QEvent::registerEventType();
101 
103 {
104  RunProlog();
105  m_parent->scanCD();
106  RunEpilog();
107 }
108 
110 
112 {
113  RunProlog();
114  m_parent->ejectCD();
115  RunEpilog();
116 }
117 
119 
120 static long int getSectorCount (QString &cddevice, int tracknum)
121 {
122 #ifdef HAVE_CDIO
123  QByteArray devname = cddevice.toLatin1();
124  cdrom_drive *device = cdda_identify(devname.constData(), 0, nullptr);
125 
126  if (!device)
127  {
128  LOG(VB_GENERAL, LOG_ERR,
129  QString("Error: %1('%2',track=%3) failed at cdda_identify()").
130  arg(__func__).arg(cddevice).arg(tracknum));
131  return -1;
132  }
133 
134  if (cdda_open(device))
135  {
136  LOG(VB_GENERAL, LOG_ERR,
137  QString("Error: %1('%2',track=%3) failed at cdda_open() - cdda not supported").
138  arg(__func__).arg(cddevice).arg(tracknum));
139  cdda_close(device);
140  return -1;
141  }
142 
143  // we only care about audio tracks
144  if (cdda_track_audiop (device, tracknum))
145  {
146  cdda_verbose_set(device, CDDA_MESSAGE_FORGETIT, CDDA_MESSAGE_FORGETIT);
147  long int start = cdda_track_firstsector(device, tracknum);
148  long int end = cdda_track_lastsector( device, tracknum);
149  cdda_close(device);
150  return end - start + 1;
151  }
152  LOG(VB_GENERAL, LOG_ERR,
153  QString("Error: cdrip - cdda_track_audiop(%1) returned 0").arg(cddevice));
154 
155  cdda_close(device);
156 #else
157  (void)cddevice; (void)tracknum;
158 #endif // HAVE_CDIO
159  return 0;
160 }
161 
162 #ifdef HAVE_CDIO
163 static void paranoia_cb(long /*status*/, paranoia_cb_mode_t /*mode*/)
164 {
165 }
166 #endif // HAVE_CDIO
167 
169  QVector<RipTrack*> *tracks, int quality) :
170  MThread("CDRipper"),
171  m_parent(parent),
172  m_cdDevice(std::move(device)), m_quality(quality),
173  m_tracks(tracks)
174 {
175 #ifdef WIN32 // libcdio needs the drive letter with no path
176  if (m_cdDevice.endsWith('\\'))
177  m_cdDevice.chop(1);
178 #endif // WIN32
179 
180  QString lastHost = gCoreContext->GetSetting("MythMusicLastRipHost", gCoreContext->GetMasterHostName());
181  QStringList dirs = StorageGroup::getGroupDirs("Music", lastHost);
182  if (dirs.count() > 0)
183  m_musicStorageDir = StorageGroup::getGroupDirs("Music", lastHost).at(0);
184 }
185 
187 {
188  cancel();
189  wait();
190 }
191 
193 {
194  m_quit = true;
195 }
196 
198 {
199  return m_quit;
200 }
201 
203 {
204  RunProlog();
205 
206  if (m_tracks->empty())
207  {
208  RunEpilog();
209  return;
210  }
211 
212  m_totalSectors = 0;
213  m_totalSectorsDone = 0;
214  for (int trackno = 0; trackno < m_tracks->size(); trackno++)
215  {
216  m_totalSectors += getSectorCount(m_cdDevice, trackno + 1);
217  }
218 
219  if (!m_totalSectors)
220  {
221  RunEpilog();
222  return;
223  }
224 
225  MusicMetadata *track = m_tracks->at(0)->metadata;
226  QString tots;
227 
228  if (track->Compilation())
229  {
230  tots = track->CompilationArtist() + " ~ " + track->Album();
231  }
232  else
233  {
234  tots = track->Artist() + " ~ " + track->Album();
235  }
236 
237  QApplication::postEvent(
238  m_parent,
240  QApplication::postEvent(
241  m_parent,
243  QApplication::postEvent(
244  m_parent,
246 
247  QString textstatus;
248  QString encodertype = gCoreContext->GetSetting("EncoderType");
249  bool mp3usevbr = gCoreContext->GetBoolSetting("Mp3UseVBR", false);
250 
251  QApplication::postEvent(m_parent,
253 
254  if (LCD *lcd = LCD::Get())
255  {
256  QString lcd_tots = tr("Importing %1").arg(tots);
257  QList<LCDTextItem> textItems;
258  textItems.append(LCDTextItem(1, ALIGN_CENTERED,
259  lcd_tots, "Generic", false));
260  lcd->switchToGeneric(textItems);
261  }
262 
263  MusicMetadata *titleTrack = nullptr;
264  QString saveDir = GetConfDir() + "/tmp/RipTemp/";
265  QString outfile;
266 
267  std::unique_ptr<Encoder> encoder;
268 
269  for (int trackno = 0; trackno < m_tracks->size(); trackno++)
270  {
271  if (isCancelled())
272  break;
273 
274  QApplication::postEvent(
275  m_parent,
277  QString("Track %1 of %2")
278  .arg(trackno + 1).arg(m_tracks->size())));
279 
280  QApplication::postEvent(
281  m_parent,
283 
284  track = m_tracks->at(trackno)->metadata;
285 
286  if (track)
287  {
288  textstatus = track->Title();
289  QApplication::postEvent(
290  m_parent,
291  new RipStatusEvent(
292  RipStatusEvent::kTrackTextEvent, textstatus));
293  QApplication::postEvent(
294  m_parent,
296  QApplication::postEvent(
297  m_parent,
299 
300  // do we need to start a new file?
301  if (m_tracks->at(trackno)->active)
302  {
303  titleTrack = track;
304  titleTrack->setLength(m_tracks->at(trackno)->length);
305 
306  if (m_quality < 3)
307  {
308  if (encodertype == "mp3")
309  {
310  outfile = QString("track%1.mp3").arg(trackno);
311  encoder.reset(new LameEncoder(saveDir + outfile, m_quality,
312  titleTrack, mp3usevbr));
313  }
314  else // ogg
315  {
316  outfile = QString("track%1.ogg").arg(trackno);
317  encoder.reset(new VorbisEncoder(saveDir + outfile, m_quality,
318  titleTrack));
319  }
320  }
321  else
322  {
323  outfile = QString("track%1.flac").arg(trackno);
324  encoder.reset(new FlacEncoder(saveDir + outfile, m_quality,
325  titleTrack));
326  }
327 
328  if (!encoder->isValid())
329  {
330  QApplication::postEvent(
331  m_parent,
332  new RipStatusEvent(
334  "Encoder failed to open file for writing"));
335  LOG(VB_GENERAL, LOG_ERR, "MythMusic: Encoder failed"
336  " to open file for writing");
337 
338  RunEpilog();
339  return;
340  }
341  }
342 
343  if (!encoder)
344  {
345  // This should never happen.
346  QApplication::postEvent(
347  m_parent,
349  "Failed to create encoder"));
350  LOG(VB_GENERAL, LOG_ERR, "MythMusic: No encoder, failing");
351  RunEpilog();
352  return;
353  }
354  ripTrack(m_cdDevice, encoder.get(), trackno + 1);
355 
356  if (isCancelled())
357  {
358  RunEpilog();
359  return;
360  }
361 
362  if (m_tracks->at(trackno)->active)
363  {
364  QString ext = QFileInfo(outfile).suffix();
365  QString destFile = filenameFromMetadata(titleTrack) + '.' + ext;
366  QUrl url(m_musicStorageDir);
367 
368  // save the metadata to the DB
369  titleTrack->setFilename(destFile);
370  titleTrack->setHostname(url.host());
371  titleTrack->setFileSize((quint64)QFileInfo(outfile).size());
372  titleTrack->dumpToDatabase();
373 
374  // this will delete the encoder which will write the metadata in it's dtor
375  encoder.reset();
376 
377  // copy track to the BE
378  destFile = MythCoreContext::GenMythURL(url.host(), 0, destFile, "Music");
379 
380  QApplication::postEvent(m_parent, new RipStatusEvent(RipStatusEvent::kCopyStartEvent, 0));
381  RemoteFile::CopyFile(saveDir + outfile, destFile, true);
382  QApplication::postEvent(m_parent, new RipStatusEvent(RipStatusEvent::kCopyEndEvent, 0));
383  }
384  }
385  }
386 
387  QString PostRipCDScript = gCoreContext->GetSetting("PostCDRipScript");
388 
389  if (!PostRipCDScript.isEmpty())
390  myth_system(PostRipCDScript);
391 
392  QApplication::postEvent(
394 
395  RunEpilog();
396 }
397 
398 int CDRipperThread::ripTrack(QString &cddevice, Encoder *encoder, int tracknum)
399 {
400 #ifdef HAVE_CDIO
401  QByteArray devname = cddevice.toLatin1();
402  cdrom_drive *device = cdda_identify(devname.constData(), 0, nullptr);
403 
404  if (!device)
405  {
406  LOG(VB_GENERAL, LOG_ERR,
407  QString("cdda_identify failed for device '%1', "
408  "CDRipperThread::ripTrack(tracknum = %2) exiting.")
409  .arg(cddevice).arg(tracknum));
410  return -1;
411  }
412 
413  if (cdda_open(device))
414  {
415  LOG(VB_MEDIA, LOG_INFO,
416  QString("Error: %1('%2',track=%3) failed at cdda_open() - cdda not supported")
417  .arg(__func__).arg(cddevice).arg(tracknum));
418  cdda_close(device);
419  return -1;
420  }
421 
422  cdda_verbose_set(device, CDDA_MESSAGE_FORGETIT, CDDA_MESSAGE_FORGETIT);
423  long int start = cdda_track_firstsector(device, tracknum);
424  long int end = cdda_track_lastsector(device, tracknum);
425  LOG(VB_MEDIA, LOG_INFO, QString("%1(%2,track=%3) start=%4 end=%5")
426  .arg(__func__).arg(cddevice).arg(tracknum).arg(start).arg(end));
427 
428  cdrom_paranoia *paranoia = paranoia_init(device);
429  if (gCoreContext->GetSetting("ParanoiaLevel") == "full")
430  {
431  paranoia_modeset(paranoia, PARANOIA_MODE_FULL |
432  PARANOIA_MODE_NEVERSKIP);
433  }
434  else
435  {
436  paranoia_modeset(paranoia, PARANOIA_MODE_OVERLAP);
437  }
438 
439  paranoia_seek(paranoia, start, SEEK_SET);
440 
441  long int curpos = start;
442 
443  QApplication::postEvent(
444  m_parent,
446  m_lastTrackPct = -1;
447  m_lastOverallPct = -1;
448 
449  int every15 = 15;
450  while (curpos < end)
451  {
452  int16_t *buffer = paranoia_read(paranoia, paranoia_cb);
453 
454  if (encoder->addSamples(buffer, CD_FRAMESIZE_RAW))
455  break;
456 
457  curpos++;
458 
459  every15--;
460 
461  if (every15 <= 0)
462  {
463  every15 = 15;
464 
465  // updating the UITypes can be slow - only update if we need to:
466  int newOverallPct = (int) (100.0 / ((double) m_totalSectors /
467  (m_totalSectorsDone + curpos - start)));
468  if (newOverallPct != m_lastOverallPct)
469  {
470  m_lastOverallPct = newOverallPct;
471  QApplication::postEvent(
472  m_parent,
474  newOverallPct));
475  QApplication::postEvent(
476  m_parent,
478  m_totalSectorsDone + curpos - start));
479  }
480 
481  int newTrackPct = (int) (100.0 / ((double) (end - start + 1) / (curpos - start)));
482  if (newTrackPct != m_lastTrackPct)
483  {
484  m_lastTrackPct = newTrackPct;
485  QApplication::postEvent(
486  m_parent,
488  newTrackPct));
489  QApplication::postEvent(
490  m_parent,
492  curpos - start));
493  }
494 
495  if (LCD *lcd = LCD::Get())
496  {
497  float fProgress = (float)(m_totalSectorsDone + (curpos - start))
498  / m_totalSectors;
499  lcd->setGenericProgress(fProgress);
500  }
501  }
502 
503  if (isCancelled())
504  {
505  break;
506  }
507  }
508 
509  m_totalSectorsDone += end - start + 1;
510 
511  paranoia_free(paranoia);
512  cdda_close(device);
513 
514  return (curpos - start + 1) * CD_FRAMESIZE_RAW;
515 #else
516  (void)cddevice; (void)encoder; (void)tracknum;
517  return 0;
518 #endif // HAVE_CDIO
519 }
520 
522 
523 Ripper::Ripper(MythScreenStack *parent, QString device) :
524  MythScreenType(parent, "ripcd"),
525  m_tracks(new QVector<RipTrack*>),
526  m_cdDevice(std::move(device))
527 {
528 #ifndef _WIN32
529  // if the MediaMonitor is running stop it
530  m_mediaMonitorActive = false;
532  if (mon && mon->IsActive())
533  {
534  m_mediaMonitorActive = true;
535  mon->StopMonitoring();
536  }
537 #endif // _WIN32
538 
539  // make sure the directory where we temporarily save the rips is present
540  QDir dir;
541  dir.mkpath(GetConfDir() + "/tmp/RipTemp/");
542 
543  // remove any ripped tracks from the temp rip directory
544  QString command = "rm -f " + GetConfDir() + "/tmp/RipTemp/*";
545  myth_system(command);
546 
547  // get last host and directory we ripped to
548  QString lastHost = gCoreContext->GetSetting("MythMusicLastRipHost", gCoreContext->GetMasterHostName());
549  QStringList dirs = StorageGroup::getGroupDirs("Music", lastHost);
550  if (dirs.count() > 0)
551  m_musicStorageDir = StorageGroup::getGroupDirs("Music", lastHost).at(0);
552 }
553 
555 {
556  // remove any ripped tracks from the temp rip directory
557  QString command = "rm -f " + GetConfDir() + "/tmp/RipTemp/*";
558  myth_system(command);
559 
560  delete m_decoder;
561 
562 #ifndef _WIN32
563  // if the MediaMonitor was active when we started then restart it
565  {
567  if (mon)
568  mon->StartMonitoring();
569  }
570 #endif // _WIN32
571 
573  emit ripFinished();
574 }
575 
576 bool Ripper::Create(void)
577 {
578  if (!LoadWindowFromXML("music-ui.xml", "cdripper", this))
579  return false;
580 
581  m_qualityList = dynamic_cast<MythUIButtonList *>(GetChild("quality"));
582  m_artistEdit = dynamic_cast<MythUITextEdit *>(GetChild("artist"));
583  m_searchArtistButton = dynamic_cast<MythUIButton *>(GetChild("searchartist"));
584  m_albumEdit = dynamic_cast<MythUITextEdit *>(GetChild("album"));
585  m_searchAlbumButton = dynamic_cast<MythUIButton *>(GetChild("searchalbum"));
586  m_genreEdit = dynamic_cast<MythUITextEdit *>(GetChild("genre"));
587  m_yearEdit = dynamic_cast<MythUITextEdit *>(GetChild("year"));
588  m_searchGenreButton = dynamic_cast<MythUIButton *>(GetChild("searchgenre"));
589  m_compilationCheck = dynamic_cast<MythUICheckBox *>(GetChild("compilation"));
590  m_switchTitleArtist = dynamic_cast<MythUIButton *>(GetChild("switch"));
591  m_scanButton = dynamic_cast<MythUIButton *>(GetChild("scan"));
592  m_ripButton = dynamic_cast<MythUIButton *>(GetChild("rip"));
593  m_trackList = dynamic_cast<MythUIButtonList *>(GetChild("tracks"));
594 
595  BuildFocusList();
596 
601  {
602  LOG(VB_GENERAL, LOG_ERR,
603  "Missing theme elements for screen 'cdripper'");
604  return false;
605  }
606 
607  connect(m_trackList, SIGNAL(itemClicked(MythUIButtonListItem *)),
609  connect(m_ripButton, SIGNAL(Clicked()), SLOT(startRipper()));
610  connect(m_scanButton, SIGNAL(Clicked()), SLOT(startScanCD()));
611  connect(m_switchTitleArtist, SIGNAL(Clicked()),
612  SLOT(switchTitlesAndArtists()));
613  connect(m_compilationCheck, SIGNAL(toggled(bool)),
614  SLOT(compilationChanged(bool)));
615  connect(m_searchGenreButton, SIGNAL(Clicked()), SLOT(searchGenre()));
616  connect(m_genreEdit, SIGNAL(valueChanged()), SLOT(genreChanged()));
619  connect(m_yearEdit, SIGNAL(valueChanged()), SLOT(yearChanged()));
620  connect(m_artistEdit, SIGNAL(valueChanged()), SLOT(artistChanged()));
621  connect(m_searchArtistButton, SIGNAL(Clicked()), SLOT(searchArtist()));
622  connect(m_albumEdit, SIGNAL(valueChanged()), SLOT(albumChanged()));
623  connect(m_searchAlbumButton, SIGNAL(Clicked()), SLOT(searchAlbum()));
624 
625  // Populate Quality List
626  new MythUIButtonListItem(m_qualityList, tr("Low"), QVariant::fromValue(0));
627  new MythUIButtonListItem(m_qualityList, tr("Medium"), QVariant::fromValue(1));
628  new MythUIButtonListItem(m_qualityList, tr("High"), QVariant::fromValue(2));
629  new MythUIButtonListItem(m_qualityList, tr("Perfect"), QVariant::fromValue(3));
630  m_qualityList->SetValueByData(QVariant::fromValue(
631  gCoreContext->GetNumSetting("DefaultRipQuality", 1)));
632 
633  QTimer::singleShot(500, this, SLOT(startScanCD()));
634 
635  return true;
636 }
637 
638 bool Ripper::keyPressEvent(QKeyEvent *event)
639 {
640  if (GetFocusWidget() && GetFocusWidget()->keyPressEvent(event))
641  return true;
642 
643  QStringList actions;
644  bool handled = GetMythMainWindow()->TranslateKeyPress("Global", event, actions);
645 
646  for (int i = 0; i < actions.size() && !handled; i++)
647  {
648  QString action = actions[i];
649  handled = true;
650 
651  if (action == "EDIT" || action == "INFO") // INFO purely for historical reasons
653  else if (action == "MENU")
654  ShowMenu();
655  else
656  handled = false;
657  }
658 
659  if (!handled && MythScreenType::keyPressEvent(event))
660  handled = true;
661 
662  return handled;
663 }
664 
666 {
667  if (m_tracks->empty())
668  return;
669 
670  MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
671 
672  auto *menu = new MythDialogBox("", popupStack, "ripmusicmenu");
673 
674  if (menu->Create())
675  popupStack->AddScreen(menu);
676  else
677  {
678  delete menu;
679  return;
680  }
681 
682  menu->SetReturnEvent(this, "menu");
683  menu->AddButton(tr("Select Where To Save Tracks"), SLOT(chooseBackend()));
684  menu->AddButton(tr("Edit Track Metadata"), SLOT(showEditMetadataDialog()));
685 }
686 
688 {
690 }
691 
693 {
694  QStringList hostList;
695 
696  // get a list of hosts with a directory defined for the 'Music' storage group
697  MSqlQuery query(MSqlQuery::InitCon());
698  QString sql = "SELECT DISTINCT hostname "
699  "FROM storagegroup "
700  "WHERE groupname = 'Music'";
701  if (!query.exec(sql) || !query.isActive())
702  MythDB::DBError("Ripper::chooseBackend get host list", query);
703  else
704  {
705  while(query.next())
706  {
707  hostList.append(query.value(0).toString());
708  }
709  }
710 
711  if (hostList.isEmpty())
712  {
713  LOG(VB_GENERAL, LOG_ERR, "Ripper::chooseBackend: No backends found");
714  return;
715  }
716 
717  QString msg = tr("Select where to save tracks");
718 
719  MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
720  auto *searchDlg = new MythUISearchDialog(popupStack, msg, hostList, false, "");
721 
722  if (!searchDlg->Create())
723  {
724  delete searchDlg;
725  return;
726  }
727 
728  connect(searchDlg, SIGNAL(haveResult(QString)), SLOT(setSaveHost(QString)));
729 
730  popupStack->AddScreen(searchDlg);
731 }
732 
733 void Ripper::setSaveHost(const QString& host)
734 {
735  gCoreContext->SaveSetting("MythMusicLastRipHost", host);
736 
737  QStringList dirs = StorageGroup::getGroupDirs("Music", host);
738  if (dirs.count() > 0)
739  m_musicStorageDir = StorageGroup::getGroupDirs("Music", host).at(0);
740 }
741 
743 {
744  if (m_scanThread)
745  return;
746 
747  QString message = tr("Scanning CD. Please Wait ...");
748  OpenBusyPopup(message);
749 
750  m_scanThread = new CDScannerThread(this);
751  connect(m_scanThread->qthread(), SIGNAL(finished()), SLOT(ScanFinished()));
752  m_scanThread->start();
753 }
754 
756 {
757  delete m_scanThread;
758  m_scanThread = nullptr;
759 
760  m_tracks->clear();
761 
762  if (m_decoder)
763  {
764  bool isCompilation = false;
765 
766  m_artistName.clear();
767  m_albumName.clear();
768  m_genreName.clear();
769  m_year.clear();
770 
771  for (int trackno = 0; trackno < m_decoder->getNumTracks(); trackno++)
772  {
773  auto *ripTrack = new RipTrack;
774 
775  MusicMetadata *metadata = m_decoder->getMetadata(trackno + 1);
776  if (metadata)
777  {
778  ripTrack->metadata = metadata;
779  ripTrack->length = metadata->Length();
780 
781  if (metadata->Compilation())
782  {
783  isCompilation = true;
784  m_artistName = metadata->CompilationArtist();
785  }
786  else if (m_artistName.isEmpty())
787  {
788  m_artistName = metadata->Artist();
789  }
790 
791  if (m_albumName.isEmpty())
792  m_albumName = metadata->Album();
793 
794  if (m_genreName.isEmpty() && !metadata->Genre().isEmpty())
795  m_genreName = metadata->Genre();
796 
797  if (m_year.isEmpty() && metadata->Year() > 0)
798  m_year = QString::number(metadata->Year());
799 
800  QString title = metadata->Title();
801  ripTrack->isNew = isNewTune(m_artistName, m_albumName, title);
802 
803  ripTrack->active = ripTrack->isNew;
804 
805  m_tracks->push_back(ripTrack);
806 
807  }
808  else
809  delete ripTrack;
810  }
811 
816  m_compilationCheck->SetCheckState(isCompilation);
817 
818  if (!isCompilation)
820  else
822  }
823 
824  BuildFocusList();
825  updateTrackList();
826 
827  CloseBusyPopup();
828 }
829 
830 void Ripper::scanCD(void)
831 {
832 #ifdef HAVE_CDIO
833  {
834  LOG(VB_MEDIA, LOG_INFO, QString("Ripper::%1 CD='%2'").
835  arg(__func__).arg(m_cdDevice));
836  (void)cdio_close_tray(m_cdDevice.toLatin1().constData(), nullptr);
837  }
838 #endif // HAVE_CDIO
839 
840  delete m_decoder;
841  m_decoder = new CdDecoder("cda", nullptr, nullptr);
842  if (m_decoder)
844 }
845 
847 {
848  for (auto it = m_tracks->begin(); it < m_tracks->end(); ++it)
849  {
850  RipTrack *track = (*it);
851  if (track && !track->isNew)
852  {
853  if (deleteExistingTrack(track))
854  {
855  track->isNew = true;
856  toggleTrackActive(track);
857  }
858  }
859  }
860 }
861 
863 {
864  if (!track)
865  return false;
866 
867  MusicMetadata *metadata = track->metadata;
868 
869  if (!metadata)
870  return false;
871 
872  QString artist = metadata->Artist();
873  QString album = metadata->Album();
874  QString title = metadata->Title();
875 
876  MSqlQuery query(MSqlQuery::InitCon());
877  QString queryString("SELECT song_id, "
878  "CONCAT_WS('/', music_directories.path, music_songs.filename) AS filename "
879  "FROM music_songs "
880  "LEFT JOIN music_artists"
881  " ON music_songs.artist_id=music_artists.artist_id "
882  "LEFT JOIN music_albums"
883  " ON music_songs.album_id=music_albums.album_id "
884  "LEFT JOIN music_directories "
885  " ON music_songs.directory_id=music_directories.directory_id "
886  "WHERE artist_name REGEXP \'");
887  QString token = artist;
888  token.replace(QRegExp("(/|\\\\|:|\'|\\,|\\!|\\(|\\)|\"|\\?|\\|)"),
889  QString("."));
890 
891  queryString += token + "\' AND " + "album_name REGEXP \'";
892  token = album;
893  token.replace(QRegExp("(/|\\\\|:|\'|\\,|\\!|\\(|\\)|\"|\\?|\\|)"),
894  QString("."));
895  queryString += token + "\' AND " + "name REGEXP \'";
896  token = title;
897  token.replace(QRegExp("(/|\\\\|:|\'|\\,|\\!|\\(|\\)|\"|\\?|\\|)"),
898  QString("."));
899  queryString += token + "\' ORDER BY artist_name, album_name,"
900  " name, song_id, filename LIMIT 1";
901  query.prepare(queryString);
902 
903  if (!query.exec() || !query.isActive())
904  {
905  MythDB::DBError("Search music database", query);
906  return false;
907  }
908 
909  if (query.next())
910  {
911  int trackID = query.value(0).toInt();
912  QString filename = query.value(1).toString();
913  QUrl url(m_musicStorageDir);
914  filename = MythCoreContext::GenMythURL(url.host(), 0, filename, "Music");
915 
916  // delete file
917  // FIXME: RemoteFile::DeleteFile will only work with files on the master BE
919  {
920  LOG(VB_GENERAL, LOG_NOTICE, QString("Ripper::deleteExistingTrack() "
921  "Could not delete %1")
922  .arg(filename));
923  return false;
924  }
925 
926  // remove database entry
927  MSqlQuery deleteQuery(MSqlQuery::InitCon());
928  deleteQuery.prepare("DELETE FROM music_songs"
929  " WHERE song_id = :SONG_ID");
930  deleteQuery.bindValue(":SONG_ID", trackID);
931  if (!deleteQuery.exec())
932  {
933  MythDB::DBError("Delete Track", deleteQuery);
934  return false;
935  }
936  return true;
937  }
938 
939  return false;
940 }
941 
943 {
944  return m_somethingwasripped;
945 }
946 
948 {
949  QString newartist = m_artistEdit->GetText();
950 
951  if (!m_tracks->empty())
952  {
953  foreach (auto track, *m_tracks)
954  {
955  MusicMetadata *data = track->metadata;
956  if (data)
957  {
959  {
960  data->setCompilationArtist(newartist);
961  }
962  else
963  {
964  data->setArtist(newartist);
965  data->setCompilationArtist("");
966  }
967  }
968  }
969 
970  updateTrackList();
971  }
972 
973  m_artistName = newartist;
974 }
975 
977 {
978  QString newalbum = m_albumEdit->GetText();
979 
980  if (!m_tracks->empty())
981  {
982  foreach (auto track, *m_tracks)
983  {
984  MusicMetadata *data = track->metadata;
985  if (data)
986  data->setAlbum(newalbum);
987  }
988  }
989 
990  m_albumName = newalbum;
991 }
992 
994 {
995  QString newgenre = m_genreEdit->GetText();
996 
997  if (!m_tracks->empty())
998  {
999  foreach (auto track, *m_tracks)
1000  {
1001  MusicMetadata *data = track->metadata;
1002  if (data)
1003  data->setGenre(newgenre);
1004  }
1005  }
1006 
1007  m_genreName = newgenre;
1008 }
1009 
1011 {
1012  QString newyear = m_yearEdit->GetText();
1013 
1014  if (!m_tracks->empty())
1015  {
1016  foreach (auto track, *m_tracks)
1017  {
1018  MusicMetadata *data = track->metadata;
1019  if (data)
1020  data->setYear(newyear.toInt());
1021  }
1022  }
1023 
1024  m_year = newyear;
1025 }
1026 
1028 {
1029  if (!state)
1030  {
1031  if (!m_tracks->empty())
1032  {
1033  // Update artist MetaData of each track on the ablum...
1034  foreach (auto track, *m_tracks)
1035  {
1036  MusicMetadata *data = track->metadata;
1037  if (data)
1038  {
1039  data->setCompilationArtist("");
1040  data->setArtist(m_artistName);
1041  data->setCompilation(false);
1042  }
1043  }
1044  }
1045 
1047  }
1048  else
1049  {
1050  if (!m_tracks->empty())
1051  {
1052  // Update artist MetaData of each track on the album...
1053  foreach (auto track, *m_tracks)
1054  {
1055  MusicMetadata *data = track->metadata;
1056 
1057  if (data)
1058  {
1060  data->setCompilation(true);
1061  }
1062  }
1063  }
1064 
1066  }
1067 
1068  BuildFocusList();
1069  updateTrackList();
1070 }
1071 
1073 {
1075  return;
1076 
1077  // Switch title and artist for each track
1078  QString tmp;
1079  if (!m_tracks->empty())
1080  {
1081  foreach (auto track, *m_tracks)
1082  {
1083  MusicMetadata *data = track->metadata;
1084 
1085  if (data)
1086  {
1087  tmp = data->Artist();
1088  data->setArtist(data->Title());
1089  data->setTitle(tmp);
1090  }
1091  }
1092 
1093  updateTrackList();
1094  }
1095 }
1096 
1098 {
1099  if (m_tracks->isEmpty())
1100  {
1101  ShowOkPopup(tr("There are no tracks to rip?"));
1102  return;
1103  }
1104 
1106 
1107  int quality = m_qualityList->GetItemCurrent()->GetData().toInt();
1108 
1109  auto *statusDialog = new RipStatus(mainStack, m_cdDevice, m_tracks, quality);
1110 
1111  if (statusDialog->Create())
1112  {
1113  connect(statusDialog, SIGNAL(Result(bool)), SLOT(RipComplete(bool)));
1114  mainStack->AddScreen(statusDialog);
1115  }
1116  else
1117  delete statusDialog;
1118 }
1119 
1120 void Ripper::RipComplete(bool result)
1121 {
1122  if (result)
1123  {
1124  bool EjectCD = gCoreContext->GetBoolSetting("EjectCDAfterRipping", true);
1125  if (EjectCD)
1126  startEjectCD();
1127 
1128  ShowOkPopup(tr("Rip completed successfully."));
1129 
1130  m_somethingwasripped = true;
1131  }
1132 
1133  if (LCD *lcd = LCD::Get())
1134  lcd->switchToTime();
1135 }
1136 
1137 
1139 {
1140  if (m_ejectThread)
1141  return;
1142 
1143  QString message = tr("Ejecting CD. Please Wait ...");
1144 
1145  OpenBusyPopup(message);
1146 
1147  m_ejectThread = new CDEjectorThread(this);
1148  connect(m_ejectThread->qthread(),
1149  SIGNAL(finished()), SLOT(EjectFinished()));
1150  m_ejectThread->start();
1151 }
1152 
1154 {
1155  delete m_ejectThread;
1156  m_ejectThread = nullptr;
1157 
1158  CloseBusyPopup();
1159 }
1160 
1162 {
1163  LOG(VB_MEDIA, LOG_INFO, __PRETTY_FUNCTION__);
1164  bool bEjectCD = gCoreContext->GetBoolSetting("EjectCDAfterRipping",true);
1165  if (bEjectCD)
1166  {
1167 #ifdef HAVE_CDIO
1168  LOG(VB_MEDIA, LOG_INFO, QString("Ripper::%1 '%2'").
1169  arg(__func__).arg(m_cdDevice));
1170  (void)cdio_eject_media_drive(m_cdDevice.toLatin1().constData());
1171 #else
1173  if (mon)
1174  {
1175  QByteArray devname = m_cdDevice.toLatin1();
1176  MythMediaDevice *pMedia = mon->GetMedia(devname.constData());
1177  if (pMedia && mon->ValidateAndLock(pMedia))
1178  {
1179  pMedia->eject();
1180  mon->Unlock(pMedia);
1181  }
1182  }
1183 #endif // HAVE_CDIO
1184  }
1185 }
1186 
1188 {
1189  if (m_tracks->isEmpty())
1190  return;
1191 
1192  if (m_trackList)
1193  {
1194  m_trackList->Reset();
1195 
1196  for (int i = 0; i < m_tracks->size(); i++)
1197  {
1198  if (i >= m_tracks->size())
1199  break;
1200 
1201  RipTrack *track = m_tracks->at(i);
1202  MusicMetadata *metadata = track->metadata;
1203 
1204  auto *item = new MythUIButtonListItem(m_trackList,"");
1205 
1206  item->setCheckable(true);
1207 
1208  item->SetData(QVariant::fromValue(track));
1209 
1210  if (track->isNew)
1211  item->DisplayState("new", "yes");
1212  else
1213  item->DisplayState("new", "no");
1214 
1215  if (track->active)
1216  item->setChecked(MythUIButtonListItem::FullChecked);
1217  else
1218  item->setChecked(MythUIButtonListItem::NotChecked);
1219 
1220  item->SetText(QString::number(metadata->Track()), "track");
1221  item->SetText(metadata->Title(), "title");
1222  item->SetText(metadata->Artist(), "artist");
1223 
1224  int length = track->length / 1000;
1225  if (length > 0)
1226  {
1227  int min = length / 60;
1228  int sec = length % 60;
1229  QString s;
1230  s.sprintf("%02d:%02d", min, sec);
1231  item->SetText(s, "length");
1232  }
1233  else
1234  item->SetText("", "length");
1235 
1236 // if (i == m_currentTrack)
1237 // m_trackList->SetItemCurrent(i);
1238  }
1239  }
1240 }
1241 
1243 {
1244  QString msg = tr("Select an Artist");
1245  QStringList searchList = MusicMetadata::fillFieldList("artist");
1246 
1247  MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
1248  auto *searchDlg = new MythUISearchDialog(popupStack, msg, searchList, false, "");
1249 
1250  if (!searchDlg->Create())
1251  {
1252  delete searchDlg;
1253  return;
1254  }
1255 
1256  connect(searchDlg, SIGNAL(haveResult(QString)), SLOT(setArtist(QString)));
1257 
1258  popupStack->AddScreen(searchDlg);
1259 }
1260 
1261 void Ripper::setArtist(const QString& artist)
1262 {
1263  m_artistEdit->SetText(artist);
1264 }
1265 
1267 {
1268  QString msg = tr("Select an Album");
1269  QStringList searchList = MusicMetadata::fillFieldList("album");
1270 
1271  MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
1272  auto *searchDlg = new MythUISearchDialog(popupStack, msg, searchList, false, "");
1273 
1274  if (!searchDlg->Create())
1275  {
1276  delete searchDlg;
1277  return;
1278  }
1279 
1280  connect(searchDlg, SIGNAL(haveResult(QString)), SLOT(setAlbum(QString)));
1281 
1282  popupStack->AddScreen(searchDlg);
1283 }
1284 
1285 void Ripper::setAlbum(const QString& album)
1286 {
1287  m_albumEdit->SetText(album);
1288 }
1289 
1291 {
1292  QString msg = tr("Select a Genre");
1293  QStringList searchList = MusicMetadata::fillFieldList("genre");
1294  // load genre list
1295  m_searchList.clear();
1296  for (int x = 0; x < genre_table_size; x++)
1297  m_searchList.push_back(QString(genre_table[x]));
1298  m_searchList.sort();
1299 
1300  MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
1301  auto *searchDlg = new MythUISearchDialog(popupStack, msg, searchList, false, "");
1302 
1303  if (!searchDlg->Create())
1304  {
1305  delete searchDlg;
1306  return;
1307  }
1308 
1309  connect(searchDlg, SIGNAL(haveResult(QString)), SLOT(setGenre(QString)));
1310 
1311  popupStack->AddScreen(searchDlg);
1312 }
1313 
1314 void Ripper::setGenre(const QString& genre)
1315 {
1316  m_genreEdit->SetText(genre);
1317 }
1318 
1320 {
1321  if (!item || m_tracks->isEmpty())
1322  return;
1323 
1324  auto *track = item->GetData().value<RipTrack *>();
1325 
1326  if (!track)
1327  return;
1328 
1329  MusicMetadata *editMeta = track->metadata;
1330 
1332 
1333  auto *editDialog = new EditMetadataDialog(mainStack, editMeta);
1334  editDialog->setSaveMetadataOnly();
1335 
1336  if (!editDialog->Create())
1337  {
1338  delete editDialog;
1339  return;
1340  }
1341 
1342  connect(editDialog, SIGNAL(metadataChanged()), this, SLOT(metadataChanged()));
1343 
1344  mainStack->AddScreen(editDialog);
1345 }
1346 
1348 {
1349  updateTrackList();
1350 }
1351 
1353 {
1354  QVariant data = QVariant::fromValue(track);
1356  if (item)
1357  {
1358  toggleTrackActive(item);
1359  }
1360 }
1361 
1363 {
1364  if (m_tracks->isEmpty() || !item)
1365  return;
1366 
1367  int pos = m_trackList->GetItemPos(item);
1368 
1369  // sanity check item position
1370  if (pos < 0 || pos > m_tracks->count() - 1)
1371  return;
1372 
1373  RipTrack *track = m_tracks->at(pos);
1374 
1375  if (!track->active && !track->isNew)
1376  {
1377  ShowConflictMenu(track);
1378  return;
1379  }
1380 
1381  track->active = !track->active;
1382 
1383  if (track->active)
1385  else
1387 
1389 }
1390 
1392 {
1393  MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
1394 
1395  QString msg = tr("This track has been disabled because it is already "
1396  "present in the database.\n"
1397  "Do you want to permanently delete the existing "
1398  "file(s)?");
1399  auto *menu = new MythDialogBox(msg, popupStack, "conflictmenu", true);
1400 
1401  if (menu->Create())
1402  popupStack->AddScreen(menu);
1403  else
1404  {
1405  delete menu;
1406  return;
1407  }
1408 
1409  menu->SetReturnEvent(this, "conflictmenu");
1410  menu->AddButton(tr("No, Cancel"));
1411  menu->AddButton(tr("Yes, Delete"), QVariant::fromValue(track));
1412  menu->AddButton(tr("Yes, Delete All"));
1413 }
1414 
1416 {
1417  int length = 0;
1418 
1419  for (auto it = m_tracks->end() - 1; it == m_tracks->begin(); --it)
1420  {
1421  RipTrack *track = *it;
1422  if (track->active)
1423  {
1424  track->length = length + track->metadata->Length();
1425  length = 0;
1426  }
1427  else
1428  {
1429  track->length = 0;
1430  length += track->metadata->Length();
1431  }
1432  }
1433 }
1434 
1435 void Ripper::customEvent(QEvent* event)
1436 {
1437  if (event->type() == DialogCompletionEvent::kEventType)
1438  {
1439  auto dce = dynamic_cast<DialogCompletionEvent *>(event);
1440  if (dce == nullptr)
1441  return;
1442  if (dce->GetId() == "conflictmenu")
1443  {
1444  int buttonNum = dce->GetResult();
1445  auto *track = dce->GetData().value<RipTrack *>();
1446 
1447  switch (buttonNum)
1448  {
1449  case 0:
1450  // Do nothing
1451  break;
1452  case 1:
1453  if (deleteExistingTrack(track))
1454  {
1455  track->isNew = true;
1456  toggleTrackActive(track);
1457  }
1458  break;
1459  case 2:
1461  break;
1462  default:
1463  break;
1464  }
1465  }
1466 
1467  return;
1468  }
1469 
1470  MythUIType::customEvent(event);
1471 }
1472 
1473 
1475 
1477 {
1478  delete m_ripperThread;
1479  if (LCD *lcd = LCD::Get())
1480  lcd->switchToTime();
1481 }
1482 
1484 {
1485  if (!LoadWindowFromXML("music-ui.xml", "ripstatus", this))
1486  return false;
1487 
1488  m_overallText = dynamic_cast<MythUIText *>(GetChild("overall"));
1489  m_trackText = dynamic_cast<MythUIText *>(GetChild("track"));
1490  m_statusText = dynamic_cast<MythUIText *>(GetChild("status"));
1491  m_trackPctText = dynamic_cast<MythUIText *>(GetChild("trackpct"));
1492  m_overallPctText = dynamic_cast<MythUIText *>(GetChild("overallpct"));
1493 
1494  m_overallProgress = dynamic_cast<MythUIProgressBar *>(GetChild("overall_progress"));
1495  m_trackProgress = dynamic_cast<MythUIProgressBar *>(GetChild("track_progress"));
1496 
1497  BuildFocusList();
1498 
1499  startRip();
1500 
1501  return true;
1502 }
1503 
1504 bool RipStatus::keyPressEvent(QKeyEvent *event)
1505 {
1506  if (GetFocusWidget() && GetFocusWidget()->keyPressEvent(event))
1507  return true;
1508 
1509  QStringList actions;
1510  bool handled = GetMythMainWindow()->TranslateKeyPress("Global", event, actions);
1511 
1512  for (int i = 0; i < actions.size() && !handled; i++)
1513  {
1514  QString action = actions[i];
1515  handled = true;
1516 
1517 
1518  if (action == "ESCAPE" &&
1520  {
1521  MythConfirmationDialog *dialog =
1522  ShowOkPopup(tr("Cancel ripping the CD?"), this,
1523  static_cast<const char*>(nullptr), true);
1524  if (dialog)
1525  dialog->SetReturnEvent(this, "stop_ripping");
1526  }
1527  else
1528  handled = false;
1529  }
1530 
1531  if (!handled && MythScreenType::keyPressEvent(event))
1532  handled = true;
1533 
1534  return handled;
1535 }
1536 
1537 void RipStatus::customEvent(QEvent *event)
1538 {
1539  if (event->type() == DialogCompletionEvent::kEventType)
1540  {
1541  auto *dce = dynamic_cast<DialogCompletionEvent *>(event);
1542  if (dce == nullptr)
1543  return;
1544  if (dce->GetId() == "stop_ripping" && dce->GetResult())
1545  {
1547  m_ripperThread->wait();
1548  Close();
1549  }
1550 
1551  return;
1552  }
1553 
1554  auto *rse = dynamic_cast<RipStatusEvent *> (event);
1555  if (!rse)
1556  return;
1557 
1558  if (event->type() == RipStatusEvent::kTrackTextEvent)
1559  {
1560  if (m_trackText)
1561  m_trackText->SetText(rse->m_text);
1562  }
1563  else if (event->type() == RipStatusEvent::kOverallTextEvent)
1564  {
1565  if (m_overallText)
1566  m_overallText->SetText(rse->m_text);
1567  }
1568  else if (event->type() == RipStatusEvent::kStatusTextEvent)
1569  {
1570  if (m_statusText)
1571  m_statusText->SetText(rse->m_text);
1572  }
1573  else if (event->type() == RipStatusEvent::kTrackProgressEvent)
1574  {
1575  if (m_trackProgress)
1576  m_trackProgress->SetUsed(rse->m_value);
1577  }
1578  else if (event->type() == RipStatusEvent::kTrackPercentEvent)
1579  {
1580  if (m_trackPctText)
1581  m_trackPctText->SetText(QString("%1%").arg(rse->m_value));
1582  }
1583  else if (event->type() == RipStatusEvent::kTrackStartEvent)
1584  {
1585  if (m_trackProgress)
1586  m_trackProgress->SetTotal(rse->m_value);
1587  }
1588  else if (event->type() == RipStatusEvent::kCopyStartEvent)
1589  {
1590  if (m_trackPctText)
1591  m_trackPctText->SetText(tr("Copying Track ..."));
1592  }
1593  else if (event->type() == RipStatusEvent::kCopyEndEvent)
1594  {
1595  if (m_trackPctText)
1596  m_trackPctText->SetText("");
1597  }
1598  else if (event->type() == RipStatusEvent::kOverallProgressEvent)
1599  {
1600  if (m_overallProgress)
1601  m_overallProgress->SetUsed(rse->m_value);
1602  }
1603  else if (event->type() == RipStatusEvent::kOverallStartEvent)
1604  {
1605  if (m_overallProgress)
1606  m_overallProgress->SetTotal(rse->m_value);
1607  }
1608  else if (event->type() == RipStatusEvent::kOverallPercentEvent)
1609  {
1610  if (m_overallPctText)
1611  m_overallPctText->SetText(QString("%1%").arg(rse->m_value));
1612  }
1613  else if (event->type() == RipStatusEvent::kFinishedEvent)
1614  {
1615  emit Result(true);
1616  Close();
1617  }
1618  else if (event->type() == RipStatusEvent::kEncoderErrorEvent)
1619  {
1620  ShowOkPopup(tr("The encoder failed to create the file.\n"
1621  "Do you have write permissions"
1622  " for the music directory?"));
1623  Close();
1624  }
1625  else
1626  {
1627  LOG(VB_GENERAL, LOG_ERR, "Received an unknown event type!");
1628  }
1629 }
1630 
1632 {
1633  delete m_ripperThread;
1635  m_ripperThread->start();
1636 }
void RunEpilog(void)
Cleans up a thread's resources, call this if you reimplement run().
Definition: mthread.cpp:215
~Ripper(void) override
Definition: cdrip.cpp:554
bool next(void)
Wrap QSqlQuery::next() so we can display the query results.
Definition: mythdbcon.cpp:783
MythUITextEdit * m_genreEdit
Definition: cdrip.h:155
MythUITextEdit * m_artistEdit
Definition: cdrip.h:153
void startEjectCD(void)
Definition: cdrip.cpp:1138
static bool DeleteFile(const QString &url)
Definition: remotefile.cpp:417
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
Definition: cdrip.cpp:1504
void SetUsed(int value)
This is a wrapper around QThread that does several additional things.
Definition: mthread.h:46
void bindValue(const QString &placeholder, const QVariant &val)
Add a single binding.
Definition: mythdbcon.cpp:864
void searchAlbum(void)
Definition: cdrip.cpp:1266
void updateTrackLengths(void)
Definition: cdrip.cpp:1415
void switchTitlesAndArtists()
Definition: cdrip.cpp:1072
MythUITextEdit * m_albumEdit
Definition: cdrip.h:154
QString m_musicStorageDir
Definition: cdrip.h:91
int m_quality
Definition: cdrip.h:237
MythUIButton * m_switchTitleArtist
Definition: cdrip.h:163
Dialog asking for user confirmation.
static long int getSectorCount(QString &cddevice, int tracknum)
Definition: cdrip.cpp:120
bool TranslateKeyPress(const QString &context, QKeyEvent *e, QStringList &actions, bool allowJumps=true)
Get a list of actions for a keypress in the given context.
void toggleTrackActive(MythUIButtonListItem *item)
Definition: cdrip.cpp:1362
MythUIText * m_trackPctText
Definition: cdrip.h:244
MythConfirmationDialog * ShowOkPopup(const QString &message, QObject *parent, const char *slot, bool showCancel)
Non-blocking version of MythPopupBox::showOkPopup()
void deleteAllExistingTracks(void)
Definition: cdrip.cpp:846
MythUIButton * m_searchGenreButton
Definition: cdrip.h:168
void customEvent(QEvent *event) override
Definition: cdrip.cpp:1537
void setYear(int lyear)
MusicMetadata * metadata
Definition: cdrip.h:52
bool IsActive(void) const
QString m_cdDevice
Definition: cdrip.h:238
void customEvent(QEvent *event) override
Definition: mythuitype.cpp:978
void SaveSetting(const QString &key, int newValue)
QString m_cdDevice
Definition: cdrip.h:180
void run() override
Runs the Qt event loop unless we have a QRunnable, in which case we run the runnable run instead.
Definition: cdrip.cpp:102
MythUIProgressBar * m_trackProgress
Definition: cdrip.h:246
QSqlQuery wrapper that fetches a DB connection from the connection pool.
Definition: mythdbcon.h:125
QString Genre() const
int getNumTracks()
Definition: cddecoder.cpp:449
CDRipperThread * m_ripperThread
Definition: cdrip.h:248
bool wait(unsigned long time=ULONG_MAX)
Wait for the MThread to exit, with a maximum timeout.
Definition: mthread.cpp:311
Basic menu dialog, message and a list of options.
int genre_table_size
Definition: genres.cpp:153
void setLength(int llength)
MythMediaDevice * GetMedia(const QString &path)
Get media device by pathname.
virtual void StartMonitoring(void)
Start the monitoring thread if needed.
static Type kTrackProgressEvent
Definition: cdrip.h:202
RipStatus * m_parent
Definition: cdrip.h:79
void SetFilter(InputFilter filter)
virtual void SetText(const QString &text)
Definition: mythuitext.cpp:135
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
Definition: cdrip.cpp:638
int GetItemPos(MythUIButtonListItem *item) const
~CDRipperThread() override
Definition: cdrip.cpp:186
void scanCD(void)
Definition: cdrip.cpp:830
static bool CopyFile(const QString &src, const QString &dst, bool overwrite=false, bool verify=false)
Definition: remotefile.cpp:586
static QStringList fillFieldList(const QString &field)
int Length() const
MythScreenStack * GetStack(const QString &stackname)
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
static Type kTrackStartEvent
Definition: cdrip.h:204
bool isNew
Definition: cdrip.h:55
void setFilename(const QString &lfilename)
MythScreenStack * GetMainStack()
bool Create(void) override
MusicMetadata * getMetadata(void)
Definition: cddecoder.cpp:537
void ShowMenu(void) override
Definition: cdrip.cpp:665
bool m_quit
Definition: cdrip.h:80
MythUIButton * m_scanButton
Definition: cdrip.h:164
static MythThemedMenu * menu
MythUICheckBox * m_compilationCheck
Definition: cdrip.h:158
InputFilter
static guint32 * tmp
Definition: goom_core.c:35
void ripFinished(void)
void BuildFocusList(void)
void setGenre(const QString &genre)
Definition: cdrip.cpp:1314
static Type kEventType
Definition: mythdialogbox.h:56
void setHostname(const QString &host)
QString m_year
Definition: cdrip.h:175
static QStringList getGroupDirs(const QString &groupname, const QString &host)
void StopMonitoring(void)
Stop the monitoring thread if needed.
void showEditMetadataDialog(void)
Definition: cdrip.cpp:687
static LCD * Get(void)
Definition: lcddevice.cpp:65
QString GetConfDir(void)
Definition: mythdirs.cpp:224
QVariant value(int i) const
Definition: mythdbcon.h:198
virtual void Close()
void startRipper(void)
Definition: cdrip.cpp:1097
void setCompilation(bool state)
QString Artist() const
MythUIButtonListItem * GetItemByData(const QVariant &data)
MythUIButton * m_searchAlbumButton
Definition: cdrip.h:167
void dumpToDatabase(void)
Ripper(MythScreenStack *parent, QString device)
Definition: cdrip.cpp:523
bool GetBooleanCheckState(void) const
void updateTrackList(void)
Definition: cdrip.cpp:1187
MythUITextEdit * m_yearEdit
Definition: cdrip.h:156
void ScanFinished(void)
Definition: cdrip.cpp:755
virtual void SetVisible(bool visible)
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
void EjectFinished(void)
Definition: cdrip.cpp:1153
void SetMaxLength(int length)
int m_lastOverallPct
Definition: cdrip.h:89
static Type kCopyStartEvent
Definition: cdrip.h:208
int ripTrack(QString &cddevice, Encoder *encoder, int tracknum)
Definition: cdrip.cpp:398
static Type kTrackPercentEvent
Definition: cdrip.h:203
void startRip(void)
Definition: cdrip.cpp:1631
static QString GenMythURL(const QString &host=QString(), int port=0, QString path=QString(), const QString &storageGroup=QString())
QString GetSetting(const QString &key, const QString &defaultval="")
void setDevice(const QString &dev)
Definition: cddecoder.cpp:107
static MediaMonitor * GetMediaMonitor(void)
void setAlbum(const QString &lalbum, const QString &lalbum_sort=nullptr)
bool isRunning(void) const
Definition: mthread.cpp:274
bool isActive(void) const
Definition: mythdbcon.h:204
QString m_albumName
Definition: cdrip.h:172
int m_lastTrackPct
Definition: cdrip.h:88
void SetReturnEvent(QObject *retobject, const QString &resultid)
void setAlbum(const QString &album)
Definition: cdrip.cpp:1285
CDEjectorThread * m_ejectThread
Definition: cdrip.h:182
int Track() const
void RipComplete(bool result)
Definition: cdrip.cpp:1120
void OpenBusyPopup(const QString &message="")
void artistChanged(void)
Definition: cdrip.cpp:947
bool m_mediaMonitorActive
Definition: cdrip.h:178
void SetTotal(int value)
void searchArtist(void)
Definition: cdrip.cpp:1242
QString m_artistName
Definition: cdrip.h:173
CDScannerThread * m_scanThread
Definition: cdrip.h:183
void metadataChanged(void)
Definition: cdrip.cpp:1347
QString GetMasterHostName(void)
MythUIButton * m_searchArtistButton
Definition: cdrip.h:166
bool Create(void) override
Definition: cdrip.cpp:1483
void run() override
Runs the Qt event loop unless we have a QRunnable, in which case we run the runnable run instead.
Definition: cdrip.cpp:111
bool somethingWasRipped()
Definition: cdrip.cpp:942
static MSqlQueryInfo InitCon(ConnectionReuse _reuse=kNormalConnection)
Only use this in combination with MSqlQuery constructor.
Definition: mythdbcon.cpp:535
QString Album() const
QString m_cdDevice
Definition: cdrip.h:81
void chooseBackend(void)
Definition: cdrip.cpp:692
void Unlock(MythMediaDevice *pMedia)
decrements the MythMediaDevices reference count
uint myth_system(const QString &command, uint flags, uint timeout)
bool isCancelled(void)
Definition: cdrip.cpp:197
void ejectCD(void)
Definition: cdrip.cpp:1161
MythUIText * m_trackText
Definition: cdrip.h:241
MythUIButtonList * m_trackList
Definition: cdrip.h:160
static Type kOverallProgressEvent
Definition: cdrip.h:205
void setTitle(const QString &ltitle, const QString &ltitle_sort=nullptr)
void albumChanged(void)
Definition: cdrip.cpp:976
static bool LoadWindowFromXML(const QString &xmlfile, const QString &windowname, MythUIType *parent)
bool active
Definition: cdrip.h:53
void SetText(const QString &text, bool moveCursor=true)
MythUIType * GetFocusWidget(void) const
QVector< RipTrack * > * m_tracks
Definition: cdrip.h:170
void setArtist(const QString &lartist, const QString &lartist_sort=nullptr)
void Reset() override
Reset the widget to it's original state, should not reset changes made by the theme.
virtual MythMediaError eject(bool open_close=true)
Definition: mythmedia.cpp:302
MythMainWindow * GetMythMainWindow(void)
long int m_totalSectors
Definition: cdrip.h:85
bool Compilation() const
void run(void) override
Runs the Qt event loop unless we have a QRunnable, in which case we run the runnable run instead.
Definition: cdrip.cpp:202
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
int GetNumSetting(const QString &key, int defaultval=0)
bool prepare(const QString &query)
QSqlQuery::prepare() is not thread safe in Qt <= 3.3.2.
Definition: mythdbcon.cpp:808
static Type kTrackTextEvent
Definition: cdrip.h:199
void genreChanged(void)
Definition: cdrip.cpp:993
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
int Year() const
void CloseBusyPopup(void)
bool ValidateAndLock(MythMediaDevice *pMedia)
Validates the MythMediaDevice and increments its reference count.
void searchGenre(void)
Definition: cdrip.cpp:1290
bool GetBoolSetting(const QString &key, bool defaultval=false)
void cancel(void)
Definition: cdrip.cpp:192
void setArtist(const QString &artist)
Definition: cdrip.cpp:1261
static Type kFinishedEvent
Definition: cdrip.h:210
QString Title() const
bool m_somethingwasripped
Definition: cdrip.h:177
QString m_musicStorageDir
Definition: cdrip.h:149
void setFileSize(uint64_t lfilesize)
void RunProlog(void)
Sets up a thread, call this if you reimplement run().
Definition: mthread.cpp:202
Definition: cdrip.h:50
int m_quality
Definition: cdrip.h:82
static Type kOverallPercentEvent
Definition: cdrip.h:206
QString m_genreName
Definition: cdrip.h:174
void start(QThread::Priority p=QThread::InheritPriority)
Tell MThread to start running the thread in the near future.
Definition: mthread.cpp:294
MythUIProgressBar * m_overallProgress
Definition: cdrip.h:245
MythUIText * m_overallPctText
Definition: cdrip.h:243
QThread * qthread(void)
Returns the thread, this will always return the same pointer no matter how often you restart the thre...
Definition: mthread.cpp:244
const char * genre_table[]
Definition: genres.cpp:1
MythUIButton * m_ripButton
Definition: cdrip.h:165
void SetCheckState(MythUIStateType::StateType state)
Definition: lcddevice.h:169
MythUIText * m_overallText
Definition: cdrip.h:240
void ShowConflictMenu(RipTrack *track)
Definition: cdrip.cpp:1391
CdDecoder * m_decoder
Definition: cdrip.h:151
static Type kStatusTextEvent
Definition: cdrip.h:201
QVector< RipTrack * > * m_tracks
Definition: cdrip.h:83
QVector< RipTrack * > * m_tracks
Definition: cdrip.h:236
QString CompilationArtist() const
~RipStatus(void) override
Definition: cdrip.cpp:1476
virtual int addSamples(int16_t *bytes, unsigned int len)=0
bool exec(void)
Wrap QSqlQuery::exec() so we can display SQL.
Definition: mythdbcon.cpp:603
void setSaveHost(const QString &host)
Definition: cdrip.cpp:733
void compilationChanged(bool state)
Definition: cdrip.cpp:1027
static Type kOverallTextEvent
Definition: cdrip.h:200
static void DBError(const QString &where, const MSqlQuery &query)
Definition: mythdb.cpp:179
Screen in which all other widgets are contained and rendered.
bool isNewTune(const QString &artist, const QString &album, const QString &title)
try to find a track in the db using the given artist, album and title
Definition: musicutils.cpp:139
static Type kOverallStartEvent
Definition: cdrip.h:207
QString filenameFromMetadata(MusicMetadata *track)
create a filename using the template in the settings and a MusicMetadata object
Definition: musicutils.cpp:77
MythUIText * m_statusText
Definition: cdrip.h:242
long int m_totalSectorsDone
Definition: cdrip.h:86
bool deleteExistingTrack(RipTrack *track)
Definition: cdrip.cpp:862
void setCompilationArtist(const QString &lcompilation_artist, const QString &lcompilation_artist_sort=nullptr)
MythUIType * GetChild(const QString &name) const
Get a named child of this UIType.
Definition: mythuitype.cpp:130
static Type kEncoderErrorEvent
Definition: cdrip.h:211
void Result(bool)
QStringList m_searchList
Definition: cdrip.h:176
void startScanCD(void)
Definition: cdrip.cpp:742
void setChecked(CheckState state)
Provide a dialog to quickly find an entry in a list.
QString GetText(void) const
int length
Definition: cdrip.h:54
bool Create(void) override
Definition: cdrip.cpp:576
MythUIButtonListItem * GetItemCurrent() const
void SetValueByData(const QVariant &data)
CDRipperThread(RipStatus *parent, QString device, QVector< RipTrack * > *tracks, int quality)
Definition: cdrip.cpp:168
static Type kCopyEndEvent
Definition: cdrip.h:209
void customEvent(QEvent *event) override
Definition: cdrip.cpp:1435
MythUIButtonList * m_qualityList
Definition: cdrip.h:161
void setGenre(const QString &lgenre)
void yearChanged(void)
Definition: cdrip.cpp:1010