From 7a29d1d26da9c5f98e2a598ba84bdd033385a346 Mon Sep 17 00:00:00 2001 From: Herwig Birke Date: Wed, 18 Oct 2017 13:11:26 +0200 Subject: [PATCH] . --- cmainwindow.cpp | 196 ++++++++++++++++++++++++++++++--------- cmainwindow.h | 13 +++ cmainwindow.ui | 26 +++++- cmovie.cpp | 230 ++++++++++++++++++++++++++++++++++++++++++++++ cmovie.h | 90 ++++++++++++++++++ cmoviesearch.cpp | 89 ++++++++++++++++++ cmoviesearch.h | 33 +++++++ cmoviesearch.ui | 180 ++++++++++++++++++++++++++++++++++++ csearch.h | 1 + cthemoviedbv3.cpp | 128 ++++++++++++++++++++------ cthemoviedbv3.h | 2 +- cupdatethread.cpp | 9 +- cupdatethread.h | 6 +- qtMovies.pro | 9 +- 14 files changed, 926 insertions(+), 86 deletions(-) create mode 100644 cmoviesearch.cpp create mode 100644 cmoviesearch.h create mode 100644 cmoviesearch.ui diff --git a/cmainwindow.cpp b/cmainwindow.cpp index 33bd151..3de18de 100644 --- a/cmainwindow.cpp +++ b/cmainwindow.cpp @@ -4,6 +4,7 @@ #include "cthetvdbv2.h" #include "cseasondelegate.h" #include "csearch.h" +#include "cmoviesearch.h" #include "cmessageanimatedialog.h" #include "cmessagedialog.h" #include "cedit.h" @@ -579,52 +580,27 @@ void cMainWindow::displaySeries() void cMainWindow::on_m_lpSeriesList1_customContextMenuRequested(const QPoint &pos) { - QMenu* lpMenu = new QMenu(this); - - lpMenu->addAction("add", this, SLOT(onActionAdd())); - - if(ui->m_lpSeriesList1->selectionModel()->selectedRows().count() == 1) - { - cSerie* lpSerie = m_lpSeriesListModel->itemFromIndex(ui->m_lpSeriesList1->selectionModel()->selectedRows().at(0))->data(Qt::UserRole).value(); - if(lpSerie) - { - lpMenu->addAction("update", this, SLOT(onActionUpdate())); - lpMenu->addAction("delete", this, SLOT(onActionDelete())); - lpMenu->addAction("edit", this, SLOT(onActionEdit())); - lpMenu->addSeparator(); - - if(!lpSerie->imdbID().isEmpty()) - lpMenu->addAction("open IMDB", this, SLOT(onActionGotoIMDB())); - - if(!lpSerie->download().isEmpty()) - { - lpMenu->addAction("open download link", this, SLOT(onActionGotoDownload())); - lpMenu->addAction("copy download link", this, SLOT(onActionCopyDownload())); - } - lpMenu->addSeparator(); - lpMenu->addAction("load images", this, SLOT(onActionLoadPictures())); - } - } - else if(ui->m_lpSeriesList1->selectionModel()->selectedRows().count()) - { - lpMenu->addAction("update", this, SLOT(onActionUpdate())); - lpMenu->addAction("delete", this, SLOT(onActionDelete())); - lpMenu->addSeparator(); - lpMenu->addAction("load images", this, SLOT(onActionLoadPictures())); - } - - lpMenu->popup(ui->m_lpSeriesList1->viewport()->mapToGlobal(pos)); + showSeriesContextMenu(ui->m_lpSeriesList1, pos); } void cMainWindow::on_m_lpSeriesList2_customContextMenuRequested(const QPoint &pos) +{ + showSeriesContextMenu(ui->m_lpSeriesList2, pos); +} + +void cMainWindow::showSeriesContextMenu(QTreeView* lpTreeView, const QPoint &pos) { QMenu* lpMenu = new QMenu(this); lpMenu->addAction("add", this, SLOT(onActionAdd())); - if(ui->m_lpSeriesList2->selectionModel()->selectedRows().count() == 1) + lpMenu->addAction("update all", this, SLOT(onActionUpdateAll())); + lpMenu->addAction("update unfinished", this, SLOT(onActionUpdateUnfinished())); + lpMenu->addSeparator(); + + if(lpTreeView->selectionModel()->selectedRows().count() == 1) { - cSerie* lpSerie = m_lpSeriesListModel->itemFromIndex(ui->m_lpSeriesList2->selectionModel()->selectedRows().at(0))->data(Qt::UserRole).value(); + cSerie* lpSerie = m_lpSeriesListModel->itemFromIndex(lpTreeView->selectionModel()->selectedRows().at(0))->data(Qt::UserRole).value(); if(lpSerie) { lpMenu->addAction("update", this, SLOT(onActionUpdate())); @@ -644,15 +620,29 @@ void cMainWindow::on_m_lpSeriesList2_customContextMenuRequested(const QPoint &po lpMenu->addAction("load images", this, SLOT(onActionLoadPictures())); } } - else if(ui->m_lpSeriesList2->selectionModel()->selectedRows().count()) + else if(lpTreeView->selectionModel()->selectedRows().count()) { - lpMenu->addAction("update", this, SLOT(onActionUpdate())); - lpMenu->addAction("delete", this, SLOT(onActionDelete())); + lpMenu->addAction("update selected", this, SLOT(onActionUpdate())); + lpMenu->addAction("delete selected", this, SLOT(onActionDelete())); lpMenu->addSeparator(); lpMenu->addAction("load images", this, SLOT(onActionLoadPictures())); } - lpMenu->popup(ui->m_lpSeriesList2->viewport()->mapToGlobal(pos)); + lpMenu->popup(lpTreeView->viewport()->mapToGlobal(pos)); +} + +void cMainWindow::on_m_lpMoviesList_customContextMenuRequested(const QPoint &pos) +{ + showMoviesContextMenu(ui->m_lpMoviesList, pos); +} + +void cMainWindow::showMoviesContextMenu(QTreeView* lpTreeView, const QPoint &pos) +{ + QMenu* lpMenu = new QMenu(this); + + lpMenu->addAction("add", this, SLOT(onActionMovieAdd())); + + lpMenu->popup(lpTreeView->viewport()->mapToGlobal(pos)); } static bool serieSort(cSerie* s1, cSerie* s2) @@ -811,9 +801,127 @@ void cMainWindow::onActionAdd() delete lpDialog; } +void cMainWindow::onActionMovieAdd() +{ + cMovieSearch* lpSearch = new cMovieSearch(this); + if(lpSearch->exec() == QDialog::Rejected) + { + delete lpSearch; + return; + } + + + qint32 id = lpSearch->id(); + QString szPlaceholder = lpSearch->placeholderName(); + bool bPlaceholder = lpSearch->placeholder(); + qint16 iYear = lpSearch->year(); + + delete lpSearch; + + cMovie* lpMovie = 0; + + cMessageAnimateDialog* lpDialog = new cMessageAnimateDialog(this); + lpDialog->setTitle("Refresh"); + lpDialog->setMessage("Loading"); + lpDialog->show(); + + if(!bPlaceholder) + { + if(id == -1) + return; + + cTheMovieDBV3 movieDB3; + + lpMovie = movieDB3.load(id, "de"); + if(!lpMovie) + lpMovie = movieDB3.load(id, "en"); + + delete lpDialog; +/* + QString szDownload; + if(!runEdit(lpSerie, szDownload)) + return; + + lpDialog = new cMessageAnimateDialog(this); + lpDialog->setTitle("Update"); + lpDialog->setMessage("Updating"); + lpDialog->show(); + + lpSerie->save(m_db); +*/ + } + else + { +/* + lpSerie = new cSerie; + lpSerie->setSeriesName(szPlaceholder); + + qint32 iMax = 0; + QSqlQuery query; + if(query.exec("SELECT MAX(id) FROM serie;")) + { + query.next(); + if(query.isValid()) + iMax = query.value(0).toInt(); + } + if(iMax < 1000000) + iMax = 1000000; + else + iMax++; + lpSerie->setID(iMax); + lpSerie->setFirstAired(QDate(iYear, 1, 1)); + lpSerie->save(m_db); +*/ + } +/* + m_serieList.add(lpSerie); + std::sort(m_serieList.begin(), m_serieList.end(), serieSort); + + m_szOldSelected = lpSerie->seriesName(); + displaySeries(); + + delete lpDialog; +*/ +} + +void cMainWindow::onActionUpdateAll() +{ + cSerieList serieList = m_serieList; + + if(serieList.count()) + doUpdate(serieList); +} + +void cMainWindow::onActionUpdateUnfinished() +{ + cSerieList serieList; + + for(int x = 0;x < m_serieList.count();x++) + { + cSerie* lpSerie = m_serieList.at(x); + if(lpSerie->status().compare("Ended", Qt::CaseInsensitive)) + serieList.add(lpSerie); + } + if(serieList.count()) + doUpdate(serieList); +} + void cMainWindow::onActionUpdate() { - if(ui->m_lpSeriesList1->selectionModel()->selectedRows().count()) + cSerieList serieList; + + for(int x = 0;x < ui->m_lpSeriesList1->selectionModel()->selectedRows().count();x++) + { + cSerie* lpSerie = ui->m_lpSeriesList1->selectionModel()->selectedRows().at(x).data(Qt::UserRole).value(); + serieList.add(lpSerie); + } + if(serieList.count()) + doUpdate(serieList); +} + +void cMainWindow::doUpdate(cSerieList& serieList) +{ + if(serieList.count()) { if(ui->m_lpSeriesList1->selectionModel()->selectedRows().count() == 1) m_szOldSelected = m_lpSeriesListModel->itemFromIndex(ui->m_lpSeriesList1->selectionModel()->selectedIndexes().at(1))->text(); @@ -821,11 +929,11 @@ void cMainWindow::onActionUpdate() m_lpMessageDialog = new cMessageDialog(this); m_lpMessageDialog->setWindowTitle("Update"); m_lpMessageDialog->setMessage("Updating"); - m_lpMessageDialog->setProgress(0, ui->m_lpSeriesList1->selectionModel()->selectedRows().count()); + m_lpMessageDialog->setProgress(0, serieList.count()); m_lpMessageDialog->show(); m_lpUpdateThread = new cUpdateThread; - m_lpUpdateThread->setData(m_lpMessageDialog, ui->m_lpSeriesList1->selectionModel()->selectedRows(), m_db); + m_lpUpdateThread->setData(m_lpMessageDialog, serieList, m_db); connect(m_lpUpdateThread, SIGNAL(finished()), this, SLOT(updateDone())); connect(m_lpUpdateThread, SIGNAL(updateMessage(QString,qint32)), this, SLOT(updateMessage(QString,qint32))); diff --git a/cmainwindow.h b/cmainwindow.h index 521c9cd..c494fc1 100644 --- a/cmainwindow.h +++ b/cmainwindow.h @@ -19,6 +19,8 @@ #include #include +#include + namespace Ui { class cMainWindow; @@ -42,7 +44,11 @@ private slots: void on_m_lpSeriesList2_doubleClicked(const QModelIndex &index); void on_m_lpSeriesList2_pressed(const QModelIndex &index); + void on_m_lpMoviesList_customContextMenuRequested(const QPoint &pos); + void onActionAdd(); + void onActionUpdateAll(); + void onActionUpdateUnfinished(); void onActionUpdate(); void onActionDelete(); void onActionEdit(); @@ -51,6 +57,8 @@ private slots: void onActionCopyDownload(); void onActionLoadPictures(); + void onActionMovieAdd(); + void updateMessage(const QString& szMessage, const qint32 &iProgress); void updateAppendMessage(const QString& szMessage); void updateDone(); @@ -91,6 +99,11 @@ private: void displaySeries(); bool runEdit(cSerie *lpSerie, QString& szDownload); + + void showSeriesContextMenu(QTreeView* lpTreeView, const QPoint &pos); + void doUpdate(cSerieList& serieList); + + void showMoviesContextMenu(QTreeView* lpTreeView, const QPoint &pos); protected: void closeEvent(QCloseEvent *event); }; diff --git a/cmainwindow.ui b/cmainwindow.ui index 7bd1311..cca44c3 100644 --- a/cmainwindow.ui +++ b/cmainwindow.ui @@ -18,7 +18,7 @@ - 0 + 1 @@ -114,6 +114,30 @@ Movies + + + + + Qt::CustomContextMenu + + + QAbstractItemView::NoEditTriggers + + + true + + + QAbstractItemView::ExtendedSelection + + + false + + + true + + + + diff --git a/cmovie.cpp b/cmovie.cpp index 5462ffe..1cf66b6 100644 --- a/cmovie.cpp +++ b/cmovie.cpp @@ -45,3 +45,233 @@ QDate cMovie::releaseDate() { return(m_releaseDate); } + +void cMovie::setAdult(const bool bAdult) +{ + m_bAdult = bAdult; +} + +bool cMovie::adult() +{ + return(m_bAdult); +} + +void cMovie::setBackdropPath(const QString& szBackdropPath) +{ + m_szBackdropPath = szBackdropPath; +} + +QString cMovie::backdropPath() +{ + return(m_szBackdropPath); +} + +void cMovie::setBelongsToCollection(const QString& szBelongsToCollection) +{ + m_szBelongsToCollection = szBelongsToCollection; +} + +QString cMovie::belongsToCollection() +{ + return(m_szBelongsToCollection); +} + +void cMovie::setButget(const qreal dBudget) +{ + m_dBudget = dBudget; +} + +qreal cMovie::budget() +{ + return(m_dBudget); +} + +void cMovie::setGenres(const QString& szGenres) +{ + m_szGenres = szGenres.split(","); +} + +void cMovie::setGenres(const QStringList& szGenres) +{ + m_szGenres = szGenres; +} + +QStringList cMovie::genres() +{ + return(m_szGenres); +} + +void cMovie::setHomepage(const QString& szHomepage) +{ + m_szHomepage = szHomepage; +} + +QString cMovie::homepage() +{ + return(m_szHomepage); +} + +void cMovie::setIMDBID(const QString &szIMDBID) +{ + m_szIMDBID = szIMDBID; +} + +QString cMovie::imdbID() +{ + return(m_szIMDBID); +} + +void cMovie::setOriginalLanguage(const QString& szOriginalLanguage) +{ + m_szOriginalLanguage = szOriginalLanguage; +} + +QString cMovie::originalLanguage() +{ + return(m_szOriginalLanguage); +} + +void cMovie::setOverview(const QString& szOverview) +{ + m_szOverview = szOverview; +} + +QString cMovie::overview() +{ + return(m_szOverview); +} + +void cMovie::setPopularity(const qreal dPopularity) +{ + m_dPopularity = dPopularity; +} + +qreal cMovie::popularity() +{ + return(m_dPopularity); +} + +void cMovie::setPosterPath(const QString& szPosterPath) +{ + m_szPosterPath = szPosterPath; +} + +QString cMovie::posterPath() +{ + return(m_szPosterPath); +} + +void cMovie::setProductionCompanies(const QString& szProductionCompanies) +{ + m_szProductionCompanies = szProductionCompanies.split(","); +} + +void cMovie::setProductionCompanies(const QStringList& szProductionCompanies) +{ + m_szProductionCompanies = szProductionCompanies; +} + +QStringList cMovie::productionCompanies() +{ + return(m_szProductionCompanies); +} + +void cMovie::setProductionCountries(const QString& szProductionCountries) +{ + m_szProductionCountries = szProductionCountries.split(","); +} + +void cMovie::setProductionCountries(const QStringList& szProductionCountries) +{ + m_szProductionCountries = szProductionCountries; +} + +QStringList cMovie::productionCountries() +{ + return(m_szProductionCountries); +} + +void cMovie::setRevenue(const qreal dRevenue) +{ + m_dRevenue = dRevenue; +} + +qreal cMovie::revenue() +{ + return(m_dRevenue); +} + +void cMovie::setRuntime(const qint32 iRuntime) +{ + m_iRuntime = iRuntime; +} + +qint32 cMovie::runtime() +{ + return(m_iRuntime); +} + +void cMovie::setSpokenLanguages(const QString& szSpokenLanguages) +{ + m_szSpokenLanguages = szSpokenLanguages.split(","); +} + +void cMovie::setSpokenLanguages(const QStringList& szSpokenLanguages) +{ + m_szSpokenLanguages = szSpokenLanguages; +} + +QStringList cMovie::spokenLanguages() +{ + return(m_szSpokenLanguages); +} + +void cMovie::setStatus(const QString& szStatus) +{ + m_szStatus = szStatus; +} + +QString cMovie::status() +{ + return(m_szStatus); +} + +void cMovie::setTagline(const QString& szTagline) +{ + m_szTagline = szTagline; +} + +QString cMovie::tagline() +{ + return(m_szTagline); +} + +void cMovie::setVideo(const bool bVideo) +{ + m_bVideo = bVideo; +} + +bool cMovie::video() +{ + return(m_bVideo); +} + +void cMovie::setVoteAverage(const qreal dVoteAverage) +{ + m_dVoteAverage = dVoteAverage; +} + +qreal cMovie::voteAverage() +{ + return(m_dVoteAverage); +} + +void cMovie::setVoteCount(const qint32 iVoteCount) +{ + m_iVoteCount = iVoteCount; +} + +qint32 cMovie::voteCount() +{ + return(m_iVoteCount); +} diff --git a/cmovie.h b/cmovie.h index 08e5a2a..1e9a586 100644 --- a/cmovie.h +++ b/cmovie.h @@ -5,6 +5,7 @@ #include #include #include +#include class cMovie @@ -23,11 +24,100 @@ public: void setReleaseDate(const QString& szDate); QDate releaseDate(); + + void setAdult(const bool bAdult); + bool adult(); + + void setBackdropPath(const QString& szBackdropPath); + QString backdropPath(); + + void setBelongsToCollection(const QString& szBelongsToCollection); + QString belongsToCollection(); + + void setButget(const qreal dBudget); + qreal budget(); + + void setGenres(const QString& szGenres); + void setGenres(const QStringList& szGenres); + QStringList genres(); + + void setHomepage(const QString& szHomepage); + QString homepage(); + + void setIMDBID(const QString& szIMDBID); + QString imdbID(); + + void setOriginalLanguage(const QString& szOriginalLanguage); + QString originalLanguage(); + + void setOverview(const QString& szOverview); + QString overview(); + + void setPopularity(const qreal dPopularity); + qreal popularity(); + + void setPosterPath(const QString& szPosterPath); + QString posterPath(); + + void setProductionCompanies(const QString& szProductionCompanies); + void setProductionCompanies(const QStringList& szProductionCompanies); + QStringList productionCompanies(); + + void setProductionCountries(const QString& szProductionCountries); + void setProductionCountries(const QStringList& szProductionCountries); + QStringList productionCountries(); + + void setRevenue(const qreal dRevenue); + qreal revenue(); + + void setRuntime(const qint32 iRuntime); + qint32 runtime(); + + void setSpokenLanguages(const QString& szSpokenLanguages); + void setSpokenLanguages(const QStringList& szSpokenLanguages); + QStringList spokenLanguages(); + + void setStatus(const QString& szStatus); + QString status(); + + void setTagline(const QString& szTagline); + QString tagline(); + + void setVideo(const bool bVideo); + bool video(); + + void setVoteAverage(const qreal dVoteAverage); + qreal voteAverage(); + + void setVoteCount(const qint32 iVoteCount); + qint32 voteCount(); private: QString m_szMovieTitle; qint32 m_iID; QString m_szOriginalTitle; QDate m_releaseDate; + + bool m_bAdult; + QString m_szBackdropPath; + QString m_szBelongsToCollection; + qreal m_dBudget; + QStringList m_szGenres; + QString m_szHomepage; + QString m_szIMDBID; + QString m_szOriginalLanguage; + QString m_szOverview; + qreal m_dPopularity; + QString m_szPosterPath; + QStringList m_szProductionCompanies; + QStringList m_szProductionCountries; + qreal m_dRevenue; + qint32 m_iRuntime; + QStringList m_szSpokenLanguages; + QString m_szStatus; + QString m_szTagline; + bool m_bVideo; + qreal m_dVoteAverage; + qint32 m_iVoteCount; }; Q_DECLARE_METATYPE(cMovie*) diff --git a/cmoviesearch.cpp b/cmoviesearch.cpp new file mode 100644 index 0000000..5771ad2 --- /dev/null +++ b/cmoviesearch.cpp @@ -0,0 +1,89 @@ +#include "cmoviesearch.h" +#include "ui_cmoviesearch.h" + +#include "cthemoviedbv3.h" + +#include "cmovie.h" +#include "cmessageanimatedialog.h" + +#include + + + +cMovieSearch::cMovieSearch(QWidget *parent) : + QDialog(parent), + ui(new Ui::cMovieSearch) +{ + ui->setupUi(this); + ui->m_lpSearchButton->setEnabled(false); + ui->m_lpTabWidget->setCurrentIndex(0); +} + +cMovieSearch::~cMovieSearch() +{ + delete ui; +} + +void cMovieSearch::on_m_lpSearch_textChanged(const QString &arg1) +{ + if(ui->m_lpSearch->text().isEmpty()) + ui->m_lpSearchButton->setEnabled(false); + else + ui->m_lpSearchButton->setEnabled(true); +} + +void cMovieSearch::on_m_lpSearchButton_clicked() +{ + cMessageAnimateDialog* lpDialog = new cMessageAnimateDialog(this); + lpDialog->setTitle("Search"); + lpDialog->setMessage("Searching"); + lpDialog->show(); + + cTheMovieDBV3 theMovieDBV3; + QList movieList = theMovieDBV3.search(ui->m_lpSearch->text()); + + ui->m_lpResults->clear(); + + for(int z = 0;z < movieList.count();z++) + { + cMovie* lpMovie = movieList.at(z); + QTreeWidgetItem* lpNew = new QTreeWidgetItem(ui->m_lpResults); + lpNew->setText(0, lpMovie->movieTitle()); + lpNew->setText(2, QString("%1").arg(lpMovie->releaseDate().year())); + lpNew->setData(0, Qt::UserRole, QVariant::fromValue(lpMovie->movieID())); + ui->m_lpResults->addTopLevelItem(lpNew); + } + ui->m_lpResults->resizeColumnToContents(0); + ui->m_lpResults->resizeColumnToContents(1); + + ui->m_lpResults->sortItems(0, Qt::AscendingOrder); + + delete lpDialog; +} + +qint32 cMovieSearch::id() +{ + if(!ui->m_lpResults->selectedItems().count()) + { + qint32 iID = ui->m_lpSearch->text().toInt(); + if(iID) + return(iID); + return(-1); + } + return(ui->m_lpResults->selectedItems().at(0)->data(0, Qt::UserRole).toInt()); +} + +QString cMovieSearch::placeholderName() +{ + return(ui->m_lpPlaceholderName->text()); +} + +bool cMovieSearch::placeholder() +{ + return(ui->m_lpTabWidget->currentIndex() == 1); +} + +qint16 cMovieSearch::year() +{ + return(ui->m_lpYear->value()); +} diff --git a/cmoviesearch.h b/cmoviesearch.h new file mode 100644 index 0000000..882bf19 --- /dev/null +++ b/cmoviesearch.h @@ -0,0 +1,33 @@ +#ifndef CMOVIESEARCH_H +#define CMOVIESEARCH_H + +#include + +namespace Ui { +class cMovieSearch; +} + +class cMovieSearch : public QDialog +{ + Q_OBJECT + +public: + explicit cMovieSearch(QWidget *parent = 0); + ~cMovieSearch(); + + qint32 id(); + QString placeholderName(); + + bool placeholder(); + qint16 year(); + +private slots: + void on_m_lpSearchButton_clicked(); + + void on_m_lpSearch_textChanged(const QString &arg1); + +private: + Ui::cMovieSearch *ui; +}; + +#endif // CMOVIESEARCH_H diff --git a/cmoviesearch.ui b/cmoviesearch.ui new file mode 100644 index 0000000..23a4efb --- /dev/null +++ b/cmoviesearch.ui @@ -0,0 +1,180 @@ + + + cMovieSearch + + + + 0 + 0 + 334 + 460 + + + + Dialog + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + 1 + + + + Search + + + + + + + + + + + + + + + Search + + + + + + + + + 3 + + + false + + + + 1 + + + + + 2 + + + + + 3 + + + + + + + + + + + + + Add Placeholder + + + + + + + + + + Name: + + + + + + + + + + Year: + + + + + + + 1800 + + + 2100 + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + + + + m_lpButtonBox + accepted() + cMovieSearch + accept() + + + 248 + 254 + + + 157 + 274 + + + + + m_lpButtonBox + rejected() + cMovieSearch + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/csearch.h b/csearch.h index c1cc38d..00561c2 100644 --- a/csearch.h +++ b/csearch.h @@ -20,6 +20,7 @@ public: bool placeholder(); qint16 year(); + private slots: void on_m_lpSearchButton_clicked(); void on_m_lpSearch_textChanged(const QString &arg1); diff --git a/cthemoviedbv3.cpp b/cthemoviedbv3.cpp index 4779bc5..120ec47 100644 --- a/cthemoviedbv3.cpp +++ b/cthemoviedbv3.cpp @@ -14,33 +14,6 @@ cTheMovieDBV3::cTheMovieDBV3() { m_szToken = "a33271b9e54cdcb9a80680eaf5522f1b"; -/* - QNetworkAccessManager networkManager; - - QNetworkRequest request(QUrl(QString("https://api.themoviedb.org/3/authentication/token/new?api_key=a33271b9e54cdcb9a80680eaf5522f1b"))); - - QNetworkReply* reply = networkManager.get(request); - QEventLoop loop; - - QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit())); - loop.exec(); - - if (reply->error() == QNetworkReply::NoError) - { - QString strReply = (QString)reply->readAll(); - QJsonDocument jsonResponse = QJsonDocument::fromJson(strReply.toUtf8()); - QJsonObject jsonObj = jsonResponse.object(); - bool success = jsonObj["success"].toBool(); - m_szToken = jsonObj["request_token"].toString(); - - delete reply; - } - else - { - qDebug() << reply->errorString(); - delete reply; - } -*/ } QList cTheMovieDBV3::search(const QString& szMovie, const qint16& year, const QString& szLanguage) @@ -81,9 +54,6 @@ QList cTheMovieDBV3::search(const QString& szMovie, const qint16& year, { QJsonObject movie = jsonArray[z].toObject(); cMovie* lpMovie = new cMovie; -// lpSerie->setID(serie["id"].toInt()); -// lpSerie->setSeriesName(serie["seriesName"].toString()); -// lpSerie->setFirstAired(serie["firstAired"].toString()); lpMovie->setMovieTitle(movie["title"].toString()); lpMovie->setMovieID(movie["id"].toInt()); lpMovie->setOriginalTitle(movie["original_title"].toString()); @@ -104,3 +74,101 @@ QList cTheMovieDBV3::search(const QString& szMovie, const qint16& year, } return(movieList); } + +cMovie* cTheMovieDBV3::load(const qint32 &iID, const QString &szLanguage) +{ + cMovie* lpMovie = 0; + QNetworkAccessManager networkManager; + QNetworkRequest request(QUrl(QString("https://api.themoviedb.org/3/movie/%1?api_key=%2&language=%3").arg(iID).arg(m_szToken).arg(szLanguage))); + + request.setRawHeader("Content-Type", "application/json"); + request.setRawHeader("Authorization", QString("Bearer %1").arg(m_szToken).toUtf8()); + if(!szLanguage.contains("all")) + request.setRawHeader("Accept-Language", szLanguage.toUtf8()); + else + request.setRawHeader("Accept-Language", "en"); + + QNetworkReply* reply = networkManager.get(request); + QEventLoop loop; + + QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit())); + loop.exec(); + + if (reply->error() == QNetworkReply::NoError) + { + QString strReply = (QString)reply->readAll(); + QJsonDocument jsonResponse = QJsonDocument::fromJson(strReply.toUtf8()); + QJsonObject jsonObj = jsonResponse.object(); + + QJsonArray genreArray = jsonObj["genres"].toArray(); + QStringList genreList; + + QJsonArray productionCompaniesArray = jsonObj["production_companies"].toArray(); + QStringList productionCompaniesList; + + QJsonArray productionCountriesArray = jsonObj["production_countries"].toArray(); + QStringList productionCountriesList; + + QJsonArray spokenLanguagesArray = jsonObj["spoken_languages"].toArray(); + QStringList spokenLanguagesList; + + QJsonObject tmpObj; + + delete reply; + + lpMovie = new cMovie; + + lpMovie->setMovieTitle(jsonObj["title"].toString()); + lpMovie->setMovieID(jsonObj["id"].toInt()); + lpMovie->setOriginalTitle(jsonObj["original_title"].toString()); + lpMovie->setReleaseDate(jsonObj["release_date"].toString()); + lpMovie->setAdult(jsonObj["adult"].toBool()); + lpMovie->setBackdropPath(jsonObj["backdrop_path"].toString()); + tmpObj = jsonObj["belongs_to_collection"].toObject(); + lpMovie->setBelongsToCollection(tmpObj["name"].toString()); + lpMovie->setButget(jsonObj["budget"].toDouble()); + for(int z = 0;z < genreArray.count();z++) + { + tmpObj = genreArray[z].toObject(); + genreList.append(tmpObj["name"].toString()); + } + lpMovie->setGenres(genreList); + lpMovie->setHomepage(jsonObj["homepage"].toString()); + lpMovie->setIMDBID(jsonObj["imdb_id"].toString()); + lpMovie->setOriginalLanguage(jsonObj["original_language"].toString()); + lpMovie->setOverview(jsonObj["overview"].toString()); + lpMovie->setPopularity(jsonObj["popularity"].toDouble()); + lpMovie->setPosterPath(jsonObj["poster_path"].toString()); + for(int z = 0;z < productionCompaniesArray.count();z++) + { + tmpObj = productionCompaniesArray[z].toObject(); + productionCompaniesList.append(tmpObj["name"].toString()); + } + lpMovie->setProductionCompanies(productionCompaniesList); + for(int z = 0;z < productionCountriesArray.count();z++) + { + tmpObj = productionCountriesArray[z].toObject(); + productionCountriesList.append(tmpObj["name"].toString()); + } + lpMovie->setProductionCountries(productionCountriesList); + lpMovie->setRevenue(jsonObj["revenue"].toDouble()); + lpMovie->setRuntime(jsonObj["runtime"].toInt()); + for(int z = 0;z < spokenLanguagesArray.count();z++) + { + tmpObj = spokenLanguagesArray[z].toObject(); + spokenLanguagesList.append(tmpObj["name"].toString()); + } + lpMovie->setSpokenLanguages(spokenLanguagesList); + lpMovie->setStatus(jsonObj["status"].toString()); + lpMovie->setTagline(jsonObj["tagline"].toString()); + lpMovie->setVideo(jsonObj["video"].toBool()); + lpMovie->setVoteAverage(jsonObj["vote_average"].toDouble()); + lpMovie->setVoteCount(jsonObj["vote_count"].toInt()); + } + else + { + qDebug() << reply->errorString(); + delete reply; + } + return(lpMovie); +} diff --git a/cthemoviedbv3.h b/cthemoviedbv3.h index 892c6e8..f7acf29 100644 --- a/cthemoviedbv3.h +++ b/cthemoviedbv3.h @@ -15,7 +15,7 @@ public: cTheMovieDBV3(); QList search(const QString& szMovie, const qint16& year = -1, const QString& szLanguage = "all"); -// cSerie* load(const qint32 &iID, const QString& szLanguage); + cMovie* load(const qint32 &iID, const QString& szLanguage); private: QString m_szToken; // QStringList getActors(const qint32& iID); diff --git a/cupdatethread.cpp b/cupdatethread.cpp index 0b961d4..4c81be5 100644 --- a/cupdatethread.cpp +++ b/cupdatethread.cpp @@ -1,5 +1,4 @@ #include "cupdatethread.h" -#include "cserie.h" #include "cseason.h" #include "cepisode.h" #include "cthetvdbv2.h" @@ -28,9 +27,9 @@ void cUpdateThread::run() timer.restart(); QString szFailed; - for(int x = 0;x < m_indexList.count();x++) + for(int x = 0;x < m_serieList.count();x++) { - cSerie* lpSerie = m_indexList.at(x).data(Qt::UserRole).value(); + cSerie* lpSerie = m_serieList.at(x); if(lpSerie) { emit updateMessage(lpSerie->seriesName(), x); @@ -82,9 +81,9 @@ void cUpdateThread::run() */ } -void cUpdateThread::setData(cMessageDialog* lpMessageDialog, const QModelIndexList &indexList, const QSqlDatabase& db) +void cUpdateThread::setData(cMessageDialog* lpMessageDialog, const cSerieList &serieList, const QSqlDatabase& db) { connect(lpMessageDialog->cancelButton(), SIGNAL(clicked()), this, SLOT(stop())); - m_indexList = indexList; + m_serieList = serieList; m_db = db; } diff --git a/cupdatethread.h b/cupdatethread.h index c4fd113..7a478b2 100644 --- a/cupdatethread.h +++ b/cupdatethread.h @@ -4,6 +4,8 @@ #include "cmessagedialog.h" +#include "cserie.h" + #include #include #include @@ -18,7 +20,7 @@ class cUpdateThread : public QThread public: explicit cUpdateThread(); - void setData(cMessageDialog *lpMessageDialog, const QModelIndexList& indexList, const QSqlDatabase& db); + void setData(cMessageDialog *lpMessageDialog, const cSerieList& serieList, const QSqlDatabase& db); public slots: void stop(); @@ -29,7 +31,7 @@ signals: private: QMutex m_mutex; bool m_bStop; - QModelIndexList m_indexList; + cSerieList m_serieList; QSqlDatabase m_db; QWidget* m_lpParent; diff --git a/qtMovies.pro b/qtMovies.pro index 48512fd..f20a40f 100644 --- a/qtMovies.pro +++ b/qtMovies.pro @@ -30,7 +30,8 @@ SOURCES += main.cpp\ cpicturesthread.cpp \ cthetvdbv2.cpp \ cthemoviedbv3.cpp \ - cmovie.cpp + cmovie.cpp \ + cmoviesearch.cpp HEADERS += cmainwindow.h \ cserie.h \ @@ -49,7 +50,8 @@ HEADERS += cmainwindow.h \ cpicturesthread.h \ cthetvdbv2.h \ cthemoviedbv3.h \ - cmovie.h + cmovie.h \ + cmoviesearch.h FORMS += cmainwindow.ui \ csearch.ui \ @@ -57,7 +59,8 @@ FORMS += cmainwindow.ui \ cedit.ui \ cseasondetails.ui \ cepisodedetails.ui \ - cmessagedialog.ui + cmessagedialog.ui \ + cmoviesearch.ui DISTFILES +=