.
This commit is contained in:
+5
-3
@@ -1,3 +1,5 @@
|
||||
#include "common.h"
|
||||
|
||||
#include "cimage.h"
|
||||
|
||||
#include <QDir>
|
||||
@@ -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;
|
||||
|
||||
+8
-6
@@ -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("<b>%1</b> <font color='blue'>(%2)</font> <br><i>%3</i>").arg(lpMovie->movieTitle()).arg(lpMovie->releaseDate().year()).arg(lpMovie->tagline()));
|
||||
QStandardItem* lpItem = new QStandardItem(QString("<font color='white'><b>%1</b> (%2) <br><i>%3</i></font>").arg(lpMovie->movieTitle()).arg(lpMovie->releaseDate().year()).arg(lpMovie->tagline()));
|
||||
lpItem->setData(QVariant::fromValue(lpMovie), Qt::UserRole);
|
||||
m_lpMoviesListModel->appendRow(lpItem);
|
||||
}
|
||||
|
||||
+13
-2
@@ -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())
|
||||
{
|
||||
|
||||
@@ -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*)
|
||||
|
||||
@@ -1,12 +1,22 @@
|
||||
#include "cmovieviewitemdelegate.h"
|
||||
|
||||
#include "cmovie.h"
|
||||
|
||||
#include <QPainter>
|
||||
#include <QTextDocument>
|
||||
#include <QAbstractTextDocumentLayout>
|
||||
|
||||
|
||||
#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<cMovie*>(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)
|
||||
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
#include "common.h"
|
||||
|
||||
#include <QSettings>
|
||||
#include <QDir>
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
#ifndef COMMON_H
|
||||
#define COMMON_H
|
||||
|
||||
|
||||
#include <QString>
|
||||
|
||||
|
||||
QString rootPath();
|
||||
|
||||
|
||||
#endif // COMMON_H
|
||||
@@ -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)));
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
+5
-3
@@ -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 \
|
||||
|
||||
Reference in New Issue
Block a user