blob: 77af195139ba65e488298a9444b431746246d036 (
plain)
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
|
#ifndef QUICKSAVE_H
#define QUICKSAVE_H
#include <QObject>
#include <QFile>
#include <QUrl>
#include <QFileDialog>
#include <QDebug>
class QuickSave : public QObject {
Q_OBJECT
QString _filename;
QString _data;
Q_PROPERTY(QString save READ save)
Q_PROPERTY(QString filename READ filename WRITE setFilename)
Q_PROPERTY(QString data READ data WRITE setData)
public:
QuickSave(QObject *parent=0) : QObject(parent) {}
QString save() const {
QString fileName = QFileDialog::getOpenFileName(0, tr("Save File"), "",tr("Files (*.qml)"));
// FIXME: ensure fileName is appropriate as a qml Component
if(!fileName.endsWith(".qml"))
fileName.append(".qml");
QFile file(fileName);
qDebug("Attempting to write: %s", file.fileName().toAscii().constData());
if (!file.open(QFile::WriteOnly))
return file.errorString();
file.write(_data.toUtf8());
file.close();
return QString();
}
//TODO: these really should be emitting signals upon changing;
// but we don't display them so it doesn't technically matter
QString filename() const { return _filename; }
void setFilename(const QString filename) { if (_filename != filename) _filename = filename; }
QString data() const { return _data; }
void setData(const QString data) { if (_data != data) _data = data; }
};
#endif // QUICKSAVE_H
|