Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
rthomsen committed Nov 18, 2013
0 parents commit 8a45297
Show file tree
Hide file tree
Showing 19 changed files with 4,093 additions and 0 deletions.
25 changes: 25 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
project(kcmsystemd)
set(KCM_SYSTEMD_VERSION_MAJOR "0")
set(KCM_SYSTEMD_VERSION_MINOR "1")
set(KCM_SYSTEMD_VERSION_PATCH "0")
set(KCM_SYSTEMD_VERSION "${KCM_SYSTEMD_VERSION_MAJOR}.${KCM_SYSTEMD_VERSION_MINOR}.${KCM_SYSTEMD_VERSION_PATCH}")

cmake_minimum_required(VERSION 2.6)
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})

find_package(Qt4 4.6.0 REQUIRED)
find_package(KDE4 4.4.0 REQUIRED)
include(KDE4Defaults)

include_directories( ${QT_INCLUDES} ${CMAKE_CURRENT_BINARY_DIR} )
include_directories( ${KDE4_INCLUDES} )
add_definitions( ${KDE4_DEFINITIONS} )

set(kcmsystemd_INCLUDE_DIRS ${KDE4_INCLUDES})

set(CMAKE_CXX_FLAGS "-fexceptions")

configure_file(config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/src/config.h)

add_subdirectory(other)
add_subdirectory(src)
6 changes: 6 additions & 0 deletions config.h.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef CONFIG_H
#define CONFIG_H

#define KCM_SYSTEMD_VERSION "@KCM_SYSTEMD_VERSION@"

#endif
1 change: 1 addition & 0 deletions other/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
install(FILES kcm_systemd.desktop DESTINATION ${SERVICES_INSTALL_DIR})
14 changes: 14 additions & 0 deletions other/kcm_systemd.desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[Desktop Entry]
Icon=system-run
Type=Service
X-KDE-ServiceTypes=KCModule
Exec=kcmshell4 kcm_systemd

X-KDE-Library=kcm_systemd
X-KDE-ParentApp=kcontrol
X-KDE-System-Settings-Parent-Category=system-administration

Name=Systemd
Comment=Configure the systemd daemon
X-KDE-Keywords=systemd
Categories=Qt;KDE;X-KDE-settings-system;
4 changes: 4 additions & 0 deletions src/.directory
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[Dolphin]
Timestamp=2013,8,13,12,32,11
Version=3
ViewMode=2
17 changes: 17 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
add_subdirectory(helper)

set(kcmsystemd_INCLUDE_DIRS ${KDE4_INCLUDES})

set(kcmsystemd_SRCS kcmsystemd.cpp reslimits.cpp environ.cpp)

find_package(Boost 1.45.0 COMPONENTS filesystem system)

kde4_add_ui_files(kcmsystemd_SRCS ../ui/kcmsystemd.ui)
kde4_add_ui_files(kcmsystemd_SRCS ../ui/reslimits.ui)
kde4_add_ui_files(kcmsystemd_SRCS ../ui/environ.ui)

include_directories(${kcmsystemd_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS})
link_directories(${Boost_LIBRARY_DIR})
kde4_add_plugin(kcm_systemd ${kcmsystemd_SRCS})
target_link_libraries(kcm_systemd ${KDE4_KDEUI_LIBS} ${KDE4_KIO_LIBS} ${Boost_LIBRARIES})
install(TARGETS kcm_systemd DESTINATION ${PLUGIN_INSTALL_DIR})
146 changes: 146 additions & 0 deletions src/environ.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
/*******************************************************************************
* Copyright (C) 2013 Ragnar Thomsen <rthomsen6@gmail.com> *
* *
* 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 3 of the License, or (at your option) *
* any later version. *
* *
* 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 "environ.h"
#include "kcmsystemd.h"

#include <QMessageBox>
#include <QSignalMapper>

int addedVars = 0;

EnvironDialog::EnvironDialog (QWidget* parent, Qt::WFlags flags) : KDialog ( parent)
{
// Initialize dialog window
addedVars = 0;
QWidget *widget = new QWidget(this);
ui.setupUi(widget);
setMainWidget( widget );
setWindowTitle(i18n("Set environment variables"));

// create line edits for variables read from system.conf
QListIterator<QPair<QString,QString> > i(kcmsystemd::environ);
while (i.hasNext())
{
addedVars++;
//QMessageBox::information(this, "Test", i.peekNext().first + "=" + i.peekNext().second);
addNewVariable(addedVars, i.peekNext().first, i.peekNext().second);
i.next();
}

// button for adding a new variable
connect(ui.btnNewVariable, SIGNAL(clicked()), this, SLOT(slotNewVariable()));
}

void EnvironDialog::slotButtonClicked(int button)
{
if (button == KDialog::Ok)
{
// empty "environ"
kcmsystemd::environ.clear();

QPair<QString,QString> i;
//QString test;

// find all QLineEdits that contain "Name"
QList<QLineEdit *> list = this->findChildren<QLineEdit *>();
foreach(QLineEdit *Name, list)
{
if (Name->objectName().contains("Name"))
{
QLineEdit *Value = this->findChild<QLineEdit *>(Name->objectName().section("Name",0,0) + "Value");

//test.append(Name->text() + "=" + Value->text() + " ");

// If qlineedits not empty append them to "environ"
if (!Name->text().trimmed().isEmpty() && !Value->text().trimmed().isEmpty())
{
i.first = Name->text();
i.second = Value->text();
kcmsystemd::environ.append(i);
}
}
}

// QMessageBox::information(this, "Test", test);
}
KDialog::slotButtonClicked(button);
}

// slot for button to add new variable
void EnvironDialog::slotNewVariable()
{
// each variable needs a numeric identifier so we can loop through them
addedVars++;
addNewVariable(addedVars,QString(""),QString(""));
kcmsystemd::environChanged = 1;
}

void EnvironDialog::addNewVariable(int index, QString name, QString value)
{
//QMessageBox::information(this, "Test", "Creating: " + QString::number(index));
QSignalMapper* signalMapper = new QSignalMapper (this);

QLineEdit* leName = new QLineEdit (this);
QLabel* lblEquals = new QLabel (this);
QLineEdit* leValue = new QLineEdit (this);
QPushButton* btnRm = new QPushButton ("Remove", this);
ui.veLayoutVarNames->addWidget(leName);
ui.veLayoutEquals->addWidget(lblEquals);
ui.veLayoutVarValues->addWidget(leValue);
ui.veLayoutRemoval->addWidget(btnRm);
leName->setObjectName(QString::number(index)+"Name");
leName->show();
lblEquals->setObjectName(QString::number(index)+"Equals");
lblEquals->show();
leValue->setObjectName(QString::number(index)+"Value");
leValue->show();
btnRm->setObjectName(QString::number(index)+"Btn");
btnRm->show();

leName->setText(name);
leValue->setText(value);
lblEquals->setText("=");

connect(btnRm, SIGNAL(clicked()), signalMapper, SLOT(map()));
signalMapper->setMapping (btnRm, index);
connect(signalMapper, SIGNAL(mapped(const int &)), this, SLOT(slotRemoveVariable(const int &)));
}

void EnvironDialog::slotRemoveVariable(const int &index)
{
//QMessageBox::information(this, "Test", "Removing: " + QString::number(index));
QLineEdit *varName = this->findChild<QLineEdit *>(QString::number(index)+"Name");
if (varName)
varName->hide();
delete varName;
QLabel *varEquals = this->findChild<QLabel *>(QString::number(index)+"Equals");
if (varEquals)
varEquals->hide();
delete varEquals;
QLineEdit *varValue = this->findChild<QLineEdit *>(QString::number(index)+"Value");
if (varValue)
varValue->hide();
delete varValue;
QPushButton *varBtn = this->findChild<QPushButton *>(QString::number(index)+"Btn");
if (varBtn)
varBtn->hide();
delete varBtn;
addedVars--;
kcmsystemd::environChanged = 1;
layout()->setSizeConstraint(QLayout::SetFixedSize);
}
40 changes: 40 additions & 0 deletions src/environ.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*******************************************************************************
* Copyright (C) 2013 Ragnar Thomsen <rthomsen6@gmail.com> *
* *
* 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 3 of the License, or (at your option) *
* any later version. *
* *
* 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 ENVIRON_H
#define ENVIRON_H

#include "ui_environ.h"

class EnvironDialog : public KDialog
{
Q_OBJECT

public:
explicit EnvironDialog(QWidget *parent=0, Qt::WFlags flags = 0);
virtual void addNewVariable(int, QString, QString);

private slots:
void slotButtonClicked(int button);
void slotNewVariable();
void slotRemoveVariable(const int &index);

private:
Ui::EnvironDialog ui;
};

#endif
18 changes: 18 additions & 0 deletions src/helper/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Set Include Directories
set(kcmsystemdhelper_INCLUDE_DIRS ${KDE4_INCLUDES})

# Set Sources
set(kcmsystemdhelper_SRCS helper.cpp)

# Set Link Libraries
set(kcmsystemdhelper_LINK_LIBS ${KDE4_KDECORE_LIBS})

# Build & Link
include_directories(${kcmsystemdhelper_INCLUDE_DIRS})
kde4_add_executable(kcmsystemdhelper ${kcmsystemdhelper_SRCS})
target_link_libraries(kcmsystemdhelper ${kcmsystemdhelper_LINK_LIBS})

# Install
install(TARGETS kcmsystemdhelper DESTINATION ${LIBEXEC_INSTALL_DIR})
kde4_install_auth_helper_files(kcmsystemdhelper org.kde.kcontrol.kcmsystemd root)
kde4_install_auth_actions(org.kde.kcontrol.kcmsystemd kcmsystemd.actions)
79 changes: 79 additions & 0 deletions src/helper/helper.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*******************************************************************************
* Copyright (C) 2013 Ragnar Thomsen <rthomsen6@gmail.com> *
* *
* 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 3 of the License, or (at your option) *
* any later version. *
* *
* 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 "helper.h"

#include <QDir>
#include <QTextStream>

#include <kdeversion.h>
#include <KAuth/HelperSupport>

#include "../config.h"

ActionReply Helper::save(QVariantMap args)
{
ActionReply reply;

// Declare QStrings with file names and contents
QString systemConfFileContents = args["systemConfFileContents"].toString();
QString journaldConfFileContents = args["journaldConfFileContents"].toString();
QString logindConfFileContents = args["logindConfFileContents"].toString();

// write system.conf
//QMessageBox::information(this, QString("Title"), args["etcDir"].toString());
QFile sysFile(args["etcDir"].toString() + "/system.conf");
if (!sysFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
reply = ActionReply::HelperErrorReply;
reply.addData("errorDescription", sysFile.errorString());
reply.setErrorCode(sysFile.error());
reply.addData("filename", "system.conf");
return reply;
}
QTextStream sysStream(&sysFile);
sysStream << systemConfFileContents;
sysFile.close();

// write journald.conf
QFile jrnlFile(args["etcDir"].toString() + "/journald.conf");
if (!jrnlFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
reply = ActionReply::HelperErrorReply;
reply.setErrorCode(jrnlFile.error());
reply.addData("filename", "journald.conf");
return reply;
}
QTextStream jrnlStream(&jrnlFile);
jrnlStream << journaldConfFileContents;
jrnlFile.close();

// write logind.conf
QFile loginFile(args["etcDir"].toString() + "/logind.conf");
if (!loginFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
reply = ActionReply::HelperErrorReply;
reply.setErrorCode(loginFile.error());
reply.addData("filename", "logind.conf");
return reply;
}
QTextStream loginStream(&loginFile);
loginStream << logindConfFileContents;
loginFile.close();

// return a reply
return reply;
}

KDE4_AUTH_HELPER_MAIN("org.kde.kcontrol.kcmsystemd", Helper)
31 changes: 31 additions & 0 deletions src/helper/helper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*******************************************************************************
* Copyright (C) 2013 Ragnar Thomsen <rthomsen6@gmail.com> *
* *
* 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 3 of the License, or (at your option) *
* any later version. *
* *
* 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 HELPER_H
#define HELPER_H

#include <kauth.h>
using namespace KAuth;

class Helper : public QObject
{
Q_OBJECT
public slots:
ActionReply save(QVariantMap args);
};

#endif
Loading

0 comments on commit 8a45297

Please sign in to comment.