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(QVariant::fromValue(
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(QVariant::fromValue(
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(QVariant::fromValue(
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(QVariant::fromValue(
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(QVariant::fromValue(
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(QVariant::fromValue(
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") || (action == "INCSEARCHNEXT"))
200  searchStart();
201  else if (action == "DOWNLOADDATA")
202  gameSearch();
203  else
204  handled = false;
205  }
206 
207  if (!handled && MythScreenType::keyPressEvent(event))
208  handled = true;
209 
210  return handled;
211 }
212 
214 {
215  if (!node)
216  return;
217 
218  if (!isLeaf(node))
219  {
220  if (node->childCount() == 0 || node == m_favouriteNode)
221  {
222  node->deleteAllChildren();
223  fillNode(node);
224  }
225  clearRomInfo();
226  }
227  else
228  {
229  auto *romInfo = node->GetData().value<RomInfo *>();
230  if (!romInfo)
231  return;
232  if (romInfo->Romname().isEmpty())
233  romInfo->fillData();
234  updateRomInfo(romInfo);
235  if (!romInfo->Screenshot().isEmpty() || !romInfo->Fanart().isEmpty() ||
236  !romInfo->Boxart().isEmpty())
237  showImages();
238  else
239  {
240  if (m_gameImage)
241  m_gameImage->Reset();
242  if (m_fanartImage)
243  m_fanartImage->Reset();
244  if (m_boxImage)
245  m_boxImage->Reset();
246  }
247  }
248 }
249 
251 {
253  if (isLeaf(node))
254  {
255  auto *romInfo = node->GetData().value<RomInfo *>();
256  if (!romInfo)
257  return;
258  if (romInfo->RomCount() == 1)
259  {
260  GameHandler::Launchgame(romInfo, nullptr);
261  }
262  else
263  {
264  //: %1 is the game name
265  QString msg = tr("Choose System for:\n%1").arg(node->GetText());
266  MythScreenStack *popupStack = GetMythMainWindow()->
267  GetStack("popup stack");
268  auto *chooseSystemPopup = new MythDialogBox(
269  msg, popupStack, "chooseSystemPopup");
270 
271  if (chooseSystemPopup->Create())
272  {
273  chooseSystemPopup->SetReturnEvent(this, "chooseSystemPopup");
274  QString all_systems = romInfo->AllSystems();
275  QStringList players = all_systems.split(',');
276  foreach (auto & player, players)
277  chooseSystemPopup->AddButton(player);
278  popupStack->AddScreen(chooseSystemPopup);
279  }
280  else
281  delete chooseSystemPopup;
282  }
283  }
284 }
285 
287 {
288  if (m_gameImage)
289  m_gameImage->Load();
290  if (m_fanartImage)
291  m_fanartImage->Load();
292  if (m_boxImage)
293  m_boxImage->Load();
294 }
295 
296 void GameUI::searchComplete(const QString& string)
297 {
299  return;
300 
302  if (!parent)
303  return;
304 
305  MythGenericTree *new_node = parent->getChildByName(string);
306  if (new_node)
307  m_gameUITree->SetCurrentNode(new_node);
308 }
309 
311 {
312  if (m_gameTitleText)
314  if (m_gameSystemText)
316  if (m_gameYearText)
317  m_gameYearText->SetText(rom->Year());
318  if (m_gameGenreText)
319  m_gameGenreText->SetText(rom->Genre());
320  if (m_gamePlotText)
321  m_gamePlotText->SetText(rom->Plot());
322 
324  {
325  if (rom->Favorite())
327  else
329  }
330 
331  if (m_gameImage)
332  {
333  m_gameImage->Reset();
335  }
336  if (m_fanartImage)
337  {
338  m_fanartImage->Reset();
340  }
341  if (m_boxImage)
342  {
343  m_boxImage->Reset();
344  m_boxImage->SetFilename(rom->Boxart());
345  }
346 }
347 
349 {
350  if (m_gameTitleText)
352  if (m_gameSystemText)
354  if (m_gameYearText)
356  if (m_gameGenreText)
358  if (m_gamePlotText)
362 
363  if (m_gameImage)
364  m_gameImage->Reset();
365 
366  if (m_fanartImage)
367  m_fanartImage->Reset();
368 
369  if (m_boxImage)
370  m_boxImage->Reset();
371 }
372 
373 void GameUI::edit(void)
374 {
376  if (isLeaf(node))
377  {
378  auto *romInfo = node->GetData().value<RomInfo *>();
379 
380  MythScreenStack *screenStack = GetScreenStack();
381 
382  auto *md_editor = new EditRomInfoDialog(screenStack,
383  "mythgameeditmetadata", romInfo);
384 
385  if (md_editor->Create())
386  {
387  screenStack->AddScreen(md_editor);
388  md_editor->SetReturnEvent(this, "editMetadata");
389  }
390  else
391  delete md_editor;
392  }
393 }
394 
396 {
398  if (isLeaf(node))
399  {
400  auto *romInfo = node->GetData().value<RomInfo *>();
401  if (!romInfo)
402  return;
404  auto *details_dialog = new GameDetailsPopup(mainStack, romInfo);
405 
406  if (details_dialog->Create())
407  {
408  mainStack->AddScreen(details_dialog);
409  details_dialog->SetReturnEvent(this, "detailsPopup");
410  }
411  else
412  delete details_dialog;
413  }
414 }
415 
417 {
419 
420  MythScreenStack *popupStack = GetMythMainWindow()->
421  GetStack("popup stack");
422  auto *showMenuPopup =
423  new MythDialogBox(node->GetText(), popupStack, "showMenuPopup");
424 
425  if (showMenuPopup->Create())
426  {
427  showMenuPopup->SetReturnEvent(this, "showMenuPopup");
428 
429  showMenuPopup->AddButton(tr("Scan For Changes"));
430  if (isLeaf(node))
431  {
432  auto *romInfo = node->GetData().value<RomInfo *>();
433  if (romInfo)
434  {
435  showMenuPopup->AddButton(tr("Show Information"));
436  if (romInfo->Favorite())
437  showMenuPopup->AddButton(tr("Remove Favorite"));
438  else
439  showMenuPopup->AddButton(tr("Make Favorite"));
440  showMenuPopup->AddButton(tr("Retrieve Details"));
441  showMenuPopup->AddButton(tr("Edit Details"));
442  }
443  }
444  popupStack->AddScreen(showMenuPopup);
445  }
446  else
447  delete showMenuPopup;
448 }
449 
451 {
453 
454  if (parent != nullptr)
455  {
456  QStringList childList;
457  QList<MythGenericTree*>::iterator it;
458  QList<MythGenericTree*> *children = parent->getAllChildren();
459 
460  for (it = children->begin(); it != children->end(); ++it)
461  {
462  MythGenericTree *child = *it;
463  childList << child->GetText();
464  }
465 
466  MythScreenStack *popupStack =
467  GetMythMainWindow()->GetStack("popup stack");
468  auto *searchDialog = new MythUISearchDialog(popupStack,
469  tr("Game Search"), childList, true, "");
470 
471  if (searchDialog->Create())
472  {
473  connect(searchDialog, SIGNAL(haveResult(QString)),
474  SLOT(searchComplete(QString)));
475 
476  popupStack->AddScreen(searchDialog);
477  }
478  else
479  delete searchDialog;
480  }
481 }
482 
484 {
486  if (isLeaf(node))
487  {
488  auto *romInfo = node->GetData().value<RomInfo *>();
489  romInfo->setFavorite(true);
490  updateChangedNode(node, romInfo);
491  }
492 }
493 
494 void GameUI::customEvent(QEvent *event)
495 {
496  if (event->type() == DialogCompletionEvent::kEventType)
497  {
498  auto dce = dynamic_cast<DialogCompletionEvent*>(event);
499  if (dce == nullptr)
500  return;
501  QString resultid = dce->GetId();
502  QString resulttext = dce->GetResultText();
503 
504  if (resultid == "showMenuPopup")
505  {
506  if (resulttext == tr("Edit Details"))
507  {
508  edit();
509  }
510  if (resulttext == tr("Scan For Changes"))
511  {
512  doScan();
513  }
514  else if (resulttext == tr("Show Information"))
515  {
516  showInfo();
517  }
518  else if (resulttext == tr("Make Favorite") ||
519  resulttext == tr("Remove Favorite"))
520  {
521  toggleFavorite();
522  }
523  else if (resulttext == tr("Retrieve Details"))
524  {
525  gameSearch();
526  }
527  }
528  else if (resultid == "chooseSystemPopup")
529  {
530  if (!resulttext.isEmpty() && resulttext != tr("Cancel"))
531  {
533  auto *romInfo = node->GetData().value<RomInfo *>();
534  GameHandler::Launchgame(romInfo, resulttext);
535  }
536  }
537  else if (resultid == "editMetadata")
538  {
540  auto *oldRomInfo = node->GetData().value<RomInfo *>();
541  delete oldRomInfo;
542 
543  auto *romInfo = dce->GetData().value<RomInfo *>();
544  node->SetData(QVariant::fromValue(romInfo));
545  node->SetText(romInfo->Gamename());
546 
547  romInfo->SaveToDatabase();
548  updateChangedNode(node, romInfo);
549  }
550  else if (resultid == "detailsPopup")
551  {
552  // Play button pushed
553  itemClicked(nullptr);
554  }
555  }
556  if (event->type() == MetadataLookupEvent::kEventType)
557  {
558  auto lue = dynamic_cast<MetadataLookupEvent *>(event);
559  if (lue == nullptr)
560  return;
561  MetadataLookupList lul = lue->m_lookupList;
562 
563  if (m_busyPopup)
564  {
565  m_busyPopup->Close();
566  m_busyPopup = nullptr;
567  }
568 
569  if (lul.isEmpty())
570  return;
571 
572  if (lul.count() == 1)
573  {
574  OnGameSearchDone(lul[0]);
575  }
576  else
577  {
578  auto *resultsdialog =
580 
581  connect(resultsdialog, SIGNAL(haveResult(RefCountHandler<MetadataLookup>)),
583  Qt::QueuedConnection);
584 
585  if (resultsdialog->Create())
586  m_popupStack->AddScreen(resultsdialog);
587  }
588  }
589  else if (event->type() == MetadataLookupFailure::kEventType)
590  {
591  auto luf = dynamic_cast<MetadataLookupFailure *>(event);
592  if (luf == nullptr)
593  return;
594  MetadataLookupList lul = luf->m_lookupList;
595 
596  if (m_busyPopup)
597  {
598  m_busyPopup->Close();
599  m_busyPopup = nullptr;
600  }
601 
602  if (!lul.empty())
603  {
604  MetadataLookup *lookup = lul[0];
605  auto *node = lookup->GetData().value<MythGenericTree *>();
606  if (node)
607  {
608  auto *metadata = node->GetData().value<RomInfo *>();
609  if (metadata)
610  {
611  }
612  }
613  LOG(VB_GENERAL, LOG_ERR,
614  QString("No results found for %1").arg(lookup->GetTitle()));
615  }
616  }
617  else if (event->type() == ImageDLEvent::kEventType)
618  {
619  auto *ide = dynamic_cast<ImageDLEvent *>(event);
620  if (ide == nullptr)
621  return;
622  MetadataLookup *lookup = ide->m_item;
623 
624  if (!lookup)
625  return;
626 
627  handleDownloadedImages(lookup);
628  }
629  else if (event->type() == ImageDLFailureEvent::kEventType)
630  {
631  MythErrorNotification n(tr("Failed to retrieve image(s)"),
632  _Location,
633  tr("Check logs"));
635  }
636 }
637 
639 {
640  QString layer = node->GetText();
641  int childDepth = node->getInt() + 1;
642  QString childLevel = getChildLevelString(node);
643  QString filter = getFilter(node);
644  bool childIsLeaf = childDepth == getLevelsOnThisBranch(node) + 1;
645  auto *romInfo = node->GetData().value<RomInfo *>();
646 
647  QString columns;
648  QString conj = "where ";
649 
650  if (!filter.isEmpty())
651  {
652  filter = conj + filter;
653  conj = " and ";
654  }
655  if ((childLevel == "gamename") && (m_gameShowFileName))
656  {
657  columns = childIsLeaf
658  ? "romname,system,year,genre,gamename"
659  : "romname";
660 
661  if (m_showHashed)
662  filter += " and romname like '" + layer + "%'";
663 
664  }
665  else if ((childLevel == "gamename") && (layer.length() == 1))
666  {
667  columns = childIsLeaf
668  ? childLevel + ",system,year,genre,gamename"
669  : childLevel;
670 
671  if (m_showHashed)
672  filter += " and gamename like '" + layer + "%'";
673 
674  }
675  else if (childLevel == "hash")
676  {
677  columns = "left(gamename,1)";
678  }
679  else
680  {
681 
682  columns = childIsLeaf
683  ? childLevel + ",system,year,genre,gamename"
684  : childLevel;
685  }
686 
687  // this whole section ought to be in rominfo.cpp really, but I've put it
688  // in here for now to minimise the number of files changed by this mod
689  if (romInfo)
690  {
691  if (!romInfo->System().isEmpty())
692  {
693  filter += conj + "trim(system)=:SYSTEM";
694  conj = " and ";
695  }
696  if (!romInfo->Year().isEmpty())
697  {
698  filter += conj + "year=:YEAR";
699  conj = " and ";
700  }
701  if (!romInfo->Genre().isEmpty())
702  {
703  filter += conj + "trim(genre)=:GENRE";
704  conj = " and ";
705  }
706  if (!romInfo->Plot().isEmpty())
707  {
708  filter += conj + "plot=:PLOT";
709  conj = " and ";
710  }
711  if (!romInfo->Publisher().isEmpty())
712  {
713  filter += conj + "publisher=:PUBLISHER";
714  conj = " and ";
715  }
716  if (!romInfo->Gamename().isEmpty())
717  {
718  filter += conj + "trim(gamename)=:GAMENAME";
719  }
720 
721  }
722 
723  filter += conj + " display = 1 ";
724 
725  QString sql;
726 
727  if ((childLevel == "gamename") && (m_gameShowFileName))
728  {
729  sql = "select distinct "
730  + columns
731  + " from gamemetadata "
732  + filter
733  + " order by romname"
734  + ";";
735  }
736  else if (childLevel == "hash")
737  {
738  sql = "select distinct "
739  + columns
740  + " from gamemetadata "
741  + filter
742  + " order by gamename,romname"
743  + ";";
744  }
745  else
746  {
747  sql = "select distinct "
748  + columns
749  + " from gamemetadata "
750  + filter
751  + " order by "
752  + childLevel
753  + ";";
754  }
755 
756  return sql;
757 }
758 
760 {
761  unsigned this_level = node->getInt();
762  while (node->getInt() != 1)
763  node = node->getParent();
764 
765  auto *gi = node->GetData().value<GameTreeInfo *>();
766  return gi->getLevel(this_level - 1);
767 }
768 
770 {
771  while (node->getInt() != 1)
772  node = node->getParent();
773  auto *gi = node->GetData().value<GameTreeInfo *>();
774  return gi->getFilter();
775 }
776 
778 {
779  while (node->getInt() != 1)
780  node = node->getParent();
781 
782  auto *gi = node->GetData().value<GameTreeInfo *>();
783  return gi->getDepth();
784 }
785 
787 {
788  return (node->getInt() - 1) == getLevelsOnThisBranch(node);
789 }
790 
792 {
793  QString layername = node->GetText();
794  auto *romInfo = node->GetData().value<RomInfo *>();
795 
796  MSqlQuery query(MSqlQuery::InitCon());
797 
798  query.prepare(getFillSql(node));
799 
800  if (romInfo)
801  {
802  if (!romInfo->System().isEmpty())
803  query.bindValue(":SYSTEM", romInfo->System());
804  if (!romInfo->Year().isEmpty())
805  query.bindValue(":YEAR", romInfo->Year());
806  if (!romInfo->Genre().isEmpty())
807  query.bindValue(":GENRE", romInfo->Genre());
808  if (!romInfo->Plot().isEmpty())
809  query.bindValue(":PLOT", romInfo->Plot());
810  if (!romInfo->Publisher().isEmpty())
811  query.bindValue(":PUBLISHER", romInfo->Publisher());
812  if (!romInfo->Gamename().isEmpty())
813  query.bindValue(":GAMENAME", romInfo->Gamename());
814  }
815 
816  bool IsLeaf = node->getInt() == getLevelsOnThisBranch(node);
817  if (query.exec() && query.size() > 0)
818  {
819  while (query.next())
820  {
821  QString current = query.value(0).toString().trimmed();
822  auto *new_node =
823  new MythGenericTree(current, node->getInt() + 1, false);
824  if (IsLeaf)
825  {
826  auto *temp = new RomInfo();
827  temp->setSystem(query.value(1).toString().trimmed());
828  temp->setYear(query.value(2).toString());
829  temp->setGenre(query.value(3).toString().trimmed());
830  temp->setGamename(query.value(4).toString().trimmed());
831  new_node->SetData(QVariant::fromValue(temp));
832  node->addNode(new_node);
833  }
834  else
835  {
836  RomInfo *newRomInfo = nullptr;
837  if (node->getInt() > 1)
838  {
839  auto *currentRomInfo = node->GetData().value<RomInfo *>();
840  newRomInfo = new RomInfo(*currentRomInfo);
841  }
842  else
843  {
844  newRomInfo = new RomInfo();
845  }
846  new_node->SetData(QVariant::fromValue(newRomInfo));
847  node->addNode(new_node);
848  if (getChildLevelString(node) != "hash")
849  newRomInfo->setField(getChildLevelString(node), current);
850  }
851  }
852  }
853 }
854 
856 {
857  MythGenericTree *top_level = node;
858  while (top_level->getParent() != m_gameTree)
859  {
860  top_level = top_level->getParent();
861  }
862 
863  QList<MythGenericTree*>::iterator it;
864  QList<MythGenericTree*> *children = m_gameTree->getAllChildren();
865 
866  for (it = children->begin(); it != children->end(); ++it)
867  {
868  MythGenericTree *child = *it;
869  if (child != top_level)
870  {
871  child->deleteAllChildren();
872  }
873  }
874 }
875 
877 {
878  resetOtherTrees(node);
879 
880  if (node->getParent() == m_favouriteNode && romInfo->Favorite() == 0)
881  {
882  // node is being removed
884  }
885  else
886  nodeChanged(node);
887 }
888 
890  bool automode)
891 {
892  if (!node)
893  node = m_gameUITree->GetCurrentNode();
894 
895  if (!node)
896  return;
897 
898  auto *metadata = node->GetData().value<RomInfo *>();
899  if (!metadata)
900  return;
901 
902  auto *lookup = new MetadataLookup();
903  lookup->SetStep(kLookupSearch);
904  lookup->SetType(kMetadataGame);
905  lookup->SetData(QVariant::fromValue(node));
906 
907  if (automode)
908  {
909  lookup->SetAutomatic(true);
910  }
911 
912  lookup->SetTitle(metadata->Gamename());
913  lookup->SetInetref(metadata->Inetref());
914  if (m_query->isRunning())
915  m_query->prependLookup(lookup);
916  else
917  m_query->addLookup(lookup);
918 
919  if (!automode)
920  {
921  //: %1 is the game name
922  QString msg = tr("Fetching details for %1")
923  .arg(metadata->Gamename());
924  createBusyDialog(msg);
925  }
926 }
927 
928 void GameUI::createBusyDialog(const QString& title)
929 {
930  if (m_busyPopup)
931  return;
932 
933  const QString& message = title;
934 
936  "mythgamebusydialog");
937 
938  if (m_busyPopup->Create())
940 }
941 
943 {
944  if (!lookup)
945  return;
946 
947  lookup->SetStep(kLookupData);
948  lookup->IncrRef();
949  m_query->prependLookup(lookup);
950 }
951 
953 {
954  if (m_busyPopup)
955  {
956  m_busyPopup->Close();
957  m_busyPopup = nullptr;
958  }
959 
960  if (!lookup)
961  return;
962 
963  auto *node = lookup->GetData().value<MythGenericTree *>();
964  if (!node)
965  return;
966 
967  auto *metadata = node->GetData().value<RomInfo *>();
968  if (!metadata)
969  return;
970 
971  metadata->setGamename(lookup->GetTitle());
972  metadata->setYear(QString::number(lookup->GetYear()));
973  metadata->setPlot(lookup->GetDescription());
974  metadata->setSystem(lookup->GetSystem());
975 
976  QStringList coverart;
977  QStringList fanart;
978  QStringList screenshot;
979 
980  // Imagery
981  ArtworkList coverartlist = lookup->GetArtwork(kArtworkCoverart);
982  for (ArtworkList::const_iterator p = coverartlist.begin();
983  p != coverartlist.end(); ++p)
984  {
985  coverart.prepend((*p).url);
986  }
987  ArtworkList fanartlist = lookup->GetArtwork(kArtworkFanart);
988  for (ArtworkList::const_iterator p = fanartlist.begin();
989  p != fanartlist.end(); ++p)
990  {
991  fanart.prepend((*p).url);
992  }
993  ArtworkList screenshotlist = lookup->GetArtwork(kArtworkScreenshot);
994  for (ArtworkList::const_iterator p = screenshotlist.begin();
995  p != screenshotlist.end(); ++p)
996  {
997  screenshot.prepend((*p).url);
998  }
999 
1000  StartGameImageSet(node, coverart, fanart, screenshot);
1001 
1002  metadata->SaveToDatabase();
1003  updateChangedNode(node, metadata);
1004 }
1005 
1006 void GameUI::StartGameImageSet(MythGenericTree *node, QStringList coverart,
1007  QStringList fanart, QStringList screenshot)
1008 {
1009  if (!node)
1010  return;
1011 
1012  auto *metadata = node->GetData().value<RomInfo *>();
1013  if (!metadata)
1014  return;
1015 
1016  ArtworkMap map;
1017 
1018  QString inetref = metadata->Inetref();
1019  QString system = metadata->System();
1020  QString title = metadata->Gamename();
1021 
1022  if (metadata->Boxart().isEmpty() && !coverart.empty())
1023  {
1024  ArtworkInfo info;
1025  info.url = coverart.takeAt(0).trimmed();
1026  map.insert(kArtworkCoverart, info);
1027  }
1028 
1029  if (metadata->Fanart().isEmpty() && !fanart.empty())
1030  {
1031  ArtworkInfo info;
1032  info.url = fanart.takeAt(0).trimmed();
1033  map.insert(kArtworkFanart, info);
1034  }
1035 
1036  if (metadata->Screenshot().isEmpty() && !screenshot.empty())
1037  {
1038  ArtworkInfo info;
1039  info.url = screenshot.takeAt(0).trimmed();
1040  map.insert(kArtworkScreenshot, info);
1041  }
1042 
1043  auto *lookup = new MetadataLookup();
1044  lookup->SetTitle(metadata->Gamename());
1045  lookup->SetSystem(metadata->System());
1046  lookup->SetInetref(metadata->Inetref());
1047  lookup->SetType(kMetadataGame);
1048  lookup->SetDownloads(map);
1049  lookup->SetData(QVariant::fromValue(node));
1050 
1051  m_imageDownload->addDownloads(lookup);
1052 }
1053 
1055 {
1056  if (!lookup)
1057  return;
1058 
1059  auto *node = lookup->GetData().value<MythGenericTree *>();
1060  if (!node)
1061  return;
1062 
1063  auto *metadata = node->GetData().value<RomInfo *>();
1064  if (!metadata)
1065  return;
1066 
1067  DownloadMap downloads = lookup->GetDownloads();
1068 
1069  if (downloads.isEmpty())
1070  return;
1071 
1072  for (DownloadMap::iterator i = downloads.begin();
1073  i != downloads.end(); ++i)
1074  {
1075  VideoArtworkType type = i.key();
1076  ArtworkInfo info = i.value();
1077  QString filename = info.url;
1078 
1079  if (type == kArtworkCoverart)
1080  metadata->setBoxart(filename);
1081  else if (type == kArtworkFanart)
1082  metadata->setFanart(filename);
1083  else if (type == kArtworkScreenshot)
1084  metadata->setScreenshot(filename);
1085  }
1086 
1087  metadata->SaveToDatabase();
1088  updateChangedNode(node, metadata);
1089 }
1090 
1092 {
1093  if (!m_scanner)
1094  m_scanner = new GameScanner();
1095  connect(m_scanner, SIGNAL(finished(bool)), SLOT(reloadAllData(bool)));
1096  m_scanner->doScanAll();
1097 }
1098 
1099 void GameUI::reloadAllData(bool dbChanged)
1100 {
1101  delete m_scanner;
1102  m_scanner = nullptr;
1103 
1104  if (dbChanged)
1105  BuildTree();
1106 }
1107 
MythUIBusyDialog * m_busyPopup
Definition: gameui.h:78
void toggleFavorite(void)
Definition: gameui.cpp:483
void resetOtherTrees(MythGenericTree *node)
Definition: gameui.cpp:855
void clearRomInfo(void)
Definition: gameui.cpp:348
MythGenericTree * GetCurrentNode(void) const
MythScreenStack * GetScreenStack() const
MythGenericTree * m_gameTree
Definition: gameui.h:75
void doScan(void)
Definition: gameui.cpp:1091
MetadataDownload * m_query
Definition: gameui.h:92
ArtworkList GetArtwork(VideoArtworkType type) const
void updateChangedNode(MythGenericTree *node, RomInfo *romInfo)
Definition: gameui.cpp:876
void doScanAll(void)
Definition: gamescan.cpp:227
MythGenericTree * addNode(const QString &a_string, int an_int=0, bool selectable_flag=false, bool visible=true)
void handleDownloadedImages(MetadataLookup *lookup)
Definition: gameui.cpp:1054
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
void searchComplete(const QString &string)
Definition: gameui.cpp:296
QString Screenshot() const
Definition: rominfo.h:84
void fillData()
Definition: rominfo.cpp:247
QString Plot() const
Definition: rominfo.h:123
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:286
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
QString Gamename() const
Definition: rominfo.h:99
void reloadAllData(bool dbchanged)
Definition: gameui.cpp:1099
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:416
Q_DECLARE_METATYPE(GrabberScript *)
void OnGameSearchListSelection(RefCountHandler< MetadataLookup > lookup)
Definition: gameui.cpp:942
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:56
void nodeChanged(MythGenericTree *node)
Definition: gameui.cpp:213
QStringList m_levels
Definition: gameui.cpp:40
void customEvent(QEvent *event) override
Definition: gameui.cpp:494
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:450
bool Create(void) override
void showInfo(void)
Definition: gameui.cpp:395
static QString getFilter(MythGenericTree *node)
Definition: gameui.cpp:769
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:759
void updateRomInfo(RomInfo *rom)
Definition: gameui.cpp:310
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:889
static MSqlQueryInfo InitCon(ConnectionReuse _reuse=kNormalConnection)
Only use this in combination with MSqlQuery constructor.
Definition: mythdbcon.cpp:535
void fillNode(MythGenericTree *node)
Definition: gameui.cpp:791
void OnGameSearchDone(MetadataLookup *lookup)
Definition: gameui.cpp:952
MetadataImageDownload * m_imageDownload
Definition: gameui.h:93
void edit(void)
Definition: gameui.cpp:373
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:132
static void Launchgame(RomInfo *romdata, const QString &systemname)
bool SetCurrentNode(MythGenericTree *node)
Set the currently selected node.
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
int getInt() const
bool Create() override
Definition: gameui.cpp:55
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
QMap< VideoArtworkType, ArtworkInfo > DownloadMap
static Type kEventType
QVariant GetData(void) const
bool GetBoolSetting(const QString &key, bool defaultval=false)
QString Boxart() const
Definition: rominfo.h:90
QString Genre() const
Definition: rominfo.h:102
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:638
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:101
QString Fanart() const
Definition: rominfo.h:87
static bool isLeaf(MythGenericTree *node)
Definition: gameui.cpp:786
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:250
DownloadMap GetDownloads() const
QString Inetref() const
Definition: rominfo.h:135
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:1006
void createBusyDialog(const QString &title)
Definition: gameui.cpp:928
static uint count(void)
Definition: gamehandler.cpp:92
void setGamename(const QString &lgamename)
Definition: rominfo.h:100
MythGenericTree * m_favouriteNode
Definition: gameui.h:76
int getDepth() const
Definition: gameui.cpp:35
QString System() const
Definition: rominfo.h:96
bool m_gameShowFileName
Definition: gameui.h:73
static int getLevelsOnThisBranch(MythGenericTree *node)
Definition: gameui.cpp:777
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:138
MythNotificationCenter * GetNotificationCenter(void)
MythUIText * m_gameGenreText
Definition: gameui.h:85