-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathNoteData.vala
More file actions
89 lines (78 loc) · 3.23 KB
/
NoteData.vala
File metadata and controls
89 lines (78 loc) · 3.23 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
/*
* SPDX-License-Identifier: GPL-3.0-or-later
* SPDX-FileCopyrightText: 2017-2024 Lains
* 2025 Contributions from the ellie_Commons community (github.com/ellie-commons/)
* 2025-2026 Stella & Charlie (teamcons.carrd.co)
*/
/*************************************************/
/**
* An object used to package all data conveniently as needed.
*/
public class Jorts.NoteData : Object {
// Will determine properties (or lack thereof) for any new note
public static Jorts.Themes latest_theme = DEFAULT_THEME;
public static int latest_zoom = DEFAULT_ZOOM;
public static bool latest_mono = DEFAULT_MONO;
public string? title;
public Jorts.Themes? theme;
public string? content;
public bool? monospace;
public int? zoom;
public int? width;
public int? height;
/*************************************************/
/**
* Convert into a Json.Object()
*/
construct {
// We assign defaults in case theres args missing
this.title = title ?? Jorts.Utils.random_title ();
this.theme = theme ?? Jorts.Themes.random_theme (latest_theme);
this.content = content ?? "";
this.monospace = monospace ?? latest_mono;
this.zoom = zoom ?? latest_zoom;
this.width = width ?? DEFAULT_WIDTH;
this.height = height ?? DEFAULT_HEIGHT;
}
/*************************************************/
/**
* Parse a node to create an associated NoteData object
*/
public NoteData.from_json (Json.Object node) {
title = node.get_string_member_with_default ("title", (_("Forgot title!")));
theme = (Jorts.Themes)node.get_int_member_with_default ("color", Jorts.Themes.random_theme ());
content = node.get_string_member_with_default ("content","");
monospace = node.get_boolean_member_with_default ("monospace", DEFAULT_MONO);
zoom = (int)node.get_int_member_with_default ("zoom", DEFAULT_ZOOM);
// Make sure the values are nothing crazy
if (zoom < ZOOM_MIN) { zoom = ZOOM_MIN;}
else if (zoom > ZOOM_MAX) { zoom = ZOOM_MAX;}
width = (int)node.get_int_member_with_default ("width", DEFAULT_WIDTH);
height = (int)node.get_int_member_with_default ("height", DEFAULT_HEIGHT);
}
/*************************************************/
/**
* Used for storing NoteData inside disk storage
*/
public Json.Object to_json () {
var builder = new Json.Builder ();
// Lets fkin gooo
builder.begin_object ();
builder.set_member_name ("title");
builder.add_string_value (title);
builder.set_member_name ("color");
builder.add_int_value (theme);
builder.set_member_name ("content");
builder.add_string_value (content);
builder.set_member_name ("monospace");
builder.add_boolean_value (monospace);
builder.set_member_name ("zoom");
builder.add_int_value (zoom);
builder.set_member_name ("width");
builder.add_int_value (width);
builder.set_member_name ("height");
builder.add_int_value (height);
builder.end_object ();
return builder.get_root ().get_object ();
}
}