File indexing completed on 2024-04-21 16:12:15

0001 /*******************************************************************
0002  * bugzillalib.h
0003  * SPDX-FileCopyrightText: 2009, 2011 Dario Andres Rodriguez <andresbajotierra@gmail.com>
0004  * SPDX-FileCopyrightText: 2012 George Kiagiadakis <kiagiadakis.george@gmail.com>
0005  * SPDX-FileCopyrightText: 2019-2022 Harald Sitter <sitter@kde.org>
0006  *
0007  * SPDX-License-Identifier: GPL-2.0-or-later
0008  *
0009  ******************************************************************/
0010 
0011 #ifndef BUGZILLALIB__H
0012 #define BUGZILLALIB__H
0013 
0014 #include <QObject>
0015 #include <QString>
0016 
0017 #include "libbugzilla/clients/attachmentclient.h"
0018 #include "libbugzilla/clients/bugclient.h"
0019 #include "libbugzilla/clients/productclient.h"
0020 
0021 #include "../drkonqi_globals.h"
0022 
0023 namespace KIO
0024 {
0025 class KJob;
0026 }
0027 
0028 class BugzillaManager : public QObject
0029 {
0030     Q_OBJECT
0031 
0032 public:
0033     // Note: it expect the bugTrackerUrl parameter to contain the trailing slash.
0034     // so it should be "https://bugs.kde.org/", not "https://bugs.kde.org"
0035     explicit BugzillaManager(const QString &bugTrackerUrl = QString(), QObject *parent = nullptr);
0036 
0037     /* Login methods */
0038     Q_SCRIPTABLE void tryLogin(const QString &username, const QString &password);
0039     Q_INVOKABLE void refreshToken();
0040     bool getLogged() const;
0041 
0042     QString getUsername() const;
0043 
0044     /* Bugzilla Action methods */
0045     void fetchBugReport(int, QObject *jobOwner = nullptr);
0046     Q_INVOKABLE void searchBugs(const QStringList &products, const QString &severity, const QString &comment, int offset);
0047     void sendReport(const Bugzilla::NewBug &bug);
0048     void attachTextToReport(const QString &text, const QString &filename, const QString &description, int bugId, const QString &comment);
0049     void addMeToCC(int bugId);
0050     void fetchProductInfo(const QString &);
0051 
0052     /* Misc methods */
0053     QString urlForBug(int bug_number) const;
0054     void stopCurrentSearch();
0055 
0056     void fetchComments(const Bugzilla::Bug::Ptr &bug, QObject *jobOwner);
0057     Q_SCRIPTABLE void lookupVersion();
0058 
0059 Q_SIGNALS:
0060     /* Bugzilla actions finished successfully */
0061     void loginFinished(bool logged);
0062     void bugReportFetched(Bugzilla::Bug::Ptr bug, QObject *jobOwner);
0063     void commentsFetched(QList<Bugzilla::Comment::Ptr> comments, QObject *jobOwner);
0064     void searchFinished(const QList<Bugzilla::Bug::Ptr> &bug);
0065     void reportSent(int bugId);
0066     void attachToReportSent(int bugId);
0067     void addMeToCCFinished(int bugId);
0068     void productInfoFetched(const Bugzilla::Product::Ptr &product);
0069     void bugzillaVersionFound();
0070 
0071     /* Bugzilla actions had errors */
0072     void loginError(const QString &errorMsg);
0073     void bugReportError(const QString &errorMsg, QObject *jobOwner);
0074     void commentsError(const QString &errorMsg, QObject *jobOwner);
0075     void searchError(const QString &errorMsg);
0076     void sendReportError(const QString &errorMsg);
0077     void sendReportErrorInvalidValues(); // To use default values
0078     void attachToReportError(const QString &errorMsg);
0079     void addMeToCCError(const QString &errorMsg);
0080     void productInfoError();
0081     void bugzillaVersionError(const QString &errorMsg);
0082 
0083 private:
0084     QString m_bugTrackerUrl;
0085     QString m_username;
0086     QString m_token;
0087     QString m_password;
0088     bool m_logged = false;
0089 
0090     KJob *m_searchJob = nullptr;
0091 
0092     void setFeaturesForVersion(const QString &version);
0093 };
0094 
0095 #endif