The Battle for Wesnoth  1.17.0-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"
21 
22 #include <atomic>
23 #include <future>
24 
25 namespace gui2::dialogs
26 {
27 
28 /**
29  * Dialog that tracks network transmissions
30  *
31  * It shows upload/download progress and allows the user
32  * to cancel the transmission.
33  */
35 {
36 public:
37  /** A wrapper of either a wesnothd_connection or a network_asio::connection. */
39  {
40  public:
41  virtual std::size_t total() { return 0; }
42  virtual std::size_t current() { return 0; }
43  virtual bool finished() = 0;
44  virtual void cancel() = 0;
45  virtual void poll() = 0;
46  virtual ~connection_data() {}
47  };
48 
49 private:
51 
53  {
54  public:
55  virtual void process(events::pump_info&) override;
56 
57  pump_monitor(connection_data*& connection);
58 
60 
62 
63  std::atomic_size_t completed_, total_;
64 
65  std::atomic_bool stop_;
66 
67  std::future<void> poller_;
68  } pump_monitor_;
69 
70 public:
72  const std::string& title,
73  const std::string& subtitle);
74 
75 protected:
76  virtual void pre_show(window& window) override;
77 
78  virtual void post_show(window& window) override;
79 
80 private:
81  /**
82  * The subtitle for the dialog.
83  *
84  * This field commonly shows the action in progress eg connecting,
85  * uploading, downloading etc..
86  */
87  std::string subtitle_;
88 
89  virtual const std::string& window_id() const override;
90 };
91 
92 } // namespace dialogs
virtual void post_show(window &window) override
Actions to be taken after the window has been shown.
virtual void pre_show(window &window) override
Actions to be taken before showing the window.
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_
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:64
virtual const std::string & window_id() const override
The id of the window to build.
A simple wrapper class for optional reference types.