-
Notifications
You must be signed in to change notification settings - Fork 2
/
DocumentFactory.cpp
83 lines (65 loc) · 1.83 KB
/
DocumentFactory.cpp
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
#include "DocumentFactory.h"
#include <QFile>
#include <QTextStream>
#include <exception>
#include "NotesManager.h"
#include "TagManager.h"
#include "Trash.h"
/***
* Document
*/
Document* DocumentFactory::buildNote(const QString &path)
{
QFile fichier(path);
if(!fichier.open(QIODevice::ReadOnly | QIODevice::Text)){
return 0;
}
QTextStream flux(&fichier);
QString fpath = flux.readLine();
QString title=flux.readLine();
Document *d = new Document(fpath, title);
QString tags = flux.readLine();
QStringList tagList = QStringList();
if(!tags.isEmpty())
tagList = tags.split("|||");
qDebug()<<"Factory: getting taglist: " << tagList;
for(QStringList::iterator it = tagList.begin(); it!=tagList.end(); ++it){
Tag* t = this->tm->getTag(*it);
// double binding method
tm->addTagToNote(t, d);
}
QString isDeleted = flux.readLine();
NotesManager *nm = &NotesManager::getInstance();
QString notePath = "";
while(!notePath.isNull()) {
notePath = flux.readLine();
qDebug()<<"getting note path from Doc" << notePath;
QFile noteFile(notePath);
if(noteFile.open(QIODevice::ReadOnly | QIODevice::Text))
d->addNote(&nm->getNote(notePath));
else
break;
}
fichier.close();
// We do this at the end so that all documents are properly loaded.
if(isDeleted == "isDeleted"){
// Trash will take care of all unbinding staff
Trash::getInstance()->recycle(d);
}
else
d->setDeleted(false);
d->setModified(false);
return d;
}
Document* DocumentFactory::buildNewNote()
{
return new Document(generateNewFilePath());
}
QString DocumentFactory::getFolder()
{
return "DOC/";
}
QString DocumentFactory::getExtension()
{
return ".doc";
}