game_list.h 2.7 KB

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