gui2/tscreenshot_notification: Don't obtain file size from caller
The caller's provided size is notoriously unreliable right now -- especially after the addition of PNG support -- because it's obtained from display::screenshot(), which just does some math voodoo to calculate the *expected* size of a BMP file and sticks to that. stat-ing a file is cheap, and simplifies our constructor's signature. This also fixes PNG files having the wrong size reported.
This commit is contained in:
parent
a17169a406
commit
db28dca52c
4 changed files with 17 additions and 11 deletions
|
@ -63,13 +63,19 @@ namespace gui2
|
|||
|
||||
REGISTER_DIALOG(screenshot_notification)
|
||||
|
||||
tscreenshot_notification::tscreenshot_notification(const std::string& path,
|
||||
int filesize)
|
||||
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,
|
||||
utils::si_string(filesize, true, _("unit_byte^B")),
|
||||
sizetext,
|
||||
false);
|
||||
}
|
||||
|
||||
|
|
|
@ -26,19 +26,20 @@ public:
|
|||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param path Path to the screenshot file created,
|
||||
* @param filesize Size of the screenshot file.
|
||||
* @param path Path to the screenshot file created. The caller should
|
||||
* ensure the file exists, otherwise it will be displayed
|
||||
* with size 0.
|
||||
*/
|
||||
tscreenshot_notification(const std::string& path, int filesize);
|
||||
tscreenshot_notification(const std::string& path);
|
||||
|
||||
/**
|
||||
* The display function.
|
||||
*
|
||||
* See @ref tdialog for more information.
|
||||
*/
|
||||
static void display(const std::string& path, int filesize, CVideo& video)
|
||||
static void display(const std::string& path, CVideo& video)
|
||||
{
|
||||
tscreenshot_notification(path, filesize).show(video);
|
||||
tscreenshot_notification(path).show(video);
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
|
@ -651,7 +651,7 @@ void execute_command(display& disp, const hotkey_command& command, command_execu
|
|||
filename = filesystem::get_next_filename(filename, ext);
|
||||
int size = disp.screenshot(filename, map_screenshot);
|
||||
if (size > 0) {
|
||||
gui2::tscreenshot_notification::display(filename, size, disp.video());
|
||||
gui2::tscreenshot_notification::display(filename, disp.video());
|
||||
} else {
|
||||
gui2::show_message(disp.video(), _("Screenshot Done"), "");
|
||||
}
|
||||
|
|
|
@ -811,8 +811,7 @@ struct twrapper<gui2::tscreenshot_notification>
|
|||
{
|
||||
static gui2::tscreenshot_notification* create()
|
||||
{
|
||||
return new gui2::tscreenshot_notification("path"
|
||||
, 0);
|
||||
return new gui2::tscreenshot_notification("path");
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue