Commit 27e20a2e authored by Katja Marttila's avatar Katja Marttila

Example of showing how to use licensechecker plugin

Licensechecker plugin is a QtCreator plugin which is installer for all
except opensource users. This example shows how to check if user has
evaluation license and how to launch dialog when starting QtCreator to
ask user if he wants to install vplay plugin. For evaluation users it is
not possible to disable the install, only is informed to user that data
is collected. The vplay plugin install itself is not done in this example.
The relevant part for connecting to licensechecker plugin and to launch
dialog is done in vplayplugintestplugin.cpp extensionsInitialized()
-function.
parents
{
\"Name\" : \"VPlayPluginTest\",
\"Version\" : \"0.0.1\",
\"CompatVersion\" : \"0.0.1\",
\"Vendor\" : \"MyCompany\",
\"Copyright\" : \"(C) MyCompany\",
\"License\" : \"Put your license information here\",
\"Description\" : \"Put a short description of your plugin here\",
\"Url\" : \"http://www.mycompany.com\",
$$dependencyList
}
#include <windows.h>
VS_VERSION_INFO VERSIONINFO
FILEVERSION 4,4,0,0
PRODUCTVERSION 4,4,0,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS VS_FF_DEBUG
#else
FILEFLAGS 0x0L
#endif
FILEOS VOS__WINDOWS32
FILETYPE VFT_DLL
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "CompanyName", "\0"
VALUE "FileDescription", "\0"
VALUE "FileVersion", "4.4.0.0\0"
VALUE "LegalCopyright", "\0"
VALUE "OriginalFilename", "VPlayPlugin4.dll\0"
VALUE "ProductName", "VPlayPlugin\0"
VALUE "ProductVersion", "4.4.0.0\0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x0409, 1200
END
END
/* End of Version info */
#include <windows.h>
VS_VERSION_INFO VERSIONINFO
FILEVERSION 4,4,0,0
PRODUCTVERSION 4,4,0,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS VS_FF_DEBUG
#else
FILEFLAGS 0x0L
#endif
FILEOS VOS__WINDOWS32
FILETYPE VFT_DLL
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "CompanyName", "\0"
VALUE "FileDescription", "\0"
VALUE "FileVersion", "4.4.0.0\0"
VALUE "LegalCopyright", "\0"
VALUE "OriginalFilename", "VPlayPlugind4.dll\0"
VALUE "ProductName", "VPlayPlugind\0"
VALUE "ProductVersion", "4.4.0.0\0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x0409, 1200
END
END
/* End of Version info */
isEmpty(IDE_SOURCE_TREE): IDE_SOURCE_TREE=$$(QTC_SOURCE)
isEmpty(IDE_BUILD_TREE): IDE_BUILD_TREE=$$(QTC_BUILD)
isEmpty(IDE_SOURCE_TREE):error(Set QTC_SOURCE environment variable)
isEmpty(IDE_BUILD_TREE):error(Set QTC_BUILD environment variable)
INCLUDEPATH+= $$PWD/plugins
include($$IDE_SOURCE_TREE/src/qtcreatorplugin.pri)
/********************************************************************************
** Form generated from reading UI file 'vplayacceptdialog.ui'
**
** Created by: Qt User Interface Compiler version 5.9.1
**
** WARNING! All changes made in this file will be lost when recompiling UI file!
********************************************************************************/
#ifndef UI_VPLAYACCEPTDIALOG_H
#define UI_VPLAYACCEPTDIALOG_H
#include <QtCore/QVariant>
#include <QtWidgets/QAction>
#include <QtWidgets/QApplication>
#include <QtWidgets/QButtonGroup>
#include <QtWidgets/QCheckBox>
#include <QtWidgets/QDialog>
#include <QtWidgets/QHBoxLayout>
#include <QtWidgets/QHeaderView>
#include <QtWidgets/QLabel>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QSpacerItem>
#include <QtWidgets/QVBoxLayout>
QT_BEGIN_NAMESPACE
class Ui_VPlayAcceptDialog
{
public:
QVBoxLayout *verticalLayout_2;
QVBoxLayout *verticalLayout;
QLabel *installSoftwareLabel;
QLabel *commercialLabel;
QSpacerItem *verticalSpacer;
QCheckBox *acceptCheckBox;
QHBoxLayout *horizontalLayout;
QSpacerItem *horizontalSpacer;
QPushButton *pushButton;
void setupUi(QDialog *VPlayAcceptDialog)
{
if (VPlayAcceptDialog->objectName().isEmpty())
VPlayAcceptDialog->setObjectName(QStringLiteral("VPlayAcceptDialog"));
VPlayAcceptDialog->resize(443, 155);
verticalLayout_2 = new QVBoxLayout(VPlayAcceptDialog);
verticalLayout_2->setObjectName(QStringLiteral("verticalLayout_2"));
verticalLayout = new QVBoxLayout();
verticalLayout->setObjectName(QStringLiteral("verticalLayout"));
installSoftwareLabel = new QLabel(VPlayAcceptDialog);
installSoftwareLabel->setObjectName(QStringLiteral("installSoftwareLabel"));
installSoftwareLabel->setWordWrap(true);
verticalLayout->addWidget(installSoftwareLabel);
commercialLabel = new QLabel(VPlayAcceptDialog);
commercialLabel->setObjectName(QStringLiteral("commercialLabel"));
verticalLayout->addWidget(commercialLabel);
verticalSpacer = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding);
verticalLayout->addItem(verticalSpacer);
acceptCheckBox = new QCheckBox(VPlayAcceptDialog);
acceptCheckBox->setObjectName(QStringLiteral("acceptCheckBox"));
acceptCheckBox->setChecked(true);
verticalLayout->addWidget(acceptCheckBox);
verticalLayout_2->addLayout(verticalLayout);
horizontalLayout = new QHBoxLayout();
horizontalLayout->setObjectName(QStringLiteral("horizontalLayout"));
horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
horizontalLayout->addItem(horizontalSpacer);
pushButton = new QPushButton(VPlayAcceptDialog);
pushButton->setObjectName(QStringLiteral("pushButton"));
horizontalLayout->addWidget(pushButton);
verticalLayout_2->addLayout(horizontalLayout);
retranslateUi(VPlayAcceptDialog);
QMetaObject::connectSlotsByName(VPlayAcceptDialog);
} // setupUi
void retranslateUi(QDialog *VPlayAcceptDialog)
{
VPlayAcceptDialog->setWindowTitle(QApplication::translate("VPlayAcceptDialog", "VPlay plugin accept", Q_NULLPTR));
installSoftwareLabel->setText(QApplication::translate("VPlayAcceptDialog", "By installing the Software you agree that The Qt Company collects and processes data that relates to your use of the Software. Collected data is anonymous and no personal data is collected. The data will be used for improving the user experience.", Q_NULLPTR));
commercialLabel->setText(QApplication::translate("VPlayAcceptDialog", "It is possible to opt-out data collection in Qt Creator settings at any time.", Q_NULLPTR));
acceptCheckBox->setText(QApplication::translate("VPlayAcceptDialog", "Accept data collection", Q_NULLPTR));
pushButton->setText(QApplication::translate("VPlayAcceptDialog", "Close", Q_NULLPTR));
} // retranslateUi
};
namespace Ui {
class VPlayAcceptDialog: public Ui_VPlayAcceptDialog {};
} // namespace Ui
QT_END_NAMESPACE
#endif // UI_VPLAYACCEPTDIALOG_H
#include "vplayacceptdialog.h"
#include "ui_vplayacceptdialog.h"
#include <QPushButton>
VPlayAcceptDialog::VPlayAcceptDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::VPlayAcceptDialog)
{
ui->setupUi(this);
}
VPlayAcceptDialog::~VPlayAcceptDialog()
{
delete ui;
}
void VPlayAcceptDialog::initializeEvaluationDialog()
{
ui->acceptCheckBox->hide();
ui->commercialLabel->hide();
}
void VPlayAcceptDialog::on_pushButton_clicked()
{
if (ui->acceptCheckBox->isChecked()) {
qDebug()<<"Install vplay plugin";
} else {
qDebug()<<"Uninstall vplay plugin" ;
}
close();
}
#ifndef VPLAYACCEPTDIALOG_H
#define VPLAYACCEPTDIALOG_H
#include <QDialog>
#include <QAbstractButton>
namespace Ui {
class VPlayAcceptDialog;
}
class VPlayAcceptDialog : public QDialog
{
Q_OBJECT
public:
explicit VPlayAcceptDialog(QWidget *parent = 0);
~VPlayAcceptDialog();
void initializeEvaluationDialog();
private slots:
void on_pushButton_clicked();
private:
Ui::VPlayAcceptDialog *ui;
};
#endif // VPLAYACCEPTDIALOG_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>VPlayAcceptDialog</class>
<widget class="QDialog" name="VPlayAcceptDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>443</width>
<height>155</height>
</rect>
</property>
<property name="windowTitle">
<string>VPlay plugin accept</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="installSoftwareLabel">
<property name="text">
<string>By installing the Software you agree that The Qt Company collects and processes data that relates to your use of the Software. Collected data is anonymous and no personal data is collected. The data will be used for improving the user experience.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="commercialLabel">
<property name="text">
<string>It is possible to opt-out data collection in Qt Creator settings at any time.</string>
</property>
</widget>
</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>
<item>
<widget class="QCheckBox" name="acceptCheckBox">
<property name="text">
<string>Accept data collection</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<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>
<item>
<widget class="QPushButton" name="pushButton">
<property name="text">
<string>Close</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
TARGET = VPlayPlugin
TEMPLATE = lib
include(qtcreatorplugin.pri)
DEFINES += VPLAYPLUGIN_LIBRARY
SOURCES += vplayplugintestplugin.cpp \
vplayacceptdialog.cpp
HEADERS += vplayplugintestplugin.h \
vplayplugintest_global.h \
vplayplugintestconstants.h \
vplayacceptdialog.h
OTHER_FILES += \
LicenseChecker.json
FORMS += \
vplayacceptdialog.ui
QTC_PLUGIN_NAME = VPlayPlugin
QTC_LIB_DEPENDS += \
extensionsystem
QTC_PLUGIN_DEPENDS += \
coreplugin
#pragma once
#include <QtGlobal>
#if defined(VPLAYPLUGINTEST_LIBRARY)
# define VPLAYPLUGINTESTSHARED_EXPORT Q_DECL_EXPORT
#else
# define VPLAYPLUGINTESTSHARED_EXPORT Q_DECL_IMPORT
#endif
#pragma once
namespace VPlayPluginTest {
namespace Constants {
const char ACTION_ID[] = "VPlayPluginTest.Action";
const char MENU_ID[] = "VPlayPluginTest.Menu";
} // namespace VPlayPluginTest
} // namespace Constants
#include "vplayplugintestplugin.h"
#include "vplayplugintestconstants.h"
#include "vplayacceptdialog.h"
#include <coreplugin/icore.h>
#include <coreplugin/icontext.h>
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/actionmanager/command.h>
#include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/coreconstants.h>
#include <coreplugin/messagemanager.h>
#include <extensionsystem/pluginmanager.h>
#include <QAction>
#include <QMessageBox>
#include <QMainWindow>
#include <QMenu>
#include <QDebug>
using namespace Core;
namespace VPlayPluginTest {
//
// logging helpers
//
static void logError(const QString &message)
{
MessageManager::write(message, MessageManager::Flash);
}
static void logInfo(const QString &message)
{
MessageManager::write(message, MessageManager::Silent);
}
namespace Internal {
VPlayPluginTestPlugin::VPlayPluginTestPlugin()
{
// Create your members
m_evaluationLicense = false;
}
VPlayPluginTestPlugin::~VPlayPluginTestPlugin()
{
// Unregister objects from the plugin manager's object pool
// Delete members
}
bool VPlayPluginTestPlugin::initialize(const QStringList &arguments, QString *errorString)
{
// Register objects in the plugin manager's object pool
// Load settings
// Add actions to menus
// Connect to other plugins' signals
// In the initialize function, a plugin can be sure that the plugins it
// depends on have initialized their members.
Q_UNUSED(arguments)
Q_UNUSED(errorString)
return true;
}
void VPlayPluginTestPlugin::extensionsInitialized()
{
// Retrieve objects from the plugin manager's object pool
// In the extensionsInitialized function, a plugin can be sure that all
// plugins that depend on it are completely initialized.
QObject *licenseChecker = ExtensionSystem::PluginManager::getObjectByClassName("LicenseChecker::LicenseCheckerPlugin");
if (licenseChecker) {
qDebug()<<"License checker plugin found";
QMetaObject::invokeMethod(licenseChecker, "evaluationLicense",
Qt::DirectConnection, Q_RETURN_ARG(bool, m_evaluationLicense));
qDebug()<<"Is evaluation license: "<<m_evaluationLicense;
connect(Core::ICore::instance(), &Core::ICore::coreOpened,
this, &VPlayPluginTestPlugin::showVPlayPluginDialog);
} else {
qDebug()<<"License checker plugin not found. The QtCreator is probably opensource.";
}
}
ExtensionSystem::IPlugin::ShutdownFlag VPlayPluginTestPlugin::aboutToShutdown()
{
// Save settings
// Disconnect from signals that are not needed during shutdown
// Hide UI (if you add UI that is not in the main window directly)
return SynchronousShutdown;
}
void VPlayPluginTestPlugin::showVPlayPluginDialog()
{
VPlayAcceptDialog *dialog = new VPlayAcceptDialog(Core::ICore::dialogParent());
if (m_evaluationLicense) {
dialog->initializeEvaluationDialog();
}
// resize to visible widgets
dialog->adjustSize();
dialog->setFixedHeight(dialog->height());
dialog->show();
}
} // namespace Internal
} // namespace VPlayPluginTest
#pragma once
#include "vplayplugintest_global.h"
#include <extensionsystem/iplugin.h>
namespace VPlayPluginTest {
namespace Internal {
class VPlayPluginTestPlugin : public ExtensionSystem::IPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "VPlayPluginTest.json")
public:
VPlayPluginTestPlugin();
~VPlayPluginTestPlugin();
bool initialize(const QStringList &arguments, QString *errorString);
void extensionsInitialized();
ShutdownFlag aboutToShutdown();
private:
void triggerAction();
void showVPlayPluginDialog();
bool m_evaluationLicense;
};
} // namespace Internal
} // namespace VPlayPluginTest
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment