/*************************************************************************** * This file is part of netctl-gui * * * * netctl-gui 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. * * * * netctl-gui 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 netctl-gui. If not, see http://www.gnu.org/licenses/ * ***************************************************************************/ #include #include #include #include #include #include #include #include #include #include #include "messages.h" #include "netctlhelper.h" #include "version.h" #if QT_VERSION >= 0x050000 #include #endif /* QT_VERSION >= 0x050000 */ using namespace std; bool existingSessionOperation(const QString operation) { QDBusConnection bus = QDBusConnection::systemBus(); QDBusMessage request = QDBusMessage::createMethodCall(DBUS_HELPER_SERVICE, DBUS_CTRL_PATH, DBUS_HELPER_INTERFACE, operation); QDBusMessage response = bus.call(request); QList arguments = response.arguments(); return (!arguments.isEmpty() && arguments[0].toBool()); } int main(int argc, char *argv[]) { QVariantMap args = getArgs(); // reading for (int i=1; i= 0x050000 QCoreApplication::setSetuidAllowed(true); qInstallMessageHandler(debugString); #endif QCoreApplication a(argc, argv); // reread translations according to flags QString language = Language::defineLanguage(args[QString("config")].toString(), args[QString("options")].toString()); QTranslator qtTranslator; qtTranslator.load(QString("qt_%1").arg(language), QLibraryInfo::location(QLibraryInfo::TranslationsPath)); a.installTranslator(&qtTranslator); QTranslator translator; translator.load(QString(":/translations-helper/%1").arg(language)); a.installTranslator(&translator); // running if (args[QString("error")].toBool()) { cout << errorMessage().toUtf8().data() << endl; cout << helpMessage().toUtf8().data(); return 11; } else if (args[QString("help")].toBool()) { cout << helpMessage().toUtf8().data(); return 0; } else if (args[QString("info")].toBool()) { cout << versionMessage().toUtf8().data() << endl; cout << infoMessage().toUtf8().data(); return 0; } else if (args[QString("version")].toBool()) { cout << versionMessage().toUtf8().data(); return 0; } // check if exists if (existingSessionOperation(QString("Active"))) { if (args[QString("state")].toInt() == 1) { // replace session cout << QCoreApplication::translate("NetctlHelper", "Replace existing session.") .toUtf8().data() << endl; existingSessionOperation(QString("Close")); } else if (args[QString("state")].toInt() == 2) { // restore session cout << QCoreApplication::translate("NetctlHelper", "Restore existing session.") .toUtf8().data() << endl; return 0; } else if (geteuid() == 0) { // replace if running as root cout << QCoreApplication::translate("NetctlHelper", "Replace existing session.") .toUtf8().data() << endl; existingSessionOperation(QString("Close")); } else { // restore if running as non-root cout << QCoreApplication::translate("NetctlHelper", "Restore existing session.") .toUtf8().data() << endl; return 0; } } NetctlHelper w(0, args); return a.exec(); }