diff --git a/cimage.cpp b/cimage.cpp index e6000ab..11c4db8 100644 --- a/cimage.cpp +++ b/cimage.cpp @@ -1,3 +1,5 @@ +#include "common.h" + #include "cimage.h" #include @@ -17,10 +19,10 @@ QPixmap cImage::getImage(const QString& szFileName) { QPixmap pixmap; - QString szPath = QDir::homePath() + QDir::separator() + "qtseries" + QDir::separator() + szFileName; + QString szPath = rootPath() + QDir::separator() + szFileName; if(szFileName.isEmpty()) - pixmap.load(QDir::homePath() + QDir::separator() + "qtseries" + QDir::separator() + "empty.jpg"); + pixmap.load(rootPath() + QDir::separator() + QDir::separator() + "empty.jpg"); else pixmap.load(szPath); @@ -34,7 +36,7 @@ QPixmap cImage::downloadFile(const QString& szFileName) { QPixmap pixmap; - QString szPath = QDir::homePath() + QDir::separator() + "qtseries" + QDir::separator() + szFileName; + QString szPath = rootPath() + QDir::separator() + szFileName; QString szURL = "http://thetvdb.com/banners/" + szFileName; QNetworkAccessManager networkManager; diff --git a/cmainwindow.cpp b/cmainwindow.cpp index 09c4798..ccc7597 100644 --- a/cmainwindow.cpp +++ b/cmainwindow.cpp @@ -1,3 +1,5 @@ +#include "common.h" + #include "cmainwindow.h" #include "ui_cmainwindow.h" @@ -135,9 +137,7 @@ void cMainWindow::closeEvent(QCloseEvent *event) void cMainWindow::initDB() { - QDir dir; - dir.mkpath(QDir::homePath() + QDir::separator() + "qtseries" + QDir::separator()); - QString szDBPath = QDir::homePath() + QDir::separator() + "qtseries" + QDir::separator() + "qtseries.db"; + QString szDBPath = rootPath()+ QDir::separator() + QString("qtmovies.db"); m_db = QSqlDatabase::addDatabase("QSQLITE"); m_db.setHostName("localhost"); @@ -224,7 +224,8 @@ void cMainWindow::initDB() " tagline STRING," " video BOOL," " cast TEXT," - " crew TEXT);"); // NAME|CHARACTER|ORDER + " crew TEXT," + " state INTEGER);"); } } @@ -316,7 +317,7 @@ void cMainWindow::loadMoviesDB() QSqlQuery query; qint32 iMovieID; - if(query.exec("SELECT movieID, movieTitle, originalTitle, backdropPath, posterPath, overview, releaseDate, genre, imdbid, originalLanguage, popularity, productionCompanies, productionCountries, voteAverage, voteCount, adult, belongsToCollection, budget, homepage, revenue, runtime, spokenLanguages, status, tagline, video, `cast`, crew FROM movie ORDER BY movieTitle, releaseDate;")) + if(query.exec("SELECT movieID, movieTitle, originalTitle, backdropPath, posterPath, overview, releaseDate, genre, imdbid, originalLanguage, popularity, productionCompanies, productionCountries, voteAverage, voteCount, adult, belongsToCollection, budget, homepage, revenue, runtime, spokenLanguages, status, tagline, video, `cast`, crew, state FROM movie ORDER BY movieTitle, releaseDate;")) { while(query.next()) { @@ -349,6 +350,7 @@ void cMainWindow::loadMoviesDB() lpMovie->setVoteCount(query.value("voteCount").toInt()); lpMovie->setCast(query.value("cast").toString().split("|")); lpMovie->setCrew(query.value("crew").toString().split("|")); + lpMovie->setState((cMovie::State)query.value("state").toInt()); } } else @@ -584,7 +586,7 @@ void cMainWindow::displayMovies() { cMovie* lpMovie = m_movieList.at(x); - QStandardItem* lpItem = new QStandardItem(QString("%1 (%2)  
%3").arg(lpMovie->movieTitle()).arg(lpMovie->releaseDate().year()).arg(lpMovie->tagline())); + QStandardItem* lpItem = new QStandardItem(QString("%1 (%2)  
%3
").arg(lpMovie->movieTitle()).arg(lpMovie->releaseDate().year()).arg(lpMovie->tagline())); lpItem->setData(QVariant::fromValue(lpMovie), Qt::UserRole); m_lpMoviesListModel->appendRow(lpItem); } diff --git a/cmovie.cpp b/cmovie.cpp index 09a16b9..bff2907 100644 --- a/cmovie.cpp +++ b/cmovie.cpp @@ -305,13 +305,23 @@ QStringList cMovie::crew() return(m_szCrew); } +void cMovie::setState(const State state) +{ + m_iState = state; +} + +cMovie::State cMovie::state() +{ + return(m_iState); +} + bool cMovie::save(QSqlDatabase &db) { QSqlQuery query; QSqlQuery queryMovie; - queryMovie.prepare("INSERT INTO movie (movieID,movieTitle,originalTitle,backdropPath,posterPath,overview,releaseDate,genre,imdbid,originalLanguage,popularity,productionCompanies,productionCountries,voteAverage,voteCount,adult,belongsToCollection,budget,homepage,revenue,runtime,spokenLanguages,status,tagline,video,cast,crew)" - " VALUES (:movieID,:movieTitle,:originalTitle,:backdropPath,:posterPath,:overview,:releaseDate,:genre,:imdbid,:originalLanguage,:popularity,:productionCompanies,:productionCountries,:voteAverage,:voteCount,:adult,:belongsToCollection,:budget,:homepage,:revenue,:runtime,:spokenLanguages,:status,:tagline,:video,:cast,:crew);"); + queryMovie.prepare("INSERT INTO movie (movieID,movieTitle,originalTitle,backdropPath,posterPath,overview,releaseDate,genre,imdbid,originalLanguage,popularity,productionCompanies,productionCountries,voteAverage,voteCount,adult,belongsToCollection,budget,homepage,revenue,runtime,spokenLanguages,status,tagline,video,cast,crew,state)" + " VALUES (:movieID,:movieTitle,:originalTitle,:backdropPath,:posterPath,:overview,:releaseDate,:genre,:imdbid,:originalLanguage,:popularity,:productionCompanies,:productionCountries,:voteAverage,:voteCount,:adult,:belongsToCollection,:budget,:homepage,:revenue,:runtime,:spokenLanguages,:status,:tagline,:video,:cast,:crew,:state);"); db.transaction(); query.exec(QString("SELECT movieID FROM movie WHERE movieID=%1;").arg(movieID())); @@ -344,6 +354,7 @@ bool cMovie::save(QSqlDatabase &db) queryMovie.bindValue(":video", video()); queryMovie.bindValue(":cast", cast().join("|")); queryMovie.bindValue(":crew", crew().join("|")); + queryMovie.bindValue(":state", state()); if(queryMovie.exec()) { diff --git a/cmovie.h b/cmovie.h index d1c9f31..470c6a2 100644 --- a/cmovie.h +++ b/cmovie.h @@ -12,6 +12,14 @@ class cMovie { public: + enum State + { + StateUnknown = 0, + StateInit = 1, + StateProgress = 2, + StateDone = 3, + }; + cMovie(); void setMovieTitle(const QString& szTitle); @@ -99,6 +107,9 @@ public: void setCrew(const QStringList& szCrew); QStringList crew(); + void setState(const State state); + State state(); + bool save(QSqlDatabase& db); bool del(QSqlDatabase& db); private: @@ -130,6 +141,7 @@ private: qint32 m_iVoteCount; QStringList m_szCast; QStringList m_szCrew; + State m_iState; }; Q_DECLARE_METATYPE(cMovie*) diff --git a/cmovieviewitemdelegate.cpp b/cmovieviewitemdelegate.cpp index a307e3e..5f4de73 100644 --- a/cmovieviewitemdelegate.cpp +++ b/cmovieviewitemdelegate.cpp @@ -1,12 +1,22 @@ #include "cmovieviewitemdelegate.h" +#include "cmovie.h" + #include #include #include +#define STATE_INIT Qt::gray +#define STATE_PROGRESS Qt::blue +#define STATE_DONE Qt::green +#define STATE_UNKNOWN Qt::black + void cMovieViewItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem & option, const QModelIndex &index) const { + cMovie* lpMovie = qvariant_cast(index.data(Qt::UserRole)); + QBrush oldBrush; + QStyleOptionViewItem options = option; initStyleOption(&options, index); @@ -26,6 +36,26 @@ void cMovieViewItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem //doc.drawContents(painter, clip); painter->setClipRect(clip); + oldBrush = painter->brush(); + + switch(lpMovie->state()) + { + case cMovie::StateInit: + painter->setBrush(STATE_INIT); + break; + case cMovie::StateProgress: + painter->setBrush(STATE_PROGRESS); + break; + case cMovie::StateDone: + painter->setBrush(STATE_DONE); + break; + default: + break; + } + painter->drawRect(clip); + + painter->setBrush(oldBrush); + QAbstractTextDocumentLayout::PaintContext ctx; // set text color to red for selected item if (option.state & QStyle::State_Selected) diff --git a/common.cpp b/common.cpp new file mode 100644 index 0000000..4d801ad --- /dev/null +++ b/common.cpp @@ -0,0 +1,19 @@ +#include "common.h" + +#include +#include + + +QString rootPath() +{ + QSettings settings; + QString szPath = settings.value("database", QVariant::fromValue(QString("%HOME%"))).toString(); + + if(!szPath.compare("%HOME%") || szPath.isEmpty()) + { + QDir dir; + szPath = QDir::homePath() + QDir::separator() + "qtmovies"; + } + + return(szPath); +} diff --git a/common.h b/common.h new file mode 100644 index 0000000..9babbb9 --- /dev/null +++ b/common.h @@ -0,0 +1,11 @@ +#ifndef COMMON_H +#define COMMON_H + + +#include + + +QString rootPath(); + + +#endif // COMMON_H diff --git a/cthemoviedbv3.cpp b/cthemoviedbv3.cpp index 68eb0c4..4d5578f 100644 --- a/cthemoviedbv3.cpp +++ b/cthemoviedbv3.cpp @@ -166,6 +166,7 @@ cMovie* cTheMovieDBV3::load(const qint32 &iID, const QString &szLanguage) lpMovie->setVideo(jsonObj["video"].toBool()); lpMovie->setVoteAverage(jsonObj["vote_average"].toDouble()); lpMovie->setVoteCount(jsonObj["vote_count"].toInt()); + lpMovie->setState(cMovie::StateInit); request.setUrl(QUrl(QString("https://api.themoviedb.org/3/movie/%1/credits?api_key=%2").arg(iID).arg(m_szToken))); diff --git a/main.cpp b/main.cpp index 5b89a92..d55c4be 100644 --- a/main.cpp +++ b/main.cpp @@ -8,7 +8,7 @@ int main(int argc, char *argv[]) QCoreApplication::setOrganizationName("WIN-DESIGN"); QCoreApplication::setOrganizationDomain("windesign.at"); - QCoreApplication::setApplicationName("qtSerien"); + QCoreApplication::setApplicationName("qtMovies"); QSettings settings; diff --git a/qtMovies.pro b/qtMovies.pro index 3e3d220..b123712 100644 --- a/qtMovies.pro +++ b/qtMovies.pro @@ -8,7 +8,7 @@ QT += core gui network xml sql greaterThan(QT_MAJOR_VERSION, 4): QT += widgets -TARGET = qtSerien +TARGET = qtMovies TEMPLATE = app @@ -32,7 +32,8 @@ SOURCES += main.cpp\ cthemoviedbv3.cpp \ cmovie.cpp \ cmoviesearch.cpp \ - cmovieviewitemdelegate.cpp + cmovieviewitemdelegate.cpp \ + common.cpp HEADERS += cmainwindow.h \ cserie.h \ @@ -53,7 +54,8 @@ HEADERS += cmainwindow.h \ cthemoviedbv3.h \ cmovie.h \ cmoviesearch.h \ - cmovieviewitemdelegate.h + cmovieviewitemdelegate.h \ + common.h FORMS += cmainwindow.ui \ csearch.ui \