dmflagshtmlgenerator.cpp
1 //------------------------------------------------------------------------------
2 // dmflagshtmlgenerator.cpp
3 //------------------------------------------------------------------------------
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 // 02110-1301 USA
19 //
20 //------------------------------------------------------------------------------
21 // Copyright (C) 2010 "Zalewa" <zalewapl@gmail.com>
22 //------------------------------------------------------------------------------
23 #include "dmflagshtmlgenerator.h"
24 
25 #include "serverapi/server.h"
27 
28 DClass<DmflagsHtmlGenerator>
29 {
30 public:
31  ServerCPtr server;
32 
33  QString mkSectionContents(const DMFlagsSection &section)
34  {
35  QString result;
36  for (int i = 0; i < section.count(); ++i)
37  {
38  result += "<li>" + section[i].name() + "</li>";
39  }
40  return result;
41  }
42 };
43 
44 DPointered(DmflagsHtmlGenerator)
45 
46 DmflagsHtmlGenerator::DmflagsHtmlGenerator(const ServerCPtr &server)
47 {
48  d->server = server;
49 }
50 
51 DmflagsHtmlGenerator::~DmflagsHtmlGenerator()
52 {
53 }
54 
55 QString DmflagsHtmlGenerator::generate()
56 {
57  QString result;
58  const QList<DMFlagsSection> sections = d->server->dmFlags();
59  for (const DMFlagsSection &section : sections)
60  {
61  if (!section.isEmpty())
62  {
63  // Hack (#3944): the dmflag bits are stored in Doomseeker in the
64  // 32-bit unsigned format, but ZDoom-based ports use signed. If port
65  // uses the most significant bit for a dmflag the combined values
66  // will go into negative numbers.
67  const int32_t numerical = static_cast<int32_t>(section.combineValues());
68 
69  result += QString("<li><b>%1 (%2):</b></li>").arg(section.name()).arg(numerical);
70  result += "<ul>";
71  result += d->mkSectionContents(section);
72  result += "</ul>";
73  }
74  }
75  if (!result.isEmpty())
76  {
77  result = "<ul>" + result + "</ul>";
78  }
79  return result;
80 }