MythTV  master
romedit.cpp
Go to the documentation of this file.
1 #include <QImageReader>
2 #include <QApplication>
3 
4 #include <mythcontext.h>
5 #include <mythdirs.h>
6 
7 #include <mythmainwindow.h>
8 #include <mythdialogbox.h>
9 #include <mythuibuttonlist.h>
10 #include <mythuitext.h>
11 #include <mythuitextedit.h>
12 #include <mythuibutton.h>
13 #include <mythuicheckbox.h>
14 #include <mythuifilebrowser.h>
15 
16 #include "romedit.h"
17 #include "rominfo.h"
18 
20  const QString& name, RomInfo *romInfo)
21  : MythScreenType(parent, name)
22 {
23  m_workingRomInfo = new RomInfo(*romInfo);
24 }
25 
27 {
28  delete m_workingRomInfo;
29 }
30 
32 {
33  if (!LoadWindowFromXML("game-ui.xml", "edit_metadata", this))
34  return false;
35 
36  bool err = false;
37  UIUtilE::Assign(this, m_gamenameEdit, "title_edit", &err);
38  UIUtilE::Assign(this, m_genreEdit, "genre_edit", &err);
39  UIUtilE::Assign(this, m_yearEdit, "year_edit", &err);
40  UIUtilE::Assign(this, m_countryEdit, "country_edit", &err);
41  UIUtilE::Assign(this, m_plotEdit, "description_edit", &err);
42  UIUtilE::Assign(this, m_publisherEdit, "publisher_edit", &err);
43 
44  UIUtilE::Assign(this, m_favoriteCheck, "favorite_check", &err);
45 
46  UIUtilE::Assign(this, m_screenshotButton, "screenshot_button", &err);
47  UIUtilE::Assign(this, m_screenshotText, "screenshot_text", &err);
48  UIUtilE::Assign(this, m_fanartButton, "fanart_button", &err);
49  UIUtilE::Assign(this, m_fanartText, "fanart_text", &err);
50  UIUtilE::Assign(this, m_boxartButton, "coverart_button", &err);
51  UIUtilE::Assign(this, m_boxartText, "coverart_text", &err);
52 
53  UIUtilE::Assign(this, m_doneButton, "done_button", &err);
54 
55  if (err)
56  {
57  LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'edit_metadata'");
58  return false;
59  }
60 
61  fillWidgets();
62 
64 
65  connect(m_gamenameEdit, SIGNAL(valueChanged()), SLOT(SetGamename()));
66  connect(m_genreEdit, SIGNAL(valueChanged()), SLOT(SetGenre()));
67  connect(m_yearEdit, SIGNAL(valueChanged()), SLOT(SetYear()));
68  connect(m_countryEdit, SIGNAL(valueChanged()), SLOT(SetCountry()));
69  connect(m_plotEdit, SIGNAL(valueChanged()), SLOT(SetPlot()));
70  connect(m_publisherEdit, SIGNAL(valueChanged()), SLOT(SetPublisher()));
71 
72  connect(m_favoriteCheck, SIGNAL(valueChanged()), SLOT(ToggleFavorite()));
73 
74  connect(m_screenshotButton, SIGNAL(Clicked()), SLOT(FindScreenshot()));
75  connect(m_fanartButton, SIGNAL(Clicked()), SLOT(FindFanart()));
76  connect(m_boxartButton, SIGNAL(Clicked()), SLOT(FindBoxart()));
77 
78  connect(m_doneButton, SIGNAL(Clicked()), SLOT(SaveAndExit()));
79 
80  return true;
81 }
82 
83 namespace
84 {
85  QStringList GetSupportedImageExtensionFilter()
86  {
87  QStringList ret;
88 
89  QList<QByteArray> exts = QImageReader::supportedImageFormats();
90  foreach (auto & ext, exts)
91  ret.append(QString("*.").append(ext));
92 
93  return ret;
94  }
95 
96  void FindImagePopup(const QString &prefix, const QString &prefixAlt,
97  QObject &inst, const QString &returnEvent)
98  {
99  QString fp = prefix.isEmpty() ? prefixAlt : prefix;
100 
101  MythScreenStack *popupStack =
102  GetMythMainWindow()->GetStack("popup stack");
103 
104  auto *fb = new MythUIFileBrowser(popupStack, fp);
105  fb->SetNameFilter(GetSupportedImageExtensionFilter());
106  if (fb->Create())
107  {
108  fb->SetReturnEvent(&inst, returnEvent);
109  popupStack->AddScreen(fb);
110  }
111  else
112  delete fb;
113  }
114 
115  const QString CEID_SCREENSHOTFILE = "screenshotfile";
116  const QString CEID_FANARTFILE = "fanartfile";
117  const QString CEID_BOXARTFILE = "boxartfile";
118 }
119 
121 {
122  if (auto dce = dynamic_cast<DialogCompletionEvent*>(event))
123  {
124  const QString resultid = dce->GetId();
125 
126  if (resultid == CEID_FANARTFILE)
127  SetFanart(dce->GetResultText());
128  else if (resultid == CEID_SCREENSHOTFILE)
129  SetScreenshot(dce->GetResultText());
130  else if (resultid == CEID_BOXARTFILE)
131  SetBoxart(dce->GetResultText());
132  }
133 }
134 
136 {
143 
144  if (m_workingRomInfo->Favorite())
146 
150 }
151 
152 void EditRomInfoDialog::SetReturnEvent(QObject *retobject,
153  const QString &resultid)
154 {
155  m_retObject = retobject;
156  m_id = resultid;
157 }
158 
160 {
161  if (m_retObject)
162  {
163  auto *romInfo = new RomInfo(*m_workingRomInfo);
164  auto *dce = new DialogCompletionEvent(m_id, 0, "",
165  QVariant::fromValue(romInfo));
166 
167  QApplication::postEvent(m_retObject, dce);
168  }
169  Close();
170 }
171 
173 {
175 }
176 
178 {
180 }
181 
183 {
185 }
186 
188 {
190 }
191 
193 {
195 }
196 
198 {
200 }
201 
203 {
205 }
206 
208 {
209  FindImagePopup(gCoreContext->GetSetting("mythgame.screenshotDir"),
210  GetConfDir() + "/MythGame/Screenshots",
211  *this, CEID_SCREENSHOTFILE);
212 }
213 
215 {
216  FindImagePopup(gCoreContext->GetSetting("mythgame.fanartDir"),
217  GetConfDir() + "/MythGame/Fanart",
218  *this, CEID_FANARTFILE);
219 }
220 
222 {
223  FindImagePopup(gCoreContext->GetSetting("mythgame.boxartDir"),
224  GetConfDir() + "/MythGame/Boxart",
225  *this, CEID_BOXARTFILE);
226 }
227 
229 {
230  if (file.isEmpty())
231  return;
232 
235 }
236 
237 void EditRomInfoDialog::SetFanart(const QString& file)
238 {
239  if (file.isEmpty())
240  return;
241 
244 }
245 
246 void EditRomInfoDialog::SetBoxart(const QString& file)
247 {
248  if (file.isEmpty())
249  return;
250 
253 }
void SetPublisher()
Definition: romedit.cpp:197
void setPlot(const QString &lplot)
Definition: rominfo.h:124
QString Screenshot() const
Definition: rominfo.h:84
void customEvent(QEvent *levent) override
Definition: romedit.cpp:120
MythUIText * m_boxartText
Definition: romedit.h:59
MythUIText * m_fanartText
Definition: romedit.h:57
QString Plot() const
Definition: rominfo.h:123
void fillWidgets()
Definition: romedit.cpp:135
MythUITextEdit * m_genreEdit
Definition: romedit.h:48
virtual void SetText(const QString &text)
Definition: mythuitext.cpp:135
QString Gamename() const
Definition: rominfo.h:99
MythUIButton * m_fanartButton
Definition: romedit.h:56
MythScreenStack * GetStack(const QString &stackname)
QString Country() const
Definition: rominfo.h:105
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
void setBoxart(const QString &lboxart)
Definition: rominfo.h:91
void ToggleFavorite()
Definition: romedit.cpp:202
void SetBoxart(const QString &file)
Definition: romedit.cpp:246
MythUITextEdit * m_plotEdit
Definition: romedit.h:51
void BuildFocusList(void)
MythUIButton * m_screenshotButton
Definition: romedit.h:54
QString GetConfDir(void)
Definition: mythdirs.cpp:224
virtual void Close()
void setPublisher(const QString &lpublisher)
Definition: rominfo.h:127
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
MythUITextEdit * m_gamenameEdit
Definition: romedit.h:47
void SetReturnEvent(QObject *retobject, const QString &resultid)
Definition: romedit.cpp:152
MythUIText * m_screenshotText
Definition: romedit.h:55
void setScreenshot(const QString &lscreenshot)
Definition: rominfo.h:85
QString m_id
Definition: romedit.h:44
QString GetSetting(const QString &key, const QString &defaultval="")
bool Create() override
Definition: romedit.cpp:31
static bool Assign(ContainerType *container, UIType *&item, const QString &name, bool *err=nullptr)
Definition: mythuiutils.h:27
MythUITextEdit * m_countryEdit
Definition: romedit.h:50
static bool LoadWindowFromXML(const QString &xmlfile, const QString &windowname, MythUIType *parent)
~EditRomInfoDialog() override
Definition: romedit.cpp:26
void setFavorite(bool updateDatabase=false)
Definition: rominfo.cpp:213
void SetText(const QString &text, bool moveCursor=true)
MythMainWindow * GetMythMainWindow(void)
QString Year() const
Definition: rominfo.h:132
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
void SetFanart(const QString &file)
Definition: romedit.cpp:237
void SetScreenshot(const QString &file)
Definition: romedit.cpp:228
QString Boxart() const
Definition: rominfo.h:90
QString Genre() const
Definition: rominfo.h:102
MythUICheckBox * m_favoriteCheck
Definition: romedit.h:53
void setCountry(const QString &lcountry)
Definition: rominfo.h:106
QObject * m_retObject
Definition: romedit.h:45
QString Fanart() const
Definition: rominfo.h:87
MythUIButton * m_boxartButton
Definition: romedit.h:58
void SetCheckState(MythUIStateType::StateType state)
void setFanart(const QString &lfanart)
Definition: rominfo.h:88
RomInfo * m_workingRomInfo
Definition: romedit.h:43
EditRomInfoDialog(MythScreenStack *parent, const QString &name, RomInfo *romInfo)
Definition: romedit.cpp:19
void setYear(const QString &lyear)
Definition: rominfo.h:133
void FindScreenshot()
Definition: romedit.cpp:207
Screen in which all other widgets are contained and rendered.
MythUITextEdit * m_publisherEdit
Definition: romedit.h:52
QString Publisher() const
Definition: rominfo.h:126
void setGenre(const QString &lgenre)
Definition: rominfo.h:103
MythUITextEdit * m_yearEdit
Definition: romedit.h:49
Event dispatched from MythUI modal dialogs to a listening class containing a result of some form.
Definition: mythdialogbox.h:41
MythUIButton * m_doneButton
Definition: romedit.h:60
void SaveAndExit()
Definition: romedit.cpp:159
void setGamename(const QString &lgamename)
Definition: rominfo.h:100
void SetGamename()
Definition: romedit.cpp:172
QString GetText(void) const
int Favorite() const
Definition: rominfo.h:138