Skip to content

Commit

Permalink
ServicesAPI: add the genre list to the output from Video/GetVideoList
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Harrison committed Mar 8, 2017
1 parent ab4513f commit ab1c3e8
Show file tree
Hide file tree
Showing 8 changed files with 211 additions and 6 deletions.
Expand Up @@ -29,7 +29,7 @@ class SERVICE_PUBLIC ArtworkInfoList : public QObject

// Q_CLASSINFO Used to augment Metadata for properties.
// See datacontracthelper.h for details

Q_CLASSINFO( "ArtworkInfos", "type=DTC::ArtworkInfo");

Q_PROPERTY( QVariantList ArtworkInfos READ ArtworkInfos DESIGNABLE true )
Expand Down
69 changes: 69 additions & 0 deletions mythtv/libs/libmythservicecontracts/datacontracts/genre.h
@@ -0,0 +1,69 @@
//////////////////////////////////////////////////////////////////////////////
// Program Name: genre.h
// Created : Mar. 08, 2017
//
// Copyright (c) 2017 Paul Harrison <pharrison@mythtv.org>
//
// Licensed under the GPL v2 or later, see COPYING for details
//
//////////////////////////////////////////////////////////////////////////////

#ifndef GENRE_H_
#define GENRE_H_

#include <QString>

#include "serviceexp.h"
#include "datacontracthelper.h"

namespace DTC
{

/////////////////////////////////////////////////////////////////////////////

class SERVICE_PUBLIC Genre : public QObject
{
Q_OBJECT
Q_CLASSINFO( "version" , "1.0" );

Q_PROPERTY( QString Name READ Name WRITE setName )

PROPERTYIMP ( QString , Name )

public:

static inline void InitializeCustomTypes();

public:

Genre(QObject *parent = 0)
: QObject ( parent )
{
}

Genre( const Genre &src )
{
Copy( src );
}

void Copy( const Genre &src )
{
m_Name = src.m_Name ;
}
};

} // namespace DTC

Q_DECLARE_METATYPE( DTC::Genre )
Q_DECLARE_METATYPE( DTC::Genre* )

namespace DTC
{
inline void Genre::InitializeCustomTypes()
{
qRegisterMetaType< Genre >();
qRegisterMetaType< Genre* >();
}
}

#endif
89 changes: 89 additions & 0 deletions mythtv/libs/libmythservicecontracts/datacontracts/genreList.h
@@ -0,0 +1,89 @@
//////////////////////////////////////////////////////////////////////////////
// Program Name: genreList.h
// Created : Mar. 08, 2017
//
// Copyright (c) 2017 Paul Harrison <pharrison@mythtv.org>
//
// Licensed under the GPL v2 or later, see COPYING for details
//
//////////////////////////////////////////////////////////////////////////////

#ifndef GENRELIST_H_
#define GENRELIST_H_

#include <QString>
#include <QVariantList>

#include "serviceexp.h"
#include "datacontracthelper.h"

#include "genre.h"

namespace DTC
{

class SERVICE_PUBLIC GenreList : public QObject
{
Q_OBJECT
Q_CLASSINFO( "version", "1.0" );

// Q_CLASSINFO Used to augment Metadata for properties.
// See datacontracthelper.h for details

Q_CLASSINFO( "GenreList", "type=DTC::Genre");

Q_PROPERTY( QVariantList Genres READ Genres DESIGNABLE true )

PROPERTYIMP_RO_REF( QVariantList, Genres )

public:

static inline void InitializeCustomTypes();

public:

GenreList(QObject *parent = 0)
: QObject ( parent )
{
}

GenreList( const GenreList &src )
{
Copy( src );
}

void Copy( const GenreList &src )
{
CopyListContents< Genre >( this, m_Genres, src.m_Genres );
}

Genre *AddNewGenre()
{
// We must make sure the object added to the QVariantList has
// a parent of 'this'

Genre *pObject = new Genre( this );
m_Genres.append( QVariant::fromValue<QObject *>( pObject ));

return pObject;
}

};

} // namespace DTC

Q_DECLARE_METATYPE( DTC::GenreList )
Q_DECLARE_METATYPE( DTC::GenreList* )

namespace DTC
{
inline void GenreList::InitializeCustomTypes()
{
qRegisterMetaType< GenreList >();
qRegisterMetaType< GenreList* >();

Genre::InitializeCustomTypes();
}
}

#endif
Expand Up @@ -19,6 +19,7 @@
#include "datacontracthelper.h"
#include "artworkInfoList.h"
#include "castMemberList.h"
#include "genreList.h"

namespace DTC
{
Expand All @@ -28,7 +29,7 @@ namespace DTC
class SERVICE_PUBLIC VideoMetadataInfo : public QObject
{
Q_OBJECT
Q_CLASSINFO( "version" , "2.0" );
Q_CLASSINFO( "version" , "2.01" );

Q_PROPERTY( int Id READ Id WRITE setId )
Q_PROPERTY( QString Title READ Title WRITE setTitle )
Expand Down Expand Up @@ -65,6 +66,7 @@ class SERVICE_PUBLIC VideoMetadataInfo : public QObject

Q_PROPERTY( QObject* Artwork READ Artwork DESIGNABLE SerializeArtwork )
Q_PROPERTY( QObject* Cast READ Cast DESIGNABLE SerializeCast )
Q_PROPERTY( QObject* Genres READ Genres DESIGNABLE SerializeGenres )

PROPERTYIMP ( int , Id )
PROPERTYIMP ( QString , Title )
Expand Down Expand Up @@ -99,11 +101,13 @@ class SERVICE_PUBLIC VideoMetadataInfo : public QObject
PROPERTYIMP ( QString , Screenshot )
PROPERTYIMP ( QString , Trailer )

PROPERTYIMP_PTR( ArtworkInfoList, Artwork )
PROPERTYIMP_PTR( CastMemberList , Cast )
PROPERTYIMP_PTR( ArtworkInfoList , Artwork )
PROPERTYIMP_PTR( CastMemberList , Cast )
PROPERTYIMP_PTR( GenreList , Genres )

PROPERTYIMP ( bool , SerializeArtwork)
PROPERTYIMP ( bool , SerializeCast )
PROPERTYIMP ( bool , SerializeGenres )

public:

Expand All @@ -127,8 +131,10 @@ class SERVICE_PUBLIC VideoMetadataInfo : public QObject
m_Processed ( false ),
m_Artwork ( NULL ),
m_Cast ( NULL ),
m_Genres ( NULL ),
m_SerializeArtwork( true ),
m_SerializeCast ( true )
m_SerializeCast ( true ),
m_SerializeGenres ( true )
{
}

Expand All @@ -142,12 +148,17 @@ class SERVICE_PUBLIC VideoMetadataInfo : public QObject
m_Id = src.m_Id;
m_SerializeArtwork = src.m_SerializeArtwork;
m_SerializeCast = src.m_SerializeCast;
m_SerializeGenres = src.m_SerializeGenres;

if ( src.m_Artwork != NULL)
Artwork()->Copy( src.m_Artwork );

if (src.m_Cast != NULL)
Cast()->Copy( src.m_Cast );

if (src.m_Genres != NULL)
Genres()->Copy( src.m_Genres );

}
};

Expand All @@ -168,6 +179,9 @@ inline void VideoMetadataInfo::InitializeCustomTypes()

if (QMetaType::type( "DTC::CastMemberList" ) == 0)
CastMemberList::InitializeCustomTypes();

if (QMetaType::type( "DTC::GenreMemberList" ) == 0)
GenreList::InitializeCustomTypes();
}
}

Expand Down
Expand Up @@ -24,7 +24,7 @@ namespace DTC
class SERVICE_PUBLIC VideoMetadataInfoList : public QObject
{
Q_OBJECT
Q_CLASSINFO( "version", "1.01" );
Q_CLASSINFO( "version", "1.02" );

// Q_CLASSINFO Used to augment Metadata for properties.
// See datacontracthelper.h for details
Expand Down
Expand Up @@ -60,6 +60,7 @@ HEADERS += datacontracts/frontend.h datacontracts/frontendList.h
HEADERS += datacontracts/cutting.h datacontracts/cutList.h
HEADERS += datacontracts/backendInfo.h datacontracts/envInfo.h
HEADERS += datacontracts/buildInfo.h datacontracts/logInfo.h
HEADERS += datacontracts/genre.h datacontracts/genreList.h

HEADERS += enums/recStatus.h

Expand Down
29 changes: 29 additions & 0 deletions mythtv/programs/mythbackend/services/serviceUtil.cpp
Expand Up @@ -349,6 +349,33 @@ void FillArtworkInfoList( DTC::ArtworkInfoList *pArtworkInfoList,
//
/////////////////////////////////////////////////////////////////////////////

void FillGenreList(DTC::GenreList* pGenreList, int videoID)
{
if (!pGenreList)
return;

MSqlQuery query(MSqlQuery::InitCon());
query.prepare("SELECT genre from videogenre "
"LEFT JOIN videometadatagenre ON videometadatagenre.idgenre = videogenre.intid "
"WHERE idvideo = :ID;"
"ORDER BY genre;");
query.bindValue(":ID", videoID);

if (query.exec() && query.size() > 0)
{
while (query.next())
{
DTC::Genre *pGenre = pGenreList->AddNewGenre();
QString genre = query.value(0).toString();
pGenre->setName(genre);
}
}
}

/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////

void FillVideoMetadataInfo (
DTC::VideoMetadataInfo *pVideoMetadataInfo,
VideoMetadataListManager::VideoMetadataPtr pMetadata,
Expand Down Expand Up @@ -436,6 +463,8 @@ void FillVideoMetadataInfo (
.arg(pMetadata->GetScreenshot()));
}
}

FillGenreList(pVideoMetadataInfo->Genres(), pVideoMetadataInfo->Id());
}

/////////////////////////////////////////////////////////////////////////////
Expand Down
3 changes: 3 additions & 0 deletions mythtv/programs/mythbackend/services/serviceUtil.h
Expand Up @@ -34,6 +34,7 @@
#include "datacontracts/input.h"
#include "datacontracts/castMemberList.h"
#include "datacontracts/cutList.h"
#include "datacontracts/genreList.h"

#include "programinfo.h"
#include "recordingrule.h"
Expand Down Expand Up @@ -66,6 +67,8 @@ void FillArtworkInfoList( DTC::ArtworkInfoList *pArtworkInfoList,
const QString &sInetref,
uint nSeason );

void FillGenreList( DTC::GenreList *pGenreList, int videoID);

void FillVideoMetadataInfo (
DTC::VideoMetadataInfo *pVideoMetadataInfo,
VideoMetadataListManager::VideoMetadataPtr pMetadata,
Expand Down

0 comments on commit ab1c3e8

Please sign in to comment.