gui/dialogs/network_transmission.cpp

Go to the documentation of this file.
00001 /* $Id: network_transmission.cpp 54116 2012-05-07 00:15:14Z loonycyborg $ */
00002 /*
00003    Copyright (C) 2011 - 2012 Sergey Popov <loonycyborg@gmail.com>
00004    Part of the Battle for Wesnoth Project http://www.wesnoth.org/
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License as published by
00008    the Free Software Foundation; either version 2 of the License, or
00009    (at your option) any later version.
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY.
00012 
00013    See the COPYING file for more details.
00014 */
00015 
00016 #define GETTEXT_DOMAIN "wesnoth-lib"
00017 
00018 #include "gui/dialogs/network_transmission.hpp"
00019 
00020 #include "foreach.hpp"
00021 #include "formula_string_utils.hpp"
00022 #include "gettext.hpp"
00023 #include "gui/widgets/button.hpp"
00024 #include "gui/widgets/progress_bar.hpp"
00025 #include "gui/widgets/label.hpp"
00026 #include "gui/widgets/settings.hpp"
00027 #include "gui/widgets/window.hpp"
00028 #include "log.hpp"
00029 #include "serialization/string_utils.hpp"
00030 
00031 namespace gui2 {
00032 
00033 REGISTER_DIALOG(network_transmission)
00034 
00035 void tnetwork_transmission::pump_monitor::process(events::pump_info&)
00036 {
00037     connection_.poll();
00038     if(!window_) return;
00039     if(connection_.done()) {
00040         window_.get().set_retval(twindow::OK);
00041     } else {
00042         size_t completed, total;
00043         if(track_upload_) {
00044             completed = connection_.bytes_written();
00045             total = connection_.bytes_to_write();
00046         } else {
00047             completed = connection_.bytes_read();
00048             total = connection_.bytes_to_read();
00049         }
00050         if(total) {
00051             find_widget<tprogress_bar>(&(window_.get()), "progress", false)
00052                 .set_percentage((completed*100.)/total);
00053 
00054             std::stringstream ss;
00055             ss << utils::si_string(completed, true, _("unit_byte^B"))
00056                << "/"
00057                << utils::si_string(total, true, _("unit_byte^B"));
00058 
00059             find_widget<tlabel>(&(window_.get()), "numeric_progress", false)
00060                     .set_label(ss.str());
00061             window_->invalidate_layout();
00062         }
00063     }
00064 }
00065 
00066 tnetwork_transmission::tnetwork_transmission(
00067           network_asio::connection& connection
00068         , const std::string& title
00069         , const std::string& subtitle)
00070     : connection_(connection)
00071     , pump_monitor(connection, track_upload_)
00072     , subtitle_(subtitle)
00073 {
00074     register_label("title", true, title, false);
00075 }
00076 
00077 void tnetwork_transmission::set_subtitle(const std::string& subtitle)
00078 {
00079     subtitle_ = subtitle;
00080 }
00081 
00082 void tnetwork_transmission::pre_show(CVideo& /*video*/, twindow& window)
00083 {
00084     // ***** ***** ***** ***** Set up the widgets ***** ***** ***** *****
00085     if(!subtitle_.empty()) {
00086         tlabel& subtitle_label = find_widget<tlabel>(&window, "subtitle", false);
00087         subtitle_label.set_label(subtitle_);
00088         subtitle_label.set_use_markup(true);
00089     }
00090 
00091     pump_monitor.window_ = window;
00092 
00093 }
00094 
00095 void tnetwork_transmission::post_show(twindow& /*window*/)
00096 {
00097     pump_monitor.window_.reset();
00098     connection_.cancel();
00099 }
00100 
00101 } // namespace gui2
00102 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Fri May 25 2012 01:02:58 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs