]> git.sven.stormbind.net Git - sven/vym.git/blob - src/confluence-agent.h
New upstream version 2.9.22
[sven/vym.git] / src / confluence-agent.h
1 #ifndef CONFLUENCEAGENT_H
2 #define CONFLUENCEAGENT_H
3
4 #include <QHash>
5 #include <QJsonObject>
6 #include <QNetworkAccessManager>
7 #include <QObject>
8 #include <QTimer>
9
10 #include "confluence-user.h"
11
12 class BranchItem;
13 class VymModel;
14
15 //////////////////////////////////////////////////////////////////////////
16
17 class ConfluenceAgent : public QObject {
18     Q_OBJECT
19
20   public:
21     enum JobType {
22         Undefined,
23         CopyPagenameToHeading,
24         CreatePage,
25         UpdatePage,
26         UploadAttachments,
27         GetUserInfo
28     };
29
30     static bool available();
31
32     ConfluenceAgent();
33     ConfluenceAgent(BranchItem *bi);
34     ~ConfluenceAgent();
35     void init();
36     void setJobType(JobType jt);
37     void setBranch(BranchItem *bi);
38     void setModelID(uint id);
39     void setPageURL(const QString &u);
40     void setNewPageName(const QString &t);
41     void setUploadPagePath(const QString &fp);
42     void addUploadAttachmentPath(const QString &fp);
43
44     void startJob();
45
46   private:
47     void continueJob(int nextStep = -1);
48     void finishJob();
49     void unknownStepWarningFinishJob();
50
51   signals:
52     void foundUsers(QList <ConfluenceUser>);
53
54   public:
55     void getUsers(const QString &name); //! Convenience function to get user data
56
57   private: QNetworkRequest createRequest(const QUrl &url);
58   private: void startGetPageSourceRequest(QUrl requestedUrl);
59   private slots: void pageSourceReceived(QNetworkReply *reply);
60
61   private: void startGetPageDetailsRequest();
62   private slots: void pageDetailsReceived(QNetworkReply *reply);
63
64   private: void startCreatePageRequest();
65   private: void startUpdatePageRequest();
66   private slots: void pageUploaded(QNetworkReply *reply);
67
68
69   private: void startGetUserInfoRequest();
70   private slots: void userInfoReceived(QNetworkReply *reply);
71
72   private: void startGetAttachmentsInfoRequest();
73   private slots: void attachmentsInfoReceived(QNetworkReply *reply);
74
75   private: void startCreateAttachmentRequest();
76   private slots: void attachmentCreated(QNetworkReply *reply);
77
78   private: void startUpdateAttachmentRequest();
79   private slots: void attachmentUpdated(QNetworkReply *reply);
80
81   signals:
82     void attachmentsSuccess();
83     void attachmentsFailure();
84
85   public slots:
86     void attachmentsUploadSuccess();
87     void attachmentsUploadFailure();
88
89   private: bool wasRequestSuccessful(
90             QNetworkReply *reply, 
91             const QString &requestDesc,
92             const QByteArray &fullReply);
93
94
95   private slots: void timeout();
96
97 #ifndef QT_NO_SSL
98     void sslErrors(QNetworkReply *, const QList<QSslError> &errors);
99 #endif
100
101   private:
102     // Job related 
103     QTimer *killTimer;
104     JobType jobType;
105     int jobStep;
106     bool abortJob;  // Flag to abort during initialization of job
107
108     // Network handling
109     QNetworkAccessManager *networkManager;
110     QJsonObject pageObj;
111     QJsonObject attachmentObj;
112
113     // Settings: Credentials to access Confluence
114     bool authUsingPAT;
115     QString personalAccessToken;
116     QString username;
117     QString password;
118
119     // Settings: Where to find Confluggence
120     QString baseURL;
121     QString apiURL;
122
123     // Backreferences to take action in calling model
124     uint branchID;
125     uint modelID;
126
127   private:
128     // Parameters
129     QString pageURL;
130     QString newPageName;
131     QString uploadPagePath;
132     QString userQuery;
133
134     // Page details received from Confluence
135     QString pageID;
136     QString spaceKey;
137
138     // Child agent for attachments
139     ConfluenceAgent *attachmentsAgent;
140
141     // Attachments found in page
142     QStringList attachmentsTitles;
143     QStringList attachmentsIds;
144
145     // Current attachments queued for upload
146     QStringList uploadAttachmentPaths;
147     int currentUploadAttachmentIndex;
148     QString currentAttachmentPath;      // set with basename(..) from path
149     QString currentAttachmentTitle;      // set with basename(..) from path
150     QString currentAttachmentId;         // copied from attachmentsIds
151
152     // User info received from Confluence
153     QList <ConfluenceUser> userList;
154 };
155 #endif