/*************************************************************************** File: template.cpp Project: Kio-Sword -- An ioslave for SWORD and KDE Copyright: Copyright (C) 2005 Luke Plant ***************************************************************************/ /*************************************************************************** * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "template.h" #include "utils.h" #include "swordoptions.h" #include #include #include #include namespace KioSword { // placeholders static const char* PAGETITLE = "{$pagetitle}"; static const char* BASECSS = "{$basecss}"; static const char* CONTENT = "{$content}"; static const char* HOMELINK = "{$homelink}"; static const char* HOMELINKCAPTION = "{$homelinkcaption}"; static const char* SEARCHLINK = "{$searchlink}"; static const char* SEARCHLINKCAPTION = "{$searchlinkcaption}"; static const char* SETTINGSLINK = "{$settingslink}"; static const char* SETTINGSLINKCAPTION = "{$settingslinkcaption}"; static const char* HELPLINK = "{$helplink}"; static const char* HELPLINKCAPTION = "{$helplinkcaption}"; static const char* TOPNAV = "{$topnav}"; static const char* BOTTOMNAV = "{$bottomnav}"; static const char* TOGGLES = "{$toggles}"; // static HTML fragments ------------------------------------------------------------------------------------------------------- static const TQString &html_page(TQString("") + "\n" "\n" "\n" "" + PAGETITLE + "\n" "\n" "\n" "" "
" " " + TOPNAV + "\n" "
" + CONTENT + "
\n" " " + TOGGLES + "\n" " " + BOTTOMNAV + "\n" " \n" "
\n" "\n" "\n"); Template::Template() { m_showToggles = false; } TQCString Template::render(const SwordOptions& options) const { TQString cssdir = KGlobal::dirs()->findResourceDir("data", "kio_sword/kio_sword.css") + "kio_sword/"; TQString output = html_page; output = output .replace(HOMELINK, swordUrl("", options)) .replace(HOMELINKCAPTION, i18n("Module list")) .replace(SEARCHLINK, swordUrlForPage("search", options)) .replace(SEARCHLINKCAPTION, i18n("Search")) .replace(SETTINGSLINK, swordUrlForSettings(m_currentPath, options)) .replace(SETTINGSLINKCAPTION, i18n("Settings")) .replace(HELPLINK, swordUrlForPage("help", options)) .replace(HELPLINKCAPTION, i18n("Help")) .replace(BASECSS, cssdir + "kio_sword.css") .replace(PAGETITLE, m_title) .replace(CONTENT, m_content); if (!m_nav.isEmpty()) { output = output .replace(TOPNAV, "") .replace(BOTTOMNAV, ""); } else { output = output .replace(TOPNAV, "") .replace(BOTTOMNAV, ""); } if (m_showToggles) { TQString toggles; SwordOptions toggledOptions(options); toggledOptions.verseNumbers.set(!toggledOptions.verseNumbers()); toggles += "
  • " + i18n("Verse Numbers") + "
  • "; toggledOptions.verseNumbers.set(!toggledOptions.verseNumbers()); toggledOptions.verseLineBreaks.set(!toggledOptions.verseLineBreaks()); toggles += "
  • " + i18n("Verse Line Breaks") + "
  • "; toggledOptions.verseLineBreaks.set(!toggledOptions.verseLineBreaks()); toggledOptions.strongs.set(!toggledOptions.strongs()); toggles += "
  • " + i18n("Strongs") + "
  • "; toggledOptions.strongs.set(!toggledOptions.strongs()); toggledOptions.morph.set(!toggledOptions.morph()); toggles += "
  • " + i18n("Morphological tags") + "
  • "; toggledOptions.morph.set(!toggledOptions.morph()); output = output.replace(TOGGLES, "
      " + toggles + "
    "); } else { output = output.replace(TOGGLES, ""); } return output.utf8(); } void Template::setTitle(const TQString& title) { m_title = title; } void Template::setContent(const TQString& content) { m_content = content; } void Template::setNav(const TQString& nav) { m_nav = nav; } void Template::setCurrentPath(const TQString& currentPath) { m_currentPath = currentPath; } void Template::setShowToggles(bool showToggles) { m_showToggles = showToggles; } }