| 352 |
david |
1 |
#include <QFile>
|
|
|
2 |
#include <QTextStream>
|
|
|
3 |
#include <QMessageBox>
|
|
|
4 |
#include <QDir>
|
|
|
5 |
#include <QPushButton>
|
|
|
6 |
#include <QDateTime>
|
|
|
7 |
|
|
|
8 |
#include "QmEditAwards.h"
|
|
|
9 |
#include "ui_QmEditAwards.h"
|
|
|
10 |
#include "consts.h"
|
|
|
11 |
#include "structs.h"
|
|
|
12 |
#include "proto.h"
|
|
|
13 |
|
|
|
14 |
QmEditAwards::QmEditAwards(const QString& name, const bool silentCreate ,QWidget *parent) :
|
|
|
15 |
QDialog(parent),
|
|
|
16 |
ui(new Ui::QmEditAwards)
|
|
|
17 |
{
|
|
|
18 |
ui->setupUi(this);
|
|
|
19 |
|
|
|
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 |
QSpacerItem *horizontalSpacer2;
|
|
|
52 |
horizontalSpacer2 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
|
|
|
53 |
ui->horizontalLayout2->addItem(horizontalSpacer2);
|
|
|
54 |
|
|
|
55 |
// Attempt to open the file name specified
|
|
|
56 |
// qDebug("Edit: %s", name);
|
|
|
57 |
setWindowTitle(name);
|
|
|
58 |
|
|
|
59 |
/*
|
|
|
60 |
** Read the file into the message area
|
|
|
61 |
*/
|
|
|
62 |
file.setFileName(name);
|
|
|
63 |
if (!file.open(QFile::ReadOnly | QFile::Text)) {
|
|
|
64 |
if (! silentCreate)
|
|
|
65 |
{
|
|
|
66 |
QMessageBox::warning(this, tr("Application"),
|
|
|
67 |
tr("Cannot read file %1:\n%2.")
|
|
|
68 |
.arg(name)
|
|
|
69 |
.arg(file.errorString()));
|
|
|
70 |
return;
|
|
|
71 |
}
|
|
|
72 |
}
|
|
|
73 |
|
|
|
74 |
QTextStream in(&file);
|
|
|
75 |
ui->textEdit->setPlainText(in.readAll());
|
|
|
76 |
file.close();
|
|
|
77 |
|
|
|
78 |
/*
|
|
|
79 |
** Put the user into the editor
|
|
|
80 |
*/
|
|
|
81 |
ui->textEdit->setFocus();
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
/*----------------------------------------------------------------------------
|
|
|
85 |
** FUNCTION : ~QmEditAwards()
|
|
|
86 |
**
|
|
|
87 |
** DESCRIPTION : Descructor
|
|
|
88 |
**
|
|
|
89 |
**
|
|
|
90 |
** INPUTS :
|
|
|
91 |
**
|
|
|
92 |
** RETURNS :
|
|
|
93 |
**
|
|
|
94 |
----------------------------------------------------------------------------*/
|
|
|
95 |
|
|
|
96 |
QmEditAwards::~QmEditAwards()
|
|
|
97 |
{
|
|
|
98 |
delete ui;
|
|
|
99 |
}
|
|
|
100 |
|
|
|
101 |
/*----------------------------------------------------------------------------
|
|
|
102 |
** FUNCTION : save
|
|
|
103 |
**
|
|
|
104 |
** DESCRIPTION : Save the text to the output file
|
|
|
105 |
**
|
|
|
106 |
**
|
|
|
107 |
** INPUTS :
|
|
|
108 |
**
|
|
|
109 |
** RETURNS :
|
|
|
110 |
**
|
|
|
111 |
----------------------------------------------------------------------------*/
|
|
|
112 |
|
|
|
113 |
void QmEditAwards::save(void)
|
|
|
114 |
{
|
|
|
115 |
//qDebug("Save File");
|
|
|
116 |
if (file.open(QFile::WriteOnly | QFile::Text | QFile::Truncate))
|
|
|
117 |
{
|
|
|
118 |
QTextStream out(&file);
|
|
|
119 |
out << ui->textEdit->toPlainText();
|
|
|
120 |
file.close();
|
|
|
121 |
}
|
|
|
122 |
}
|
|
|
123 |
|
|
|
124 |
/*----------------------------------------------------------------------------
|
|
|
125 |
** FUNCTION : saveAndClose
|
|
|
126 |
**
|
|
|
127 |
** DESCRIPTION : Save the text and close the dialog
|
|
|
128 |
**
|
|
|
129 |
**
|
|
|
130 |
** INPUTS :
|
|
|
131 |
**
|
|
|
132 |
** RETURNS :
|
|
|
133 |
**
|
|
|
134 |
----------------------------------------------------------------------------*/
|
|
|
135 |
|
|
|
136 |
void QmEditAwards::saveAndClose(void)
|
|
|
137 |
{
|
|
|
138 |
qDebug("saveAndClose");
|
|
|
139 |
save();
|
|
|
140 |
done(0);
|
|
|
141 |
}
|
|
|
142 |
|
|
|
143 |
/*----------------------------------------------------------------------------
|
|
|
144 |
** FUNCTION : doClear
|
|
|
145 |
**
|
|
|
146 |
** DESCRIPTION : Clear the text
|
|
|
147 |
**
|
|
|
148 |
**
|
|
|
149 |
** INPUTS :
|
|
|
150 |
**
|
|
|
151 |
** RETURNS :
|
|
|
152 |
**
|
|
|
153 |
----------------------------------------------------------------------------*/
|
|
|
154 |
|
|
|
155 |
void QmEditAwards::doClear(void)
|
|
|
156 |
{
|
|
|
157 |
ui->textEdit->clear();
|
|
|
158 |
ui->textEdit->setFocus();
|
|
|
159 |
}
|
|
|
160 |
|
|
|
161 |
/*----------------------------------------------------------------------------
|
|
|
162 |
** FUNCTION : doDelete
|
|
|
163 |
**
|
|
|
164 |
** DESCRIPTION : Delete the file from disk
|
|
|
165 |
**
|
|
|
166 |
**
|
|
|
167 |
** INPUTS :
|
|
|
168 |
**
|
|
|
169 |
** RETURNS :
|
|
|
170 |
**
|
|
|
171 |
----------------------------------------------------------------------------*/
|
|
|
172 |
|
|
|
173 |
void QmEditAwards::doDelete(void)
|
|
|
174 |
{
|
|
|
175 |
file.remove();
|
|
|
176 |
done(0);
|
|
|
177 |
}
|
|
|
178 |
|
|
|
179 |
|
|
|
180 |
|