gitrepository.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #ifndef GITREPOSITORY_H
  2. #define GITREPOSITORY_H
  3. #include <QObject>
  4. #include <QString>
  5. #include <QMap>
  6. #include <QPointer>
  7. #include <gitoid.h>
  8. struct git_repository;
  9. class GitBranch;
  10. class GitTag;
  11. class GitDiff;
  12. class GitCommit;
  13. class GitRemote;
  14. struct git_oid;
  15. typedef QMap<QString, QPointer<GitBranch> > BranchContainer;
  16. typedef QMap<GitOid, QPointer<GitTag> > TagContainer;
  17. typedef QMap<QString, QPointer<GitRemote> > RemoteContainer;
  18. class GitRepository : public QObject
  19. {
  20. Q_OBJECT
  21. Q_PROPERTY(QString root READ root WRITE setRoot NOTIFY rootChanged)
  22. Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
  23. Q_PROPERTY(QString path READ path NOTIFY rootChanged)
  24. public:
  25. GitRepository(const QString &root);
  26. ~GitRepository();
  27. QString root() const {
  28. return m_root;
  29. }
  30. QString name() const {
  31. return m_name;
  32. }
  33. QString path() const {
  34. return m_path;
  35. }
  36. git_repository* raw() const {
  37. return m_raw;
  38. }
  39. bool isValid() const {
  40. return m_raw != nullptr;
  41. }
  42. BranchContainer& branches() {
  43. return m_branches;
  44. }
  45. TagContainer& tags() {
  46. return m_tags;
  47. }
  48. RemoteContainer& remotes() {
  49. return m_remotes;
  50. }
  51. public slots:
  52. void setRoot(QString root) {
  53. if (m_root == root)
  54. return;
  55. m_root = root;
  56. emit rootChanged(root);
  57. }
  58. void setName(QString name) {
  59. if (m_name == name)
  60. return;
  61. m_name = name;
  62. emit nameChanged(name);
  63. }
  64. signals:
  65. void rootChanged(QString root);
  66. void nameChanged(QString name);
  67. private:
  68. void close();
  69. void readBranches();
  70. void readTags();
  71. void readRemotes();
  72. QString m_root;
  73. QString m_name;
  74. QString m_path;
  75. git_repository* m_raw;
  76. BranchContainer m_branches;
  77. TagContainer m_tags;
  78. RemoteContainer m_remotes;
  79. };
  80. #endif // GITREPOSITORY_H