Git commit 7d3c3f70cfebc96d8447a9d21c3a0ff72f3d5379 by Alexander Volkov. Committed on 11/05/2018 at 17:41. Pushed by volkov into branch 'frameworks'. Initial port to KF5 Without QApt and QPackageKit backends. M +61 -16 CMakeLists.txt M +1 -1 other/CMakeLists.txt M +1 -1 other/kcm_grub2.desktop M +5 -7 src/CMakeLists.txt M +7 -6 src/convertDlg.cpp M +5 -7 src/helper/CMakeLists.txt M +40 -23 src/helper/helper.cpp M +2 -0 src/helper/helper.h M +30 -16 src/installDlg.cpp M +66 -89 src/kcm_grub2.cpp M +0 -1 src/kcm_grub2.h https://commits.kde.org/kcm-grub2/7d3c3f70cfebc96d8447a9d21c3a0ff72f3d5379 diff --git a/CMakeLists.txt b/CMakeLists.txt index 8fbf4c4..9291ed7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,16 @@ project(kcm-grub2) + +cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR) +set(PROJECT_VERSION "5.12.80") +set(QT_MIN_VERSION "5.9.0") +find_package(ECM 1.0.0 REQUIRED NO_MODULE) +set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR} ${CMAKE_CUR= RENT_SOURCE_DIR}/cmake) +include(ECMInstallIcons) +include(KDEInstallDirs) +include(KDECMakeSettings) +include(KDECompilerSettings) +include(FeatureSummary) + set(KCM_GRUB2_VERSION_MAJOR "0") set(KCM_GRUB2_VERSION_MINOR "6") set(KCM_GRUB2_VERSION_PATCH "4") @@ -6,34 +18,67 @@ set(KCM_GRUB2_VERSION "${KCM_GRUB2_VERSION_MAJOR}.${KCM_= GRUB2_VERSION_MINOR}.${K = set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_PAT= H}) = -find_package(Qt4 4.6.0 REQUIRED) -find_package(KDE4 4.4.0 REQUIRED) -include(KDE4Defaults) include(GRUBPaths) = +find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS Core Gui Wid= gets) + +find_package(KF5 REQUIRED COMPONENTS + Auth + KDELibs4Support +) + # Qt add_definitions(-DQT_NO_CAST_FROM_ASCII -DQT_NO_CAST_TO_ASCII -DQT_NO_CAST= _FROM_BYTEARRAY -DQT_NO_KEYWORDS -DQT_STRICT_ITERATORS -DQT_USE_FAST_CONCAT= ENATION -DQT_USE_FAST_OPERATOR_PLUS) # ImageMagick add_definitions(-DMAGICKCORE_HDRI_ENABLE=3D0 -DMAGICKCORE_QUANTUM_DEPTH=3D= 16) = -macro_optional_find_package(ImageMagick COMPONENTS Magick++ MagickCore) -macro_log_feature(ImageMagick_FOUND "ImageMagick" "Create splash images co= mpatible with GRUB2" "http://www.imagemagick.org/" FALSE "" "") -macro_bool_to_01(ImageMagick_FOUND HAVE_IMAGEMAGICK) +find_package(ImageMagick COMPONENTS Magick++ MagickCore) +set_package_properties(ImageMagick PROPERTIES + DESCRIPTION "Create splash images compatible with G= RUB2" + URL "http://www.imagemagick.org/" + TYPE OPTIONAL) +if(ImageMagick_FOUND) + set(HAVE_IMAGEMAGICK 1) +else() + set(HAVE_IMAGEMAGICK 0) +endif() = -macro_optional_find_package(HD) -macro_log_feature(HD_FOUND "hwinfo" "Retrieve list of resolutions valid in= GRUB2" "http://www.opensuse.org/" FALSE "" "") -macro_bool_to_01(HD_FOUND HAVE_HD) +find_package(HD) +set_package_properties(hwinfo PROPERTIES + DESCRIPTION "Retrieve list of resolutions valid in = GRUB2" + URL "http://www.opensuse.org/" + TYPE OPTIONAL) +if(HD_FOUND) + set(HAVE_HD 1) +else() + set(HAVE_HD 0) +endif() = -macro_optional_find_package(QApt) -macro_log_feature(QAPT_FOUND "LibQApt" "Remove unneeded old entries (qapt = backend)" "https://projects.kde.org/projects/extragear/sysadmin/libqapt/" F= ALSE "" "") -macro_bool_to_01(QAPT_FOUND HAVE_QAPT) +find_package(QApt) +set_package_properties(QApt PROPERTIES + DESCRIPTION "Remove unneeded old entries (qapt back= end)" + URL "https://projects.kde.org/projects/extragear/sy= sadmin/libqapt/" + TYPE OPTIONAL) +if(QAPT_FOUND) + set(HAVE_QAPT 1) +else() + set(HAVE_QAPT 0) +endif() = -macro_optional_find_package(QPackageKit) -macro_log_feature(QPACKAGEKIT_FOUND "QPackageKit" "Remove unneeded old ent= ries (qpackagekit backend)" "http://www.packagekit.org/" FALSE "" "") -macro_bool_to_01(QPACKAGEKIT_FOUND HAVE_QPACKAGEKIT) +find_package(QPackageKit) +set_package_properties(QPackageKit PROPERTIES + DESCRIPTION "Remove unneeded old entries (qpackagek= it backend)" + URL "http://www.packagekit.org/" + TYPE OPTIONAL) +if(QPACKAGEKIT_FOUND) + set(HAVE_QPACKAGEKIT 1) +else() + set(HAVE_QPACKAGEKIT 0) +endif() = -macro_display_feature_log() configure_file(config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/src/config.h) = +feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_= PACKAGES) + add_subdirectory(other) add_subdirectory(src) diff --git a/other/CMakeLists.txt b/other/CMakeLists.txt index 3564d80..59db95f 100644 --- a/other/CMakeLists.txt +++ b/other/CMakeLists.txt @@ -1,2 +1,2 @@ # Install -install(FILES kcm_grub2.desktop DESTINATION ${SERVICES_INSTALL_DIR}) +install(FILES kcm_grub2.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR}) diff --git a/other/kcm_grub2.desktop b/other/kcm_grub2.desktop index 90b3ee2..7fbb0bf 100644 --- a/other/kcm_grub2.desktop +++ b/other/kcm_grub2.desktop @@ -2,7 +2,7 @@ Icon=3Dsystem-reboot Type=3DService X-KDE-ServiceTypes=3DKCModule -Exec=3Dkcmshell4 kcm_grub2 +Exec=3Dkcmshell5 kcm_grub2 = X-KDE-Library=3Dkcm_grub2 X-KDE-ParentApp=3Dkcontrol diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2e46392..0daa4fa 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,7 +1,6 @@ add_subdirectory(helper) = # Set Include Directories -set(kcm_grub2_INCLUDE_DIRS ${KDE4_INCLUDES}) if(HAVE_IMAGEMAGICK) set(kcm_grub2_INCLUDE_DIRS ${kcm_grub2_INCLUDE_DIRS} ${ImageMagick_INC= LUDE_DIRS}) endif(HAVE_IMAGEMAGICK) @@ -13,14 +12,14 @@ endif(HAVE_QAPT) = # Set Sources set(kcm_grub2_SRCS common.cpp entry.cpp installDlg.cpp kcm_grub2.cpp) -kde4_add_ui_files(kcm_grub2_SRCS ../ui/installDlg.ui ../ui/kcm_grub2.ui) +qt5_wrap_ui(kcm_grub2_SRCS ../ui/installDlg.ui ../ui/kcm_grub2.ui) if(HAVE_IMAGEMAGICK) set(kcm_grub2_SRCS ${kcm_grub2_SRCS} convertDlg.cpp) - kde4_add_ui_files(kcm_grub2_SRCS ../ui/convertDlg.ui) + qt5_wrap_ui(kcm_grub2_SRCS ../ui/convertDlg.ui) endif(HAVE_IMAGEMAGICK) if(HAVE_QAPT OR HAVE_QPACKAGEKIT) set(kcm_grub2_SRCS ${kcm_grub2_SRCS} removeDlg.cpp) - kde4_add_ui_files(kcm_grub2_SRCS ../ui/removeDlg.ui) + qt5_wrap_ui(kcm_grub2_SRCS ../ui/removeDlg.ui) endif(HAVE_QAPT OR HAVE_QPACKAGEKIT) if(HAVE_QAPT) if(QAPT_VERSION_MAJOR EQUAL 1) @@ -33,7 +32,6 @@ elseif(HAVE_QPACKAGEKIT) endif(HAVE_QAPT) = # Set Link Libraries -set(kcm_grub2_LINK_LIBS ${KDE4_KDEUI_LIBS} ${KDE4_KIO_LIBS} ${KDE4_SOLID_L= IBS}) if(HAVE_IMAGEMAGICK) set(kcm_grub2_LINK_LIBS ${kcm_grub2_LINK_LIBS} ${ImageMagick_LIBRARIES= }) endif(HAVE_IMAGEMAGICK) @@ -50,8 +48,8 @@ endif(HAVE_IMAGEMAGICK) = # Build & Link include_directories(${kcm_grub2_INCLUDE_DIRS}) -kde4_add_plugin(kcm_grub2 ${kcm_grub2_SRCS}) -target_link_libraries(kcm_grub2 ${kcm_grub2_LINK_LIBS}) +add_library(kcm_grub2 MODULE ${kcm_grub2_SRCS}) +target_link_libraries(kcm_grub2 ${kcm_grub2_LINK_LIBS} Qt5::Core Qt5::Widg= ets KF5::Auth KF5::KIOCore KF5::Solid KF5::KDELibs4Support) = # Install install(TARGETS kcm_grub2 DESTINATION ${PLUGIN_INSTALL_DIR}) diff --git a/src/convertDlg.cpp b/src/convertDlg.cpp index 6e1cca9..4cc14fa 100644 --- a/src/convertDlg.cpp +++ b/src/convertDlg.cpp @@ -19,9 +19,10 @@ #include "convertDlg.h" = //KDE -#include #include #include +#include +#include = //ImageMagick #include @@ -48,11 +49,11 @@ ConvertDialog::ConvertDialog(QWidget *parent, Qt::WFlag= s flags) : KDialog(parent QString writeFilter =3D QString(QLatin1String("*%1|%5 (%1)\n*%2|%6 (%2= )\n*%3 *%4|%7 (%3 %4)")).arg(QLatin1String(".png"), QLatin1String(".tga"), = QLatin1String(".jpg"), QLatin1String(".jpeg"), KMimeType::mimeType(QLatin1S= tring("image/png"))->comment(), KMimeType::mimeType(QLatin1String("image/x-= tga"))->comment(), KMimeType::mimeType(QLatin1String("image/jpeg"))->commen= t()); = ui->kurlrequester_image->setMode(KFile::File | KFile::ExistingOnly | K= File::LocalOnly); - ui->kurlrequester_image->fileDialog()->setOperationMode(KFileDialog::O= pening); - ui->kurlrequester_image->fileDialog()->setFilter(readFilter); + ui->kurlrequester_image->setAcceptMode(QFileDialog::AcceptOpen); + ui->kurlrequester_image->setFilter(readFilter); ui->kurlrequester_converted->setMode(KFile::File | KFile::LocalOnly); - ui->kurlrequester_converted->fileDialog()->setOperationMode(KFileDialo= g::Saving); - ui->kurlrequester_converted->fileDialog()->setFilter(writeFilter); + ui->kurlrequester_converted->setAcceptMode(QFileDialog::AcceptSave); + ui->kurlrequester_converted->setFilter(writeFilter); } ConvertDialog::~ConvertDialog() { @@ -76,7 +77,7 @@ void ConvertDialog::slotButtonClicked(int button) } else if (ui->spinBox_width->value() =3D=3D 0 || ui->spinBox_heig= ht->value() =3D=3D 0) { KMessageBox::information(this, i18nc("@info", "Please fill in = both Width and Height fields.= ")); return; - } else if (!QFileInfo(ui->kurlrequester_converted->url().directory= ()).isWritable()) { + } else if (!QFileInfo(KUrl(ui->kurlrequester_converted->url()).dir= ectory()).isWritable()) { KMessageBox::information(this, i18nc("@info", "You do not have= write permissions in this directory, please select another destination.")); return; } diff --git a/src/helper/CMakeLists.txt b/src/helper/CMakeLists.txt index 6a8792b..03f90f7 100644 --- a/src/helper/CMakeLists.txt +++ b/src/helper/CMakeLists.txt @@ -1,5 +1,4 @@ # Set Include Directories -set(kcmgrub2helper_INCLUDE_DIRS ${KDE4_INCLUDES}) if(HAVE_HD) set(kcmgrub2helper_INCLUDE_DIRS ${kcmgrub2helper_INCLUDE_DIRS} ${HD_IN= CLUDE_DIR}) endif(HAVE_HD) @@ -8,17 +7,16 @@ endif(HAVE_HD) set(kcmgrub2helper_SRCS helper.cpp) = # Set Link Libraries -set(kcmgrub2helper_LINK_LIBS ${KDE4_KDECORE_LIBS}) if(HAVE_HD) set(kcmgrub2helper_LINK_LIBS ${kcmgrub2helper_LINK_LIBS} ${HD_LIBRARY}) endif(HAVE_HD) = # Build & Link include_directories(${kcmgrub2helper_INCLUDE_DIRS}) -kde4_add_executable(kcmgrub2helper ${kcmgrub2helper_SRCS}) -target_link_libraries(kcmgrub2helper ${kcmgrub2helper_LINK_LIBS}) +add_executable(kcmgrub2helper ${kcmgrub2helper_SRCS}) +target_link_libraries(kcmgrub2helper ${kcmgrub2helper_LINK_LIBS} KF5::KDEL= ibs4Support) = # Install -install(TARGETS kcmgrub2helper DESTINATION ${LIBEXEC_INSTALL_DIR}) -kde4_install_auth_helper_files(kcmgrub2helper org.kde.kcontrol.kcmgrub2 ro= ot) -kde4_install_auth_actions(org.kde.kcontrol.kcmgrub2 kcmgrub2.actions) +install(TARGETS kcmgrub2helper DESTINATION ${KAUTH_HELPER_INSTALL_DIR}) +kauth_install_helper_files(kcmgrub2helper org.kde.kcontrol.kcmgrub2 root) +kauth_install_actions(org.kde.kcontrol.kcmgrub2 kcmgrub2.actions) diff --git a/src/helper/helper.cpp b/src/helper/helper.cpp index 2581dff..b799d09 100644 --- a/src/helper/helper.cpp +++ b/src/helper/helper.cpp @@ -26,7 +26,6 @@ = //KDE #include -#include #include #include #include @@ -45,7 +44,6 @@ static const QLatin1String path("/usr/sbin:/usr/bin:/sbin= :/bin"); = Helper::Helper() { - KGlobal::locale()->insertCatalog(QLatin1String("kcm-grub2")); qputenv("PATH", path.latin1()); } = @@ -57,15 +55,29 @@ ActionReply Helper::executeCommand(const QStringList &c= ommand) = kDebug() << "Executing" << command.join(QLatin1String(" ")); int exitCode =3D process.execute(); + const QByteArray output =3D process.readAll(); = ActionReply reply; if (exitCode !=3D 0) { - reply =3D ActionReply::HelperErrorReply; - reply.setErrorCode(exitCode); + reply =3D ActionReply::HelperErrorReply(exitCode); + QString errorMessage; + switch (exitCode) { + case -2: + errorMessage =3D i18nc("@info", "The process could not be star= ted."); + break; + case -1: + errorMessage =3D i18nc("@info", "The process crashed."); + break; + default: + errorMessage =3D QString::fromUtf8(output); + break; + } + reply.setErrorDescription(i18nc("@info", "Command: %1", command.join(QLatin1String(" "))) + + errorDescription(exitCode, errorMessage)= ); + } else { + reply.addData(QLatin1String("command"), command); + reply.addData(QLatin1String("output"), output); } - reply.addData(QLatin1String("isProcessReply"), true); - reply.addData(QLatin1String("command"), command); - reply.addData(QLatin1String("output"), process.readAll()); return reply; } bool Helper::setLang(const QString &lang) @@ -104,21 +116,21 @@ ActionReply Helper::defaults(QVariantMap args) QString originalConfigFileName =3D configFileName + QLatin1String(".or= iginal"); = if (!QFile::exists(originalConfigFileName)) { - reply =3D ActionReply::HelperErrorReply; - reply.setErrorCode(1); - reply.addData(QLatin1String("errorDescription"), i18n("Original co= nfiguration file %1 does not exist.", originalConfigFi= leName)); + reply =3D ActionReply::HelperErrorReply(); + reply.setError(1); + reply.setErrorDescription(errorDescription(reply.errorCode(), i18n= ("Original configuration file %1 does not exist.", ori= ginalConfigFileName))); return reply; } if (!QFile::remove(configFileName)) { - reply =3D ActionReply::HelperErrorReply; - reply.setErrorCode(2); - reply.addData(QLatin1String("errorDescription"), i18n("Cannot remo= ve current configuration file %1.", configFileName)); + reply =3D ActionReply::HelperErrorReply(); + reply.setError(2); + reply.setErrorDescription(errorDescription(reply.errorCode(), i18n= ("Cannot remove current configuration file %1.", confi= gFileName))); return reply; } if (!QFile::copy(originalConfigFileName, configFileName)) { - reply =3D ActionReply::HelperErrorReply; - reply.setErrorCode(3); - reply.addData(QLatin1String("errorDescription"), i18n("Cannot copy= original configuration file %1 to %2.", originalConfigFileName, configFileName)); + reply =3D ActionReply::HelperErrorReply(); + reply.setError(3); + reply.setErrorDescription(errorDescription(reply.errorCode(), i18n= ("Cannot copy original configuration file %1 to %2.", originalConfigFileName, configFileName))); return reply; } return reply; @@ -133,9 +145,9 @@ ActionReply Helper::install(QVariantMap args) if (mountPoint.isEmpty()) { for (int i =3D 0; QDir(mountPoint =3D QString(QLatin1String("%1/kc= m-grub2-%2")).arg(QDir::tempPath(), QString::number(i))).exists(); i++); if (!QDir().mkpath(mountPoint)) { - reply =3D ActionReply::HelperErrorReply; - reply.setErrorCode(4); - reply.addData(QLatin1String("errorDescription"), i18n("Failed = to create temporary mount point.")); + reply =3D ActionReply::HelperErrorReply(); + reply.setError(4); + reply.setErrorDescription(errorDescription(reply.errorCode(), = i18n("Failed to create temporary mount point."))); return reply; } ActionReply mountReply =3D executeCommand(QStringList() << QLatin1= String("mount") << partition << mountPoint); @@ -231,9 +243,9 @@ ActionReply Helper::save(QVariantMap args) = QFile file(configFileName); if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { - reply =3D ActionReply::HelperErrorReply; - reply.setErrorCode(5); - reply.addData(QLatin1String("errorDescription"), file.errorString(= )); + reply =3D ActionReply::HelperErrorReply(); + reply.setError(5); + reply.setErrorDescription(errorDescription(reply.errorCode(), file= .errorString())); return reply; } file.write(rawConfigFileContents); @@ -271,4 +283,9 @@ ActionReply Helper::save(QVariantMap args) return grub_mkconfigReply; } = -KDE4_AUTH_HELPER_MAIN("org.kde.kcontrol.kcmgrub2", Helper) +QString Helper::errorDescription(int errorCode, const QString &errorMessag= e) const +{ + return i18nc("@info", "Error code: %1Error message= : %2", errorCode, errorMessage); +} + +KAUTH_HELPER_MAIN("org.kde.kcontrol.kcmgrub2", Helper) diff --git a/src/helper/helper.h b/src/helper/helper.h index e63b41f..9a8f37f 100644 --- a/src/helper/helper.h +++ b/src/helper/helper.h @@ -35,6 +35,8 @@ public Q_SLOTS: ActionReply install(QVariantMap args); ActionReply load(QVariantMap args); ActionReply save(QVariantMap args); +private: + QString errorDescription(int errorCode, const QString &errorMessage) c= onst; }; = #endif diff --git a/src/installDlg.cpp b/src/installDlg.cpp index 34a2847..8f2d4ec 100644 --- a/src/installDlg.cpp +++ b/src/installDlg.cpp @@ -21,12 +21,16 @@ //Qt #include #include +#include = //KDE -#include +#include +#include +#include #include #include -#include +#include +#include using namespace KAuth; #include #include @@ -84,7 +88,7 @@ void InstallDialog::slotButtonClicked(int button) { if (button =3D=3D KDialog::Ok) { Action installAction(QLatin1String("org.kde.kcontrol.kcmgrub2.inst= all")); - installAction.setHelperID(QLatin1String("org.kde.kcontrol.kcmgrub2= ")); + installAction.setHelperId(QLatin1String("org.kde.kcontrol.kcmgrub2= ")); for (int i =3D 0; i < ui->treeWidget_recover->topLevelItemCount();= i++) { QRadioButton *radio =3D qobject_cast(ui->treeW= idget_recover->itemWidget(ui->treeWidget_recover->topLevelItem(i), 0)); if (radio && radio->isChecked()) { @@ -98,11 +102,10 @@ void InstallDialog::slotButtonClicked(int button) KMessageBox::sorry(this, i18nc("@info", "Sorry, you have to se= lect a partition with a proper name!")); return; } -#if KDE_IS_VERSION(4,6,0) installAction.setParentWidget(this); -#endif = - if (installAction.authorize() !=3D Action::Authorized) { + KAuth::ExecuteJob *installJob =3D installAction.execute(KAuth::Act= ion::AuthorizeOnlyMode); + if (!installJob->exec()) { return; } = @@ -112,19 +115,30 @@ void InstallDialog::slotButtonClicked(int button) progressDlg.progressBar()->setMinimum(0); progressDlg.progressBar()->setMaximum(0); progressDlg.show(); - connect(installAction.watcher(), SIGNAL(actionPerformed(ActionRepl= y)), &progressDlg, SLOT(hide())); + installJob =3D installAction.execute(); + connect(installJob, SIGNAL(finished(KJob*)), &progressDlg, SLOT(hi= de())); = - ActionReply reply =3D installAction.execute(); - if (reply.succeeded()) { - KDialog *dialog =3D new KDialog(this, Qt::Dialog); - dialog->setCaption(i18nc("@title:window", "Information")); - dialog->setButtons(KDialog::Ok | KDialog::Details); + if (installJob->exec()) { + QDialog *dialog =3D new QDialog(this); + dialog->setWindowTitle(i18nc("@title:window", "Information")); dialog->setModal(true); - dialog->setDefaultButton(KDialog::Ok); - dialog->setEscapeButton(KDialog::Ok); - KMessageBox::createKMessageBox(dialog, QMessageBox::Informatio= n, i18nc("@info", "Successfully installed GRUB."), QStringList(), QString()= , 0, KMessageBox::Notify, reply.data().value(QLatin1String("output")).toStr= ing()); // krazy:exclude=3Dqclasses + dialog->setAttribute(Qt::WA_DeleteOnClose); + + QPushButton *detailsButton =3D new QPushButton; + detailsButton->setObjectName(QStringLiteral("detailsButton")); + detailsButton->setText(QApplication::translate("KMessageBox", = "&Details") + QStringLiteral(" >>")); + detailsButton->setIcon(QIcon::fromTheme(QStringLiteral("help-a= bout"))); + + QDialogButtonBox *buttonBox =3D new QDialogButtonBox(dialog); + buttonBox->addButton(detailsButton, QDialogButtonBox::HelpRole= ); + buttonBox->addButton(QDialogButtonBox::Ok); + buttonBox->button(QDialogButtonBox::Ok)->setFocus(); + + KMessageBox::createKMessageBox(dialog, buttonBox, QMessageBox:= :Information, i18nc("@info", "Successfully installed GRUB."), + QStringList(), QString(), nullp= tr, KMessageBox::Notify, + QString::fromUtf8(installJob->d= ata().value(QLatin1String("output")).toByteArray())); // krazy:exclude=3Dqc= lasses } else { - KMessageBox::detailedError(this, i18nc("@info", "Failed to ins= tall GRUB."), KDE_IS_VERSION(4,7,0) ? reply.errorDescription() : reply.data= ().value(QLatin1String("errorDescription")).toString()); + KMessageBox::detailedError(this, i18nc("@info", "Failed to ins= tall GRUB."), installJob->errorText()); } } KDialog::slotButtonClicked(button); diff --git a/src/kcm_grub2.cpp b/src/kcm_grub2.cpp index 0f44efb..fd7db2a 100644 --- a/src/kcm_grub2.cpp +++ b/src/kcm_grub2.cpp @@ -25,8 +25,12 @@ #include #include #include +#include = //KDE +#include +#include +#include #include #include #include @@ -34,7 +38,8 @@ #include #include #include -#include +#include +#include = //Project #include "common.h" @@ -54,13 +59,14 @@ K_PLUGIN_FACTORY(GRUB2Factory, registerPlugin();) K_EXPORT_PLUGIN(GRUB2Factory("kcmgrub2")) = -KCMGRUB2::KCMGRUB2(QWidget *parent, const QVariantList &list) : KCModule(G= RUB2Factory::componentData(), parent, list) +KCMGRUB2::KCMGRUB2(QWidget *parent, const QVariantList &list) : KCModule(p= arent, list) { - //Isn't KAboutData's second argument supposed to do this? - KGlobal::locale()->insertCatalog(QLatin1String("kcm-grub2")); - - KAboutData *about =3D new KAboutData("kcmgrub2", "kcm-grub2", ki18nc("= @title", "KDE GRUB2 Bootloader Control Module"), KCM_GRUB2_VERSION, ki18nc(= "@title", "A KDE Control Module for configuring the GRUB2 bootloader."), KA= boutData::License_GPL_V3, ki18nc("@info:credit", "Copyright (C) 2008-2013 K= onstantinos Smanis"), KLocalizedString(), "http://ksmanis.wordpress.com/pro= jects/grub2-editor/"); - about->addAuthor(ki18nc("@info:credit", "=CE=9Aonstantinos Smanis"), k= i18nc("@info:credit", "Main Developer"), "konstantinos.smanis@gmail.com", "= http://ksmanis.wordpress.com/"); + KAboutData *about =3D new KAboutData(QStringLiteral("kcmgrub2"), i18nc= ("@title", "KDE GRUB2 Bootloader Control Module"), + QStringLiteral(KCM_GRUB2_VERSION), = i18nc("@title", "A KDE Control Module for configuring the GRUB2 bootloader.= "), + KAboutLicense::GPL_V3, i18nc("@info= :credit", "Copyright (C) 2008-2013 Konstantinos Smanis"), QString(), + QStringLiteral("http://ksmanis.word= press.com/projects/grub2-editor/")); + about->addAuthor(i18nc("@info:credit", "=CE=9Aonstantinos Smanis"), i1= 8nc("@info:credit", "Main Developer"), + QStringLiteral("konstantinos.smanis@gmail.com"), QStr= ingLiteral("http://ksmanis.wordpress.com/")); setAboutData(about); = ui =3D new Ui::KCMGRUB2; @@ -76,19 +82,16 @@ KCMGRUB2::~KCMGRUB2() void KCMGRUB2::defaults() { Action defaultsAction(QLatin1String("org.kde.kcontrol.kcmgrub2.default= s")); - defaultsAction.setHelperID(QLatin1String("org.kde.kcontrol.kcmgrub2")); -#if KDE_IS_VERSION(4,6,0) + defaultsAction.setHelperId(QLatin1String("org.kde.kcontrol.kcmgrub2")); defaultsAction.setParentWidget(this); -#endif = - ActionReply reply =3D defaultsAction.execute(); - processReply(reply); - if (reply.succeeded()) { + KAuth::ExecuteJob *defaultsJob =3D defaultsAction.execute(); + if (defaultsJob->exec()) { load(); save(); KMessageBox::information(this, i18nc("@info", "Successfully restor= ed the default values.")); } else { - KMessageBox::detailedError(this, i18nc("@info", "Failed to restore= the default values."), reply.errorDescription()); + KMessageBox::detailedError(this, i18nc("@info", "Failed to restore= the default values."), defaultsJob->errorText()); } } void KCMGRUB2::load() @@ -472,7 +475,7 @@ void KCMGRUB2::save() } = Action saveAction(QLatin1String("org.kde.kcontrol.kcmgrub2.save")); - saveAction.setHelperID(QLatin1String("org.kde.kcontrol.kcmgrub2")); + saveAction.setHelperId(QLatin1String("org.kde.kcontrol.kcmgrub2")); saveAction.addArgument(QLatin1String("rawConfigFileContents"), configF= ileContents.toUtf8()); saveAction.addArgument(QLatin1String("rawDefaultEntry"), !m_entries.is= Empty() ? grubDefault.toUtf8() : m_settings.value(QLatin1String("GRUB_DEFAU= LT")).toUtf8()); if (ui->kcombobox_language->currentIndex() > 0) { @@ -482,13 +485,14 @@ void KCMGRUB2::save() if (m_dirtyBits.testBit(memtestDirty)) { saveAction.addArgument(QLatin1String("memtest"), ui->checkBox_memt= est->isChecked()); } -#if KDE_IS_VERSION(4,6,0) saveAction.setParentWidget(this); -#endif + saveAction.setTimeout(60000); = - if (saveAction.authorize() !=3D Action::Authorized) { + KAuth::ExecuteJob *saveJob =3D saveAction.execute(KAuth::Action::Autho= rizeOnlyMode); + if (!saveJob->exec()) { return; } + saveJob =3D saveAction.execute(); = KProgressDialog progressDlg(this, i18nc("@title:window Verb (gerund). = Refers to current status.", "Saving"), i18nc("@info:progress", "Saving GRUB= settings...")); progressDlg.setAllowCancel(false); @@ -496,21 +500,30 @@ void KCMGRUB2::save() progressDlg.progressBar()->setMinimum(0); progressDlg.progressBar()->setMaximum(0); progressDlg.show(); - connect(saveAction.watcher(), SIGNAL(actionPerformed(ActionReply)), &p= rogressDlg, SLOT(hide())); - - ActionReply reply =3D saveAction.execute(); - processReply(reply); - if (reply.succeeded()) { - KDialog *dialog =3D new KDialog(this, Qt::Dialog); - dialog->setCaption(i18nc("@title:window", "Information")); - dialog->setButtons(KDialog::Ok | KDialog::Details); + connect(saveJob, SIGNAL(finished(KJob*)), &progressDlg, SLOT(hide())); + + if (saveJob->exec()) { + QDialog *dialog =3D new QDialog(this); + dialog->setWindowTitle(i18nc("@title:window", "Information")); dialog->setModal(true); - dialog->setDefaultButton(KDialog::Ok); - dialog->setEscapeButton(KDialog::Ok); - KMessageBox::createKMessageBox(dialog, QMessageBox::Information, i= 18nc("@info", "Successfully saved GRUB settings."), QStringList(), QString(= ), 0, KMessageBox::Notify, QString::fromUtf8(reply.data().value(QLatin1Stri= ng("output")).toByteArray().constData())); // krazy:exclude=3Dqclasses + dialog->setAttribute(Qt::WA_DeleteOnClose); + + QPushButton *detailsButton =3D new QPushButton; + detailsButton->setObjectName(QStringLiteral("detailsButton")); + detailsButton->setText(QApplication::translate("KMessageBox", "&De= tails") + QStringLiteral(" >>")); + detailsButton->setIcon(QIcon::fromTheme(QStringLiteral("help-about= "))); + + QDialogButtonBox *buttonBox =3D new QDialogButtonBox(dialog); + buttonBox->addButton(detailsButton, QDialogButtonBox::HelpRole); + buttonBox->addButton(QDialogButtonBox::Ok); + buttonBox->button(QDialogButtonBox::Ok)->setFocus(); + + KMessageBox::createKMessageBox(dialog, buttonBox, QMessageBox::Inf= ormation, i18nc("@info", "Successfully saved GRUB settings."), + QStringList(), QString(), nullptr, = KMessageBox::Notify, + QString::fromUtf8(saveJob->data().v= alue(QLatin1String("output")).toByteArray().constData())); // krazy:exclude= =3Dqclasses load(); } else { - KMessageBox::detailedError(this, i18nc("@info", "Failed to save GR= UB settings."), reply.errorDescription()); + KMessageBox::detailedError(this, i18nc("@info", "Failed to save GR= UB settings."), saveJob->errorText()); } } = @@ -1020,61 +1033,58 @@ void KCMGRUB2::readAll() //Do not prompt for password if only the VBE operation is required, un= less forced. if (operations && ((operations & (~Vbe)) || m_resolutionsForceRead)) { Action loadAction(QLatin1String("org.kde.kcontrol.kcmgrub2.load")); - loadAction.setHelperID(QLatin1String("org.kde.kcontrol.kcmgrub2")); + loadAction.setHelperId(QLatin1String("org.kde.kcontrol.kcmgrub2")); loadAction.addArgument(QLatin1String("operations"), (int)(operatio= ns)); -#if KDE_IS_VERSION(4,6,0) loadAction.setParentWidget(this); -#endif = - ActionReply reply =3D loadAction.execute(); - processReply(reply); - if (reply.failed()) { + KAuth::ExecuteJob *loadJob =3D loadAction.execute(); + if (!loadJob->exec()) { kError() << "KAuth error!"; - kError() << "Error code:" << reply.errorCode(); - kError() << "Error description:" << reply.errorDescription(); + kError() << "Error code:" << loadJob->error(); + kError() << "Error description:" << loadJob->errorText(); return; } = if (operations.testFlag(MenuFile)) { - if (reply.data().value(QLatin1String("menuSuccess")).toBool())= { - parseEntries(QString::fromUtf8(reply.data().value(QLatin1S= tring("menuContents")).toByteArray().constData())); + if (loadJob->data().value(QLatin1String("menuSuccess")).toBool= ()) { + parseEntries(QString::fromUtf8(loadJob->data().value(QLati= n1String("menuContents")).toByteArray().constData())); } else { kError() << "Helper failed to read file:" << grubMenuPath(= ); - kError() << "Error code:" << reply.data().value(QLatin1Str= ing("menuError")).toInt(); - kError() << "Error description:" << reply.data().value(QLa= tin1String("menuErrorString")).toString(); + kError() << "Error code:" << loadJob->data().value(QLatin1= String("menuError")).toInt(); + kError() << "Error description:" << loadJob->data().value(= QLatin1String("menuErrorString")).toString(); } } if (operations.testFlag(ConfigurationFile)) { - if (reply.data().value(QLatin1String("configSuccess")).toBool(= )) { - parseSettings(QString::fromUtf8(reply.data().value(QLatin1= String("configContents")).toByteArray().constData())); + if (loadJob->data().value(QLatin1String("configSuccess")).toBo= ol()) { + parseSettings(QString::fromUtf8(loadJob->data().value(QLat= in1String("configContents")).toByteArray().constData())); } else { kError() << "Helper failed to read file:" << grubConfigPat= h(); - kError() << "Error code:" << reply.data().value(QLatin1Str= ing("configError")).toInt(); - kError() << "Error description:" << reply.data().value(QLa= tin1String("configErrorString")).toString(); + kError() << "Error code:" << loadJob->data().value(QLatin1= String("configError")).toInt(); + kError() << "Error description:" << loadJob->data().value(= QLatin1String("configErrorString")).toString(); } } if (operations.testFlag(EnvironmentFile)) { - if (reply.data().value(QLatin1String("envSuccess")).toBool()) { - parseEnv(QString::fromUtf8(reply.data().value(QLatin1Strin= g("envContents")).toByteArray().constData())); + if (loadJob->data().value(QLatin1String("envSuccess")).toBool(= )) { + parseEnv(QString::fromUtf8(loadJob->data().value(QLatin1St= ring("envContents")).toByteArray().constData())); } else { kError() << "Helper failed to read file:" << grubEnvPath(); - kError() << "Error code:" << reply.data().value(QLatin1Str= ing("envError")).toInt(); - kError() << "Error description:" << reply.data().value(QLa= tin1String("envErrorString")).toString(); + kError() << "Error code:" << loadJob->data().value(QLatin1= String("envError")).toInt(); + kError() << "Error description:" << loadJob->data().value(= QLatin1String("envErrorString")).toString(); } } if (operations.testFlag(MemtestFile)) { - m_memtest =3D reply.data().value(QLatin1String("memtest")).toB= ool(); + m_memtest =3D loadJob->data().value(QLatin1String("memtest")).= toBool(); if (m_memtest) { - m_memtestOn =3D reply.data().value(QLatin1String("memtestO= n")).toBool(); + m_memtestOn =3D loadJob->data().value(QLatin1String("memte= stOn")).toBool(); } } if (operations.testFlag(Vbe)) { - m_resolutions =3D reply.data().value(QLatin1String("gfxmodes")= ).toStringList(); + m_resolutions =3D loadJob->data().value(QLatin1String("gfxmode= s")).toStringList(); m_resolutionsEmpty =3D false; m_resolutionsForceRead =3D false; } if (operations.testFlag(Locales)) { - m_locales =3D reply.data().value(QLatin1String("locales")).toS= tringList(); + m_locales =3D loadJob->data().value(QLatin1String("locales")).= toStringList(); } } } @@ -1137,41 +1147,6 @@ void KCMGRUB2::showResolutions() } } = -void KCMGRUB2::processReply(ActionReply &reply) -{ - if (reply.type() =3D=3D ActionReply::Success || reply.type() =3D=3D Ac= tionReply::KAuthError) { - return; - } - - //Process error (contains command, output, errorCode, errorMessage, er= rorDescription) - QLatin1String processKey("isProcessReply"); - if (reply.data().contains(processKey) && reply.data().value(processKey= ).toBool()) { - QString errorMessage; - switch (reply.errorCode()) { - case -2: - errorMessage =3D i18nc("@info", "The process could not be star= ted."); - break; - case -1: - errorMessage =3D i18nc("@info", "The process crashed."); - break; - default: - errorMessage =3D QString::fromUtf8(reply.data().value(QLatin1S= tring("output")).toByteArray().constData()); - break; - } - reply.addData(QLatin1String("errorMessage"), errorMessage); - reply.setErrorDescription(i18nc("@info", "Command: %1Error code: %2Error message:%3= ", reply.data().value(QLatin1String("command")).toStringList().jo= in(QLatin1String(" ")), reply.errorCode(), errorMessage)); - return; - } - - //Simple error (contains errorCode, errorMessage, errorDescription) - QLatin1String errorKey("errorDescription"); - if (reply.data().contains(errorKey)) { - QString errorMessage =3D reply.data().value(errorKey).toString(); - reply.addData(QLatin1String("errorMessage"), errorMessage); - reply.setErrorDescription(i18nc("@info", "Error code: %1Error message: %2", reply.errorCode(), errorMe= ssage)); - reply.data().remove(errorKey); - } -} QString KCMGRUB2::parseTitle(const QString &line) { QChar ch; @@ -1312,3 +1287,5 @@ void KCMGRUB2::parseEnv(const QString &config) m_env[line.section(QLatin1Char('=3D'), 0, 0)] =3D line.section(QLa= tin1Char('=3D'), 1); } } + +#include "kcm_grub2.moc" diff --git a/src/kcm_grub2.h b/src/kcm_grub2.h index bc57d30..c36657b 100644 --- a/src/kcm_grub2.h +++ b/src/kcm_grub2.h @@ -93,7 +93,6 @@ private: void sortResolutions(); void showResolutions(); = - void processReply(ActionReply &reply); QString parseTitle(const QString &line); void parseEntries(const QString &config); void parseSettings(const QString &config);