The Battle for Wesnoth  1.19.5+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 
20 #include "gui/widgets/window.hpp"
21 #include "log.hpp"
22 
23 #include "gettext.hpp"
24 
25 namespace gui2
26 {
27 namespace dialogs
28 {
29 
30 REGISTER_DIALOG(transient_message)
31 
32 transient_message::transient_message(const std::string& title,
33  const bool title_use_markup,
34  const std::string& message,
35  const bool message_use_markup,
36  const std::string& image)
37  : modal_dialog(window_id())
38  , hide_title_(title.empty())
39  , 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>("title");
51  }
52 
53  if(hide_image_) {
54  widget& image = find_widget<widget>("image");
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 {
67  title, title_use_markup, message, message_use_markup, image);
68 
69  dlg.show();
70 }
71 
72 void show_transient_error_message(const std::string& message,
73  const std::string& image,
74  const bool message_use_markup)
75 {
77  show_transient_message(_("Error"), message, image, message_use_markup);
78 }
79 
80 } // 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() override
Actions to be taken before showing the window.
Base class for all widgets.
Definition: widget.hpp:55
void set_visible(const visibility visible)
Definition: widget.cpp:479
@ invisible
The user set the widget invisible, that means:
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:281
Various uncategorised dialogs.
REGISTER_DIALOG(editor_edit_unit)
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:305
log_domain & general()
Definition: log.cpp:331