forked from qt-creator/qt-creator
StudioWelcome: Use the QSetting to disable UsageStatistics
Instead of enabling/disabling the plugin we use the existing setting. Task-number: QDS-4128 Change-Id: Ibddf39b53aeac3741396c0329879ed1b29f8bf57 Reviewed-by: Marco Bubke <marco.bubke@qt.io>
This commit is contained in:
@@ -305,6 +305,6 @@ Image {
|
|||||||
scale: 0.5
|
scale: 0.5
|
||||||
checked: usageStatisticModel.usageStatisticEnabled
|
checked: usageStatisticModel.usageStatisticEnabled
|
||||||
|
|
||||||
onCheckedChanged: usageStatisticModel.setPluginEnabled(usageStatisticCheckBox.checked)
|
onCheckedChanged: usageStatisticModel.setTelemetryEnabled(usageStatisticCheckBox.checked)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,36 +49,55 @@
|
|||||||
#include <QAbstractListModel>
|
#include <QAbstractListModel>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
#include <QFontDatabase>
|
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
|
#include <QFontDatabase>
|
||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
#include <QQmlContext>
|
#include <QQmlContext>
|
||||||
#include <QQmlEngine>
|
#include <QQmlEngine>
|
||||||
#include <QQuickItem>
|
#include <QQuickItem>
|
||||||
#include <QQuickView>
|
#include <QQuickView>
|
||||||
#include <QQuickWidget>
|
#include <QQuickWidget>
|
||||||
|
#include <QSettings>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
namespace StudioWelcome {
|
namespace StudioWelcome {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
const char DO_NOT_SHOW_SPLASHSCREEN_AGAIN_KEY[] = "StudioSplashScreen";
|
const char DO_NOT_SHOW_SPLASHSCREEN_AGAIN_KEY[] = "StudioSplashScreen";
|
||||||
|
|
||||||
|
const char DETAILED_USAGE_STATISTICS[] = "DetailedUsageStatistics";
|
||||||
|
const char STATISTICS_COLLECTION_MODE[] = "StatisticsCollectionMode";
|
||||||
|
const char NO_TELEMETRY[] = "NoTelemetry";
|
||||||
|
|
||||||
QPointer<QQuickWidget> s_view = nullptr;
|
QPointer<QQuickWidget> s_view = nullptr;
|
||||||
static StudioWelcomePlugin *s_pluginInstance = nullptr;
|
static StudioWelcomePlugin *s_pluginInstance = nullptr;
|
||||||
|
|
||||||
static bool isUsageStatistic(const ExtensionSystem::PluginSpec *spec)
|
std::unique_ptr<QSettings> makeUserFeedbackSettings()
|
||||||
{
|
{
|
||||||
if (!spec)
|
QStringList domain = QCoreApplication::organizationDomain().split(QLatin1Char('.'));
|
||||||
return false;
|
std::reverse(domain.begin(), domain.end());
|
||||||
|
QString productId = domain.join(QLatin1String("."));
|
||||||
|
if (!productId.isEmpty())
|
||||||
|
productId += ".";
|
||||||
|
productId += QCoreApplication::applicationName();
|
||||||
|
|
||||||
return spec->name().contains("UsageStatistic");
|
QString organization;
|
||||||
}
|
if (Utils::HostOsInfo::isMacHost()) {
|
||||||
|
organization = QCoreApplication::organizationDomain().isEmpty()
|
||||||
|
? QCoreApplication::organizationName()
|
||||||
|
: QCoreApplication::organizationDomain();
|
||||||
|
} else {
|
||||||
|
organization = QCoreApplication::organizationName().isEmpty()
|
||||||
|
? QCoreApplication::organizationDomain()
|
||||||
|
: QCoreApplication::organizationName();
|
||||||
|
}
|
||||||
|
|
||||||
ExtensionSystem::PluginSpec *getUsageStatisticPlugin()
|
std::unique_ptr<QSettings> settings(new QSettings(organization, "UserFeedback." + productId));
|
||||||
{
|
settings->beginGroup("UserFeedback");
|
||||||
const auto plugins = ExtensionSystem::PluginManager::plugins();
|
return settings;
|
||||||
return Utils::findOrDefault(plugins, &isUsageStatistic);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class UsageStatisticPluginModel : public QObject
|
class UsageStatisticPluginModel : public QObject
|
||||||
@@ -95,27 +114,21 @@ public:
|
|||||||
|
|
||||||
void setupModel()
|
void setupModel()
|
||||||
{
|
{
|
||||||
auto plugin = getUsageStatisticPlugin();
|
auto settings = makeUserFeedbackSettings();
|
||||||
if (plugin)
|
QVariant value = settings->value(STATISTICS_COLLECTION_MODE);
|
||||||
m_usageStatisticEnabled = plugin->isEnabledBySettings();
|
m_usageStatisticEnabled = value.isValid() && value.toString() == DETAILED_USAGE_STATISTICS;
|
||||||
else
|
|
||||||
m_usageStatisticEnabled = false;
|
|
||||||
|
|
||||||
emit usageStatisticChanged();
|
emit usageStatisticChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
Q_INVOKABLE void setPluginEnabled(bool b)
|
Q_INVOKABLE void setTelemetryEnabled(bool b)
|
||||||
{
|
{
|
||||||
auto plugin = getUsageStatisticPlugin();
|
if (m_usageStatisticEnabled == b)
|
||||||
|
|
||||||
if (!plugin)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (plugin->isEnabledBySettings() == b)
|
auto settings = makeUserFeedbackSettings();
|
||||||
return;
|
|
||||||
|
|
||||||
plugin->setEnabledBySettings(b);
|
settings->setValue(STATISTICS_COLLECTION_MODE, b ? DETAILED_USAGE_STATISTICS : NO_TELEMETRY);
|
||||||
ExtensionSystem::PluginManager::writeSettings();
|
|
||||||
|
|
||||||
// pause remove splash timer while dialog is open otherwise splash crashes upon removal
|
// pause remove splash timer while dialog is open otherwise splash crashes upon removal
|
||||||
s_pluginInstance->pauseRemoveSplashTimer();
|
s_pluginInstance->pauseRemoveSplashTimer();
|
||||||
@@ -139,9 +152,9 @@ class ProjectModel : public QAbstractListModel
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
enum { FilePathRole = Qt::UserRole+1, PrettyFilePathRole };
|
enum { FilePathRole = Qt::UserRole + 1, PrettyFilePathRole };
|
||||||
|
|
||||||
Q_PROPERTY(bool communityVersion MEMBER m_communityVersion NOTIFY communityVersionChanged)
|
Q_PROPERTY(bool communityVersion MEMBER m_communityVersion NOTIFY communityVersionChanged)
|
||||||
|
|
||||||
explicit ProjectModel(QObject *parent = nullptr);
|
explicit ProjectModel(QObject *parent = nullptr);
|
||||||
|
|
||||||
@@ -161,16 +174,12 @@ public:
|
|||||||
|
|
||||||
Q_INVOKABLE void openProjectAt(int row)
|
Q_INVOKABLE void openProjectAt(int row)
|
||||||
{
|
{
|
||||||
const QString projectFile = data(index(row, 0),
|
const QString projectFile = data(index(row, 0), ProjectModel::FilePathRole).toString();
|
||||||
ProjectModel::FilePathRole).toString();
|
|
||||||
if (QFileInfo::exists(projectFile))
|
if (QFileInfo::exists(projectFile))
|
||||||
ProjectExplorer::ProjectExplorerPlugin::openProjectWelcomePage(projectFile);
|
ProjectExplorer::ProjectExplorerPlugin::openProjectWelcomePage(projectFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
Q_INVOKABLE int get(int)
|
Q_INVOKABLE int get(int) { return -1; }
|
||||||
{
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
Q_INVOKABLE void showHelp()
|
Q_INVOKABLE void showHelp()
|
||||||
{
|
{
|
||||||
@@ -200,8 +209,11 @@ public:
|
|||||||
|
|
||||||
const QString projectFile = Core::ICore::resourcePath() + "/examples/" + example + "/"
|
const QString projectFile = Core::ICore::resourcePath() + "/examples/" + example + "/"
|
||||||
+ example + ".qmlproject";
|
+ example + ".qmlproject";
|
||||||
|
|
||||||
ProjectExplorer::ProjectExplorerPlugin::openProjectWelcomePage(projectFile);
|
ProjectExplorer::ProjectExplorerPlugin::openProjectWelcomePage(projectFile);
|
||||||
const QString qmlFile = Core::ICore::resourcePath() + "/examples/" + example + "/" + formFile;
|
const QString qmlFile = Core::ICore::resourcePath() + "/examples/" + example + "/"
|
||||||
|
+ formFile;
|
||||||
|
|
||||||
Core::EditorManager::openEditor(qmlFile);
|
Core::EditorManager::openEditor(qmlFile);
|
||||||
}
|
}
|
||||||
public slots:
|
public slots:
|
||||||
@@ -222,9 +234,9 @@ ProjectModel::ProjectModel(QObject *parent)
|
|||||||
this,
|
this,
|
||||||
&ProjectModel::resetProjects);
|
&ProjectModel::resetProjects);
|
||||||
|
|
||||||
|
|
||||||
if (!Utils::findOrDefault(ExtensionSystem::PluginManager::plugins(),
|
if (!Utils::findOrDefault(ExtensionSystem::PluginManager::plugins(),
|
||||||
Utils::equal(&ExtensionSystem::PluginSpec::name, QString("LicenseChecker"))))
|
Utils::equal(&ExtensionSystem::PluginSpec::name,
|
||||||
|
QString("LicenseChecker"))))
|
||||||
m_communityVersion = true;
|
m_communityVersion = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -235,8 +247,8 @@ int ProjectModel::rowCount(const QModelIndex &) const
|
|||||||
|
|
||||||
QVariant ProjectModel::data(const QModelIndex &index, int role) const
|
QVariant ProjectModel::data(const QModelIndex &index, int role) const
|
||||||
{
|
{
|
||||||
QPair<QString,QString> data =
|
QPair<QString, QString> data = ProjectExplorer::ProjectExplorerPlugin::recentProjects().at(
|
||||||
ProjectExplorer::ProjectExplorerPlugin::recentProjects().at(index.row());
|
index.row());
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case Qt::DisplayRole:
|
case Qt::DisplayRole:
|
||||||
return data.second;
|
return data.second;
|
||||||
@@ -275,7 +287,6 @@ public:
|
|||||||
~WelcomeMode() override;
|
~WelcomeMode() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
QQuickWidget *m_modeWidget = nullptr;
|
QQuickWidget *m_modeWidget = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -344,22 +355,25 @@ void StudioWelcomePlugin::extensionsInitialized()
|
|||||||
s_view->setWindowFlag(Qt::SplashScreen, true);
|
s_view->setWindowFlag(Qt::SplashScreen, true);
|
||||||
s_view->setWindowModality(Qt::ApplicationModal);
|
s_view->setWindowModality(Qt::ApplicationModal);
|
||||||
s_view->engine()->addImportPath("qrc:/studiofonts");
|
s_view->engine()->addImportPath("qrc:/studiofonts");
|
||||||
#ifdef QT_DEBUG
|
#ifdef QT_DEBUG
|
||||||
s_view->engine()->addImportPath(QLatin1String(STUDIO_QML_PATH)
|
s_view->engine()->addImportPath(QLatin1String(STUDIO_QML_PATH) + "splashscreen/imports");
|
||||||
+ "splashscreen/imports");
|
s_view->setSource(
|
||||||
s_view->setSource(QUrl::fromLocalFile(QLatin1String(STUDIO_QML_PATH)
|
QUrl::fromLocalFile(QLatin1String(STUDIO_QML_PATH) + "splashscreen/main.qml"));
|
||||||
+ "splashscreen/main.qml"));
|
#else
|
||||||
#else
|
|
||||||
s_view->engine()->addImportPath("qrc:/qml/splashscreen/imports");
|
s_view->engine()->addImportPath("qrc:/qml/splashscreen/imports");
|
||||||
s_view->setSource(QUrl("qrc:/qml/splashscreen/main.qml"));
|
s_view->setSource(QUrl("qrc:/qml/splashscreen/main.qml"));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
QTC_ASSERT(s_view->rootObject(),
|
QTC_ASSERT(s_view->rootObject(),
|
||||||
qWarning() << "The StudioWelcomePlugin has a runtime depdendency on qt/qtquicktimeline.";
|
qWarning() << "The StudioWelcomePlugin has a runtime depdendency on "
|
||||||
return);
|
"qt/qtquicktimeline.";
|
||||||
|
return );
|
||||||
|
|
||||||
connect(s_view->rootObject(), SIGNAL(closeClicked()), this, SLOT(closeSplashScreen()));
|
connect(s_view->rootObject(), SIGNAL(closeClicked()), this, SLOT(closeSplashScreen()));
|
||||||
connect(s_view->rootObject(), SIGNAL(configureClicked()), this, SLOT(showSystemSettings()));
|
connect(s_view->rootObject(),
|
||||||
|
SIGNAL(configureClicked()),
|
||||||
|
this,
|
||||||
|
SLOT(showSystemSettings()));
|
||||||
|
|
||||||
s_view->show();
|
s_view->show();
|
||||||
s_view->raise();
|
s_view->raise();
|
||||||
@@ -374,7 +388,7 @@ bool StudioWelcomePlugin::delayedInitialize()
|
|||||||
if (s_view.isNull())
|
if (s_view.isNull())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
QTC_ASSERT(s_view->rootObject() , return true);
|
QTC_ASSERT(s_view->rootObject(), return true);
|
||||||
|
|
||||||
#ifdef ENABLE_CRASHPAD
|
#ifdef ENABLE_CRASHPAD
|
||||||
const bool crashReportingEnabled = true;
|
const bool crashReportingEnabled = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user