MythTV  master
romedit.cpp
Go to the documentation of this file.
1 // Qt
2 #include <QImageReader>
3 #include <QApplication>
4 
5 // MythtTV
6 #include <libmyth/mythcontext.h>
7 #include <libmythbase/mythdirs.h>
10 #include <libmythui/mythuibutton.h>
14 #include <libmythui/mythuitext.h>
16 
17 //MythGame
18 #include "romedit.h"
19 #include "rominfo.h"
20 
22  const QString& name, RomInfo *romInfo)
23  : MythScreenType(parent, name)
24 {
25  m_workingRomInfo = new RomInfo(*romInfo);
26 }
27 
29 {
30  delete m_workingRomInfo;
31 }
32 
34 {
35  if (!LoadWindowFromXML("game-ui.xml", "edit_metadata", this))
36  return false;
37 
38  bool err = false;
39  UIUtilE::Assign(this, m_gamenameEdit, "title_edit", &err);
40  UIUtilE::Assign(this, m_genreEdit, "genre_edit", &err);
41  UIUtilE::Assign(this, m_yearEdit, "year_edit", &err);
42  UIUtilE::Assign(this, m_countryEdit, "country_edit", &err);
43  UIUtilE::Assign(this, m_plotEdit, "description_edit", &err);
44  UIUtilE::Assign(this, m_publisherEdit, "publisher_edit", &err);
45 
46  UIUtilE::Assign(this, m_favoriteCheck, "favorite_check", &err);
47 
48  UIUtilE::Assign(this, m_screenshotButton, "screenshot_button", &err);
49  UIUtilE::Assign(this, m_screenshotText, "screenshot_text", &err);
50  UIUtilE::Assign(this, m_fanartButton, "fanart_button", &err);
51  UIUtilE::Assign(this, m_fanartText, "fanart_text", &err);
52  UIUtilE::Assign(this, m_boxartButton, "coverart_button", &err);
53  UIUtilE::Assign(this, m_boxartText, "coverart_text", &err);
54 
55  UIUtilE::Assign(this, m_doneButton, "done_button", &err);
56 
57  if (err)
58  {
59  LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'edit_metadata'");
60  return false;
61  }
62 
63  fillWidgets();
64 
66 
73 
75 
79 
81 
82  return true;
83 }
84 
85 namespace
86 {
87  QStringList GetSupportedImageExtensionFilter()
88  {
89  QStringList ret;
90 
91  QList<QByteArray> exts = QImageReader::supportedImageFormats();
92  for (const auto & ext : qAsConst(exts))
93  ret.append(QString("*.").append(ext));
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  QVariant::fromValue(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 }
MythUIButton::Clicked
void Clicked()
RomInfo::Boxart
QString Boxart() const
Definition: rominfo.h:69
mythuitext.h
EditRomInfoDialog::m_yearEdit
MythUITextEdit * m_yearEdit
Definition: romedit.h:50
EditRomInfoDialog::SaveAndExit
void SaveAndExit()
Definition: romedit.cpp:161
RomInfo::Plot
QString Plot() const
Definition: rominfo.h:102
MythScreenType::Close
virtual void Close()
Definition: mythscreentype.cpp:386
RomInfo::Country
QString Country() const
Definition: rominfo.h:84
RomInfo::Gamename
QString Gamename() const
Definition: rominfo.h:78
EditRomInfoDialog::fillWidgets
void fillWidgets()
Definition: romedit.cpp:137
RomInfo::Favorite
bool Favorite() const
Definition: rominfo.h:117
RomInfo::setBoxart
void setBoxart(const QString &lboxart)
Definition: rominfo.h:70
EditRomInfoDialog::FindFanart
void FindFanart()
Definition: romedit.cpp:216
EditRomInfoDialog::SetCountry
void SetCountry()
Definition: romedit.cpp:189
romedit.h
mythdialogbox.h
MythScreenStack
Definition: mythscreenstack.h:16
RomInfo::setCountry
void setCountry(const QString &lcountry)
Definition: rominfo.h:85
EditRomInfoDialog::ToggleFavorite
void ToggleFavorite()
Definition: romedit.cpp:204
EditRomInfoDialog::SetBoxart
void SetBoxart(const QString &file)
Definition: romedit.cpp:248
RomInfo::Genre
QString Genre() const
Definition: rominfo.h:81
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
MythScreenType
Screen in which all other widgets are contained and rendered.
Definition: mythscreentype.h:45
MythUITextEdit::GetText
QString GetText(void) const
Definition: mythuitextedit.h:50
build_compdb.file
file
Definition: build_compdb.py:55
EditRomInfoDialog::FindBoxart
void FindBoxart()
Definition: romedit.cpp:223
mythdirs.h
EditRomInfoDialog::m_fanartButton
MythUIButton * m_fanartButton
Definition: romedit.h:57
EditRomInfoDialog::customEvent
void customEvent(QEvent *levent) override
Definition: romedit.cpp:122
EditRomInfoDialog::m_boxartText
MythUIText * m_boxartText
Definition: romedit.h:60
mythuibuttonlist.h
hardwareprofile.distros.mythtv_data.data_mythtv.prefix
string prefix
Definition: data_mythtv.py:40
EditRomInfoDialog::m_genreEdit
MythUITextEdit * m_genreEdit
Definition: romedit.h:49
EditRomInfoDialog::m_plotEdit
MythUITextEdit * m_plotEdit
Definition: romedit.h:52
MythUITextEdit::SetText
void SetText(const QString &text, bool moveCursor=true)
Definition: mythuitextedit.cpp:197
RomInfo::Screenshot
QString Screenshot() const
Definition: rominfo.h:63
MythUICheckBox::valueChanged
void valueChanged()
GetConfDir
QString GetConfDir(void)
Definition: mythdirs.cpp:224
EditRomInfoDialog::m_id
QString m_id
Definition: romedit.h:45
RomInfo::setGamename
void setGamename(const QString &lgamename)
Definition: rominfo.h:79
EditRomInfoDialog::SetGenre
void SetGenre()
Definition: romedit.cpp:179
EditRomInfoDialog::m_gamenameEdit
MythUITextEdit * m_gamenameEdit
Definition: romedit.h:48
MythScreenType::BuildFocusList
void BuildFocusList(void)
Definition: mythscreentype.cpp:206
EditRomInfoDialog::SetReturnEvent
void SetReturnEvent(QObject *retobject, const QString &resultid)
Definition: romedit.cpp:154
EditRomInfoDialog::m_screenshotText
MythUIText * m_screenshotText
Definition: romedit.h:56
RomInfo::setPublisher
void setPublisher(const QString &lpublisher)
Definition: rominfo.h:106
EditRomInfoDialog::m_screenshotButton
MythUIButton * m_screenshotButton
Definition: romedit.h:55
RomInfo::setFavorite
void setFavorite(bool updateDatabase=false)
Definition: rominfo.cpp:213
rominfo.h
RomInfo::setFanart
void setFanart(const QString &lfanart)
Definition: rominfo.h:67
mythuifilebrowser.h
RomInfo::setPlot
void setPlot(const QString &lplot)
Definition: rominfo.h:103
MythUIStateType::Full
@ Full
Definition: mythuistatetype.h:25
EditRomInfoDialog::Create
bool Create() override
Definition: romedit.cpp:33
gCoreContext
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
Definition: mythcorecontext.cpp:54
MythUIFileBrowser
Definition: mythuifilebrowser.h:76
UIUtilDisp::Assign
static bool Assign(ContainerType *container, UIType *&item, const QString &name, bool *err=nullptr)
Definition: mythuiutils.h:27
RomInfo::Publisher
QString Publisher() const
Definition: rominfo.h:105
RomInfo
Definition: rominfo.h:14
EditRomInfoDialog::EditRomInfoDialog
EditRomInfoDialog(MythScreenStack *parent, const QString &name, RomInfo *romInfo)
Definition: romedit.cpp:21
EditRomInfoDialog::m_favoriteCheck
MythUICheckBox * m_favoriteCheck
Definition: romedit.h:54
EditRomInfoDialog::FindScreenshot
void FindScreenshot()
Definition: romedit.cpp:209
EditRomInfoDialog::m_retObject
QObject * m_retObject
Definition: romedit.h:46
RomInfo::Fanart
QString Fanart() const
Definition: rominfo.h:66
mythuitextedit.h
MythUICheckBox::SetCheckState
void SetCheckState(MythUIStateType::StateType state)
Definition: mythuicheckbox.cpp:66
XMLParseBase::LoadWindowFromXML
static bool LoadWindowFromXML(const QString &xmlfile, const QString &windowname, MythUIType *parent)
Definition: xmlparsebase.cpp:695
DialogCompletionEvent
Event dispatched from MythUI modal dialogs to a listening class containing a result of some form.
Definition: mythdialogbox.h:41
RomInfo::setYear
void setYear(const QString &lyear)
Definition: rominfo.h:112
EditRomInfoDialog::SetPlot
void SetPlot()
Definition: romedit.cpp:194
EditRomInfoDialog::~EditRomInfoDialog
~EditRomInfoDialog() override
Definition: romedit.cpp:28
EditRomInfoDialog::m_countryEdit
MythUITextEdit * m_countryEdit
Definition: romedit.h:51
EditRomInfoDialog::SetFanart
void SetFanart(const QString &file)
Definition: romedit.cpp:239
MythUIText::SetText
virtual void SetText(const QString &text)
Definition: mythuitext.cpp:132
EditRomInfoDialog::SetScreenshot
void SetScreenshot(const QString &file)
Definition: romedit.cpp:230
EditRomInfoDialog::SetYear
void SetYear()
Definition: romedit.cpp:184
mythcontext.h
GetMythMainWindow
MythMainWindow * GetMythMainWindow(void)
Definition: mythmainwindow.cpp:102
EditRomInfoDialog::SetGamename
void SetGamename()
Definition: romedit.cpp:174
EditRomInfoDialog::m_publisherEdit
MythUITextEdit * m_publisherEdit
Definition: romedit.h:53
mythuibutton.h
MythMainWindow::GetStack
MythScreenStack * GetStack(const QString &Stackname)
Definition: mythmainwindow.cpp:320
MythUITextEdit::valueChanged
void valueChanged()
EditRomInfoDialog::m_workingRomInfo
RomInfo * m_workingRomInfo
Definition: romedit.h:44
mythuicheckbox.h
mythmainwindow.h
RomInfo::setScreenshot
void setScreenshot(const QString &lscreenshot)
Definition: rominfo.h:64
MythScreenStack::AddScreen
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
Definition: mythscreenstack.cpp:50
EditRomInfoDialog::m_boxartButton
MythUIButton * m_boxartButton
Definition: romedit.h:59
RomInfo::Year
QString Year() const
Definition: rominfo.h:111
EditRomInfoDialog::m_doneButton
MythUIButton * m_doneButton
Definition: romedit.h:61
RomInfo::setGenre
void setGenre(const QString &lgenre)
Definition: rominfo.h:82
MythCoreContext::GetSetting
QString GetSetting(const QString &key, const QString &defaultval="")
Definition: mythcorecontext.cpp:896
EditRomInfoDialog::SetPublisher
void SetPublisher()
Definition: romedit.cpp:199
EditRomInfoDialog::m_fanartText
MythUIText * m_fanartText
Definition: romedit.h:58