Fawkes API  Fawkes Development Version
footer_generator.cpp
1 
2 /***************************************************************************
3  * footer_generator.cpp - Generator of page footer
4  *
5  * Created: Sun Aug 30 14:40:26 2009
6  * Copyright 2006-2009 Tim Niemueller [www.niemueller.de]
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Library General Public License for more details.
19  *
20  * Read the full text in the LICENSE.GPL file in the doc directory.
21  */
22 
23 #include "footer_generator.h"
24 
25 #include <core/version.h>
26 #include <utils/misc/string_conversions.h>
27 
28 /** @class WebviewFooterGenerator "footer_generator.h"
29  * Webview page footer.
30  * Custom page header that shows other webview instances found on the net
31  * via mDNS-SD.
32  * @author Tim Niemueller
33  */
34 
35 /** Constructor.
36  * @param service_browser service browser used to add links to other Webview
37  * instances.
38  */
40 {
41  __service_browser = service_browser;
42 }
43 
44 
45 std::string
47 {
48  std::string f = std::string("\n <div id=\"footer\">\n")
49  + " <hr />\n";
50 
51  f += " <div id=\"version\"><a href=\"http://www.fawkesrobotics.org\" "
52  "rel=\"external\">Fawkes ";
53  f += FAWKES_VERSION_STRING;
54  f += "</a></div>\n";
56  if (! sl.empty()) {
57  f += " <div class=\"instances\"><ul>";
58  WebviewServiceBrowseHandler::ServiceList &sl = __service_browser->service_list();
59  WebviewServiceBrowseHandler::ServiceList::iterator i;
60  for (i = sl.begin(); i != sl.end(); ++i) {
61  std::string short_host = i->second->host();
62  std::string::size_type s = short_host.find(".");
63  if (s != std::string::npos) short_host = short_host.substr(0, s);
64 
65  f += std::string("<li><a href=\"http://") + i->second->host() + ":"
66  + fawkes::StringConversions::to_string(i->second->port()) + "/\""
67  + " title=\"" + i->first + "\">"
68  + short_host + "</a></li>";
69  }
70  f += "</ul></div>\n";
71  }
72  f += " </div>";
73  f += "\n </body>\n";
74  f += "</html>\n";
75 
76  return f;
77 }
std::string html_footer()
Generate HTML footer.
WebviewFooterGenerator(WebviewServiceBrowseHandler *service_browser)
Constructor.
ServiceList & service_list()
Get the service list.
Browse handler to detect other Webview instances on the network.
std::map< std::string, fawkes::NetworkService * > ServiceList
A map of services.
static std::string to_string(unsigned int i)
Convert unsigned int value to a string.