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 
71 
73 
77 
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 (const auto & ext : qAsConst(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 }
MythUIButton::Clicked
void Clicked()
RomInfo::Boxart
QString Boxart() const
Definition: rominfo.h:67
mythuitext.h
EditRomInfoDialog::m_yearEdit
MythUITextEdit * m_yearEdit
Definition: romedit.h:49
EditRomInfoDialog::SaveAndExit
void SaveAndExit()
Definition: romedit.cpp:159
RomInfo::Plot
QString Plot() const
Definition: rominfo.h:100
MythScreenType::Close
virtual void Close()
Definition: mythscreentype.cpp:402
RomInfo::Country
QString Country() const
Definition: rominfo.h:82
RomInfo::Gamename
QString Gamename() const
Definition: rominfo.h:76
EditRomInfoDialog::fillWidgets
void fillWidgets()
Definition: romedit.cpp:135
RomInfo::Favorite
bool Favorite() const
Definition: rominfo.h:115
RomInfo::setBoxart
void setBoxart(const QString &lboxart)
Definition: rominfo.h:68
EditRomInfoDialog::FindFanart
void FindFanart()
Definition: romedit.cpp:214
EditRomInfoDialog::SetCountry
void SetCountry()
Definition: romedit.cpp:187
romedit.h
mythdialogbox.h
MythScreenStack
Definition: mythscreenstack.h:16
RomInfo::setCountry
void setCountry(const QString &lcountry)
Definition: rominfo.h:83
EditRomInfoDialog::ToggleFavorite
void ToggleFavorite()
Definition: romedit.cpp:202
EditRomInfoDialog::SetBoxart
void SetBoxart(const QString &file)
Definition: romedit.cpp:246
RomInfo::Genre
QString Genre() const
Definition: rominfo.h:79
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
MythScreenType
Screen in which all other widgets are contained and rendered.
Definition: mythscreentype.h:45
MythUITextEdit::GetText
QString GetText(void) const
Definition: mythuitextedit.h:47
build_compdb.file
file
Definition: build_compdb.py:55
EditRomInfoDialog::FindBoxart
void FindBoxart()
Definition: romedit.cpp:221
mythdirs.h
EditRomInfoDialog::m_fanartButton
MythUIButton * m_fanartButton
Definition: romedit.h:56
EditRomInfoDialog::customEvent
void customEvent(QEvent *levent) override
Definition: romedit.cpp:120
EditRomInfoDialog::m_boxartText
MythUIText * m_boxartText
Definition: romedit.h:59
MythMainWindow::GetStack
MythScreenStack * GetStack(const QString &stackname)
Definition: mythmainwindow.cpp:326
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:48
EditRomInfoDialog::m_plotEdit
MythUITextEdit * m_plotEdit
Definition: romedit.h:51
MythUITextEdit::SetText
void SetText(const QString &text, bool moveCursor=true)
Definition: mythuitextedit.cpp:216
RomInfo::Screenshot
QString Screenshot() const
Definition: rominfo.h:61
MythUICheckBox::valueChanged
void valueChanged()
GetConfDir
QString GetConfDir(void)
Definition: mythdirs.cpp:224
EditRomInfoDialog::m_id
QString m_id
Definition: romedit.h:44
RomInfo::setGamename
void setGamename(const QString &lgamename)
Definition: rominfo.h:77
EditRomInfoDialog::SetGenre
void SetGenre()
Definition: romedit.cpp:177
EditRomInfoDialog::m_gamenameEdit
MythUITextEdit * m_gamenameEdit
Definition: romedit.h:47
MythScreenType::BuildFocusList
void BuildFocusList(void)
Definition: mythscreentype.cpp:222
EditRomInfoDialog::SetReturnEvent
void SetReturnEvent(QObject *retobject, const QString &resultid)
Definition: romedit.cpp:152
EditRomInfoDialog::m_screenshotText
MythUIText * m_screenshotText
Definition: romedit.h:55
RomInfo::setPublisher
void setPublisher(const QString &lpublisher)
Definition: rominfo.h:104
EditRomInfoDialog::m_screenshotButton
MythUIButton * m_screenshotButton
Definition: romedit.h:54
RomInfo::setFavorite
void setFavorite(bool updateDatabase=false)
Definition: rominfo.cpp:210
rominfo.h
RomInfo::setFanart
void setFanart(const QString &lfanart)
Definition: rominfo.h:65
mythuifilebrowser.h
RomInfo::setPlot
void setPlot(const QString &lplot)
Definition: rominfo.h:101
MythUIStateType::Full
@ Full
Definition: mythuistatetype.h:25
EditRomInfoDialog::Create
bool Create() override
Definition: romedit.cpp:31
gCoreContext
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
Definition: mythcorecontext.cpp:56
MythUIFileBrowser
Definition: mythuifilebrowser.h:81
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:103
RomInfo
Definition: rominfo.h:13
EditRomInfoDialog::EditRomInfoDialog
EditRomInfoDialog(MythScreenStack *parent, const QString &name, RomInfo *romInfo)
Definition: romedit.cpp:19
EditRomInfoDialog::m_favoriteCheck
MythUICheckBox * m_favoriteCheck
Definition: romedit.h:53
EditRomInfoDialog::FindScreenshot
void FindScreenshot()
Definition: romedit.cpp:207
EditRomInfoDialog::m_retObject
QObject * m_retObject
Definition: romedit.h:45
RomInfo::Fanart
QString Fanart() const
Definition: rominfo.h:64
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:692
DialogCompletionEvent
Event dispatched from MythUI modal dialogs to a listening class containing a result of some form.
Definition: mythdialogbox.h:42
RomInfo::setYear
void setYear(const QString &lyear)
Definition: rominfo.h:110
EditRomInfoDialog::SetPlot
void SetPlot()
Definition: romedit.cpp:192
EditRomInfoDialog::~EditRomInfoDialog
~EditRomInfoDialog() override
Definition: romedit.cpp:26
EditRomInfoDialog::m_countryEdit
MythUITextEdit * m_countryEdit
Definition: romedit.h:50
EditRomInfoDialog::SetFanart
void SetFanart(const QString &file)
Definition: romedit.cpp:237
MythUIText::SetText
virtual void SetText(const QString &text)
Definition: mythuitext.cpp:134
EditRomInfoDialog::SetScreenshot
void SetScreenshot(const QString &file)
Definition: romedit.cpp:228
EditRomInfoDialog::SetYear
void SetYear()
Definition: romedit.cpp:182
mythcontext.h
GetMythMainWindow
MythMainWindow * GetMythMainWindow(void)
Definition: mythmainwindow.cpp:105
EditRomInfoDialog::SetGamename
void SetGamename()
Definition: romedit.cpp:172
EditRomInfoDialog::m_publisherEdit
MythUITextEdit * m_publisherEdit
Definition: romedit.h:52
mythuibutton.h
MythUITextEdit::valueChanged
void valueChanged()
EditRomInfoDialog::m_workingRomInfo
RomInfo * m_workingRomInfo
Definition: romedit.h:43
mythuicheckbox.h
mythmainwindow.h
RomInfo::setScreenshot
void setScreenshot(const QString &lscreenshot)
Definition: rominfo.h:62
MythScreenStack::AddScreen
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
Definition: mythscreenstack.cpp:49
EditRomInfoDialog::m_boxartButton
MythUIButton * m_boxartButton
Definition: romedit.h:58
RomInfo::Year
QString Year() const
Definition: rominfo.h:109
EditRomInfoDialog::m_doneButton
MythUIButton * m_doneButton
Definition: romedit.h:60
RomInfo::setGenre
void setGenre(const QString &lgenre)
Definition: rominfo.h:80
MythCoreContext::GetSetting
QString GetSetting(const QString &key, const QString &defaultval="")
Definition: mythcorecontext.cpp:915
EditRomInfoDialog::SetPublisher
void SetPublisher()
Definition: romedit.cpp:197
EditRomInfoDialog::m_fanartText
MythUIText * m_fanartText
Definition: romedit.h:57