Sayonara Player
LyricServer.h
1 /* LyricServer.h */
2 
3 /* Copyright (C) 2012 Lucio Carreras
4  *
5  * This file is part of sayonara player
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11 
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16 
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 
22 #ifndef LYRICSERVER_H_
23 #define LYRICSERVER_H_
24 
25 #include <QString>
26 #include <QMap>
27 #include "Helper/Logger/Logger.h"
28 
34 
35  QString display_str;
36  QString server_address;
37  QMap<QString, QString> replacements;
38  QString call_policy;
39  QMap<QString, QString> start_end_tag;
40  bool include_start_tag;
41  bool include_end_tag;
42  bool is_numeric;
43  bool to_lower;
44  QString error;
45 
46  void addReplacement(QString rep, QString rep_with){
47  replacements[rep] = rep_with;
48  }
49 
50 #define STR_TRUE QString("true")
51 #define STR_FALSE QString("false")
52 
53  void print_xml() const
54  {
55 
56  sp_log(Log::Info) << "<ServerTemplate>";
57  sp_log(Log::Info) << " <name>\"" << display_str << "\"</name>";
58  sp_log(Log::Info) << " <server_address>\"" << server_address << "\"</server_address>";
59  sp_log(Log::Info) << " <call_policy>\"" << call_policy << "\"</call_policy>";
60  /*sp_log(Log::Info) << " <start_tag>\"" << start_tag << "\"</start_tag>";
61  sp_log(Log::Info) << " <end_tag>\"" << end_tag << "\"</end_tag>";*/
62  sp_log(Log::Info) << " <include_start_tag>" << (include_start_tag ? STR_TRUE : STR_FALSE) << "</include_start_tag>";
63  sp_log(Log::Info) << " <include_end_tag>" << (include_end_tag ? STR_TRUE : STR_FALSE) << "</include_end_tag>";
64  sp_log(Log::Info) << " <is_numeric>" << (is_numeric ? STR_TRUE : STR_FALSE) << "</is_numeric>";
65  sp_log(Log::Info) << " <to_lower>" << (to_lower ? STR_TRUE : STR_FALSE) << "</to_lower>";
66  sp_log(Log::Info) << " <error>\"" << error << "\"</error>";
67 
68  for(QString key : replacements.keys()){
69  sp_log(Log::Info) << " <replacement>";
70  sp_log(Log::Info) << " <from>\"" << key << "\"</from>";
71  sp_log(Log::Info) << " <to>\"" << replacements[key] << "\"</to>";
72  sp_log(Log::Info) << " </replacement>";
73  }
74 
75  sp_log(Log::Info) << "</ServerTemplate>";
76  }
77 
78  void print_json() const
79  {
80  sp_log(Log::Info) << " {";
81  sp_log(Log::Info) << " \"ServerName\": \"" + display_str + "\",";
82  sp_log(Log::Info) << " \"ServerAddress\": \"" + server_address + "\",";
83  sp_log(Log::Info) << " \"CallPolicy\": \"" + call_policy + "\",";
84  sp_log(Log::Info) << " \"IncludeStartTag\": " + QString::number(include_start_tag) + ",";
85  sp_log(Log::Info) << " \"IncludeEndTag\": " + QString::number(include_end_tag) + ",";
86  sp_log(Log::Info) << " \"IsNumeric\": " + QString::number(is_numeric) + ",";
87  sp_log(Log::Info) << " \"ToLower\": " + QString::number(to_lower) + ",";
88  sp_log(Log::Info) << " \"Error\": \"" + error + "\",";
89 
90  sp_log(Log::Info) << " \"Replacements\": [";
91 
92  for(const QString& str : replacements.keys()){
93  sp_log(Log::Info) << " {";
94  sp_log(Log::Info) << " \"OrgString\": \"" + str + "\",";
95  sp_log(Log::Info) << " \"RepString\": \"" + replacements[str] + "\"";
96  sp_log(Log::Info) << " },";
97  }
98 
99  sp_log(Log::Info) << " ]";
100 
101  sp_log(Log::Info) << " \"BorderTags\": [";
102  for(const QString& str : start_end_tag.keys()){
103  QString key = str;
104  key.replace("\"", "\\\"");
105  QString value = start_end_tag[str];
106  value.replace("\"", "\\\"");
107 
108  sp_log(Log::Info) << " {";
109  sp_log(Log::Info) << " \"StartTag\": \"" + key + "\",";
110  sp_log(Log::Info) << " \"EndTag\": \"" + value + "\"";
111  sp_log(Log::Info) << " },";
112  }
113 
114  sp_log(Log::Info) << " ]";
115  sp_log(Log::Info) << " }";
116  }
117 
118 };
119 
120 #endif /* LYRICSERVER_H_ */
The ServerTemplate struct.
Definition: LyricServer.h:33