From 2947b9571f1009d39305a84720bf64a4ab6b3c46 Mon Sep 17 00:00:00 2001 From: Vitaly Fanaskov Date: Tue, 26 Nov 2019 14:34:18 +0100 Subject: Use InfoBar to show encouragement message Fixes: QTCREATORBUG-23271 Change-Id: Ia0f9ef8958ce5945b176c93248826d9c86873850 Reviewed-by: Alessandro Portale --- src/src.pro | 4 -- src/ui/encouragementwidget.cpp | 101 ---------------------------------- src/ui/encouragementwidget.h | 69 ----------------------- src/ui/outputpane.cpp | 121 ----------------------------------------- src/ui/outputpane.h | 95 -------------------------------- src/usagestatisticconstants.h | 2 + src/usagestatisticplugin.cpp | 61 +++++++++++++-------- src/usagestatisticplugin.h | 4 -- 8 files changed, 39 insertions(+), 418 deletions(-) delete mode 100644 src/ui/encouragementwidget.cpp delete mode 100644 src/ui/encouragementwidget.h delete mode 100644 src/ui/outputpane.cpp delete mode 100644 src/ui/outputpane.h diff --git a/src/src.pro b/src/src.pro index 897f53c..6e8f16c 100644 --- a/src/src.pro +++ b/src/src.pro @@ -24,8 +24,6 @@ SOURCES += \ datasources/qmldesignerusagetimesource.cpp \ ui/usagestatisticpage.cpp \ ui/usagestatisticwidget.cpp \ - ui/outputpane.cpp \ - ui/encouragementwidget.cpp \ services/datasubmitter.cpp HEADERS += \ @@ -44,8 +42,6 @@ HEADERS += \ datasources/qmldesignerusagetimesource.h \ ui/usagestatisticpage.h \ ui/usagestatisticwidget.h \ - ui/outputpane.h \ - ui/encouragementwidget.h \ services/datasubmitter.h \ common/utils.h diff --git a/src/ui/encouragementwidget.cpp b/src/ui/encouragementwidget.cpp deleted file mode 100644 index 457422e..0000000 --- a/src/ui/encouragementwidget.cpp +++ /dev/null @@ -1,101 +0,0 @@ -/**************************************************************************** -** -** 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 - -#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()) -{ - ui->setupUi(this); - - connect(this, &EncouragementWidget::providerChanged, - this, &EncouragementWidget::onProviderChanged); - connect(ui->pbOptions, &QPushButton::clicked, - this, &EncouragementWidget::showSettingsDialog); -} - -std::shared_ptr EncouragementWidget::provider() const -{ - return m_provider; -} - -void EncouragementWidget::setProvider(std::shared_ptr 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 &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 deleted file mode 100644 index 6386a54..0000000 --- a/src/ui/encouragementwidget.h +++ /dev/null @@ -1,69 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include - -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 provider() const; - void setProvider(std::shared_ptr provider); - -protected: // QWidget interface - void showEvent(QShowEvent *event) override; - -Q_SIGNALS: - void providerChanged(const std::shared_ptr &); - -private Q_SLOTS: - void showSettingsDialog(); - void updateMessage(); - void onProviderChanged(const std::shared_ptr &p); - -private: - QScopedPointer ui; - std::shared_ptr m_provider; - std::unique_ptr m_controller; -}; - -} // namespace Internal -} // namespace UsageStatistic diff --git a/src/ui/outputpane.cpp b/src/ui/outputpane.cpp deleted file mode 100644 index 3529ca3..0000000 --- a/src/ui/outputpane.cpp +++ /dev/null @@ -1,121 +0,0 @@ -/**************************************************************************** -** -** 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 -#include -#include - -#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 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 OutputPane::provider() const -{ - return m_provider; -} - -void OutputPane::setProvider(std::shared_ptr 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 deleted file mode 100644 index 039b3f2..0000000 --- a/src/ui/outputpane.h +++ /dev/null @@ -1,95 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include -#include - -#include - -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 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 provider() const; - void setProvider(std::shared_ptr provider); - -Q_SIGNALS: - void providerChanged(std::shared_ptr); - -private: // Methods - void createEncouragementWidget(QWidget *parent); - -private: // Data - std::shared_ptr m_provider; - QPointer m_outputPaneWidget; -}; - -} // namespace Internal -} // namespace UsageStatistic - -Q_DECLARE_METATYPE(std::shared_ptr) diff --git a/src/usagestatisticconstants.h b/src/usagestatisticconstants.h index 0abde08..b7e9904 100644 --- a/src/usagestatisticconstants.h +++ b/src/usagestatisticconstants.h @@ -37,5 +37,7 @@ static constexpr char USAGE_STATISTIC_PAGE_ID[] = "UsageStatistic"; static constexpr char PRIVACY_POLICY_URL[] = "https://www.qt.io/terms-conditions/#privacy"; +static constexpr char ENC_MSG_INFOBAR_ENTRY_ID[] = "UsageStatisticPlugin_EncMsg_InfoBarEntry_Id"; + } // namespace UsageStatistic } // namespace Constants diff --git a/src/usagestatisticplugin.cpp b/src/usagestatisticplugin.cpp index d4e2555..bcd5856 100644 --- a/src/usagestatisticplugin.cpp +++ b/src/usagestatisticplugin.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -58,7 +59,6 @@ #include "services/datasubmitter.h" #include "ui/usagestatisticpage.h" -#include "ui/outputpane.h" #include "common/utils.h" @@ -74,9 +74,6 @@ bool UsageStatisticPlugin::initialize(const QStringList &arguments, QString *err Q_UNUSED(arguments) Q_UNUSED(errorString) - // We have to create a pane here because of OutputPaneManager internal initialization order - createOutputPane(); - return true; } @@ -132,8 +129,6 @@ bool UsageStatisticPlugin::delayedInitialize() restoreSettings(); - configureOutputPane(); - showFirstTimeMessage(); return true; @@ -154,21 +149,6 @@ void UsageStatisticPlugin::createUsageStatisticPage() this, &UsageStatisticPlugin::storeSettings); } -void UsageStatisticPlugin::createOutputPane() -{ - m_outputPane = std::make_unique(); -} - -void UsageStatisticPlugin::configureOutputPane() -{ - Q_ASSERT(m_outputPane); - - m_outputPane->setProvider(m_provider); - - connect(m_provider.get(), &KUserFeedback::Provider::showEncouragementMessage, - this, &UsageStatisticPlugin::showEncouragementMessage); -} - void UsageStatisticPlugin::storeSettings() { if (m_provider) { @@ -218,17 +198,50 @@ static bool runFirstTime(const KUserFeedback::Provider &provider) return false; } +static bool telemetryLevelNotSet(const KUserFeedback::Provider &provider) +{ + return provider.telemetryMode() == KUserFeedback::Provider::NoTelemetry; +} + void UsageStatisticPlugin::showFirstTimeMessage() { - if (m_provider && runFirstTime(*m_provider)) { + if (m_provider && runFirstTime(*m_provider) && telemetryLevelNotSet(*m_provider)) { showEncouragementMessage(); } } +static Core::InfoBarEntry makeInfoBarEntry() +{ + static auto infoText = UsageStatisticPlugin::tr( + "We make Qt Creator for you. Would you like to help us make it even better?"); + static auto customButtonInfoText = UsageStatisticPlugin::tr("Adjust usage statistics settings"); + static auto cancelButtonInfoText = UsageStatisticPlugin::tr("Decide later"); + + static auto hideEncouragementMessageCallback = []() { + if (auto infoBar = Core::ICore::infoBar()) { + infoBar->removeInfo(Constants::ENC_MSG_INFOBAR_ENTRY_ID); + } + }; + + static auto showUsageStatisticsSettingsCallback = []() { + hideEncouragementMessageCallback(); + Core::ICore::showOptionsDialog(Constants::USAGE_STATISTIC_PAGE_ID); + }; + + Core::InfoBarEntry entry(Constants::ENC_MSG_INFOBAR_ENTRY_ID, infoText); + entry.setCustomButtonInfo(customButtonInfoText, showUsageStatisticsSettingsCallback); + entry.setCancelButtonInfo(cancelButtonInfoText, hideEncouragementMessageCallback); + + return entry; +} + void UsageStatisticPlugin::showEncouragementMessage() { - if (m_outputPane) { - m_outputPane->flash(); + if (auto infoBar = Core::ICore::infoBar()) { + if (!infoBar->containsInfo(Constants::ENC_MSG_INFOBAR_ENTRY_ID)) { + static auto infoBarEntry = makeInfoBarEntry(); + infoBar->addInfo(infoBarEntry); + } } } diff --git a/src/usagestatisticplugin.h b/src/usagestatisticplugin.h index 798d27d..0fb6278 100644 --- a/src/usagestatisticplugin.h +++ b/src/usagestatisticplugin.h @@ -36,7 +36,6 @@ namespace UsageStatistic { namespace Internal { class UsageStatisticPage; -class OutputPane; //! Plugin for collecting and sending usage statistics class UsageStatisticPlugin : public ExtensionSystem::IPlugin @@ -55,8 +54,6 @@ public: private: void createUsageStatisticPage(); - void createOutputPane(); - void configureOutputPane(); void storeSettings(); void restoreSettings(); void createProvider(); @@ -66,7 +63,6 @@ private: private: std::shared_ptr m_provider; std::unique_ptr m_usageStatisticPage; - std::unique_ptr m_outputPane; }; } // namespace Internal -- cgit v1.2.3