MythTV  master
gameui.cpp
Go to the documentation of this file.
1 #include <QMetaType>
2 #include <QStringList>
3 #include <QTimer>
4 
5 #include <mythcontext.h>
6 #include <mythuibuttontree.h>
8 #include <mythuiimage.h>
9 #include <mythuitext.h>
10 #include <mythuistatetype.h>
11 #include <mythmainwindow.h>
12 #include <mythdialogbox.h>
13 #include <mythgenerictree.h>
14 #include <mythdirs.h>
15 
16 // MythGame headers
17 #include "gamehandler.h"
18 #include "rominfo.h"
19 #include "gamedetails.h"
20 #include "romedit.h"
21 #include "gamescan.h"
22 #include "gameui.h"
23 
24 static const QString _Location = "MythGame";
25 
27 {
28  public:
29  GameTreeInfo(const QString& levels, QString filter)
30  : m_levels(levels.split(" "))
31  , m_filter(std::move(filter))
32  {
33  }
34 
35  int getDepth() const { return m_levels.size(); }
36  const QString& getLevel(unsigned i) const { return m_levels[i]; }
37  const QString& getFilter() const { return m_filter; }
38 
39  private:
40  QStringList m_levels;
41  QString m_filter;
42 };
43 
45 
47  : MythScreenType(parent, "GameUI")
48 {
49  m_popupStack = GetMythMainWindow()->GetStack("popup stack");
50 
51  m_query = new MetadataDownload(this);
52  m_imageDownload = new MetadataImageDownload(this);
53 }
54 
56 {
57  if (!LoadWindowFromXML("game-ui.xml", "gameui", this))
58  return false;
59 
60  bool err = false;
61  UIUtilE::Assign(this, m_gameUITree, "gametreelist", &err);
62  UIUtilW::Assign(this, m_gameTitleText, "title");
63  UIUtilW::Assign(this, m_gameSystemText, "system");
64  UIUtilW::Assign(this, m_gameYearText, "year");
65  UIUtilW::Assign(this, m_gameGenreText, "genre");
66  UIUtilW::Assign(this, m_gameFavouriteState, "favorite");
67  UIUtilW::Assign(this, m_gamePlotText, "description");
68  UIUtilW::Assign(this, m_gameImage, "screenshot");
69  UIUtilW::Assign(this, m_fanartImage, "fanart");
70  UIUtilW::Assign(this, m_boxImage, "coverart");
71 
72  if (err)
73  {
74  LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'gameui'");
75  return false;
76  }
77 
79  this, SLOT(itemClicked(MythUIButtonListItem*)));
80 
81  connect(m_gameUITree, SIGNAL(nodeChanged(MythGenericTree*)),
82  this, SLOT(nodeChanged(MythGenericTree*)));
83 
84  m_gameShowFileName = gCoreContext->GetBoolSetting("GameShowFileNames");
85 
86  BuildTree();
87 
89 
90  return true;
91 }
92 
94 {
95  if (m_gameTree)
96  {
98  delete m_gameTree;
99  m_gameTree = nullptr;
100  }
101 
102  m_gameTree = new MythGenericTree("game root", 0, false);
103 
104  // create system filter to only select games where handlers are present
105  QString systemFilter;
106 
107  // The call to GameHandler::count() fills the handler list for us
108  // to move through.
109  unsigned handlercount = GameHandler::count();
110 
111  for (unsigned i = 0; i < handlercount; ++i)
112  {
113  QString system = GameHandler::getHandler(i)->SystemName();
114  if (i == 0)
115  systemFilter = "system in ('" + system + "'";
116  else
117  systemFilter += ",'" + system + "'";
118  }
119  if (systemFilter.isEmpty())
120  {
121  systemFilter = "1=0";
122  LOG(VB_GENERAL, LOG_ERR, QString("Couldn't find any game handlers!"));
123  }
124  else
125  systemFilter += ")";
126 
127  m_showHashed = gCoreContext->GetBoolSetting("GameTreeView");
128 
129  // create a few top level nodes - this could be moved to a config based
130  // approach with multiple roots if/when someone has the time to create
131  // the relevant dialog screens
132 
133  QString levels = gCoreContext->GetSetting("GameFavTreeLevels");
134 
135  auto *new_node = new MythGenericTree(tr("Favorites"), 1, true);
136  new_node->SetData(qVariantFromValue(
137  new GameTreeInfo(levels, systemFilter + " and favorite=1")));
138  m_favouriteNode = m_gameTree->addNode(new_node);
139 
140  levels = gCoreContext->GetSetting("GameAllTreeLevels");
141 
142  if (m_showHashed)
143  {
144  int pos = levels.indexOf("gamename");
145  if (pos >= 0)
146  levels.insert(pos, " hash ");
147  }
148 
149  new_node = new MythGenericTree(tr("All Games"), 1, true);
150  new_node->SetData(qVariantFromValue(
151  new GameTreeInfo(levels, systemFilter)));
152  m_gameTree->addNode(new_node);
153 
154  new_node = new MythGenericTree(tr("- By Genre"), 1, true);
155  new_node->SetData(qVariantFromValue(
156  new GameTreeInfo("genre gamename", systemFilter)));
157  m_gameTree->addNode(new_node);
158 
159  new_node = new MythGenericTree(tr("- By Year"), 1, true);
160  new_node->SetData(qVariantFromValue(
161  new GameTreeInfo("year gamename", systemFilter)));
162  m_gameTree->addNode(new_node);
163 
164  new_node = new MythGenericTree(tr("- By Name"), 1, true);
165  new_node->SetData(qVariantFromValue(
166  new GameTreeInfo("gamename", systemFilter)));
167  m_gameTree->addNode(new_node);
168 
169  new_node = new MythGenericTree(tr("- By Publisher"), 1, true);
170  new_node->SetData(qVariantFromValue(
171  new GameTreeInfo("publisher gamename", systemFilter)));
172  m_gameTree->addNode(new_node);
173 
176 }
177 
178 bool GameUI::keyPressEvent(QKeyEvent *event)
179 {
180  if (GetFocusWidget()->keyPressEvent(event))
181  return true;
182 
183  QStringList actions;
184  bool handled = GetMythMainWindow()->TranslateKeyPress("Game", event, actions);
185 
186  for (int i = 0; i < actions.size() && !handled; i++)
187  {
188  QString action = actions[i];
189  handled = true;
190 
191  if (action == "MENU")
192  ShowMenu();
193  else if (action == "EDIT")
194  edit();
195  else if (action == "INFO")
196  showInfo();
197  else if (action == "TOGGLEFAV")
198  toggleFavorite();
199  else if (action == "INCSEARCH")
200  searchStart();
201  else if (action == "INCSEARCHNEXT")
202  searchStart();
203  else if (action == "DOWNLOADDATA")
204  gameSearch();
205  else
206  handled = false;
207  }
208 
209  if (!handled && MythScreenType::keyPressEvent(event))
210  handled = true;
211 
212  return handled;
213 }
214 
216 {
217  if (!node)
218  return;
219 
220  if (!isLeaf(node))
221  {
222  if (node->childCount() == 0 || node == m_favouriteNode)
223  {
224  node->deleteAllChildren();
225  fillNode(node);
226  }
227  clearRomInfo();
228  }
229  else
230  {
231  auto *romInfo = node->GetData().value<RomInfo *>();
232  if (!romInfo)
233  return;
234  if (romInfo->Romname().isEmpty())
235  romInfo->fillData();
236  updateRomInfo(romInfo);
237  if (!romInfo->Screenshot().isEmpty() || !romInfo->Fanart().isEmpty() ||
238  !romInfo->Boxart().isEmpty())
239  showImages();
240  else
241  {
242  if (m_gameImage)
243  m_gameImage->Reset();
244  if (m_fanartImage)
245  m_fanartImage->Reset();
246  if (m_boxImage)
247  m_boxImage->Reset();
248  }
249  }
250 }
251 
253 {
255  if (isLeaf(node))
256  {
257  auto *romInfo = node->GetData().value<RomInfo *>();
258  if (!romInfo)
259  return;
260  if (romInfo->RomCount() == 1)
261  {
262  GameHandler::Launchgame(romInfo, nullptr);
263  }
264  else
265  {
266  //: %1 is the game name
267  QString msg = tr("Choose System for:\n%1").arg(node->GetText());
268  MythScreenStack *popupStack = GetMythMainWindow()->
269  GetStack("popup stack");
270  auto *chooseSystemPopup = new MythDialogBox(
271  msg, popupStack, "chooseSystemPopup");
272 
273  if (chooseSystemPopup->Create())
274  {
275  chooseSystemPopup->SetReturnEvent(this, "chooseSystemPopup");
276  QString all_systems = romInfo->AllSystems();
277  QStringList players = all_systems.split(',');
278  for (QStringList::Iterator it = players.begin();
279  it != players.end(); ++it)
280  {
281  chooseSystemPopup->AddButton(*it);
282  }
283  popupStack->AddScreen(chooseSystemPopup);
284  }
285  else
286  delete chooseSystemPopup;
287  }
288  }
289 }
290 
292 {
293  if (m_gameImage)
294  m_gameImage->Load();
295  if (m_fanartImage)
296  m_fanartImage->Load();
297  if (m_boxImage)
298  m_boxImage->Load();
299 }
300 
301 void GameUI::searchComplete(const QString& string)
302 {
304  return;
305 
307  if (!parent)
308  return;
309 
310  MythGenericTree *new_node = parent->getChildByName(string);
311  if (new_node)
312  m_gameUITree->SetCurrentNode(new_node);
313 }
314 
316 {
317  if (m_gameTitleText)
319  if (m_gameSystemText)
321  if (m_gameYearText)
322  m_gameYearText->SetText(rom->Year());
323  if (m_gameGenreText)
324  m_gameGenreText->SetText(rom->Genre());
325  if (m_gamePlotText)
326  m_gamePlotText->SetText(rom->Plot());
327 
329  {
330  if (rom->Favorite())
332  else
334  }
335 
336  if (m_gameImage)
337  {
338  m_gameImage->Reset();
340  }
341  if (m_fanartImage)
342  {
343  m_fanartImage->Reset();
345  }
346  if (m_boxImage)
347  {
348  m_boxImage->Reset();
349  m_boxImage->SetFilename(rom->Boxart());
350  }
351 }
352 
354 {
355  if (m_gameTitleText)
357  if (m_gameSystemText)
359  if (m_gameYearText)
361  if (m_gameGenreText)
363  if (m_gamePlotText)
367 
368  if (m_gameImage)
369  m_gameImage->Reset();
370 
371  if (m_fanartImage)
372  m_fanartImage->Reset();
373 
374  if (m_boxImage)
375  m_boxImage->Reset();
376 }
377 
378 void GameUI::edit(void)
379 {
381  if (isLeaf(node))
382  {
383  auto *romInfo = node->GetData().value<RomInfo *>();
384 
385  MythScreenStack *screenStack = GetScreenStack();
386 
387  auto *md_editor = new EditRomInfoDialog(screenStack,
388  "mythgameeditmetadata", romInfo);
389 
390  if (md_editor->Create())
391  {
392  screenStack->AddScreen(md_editor);
393  md_editor->SetReturnEvent(this, "editMetadata");
394  }
395  else
396  delete md_editor;
397  }
398 }
399 
401 {
403  if (isLeaf(node))
404  {
405  auto *romInfo = node->GetData().value<RomInfo *>();
406  if (!romInfo)
407  return;
409  auto *details_dialog = new GameDetailsPopup(mainStack, romInfo);
410 
411  if (details_dialog->Create())
412  {
413  mainStack->AddScreen(details_dialog);
414  details_dialog->SetReturnEvent(this, "detailsPopup");
415  }
416  else
417  delete details_dialog;
418  }
419 }
420 
422 {
424 
425  MythScreenStack *popupStack = GetMythMainWindow()->
426  GetStack("popup stack");
427  auto *showMenuPopup =
428  new MythDialogBox(node->GetText(), popupStack, "showMenuPopup");
429 
430  if (showMenuPopup->Create())
431  {
432  showMenuPopup->SetReturnEvent(this, "showMenuPopup");
433 
434  showMenuPopup->AddButton(tr("Scan For Changes"));
435  if (isLeaf(node))
436  {
437  auto *romInfo = node->GetData().value<RomInfo *>();
438  if (romInfo)
439  {
440  showMenuPopup->AddButton(tr("Show Information"));
441  if (romInfo->Favorite())
442  showMenuPopup->AddButton(tr("Remove Favorite"));
443  else
444  showMenuPopup->AddButton(tr("Make Favorite"));
445  showMenuPopup->AddButton(tr("Retrieve Details"));
446  showMenuPopup->AddButton(tr("Edit Details"));
447  }
448  }
449  popupStack->AddScreen(showMenuPopup);
450  }
451  else
452  delete showMenuPopup;
453 }
454 
456 {
458 
459  if (parent != nullptr)
460  {
461  QStringList childList;
462  QList<MythGenericTree*>::iterator it;
463  QList<MythGenericTree*> *children = parent->getAllChildren();
464 
465  for (it = children->begin(); it != children->end(); ++it)
466  {
467  MythGenericTree *child = *it;
468  childList << child->GetText();
469  }
470 
471  MythScreenStack *popupStack =
472  GetMythMainWindow()->GetStack("popup stack");
473  auto *searchDialog = new MythUISearchDialog(popupStack,
474  tr("Game Search"), childList, true, "");
475 
476  if (searchDialog->Create())
477  {
478  connect(searchDialog, SIGNAL(haveResult(QString)),
479  SLOT(searchComplete(QString)));
480 
481  popupStack->AddScreen(searchDialog);
482  }
483  else
484  delete searchDialog;
485  }
486 }
487 
489 {
491  if (isLeaf(node))
492  {
493  auto *romInfo = node->GetData().value<RomInfo *>();
494  romInfo->setFavorite(true);
495  updateChangedNode(node, romInfo);
496  }
497 }
498 
499 void GameUI::customEvent(QEvent *event)
500 {
501  if (event->type() == DialogCompletionEvent::kEventType)
502  {
503  auto dce = dynamic_cast<DialogCompletionEvent*>(event);
504  if (dce == nullptr)
505  return;
506  QString resultid = dce->GetId();
507  QString resulttext = dce->GetResultText();
508 
509  if (resultid == "showMenuPopup")
510  {
511  if (resulttext == tr("Edit Details"))
512  {
513  edit();
514  }
515  if (resulttext == tr("Scan For Changes"))
516  {
517  doScan();
518  }
519  else if (resulttext == tr("Show Information"))
520  {
521  showInfo();
522  }
523  else if (resulttext == tr("Make Favorite") ||
524  resulttext == tr("Remove Favorite"))
525  {
526  toggleFavorite();
527  }
528  else if (resulttext == tr("Retrieve Details"))
529  {
530  gameSearch();
531  }
532  }
533  else if (resultid == "chooseSystemPopup")
534  {
535  if (!resulttext.isEmpty() && resulttext != tr("Cancel"))
536  {
538  auto *romInfo = node->GetData().value<RomInfo *>();
539  GameHandler::Launchgame(romInfo, resulttext);
540  }
541  }
542  else if (resultid == "editMetadata")
543  {
545  auto *oldRomInfo = node->GetData().value<RomInfo *>();
546  delete oldRomInfo;
547 
548  auto *romInfo = dce->GetData().value<RomInfo *>();
549  node->SetData(qVariantFromValue(romInfo));
550  node->SetText(romInfo->Gamename());
551 
552  romInfo->SaveToDatabase();
553  updateChangedNode(node, romInfo);
554  }
555  else if (resultid == "detailsPopup")
556  {
557  // Play button pushed
558  itemClicked(nullptr);
559  }
560  }
561  if (event->type() == MetadataLookupEvent::kEventType)
562  {
563  auto lue = dynamic_cast<MetadataLookupEvent *>(event);
564  if (lue == nullptr)
565  return;
566  MetadataLookupList lul = lue->m_lookupList;
567 
568  if (m_busyPopup)
569  {
570  m_busyPopup->Close();
571  m_busyPopup = nullptr;
572  }
573 
574  if (lul.isEmpty())
575  return;
576 
577  if (lul.count() == 1)
578  {
579  OnGameSearchDone(lul[0]);
580  }
581  else
582  {
583  auto *resultsdialog =
585 
586  connect(resultsdialog, SIGNAL(haveResult(RefCountHandler<MetadataLookup>)),
588  Qt::QueuedConnection);
589 
590  if (resultsdialog->Create())
591  m_popupStack->AddScreen(resultsdialog);
592  }
593  }
594  else if (event->type() == MetadataLookupFailure::kEventType)
595  {
596  auto luf = dynamic_cast<MetadataLookupFailure *>(event);
597  if (luf == nullptr)
598  return;
599  MetadataLookupList lul = luf->m_lookupList;
600 
601  if (m_busyPopup)
602  {
603  m_busyPopup->Close();
604  m_busyPopup = nullptr;
605  }
606 
607  if (!lul.empty())
608  {
609  MetadataLookup *lookup = lul[0];
610  auto *node = lookup->GetData().value<MythGenericTree *>();
611  if (node)
612  {
613  auto *metadata = node->GetData().value<RomInfo *>();
614  if (metadata)
615  {
616  }
617  }
618  LOG(VB_GENERAL, LOG_ERR,
619  QString("No results found for %1").arg(lookup->GetTitle()));
620  }
621  }
622  else if (event->type() == ImageDLEvent::kEventType)
623  {
624  auto *ide = dynamic_cast<ImageDLEvent *>(event);
625  if (ide == nullptr)
626  return;
627  MetadataLookup *lookup = ide->m_item;
628 
629  if (!lookup)
630  return;
631 
632  handleDownloadedImages(lookup);
633  }
634  else if (event->type() == ImageDLFailureEvent::kEventType)
635  {
636  MythErrorNotification n(tr("Failed to retrieve image(s)"),
637  _Location,
638  tr("Check logs"));
640  }
641 }
642 
644 {
645  QString layer = node->GetText();
646  int childDepth = node->getInt() + 1;
647  QString childLevel = getChildLevelString(node);
648  QString filter = getFilter(node);
649  bool childIsLeaf = childDepth == getLevelsOnThisBranch(node) + 1;
650  auto *romInfo = node->GetData().value<RomInfo *>();
651 
652  QString columns;
653  QString conj = "where ";
654 
655  if (!filter.isEmpty())
656  {
657  filter = conj + filter;
658  conj = " and ";
659  }
660  if ((childLevel == "gamename") && (m_gameShowFileName))
661  {
662  columns = childIsLeaf
663  ? "romname,system,year,genre,gamename"
664  : "romname";
665 
666  if (m_showHashed)
667  filter += " and romname like '" + layer + "%'";
668 
669  }
670  else if ((childLevel == "gamename") && (layer.length() == 1))
671  {
672  columns = childIsLeaf
673  ? childLevel + ",system,year,genre,gamename"
674  : childLevel;
675 
676  if (m_showHashed)
677  filter += " and gamename like '" + layer + "%'";
678 
679  }
680  else if (childLevel == "hash")
681  {
682  columns = "left(gamename,1)";
683  }
684  else
685  {
686 
687  columns = childIsLeaf
688  ? childLevel + ",system,year,genre,gamename"
689  : childLevel;
690  }
691 
692  // this whole section ought to be in rominfo.cpp really, but I've put it
693  // in here for now to minimise the number of files changed by this mod
694  if (romInfo)
695  {
696  if (!romInfo->System().isEmpty())
697  {
698  filter += conj + "trim(system)=:SYSTEM";
699  conj = " and ";
700  }
701  if (!romInfo->Year().isEmpty())
702  {
703  filter += conj + "year=:YEAR";
704  conj = " and ";
705  }
706  if (!romInfo->Genre().isEmpty())
707  {
708  filter += conj + "trim(genre)=:GENRE";
709  conj = " and ";
710  }
711  if (!romInfo->Plot().isEmpty())
712  {
713  filter += conj + "plot=:PLOT";
714  conj = " and ";
715  }
716  if (!romInfo->Publisher().isEmpty())
717  {
718  filter += conj + "publisher=:PUBLISHER";
719  conj = " and ";
720  }
721  if (!romInfo->Gamename().isEmpty())
722  {
723  filter += conj + "trim(gamename)=:GAMENAME";
724  }
725 
726  }
727 
728  filter += conj + " display = 1 ";
729 
730  QString sql;
731 
732  if ((childLevel == "gamename") && (m_gameShowFileName))
733  {
734  sql = "select distinct "
735  + columns
736  + " from gamemetadata "
737  + filter
738  + " order by romname"
739  + ";";
740  }
741  else if (childLevel == "hash")
742  {
743  sql = "select distinct "
744  + columns
745  + " from gamemetadata "
746  + filter
747  + " order by gamename,romname"
748  + ";";
749  }
750  else
751  {
752  sql = "select distinct "
753  + columns
754  + " from gamemetadata "
755  + filter
756  + " order by "
757  + childLevel
758  + ";";
759  }
760 
761  return sql;
762 }
763 
765 {
766  unsigned this_level = node->getInt();
767  while (node->getInt() != 1)
768  node = node->getParent();
769 
770  auto *gi = node->GetData().value<GameTreeInfo *>();
771  return gi->getLevel(this_level - 1);
772 }
773 
775 {
776  while (node->getInt() != 1)
777  node = node->getParent();
778  auto *gi = node->GetData().value<GameTreeInfo *>();
779  return gi->getFilter();
780 }
781 
783 {
784  while (node->getInt() != 1)
785  node = node->getParent();
786 
787  auto *gi = node->GetData().value<GameTreeInfo *>();
788  return gi->getDepth();
789 }
790 
792 {
793  return (node->getInt() - 1) == getLevelsOnThisBranch(node);
794 }
795 
797 {
798  QString layername = node->GetText();
799  auto *romInfo = node->GetData().value<RomInfo *>();
800 
801  MSqlQuery query(MSqlQuery::InitCon());
802 
803  query.prepare(getFillSql(node));
804 
805  if (romInfo)
806  {
807  if (!romInfo->System().isEmpty())
808  query.bindValue(":SYSTEM", romInfo->System());
809  if (!romInfo->Year().isEmpty())
810  query.bindValue(":YEAR", romInfo->Year());
811  if (!romInfo->Genre().isEmpty())
812  query.bindValue(":GENRE", romInfo->Genre());
813  if (!romInfo->Plot().isEmpty())
814  query.bindValue(":PLOT", romInfo->Plot());
815  if (!romInfo->Publisher().isEmpty())
816  query.bindValue(":PUBLISHER", romInfo->Publisher());
817  if (!romInfo->Gamename().isEmpty())
818  query.bindValue(":GAMENAME", romInfo->Gamename());
819  }
820 
821  bool IsLeaf = node->getInt() == getLevelsOnThisBranch(node);
822  if (query.exec() && query.size() > 0)
823  {
824  while (query.next())
825  {
826  QString current = query.value(0).toString().trimmed();
827  auto *new_node =
828  new MythGenericTree(current, node->getInt() + 1, false);
829  if (IsLeaf)
830  {
831  auto *temp = new RomInfo();
832  temp->setSystem(query.value(1).toString().trimmed());
833  temp->setYear(query.value(2).toString());
834  temp->setGenre(query.value(3).toString().trimmed());
835  temp->setGamename(query.value(4).toString().trimmed());
836  new_node->SetData(qVariantFromValue(temp));
837  node->addNode(new_node);
838  }
839  else
840  {
841  RomInfo *newRomInfo = nullptr;
842  if (node->getInt() > 1)
843  {
844  auto *currentRomInfo = node->GetData().value<RomInfo *>();
845  newRomInfo = new RomInfo(*currentRomInfo);
846  }
847  else
848  {
849  newRomInfo = new RomInfo();
850  }
851  new_node->SetData(qVariantFromValue(newRomInfo));
852  node->addNode(new_node);
853  if (getChildLevelString(node) != "hash")
854  newRomInfo->setField(getChildLevelString(node), current);
855  }
856  }
857  }
858 }
859 
861 {
862  MythGenericTree *top_level = node;
863  while (top_level->getParent() != m_gameTree)
864  {
865  top_level = top_level->getParent();
866  }
867 
868  QList<MythGenericTree*>::iterator it;
869  QList<MythGenericTree*> *children = m_gameTree->getAllChildren();
870 
871  for (it = children->begin(); it != children->end(); ++it)
872  {
873  MythGenericTree *child = *it;
874  if (child != top_level)
875  {
876  child->deleteAllChildren();
877  }
878  }
879 }
880 
882 {
883  resetOtherTrees(node);
884 
885  if (node->getParent() == m_favouriteNode && romInfo->Favorite() == 0)
886  {
887  // node is being removed
889  }
890  else
891  nodeChanged(node);
892 }
893 
895  bool automode)
896 {
897  if (!node)
898  node = m_gameUITree->GetCurrentNode();
899 
900  if (!node)
901  return;
902 
903  auto *metadata = node->GetData().value<RomInfo *>();
904  if (!metadata)
905  return;
906 
907  auto *lookup = new MetadataLookup();
908  lookup->SetStep(kLookupSearch);
909  lookup->SetType(kMetadataGame);
910  lookup->SetData(qVariantFromValue(node));
911 
912  if (automode)
913  {
914  lookup->SetAutomatic(true);
915  }
916 
917  lookup->SetTitle(metadata->Gamename());
918  lookup->SetInetref(metadata->Inetref());
919  if (m_query->isRunning())
920  m_query->prependLookup(lookup);
921  else
922  m_query->addLookup(lookup);
923 
924  if (!automode)
925  {
926  //: %1 is the game name
927  QString msg = tr("Fetching details for %1")
928  .arg(metadata->Gamename());
929  createBusyDialog(msg);
930  }
931 }
932 
933 void GameUI::createBusyDialog(const QString& title)
934 {
935  if (m_busyPopup)
936  return;
937 
938  const QString& message = title;
939 
941  "mythgamebusydialog");
942 
943  if (m_busyPopup->Create())
945 }
946 
948 {
949  if (!lookup)
950  return;
951 
952  lookup->SetStep(kLookupData);
953  lookup->IncrRef();
954  m_query->prependLookup(lookup);
955 }
956 
958 {
959  if (m_busyPopup)
960  {
961  m_busyPopup->Close();
962  m_busyPopup = nullptr;
963  }
964 
965  if (!lookup)
966  return;
967 
968  auto *node = lookup->GetData().value<MythGenericTree *>();
969  if (!node)
970  return;
971 
972  auto *metadata = node->GetData().value<RomInfo *>();
973  if (!metadata)
974  return;
975 
976  metadata->setGamename(lookup->GetTitle());
977  metadata->setYear(QString::number(lookup->GetYear()));
978  metadata->setPlot(lookup->GetDescription());
979  metadata->setSystem(lookup->GetSystem());
980 
981  QStringList coverart, fanart, screenshot;
982 
983  // Imagery
984  ArtworkList coverartlist = lookup->GetArtwork(kArtworkCoverart);
985  for (ArtworkList::const_iterator p = coverartlist.begin();
986  p != coverartlist.end(); ++p)
987  {
988  coverart.prepend((*p).url);
989  }
990  ArtworkList fanartlist = lookup->GetArtwork(kArtworkFanart);
991  for (ArtworkList::const_iterator p = fanartlist.begin();
992  p != fanartlist.end(); ++p)
993  {
994  fanart.prepend((*p).url);
995  }
996  ArtworkList screenshotlist = lookup->GetArtwork(kArtworkScreenshot);
997  for (ArtworkList::const_iterator p = screenshotlist.begin();
998  p != screenshotlist.end(); ++p)
999  {
1000  screenshot.prepend((*p).url);
1001  }
1002 
1003  StartGameImageSet(node, coverart, fanart, screenshot);
1004 
1005  metadata->SaveToDatabase();
1006  updateChangedNode(node, metadata);
1007 }
1008 
1009 void GameUI::StartGameImageSet(MythGenericTree *node, QStringList coverart,
1010  QStringList fanart, QStringList screenshot)
1011 {
1012  if (!node)
1013  return;
1014 
1015  auto *metadata = node->GetData().value<RomInfo *>();
1016  if (!metadata)
1017  return;
1018 
1019  ArtworkMap map;
1020 
1021  QString inetref = metadata->Inetref();
1022  QString system = metadata->System();
1023  QString title = metadata->Gamename();
1024 
1025  if (metadata->Boxart().isEmpty() && !coverart.empty())
1026  {
1027  ArtworkInfo info;
1028  info.url = coverart.takeAt(0).trimmed();
1029  map.insert(kArtworkCoverart, info);
1030  }
1031 
1032  if (metadata->Fanart().isEmpty() && !fanart.empty())
1033  {
1034  ArtworkInfo info;
1035  info.url = fanart.takeAt(0).trimmed();
1036  map.insert(kArtworkFanart, info);
1037  }
1038 
1039  if (metadata->Screenshot().isEmpty() && !screenshot.empty())
1040  {
1041  ArtworkInfo info;
1042  info.url = screenshot.takeAt(0).trimmed();
1043  map.insert(kArtworkScreenshot, info);
1044  }
1045 
1046  auto *lookup = new MetadataLookup();
1047  lookup->SetTitle(metadata->Gamename());
1048  lookup->SetSystem(metadata->System());
1049  lookup->SetInetref(metadata->Inetref());
1050  lookup->SetType(kMetadataGame);
1051  lookup->SetDownloads(map);
1052  lookup->SetData(qVariantFromValue(node));
1053 
1054  m_imageDownload->addDownloads(lookup);
1055 }
1056 
1058 {
1059  if (!lookup)
1060  return;
1061 
1062  auto *node = lookup->GetData().value<MythGenericTree *>();
1063  if (!node)
1064  return;
1065 
1066  auto *metadata = node->GetData().value<RomInfo *>();
1067  if (!metadata)
1068  return;
1069 
1070  DownloadMap downloads = lookup->GetDownloads();
1071 
1072  if (downloads.isEmpty())
1073  return;
1074 
1075  for (DownloadMap::iterator i = downloads.begin();
1076  i != downloads.end(); ++i)
1077  {
1078  VideoArtworkType type = i.key();
1079  ArtworkInfo info = i.value();
1080  QString filename = info.url;
1081 
1082  if (type == kArtworkCoverart)
1083  metadata->setBoxart(filename);
1084  else if (type == kArtworkFanart)
1085  metadata->setFanart(filename);
1086  else if (type == kArtworkScreenshot)
1087  metadata->setScreenshot(filename);
1088  }
1089 
1090  metadata->SaveToDatabase();
1091  updateChangedNode(node, metadata);
1092 }
1093 
1095 {
1096  if (!m_scanner)
1097  m_scanner = new GameScanner();
1098  connect(m_scanner, SIGNAL(finished(bool)), SLOT(reloadAllData(bool)));
1099  m_scanner->doScanAll();
1100 }
1101 
1102 void GameUI::reloadAllData(bool dbChanged)
1103 {
1104  delete m_scanner;
1105  m_scanner = nullptr;
1106 
1107  if (dbChanged)
1108  BuildTree();
1109 }
1110 
MythUIBusyDialog * m_busyPopup
Definition: gameui.h:78
void toggleFavorite(void)
Definition: gameui.cpp:488
void resetOtherTrees(MythGenericTree *node)
Definition: gameui.cpp:860
void clearRomInfo(void)
Definition: gameui.cpp:353
MythGenericTree * GetCurrentNode(void) const
MythScreenStack * GetScreenStack() const
MythGenericTree * m_gameTree
Definition: gameui.h:75
void doScan(void)
Definition: gameui.cpp:1094
MetadataDownload * m_query
Definition: gameui.h:92
ArtworkList GetArtwork(VideoArtworkType type) const
void updateChangedNode(MythGenericTree *node, RomInfo *romInfo)
Definition: gameui.cpp:881
void doScanAll(void)
Definition: gamescan.cpp:231
MythGenericTree * addNode(const QString &a_string, int an_int=0, bool selectable_flag=false, bool visible=true)
void handleDownloadedImages(MetadataLookup *lookup)
Definition: gameui.cpp:1057
const QString & getFilter() const
Definition: gameui.cpp:37
bool TranslateKeyPress(const QString &context, QKeyEvent *e, QStringList &actions, bool allowJumps=true)
Get a list of actions for a keypress in the given context.
QList< MythGenericTree * > * getAllChildren() const
void SetText(const QString &text, const QString &name="", const QString &state="")
uint GetYear() const
QString Screenshot() const
Definition: rominfo.h:82
void fillData()
Definition: rominfo.cpp:247
QString Plot() const
Definition: rominfo.h:121
QString GetDescription() const
QSqlQuery wrapper that fetches a DB connection from the connection pool.
Definition: mythdbcon.h:125
Basic menu dialog, message and a list of options.
void showImages(void)
Definition: gameui.cpp:291
VideoArtworkType
int childCount(void) const
QString GetSystem() const
MythUIImage * m_boxImage
Definition: gameui.h:90
virtual void SetText(const QString &text)
Definition: mythuitext.cpp:135
const QVariant GetData(void) const
QString Gamename() const
Definition: rominfo.h:97
void reloadAllData(bool dbchanged)
Definition: gameui.cpp:1102
MythScreenStack * GetStack(const QString &stackname)
void Reset(void) override
Reset the widget to it's original state, should not reset changes made by the theme.
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
MythScreenStack * GetMainStack()
MythUIImage * m_gameImage
Definition: gameui.h:88
void ShowMenu(void) override
Definition: gameui.cpp:421
Q_DECLARE_METATYPE(GrabberScript *)
void OnGameSearchListSelection(RefCountHandler< MetadataLookup > lookup)
Definition: gameui.cpp:947
bool m_showHashed
Definition: gameui.h:72
MythUIStateType * m_gameFavouriteState
Definition: gameui.h:87
void prependLookup(MetadataLookup *lookup)
prependLookup: Add lookup to top of the queue MetadataDownload::m_lookupList takes ownership of the g...
MythUIText * m_gameYearText
Definition: gameui.h:84
bool Load(bool allowLoadInBackground=true, bool forceStat=false)
Load the image(s), wraps ImageLoader::LoadImage()
const QString & getLevel(unsigned i) const
Definition: gameui.cpp:36
void BuildFocusList(void)
QList< ArtworkInfo > ArtworkList
static Type kEventType
Definition: mythdialogbox.h:50
void nodeChanged(MythGenericTree *node)
Definition: gameui.cpp:215
QStringList m_levels
Definition: gameui.cpp:40
void customEvent(QEvent *event) override
Definition: gameui.cpp:499
QString GetTitle() const
void SetStep(LookupStep step)
virtual void Close()
QString GetText(const QString &name="") const
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
Definition: gameui.cpp:178
void setField(const QString &field, const QString &data)
Definition: rominfo.cpp:172
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
GameScanner * m_scanner
Definition: gameui.h:95
virtual int IncrRef(void)
Increments reference count.
MythUIButtonTree * m_gameUITree
Definition: gameui.h:81
void searchStart(void)
Definition: gameui.cpp:455
bool Create(void) override
void showInfo(void)
Definition: gameui.cpp:400
static QString getFilter(MythGenericTree *node)
Definition: gameui.cpp:774
QDateTime current(bool stripped)
Returns current Date and Time in UTC.
Definition: mythdate.cpp:10
MythScreenStack * m_popupStack
Definition: gameui.h:79
QString GetSetting(const QString &key, const QString &defaultval="")
void addDownloads(MetadataLookup *lookup)
addLookup: Add lookup to bottom of the queue MetadataDownload::m_downloadList takes ownership of the ...
void Reset(void) override
Reset the widget to it's original state, should not reset changes made by the theme.
Definition: mythuitext.cpp:83
MythUIText * m_gamePlotText
Definition: gameui.h:86
bool isRunning(void) const
Definition: mthread.cpp:274
static QString getChildLevelString(MythGenericTree *node)
Definition: gameui.cpp:764
void updateRomInfo(RomInfo *rom)
Definition: gameui.cpp:315
static GameHandler * getHandler(uint i)
Definition: gamehandler.cpp:50
MythUIImage * m_fanartImage
Definition: gameui.h:89
void Reset(void) override
Reset the image back to the default defined in the theme.
bool Queue(const MythNotification &notification)
Queue a notification Queue() is thread-safe and can be called from anywhere.
static bool Assign(ContainerType *container, UIType *&item, const QString &name, bool *err=nullptr)
Definition: mythuiutils.h:27
void gameSearch(MythGenericTree *node=nullptr, bool automode=false)
Definition: gameui.cpp:894
static MSqlQueryInfo InitCon(ConnectionReuse=kNormalConnection)
Only use this in combination with MSqlQuery constructor.
Definition: mythdbcon.cpp:535
void fillNode(MythGenericTree *node)
Definition: gameui.cpp:796
void OnGameSearchDone(MetadataLookup *lookup)
Definition: gameui.cpp:957
MetadataImageDownload * m_imageDownload
Definition: gameui.h:93
void edit(void)
Definition: gameui.cpp:378
static bool LoadWindowFromXML(const QString &xmlfile, const QString &windowname, MythUIType *parent)
void setFavorite(bool updateDatabase=false)
Definition: rominfo.cpp:213
QVariant GetData() const
MythUIType * GetFocusWidget(void) const
MythMainWindow * GetMythMainWindow(void)
void BuildTree()
Definition: gameui.cpp:93
QString Year() const
Definition: rominfo.h:130
static void Launchgame(RomInfo *romdata, const QString &systemname)
bool SetCurrentNode(MythGenericTree *node)
Set the currently selected node.
int getInt() const
bool Create() override
Definition: gameui.cpp:55
bool keyPressEvent(QKeyEvent *) override
Key event handler.
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
QMap< VideoArtworkType, ArtworkInfo > DownloadMap
static Type kEventType
bool GetBoolSetting(const QString &key, bool defaultval=false)
QString Boxart() const
Definition: rominfo.h:88
QString Genre() const
Definition: rominfo.h:100
MythGenericTree * getChildByName(const QString &a_name) const
void SetFilename(const QString &filename)
Must be followed by a call to Load() to load the image.
QString getFillSql(MythGenericTree *node) const
Definition: gameui.cpp:643
bool AssignTree(MythGenericTree *tree)
Assign the root node of the tree to be displayed.
void SetReturnEvent(QObject *retobject, const QString &resultid)
void SetData(QVariant data)
QString SystemName() const
Definition: gamehandler.h:96
QString Fanart() const
Definition: rominfo.h:85
static bool isLeaf(MythGenericTree *node)
Definition: gameui.cpp:791
bool DisplayState(const QString &name)
MythUIText * m_gameSystemText
Definition: gameui.h:83
MythGenericTree * getParent(void) const
void Reset(void) override
Reset the widget to it's original state, should not reset changes made by the theme.
void itemClicked(MythUIButtonListItem *item)
Definition: gameui.cpp:252
DownloadMap GetDownloads() const
QString Inetref() const
Definition: rominfo.h:133
MythUIText * m_gameTitleText
Definition: gameui.h:82
QString m_filter
Definition: gameui.cpp:41
GameTreeInfo(const QString &levels, QString filter)
Definition: gameui.cpp:29
QMultiMap< VideoArtworkType, ArtworkInfo > ArtworkMap
Screen in which all other widgets are contained and rendered.
Definition: gameui.h:24
void addLookup(MetadataLookup *lookup)
addLookup: Add lookup to bottom of the queue MetadataDownload::m_lookupList takes ownership of the gi...
void StartGameImageSet(MythGenericTree *node, QStringList coverart, QStringList fanart, QStringList screenshot)
Definition: gameui.cpp:1009
void searchComplete(const QString &)
Definition: gameui.cpp:301
void createBusyDialog(const QString &title)
Definition: gameui.cpp:933
static uint count(void)
Definition: gamehandler.cpp:92
void setGamename(const QString &lgamename)
Definition: rominfo.h:98
MythGenericTree * m_favouriteNode
Definition: gameui.h:76
int getDepth() const
Definition: gameui.cpp:35
QString System() const
Definition: rominfo.h:94
bool m_gameShowFileName
Definition: gameui.h:73
static int getLevelsOnThisBranch(MythGenericTree *node)
Definition: gameui.cpp:782
Provide a dialog to quickly find an entry in a list.
static const QString _Location
Definition: gameui.cpp:24
int Favorite() const
Definition: rominfo.h:136
MythNotificationCenter * GetNotificationCenter(void)
MythUIText * m_gameGenreText
Definition: gameui.h:85