Fawkes API
Fawkes Development Version
|
00001 00002 /*************************************************************************** 00003 * header_generator.cpp - Generator of page header 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 "header_generator.h" 00024 00025 #include <utils/system/hostinfo.h> 00026 #include <webview/nav_manager.h> 00027 00028 #include <cstdio> 00029 #include <cstdlib> 00030 00031 using namespace fawkes; 00032 00033 /** @class WebviewHeaderGenerator "header_generator.h" 00034 * Webview page header. 00035 * Custom page header that shows the logo and a navigation bar. 00036 * @author Tim Niemueller 00037 */ 00038 00039 /** Page header template. */ 00040 const char * WebviewHeaderGenerator::PAGE_HEADER = 00041 "<html>\n" 00042 " <head>\n" 00043 " <meta http-equiv=\"Content-type\" content=\"text/html; charset=utf-8\" />\n" 00044 " <meta http-equiv=\"Content-Language\" content=\"en-us\" />\n" 00045 " <title>%s (%s)</title>\n" 00046 " <link rel=\"icon\" type=\"image/png\" href=\"/static/images/favicon.png\" />\n" 00047 " <link rel=\"stylesheet\" type=\"text/css\" href=\"/static/css/webview.css\" />\n" 00048 "%s" 00049 " </head>\n" 00050 " <body>\n" 00051 " <div id=\"header\">" 00052 "<a id=\"logo\" href=\"/\"/><img src=\"/static/webview.png\" alt=\"Fawkes WebView\"/></a>" 00053 "<hr /></div>\n"; 00054 00055 /** Constructor. 00056 * @param nav_manager navigation manager to use to generate the navigation 00057 */ 00058 WebviewHeaderGenerator::WebviewHeaderGenerator(WebNavManager *nav_manager) 00059 { 00060 __nav_manager = nav_manager; 00061 } 00062 00063 std::string 00064 WebviewHeaderGenerator::html_header(std::string &title, 00065 std::string &active_baseurl, 00066 std::string &html_header) 00067 { 00068 fawkes::HostInfo hi; 00069 00070 std::string rv = ""; 00071 char *s; 00072 if ( asprintf(&s, PAGE_HEADER, title.c_str(), hi.short_name(), 00073 html_header.c_str()) != -1 ) 00074 { 00075 rv = s; 00076 free(s); 00077 } 00078 00079 rv += " <div id=\"mainnav\" class=\"nav\"><ul>"; 00080 WebNavManager::NavMap::const_iterator nei; 00081 const WebNavManager::NavMap &nav_entries(__nav_manager->get_nav_entries()); 00082 for (nei = nav_entries.begin(); nei != nav_entries.end(); ++nei) { 00083 rv += "<li"; 00084 if ( nei->first == active_baseurl ) { 00085 rv += " class=\"active\""; 00086 } 00087 rv += "><a href=\"" + nei->first + "\">" + nei->second + "</a></li>"; 00088 } 00089 rv += "</ul></div>"; 00090 00091 return rv; 00092 }