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  for (QList<QByteArray>::iterator p = exts.begin(); p != exts.end(); ++p)
91  {
92  ret.append(QString("*.").append(*p));
93  }
94 
95  return ret;
96  }
97 
98  void FindImagePopup(const QString &prefix, const QString &prefixAlt,
99  QObject &inst, const QString &returnEvent)
100  {
101  QString fp = prefix.isEmpty() ? prefixAlt : prefix;
102 
103  MythScreenStack *popupStack =
104  GetMythMainWindow()->GetStack("popup stack");
105 
106  auto *fb = new MythUIFileBrowser(popupStack, fp);
107  fb->SetNameFilter(GetSupportedImageExtensionFilter());
108  if (fb->Create())
109  {
110  fb->SetReturnEvent(&inst, returnEvent);
111  popupStack->AddScreen(fb);
112  }
113  else
114  delete fb;
115  }
116 
117  const QString CEID_SCREENSHOTFILE = "screenshotfile";
118  const QString CEID_FANARTFILE = "fanartfile";
119  const QString CEID_BOXARTFILE = "boxartfile";
120 }
121 
123 {
124  if (auto dce = dynamic_cast<DialogCompletionEvent*>(event))
125  {
126  const QString resultid = dce->GetId();
127 
128  if (resultid == CEID_FANARTFILE)
129  SetFanart(dce->GetResultText());
130  else if (resultid == CEID_SCREENSHOTFILE)
131  SetScreenshot(dce->GetResultText());
132  else if (resultid == CEID_BOXARTFILE)
133  SetBoxart(dce->GetResultText());
134  }
135 }
136 
138 {
145 
146  if (m_workingRomInfo->Favorite())
148 
152 }
153 
154 void EditRomInfoDialog::SetReturnEvent(QObject *retobject,
155  const QString &resultid)
156 {
157  m_retObject = retobject;
158  m_id = resultid;
159 }
160 
162 {
163  if (m_retObject)
164  {
165  auto *romInfo = new RomInfo(*m_workingRomInfo);
166  auto *dce = new DialogCompletionEvent(m_id, 0, "",
167  qVariantFromValue(romInfo));
168 
169  QApplication::postEvent(m_retObject, dce);
170  }
171  Close();
172 }
173 
175 {
177 }
178 
180 {
182 }
183 
185 {
187 }
188 
190 {
192 }
193 
195 {
197 }
198 
200 {
202 }
203 
205 {
207 }
208 
210 {
211  FindImagePopup(gCoreContext->GetSetting("mythgame.screenshotDir"),
212  GetConfDir() + "/MythGame/Screenshots",
213  *this, CEID_SCREENSHOTFILE);
214 }
215 
217 {
218  FindImagePopup(gCoreContext->GetSetting("mythgame.fanartDir"),
219  GetConfDir() + "/MythGame/Fanart",
220  *this, CEID_FANARTFILE);
221 }
222 
224 {
225  FindImagePopup(gCoreContext->GetSetting("mythgame.boxartDir"),
226  GetConfDir() + "/MythGame/Boxart",
227  *this, CEID_BOXARTFILE);
228 }
229 
231 {
232  if (file.isEmpty())
233  return;
234 
237 }
238 
239 void EditRomInfoDialog::SetFanart(const QString& file)
240 {
241  if (file.isEmpty())
242  return;
243 
246 }
247 
248 void EditRomInfoDialog::SetBoxart(const QString& file)
249 {
250  if (file.isEmpty())
251  return;
252 
255 }
void SetPublisher()
Definition: romedit.cpp:199
void setPlot(const QString &lplot)
Definition: rominfo.h:122
QString Screenshot() const
Definition: rominfo.h:82
void customEvent(QEvent *levent) override
Definition: romedit.cpp:122
MythUIText * m_boxartText
Definition: romedit.h:59
MythUIText * m_fanartText
Definition: romedit.h:57
QString Plot() const
Definition: rominfo.h:121
void fillWidgets()
Definition: romedit.cpp:137
MythUITextEdit * m_genreEdit
Definition: romedit.h:48
virtual void SetText(const QString &text)
Definition: mythuitext.cpp:135
QString Gamename() const
Definition: rominfo.h:97
MythUIButton * m_fanartButton
Definition: romedit.h:56
MythScreenStack * GetStack(const QString &stackname)
QString Country() const
Definition: rominfo.h:103
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
void setBoxart(const QString &lboxart)
Definition: rominfo.h:89
void ToggleFavorite()
Definition: romedit.cpp:204
void SetBoxart(const QString &file)
Definition: romedit.cpp:248
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:125
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:154
MythUIText * m_screenshotText
Definition: romedit.h:55
void setScreenshot(const QString &lscreenshot)
Definition: rominfo.h:83
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)
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:130
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
void SetFanart(const QString &file)
Definition: romedit.cpp:239
void SetScreenshot(const QString &file)
Definition: romedit.cpp:230
QString Boxart() const
Definition: rominfo.h:88
QString Genre() const
Definition: rominfo.h:100
MythUICheckBox * m_favoriteCheck
Definition: romedit.h:53
void setCountry(const QString &lcountry)
Definition: rominfo.h:104
QObject * m_retObject
Definition: romedit.h:45
QString Fanart() const
Definition: rominfo.h:85
MythUIButton * m_boxartButton
Definition: romedit.h:58
void SetCheckState(MythUIStateType::StateType state)
void setFanart(const QString &lfanart)
Definition: rominfo.h:86
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:131
void FindScreenshot()
Definition: romedit.cpp:209
Screen in which all other widgets are contained and rendered.
MythUITextEdit * m_publisherEdit
Definition: romedit.h:52
QString Publisher() const
Definition: rominfo.h:124
void setGenre(const QString &lgenre)
Definition: rominfo.h:101
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:37
MythUIButton * m_doneButton
Definition: romedit.h:60
void SaveAndExit()
Definition: romedit.cpp:161
void setGamename(const QString &lgamename)
Definition: rominfo.h:98
void SetGamename()
Definition: romedit.cpp:174
QString GetText(void) const
int Favorite() const
Definition: rominfo.h:136