The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
screenshot_notification.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2013 - 2016 by Ignacio Riquelme Morelle <[email protected]>
3  Part of the Battle for Wesnoth Project http://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 
19 #include "desktop/clipboard.hpp"
20 #include "desktop/open.hpp"
21 #include "filesystem.hpp"
23 #include "gui/widgets/button.hpp"
24 #include "gui/widgets/settings.hpp"
25 #include "gui/widgets/text_box.hpp"
26 #include "gui/widgets/window.hpp"
27 
28 #include "utils/functional.hpp"
29 
30 #include "gettext.hpp"
31 
32 namespace gui2
33 {
34 
35 /*WIKI
36  * @page = GUIWindowDefinitionWML
37  * @order = 2_screenshot_notification
38  *
39  * == Screenshot notification ==
40  *
41  * Notification dialog used after saving a game or map screenshot to display
42  * information about it for the user.
43  *
44  * @begin{table}{dialog_widgets}
45  *
46  * path & & text_box & m &
47  * Read-only textbox containing the screenshot path. $
48  *
49  * filesize & & label & o &
50  * Optional label to display the file size. $
51  *
52  * copy & & button & m &
53  * Button to copy the path to clipboard. $
54  *
55  * open & & button & m &
56  * Button to open the screnshot using the default application. $
57  *
58  * browse_dir & & button & m &
59  * Button to browse the screenshots directory in the file manager. $
60  *
61  * @end{table}
62  */
63 
64 REGISTER_DIALOG(screenshot_notification)
65 
67  : path_(path), screenshots_dir_path_(filesystem::get_screenshot_dir())
68 {
69  const int filesize = filesystem::file_size(path);
70 
71  const std::string sizetext
72  = filesize >= 0
73  ? utils::si_string(filesize, true, _("unit_byte^B"))
74  : _("file_size^Unknown");
75 
76  register_label("filesize",
77  false,
78  sizetext,
79  false);
80 }
81 
83 {
84  ttext_box& path_box = find_widget<ttext_box>(&window, "path", false);
86  path_box.set_active(false);
87 
88  tbutton& copy_b = find_widget<tbutton>(&window, "copy", false);
90  copy_b, std::bind(&desktop::clipboard::copy_to_clipboard, std::ref(path_), false));
91 
93  copy_b.set_active(false);
94  copy_b.set_tooltip(_("Clipboard support not found, contact your packager"));
95  }
96 
97  tbutton& open_b = find_widget<tbutton>(&window, "open", false);
100 
101  tbutton& bdir_b = find_widget<tbutton>(&window, "browse_dir", false);
103  bdir_b,
106 }
107 }
std::string si_string(double input, bool base2, std::string unit)
Convert into a string with an SI-postfix.
virtual void set_active(const bool active) override
See tcontrol::set_active.
Definition: button.cpp:58
bool available()
Whether wesnoth was compiled with support for a clipboard.
Definition: clipboard.cpp:61
virtual void set_active(const bool active) override
See tcontrol::set_active.
Definition: text.cpp:56
This file contains the window object, this object is a top level container which has the event manage...
REGISTER_DIALOG(label_settings)
std::string get_screenshot_dir()
void connect_signal_mouse_left_click(tdispatcher &dispatcher, const tsignal_function &signal)
Connects a signal handler for a left mouse button click.
Definition: dispatcher.hpp:710
STL namespace.
Class for a single line text area.
Definition: text_box.hpp:118
virtual void set_value(const std::string &text)
The set_value is virtual for the tpassword_box class.
Definition: text.cpp:95
base class of top level items, the only item which needs to store the final canvases to draw on ...
Definition: window.hpp:62
A class inherited from ttext_box that displays its input as stars.
Definition: field-fwd.hpp:23
Simple push button.
Definition: button.hpp:32
Desktop environment interaction functions.
static UNUSEDNOWARN std::string _(const char *str)
Definition: gettext.hpp:82
GLsizei const char ** path
Definition: glew.h:4654
auto bind_void(F fcn, P...bindings) -> decltype(boost::bind(detail::make_apply(std::function< typename detail::function_base< F >::type >(fcn)), bindings...))
Definition: functional.hpp:94
This file contains the settings handling of the widget library.
std::string base_name(const std::string &file)
Returns the base filename of a file, with directory name stripped.
void set_tooltip(const t_string &tooltip)
Definition: control.hpp:265
bool open_object(const std::string &path_or_url)
Opens the specified object with the default application configured for its type.
Definition: open.cpp:53
Declarations for File-IO.
int file_size(const std::string &fname)
Returns the size of a file, or -1 if the file doesn't exist.
void copy_to_clipboard(const std::string &text, const bool)
Copies text to the clipboard.
Definition: clipboard.cpp:40
GLenum GLint ref
Definition: glew.h:1813
void pre_show(twindow &window)
Inherited from tdialog.
GLsizei const GLcharARB ** string
Definition: glew.h:4503