File indexing completed on 2024-12-15 03:45:03

0001 /*
0002     SPDX-FileCopyrightText: 2017 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: MIT
0005 */
0006 
0007 #ifndef KUSERFEEDBACK_FEEDBACKCONFIGUICONTROLLER_H
0008 #define KUSERFEEDBACK_FEEDBACKCONFIGUICONTROLLER_H
0009 
0010 #include "kuserfeedbackcore_export.h"
0011 #include "provider.h"
0012 
0013 #include <QObject>
0014 
0015 #include <memory>
0016 
0017 namespace KUserFeedback {
0018 
0019 class FeedbackConfigUiControllerPrivate;
0020 class Provider;
0021 
0022 /*! Logic/behavior of the feedback configuration UI.
0023  *  This is available for use in e.g. QtQuick-based UIs.
0024  *  @see FeedbackConfigWidget
0025  */
0026 class KUSERFEEDBACKCORE_EXPORT FeedbackConfigUiController : public QObject
0027 {
0028     Q_OBJECT
0029     /*! The Provider instance we are configuring. */
0030     Q_PROPERTY(KUserFeedback::Provider* feedbackProvider READ feedbackProvider WRITE setFeedbackProvider NOTIFY providerChanged)
0031     /*! Amount of telemetry modes supported by the provider. */
0032     Q_PROPERTY(int telemetryModeCount READ telemetryModeCount NOTIFY providerChanged)
0033     /*! Amount of supported survey modes. */
0034     Q_PROPERTY(int surveyModeCount READ surveyModeCount CONSTANT)
0035     /*! Name of the application that will appear on descriptions. By default it will use QGuiApplication::applicationDisplayName() */
0036     Q_PROPERTY(QString applicationName READ applicationName WRITE setApplicationName NOTIFY applicationNameChanged)
0037 public:
0038     explicit FeedbackConfigUiController(QObject *parent = nullptr);
0039     ~FeedbackConfigUiController() override;
0040 
0041     /*! Returns the feedback provider to be configured. */
0042     Provider* feedbackProvider() const;
0043     /*! Set the feedback provider to configure. */
0044     void setFeedbackProvider(Provider *provider);
0045 
0046     /*! Amount of supported telemetry modes.
0047      *  This depends on what type of sources the provider actually has.
0048      */
0049     int telemetryModeCount() const;
0050     /*! Amount of supported survey modes. */
0051     int surveyModeCount() const;
0052 
0053     QString applicationName() const;
0054     void setApplicationName(const QString& appName);
0055 
0056     /*! Convert slider index to telemetry mode. */
0057     Q_INVOKABLE KUserFeedback::Provider::TelemetryMode telemetryIndexToMode(int index) const;
0058     /*! Convert telemetry mode to slider index. */
0059     Q_INVOKABLE int telemetryModeToIndex(KUserFeedback::Provider::TelemetryMode mode) const;
0060 
0061     /*! Telemetry mode short name. */
0062     Q_INVOKABLE QString telemetryModeName(int telemetryIndex) const;
0063     /*! Telemetry mode explanation text. */
0064     Q_INVOKABLE QString telemetryModeDescription(int telemetryIndex) const;
0065     /*! Detailed information about the data sources of the given telemetry mode index. */
0066     Q_INVOKABLE QString telemetryModeDetails(int telemetryIndex) const;
0067 
0068     /*! Telemetry mode short name. */
0069     Q_INVOKABLE QString telemetryName(KUserFeedback::Provider::TelemetryMode mode) const;
0070     /*! Telemetry mode explanation text. */
0071     Q_INVOKABLE QString telemetryDescription(KUserFeedback::Provider::TelemetryMode mode) const;
0072 
0073     /*! Convert slider index to survey interval. */
0074     Q_INVOKABLE int surveyIndexToInterval(int index) const;
0075     /*! Convert survey interval to slider index. */
0076     Q_INVOKABLE int surveyIntervalToIndex(int interval) const;
0077 
0078     /*! Survey mode explanation text. */
0079     Q_INVOKABLE QString surveyModeDescription(int surveyIndex) const;
0080 
0081 Q_SIGNALS:
0082     /*! A provider-related setting has changed. */
0083     void providerChanged();
0084     void applicationNameChanged(const QString &applicationName);
0085 
0086 private:
0087     std::unique_ptr<FeedbackConfigUiControllerPrivate> d;
0088 };
0089 
0090 }
0091 
0092 #endif // KUSERFEEDBACK_FEEDBACKCONFIGUICONTROLLER_H