30 : QWidget(parent), meta_scan_timer(nullptr), lan_scan_timer(nullptr)
37 ui.connect_password_edit->setEchoMode(QLineEdit::Password);
38 ui.connect_confirm_password_edit->setEchoMode(QLineEdit::Password);
39 ui.connect_password_edit->setDisabled(
true);
40 ui.connect_confirm_password_edit->setDisabled(
true);
42 QStringList servers_list;
43 servers_list <<
_(
"Server Name") <<
_(
"Port") <<
_(
"Version")
44 <<
_(
"Status") <<
Q_(
"?count:Players") <<
_(
"Comment");
45 QStringList server_info;
46 server_info <<
_(
"Name") <<
_(
"Type") <<
_(
"Host") <<
_(
"Nation");
48 ui.lan_widget->setRowCount(0);
49 ui.lan_widget->setColumnCount(servers_list.count());
50 ui.lan_widget->verticalHeader()->setVisible(
false);
51 ui.lan_widget->setAutoScroll(
false);
52 ui.wan_widget->setRowCount(0);
53 ui.wan_widget->setColumnCount(servers_list.count());
54 ui.wan_widget->verticalHeader()->setVisible(
false);
55 ui.wan_widget->setAutoScroll(
false);
56 ui.info_widget->setRowCount(0);
57 ui.info_widget->setColumnCount(server_info.count());
58 ui.info_widget->verticalHeader()->setVisible(
false);
59 ui.lan_widget->setHorizontalHeaderLabels(servers_list);
60 ui.lan_widget->setProperty(
"showGrid",
"false");
61 ui.lan_widget->setProperty(
"selectionBehavior",
"SelectRows");
62 ui.lan_widget->setEditTriggers(QAbstractItemView::NoEditTriggers);
63 ui.lan_widget->setSelectionMode(QAbstractItemView::SingleSelection);
64 ui.wan_widget->setHorizontalHeaderLabels(servers_list);
65 ui.wan_widget->setProperty(
"showGrid",
"false");
66 ui.wan_widget->setProperty(
"selectionBehavior",
"SelectRows");
67 ui.wan_widget->setEditTriggers(QAbstractItemView::NoEditTriggers);
68 ui.wan_widget->setSelectionMode(QAbstractItemView::SingleSelection);
70 connect(
ui.wan_widget->selectionModel(),
71 &QItemSelectionModel::selectionChanged,
this,
74 connect(
ui.lan_widget->selectionModel(),
75 &QItemSelectionModel::selectionChanged,
this,
77 connect(
ui.wan_widget, &QTableWidget::itemDoubleClicked,
this,
79 connect(
ui.lan_widget, &QTableWidget::itemDoubleClicked,
this,
82 ui.info_widget->setHorizontalHeaderLabels(server_info);
83 ui.info_widget->setProperty(
"selectionBehavior",
"SelectRows");
84 ui.info_widget->setEditTriggers(QAbstractItemView::NoEditTriggers);
85 ui.info_widget->setSelectionMode(QAbstractItemView::SingleSelection);
86 ui.info_widget->setProperty(
"showGrid",
"false");
87 ui.info_widget->setAlternatingRowColors(
true);
89 header =
ui.lan_widget->horizontalHeader();
90 header->setSectionResizeMode(0, QHeaderView::Stretch);
91 header->setStretchLastSection(
true);
92 header =
ui.wan_widget->horizontalHeader();
93 header->setSectionResizeMode(0, QHeaderView::Stretch);
94 header->setStretchLastSection(
true);
95 header =
ui.info_widget->horizontalHeader();
96 header->setSectionResizeMode(0, QHeaderView::Stretch);
97 header->setStretchLastSection(
true);
99 ui.lhost->setText(
_(
"Connect"));
100 ui.lport->setText(
_(
"Port"));
101 ui.lname->setText(
_(
"Username"));
102 ui.lpass->setText(
_(
"Password"));
103 ui.lconfpass->setText(
_(
"Confirm Password"));
105 ui.refresh_button->setText(
_(
"Refresh"));
106 ui.cancel_button->setText(
_(
"Cancel"));
107 ui.connect_button->setText(
_(
"Connect"));
108 QObject::connect(
ui.refresh_button, &QAbstractButton::clicked,
this,
110 QObject::connect(
ui.cancel_button, &QPushButton::clicked,
111 [
gui]() { gui->switch_page(PAGE_MAIN); });
112 connect(
ui.connect_button, &QAbstractButton::clicked,
this,
114 connect(
ui.connect_login_edit, &QLineEdit::returnPressed,
this,
116 connect(
ui.connect_password_edit, &QLineEdit::returnPressed,
this,
118 connect(
ui.connect_confirm_password_edit, &QLineEdit::returnPressed,
this,
121 ui.lan_label->setText(
_(
"Internet servers:"));
122 ui.wan_label->setText(
_(
"Local servers:"));
125 ui.connect_port_edit->setText(QString::number(
client_url().port()));
126 ui.connect_login_edit->setText(
client_url().userName());
127 ui.connect_password_edit->setDisabled(
true);
128 ui.connect_confirm_password_edit->setDisabled(
true);
129 setLayout(
ui.gridLayout);
142 ui.connect_password_edit->setText(QLatin1String(
""));
143 ui.connect_password_edit->setDisabled(
true);
144 ui.connect_confirm_password_edit->setText(QLatin1String(
""));
145 ui.connect_confirm_password_edit->setDisabled(
true);
148 ui.connect_password_edit->setText(QLatin1String(
""));
149 ui.connect_confirm_password_edit->setText(QLatin1String(
""));
150 ui.connect_password_edit->setDisabled(
false);
151 ui.connect_confirm_password_edit->setDisabled(
false);
152 ui.connect_password_edit->setFocus(Qt::OtherFocusReason);
155 ui.connect_password_edit->setText(QLatin1String(
""));
156 ui.connect_confirm_password_edit->setText(QLatin1String(
""));
157 ui.connect_password_edit->setDisabled(
false);
158 ui.connect_confirm_password_edit->setDisabled(
true);
159 ui.connect_password_edit->setFocus(Qt::OtherFocusReason);
174 const struct server_list *list)
176 QTableWidget *sel =
nullptr;
177 QString host, portstr;
201 host =
ui.connect_host_edit->text();
202 portstr =
ui.connect_port_edit->text();
203 port = portstr.toInt();
204 old_row_count = sel->rowCount();
205 sel->clearContents();
213 if (old_row_count <= row) {
217 if (pserver->humans >= 0) {
218 fc_snprintf(buf,
sizeof(buf),
"%d", pserver->humans);
220 qstrncpy(buf,
_(
"Unknown"),
sizeof(buf) - 1);
224 tstring = QString::number(tmp);
226 for (
int col = 0; col < 6; col++) {
227 QTableWidgetItem *
item;
229 item =
new QTableWidgetItem();
233 item->setText(pserver->host);
236 item->setText(tstring);
239 item->setText(pserver->version);
242 item->setText(
_(pserver->state));
248 item->setText(pserver->message);
253 sel->setItem(row, col,
item);
256 if (host == pserver->host && port == pserver->port) {
265 while (old_row_count - row > 0) {
266 sel->removeRow(old_row_count - 1);
279 qobject_cast<page_network *>(
king()->pages[PAGE_NETWORK])
280 ->destroy_server_scans();
288 #ifndef __EMSCRIPTEN__
320 #ifndef __EMSCRIPTEN__
348 #ifndef __EMSCRIPTEN__
360 struct server_list *srvrs;
413 struct packet_authentication_reply reply;
416 send_packet_authentication_reply(&
client.
conn, &reply);
431 qCritical(
"Unsupported authentication type %d: %s.", type,
message);
442 struct packet_authentication_reply reply;
446 client_url().setScheme(QStringLiteral(
"fc21"));
447 client_url().setUserName(
ui.connect_login_edit->text());
449 client_url().setPort(
ui.connect_port_edit->text().toInt());
458 client_url().setPassword(
ui.connect_password_edit->text());
460 ==
ui.connect_confirm_password_edit->text()) {
463 send_packet_authentication_reply(&
client.
conn, &reply);
472 client_url().setPassword(
ui.connect_password_edit->text());
475 send_packet_authentication_reply(&
client.
conn, &reply);
489 const QItemSelection &deselected)
492 QModelIndexList indexes = selected.indexes();
495 QTableWidgetItem *
item;
496 QItemSelectionModel *tw;
498 const struct server *pserver =
nullptr;
500 struct server_list *srvrs;
502 if (indexes.isEmpty()) {
506 index = indexes.at(0);
507 ui.connect_host_edit->setText(index.data().toString());
508 index = indexes.at(1);
509 ui.connect_port_edit->setText(index.data().toString());
511 tw = qobject_cast<QItemSelectionModel *>(sender());
513 if (tw ==
ui.lan_widget->selectionModel()) {
514 ui.wan_widget->clearSelection();
516 ui.lan_widget->clearSelection();
519 #ifndef __EMSCRIPTEN__
522 pserver = server_list_get(srvrs, index.row());
524 if (!pserver || !pserver->
players) {
528 ui.info_widget->clearContents();
529 ui.info_widget->setRowCount(0);
530 for (k = 0; k < n; k++) {
531 ui.info_widget->insertRow(k);
532 for (col = 0; col < 4; col++) {
533 item =
new QTableWidgetItem();
550 ui.info_widget->setItem(k, col,
item);
void version_message(const QString &vertext)
Got version message from metaserver.
void output_window_append(const struct ft_color color, const char *featured_text)
Add a line of text to the output ("chatline") window, like puts() would do it in the console.
void set_status_bar(const QString &str, int timeout=20000)
Sets application status bar for given time in miliseconds.
void update_network_lists()
Stop and restart the metaserver and lan server scans.
void update_server_list(enum server_scan_type sstype, const struct server_list *list)
Updates list of servers in network page in proper QTableViews.
void slot_meta_scan()
Executes metaserver scan network.
void slot_lan_scan()
Executes lan scan network.
void slot_connect()
If on the network page, switch page to the login page (with new server and port).
void handle_authentication_req(enum authentication_type type, const char *message)
Configure the dialog depending on what type of authentication request the server is making.
bool check_server_scan(server_scan *scan_data)
This function updates the list of servers every so often.
void slot_selection_changed(const QItemSelection &, const QItemSelection &)
void destroy_server_scans()
Free the server scans.
void set_connection_state(enum connection_state state)
Update network page connection state.
page_network(QWidget *, fc_client *)
QUrl & client_url()
Returns the URL that this client connects to.
int connect_to_server(const QUrl &url, char *errbuf, int errbufsize)
Connect to a freeciv21-server instance – or at least try to.
class fc_client * king()
Return fc_client instance.
const struct ft_color ftc_client
static enum connection_state connection_status
static struct server_scan * meta_scan
void server_scan_error(struct server_scan *scan, const char *message)
Callback function for when there's an error in the server scan.
static struct server_scan * lan_scan
struct server_list * server_scan_get_list(struct server_scan *scan)
Returns the srv_list currently held by the scan (may be nullptr).
struct server_scan * server_scan_begin(enum server_scan_type type, ServerScanErrorFunc error_func)
Creates a new server scan and returns it, or nullptr if impossible.
void server_scan_finish(struct server_scan *scan)
Closes the socket listening on the scan, frees the list of servers, and frees the memory allocated fo...
enum server_scan_type server_scan_get_type(const struct server_scan *scan)
A simple query function to determine the type of a server scan (previously allocated in server_scan_b...
enum server_scan_status server_scan_poll(struct server_scan *scan)
A function to query servers of the server scan.
#define server_list_iterate_end
#define server_list_iterate(serverlist, pserver)
enum server_scan_type type
int fc_snprintf(char *str, size_t n, const char *format,...)
See also fc_utf8_snprintf_trunc(), fc_utf8_snprintf_rep().
size_t fc_strlcpy(char *dest, const char *src, size_t n)
fc_strlcpy() provides utf-8 version of (non-standard) function strlcpy() It is intended as more user-...
#define sz_strlcpy(dest, src)