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  MythUIFileBrowser *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 (event->type() == DialogCompletionEvent::kEventType)
125  {
127  const QString resultid = dce->GetId();
128 
129  if (resultid == CEID_FANARTFILE)
130  SetFanart(dce->GetResultText());
131  else if (resultid == CEID_SCREENSHOTFILE)
133  else if (resultid == CEID_BOXARTFILE)
134  SetBoxart(dce->GetResultText());
135  }
136 }
137 
139 {
146 
147  if (m_workingRomInfo->Favorite())
149 
153 }
154 
155 void EditRomInfoDialog::SetReturnEvent(QObject *retobject,
156  const QString &resultid)
157 {
158  m_retObject = retobject;
159  m_id = resultid;
160 }
161 
163 {
164  if (m_retObject)
165  {
166  RomInfo *romInfo = new RomInfo(*m_workingRomInfo);
167  DialogCompletionEvent *dce =
168  new DialogCompletionEvent(m_id, 0, "",
169  qVariantFromValue(romInfo));
170 
171  QApplication::postEvent(m_retObject, dce);
172  }
173  Close();
174 }
175 
177 {
179 }
180 
182 {
184 }
185 
187 {
189 }
190 
192 {
194 }
195 
197 {
199 }
200 
202 {
204 }
205 
207 {
209 }
210 
212 {
213  FindImagePopup(gCoreContext->GetSetting("mythgame.screenshotDir"),
214  GetConfDir() + "/MythGame/Screenshots",
215  *this, CEID_SCREENSHOTFILE);
216 }
217 
219 {
220  FindImagePopup(gCoreContext->GetSetting("mythgame.fanartDir"),
221  GetConfDir() + "/MythGame/Fanart",
222  *this, CEID_FANARTFILE);
223 }
224 
226 {
227  FindImagePopup(gCoreContext->GetSetting("mythgame.boxartDir"),
228  GetConfDir() + "/MythGame/Boxart",
229  *this, CEID_BOXARTFILE);
230 }
231 
232 void EditRomInfoDialog::SetScreenshot(const QString& file)
233 {
234  if (file.isEmpty())
235  return;
236 
238  m_screenshotText->SetText(file);
239 }
240 
241 void EditRomInfoDialog::SetFanart(const QString& file)
242 {
243  if (file.isEmpty())
244  return;
245 
247  m_fanartText->SetText(file);
248 }
249 
250 void EditRomInfoDialog::SetBoxart(const QString& file)
251 {
252  if (file.isEmpty())
253  return;
254 
256  m_boxartText->SetText(file);
257 }
void SetPublisher()
Definition: romedit.cpp:201
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:138
MythUITextEdit * m_genreEdit
Definition: romedit.h:48
void SetReturnEvent(QObject *retobject, const QString &resultid)
virtual void SetText(const QString &text)
Definition: mythuitext.cpp:136
bool Create(void) override
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:206
void SetBoxart(const QString &file)
Definition: romedit.cpp:250
MythUITextEdit * m_plotEdit
Definition: romedit.h:51
void BuildFocusList(void)
static Type kEventType
Definition: mythdialogbox.h:50
MythUIButton * m_screenshotButton
Definition: romedit.h:54
QString GetConfDir(void)
Definition: mythdirs.cpp:224
void SetNameFilter(QStringList filter)
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:155
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
const char * name
Definition: ParseText.cpp:328
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:241
void SetScreenshot(const QString &file)
Definition: romedit.cpp:232
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:211
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:162
void setGamename(const QString &lgamename)
Definition: rominfo.h:98
void SetGamename()
Definition: romedit.cpp:176
QString GetText(void) const
int Favorite() const
Definition: rominfo.h:136