The Battle for Wesnoth  1.15.12+dev
transient_message.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 - 2018 by Mark de Wever <koraq@xs4all.nl>
3  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #define GETTEXT_DOMAIN "wesnoth-lib"
16 
18 
20 #include "gui/widgets/settings.hpp"
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  : hide_title_(title.empty()), hide_image_(image.empty())
39 {
40  register_label("title", true, title, title_use_markup);
41  register_label("message", true, message, message_use_markup);
42  register_image("image", true, image);
43 }
44 
46 {
47  if(hide_title_) {
48  widget& title = find_widget<widget>(&window, "title", false);
50  }
51 
52  if(hide_image_) {
53  widget& image = find_widget<widget>(&window, "image", false);
55  }
56 }
57 } // namespace dialogs
58 
59 void show_transient_message(const std::string& title,
60  const std::string& message,
61  const std::string& image,
62  const bool message_use_markup,
63  const bool title_use_markup,
64  const bool restore_background)
65 {
67  title, title_use_markup, message, message_use_markup, image);
68 
69  dlg.set_restore(restore_background);
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 {
77  LOG_STREAM(err, lg::general()) << message << '\n';
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:34
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:92
#define LOG_STREAM(level, domain)
Definition: log.hpp:209
bool show(const unsigned auto_close_time=0)
Shows the window.
Generic file dialog.
Definition: field-fwd.hpp:22
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:475
Various uncategorised dialogs.
log_domain & general()
Definition: log.cpp:102
logger & err()
Definition: log.cpp:76
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:64
void set_restore(const bool restore)