Nenhuma descrição

movie.cpp 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. #include "movie.h"
  2. string getMovieByPosition(int position, filemanip &file){
  3. int counter = 0 ;
  4. //Input Validation
  5. if (position < 1){
  6. return "" ;
  7. }
  8. file.reset();
  9. QString line = file.getnext() ;
  10. while(line != ""){
  11. if (counter == position){
  12. return line.toStdString() ;
  13. }
  14. line = file.getnext() ;
  15. counter++ ;
  16. }
  17. return "" ;
  18. }
  19. string getMovieByName(string moviename, filemanip &file){
  20. QString movie = QString::fromStdString(moviename) ;
  21. QStringList fields ;
  22. file.reset();
  23. QString line = file.getnext() ;
  24. while(line != "") {
  25. fields = line.split("|");
  26. if (fields[0] == movie){
  27. return line.toStdString() ;
  28. }
  29. line = file.getnext() ;
  30. }
  31. return "" ;
  32. }
  33. void showMovie(string movieinfo){
  34. QStringList fields = QString::fromStdString(movieinfo).split('|') ;
  35. if(fields.size() >= 15){
  36. cout << "==================== MOVIE =======================" <<endl
  37. << "Name:\t" << fields[0].toStdString() <<endl
  38. << "Rating:\t" << fields[7].toStdString() << endl
  39. << "Year:\t" << fields[8].toStdString() <<endl
  40. << "Genre:\t" << fields[9].toStdString() <<endl ;
  41. }
  42. }
  43. void showMovies(filemanip &file, int start, int end){
  44. int counter = 0;
  45. if(start < 1 || end < start)
  46. return ;
  47. file.reset();
  48. QString line = file.getnext() ;
  49. while(line != "") {
  50. if(counter >= start && counter <=end){
  51. showMovie(line.toStdString()) ;
  52. }
  53. line = file.getnext() ;
  54. counter++ ;
  55. }
  56. }
  57. void showMovies(filemanip &file, string keyword){
  58. QStringList fields ;
  59. if(keyword.size() < 1)
  60. return ;
  61. file.reset();
  62. QString line = file.getnext() ;
  63. while(line != "") {
  64. fields = line.split('|') ;
  65. if(fields[0].contains(QString::fromStdString(keyword), Qt::CaseInsensitive)){
  66. showMovie(line.toStdString()) ;
  67. }
  68. line = file.getnext() ;
  69. }
  70. }
  71. string getMovieName(string movieinfo){
  72. QStringList fields = QString::fromStdString(movieinfo).split('|') ;
  73. if (fields.size() >= 15)
  74. return fields[0].toStdString() ;
  75. return "" ;
  76. }
  77. string getMovieRating(string movieinfo){
  78. QStringList fields = QString::fromStdString(movieinfo).split('|') ;
  79. if (fields.size() >= 15)
  80. return fields[7].toStdString() ;
  81. return "" ;
  82. }
  83. string getMovieYear(string movieinfo){
  84. QStringList fields = QString::fromStdString(movieinfo).split('|') ;
  85. if (fields.size() >= 15)
  86. return fields[8].toStdString() ;
  87. return "" ;
  88. }
  89. string getMovieGenre(string movieinfo){
  90. QStringList fields = QString::fromStdString(movieinfo).split('|') ;
  91. if (fields.size() >= 15)
  92. return fields[9].toStdString() ;
  93. return "" ;
  94. }
  95. void getMovieInfo(string movieinfo, string &rating, string &year, string &genre){
  96. QStringList fields = QString::fromStdString(movieinfo).split('|') ;
  97. if (fields.size() >= 15){
  98. rating = fields[7].toStdString() ;
  99. year = fields[8].toStdString() ;
  100. genre = fields[9].toStdString() ;
  101. }
  102. return ;
  103. }