Guest User

Untitled

a guest
Jun 22nd, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. #include "ClipScanner.h"
  2. #include <QDebug>
  3.  
  4. #define SCAN_TIMEOUT 500
  5.  
  6. ClipScanner *ClipScanner::m_instance = 0;
  7. ClipScanner *ClipScanner::instance()
  8. {
  9. if (!m_instance)
  10. m_instance = new ClipScanner;
  11. return m_instance;
  12. }
  13.  
  14. ClipScanner::ClipScanner()
  15. : m_hbHandle(0)
  16. {
  17. connect(&m_scanTimer, SIGNAL(timeout()), this, SLOT(checkScan()));
  18. }
  19.  
  20. void ClipScanner::setHandle(hb_handle_t *handle)
  21. {
  22. m_hbHandle = handle;
  23. }
  24.  
  25. void ClipScanner::scanClips(const QStringList &clips)
  26. {
  27. m_clipsToScan << clips;
  28.  
  29. if (!m_scanTimer.isActive())
  30. scanNextClip();
  31. }
  32.  
  33. void ClipScanner::checkScan()
  34. {
  35. if (!m_hbHandle) {
  36. m_scanTimer.stop();
  37. return;
  38. }
  39.  
  40. hb_state_t s;
  41. hb_get_state( m_hbHandle, &s );
  42.  
  43. switch (s.state)
  44. {
  45. case HB_STATE_IDLE:
  46. m_scanTimer.stop();
  47. break;
  48.  
  49. case HB_STATE_SCANDONE:
  50. {
  51. hb_list_t *list = 0;
  52. hb_title_t *title = 0;
  53.  
  54. list = (hb_list_t *) hb_get_titles( m_hbHandle );
  55.  
  56. if( !hb_list_count( list ) )
  57. {
  58. /* No valid title, stop right there */
  59. qDebug() << "No title found.";
  60. break;
  61. } else {
  62. title = (hb_title_t *) hb_list_item( list, 0 );
  63. }
  64.  
  65. if (title)
  66. qDebug() << "got it";
  67.  
  68. }
  69. case HB_STATE_WORKING:
  70. qDebug() << "hb state: WORKING...";
  71. break;
  72.  
  73. default:
  74. break;
  75. }
  76.  
  77.  
  78.  
  79. /*
  80. if (s.state != HB_STATE_SCANNING) {
  81. m_scanTimer.stop();
  82.  
  83. if (s.state == HB_STATE_SCANDONE) {
  84. hb_list_t *list = hb_get_titles( m_hbHandle );
  85. if (!hb_list_count(list))
  86. qDebug() << "No valid source found for clip";
  87. else {
  88. hb_title_t *title = (hb_title_t *) hb_list_item( list, 0 );
  89.  
  90. VideoClip clip = VideoClip::createFromTitle(m_currentClipPath, title);
  91. emit clipScanned(clip);
  92. }
  93. }
  94.  
  95. QTimer::singleShot(500, this, SLOT(scanNextClip()));
  96. }
  97. */
  98. }
  99.  
  100. void ClipScanner::scanNextClip()
  101. {
  102. if (m_clipsToScan.isEmpty()) {
  103. m_currentClipPath = QString();
  104. m_scanTimer.stop();
  105. } else {
  106. m_currentClipPath = m_clipsToScan.takeFirst();
  107. hb_scan( m_hbHandle, m_currentClipPath.toUtf8(), 1, 0, 0 );
  108. m_scanTimer.start(SCAN_TIMEOUT);
  109. }
  110. }
Add Comment
Please, Sign In to add comment