MythTV  master
grabbersettings.cpp
Go to the documentation of this file.
1 #include <iostream>
2 
3 // qt
4 #include <QString>
5 #include <QString>
6 #include <QStringList>
7 
8 // myth
9 #include "mythcorecontext.h"
10 #include "mythsystemlegacy.h"
11 #include "mythdbcon.h"
12 #include "mythdirs.h"
13 
14 #include "mythprogressdialog.h"
15 #include "metadatacommon.h"
16 #include "grabbersettings.h"
17 
18 using namespace std;
19 
20 // ---------------------------------------------------
21 
23 {
24  // Load the theme for this screen
25  bool foundtheme = LoadWindowFromXML("config-ui.xml", "grabbersettings", this);
26  if (!foundtheme)
27  return false;
28 
29  m_movieGrabberButtonList = dynamic_cast<MythUIButtonList *> (GetChild("moviegrabber"));
30  m_tvGrabberButtonList = dynamic_cast<MythUIButtonList *> (GetChild("tvgrabber"));
31  m_gameGrabberButtonList = dynamic_cast<MythUIButtonList *> (GetChild("gamegrabber"));
32 
33  m_dailyUpdatesCheck = dynamic_cast<MythUICheckBox *> (GetChild("dailyupdates"));
34 
35  m_okButton = dynamic_cast<MythUIButton *> (GetChild("ok"));
36  m_cancelButton = dynamic_cast<MythUIButton *> (GetChild("cancel"));
37 
38  if (!m_movieGrabberButtonList || !m_tvGrabberButtonList ||
39  !m_gameGrabberButtonList || !m_dailyUpdatesCheck || !m_okButton || !m_cancelButton)
40  {
41  LOG(VB_GENERAL, LOG_ERR, "Theme is missing critical theme elements.");
42  return false;
43  }
44 
45  m_movieGrabberButtonList->SetHelpText(tr("Select a source to use when searching for "
46  "information and artwork about movies."));
47  m_tvGrabberButtonList->SetHelpText(tr("Select a source to use when searching for "
48  "information and artwork about television."));
49  m_gameGrabberButtonList->SetHelpText(tr("Select a source to use when searching for "
50  "information and artwork about video games."));
51  m_okButton->SetHelpText(tr("Save your changes and close this window."));
52  m_cancelButton->SetHelpText(tr("Discard your changes and close this window."));
53 
54  m_dailyUpdatesCheck->SetHelpText(tr("If set, the backend will attempt to "
55  "perform artwork updates for recordings daily. When "
56  "new seasons begin to record, this will attempt to "
57  "provide you with fresh, relevant artwork while "
58  "preserving the artwork assigned to old recordings."));
59 
60  connect(m_okButton, SIGNAL(Clicked()), this, SLOT(slotSave()));
61  connect(m_cancelButton, SIGNAL(Clicked()), this, SLOT(Close()));
62 
63  BuildFocusList();
64 
65  QString message = tr("Searching for data sources...");
66  LoadInBackground(message);
67 
68  return true;
69 }
70 
72 {
73  m_movieGrabberList = MetaGrabberScript::GetList(kGrabberMovie, true);
75  m_gameGrabberList = MetaGrabberScript::GetList(kGrabberGame);
76 }
77 
79 {
80  for (GrabberList::const_iterator it = m_movieGrabberList.begin();
81  it != m_movieGrabberList.end(); ++it)
82  {
83  InfoMap map;
84  it->toMap(map);
85  MythUIButtonListItem *item =
86  new MythUIButtonListItem(m_movieGrabberButtonList, it->GetName());
87  item->SetData(it->GetRelPath());
88  item->SetTextFromMap(map);
89  }
90 
91  m_movieGrabberList.clear();
92 
93  for (GrabberList::const_iterator it = m_tvGrabberList.begin();
94  it != m_tvGrabberList.end(); ++it)
95  {
96  InfoMap map;
97  it->toMap(map);
98  MythUIButtonListItem *item =
99  new MythUIButtonListItem(m_tvGrabberButtonList, it->GetName());
100  item->SetData(it->GetRelPath());
101  item->SetTextFromMap(map);
102  }
103 
104  m_tvGrabberList.clear();
105 
106  for (GrabberList::const_iterator it = m_gameGrabberList.begin();
107  it != m_gameGrabberList.end(); ++it)
108  {
109  InfoMap map;
110  it->toMap(map);
111  MythUIButtonListItem *item =
112  new MythUIButtonListItem(m_gameGrabberButtonList, it->GetName());
113  item->SetData(it->GetRelPath());
114  item->SetTextFromMap(map);
115  }
116 
117  m_gameGrabberList.clear();
118 
119  // TODO
120  // pull these values from MetaGrabberScript so we're not defining them in multiple locations
121  QString currentTVGrabber = gCoreContext->GetSetting("TelevisionGrabber",
122  "metadata/Television/ttvdb.py");
123  QString currentMovieGrabber = gCoreContext->GetSetting("MovieGrabber",
124  "metadata/Movie/tmdb3.py");
125  QString currentGameGrabber = gCoreContext->GetSetting("mythgame.MetadataGrabber",
126  "metadata/Game/giantbomb.py");
127 
128  m_movieGrabberButtonList->SetValueByData(qVariantFromValue(currentMovieGrabber));
129  m_tvGrabberButtonList->SetValueByData(qVariantFromValue(currentTVGrabber));
130  m_gameGrabberButtonList->SetValueByData(qVariantFromValue(currentGameGrabber));
131 
132  int updates =
133  gCoreContext->GetNumSetting("DailyArtworkUpdates", 0);
134  if (updates == 1)
135  m_dailyUpdatesCheck->SetCheckState(MythUIStateType::Full);
136 }
137 
139 {
140  gCoreContext->SaveSettingOnHost("TelevisionGrabber", m_tvGrabberButtonList->GetDataValue().toString(), "");
141  gCoreContext->SaveSettingOnHost("MovieGrabber", m_movieGrabberButtonList->GetDataValue().toString(), "");
142  gCoreContext->SaveSetting("mythgame.MetadataGrabber", m_gameGrabberButtonList->GetDataValue().toString());
143 
144  int dailyupdatestate = 0;
145  if (m_dailyUpdatesCheck->GetCheckState() == MythUIStateType::Full)
146  dailyupdatestate = 1;
147  gCoreContext->SaveSettingOnHost("DailyArtworkUpdates",
148  QString::number(dailyupdatestate), "");
149 
150  Close();
151 }
152 
153 bool GrabberSettings::keyPressEvent(QKeyEvent *event)
154 {
155  if (GetFocusWidget()->keyPressEvent(event))
156  return true;
157 
158  return MythScreenType::keyPressEvent(event);
159 }
void SetData(QVariant data)
void SaveSetting(const QString &key, int newValue)
bool Create(void) override
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
static GrabberList GetList(bool refresh=false)
QHash< QString, QString > InfoMap
Definition: mythtypes.h:15
QString GetSetting(const QString &key, const QString &defaultval="")
int GetNumSetting(const QString &key, int defaultval=0)
bool keyPressEvent(QKeyEvent *) override
Key event handler.
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
void Init(void) override
Used after calling Load() to assign data to widgets and other UI initilisation which is prohibited in...
bool SaveSettingOnHost(const QString &key, const QString &newValue, const QString &host)
void Load(void) override
Load data which will ultimately be displayed on-screen or used to determine what appears on-screen (S...
void SetTextFromMap(const InfoMap &infoMap, const QString &state="")
bool keyPressEvent(QKeyEvent *) override
Key event handler.