File: debugtool.cpp

package info (click to toggle)
nixnote2 2.0~beta11-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 9,448 kB
  • ctags: 7,058
  • sloc: cpp: 68,338; java: 1,096; sh: 834; makefile: 27
file content (314 lines) | stat: -rw-r--r-- 10,062 bytes parent folder | download
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
/*********************************************************************************
NixNote - An open-source client for the Evernote service.
Copyright (C) 2015 Randy Baumgarte

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
***********************************************************************************/

#include "debugtool.h"
#include "global.h"


DebugTool::DebugTool()
{
}


//************************************
// Dump a tag to the debug log
//************************************
void DebugTool::dumpTag(Tag tag) {
    QLOG_DEBUG() << "*** Dumping Tag ***";
    dumpField(tag.guid, "guid");
    dumpField(tag.name, "name");
    dumpField(tag.parentGuid, "parent");
    dumpField(tag.updateSequenceNum, "USN");
    QLOG_DEBUG() << "*** Tag Dump complete ***";
}



//************************************
// Dump a saved search to the debug log
//************************************
void DebugTool::dumpSavedSearch(SavedSearch search) {
    QLOG_DEBUG() << "*** Dumping Saved Search ***";
    dumpField(search.guid, "guid");
    dumpField(search.name, "name");
    dumpField(search.query, "query");
    dumpField(search.updateSequenceNum, "USN");
    if (search.format.isSet())
        QLOG_DEBUG() << "format:" << search.format << ":";
    else
        QLOG_DEBUG() << "format not found.";
    if (search.scope.isSet()) {
        SavedSearchScope scope = search.scope;
        dumpField(scope.includeAccount, "includeAccount");
        dumpField(scope.includePersonalLinkedNotebooks, "includePersonalLinkedNotebooks");
        dumpField(scope.includeBusinessLinkedNotebooks, "includeBusinessLinkedNotebooks");
    } else
        QLOG_DEBUG() << "search scope not found.";

    QLOG_DEBUG() << "*** Saved Search Dump Complete ***";
}



//************************************
// Dump a note to the debug log
//************************************
void DebugTool::dumpNote(Note note) {
    QLOG_DEBUG() << "*** Dumping Note ***";
    dumpField(note.guid, "guid");
    dumpField(note.active, "active");
    dumpField(note.title, "title");
    dumpField(note.content, "content");
    dumpField(note.contentHash, "contentHash", true);
    dumpField(note.contentLength, "contentLength");
    dumpField(note.created, "created");
    dumpField(note.updated, "updated");
    dumpField(note.deleted, "deleted");
    dumpField(note.updateSequenceNum, "USN");
    dumpField(note.tagGuids, "tag guids");
    dumpField(note.tagNames, "tag names");
    if (!note.attributes.isSet()) {
        QLOG_DEBUG() << "no note attributes found.";
    } else {
        NoteAttributes attributes = note.attributes;
        dumpField(attributes.subjectDate, "subject date");
        dumpField(attributes.latitude, "latitude");
        dumpField(attributes.longitude, "longitude");
        dumpField(attributes.altitude, "altitude");
        dumpField(attributes.author, "author");
        dumpField(attributes.source, "source");
        dumpField(attributes.sourceURL, "sourceURL");
        dumpField(attributes.sourceApplication, "sourceApplication");
        dumpField(attributes.shareDate, "shareDate");
        dumpField(attributes.reminderOrder, "reminderOrder");
        dumpField(attributes.reminderDoneTime, "reminderDoneTime");
        dumpField(attributes.reminderTime, "reminderTime");
        dumpField(attributes.placeName, "placeName");
        dumpField(attributes.contentClass, "contentClass");
        dumpField(attributes.lastEditedBy, "lastEditedBy");
        dumpField(attributes.creatorId, "creatorId");
        dumpField(attributes.lastEditorId, "lastEditorId");
    }

    if (note.resources.isSet()) {
        QList<Resource> resources = note.resources;
        QLOG_DEBUG() << resources.size() << " resources found";
        for (int i=0; i<resources.size(); i++) {
            QLOG_DEBUG() << "resource #" << i;
            dumpResource(resources[i]);
        }
    }
    QLOG_DEBUG() << "*** Note Dump complete ***";
}


//************************************
// Dump a resource to the debug log
//************************************
void DebugTool::dumpResource(Resource r) {
    QLOG_DEBUG() << "*** Dumping Resource ***";
    dumpField(r.guid, "guid");
    dumpField(r.noteGuid, "noteGuid");
    dumpField(r.mime, "mime");
    dumpField(r.width, "width");
    dumpField(r.height, "height");
    dumpField(r.duration, "duration");
    dumpField(r.active, "active");
    dumpField(r.updateSequenceNum, "USN");
    if (r.data.isSet()) {
        QLOG_DEBUG() << "resource data found:";
        dumpData(r.data);
    } else
        QLOG_DEBUG() << "resource data not found.";
    if (r.recognition.isSet()) {
        QLOG_DEBUG() << "resource recognition data found:";
        dumpData(r.data);
    } else
        QLOG_DEBUG() << "resource recognition data not found.";
    if (r.alternateData.isSet()) {
        QLOG_DEBUG() << "resource alternate data found:";
        dumpData(r.alternateData);
    } else
        QLOG_DEBUG() << "resource alternate data not found.";
    QLOG_DEBUG() << "*** Resource Dump Complete ***";
}




//******************************************
// Dump a generic data segment to the log
//******************************************
void DebugTool::dumpData(Data d) {
    QLOG_DEBUG() << "*** Dumping Data Field ***";
    dumpField(d.bodyHash, "bodyHash", true);
    dumpField(d.size, "size");
    QLOG_DEBUG() << "*** Data Field Dump Complete ***";
}




//************************************
// Dump a notebook to the log
//************************************
void DebugTool::dumpNotebook(Notebook n) {
    QLOG_DEBUG() << "*** Dumping Notebook ***";
    dumpField(n.guid, "guid");
    dumpField(n.name, "name");
    dumpField(n.updateSequenceNum, "USN");
    dumpField(n.defaultNotebook, "defaultNotebook");
    dumpField(n.serviceCreated, "serviceCreated");
    dumpField(n.serviceUpdated, "serviceUpdate");
    dumpField(n.stack, "stack");
    dumpField(n.published, "published");
    if (n.publishing.isSet()) {
        QLOG_DEBUG() << "publishing data:";
        Publishing p = n.publishing;
        dumpField(p.uri, "uri");
        QLOG_DEBUG() << "order:" << p.order << ":";
        dumpField(p.publicDescription, "publicDescription");
    } else
        QLOG_DEBUG() << "publishing data not found";
    if (n.businessNotebook.isSet()) {
        QLOG_DEBUG() << "businessnotebook data:";
        BusinessNotebook b = n.businessNotebook;
        dumpField(b.notebookDescription, "notebookDescription");
        dumpField(b.recommended, "recommended");
        int i = b.privilege;
        QLOG_DEBUG() << "privilege:" << i;
    } else {
        QLOG_DEBUG() << "businessnotebooek data not found.";
    }
    QLOG_DEBUG() << "*** Notebook Dump Complete ***";
}




//*******************************************************
//* The remainder of these methods are generic
//* functions called by the functions above.  They
//* all work pretty much the same.  They just accept a
//* value and, if it is set, dump the contents to the
//* debug log.
//*******************************************************

void DebugTool::dumpField(Optional<QString> field, QString name) {
    if (field.isSet())
        QLOG_DEBUG() << name << ":" << field << ":";
    else
        QLOG_DEBUG() << name << " is not set.";
}






void DebugTool::dumpField(Optional<bool> field, QString name) {
    if (field.isSet())
        QLOG_DEBUG() << name << ":" << field << ":";
    else
        QLOG_DEBUG() << name << " is not set.";
}



void DebugTool::dumpField(Optional<double> field, QString name) {
    if (field.isSet())
        QLOG_DEBUG() << name << ":" << field << ":";
    else
        QLOG_DEBUG() << name << " is not set.";
}



void DebugTool::dumpField(Optional<qint32> field, QString name) {
    if (field.isSet())
        QLOG_DEBUG() << name << ":" << field << ":";
    else
        QLOG_DEBUG() << name << " is not set.";
}




void DebugTool::dumpField(Optional<long long> field, QString name) {
    if (field.isSet())
        QLOG_DEBUG() << name << ":" << field << ":";
    else
        QLOG_DEBUG() << name << " is not set.";
}





void DebugTool::dumpField(Optional<short int> field, QString name) {
    if (field.isSet())
        QLOG_DEBUG() << name << ":" << field << ":";
    else
        QLOG_DEBUG() << name << " is not set.";
}




void DebugTool::dumpField(Optional<QByteArray> field, QString name, bool hexValue) {
    if (field.isSet()) {
        if (hexValue) {
            QByteArray hex = field;
            QLOG_DEBUG() << name << ":" << hex.toHex() << ":";
        } else
            QLOG_DEBUG() << name << ":" << field << ":";
    } else {
        QLOG_DEBUG() << name << " is not set.";
    }
}




void DebugTool::dumpField(Optional<QStringList>  field, QString name) {
    if (!field.isSet()) {
        QLOG_DEBUG() << name << " is not set.";
        return;
    }
    QStringList fields = field;
    QLOG_DEBUG() << name << " has " << fields.size() << " entries.";
    for (int i=0; i<fields.size(); i++) {
        QLOG_DEBUG() << "#" << i << ":" << fields[i];
    }
}



void DebugTool::dumpField(Optional< QList<QString> >  field, QString name) {
    if (!field.isSet()) {
        QLOG_DEBUG() << name << " is not set.";
        return;
    }
    QList<QString> fields = field;
    QLOG_DEBUG() << name << " has " << fields.size() << " entries.";
    for (int i=0; i<fields.size(); i++) {
        QLOG_DEBUG() << "#" << i << ":" << fields[i];
    }
}