The Battle for Wesnoth  1.15.2+dev
network_transmission.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2011 - 2018 by Sergey Popov <loonycyborg@gmail.com>
3  Part of the Battle for Wesnoth Project https://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 #pragma once
16 
17 #include "events.hpp"
19 #include "network_asio.hpp"
20 
21 #include <boost/optional.hpp>
22 
23 #include <atomic>
24 #include <future>
25 
26 namespace gui2
27 {
28 namespace dialogs
29 {
30 
31 /**
32  * Dialog that tracks network transmissions
33  *
34  * It shows upload/download progress and allows the user
35  * to cancel the transmission.
36  */
38 {
39 public:
40  /** A wrapper of either a wesnothd_connection or a network_asio::connection. */
42  {
43  public:
44  virtual std::size_t total() { return 0; }
45  virtual std::size_t current() { return 0; }
46  virtual bool finished() = 0;
47  virtual void cancel() = 0;
48  virtual void poll() = 0;
49  virtual ~connection_data() {}
50  };
51 
52 private:
54 
56  {
57  public:
58  virtual void process(events::pump_info&) override;
59 
60  pump_monitor(connection_data*& connection);
61 
63 
64  boost::optional<window&> window_;
65 
66  std::atomic_size_t completed_, total_;
67 
68  std::atomic_bool stop_;
69 
70  std::future<void> poller_;
71  } pump_monitor_;
72 
73 public:
75  const std::string& title,
76  const std::string& subtitle);
77 
78 protected:
79  /** Inherited from modal_dialog. */
80  virtual void pre_show(window& window) override;
81 
82  /** Inherited from modal_dialog. */
83  virtual void post_show(window& window) override;
84 
85 private:
86  /**
87  * The subtitle for the dialog.
88  *
89  * This field commonly shows the action in progress eg connecting,
90  * uploading, downloading etc..
91  */
92  std::string subtitle_;
93 
94  /** Inherited from modal_dialog, implemented by REGISTER_DIALOG. */
95  virtual const std::string& window_id() const override;
96 };
97 
98 } // namespace dialogs
99 } // namespace gui2
virtual void post_show(window &window) override
Inherited from modal_dialog.
virtual void pre_show(window &window) override
Inherited from modal_dialog.
Generic file dialog.
Definition: field-fwd.hpp:22
void process(int mousex, int mousey)
Definition: tooltips.cpp:193
std::string subtitle_
The subtitle for the dialog.
gui2::dialogs::network_transmission::pump_monitor pump_monitor_
Various uncategorised dialogs.
network_transmission(connection_data &connection, const std::string &title, const std::string &subtitle)
A wrapper of either a wesnothd_connection or a network_asio::connection.
Abstract base class for all modal dialogs.
Dialog that tracks network transmissions.
base class of top level items, the only item which needs to store the final canvases to draw on ...
Definition: window.hpp:62
virtual const std::string & window_id() const override
Inherited from modal_dialog, implemented by REGISTER_DIALOG.