Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
MythFrontend: Add a Grabber Settings window.
Adds a central configuration location to choose metadata sources.  Currently supported are Movies, Television, and Games.  We needed this in order to start using the metadata classes in core MythTV to get artwork and additional information about recorded items.  Currently there is only one option each for Movies and Television, but hopefully that will soon change.  There are two options for MythGame but one of them needs a slight tweak before it will appear in this screen.

This commit does not add the option to the menu themes as I have not completed the default themes (nor have I begun them).
  • Loading branch information
Robert McNamara committed Jan 23, 2011
1 parent 49a53db commit 75c7dee
Show file tree
Hide file tree
Showing 4 changed files with 331 additions and 0 deletions.
271 changes: 271 additions & 0 deletions mythtv/programs/mythfrontend/grabbersettings.cpp
@@ -0,0 +1,271 @@
#include <iostream>

// qt
#include <QString>
#include <QProcess>
#include <QString>
#include <QStringList>

// myth
#include "mythcorecontext.h"
#include "mythdbcon.h"
#include "mythdirs.h"

#include "mythprogressdialog.h"
#include "metadatacommon.h"
#include "grabbersettings.h"

using namespace std;

// ---------------------------------------------------

GrabberSettings::GrabberSettings(MythScreenStack *parent, const char *name)
: MythScreenType(parent, name),
m_movieGrabberButtonList(NULL), m_tvGrabberButtonList(NULL),
m_gameGrabberButtonList(NULL), m_okButton(NULL),
m_cancelButton(NULL)
{
}

bool GrabberSettings::Create()
{
bool foundtheme = false;

// Load the theme for this screen
foundtheme = LoadWindowFromXML("config-ui.xml", "grabbersettings", this);

if (!foundtheme)
return false;

m_movieGrabberButtonList = dynamic_cast<MythUIButtonList *> (GetChild("moviegrabber"));
m_tvGrabberButtonList = dynamic_cast<MythUIButtonList *> (GetChild("tvgrabber"));
m_gameGrabberButtonList = dynamic_cast<MythUIButtonList *> (GetChild("gamegrabber"));

m_okButton = dynamic_cast<MythUIButton *> (GetChild("ok"));
m_cancelButton = dynamic_cast<MythUIButton *> (GetChild("cancel"));

if (!m_movieGrabberButtonList || !m_tvGrabberButtonList ||
!m_gameGrabberButtonList ||!m_okButton || !m_cancelButton)
{
VERBOSE(VB_IMPORTANT, "Theme is missing critical theme elements.");
return false;
}

m_movieGrabberButtonList->SetHelpText(tr("Select an source to use when searching for "
"information and artwork about movies."));
m_tvGrabberButtonList->SetHelpText(tr("Select a source to use when searching for "
"information and artwork about television."));
m_gameGrabberButtonList->SetHelpText(tr("Select a source to use when searching for "
"information and artwork about video games."));

connect(m_okButton, SIGNAL(Clicked()), this, SLOT(slotSave()));
connect(m_cancelButton, SIGNAL(Clicked()), this, SLOT(Close()));

BuildFocusList();

QString message = tr("Searching for data sources...");
LoadInBackground(message);

return true;
}

GrabberSettings::~GrabberSettings()
{
}

void GrabberSettings::Load(void)
{
QString busymessage = tr("Searching for data sources...");
MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
MythUIBusyDialog *busyPopup = new MythUIBusyDialog(busymessage, popupStack,
"grabberbusydialog");

if (busyPopup->Create())
{
popupStack->AddScreen(busyPopup, false);
}
else
{
delete busyPopup;
busyPopup = NULL;
}

QDir TVScriptPath = QString("%1metadata/Television/").arg(GetShareDir());
QStringList TVScripts = TVScriptPath.entryList(QDir::Files);
QDir MovieScriptPath = QString("%1metadata/Movie/").arg(GetShareDir());
QStringList MovieScripts = MovieScriptPath.entryList(QDir::Files);
QDir GameScriptPath = QString("%1metadata/Game/").arg(GetShareDir());
QStringList GameScripts = GameScriptPath.entryList(QDir::Files);

if (MovieScripts.count())
{
for (QStringList::const_iterator i = MovieScripts.begin();
i != MovieScripts.end(); i++)
{
QString commandline = QString("%1/%2")
.arg(MovieScriptPath.path()).arg(*i);
MythSystem grabber(commandline, QStringList() << "-v", kMSRunShell | kMSStdOut | kMSBuffered);
grabber.Run();
grabber.Wait();
QByteArray result = grabber.ReadAll();

if (!result.isEmpty())
{
QDomDocument doc;
doc.setContent(result, true);
QDomElement root = doc.documentElement();
if (!root.isNull())
{
MetaGrabberScript *script = ParseGrabberVersion(root);
if (!script->GetName().isEmpty())
m_movieGrabberList.append(script);
}
}
}
}

if (TVScripts.count())
{
for (QStringList::const_iterator i = TVScripts.end() - 1;
i != TVScripts.begin() - 1; --i)
{
QString commandline = QString("%1/%2")
.arg(TVScriptPath.path()).arg(*i);
MythSystem grabber(commandline, QStringList() << "-v", kMSRunShell | kMSStdOut | kMSBuffered);
grabber.Run();
grabber.Wait();
QByteArray result = grabber.ReadAll();

if (!result.isEmpty())
{
QDomDocument doc;
doc.setContent(result, true);
QDomElement root = doc.documentElement();
if (!root.isNull())
{
MetaGrabberScript *script = ParseGrabberVersion(root);
if (!script->GetName().isEmpty())
m_tvGrabberList.append(script);

}
}
}
}

if (GameScripts.count())
{
for (QStringList::const_iterator i = GameScripts.end() - 1;
i != GameScripts.begin() - 1; --i)
{
QString commandline = QString("%1/%2")
.arg(GameScriptPath.path()).arg(*i);
MythSystem grabber(commandline, QStringList() << "-v", kMSRunShell | kMSStdOut | kMSBuffered);
grabber.Run();
grabber.Wait();
QByteArray result = grabber.ReadAll();

if (!result.isEmpty())
{
QDomDocument doc;
doc.setContent(result, true);
QDomElement root = doc.documentElement();
if (!root.isNull())
{
MetaGrabberScript *script = ParseGrabberVersion(root);
if (!script->GetName().isEmpty())
m_gameGrabberList.append(script);
}
}
}
}

if (busyPopup)
{
busyPopup->Close();
busyPopup = NULL;
}
}

void GrabberSettings::Init(void)
{
for (QList<MetaGrabberScript*>::const_iterator it = m_movieGrabberList.begin();
it != m_movieGrabberList.end(); it++)
{
QString commandline = QString("%1metadata/Movie/%2")
.arg(GetShareDir()).arg((*it)->GetCommand());
MetadataMap map;
(*it)->toMap(map);
MythUIButtonListItem *item =
new MythUIButtonListItem(m_movieGrabberButtonList, (*it)->GetName());
item->SetData(commandline);
item->SetTextFromMap(map);
}

m_movieGrabberList.clear();

for (QList<MetaGrabberScript*>::const_iterator it = m_tvGrabberList.begin();
it != m_tvGrabberList.end(); it++)
{
QString commandline = QString("%1metadata/Television/%2")
.arg(GetShareDir()).arg((*it)->GetCommand());
MetadataMap map;
(*it)->toMap(map);
MythUIButtonListItem *item =
new MythUIButtonListItem(m_tvGrabberButtonList, (*it)->GetName());
item->SetData(commandline);
item->SetTextFromMap(map);
}

m_tvGrabberList.clear();

for (QList<MetaGrabberScript*>::const_iterator it = m_gameGrabberList.begin();
it != m_gameGrabberList.end(); it++)
{
QString commandline = QString("%1metadata/Game/%2")
.arg(GetShareDir()).arg((*it)->GetCommand());
MetadataMap map;
(*it)->toMap(map);
MythUIButtonListItem *item =
new MythUIButtonListItem(m_gameGrabberButtonList, (*it)->GetName());
item->SetData(commandline);
item->SetTextFromMap(map);
}

m_gameGrabberList.clear();

QString currentTVGrabber = gCoreContext->GetSetting("TelevisionGrabber",
QString("%1metadata/Television/%2")
.arg(GetShareDir()).arg("ttvdb.py"));
QString currentMovieGrabber = gCoreContext->GetSetting("MovieGrabber",
QString("%1metadata/Movie/%2")
.arg(GetShareDir()).arg("tmdb.py"));
QString currentGameGrabber = gCoreContext->GetSetting("mythgame.MetadataGrabber",
QString("%1metadata/Game/%2")
.arg(GetShareDir()).arg("giantbomb.py"));

m_movieGrabberButtonList->SetValueByData(qVariantFromValue(currentMovieGrabber));
m_tvGrabberButtonList->SetValueByData(qVariantFromValue(currentTVGrabber));
m_gameGrabberButtonList->SetValueByData(qVariantFromValue(currentGameGrabber));
}

void GrabberSettings::slotSave(void)
{
gCoreContext->SaveSetting("TelevisionGrabber", m_tvGrabberButtonList->GetDataValue().toString());
gCoreContext->SaveSetting("MovieGrabber", m_movieGrabberButtonList->GetDataValue().toString());
gCoreContext->SaveSetting("mythgame.MetadataGrabber", m_gameGrabberButtonList->GetDataValue().toString());

Close();
}

bool GrabberSettings::keyPressEvent(QKeyEvent *event)
{
if (GetFocusWidget()->keyPressEvent(event))
return true;

bool handled = false;

if (!handled && MythScreenType::keyPressEvent(event))
handled = true;

return handled;
}
47 changes: 47 additions & 0 deletions mythtv/programs/mythfrontend/grabbersettings.h
@@ -0,0 +1,47 @@
#ifndef GRABBERSETTINGS_H
#define GRABBERSETTINGS_H

#include "uitypes.h"
#include "mythwidgets.h"
#include "mythdialogs.h"

// libmythui
#include "mythuibutton.h"
#include "mythuibuttonlist.h"
#include "mythscreentype.h"
#include "mythdialogbox.h"

class MetaGrabberScript;
class GrabberSettings : public MythScreenType
{
Q_OBJECT

public:

GrabberSettings(MythScreenStack *parent, const char *name = 0);
~GrabberSettings();

bool Create(void);
bool keyPressEvent(QKeyEvent *);

private:
virtual void Load(void);
virtual void Init(void);

QList<MetaGrabberScript*> m_movieGrabberList;
QList<MetaGrabberScript*> m_tvGrabberList;
QList<MetaGrabberScript*> m_gameGrabberList;

MythUIButtonList *m_movieGrabberButtonList;
MythUIButtonList *m_tvGrabberButtonList;
MythUIButtonList *m_gameGrabberButtonList;

MythUIButton *m_okButton;
MythUIButton *m_cancelButton;

private slots:
void slotSave(void);
};

#endif

11 changes: 11 additions & 0 deletions mythtv/programs/mythfrontend/main.cpp
Expand Up @@ -37,6 +37,7 @@ using namespace std;
#include "audiooutput.h"
#include "globalsettings.h"
#include "audiogeneralsettings.h"
#include "grabbersettings.h"
#include "profilegroup.h"
#include "playgroup.h"
#include "networkcontrol.h"
Expand Down Expand Up @@ -591,6 +592,16 @@ static void TVMenuCallback(void *data, QString &selection)
else
delete sw;
}
else if (sel == "settings grabbers")
{
MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack();
GrabberSettings *gs = new GrabberSettings(mainStack, "grabbersettings");

if (gs->Create())
mainStack->AddScreen(gs);
else
delete gs;
}
else if (sel == "screensetupwizard")
{
startAppearWiz();
Expand Down
2 changes: 2 additions & 0 deletions mythtv/programs/mythfrontend/mythfrontend.pro
Expand Up @@ -33,6 +33,7 @@ HEADERS += proglist.h proglist_helpers.h
HEADERS += playbackboxhelper.h viewschedulediff.h
HEADERS += themechooser.h setupwizard_general.h
HEADERS += setupwizard_audio.h setupwizard_video.h
HEADERS += grabbersettings.h

SOURCES += main.cpp playbackbox.cpp viewscheduled.cpp audiogeneralsettings.cpp
SOURCES += globalsettings.cpp manualschedule.cpp programrecpriority.cpp
Expand All @@ -47,6 +48,7 @@ SOURCES += proglist.cpp proglist_helpers.cpp
SOURCES += playbackboxhelper.cpp viewschedulediff.cpp
SOURCES += themechooser.cpp setupwizard_general.cpp
SOURCES += setupwizard_audio.cpp setupwizard_video.cpp
SOURCES += grabbersettings.cpp

macx {
mac_bundle {
Expand Down

0 comments on commit 75c7dee

Please sign in to comment.