game_list.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 <QModelIndex>
  10. #include <QSettings>
  11. #include <QStandardItem>
  12. #include <QStandardItemModel>
  13. #include <QString>
  14. #include <QToolButton>
  15. #include <QTreeView>
  16. #include <QVBoxLayout>
  17. #include <QWidget>
  18. #include "common/common_types.h"
  19. #include "yuzu/compatibility_list.h"
  20. class GameListWorker;
  21. class GMainWindow;
  22. namespace FileSys {
  23. class VfsFilesystem;
  24. }
  25. enum class GameListOpenTarget {
  26. SaveData,
  27. ModData,
  28. };
  29. class GameList : public QWidget {
  30. Q_OBJECT
  31. public:
  32. enum {
  33. COLUMN_NAME,
  34. COLUMN_COMPATIBILITY,
  35. COLUMN_ADD_ONS,
  36. COLUMN_FILE_TYPE,
  37. COLUMN_SIZE,
  38. COLUMN_COUNT, // Number of columns
  39. };
  40. class SearchField : public QWidget {
  41. public:
  42. void setFilterResult(int visible, int total);
  43. void clear();
  44. void setFocus();
  45. explicit SearchField(GameList* parent = nullptr);
  46. private:
  47. class KeyReleaseEater : public QObject {
  48. public:
  49. explicit KeyReleaseEater(GameList* gamelist);
  50. private:
  51. GameList* gamelist = nullptr;
  52. QString edit_filter_text_old;
  53. protected:
  54. bool eventFilter(QObject* obj, QEvent* event) override;
  55. };
  56. QHBoxLayout* layout_filter = nullptr;
  57. QTreeView* tree_view = nullptr;
  58. QLabel* label_filter = nullptr;
  59. QLineEdit* edit_filter = nullptr;
  60. QLabel* label_filter_result = nullptr;
  61. QToolButton* button_filter_close = nullptr;
  62. };
  63. explicit GameList(std::shared_ptr<FileSys::VfsFilesystem> vfs, GMainWindow* parent = nullptr);
  64. ~GameList() override;
  65. void clearFilter();
  66. void setFilterFocus();
  67. void setFilterVisible(bool visibility);
  68. void LoadCompatibilityList();
  69. void PopulateAsync(const QString& dir_path, bool deep_scan);
  70. void SaveInterfaceLayout();
  71. void LoadInterfaceLayout();
  72. static const QStringList supported_file_extensions;
  73. signals:
  74. void GameChosen(QString game_path);
  75. void ShouldCancelWorker();
  76. void OpenFolderRequested(u64 program_id, GameListOpenTarget target);
  77. void DumpRomFSRequested(u64 program_id, const std::string& game_path);
  78. void CopyTIDRequested(u64 program_id);
  79. void NavigateToGamedbEntryRequested(u64 program_id,
  80. const CompatibilityList& compatibility_list);
  81. private slots:
  82. void onTextChanged(const QString& newText);
  83. void onFilterCloseClicked();
  84. private:
  85. void AddEntry(const QList<QStandardItem*>& entry_items);
  86. void ValidateEntry(const QModelIndex& item);
  87. void DonePopulating(QStringList watch_list);
  88. void PopupContextMenu(const QPoint& menu_location);
  89. void RefreshGameDirectory();
  90. std::shared_ptr<FileSys::VfsFilesystem> vfs;
  91. SearchField* search_field;
  92. GMainWindow* main_window = nullptr;
  93. QVBoxLayout* layout = nullptr;
  94. QTreeView* tree_view = nullptr;
  95. QStandardItemModel* item_model = nullptr;
  96. GameListWorker* current_worker = nullptr;
  97. QFileSystemWatcher* watcher = nullptr;
  98. CompatibilityList compatibility_list;
  99. };
  100. Q_DECLARE_METATYPE(GameListOpenTarget);