The Battle for Wesnoth  1.19.5+dev
match_history.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2021 - 2024
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 
18 
20 
21 namespace gui2
22 {
23 class window;
24 
25 namespace dialogs
26 {
28 {
29 public:
30  /**
31  * Creates a dialog to view a player's history 10 games at a time.
32  *
33  * @param player_name The username of the player whose history is being viewed
34  * @param connection A reference to the lobby's network connection to wesnothd
35  * @param wait_for_response Whether to wait a few seconds for a response or not.
36  */
37  mp_match_history(const std::string& player_name, wesnothd_connection& connection, bool wait_for_response = true);
38 
39  /**
40  * The display function.
41  *
42  * See @ref modal_dialog for more information.
43  */
44  static void display(const std::string& player_name, wesnothd_connection& connection, bool wait_for_response = true)
45  {
46  mp_match_history(player_name, connection, wait_for_response).show();
47  }
48 
49 private:
50  virtual const std::string& window_id() const override;
51 
52  virtual void pre_show() override;
53 
54  /**
55  * Requests game history from the server based on the offset.
56  * 11 rows are returned and 10 displayed - the presence of the 11th indicates whether incrementing the offset again would return any data.
57  * A request can time out if the server takes too long to respond so that a failure by the server to respond at all doesn't lock the game indefinitely.
58  *
59  * @return A config containing the game history information or an empty config if either the request times out or returns with an error
60  */
61  const config request_history();
62 
63  /**
64  * Updates the dialog with the information returned by the server.
65  * This is called on dialog open as well as when incrementing or decrementing the offset.
66  *
67  * @return Whether the game history information was returned by the server or not.
68  */
69  bool update_display();
70 
71  /**
72  * Handles changing the selected horizontal listbox item for the specified game history row.
73  */
74  void tab_switch_callback();
75 
76  /** Executes a new search for the entered username */
77  void new_search();
78  /** Increments the offset to use for querying data by 10 and updates the information displayed by the dialog. */
79  void newer_history_offset();
80  /** Decrements the offset to use for querying data by 10 and updates the information displayed by the dialog. */
81  void older_history_offset();
82 
83  /** The username of the player whose history is being viewed */
84  std::string player_name_;
85  /** A reference to the lobby's network connection to wesnothd */
87  /** The offset to start retrieving history data at - should be increments of 10 */
88  int offset_;
89  /**
90  * Whether to wait a few seconds for a response or not.
91  * True for the regular client.
92  * False for the boost unit tests, since otherwise the gui2 test times out waiting for the request to the dummy wesnothd_connection to fail.
93  */
95 };
96 
97 } // namespace dialogs
98 } // namespace gui2
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:172
Abstract base class for all modal dialogs.
const config request_history()
Requests game history from the server based on the offset.
mp_match_history(const std::string &player_name, wesnothd_connection &connection, bool wait_for_response=true)
Creates a dialog to view a player's history 10 games at a time.
int offset_
The offset to start retrieving history data at - should be increments of 10.
virtual const std::string & window_id() const override
The ID of the window to build.
bool wait_for_response_
Whether to wait a few seconds for a response or not.
std::string player_name_
The username of the player whose history is being viewed.
void older_history_offset()
Decrements the offset to use for querying data by 10 and updates the information displayed by the dia...
void new_search()
Executes a new search for the entered username.
void tab_switch_callback()
Handles changing the selected horizontal listbox item for the specified game history row.
wesnothd_connection & connection_
A reference to the lobby's network connection to wesnothd.
void newer_history_offset()
Increments the offset to use for querying data by 10 and updates the information displayed by the dia...
bool update_display()
Updates the dialog with the information returned by the server.
static void display(const std::string &player_name, wesnothd_connection &connection, bool wait_for_response=true)
The display function.
virtual void pre_show() override
Actions to be taken before showing the window.
A class that represents a TCP/IP connection to the wesnothd server.
Various uncategorised dialogs.
Generic file dialog.