game_list.h 3.1 KB

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