Skip to content

Commit

Permalink
Merge contents of two prefs files
Browse files Browse the repository at this point in the history
This moves these functions' implementations with others in the same header
  • Loading branch information
Vultraz committed Mar 3, 2016
1 parent 5267d83 commit d66e33c
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 133 deletions.
1 change: 0 additions & 1 deletion src/CMakeLists.txt
Expand Up @@ -876,7 +876,6 @@ set(wesnoth-main_SRC
game_events/wmi_container.cpp
game_launcher.cpp
game_preferences.cpp
game_preferences_display.cpp
game_state.cpp
generic_event.cpp
gui/auxiliary/canvas.cpp
Expand Down
2 changes: 1 addition & 1 deletion src/SConscript
Expand Up @@ -649,7 +649,7 @@ if env["PLATFORM"] == 'darwin':
if env["notifications"]:
wesnoth_sources.append("desktop/dbus_notification.cpp")

wesnoth_sources.extend(client_env.Object("game_preferences_display.cpp", EXTRA_DEFINE = env["PLATFORM"] != "win32" and "WESNOTH_PREFIX='\"$prefix\"'" or None))
wesnoth_sources.extend(client_env.Object("preferences_display.cpp", EXTRA_DEFINE = env["PLATFORM"] != "win32" and "WESNOTH_PREFIX='\"$prefix\"'" or None))

libwesnoth_extras = client_env.Library("wesnoth_extras", wesnoth_sources)

Expand Down
130 changes: 0 additions & 130 deletions src/game_preferences_display.cpp

This file was deleted.

104 changes: 103 additions & 1 deletion src/preferences_display.cpp
Expand Up @@ -23,11 +23,15 @@
#include "preferences_display.hpp"

#include "display.hpp"
#include "filechooser.hpp"
#include "filesystem.hpp"
#include "formatter.hpp"
#include "formula_string_utils.hpp"
#include "game_preferences.hpp"
#include "gettext.hpp"
#include "gui/dialogs/message.hpp"
#include "gui/dialogs/simple_item_selector.hpp"
#include "gui/dialogs/preferences_dialog.hpp"
#include "gui/dialogs/theme_list.hpp"
#include "gui/dialogs/transient_message.hpp"
#include "gui/widgets/window.hpp"
#include "log.hpp"
Expand Down Expand Up @@ -57,6 +61,23 @@ display_manager::~display_manager()
disp = NULL;
}

void show_preferences_dialog(CVideo& video, const config& game_cfg, const DIALOG_OPEN_TO initial_view)
{
gui2::tpreferences dlg(video, game_cfg);

switch (initial_view) {
case VIEW_DEFAULT:
// Default value (0,0) already set in tpreferences
break;
case VIEW_FRIENDS: {
dlg.set_selected_index(std::make_pair(4, 1));
break;
}
}

dlg.show(video);
}

void set_scroll_to_action(bool ison)
{
_set_scroll_to_action(ison);
Expand Down Expand Up @@ -115,5 +136,86 @@ void set_idle_anim_rate(int rate) {
}
}

bool show_theme_dialog(CVideo& video)
{
std::vector<theme_info> themes = theme::get_known_themes();

if (themes.empty()) {
gui2::show_transient_message(video, "",
_("No known themes. Try changing from within an existing game."));

return false;
}

gui2::ttheme_list dlg(themes);

for (size_t k = 0; k < themes.size(); ++k) {
if(themes[k].id == preferences::theme()) {
dlg.set_selected_index(static_cast<int>(k));
}
}

dlg.show(video);
const int action = dlg.selected_index();

if (action >= 0) {
// FIXME: it would be preferable for the new theme to take effect
// immediately.
preferences::set_theme(themes[action].id);

return true;
}

return false;
}

std::string show_wesnothd_server_search(CVideo& video)
{
// Showing file_chooser so user can search the wesnothd
std::string old_path = preferences::get_mp_server_program_name();
size_t offset = old_path.rfind("/");
if (offset != std::string::npos)
{
old_path = old_path.substr(0, offset);
}
else
{
old_path.clear();
}
#ifndef _WIN32

#ifndef WESNOTH_PREFIX
#define WESNOTH_PREFIX "/usr"
#endif
const std::string filename = "wesnothd";
std::string path = WESNOTH_PREFIX + std::string("/bin");
if (!filesystem::is_directory(path))
path = filesystem::get_cwd();

#else
const std::string filename = "wesnothd.exe";
std::string path = filesystem::get_cwd();
#endif
if (!old_path.empty()
&& filesystem::is_directory(old_path))
{
path = old_path;
}

utils::string_map symbols;

symbols["filename"] = filename;

const std::string title = utils::interpolate_variables_into_string(
_("Find $filename server binary")
, &symbols);

int res = dialogs::show_file_chooser_dialog(video, path, title, false, filename);
if (res == 0)
return path;
else
return "";
}

} // end namespace preferences

0 comments on commit d66e33c

Please sign in to comment.