[libcalamaresui] Add openUrl user session method

This commit is contained in:
Artem Grinev 2023-12-01 19:34:31 +06:00
parent 75ff3ee69c
commit 50918f10b2
4 changed files with 67 additions and 0 deletions

View File

@ -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

View File

@ -17,12 +17,14 @@
#include "network/Manager.h"
#include "utils/Dirs.h"
#include "utils/Logger.h"
#include "utils/QmlDesktopUtils.h"
#include <QByteArray>
#include <QObject>
#include <QQuickItem>
#include <QString>
#include <QVariant>
#include <qqml.h>
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 ); } );
}
}

View File

@ -0,0 +1,26 @@
/* === This file is part of Manjaro's Calamares modules - <https://gitlab.manjaro.org/applications/calamares> ===
*
* SPDX-FileCopyrightText: 2023 Artem Grinev <agrinev@manjaro.org>
* 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 <QProcess>
#include <QQmlEngine>
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 } );
}

View File

@ -0,0 +1,30 @@
/* === This file is part of Manjaro's Calamares modules - <https://gitlab.manjaro.org/applications/calamares> ===
*
* SPDX-FileCopyrightText: 2023 Artem Grinev <agrinev@manjaro.org>
* 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 <QObject>
#include <QString>
#include <QUrl>
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