/* * Copyright (C) 2015 Malte Veerman * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * */ #include "helper.h" #include #include #ifndef NO_SYSTEMD #include #endif ActionReply Helper::action(const QVariantMap &arguments) { ActionReply reply; #ifndef NO_SYSTEMD if (arguments["action"] == "dbusaction") { QString method = arguments["method"].toString(); QVariantList argsForCall = arguments["arguments"].toList(); QDBusConnection systembus = QDBusConnection::systemBus(); QDBusInterface *iface = new QDBusInterface ("org.freedesktop.systemd1", "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", systembus, this); QDBusMessage dbusreply; if (iface->isValid()) dbusreply = iface->callWithArgumentList(QDBus::AutoDetect, method, argsForCall); delete iface; if (method != "Reexecute") { if (dbusreply.type() == QDBusMessage::ErrorMessage) { reply.setErrorCode(ActionReply::DBusError); reply.setErrorDescription(dbusreply.errorMessage()); } } } else #endif if (arguments["action"] == "read") { QString filename = arguments["filename"].toString(); QFile file(filename); if (!file.open(QIODevice::ReadOnly)) { reply = ActionReply::HelperErrorType; reply.setErrorCode(ActionReply::AuthorizationDeniedError); return reply; } QTextStream stream(&file); QString content = stream.readAll(); QVariantMap retdata; retdata["content"] = content; reply.setData(retdata); } else if (arguments["action"] == "write") { QString filename = arguments["filename"].toString(); QFile file(filename); if (!file.open(QIODevice::WriteOnly)) { reply = ActionReply::HelperErrorType; reply.addData("errorDescription", file.errorString()); return reply; } QTextStream stream(&file); stream << arguments["content"].toString(); } return reply; } KAUTH_HELPER_MAIN("fancontrol.gui.helper", Helper)