-
Notifications
You must be signed in to change notification settings - Fork 2
/
Notefactory.cpp
144 lines (116 loc) · 3.81 KB
/
Notefactory.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
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
#include "NoteFactory.h"
#include "ImageNoteFactory.h"
#include "AudioNoteFactory.h"
#include "VideoNoteFactory.h"
#include "ArticleFactory.h"
#include "DocumentFactory.h"
#include "TagManager.h"
#include "NotesManager.h"
#include <QMap>
#include <QApplication>
#include <QSettings>
#include <QDateTime>
#include <QUuid>
/***
* NoteFactory
*/
NoteFactory::NoteFactory()
{
tm = &TagManager::getInstance();
}
Article *NoteFactory::buildArticleCopy(const Article ¬e)
{
QString fpath = generateNewFilePath();
QString title=note.getTitle();
QString text = note.getText();
Article *a=new Article(fpath,title,text);
a->setTags(note.getTags());
a->setDeleted(note.isDeleted());
return a;
}
Document *NoteFactory::buildDocumentCopy(const Document ¬e)
{
Document *d = new Document(generateNewFilePath(), note.getTitle());
NotesManager *nm = &NotesManager::getInstance();
for(QList<Note*>::const_iterator it = note.begin(); it != note.end(); it++){
Note * nCopy = &nm->getNoteClone((**it));
d->addNote(nCopy);
}
d->setTags(note.getTags());
return d;
}
ImageNote *NoteFactory::buildImageNoteCopy(const ImageNote ¬e)
{
ImageNote * a = new ImageNote(generateNewFilePath(), note.getTitle(), note.getDescription(), note.getMediaPath());
a->setTags(note.getTags());
a->setDeleted(note.isDeleted());
return a;
}
AudioNote *NoteFactory::buildAudioNoteCopy(const AudioNote ¬e)
{
AudioNote * a = new AudioNote(generateNewFilePath(), note.getTitle(), note.getDescription(), note.getMediaPath());
a->setTags(note.getTags());
a->setDeleted(note.isDeleted());
return a;
}
VideoNote *NoteFactory::buildVideoNoteCopy(const VideoNote ¬e)
{
VideoNote * a = new VideoNote(generateNewFilePath(), note.getTitle(), note.getDescription(), note.getMediaPath());
a->setTags(note.getTags());
a->setDeleted(note.isDeleted());
return a;
}
QMap<NoteType, NoteFactory *> *NoteFactory::getFactories()
{
QMap<NoteType, NoteFactory *> *factories = new QMap<NoteType, NoteFactory*>();
factories->insert(article,new ArticleFactory());
factories->insert(document,new DocumentFactory());
factories->insert(imageNote,new ImageNoteFactory());
factories->insert(videoNote,new VideoNoteFactory());
factories->insert(audioNote,new AudioNoteFactory());
return factories;
}
QString NoteFactory::generateNewFilePath()
{
QString path = this->getFullFolder()+generateID()+this->getExtension();
qDebug()<<path;
return path;
}
Note *NoteFactory::buildNoteCopy(const Note ¬e)
{
switch(note.type){
case document:
return buildDocumentCopy(dynamic_cast<const Document&>(note));
case article:
return buildArticleCopy(dynamic_cast<const Article&>(note));
case imageNote:
return buildImageNoteCopy(dynamic_cast<const ImageNote&>(note));
case audioNote:
return buildAudioNoteCopy(dynamic_cast<const AudioNote&>(note));
case videoNote:
return buildVideoNoteCopy(dynamic_cast<const VideoNote&>(note));
default:
throw NotesException("Unknown note type when copy note.");
}
}
QString NoteFactory::getFullFolder()
{
QSettings settings;
QString dir;
if(!settings.contains("workspace"))
settings.setValue("workspace", qApp->applicationDirPath());
dir = settings.value("workspace").toString()+"/"+this->getFolder();
return dir;
}
QString NoteFactory::generateID(){
QSettings settings;
qint64 thisone;
if(!settings.value("nextUUid").isNull()){
thisone = settings.value("nextUUid").toInt();
settings.setValue("nextUUid", settings.value("nextUUid").toInt()+1);
} else {
thisone = QDateTime::currentDateTime().toMSecsSinceEpoch();
settings.setValue("nextUUid", thisone+1);
}
return QString::number(thisone);
}