-
Notifications
You must be signed in to change notification settings - Fork 0
/
CNotes.qml
executable file
·385 lines (318 loc) · 11.4 KB
/
CNotes.qml
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
import QtQuick 2.0
import QtMultimedia 5.0
import Ubuntu.Components 0.1
import Ubuntu.Components.ListItems 0.1 as ListItem
import Ubuntu.Components.Popups 0.1
import Ubuntu.Layouts 0.1
import U1db 1.0 as U1db
import DirParser 1.0
import "showdown.js" as Showdown
import "components"
import "view"
import "pages"
MainView {
id: mainView
// objectName for functional testing purposes (autopilot-qt5)
objectName: "mainView"
// Note! applicationName needs to match the .desktop filename
applicationName: "CNotes"
/*
This property enables the application to change orientation
when the device is rotated. The default is false.
*/
//automaticOrientation: true
width: units.gu(50)
height: units.gu(75)
headerColor: "#57365E"
backgroundColor: "#A55263"
footerColor: "#D75669"
property bool wideAspect: width > units.gu(80)
property string idCount
property string id
property string title
property string body
property string category : "None"
property string tag : "None"
property string position
property string archivePos
property string filter
property string archive
property string mode
property string link
property string links
property string imageLocation
property bool showArchive: false
property bool createNote: false
property string specificTag
property variant filterNotesModel
property variant noteLinksModel
property variant imagesModel
property string focusedEntry: ""
property variant database
property variant backend
filterNotesModel: ListModel {}
noteLinksModel: ListModel {}
imagesModel: ListModel {}
ListModel { id: noteTagsModel }
ListModel {
// Here are stored the three last used tags (for the gridView)
id: tagsModel
}
DirParser {id: dirParser}
onTagChanged: {
if (wideAspect) {
noteTagsModel.clear()
for (var i = 0; i < mainView.tag.split(",").length; i++) {
noteTagsModel.append({tag: mainView.tag.split(",")[i]})
}
}
}
function setIdCount() {
mainView.idCount = 0
var archive = database.getDoc("archive")
var all = database.getDoc("notes")
for (var i = 0; i < archive["notes"].length; i++) {
all["notes"][all["notes"].length] = archive["notes"][i]
}
mainView.idCount = all["notes"].length
}
function containTag(t) {
for (var i = 0; i < tagsModel.count; i++) {
if (t === tagsModel.get(i).tag) {
return true
}
}
return false
}
function tagIsUsed(t, tags) {
for (var i = 0; i < tags.length; i++) {
if (t === tags[i]) {
return true
}
}
return false
}
function getHtmlText(text) {
var converter = new Showdown.Showdown.converter();
return converter.makeHtml(text)
}
function getLinksForStorage() {
var res = "undefined"
if (noteLinksModel.count > 0) {
res = noteLinksModel.get(0).link
for (var i = 1; i < noteLinksModel.count; i++) {
res = res + "," + noteLinksModel.get(i).link
}
}
return res
}
function deleteArchive() {
for (var i = 0; i < archivesModel.count; i++) {
Storage.removeNote(archivesModel.get(i).id)
}
archivesModel.clear()
}
database: U1db.Database {
id: database
path: "CNotesDatabase.db"
}
U1db.Document {
id: notesDocument
database: database
docId: "notes"
create: true
defaults: {"notes": []}
}
U1db.Document {
id: archiveDocument
database: database
docId: "archive"
create: true
defaults: {"notes": []}
}
U1db.Document {
id: categoriesDocument
database: database
docId: "categories"
create: true
defaults: {"categories": ["None", "Work", "Things to do"] }
}
U1db.Document {
id: tagsDocument
database: database
docId: "tags"
create: true
defaults: {"tags": []}
}
backend: U1Backend {
id: backend
}
PageStack {
id: rootPageStack
Component.onCompleted: {
setIdCount()
rootPageStack.push(mainConditionalPage)
}
Page {
id: mainConditionalPage
visible: false
title: "CNotes"
tools: MainToolbar {}
Layouts {
anchors.fill: parent
layouts: [
ConditionalLayout {
name: "tabletMainView"
when: mainView.width >= units.gu(80)
Row {
anchors.fill: parent
spacing: units.gu(2)
ItemLayout {
id: itemL
item: "notesSidebar"
width: parent.width / 3 - units.gu(1)
height: parent.height
}
ItemLayout {
id: item
item: "noteView"
width: parent.width * 2 / 3 - units.gu(1)
height: parent.height
}
}
},
ConditionalLayout {
name: "phoneMainView"
when: mainView.width < units.gu(80)
ItemLayout {
item: "notesSidebar"
anchors.fill: parent
}
}
]
NotesListView {
id: notesListView
Layouts.item: "notesSidebar"
model: notesDocument.contents.notes
onCurrentIndexChanged: {
if (notesDocument.contents.notes.length === 0 && wideAspect) {
noteViewRow.visible = false
return
}
if (wideAspect) {
noteViewRow.visible = true
}
}
}
NoteViewRow {
id: noteViewRow
Layouts.item: "noteView"
visible: false
}
}
}
Component {
id: tagsComponent
Popover {
id: tagsPopover
Component.onCompleted: {
var usedTags= database.getDoc("tags").tags
var end = usedTags.length - 4
if (usedTags.length < 4) {
end = 0
}
for (var i = usedTags.length - 1; i > end; i--) {
tagsModel.append({tag: usedTags[i]})
}
}
Column {
anchors {
top: parent.top
left: parent.left
right: parent.right
}
ListItem.Empty {
id: tagListItem
visible: {
if (tagsModel.count == 0) {
return false
}
return true
}
GridView {
id: grid
anchors {
fill: parent
margins: units.gu(1)
}
model: tagsModel
delegate: Button {
id: tagButton
text: tag
color: "#A55263"
anchors.bottomMargin: units.gu(1)
onClicked: {
if (tagTextField.text.length != 0) {
if (!tagIsUsed(tag, tagTextField.text.split(','))) {
tagTextField.text = tagTextField.text.toString() + "," + tag
}
}
else {
tagTextField.text = tag
}
tagListItem.visible = true
}
}
}
}
ListItem.Empty {
Row {
spacing: units.gu(1)
anchors {
verticalCenter: parent.verticalCenter
horizontalCenter: parent.horizontalCenter
}
TextField {
id: tagTextField
placeholderText: i18n.tr("Seperate tags with comma")
text: {
if (mainView.tag != "None") {
return mainView.tag
}
else {
return ""
}
}
anchors.leftMargin: units.gu(1)
}
Button {
id: addTagsButton
height: tagTextField.height
text: i18n.tr("Add tags")
color: "#A55263"
onClicked: {
if (tagTextField.text == "")
tagTextField.text = i18n.tr("None")
mainView.tag = tagTextField.text
for (var i = 0; i < tagTextField.text.split(",").length; i++) {
// Check if tag already exists!
if (!containTag(tagTextField.text.split(",")[i])) {
if (tagsModel.count == 3) {
mainView.backend.addTag(tagsModel.get(0), tagTextField.text.split(",")[i])
}
else {
mainView.backend.addTag("", tagTextField.text.split(",")[i])
}
tagsModel.append({tag: tagTextField.text.split(",")[i]})
}
}
PopupUtils.close(tagsPopover)
}
}
}
}
}
}
}
}
}