diff --git a/src/dialogs/profilesdialog.h b/src/dialogs/profilesdialog.h
--- a/src/dialogs/profilesdialog.h
+++ b/src/dialogs/profilesdialog.h
@@ -1,7 +1,7 @@
/* Atelier KDE Printer Host for 3D Printing
Copyright (C) <2016>
Author: Lays Rodrigues - lays.rodrigues@kde.org
-
+ Chris Rizzitello - rizzitello@kde.org
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
@@ -38,10 +38,14 @@
QSettings m_settings;
QStringList detectFWPlugins() const;
void accept();
+ void askToSave();
void loadSettings(const QString ¤tProfile = QString());
void removeProfile();
+ void save();
void saveSettings();
void updateCBProfiles();
+ void setModified(bool modified);
+ bool m_modified;
signals:
void updateProfiles();
diff --git a/src/dialogs/profilesdialog.cpp b/src/dialogs/profilesdialog.cpp
--- a/src/dialogs/profilesdialog.cpp
+++ b/src/dialogs/profilesdialog.cpp
@@ -16,40 +16,38 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
+#include
#include
#include
#include
#include "profilesdialog.h"
#include "ui_profilesdialog.h"
-//Do not include for windows/mac os
-#ifndef Q_OS_WIN
-#ifndef Q_OS_MAC
-#include
-#endif
-#endif
-
ProfilesDialog::ProfilesDialog(QWidget *parent) :
QDialog(parent)
, ui(new Ui::ProfilesDialog)
+ , m_modified(false)
{
ui->setupUi(this);
ui->firmwareCB->addItem(QStringLiteral("Auto-Detect"));
ui->firmwareCB->addItems(detectFWPlugins());
ui->baudCB->addItems(SERIAL::BAUDS);
ui->baudCB->setCurrentText(QLatin1String("115200"));
ui->profileCB->setAutoCompletion(true);
connect(ui->profileCB, static_cast(&QComboBox::currentIndexChanged), [this] {
+ askToSave();
loadSettings();
});
updateCBProfiles();
connect(ui->buttonBox, &QDialogButtonBox::clicked, [this](QAbstractButton * btn) {
switch (ui->buttonBox->buttonRole(btn)) {
case QDialogButtonBox::ResetRole:
+ askToSave();
loadSettings();
break;
case QDialogButtonBox::RejectRole:
+ askToSave();
close();
break;
default:
@@ -77,6 +75,19 @@
#else
ui->removeProfilePB->setIcon(style()->standardIcon(QStyle::SP_TrashIcon));
#endif
+//if any control is modifed and no load / save has happend contents are not saved.
+ auto modify = [this] {setModified(true);};
+ connect(ui->baudCB, &QComboBox::currentTextChanged, modify);
+ connect(ui->radiusSB, &QSpinBox::editingFinished, modify);
+ connect(ui->z_delta_dimensionSB, &QSpinBox::editingFinished, modify);
+ connect(ui->x_dimensionSB, &QSpinBox::editingFinished, modify);
+ connect(ui->y_dimensionSB, &QSpinBox::editingFinished, modify);
+ connect(ui->z_dimensionSB, &QSpinBox::editingFinished, modify);
+ connect(ui->heatedBedCK, &QCheckBox::stateChanged, modify);
+ connect(ui->bedTempSB, &QSpinBox::editingFinished, modify);
+ connect(ui->extruderTempSB, &QSpinBox::editingFinished, modify);
+ connect(ui->postPauseLE, &QLineEdit::editingFinished, modify);
+ connect(ui->firmwareCB, &QComboBox::currentTextChanged, modify);
}
ProfilesDialog::~ProfilesDialog()
@@ -89,11 +100,10 @@
m_settings.beginGroup(QStringLiteral("Profiles"));
QStringList groups = m_settings.childGroups();
m_settings.endGroup();
- QString currentProfile = ui->profileCB->currentText();
- if (groups.contains(currentProfile)) {
- int ret = QMessageBox::information(
+ if (groups.contains(ui->profileCB->currentText())) {
+ int ret = QMessageBox::warning(
this
- , i18n("Save?")
+ , i18n("Overwrite Profile?")
, i18n("A profile with this name already exists. \n Are you sure you want to overwrite it?")
, QMessageBox::Save
, QMessageBox::Cancel
@@ -103,6 +113,12 @@
return;
}
}
+ save();
+}
+
+void ProfilesDialog::save()
+{
+ QString currentProfile = ui->profileCB->currentText();
//Add indent to better view of the data
m_settings.beginGroup(QStringLiteral("Profiles"));
m_settings.beginGroup(currentProfile);
@@ -172,6 +188,7 @@
ui->postPauseLE->setText(m_settings.value(QStringLiteral("postPause"), QStringLiteral("")).toString());
m_settings.endGroup();
m_settings.endGroup();
+ setModified(false);
}
@@ -206,39 +223,57 @@
QStringList ProfilesDialog::detectFWPlugins() const
{
- //Path used if for windows/ mac os only.
- QDir pluginDir(qApp->applicationDirPath() + QStringLiteral("/plugins"));
-
-#if defined(Q_OS_WIN)
- pluginDir.setNameFilters(QStringList() << "*.dll");
-
-#elif defined(Q_OS_MAC)
- pluginDir.setNameFilters(QStringList() << "*.dylib");
-
-#else //Not Windows || Not MAC
- QStringList pathList = AtCoreDirectories::pluginDir;
- pathList.append(QLibraryInfo::location(QLibraryInfo::PluginsPath) + QStringLiteral("/AtCore"));
-
- for (const auto &path : pathList) {
+ QDir pluginDir;
+ for (const auto &path : AtCoreDirectories::pluginDir) {
if (QDir(path).exists()) {
//use path where plugins were detected.
pluginDir = QDir(path);
break;
}
}
- pluginDir.setNameFilters(QStringList() << "*.so");
-#endif
QStringList firmwares;
QStringList files = pluginDir.entryList(QDir::Files);
- foreach (const QString &f, files) {
+ for (const QString &f : files) {
QString file = f;
- file = file.split(QChar::fromLatin1('.')).at(0);
+#if defined(Q_OS_WIN)
+ if (file.endsWith(QStringLiteral(".dll")))
+#elif defined(Q_OS_MAC)
+ if (file.endsWith(QStringLiteral(".dylib")))
+#else
+ if (file.endsWith(QStringLiteral(".so")))
+#endif
+ file = file.split(QChar::fromLatin1('.')).at(0);
+ else {
+ continue;
+ }
if (file.startsWith(QStringLiteral("lib"))) {
file = file.remove(QStringLiteral("lib"));
}
file = file.toLower().simplified();
firmwares.append(file);
}
return firmwares;
}
+
+void ProfilesDialog::setModified(bool modified)
+{
+ m_modified = modified;
+}
+
+void ProfilesDialog::askToSave()
+{
+ if (m_modified) {
+ int ret = QMessageBox::question(
+
+ this
+ , i18n("Save?")
+ , i18n("This Profile has been modified, Would you like to Save it?")
+ , QMessageBox::Save
+ , QMessageBox::No
+ );
+ if (ret == QMessageBox::Save) {
+ save();
+ }
+ }
+}