diff --git a/CMakeLists.txt b/CMakeLists.txt index 89b6291..303a027 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,82 +1,93 @@ -project(libdebconf-kde) +cmake_minimum_required(VERSION 3.1) +cmake_policy(SET CMP0048 NEW) -set(PROJECT_VERSION_MAJOR 1) -set(PROJECT_VERSION_MINOR 0) -set(PROJECT_VERSION_PATCH 2) -set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}" ) +if (POLICY CMP0043) + cmake_policy(SET CMP0043 NEW) +endif() +if (POLICY CMP0063) + cmake_policy(SET CMP0063 NEW) +endif() -cmake_minimum_required(VERSION 2.8.12) +project(libdebconf-kde VERSION 1.1.0) find_package(ECM 0.0.14 REQUIRED NO_MODULE) set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules) include(ECMPackageConfigHelpers) include(ECMSetupVersion) include(FeatureSummary) include(KDEInstallDirs) include(KDECMakeSettings) include(KDECompilerSettings) set(REQUIRED_QT_VERSION 5.2.0) # Used in CMakeConfig to check deps find_package(Qt5 ${REQUIRED_QT_VERSION} CONFIG REQUIRED COMPONENTS Widgets Network ) find_package(KF5 5.0.0 REQUIRED COMPONENTS CoreAddons I18n IconThemes TextWidgets WidgetsAddons ) if(ECM_VERSION VERSION_GREATER 1.5.0) # >1.5 has an optional compatibility option for the package version file. # TODO: bump dep and remove this check once 1.7 is out. set(VERSION_COMPAT_OPTION COMPATIBILITY SameMajorVersion) endif() ecm_setup_version(${PROJECT_VERSION} VARIABLE_PREFIX DEBCONF SOVERSION ${PROJECT_VERSION_MAJOR} VERSION_HEADER "${CMAKE_CURRENT_BINARY_DIR}/DebconfVersion.h" PACKAGE_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/DebconfKDEConfigVersion.cmake" ${VERSION_COMPAT_OPTION} ) add_definitions(-DPROJECT_VERSION=\"${PROJECT_VERSION}\") -add_definitions(-DQT_NO_CAST_FROM_ASCII) -add_definitions(-DQT_NO_CAST_TO_ASCII) +add_definitions( + -DQT_NO_KEYWORDS + -DQT_NO_CAST_TO_ASCII + -DQT_NO_CAST_FROM_ASCII + -DQT_STRICT_ITERATORS + -DQT_NO_URL_CAST_FROM_STRING + -DQT_NO_CAST_FROM_BYTEARRAY + -DQT_USE_QSTRINGBUILDER + -DQT_DISABLE_DEPRECATED_BEFORE=0x050900 +) include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ) # create a Config.cmake and a ConfigVersion.cmake file and install them set(CMAKECONFIG_INSTALL_DIR "${CMAKECONFIG_INSTALL_PREFIX}/DebconfKDE") ecm_configure_package_config_file( "${CMAKE_CURRENT_SOURCE_DIR}/DebconfKDEConfig.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/DebconfKDEConfig.cmake" INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR}) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/DebconfKDEConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/DebconfKDEConfigVersion.cmake" DESTINATION "${CMAKECONFIG_INSTALL_DIR}" COMPONENT Devel) install(EXPORT DebconfKDETargets DESTINATION "${CMAKECONFIG_INSTALL_DIR}" FILE DebconfKDETargets.cmake NAMESPACE DebconfKDE::) add_subdirectory(src) add_subdirectory(tools) feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index bbd664f..a6640ed 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,52 +1,52 @@ set(libdebconf_SRCS debconf.cpp DebconfElement.cpp DebconfBoolean.cpp DebconfError.cpp DebconfMultiselect.cpp DebconfNote.cpp DebconfPassword.cpp DebconfProgress.cpp DebconfSelect.cpp DebconfString.cpp DebconfText.cpp DebconfGui.cpp Debug.cpp) ki18n_wrap_ui(libdebconf_SRCS DebconfBoolean.ui DebconfError.ui DebconfMultiselect.ui DebconfNote.ui DebconfPassword.ui DebconfProgress.ui DebconfSelect.ui DebconfString.ui DebconfText.ui DebconfGui.ui) add_definitions(-DTRANSLATION_DOMAIN=\"libdebconf-kde\") add_library(debconf-kde SHARED ${libdebconf_SRCS}) add_library(DebconfKDE::Main ALIAS debconf-kde) target_link_libraries(debconf-kde PUBLIC Qt5::Widgets PRIVATE Qt5::Network KF5::I18n KF5::IconThemes KF5::TextWidgets KF5::WidgetsAddons ) target_include_directories(debconf-kde INTERFACE "$") set_target_properties(debconf-kde PROPERTIES - VERSION ${DEBCONF_VERSION_STRING} + VERSION ${PROJECT_VERSION} SOVERSION ${DEBCONF_SOVERSION} EXPORT_NAME Main) install(TARGETS debconf-kde EXPORT DebconfKDETargets ${INSTALL_TARGETS_DEFAULT_ARGS}) install(FILES DebconfGui.h DESTINATION ${INCLUDE_INSTALL_DIR}/DebconfKDE) diff --git a/src/DebconfBoolean.cpp b/src/DebconfBoolean.cpp index 665db9c..c761a12 100644 --- a/src/DebconfBoolean.cpp +++ b/src/DebconfBoolean.cpp @@ -1,59 +1,61 @@ /* - * Copyright (C) 2010 Daniel Nicoletti + * Copyright (C) 2010-2018 Daniel Nicoletti * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library 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 "DebconfBoolean.h" #include #include using namespace DebconfKde; DebconfBoolean::DebconfBoolean(const QString &name, QWidget *parent) : DebconfElement(name, parent) { setupUi(this); const KGuiItem yes = KStandardGuiItem::yes(); radioButton->setText(yes.text()); radioButton->setToolTip(yes.toolTip()); radioButton->setWhatsThis(yes.whatsThis()); const KGuiItem no = KStandardGuiItem::no(); radioButton_2->setText(no.text()); radioButton_2->setToolTip(no.toolTip()); radioButton_2->setWhatsThis(no.whatsThis()); } DebconfBoolean::~DebconfBoolean() { } QString DebconfBoolean::value() const { - return radioButton->isChecked() ? QStringLiteral( "true" ) : QStringLiteral( "false" ); + return radioButton->isChecked() ? QLatin1String("true") : QLatin1String("false"); } void DebconfBoolean::setBoolean(const QString &extended_description, const QString &description, bool default_boolean) { extendedDescriptionL->setText(extended_description); descriptionL->setText(description); radioButton->setChecked(default_boolean); } + +#include "moc_DebconfBoolean.cpp" diff --git a/src/DebconfElement.cpp b/src/DebconfElement.cpp index 839c516..74d3179 100644 --- a/src/DebconfElement.cpp +++ b/src/DebconfElement.cpp @@ -1,25 +1,27 @@ /* * Copyright (C) 2010 Daniel Nicoletti * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library 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 "DebconfElement.h" DebconfElement::DebconfElement(const QString &name, QWidget *parent) : QWidget(parent), m_name(name) { } + +#include "moc_DebconfElement.cpp" diff --git a/src/DebconfError.cpp b/src/DebconfError.cpp index 6b4c84d..dae0a4e 100644 --- a/src/DebconfError.cpp +++ b/src/DebconfError.cpp @@ -1,49 +1,51 @@ /* * Copyright (C) 2010 Daniel Nicoletti * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library 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 "DebconfError.h" #include #include using namespace DebconfKde; DebconfError::DebconfError(const QString &name, QWidget *parent) : DebconfElement(name, parent) { setupUi(this); - iconL->setPixmap(QIcon::fromTheme(QStringLiteral("dialog-error")).pixmap(KIconLoader::SizeHuge, - KIconLoader::SizeHuge)); + iconL->setPixmap(QIcon::fromTheme(QLatin1String("dialog-error")).pixmap(KIconLoader::SizeHuge, + KIconLoader::SizeHuge)); } DebconfError::~DebconfError() { } int DebconfError::nextId() const { return 0; } void DebconfError::setError(const QString &description, const QString &error) { descriptionL->setText(description); textTE->setText(error); } + +#include "moc_DebconfError.cpp" diff --git a/src/DebconfGui.cpp b/src/DebconfGui.cpp index 8125d9c..34b6bcb 100644 --- a/src/DebconfGui.cpp +++ b/src/DebconfGui.cpp @@ -1,375 +1,372 @@ // This license reflects the original Adept code: // -*- C++ -*- (c) 2008 Petr Rockai // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following // disclaimer in the documentation and/or other materials provided // with the distribution. // // * Neither the name of [original copyright holder] nor the names of // its contributors may be used to endorse or promote products // derived from this software without specific prior written // permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. /* * All the modifications below are licensed under this license - * Copyright (C) 2010 Daniel Nicoletti + * Copyright (C) 2010-2018 Daniel Nicoletti * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library 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 "DebconfGui.h" #include "ui_DebconfGui.h" #include "DebconfBoolean.h" #include "DebconfError.h" #include "DebconfMultiselect.h" #include "DebconfNote.h" #include "DebconfPassword.h" #include "DebconfProgress.h" #include "DebconfSelect.h" #include "DebconfString.h" #include "DebconfText.h" #include "Debug_p.h" #include #include #include #include #include #include #include #include #include using namespace DebconfKde; class DebconfKde::DebconfGuiPrivate : public Ui::DebconfGui { public: virtual ~DebconfGuiPrivate() { } DebconfFrontend *frontend; - DebconfProgress *elementProgress; - QWidget *parentWidget; - QList elements; + DebconfProgress *elementProgress = nullptr; + QWidget *parentWidget = nullptr; + QVector elements; DebconfElement* createElement(const QString &k); void cleanup(); }; DebconfGui::DebconfGui(const QString &socketName, QWidget *parent) : QWidget(parent), d_ptr(new DebconfGuiPrivate) { Q_D(DebconfGui); d->frontend = new DebconfFrontendSocket(socketName, this); init(); } DebconfGui::DebconfGui(int readfd, int writefd, QWidget *parent) : QWidget(parent), d_ptr(new DebconfGuiPrivate) { Q_D(DebconfGui); d->frontend = new DebconfFrontendFifo(readfd, writefd, this); init(); } DebconfGui::~DebconfGui() { delete d_ptr; } void DebconfGui::init() { Q_D(DebconfGui); - d->elementProgress = 0; - d->parentWidget = 0; d->setupUi(this); // Setup buttons. They are marked non-translatable in the UI file. KGuiItem::assign(d->cancelPB, KStandardGuiItem::cancel()); KGuiItem::assign(d->backPB, KStandardGuiItem::back()); KGuiItem::assign(d->nextPB, KStandardGuiItem::cont()); setMinimumSize(500, 400); d->cancelPB->setVisible(false); - connect(d->frontend, SIGNAL(go(QString,QStringList)), - this, SLOT(cmd_go(QString,QStringList))); - connect(d->frontend, SIGNAL(finished()), - this, SIGNAL(deactivated())); - connect(d->frontend, SIGNAL(progress(QString)), - this, SLOT(cmd_progress(QString))); - connect(d->frontend, SIGNAL(backup(bool)), - d->backPB, SLOT(setEnabled(bool))); + connect(d->frontend, &DebconfFrontend::go, this, &DebconfGui::cmd_go); + connect(d->frontend, &DebconfFrontend::finished, this, &DebconfGui::deactivated); + connect(d->frontend, &DebconfFrontend::progress, this, &DebconfGui::cmd_progress); + connect(d->frontend, &DebconfFrontend::backup, d->backPB, &QPushButton::setEnabled); // find out the distribution logo - QString distro_logo(QStringLiteral( "/usr/share/pixmaps/debian-logo.png" )); - QProcess *myProcess = new QProcess(this); + QString distro_logo(QLatin1String("/usr/share/pixmaps/debian-logo.png")); + auto myProcess = new QProcess(this); - myProcess->start(QStringLiteral( "hostname" )); + myProcess->start(QLatin1String("hostname")); myProcess->waitForFinished(); - QString hostname = QString::fromLatin1( myProcess->readAllStandardOutput() ); + const QString hostname = QString::fromLatin1(myProcess->readAllStandardOutput()); setWindowTitle(i18n("Debconf on %1", hostname.trimmed())); - myProcess->start(QStringLiteral( "lsb_release" ), QStringList() << QStringLiteral( "-is" )); + myProcess->start(QLatin1String("lsb_release"), { QLatin1String("-is") }); if (myProcess->waitForFinished()) { if (myProcess->exitCode() == 0){ - QString data = QLatin1String( myProcess->readAllStandardOutput() ); - data = QString(QLatin1String( "/usr/share/pixmaps/%1-logo.png" )).arg(data.trimmed().toLower()); + QString data = QString::fromLatin1(myProcess->readAllStandardOutput()); + data = QString(QLatin1String("/usr/share/pixmaps/%1-logo.png")).arg(data.trimmed().toLower()); if (QFile::exists(data)) { distro_logo = data; } } } - QPixmap icon = KIconLoader::global()->loadIcon(distro_logo, - KIconLoader::NoGroup, - KIconLoader::SizeLarge, - KIconLoader::DefaultState); + const QPixmap icon = KIconLoader::global()->loadIcon(distro_logo, + KIconLoader::NoGroup, + KIconLoader::SizeLarge, + KIconLoader::DefaultState); if (!icon.isNull()) { d->iconL->setPixmap(icon); setWindowIcon(icon); } d->scrollArea->viewport()->setAutoFillBackground(false); } DebconfElement* DebconfGuiPrivate::createElement(const QString &k) { qCDebug(DEBCONF) << "creating widget for " << k; QString extendedDescription = frontend->property(k, DebconfFrontend::ExtendedDescription); - extendedDescription.replace(QStringLiteral( "\\n" ), QStringLiteral( "\n" )); + extendedDescription.replace(QLatin1String("\\n"), QLatin1String("\n")); switch (frontend->type(k)) { case DebconfFrontend::Boolean: { - DebconfBoolean *element = new DebconfBoolean(k, parentWidget); + auto element = new DebconfBoolean(k, parentWidget); element->setBoolean(extendedDescription, frontend->property(k, DebconfFrontend::Description), - frontend->value(k) == QStringLiteral( "true" )); + frontend->value(k) == QLatin1String("true")); return element; } case DebconfFrontend::Error: { - DebconfError *element = new DebconfError(k, parentWidget); + auto element = new DebconfError(k, parentWidget); element->setError(extendedDescription, frontend->property(k, DebconfFrontend::Description)); return element; } case DebconfFrontend::Multiselect: { - DebconfMultiselect *element = new DebconfMultiselect(k, parentWidget); + auto element = new DebconfMultiselect(k, parentWidget); element->setMultiselect(extendedDescription, frontend->property(k, DebconfFrontend::Description), - frontend->value(k).split(QStringLiteral( ", " )), - frontend->property(k, DebconfFrontend::Choices).split(QStringLiteral( ", " ))); + frontend->value(k).split(QLatin1String(", ")), + frontend->property(k, DebconfFrontend::Choices).split(QLatin1String(", "))); return element; } case DebconfFrontend::Note: { - DebconfNote *element = new DebconfNote(k, parentWidget); + auto element = new DebconfNote(k, parentWidget); element->setNote(extendedDescription, frontend->property(k, DebconfFrontend::Description)); return element; } case DebconfFrontend::Password: { - DebconfPassword *element = new DebconfPassword(k, parentWidget); + auto element = new DebconfPassword(k, parentWidget); element->setPassword(extendedDescription, frontend->property(k, DebconfFrontend::Description)); return element; } case DebconfFrontend::Select: { - DebconfSelect *element = new DebconfSelect(k, parentWidget); + auto element = new DebconfSelect(k, parentWidget); element->setSelect(extendedDescription, frontend->property(k, DebconfFrontend::Description), frontend->value(k), - frontend->property(k, DebconfFrontend::Choices).split(QStringLiteral( ", " ))); + frontend->property(k, DebconfFrontend::Choices).split(QLatin1String(", "))); return element; } case DebconfFrontend::String: { - DebconfString *element = new DebconfString(k, parentWidget); + auto element = new DebconfString(k, parentWidget); element->setString(extendedDescription, frontend->property(k, DebconfFrontend::Description), frontend->value(k)); return element; } case DebconfFrontend::Text: { - DebconfText *element = new DebconfText(k, parentWidget); + auto element = new DebconfText(k, parentWidget); element->setText(frontend->property(k, DebconfFrontend::Description)); return element; } default: qWarning() << "Default REACHED!!!"; - DebconfElement *element = new DebconfElement(k, parentWidget); - QLabel *label = new QLabel(element); + auto element = new DebconfElement(k, parentWidget); + auto label = new QLabel(element); label->setText(i18n("Not implemented: The input widget for data" " type '%1' is not implemented. Will use default of '%2'.", frontend->property(k, DebconfFrontend::Type), frontend->value(k))); label->setWordWrap(true); return element; } } void DebconfGui::cmd_go(const QString &title, const QStringList &input) { Q_D(DebconfGui); qCDebug(DEBCONF) << "# GO GUI"; d->cleanup(); - QVBoxLayout *layout = qobject_cast(d->parentWidget->layout()); + auto layout = qobject_cast(d->parentWidget->layout()); // if we have just one element and we are showing // elements that can make use of extra space // we don't add stretches bool needStretch = true; if (input.size() == 1) { - QString key = input.first(); + const QString key = input.first(); if (d->frontend->type(key) == DebconfFrontend::Text && d->frontend->type(key) == DebconfFrontend::Note && d->frontend->type(key) == DebconfFrontend::Error && d->frontend->type(key) == DebconfFrontend::Multiselect) { needStretch = false; } } if (needStretch) { layout->addStretch(); } - foreach (const QString &elementName, input) { + for (const QString &elementName : input) { DebconfElement *element = d->createElement(elementName); d->elements.append(element); layout->addWidget(element); } if (needStretch) { layout->addStretch(); } d->parentWidget->setAutoFillBackground(false); d->titleL->setText(title); d->nextPB->setEnabled(true); - emit activated(); + Q_EMIT activated(); } void DebconfGui::cmd_progress(const QString &cmd) { Q_D(DebconfGui); if (!d->elementProgress) { d->cleanup(); d->elementProgress = new DebconfProgress(QString(), d->parentWidget); - QVBoxLayout *layout = qobject_cast(d->parentWidget->layout()); + auto layout = qobject_cast(d->parentWidget->layout()); layout->addStretch(); layout->addWidget(d->elementProgress); layout->addStretch(); d->parentWidget->setAutoFillBackground(false); d->nextPB->setEnabled(false); d->backPB->setEnabled(false); } DebconfProgress *element = d->elementProgress; - QStringList commands = cmd.split(QLatin1Char( ' ' )); + QStringList commands = cmd.split(QLatin1Char(' ')); qCDebug(DEBCONF) << "KPROGRESS" << commands; - if (commands.first() == QStringLiteral( "START" )) { + if (commands.first() == QLatin1String("START")) { d->titleL->setText(d->frontend->property(commands.at(3), DebconfFrontend::Description)); int progress_min = commands.at(1).toInt(); int progress_max = commands.at(2).toInt(); element->startProgress(d->frontend->property(commands.at(3), DebconfFrontend::ExtendedDescription), progress_min, progress_max); - } else if (commands.first() == QStringLiteral( "SET" )) { + } else if (commands.first() == QLatin1String("SET")) { element->setProgress(commands.at(1).toInt()); - } else if (commands.first() == QStringLiteral( "STEP" )) { + } else if (commands.first() == QLatin1String("STEP")) { element->stepProgress(commands.at(1).toInt()); - } else if (commands.first() == QStringLiteral( "INFO" )) { + } else if (commands.first() == QLatin1String("INFO")) { element->setProgressInfo(d->frontend->property(commands.at(1), DebconfFrontend::Description)); - } else if (commands.first() == QStringLiteral( "STOP" )) { + } else if (commands.first() == QLatin1String("STOP")) { element->stopProgress(); } - emit activated(); - d->frontend->say(QStringLiteral( "0 ok" )); + Q_EMIT activated(); + d->frontend->say(QLatin1String("0 ok")); } void DebconfGuiPrivate::cleanup() { delete parentWidget; - elementProgress = 0; + elementProgress = nullptr; elements.clear(); parentWidget = new QWidget(scrollArea); scrollArea->setWidget(parentWidget); - QVBoxLayout *layout = new QVBoxLayout(parentWidget); + auto layout = new QVBoxLayout(parentWidget); parentWidget->setLayout(layout); } void DebconfGui::on_nextPB_clicked() { Q_D(DebconfGui); // extract all the elements - foreach (const DebconfElement *element, d->elements) { + const auto elements = d->elements; + for (const DebconfElement *element : elements) { d->frontend->setValue(element->name(), element->value()); } d->frontend->next(); } void DebconfGui::on_backPB_clicked() { Q_D(DebconfGui); d->frontend->back(); } void DebconfGui::on_cancelPB_clicked() { Q_D(DebconfGui); d->frontend->cancel(); } void DebconfGui::closeEvent(QCloseEvent *event) { Q_D(DebconfGui); // It would be better to hid the close button on // on the window decoration: d->frontend->cancel(); QWidget::closeEvent(event); } + +#include "moc_DebconfGui.cpp" diff --git a/src/DebconfMultiselect.cpp b/src/DebconfMultiselect.cpp index fa01e20..755add1 100644 --- a/src/DebconfMultiselect.cpp +++ b/src/DebconfMultiselect.cpp @@ -1,73 +1,75 @@ /* - * Copyright (C) 2010 Daniel Nicoletti + * Copyright (C) 2010-2018 Daniel Nicoletti * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library 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 "DebconfMultiselect.h" #include #include using namespace DebconfKde; DebconfMultiselect::DebconfMultiselect(const QString &name, QWidget *parent) : DebconfElement(name, parent) { setupUi(this); m_model = new QStandardItemModel(this); multiselectLV->setModel(m_model); } DebconfMultiselect::~DebconfMultiselect() { } QString DebconfMultiselect::value() const { QStringList checked; for (int i = 0; i < m_model->rowCount(); i++) { int state; state = m_model->data(m_model->index(i, 0), Qt::CheckStateRole).toInt(); if (state == Qt::Checked) { checked << m_model->data(m_model->index(i, 0), Qt::DisplayRole).toString(); } } - return checked.join(QStringLiteral( ", " )); + return checked.join(QLatin1String(", ")); } void DebconfMultiselect::setMultiselect(const QString &extended_description, const QString &description, const QStringList &default_choices, const QStringList &choices) { extendedDescriptionL->setText(extended_description); descriptionL->setText(description); m_model->clear(); - foreach (const QString &choice, choices) { - QStandardItem *item; - m_model->appendRow(item = new QStandardItem(choice)); + for (const QString &choice : choices) { + auto item = new QStandardItem(choice); item->setSelectable(false); item->setCheckable(true); if (default_choices.contains(choice)) { item->setCheckState(Qt::Checked); } else { item->setCheckState(Qt::Unchecked); } + m_model->appendRow(item); } } + +#include "moc_DebconfMultiselect.cpp" diff --git a/src/DebconfNote.cpp b/src/DebconfNote.cpp index 5b1013d..9b42247 100644 --- a/src/DebconfNote.cpp +++ b/src/DebconfNote.cpp @@ -1,38 +1,40 @@ /* * Copyright (C) 2010 Daniel Nicoletti * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library 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 "DebconfNote.h" using namespace DebconfKde; DebconfNote::DebconfNote(const QString &name, QWidget *parent) : DebconfElement(name, parent) { setupUi(this); } DebconfNote::~DebconfNote() { } void DebconfNote::setNote(const QString &description, const QString ¬e) { descriptionL->setText(description); noteTE->setText(note); } + +#include "moc_DebconfNote.cpp" diff --git a/src/DebconfPassword.cpp b/src/DebconfPassword.cpp index 244ac80..ae0d329 100644 --- a/src/DebconfPassword.cpp +++ b/src/DebconfPassword.cpp @@ -1,44 +1,46 @@ /* * Copyright (C) 2010 Daniel Nicoletti * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library 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 "DebconfPassword.h" using namespace DebconfKde; DebconfPassword::DebconfPassword(const QString &name, QWidget *parent) : DebconfElement(name, parent) { setupUi(this); } DebconfPassword::~DebconfPassword() { } QString DebconfPassword::value() const { return passwordLE->text(); } void DebconfPassword::setPassword(const QString &extended_description, const QString &description) { extendedDescriptionL->setText(extended_description); descriptionL->setText(description); } + +#include "moc_DebconfPassword.cpp" diff --git a/src/DebconfProgress.cpp b/src/DebconfProgress.cpp index 2940319..0aa822d 100644 --- a/src/DebconfProgress.cpp +++ b/src/DebconfProgress.cpp @@ -1,62 +1,64 @@ /* * Copyright (C) 2010 Daniel Nicoletti * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library 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 "DebconfProgress.h" using namespace DebconfKde; DebconfProgress::DebconfProgress(const QString &name, QWidget *parent) : DebconfElement(name, parent) { setupUi(this); } DebconfProgress::~DebconfProgress() { } void DebconfProgress::startProgress(const QString &extended_description, uint progress_min, uint progress_max) { label->setText(extended_description); progressBar->setMaximum(progress_max); progressBar->setMinimum(progress_min); progressBar->setValue(progress_min); } void DebconfProgress::stopProgress() { progressBar->setValue(progressBar->maximum()); } void DebconfProgress::setProgress(uint progress_cur) { progressBar->setValue(progress_cur); } void DebconfProgress::stepProgress(uint progress_step) { progressBar->setValue(progressBar->value() + progress_step); } void DebconfProgress::setProgressInfo(const QString &description) { label->setText(description); } + +#include "moc_DebconfProgress.cpp" diff --git a/src/DebconfSelect.cpp b/src/DebconfSelect.cpp index 305d7d4..740fc18 100644 --- a/src/DebconfSelect.cpp +++ b/src/DebconfSelect.cpp @@ -1,51 +1,53 @@ /* * Copyright (C) 2010 Daniel Nicoletti * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library 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 "DebconfSelect.h" using namespace DebconfKde; DebconfSelect::DebconfSelect(const QString &name, QWidget *parent) : DebconfElement(name, parent) { setupUi(this); } DebconfSelect::~DebconfSelect() { } QString DebconfSelect::value() const { return selectCB->currentText(); } void DebconfSelect::setSelect(const QString &extended_description, const QString &description, const QString &default_choice, const QStringList &choices) { extendedDescriptionL->setText(extended_description); descriptionL->setText(description); selectCB->clear(); selectCB->addItems(choices); int index = selectCB->findText(default_choice); selectCB->setCurrentIndex(index != -1 ? index : 0); } + +#include "moc_DebconfSelect.cpp" diff --git a/src/DebconfString.cpp b/src/DebconfString.cpp index 1405231..de0b477 100644 --- a/src/DebconfString.cpp +++ b/src/DebconfString.cpp @@ -1,46 +1,48 @@ /* * Copyright (C) 2010 Daniel Nicoletti * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library 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 "DebconfString.h" using namespace DebconfKde; DebconfString::DebconfString(const QString &name, QWidget *parent) : DebconfElement(name, parent) { setupUi(this); } DebconfString::~DebconfString() { } QString DebconfString::value() const { return stringLE->text(); } void DebconfString::setString(const QString &extended_description, const QString &description, const QString &default_string) { extendedDescriptionL->setText(extended_description); descriptionL->setText(description); stringLE->setText(default_string); } + +#include "moc_DebconfString.cpp" diff --git a/src/DebconfText.cpp b/src/DebconfText.cpp index b7b4dd8..bbbd5b9 100644 --- a/src/DebconfText.cpp +++ b/src/DebconfText.cpp @@ -1,37 +1,39 @@ /* * Copyright (C) 2010 Daniel Nicoletti * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library 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 "DebconfText.h" using namespace DebconfKde; DebconfText::DebconfText(const QString &name, QWidget *parent) : DebconfElement(name, parent) { setupUi(this); } DebconfText::~DebconfText() { } void DebconfText::setText(const QString &text) { textTE->setText(text); } + +#include "moc_DebconfText.cpp" diff --git a/src/debconf.cpp b/src/debconf.cpp index 1055785..8b0568d 100644 --- a/src/debconf.cpp +++ b/src/debconf.cpp @@ -1,559 +1,560 @@ // This license reflects the original Adept code: // -*- C++ -*- (c) 2008 Petr Rockai // (c) 2011 Modestas Vainius // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following // disclaimer in the documentation and/or other materials provided // with the distribution. // // * Neither the name of [original copyright holder] nor the names of // its contributors may be used to endorse or promote products // derived from this software without specific prior written // permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. /* * All the modifications below are licensed under this license - * Copyright (C) 2010 Daniel Nicoletti + * Copyright (C) 2010-2018 Daniel Nicoletti * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library 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 "debconf.h" #include #include -#include #include #include #include #include "Debug_p.h" namespace DebconfKde { const DebconfFrontend::Cmd DebconfFrontend::commands[] = { { "SET", &DebconfFrontend::cmd_set }, { "GO", &DebconfFrontend::cmd_go }, { "TITLE", &DebconfFrontend::cmd_title }, { "SETTITLE", &DebconfFrontend::cmd_title }, { "DATA", &DebconfFrontend::cmd_data }, { "SUBST", &DebconfFrontend::cmd_subst }, { "INPUT", &DebconfFrontend::cmd_input }, { "GET", &DebconfFrontend::cmd_get }, { "CAPB", &DebconfFrontend::cmd_capb }, { "PROGRESS", &DebconfFrontend::cmd_progress }, { "X_PING", &DebconfFrontend::cmd_x_ping }, { "VERSION", &DebconfFrontend::cmd_version }, { "X_LOADTEMPLATEFILE", &DebconfFrontend::cmd_x_loadtemplatefile }, { "INFO", &DebconfFrontend::cmd_info }, { "FGET", &DebconfFrontend::cmd_fget }, { "FSET", &DebconfFrontend::cmd_fset }, { "BEGINBLOCK", &DebconfFrontend::cmd_beginblock }, { "ENDBLOCK", &DebconfFrontend::cmd_endblock }, { "STOP", &DebconfFrontend::cmd_stop }, { 0, 0 } }; DebconfFrontend::DebconfFrontend(QObject *parent) : QObject(parent) { } DebconfFrontend::~DebconfFrontend() { } void DebconfFrontend::disconnected() { reset(); - emit finished(); + Q_EMIT finished(); } QString DebconfFrontend::value(const QString &key) const { return m_values[key]; } void DebconfFrontend::setValue(const QString &key, const QString &value) { m_values[key] = value; } template int DebconfFrontend::enumFromString(const QString &str, const char *enumName) { QString realName(str); realName.replace(0, 1, str.at(0).toUpper()); int pos; while ((pos = realName.indexOf(QLatin1Char( '_' ))) != -1) { if (pos + 1 >= realName.size()) { // pos is from 0, size from 1, mustn't go off-by-one realName.chop(1); } else{ realName.replace(pos, 2, realName.at(pos + 1).toUpper()); } } int id = T::staticMetaObject.indexOfEnumerator(enumName); QMetaEnum e = T::staticMetaObject.enumerator(id); int enumValue = e.keyToValue(realName.toLatin1().data()); if(enumValue == -1) { - enumValue = e.keyToValue(QString(QStringLiteral( "Unknown" )).append(QLatin1String( enumName )).toLatin1().data()); - qCDebug(DEBCONF) << "enumFromString (" <(enumFromString(string, "PropertyKey" )); } DebconfFrontend::TypeKey DebconfFrontend::type(const QString &string) const { return static_cast(enumFromString(property(string, Type), "TypeKey" )); } void DebconfFrontend::reset() { - emit backup(false); + Q_EMIT backup(false); m_data.clear(); m_subst.clear(); m_values.clear(); m_flags.clear(); } void DebconfFrontend::say(const QString &string) { qCDebug(DEBCONF) << "DEBCONF ---> " << string; QTextStream out(getWriteDevice()); out << string << "\n"; out.flush(); } QString DebconfFrontend::substitute(const QString &key, const QString &rest) const { Substitutions sub = m_subst[key]; QString result, var, escape; - QRegExp rx(QStringLiteral( "^(.*)(\\\\)?\\$\\{([^\\{\\}]+)\\}(.*)$" )); + QRegExp rx(QLatin1String("^(.*)(\\\\)?\\$\\{([^\\{\\}]+)\\}(.*)$")); QString last(rest); int pos = 0; - while ( (pos = rx.indexIn(rest, pos)) != -1) { + while ((pos = rx.indexIn(rest, pos)) != -1) { qCDebug(DEBCONF) << "var found! at" << pos; result += rx.cap(1); escape = rx.cap(2); var = rx.cap(3); last = rx.cap(4); if (!escape.isEmpty()) { - result += QString(QLatin1Literal( "${" ) % var % QLatin1Char( '}' )); + result += QLatin1Literal("${") + var + QLatin1Char('}'); } else { result += sub.value(var); } pos += rx.matchedLength(); } return result + last; } QString DebconfFrontend::property(const QString &key, PropertyKey p) const { - QString r = m_data.value(key).value(p); + const QString r = m_data.value(key).value(p); if (p == Description || p == Choices) { return substitute(key, r); } return r; } void DebconfFrontend::cmd_capb(const QString &caps) { - emit backup(caps.split(QStringLiteral( ", " )).contains(QStringLiteral( "backup" ))); - say(QStringLiteral( "0 backup" )); + Q_EMIT backup(caps.split(QLatin1String(", ")).contains(QLatin1String("backup"))); + say(QLatin1String("0 backup")); } void DebconfFrontend::cmd_set(const QString ¶m) { - QString item = param.section(QLatin1Char( ' ' ), 0, 0); - QString value = param.section(QLatin1Char( ' ' ), 1); + const QString item = param.section(QLatin1Char(' '), 0, 0); + const QString value = param.section(QLatin1Char(' '), 1); m_values[item] = value; qCDebug(DEBCONF) << "# SET: [" << item << "] " << value; - say(QStringLiteral( "0 ok" )); + say(QLatin1String("0 ok")); } void DebconfFrontend::cmd_get(const QString ¶m) { - say(QStringLiteral( "0 " ) + m_values.value(param)); + say(QLatin1String("0 ") + m_values.value(param)); } void DebconfFrontend::cmd_input(const QString ¶m) { - m_input.append(param.section(QLatin1Char( ' ' ), 1)); - say(QStringLiteral( "0 will ask" )); + m_input.append(param.section(QLatin1Char(' '), 1)); + say(QLatin1String("0 will ask" )); } void DebconfFrontend::cmd_go(const QString &) { qCDebug(DEBCONF) << "# GO"; m_input.removeDuplicates(); - emit go(m_title, m_input); + Q_EMIT go(m_title, m_input); m_input.clear(); } void DebconfFrontend::cmd_progress(const QString ¶m) { qCDebug(DEBCONF) << "DEBCONF: PROGRESS " << param; - emit progress(param); + Q_EMIT progress(param); } void DebconfFrontend::next() { m_input.clear(); - say(QStringLiteral( "0 ok, got the answers" )); + say(QLatin1String("0 ok, got the answers")); } void DebconfFrontend::back() { m_input.clear(); - say(QStringLiteral( "30 go back" )); + say(QLatin1String("30 go back")); } void DebconfFrontend::cancel() { reset(); } void DebconfFrontend::cmd_title(const QString ¶m) { if (!property(param, Description).isEmpty()) { m_title = property(param, Description); } else { m_title = param; } qCDebug(DEBCONF) << "DEBCONF: TITLE " << m_title; - say(QStringLiteral( "0 ok" )); + say(QLatin1String("0 ok")); } void DebconfFrontend::cmd_data(const QString ¶m) { // We get strings like // aiccu/brokername description Tunnel broker: // item = "aiccu/brokername" // type = "description" // rest = "Tunnel broker:" - QString item = param.section(QLatin1Char( ' ' ), 0, 0); - QString type = param.section(QLatin1Char( ' ' ), 1, 1); - QString value = param.section(QLatin1Char( ' ' ), 2); + const QString item = param.section(QLatin1Char(' '), 0, 0); + const QString type = param.section(QLatin1Char(' '), 1, 1); + const QString value = param.section(QLatin1Char(' '), 2); m_data[item][propertyKeyFromString(type)] = value; qCDebug(DEBCONF) << "# NOTED: [" << item << "] [" << type << "] " << value; say(QStringLiteral( "0 ok" )); } void DebconfFrontend::cmd_subst(const QString ¶m) { // We get strings like // aiccu/brokername brokers AARNet, Hexago / Freenet6, SixXS, Wanadoo France // item = "aiccu/brokername" // type = "brokers" // value = "AARNet, Hexago / Freenet6, SixXS, Wanadoo France" - QString item = param.section(QLatin1Char( ' ' ), 0, 0); - QString type = param.section(QLatin1Char( ' ' ), 1, 1); - QString value = param.section(QLatin1Char( ' ' ), 2); + const QString item = param.section(QLatin1Char(' '), 0, 0); + const QString type = param.section(QLatin1Char(' '), 1, 1); + const QString value = param.section(QLatin1Char(' '), 2); m_subst[item][type] = value; qCDebug(DEBCONF) << "# SUBST: [" << item << "] [" << type << "] " << value; - say(QStringLiteral( "0 ok" )); + say(QLatin1String("0 ok")); } void DebconfFrontend::cmd_x_ping(const QString ¶m) { Q_UNUSED(param); - say(QStringLiteral( "0 pong" )); + say(QLatin1String("0 pong")); } void DebconfFrontend::cmd_version(const QString ¶m) { if ( !param.isEmpty() ) { - QString major_version_str = param.section(QLatin1Char( '.' ), 0, 0); + const QString major_version_str = param.section(QLatin1Char('.'), 0, 0); bool ok = false; int major_version = major_version_str.toInt( &ok ); if ( !ok || (major_version != 2) ) { - say(QStringLiteral( "30 wrong or too old protocol version" )); + say(QLatin1String("30 wrong or too old protocol version")); return; } } //This debconf frontend is suposed to use the version 2.1 of the protocol. - say(QStringLiteral( "0 2.1" )); + say(QLatin1String("0 2.1")); } void DebconfFrontend::cmd_x_loadtemplatefile(const QString ¶m) { QFile template_file(param); if (template_file.open(QFile::ReadOnly)) { QTextStream template_stream(&template_file); - QString line = QStringLiteral(""); + QString line = QLatin1String(""); int linecount = 0; - QHash field_short_value; - QHash field_long_value; - QString last_field_name; + QHash field_short_value; + QHash field_long_value; + QString last_field_name; while ( !line.isNull() ) { ++linecount; line = template_stream.readLine(); qCDebug(DEBCONF) << linecount << line; if ( line.isEmpty() ) { if (!last_field_name.isEmpty()) { //Submit last block values. qCDebug(DEBCONF) << "submit" << last_field_name; - QString item = field_short_value[QStringLiteral("template")]; - QString type = field_short_value[QStringLiteral("type")]; - QString short_description = field_short_value[QStringLiteral("description")]; - QString long_description = field_long_value[QStringLiteral("description")]; + const QString item = field_short_value[QLatin1String("template")]; + const QString type = field_short_value[QLatin1String("type")]; + const QString short_description = field_short_value[QLatin1String("description")]; + const QString long_description = field_long_value[QLatin1String("description")]; m_data[item][DebconfFrontend::Type] = type; m_data[item][DebconfFrontend::Description] = short_description; m_data[item][DebconfFrontend::ExtendedDescription] = long_description; //Clear data. field_short_value.clear(); field_long_value.clear(); last_field_name.clear(); } } else { if (!line.startsWith(QLatin1Char(' '))) { - last_field_name = line.section(QStringLiteral(": "), 0, 0).toLower(); - field_short_value[last_field_name] = line.section(QStringLiteral(": "), 1); + last_field_name = line.section(QLatin1String(": "), 0, 0).toLower(); + field_short_value[last_field_name] = line.section(QLatin1String(": "), 1); } else { if ( field_long_value[last_field_name].isEmpty() ){ field_long_value[last_field_name] = line.remove(0, 1); } else { field_long_value[last_field_name].append(QLatin1Char('\n')); - if ( !(line.trimmed() == QStringLiteral(".")) ) { + if ( !(line.trimmed() == QLatin1String(".")) ) { field_long_value[last_field_name].append(line.remove(0, 1)); } } } } } } else { - say(QStringLiteral( "30 couldn't open file" )); + say(QLatin1String("30 couldn't open file")); return; } - say(QStringLiteral( "0 ok" )); + say(QLatin1String("0 ok")); } void DebconfFrontend::cmd_info(const QString ¶m) { Q_UNUSED(param) //FIXME: this is a dummy command, we should actually do something //with param. - say(QStringLiteral( "0 ok" )); + say(QLatin1String("0 ok")); } void DebconfFrontend::cmd_fget(const QString ¶m) { // We get strings like // foo/bar seen false // question = "foo/bar" // flag = "seen" - QString question = param.section(QLatin1Char( ' ' ), 0, 0); - QString flag = param.section(QLatin1Char( ' ' ), 1, 1); + const QString question = param.section(QLatin1Char(' '), 0, 0); + const QString flag = param.section(QLatin1Char(' '), 1, 1); if (m_flags[question][flag]) { - say( QStringLiteral("0 true") ); + say(QLatin1String("0 true")); } else { - say( QStringLiteral("0 false") ); + say(QLatin1String("0 false")); } } void DebconfFrontend::cmd_fset(const QString ¶m) { // We get strings like // foo/bar seen false // question = "foo/bar" // flag = "seen" // value = "false" - QString question = param.section(QLatin1Char( ' ' ), 0, 0); - QString flag = param.section(QLatin1Char( ' ' ), 1, 1); - QString value = param.section(QLatin1Char( ' ' ), 2, 2); + const QString question = param.section(QLatin1Char(' '), 0, 0); + const QString flag = param.section(QLatin1Char(' '), 1, 1); + const QString value = param.section(QLatin1Char(' '), 2, 2); - if ( value == QStringLiteral("false") ) { + if ( value == QLatin1String("false") ) { m_flags[question][flag] = false; } else { m_flags[question][flag] = true; } - say(QStringLiteral( "0 ok" )); + say(QLatin1String("0 ok")); } void DebconfFrontend::cmd_beginblock(const QString ¶m) { Q_UNUSED(param) //FIXME: this is a dummy command, we should actually do something //with param. - say(QStringLiteral( "0 ok" )); + say(QLatin1String("0 ok")); } void DebconfFrontend::cmd_endblock(const QString ¶m) { Q_UNUSED(param) //FIXME: this is a dummy command, we should actually do something //with param. - say(QStringLiteral( "0 ok" )); + say(QLatin1String("0 ok")); } void DebconfFrontend::cmd_stop(const QString ¶m) { Q_UNUSED(param) //Do nothing. } bool DebconfFrontend::process() { QTextStream in(getReadDevice()); QString line = in.readLine(); if (line.isEmpty()) { return false; } - QString command = line.section(QLatin1Char( ' ' ), 0, 0); - QString value = line.section(QLatin1Char( ' ' ), 1); + const QString command = line.section(QLatin1Char(' '), 0, 0); + const QString value = line.section(QLatin1Char(' '), 1); qCDebug(DEBCONF) << "DEBCONF <--- [" << command << "] " << value; const Cmd *c = commands; while (c->cmd != 0) { - if (command == QLatin1String( c->cmd )) { + if (command == QLatin1String(c->cmd)) { (this->*(c->run))(value); return true; } ++ c; } return false; } DebconfFrontendSocket::DebconfFrontendSocket(const QString &socketName, QObject *parent) : DebconfFrontend(parent), m_socket(0) { m_server = new QLocalServer(this); QFile::remove(socketName); m_server->listen(socketName); - connect(m_server, SIGNAL(newConnection()), this, SLOT(newConnection())); + connect(m_server, &QLocalServer::newConnection, this, &DebconfFrontendSocket::newConnection); } DebconfFrontendSocket::~DebconfFrontendSocket() { QFile::remove(m_server->fullServerName()); } void DebconfFrontendSocket::newConnection() { qCDebug(DEBCONF); if (m_socket) { QLocalSocket *socket = m_server->nextPendingConnection(); socket->disconnectFromServer(); socket->deleteLater(); return; } m_socket = m_server->nextPendingConnection(); if (m_socket) { - connect(m_socket, SIGNAL(readyRead()), this, SLOT(process())); - connect(m_socket, SIGNAL(disconnected()), this, SLOT(disconnected())); + connect(m_socket, &QLocalSocket::readyRead, this, &DebconfFrontendSocket::process); + connect(m_socket, &QLocalSocket::disconnected, this, &DebconfFrontendSocket::disconnected); } } void DebconfFrontendSocket::reset() { if (m_socket) { m_socket->deleteLater(); m_socket = 0; } DebconfFrontend::reset(); } void DebconfFrontendSocket::cancel() { if (m_socket) { m_socket->disconnectFromServer(); } DebconfFrontend::cancel(); } DebconfFrontendFifo::DebconfFrontendFifo(int readfd, int writefd, QObject *parent) : DebconfFrontend(parent) { m_readf = new QFile(this); // Use QFile::open(fh,mode) method for opening read file descriptor as // sequential files opened with QFile::open(fd,mode) are not handled // properly. FILE *readfh = ::fdopen(readfd, "rb"); m_readf->open(readfh, QIODevice::ReadOnly); m_writef = new QFile(this); m_writef->open(writefd, QIODevice::WriteOnly); // QIODevice::readyReady() does not work with QFile // http://bugreports.qt.nokia.com/browse/QTBUG-16089 m_readnotifier = new QSocketNotifier(readfd, QSocketNotifier::Read, this); - connect(m_readnotifier, SIGNAL(activated(int)), this, SLOT(process())); + connect(m_readnotifier, &QSocketNotifier::activated, this, &DebconfFrontendFifo::process); } void DebconfFrontendFifo::reset() { if (m_readf) { // Close file descriptors int readfd = m_readf->handle(); int writefd = m_writef->handle(); m_readnotifier->setEnabled(false); m_readf->close(); m_writef->close(); m_readf = m_writef = 0; // Use C library calls because QFile::close() won't close them actually ::close(readfd); ::close(writefd); } DebconfFrontend::reset(); } void DebconfFrontendFifo::cancel() { disconnected(); } bool DebconfFrontendFifo::process() { // We will get notification when the other end is closed if (m_readf->atEnd()) { cancel(); return false; } return DebconfFrontend::process(); } } + +#include "moc_debconf.cpp" diff --git a/src/debconf.h b/src/debconf.h index 949c9bf..9d2c997 100644 --- a/src/debconf.h +++ b/src/debconf.h @@ -1,284 +1,284 @@ // This license reflects the original Adept code: // -*- C++ -*- (c) 2008 Petr Rockai // (c) 2011 Modestas Vainius // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following // disclaimer in the documentation and/or other materials provided // with the distribution. // // * Neither the name of [original copyright holder] nor the names of // its contributors may be used to endorse or promote products // derived from this software without specific prior written // permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. /* * All the modifications below are licensed under this license * Copyright (C) 2010 Daniel Nicoletti * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library 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. */ #ifndef DEBCONF_H #define DEBCONF_H #include #include #include #include #include #include #include class QSocketNotifier; namespace DebconfKde { /** * An abstract class which talks Debconf Passthrough frontend protocol. It * does not implement underlying I/O method specifics. */ class DebconfFrontend : public QObject { Q_OBJECT Q_ENUMS(PropertyKey) Q_ENUMS(TypeKey) public: typedef enum { Choices, Description, ExtendedDescription, Type, UnknownPropertyKey = -1 } PropertyKey; typedef enum { String, Password, Progress, Boolean, Select, Multiselect, Note, Error, Title, Text, UnknownTypeKey = -1 } TypeKey; explicit DebconfFrontend(QObject *parent = 0); virtual ~DebconfFrontend(); QString value(const QString &key) const; void setValue(const QString &key, const QString &value); QString property(const QString &key, PropertyKey p) const; TypeKey type(const QString &string) const; /** * Send \p string to Debconf over established connection */ void say(const QString &string); /** * Goes to the next question */ void next(); /** * Goes back one question (if backup(true) was emitted) */ void back(); /** * Closes the current connection, canceling all questions */ virtual void cancel(); -signals: +Q_SIGNALS: void go(const QString &title, const QStringList &input); void progress(const QString ¶m); /** * Emitted when connection with Debconf is terminated. */ void finished(); void backup(bool capable); protected Q_SLOTS: /** * This slot should be called when there is new data available. */ virtual bool process(); /** * This slot should be called when connection with Debconf is terminated. */ virtual void disconnected(); protected: /** * This method must be overridden by the derivative class and return * current QIODevice which should be used to read data from Debconf. */ virtual QIODevice* getReadDevice() const = 0; /** * This method must be overridden by the derivative class and return * current QIODevice which should be used to write data to Debconf. */ virtual QIODevice* getWriteDevice() const = 0; /** * This is called to clean up internal data once connection with * Debconf is terminated. */ virtual void reset(); private: void cmd_capb(const QString &caps); void cmd_set(const QString ¶m); void cmd_get(const QString ¶m); void cmd_input(const QString ¶m); void cmd_go(const QString &); void cmd_title(const QString ¶m); void cmd_data(const QString ¶m); void cmd_subst(const QString ¶m); void cmd_progress(const QString ¶m); void cmd_x_ping(const QString ¶m); void cmd_version(const QString ¶m); void cmd_x_loadtemplatefile(const QString ¶m); void cmd_info(const QString ¶m); void cmd_fget(const QString ¶m); void cmd_fset(const QString ¶m); void cmd_beginblock(const QString ¶m); void cmd_endblock(const QString ¶m); void cmd_stop(const QString ¶m); struct Cmd { const char *cmd; void (DebconfFrontend::*run)(const QString &); }; static const Cmd commands[]; // TODO this is apparently very much untested QString substitute(const QString &key, const QString &rest) const; /** * Transforms the string camel cased and return it's enum given the enum name */ template static int enumFromString(const QString &str, const char *enumName); PropertyKey propertyKeyFromString(const QString &string); typedef QHash Properties; typedef QHash Substitutions; typedef QHash Flags; QHash m_data; QHash m_subst; QHash m_values; QHash m_flags; QString m_title; QStringList m_input; }; /** * DebconfFrontend which communicates with Debconf over UNIX socket. Even when * finished signal is emitted, DeconfFrontend will reset and continue to * listen for new connections on the socket. */ class DebconfFrontendSocket : public DebconfFrontend { Q_OBJECT public: /** * Instantiates the class and starts listening for new connections on the * socket at \p socketName path. Please note that any file at \p socketName * will be removed if it exists prior to the call of this constructor. */ explicit DebconfFrontendSocket(const QString &socketName, QObject *parent = 0); /** * Removes socket when the object is destroyed. */ virtual ~DebconfFrontendSocket(); /** * Overridden to trigger termination of the current connection. */ void cancel(); protected: inline QIODevice* getReadDevice() const { return m_socket; } inline QIODevice* getWriteDevice() const { return m_socket; } void reset(); private Q_SLOTS: /** * Called when a new connection is received on the socket * If we are already handlyng a connection we refuse the others */ void newConnection(); private: QLocalServer *m_server; QLocalSocket *m_socket; }; /** * DebconfFrontend which communicates with Debconf over FIFO pipes. Once * finished signal is emitted, the frontend is no longer usable as pipes * have been been closed by then. */ class DebconfFrontendFifo : public DebconfFrontend { public: /** * Instantiates the class and prepares for communication with Debconf over * \p readfd (read) and \p writefd (write) FIFO file descriptors. */ explicit DebconfFrontendFifo(int readfd, int writefd, QObject *parent = 0); /** * Overridden to trigger full disconnection */ void cancel(); protected: QIODevice* getReadDevice() const { return m_readf; } QIODevice* getWriteDevice() const { return m_writef; } void reset(); bool process(); private: QFile *m_readf; QFile *m_writef; QSocketNotifier *m_readnotifier; }; } #endif diff --git a/tools/main.cpp b/tools/main.cpp index 4488622..b8bb8c9 100644 --- a/tools/main.cpp +++ b/tools/main.cpp @@ -1,94 +1,94 @@ /* - * Copyright (C) 2010 Daniel Nicoletti + * Copyright (C) 2010-2018 Daniel Nicoletti * (C) 2011 Modestas Vainius * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library 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 #include #include #include #include #include #include #include using namespace DebconfKde; int main(int argc, char **argv) { QApplication app(argc, argv); KLocalizedString::setApplicationDomain("libdebconf-kde"); KAboutData aboutData(QStringLiteral("debconf-kde-helper"), i18nc("@title", "Debconf KDE"), QStringLiteral(PROJECT_VERSION), i18nc("@info", "Debconf frontend for KDE"), KAboutLicense::LicenseKey::LGPL); KAboutData::setApplicationData(aboutData); QCommandLineParser parser; parser.addHelpOption(); parser.addVersionOption(); QCommandLineOption socketOption(QStringLiteral("socket-path"), i18nc("@info:shell", "Path to where the socket should be created"), i18nc("@info:shell value name", "path_to_socket"), QStringLiteral("/tmp/debkonf-sock")); parser.addOption(socketOption); QCommandLineOption fifoFdsOption(QStringLiteral("fifo-fds"), i18nc("@info:shell", "FIFO file descriptors for communication with Debconf"), i18nc("@info:shell value name", "read_fd,write_fd")); parser.addOption(fifoFdsOption); aboutData.setupCommandLine(&parser); parser.process(app); aboutData.processCommandLine(&parser); - DebconfGui *dcf = 0; + DebconfGui *dcf = nullptr; if (parser.isSet(fifoFdsOption)) { int readfd, writefd; QRegExp regex(QLatin1String("(\\d+),(\\d+)")); if (regex.exactMatch(parser.value(fifoFdsOption))) { readfd = regex.cap(1).toInt(); writefd = regex.cap(2).toInt(); dcf = new DebconfGui(readfd, writefd); - dcf->connect(dcf, SIGNAL(activated()), SLOT(show())); + dcf->connect(dcf, &DebconfGui::activated, dcf, &DebconfGui::show); // Once FIFO pipes are closed, they cannot be reopened. Hence we // should terminate as well. - dcf->connect(dcf, SIGNAL(deactivated()), SLOT(close())); + dcf->connect(dcf, &DebconfGui::deactivated, dcf, &DebconfGui::close); } else { qFatal("Incorrect value of the --fifo-fds parameter"); } } else { QString path = parser.value(socketOption); dcf = new DebconfGui(path); std::cout << "export DEBIAN_FRONTEND=passthrough" << std::endl; std::cout << "export DEBCONF_PIPE=" << path.toUtf8().data() << std::endl; - dcf->connect(dcf, SIGNAL(activated()), SLOT(show())); - dcf->connect(dcf, SIGNAL(deactivated()), SLOT(hide())); + dcf->connect(dcf, &DebconfGui::activated, dcf, &DebconfGui::show); + dcf->connect(dcf, &DebconfGui::deactivated, dcf, &DebconfGui::hide); } if (!dcf) return 1; return app.exec(); }