githandler.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #ifndef GITHANDLER_H
  2. #define GITHANDLER_H
  3. #include <QObject>
  4. #include <repositorymodel.h>
  5. class CommitModel;
  6. class CommitGraph;
  7. typedef QHash<QString, QPointer<CommitModel>> CommitModelContainer;
  8. class GitHandler : public QObject
  9. {
  10. Q_OBJECT
  11. Q_PROPERTY(RepositoryModel* repositories READ repositories NOTIFY repositoriesChanged)
  12. Q_PROPERTY(CommitGraph* graph READ graph WRITE setGraph NOTIFY graphChanged)
  13. Q_PROPERTY(GitRepository* activeRepo READ activeRepo CONSTANT)
  14. Q_PROPERTY(GitDiff* activeDiff READ activeDiff WRITE setActiveDiff NOTIFY activeDiffChanged)
  15. Q_PROPERTY(CommitModel* commits READ commits WRITE setCommits NOTIFY commitsChanged)
  16. public:
  17. GitHandler();
  18. virtual ~GitHandler();
  19. Q_INVOKABLE void open(const QString &path);
  20. Q_INVOKABLE void open(const QUrl &url);
  21. Q_INVOKABLE GitDiff* diff(GitCommit* a, GitCommit* b);
  22. RepositoryModel* repositories() const
  23. {
  24. return m_repositories;
  25. }
  26. CommitGraph* graph() const
  27. {
  28. return m_graph;
  29. }
  30. GitRepository* activeRepo() const
  31. {
  32. return m_activeRepo;
  33. }
  34. GitDiff* activeDiff() const;
  35. CommitModel* commits() const
  36. {
  37. return m_commits;
  38. }
  39. void pull() const;
  40. public slots:
  41. void setGraph(CommitGraph* graph)
  42. {
  43. if (m_graph == graph)
  44. return;
  45. m_graph = graph;
  46. emit graphChanged(graph);
  47. }
  48. void setActiveDiff(GitDiff* activeDiff);
  49. void setCommits(CommitModel* commits)
  50. {
  51. if (m_commits == commits)
  52. return;
  53. m_commits = commits;
  54. emit commitsChanged(commits);
  55. }
  56. signals:
  57. void repositoriesChanged(RepositoryModel* repositories);
  58. void graphChanged(CommitGraph* graph);
  59. void activeDiffChanged(GitDiff* activeDiff);
  60. void commitsChanged(CommitModel* commits);
  61. protected:
  62. QString lastError() const;
  63. private:
  64. RepositoryModel* m_repositories;
  65. CommitModel* m_commits;
  66. CommitGraph* m_graph;
  67. GitRepository* m_activeRepo;
  68. QPointer<GitDiff> m_activeDiff;
  69. };
  70. #endif // GITHANDLER_H