-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheditconfig.cpp
More file actions
89 lines (76 loc) · 2.6 KB
/
editconfig.cpp
File metadata and controls
89 lines (76 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
* Copyright 2017 Sinodun Internet Technologies Ltd.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
*/
#include "editconfig.h"
#include "ui_editconfig.h"
#include "configfilemanager.h"
#include "msgdefs.h"
#include <QDebug>
EditConfig::EditConfig(QWidget *parent) :
QDialog(parent, Qt::Sheet),
ui(new Ui::EditConfig),
m_fileName(""),
m_defaultFileName("")
{
ui->setupUi(this);
setSizeGripEnabled((true));
SMDebug(eConfiguration, "sizeGripEnabled is %s", (isSizeGripEnabled() ? "true" : "false"));
connect(this, SIGNAL(rejected()), this, SLOT(on_rejected()));
bool ok;
/* Open the most recently edited configuration*/
QString configText = ConfigFileManager().getLastSavedConfig(&ok);
if (ok) {
ui->plainTextEdit->setPlainText(configText);
} else {
ui->plainTextEdit->setPlainText("Error opening config file");
}
}
EditConfig::~EditConfig()
{
SMDebug(eDestructors,"");
delete ui;
}
void EditConfig:: on_rejected()
{
SMDebug(eConfiguration, "");
/*there may be changes from earlier*/
emit doneEditing(ConfigFileManager().tempConfigFileExists());
}
void EditConfig::on_saveButton_clicked()
{
SMDebug(eConfiguration, "");
bool ok;
QString text = ui->plainTextEdit->toPlainText();
if (ConfigFileManager().isValidConfigText(text, &ok) && ok) {
ConfigFileManager().saveTempConfig(text, &ok); //saves to temporary file, overwriting if one already exists.
qDebug() << __FILE__ << ":" << __FUNCTION__ << ": config saved to temp file";
if (ConfigFileManager().getRuntimeConfig(&ok) == text) {
ConfigFileManager().discardTempConfigFile(&ok);
emit doneEditing(false);
} else {
emit doneEditing(true);
}
} else {
SMWarning("Edited configuration could not be validated - it was not saved");
emit newStatusMessage("Edited configuration could not be validated - it was not saved");
ui->validateLabel->setText("Not valid - config cannot be saved.");
}
}
void EditConfig::on_validateButton_clicked()
{
bool ok;
if (ConfigFileManager().isValidConfigText(ui->plainTextEdit->toPlainText(), &ok) && ok) {
ui->validateLabel->setText("Valid!");
} else {
if (ok) {
ui->validateLabel->setText("Not valid");
} else {
ui->validateLabel->setText("Error");
SMDebug(eConfiguration, "Error during validation");
}
}
}