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  m_workingRomInfo(new RomInfo(*romInfo))
25 {
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 {
88  {
89  QStringList ret;
90 
91  QList<QByteArray> exts = QImageReader::supportedImageFormats();
92  for (const auto & ext : std::as_const(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  {
115  delete fb;
116  }
117  }
118 
119  const QString CEID_SCREENSHOTFILE = "screenshotfile";
120  const QString CEID_FANARTFILE = "fanartfile";
121  const QString CEID_BOXARTFILE = "boxartfile";
122 }
123 
125 {
126  if (auto *dce = dynamic_cast<DialogCompletionEvent*>(event))
127  {
128  const QString resultid = dce->GetId();
129 
130  if (resultid == CEID_FANARTFILE)
131  SetFanart(dce->GetResultText());
132  else if (resultid == CEID_SCREENSHOTFILE)
133  SetScreenshot(dce->GetResultText());
134  else if (resultid == CEID_BOXARTFILE)
135  SetBoxart(dce->GetResultText());
136  }
137 }
138 
140 {
147 
148  if (m_workingRomInfo->Favorite())
150 
154 }
155 
156 void EditRomInfoDialog::SetReturnEvent(QObject *retobject,
157  const QString &resultid)
158 {
159  m_retObject = retobject;
160  m_id = resultid;
161 }
162 
164 {
165  if (m_retObject)
166  {
167  auto *romInfo = new RomInfo(*m_workingRomInfo);
168  auto *dce = new DialogCompletionEvent(m_id, 0, "",
169  QVariant::fromValue(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 
233 {
234  if (file.isEmpty())
235  return;
236 
239 }
240 
241 void EditRomInfoDialog::SetFanart(const QString& file)
242 {
243  if (file.isEmpty())
244  return;
245 
248 }
249 
250 void EditRomInfoDialog::SetBoxart(const QString& file)
251 {
252  if (file.isEmpty())
253  return;
254 
257 }
MythUIButton::Clicked
void Clicked()
RomInfo::Boxart
QString Boxart() const
Definition: rominfo.h:69
anonymous_namespace{romedit.cpp}::CEID_BOXARTFILE
const QString CEID_BOXARTFILE
Definition: romedit.cpp:121
mythuitext.h
EditRomInfoDialog::m_yearEdit
MythUITextEdit * m_yearEdit
Definition: romedit.h:50
EditRomInfoDialog::SaveAndExit
void SaveAndExit()
Definition: romedit.cpp:163
RomInfo::Plot
QString Plot() const
Definition: rominfo.h:102
MythScreenType::Close
virtual void Close()
Definition: mythscreentype.cpp:383
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:139
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:218
EditRomInfoDialog::SetCountry
void SetCountry()
Definition: romedit.cpp:191
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:206
EditRomInfoDialog::SetBoxart
void SetBoxart(const QString &file)
Definition: romedit.cpp:250
RomInfo::Genre
QString Genre() const
Definition: rominfo.h:81
anonymous_namespace{romedit.cpp}::CEID_SCREENSHOTFILE
const QString CEID_SCREENSHOTFILE
Definition: romedit.cpp:119
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
anonymous_namespace{romedit.cpp}::FindImagePopup
void FindImagePopup(const QString &prefix, const QString &prefixAlt, QObject &inst, const QString &returnEvent)
Definition: romedit.cpp:98
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:225
mythdirs.h
EditRomInfoDialog::m_fanartButton
MythUIButton * m_fanartButton
Definition: romedit.h:57
EditRomInfoDialog::customEvent
void customEvent(QEvent *levent) override
Definition: romedit.cpp:124
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:198
RomInfo::Screenshot
QString Screenshot() const
Definition: rominfo.h:63
MythUICheckBox::valueChanged
void valueChanged()
GetConfDir
QString GetConfDir(void)
Definition: mythdirs.cpp:256
EditRomInfoDialog::m_id
QString m_id
Definition: romedit.h:45
anonymous_namespace{romedit.cpp}::CEID_FANARTFILE
const QString CEID_FANARTFILE
Definition: romedit.cpp:120
RomInfo::setGamename
void setGamename(const QString &lgamename)
Definition: rominfo.h:79
EditRomInfoDialog::SetGenre
void SetGenre()
Definition: romedit.cpp:181
EditRomInfoDialog::m_gamenameEdit
MythUITextEdit * m_gamenameEdit
Definition: romedit.h:48
MythScreenType::BuildFocusList
void BuildFocusList(void)
Definition: mythscreentype.cpp:203
EditRomInfoDialog::SetReturnEvent
void SetReturnEvent(QObject *retobject, const QString &resultid)
Definition: romedit.cpp:156
EditRomInfoDialog::m_screenshotText
MythUIText * m_screenshotText
Definition: romedit.h:56
anonymous_namespace{romedit.cpp}::GetSupportedImageExtensionFilter
QStringList GetSupportedImageExtensionFilter()
Definition: romedit.cpp:87
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
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:55
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:211
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:687
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:196
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:241
MythUIText::SetText
virtual void SetText(const QString &text)
Definition: mythuitext.cpp:115
EditRomInfoDialog::SetScreenshot
void SetScreenshot(const QString &file)
Definition: romedit.cpp:232
EditRomInfoDialog::SetYear
void SetYear()
Definition: romedit.cpp:186
mythcontext.h
GetMythMainWindow
MythMainWindow * GetMythMainWindow(void)
Definition: mythmainwindow.cpp:104
EditRomInfoDialog::SetGamename
void SetGamename()
Definition: romedit.cpp:176
EditRomInfoDialog::m_publisherEdit
MythUITextEdit * m_publisherEdit
Definition: romedit.h:53
mythuibutton.h
MythMainWindow::GetStack
MythScreenStack * GetStack(const QString &Stackname)
Definition: mythmainwindow.cpp:322
MythUITextEdit::valueChanged
void valueChanged()
MythUIStateType::Full
@ Full
Definition: mythuistatetype.h:27
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:52
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:902
EditRomInfoDialog::SetPublisher
void SetPublisher()
Definition: romedit.cpp:201
EditRomInfoDialog::m_fanartText
MythUIText * m_fanartText
Definition: romedit.h:58