From 6a838d7c3c731a4f555f118dc385e41aff24d635 Mon Sep 17 00:00:00 2001 From: hjk Date: Thu, 18 Mar 2021 08:52:42 +0100 Subject: [PATCH] Docker: New empty shell The usual boiler plate for plugins, including an option page that knows how to run "docker search" for demonstration purposes. Change-Id: I2df91f18f4869cbb2ee8f65ccb8b41969f8c90ae Reviewed-by: Alessandro Portale --- src/plugins/CMakeLists.txt | 1 + src/plugins/docker/CMakeLists.txt | 10 ++ src/plugins/docker/Docker.json.in | 20 +++ src/plugins/docker/docker.pro | 12 ++ src/plugins/docker/docker.qbs | 21 +++ src/plugins/docker/docker_dependencies.pri | 6 + src/plugins/docker/docker_global.h | 10 ++ src/plugins/docker/dockerconstants.h | 39 +++++ src/plugins/docker/dockerplugin.cpp | 60 ++++++++ src/plugins/docker/dockerplugin.h | 47 ++++++ src/plugins/docker/dockersettings.cpp | 161 +++++++++++++++++++++ src/plugins/docker/dockersettings.h | 58 ++++++++ src/plugins/plugins.pro | 3 +- src/plugins/plugins.qbs | 1 + 14 files changed, 448 insertions(+), 1 deletion(-) create mode 100644 src/plugins/docker/CMakeLists.txt create mode 100644 src/plugins/docker/Docker.json.in create mode 100644 src/plugins/docker/docker.pro create mode 100644 src/plugins/docker/docker.qbs create mode 100644 src/plugins/docker/docker_dependencies.pri create mode 100644 src/plugins/docker/docker_global.h create mode 100644 src/plugins/docker/dockerconstants.h create mode 100644 src/plugins/docker/dockerplugin.cpp create mode 100644 src/plugins/docker/dockerplugin.h create mode 100644 src/plugins/docker/dockersettings.cpp create mode 100644 src/plugins/docker/dockersettings.h diff --git a/src/plugins/CMakeLists.txt b/src/plugins/CMakeLists.txt index 871f999b43e..11bc46f1c34 100644 --- a/src/plugins/CMakeLists.txt +++ b/src/plugins/CMakeLists.txt @@ -27,6 +27,7 @@ add_subdirectory(resourceeditor) add_subdirectory(tasklist) add_subdirectory(nim) add_subdirectory(conan) +add_subdirectory(docker) # Level 4: (only depends on Level 3 and below) add_subdirectory(clangpchmanager) diff --git a/src/plugins/docker/CMakeLists.txt b/src/plugins/docker/CMakeLists.txt new file mode 100644 index 00000000000..90e866435ab --- /dev/null +++ b/src/plugins/docker/CMakeLists.txt @@ -0,0 +1,10 @@ +add_qtc_plugin(Docker + PLUGIN_DEPENDS Core + SOURCES + dockerplugin.cpp + dockerplugin.h + dockersettings.cpp + dockersettings.h + docker_global.h + dockerconstants.h +) diff --git a/src/plugins/docker/Docker.json.in b/src/plugins/docker/Docker.json.in new file mode 100644 index 00000000000..4107350999f --- /dev/null +++ b/src/plugins/docker/Docker.json.in @@ -0,0 +1,20 @@ +{ + \"Name\" : \"Docker\", + \"Version\" : \"$$QTCREATOR_VERSION\", + \"CompatVersion\" : \"$$QTCREATOR_COMPAT_VERSION\", + \"Vendor\" : \"The Qt Company Ltd\", + \"Copyright\" : \"(C) $$QTCREATOR_COPYRIGHT_YEAR The Qt Company Ltd\", + \"License\" : [ \"Commercial Usage\", + \"\", + \"Licensees holding valid Qt Commercial licenses may use this plugin in accordance with the Qt 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.\", + \"\", + \"GNU General Public License Usage\", + \"\", + \"Alternatively, this plugin 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 plugin. 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.\" + ], + \"Category\" : \"Utilities\", + \"Experimental\" : true, + \"Description\" : \"Basic support for Docker\", + \"Url\" : \"http://www.qt.io\", + $$dependencyList +} diff --git a/src/plugins/docker/docker.pro b/src/plugins/docker/docker.pro new file mode 100644 index 00000000000..d2839b2287b --- /dev/null +++ b/src/plugins/docker/docker.pro @@ -0,0 +1,12 @@ +include(../../qtcreatorplugin.pri) + +DEFINES += QT_RESTRICTED_CAST_FROM_ASCII + +SOURCES += \ + dockerplugin.cpp \ + dockersettings.cpp +HEADERS += \ + dockerconstants.h \ + dockerplugin.h \ + docker_global.h \ + dockersettings.h diff --git a/src/plugins/docker/docker.qbs b/src/plugins/docker/docker.qbs new file mode 100644 index 00000000000..fa7a081315b --- /dev/null +++ b/src/plugins/docker/docker.qbs @@ -0,0 +1,21 @@ +import qbs 1.0 + +QtcPlugin { + name: "Docker" + + Depends { name: "Qt.widgets" } + Depends { name: "Utils" } + + Depends { name: "Core" } + Depends { name: "ProjectExplorer" } + + files: [ + "docker_global.h", + "dockerconstants.h", + "dockerplugin.h", + "dockerplugin.cpp", + "dockersettings.h", + "dockersettings.cpp" + ] +} + diff --git a/src/plugins/docker/docker_dependencies.pri b/src/plugins/docker/docker_dependencies.pri new file mode 100644 index 00000000000..ce3aefbe58e --- /dev/null +++ b/src/plugins/docker/docker_dependencies.pri @@ -0,0 +1,6 @@ +QTC_PLUGIN_NAME = Docker +QTC_LIB_DEPENDS += \ + utils +QTC_PLUGIN_DEPENDS += \ + coreplugin \ + projectexplorer diff --git a/src/plugins/docker/docker_global.h b/src/plugins/docker/docker_global.h new file mode 100644 index 00000000000..5dd732b10b5 --- /dev/null +++ b/src/plugins/docker/docker_global.h @@ -0,0 +1,10 @@ +#ifndef DOCKER_GLOBAL_H +#define DOCKER_GLOBAL_H + +#if defined(DOCKER_LIBRARY) +# define DOCKER_EXPORT Q_DECL_EXPORT +#else +# define DOCKER_EXPORT Q_DECL_IMPORT +#endif + +#endif // DOCKER_GLOBAL_H diff --git a/src/plugins/docker/dockerconstants.h b/src/plugins/docker/dockerconstants.h new file mode 100644 index 00000000000..879b394270e --- /dev/null +++ b/src/plugins/docker/dockerconstants.h @@ -0,0 +1,39 @@ +/**************************************************************************** +** +** Copyright (C) 2021 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of 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. +** +****************************************************************************/ + +#ifndef DOCKERCONSTANTS_H +#define DOCKERCONSTANTS_H + +namespace Docker { +namespace Constants { + +const char DOCKER_SETTINGS_ID[] = "Docker.Settings"; +const char ACTION_ID[] = "Docker.Action"; +const char MENU_ID[] = "Docker.Menu"; + +} // namespace Constants +} // namespace Docker + +#endif // DOCKERCONSTANTS_H diff --git a/src/plugins/docker/dockerplugin.cpp b/src/plugins/docker/dockerplugin.cpp new file mode 100644 index 00000000000..64ad244fd0a --- /dev/null +++ b/src/plugins/docker/dockerplugin.cpp @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** Copyright (C) 2021 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of 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 "dockerplugin.h" + +#include "dockerconstants.h" +#include "dockersettings.h" + +using namespace Core; +using namespace Utils; + +namespace Docker { +namespace Internal { + +class DockerPluginPrivate +{ +public: + DockerSettings settings; + DockerOptionsPage optionsPage{&settings}; +}; + +DockerPlugin::~DockerPlugin() +{ + delete d; +} + +bool DockerPlugin::initialize(const QStringList &arguments, QString *errorString) +{ + Q_UNUSED(arguments) + Q_UNUSED(errorString) + + d = new DockerPluginPrivate; + + return true; +} + +} // namespace Internal +} // namespace Docker diff --git a/src/plugins/docker/dockerplugin.h b/src/plugins/docker/dockerplugin.h new file mode 100644 index 00000000000..a76aad710aa --- /dev/null +++ b/src/plugins/docker/dockerplugin.h @@ -0,0 +1,47 @@ +/**************************************************************************** +** +** Copyright (C) 2021 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of 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 + +namespace Docker { +namespace Internal { + +class DockerPlugin final : public ExtensionSystem::IPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "Docker.json") + +private: + ~DockerPlugin() final; + + bool initialize(const QStringList &arguments, QString *errorString) final; + + class DockerPluginPrivate *d = nullptr; +}; + +} // namespace Internal +} // namespace Docker diff --git a/src/plugins/docker/dockersettings.cpp b/src/plugins/docker/dockersettings.cpp new file mode 100644 index 00000000000..dba48142a4d --- /dev/null +++ b/src/plugins/docker/dockersettings.cpp @@ -0,0 +1,161 @@ +/**************************************************************************** +** +** Copyright (C) 2021 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of 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 "dockerconstants.h" +#include "dockersettings.h" + +#include + +#include + +#include +#include +#include + +using namespace Utils; + +namespace Docker { +namespace Internal { + +// DockerSettings + +const char SETTINGS_KEY[] = "Docker"; + +static DockerSettings *theSettings = nullptr; + +DockerSettings::DockerSettings() +{ + theSettings = this; + setAutoApply(false); + readSettings(Core::ICore::settings()); + + imageListFilter.setSettingsKey("DockerListFilter"); + imageListFilter.setPlaceHolderText(tr("")); + imageListFilter.setDisplayStyle(StringAspect::LineEditDisplay); + imageListFilter.setLabelText(tr("Filter:")); + + imageList.setDisplayStyle(StringAspect::TextEditDisplay); + imageList.setLabelText(tr("Images:")); + + connect(&imageListFilter, &BaseAspect::changed, this, &DockerSettings::updateImageList); +} + +DockerSettings *DockerSettings::instance() +{ + return theSettings; +} + +void DockerSettings::writeSettings(QSettings *settings) const +{ + settings->remove(SETTINGS_KEY); + settings->beginGroup(SETTINGS_KEY); + forEachAspect([settings](BaseAspect *aspect) { + QtcSettings::setValueWithDefault(settings, aspect->settingsKey(), + aspect->value(), aspect->defaultValue()); + }); + settings->endGroup(); +} + +void DockerSettings::updateImageList() +{ + QtcProcess process; + process.setCommand({"docker", {"search", imageListFilter.value()}}); + + const auto finished = QOverload::of(&QProcess::finished); + connect(&process, finished, this, [&process, this] { + const QString data = QString::fromUtf8(process.readAll()); + imageList.setValue(data); + }); + + process.start(); + process.waitForFinished(); +} + +void DockerSettings::readSettings(const QSettings *settings) +{ + const QString keyRoot = QString(SETTINGS_KEY) + '/'; + forEachAspect([settings, keyRoot](BaseAspect *aspect) { + QString key = aspect->settingsKey(); + const QVariant value = settings->value(keyRoot + key, aspect->defaultValue()); + aspect->setValue(value); + }); +} + +// DockerOptionsPage + +class DockerConfigWidget : public Core::IOptionsPageWidget +{ + Q_DECLARE_TR_FUNCTIONS(Docker::Internal::DockerConfigWidget) + +public: + explicit DockerConfigWidget(DockerSettings *settings); + + void apply() final + { + m_settings->apply(); + m_settings->writeSettings(Core::ICore::settings()); + } + + void finish() final + { + m_settings->finish(); + } + +private: + DockerSettings *m_settings; +}; + +DockerConfigWidget::DockerConfigWidget(DockerSettings *settings) + : m_settings(settings) +{ + using namespace Layouting; + DockerSettings &s = *settings; + + Column { + Group { + Title(tr("Search images on Docker Hub")), + Form { + s.imageListFilter, Break(), + s.imageList + }, + }, + Stretch() + }.attachTo(this); +} + +// DockerOptionsPage + +DockerOptionsPage::DockerOptionsPage(DockerSettings *settings) +{ + setId(Constants::DOCKER_SETTINGS_ID); + setDisplayName(DockerConfigWidget::tr("Docker")); + setCategory(ProjectExplorer::Constants::DEVICE_SETTINGS_CATEGORY); + setDisplayCategory(QCoreApplication::translate("ProjectExplorer", "Devices")); + setCategoryIconPath(":/projectexplorer/images/settingscategory_devices.png"); + setWidgetCreator([settings] { return new DockerConfigWidget(settings); }); +} + +} // Internal +} // Docker diff --git a/src/plugins/docker/dockersettings.h b/src/plugins/docker/dockersettings.h new file mode 100644 index 00000000000..8a0df8f4adb --- /dev/null +++ b/src/plugins/docker/dockersettings.h @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2021 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of 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 + +namespace Docker { +namespace Internal { + +class DockerSettings : public QObject, public Utils::AspectContainer +{ +public: + DockerSettings(); + static DockerSettings *instance(); + + void readSettings(const QSettings *settings); + void writeSettings(QSettings *settings) const; + + void updateImageList(); + + Utils::StringAspect imageListFilter; + Utils::StringAspect imageList; +}; + +class DockerOptionsPage final : public Core::IOptionsPage +{ +public: + explicit DockerOptionsPage(DockerSettings *settings); +}; + +} // Internal +} // Docker diff --git a/src/plugins/plugins.pro b/src/plugins/plugins.pro index abf6e510c08..216407558ee 100644 --- a/src/plugins/plugins.pro +++ b/src/plugins/plugins.pro @@ -67,7 +67,8 @@ SUBDIRS = \ mcusupport \ marketplace \ incredibuild \ - conan + conan \ + docker qtHaveModule(serialport) { SUBDIRS += serialterminal diff --git a/src/plugins/plugins.qbs b/src/plugins/plugins.qbs index e2310ee1ff5..4a2298dc551 100644 --- a/src/plugins/plugins.qbs +++ b/src/plugins/plugins.qbs @@ -37,6 +37,7 @@ Project { "debugger/ptracepreload.qbs", "designer/designer.qbs", "diffeditor/diffeditor.qbs", + "docker/docker.qbs", "fakevim/fakevim.qbs", "emacskeys/emacskeys.qbs", "genericprojectmanager/genericprojectmanager.qbs",