Fawkes API  Fawkes Development Version
footer_generator.cpp
00001 
00002 /***************************************************************************
00003  *  footer_generator.cpp - Generator of page footer
00004  *
00005  *  Created: Sun Aug 30 14:40:26 2009
00006  *  Copyright  2006-2009  Tim Niemueller [www.niemueller.de]
00007  *
00008  ****************************************************************************/
00009 
00010 /*  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version.
00014  *
00015  *  This program is distributed in the hope that it will be useful,
00016  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  *  GNU Library General Public License for more details.
00019  *
00020  *  Read the full text in the LICENSE.GPL file in the doc directory.
00021  */
00022 
00023 #include "footer_generator.h"
00024 
00025 #include <utils/misc/string_conversions.h>
00026 
00027 /** @class WebviewFooterGenerator "footer_generator.h"
00028  * Webview page footer.
00029  * Custom page header that shows other webview instances found on the net
00030  * via mDNS-SD.
00031  * @author Tim Niemueller
00032  */
00033 
00034 /** Constructor.
00035  * @param service_browser service browser used to add links to other Webview
00036  * instances.
00037  */
00038 WebviewFooterGenerator::WebviewFooterGenerator(WebviewServiceBrowseHandler *service_browser)
00039 {
00040   __service_browser = service_browser;
00041 }
00042 
00043 
00044 std::string
00045 WebviewFooterGenerator::html_footer()
00046 {
00047   std::string f = std::string("\n  <div id=\"footer\">\n")
00048     + "    <hr />\n";
00049   WebviewServiceBrowseHandler::ServiceList sl = __service_browser->service_list();
00050   if (! sl.empty()) {
00051     f += "    <div class=\"instances\"><ul>";
00052     WebviewServiceBrowseHandler::ServiceList &sl = __service_browser->service_list();
00053     WebviewServiceBrowseHandler::ServiceList::iterator i;
00054     for (i = sl.begin(); i != sl.end(); ++i) {
00055       std::string short_host = i->second->host();
00056       std::string::size_type s = short_host.find(".");
00057       if (s != std::string::npos)  short_host = short_host.substr(0, s);
00058 
00059       f += std::string("<li><a href=\"http://") + i->second->host() + ":"
00060         + fawkes::StringConversions::to_string(i->second->port()) + "/\""
00061         + " title=\"" + i->first + "\">"
00062         + short_host + "</a></li>";
00063     }
00064     f += "</ul></div>\n";
00065   }
00066   f += "  </div>";
00067   f += "\n </body>\n";
00068   f += "</html>\n";
00069 
00070   return f;
00071 }