From d99ad8fab9fc0a5708a61b6fbe481acbfd5e3446 Mon Sep 17 00:00:00 2001 From: Rohan Garg Date: Fri, 14 Aug 2015 17:18:17 +0200 Subject: [PATCH] Add a webview module Add a webview module so that calamares can load a webpage. This is useful when configuring webservices on your device such as ownCloud. --- src/modules/webview/CMakeLists.txt | 20 +++++ src/modules/webview/WebViewStep.cpp | 115 ++++++++++++++++++++++++++++ src/modules/webview/WebViewStep.h | 66 ++++++++++++++++ src/modules/webview/module.desc | 7 ++ src/modules/webview/webview.conf | 3 + 5 files changed, 211 insertions(+) create mode 100644 src/modules/webview/CMakeLists.txt create mode 100644 src/modules/webview/WebViewStep.cpp create mode 100644 src/modules/webview/WebViewStep.h create mode 100644 src/modules/webview/module.desc create mode 100644 src/modules/webview/webview.conf diff --git a/src/modules/webview/CMakeLists.txt b/src/modules/webview/CMakeLists.txt new file mode 100644 index 000000000..eb5c81a68 --- /dev/null +++ b/src/modules/webview/CMakeLists.txt @@ -0,0 +1,20 @@ +find_package( Qt5 ${QT_VERSION} CONFIG REQUIRED WebKit WebKitWidgets ) + +include_directories( ${PROJECT_BINARY_DIR}/src/libcalamaresui + ${QT_QTWEBKIT_INCLUDE_DIR} ) + +set( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} + ${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules ) + + +calamares_add_plugin( webview + TYPE viewmodule + EXPORT_MACRO PLUGINDLLEXPORT_PRO + SOURCES + WebViewStep.cpp + LINK_LIBRARIES + calamaresui + Qt5::WebKit + Qt5::WebKitWidgets + SHARED_LIB +) diff --git a/src/modules/webview/WebViewStep.cpp b/src/modules/webview/WebViewStep.cpp new file mode 100644 index 000000000..df4234136 --- /dev/null +++ b/src/modules/webview/WebViewStep.cpp @@ -0,0 +1,115 @@ +/* === This file is part of Calamares - === + * + * Copyright 2014-2015, Teo Mrnjavac + * + * Calamares is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Calamares is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Calamares. If not, see . + */ + +#include "WebViewStep.h" + +#include +#include + +WebViewStep::WebViewStep( QObject* parent ) + : Calamares::ViewStep( parent ) +{ + emit nextStatusChanged( true ); + m_view = new QWebView; +} + + +WebViewStep::~WebViewStep() +{ + if ( m_view && m_view->parent() == nullptr ) + m_view->deleteLater(); +} + + +QString +WebViewStep::prettyName() const +{ + return m_prettyName; +} + + +QWidget* +WebViewStep::widget() +{ + return m_view; +} + + +void +WebViewStep::next() +{ + emit done(); +} + + +void +WebViewStep::back() +{} + + +bool +WebViewStep::isNextEnabled() const +{ + return true; +} + + +bool +WebViewStep::isBackEnabled() const +{ + return false; +} + + +bool +WebViewStep::isAtBeginning() const +{ + return true; +} + + +bool +WebViewStep::isAtEnd() const +{ + return true; +} + +void WebViewStep::onActivate() +{ + m_view->load(QUrl(m_url)); + m_view->show(); +} + +QList< Calamares::job_ptr > +WebViewStep::jobs() const +{ + return QList< Calamares::job_ptr >(); +} + + +void +WebViewStep::setConfigurationMap( const QVariantMap& configurationMap ) +{ + if ( configurationMap.contains("url") && + configurationMap.value("url").type() == QVariant::String ) + m_url = configurationMap.value("url").toString(); + + if ( configurationMap.contains("prettyName") && + configurationMap.value("prettyName").type() == QVariant::String ) + m_prettyName = configurationMap.value("prettyName").toString(); +} diff --git a/src/modules/webview/WebViewStep.h b/src/modules/webview/WebViewStep.h new file mode 100644 index 000000000..ca7ab14a4 --- /dev/null +++ b/src/modules/webview/WebViewStep.h @@ -0,0 +1,66 @@ +/* === This file is part of Calamares - === + * + * Copyright 2014-2015, Teo Mrnjavac + * + * Calamares is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Calamares is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Calamares. If not, see . + */ + +#ifndef WEBVIEWPLUGIN_H +#define WEBVIEWPLUGIN_H + +#include + +#include "viewpages/ViewStep.h" +#include "PluginDllMacro.h" + +#include + +class QWebView; + +class PLUGINDLLEXPORT WebViewStep : public Calamares::ViewStep +{ + Q_OBJECT + Q_PLUGIN_METADATA( IID "calamares.ViewModule/1.0" ) + + Q_INTERFACES( Calamares::ViewStep ) + +public: + explicit WebViewStep( QObject* parent = nullptr ); + virtual ~WebViewStep(); + + QString prettyName() const override; + + QWidget* widget() override; + + void next() override; + void back() override; + void onActivate() override; + + bool isNextEnabled() const override; + bool isBackEnabled() const override; + + bool isAtBeginning() const override; + bool isAtEnd() const override; + + QList< Calamares::job_ptr > jobs() const override; + + void setConfigurationMap( const QVariantMap& configurationMap ) override; + +private: + QWebView *m_view; + QString m_url; + QString m_prettyName; +}; + +#endif // WEBVIEWPLUGIN_H diff --git a/src/modules/webview/module.desc b/src/modules/webview/module.desc new file mode 100644 index 000000000..006198124 --- /dev/null +++ b/src/modules/webview/module.desc @@ -0,0 +1,7 @@ +# Module metadata file for welcome viewmodule +# Syntax is YAML 1.2 +--- +type: "view" #core or view +name: "webview" #the module name. must be unique and same as the parent directory +interface: "qtplugin" #can be: qtplugin, python, process, ... +load: "libcalamares_viewmodule_webview.so" diff --git a/src/modules/webview/webview.conf b/src/modules/webview/webview.conf new file mode 100644 index 000000000..c4e6568e9 --- /dev/null +++ b/src/modules/webview/webview.conf @@ -0,0 +1,3 @@ +--- +prettyName: "Webview" +url: "https://calamares.io"