game_list.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. // Copyright 2015 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <QFileSystemWatcher>
  6. #include <QHBoxLayout>
  7. #include <QLabel>
  8. #include <QLineEdit>
  9. #include <QList>
  10. #include <QModelIndex>
  11. #include <QSettings>
  12. #include <QStandardItem>
  13. #include <QStandardItemModel>
  14. #include <QString>
  15. #include <QToolButton>
  16. #include <QTreeView>
  17. #include <QVBoxLayout>
  18. #include <QVector>
  19. #include <QWidget>
  20. #include "common/common_types.h"
  21. #include "uisettings.h"
  22. #include "yuzu/compatibility_list.h"
  23. class GameListWorker;
  24. class GameListSearchField;
  25. class GameListDir;
  26. class GMainWindow;
  27. namespace FileSys {
  28. class ManualContentProvider;
  29. class VfsFilesystem;
  30. } // namespace FileSys
  31. enum class GameListOpenTarget {
  32. SaveData,
  33. ModData,
  34. };
  35. class GameList : public QWidget {
  36. Q_OBJECT
  37. public:
  38. enum {
  39. COLUMN_NAME,
  40. COLUMN_COMPATIBILITY,
  41. COLUMN_ADD_ONS,
  42. COLUMN_FILE_TYPE,
  43. COLUMN_SIZE,
  44. COLUMN_COUNT, // Number of columns
  45. };
  46. explicit GameList(std::shared_ptr<FileSys::VfsFilesystem> vfs,
  47. FileSys::ManualContentProvider* provider, GMainWindow* parent = nullptr);
  48. ~GameList() override;
  49. QString getLastFilterResultItem() const;
  50. void clearFilter();
  51. void setFilterFocus();
  52. void setFilterVisible(bool visibility);
  53. bool isEmpty() const;
  54. void LoadCompatibilityList();
  55. void PopulateAsync(QVector<UISettings::GameDir>& game_dirs);
  56. void SaveInterfaceLayout();
  57. void LoadInterfaceLayout();
  58. static const QStringList supported_file_extensions;
  59. signals:
  60. void GameChosen(QString game_path);
  61. void ShouldCancelWorker();
  62. void OpenFolderRequested(GameListOpenTarget target, const std::string& game_path);
  63. void OpenTransferableShaderCacheRequested(u64 program_id);
  64. void DumpRomFSRequested(u64 program_id, const std::string& game_path);
  65. void CopyTIDRequested(u64 program_id);
  66. void NavigateToGamedbEntryRequested(u64 program_id,
  67. const CompatibilityList& compatibility_list);
  68. void OpenPerGameGeneralRequested(const std::string& file);
  69. void OpenDirectory(const QString& directory);
  70. void AddDirectory();
  71. void ShowList(bool show);
  72. private slots:
  73. void onItemExpanded(const QModelIndex& item);
  74. void onTextChanged(const QString& new_text);
  75. void onFilterCloseClicked();
  76. void onUpdateThemedIcons();
  77. private:
  78. void AddDirEntry(GameListDir* entry_items);
  79. void AddEntry(const QList<QStandardItem*>& entry_items, GameListDir* parent);
  80. void ValidateEntry(const QModelIndex& item);
  81. void DonePopulating(QStringList watch_list);
  82. void RefreshGameDirectory();
  83. void PopupContextMenu(const QPoint& menu_location);
  84. void AddGamePopup(QMenu& context_menu, u64 program_id, std::string path);
  85. void AddCustomDirPopup(QMenu& context_menu, QModelIndex selected);
  86. void AddPermDirPopup(QMenu& context_menu, QModelIndex selected);
  87. std::shared_ptr<FileSys::VfsFilesystem> vfs;
  88. FileSys::ManualContentProvider* provider;
  89. GameListSearchField* search_field;
  90. GMainWindow* main_window = nullptr;
  91. QVBoxLayout* layout = nullptr;
  92. QTreeView* tree_view = nullptr;
  93. QStandardItemModel* item_model = nullptr;
  94. GameListWorker* current_worker = nullptr;
  95. QFileSystemWatcher* watcher = nullptr;
  96. CompatibilityList compatibility_list;
  97. friend class GameListSearchField;
  98. };
  99. Q_DECLARE_METATYPE(GameListOpenTarget);
  100. class GameListPlaceholder : public QWidget {
  101. Q_OBJECT
  102. public:
  103. explicit GameListPlaceholder(GMainWindow* parent = nullptr);
  104. ~GameListPlaceholder();
  105. signals:
  106. void AddDirectory();
  107. private slots:
  108. void onUpdateThemedIcons();
  109. protected:
  110. void mouseDoubleClickEvent(QMouseEvent* event) override;
  111. private:
  112. QVBoxLayout* layout = nullptr;
  113. QLabel* image = nullptr;
  114. QLabel* text = nullptr;
  115. };