Skip to content

Commit

Permalink
[TvShow] Introduce SeasonNumber type
Browse files Browse the repository at this point in the history
  • Loading branch information
bugwelle committed Sep 25, 2018
1 parent f2f142f commit 3b4367c
Show file tree
Hide file tree
Showing 54 changed files with 453 additions and 332 deletions.
6 changes: 4 additions & 2 deletions MediaElch.pro
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,8 @@ SOURCES += src/main.cpp \
src/xbmc/XbmcSync.cpp \
src/data/ImdbId.cpp \
src/data/TmdbId.cpp \
src/data/EpisodeNumber.cpp
src/data/EpisodeNumber.cpp \
src/data/SeasonNumber.cpp

macx {
OBJECTIVE_SOURCES += src/notifications/MacNotificationHandler.mm
Expand Down Expand Up @@ -422,7 +423,8 @@ HEADERS += Version.h \
src/xbmc/XbmcSync.h \
src/data/ImdbId.h \
src/data/TmdbId.h \
src/data/EpisodeNumber.h
src/data/EpisodeNumber.h \
src/data/SeasonNumber.h

FORMS += src/main/MainWindow.ui \
src/concerts/ConcertFilesWidget.ui \
Expand Down
12 changes: 6 additions & 6 deletions src/data/Database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -639,11 +639,11 @@ void Database::add(TvShowEpisode *episode, QString path, int idShow)
query.bindValue(":content", episode->nfoContent().isEmpty() ? "" : episode->nfoContent().toUtf8());
query.bindValue(":idShow", idShow);
query.bindValue(":path", path.toUtf8());
query.bindValue(":seasonNumber", episode->season());
query.bindValue(":seasonNumber", episode->season().toInt());
query.bindValue(":episodeNumber", episode->episode().toInt());
query.exec();
int insertId = query.lastInsertId().toInt();
foreach (const QString &file, episode->files()) {
for (const QString &file : episode->files()) {
query.prepare("INSERT INTO episodeFiles(idEpisode, file) VALUES(:idEpisode, :file)");
query.bindValue(":idEpisode", insertId);
query.bindValue(":file", file.toUtf8());
Expand Down Expand Up @@ -740,7 +740,7 @@ QList<TvShowEpisode *> Database::episodes(int idShow)
}

TvShowEpisode *episode = new TvShowEpisode(files);
episode->setSeason(query.value(query.record().indexOf("seasonNumber")).toInt());
episode->setSeason(SeasonNumber(query.value(query.record().indexOf("seasonNumber")).toInt()));
episode->setEpisode(EpisodeNumber(query.value(query.record().indexOf("episodeNumber")).toInt()));
episode->setDatabaseId(query.value(query.record().indexOf("idEpisode")).toInt());
episode->setNfoContent(QString::fromUtf8(query.value(query.record().indexOf("content")).toByteArray()));
Expand Down Expand Up @@ -857,15 +857,15 @@ void Database::addEpisodeToShowList(TvShowEpisode *episode, int showsSettingsId,
"content=:content WHERE idEpisode=:idEpisode");
query.bindValue(":content", xmlContent.isEmpty() ? "" : xmlContent);
query.bindValue(":idEpisode", idEpisode);
query.bindValue(":seasonNumber", episode->season());
query.bindValue(":seasonNumber", episode->season().toInt());
query.bindValue(":episodeNumber", episode->episode().toInt());
query.exec();
} else {
query.prepare("INSERT INTO showsEpisodes(content, idShow, seasonNumber, episodeNumber, tvdbid, updated) "
"VALUES(:content, :idShow, :seasonNumber, :episodeNumber, :tvdbid, 1)");
query.bindValue(":content", xmlContent.isEmpty() ? "" : xmlContent);
query.bindValue(":idShow", showsSettingsId);
query.bindValue(":seasonNumber", episode->season());
query.bindValue(":seasonNumber", episode->season().toInt());
query.bindValue(":episodeNumber", episode->episode().toInt());
query.bindValue(":tvdbid", tvdbid);
query.exec();
Expand All @@ -890,7 +890,7 @@ QList<TvShowEpisode *> Database::showsEpisodes(TvShow *show)
query.exec();
while (query.next()) {
TvShowEpisode *episode = new TvShowEpisode(QStringList(), show);
episode->setSeason(query.value(query.record().indexOf("seasonNumber")).toInt());
episode->setSeason(SeasonNumber(query.value(query.record().indexOf("seasonNumber")).toInt()));
episode->setEpisode(EpisodeNumber(query.value(query.record().indexOf("episodeNumber")).toInt()));
episode->setNfoContent(QString::fromUtf8(query.value(query.record().indexOf("content")).toByteArray()));
episodes.append(episode);
Expand Down
11 changes: 7 additions & 4 deletions src/data/EpisodeNumber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@ EpisodeNumber::EpisodeNumber(int episodeNumber) :

const EpisodeNumber EpisodeNumber::NoEpisode = EpisodeNumber(-2);

bool EpisodeNumber::operator==(const EpisodeNumber &other)
bool EpisodeNumber::operator==(const EpisodeNumber &other) const
{
// Only valid IMDb id's are comparable
return m_episodeNumber == other.m_episodeNumber;
}

bool EpisodeNumber::operator!=(const EpisodeNumber &other)
bool EpisodeNumber::operator!=(const EpisodeNumber &other) const
{
return !(*this == other);
}

bool EpisodeNumber::operator>(const EpisodeNumber &other)
bool EpisodeNumber::operator>(const EpisodeNumber &other) const
{
return m_episodeNumber > other.m_episodeNumber;
}

bool EpisodeNumber::operator<(const EpisodeNumber &other)
bool EpisodeNumber::operator<(const EpisodeNumber &other) const
{
return m_episodeNumber < other.m_episodeNumber;
}
Expand All @@ -39,6 +39,9 @@ int EpisodeNumber::toInt() const

QString EpisodeNumber::toPaddedString() const
{
if (m_episodeNumber == EpisodeNumber::NoEpisode.toInt()) {
return QStringLiteral("xx");
}
return QString::number(m_episodeNumber).prepend((m_episodeNumber < 10) ? "0" : "");
}

Expand Down
8 changes: 4 additions & 4 deletions src/data/EpisodeNumber.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ class EpisodeNumber
EpisodeNumber() = default;
explicit EpisodeNumber(int episodeNumber);

bool operator==(const EpisodeNumber &other);
bool operator!=(const EpisodeNumber &other);
bool operator>(const EpisodeNumber &other);
bool operator<(const EpisodeNumber &other);
bool operator==(const EpisodeNumber &other) const;
bool operator!=(const EpisodeNumber &other) const;
bool operator>(const EpisodeNumber &other) const;
bool operator<(const EpisodeNumber &other) const;

int toInt() const;
QString toPaddedString() const;
Expand Down
12 changes: 7 additions & 5 deletions src/data/ImageProviderInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
#include <QString>

#include "data/Concert.h"
#include "data/EpisodeNumber.h"
#include "data/Movie.h"
#include "data/SeasonNumber.h"
#include "data/TvShow.h"
#include "globals/Globals.h"

Expand Down Expand Up @@ -41,11 +43,11 @@ class ImageProviderInterface : public QObject
virtual void tvShowClearArts(QString tvdbId) = 0;
virtual void tvShowCharacterArts(QString tvdbId) = 0;
virtual void tvShowBanners(QString tvdbId) = 0;
virtual void tvShowEpisodeThumb(QString tvdbId, int season, EpisodeNumber episode) = 0;
virtual void tvShowSeason(QString tvdbId, int season) = 0;
virtual void tvShowSeasonBanners(QString tvdbId, int season) = 0;
virtual void tvShowSeasonBackdrops(QString tvdbId, int season) = 0;
virtual void tvShowSeasonThumbs(QString tvdbId, int season) = 0;
virtual void tvShowEpisodeThumb(QString tvdbId, SeasonNumber season, EpisodeNumber episode) = 0;
virtual void tvShowSeason(QString tvdbId, SeasonNumber season) = 0;
virtual void tvShowSeasonBanners(QString tvdbId, SeasonNumber season) = 0;
virtual void tvShowSeasonBackdrops(QString tvdbId, SeasonNumber season) = 0;
virtual void tvShowSeasonThumbs(QString tvdbId, SeasonNumber season) = 0;
virtual void tvShowThumbs(QString tvdbId) = 0;
virtual void artistFanarts(QString mbId) = 0;
virtual void artistLogos(QString mbId) = 0;
Expand Down
3 changes: 2 additions & 1 deletion src/data/MediaCenterInterface.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef MEDIACENTERINTERFACE_H
#define MEDIACENTERINTERFACE_H

#include "data/SeasonNumber.h"
#include "globals/Globals.h"
#include "settings/DataFile.h"

Expand Down Expand Up @@ -61,9 +62,9 @@ class MediaCenterInterface : public QObject
virtual QString imageFileName(const Movie *movie, ImageType type, QList<DataFile> dataFiles = QList<DataFile>(), bool constructName = false) = 0;
virtual QString imageFileName(const Concert *concert, ImageType type, QList<DataFile> dataFiles = QList<DataFile>(), bool constructName = false) = 0;
virtual QString imageFileName(const TvShowEpisode *episode, ImageType type, QList<DataFile> dataFiles = QList<DataFile>(), bool constructName = false) = 0;
virtual QString imageFileName(const TvShow *show, ImageType type, int season = -2, QList<DataFile> dataFiles = QList<DataFile>(), bool constructName = false) = 0;
virtual QString imageFileName(const Artist *artist, ImageType type, QList<DataFile> dataFiles = QList<DataFile>(), bool constructName = false) = 0;
virtual QString imageFileName(const Album *album, ImageType type, QList<DataFile> dataFiles = QList<DataFile>(), bool constructName = false) = 0;
virtual QString imageFileName(const TvShow *show, ImageType type, SeasonNumber season = SeasonNumber::NoSeason, QList<DataFile> dataFiles = QList<DataFile>(), bool constructName = false) = 0;
// clang-format on

virtual void loadBooklets(Album *album) = 0;
Expand Down
52 changes: 52 additions & 0 deletions src/data/SeasonNumber.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include "SeasonNumber.h"

#include <QRegExp>
#include <QString>

SeasonNumber::SeasonNumber(int seasonNumber) :
// Any number lower than 0 is regarded invalid => no episode number
m_seasonNumber(seasonNumber > -1 ? seasonNumber : SeasonNumber::NoSeason.toInt())
{
}

const SeasonNumber SeasonNumber::NoSeason = SeasonNumber(-1);
const SeasonNumber SeasonNumber::SpecialsSeason = SeasonNumber(0);

bool SeasonNumber::operator==(const SeasonNumber &other) const
{
// Only valid IMDb id's are comparable
return m_seasonNumber == other.m_seasonNumber;
}

bool SeasonNumber::operator!=(const SeasonNumber &other) const
{
return !(*this == other);
}

bool SeasonNumber::operator>(const SeasonNumber &other) const
{
return m_seasonNumber > other.m_seasonNumber;
}

bool SeasonNumber::operator<(const SeasonNumber &other) const
{
return m_seasonNumber < other.m_seasonNumber;
}

int SeasonNumber::toInt() const
{
return m_seasonNumber;
}

QString SeasonNumber::toPaddedString() const
{
if (m_seasonNumber == SeasonNumber::NoSeason.toInt()) {
return QStringLiteral("xx");
}
return QString::number(m_seasonNumber).prepend((m_seasonNumber < 10) ? "0" : "");
}

QString SeasonNumber::toString() const
{
return QString::number(m_seasonNumber);
}
28 changes: 28 additions & 0 deletions src/data/SeasonNumber.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#ifndef DATA_SEASON_NUMBER
#define DATA_SEASON_NUMBER

#include <QString>

class SeasonNumber
{
public:
SeasonNumber() = default;
explicit SeasonNumber(int seasonNumber);

bool operator==(const SeasonNumber &other) const;
bool operator!=(const SeasonNumber &other) const;
bool operator>(const SeasonNumber &other) const;
bool operator<(const SeasonNumber &other) const;

int toInt() const;
QString toPaddedString() const;
QString toString() const;

static const SeasonNumber NoSeason;
static const SeasonNumber SpecialsSeason;

private:
int m_seasonNumber;
};

#endif // DATA_SEASON_NUMBER
Loading

0 comments on commit 3b4367c

Please sign in to comment.