Thu, 06 Nov 2014 15:49:09 +0200
- closed old head
900
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1 | #include "ldHeader.h" |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
2 | |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
3 | static const char* g_PartTypeNames[PARTTYPE_NUM_TYPES] = |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
4 | { |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
5 | "Part", |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
6 | "Subpart", |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
7 | "Primitive", |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
8 | "48_Primitive", |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
9 | "Shortcut", |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
10 | "Unofficial_Part", |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
11 | "Unofficial_Subpart", |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
12 | "Unofficial_Primitive", |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
13 | "Unofficial_48_Primitive", |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
14 | "Unofficial_Shortcut", |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
15 | }; |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
16 | |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
17 | static const char g_HeaderBFCNames[] = |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
18 | { |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
19 | "CCW", |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
20 | "CW", |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
21 | "NOCERTIFY", |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
22 | } |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
23 | |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
24 | QString LDHeader::serialize() const |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
25 | { |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
26 | QStringList result; |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
27 | |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
28 | // Title, name and part type |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
29 | result << m_title; |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
30 | result << "Name:" + m_name; |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
31 | result << format ("0 !LDRAW_ORG %1 %2", g_PartTypeNames[int (partType())], qualifiers()) |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
32 | |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
33 | // License (if any, heh) |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
34 | if (not license().isEmpty()) |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
35 | result << "0 !LICENSE " + license(); |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
36 | |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
37 | // Help text, if any |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
38 | if (not help().isEmpty()) |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
39 | { |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
40 | result << ""; |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
41 | |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
42 | for (QString const& a : keywords()) |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
43 | result << "0 !HELP " + a; |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
44 | } |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
45 | |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
46 | // BFC type - specs say this isn't mandatory for NOCERTIFY parts but |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
47 | // highly recommended, so we'll add it in. |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
48 | result << ""; |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
49 | result << "0 BFC " + g_HeaderBFCNames[int (headerBFC())]; |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
50 | |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
51 | // Category, if present |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
52 | if (not category().isEmpty()) |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
53 | { |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
54 | result << ""; |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
55 | result << "0 !CATEGORY " + category(); |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
56 | } |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
57 | |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
58 | // Keywords, if any |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
59 | if (not keywords.isEmpty()) |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
60 | { |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
61 | if (category.isEmpty()) |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
62 | result << ""; |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
63 | |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
64 | for (QString const& a : keywords()) |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
65 | result << "0 !KEYWORDS " + a; |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
66 | } |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
67 | |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
68 | // Command line, if any |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
69 | if (not commandLine().isEmpty()) |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
70 | result << "" << "0 !CMDLINE " + commandLine(); |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
71 | |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
72 | // History entries, if any |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
73 | if (not history().isEmpty()) |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
74 | { |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
75 | result << ""; |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
76 | |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
77 | for (LDHistoryEntry const& a : history()) |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
78 | result << a.serialize(); |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
79 | } |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
80 | |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
81 | // Comments, if any |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
82 | if (not comments().isEmpty()) |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
83 | { |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
84 | result << ""; |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
85 | |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
86 | for (QString const& a : comments()) |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
87 | result << "0 // " + a; |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
88 | } |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
89 | |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
90 | result << ""; |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
91 | QString resultText; |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
92 | |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
93 | // Wrap it all up into a single string |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
94 | for (QString a : result) |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
95 | { |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
96 | // Remove trailing space |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
97 | while (a.right (1) == " ") |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
98 | a.chop (1); |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
99 | |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
100 | result += a + "\r\n"; |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
101 | } |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
102 | |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
103 | return result; |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
104 | } |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
105 | |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
106 | bool LDHeader::isUnofficial() const |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
107 | { |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
108 | return m_partType >= PARTTYPE_FIRST_UNOFFICIAL; |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
109 | } |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
110 | |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
111 | void LDHeader::makeUnofficial() |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
112 | { |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
113 | if (not isUnofficial()) |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
114 | m_partType += PARTTYPE_FIRST_UNOFFICIAL; |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
115 | } |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
116 | |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
117 | void LDHeader::makeOfficial() |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
118 | { |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
119 | if (isUnofficial()) |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
120 | m_partType -= PARTTYPE_FIRST_UNOFFICIAL; |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
121 | } |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
122 | |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
123 | LDHistoryEntry::LDHistoryEntry() : |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
124 | m_isRealName (false) {} |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
125 | |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
126 | QString LDHistoryEntry::serialize() const |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
127 | { |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
128 | QString userblock; |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
129 | |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
130 | if (isRealName()) |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
131 | userblock = format ("{%1}", username()); |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
132 | else |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
133 | userblock = format ("[%1]", username()); |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
134 | |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
135 | return format ("0 !HISTORY %1 %2 %3", date().toString ("yyyy-MM-dd"), userblock, description); |
680009bac81f
- commit work done on header/body split
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
136 | } |