aboutsummaryrefslogtreecommitdiffstats
path: root/src/ui
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/encouragementwidget.cpp101
-rw-r--r--src/ui/encouragementwidget.h69
-rw-r--r--src/ui/encouragementwidget.ui71
-rw-r--r--src/ui/outputpane.cpp121
-rw-r--r--src/ui/outputpane.h95
-rw-r--r--src/ui/usagestatisticpage.cpp93
-rw-r--r--src/ui/usagestatisticpage.h66
-rw-r--r--src/ui/usagestatisticwidget.cpp204
-rw-r--r--src/ui/usagestatisticwidget.h94
-rw-r--r--src/ui/usagestatisticwidget.ui161
10 files changed, 1075 insertions, 0 deletions
diff --git a/src/ui/encouragementwidget.cpp b/src/ui/encouragementwidget.cpp
new file mode 100644
index 0000000..457422e
--- /dev/null
+++ b/src/ui/encouragementwidget.cpp
@@ -0,0 +1,101 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of UsageStatistic plugin for Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+#include "encouragementwidget.h"
+#include "ui_encouragementwidget.h"
+
+#include "coreplugin/icore.h"
+
+#include <KUserFeedback/FeedbackConfigUiController>
+
+#include "usagestatisticconstants.h"
+
+namespace UsageStatistic {
+namespace Internal {
+
+using namespace KUserFeedback;
+
+EncouragementWidget::EncouragementWidget(QWidget *parent)
+ : QWidget(parent)
+ , ui(new Ui::EncouragementWidget)
+ , m_controller(std::make_unique<FeedbackConfigUiController>())
+{
+ ui->setupUi(this);
+
+ connect(this, &EncouragementWidget::providerChanged,
+ this, &EncouragementWidget::onProviderChanged);
+ connect(ui->pbOptions, &QPushButton::clicked,
+ this, &EncouragementWidget::showSettingsDialog);
+}
+
+std::shared_ptr<Provider> EncouragementWidget::provider() const
+{
+ return m_provider;
+}
+
+void EncouragementWidget::setProvider(std::shared_ptr<Provider> provider)
+{
+ m_provider = std::move(provider);
+
+ Q_EMIT providerChanged(m_provider);
+}
+
+void EncouragementWidget::showEvent(QShowEvent *event)
+{
+ updateMessage();
+ QWidget::showEvent(event);
+}
+
+void EncouragementWidget::showSettingsDialog()
+{
+ Core::ICore::showOptionsDialog(Constants::USAGE_STATISTIC_PAGE_ID, this);
+}
+
+void EncouragementWidget::updateMessage()
+{
+ if (m_provider) {
+ auto modeIndex = m_controller->telemetryModeToIndex(m_provider->telemetryMode());
+
+ auto description = m_controller->telemetryModeDescription(modeIndex);
+
+ auto modeName = m_controller->telemetryModeName(modeIndex);
+ description.prepend(tr("Telemetry mode: %1.\n").arg(modeName));
+
+ ui->lblMsg->setText(description);
+ }
+}
+
+void EncouragementWidget::onProviderChanged(const std::shared_ptr<Provider> &p)
+{
+ m_controller->setFeedbackProvider(p.get());
+
+ connect(m_provider.get(), &Provider::telemetryModeChanged,
+ this, &EncouragementWidget::updateMessage);
+ updateMessage();
+}
+
+EncouragementWidget::~EncouragementWidget() = default;
+
+} // namespace Internal
+} // namespace UsageStatistic
diff --git a/src/ui/encouragementwidget.h b/src/ui/encouragementwidget.h
new file mode 100644
index 0000000..6386a54
--- /dev/null
+++ b/src/ui/encouragementwidget.h
@@ -0,0 +1,69 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of UsageStatistic plugin for Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+#include <memory>
+
+#include <QWidget>
+
+namespace KUserFeedback {
+class Provider;
+class FeedbackConfigUiController;
+}
+
+namespace UsageStatistic {
+namespace Internal {
+
+namespace Ui { class EncouragementWidget; }
+
+//! Widget for displaying current telemetry level at the output pane
+class EncouragementWidget : public QWidget
+{
+ Q_OBJECT
+
+public:
+ explicit EncouragementWidget(QWidget *parent = nullptr);
+ ~EncouragementWidget() override;
+
+ std::shared_ptr<KUserFeedback::Provider> provider() const;
+ void setProvider(std::shared_ptr<KUserFeedback::Provider> provider);
+
+protected: // QWidget interface
+ void showEvent(QShowEvent *event) override;
+
+Q_SIGNALS:
+ void providerChanged(const std::shared_ptr<KUserFeedback::Provider> &);
+
+private Q_SLOTS:
+ void showSettingsDialog();
+ void updateMessage();
+ void onProviderChanged(const std::shared_ptr<KUserFeedback::Provider> &p);
+
+private:
+ QScopedPointer<Ui::EncouragementWidget> ui;
+ std::shared_ptr<KUserFeedback::Provider> m_provider;
+ std::unique_ptr<KUserFeedback::FeedbackConfigUiController> m_controller;
+};
+
+} // namespace Internal
+} // namespace UsageStatistic
diff --git a/src/ui/encouragementwidget.ui b/src/ui/encouragementwidget.ui
new file mode 100644
index 0000000..19f24a1
--- /dev/null
+++ b/src/ui/encouragementwidget.ui
@@ -0,0 +1,71 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>UsageStatistic::Internal::EncouragementWidget</class>
+ <widget class="QWidget" name="UsageStatistic::Internal::EncouragementWidget">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>572</width>
+ <height>70</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Form</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <widget class="QLabel" name="lblMsg">
+ <property name="text">
+ <string>Message here...</string>
+ </property>
+ <property name="wordWrap">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <widget class="QPushButton" name="pbOptions">
+ <property name="text">
+ <string>&amp;Adjust telemetry settings</string>
+ </property>
+ <property name="default">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <spacer name="verticalSpacer">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>40</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/src/ui/outputpane.cpp b/src/ui/outputpane.cpp
new file mode 100644
index 0000000..3529ca3
--- /dev/null
+++ b/src/ui/outputpane.cpp
@@ -0,0 +1,121 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of UsageStatistic plugin for Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+#include "outputpane.h"
+
+#include <QtWidgets/QPushButton>
+#include <QtWidgets/QHBoxLayout>
+#include <QtCore/QDebug>
+
+#include "encouragementwidget.h"
+
+namespace UsageStatistic {
+namespace Internal {
+
+OutputPane::OutputPane() = default;
+
+OutputPane::~OutputPane() = default;
+
+QWidget *OutputPane::outputWidget(QWidget *parent)
+{
+ if (!m_outputPaneWidget) {
+ createEncouragementWidget(parent);
+ }
+
+ return m_outputPaneWidget;
+}
+
+QList<QWidget *> OutputPane::toolBarWidgets() const
+{
+ return {};
+}
+
+QString OutputPane::displayName() const
+{
+ return tr("Feedback");
+}
+
+int OutputPane::priorityInStatusBar() const
+{
+ return 1;
+}
+
+void OutputPane::clearContents() {}
+
+void OutputPane::visibilityChanged(bool /*visible*/)
+{
+}
+
+void OutputPane::setFocus() {}
+
+bool OutputPane::hasFocus() const
+{
+ return false;
+}
+
+bool OutputPane::canFocus() const
+{
+ return true;
+}
+
+bool OutputPane::canNavigate() const
+{
+ return false;
+}
+
+bool OutputPane::canNext() const
+{
+ return false;
+}
+
+bool OutputPane::canPrevious() const
+{
+ return false;
+}
+
+void OutputPane::goToNext() {}
+
+void OutputPane::goToPrev() {}
+
+void OutputPane::createEncouragementWidget(QWidget *parent)
+{
+ auto wgt = new EncouragementWidget(parent);
+ connect(this, &OutputPane::providerChanged, wgt, &EncouragementWidget::setProvider);
+
+ m_outputPaneWidget = wgt;
+}
+
+std::shared_ptr<KUserFeedback::Provider> OutputPane::provider() const
+{
+ return m_provider;
+}
+
+void OutputPane::setProvider(std::shared_ptr<KUserFeedback::Provider> provider)
+{
+ m_provider = std::move(provider);
+ Q_EMIT providerChanged(m_provider);
+}
+
+} // namespace Internal
+} // namespace UsageStatistic
diff --git a/src/ui/outputpane.h b/src/ui/outputpane.h
new file mode 100644
index 0000000..039b3f2
--- /dev/null
+++ b/src/ui/outputpane.h
@@ -0,0 +1,95 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of UsageStatistic plugin for Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+#pragma once
+
+#include <memory>
+
+#include <QtCore/QPointer>
+#include <QtWidgets/QWidget>
+
+#include <coreplugin/ioutputpane.h>
+
+QT_BEGIN_NAMESPACE
+class QHBoxLayout;
+QT_END_NAMESPACE
+
+namespace KUserFeedback { class Provider; }
+
+namespace UsageStatistic {
+namespace Internal {
+
+class EncouragementWidget;
+
+//! Output pane for displayed different different information (telemetry level, surveys, etc.)
+class OutputPane : public Core::IOutputPane
+{
+ Q_OBJECT
+
+public:
+ OutputPane();
+ ~OutputPane() override;
+
+public: // IOutputPane interface
+ QWidget *outputWidget(QWidget *parent) override;
+
+ QList<QWidget *> toolBarWidgets() const override;
+
+ QString displayName() const override;
+
+ int priorityInStatusBar() const override;
+
+ void clearContents() override;
+
+ void visibilityChanged(bool visible) override;
+
+ void setFocus() override;
+ bool hasFocus() const override;
+
+ bool canFocus() const override;
+ bool canNavigate() const override;
+ bool canNext() const override;
+ bool canPrevious() const override;
+
+ void goToNext() override;
+ void goToPrev() override;
+
+ std::shared_ptr<KUserFeedback::Provider> provider() const;
+ void setProvider(std::shared_ptr<KUserFeedback::Provider> provider);
+
+Q_SIGNALS:
+ void providerChanged(std::shared_ptr<KUserFeedback::Provider>);
+
+private: // Methods
+ void createEncouragementWidget(QWidget *parent);
+
+private: // Data
+ std::shared_ptr<KUserFeedback::Provider> m_provider;
+ QPointer<QWidget> m_outputPaneWidget;
+};
+
+} // namespace Internal
+} // namespace UsageStatistic
+
+Q_DECLARE_METATYPE(std::shared_ptr<KUserFeedback::Provider>)
diff --git a/src/ui/usagestatisticpage.cpp b/src/ui/usagestatisticpage.cpp
new file mode 100644
index 0000000..a81fc87
--- /dev/null
+++ b/src/ui/usagestatisticpage.cpp
@@ -0,0 +1,93 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of UsageStatistic plugin for Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+#include "usagestatisticpage.h"
+
+#include <KUserFeedback/AbstractDataSource>
+
+#include "usagestatisticwidget.h"
+#include "usagestatisticconstants.h"
+
+namespace UsageStatistic {
+namespace Internal {
+
+UsageStatisticPage::UsageStatisticPage(std::shared_ptr<KUserFeedback::Provider> provider)
+ : m_provider(std::move(provider))
+{
+ configure();
+}
+
+UsageStatisticPage::~UsageStatisticPage() = default;
+
+QWidget *UsageStatisticPage::widget()
+{
+ if (!m_feedbackWidget) {
+ m_feedbackWidget = std::make_unique<UsageStatisticWidget>(m_provider);
+ m_feedbackWidget->updateSettings();
+ }
+
+ return m_feedbackWidget.get();
+}
+
+static void applyDataSourcesActiveStatuses(const QHash<QString, bool> &statuses,
+ const KUserFeedback::Provider &provider)
+{
+ for (auto &&ds : provider.dataSources()) {
+ if (ds) {
+ const auto it = statuses.find(ds->id());
+ if (it != std::end(statuses)) {
+ ds->setActive(*it);
+ }
+ }
+ }
+}
+
+void UsageStatisticPage::apply()
+{
+ auto settings = m_feedbackWidget->settings();
+
+ m_provider->setTelemetryMode(settings.telemetryMode);
+ applyDataSourcesActiveStatuses(settings.activeStatusesById, *m_provider);
+
+ Q_EMIT settingsChanged();
+}
+
+void UsageStatisticPage::finish()
+{
+ m_feedbackWidget.reset();
+}
+
+void UsageStatisticPage::configure()
+{
+ setId(Constants::USAGE_STATISTIC_PAGE_ID);
+ setCategory(Constants::TELEMETRY_SETTINGS_CATEGORY_ID);
+ setCategoryIcon(Utils::Icon({{":/usagestatistic/images/settingscategory_usagestatistic.png",
+ Utils::Theme::PanelTextColorDark}}, Utils::Icon::Tint));
+
+ setDisplayName(tr("Usage Statistic"));
+ setDisplayCategory(tr("Telemetry"));
+}
+
+} // namespace Internal
+} // namespace UsageStatistic
diff --git a/src/ui/usagestatisticpage.h b/src/ui/usagestatisticpage.h
new file mode 100644
index 0000000..1052611
--- /dev/null
+++ b/src/ui/usagestatisticpage.h
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of UsageStatistic plugin for Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+#pragma once
+
+#include <memory>
+
+#include <QtCore/QPointer>
+
+#include <coreplugin/dialogs/ioptionspage.h>
+
+namespace KUserFeedback { class Provider; }
+
+namespace UsageStatistic {
+namespace Internal {
+
+class UsageStatisticWidget;
+
+//! Settings page
+class UsageStatisticPage : public Core::IOptionsPage
+{
+ Q_OBJECT
+
+public:
+ UsageStatisticPage(std::shared_ptr<KUserFeedback::Provider> provider);
+ ~UsageStatisticPage() override;
+
+public: // IOptionsPage interface
+ QWidget *widget() override;
+ void apply() override;
+ void finish() override;
+
+Q_SIGNALS:
+ void settingsChanged();
+
+private: // Data
+ std::unique_ptr<UsageStatisticWidget> m_feedbackWidget;
+ std::shared_ptr<KUserFeedback::Provider> m_provider;
+
+private: // Methods
+ void configure();
+};
+
+} // namespace Internal
+} // namespace UsageStatistic
diff --git a/src/ui/usagestatisticwidget.cpp b/src/ui/usagestatisticwidget.cpp
new file mode 100644
index 0000000..b6f7a3b
--- /dev/null
+++ b/src/ui/usagestatisticwidget.cpp
@@ -0,0 +1,204 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of UsageStatistic plugin for Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+#include "usagestatisticwidget.h"
+#include "ui_usagestatisticwidget.h"
+
+#include <QtCore/QJsonObject>
+#include <QtCore/QJsonArray>
+#include <QtCore/QJsonDocument>
+
+#include <KUserFeedback/FeedbackConfigUiController>
+#include <KUserFeedback/AbstractDataSource>
+
+#include "usagestatisticconstants.h"
+
+namespace UsageStatistic {
+namespace Internal {
+
+using namespace KUserFeedback;
+
+UsageStatisticWidget::UsageStatisticWidget(std::shared_ptr<KUserFeedback::Provider> provider)
+ : ui(std::make_unique<Ui::UsageStatisticWidget>())
+ , m_provider(std::move(provider))
+ , m_controller(std::make_unique<FeedbackConfigUiController>())
+{
+ ui->setupUi(this);
+
+ configure();
+
+ addPrivacyPolicyLink();
+}
+
+void UsageStatisticWidget::updateSettings()
+{
+ setupActiveStatuses();
+ setupTelemetryModeUi();
+}
+
+UsageStatisticWidget::Settings UsageStatisticWidget::settings() const
+{
+ return {m_controller->telemetryIndexToMode(ui->cbMode->currentIndex()), m_activeStatusesById};
+}
+
+static constexpr int dataSourceIDRole = Qt::UserRole + 1;
+
+void UsageStatisticWidget::configure()
+{
+ m_controller->setFeedbackProvider(m_provider.get());
+
+ connect(ui->cbMode, QOverload<int>::of(&QComboBox::currentIndexChanged),
+ this, &UsageStatisticWidget::updateTelemetryModeDescription);
+ connect(ui->cbMode, QOverload<int>::of(&QComboBox::currentIndexChanged),
+ [this](int index) { preserveCurrentActiveStatuses(); updateDataSources(index); });
+
+ connect(ui->lvDataSources, &QListWidget::currentItemChanged,
+ this, &UsageStatisticWidget::updateDataSource);
+ connect(ui->lvDataSources, &QListWidget::itemChanged,
+ this, &UsageStatisticWidget::updateActiveStatus);
+}
+
+void UsageStatisticWidget::setupTelemetryModeUi()
+{
+ ui->cbMode->clear();
+ for (int i = 0; i < m_controller->telemetryModeCount(); ++i) {
+ ui->cbMode->addItem(QString("%1 - %2").arg(i).arg(m_controller->telemetryModeName(i)));
+ }
+
+ ui->cbMode->setCurrentIndex(m_controller->telemetryModeToIndex(m_provider->telemetryMode()));
+}
+
+void UsageStatisticWidget::updateTelemetryModeDescription(int modeIndex)
+{
+ ui->pteTelemetryLvlDescription->setPlainText(m_controller->telemetryModeDescription(modeIndex));
+}
+
+static auto dataSourceToItem(const AbstractDataSource &ds,
+ const UsageStatisticWidget::ActiveStatusesById &activeStatusesById)
+{
+ auto item = std::make_unique<QListWidgetItem>(ds.name());
+
+ item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
+ const auto it = activeStatusesById.find(ds.id());
+ if (it != std::end(activeStatusesById)) {
+ item->setCheckState(*it ? Qt::Checked : Qt::Unchecked);
+ } else {
+ item->setCheckState(Qt::Checked);
+ }
+
+ item->setData(dataSourceIDRole, ds.id());
+
+ return item;
+}
+
+void UsageStatisticWidget::updateDataSources(int modeIndex)
+{
+ ui->lvDataSources->clear();
+
+ for (auto &&ds : m_provider->dataSources()) {
+ if (ds && ds->telemetryMode() <= m_controller->telemetryIndexToMode(modeIndex)) {
+ auto item = dataSourceToItem(*ds, m_activeStatusesById).release();
+ ui->lvDataSources->addItem(item);
+
+ if (m_currentItemId == ds->id()) {
+ ui->lvDataSources->setCurrentItem(item);
+ }
+ }
+ }
+}
+
+static QString collectedData(AbstractDataSource &ds)
+{
+ QByteArray result;
+ auto variantData = ds.data();
+
+ if (variantData.canConvert<QVariantMap>()) {
+ result = QJsonDocument(QJsonObject::fromVariantMap(variantData.toMap())).toJson();
+ }
+
+ if (variantData.canConvert<QVariantList>()) {
+ result = QJsonDocument(QJsonArray::fromVariantList(variantData.value<QVariantList>())).toJson();
+ }
+
+ return QString::fromUtf8(result);
+}
+
+void UsageStatisticWidget::updateDataSource(QListWidgetItem *item)
+{
+ if (item) {
+ m_currentItemId = item->data(dataSourceIDRole).toString();
+
+ if (auto ds = m_provider->dataSource(m_currentItemId)) {
+ ui->pteDataSourceDescription->setPlainText(ds->description());
+ ui->pteCollectedData->setPlainText(collectedData(*ds));
+ }
+ } else {
+ ui->pteDataSourceDescription->clear();
+ ui->pteCollectedData->clear();
+ }
+}
+
+void UsageStatisticWidget::updateActiveStatus(QListWidgetItem *item)
+{
+ if (item) {
+ auto id = item->data(dataSourceIDRole).toString();
+ m_activeStatusesById[id] = item->checkState() == Qt::Checked;
+ }
+}
+
+void UsageStatisticWidget::preserveCurrentActiveStatuses()
+{
+ for (int row = 0; row < ui->lvDataSources->count(); ++row) {
+ if (auto item = ui->lvDataSources->item(row)) {
+ auto id = item->data(dataSourceIDRole).toString();
+ m_activeStatusesById[id] = item->checkState() == Qt::Checked;
+ }
+ }
+}
+
+void UsageStatisticWidget::setupActiveStatuses()
+{
+ m_activeStatusesById.clear();
+
+ for (auto &&ds : m_provider->dataSources()) {
+ if (ds) {
+ m_activeStatusesById[ds->id()] = ds->isActive();
+ }
+ }
+}
+
+void UsageStatisticWidget::addPrivacyPolicyLink()
+{
+ const auto currentText = ui->lblPrivacyPolicy->text();
+ const auto linkTemplate = QString("<a href=\"%1\">%2<\\a>");
+ ui->lblPrivacyPolicy->setText(linkTemplate.arg(Constants::PRIVACY_POLICY_URL, currentText));
+
+ const auto tooltipTemplate = tr("Open %1");
+ ui->lblPrivacyPolicy->setToolTip(tooltipTemplate.arg(Constants::PRIVACY_POLICY_URL));
+}
+
+UsageStatisticWidget::~UsageStatisticWidget() = default;
+
+} // namespace Internal
+} // namespace UsageStatistic
diff --git a/src/ui/usagestatisticwidget.h b/src/ui/usagestatisticwidget.h
new file mode 100644
index 0000000..fb3341a
--- /dev/null
+++ b/src/ui/usagestatisticwidget.h
@@ -0,0 +1,94 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of UsageStatistic plugin for Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+#pragma once
+
+#include <memory>
+
+#include <QtWidgets/QWidget>
+#include <QtCore/QHash>
+
+#include <KUserFeedback/Provider>
+
+namespace KUserFeedback { class FeedbackConfigUiController; }
+
+QT_BEGIN_NAMESPACE
+class QListWidgetItem;
+QT_END_NAMESPACE
+
+namespace UsageStatistic {
+namespace Internal {
+
+namespace Ui { class UsageStatisticWidget; }
+
+//! Telemetry settings widget
+class UsageStatisticWidget : public QWidget
+{
+ Q_OBJECT
+
+public: // Types
+ using ActiveStatusesById = QHash<QString, bool>;
+
+ struct Settings
+ {
+ KUserFeedback::Provider::TelemetryMode telemetryMode;
+ ActiveStatusesById activeStatusesById;
+ };
+
+public:
+ explicit UsageStatisticWidget(std::shared_ptr<KUserFeedback::Provider> provider);
+ ~UsageStatisticWidget() override;
+
+ void updateSettings();
+
+ Settings settings() const;
+
+private: // Methods
+ void configure();
+
+ void setupTelemetryModeUi();
+ void updateTelemetryModeDescription(int modeIndex);
+
+ void updateDataSources(int modeIndex);
+
+ void updateDataSource(QListWidgetItem *item);
+ void updateActiveStatus(QListWidgetItem *item);
+
+ void preserveCurrentActiveStatuses();
+
+ void setupActiveStatuses();
+
+ void addPrivacyPolicyLink();
+
+private: // Data
+ std::unique_ptr<Ui::UsageStatisticWidget> ui;
+ std::shared_ptr<KUserFeedback::Provider> m_provider;
+ std::unique_ptr<KUserFeedback::FeedbackConfigUiController> m_controller;
+
+ QString m_currentItemId;
+ ActiveStatusesById m_activeStatusesById;
+};
+
+} // namespace Internal
+} // namespace UsageStatistic
diff --git a/src/ui/usagestatisticwidget.ui b/src/ui/usagestatisticwidget.ui
new file mode 100644
index 0000000..484b69a
--- /dev/null
+++ b/src/ui/usagestatisticwidget.ui
@@ -0,0 +1,161 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>UsageStatistic::Internal::UsageStatisticWidget</class>
+ <widget class="QWidget" name="UsageStatistic::Internal::UsageStatisticWidget">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>676</width>
+ <height>527</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Form</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout_5">
+ <item>
+ <widget class="QGroupBox" name="gbTelemetryMode">
+ <property name="title">
+ <string>&amp;Telemetry mode</string>
+ </property>
+ <property name="flat">
+ <bool>true</bool>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout_4">
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_2">
+ <item>
+ <widget class="QComboBox" name="cbMode">
+ <property name="sizeAdjustPolicy">
+ <enum>QComboBox::AdjustToContents</enum>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <widget class="QPlainTextEdit" name="pteTelemetryLvlDescription">
+ <property name="undoRedoEnabled">
+ <bool>false</bool>
+ </property>
+ <property name="readOnly">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
+ <widget class="QGroupBox" name="gbDataSources">
+ <property name="title">
+ <string>Data &amp;sources</string>
+ </property>
+ <layout class="QHBoxLayout" name="horizontalLayout" stretch="3,7">
+ <item>
+ <widget class="QListWidget" name="lvDataSources"/>
+ </item>
+ <item>
+ <layout class="QVBoxLayout" name="verticalLayout_3" stretch="2,8">
+ <item>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <widget class="QLabel" name="lblDataSourceDescription">
+ <property name="text">
+ <string>&amp;Description</string>
+ </property>
+ <property name="buddy">
+ <cstring>pteDataSourceDescription</cstring>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPlainTextEdit" name="pteDataSourceDescription">
+ <property name="undoRedoEnabled">
+ <bool>false</bool>
+ </property>
+ <property name="readOnly">
+ <bool>true</bool>
+ </property>
+ <property name="textInteractionFlags">
+ <set>Qt::TextSelectableByMouse</set>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QVBoxLayout" name="verticalLayout_2">
+ <item>
+ <widget class="QLabel" name="lblCollectedData">
+ <property name="text">
+ <string>&amp;Collected Data</string>
+ </property>
+ <property name="buddy">
+ <cstring>pteCollectedData</cstring>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPlainTextEdit" name="pteCollectedData">
+ <property name="undoRedoEnabled">
+ <bool>false</bool>
+ </property>
+ <property name="readOnly">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_3">
+ <item>
+ <widget class="QLabel" name="lblPrivacyPolicy">
+ <property name="text">
+ <string>Legal Notice and Privacy Policy</string>
+ </property>
+ <property name="openExternalLinks">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer_2">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>