Some minor tweaks to the network dialog.

Changes:

- Allows the progress to be translated.

- Sets the title directly upon creation.
This commit is contained in:
Mark de Wever 2011-07-05 18:42:22 +00:00
parent a441cece01
commit 5bf057903c
2 changed files with 32 additions and 13 deletions

View File

@ -18,6 +18,7 @@
#include "gui/dialogs/network_transmission.hpp"
#include "foreach.hpp"
#include "formula_string_utils.hpp"
#include "gettext.hpp"
#include "gui/widgets/button.hpp"
#include "gui/widgets/progress_bar.hpp"
@ -38,20 +39,35 @@ void tnetwork_transmission::pump_monitor::process(events::pump_info&)
window_.get().set_retval(twindow::OK);
} else {
if(connection_.bytes_to_read()) {
size_t total = connection_.bytes_to_read();
size_t completed = connection_.bytes_read();
size_t total = connection_.bytes_to_read();
find_widget<tprogress_bar>(&(window_.get()), "progress", false)
.set_percentage((completed*100)/total);
std::ostringstream os;
os << (completed/1024) << "KiB/" << (total/1024) << "KiB";
std::cout << os.str() << std::endl;
string_map symbols;
symbols["total"] = str_cast(total);
symbols["completed"] = str_cast(completed);
find_widget<tlabel>(&(window_.get()), "numeric_progress", false)
.set_label(os.str());
.set_label(vgettext(
"$completed KiB/$total KiB"
, symbols));
window_->invalidate_layout();
}
}
}
tnetwork_transmission::tnetwork_transmission(
network_asio::connection& connection
, const std::string& title
, const std::string& subtitle)
: connection_(connection)
, pump_monitor(connection)
, subtitle_(subtitle)
{
register_label2("title", true, title, false);
}
void tnetwork_transmission::set_subtitle(const std::string& subtitle)
{
subtitle_ = subtitle;
@ -60,9 +76,6 @@ void tnetwork_transmission::set_subtitle(const std::string& subtitle)
void tnetwork_transmission::pre_show(CVideo& /*video*/, twindow& window)
{
// ***** ***** ***** ***** Set up the widgets ***** ***** ***** *****
if(!title_.empty()) {
find_widget<tlabel>(&window, "title", false).set_label(title_);
}
if(!subtitle_.empty()) {
find_widget<tlabel>(&window, "subtitle", false).set_label(subtitle_);
}

View File

@ -49,9 +49,11 @@ class tnetwork_transmission : public tdialog
boost::optional<twindow&> window_;
} pump_monitor;
public:
tnetwork_transmission(network_asio::connection& connection, const std::string& title, const std::string& subtitle)
: connection_(connection), pump_monitor(connection), title_(title), subtitle_(subtitle)
{}
tnetwork_transmission(
network_asio::connection& connection
, const std::string& title
, const std::string& subtitle);
void set_subtitle(const std::string&);
@ -63,8 +65,12 @@ protected:
void post_show(twindow& window);
private:
/** The title for the dialog. */
std::string title_;
/**
* The subtitle for the dialog.
*
* This field commenly shows the action in progress eg connecting,
* uploading, downloading etc..
*/
std::string subtitle_;
/** Inherited from tdialog, implemented by REGISTER_DIALOG. */