PageRenderTime 38ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/client/src/GUI/searchwidget.cpp

https://github.com/epibobby/Bol.os
C++ | 82 lines | 74 code | 7 blank | 1 comment | 19 complexity | 943a6ac28bcb2ebf226da71742777ef0 MD5 | raw file
  1. #include "searchwidget.h"
  2. #include "ui_searchwidget.h"
  3. SearchWidget::SearchWidget(QTabWidget *tab, MyIRC *irc, ApiMovie *api, QWidget *parent) : _tab(tab), _irc(irc),
  4. _api(api),
  5. QWidget(parent),
  6. ui(new Ui::SearchWidget)
  7. {
  8. _listMovies = new ListMovies(_api);
  9. ui->setupUi(this);
  10. connect(_api, SIGNAL(found(QList<QMap<QString, QString> >)), this, SLOT(IncomingSheet(QList<QMap<QString, QString> >)));
  11. }
  12. void SearchWidget::IncomingSheet(QList<QMap<QString, QString> > list)
  13. {
  14. Sheet sheet;
  15. QList<InfoMovies> list2;
  16. while(!list.isEmpty())
  17. {
  18. InfoMovies tmp;
  19. QMap<QString,QString> map = list.first();
  20. list.pop_front();
  21. QMapIterator<QString, QString> i(map);
  22. while (i.hasNext()) {
  23. i.next();
  24. if (i.key() == "original_name") {
  25. sheet.title = i.value();
  26. tmp.title = i.value();
  27. }
  28. else if (i.key() == "id")
  29. tmp.id = i.value();
  30. else if (i.key() == "overview")
  31. sheet.summary = i.value();
  32. else if (i.key() == "trailer") {
  33. this->trailer = i.value();
  34. }
  35. else if (i.key() == "tagline") {
  36. ui->Title2->setText(i.value());
  37. }
  38. qDebug() << i.key() << ": " << i.value() << endl;
  39. }
  40. if (tmp.id != 0)
  41. list2.append(tmp);
  42. }
  43. //Si resultats > 1 afficher la liste sinon afficher direct la fiche
  44. if (list2.length() > 1) {
  45. _listMovies->AddListMovies(list2);
  46. _listMovies->show();
  47. }
  48. else {
  49. _listMovies->hide();
  50. ui->SumUpMovieText->setFont (QFont("Arial", 15));
  51. UpdateMovie(sheet);
  52. }
  53. }
  54. void SearchWidget::UpdateMovie(Sheet sheet)
  55. {
  56. ui->Title->setText(sheet.title);
  57. ui->SumUpMovieText->setText(sheet.summary);
  58. }
  59. SearchWidget::~SearchWidget()
  60. {
  61. delete ui;
  62. }
  63. void SearchWidget::on_Search_clicked()
  64. {
  65. _api->requestASheet(ui->SearchMovie->text());
  66. }
  67. void SearchWidget::on_PlayTrailer_clicked()
  68. {
  69. QDesktopServices::openUrl(QUrl(this->trailer));
  70. }
  71. void SearchWidget::on_JoinChannel_clicked()
  72. {
  73. _irc->getController()->getSession()->sendCommand(_irc->getController()->getInputHandler()->createChan("#" + ui->Title->text().replace(' ', '-')));
  74. _tab->setCurrentIndex(4);
  75. }