The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
network_transmission.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2011 - 2016 Sergey Popov <[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 "formula/string_utils.hpp"
20 #include "gettext.hpp"
22 #include "gui/widgets/button.hpp"
24 #include "gui/widgets/label.hpp"
25 #include "gui/widgets/settings.hpp"
26 #include "gui/widgets/window.hpp"
27 #include "log.hpp"
29 
30 namespace gui2
31 {
32 
33 REGISTER_DIALOG(network_transmission)
34 
36 {
37  if(!window_)
38  return;
39  connection_->poll();
40  if(connection_->finished()) {
41  window_.get().set_retval(twindow::OK);
42  } else {
43  size_t completed, total;
44  completed = connection_->current();
45  total = connection_->total();
46  if(total) {
47  find_widget<tprogress_bar>(&(window_.get()), "progress", false)
48  .set_percentage((completed * 100.) / total);
49 
50  std::stringstream ss;
51  ss << utils::si_string(completed, true, _("unit_byte^B")) << "/"
52  << utils::si_string(total, true, _("unit_byte^B"));
53 
54  find_widget<tlabel>(&(window_.get()), "numeric_progress", false)
55  .set_label(ss.str());
56  window_->invalidate_layout();
57  }
58  }
59 }
60 
63  const std::string& title,
64  const std::string& subtitle)
65  : connection_(&connection)
66  , pump_monitor_(connection_)
67  , subtitle_(subtitle)
68 {
69  register_label("title", true, title, false);
70  set_restore(true);
71 }
72 
74 {
75  subtitle_ = subtitle;
76 }
77 
79 {
80  // ***** ***** ***** ***** Set up the widgets ***** ***** ***** *****
81  if(!subtitle_.empty()) {
82  tlabel& subtitle_label
83  = find_widget<tlabel>(&window, "subtitle", false);
84  subtitle_label.set_label(subtitle_);
85  subtitle_label.set_use_markup(true);
86  }
87 
88  pump_monitor_.window_ = window;
89 }
90 
92 {
93  pump_monitor_.window_.reset();
95 }
96 
97 } // namespace gui2
std::string si_string(double input, bool base2, std::string unit)
Convert into a string with an SI-postfix.
void post_show(twindow &window)
Inherited from tdialog.
GLvoid **typedef void(GLAPIENTRY *PFNGLGETVERTEXATTRIBDVPROC)(GLuint
Definition: glew.h:1806
Dialog that tracks network transmissions.
void pre_show(twindow &window)
Inherited from tdialog.
This file contains the window object, this object is a top level container which has the event manage...
REGISTER_DIALOG(label_settings)
virtual void set_label(const t_string &label)
Definition: control.cpp:330
Label showing a text.
Definition: label.hpp:29
gui2::tnetwork_transmission::pump_monitor pump_monitor_
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
virtual void set_use_markup(bool use_markup)
Definition: control.cpp:342
static UNUSEDNOWARN std::string _(const char *str)
Definition: gettext.hpp:82
void process(int mousex, int mousey)
Definition: tooltips.cpp:198
Dialog is closed with ok button.
Definition: window.hpp:125
This file contains the settings handling of the widget library.
void set_restore(const bool restore)
Definition: dialog.hpp:171
tfield_label * register_label(const std::string &id, const bool mandatory, const std::string &text, const bool use_markup=false)
Registers a new control as a label.
Definition: dialog.cpp:160
Handling of system events.
Definition: manager.hpp:42
tnetwork_transmission(connection_data &connection, const std::string &title, const std::string &subtitle)
Standard logging facilities (interface).
void set_subtitle(const std::string &)
int connection
Definition: network.hpp:74
GLsizei const GLcharARB ** string
Definition: glew.h:4503
std::string subtitle_
The subtitle for the dialog.