Commit 949098e7 authored by Nicolas Fella's avatar Nicolas Fella
Browse files

Rework main.cpp

The main change is that all commandline parsing happens before the KDBusService part is reached. This allows to unify the command line handling and error checking for the cases of launching a new systemsettings and activating an existing instance.

This fixes the issues that it was impossible to use systemsettings5 --list when an instance was already running and that it was impossible to pass arguments with a module when activating an existing instance. It also adds some additional error checking/reporting.

The SystemSettingsApp class and its (apparently unused DBus interface) is removed in the process.
parent 313831f8
......@@ -2,7 +2,6 @@
include_directories( ToolTips )
set( systemsettings_SRCS
SystemSettingsApp.cpp
SettingsBase.cpp
ToolTips/tooltipmanager.cpp
main.cpp )
......@@ -13,7 +12,6 @@ ecm_qt_declare_logging_category(systemsettings_SRCS HEADER systemsettings_app_de
# kde4_add_app_icon( systemsettings_SRCS "${KDE4_ICON_INSTALL_DIR}/oxygen/*/categories/preferences-system.png" )
ki18n_wrap_ui( systemsettings_SRCS configDialog.ui )
kconfig_add_kcfg_files( systemsettings_SRCS BaseConfig.kcfgc )
qt5_add_dbus_adaptor( systemsettings_SRCS org.kde.systemsettings.xml SystemSettingsApp.h SystemSettingsApp )
add_executable( systemsettings5 ${systemsettings_SRCS})
target_compile_definitions(systemsettings5 PRIVATE -DPROJECT_VERSION="${PROJECT_VERSION}")
......
/**
* Copyright (C) 2009 Ben Cooksley <bcooksley@kde.org>
*
* 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) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "SystemSettingsApp.h"
#include <KDBusService>
#include <KWindowSystem>
SystemSettingsApp::SystemSettingsApp(int& argc, char* argv[])
: QApplication(argc, argv)
{
setOrganizationDomain(QStringLiteral("kde.org"));
KDBusService* service = new KDBusService(KDBusService::Unique, this);
QObject::connect(service, &KDBusService::activateRequested, this, [=](const QStringList &arguments, const QString &workingDirectory) {
if (!window) {
return;
}
if (arguments.size() > 1) {
window->setStartupModule(arguments[1]);
if (arguments.size() > 2) {
window->setStartupModuleArgs(arguments.mid(2));
}
window->reloadStartupModule();
}
KWindowSystem::forceActiveWindow(window->winId());
} );
}
SystemSettingsApp::~SystemSettingsApp()
{
}
void SystemSettingsApp::setMainWindow(SettingsBase * main)
{
window = main;
}
void SystemSettingsApp::quit()
{
if( window && !window->queryClose() ) {
return;
}
QApplication::quit();
}
/**
* Copyright (C) 2009 Ben Cooksley <bcooksley@kde.org>
*
* 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) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
/**
* Any changes to this header file need to have the following command executed afterwards to regenerate the dbus interface
* qdbuscpp2xml SystemSettingsApp.h -o org.kde.systemsettings.xml
*/
#ifndef SYSTEMSETTINGSAPP_H
#define SYSTEMSETTINGSAPP_H
#include <QApplication>
#include "SettingsBase.h"
class SystemSettingsApp : public QApplication
{
Q_OBJECT
public:
SystemSettingsApp(int& argc, char* argv[]);
~SystemSettingsApp() override;
void setMainWindow(SettingsBase * main);
public Q_SLOTS:
Q_SCRIPTABLE void quit();
private:
QPointer<SettingsBase> window;
};
#endif
......@@ -31,8 +31,8 @@
#include <KQuickAddons/QtQuickSettings>
#include <KServiceTypeTrader>
#include <KAuthorized>
#include <KWindowSystem>
#include "SystemSettingsApp.h"
#include "SettingsBase.h"
KService::List m_modules;
......@@ -76,30 +76,37 @@ int main( int argc, char *argv[] )
//which is before KAboutData::setApplicationData
QCoreApplication::setApplicationName(binaryName);
KWorkSpace::detectPlatform(argc, argv);
SystemSettingsApp application(argc, argv);
KQuickAddons::QtQuickSettings::init();
KCrash::initialize();
KLocalizedString::setApplicationDomain(binaryName.toUtf8().constData());
QApplication application(argc, argv);
application.setAttribute(Qt::AA_UseHighDpiPixmaps, true);
KAboutData aboutData;
if (mode == BaseMode::InfoCenter) {
// About data
aboutData = KAboutData(QStringLiteral("kinfocenter"), i18n("Info Center"), QLatin1String(PROJECT_VERSION), i18n("Centralized and convenient overview of system information."), KAboutLicense::GPL, i18n("(c) 2009, Ben Cooksley"));
aboutData.addAuthor(i18n("Ben Cooksley"), i18n("Maintainer"), QStringLiteral("bcooksley@kde.org"));
aboutData.addAuthor(i18n("Mathias Soeken"), i18n("Developer"), QStringLiteral("msoeken@informatik.uni-bremen.de"));
aboutData.addAuthor(i18n("Will Stephenson"), i18n("Internal module representation, internal module model"), QStringLiteral("wstephenson@kde.org"));
aboutData.setDesktopFileName(QStringLiteral("org.kde.kinfocenter"));
application.setWindowIcon(QIcon::fromTheme(QStringLiteral("hwinfo")));
} else {
aboutData = KAboutData(QStringLiteral("systemsettings"), i18n("System Settings"), QLatin1String(PROJECT_VERSION), i18n("Central configuration center by KDE."), KAboutLicense::GPL, i18n("(c) 2009, Ben Cooksley"));
aboutData.addAuthor(i18n("Ben Cooksley"), i18n("Maintainer"), QStringLiteral("bcooksley@kde.org"));
aboutData.addAuthor(i18n("Mathias Soeken"), i18n("Developer"), QStringLiteral("msoeken@informatik.uni-bremen.de"));
aboutData.addAuthor(i18n("Will Stephenson"), i18n("Internal module representation, internal module model"), QStringLiteral("wstephenson@kde.org"));
if (qEnvironmentVariableIsSet("KDE_FULL_SESSION")) {
aboutData.setDesktopFileName(QStringLiteral("systemsettings"));
} else {
aboutData.setDesktopFileName(QStringLiteral("kdesystemsettings"));
}
application.setWindowIcon(QIcon::fromTheme(QStringLiteral("preferences-system")));
}
application.setAttribute(Qt::AA_UseHighDpiPixmaps, true);
aboutData.addAuthor(i18n("Ben Cooksley"), i18n("Maintainer"), QStringLiteral("bcooksley@kde.org"));
aboutData.addAuthor(i18n("Mathias Soeken"), i18n("Developer"), QStringLiteral("msoeken@informatik.uni-bremen.de"));
aboutData.addAuthor(i18n("Will Stephenson"), i18n("Internal module representation, internal module model"), QStringLiteral("wstephenson@kde.org"));
KAboutData::setApplicationData(aboutData);
QCoreApplication::setOrganizationDomain(QStringLiteral("kde.org"));
QCommandLineParser parser;
......@@ -108,6 +115,7 @@ int main( int argc, char *argv[] )
parser.addOption(QCommandLineOption(QStringLiteral("args"), i18n("Arguments for the module"), QLatin1String("arguments")));
aboutData.setupCommandLine(&parser);
parser.process(application);
aboutData.processCommandLine(&parser);
......@@ -136,33 +144,62 @@ int main( int argc, char *argv[] )
return 0;
}
if (mode == BaseMode::InfoCenter) {
aboutData.setDesktopFileName(QStringLiteral("org.kde.kinfocenter"));
application.setWindowIcon(QIcon::fromTheme(QStringLiteral("hwinfo")));
if (parser.positionalArguments().count() > 1) {
std::cerr << "Only one module argument may be passed" << std::endl;
return -1;
}
} else {
application.setWindowIcon(QIcon::fromTheme(QStringLiteral("preferences-system")));
const QStringList args = parser.value(QStringLiteral("args")).split(QRegExp(QStringLiteral(" +")), Qt::SkipEmptyParts);
QString startupModule;
if (qEnvironmentVariableIsSet("KDE_FULL_SESSION")) {
aboutData.setDesktopFileName(QStringLiteral("systemsettings"));
} else {
aboutData.setDesktopFileName(QStringLiteral("kdesystemsettings"));
}
if (parser.positionalArguments().count() == 1) {
startupModule = parser.positionalArguments().first();
}
KAboutData::setApplicationData(aboutData);
if (!args.isEmpty() && startupModule.isEmpty()) {
std::cerr << "Arguments may only be passed when specifying a module" << std::endl;
return -1;
}
KDBusService service(KDBusService::Unique);
KWorkSpace::detectPlatform(argc, argv);
KQuickAddons::QtQuickSettings::init();
KCrash::initialize();
KLocalizedString::setApplicationDomain(binaryName.toUtf8().constData());
SettingsBase *mainWindow = new SettingsBase(mode);
application.setMainWindow(mainWindow);
if (parser.positionalArguments().count() == 1) {
QStringList moduleArgs;
const QString x = parser.value(QStringLiteral("args"));
moduleArgs << x.split(QRegExp(QStringLiteral(" +")));
QObject::connect(&service, &KDBusService::activateRequested, mainWindow, [mainWindow](const QStringList &arguments, const QString &workingDirectory) {
Q_UNUSED(workingDirectory);
// We can't use startupModule and args from above since they come from the existing instance, so we need to parse arguments.
// We don't need to do the error checking again though.
QCommandLineParser parser;
parser.addPositionalArgument(QStringLiteral("module"), i18n("Configuration module to open"));
parser.addOption(QCommandLineOption(QStringLiteral("args"), i18n("Arguments for the module"), QLatin1String("arguments")));
parser.parse(arguments);
const QStringList args = parser.value(QStringLiteral("args")).split(QRegExp(QStringLiteral(" +")), Qt::SkipEmptyParts);
QString startupModule;
if (parser.positionalArguments().count() == 1) {
startupModule = parser.positionalArguments().first();
}
if (!startupModule.isEmpty()) {
mainWindow->setStartupModule(startupModule);
mainWindow->setStartupModuleArgs(args);
mainWindow->reloadStartupModule();
}
KWindowSystem::forceActiveWindow(mainWindow->winId());
});
mainWindow->setStartupModule(parser.positionalArguments().first());
mainWindow->setStartupModuleArgs(moduleArgs);
if (!startupModule.isEmpty()) {
mainWindow->setStartupModule(startupModule);
mainWindow->setStartupModuleArgs(args);
}
return application.exec();
......
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<interface name="local.SystemSettingsApp">
<method name="quit">
</method>
</interface>
</node>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment