Skip to content

Commit

Permalink
gui/addon_manager: Add dedicated license prompt dialog
Browse files Browse the repository at this point in the history
This allows using full markup for the license text and making it
independently scrollable without messing up the dialog. It also enables
URL parsing in it.
  • Loading branch information
irydacea committed Dec 10, 2020
1 parent 704ba04 commit 8c39181
Show file tree
Hide file tree
Showing 7 changed files with 227 additions and 1 deletion.
123 changes: 123 additions & 0 deletions data/gui/window/addon_license_prompt.cfg
@@ -0,0 +1,123 @@
#textdomain wesnoth-lib
###
### Definition of the Add-ons Manager license promnpt dialog
###

[window]
id = "addon_license_prompt"
description = "Add-ons Manager content license prompt displayed during uploads."

[resolution]
definition = "default"

automatic_placement = true
vertical_placement = "center"
horizontal_placement = "center"

maximum_width = 800
#maximum_height = 600

[tooltip]
id = "tooltip"
[/tooltip]

[helptip]
id = "tooltip"
[/helptip]

[grid]
[row]
grow_factor = 0
[column]
grow_factor = 1
horizontal_alignment = "left"
border = "all"
border_size = 5

[label]
definition = "title"
label = _ "addons_server^Server Rules"
[/label]
[/column]
[/row]

[row]
grow_factor = 0
[column]
grow_factor = 1
horizontal_alignment = "left"
border = "all"
border_size = 5

[label]
id = "message"
label = "Before uploading content to this server, you must accept the following distribution terms by choosing “I Agree”."
wrap = true
[/label]
[/column]
[/row]

[row]
grow_factor = 0
[column]
horizontal_grow = true
border = "all"
border_size = 5

[panel]
definition = "box_display_no_blur_no_border"
[grid]
[row]
[column]
horizontal_grow = true
border = "all"
border_size = 5

[scroll_label]
id = "terms"
definition = "description"
label = "server terms placeholder"
[/scroll_label]
[/column]
[/row]
[/grid]
[/panel]
[/column]
[/row]

[row]
grow_factor = 0
[column]
horizontal_alignment = "right"

[grid]
[row]
grow_factor = 0
[column]
horizontal_alignment = "right"
border = "all"
border_size = 5

[button]
id = "ok"
label = _ "I Agree"
[/button]
[/column]

[column]
horizontal_alignment = "right"
border = "all"
border_size = 5

[button]
id = "cancel"
label = _ "Cancel"
[/button]
[/column]
[/row]
[/grid]
[/column]
[/row]
[/grid]
[/resolution]
[/window]
8 changes: 8 additions & 0 deletions projectfiles/VC16/wesnoth.vcxproj
Expand Up @@ -1478,6 +1478,13 @@
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='Test_Debug|x64'">$(IntDir)Gui\Dialogs\Addon\</ObjectFileName>
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='Test_Release|x64'">$(IntDir)Gui\Dialogs\Addon\</ObjectFileName>
</ClCompile>
<ClCompile Include="..\..\src\gui\dialogs\addon\license_prompt.cpp">
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(IntDir)Gui\Dialogs\Addon\</ObjectFileName>
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='ReleaseDEBUG|x64'">$(IntDir)Gui\Dialogs\Addon\</ObjectFileName>
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(IntDir)Gui\Dialogs\Addon\</ObjectFileName>
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='Test_Debug|x64'">$(IntDir)Gui\Dialogs\Addon\</ObjectFileName>
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='Test_Release|x64'">$(IntDir)Gui\Dialogs\Addon\</ObjectFileName>
</ClCompile>
<ClCompile Include="..\..\src\gui\dialogs\addon\manager.cpp">
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(IntDir)Gui\Dialogs\Addon\</ObjectFileName>
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='ReleaseDEBUG|x64'">$(IntDir)Gui\Dialogs\Addon\</ObjectFileName>
Expand Down Expand Up @@ -3803,6 +3810,7 @@
<ClInclude Include="..\..\src\gui\core\window_builder\instance.hpp" />
<ClInclude Include="..\..\src\gui\dialogs\addon\connect.hpp" />
<ClInclude Include="..\..\src\gui\dialogs\addon\install_dependencies.hpp" />
<ClInclude Include="..\..\src\gui\dialogs\addon\license_prompt.hpp" />
<ClInclude Include="..\..\src\gui\dialogs\addon\manager.hpp" />
<ClInclude Include="..\..\src\gui\dialogs\addon\uninstall_list.hpp" />
<ClInclude Include="..\..\src\gui\dialogs\attack_predictions.hpp" />
Expand Down
6 changes: 6 additions & 0 deletions projectfiles/VC16/wesnoth.vcxproj.filters
Expand Up @@ -704,6 +704,9 @@
<ClCompile Include="..\..\src\gui\dialogs\addon\install_dependencies.cpp">
<Filter>Gui\Dialogs\Addon</Filter>
</ClCompile>
<ClCompile Include="..\..\src\gui\dialogs\addon\license_prompt.cpp">
<Filter>Gui\Dialogs\Addon</Filter>
</ClCompile>
<ClCompile Include="..\..\src\gui\dialogs\addon\manager.cpp">
<Filter>Gui\Dialogs\Addon</Filter>
</ClCompile>
Expand Down Expand Up @@ -2150,6 +2153,9 @@
<ClInclude Include="..\..\src\gui\dialogs\addon\install_dependencies.hpp">
<Filter>Gui\Dialogs\Addon</Filter>
</ClInclude>
<ClInclude Include="..\..\src\gui\dialogs\addon\license_prompt.hpp">
<Filter>Gui\Dialogs\Addon</Filter>
</ClInclude>
<ClInclude Include="..\..\src\gui\dialogs\addon\manager.hpp">
<Filter>Gui\Dialogs\Addon</Filter>
</ClInclude>
Expand Down
1 change: 1 addition & 0 deletions source_lists/wesnoth
Expand Up @@ -164,6 +164,7 @@ gui/core/window_builder/helper.cpp
gui/core/window_builder/instance.cpp
gui/dialogs/addon/connect.cpp
gui/dialogs/addon/install_dependencies.cpp
gui/dialogs/addon/license_prompt.cpp
gui/dialogs/addon/manager.cpp
gui/dialogs/addon/uninstall_list.cpp
gui/dialogs/attack_predictions.cpp
Expand Down
42 changes: 42 additions & 0 deletions src/gui/dialogs/addon/license_prompt.cpp
@@ -0,0 +1,42 @@
/*
Copyright (C) 2020 by Iris Morelle <shadowm@wesnoth.org>
Part of the Battle for Wesnoth Project https://www.wesnoth.org/
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.
See the COPYING file for more details.
*/

#define GETTEXT_DOMAIN "wesnoth-lib"

#include "gui/dialogs/addon/license_prompt.hpp"

#include "gettext.hpp"
#include "gui/auxiliary/find_widget.hpp"
#include "gui/widgets/button.hpp"
#include "gui/widgets/settings.hpp"
#include "gui/widgets/window.hpp"

namespace gui2 {
namespace dialogs {

REGISTER_DIALOG(addon_license_prompt)

addon_license_prompt::addon_license_prompt(const std::string& license_terms)
: license_terms_(license_terms)
{
}

void addon_license_prompt::pre_show(window& window)
{
styled_widget& terms = find_widget<styled_widget>(&window, "terms", false);
terms.set_use_markup(true);
terms.set_label(license_terms_);
}

}} // end namespace gui2::dialogs
45 changes: 45 additions & 0 deletions src/gui/dialogs/addon/license_prompt.hpp
@@ -0,0 +1,45 @@
/*
Copyright (C) 2020 by Iris Morelle <shadowm@wesnoth.org>
Part of the Battle for Wesnoth Project https://www.wesnoth.org/
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.
See the COPYING file for more details.
*/

#pragma once

#include "gui/dialogs/modal_dialog.hpp"

namespace gui2 {
namespace dialogs {

class addon_license_prompt : public modal_dialog
{
public:
/** Constructor. */
explicit addon_license_prompt(const std::string& license_terms);

/**
* The execute function.
*
* See @ref modal_dialog for more information.
*/
DEFINE_SIMPLE_EXECUTE_WRAPPER(addon_license_prompt)

private:
/** Inherited from modal_dialog, implemented by REGISTER_DIALOG. */
virtual const std::string& window_id() const override;

/** Inherited from modal_dialog. */
virtual void pre_show(window& window) override;

std::string license_terms_;
};

}} // end namespace gui2::dialogs
3 changes: 2 additions & 1 deletion src/gui/dialogs/addon/manager.cpp
Expand Up @@ -27,6 +27,7 @@
#include "gettext.hpp"
#include "gui/auxiliary/filter.hpp"
#include "gui/auxiliary/find_widget.hpp"
#include "gui/dialogs/addon/license_prompt.hpp"
#include "gui/dialogs/message.hpp"
#include "gui/dialogs/transient_message.hpp"
#include "gui/widgets/button.hpp"
Expand Down Expand Up @@ -796,7 +797,7 @@ void addon_manager::publish_addon(const addon_info& addon)
} else if(!client_.request_distribution_terms(server_msg)) {
gui2::show_error_message(
_("The server responded with an error:") + "\n" + client_.get_last_server_error());
} else if(gui2::show_message(_("Terms"), server_msg, gui2::dialogs::message::ok_cancel_buttons, true) == gui2::retval::OK) {
} else if(gui2::dialogs::addon_license_prompt::execute(server_msg)) {
if(!client_.upload_addon(addon_id, server_msg, cfg, tracking_info_[addon_id].state == ADDON_INSTALLED_LOCAL_ONLY)) {
const std::string& msg = _("The add-on was rejected by the server:") +
"\n\n" + client_.get_last_server_error();
Expand Down

0 comments on commit 8c39181

Please sign in to comment.