diff --git a/rkward/dialogs/rksetupwizard.cpp b/rkward/dialogs/rksetupwizard.cpp index 123ec3ec..541db93e 100644 --- a/rkward/dialogs/rksetupwizard.cpp +++ b/rkward/dialogs/rksetupwizard.cpp @@ -1,242 +1,288 @@ /*************************************************************************** rksetupwizard - description ------------------- begin : Fri May 25 20200 copyright : (C) 2020 by Thomas Friedrichsmeier email : thomas.friedrichsmeier@kdemail.net ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "rksetupwizard.h" #include #include #include #include #include #include #include #include #include #include "../settings/rksettingsmoduleplugins.h" #include "../settings/rksettingsmodulegeneral.h" #include "../misc/rkcommonfunctions.h" #include "../misc/rkstandardicons.h" #include "../windows/katepluginintegration.h" +#include "../rbackend/rksessionvars.h" #include "../rbackend/rkrinterface.h" #include "../rkglobals.h" #include "../rkward.h" #include "../debug.h" bool RKSetupWizard::has_been_run = false; class RKSetupWizardItem { public: enum Status { Error, Warning, Good }; RKSetupWizardItem(const QString &shortlabel, const QString &longlabel=QString(), Status status=Good, const QString &shortstatuslabel=QString()) : status(status), shortlabel(shortlabel), longlabel(longlabel), shortstatuslabel(shortstatuslabel), box(nullptr) {}; ~RKSetupWizardItem() {}; + void addOption(const QString &shortlabel, const QString &longlabel, std::function callback) { + options.append(Option(shortlabel, longlabel, callback)); + } + void setStatus(Status _status, const QString &_shortstatuslabel) { status = _status; shortstatuslabel = _shortstatuslabel; }; + void setShortLabel(const QString &label) { shortlabel = label; }; + void setLongLabel(const QString &label) { longlabel = label; }; +private: +friend class RKSetupWizard; void createWidget(QGridLayout *layout, int row) { QString icon_id; if (status == Good) icon_id = QLatin1String("dialog-positive"); else if (status == Warning) icon_id = QLatin1String("dialog-warning"); - else icon_id = QLatin1String("dialog_error"); + else icon_id = QLatin1String("dialog-error"); auto label = new QLabel(); label->setPixmap(QIcon::fromTheme(icon_id).pixmap(32, 32)); // TODO: Correct way to not hardcode size? layout->addWidget(label, row, 0); layout->addWidget(new QLabel(shortlabel + ": " + shortstatuslabel), row, 1); if (options.isEmpty()) { layout->addWidget(new QLabel(i18n("No action needed.")), row, 2); } else if (options.length() == 1) { layout->addWidget(new QLabel(options[0].shortlabel), row, 2); } else { box = new QComboBox(); for (int i = 0; i < options.size(); ++i) { box->addItem(options[i].shortlabel); } layout->addWidget(box, row, 2); } if (!(longlabel.isEmpty() && options.isEmpty())) { QString details = longlabel; for (int i = 0; i < options.size(); ++i) { details += QString("

%1: %2

").arg(options[i].shortlabel).arg(options[i].longlabel); } auto info = new QPushButton(); info->setIcon(RKStandardIcons::getIcon(RKStandardIcons::WindowHelp)); QObject::connect(info, &QPushButton::clicked, [details, layout]() { KMessageBox::information(layout->parentWidget(), details); }); layout->addWidget(info, row, 3); } } - void addOption(const QString &shortlabel, const QString &longlabel, std::function callback) { - options.append(Option(shortlabel, longlabel, callback)); - } - void setStatus(Status _status, const QString &_shortstatuslabel) { status = _status; shortstatuslabel = _shortstatuslabel; }; - void setShortLabel(const QString &label) { shortlabel = label; }; - void setLongLabel(const QString &label) { longlabel = label; }; - void apply() { + void apply(RKSetupWizard *wizard) { if (options.isEmpty()) return; int opt = 0; if (box) opt = box->currentIndex(); - options[opt].callback(); + options[opt].callback(wizard); }; -private: + struct Option { - Option(const QString &shortlabel, const QString &longlabel, std::function callback) : shortlabel(shortlabel), longlabel(longlabel), callback(callback) {}; + Option(const QString &shortlabel, const QString &longlabel, std::function callback) : shortlabel(shortlabel), longlabel(longlabel), callback(callback) {}; QString shortlabel; QString longlabel; - std::function callback; + std::function callback; }; QList