Skip to content

Commit

Permalink
Make namespace std clearer
Browse files Browse the repository at this point in the history
  • Loading branch information
teusbenschop committed Apr 13, 2024
1 parent e64a6b3 commit 07091ee
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 44 deletions.
15 changes: 7 additions & 8 deletions assets/external.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,27 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#include <assets/external.h>
#include <config/globals.h>
#include <webserver/request.h>
using namespace std;


string assets_external_url ()
std::string assets_external_url ()
{
return "assets/external";
}


string assets_external (Webserver_Request& webserver_request)
std::string assets_external (Webserver_Request& webserver_request)
{
// Whether a URL was POSTed, that is, whether it was clicked by the user.
string href = webserver_request.post ["href"];
std::string href = webserver_request.post ["href"];
if (!href.empty ()) {
config_globals_external_url = webserver_request.post ["href"];
return string();
return std::string();
}

// Wait for some time till a URL is available.
int timer {100};
while (timer) {
this_thread::sleep_for (chrono::milliseconds (100));
std::this_thread::sleep_for (std::chrono::milliseconds (100));
timer--;
if (!config_globals_external_url.empty ()) {
href = config_globals_external_url;
Expand All @@ -55,15 +54,15 @@ string assets_external (Webserver_Request& webserver_request)
}


string assets_external_logic_link_addon ()
std::string assets_external_logic_link_addon ()
{
// Open an external link in an external browser on most clients.
// Open an external link in a new tab in some situations.
bool newtab {false};
#ifdef HAVE_CLOUD
newtab = true;
#endif
string addon {};
std::string addon {};
if (newtab) addon = R"(target="_blank")";
else addon = R"(class="external")";
// Done.
Expand Down
63 changes: 31 additions & 32 deletions assets/header.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#include <database/config/general.h>
#include <database/config/bible.h>
#include <database/cache.h>
using namespace std;


Assets_Header::Assets_Header (string title, Webserver_Request& webserver_request) :
Assets_Header::Assets_Header (const std::string& title, Webserver_Request& webserver_request) :
m_webserver_request (webserver_request)
{
m_view = new Assets_View ();
Expand Down Expand Up @@ -76,18 +75,18 @@ void Assets_Header::set_navigator ()
// Display the user's basic stylesheet.css.
void Assets_Header::set_stylesheet ()
{
const string bible = m_webserver_request.database_config_user()->getBible ();
const string stylesheet = Database_Config_Bible::getEditorStylesheet (bible);
m_included_stylesheet = stylesheet;
const std::string bible = m_webserver_request.database_config_user()->getBible ();
const std::string stylesheet = Database_Config_Bible::getEditorStylesheet (bible);
m_included_stylesheet = std::move(stylesheet);
}


// Display the user's editor stylesheet.css.
void Assets_Header::set_editor_stylesheet ()
{
const string bible = m_webserver_request.database_config_user()->getBible ();
const string stylesheet = Database_Config_Bible::getEditorStylesheet (bible);
m_included_editor_stylesheet = stylesheet;
const std::string bible = m_webserver_request.database_config_user()->getBible ();
const std::string stylesheet = Database_Config_Bible::getEditorStylesheet (bible);
m_included_editor_stylesheet = std::move(stylesheet);
}


Expand All @@ -104,34 +103,34 @@ bool Assets_Header::display_topbar ()


// Sets the page to refresh after "seconds".
void Assets_Header::refresh (int seconds, string url)
void Assets_Header::refresh (int seconds, const std::string& url)
{
string content = filter::strings::convert_to_string (seconds);
std::string content = filter::strings::convert_to_string (seconds);
if (!url.empty ()) content.append (";URL=" + url);
stringstream ss;
ss << "<META HTTP-EQUIV=" << quoted("refresh") << " CONTENT=" << quoted(content) << ">";
std::stringstream ss{};
ss << "<META HTTP-EQUIV=" << std::quoted("refresh") << " CONTENT=" << std::quoted(content) << ">";
m_head_lines.push_back (ss.str());
}


// Adds a menu item to the fading menu.
void Assets_Header::set_fading_menu (string html)
void Assets_Header::set_fading_menu (const std::string& html)
{
m_fading_menu = html;
}


// Add one breadcrumb $item with $text.
void Assets_Header::add_bread_crumb (string item, string text)
void Assets_Header::add_bread_crumb (const std::string& item, const std::string& text)
{
m_bread_crumbs.push_back (pair (item, text));
m_bread_crumbs.push_back (std::pair (item, text));
}


// Runs the header.
string Assets_Header::run ()
std::string Assets_Header::run ()
{
string page;
std::string page {};

// Include the software version number in the stylesheet and javascript URL
// to refresh the browser's cache after a software upgrade.
Expand All @@ -157,8 +156,8 @@ string Assets_Header::run ()
m_view->enable_zone ("include_notif_it");
}

string headlines;
for (auto & headline : m_head_lines) {
std::string headlines {};
for (const auto& headline : m_head_lines) {
if (!headlines.empty ()) headlines.append ("\n");
headlines.append (headline);
}
Expand All @@ -173,8 +172,8 @@ string Assets_Header::run ()
m_view->set_variable ("included_editor_stylesheet", m_included_editor_stylesheet);
}

bool basic_mode = config::logic::basic_mode (m_webserver_request);
string basicadvanced;
const bool basic_mode = config::logic::basic_mode (m_webserver_request);
std::string basicadvanced {};
if (basic_mode) basicadvanced = "basic";
else basicadvanced = "advanced";
m_view->set_variable ("basicadvanced", basicadvanced);
Expand All @@ -193,8 +192,8 @@ string Assets_Header::run ()
// Whether tabbed mode is on.
bool tabbed_mode_on = menu_logic_can_do_tabbed_mode () && Database_Config_General::getMenuInTabbedViewOn ();

string menublock;
string item = m_webserver_request.query ["item"];
std::string menublock {};
const std::string item = m_webserver_request.query ["item"];
bool main_menu_always_on = false;
if (item.empty ())
if (m_webserver_request.database_config_user ()->getMainMenuAlwaysVisible ()) {
Expand All @@ -209,7 +208,7 @@ string Assets_Header::run ()
menublock = menu_logic_basic_categories (m_webserver_request);
}
} else {
string devnull;
std::string devnull {};
menublock = menu_logic_main_categories (m_webserver_request, devnull);
}
start_button = false;
Expand All @@ -234,15 +233,15 @@ string Assets_Header::run ()

if (start_button) {
m_view->enable_zone ("start_button");
string tooltip;
std::string tooltip;
menu_logic_main_categories (m_webserver_request, tooltip);
m_view->set_variable ("starttooltip", tooltip);
}

if (!m_fading_menu.empty ()) {
m_view->enable_zone ("fading_menu");
m_view->set_variable ("fadingmenu", m_fading_menu);
string delay = filter::strings::convert_to_string (m_webserver_request.database_config_user ()->getWorkspaceMenuFadeoutDelay ()) + "000";
std::string delay = filter::strings::convert_to_string (m_webserver_request.database_config_user ()->getWorkspaceMenuFadeoutDelay ()) + "000";
m_view->set_variable ("fadingmenudelay", delay);
m_fading_menu.clear ();
}
Expand All @@ -251,18 +250,18 @@ string Assets_Header::run ()
m_view->enable_zone ("display_navigator");
// string bible = access_bible::clamp (request, m_webserver_request.database_config_user()->getBible ());
// The clamping above does not work for public feedback as it would reset the Bible always.
string bible = m_webserver_request.database_config_user()->getBible ();
const std::string bible = m_webserver_request.database_config_user()->getBible ();
m_view->set_variable ("navigation_code", Navigation_Passage::code (bible));
}
}

vector <string> embedded_css;
std::vector <std::string> embedded_css {};
int fontsize = m_webserver_request.database_config_user ()->getGeneralFontSize ();
if (fontsize != 100) {
embedded_css.push_back ("body { font-size: " + filter::strings::convert_to_string (fontsize) + "%; }");
}
fontsize = m_webserver_request.database_config_user ()->getMenuFontSize ();
string filename = menu_font_size_filebased_cache_filename (m_webserver_request.session_identifier);
std::string filename = menu_font_size_filebased_cache_filename (m_webserver_request.session_identifier);
if (fontsize != 100) {
embedded_css.push_back (".menu-advanced, .menu-basic { font-size: " + filter::strings::convert_to_string (fontsize) + "%; }");
}
Expand Down Expand Up @@ -302,10 +301,10 @@ string Assets_Header::run ()
// No bread crumbs in basic mode.
// The crumbs would be incorrect anyway, because they show the trail of advanced mode.
if (!config::logic::basic_mode (m_webserver_request)) {
stringstream track;
track << "<a href=" << quoted(index_index_url ()) << ">";
std::stringstream track {};
track << "<a href=" << std::quoted(index_index_url ()) << ">";
track << menu_logic_menu_text ("") << "</a>";
for (auto & crumb : m_bread_crumbs) {
for (const auto& crumb : m_bread_crumbs) {
track << " » ";
if (!crumb.first.empty ()) {
track << "<a href=" << quoted("/" + menu_logic_menu_url (crumb.first)) << ">";
Expand Down
8 changes: 4 additions & 4 deletions assets/header.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Webserver_Request;
class Assets_Header
{
public:
Assets_Header (std::string title, Webserver_Request& webserver_request_in);
Assets_Header (const std::string& title, Webserver_Request& webserver_request_in);
~Assets_Header ();
Assets_Header(const Assets_Header&) = delete;
Assets_Header operator=(const Assets_Header&) = delete;
Expand All @@ -38,9 +38,9 @@ class Assets_Header
void set_stylesheet ();
void set_editor_stylesheet ();
bool display_topbar ();
void refresh (int seconds, std::string url = "");
void set_fading_menu (std::string html);
void add_bread_crumb (std::string item, std::string text);
void refresh (int seconds, const std::string& url = "");
void set_fading_menu (const std::string& html);
void add_bread_crumb (const std::string& item, const std::string& text);
std::string run ();
private:
Assets_View * m_view {nullptr};
Expand Down

0 comments on commit 07091ee

Please sign in to comment.