X-Git-Url: https://git.sven.stormbind.net/?a=blobdiff_plain;f=src%2Fconfluence-agent.h;fp=src%2Fconfluence-agent.h;h=ed9cee3cdd5a922ad3890374d0fbe8b5c75f543c;hb=d483bd8e6523c23c6f1d8908a2e0611c2bc9ff4f;hp=0000000000000000000000000000000000000000;hpb=7dfa3fe589d1722d49681f42cdb0bf1e6efb5223;p=sven%2Fvym.git diff --git a/src/confluence-agent.h b/src/confluence-agent.h new file mode 100644 index 0000000..ed9cee3 --- /dev/null +++ b/src/confluence-agent.h @@ -0,0 +1,155 @@ +#ifndef CONFLUENCEAGENT_H +#define CONFLUENCEAGENT_H + +#include +#include +#include +#include +#include + +#include "confluence-user.h" + +class BranchItem; +class VymModel; + +////////////////////////////////////////////////////////////////////////// + +class ConfluenceAgent : public QObject { + Q_OBJECT + + public: + enum JobType { + Undefined, + CopyPagenameToHeading, + CreatePage, + UpdatePage, + UploadAttachments, + GetUserInfo + }; + + static bool available(); + + ConfluenceAgent(); + ConfluenceAgent(BranchItem *bi); + ~ConfluenceAgent(); + void init(); + void setJobType(JobType jt); + void setBranch(BranchItem *bi); + void setModelID(uint id); + void setPageURL(const QString &u); + void setNewPageName(const QString &t); + void setUploadPagePath(const QString &fp); + void addUploadAttachmentPath(const QString &fp); + + void startJob(); + + private: + void continueJob(int nextStep = -1); + void finishJob(); + void unknownStepWarningFinishJob(); + + signals: + void foundUsers(QList ); + + public: + void getUsers(const QString &name); //! Convenience function to get user data + + private: QNetworkRequest createRequest(const QUrl &url); + private: void startGetPageSourceRequest(QUrl requestedUrl); + private slots: void pageSourceReceived(QNetworkReply *reply); + + private: void startGetPageDetailsRequest(); + private slots: void pageDetailsReceived(QNetworkReply *reply); + + private: void startCreatePageRequest(); + private: void startUpdatePageRequest(); + private slots: void pageUploaded(QNetworkReply *reply); + + + private: void startGetUserInfoRequest(); + private slots: void userInfoReceived(QNetworkReply *reply); + + private: void startGetAttachmentsInfoRequest(); + private slots: void attachmentsInfoReceived(QNetworkReply *reply); + + private: void startCreateAttachmentRequest(); + private slots: void attachmentCreated(QNetworkReply *reply); + + private: void startUpdateAttachmentRequest(); + private slots: void attachmentUpdated(QNetworkReply *reply); + + signals: + void attachmentsSuccess(); + void attachmentsFailure(); + + public slots: + void attachmentsUploadSuccess(); + void attachmentsUploadFailure(); + + private: bool wasRequestSuccessful( + QNetworkReply *reply, + const QString &requestDesc, + const QByteArray &fullReply); + + + private slots: void timeout(); + +#ifndef QT_NO_SSL + void sslErrors(QNetworkReply *, const QList &errors); +#endif + + private: + // Job related + QTimer *killTimer; + JobType jobType; + int jobStep; + bool abortJob; // Flag to abort during initialization of job + + // Network handling + QNetworkAccessManager *networkManager; + QJsonObject pageObj; + QJsonObject attachmentObj; + + // Settings: Credentials to access Confluence + bool authUsingPAT; + QString personalAccessToken; + QString username; + QString password; + + // Settings: Where to find Confluggence + QString baseURL; + QString apiURL; + + // Backreferences to take action in calling model + uint branchID; + uint modelID; + + private: + // Parameters + QString pageURL; + QString newPageName; + QString uploadPagePath; + QString userQuery; + + // Page details received from Confluence + QString pageID; + QString spaceKey; + + // Child agent for attachments + ConfluenceAgent *attachmentsAgent; + + // Attachments found in page + QStringList attachmentsTitles; + QStringList attachmentsIds; + + // Current attachments queued for upload + QStringList uploadAttachmentPaths; + int currentUploadAttachmentIndex; + QString currentAttachmentPath; // set with basename(..) from path + QString currentAttachmentTitle; // set with basename(..) from path + QString currentAttachmentId; // copied from attachmentsIds + + // User info received from Confluence + QList userList; +}; +#endif