provider.h 4.69 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/*
    Copyright (C) 2016 Volker Krause <vkrause@kde.org>

    This program is free software; you can redistribute it and/or modify it
    under the terms of the GNU Library General Public License as published by
    the Free Software Foundation; either version 2 of the License, or (at your
    option) any later version.

    This program is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
    License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef USERFEEDBACK_PROVIDER_H
#define USERFEEDBACK_PROVIDER_H

#include "userfeedbackcore_export.h"

#include <QObject>
#include <QUrl>


namespace UserFeedback {

29
class AbstractDataSource;
30
class ProviderPrivate;
31
class SurveyInfo;
32
33
34
35
36

/** The central object managing data sources and transmitting feedback to the server. */
class USERFEEDBACKCORE_EXPORT Provider : public QObject
{
    Q_OBJECT
37
38
    Q_PROPERTY(int surveyInterval READ surveyInterval WRITE setSurveyInterval NOTIFY surveyIntervalChanged)
    Q_PROPERTY(StatisticsCollectionMode statisticsCollectionMode READ statisticsCollectionMode WRITE setStatisticsCollectionMode NOTIFY statisticsCollectionModeChanged)
39
public:
40
41
42
    enum StatisticsCollectionMode {
        NoStatistics,
        BasicStatistics,
Volker Krause's avatar
Volker Krause committed
43
44
        AllStatistics,
        CollectionModeCount = AllStatistics
45
    };
Volker Krause's avatar
Volker Krause committed
46
    Q_ENUMS(StatisticsCollectionMode)
47

48
    explicit Provider(QObject *parent = Q_NULLPTR);
49
    ~Provider();
50
51
52
53
54
55
56
57
58

    /** Set the product identifier.
     *  This is used to distinguish independent products on the same server.
     */
    void setProductIdentifier(const QString &productId);

    /** Set the feedback server URL. */
    void setFeedbackServer(const QUrl &url);

Volker Krause's avatar
Volker Krause committed
59
60
61
    /** Set the automatic submission interval. */
    void setSubmissionInterval(int days);

62
63
64
65
66
67
    /** Returns the current statistics collection mode. */
    StatisticsCollectionMode statisticsCollectionMode() const;

    /** Set which statistics should be submitted. */
    void setStatisticsCollectionMode(StatisticsCollectionMode mode);

68
    /** Adds a data source for statistical data collection.
Volker Krause's avatar
Volker Krause committed
69
     *  @param source The data source to add. The Provider takes ownership of @p source.
70
71
72
73
74
75
     *  @param mode The statistics collection mode this source belongs to. Data is only
     *  send to the server for this source is a sufficiently high collection mode is configured
     *  by the user. @c NoStatistics is not allowed.
     */
    void addDataSource(AbstractDataSource *source, StatisticsCollectionMode mode);

Volker Krause's avatar
Volker Krause committed
76
77
78
79
80
    /** Returns all data sources that have been added to this provider.
     *  @see addDataSource
     */
    QVector<AbstractDataSource*> dataSources() const;

81
82
83
84
85
86
87
88
    /** Returns the minimum time between two surveys in days. */
    int surveyInterval() const;

    /** Sets the minimum time in days between two surveys.
     *  @c -1 indicates no surveys should be requested.
     */
    void setSurveyInterval(int days);

89
90
91
92
93
    /** Marks the given survey as completed. This avoids getting further notification
     *  about the same survey.
     */
    void setSurveyCompleted(const SurveyInfo &info);

94
95
96
97
98
99
100
101
102
    /** Set the amount of application starts until the encouragement message should be shown. */
    void setApplicationStartsUntilEncouragement(int starts);

    /** Set the amount of usage time until the encouragement message should be shown. */
    void setApplicationUsageTimeUntilEncouragement(int minutes);

    /** Set the delay after application start for the earliest display of the encouragement message. */
    void setEncouragementDelay(int secs);

103
104
105
106
public slots:
    /** Manually submit currently recorded data. */
    void submit();

107
108
109
110
signals:
    /** Emitted whenever there is a new survey available that can be presented
     *  to the user.
     */
111
    void surveyAvailable(const UserFeedback::SurveyInfo &survey);
112

113
114
115
    /** Indicate that the encouragement notice should be shown. */
    void showEncouragementMessage();

116
117
118
119
120
121
    /** Emitted when the survey interval changed. */
    void surveyIntervalChanged();

    /** Emitted when the statistics collection mode has changed. */
    void statisticsCollectionModeChanged();

122
123
124
private:
    friend class ProviderPrivate;
    ProviderPrivate * const d;
125
126
    Q_PRIVATE_SLOT(d, void aboutToQuit())
    Q_PRIVATE_SLOT(d, void submitFinished())
127
    Q_PRIVATE_SLOT(d, void emitShowEncouragementMessage())
Volker Krause's avatar
Volker Krause committed
128
129
    // for UI
    Q_PRIVATE_SLOT(d, QByteArray jsonData())
130
131
132
    // for testing
    Q_PRIVATE_SLOT(d, void load())
    Q_PRIVATE_SLOT(d, void store())
133
134
135
136
137
};

}

#endif // USERFEEDBACK_PROVIDER_H