Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[sailfish-access-control] Add QML plugin. Contributes to JB#47597
Add QML plugin to new qt/ subdirectory and using new packaging. Signed-off-by: Tomi Leppänen <tomi.leppanen@jolla.com>
- Loading branch information
Showing
6 changed files
with
213 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright (c) 2019 Open Mobile Platform LLC. | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2.1 of the License, or (at your option) any later version. | ||
* | ||
* This library 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 | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this library; if not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "accesscontrol.h" | ||
#include "sailfishaccesscontrol.h" | ||
|
||
using namespace Sailfish; | ||
|
||
AccessControl::AccessControl(QObject *parent) | ||
: QObject(parent) | ||
{ | ||
} | ||
|
||
AccessControl::~AccessControl() | ||
{ | ||
} | ||
|
||
bool AccessControl::hasGroup(int uid, const QString groupName) | ||
{ | ||
switch (uid) { | ||
case RealUid: | ||
uid = getuid(); | ||
break; | ||
case EffectiveUid: | ||
uid = geteuid(); | ||
break; | ||
default: | ||
Q_ASSERT_X(uid >= 0, Q_FUNC_INFO, "Uid must be either of enum type Uid or non-negative."); | ||
break; | ||
} | ||
return sailfish_access_control_hasgroup(uid, groupName.toLatin1().data()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright (c) 2019 Open Mobile Platform LLC. | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2.1 of the License, or (at your option) any later version. | ||
* | ||
* This library 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 | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this library; if not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifndef SAILFISH_ACCESSCONTROL_H | ||
#define SAILFISH_ACCESSCONTROL_H | ||
|
||
#include <QObject> | ||
|
||
namespace Sailfish { | ||
|
||
class AccessControl : public QObject | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
explicit AccessControl(QObject *parent = 0); | ||
~AccessControl(); | ||
|
||
enum Uid : int { | ||
RealUid = -1, | ||
EffectiveUid = -2 | ||
}; | ||
Q_ENUM(Uid) | ||
|
||
Q_INVOKABLE bool hasGroup(int uid, const QString groupName); | ||
}; | ||
|
||
} | ||
|
||
#endif // SAILFISH_ACCESSCONTROL_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright (c) 2019 Open Mobile Platform LLC. | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2.1 of the License, or (at your option) any later version. | ||
* | ||
* This library 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 | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this library; if not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include <QQmlExtensionPlugin> | ||
#include <QQmlEngine> | ||
#include <qqml.h> | ||
|
||
#include "accesscontrol.h" | ||
|
||
using namespace Sailfish; | ||
|
||
template <typename T> static QObject *singletonApiCallback(QQmlEngine *engine, QJSEngine *) | ||
{ | ||
return new T(engine); | ||
} | ||
|
||
class SailfishAccessControlPlugin : public QQmlExtensionPlugin | ||
{ | ||
Q_OBJECT | ||
Q_PLUGIN_METADATA(IID "Sailfish.AccessControl" ) | ||
|
||
public: | ||
virtual void registerTypes(const char *uri) | ||
{ | ||
if (QLatin1String(uri) == QLatin1String("Sailfish.AccessControl")) { | ||
qmlRegisterSingletonType<AccessControl>(uri, 1, 0, "AccessControl", singletonApiCallback<AccessControl>); | ||
} | ||
} | ||
}; | ||
|
||
#include "plugin.moc" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module Sailfish.AccessControl | ||
plugin sailfishaccesscontrolplugin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
MODULENAME = Sailfish/AccessControl | ||
DEFINES *= MODULENAME=\"\\\"\"$${MODULENAME}\"\\\"\" | ||
TEMPLATE = lib | ||
TARGET = sailfishaccesscontrolplugin | ||
TARGET = $$qtLibraryTarget($$TARGET) | ||
TARGETPATH = $$[QT_INSTALL_QML]/$$MODULENAME | ||
|
||
QT -= gui | ||
QT += qml | ||
CONFIG += \ | ||
plugin \ | ||
link_pkgconfig \ | ||
hide_symbols \ | ||
c++14 | ||
|
||
PKGCONFIG += sailfishaccesscontrol | ||
|
||
HEADERS += accesscontrol.h | ||
|
||
SOURCES += plugin.cpp \ | ||
accesscontrol.cpp | ||
|
||
import.files = *.qml *.js qmldir plugins.qmltypes | ||
import.path = $$TARGETPATH | ||
target.path = $$TARGETPATH | ||
INSTALLS += target import | ||
|
||
QMAKE_CXXFLAGS += -Wall | ||
OTHER_FILES += qmldir *.qml *.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
Name: sailfish-access-control-qt5 | ||
Summary: Sailfish Access Control QML plugin | ||
Version: 0.0.1 | ||
Release: 1 | ||
License: LGPLv2+ | ||
URL: https://git.sailfishos.org/mer-core/sailfish-access-control | ||
Source0: %{name}-%{version}.tar.bz2 | ||
BuildRequires: pkgconfig(sailfishaccesscontrol) = %{version} | ||
BuildRequires: pkgconfig(Qt5Core) | ||
BuildRequires: pkgconfig(Qt5Qml) | ||
|
||
%description | ||
%{summary}. | ||
|
||
This library should be used to check whether a user | ||
belongs to a group or not. | ||
|
||
%package -n sailfish-access-control-qml-plugin | ||
Summary: Sailfish Access Control QML plugin | ||
Requires: sailfish-access-control = %{version} | ||
Requires(post): /sbin/ldconfig | ||
Requires(postun): /sbin/ldconfig | ||
|
||
%description -n sailfish-access-control-qml-plugin | ||
%{summary}. | ||
|
||
This library should be used to check whether a user | ||
belongs to a group or not. | ||
|
||
%prep | ||
%setup -q -n %{name}-%{version}/qt | ||
|
||
%build | ||
%qmake5 | ||
|
||
%install | ||
rm -rf %{buildroot} | ||
|
||
%qmake5_install | ||
|
||
%post -n sailfish-access-control-qml-plugin -p /sbin/ldconfig | ||
|
||
%postun -n sailfish-access-control-qml-plugin -p /sbin/ldconfig | ||
|
||
%files -n sailfish-access-control-qml-plugin | ||
%defattr(-,root,root,-) | ||
%{_libdir}/qt5/qml/Sailfish/AccessControl |