| 197 |
- |
1 |
#include <QFile>
|
|
|
2 |
#include <QTextStream>
|
|
|
3 |
#include <QMessageBox>
|
| 198 |
- |
4 |
#include <QDir>
|
| 380 |
david |
5 |
#include <QPushButton>
|
|
|
6 |
#include <QDateTime>
|
| 197 |
- |
7 |
|
|
|
8 |
#include "qmeditaddendum.h"
|
|
|
9 |
#include "ui_qmeditaddendum.h"
|
| 198 |
- |
10 |
#include "consts.h"
|
|
|
11 |
#include "structs.h"
|
|
|
12 |
#include "proto.h"
|
| 197 |
- |
13 |
|
| 380 |
david |
14 |
QmEditAddendum::QmEditAddendum(const QString& name, const bool silentCreate ,QWidget *parent) :
|
| 197 |
- |
15 |
QDialog(parent),
|
|
|
16 |
ui(new Ui::QmEditAddendum)
|
|
|
17 |
{
|
|
|
18 |
ui->setupUi(this);
|
|
|
19 |
|
| 380 |
david |
20 |
// First row of buttons
|
|
|
21 |
QPushButton * delButton = new QPushButton("Delete");
|
|
|
22 |
delButton->setToolTip("Close and delete the message");
|
|
|
23 |
ui->horizontalLayout1->addWidget(delButton);
|
|
|
24 |
connect(delButton,SIGNAL(clicked()), this, SLOT(doDelete()));
|
|
|
25 |
|
|
|
26 |
QSpacerItem *horizontalSpacer1;
|
|
|
27 |
horizontalSpacer1 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
|
|
|
28 |
ui->horizontalLayout1->addItem(horizontalSpacer1);
|
|
|
29 |
|
|
|
30 |
QPushButton * saveButton = new QPushButton("Save");
|
|
|
31 |
saveButton->setToolTip("Save message and keep editing");
|
|
|
32 |
ui->horizontalLayout1->addWidget(saveButton);
|
|
|
33 |
connect(saveButton,SIGNAL(clicked()), this, SLOT(save()));
|
|
|
34 |
|
|
|
35 |
QPushButton * doneButton = new QPushButton("Save and Close");
|
|
|
36 |
doneButton->setToolTip("Save message and close editor");
|
|
|
37 |
ui->horizontalLayout1->addWidget(doneButton);
|
|
|
38 |
connect(doneButton,SIGNAL(clicked()), this, SLOT(saveAndClose()));
|
|
|
39 |
|
|
|
40 |
QPushButton * cancelButton = new QPushButton("Cancel");
|
|
|
41 |
cancelButton->setToolTip("Exit the dialog now. Changes made since the last save will be lost.");
|
|
|
42 |
ui->horizontalLayout1->addWidget(cancelButton);
|
|
|
43 |
connect(cancelButton,SIGNAL(clicked()), this, SLOT(reject()));
|
|
|
44 |
|
|
|
45 |
// Second Row of Buttons
|
|
|
46 |
QPushButton * clearButton = new QPushButton("Clear");
|
|
|
47 |
clearButton->setToolTip("Clear the text. Continue editing");
|
|
|
48 |
ui->horizontalLayout2->addWidget(clearButton);
|
|
|
49 |
connect(clearButton,SIGNAL(clicked()), this, SLOT(doClear()));
|
|
|
50 |
|
|
|
51 |
QPushButton * timeButton = new QPushButton("TimeStamp");
|
|
|
52 |
timeButton->setToolTip("Insert a timestamp into the message");
|
|
|
53 |
ui->horizontalLayout2->addWidget(timeButton);
|
|
|
54 |
connect(timeButton,SIGNAL(clicked()), this, SLOT(doTimeStamp()));
|
|
|
55 |
|
|
|
56 |
QSpacerItem *horizontalSpacer2;
|
|
|
57 |
horizontalSpacer2 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
|
|
|
58 |
ui->horizontalLayout2->addItem(horizontalSpacer2);
|
|
|
59 |
|
| 197 |
- |
60 |
// Attempt to open the file name specified
|
| 380 |
david |
61 |
// qDebug("Edit: %s", name);
|
| 197 |
- |
62 |
setWindowTitle(name);
|
|
|
63 |
|
| 380 |
david |
64 |
/*
|
|
|
65 |
** Read the file into the message area
|
|
|
66 |
*/
|
| 199 |
david |
67 |
file.setFileName(name);
|
| 197 |
- |
68 |
if (!file.open(QFile::ReadOnly | QFile::Text)) {
|
| 380 |
david |
69 |
if (! silentCreate)
|
|
|
70 |
{
|
|
|
71 |
QMessageBox::warning(this, tr("Application"),
|
|
|
72 |
tr("Cannot read file %1:\n%2.")
|
|
|
73 |
.arg(name)
|
|
|
74 |
.arg(file.errorString()));
|
|
|
75 |
return;
|
|
|
76 |
}
|
| 197 |
- |
77 |
}
|
|
|
78 |
|
|
|
79 |
QTextStream in(&file);
|
|
|
80 |
ui->textEdit->setPlainText(in.readAll());
|
| 198 |
- |
81 |
file.close();
|
| 380 |
david |
82 |
|
|
|
83 |
/*
|
|
|
84 |
** Put the user into the editor
|
|
|
85 |
*/
|
|
|
86 |
ui->textEdit->setFocus();
|
| 197 |
- |
87 |
}
|
|
|
88 |
|
| 380 |
david |
89 |
/*----------------------------------------------------------------------------
|
|
|
90 |
** FUNCTION : ~QmEditAddendum()
|
|
|
91 |
**
|
|
|
92 |
** DESCRIPTION : Descructor
|
|
|
93 |
**
|
|
|
94 |
**
|
|
|
95 |
** INPUTS :
|
|
|
96 |
**
|
|
|
97 |
** RETURNS :
|
|
|
98 |
**
|
|
|
99 |
----------------------------------------------------------------------------*/
|
| 198 |
- |
100 |
|
| 380 |
david |
101 |
QmEditAddendum::~QmEditAddendum()
|
|
|
102 |
{
|
|
|
103 |
delete ui;
|
|
|
104 |
}
|
|
|
105 |
|
|
|
106 |
/*----------------------------------------------------------------------------
|
|
|
107 |
** FUNCTION : save
|
|
|
108 |
**
|
|
|
109 |
** DESCRIPTION : Save the text to the output file
|
|
|
110 |
**
|
|
|
111 |
**
|
|
|
112 |
** INPUTS :
|
|
|
113 |
**
|
|
|
114 |
** RETURNS :
|
|
|
115 |
**
|
|
|
116 |
----------------------------------------------------------------------------*/
|
|
|
117 |
|
| 198 |
- |
118 |
void QmEditAddendum::save(void)
|
|
|
119 |
{
|
| 380 |
david |
120 |
//qDebug("Save File");
|
| 198 |
- |
121 |
if (file.open(QFile::WriteOnly | QFile::Text | QFile::Truncate))
|
|
|
122 |
{
|
|
|
123 |
QTextStream out(&file);
|
|
|
124 |
out << ui->textEdit->toPlainText();
|
|
|
125 |
file.close();
|
|
|
126 |
}
|
| 380 |
david |
127 |
}
|
| 198 |
- |
128 |
|
| 380 |
david |
129 |
/*----------------------------------------------------------------------------
|
|
|
130 |
** FUNCTION : saveAndClose
|
|
|
131 |
**
|
|
|
132 |
** DESCRIPTION : Save the text and close the dialog
|
|
|
133 |
**
|
|
|
134 |
**
|
|
|
135 |
** INPUTS :
|
|
|
136 |
**
|
|
|
137 |
** RETURNS :
|
|
|
138 |
**
|
|
|
139 |
----------------------------------------------------------------------------*/
|
|
|
140 |
|
|
|
141 |
void QmEditAddendum::saveAndClose(void)
|
|
|
142 |
{
|
|
|
143 |
qDebug("saveAndClose");
|
|
|
144 |
save();
|
|
|
145 |
done(0);
|
| 198 |
- |
146 |
}
|
|
|
147 |
|
| 380 |
david |
148 |
/*----------------------------------------------------------------------------
|
|
|
149 |
** FUNCTION : doClear
|
|
|
150 |
**
|
|
|
151 |
** DESCRIPTION : Clear the text
|
|
|
152 |
**
|
|
|
153 |
**
|
|
|
154 |
** INPUTS :
|
|
|
155 |
**
|
|
|
156 |
** RETURNS :
|
|
|
157 |
**
|
|
|
158 |
----------------------------------------------------------------------------*/
|
|
|
159 |
|
|
|
160 |
void QmEditAddendum::doClear(void)
|
| 197 |
- |
161 |
{
|
| 380 |
david |
162 |
ui->textEdit->clear();
|
|
|
163 |
ui->textEdit->setFocus();
|
| 197 |
- |
164 |
}
|
| 380 |
david |
165 |
|
|
|
166 |
/*----------------------------------------------------------------------------
|
|
|
167 |
** FUNCTION : doDelete
|
|
|
168 |
**
|
|
|
169 |
** DESCRIPTION : Delete the file from disk
|
|
|
170 |
**
|
|
|
171 |
**
|
|
|
172 |
** INPUTS :
|
|
|
173 |
**
|
|
|
174 |
** RETURNS :
|
|
|
175 |
**
|
|
|
176 |
----------------------------------------------------------------------------*/
|
|
|
177 |
|
|
|
178 |
void QmEditAddendum::doDelete(void)
|
|
|
179 |
{
|
|
|
180 |
file.remove();
|
|
|
181 |
done(0);
|
|
|
182 |
}
|
|
|
183 |
|
|
|
184 |
/*----------------------------------------------------------------------------
|
|
|
185 |
** FUNCTION : doTimeStamp
|
|
|
186 |
**
|
|
|
187 |
** DESCRIPTION : Insert a Date-Time into the text
|
|
|
188 |
**
|
|
|
189 |
**
|
|
|
190 |
** INPUTS :
|
|
|
191 |
**
|
|
|
192 |
** RETURNS :
|
|
|
193 |
**
|
|
|
194 |
----------------------------------------------------------------------------*/
|
|
|
195 |
|
|
|
196 |
|
|
|
197 |
void QmEditAddendum::doTimeStamp(void)
|
|
|
198 |
{
|
|
|
199 |
ui->textEdit->insertPlainText(QDateTime::currentDateTime().toString("dd-MMM-yy hh:mm:ss").append(":"));
|
|
|
200 |
ui->textEdit->setFocus();
|
|
|
201 |
}
|
|
|
202 |
|