details:confirm layout change,save data when needed

pull/19/head
Michail Vourlakos 5 years ago
parent 7695443a90
commit d3a0b3cf31

@ -25,7 +25,6 @@
#include "../controllers/layoutscontroller.h"
#include "../handlers/detailshandler.h"
namespace Latte {
namespace Settings {
namespace Dialog {
@ -94,7 +93,7 @@ void DetailsDialog::accept()
void DetailsDialog::on_ok()
{
qDebug() << Q_FUNC_INFO;
m_layoutsController->setLayoutProperties(m_handler->currentData());
m_handler->save();
close();
}

@ -61,9 +61,10 @@ public:
Ui::DetailsDialog *ui() const;
Controller::Layouts *layoutsController() const;
private slots:
protected:
void accept() override;
private slots:
void on_ok();
void on_cancel();
void on_reset();

@ -21,9 +21,13 @@
#include "genericdialog.h"
// Qt
#include <QFileDialog>
#include <QKeyEvent>
#include <QMessageBox>
#include <QVBoxLayout>
// KDE
#include <KLocalizedString>
static const int ERRORINTERVAL = 4000;
static const int INFORMATIONINTERVAL = 3000;
@ -93,6 +97,25 @@ void GenericDialog::clearCurrentMessageActions()
}
}
int GenericDialog::saveChangesConfirmation(const QString &text)
{
auto msg = new QMessageBox(this);
msg->setIcon(QMessageBox::Warning);
msg->setWindowTitle(i18n("Apply Settings"));
if (text.isEmpty()) {
msg->setText(i18n("The settings have changed. Do you want to apply the changes or discard them?"));
} else {
msg->setText(text);
}
msg->setStandardButtons(QMessageBox::Apply | QMessageBox::Discard | QMessageBox::Cancel);
msg->setDefaultButton(QMessageBox::Apply);
connect(msg, &QFileDialog::finished, msg, &QFileDialog::deleteLater);
return msg->exec();
}
void GenericDialog::showInlineMessage(const QString &msg, const KMessageWidget::MessageType &type, const bool &isPersistent, QList<QAction *> actions)
{
if (msg.isEmpty()) {

@ -44,6 +44,7 @@ public:
~GenericDialog();
void showInlineMessage(const QString &msg, const KMessageWidget::MessageType &type, const bool &isPersistent = false, QList<QAction *> actions = QList<QAction *>());
int saveChangesConfirmation(const QString &text);
protected:
void keyPressEvent(QKeyEvent *event) override;

@ -469,25 +469,15 @@ void SettingsDialog::updateApplyButtonsState()
}
}
int SettingsDialog::saveChangesConfirmation()
{
auto msg = new QMessageBox(this);
msg->setIcon(QMessageBox::Warning);
msg->setWindowTitle(i18n("Apply Settings"));
QString tabName = m_ui->tabWidget->tabBar()->tabText(m_acceptedPage).remove("&");
msg->setText(i18n("The settings of <b>%0</b> tab have changed. Do you want to apply the changes or discard them?").arg(tabName));
msg->setStandardButtons(QMessageBox::Apply | QMessageBox::Discard | QMessageBox::Cancel);
msg->setDefaultButton(QMessageBox::Apply);
connect(msg, &QFileDialog::finished, msg, &QFileDialog::deleteLater);
return msg->exec();
}
bool SettingsDialog::saveChanges()
{
if ((m_acceptedPage == LayoutPage && m_tabLayoutsHandler->dataAreChanged())
|| (m_acceptedPage == PreferencesPage && m_tabPreferencesHandler->dataAreChanged())) {
int result = saveChangesConfirmation();
QString tabName = m_ui->tabWidget->tabBar()->tabText(m_acceptedPage).remove("&");
QString saveChangesText = i18n("The settings of <b>%0</b> tab have changed. Do you want to apply the changes or discard them?").arg(tabName);
int result = saveChangesConfirmation(saveChangesText);
if (result == QMessageBox::Apply) {
save();

@ -93,12 +93,13 @@ protected:
void dragMoveEvent(QDragMoveEvent *event) override;
void dropEvent(QDropEvent *event) override;
void reject() override;
private slots:
void on_import_fullconfiguration();
void on_export_fullconfiguration();
void accept() override;
void reject() override;
void apply();
void reset();
@ -122,9 +123,7 @@ private:
void save();
void setCurrentFreeActivitiesLayout(const int &row);
int saveChangesConfirmation();
bool saveChanges();
QSize storedWindowSize() const;
private:

@ -36,6 +36,7 @@
#include <QColorDialog>
#include <QFileDialog>
#include <QIcon>
#include <QMessageBox>
// KDE
#include <KIconDialog>
@ -224,6 +225,7 @@ void DetailsHandler::resetDefaults()
void DetailsHandler::save()
{
m_parentDialog->layoutsController()->setLayoutProperties(currentData());
}
void DetailsHandler::on_clearIcon()
@ -245,11 +247,30 @@ void DetailsHandler::on_currentColorIndexChanged(int row)
void DetailsHandler::on_currentLayoutIndexChanged(int row)
{
QString layoutId = m_layoutsProxyModel->data(m_layoutsProxyModel->index(row, Model::Layouts::IDCOLUMN), Qt::UserRole).toString();
m_parentDialog->layoutsController()->selectRow(layoutId);
reload();
bool switchtonewlayout{true};
emit currentLayoutChanged();
if (dataAreChanged()) {
int result = saveChanges();
if (result == QMessageBox::Apply) {
save();
} else if (result == QMessageBox::Discard) {
//do nothing
} else if (result == QMessageBox::Cancel) {
switchtonewlayout = false;
}
}
if (switchtonewlayout) {
QString layoutId = m_layoutsProxyModel->data(m_layoutsProxyModel->index(row, Model::Layouts::IDCOLUMN), Qt::UserRole).toString();
m_parentDialog->layoutsController()->selectRow(layoutId);
reload();
emit currentLayoutChanged();
} else {
//! reset combobox index
m_ui->layoutsCmb->setCurrentText(c_data.name);
}
}
void DetailsHandler::setBackground(const QString &background)
@ -372,6 +393,18 @@ void DetailsHandler::updateWindowTitle()
m_parentDialog->setWindowTitle(m_ui->layoutsCmb->currentText());
}
int DetailsHandler::saveChanges()
{
if (dataAreChanged()) {
QString layoutName = c_data.name;
QString saveChangesText = i18n("The settings of <b>%0</b> layout have changed. Do you want to apply the changes or discard them?").arg(layoutName);
return m_parentDialog->saveChangesConfirmation(saveChangesText);
}
return QMessageBox::Cancel;
}
}
}
}

@ -106,6 +106,8 @@ private:
void loadLayout(const Latte::Data::Layout &data);
int saveChanges();
private:
Dialog::DetailsDialog *m_parentDialog{nullptr};
Ui::DetailsDialog *m_ui{nullptr};

Loading…
Cancel
Save