diff --git a/src/libcalamaresui/CMakeLists.txt b/src/libcalamaresui/CMakeLists.txt index 90cdb329e..56b2fbfb0 100644 --- a/src/libcalamaresui/CMakeLists.txt +++ b/src/libcalamaresui/CMakeLists.txt @@ -23,6 +23,7 @@ set(calamaresui_SOURCES utils/CalamaresUtilsGui.cpp utils/ImageRegistry.cpp utils/Paste.cpp + utils/QmlDesktopUtils.cpp viewpages/BlankViewStep.cpp viewpages/ExecutionViewStep.cpp viewpages/Slideshow.cpp diff --git a/src/libcalamaresui/utils/Qml.cpp b/src/libcalamaresui/utils/Qml.cpp index b73bf7172..0d6a67250 100644 --- a/src/libcalamaresui/utils/Qml.cpp +++ b/src/libcalamaresui/utils/Qml.cpp @@ -17,12 +17,14 @@ #include "network/Manager.h" #include "utils/Dirs.h" #include "utils/Logger.h" +#include "utils/QmlDesktopUtils.h" #include #include #include #include #include +#include static QDir s_qmlModulesDir( QString( CMAKE_INSTALL_FULL_DATADIR ) + "/qml" ); @@ -246,6 +248,14 @@ registerQmlModels() 0, "Network", []( QQmlEngine*, QJSEngine* ) -> QObject* { return &CalamaresUtils::Network::Manager::instance(); } ); + + + qmlRegisterSingletonType< CalamaresUtils::QmlDesktopUtils >( "org.manjaro.calamares.desktop", + 1, + 0, + "DesktopUtils", + []( QQmlEngine* e, QJSEngine* ) -> QObject* + { return new QmlDesktopUtils( e ); } ); } } diff --git a/src/libcalamaresui/utils/QmlDesktopUtils.cpp b/src/libcalamaresui/utils/QmlDesktopUtils.cpp new file mode 100644 index 000000000..a5ebc5560 --- /dev/null +++ b/src/libcalamaresui/utils/QmlDesktopUtils.cpp @@ -0,0 +1,26 @@ +/* === This file is part of Manjaro's Calamares modules - === + * + * SPDX-FileCopyrightText: 2023 Artem Grinev + * SPDX-License-Identifier: GPL-3.0-or-later + * + * Calamares is Free Software: see the License-Identifier above. + * + */ + +#include "QmlDesktopUtils.h" +#include "utils/Logger.h" + +#include +#include + +CalamaresUtils::QmlDesktopUtils::QmlDesktopUtils( QQmlEngine* parent ) + : QObject( parent ) +{ +} +void +CalamaresUtils::QmlDesktopUtils::openUrl( const QString& url ) +{ + QProcess::execute( + QLatin1String( "/usr/bin/sudo" ), + { QLatin1String( "-u" ), QLatin1String( "#1000" ), QLatin1String( "-E" ), QLatin1String( "xdg-open" ), url } ); +} diff --git a/src/libcalamaresui/utils/QmlDesktopUtils.h b/src/libcalamaresui/utils/QmlDesktopUtils.h new file mode 100644 index 000000000..fc2feab34 --- /dev/null +++ b/src/libcalamaresui/utils/QmlDesktopUtils.h @@ -0,0 +1,30 @@ +/* === This file is part of Manjaro's Calamares modules - === + * + * SPDX-FileCopyrightText: 2023 Artem Grinev + * SPDX-License-Identifier: GPL-3.0-or-later + * + * Calamares is Free Software: see the License-Identifier above. + * + */ + +#ifndef UTILS_QMLDESKTOPUTILS_H +#define UTILS_QMLDESKTOPUTILS_H + +#include +#include +#include +class QQmlEngine; + +namespace CalamaresUtils +{ +class QmlDesktopUtils : public QObject +{ + Q_OBJECT +public: + explicit QmlDesktopUtils( QQmlEngine* parent = 0 ); + + Q_INVOKABLE void openUrl( const QString& url ); +}; + +} // namespace CalamaresUtils +#endif \ No newline at end of file