The Battle for Wesnoth  1.19.0-dev
transient_message.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 - 2024
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/window.hpp"
22 #include "log.hpp"
23 
24 #include "gettext.hpp"
25 
26 namespace gui2
27 {
28 namespace dialogs
29 {
30 
31 REGISTER_DIALOG(transient_message)
32 
33 transient_message::transient_message(const std::string& title,
34  const bool title_use_markup,
35  const std::string& message,
36  const bool message_use_markup,
37  const std::string& image)
38  : modal_dialog(window_id())
39  , hide_title_(title.empty())
40  , hide_image_(image.empty())
41 {
42  register_label("title", true, title, title_use_markup);
43  register_label("message", true, message, message_use_markup);
44  register_image("image", true, image);
45 }
46 
48 {
49  if(hide_title_) {
50  widget& title = find_widget<widget>(&window, "title", false);
52  }
53 
54  if(hide_image_) {
55  widget& image = find_widget<widget>(&window, "image", false);
57  }
58 }
59 } // namespace dialogs
60 
61 void show_transient_message(const std::string& title,
62  const std::string& message,
63  const std::string& image,
64  const bool message_use_markup,
65  const bool title_use_markup)
66 {
68  title, title_use_markup, message, message_use_markup, image);
69 
70  dlg.show();
71 }
72 
73 void show_transient_error_message(const std::string& message,
74  const std::string& image,
75  const bool message_use_markup)
76 {
78  show_transient_message(_("Error"), message, image, message_use_markup);
79 }
80 
81 } // namespace gui2
Main class to show messages to the user.
Definition: message.hpp:36
Abstract base class for all modal dialogs.
bool show(const unsigned auto_close_time=0)
Shows the window.
Shows a transient message.
virtual void pre_show(window &window) override
Actions to be taken before showing the window.
Base class for all widgets.
Definition: widget.hpp:53
void set_visible(const visibility visible)
Definition: widget.cpp:470
@ invisible
The user set the widget invisible, that means:
base class of top level items, the only item which needs to store the final canvases to draw on.
Definition: window.hpp:63
static std::string _(const char *str)
Definition: gettext.hpp:93
This file contains the window object, this object is a top level container which has the event manage...
Standard logging facilities (interface).
#define LOG_STREAM(level, domain)
Definition: log.hpp:277
Various uncategorised dialogs.
REGISTER_DIALOG(tod_new_schedule)
Generic file dialog.
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.
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)
Shows a transient message to the user.
Functions to load and save images from/to disk.
logger & err()
Definition: log.cpp:302
log_domain & general()
Definition: log.cpp:328