The Battle for Wesnoth  1.19.5+dev
network_transmission.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2011 - 2024
3  by Sergey Popov <loonycyborg@gmail.com>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 #pragma once
17 
18 #include "events.hpp"
20 #include "network_asio.hpp"
22 
23 namespace gui2::dialogs
24 {
25 
26 /**
27  * Dialog that tracks network transmissions
28  *
29  * It shows upload/download progress and allows the user
30  * to cancel the transmission.
31  */
33 {
34 public:
35  /** A wrapper of either a wesnothd_connection or a network_asio::connection. */
37  {
38  public:
39  virtual std::size_t total() { return 0; }
40  virtual std::size_t current() { return 0; }
41  virtual bool finished() = 0;
42  virtual void cancel() = 0;
43  virtual void poll() = 0;
44  virtual ~connection_data() {}
45  };
46 
47 private:
49 
51  {
52  public:
54  virtual void process();
55 
57  : connection_(connection), window_()
58  {
59  }
60 
63 
64 public:
65  network_transmission(connection_data& connection,
66  const std::string& title,
67  const std::string& subtitle);
68 
69 protected:
70  virtual void pre_show() override;
71 
72  virtual void post_show() override;
73 
74 private:
75  /**
76  * The subtitle for the dialog.
77  *
78  * This field commonly shows the action in progress eg connecting,
79  * uploading, downloading etc..
80  */
81  std::string subtitle_;
82 
83  virtual const std::string& window_id() const override;
84 };
85 
86 } // namespace dialogs
Abstract base class for all modal dialogs.
A wrapper of either a wesnothd_connection or a network_asio::connection.
Dialog that tracks network transmissions.
std::string subtitle_
The subtitle for the dialog.
network_transmission(connection_data &connection, const std::string &title, const std::string &subtitle)
gui2::dialogs::network_transmission::pump_monitor pump_monitor_
virtual void pre_show() override
Actions to be taken before showing the window.
virtual const std::string & window_id() const override
The ID of the window to build.
virtual void post_show() override
Actions to be taken after the window has been shown.
A simple wrapper class for optional reference types.