00001 #include <QImageReader>
00002 #include <QApplication>
00003
00004 #include <mythcontext.h>
00005 #include <mythdirs.h>
00006
00007 #include <mythmainwindow.h>
00008 #include <mythdialogbox.h>
00009 #include <mythuibuttonlist.h>
00010 #include <mythuitext.h>
00011 #include <mythuitextedit.h>
00012 #include <mythuibutton.h>
00013 #include <mythuicheckbox.h>
00014 #include <mythuifilebrowser.h>
00015
00016 #include "romedit.h"
00017 #include "rominfo.h"
00018
00019 EditRomInfoDialog::EditRomInfoDialog(MythScreenStack *parent,
00020 QString name, RomInfo *romInfo) : MythScreenType(parent, name),
00021 m_id(""), m_retObject(NULL), m_gamenameEdit(NULL), m_genreEdit(NULL),
00022 m_yearEdit(NULL), m_countryEdit(NULL), m_plotEdit(NULL),
00023 m_publisherEdit(NULL), m_favoriteCheck(NULL), m_screenshotButton(NULL),
00024 m_screenshotText(NULL), m_fanartButton(NULL), m_fanartText(NULL),
00025 m_boxartButton(NULL), m_boxartText(NULL), m_doneButton(NULL)
00026 {
00027 m_workingRomInfo = new RomInfo(*romInfo);
00028 }
00029
00030 EditRomInfoDialog::~EditRomInfoDialog()
00031 {
00032 delete m_workingRomInfo;
00033 }
00034
00035 bool EditRomInfoDialog::Create()
00036 {
00037 if (!LoadWindowFromXML("game-ui.xml", "edit_metadata", this))
00038 return false;
00039
00040 bool err = false;
00041 UIUtilE::Assign(this, m_gamenameEdit, "title_edit", &err);
00042 UIUtilE::Assign(this, m_genreEdit, "genre_edit", &err);
00043 UIUtilE::Assign(this, m_yearEdit, "year_edit", &err);
00044 UIUtilE::Assign(this, m_countryEdit, "country_edit", &err);
00045 UIUtilE::Assign(this, m_plotEdit, "description_edit", &err);
00046 UIUtilE::Assign(this, m_publisherEdit, "publisher_edit", &err);
00047
00048 UIUtilE::Assign(this, m_favoriteCheck, "favorite_check", &err);
00049
00050 UIUtilE::Assign(this, m_screenshotButton, "screenshot_button", &err);
00051 UIUtilE::Assign(this, m_screenshotText, "screenshot_text", &err);
00052 UIUtilE::Assign(this, m_fanartButton, "fanart_button", &err);
00053 UIUtilE::Assign(this, m_fanartText, "fanart_text", &err);
00054 UIUtilE::Assign(this, m_boxartButton, "coverart_button", &err);
00055 UIUtilE::Assign(this, m_boxartText, "coverart_text", &err);
00056
00057 UIUtilE::Assign(this, m_doneButton, "done_button", &err);
00058
00059 if (err)
00060 {
00061 LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'edit_metadata'");
00062 return false;
00063 }
00064
00065 fillWidgets();
00066
00067 BuildFocusList();
00068
00069 connect(m_gamenameEdit, SIGNAL(valueChanged()), SLOT(SetGamename()));
00070 connect(m_genreEdit, SIGNAL(valueChanged()), SLOT(SetGenre()));
00071 connect(m_yearEdit, SIGNAL(valueChanged()), SLOT(SetYear()));
00072 connect(m_countryEdit, SIGNAL(valueChanged()), SLOT(SetCountry()));
00073 connect(m_plotEdit, SIGNAL(valueChanged()), SLOT(SetPlot()));
00074 connect(m_publisherEdit, SIGNAL(valueChanged()), SLOT(SetPublisher()));
00075
00076 connect(m_favoriteCheck, SIGNAL(valueChanged()), SLOT(ToggleFavorite()));
00077
00078 connect(m_screenshotButton, SIGNAL(Clicked()), SLOT(FindScreenshot()));
00079 connect(m_fanartButton, SIGNAL(Clicked()), SLOT(FindFanart()));
00080 connect(m_boxartButton, SIGNAL(Clicked()), SLOT(FindBoxart()));
00081
00082 connect(m_doneButton, SIGNAL(Clicked()), SLOT(SaveAndExit()));
00083
00084 return true;
00085 }
00086
00087 namespace
00088 {
00089 QStringList GetSupportedImageExtensionFilter()
00090 {
00091 QStringList ret;
00092
00093 QList<QByteArray> exts = QImageReader::supportedImageFormats();
00094 for (QList<QByteArray>::iterator p = exts.begin(); p != exts.end(); ++p)
00095 {
00096 ret.append(QString("*.").append(*p));
00097 }
00098
00099 return ret;
00100 }
00101
00102 void FindImagePopup(const QString &prefix, const QString &prefixAlt,
00103 QObject &inst, const QString &returnEvent)
00104 {
00105 QString fp = prefix.isEmpty() ? prefixAlt : prefix;
00106
00107 MythScreenStack *popupStack =
00108 GetMythMainWindow()->GetStack("popup stack");
00109
00110 MythUIFileBrowser *fb = new MythUIFileBrowser(popupStack, fp);
00111 fb->SetNameFilter(GetSupportedImageExtensionFilter());
00112 if (fb->Create())
00113 {
00114 fb->SetReturnEvent(&inst, returnEvent);
00115 popupStack->AddScreen(fb);
00116 }
00117 else
00118 delete fb;
00119 }
00120
00121 const QString CEID_SCREENSHOTFILE = "screenshotfile";
00122 const QString CEID_FANARTFILE = "fanartfile";
00123 const QString CEID_BOXARTFILE = "boxartfile";
00124 }
00125
00126 void EditRomInfoDialog::customEvent(QEvent *event)
00127 {
00128 if (event->type() == DialogCompletionEvent::kEventType)
00129 {
00130 DialogCompletionEvent *dce = (DialogCompletionEvent*)(event);
00131 const QString resultid = dce->GetId();
00132
00133 if (resultid == CEID_FANARTFILE)
00134 SetFanart(dce->GetResultText());
00135 else if (resultid == CEID_SCREENSHOTFILE)
00136 SetScreenshot(dce->GetResultText());
00137 else if (resultid == CEID_BOXARTFILE)
00138 SetBoxart(dce->GetResultText());
00139 }
00140 }
00141
00142 void EditRomInfoDialog::fillWidgets()
00143 {
00144 m_gamenameEdit->SetText(m_workingRomInfo->Gamename());
00145 m_genreEdit->SetText(m_workingRomInfo->Genre());
00146 m_yearEdit->SetText(m_workingRomInfo->Year());
00147 m_countryEdit->SetText(m_workingRomInfo->Country());
00148 m_plotEdit->SetText(m_workingRomInfo->Plot());
00149 m_publisherEdit->SetText(m_workingRomInfo->Publisher());
00150
00151 if (m_workingRomInfo->Favorite())
00152 m_favoriteCheck->SetCheckState(MythUIStateType::Full);
00153
00154 m_screenshotText->SetText(m_workingRomInfo->Screenshot());
00155 m_fanartText->SetText(m_workingRomInfo->Fanart());
00156 m_boxartText->SetText(m_workingRomInfo->Boxart());
00157 }
00158
00159 void EditRomInfoDialog::SetReturnEvent(QObject *retobject,
00160 const QString &resultid)
00161 {
00162 m_retObject = retobject;
00163 m_id = resultid;
00164 }
00165
00166 void EditRomInfoDialog::SaveAndExit()
00167 {
00168 if (m_retObject)
00169 {
00170 RomInfo *romInfo = new RomInfo(*m_workingRomInfo);
00171 DialogCompletionEvent *dce =
00172 new DialogCompletionEvent(m_id, 0, "",
00173 qVariantFromValue(romInfo));
00174
00175 QApplication::postEvent(m_retObject, dce);
00176 }
00177 Close();
00178 }
00179
00180 void EditRomInfoDialog::SetGamename()
00181 {
00182 m_workingRomInfo->setGamename(m_gamenameEdit->GetText());
00183 }
00184
00185 void EditRomInfoDialog::SetGenre()
00186 {
00187 m_workingRomInfo->setGenre(m_genreEdit->GetText());
00188 }
00189
00190 void EditRomInfoDialog::SetYear()
00191 {
00192 m_workingRomInfo->setYear(m_yearEdit->GetText());
00193 }
00194
00195 void EditRomInfoDialog::SetCountry()
00196 {
00197 m_workingRomInfo->setCountry(m_countryEdit->GetText());
00198 }
00199
00200 void EditRomInfoDialog::SetPlot()
00201 {
00202 m_workingRomInfo->setPlot(m_plotEdit->GetText());
00203 }
00204
00205 void EditRomInfoDialog::SetPublisher()
00206 {
00207 m_workingRomInfo->setPublisher(m_publisherEdit->GetText());
00208 }
00209
00210 void EditRomInfoDialog::ToggleFavorite()
00211 {
00212 m_workingRomInfo->setFavorite();
00213 }
00214
00215 void EditRomInfoDialog::FindScreenshot()
00216 {
00217 FindImagePopup(gCoreContext->GetSetting("mythgame.screenshotDir"),
00218 GetConfDir() + "/MythGame/Screenshots",
00219 *this, CEID_SCREENSHOTFILE);
00220 }
00221
00222 void EditRomInfoDialog::FindFanart()
00223 {
00224 FindImagePopup(gCoreContext->GetSetting("mythgame.fanartDir"),
00225 GetConfDir() + "/MythGame/Fanart",
00226 *this, CEID_FANARTFILE);
00227 }
00228
00229 void EditRomInfoDialog::FindBoxart()
00230 {
00231 FindImagePopup(gCoreContext->GetSetting("mythgame.boxartDir"),
00232 GetConfDir() + "/MythGame/Boxart",
00233 *this, CEID_BOXARTFILE);
00234 }
00235
00236 void EditRomInfoDialog::SetScreenshot(QString file)
00237 {
00238 if (file.isEmpty())
00239 return;
00240
00241 m_workingRomInfo->setScreenshot(file);
00242 m_screenshotText->SetText(file);
00243 }
00244
00245 void EditRomInfoDialog::SetFanart(QString file)
00246 {
00247 if (file.isEmpty())
00248 return;
00249
00250 m_workingRomInfo->setFanart(file);
00251 m_fanartText->SetText(file);
00252 }
00253
00254 void EditRomInfoDialog::SetBoxart(QString file)
00255 {
00256 if (file.isEmpty())
00257 return;
00258
00259 m_workingRomInfo->setBoxart(file);
00260 m_boxartText->SetText(file);
00261 }