Skip to content

Commit

Permalink
Clearer types in code rather than void pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
teusbenschop committed Jan 5, 2024
1 parent 0c30f5b commit d78b3c3
Show file tree
Hide file tree
Showing 121 changed files with 162 additions and 164 deletions.
79 changes: 37 additions & 42 deletions assets/header.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
using namespace std;


Assets_Header::Assets_Header (string title, void * webserver_request)
Assets_Header::Assets_Header (string title, Webserver_Request& webserver_request) :
m_webserver_request (webserver_request)
{
m_webserver_request = webserver_request;
m_view = new Assets_View ();
m_view->set_variable ("title", title);
}
Expand Down Expand Up @@ -76,29 +76,26 @@ void Assets_Header::set_navigator ()
// Display the user's basic stylesheet.css.
void Assets_Header::set_stylesheet ()
{
Webserver_Request * request = static_cast<Webserver_Request *>(m_webserver_request);
string bible = request->database_config_user()->getBible ();
string stylesheet = Database_Config_Bible::getEditorStylesheet (bible);
const string bible = m_webserver_request.database_config_user()->getBible ();
const string stylesheet = Database_Config_Bible::getEditorStylesheet (bible);
m_included_stylesheet = stylesheet;
}


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


// Whether to display the topbar.
bool Assets_Header::display_topbar ()
{
Webserver_Request * request = static_cast<Webserver_Request *>(m_webserver_request);
// If the topbar is in the query: Don't display the top bar.
if (request->query.count ("topbar")) {
if (m_webserver_request.query.count ("topbar")) {
return false;
}
// Display the topbar.
Expand Down Expand Up @@ -134,8 +131,6 @@ void Assets_Header::add_bread_crumb (string item, string text)
// Runs the header.
string Assets_Header::run ()
{
Webserver_Request * request = static_cast<Webserver_Request *>(m_webserver_request);

string page;

// Include the software version number in the stylesheet and javascript URL
Expand All @@ -146,10 +141,10 @@ string Assets_Header::run ()
m_view->enable_zone ("include_jquery_touch");
}

if (request->session_logic ()->touchEnabled ()) {
if (m_webserver_request.session_logic ()->touchEnabled ()) {
touch_css_on();
}
if (!request->session_logic ()->loggedIn ()) {
if (!m_webserver_request.session_logic ()->loggedIn ()) {
touch_css_on();
}
if (m_touch_css_on) {
Expand Down Expand Up @@ -178,7 +173,7 @@ 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);
bool basic_mode = config::logic::basic_mode (std::addressof(m_webserver_request));
string basicadvanced;
if (basic_mode) basicadvanced = "basic";
else basicadvanced = "advanced";
Expand All @@ -199,10 +194,10 @@ string Assets_Header::run ()
bool tabbed_mode_on = menu_logic_can_do_tabbed_mode () && Database_Config_General::getMenuInTabbedViewOn ();

string menublock;
string item = request->query ["item"];
string item = m_webserver_request.query ["item"];
bool main_menu_always_on = false;
if (item.empty ())
if (request->database_config_user ()->getMainMenuAlwaysVisible ()) {
if (m_webserver_request.database_config_user ()->getMainMenuAlwaysVisible ()) {
main_menu_always_on = true;
// Add the main menu status as a Javascript variable.
m_view->set_variable ("mainmenualwayson", filter::strings::convert_to_string (main_menu_always_on));
Expand All @@ -211,25 +206,25 @@ string Assets_Header::run ()
if (basic_mode) {
// Basic mode gives basic menu, but nothing in tabbed mode.
if (!tabbed_mode_on) {
menublock = menu_logic_basic_categories (m_webserver_request);
menublock = menu_logic_basic_categories (std::addressof(m_webserver_request));
}
} else {
string devnull;
menublock = menu_logic_main_categories (m_webserver_request, devnull);
menublock = menu_logic_main_categories (std::addressof(m_webserver_request), devnull);
}
start_button = false;
} else if (item == menu_logic_translate_menu ()) {
menublock = menu_logic_translate_category (m_webserver_request);
menublock = menu_logic_translate_category (std::addressof(m_webserver_request));
} else if (item == menu_logic_search_menu ()) {
menublock = menu_logic_search_category (m_webserver_request);
menublock = menu_logic_search_category (std::addressof(m_webserver_request));
} else if (item == menu_logic_tools_menu ()) {
menublock = menu_logic_tools_category (m_webserver_request);
menublock = menu_logic_tools_category (std::addressof(m_webserver_request));
} else if (item == menu_logic_settings_menu ()) {
menublock = menu_logic_settings_category (m_webserver_request);
menublock = menu_logic_settings_category (std::addressof(m_webserver_request));
} else if (item == menu_logic_settings_resources_menu ()) {
menublock = menu_logic_settings_resources_category (m_webserver_request);
menublock = menu_logic_settings_resources_category (std::addressof(m_webserver_request));
} else if (item == "help") {
menublock = menu_logic_help_category (m_webserver_request);
menublock = menu_logic_help_category (std::addressof(m_webserver_request));
}
m_view->set_variable ("mainmenu", menublock);

Expand All @@ -240,73 +235,73 @@ string Assets_Header::run ()
if (start_button) {
m_view->enable_zone ("start_button");
string tooltip;
menu_logic_main_categories (m_webserver_request, tooltip);
menu_logic_main_categories (std::addressof(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 (request->database_config_user ()->getWorkspaceMenuFadeoutDelay ()) + "000";
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 ();
}

if (m_display_navigator) {
m_view->enable_zone ("display_navigator");
// string bible = access_bible::clamp (request, request->database_config_user()->getBible ());
// 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 = request->database_config_user()->getBible ();
string bible = m_webserver_request.database_config_user()->getBible ();
m_view->set_variable ("navigation_code", Navigation_Passage::code (bible));
}
}

vector <string> embedded_css;
int fontsize = request->database_config_user ()->getGeneralFontSize ();
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 = request->database_config_user ()->getMenuFontSize ();
string filename = menu_font_size_filebased_cache_filename (request->session_identifier);
fontsize = m_webserver_request.database_config_user ()->getMenuFontSize ();
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) + "%; }");
}
fontsize = request->database_config_user ()->getBibleEditorsFontSize ();
fontsize = m_webserver_request.database_config_user ()->getBibleEditorsFontSize ();
if (fontsize != 100) {
embedded_css.push_back (".bibleeditor { font-size: " + filter::strings::convert_to_string (fontsize) + "% !important; }");
}
fontsize = request->database_config_user ()->getResourcesFontSize ();
filename = resource_font_size_filebased_cache_filename (request->session_identifier);
fontsize = m_webserver_request.database_config_user ()->getResourcesFontSize ();
filename = resource_font_size_filebased_cache_filename (m_webserver_request.session_identifier);
if (fontsize != 100) {
embedded_css.push_back (".resource { font-size: " + filter::strings::convert_to_string (fontsize) + "% !important; }");
}
fontsize = request->database_config_user ()->getHebrewFontSize ();
fontsize = m_webserver_request.database_config_user ()->getHebrewFontSize ();
if (fontsize != 100) {
embedded_css.push_back (".hebrew { font-size: " + filter::strings::convert_to_string (fontsize) + "%!important; }");
}
fontsize = request->database_config_user ()->getGreekFontSize ();
filename = greek_font_size_filebased_cache_filename (request->session_identifier);
fontsize = m_webserver_request.database_config_user ()->getGreekFontSize ();
filename = greek_font_size_filebased_cache_filename (m_webserver_request.session_identifier);
if (fontsize != 100) {
embedded_css.push_back (".greek { font-size: " + filter::strings::convert_to_string (fontsize) + "%!important; }");
}
if (!embedded_css.empty ()) {
m_view->set_variable ("embedded_css", filter::strings::implode (embedded_css, "\n"));
}

int current_theme_index = request->database_config_user ()->getCurrentTheme ();
filename = current_theme_filebased_cache_filename (request->session_identifier);
int current_theme_index = m_webserver_request.database_config_user ()->getCurrentTheme ();
filename = current_theme_filebased_cache_filename (m_webserver_request.session_identifier);
// Add the theme color css class selector name on the body element,..
m_view->set_variable ("body_theme_color", Filter_Css::theme_picker (current_theme_index, 0));
// ..workspacewrapper div element..
m_view->set_variable ("workspace_theme_color", Filter_Css::theme_picker (current_theme_index, 4));
// ..and as a variable for JavaScript.
m_view->set_variable ("themecolorfortabs", Filter_Css::theme_picker (current_theme_index, 1));

if (request->database_config_user ()->getDisplayBreadcrumbs ()) {
if (m_webserver_request.database_config_user ()->getDisplayBreadcrumbs ()) {
if (!m_bread_crumbs.empty ()) {
// 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)) {
if (!config::logic::basic_mode (std::addressof(m_webserver_request))) {
stringstream track;
track << "<a href=" << quoted(index_index_url ()) << ">";
track << menu_logic_menu_text ("") << "</a>";
Expand Down
6 changes: 4 additions & 2 deletions assets/header.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#include <config/libraries.h>
#include <assets/view.h>

class Webserver_Request;

class Assets_Header
{
public:
Assets_Header (std::string title, void * webserver_request_in);
Assets_Header (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 @@ -49,7 +51,7 @@ class Assets_Header
bool m_display_navigator {false};
std::string m_included_stylesheet {};
std::string m_included_editor_stylesheet {};
void * m_webserver_request {nullptr};
Webserver_Request& m_webserver_request;
std::string m_fading_menu {};
std::vector <std::pair <std::string, std::string> > m_bread_crumbs {};
};
Expand Down
3 changes: 2 additions & 1 deletion assets/page.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ namespace assets_page {

string header (const string & title, void * webserver_request)
{
Assets_Header header = Assets_Header (title, webserver_request);
Webserver_Request * request = static_cast<Webserver_Request *>(webserver_request);
Assets_Header header = Assets_Header (title, *request);
string page = header.run ();
return page;
}
Expand Down
2 changes: 1 addition & 1 deletion bb/book.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ std::string bible_book (Webserver_Request& webserver_request)
{
std::string page {};

Assets_Header header = Assets_Header (translate("Book"), std::addressof(webserver_request));
Assets_Header header = Assets_Header (translate("Book"), webserver_request);
header.add_bread_crumb (menu_logic_settings_menu (), menu_logic_settings_text ());
header.add_bread_crumb (bible_manage_url (), menu_logic_bible_manage_text ());
page = header.run ();
Expand Down
2 changes: 1 addition & 1 deletion bb/css.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ std::string bible_css (Webserver_Request& webserver_request)
{
std::string page {};

Assets_Header header = Assets_Header (translate("Font and text direction"), std::addressof(webserver_request));
Assets_Header header = Assets_Header (translate("Font and text direction"), webserver_request);
header.add_bread_crumb (menu_logic_settings_menu (), menu_logic_settings_text ());
header.add_bread_crumb (bible_manage_url (), menu_logic_bible_manage_text ());
page = header.run ();
Expand Down
2 changes: 1 addition & 1 deletion bb/import.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ std::string bible_import (Webserver_Request& webserver_request)
{
std::string page {};

Assets_Header header = Assets_Header (translate("Import"), std::addressof(webserver_request));
Assets_Header header = Assets_Header (translate("Import"), webserver_request);
header.set_navigator ();
header.add_bread_crumb (menu_logic_settings_menu (), menu_logic_settings_text ());
header.add_bread_crumb (bible_manage_url (), menu_logic_bible_manage_text ());
Expand Down
2 changes: 1 addition & 1 deletion bb/manage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ std::string bible_manage (Webserver_Request& webserver_request)
{
std::string page {};

Assets_Header header = Assets_Header (translate("Bibles"), std::addressof(webserver_request));
Assets_Header header = Assets_Header (translate("Bibles"), webserver_request);
header.add_bread_crumb (menu_logic_settings_menu (), menu_logic_settings_text ());
page = header.run ();

Expand Down
2 changes: 1 addition & 1 deletion bb/order.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ std::string bible_order (Webserver_Request& webserver_request)
{
std::string page {};

Assets_Header header = Assets_Header (translate("Order"), std::addressof(webserver_request));
Assets_Header header = Assets_Header (translate("Order"), webserver_request);
header.add_bread_crumb (menu_logic_settings_menu (), menu_logic_settings_text ());
header.add_bread_crumb (bible_manage_url (), menu_logic_bible_manage_text ());
page = header.run ();
Expand Down
2 changes: 1 addition & 1 deletion bb/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ bool bible_settings_acl (Webserver_Request& webserver_request)
std::string bible_settings (Webserver_Request& webserver_request)
{
std::string page {};
Assets_Header header = Assets_Header (translate("Bible"), std::addressof(webserver_request));
Assets_Header header = Assets_Header (translate("Bible"), webserver_request);
header.add_bread_crumb (menu_logic_settings_menu (), menu_logic_settings_text ());
header.add_bread_crumb (bible_manage_url (), menu_logic_bible_manage_text ());
page = header.run ();
Expand Down
2 changes: 1 addition & 1 deletion changes/changes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ string changes_changes (Webserver_Request& webserver_request)


string page {};
Assets_Header header = Assets_Header (translate("Changes"), std::addressof(webserver_request));
Assets_Header header = Assets_Header (translate("Changes"), webserver_request);
header.set_stylesheet ();
header.add_bread_crumb (menu_logic_translate_menu (), menu_logic_translate_text ());
if (touch) header.jquery_touch_on ();
Expand Down
2 changes: 1 addition & 1 deletion changes/manage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ string changes_manage (Webserver_Request& webserver_request)


string page {};
Assets_Header header = Assets_Header (translate("Changes"), std::addressof(webserver_request));
Assets_Header header = Assets_Header (translate("Changes"), webserver_request);
header.add_bread_crumb (menu_logic_settings_menu (), menu_logic_settings_text ());
page = header.run ();
Assets_View view {};
Expand Down
2 changes: 1 addition & 1 deletion changes/statistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ string changes_statistics ([[maybe_unused]] Webserver_Request& webserver_request
#ifdef HAVE_CLOUD

string page {};
Assets_Header header = Assets_Header (translate("Change statistics"), std::addressof(webserver_request));
Assets_Header header = Assets_Header (translate("Change statistics"), webserver_request);
page += header.run ();
Assets_View view {};

Expand Down
2 changes: 1 addition & 1 deletion checks/index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ std::string checks_index (Webserver_Request& webserver_request)


std::string page {};
Assets_Header header = Assets_Header (translate("Checks"), std::addressof(webserver_request));
Assets_Header header = Assets_Header (translate("Checks"), webserver_request);
header.add_bread_crumb (menu_logic_tools_menu (), menu_logic_tools_text ());
page = header.run ();
Assets_View view {};
Expand Down
2 changes: 1 addition & 1 deletion checks/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ bool checks_settings_acl ([[maybe_unused]] Webserver_Request& webserver_request)
string checks_settings (Webserver_Request& webserver_request)
{
string page {};
Assets_Header header = Assets_Header (translate("Manage Checks"), std::addressof(webserver_request));
Assets_Header header = Assets_Header (translate("Manage Checks"), webserver_request);
header.add_bread_crumb (menu_logic_settings_menu (), menu_logic_settings_text ());
page = header.run ();
Assets_View view {};
Expand Down
2 changes: 1 addition & 1 deletion checks/settingspairs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ bool checks_settingspairs_acl ([[maybe_unused]] Webserver_Request& webserver_req
string checks_settingspairs (Webserver_Request& webserver_request)
{
string page {};
Assets_Header header = Assets_Header (translate ("Matching pairs"), std::addressof(webserver_request));
Assets_Header header = Assets_Header (translate ("Matching pairs"), webserver_request);
header.add_bread_crumb (menu_logic_settings_menu (), menu_logic_settings_text ());
header.add_bread_crumb (checks_settings_url (), menu_logic_checks_settings_text ());
page = header.run ();
Expand Down
2 changes: 1 addition & 1 deletion checks/settingspatterns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ bool checks_settingspatterns_acl ([[maybe_unused]] Webserver_Request& webserver_
string checks_settingspatterns (Webserver_Request& webserver_request)
{
string page {};
Assets_Header header = Assets_Header (translate ("Patterns"), std::addressof(webserver_request));
Assets_Header header = Assets_Header (translate ("Patterns"), webserver_request);
header.add_bread_crumb (menu_logic_settings_menu (), menu_logic_settings_text ());
header.add_bread_crumb (checks_settings_url (), menu_logic_checks_settings_text ());
page = header.run ();
Expand Down
2 changes: 1 addition & 1 deletion checks/settingssentences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ bool checks_settingssentences_acl ([[maybe_unused]] Webserver_Request& webserver
string checks_settingssentences (Webserver_Request& webserver_request)
{
string page {};
Assets_Header header = Assets_Header (translate ("Sentence Structure"), std::addressof(webserver_request));
Assets_Header header = Assets_Header (translate ("Sentence Structure"), webserver_request);
header.add_bread_crumb (menu_logic_settings_menu (), menu_logic_settings_text ());
header.add_bread_crumb (checks_settings_url (), menu_logic_checks_settings_text ());
page = header.run ();
Expand Down
2 changes: 1 addition & 1 deletion collaboration/index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ bool collaboration_index_acl (Webserver_Request& webserver_request)
std::string collaboration_index (Webserver_Request& webserver_request)
{
std::string page {};
Assets_Header header = Assets_Header (translate("Repository"), std::addressof(webserver_request));
Assets_Header header = Assets_Header (translate("Repository"), webserver_request);
header.add_bread_crumb (menu_logic_settings_menu (), menu_logic_settings_text ());
page = header.run ();
Assets_View view;
Expand Down
2 changes: 1 addition & 1 deletion collaboration/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ bool collaboration_settings_acl (Webserver_Request& webserver_request)
string collaboration_settings (Webserver_Request& webserver_request)
{
string page;
Assets_Header header = Assets_Header (translate("Collaboration"), std::addressof(webserver_request));
Assets_Header header = Assets_Header (translate("Collaboration"), webserver_request);
page = header.run ();
Assets_View view;

Expand Down
Loading

0 comments on commit d78b3c3

Please sign in to comment.