Repository navigation
Expand file tree
/
Copy pathfile.cpp
More file actions
168 lines (141 loc) · 2.38 KB
/
Copy pathfile.cpp
File metadata and controls
168 lines (141 loc) · 2.38 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#include <QFileInfo>
#include <QTextStream>
#include <QDebug>
#include <QVariant>
#include "file.h"
#include "filetypemanager.h"
int File::m_count = 0;
File::File(QFile *file) : QObject(0)
{
m_index = m_count++;
setFile(file);
}
File::~File()
{
}
void File::setFile(QFile *file = 0)
{
setModified(false);
if(file){
QFileInfo info(file->fileName());
setName(info.fileName());
setPath(info.filePath());
setSuffix(info.suffix());
QTextStream in(file);
m_content = in.readAll();
m_new = false;
m_type = FileTypes.getTypeByExtension(m_suffix);
setMode(m_type);
}
else{
m_name = "untitled";
m_path = m_suffix = m_content = "";
m_new = true;
m_type = m_mode = FileTypes.getDefaultType();
}
}
int File::getIndex()
{
return m_index;
}
void File::setName(QString name)
{
if(m_name.isNull()){
m_name = name;
}
else{
if(m_name != name){
m_name = name;
emit nameChanged();
}
}
}
QString& File::getName()
{
return m_name;
}
void File::setPath(QString path)
{
m_path = path;
}
QString& File::getPath()
{
return m_path;
}
QString& File::getSuffix()
{
return m_suffix;
}
void File::setSuffix(QString suffix)
{
m_suffix = suffix;
}
bool File::isModified()
{
return m_modified;
}
void File::setModified(bool modified)
{
if(m_modified != modified){
m_modified = modified;
emit wasModified(m_modified);
}
}
void File::setContent(QString &content)
{
m_content = content;
}
FileType* File::getType()
{
return m_type;
}
void File::setType(FileType *type)
{
m_type = type;
}
QVariantMap File::getTypeMap()
{
return m_type->toMap();
}
void File::setMode(FileType *mode)
{
if(!m_mode){
m_mode = mode;
}
else{
if(m_mode != mode){
m_mode = mode;
if(!mode->action->isChecked()) mode->action->setChecked(true);
emit modeChanged();
}
}
}
FileType* File::getMode()
{
return m_mode;
}
QVariantMap File::getModeMap()
{
return m_mode->toMap();
}
QString& File::getContent()
{
return m_content;
}
bool File::isNew()
{
return m_new;
}
void File::setCurrent()
{
emit isCurrent();
}
void File::setClosed()
{
emit closed();
delete this;
}
void File::setSave()
{
emit save();
}