bookunrarqueuethread.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #include "bookunrarqueuethread.h"
  2. BookUnrarQueueThread::BookUnrarQueueThread(QueueType type):
  3. m_type(type)
  4. {
  5. m_canProceed = false;
  6. }
  7. void BookUnrarQueueThread::append(Book* book)
  8. {
  9. switch(m_type){
  10. case PageName:{
  11. m_nameQueue.append(book);
  12. if(!this->isRunning())
  13. this->start();
  14. }break;
  15. case PageImage:{
  16. m_imageQueue.append(book);
  17. if(!this->isRunning())
  18. this->start();
  19. }break;
  20. }
  21. }
  22. void BookUnrarQueueThread::run()
  23. {
  24. switch(m_type){
  25. case PageName:{
  26. while(!m_nameQueue.isEmpty()){
  27. if(m_canProceed){
  28. emit queueNext(m_nameQueue.takeFirst());
  29. m_canProceed = false;
  30. }
  31. msleep(100);
  32. }
  33. }break;
  34. case PageImage:{
  35. while(!m_imageQueue.isEmpty()){
  36. if(m_canProceed){
  37. emit queueNext(m_imageQueue.takeFirst());
  38. m_canProceed = false;
  39. }
  40. msleep(100);
  41. }
  42. }break;
  43. default:break;
  44. }
  45. }
  46. void BookUnrarQueueThread::next()
  47. {
  48. m_canProceed = true;
  49. }
  50. bool BookUnrarQueueThread::haveItems()
  51. {
  52. bool ret(false);
  53. switch(m_type){
  54. case PageName:{
  55. if(!m_nameQueue.isEmpty())
  56. ret = true;
  57. }break;
  58. case PageImage:{
  59. if(!m_imageQueue.isEmpty()){
  60. ret = true;
  61. }
  62. }break;
  63. default:break;
  64. }
  65. return ret;
  66. }