forked from adiesner/GarminPlugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
messageBox.cpp
112 lines (94 loc) · 3.56 KB
/
messageBox.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
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
* GarminPlugin
* Copyright (C) Andreas Diesner 2010 <andreas.diesner [AT] gmx [DOT] de>
*
* GarminPlugin 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 3 of the License, or
* (at your option) any later version.
*
* GarminPlugin 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, see <http://www.gnu.org/licenses/>.
*/
#include "messageBox.h"
#define TIXML_USE_TICPP
#include "ticpp.h"
#include "log.h"
using namespace std;
MessageBox::MessageBox(MessageType type, string text, int buttons, int defaultBtn, GpsDevice *device)
{
this->device = device;
this->text = text;
this->buttons = buttons;
this->defaultButton = defaultBtn;
this->type = type;
}
string MessageBox::getXml() {
/*
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<MessageBox xmlns="http://www.garmin.com/xmlschemas/PluginAPI/v1" DefaultButtonValue="2">
<Icon>Question</Icon>
<Text>The file F:/Garmin/gpx/GC22K31.gpx already exists on your GPS Device. OK to overwrite the file?</Text>
<Button Caption="OK" Value="1"/>
<Button Caption="Cancel" Value="2"/>
</MessageBox>
*/
TiXmlDocument doc;
TiXmlDeclaration * decl = new TiXmlDeclaration( "1.0", "UTF-8", "no" );
doc.LinkEndChild( decl );
TiXmlElement * msgBox = new TiXmlElement( "MessageBox" );
msgBox->SetAttribute("xmlns", "http://www.garmin.com/xmlschemas/PluginAPI/v1");
msgBox->SetAttribute("DefaultButtonValue", this->defaultButton);
doc.LinkEndChild( msgBox );
TiXmlElement * icon = new TiXmlElement( "Icon" );
if (this->type == Question) {
icon->LinkEndChild(new TiXmlText("Question"));
} else {
Log::err("MessageBox::getXml Message type not yet implemented!");
icon->LinkEndChild(new TiXmlText("Unknown"));
}
msgBox->LinkEndChild( icon );
TiXmlElement * textelem = new TiXmlElement( "Text" );
textelem->LinkEndChild(new TiXmlText(this->text));
msgBox->LinkEndChild( textelem );
if ((this->buttons & BUTTON_OK) > 0) {
TiXmlElement * btn = new TiXmlElement( "Button" );
btn->SetAttribute("Caption", "OK");
btn->SetAttribute("Value", BUTTON_OK);
msgBox->LinkEndChild( btn );
}
if ((this->buttons & BUTTON_CANCEL) > 0) {
TiXmlElement * btn = new TiXmlElement( "Button" );
btn->SetAttribute("Caption", "Cancel");
btn->SetAttribute("Value", BUTTON_CANCEL);
msgBox->LinkEndChild( btn );
}
if ((this->buttons & BUTTON_YES) > 0) {
TiXmlElement * btn = new TiXmlElement( "Button" );
btn->SetAttribute("Caption", "Yes");
btn->SetAttribute("Value", BUTTON_YES);
msgBox->LinkEndChild( btn );
}
if ((this->buttons & BUTTON_NO) > 0) {
TiXmlElement * btn = new TiXmlElement( "Button" );
btn->SetAttribute("Caption", "No");
btn->SetAttribute("Value", BUTTON_NO);
msgBox->LinkEndChild( btn );
}
TiXmlPrinter printer;
//printer.SetIndent( "\t" );
doc.Accept( &printer );
string str = printer.Str();
return str;
}
void MessageBox::responseReceived(const int result) {
if (this->device != NULL) {
device->userAnswered(result);
}
}