githandler.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 GitDiff* diff(); //Dif of workdir
  30. Q_INVOKABLE void copy(const QString& sha1);
  31. RepositoryModel* repositories() const
  32. {
  33. return m_repositories;
  34. }
  35. CommitGraph* graph() const
  36. {
  37. return m_graph;
  38. }
  39. GitRepository* activeRepo() const
  40. {
  41. return m_activeRepo;
  42. }
  43. GitDiff* activeDiff() const;
  44. CommitModel* commits() const
  45. {
  46. return m_commits;
  47. }
  48. void pull() const;
  49. BranchListModel* branchList() const
  50. {
  51. return m_branchList;
  52. }
  53. TagListModel* tagList() const
  54. {
  55. return m_tagList;
  56. }
  57. GitConsole* console() const
  58. {
  59. return m_console;
  60. }
  61. public slots:
  62. void setActiveDiff(GitDiff* activeDiff);
  63. void setCommits(CommitModel* commits)
  64. {
  65. if (m_commits == commits)
  66. return;
  67. m_commits = commits;
  68. emit commitsChanged(commits);
  69. }
  70. signals:
  71. void repositoriesChanged(RepositoryModel* repositories);
  72. void graphChanged(CommitGraph* graph);
  73. void activeDiffChanged(GitDiff* activeDiff);
  74. void commitsChanged(CommitModel* commits);
  75. protected:
  76. QString lastError() const;
  77. private:
  78. void updateModels();
  79. RepositoryModel* m_repositories;
  80. CommitModel* m_commits;
  81. CommitGraph* m_graph;
  82. GitRepository* m_activeRepo;
  83. QPointer<GitDiff> m_activeDiff;
  84. BranchListModel* m_branchList;
  85. TagListModel* m_tagList;
  86. QFileSystemWatcher* m_activeRepoWatcher;
  87. GitConsole* m_console;
  88. GitOid m_constantHead;
  89. };
  90. #endif // GITHANDLER_H