[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [confine/gilbert] /: Initiate private branch for gilbert
From: Siddharth Sharma <siddharth () redhat ! com>
Date: 2016-03-30 20:29:47
Message-ID: E1alMkN-00047e-91 () scm ! kde ! org
[Download RAW message or body]
Git commit 3ced1f02c40c40c23ef5d37bb19d3fe46cdfa293 by Siddharth Sharma.
Committed on 30/03/2016 at 20:29.
Pushed by siddharthsharma into branch 'gilbert'.
Initiate private branch for gilbert
A +68 -0 CMakeLists.txt
A +46 -0 autotests/CMakeLists.txt
A +74 -0 autotests/configxttest.cpp [License: GPL (v2/3)]
A +36 -0 autotests/configxttest.h [License: GPL (v2/3)]
A +31 -0 autotests/data/file1.kcfg
A +2 -0 autotests/data/kf5-profile/kdeglobals
A +2 -0 autotests/data/kjotsrc
A +71 -0 autotests/immutabletest.cpp [License: GPL (v2/3)]
A +35 -0 autotests/immutabletest.h [License: GPL (v2/3)]
A +86 -0 autotests/userprofilemanagertest.cpp [License: GPL (v2/3)]
A +39 -0 autotests/userprofilemanagertest.h [License: GPL (v2/3)]
A +77 -0 autotests/usertest.cpp [License: GPL (v2/3)]
A +38 -0 autotests/usertest.h [License: GPL (v2/3)]
A +48 -0 docs/actions.kiosk
A +42 -0 src/configurationinfomanager.cpp [License: GPL (v2/3)]
A +40 -0 src/configurationinfomanager.h [License: GPL (v2/3)]
A +109 -0 src/configxtreader.cpp [License: GPL (v2/3)]
A +46 -0 src/configxtreader.h [License: GPL (v2/3)]
A +52 -0 src/confineconfiguration.cpp [License: GPL (v2/3)]
A +45 -0 src/confineconfiguration.h [License: GPL (v2/3)]
A +54 -0 src/kconfigfileinfo.cpp [License: GPL (v2/3)]
A +43 -0 src/kconfigfileinfo.h [License: GPL (v2/3)]
A +118 -0 src/kconfigimmutable.cpp [License: GPL (v2/3)]
A +40 -0 src/kconfigimmutable.h [License: GPL (v2/3)]
A +53 -0 src/kentryinfo.cpp [License: GPL (v2/3)]
A +45 -0 src/kentryinfo.h [License: GPL (v2/3)]
A +53 -0 src/kgroupinfo.cpp [License: GPL (v2/3)]
A +47 -0 src/kgroupinfo.h [License: GPL (v2/3)]
A +64 -0 src/main.cpp [License: GPL (v2/3)]
A +67 -0 src/mainwindow.cpp [License: GPL (v2/3)]
A +48 -0 src/mainwindow.h [License: GPL (v2/3)]
A +68 -0 src/mainwindow.ui
A +105 -0 src/profile.cpp [License: GPL (v2/3)]
A +53 -0 src/profile.h [License: GPL (v2/3)]
A +157 -0 src/user.cpp [License: GPL (v2/3)]
A +56 -0 src/user.h [License: GPL (v2/3)]
A +156 -0 src/userprofilemanager.cpp [License: GPL (v2/3)]
A +51 -0 src/userprofilemanager.h [License: GPL (v2/3)]
http://commits.kde.org/confine/3ced1f02c40c40c23ef5d37bb19d3fe46cdfa293
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..cbf7e16
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,68 @@
+project (confine)
+
+#1
+cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
+set(QT_MIN_VERSION "5.3.0")
+set(KF5_MIN_VERSION "5.2.0")
+
+#2
+find_package(ECM REQUIRED NO_MODULE)
+set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR} \
${CMAKE_CURRENT_SOURCE_DIR}/cmake) +
+include(KDEInstallDirs)
+include(KDECMakeSettings)
+include(KDECompilerSettings)
+include(FeatureSummary)
+
+# Find Qt modules
+find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS
+ Core # QCommandLineParser, QStringLiteral
+ Widgets # QApplication
+)
+
+# Find KDE modules
+find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS
+ CoreAddons # KAboutData
+ I18n # KLocalizedString
+ XmlGui # KXmlGuiWindow
+ Config
+)
+
+feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES)
+
+set(confineBase_SRCS
+ ${CMAKE_SOURCE_DIR}/src/profile.cpp
+ ${CMAKE_SOURCE_DIR}/src/userprofilemanager.cpp
+ ${CMAKE_SOURCE_DIR}/src/user.cpp
+ ${CMAKE_SOURCE_DIR}/src/configxtreader.cpp
+ ${CMAKE_SOURCE_DIR}/src/kgroupinfo.cpp
+ ${CMAKE_SOURCE_DIR}/src/kentryinfo.cpp
+ ${CMAKE_SOURCE_DIR}/src/kconfigfileinfo.cpp
+ ${CMAKE_SOURCE_DIR}/src/confineconfiguration.cpp
+ ${CMAKE_SOURCE_DIR}/src/configurationinfomanager.cpp
+ ${CMAKE_SOURCE_DIR}/src/kconfigimmutable.cpp
+)
+
+set(confineUI_SRCS
+ ${CMAKE_SOURCE_DIR}/src/main.cpp
+ ${CMAKE_SOURCE_DIR}/src/mainwindow.cpp
+)
+
+qt5_wrap_ui(confine_UI ${CMAKE_SOURCE_DIR}/src/mainwindow.ui)
+
+add_subdirectory(autotests)
+
+# just plain add_executable
+add_executable(confine ${confineBase_SRCS} ${confineUI_SRCS} ${confine_UI})
+
+# module-based linking
+target_link_libraries(confine
+ Qt5::Widgets
+ KF5::CoreAddons
+ KF5::I18n
+ KF5::XmlGui
+ KF5::ConfigCore
+ KF5::ConfigGui
+)
+
+install(TARGETS confine ${INSTALL_TARGETS_DEFAULT_ARGS})
diff --git a/autotests/CMakeLists.txt b/autotests/CMakeLists.txt
new file mode 100644
index 0000000..daabba7
--- /dev/null
+++ b/autotests/CMakeLists.txt
@@ -0,0 +1,46 @@
+enable_testing()
+include(ECMAddTests)
+include(ECMMarkAsTest)
+
+
+find_package(Qt5Test ${REQUIRED_QT_VERSION} CONFIG QUIET)
+
+if(NOT Qt5Test_FOUND)
+ message(STATUS "Qt5Test not found, autotests will not be built.")
+ return()
+endif()
+
+include_directories("${CMAKE_SOURCE_DIR}/src")
+
+add_library(autotests STATIC ${confineBase_SRCS} )
+
+target_link_libraries(autotests
+ Qt5::Widgets
+ KF5::CoreAddons
+ KF5::I18n
+ KF5::XmlGui
+ KF5::ConfigCore
+ KF5::ConfigGui
+)
+
+ecm_mark_as_test(autotests)
+
+ecm_add_tests(
+ configxttest.cpp
+ LINK_LIBRARIES Qt5::Test autotests
+)
+
+ecm_add_tests(
+ userprofilemanagertest.cpp
+ LINK_LIBRARIES Qt5::Test autotests
+)
+
+ecm_add_tests(
+ usertest.cpp
+ LINK_LIBRARIES Qt5::Test autotests
+)
+
+ecm_add_tests(
+ immutabletest.cpp
+ LINK_LIBRARIES Qt5::Test autotests
+)
diff --git a/autotests/configxttest.cpp b/autotests/configxttest.cpp
new file mode 100644
index 0000000..b9f423a
--- /dev/null
+++ b/autotests/configxttest.cpp
@@ -0,0 +1,74 @@
+/*
+ * <one line to give the library's name and an idea of what it does.>
+ * Copyright 2016 Gilbert Assaf <gassaf@gmx.de>
+ *
+ * This program 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 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include "configxttest.h"
+#include "kentryinfo.h"
+#include "kgroupinfo.h"
+#include "kconfigfileinfo.h"
+#include "confineconfiguration.h"
+#include "configxtreader.h"
+#include "configurationinfomanager.h"
+
+#include <QtTest>
+#include <KConfig>
+#include <KConfigGroup>
+#include <ksharedconfig.h>
+#include <kconfigbase.h>
+#include <kconfiggroup.h>
+
+QTEST_MAIN(ConfigXTTest)
+
+void ConfigXTTest::testConfig()
+{
+ ConfineConfiguration* confineConfiguration = new ConfineConfiguration();
+ confineConfiguration->setConfigXTDir(QDir::currentPath() + \
QLatin1String("/data")); + qApp->setProperty("confineConfiguration", \
QVariant::fromValue<ConfineConfiguration*>(confineConfiguration)); +
+ ConfigXTReader configReader;
+ QHash<QString, KConfigFileInfo> infos = \
configReader.getConfigurationFilesInfos(); +
+ QVERIFY(infos.contains(QLatin1String("kjotsrc")));
+ QCOMPARE(infos.size(), 1);
+ KConfigFileInfo ki = infos.value(QLatin1String("kjotsrc"));
+ KGroupInfo gi = ki.getKGroupInfo(QLatin1String("kjots"));
+ QCOMPARE(gi.getName(), QLatin1String("kjots"));
+
+ KEntryInfo kei = gi.getKEntryInfo(QLatin1String("OpenBooks"));
+
+ QCOMPARE(kei.getLabel(), QLatin1String("All books that are opened."));
+
+}
+
+void ConfigXTTest::testInfoManager()
+{
+ KSharedConfigPtr config = KSharedConfig::openConfig(QDir::currentPath() + \
QLatin1String("/data/kjotsrc")); + KConfigGroup grp(config, "kjots");
+ ConfigurationInfoManager confInfo;
+ QCOMPARE(confInfo.getInfo(grp, QLatin1String("CurrentBook")), QLatin1String("The \
book currently opened.")); + QCOMPARE(confInfo.getInfo(grp, \
QLatin1String("Height")), QLatin1String("Height of the main window.")); + \
QCOMPARE(confInfo.getInfo(grp, QLatin1String("SplitterSizes")), QLatin1String("How \
the main window is divided.")); + QCOMPARE(confInfo.getInfo(grp, \
QLatin1String("DoesNotExist")), QString()); +
+}
+
+
+#include "configxttest.moc"
diff --git a/autotests/configxttest.h b/autotests/configxttest.h
new file mode 100644
index 0000000..665125d
--- /dev/null
+++ b/autotests/configxttest.h
@@ -0,0 +1,36 @@
+/*
+ * <one line to give the library's name and an idea of what it does.>
+ * Copyright 2016 Gilbert Assaf <gassaf@gmx.de>
+ *
+ * This program 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 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef CONFIGXTTEST_H
+#define CONFIGXTTEST_H
+
+#include <QObject>
+
+class ConfigXTTest : public QObject
+{
+ Q_OBJECT
+private slots:
+ void testConfig();
+ void testInfoManager();
+};
+
+#endif // CONFIGXTTEST_H
diff --git a/autotests/data/file1.kcfg b/autotests/data/file1.kcfg
new file mode 100644
index 0000000..e2f27ff
--- /dev/null
+++ b/autotests/data/file1.kcfg
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0
+ http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
+ <include>kglobalsettings.h</include>
+ <kcfgfile name="kjotsrc"/>
+ <group name="kjots">
+ <entry name="SplitterSizes" type="IntList">
+ <label>How the main window is divided.</label>
+ </entry>
+ <entry name="Width" type="Int">
+ <label>Width of the main window.</label>
+ <default>600</default>
+ </entry>
+ <entry name="Height" type="Int">
+ <label>Height of the main window.</label>
+ <default>400</default>
+ </entry>
+ <entry name="OpenBooks" type="StringList">
+ <label>All books that are opened.</label>
+ </entry>
+ <entry name="CurrentBook" type="String">
+ <label>The book currently opened.</label>
+ </entry>
+ <entry name="Font" type="Font">
+ <label>The font used to display the contents of books.</label>
+ <default code="true">KGlobalSettings::generalFont()</default>
+ </entry>
+ </group>
+</kcfg>
\ No newline at end of file
diff --git a/autotests/data/kf5-profile/kdeglobals \
b/autotests/data/kf5-profile/kdeglobals new file mode 100644
index 0000000..d14e23c
--- /dev/null
+++ b/autotests/data/kf5-profile/kdeglobals
@@ -0,0 +1,2 @@
+[KDE Action Restrictions]
+logout=false
diff --git a/autotests/data/kjotsrc b/autotests/data/kjotsrc
new file mode 100644
index 0000000..4014f21
--- /dev/null
+++ b/autotests/data/kjotsrc
@@ -0,0 +1,2 @@
+[kjots]
+CurrentBook=book
\ No newline at end of file
diff --git a/autotests/immutabletest.cpp b/autotests/immutabletest.cpp
new file mode 100644
index 0000000..b26c791
--- /dev/null
+++ b/autotests/immutabletest.cpp
@@ -0,0 +1,71 @@
+/*
+ * <one line to give the library's name and an idea of what it does.>
+ * Copyright 2016 Gilbert Assaf <gassaf@gmx.de>
+ *
+ * This program 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 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include "immutabletest.h"
+#include "kconfigimmutable.h"
+
+#include <KConfig>
+#include <QtTest>
+
+QTEST_MAIN(ImmutableTest)
+
+void ImmutableTest::setImmutable()
+{
+ QFile testConfig(QDir::currentPath() + \
QLatin1String("/data/immutableTestConfig")); + \
QVERIFY(testConfig.open(QIODevice::WriteOnly | QIODevice::Text)); +
+ QTextStream out(&testConfig);
+ out << "[Group1]\n";
+ out << "bar=false\n";
+ out << "foo[$i]=0\n";
+ out << "foobar=test\n";
+ out << "\n";
+ out << "[Group2]\n";
+ out << "bar=true\n";
+ out << "foo=1\n";
+ out << "foobar=new\n";
+ out.flush();
+
+ testConfig.close();
+
+ KConfig config(QDir::currentPath() + \
QLatin1String("/data/immutableTestConfig")); + KConfigGroup grp(&config, \
"Group1"); + QVERIFY(!grp.isImmutable());
+ KConfigGroup grpNew = KConfigImmutable::setGroupImmutable(grp, true);
+ QVERIFY(grpNew.isImmutable());
+ grpNew = KConfigImmutable::setGroupImmutable(grp, false);
+ QVERIFY(!grpNew.isImmutable());
+
+ QString entry("bar");
+ KConfigGroup grpEntryTest(&config, "Group2");
+ QVERIFY(!grpEntryTest.isEntryImmutable(entry));
+ KConfigGroup grpEntryTestNew = KConfigImmutable::setEntryImmutable(grpEntryTest, \
entry, true); + QVERIFY(grpEntryTestNew.isEntryImmutable(entry));
+
+ grpEntryTestNew = KConfigImmutable::setEntryImmutable(grpEntryTestNew, entry, \
false); + QVERIFY(!grpEntryTestNew.isEntryImmutable(entry));
+
+
+ QVERIFY(testConfig.remove());
+}
+
+#include "immutabletest.moc"
diff --git a/autotests/immutabletest.h b/autotests/immutabletest.h
new file mode 100644
index 0000000..226c292
--- /dev/null
+++ b/autotests/immutabletest.h
@@ -0,0 +1,35 @@
+/*
+ * <one line to give the library's name and an idea of what it does.>
+ * Copyright 2016 Gilbert Assaf <gassaf@gmx.de>
+ *
+ * This program 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 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef IMMUTABLETEST_H
+#define IMMUTABLETEST_H
+
+#include <QObject>
+
+class ImmutableTest : public QObject
+{
+ Q_OBJECT
+private slots:
+ void setImmutable();
+};
+
+#endif // IMMUTABLETEST_H
diff --git a/autotests/userprofilemanagertest.cpp \
b/autotests/userprofilemanagertest.cpp new file mode 100644
index 0000000..5f0cccc
--- /dev/null
+++ b/autotests/userprofilemanagertest.cpp
@@ -0,0 +1,86 @@
+/*
+ * <one line to give the library's name and an idea of what it does.>
+ * Copyright 2016 Gilbert Assaf <gassaf@gmx.de>
+ *
+ * This program 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 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include "userprofilemanagertest.h"
+#include "userprofilemanager.h"
+#include "confineconfiguration.h"
+
+#include <QtTest>
+
+QTEST_MAIN(UserProfileManagerTest)
+
+void UserProfileManagerTest::testInitialization()
+{
+ ConfineConfiguration* confineConfiguration = new ConfineConfiguration();
+ confineConfiguration->setPasswdPath(QDir::currentPath() + \
QLatin1String("/data/passwd")); + qApp->setProperty("confineConfiguration", \
QVariant::fromValue<ConfineConfiguration*>(confineConfiguration)); + //create \
temporary test passwd file + QFile tmpFile(QDir::currentPath() + \
QLatin1String("/data/passwd")); + QVERIFY(tmpFile.open(QIODevice::WriteOnly | \
QIODevice::Text)); +
+ QTextStream out(&tmpFile);
+ out << "kde-test:x:1001:1001::";
+ out << QDir::currentPath() + QLatin1String("/data");
+ out << ":/bin/bash\n";
+
+ out.flush();
+
+ //create temporary test .profile file
+ QFile tmpFileProfile(QDir::currentPath() + QLatin1String("/data/.profile"));
+ QVERIFY(tmpFileProfile.open(QIODevice::WriteOnly | QIODevice::Text));
+
+ QTextStream out2(&tmpFileProfile);
+ out2 << "export XDG_CONFIG_DIRS=";
+ out2 << QDir::currentPath() + QLatin1String("/data/kf5-profile");
+ out2 << ":/etc/xdg/\n";
+
+ out2.flush();
+
+ //start testing
+ UserProfileManager um;
+ QCOMPARE(um.getUserNames().at(0), QLatin1String("kde-test"));
+
+ QVERIFY(um.getProfileNames().contains(QDir::currentPath() + \
QLatin1String("/data/kf5-profile/"))); + \
QVERIFY(um.getProfileNames().contains(QLatin1String("/etc/xdg/"))); +
+ QCOMPARE(um.getProfilesfromUser(QLatin1String("kde-test")).at(0).getDirectory(), \
QDir::currentPath() + QLatin1String("/data/kf5-profile/")); + \
QCOMPARE(um.getProfilesfromUser(QLatin1String("kde-test")).at(1).getDirectory(), \
QLatin1String("/etc/xdg/")); +
+ profileToTest = um.getProfilesfromUser(QLatin1String("kde-test")).at(0);
+
+ tmpFileProfile.remove();
+ tmpFile.remove();
+}
+
+void UserProfileManagerTest::testProfile()
+{
+ QMap<QString, QString> map = profileToTest.getKDEActionRestrictions();
+ QCOMPARE(map.value("logout"), QLatin1String("false"));
+ QCOMPARE(map.value("action/file_open"), QString());
+
+ QCOMPARE(profileToTest.getConfigFiles().size(), 1);
+ QCOMPARE(profileToTest.getConfigFiles().at(0), QLatin1String("kdeglobals"));
+
+}
+
+
+#include "userprofilemanagertest.moc"
diff --git a/autotests/userprofilemanagertest.h b/autotests/userprofilemanagertest.h
new file mode 100644
index 0000000..a8ad258
--- /dev/null
+++ b/autotests/userprofilemanagertest.h
@@ -0,0 +1,39 @@
+/*
+ * <one line to give the library's name and an idea of what it does.>
+ * Copyright 2016 Gilbert Assaf <gassaf@gmx.de>
+ *
+ * This program 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 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef USERPROFILEMANAGERTEST_H
+#define USERPROFILEMANAGERTEST_H
+
+#include "profile.h"
+#include <QObject>
+
+class UserProfileManagerTest : public QObject
+{
+ Q_OBJECT
+private slots:
+ void testInitialization();
+ void testProfile();
+private:
+ Profile profileToTest;
+};
+
+#endif // USERPROFILEMANAGERTEST_H
diff --git a/autotests/usertest.cpp b/autotests/usertest.cpp
new file mode 100644
index 0000000..256bc0d
--- /dev/null
+++ b/autotests/usertest.cpp
@@ -0,0 +1,77 @@
+/*
+ * <one line to give the library's name and an idea of what it does.>
+ * Copyright 2016 Gilbert Assaf <gassaf@gmx.de>
+ *
+ * This program 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 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include "usertest.h"
+#include "user.h"
+#include "profile.h"
+
+#include <QtTest>
+
+QTEST_MAIN(UserTest)
+
+
+void UserTest::testUser()
+{
+ User user(QLatin1String("kde-test"), QLatin1String("/bin/bash"), \
QDir::currentPath() + QLatin1String("/data/")); + QString \
envFilePath(QDir::currentPath() + QLatin1String("/data/.profile")); +
+ Profile profile1(QLatin1String("/etc/kf5-profile"));
+ Profile profile2(QLatin1String("/etc/xdg"));
+ Profile profile3(QLatin1String("/etc/test-profile"));
+
+ user.addProfile(profile1);
+
+ user.setEnvironmentVariableFile(QLatin1String(".profile"));
+ user.save();
+
+ QCOMPARE(readAllEnvFile(envFilePath), QLatin1String("export \
XDG_CONFIG_DIRS=/etc/kf5-profile\n")); +
+ user.clearProfiles();
+ QFile::remove(QDir::currentPath() + QLatin1String("/data/.profile"));
+
+
+ user.addProfile(profile3);
+ user.addProfile(profile2);
+ user.addProfile(profile1);
+ user.save();
+ QCOMPARE(readAllEnvFile(envFilePath), QLatin1String("export \
XDG_CONFIG_DIRS=/etc/test-profile:/etc/xdg:/etc/kf5-profile\n")); + \
user.setXDG_CONFIG_HOME(QLatin1String("/etc/users")); + user.save();
+ QCOMPARE(readAllEnvFile(envFilePath), QLatin1String("export \
XDG_CONFIG_DIRS=/etc/test-profile:/etc/xdg:/etc/kf5-profile\nexport \
XDG_CONFIG_HOME=/etc/users\n")); + QFile::remove(QDir::currentPath() + \
QLatin1String("/data/.profile")); +
+}
+
+QString UserTest::readAllEnvFile(const QString& fileName)
+{
+ QFile file(fileName);
+ if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
+ return QString();
+
+ QString result(file.readAll());
+
+ return result;
+
+}
+
+
+#include "usertest.moc"
diff --git a/autotests/usertest.h b/autotests/usertest.h
new file mode 100644
index 0000000..c6fcabc
--- /dev/null
+++ b/autotests/usertest.h
@@ -0,0 +1,38 @@
+/*
+ * <one line to give the library's name and an idea of what it does.>
+ * Copyright 2016 Gilbert Assaf <gassaf@gmx.de>
+ *
+ * This program 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 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef USERTEST_H
+#define USERTEST_H
+
+#include <QObject>
+
+class UserTest : public QObject
+{
+ Q_OBJECT
+private slots:
+ void testUser();
+private:
+ QString readAllEnvFile(const QString& fileName);
+
+};
+
+#endif // USERTEST_H
diff --git a/docs/actions.kiosk b/docs/actions.kiosk
new file mode 100644
index 0000000..9560b54
--- /dev/null
+++ b/docs/actions.kiosk
@@ -0,0 +1,48 @@
+A List of all Actions, which are being checked for authorization via KAuthorized. \
This list was extracted from all KDE projects. +
+[KDE Action Restrictions]
+movable_toolbars
+plasma-desktop/add_activities
+lineedit_text_completion
+run_desktop_files
+warn_unwritable_config
+shell_access
+plasma/allow_configure_when_locked
+plasma-desktop/add_activities
+skip_drm
+logout
+run_command
+action/kdesktop_rmb
+plasma/plasmashell/unlockedDesktop
+plasma-desktop/scripting_console
+action/menuedit
+action/openwith
+action/editfiletype
+action/logout
+action/lock_screen
+action/start_new_session
+action/switch_user
+action/help_contents
+action/help_whats_this
+action/help_report_bug
+action/switch_application_language
+action/help_about_app
+action/help_about_kde
+action/options_show_toolbar
+action/allow_downloading
+action/bookmarks
+action/switch_application_language
+action/plasma/containment_actions
+action/shell_access
+action/editable_desktop_icons
+action/bookmarks
+action/kwin_rmb
+action/show_lancelot
+action/run_command
+action/lock widgets
+
+
+[KDE Control Module Restrictions]
+filebehavior
+khtml_behavior
+kde-kwinoptions.desktop
diff --git a/src/configurationinfomanager.cpp b/src/configurationinfomanager.cpp
new file mode 100644
index 0000000..1101284
--- /dev/null
+++ b/src/configurationinfomanager.cpp
@@ -0,0 +1,42 @@
+/*
+ * <one line to give the library's name and an idea of what it does.>
+ * Copyright 2016 Gilbert Assaf <gassaf@gmx.de>
+ *
+ * This program 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 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include "configurationinfomanager.h"
+#include "configxtreader.h"
+
+#include <KConfig>
+#include <QFileInfo>
+
+ConfigurationInfoManager::ConfigurationInfoManager()
+{
+ ConfigXTReader configReader;
+ configurationFilesInfos = configReader.getConfigurationFilesInfos();
+}
+
+QString ConfigurationInfoManager::getInfo(const KConfigGroup& grp, const QString& \
entryKey) +{
+ QFileInfo configPath(grp.config()->name());
+ KConfigFileInfo kConfigFileInfo = \
configurationFilesInfos.value(configPath.fileName()); + KGroupInfo kGroupInfo = \
kConfigFileInfo.getKGroupInfo(grp.name()); + KEntryInfo kEntryInfo = \
kGroupInfo.getKEntryInfo(entryKey); + return kEntryInfo.getLabel();
+}
diff --git a/src/configurationinfomanager.h b/src/configurationinfomanager.h
new file mode 100644
index 0000000..738a491
--- /dev/null
+++ b/src/configurationinfomanager.h
@@ -0,0 +1,40 @@
+/*
+ * <one line to give the library's name and an idea of what it does.>
+ * Copyright 2016 Gilbert Assaf <gassaf@gmx.de>
+ *
+ * This program 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 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef CONFIGURATIONINFOMANAGER_H
+#define CONFIGURATIONINFOMANAGER_H
+
+#include "kconfigfileinfo.h"
+
+#include <kconfiggroup.h>
+
+class ConfigurationInfoManager
+{
+public:
+ ConfigurationInfoManager();
+ QString getInfo(const KConfigGroup& grp, const QString& entryKey);
+
+private:
+ QHash<QString, KConfigFileInfo> configurationFilesInfos;
+};
+
+#endif // CONFIGURATIONINFOMANAGER_H
diff --git a/src/configxtreader.cpp b/src/configxtreader.cpp
new file mode 100644
index 0000000..8392f56
--- /dev/null
+++ b/src/configxtreader.cpp
@@ -0,0 +1,109 @@
+/*
+ * <one line to give the library's name and an idea of what it does.>
+ * Copyright 2016 Gilbert Assaf <gassaf@gmx.de>
+ *
+ * This program 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 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include "configxtreader.h"
+#include "kgroupinfo.h"
+#include "kentryinfo.h"
+#include "confineconfiguration.h"
+
+#include <QApplication>
+#include <QFile>
+#include <QDir>
+#include <QDomDocument>
+
+ConfigXTReader::ConfigXTReader()
+{
+ ConfineConfiguration* cf = \
qApp->property("confineConfiguration").value<ConfineConfiguration*>(); + QDir \
profileDir(cf->getConfigXTDir()); + QStringList nameFilter("*.kcfg");
+ QStringList allConfigFiles = profileDir.entryList(nameFilter);
+ for (int i = 0; i < allConfigFiles.size(); i++) {
+ parseKcfgFile(cf->getConfigXTDir() + allConfigFiles.at(i));
+ }
+
+}
+
+ConfigXTReader::~ConfigXTReader()
+{
+
+}
+
+void ConfigXTReader::parseKcfgFile(const QString& filePath)
+{
+ QDomDocument doc;
+ QFile file(filePath);
+ if (!file.open(QIODevice::ReadOnly) || !doc.setContent(&file))
+ return;
+
+ QDomNodeList rates = doc.elementsByTagName("kcfg");
+
+ QDomNodeList liste = rates.item(0).childNodes();
+ QString configFileName;
+
+ for (int i = 0; i < liste.size(); i++) {
+ QDomNode n = liste.item(i);
+ if (n.isElement()) {
+ QDomElement currElement = n.toElement();
+ if (currElement.tagName() == QLatin1String("kcfgfile")) {
+ QDomNode configFileNameAttribut = \
currElement.attributes().namedItem("name"); + configFileName = \
configFileNameAttribut.toAttr().value(); + }
+
+ if (currElement.tagName() == QLatin1String("group")) {
+ parseGroupElement(currElement, configFileName);
+ }
+
+ }
+ }
+}
+
+void ConfigXTReader::parseGroupElement(QDomElement& grpElement, QString& \
configFileName) +{
+ QDomNodeList entries = grpElement.childNodes();
+ QString grpName = grpElement.attributes().namedItem("name").toAttr().value();
+ KGroupInfo kGrpInfo(grpName);
+ KConfigFileInfo kConfigInfo(configFileName);
+ if (configurationFilesInfos.contains(configFileName)) {
+ kConfigInfo = configurationFilesInfos.value(configFileName);
+ }
+ for (int j = 0; j < entries.size(); j++) {
+ QDomNode entry = entries.item(j);
+ QDomNode entryName = entry.attributes().namedItem("name");
+ QDomNode entryType = entry.attributes().namedItem("type");
+ QDomElement label = entry.firstChildElement("label");
+ QString name(entryName.toAttr().value());
+ QString type(entryType.toAttr().value());
+ QString infoLabel(label.text());
+ KEntryInfo kInfo(name, type, infoLabel);
+ kGrpInfo.addKEntryInfo(kInfo);
+ }
+ kConfigInfo.addKGroupInfo(kGrpInfo);
+ if (!configurationFilesInfos.contains(configFileName)) {
+ configurationFilesInfos.insert(configFileName, kConfigInfo);
+ }
+}
+
+QHash< QString, KConfigFileInfo > ConfigXTReader::getConfigurationFilesInfos()
+{
+ return configurationFilesInfos;
+}
+
diff --git a/src/configxtreader.h b/src/configxtreader.h
new file mode 100644
index 0000000..5c14246
--- /dev/null
+++ b/src/configxtreader.h
@@ -0,0 +1,46 @@
+/*
+ * <one line to give the library's name and an idea of what it does.>
+ * Copyright 2016 Gilbert Assaf <gassaf@gmx.de>
+ *
+ * This program 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 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef CONFIGXTREADER_H
+#define CONFIGXTREADER_H
+
+#include "kconfigfileinfo.h"
+
+#include <QFile>
+#include <QDomElement>
+
+class ConfigXTReader
+{
+public:
+ ConfigXTReader();
+ ~ConfigXTReader();
+ QHash<QString, KConfigFileInfo> getConfigurationFilesInfos();
+
+private:
+ QHash<QString, KConfigFileInfo> configurationFilesInfos;
+
+ void parseKcfgFile(const QString& filePath);
+ void parseGroupElement(QDomElement& grpElement, QString& configFileName);
+
+};
+
+#endif // CONFIGXTREADER_H
diff --git a/src/confineconfiguration.cpp b/src/confineconfiguration.cpp
new file mode 100644
index 0000000..91d3139
--- /dev/null
+++ b/src/confineconfiguration.cpp
@@ -0,0 +1,52 @@
+/*
+ * <one line to give the library's name and an idea of what it does.>
+ * Copyright 2016 Gilbert Assaf <gassaf@gmx.de>
+ *
+ * This program 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 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include "confineconfiguration.h"
+
+ConfineConfiguration::ConfineConfiguration() : passwdPath("/etc/passwd"), \
configxtDir("/usr/share/config.kcfg/") +{
+
+}
+
+QString ConfineConfiguration::getPasswdPath()
+{
+ return passwdPath;
+}
+
+QString ConfineConfiguration::getConfigXTDir()
+{
+ return configxtDir;
+}
+
+void ConfineConfiguration::setConfigXTDir(const QString& configDir)
+{
+ configxtDir = configDir;
+ if(!configxtDir.endsWith(QLatin1Char('/'))) {
+ configxtDir += QLatin1Char('/');
+ }
+
+}
+
+void ConfineConfiguration::setPasswdPath(const QString& passwd)
+{
+ passwdPath = passwd;
+}
diff --git a/src/confineconfiguration.h b/src/confineconfiguration.h
new file mode 100644
index 0000000..adc4352
--- /dev/null
+++ b/src/confineconfiguration.h
@@ -0,0 +1,45 @@
+/*
+ * <one line to give the library's name and an idea of what it does.>
+ * Copyright 2016 Gilbert Assaf <gassaf@gmx.de>
+ *
+ * This program 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 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef CONFINECONFIGURATION_H
+#define CONFINECONFIGURATION_H
+
+#include <QString>
+#include <QMetaType>
+
+class ConfineConfiguration
+{
+public:
+ ConfineConfiguration();
+ void setConfigXTDir(const QString& configDir);
+ void setPasswdPath(const QString& passwd);
+ QString getPasswdPath();
+ QString getConfigXTDir();
+
+private:
+ QString passwdPath;
+ QString configxtDir;
+
+};
+Q_DECLARE_METATYPE(ConfineConfiguration*);
+
+#endif // CONFINECONFIGURATION_H
diff --git a/src/kconfigfileinfo.cpp b/src/kconfigfileinfo.cpp
new file mode 100644
index 0000000..463cb26
--- /dev/null
+++ b/src/kconfigfileinfo.cpp
@@ -0,0 +1,54 @@
+/*
+ * <one line to give the library's name and an idea of what it does.>
+ * Copyright 2016 Gilbert Assaf <gassaf@gmx.de>
+ *
+ * This program 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 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include "kconfigfileinfo.h"
+
+KConfigFileInfo::KConfigFileInfo()
+{
+
+}
+
+KConfigFileInfo::KConfigFileInfo(QString& cfgName) : configName(cfgName)
+{
+
+}
+
+
+KConfigFileInfo::~KConfigFileInfo()
+{
+
+}
+
+KGroupInfo KConfigFileInfo::getKGroupInfo(const QString& name)
+{
+ return groups.value(name);
+}
+
+void KConfigFileInfo::addKGroupInfo(KGroupInfo& kGroupInfo)
+{
+ groups.insert(kGroupInfo.getName(), kGroupInfo);
+}
+
+QString KConfigFileInfo::getName() const
+{
+ return configName;
+}
diff --git a/src/kconfigfileinfo.h b/src/kconfigfileinfo.h
new file mode 100644
index 0000000..d9865eb
--- /dev/null
+++ b/src/kconfigfileinfo.h
@@ -0,0 +1,43 @@
+/*
+ * <one line to give the library's name and an idea of what it does.>
+ * Copyright 2016 Gilbert Assaf <gassaf@gmx.de>
+ *
+ * This program 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 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef KCONFIGFILEINFO_H
+#define KCONFIGFILEINFO_H
+
+#include "kgroupinfo.h"
+
+class KConfigFileInfo
+{
+public:
+ KConfigFileInfo();
+ explicit KConfigFileInfo(QString& cfgName);
+ ~KConfigFileInfo();
+ void addKGroupInfo(KGroupInfo& kGroupInfo);
+ QString getName() const;
+ KGroupInfo getKGroupInfo(const QString& name);
+
+private:
+ QString configName;
+ QHash<QString, KGroupInfo> groups;
+};
+
+#endif // KCONFIGFILEINFO_H
diff --git a/src/kconfigimmutable.cpp b/src/kconfigimmutable.cpp
new file mode 100644
index 0000000..32b04b7
--- /dev/null
+++ b/src/kconfigimmutable.cpp
@@ -0,0 +1,118 @@
+/*
+ * <one line to give the library's name and an idea of what it does.>
+ * Copyright 2016 Gilbert Assaf <gassaf@gmx.de>
+ *
+ * This program 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 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include "kconfigimmutable.h"
+
+#include <QDir>
+#include <KConfig>
+#include <QTextStream>
+
+KConfigGroup KConfigImmutable::setGroupImmutable(KConfigGroup& grp, bool immutable)
+{
+ QFile fileOut(QDir::currentPath() + QLatin1String("/temporary_config"));
+ createSubsetConfigFile(fileOut, grp);
+ if (!fileOut.open(QIODevice::ReadOnly | QIODevice::Text))
+ return grp;
+
+ QString searchString;
+ QString replaceString;
+
+ if (immutable) { //add [$i]
+ searchString = QLatin1Char('[') + grp.name() + QLatin1String("]\n");
+ replaceString = QLatin1Char('[') + grp.name() + QLatin1String("][$i]\n");
+ } else { //remove [$i]
+ searchString = replaceString = QLatin1Char('[') + grp.name() + \
QLatin1String("][$i]\n"); + replaceString = QLatin1Char('[') + grp.name() + \
QLatin1String("]\n"); + }
+
+ grp = setImmutableStatus(fileOut, searchString, replaceString, grp);
+ if (!immutable) {
+ //EVERY entry has to be manualy reset to mutable, just setting the group to \
mutable, doesnot reset the entries + QMap<QString, QString> entriesMap = \
grp.entryMap(); + QList<QString> entryList = entriesMap.keys();
+ Q_FOREACH(const QString & entryName, entryList) {
+ grp = setEntryImmutable(grp, entryName, false);
+ }
+ }
+ return grp;
+}
+
+KConfigGroup KConfigImmutable::setEntryImmutable(KConfigGroup& grp, const QString& \
entry, bool immutable) +{
+ QFile fileOut(QDir::currentPath() + QLatin1String("/temporary_config"));
+ createSubsetConfigFile(fileOut, grp);
+
+ if (!fileOut.open(QIODevice::ReadOnly | QIODevice::Text))
+ return grp;
+ QString entryValue = grp.readEntry(entry);
+
+ QString searchString;
+ QString replaceString;
+
+ if (immutable) { //add [$i]
+ searchString = entry + QLatin1Char('=') + entryValue + QLatin1Char('\n');
+ replaceString = entry + QLatin1String("[$i]=") + entryValue + \
QLatin1Char('\n'); + } else { //remove [$i]
+ searchString = entry + QLatin1String("[$i]=") + entryValue + \
QLatin1Char('\n'); + replaceString = entry + QLatin1Char('=') + entryValue + \
QLatin1Char('\n'); + }
+
+ return setImmutableStatus(fileOut, searchString, replaceString, grp);
+}
+
+void KConfigImmutable::createSubsetConfigFile(QFile& fileOut, KConfigGroup& grp)
+{
+ KConfig config2(fileOut.fileName());
+ KConfigGroup grp2(&config2, grp.name());
+ grp.copyTo(&grp2);
+ config2.sync();
+}
+
+KConfigGroup KConfigImmutable::setImmutableStatus(QFile& fileOut, QString& \
searchString, QString& replaceString, KConfigGroup& grp) +{
+ QString fileContent = fileOut.readAll();
+ fileContent.replace(searchString, replaceString);
+ fileOut.close();
+
+ KConfigGroup newGroup = createNewGroupFromSubsetConfig(fileOut, grp, \
fileContent); + fileOut.remove();
+ return newGroup;
+}
+
+
+KConfigGroup KConfigImmutable::createNewGroupFromSubsetConfig(QFile& fileOut, \
KConfigGroup& grp, QString& fileContent) +{
+
+ if (!fileOut.open(QIODevice::WriteOnly | QIODevice::Text))
+ return grp;
+ QTextStream out(&fileOut);
+ out << fileContent;
+ out.flush();
+ KConfig config3(fileOut.fileName());
+ KConfigGroup grp3(&config3, grp.name());
+ grp3.copyTo(&grp);
+ KConfig* config = grp.config();
+ config->sync();
+ KConfigGroup newGroup(config, grp.name());
+ fileOut.close();
+ return newGroup;
+}
diff --git a/src/kconfigimmutable.h b/src/kconfigimmutable.h
new file mode 100644
index 0000000..f9ce098
--- /dev/null
+++ b/src/kconfigimmutable.h
@@ -0,0 +1,40 @@
+/*
+ * <one line to give the library's name and an idea of what it does.>
+ * Copyright 2016 Gilbert Assaf <gassaf@gmx.de>
+ *
+ * This program 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 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef KCONFIGIMMUTABLE_H
+#define KCONFIGIMMUTABLE_H
+
+#include <kconfiggroup.h>
+#include <QFile>
+
+class KConfigImmutable
+{
+public:
+ static KConfigGroup setGroupImmutable(KConfigGroup& grp, bool immutable);
+ static KConfigGroup setEntryImmutable(KConfigGroup& grp, const QString& entry, \
bool immutable); +private:
+ static KConfigGroup createNewGroupFromSubsetConfig(QFile& fileOut, KConfigGroup& \
grp, QString& fileContent); + static void createSubsetConfigFile(QFile& fileOut, \
KConfigGroup& grp); + static KConfigGroup setImmutableStatus(QFile& fileOut, \
QString& searchString, QString& replaceString, KConfigGroup& grp); +};
+
+#endif // KCONFIGIMMUTABLE_H
diff --git a/src/kentryinfo.cpp b/src/kentryinfo.cpp
new file mode 100644
index 0000000..051bcda
--- /dev/null
+++ b/src/kentryinfo.cpp
@@ -0,0 +1,53 @@
+/*
+ * <one line to give the library's name and an idea of what it does.>
+ * Copyright 2016 Gilbert Assaf <gassaf@gmx.de>
+ *
+ * This program 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 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include "kentryinfo.h"
+
+KEntryInfo::KEntryInfo()
+{
+
+}
+
+KEntryInfo::KEntryInfo(QString& nameEntry, QString& typeEntry, QString& labelEntry) \
: name(nameEntry), type(typeEntry), label(labelEntry) +{
+
+}
+
+KEntryInfo::~KEntryInfo()
+{
+
+}
+
+QString KEntryInfo::getLabel()
+{
+ return label;
+}
+
+QString KEntryInfo::getName()
+{
+ return name;
+}
+
+QString KEntryInfo::getType()
+{
+ return type;
+}
diff --git a/src/kentryinfo.h b/src/kentryinfo.h
new file mode 100644
index 0000000..e82ba77
--- /dev/null
+++ b/src/kentryinfo.h
@@ -0,0 +1,45 @@
+/*
+ * <one line to give the library's name and an idea of what it does.>
+ * Copyright 2016 Gilbert Assaf <gassaf@gmx.de>
+ *
+ * This program 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 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef KENTRYINFO_H
+#define KENTRYINFO_H
+
+#include <QString>
+
+class KEntryInfo
+{
+public:
+ KEntryInfo();
+ explicit KEntryInfo(QString& name, QString& type, QString& label);
+ ~KEntryInfo();
+ QString getName();
+ QString getType();
+ QString getLabel();
+
+private:
+ QString name;
+ QString type;
+ QString label;
+
+};
+
+#endif // KENTRYINFO_H
diff --git a/src/kgroupinfo.cpp b/src/kgroupinfo.cpp
new file mode 100644
index 0000000..3a44e32
--- /dev/null
+++ b/src/kgroupinfo.cpp
@@ -0,0 +1,53 @@
+/*
+ * <one line to give the library's name and an idea of what it does.>
+ * Copyright 2016 Gilbert Assaf <gassaf@gmx.de>
+ *
+ * This program 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 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include "kgroupinfo.h"
+
+KGroupInfo::KGroupInfo()
+{
+
+}
+
+KGroupInfo::KGroupInfo(QString& grpName) : groupName(grpName)
+{
+
+}
+
+KGroupInfo::~KGroupInfo()
+{
+
+}
+
+void KGroupInfo::addKEntryInfo(KEntryInfo& kEntryInfo)
+{
+ entries.insert(kEntryInfo.getName(), kEntryInfo);
+}
+
+QString KGroupInfo::getName()
+{
+ return groupName;
+}
+
+KEntryInfo KGroupInfo::getKEntryInfo(const QString& name)
+{
+ return entries.value(name);
+}
diff --git a/src/kgroupinfo.h b/src/kgroupinfo.h
new file mode 100644
index 0000000..cc1e720
--- /dev/null
+++ b/src/kgroupinfo.h
@@ -0,0 +1,47 @@
+/*
+ * <one line to give the library's name and an idea of what it does.>
+ * Copyright 2016 Gilbert Assaf <gassaf@gmx.de>
+ *
+ * This program 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 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef KGROUPINFO_H
+#define KGROUPINFO_H
+
+#include "kentryinfo.h"
+
+#include <QHash>
+#include <QString>
+
+class KGroupInfo
+{
+public:
+ KGroupInfo();
+ explicit KGroupInfo(QString& grpName);
+ ~KGroupInfo();
+ void addKEntryInfo(KEntryInfo& kEntryInfo);
+ QString getName();
+ KEntryInfo getKEntryInfo(const QString& name);
+
+private:
+ QString groupName;
+ QHash<QString, KEntryInfo> entries;
+
+};
+
+#endif // KGROUPENTRYINFO_H
diff --git a/src/main.cpp b/src/main.cpp
new file mode 100644
index 0000000..e5dc627
--- /dev/null
+++ b/src/main.cpp
@@ -0,0 +1,64 @@
+/*
+ * <one line to give the library's name and an idea of what it does.>
+ * Copyright 2015 Gilbert Assaf <gassaf@gmx.de>
+ *
+ * This program 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 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include <QApplication>
+#include <QCommandLineParser>
+
+#include <KAboutData>
+#include <KLocalizedString>
+
+#include "mainwindow.h"
+#include "confineconfiguration.h"
+
+int main(int argc, char* argv[])
+{
+ QApplication app(argc, argv);
+
+ KLocalizedString::setApplicationDomain("confine");
+
+ KAboutData aboutData(
+ QStringLiteral("confine"),
+ i18n("Confine"),
+ QStringLiteral("0.1"),
+ i18n("Replacement to the KIOSK tool"),
+ KAboutLicense::GPL,
+ i18n("(c) 2015"),
+ QStringLiteral("https://projects.kde.org/projects/playground/utils/confine"),
+ QStringLiteral("submit@bugs.kde.org"));
+
+ KAboutData::setApplicationData(aboutData);
+
+ QCommandLineParser parser;
+ parser.addHelpOption();
+ parser.addVersionOption();
+ aboutData.setupCommandLine(&parser);
+ parser.process(app);
+ aboutData.processCommandLine(&parser);
+
+ ConfineConfiguration* confineConfiguration = new ConfineConfiguration();
+ app.setProperty("confineConfiguration", \
QVariant::fromValue<ConfineConfiguration*>(confineConfiguration)); +
+ MainWindow* window = new MainWindow();
+ window->show();
+
+ return app.exec();
+}
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
new file mode 100644
index 0000000..374db99
--- /dev/null
+++ b/src/mainwindow.cpp
@@ -0,0 +1,67 @@
+/*
+ * <one line to give the library's name and an idea of what it does.>
+ * Copyright 2015 Gilbert Assaf <gassaf@gmx.de>
+ *
+ * This program 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 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include "mainwindow.h"
+#include "userprofilemanager.h"
+
+#include <KLocalizedString>
+
+
+MainWindow::MainWindow(QWidget* parent) : KXmlGuiWindow(parent)
+{
+ ui.setupUi(this);
+ ui.tabWidget->setCurrentIndex(0);
+
+ ui.userList->addItems(um.getUserNames());
+ ui.profileList->addItems(um.getProfileNames());
+
+ Q_FOREACH(const QString & profileName, um.getProfileNames()) {
+ QListWidgetItem* item = new QListWidgetItem(ui.profileListForUser);
+ item->setData(Qt::DisplayRole, profileName);
+ item->setData(Qt::CheckStateRole, Qt::Unchecked);
+ }
+
+ connect(ui.userList, SIGNAL(itemClicked(QListWidgetItem*)), this, \
SLOT(fillUserData(QListWidgetItem*))); +
+}
+
+
+void MainWindow::fillUserData(QListWidgetItem* userNameItem)
+{
+ QString userName = userNameItem->data(Qt::DisplayRole).toString();
+ QList<Profile> pfList = um.getProfilesfromUser(userName);
+ QStringList profileNames;
+ Q_FOREACH(const Profile & profile, pfList) {
+ profileNames << profile.getName();
+ }
+ for (int row = 0; row < ui.profileListForUser->count(); row++) {
+ QListWidgetItem* item = ui.profileListForUser->item(row);
+ QString profileName = item->data(Qt::DisplayRole).toString();
+ if (profileNames.contains(profileName)) {
+ item->setData(Qt::CheckStateRole, Qt::Checked);
+ } else {
+ item->setData(Qt::CheckStateRole, Qt::Unchecked);
+ }
+
+ }
+}
+
diff --git a/src/mainwindow.h b/src/mainwindow.h
new file mode 100644
index 0000000..f20dd5b
--- /dev/null
+++ b/src/mainwindow.h
@@ -0,0 +1,48 @@
+/*
+ * <one line to give the library's name and an idea of what it does.>
+ * Copyright 2015 Gilbert Assaf <gassaf@gmx.de>
+ *
+ * This program 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 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include "userprofilemanager.h"
+
+#include <KXmlGuiWindow>
+
+#include <ui_mainwindow.h>
+
+class MainWindow : public KXmlGuiWindow
+{
+ Q_OBJECT
+
+ public:
+ explicit MainWindow(QWidget *parent=0);
+
+public Q_SLOTS:
+ void fillUserData(QListWidgetItem* userNameItem);
+
+private:
+ Ui::MainWindow ui;
+
+ UserProfileManager um;
+};
+
+#endif
diff --git a/src/mainwindow.ui b/src/mainwindow.ui
new file mode 100644
index 0000000..eca6fad
--- /dev/null
+++ b/src/mainwindow.ui
@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>MainWindow</class>
+ <widget class="QMainWindow" name="MainWindow">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>800</width>
+ <height>600</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>MainWindow</string>
+ </property>
+ <widget class="QWidget" name="centralwidget">
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="0" column="0">
+ <widget class="QTabWidget" name="tabWidget">
+ <property name="currentIndex">
+ <number>1</number>
+ </property>
+ <widget class="QWidget" name="tab">
+ <attribute name="title">
+ <string>Users</string>
+ </attribute>
+ <layout class="QGridLayout" name="gridLayout_3">
+ <item row="0" column="0">
+ <widget class="QListWidget" name="userList"/>
+ </item>
+ <item row="0" column="1">
+ <widget class="QListWidget" name="profileListForUser">
+ <property name="selectionMode">
+ <enum>QAbstractItemView::MultiSelection</enum>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QWidget" name="tab_2">
+ <attribute name="title">
+ <string>Profiles</string>
+ </attribute>
+ <layout class="QGridLayout" name="gridLayout_2">
+ <item row="0" column="0">
+ <widget class="QListWidget" name="profileList"/>
+ </item>
+ </layout>
+ </widget>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QMenuBar" name="menubar">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>800</width>
+ <height>30</height>
+ </rect>
+ </property>
+ </widget>
+ <widget class="QStatusBar" name="statusbar"/>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/src/profile.cpp b/src/profile.cpp
new file mode 100644
index 0000000..710856f
--- /dev/null
+++ b/src/profile.cpp
@@ -0,0 +1,105 @@
+/*
+ * <one line to give the library's name and an idea of what it does.>
+ * Copyright 2016 Gilbert Assaf <gassaf@gmx.de>
+ *
+ * This program 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 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include "profile.h"
+#include <KConfig>
+#include <KConfigGroup>
+#include <ksharedconfig.h>
+#include <kconfigbase.h>
+
+#include <QDir>
+#include <QMap>
+
+Profile::Profile()
+{
+
+}
+
+Profile::Profile(const QString& profileDir) : name(profileDir), \
directory(profileDir) +{
+ refreshConfigurationFilesFromProfile();
+}
+
+Profile::Profile(QString& profileDir, QString& profileName) : name(profileName), \
directory(profileDir) +{
+ refreshConfigurationFilesFromProfile();
+}
+
+Profile::~Profile()
+{
+
+}
+
+QString Profile::getDirectory() const
+{
+ return directory;
+}
+
+QString Profile::getName() const
+{
+ return name;
+}
+
+QStringList Profile::getConfigFiles() const
+{
+ return configurationFiles;
+}
+
+
+QMap<QString, QString> Profile::getKDEActionRestrictions() const
+{
+ KSharedConfigPtr config = KSharedConfig::openConfig(directory + "kdeglobals");
+ KConfigGroup grp(config, "KDE Action Restrictions");
+ return grp.entryMap();
+}
+
+void Profile::setKDEActionRestriction(QString& key, QString& value)
+{
+ KConfig config(directory + "kdeglobals");
+ KConfigGroup grp(&config, "KDE Action Restrictions");
+ if (!grp.isImmutable()) {
+ grp.writeEntry(key, value, KConfigBase::Persistent);
+ }
+}
+
+QMap<QString, QString> Profile::getKDEControlModuleRestrictions() const
+{
+ KSharedConfigPtr config = KSharedConfig::openConfig(directory + "kdeglobals");
+ KConfigGroup grp(config, "KDE Control Module Restrictions");
+ return grp.entryMap();
+}
+
+void Profile::setKDEControlModuleRestrictions(QString& key, QString& value)
+{
+ KConfig config(directory + "kdeglobals");
+ KConfigGroup grp(&config, "KDE Control Module Restrictions");
+ if (!grp.isImmutable()) {
+ grp.writeEntry(key, value, KConfigBase::Persistent);
+ }
+}
+
+void Profile::refreshConfigurationFilesFromProfile()
+{
+ configurationFiles.clear();
+ QDir profileDir(directory);
+ configurationFiles = profileDir.entryList(QDir::AllEntries | \
QDir::NoDotAndDotDot); +}
diff --git a/src/profile.h b/src/profile.h
new file mode 100644
index 0000000..d612c3a
--- /dev/null
+++ b/src/profile.h
@@ -0,0 +1,53 @@
+/*
+ * <one line to give the library's name and an idea of what it does.>
+ * Copyright 2016 Gilbert Assaf <gassaf@gmx.de>
+ *
+ * This program 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 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef PROFILE_H
+#define PROFILE_H
+
+#include <QString>
+#include <QStringList>
+
+
+class Profile
+{
+public:
+ Profile();
+ explicit Profile(const QString& profileDir);
+ Profile(QString& profileDir, QString& profileName);
+ ~Profile();
+ QMap<QString, QString> getKDEActionRestrictions() const;
+ void setKDEActionRestriction(QString& key, QString& value);
+ QMap<QString, QString> getKDEControlModuleRestrictions() const;
+ void setKDEControlModuleRestrictions(QString& key, QString& value);
+ QStringList getConfigFiles() const;
+ QString getDirectory() const;
+ QString getName() const;
+
+
+private:
+ void refreshConfigurationFilesFromProfile();
+ QString name;
+ QString directory;
+ QStringList configurationFiles;
+};
+
+#endif // PROFILE_H
diff --git a/src/user.cpp b/src/user.cpp
new file mode 100644
index 0000000..8239b6e
--- /dev/null
+++ b/src/user.cpp
@@ -0,0 +1,157 @@
+/*
+ * <one line to give the library's name and an idea of what it does.>
+ * Copyright 2015 Gilbert Assaf <gassaf@gmx.de>
+ *
+ * This program 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 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include "user.h"
+#include "profile.h"
+
+#include <QString>
+#include <QFile>
+#include <QList>
+#include <QDir>
+#include <QTextStream>
+
+User::User(const QString& userName, const QString& userShell, const QString& \
userHomeDir) : name(userName), + shell(userShell),
+ homeDir(userHomeDir),
+ environmentVariableFile(QLatin1String(".profile"))
+
+{
+
+
+}
+
+User::User()
+{
+
+}
+
+User::~User()
+{
+
+}
+
+QString User::getName() const
+{
+ return name;
+}
+
+QString User::getHomeDir()
+{
+ return homeDir;
+}
+
+QString User::getXDG_CONFIG_HOME()
+{
+ return XDG_CONFIG_HOME;
+}
+
+QString User::getEnvironmentVariableFile()
+{
+ return environmentVariableFile;
+}
+
+void User::setXDG_CONFIG_HOME(const QString& configHome)
+{
+ XDG_CONFIG_HOME = configHome;
+}
+
+void User::setEnvironmentVariableFile(const QString& varFile)
+{
+ environmentVariableFile = varFile;
+}
+
+void User::addProfile(const Profile& profile)
+{
+ profiles.append(profile);
+}
+
+void User::save()
+{
+ if (homeDir.isEmpty() || !QFile::exists(homeDir)) {
+ return;
+ }
+
+ QString filePath(homeDir + QDir::separator() + environmentVariableFile);
+
+ QString prefix;
+
+ if (environmentVariableFile == ".profile") {
+ prefix = "export ";
+ }
+
+ QFile file(filePath);
+ if (!file.open(QIODevice::ReadWrite | QIODevice::Text)) {
+ return;
+ }
+
+ QString configDirs;
+ QStringList helperList;
+ Q_FOREACH(const Profile & pf, profiles) {
+ helperList << pf.getDirectory();
+ }
+
+ configDirs = helperList.join(QLatin1Char(':'));
+
+ QStringList fileContent;
+ bool hasConfigDirs = false;
+ bool hasConfigHome = false;
+ while (!file.atEnd()) {
+ QString line = file.readLine();
+ if (!hasConfigDirs && line.contains(QLatin1String("XDG_CONFIG_DIRS")) && \
line.indexOf('=') > -1) { + hasConfigDirs = true;
+ line = prefix + QLatin1String("XDG_CONFIG_DIRS=") + configDirs + \
QLatin1Char('\n'); + } else if (!hasConfigHome && \
line.contains(XDG_CONFIG_HOME) && line.indexOf('=') > -1) { + \
hasConfigHome = true; + line = prefix + QLatin1String("XDG_CONFIG_HOME=") \
+ XDG_CONFIG_HOME + QLatin1Char('\n'); + }
+ fileContent << line;
+ }
+
+ if (!hasConfigDirs && !configDirs.isEmpty()) {
+ fileContent << prefix + QLatin1String("XDG_CONFIG_DIRS=") + configDirs + \
QLatin1Char('\n'); + }
+
+ if (!hasConfigHome && !XDG_CONFIG_HOME.isEmpty()) {
+ fileContent << prefix + QLatin1String("XDG_CONFIG_HOME=") + XDG_CONFIG_HOME \
+ QLatin1Char('\n'); + }
+
+ file.seek(0);
+ QTextStream out(&file);
+ Q_FOREACH(const QString & line, fileContent) {
+ out << line;
+ }
+ file.flush();
+ file.close();
+
+}
+
+QList<Profile> User::getProfiles()
+{
+ return profiles;
+}
+
+void User::clearProfiles()
+{
+ profiles.clear();
+}
+
+
diff --git a/src/user.h b/src/user.h
new file mode 100644
index 0000000..062e7a0
--- /dev/null
+++ b/src/user.h
@@ -0,0 +1,56 @@
+/*
+ * <one line to give the library's name and an idea of what it does.>
+ * Copyright 2015 Gilbert Assaf <gassaf@gmx.de>
+ *
+ * This program 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 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef USER_H
+#define USER_H
+
+#include "profile.h"
+#include <QString>
+#include <QList>
+
+class User
+{
+public:
+ User();
+ User(const QString& userName, const QString& userShell, const QString& \
userHomeDir); + ~User();
+ QString getName() const;
+ QString getHomeDir();
+ QString getXDG_CONFIG_HOME();
+ QString getEnvironmentVariableFile();
+ void setXDG_CONFIG_HOME(const QString& configHome);
+ void setEnvironmentVariableFile(const QString& varFile);
+ void save();
+ void addProfile(const Profile& profile);
+ void clearProfiles();
+ QList<Profile> getProfiles();
+
+private:
+ QString name;
+ QString shell;
+ QString homeDir;
+ QString XDG_CONFIG_HOME;
+ QString environmentVariableFile;
+ QList<Profile> profiles;
+};
+
+#endif // USER_H
diff --git a/src/userprofilemanager.cpp b/src/userprofilemanager.cpp
new file mode 100644
index 0000000..784a294
--- /dev/null
+++ b/src/userprofilemanager.cpp
@@ -0,0 +1,156 @@
+/*
+ * <one line to give the library's name and an idea of what it does.>
+ * Copyright 2015 Gilbert Assaf <gassaf@gmx.de>
+ *
+ * This program 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 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include "userprofilemanager.h"
+#include "user.h"
+#include "profile.h"
+#include "confineconfiguration.h"
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <pwd.h>
+#include <QFile>
+#include <QList>
+#include <QDir>
+#include <QApplication>
+
+
+UserProfileManager::UserProfileManager()
+{
+ XDG_CONFIG_DIRS = "XDG_CONFIG_DIRS";
+ XDG_CONFIG_HOME = "XDG_CONFIG_HOME";
+ getUsersOnSystem();
+}
+
+UserProfileManager::~UserProfileManager()
+{
+
+}
+
+void UserProfileManager::getUsersOnSystem()
+{
+ users.clear();
+ ConfineConfiguration* cf = \
qApp->property("confineConfiguration").value<ConfineConfiguration*>(); +
+ if (!QFile::exists(cf->getPasswdPath())) {
+ return;
+ }
+
+ struct passwd* pwd_entry;
+ FILE* fpwd = fopen(QFile::encodeName(cf->getPasswdPath()), "r");
+
+ while ((pwd_entry = fgetpwent(fpwd)) != NULL) {
+ QString name = QString::fromLocal8Bit(pwd_entry->pw_name);
+ QString homeDir = QString::fromLocal8Bit(pwd_entry->pw_dir);
+ QString shell = QString::fromLocal8Bit(pwd_entry->pw_shell);
+ User userEntry(name, shell, homeDir);
+ getXDGConfig(userEntry);
+ users.insert(userEntry.getName(), userEntry);
+ }
+ fclose(fpwd);
+}
+
+void UserProfileManager::getXDGConfig(User& user)
+{
+ if (user.getHomeDir().isEmpty() || !QFile::exists(user.getHomeDir())) {
+ return;
+ }
+
+ QString filePath(user.getHomeDir() + QDir::separator() + \
user.getEnvironmentVariableFile()); +
+ QFile file(filePath);
+ if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
+ return;
+ }
+ QString configDirs;
+ QString configHome;
+ while (!file.atEnd()) {
+ QString line = file.readLine();
+
+ if (line.isEmpty())
+ continue;
+
+ if (line.contains(XDG_CONFIG_DIRS) && line.indexOf('=') > -1) {
+ configDirs = line.mid(line.indexOf('=') + 1).trimmed();
+ } else if (line.contains(XDG_CONFIG_HOME) && line.indexOf('=') > -1) {
+ configHome = line.mid(line.indexOf('=') + 1).trimmed();
+ }
+ }
+
+ QStringList configDirsList = configDirs.split(QLatin1Char(':'));
+ Q_FOREACH(const QString & singleDir, configDirsList) {
+ if (singleDir.isEmpty()) {
+ continue;
+ }
+
+ QString dir(singleDir);
+ if (!dir.endsWith(QLatin1Char('/'))) {
+ dir += QLatin1Char('/');
+ }
+
+ if (!profiles.contains(dir)) {
+ Profile pf(dir);
+ profiles.insert(dir, pf);
+ }
+ user.addProfile(profiles.value(dir));
+ }
+
+ user.setXDG_CONFIG_HOME(configHome);
+}
+
+QStringList UserProfileManager::getUserNames()
+{
+ QStringList userNames;
+ Q_FOREACH(const User & user, users.values()) {
+ userNames << user.getName();
+ }
+ return userNames;
+}
+
+QStringList UserProfileManager::getProfileNames()
+{
+ QStringList profileNames;
+ Q_FOREACH(const Profile & profile, profiles.values()) {
+ profileNames << profile.getName();
+ }
+
+ return profileNames;
+}
+
+QList< Profile > UserProfileManager::getProfilesfromUser(const QString& userName)
+{
+ User user = users.value(userName);
+ return user.getProfiles();
+}
+
+void UserProfileManager::setProfilesForUser(const QString& userName, QList< Profile \
> profileList) +{
+ User user = users.value(userName);
+ user.clearProfiles();
+ Q_FOREACH(const Profile& profile, profileList) {
+ user.addProfile(profile);
+ if(!profiles.contains(profile.getName())) {
+ profiles.insert(profile.getName(), profile);
+ }
+ }
+}
+
diff --git a/src/userprofilemanager.h b/src/userprofilemanager.h
new file mode 100644
index 0000000..5a85902
--- /dev/null
+++ b/src/userprofilemanager.h
@@ -0,0 +1,51 @@
+/*
+ * <one line to give the library's name and an idea of what it does.>
+ * Copyright 2015 Gilbert Assaf <gassaf@gmx.de>
+ *
+ * This program 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 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef USERPROFILEMANAGER_H
+#define USERPROFILEMANAGER_H
+
+#include "user.h"
+#include "profile.h"
+
+#include <QList>
+#include <QHash>
+
+class UserProfileManager
+{
+public:
+UserProfileManager();
+~UserProfileManager();
+QStringList getUserNames();
+QStringList getProfileNames();
+QList<Profile> getProfilesfromUser(const QString& userName);
+void setProfilesForUser(const QString& userName, QList<Profile> profileList);
+
+private:
+ QHash<QString, User> users;
+ QHash<QString, Profile> profiles;
+ QString XDG_CONFIG_DIRS;
+ QString XDG_CONFIG_HOME;
+ void getUsersOnSystem();
+ void getXDGConfig(User& user);
+};
+
+#endif // USERMANAGER_H
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic