Pref: Wb: remove args first element on restart.
- isRebootRequired is not public but in accept&reject. - PreferencePage::isRebootRequired changed to const - Change 2 warnings to log - remove useless c_str() - Change DlgPreferencesImp::isRebootRequired name + reboot by restart everywhere. - Sort workbenches so that disabled wb are sorted.
This commit is contained in:
@@ -1377,8 +1377,6 @@ PyObject* Application::sShowPreferences(PyObject * /*self*/, PyObject *args)
|
||||
wc.restoreCursor();
|
||||
cDlg.exec();
|
||||
wc.setWaitCursor();
|
||||
cDlg.isRebootRequired(); //The user may have applied first, then clicked the cancel button so it's not in the if(cDlg.exec())
|
||||
wc.setWaitCursor();
|
||||
|
||||
Py_Return;
|
||||
}
|
||||
|
||||
@@ -385,7 +385,6 @@ void StdCmdDlgPreferences::activated(int iMsg)
|
||||
if (cDlg.exec()) {
|
||||
cDlg.activeGroupPage(groupName, index);
|
||||
}
|
||||
cDlg.isRebootRequired(); //The user may have applied first, then clicked the cancel button so it's not in the if(cDlg.exec())
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
|
||||
@@ -71,7 +71,7 @@ DlgPreferencesImp* DlgPreferencesImp::_activeDialog = nullptr;
|
||||
*/
|
||||
DlgPreferencesImp::DlgPreferencesImp(QWidget* parent, Qt::WindowFlags fl)
|
||||
: QDialog(parent, fl), ui(new Ui_DlgPreferences),
|
||||
invalidParameter(false), canEmbedScrollArea(true), rebootRequired(false)
|
||||
invalidParameter(false), canEmbedScrollArea(true), restartRequired(false)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
QFontMetrics fm(font());
|
||||
@@ -339,6 +339,14 @@ void DlgPreferencesImp::accept()
|
||||
applyChanges();
|
||||
if (!this->invalidParameter)
|
||||
QDialog::accept();
|
||||
|
||||
restartIfRequired();
|
||||
}
|
||||
|
||||
void DlgPreferencesImp::reject()
|
||||
{
|
||||
QDialog::reject();
|
||||
restartIfRequired();
|
||||
}
|
||||
|
||||
void DlgPreferencesImp::onButtonBoxClicked(QAbstractButton* btn)
|
||||
@@ -464,7 +472,7 @@ void DlgPreferencesImp::applyChanges()
|
||||
auto page = qobject_cast<PreferencePage*>(tabWidget->widget(j));
|
||||
if (page) {
|
||||
page->saveSettings();
|
||||
rebootRequired = rebootRequired || page->isRebootRequired();
|
||||
restartRequired = restartRequired || page->isRestartRequired();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -477,9 +485,9 @@ void DlgPreferencesImp::applyChanges()
|
||||
}
|
||||
}
|
||||
|
||||
void DlgPreferencesImp::isRebootRequired()
|
||||
void DlgPreferencesImp::restartIfRequired()
|
||||
{
|
||||
if (rebootRequired) {
|
||||
if (restartRequired) {
|
||||
QMessageBox* restartBox = new QMessageBox();
|
||||
restartBox->setIcon(QMessageBox::Warning);
|
||||
restartBox->setWindowTitle(tr("Restart required"));
|
||||
@@ -498,6 +506,7 @@ void DlgPreferencesImp::isRebootRequired()
|
||||
QTimer::singleShot(1000, []()
|
||||
{
|
||||
QStringList args = QApplication::arguments();
|
||||
args.pop_front();
|
||||
if (getMainWindow()->close())
|
||||
QProcess::startDetached(QApplication::applicationFilePath(), args);
|
||||
});
|
||||
|
||||
@@ -124,10 +124,11 @@ public:
|
||||
~DlgPreferencesImp() override;
|
||||
|
||||
void accept() override;
|
||||
void reject() override;
|
||||
void reload();
|
||||
void activateGroupPage(const QString& group, int index);
|
||||
void activeGroupPage(QString& group, int& index) const;
|
||||
void isRebootRequired();
|
||||
void restartIfRequired();
|
||||
|
||||
protected:
|
||||
void changeEvent(QEvent *e) override;
|
||||
@@ -163,7 +164,7 @@ private:
|
||||
std::unique_ptr<Ui_DlgPreferences> ui;
|
||||
bool invalidParameter;
|
||||
bool canEmbedScrollArea;
|
||||
bool rebootRequired;
|
||||
bool restartRequired;
|
||||
|
||||
static const int GroupNameRole; /**< A name for our Qt::UserRole, used when storing user data in a list item */
|
||||
|
||||
|
||||
@@ -343,6 +343,8 @@ void DlgSettingsWorkbenchesImp::buildWorkbenchList()
|
||||
QSignalBlocker sigblk(ui->wbList);
|
||||
|
||||
QStringList workbenches = Application::Instance->workbenches();
|
||||
workbenches.sort(); //This will sort alphabetically the disabled wb.
|
||||
|
||||
QStringList enabledWbs = getEnabledWorkbenches();
|
||||
QStringList disabledWbs = getDisabledWorkbenches();
|
||||
|
||||
@@ -352,7 +354,7 @@ void DlgSettingsWorkbenchesImp::buildWorkbenchList()
|
||||
addWorkbench(wbName, true);
|
||||
}
|
||||
else {
|
||||
Base::Console().Warning("Ignoring unknown %s workbench found in user preferences.", wbName.toStdString().c_str());
|
||||
Base::Console().Log("Ignoring unknown %s workbench found in user preferences.\n", wbName.toStdString().c_str());
|
||||
}
|
||||
}
|
||||
//Second we add workbench in alphabetical order that are either Disabled, or !enabled && !disabled, ie newly added wb.
|
||||
@@ -361,7 +363,7 @@ void DlgSettingsWorkbenchesImp::buildWorkbenchList()
|
||||
addWorkbench(wbName, false);
|
||||
}
|
||||
else if (!enabledWbs.contains(wbName)) {
|
||||
Base::Console().Warning("Adding unknown %s workbench.", wbName.toStdString().c_str());
|
||||
Base::Console().Log("Adding unknown %s workbench.\n", wbName.toStdString().c_str());
|
||||
addWorkbench(wbName, false);
|
||||
}
|
||||
}
|
||||
@@ -392,7 +394,7 @@ QStringList DlgSettingsWorkbenchesImp::getEnabledWorkbenches()
|
||||
QString allWorkbenches = QString::fromLatin1("ALL");
|
||||
|
||||
hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Workbenches");
|
||||
enabled_wbs = QString::fromStdString(hGrp->GetASCII("Enabled", allWorkbenches.toStdString().c_str()).c_str());
|
||||
enabled_wbs = QString::fromStdString(hGrp->GetASCII("Enabled", allWorkbenches.toStdString().c_str()));
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
|
||||
enabled_wbs_list = enabled_wbs.split(QLatin1String(","), Qt::SkipEmptyParts);
|
||||
#else
|
||||
@@ -461,7 +463,7 @@ void DlgSettingsWorkbenchesImp::loadWorkbenchSelector()
|
||||
|
||||
void DlgSettingsWorkbenchesImp::wbToggled(const QString& wbName, bool enabled)
|
||||
{
|
||||
requireReboot();
|
||||
requireRestart();
|
||||
|
||||
setStartWorkbenchComboItems();
|
||||
|
||||
@@ -535,7 +537,7 @@ void DlgSettingsWorkbenchesImp::setStartWorkbenchComboItems()
|
||||
|
||||
void DlgSettingsWorkbenchesImp::wbItemMoved()
|
||||
{
|
||||
requireReboot();
|
||||
requireRestart();
|
||||
for (int i = 0; i < ui->wbList->count(); i++) {
|
||||
wbListItem* wbItem = dynamic_cast<wbListItem*>(ui->wbList->itemWidget(ui->wbList->item(i)));
|
||||
if (wbItem) {
|
||||
@@ -563,13 +565,13 @@ void DlgSettingsWorkbenchesImp::onStartWbChanged(int index)
|
||||
void DlgSettingsWorkbenchesImp::onWbSelectorChanged(int index)
|
||||
{
|
||||
Q_UNUSED(index);
|
||||
requireReboot();
|
||||
requireRestart();
|
||||
}
|
||||
|
||||
void DlgSettingsWorkbenchesImp::onWbByTabToggled(bool val)
|
||||
{
|
||||
Q_UNUSED(val);
|
||||
requireReboot();
|
||||
requireRestart();
|
||||
}
|
||||
|
||||
#include "moc_DlgSettingsWorkbenchesImp.cpp"
|
||||
|
||||
@@ -98,7 +98,7 @@ void PropertyPage::onReset()
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
/** Construction */
|
||||
PreferencePage::PreferencePage(QWidget* parent) : QWidget(parent), rebootRequired(false)
|
||||
PreferencePage::PreferencePage(QWidget* parent) : QWidget(parent), restartRequired(false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -107,14 +107,14 @@ void PreferencePage::changeEvent(QEvent* event)
|
||||
QWidget::changeEvent(event);
|
||||
}
|
||||
|
||||
bool PreferencePage::isRebootRequired()
|
||||
bool PreferencePage::isRestartRequired() const
|
||||
{
|
||||
return rebootRequired;
|
||||
return restartRequired;
|
||||
}
|
||||
|
||||
void PreferencePage::requireReboot()
|
||||
void PreferencePage::requireRestart()
|
||||
{
|
||||
rebootRequired = true;
|
||||
restartRequired = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -73,8 +73,8 @@ public:
|
||||
explicit PreferencePage(QWidget* parent = nullptr);
|
||||
~PreferencePage() override = default;
|
||||
|
||||
bool isRebootRequired();
|
||||
void requireReboot();
|
||||
bool isRestartRequired() const;
|
||||
void requireRestart();
|
||||
|
||||
public Q_SLOTS:
|
||||
virtual void loadSettings()=0;
|
||||
@@ -84,7 +84,7 @@ protected:
|
||||
void changeEvent(QEvent* event) override = 0;
|
||||
|
||||
private:
|
||||
bool rebootRequired;
|
||||
bool restartRequired;
|
||||
};
|
||||
|
||||
/** Subclass that embeds a form from a UI file.
|
||||
|
||||
Reference in New Issue
Block a user