The Battle for Wesnoth  1.17.0-dev
transient_message.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 - 2021
3  by Mark de Wever <koraq@xs4all.nl>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 #define GETTEXT_DOMAIN "wesnoth-lib"
17 
19 
21 #include "gui/widgets/settings.hpp"
22 #include "gui/widgets/window.hpp"
23 #include "log.hpp"
24 
25 #include "gettext.hpp"
26 
27 namespace gui2
28 {
29 namespace dialogs
30 {
31 
32 REGISTER_DIALOG(transient_message)
33 
34 transient_message::transient_message(const std::string& title,
35  const bool title_use_markup,
36  const std::string& message,
37  const bool message_use_markup,
38  const std::string& image)
39  : hide_title_(title.empty()), hide_image_(image.empty())
40 {
41  register_label("title", true, title, title_use_markup);
42  register_label("message", true, message, message_use_markup);
43  register_image("image", true, image);
44 }
45 
47 {
48  if(hide_title_) {
49  widget& title = find_widget<widget>(&window, "title", false);
51  }
52 
53  if(hide_image_) {
54  widget& image = find_widget<widget>(&window, "image", false);
56  }
57 }
58 } // namespace dialogs
59 
60 void show_transient_message(const std::string& title,
61  const std::string& message,
62  const std::string& image,
63  const bool message_use_markup,
64  const bool title_use_markup,
65  const bool restore_background)
66 {
68  title, title_use_markup, message, message_use_markup, image);
69 
70  dlg.set_restore(restore_background);
71  dlg.show();
72 }
73 
74 void show_transient_error_message(const std::string& message,
75  const std::string& image,
76  const bool message_use_markup)
77 {
78  LOG_STREAM(err, lg::general()) << message << '\n';
79  show_transient_message(_("Error"), message, image, message_use_markup);
80 }
81 
82 } // namespace gui2
Main class to show messages to the user.
Definition: message.hpp:35
This file contains the window object, this object is a top level container which has the event manage...
void show_transient_message(const std::string &title, const std::string &message, const std::string &image, const bool message_use_markup, const bool title_use_markup, const bool restore_background)
Shows a transient message to the user.
Base class for all widgets.
Definition: widget.hpp:49
STL namespace.
static std::string _(const char *str)
Definition: gettext.hpp:93
#define LOG_STREAM(level, domain)
Definition: log.hpp:221
bool show(const unsigned auto_close_time=0)
Shows the window.
Generic file dialog.
Definition: field-fwd.hpp:23
virtual void pre_show(window &window) override
Actions to be taken before showing the window.
This file contains the settings handling of the widget library.
void set_visible(const visibility visible)
Definition: widget.cpp:476
Various uncategorised dialogs.
log_domain & general()
Definition: log.cpp:103
logger & err()
Definition: log.cpp:77
The user set the widget invisible, that means:
Shows a transient message.
void show_transient_error_message(const std::string &message, const std::string &image, const bool message_use_markup)
Shows a transient error message to the user.
Functions to load and save images from/to disk.
Standard logging facilities (interface).
base class of top level items, the only item which needs to store the final canvases to draw on...
Definition: window.hpp:65
void set_restore(const bool restore)