githandler.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #ifndef GITHANDLER_H
  2. #define GITHANDLER_H
  3. #include <QObject>
  4. #include <repositorymodel.h>
  5. class CommitModel;
  6. class CommitGraph;
  7. class BranchListModel;
  8. class TagListModel;
  9. class QFileSystemWatcher;
  10. class GitConsole;
  11. typedef QHash<QString, QPointer<CommitModel>> CommitModelContainer;
  12. class GitHandler : public QObject
  13. {
  14. Q_OBJECT
  15. Q_PROPERTY(RepositoryModel* repositories READ repositories NOTIFY repositoriesChanged)
  16. Q_PROPERTY(CommitGraph* graph READ graph NOTIFY graphChanged)
  17. Q_PROPERTY(GitRepository* activeRepo READ activeRepo CONSTANT)
  18. Q_PROPERTY(GitDiff* activeDiff READ activeDiff WRITE setActiveDiff NOTIFY activeDiffChanged)
  19. Q_PROPERTY(CommitModel* commits READ commits WRITE setCommits NOTIFY commitsChanged)
  20. Q_PROPERTY(BranchListModel* branchList READ branchList CONSTANT)
  21. Q_PROPERTY(TagListModel* tagList READ tagList CONSTANT)
  22. Q_PROPERTY(GitConsole* console READ console CONSTANT)
  23. public:
  24. GitHandler();
  25. virtual ~GitHandler();
  26. Q_INVOKABLE void open(const QString &path);
  27. Q_INVOKABLE void open(const QUrl &url);
  28. Q_INVOKABLE GitDiff* diff(GitCommit* a, GitCommit* b);
  29. Q_INVOKABLE void copySha1(const QString& sha1);
  30. RepositoryModel* repositories() const
  31. {
  32. return m_repositories;
  33. }
  34. CommitGraph* graph() const
  35. {
  36. return m_graph;
  37. }
  38. GitRepository* activeRepo() const
  39. {
  40. return m_activeRepo;
  41. }
  42. GitDiff* activeDiff() const;
  43. CommitModel* commits() const
  44. {
  45. return m_commits;
  46. }
  47. void pull() const;
  48. BranchListModel* branchList() const
  49. {
  50. return m_branchList;
  51. }
  52. TagListModel* tagList() const
  53. {
  54. return m_tagList;
  55. }
  56. GitConsole* console() const
  57. {
  58. return m_console;
  59. }
  60. public slots:
  61. void setActiveDiff(GitDiff* activeDiff);
  62. void setCommits(CommitModel* commits)
  63. {
  64. if (m_commits == commits)
  65. return;
  66. m_commits = commits;
  67. emit commitsChanged(commits);
  68. }
  69. signals:
  70. void repositoriesChanged(RepositoryModel* repositories);
  71. void graphChanged(CommitGraph* graph);
  72. void activeDiffChanged(GitDiff* activeDiff);
  73. void commitsChanged(CommitModel* commits);
  74. protected:
  75. QString lastError() const;
  76. private:
  77. void updateModels();
  78. RepositoryModel* m_repositories;
  79. CommitModel* m_commits;
  80. CommitGraph* m_graph;
  81. GitRepository* m_activeRepo;
  82. QPointer<GitDiff> m_activeDiff;
  83. BranchListModel* m_branchList;
  84. TagListModel* m_tagList;
  85. QFileSystemWatcher* m_activeRepoWatcher;
  86. GitConsole* m_console;
  87. GitOid m_constantHead;
  88. };
  89. #endif // GITHANDLER_H