-
-
Notifications
You must be signed in to change notification settings - Fork 991
/
screenshot_notification.cpp
107 lines (89 loc) · 3.03 KB
/
screenshot_notification.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
Copyright (C) 2013 - 2016 by Ignacio Riquelme Morelle <shadowm2006@gmail.com>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#define GETTEXT_DOMAIN "wesnoth-lib"
#include "gui/dialogs/screenshot_notification.hpp"
#include "desktop/clipboard.hpp"
#include "desktop/open.hpp"
#include "filesystem.hpp"
#include "gui/auxiliary/find_widget.hpp"
#include "gui/widgets/button.hpp"
#include "gui/widgets/settings.hpp"
#include "gui/widgets/text_box.hpp"
#include "gui/widgets/window.hpp"
#include "utils/functional.hpp"
#include "gettext.hpp"
namespace gui2
{
/*WIKI
* @page = GUIWindowDefinitionWML
* @order = 2_screenshot_notification
*
* == Screenshot notification ==
*
* Notification dialog used after saving a game or map screenshot to display
* information about it for the user.
*
* @begin{table}{dialog_widgets}
*
* path & & text_box & m &
* Read-only textbox containing the screenshot path. $
*
* filesize & & label & o &
* Optional label to display the file size. $
*
* copy & & button & m &
* Button to copy the path to clipboard. $
*
* open & & button & m &
* Button to open the screnshot using the default application. $
*
* browse_dir & & button & m &
* Button to browse the screenshots directory in the file manager. $
*
* @end{table}
*/
REGISTER_DIALOG(screenshot_notification)
tscreenshot_notification::tscreenshot_notification(const std::string& path)
: path_(path), screenshots_dir_path_(filesystem::get_screenshot_dir())
{
const int filesize = filesystem::file_size(path);
const std::string sizetext
= filesize >= 0
? utils::si_string(filesize, true, _("unit_byte^B"))
: _("file_size^Unknown");
register_label("filesize",
false,
sizetext,
false);
}
void tscreenshot_notification::pre_show(twindow& window)
{
ttext_box& path_box = find_widget<ttext_box>(&window, "path", false);
path_box.set_value(filesystem::base_name(path_));
path_box.set_active(false);
tbutton& copy_b = find_widget<tbutton>(&window, "copy", false);
connect_signal_mouse_left_click(
copy_b, std::bind(&desktop::clipboard::copy_to_clipboard, std::ref(path_), false));
if (!desktop::clipboard::available()) {
copy_b.set_active(false);
copy_b.set_tooltip(_("Clipboard support not found, contact your packager"));
}
tbutton& open_b = find_widget<tbutton>(&window, "open", false);
connect_signal_mouse_left_click(
open_b, bind_void(&desktop::open_object, std::ref(path_)));
tbutton& bdir_b = find_widget<tbutton>(&window, "browse_dir", false);
connect_signal_mouse_left_click(
bdir_b,
bind_void(&desktop::open_object,
std::ref(screenshots_dir_path_)));
}
}