game_list.h 3.0 KB

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