Freeciv-3.3: /fast/freeciv/nightly/main/client/gui-gtk-5.0/pages.c Source File

Freeciv-3.3

Loading...
Searching...
No Matches
pages.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12***********************************************************************/
13
14#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18#include <stdio.h>
19#include <time.h>
20
21#include <sys/stat.h>
22
23#include <gtk/gtk.h>
24
25/* utility */
26#include "fcintl.h"
27#include "log.h"
28#include "mem.h"
29#include "shared.h"
30#include "support.h"
31
32/* common */
33#include "chat.h"
34#include "dataio.h"
35#include "game.h"
36#include "mapimg.h"
37#include "version.h"
38
39/* client */
40#include "client_main.h"
41#include "climisc.h"
42#include "clinet.h"
43#include "connectdlg_common.h"
44#include "packhand.h"
45#include "servers.h"
46#include "update_queue.h"
47
48/* client/gui-gtk-5.0 */
49#include "chatline.h"
50#include "connectdlg.h"
51#include "dialogs.h"
52#include "graphics.h"
53#include "gui_main.h"
54#include "gui_stuff.h"
55#include "mapview.h"
56#include "menu.h"
57#include "optiondlg.h"
58#include "plrdlg.h" /* get_flag() */
59#include "repodlgs.h"
60#include "voteinfo_bar.h"
61
62#include "pages.h"
63
64
65 static GtkWidget *scenario_description;
66 static GtkWidget *scenario_authors;
67 static GtkWidget *scenario_filename;
68 static GtkWidget *scenario_version;
69
70 static GtkListStore *load_store, *scenario_store, *meta_store, *lan_store;
71
72 static GtkListStore *server_playerlist_store;
73 static GtkWidget *server_playerlist_view;
74
75 static GtkTreeSelection *load_selection, *scenario_selection;
76 static GtkTreeSelection *meta_selection, *lan_selection;
77
78/* This is the current page. Invalid value at start, to be sure that it won't
79 * be catch throught a switch() statement. */
80 static enum client_pages current_page = -1;
81
82struct server_scan_timer_data
83{
84 struct server_scan *scan;
85 guint timer;
86};
87
88 static struct server_scan_timer_data meta_scan = { NULL, 0 };
89 static struct server_scan_timer_data lan_scan = { NULL, 0 };
90
91 static GtkWidget *statusbar, *statusbar_frame;
92 static GQueue *statusbar_queue;
93 static guint statusbar_timer = 0;
94
95 static GtkWidget *ruleset_combo;
96
97 static GtkWidget *conn_popover = NULL;
98
99 static bool holding_srv_list_mutex = FALSE;
100
101static void connection_state_reset(void);
102
103/**********************************************************************/
106 static void start_new_game_callback(GtkWidget *w, gpointer data)
107{
108 if (!is_server_running()) {
109 client_start_server();
110
111 /* Saved settings are sent in client/options.c
112 * resend_desired_settable_options() */
113 }
114}
115
116/**********************************************************************/
119 static void start_scenario_callback(GtkWidget *w, gpointer data)
120{
121 output_window_append(ftc_client, _("Compiling scenario list."));
122 client_start_server_and_set_page(PAGE_SCENARIO);
123}
124
125/**********************************************************************/
128 static void load_saved_game_callback(GtkWidget *w, gpointer data)
129{
130 client_start_server_and_set_page(PAGE_LOAD);
131}
132
133/**********************************************************************/
136 static void connect_network_game_callback(GtkWidget *w, gpointer data)
137{
138 connection_state_reset();
139 set_client_page(PAGE_NETWORK);
140}
141
142/**********************************************************************/
145 static void open_settings(void)
146{
147 option_dialog_popup(_("Set local options"), client_optset);
148}
149
150/**********************************************************************/
153 static void main_callback(GtkWidget *w, gpointer data)
154{
155 enum client_pages page = PAGE_MAIN;
156
157 if (client.conn.used) {
158 disconnect_from_server(TRUE);
159 }
160 if (page != get_client_page()) {
161 set_client_page(page);
162 }
163}
164
165/**********************************************************************/
168 static void intro_expose(GtkDrawingArea *w, cairo_t *cr,
169 int width, int height, gpointer data)
170{
171 static PangoLayout *layout;
172 static int pwidth, pheight;
173 static bool left = FALSE;
174 GtkAllocation allocation;
175 struct sprite *intro = (struct sprite *)data;
176
177 cairo_set_source_surface(cr, intro->surface, 0, 0);
178 cairo_paint(cr);
179
180 if (!layout) {
181 char msgbuf[128];
182 const char *rev_ver;
183
184 layout = pango_layout_new(gtk_widget_create_pango_context(GTK_WIDGET(w)));
185 pango_layout_set_font_description(layout,
186 pango_font_description_from_string("Sans Bold 10"));
187
188 rev_ver = fc_git_revision();
189
190 if (rev_ver == NULL) {
191 /* TRANS: "version 2.6.0, gui-gtk-3.22 client" */
192 fc_snprintf(msgbuf, sizeof(msgbuf), _("%s%s, %s client"),
193 word_version(), VERSION_STRING, client_string);
194 } else {
195 /* TRANS: "version 2.6.0
196 * commit: [modified] <git commit id>
197 * gui-gtk-3.22 client" */
198 fc_snprintf(msgbuf, sizeof(msgbuf), _("%s%s\ncommit: %s\n%s client"),
199 word_version(), VERSION_STRING, rev_ver, client_string);
200 left = TRUE;
201 }
202 pango_layout_set_text(layout, msgbuf, -1);
203
204 pango_layout_get_pixel_size(layout, &pwidth, &pheight);
205 }
206 gtk_widget_get_allocation(GTK_WIDGET(w), &allocation);
207
208 cairo_set_source_rgb(cr, 0, 0, 0);
209 cairo_move_to(cr, left ? 4 : allocation.width - pwidth - 3,
210 allocation.height - pheight - 3);
211 pango_cairo_show_layout(cr, layout);
212
213 cairo_set_source_rgb(cr, 1, 1, 1);
214 cairo_move_to(cr, left ? 3 : allocation.width - pwidth - 4,
215 allocation.height - pheight - 4);
216 pango_cairo_show_layout(cr, layout);
217}
218
219/**********************************************************************/
222 static void intro_free(GtkWidget *w, gpointer *data)
223{
224 struct sprite *intro = (struct sprite *)data;
225
226 free_sprite(intro);
227}
228
229/**********************************************************************/
232 GtkWidget *create_main_page(void)
233{
234 GtkWidget *widget, *vgrid, *frame, *darea, *button, *table;
235 GtkSizeGroup *size;
236 struct sprite *intro_in, *intro;
237 int width, height;
238 int sh;
239 int space_needed;
240 int grid_row = 0;
241
242 size = gtk_size_group_new(GTK_SIZE_GROUP_BOTH);
243
244 vgrid = gtk_grid_new();
245 gtk_orientable_set_orientation(GTK_ORIENTABLE(vgrid),
246 GTK_ORIENTATION_VERTICAL);
247 widget = vgrid;
248
249 frame = gtk_frame_new(NULL);
250 gtk_widget_set_margin_bottom(frame, 18);
251 gtk_widget_set_margin_end(frame, 18);
252 gtk_widget_set_margin_start(frame, 18);
253 gtk_widget_set_margin_top(frame, 18);
254 gtk_widget_set_halign(frame, GTK_ALIGN_CENTER);
255 gtk_grid_attach(GTK_GRID(vgrid), frame, 0, grid_row++, 1, 1);
256
257 intro_in = load_gfxfile(tileset_main_intro_filename(tileset), FALSE);
258 get_sprite_dimensions(intro_in, &width, &height);
259 sh = screen_height();
260
261 if (sh <= 0) {
262 /* Assume some minimum height */
263 sh = 600;
264 }
265
266 space_needed = 250;
267#if IS_BETA_VERSION || IS_DEVEL_VERSION
268 /* Alpha or Beta notice takes extra space */
269 space_needed += 50;
270#endif
271
272 if (sh - height < space_needed) {
273 float scale;
274
275 if (sh < (space_needed + 0.2 * height)) {
276 /* Screen is simply too small, use minimum scale */
277 scale = 0.2;
278 } else {
279 scale = (double)(sh - space_needed) / height;
280 }
281 height *= scale;
282 width *= scale;
283 intro = sprite_scale(intro_in, width, height);
284 free_sprite(intro_in);
285 } else {
286 intro = intro_in;
287 }
288 darea = gtk_drawing_area_new();
289 gtk_widget_set_size_request(darea, width, height);
290 gtk_drawing_area_set_draw_func(GTK_DRAWING_AREA(darea),
291 intro_expose, intro, NULL);
292 g_signal_connect(widget, "destroy",
293 G_CALLBACK(intro_free), intro);
294 gtk_frame_set_child(GTK_FRAME(frame), darea);
295
296#if IS_BETA_VERSION || IS_DEVEL_VERSION
297 {
298 GtkWidget *label;
299
300 label = gtk_label_new(unstable_message());
301 gtk_widget_set_name(label, "beta_label");
302 gtk_widget_set_halign(label, GTK_ALIGN_CENTER);
303 gtk_widget_set_valign(label, GTK_ALIGN_CENTER);
304 gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_CENTER);
305 gtk_grid_attach(GTK_GRID(vgrid), label, 0, grid_row++, 1, 1);
306 }
307#endif /* IS_BETA_VERSION || IS_DEVEL_VERSION */
308
309 table = gtk_grid_new();
310 gtk_widget_set_margin_bottom(table, 12);
311 gtk_widget_set_margin_end(table, 12);
312 gtk_widget_set_margin_start(table, 12);
313 gtk_widget_set_margin_top(table, 12);
314 gtk_widget_set_hexpand(table, TRUE);
315 gtk_widget_set_vexpand(table, TRUE);
316 gtk_widget_set_halign(table, GTK_ALIGN_CENTER);
317 gtk_widget_set_valign(table, GTK_ALIGN_CENTER);
318
319 gtk_grid_set_row_spacing(GTK_GRID(table), 8);
320 gtk_grid_set_column_spacing(GTK_GRID(table), 18);
321 gtk_grid_attach(GTK_GRID(vgrid), table, 0, grid_row++, 1, 1);
322
323 button = gtk_button_new_with_mnemonic(_("Start _New Game"));
324 gtk_size_group_add_widget(size, button);
325 gtk_grid_attach(GTK_GRID(table), button, 0, 0, 1, 1);
326 g_signal_connect(button, "clicked",
327 G_CALLBACK(start_new_game_callback), NULL);
328
329 button = gtk_button_new_with_mnemonic(_("Start _Scenario Game"));
330 gtk_size_group_add_widget(size, button);
331 gtk_grid_attach(GTK_GRID(table), button, 0, 1, 1, 1);
332 g_signal_connect(button, "clicked",
333 G_CALLBACK(start_scenario_callback), NULL);
334
335 button = gtk_button_new_with_mnemonic(_("_Load Saved Game"));
336 gtk_size_group_add_widget(size, button);
337 gtk_grid_attach(GTK_GRID(table), button, 0, 2, 1, 1);
338 g_signal_connect(button, "clicked",
339 G_CALLBACK(load_saved_game_callback), NULL);
340
341 button = gtk_button_new_with_mnemonic(_("C_onnect to Network Game"));
342 gtk_size_group_add_widget(size, button);
343 gtk_grid_attach(GTK_GRID(table), button, 1, 0, 1, 1);
344 g_signal_connect(button, "clicked",
345 G_CALLBACK(connect_network_game_callback), NULL);
346
347 button = gtk_button_new_with_mnemonic(_("Client Settings"));
348 gtk_size_group_add_widget(size, button);
349 gtk_grid_attach(GTK_GRID(table), button, 1, 1, 1, 1);
350 g_signal_connect(button, "clicked", open_settings, NULL);
351
352 button = icon_label_button_new("application-exit", _("E_xit"));
353 gtk_size_group_add_widget(size, button);
354 g_object_unref(size);
355 gtk_grid_attach(GTK_GRID(table), button, 1, 2, 1, 1);
356 g_signal_connect(button, "clicked",
357 G_CALLBACK(quit_gtk_main), NULL);
358
359 return widget;
360}
361
362/****************************************************************************
363 GENERIC SAVE DIALOG
364****************************************************************************/
365 typedef void (*save_dialog_action_fn_t) (const char *filename);
366typedef struct fileinfo_list * (*save_dialog_files_fn_t) (void);
367
368struct save_dialog {
369 GtkDialog *shell;
370 GtkTreeView *tree_view;
371 GtkEntry *entry;
372 save_dialog_action_fn_t action;
373 save_dialog_files_fn_t files;
374};
375
376 enum save_dialog_columns {
377 SD_COL_PRETTY_NAME = 0,
378 SD_COL_FULL_PATH,
379
380 SD_COL_NUM
381};
382
383 enum save_dialog_response {
384 SD_RES_BROWSE,
385 SD_RES_DELETE,
386 SD_RES_SAVE
387};
388
389/**********************************************************************/
392 static inline GtkListStore *save_dialog_store_new(void)
393{
394 return gtk_list_store_new(SD_COL_NUM,
395 G_TYPE_STRING, /* SD_COL_PRETTY_NAME */
396 G_TYPE_STRING); /* SD_COL_FULL_PATH */
397}
398
399/**********************************************************************/
402 static void save_dialog_store_update(GtkListStore *store,
403 const struct fileinfo_list *files)
404{
405 GtkTreeIter iter;
406
407 gtk_list_store_clear(store);
408 fileinfo_list_iterate(files, pfile) {
409 gtk_list_store_append(store, &iter);
410 gtk_list_store_set(store, &iter,
411 SD_COL_PRETTY_NAME, pfile->name,
412 SD_COL_FULL_PATH, pfile->fullname,
413 -1);
414 } fileinfo_list_iterate_end;
415}
416
417/**********************************************************************/
420 static void save_dialog_update(struct save_dialog *pdialog)
421{
422 struct fileinfo_list *files;
423
424 fc_assert_ret(NULL != pdialog);
425
426 /* Update the store. */
427 files = pdialog->files();
428 save_dialog_store_update(GTK_LIST_STORE
429 (gtk_tree_view_get_model(pdialog->tree_view)),
430 files);
431 fileinfo_list_destroy(files);
432}
433
434/**********************************************************************/
437 static void save_dialog_file_chooser_callback(GtkWidget *widget,
438 gint response, gpointer data)
439{
440 if (response == GTK_RESPONSE_OK) {
441 save_dialog_action_fn_t action = data;
442 GFile *file = gtk_file_chooser_get_file(GTK_FILE_CHOOSER(widget));
443
444 if (file != NULL) {
445 gchar *filename = g_file_get_parse_name(file);
446
447 if (NULL != filename) {
448 action(filename);
449 g_free(filename);
450 }
451
452 g_object_unref(file);
453 }
454 }
455
456 gtk_window_destroy(GTK_WINDOW(widget));
457}
458
459/**********************************************************************/
462 static void save_dialog_file_chooser_popup(const char *title,
463 GtkFileChooserAction action,
464 save_dialog_action_fn_t cb)
465{
466 GtkWidget *filechoose;
467
468 /* Create the chooser */
469 filechoose = gtk_file_chooser_dialog_new(title, GTK_WINDOW(toplevel), action,
470 _("_Cancel"), GTK_RESPONSE_CANCEL,
471 (action == GTK_FILE_CHOOSER_ACTION_SAVE) ?
472 _("_Save") : _("_Open"),
473 GTK_RESPONSE_OK, NULL);
474 setup_dialog(filechoose, toplevel);
475
476 g_signal_connect(filechoose, "response",
477 G_CALLBACK(save_dialog_file_chooser_callback), cb);
478
479 /* Display that dialog */
480 gtk_window_present(GTK_WINDOW(filechoose));
481}
482
483/**********************************************************************/
486 static void save_dialog_response_callback(GtkWidget *w, gint response,
487 gpointer data)
488{
489 struct save_dialog *pdialog = data;
490
491 switch (response) {
492 case SD_RES_BROWSE:
493 save_dialog_file_chooser_popup(_("Select Location to Save"),
494 GTK_FILE_CHOOSER_ACTION_SAVE,
495 pdialog->action);
496 break;
497 case SD_RES_DELETE:
498 {
499 GtkTreeSelection *selection;
500 GtkTreeModel *model;
501 GtkTreeIter iter;
502 const gchar *full_path;
503
504 selection = gtk_tree_view_get_selection(pdialog->tree_view);
505 if (!gtk_tree_selection_get_selected(selection, &model, &iter)) {
506 return;
507 }
508
509 gtk_tree_model_get(model, &iter, SD_COL_FULL_PATH, &full_path, -1);
510 fc_remove(full_path);
511 save_dialog_update(pdialog);
512 }
513 return;
514 case SD_RES_SAVE:
515 {
516 const char *text = gtk_entry_buffer_get_text(gtk_entry_get_buffer(pdialog->entry));
517 gchar *filename = g_filename_from_utf8(text, -1, NULL, NULL, NULL);
518
519 if (NULL == filename) {
520 return;
521 }
522 pdialog->action(filename);
523 g_free(filename);
524 }
525 break;
526 default:
527 break;
528 }
529
530 gtk_window_destroy(GTK_WINDOW(pdialog->shell));
531}
532
533/**********************************************************************/
536 static void save_dialog_row_callback(GtkTreeView *tree_view,
537 GtkTreePath *path,
538 GtkTreeViewColumn *column,
539 gpointer data)
540{
541 save_dialog_response_callback(NULL, SD_RES_SAVE, data);
542}
543
544/**********************************************************************/
547 static void save_dialog_entry_callback(GtkEntry *entry, gpointer data)
548{
549 save_dialog_response_callback(NULL, SD_RES_SAVE, data);
550}
551
552/**********************************************************************/
555 static void save_dialog_list_callback(GtkTreeSelection *selection,
556 gpointer data)
557{
558 struct save_dialog *pdialog = data;
559 GtkTreeModel *model;
560 GtkTreeIter iter;
561 const gchar *filename;
562
563 if (!gtk_tree_selection_get_selected(selection, &model, &iter)) {
564 gtk_dialog_set_response_sensitive(pdialog->shell, SD_RES_DELETE, FALSE);
565 return;
566 }
567
568 gtk_dialog_set_response_sensitive(pdialog->shell, SD_RES_DELETE, TRUE);
569 gtk_tree_model_get(model, &iter, SD_COL_PRETTY_NAME, &filename, -1);
570 gtk_entry_buffer_set_text(gtk_entry_get_buffer(pdialog->entry), filename, -1);
571}
572
573/**********************************************************************/
576 static GtkWidget *save_dialog_new(const char *title, const char *savelabel,
577 const char *savefilelabel,
578 save_dialog_action_fn_t action,
579 save_dialog_files_fn_t files)
580{
581 GtkWidget *shell, *sbox, *sw, *label, *view, *entry;
582 GtkBox *vbox;
583 GtkListStore *store;
584 GtkCellRenderer *rend;
585 GtkTreeSelection *selection;
586 struct save_dialog *pdialog;
587
588 fc_assert_ret_val(NULL != action, NULL);
589 fc_assert_ret_val(NULL != files, NULL);
590
591 /* Save dialog structure. */
592 pdialog = fc_malloc(sizeof(*pdialog));
593 pdialog->action = action;
594 pdialog->files = files;
595
596 /* Shell. */
597 shell = gtk_dialog_new_with_buttons(title, NULL, 0,
598 _("_Browse..."), SD_RES_BROWSE,
599 _("_Delete"), SD_RES_DELETE,
600 _("_Cancel"), GTK_RESPONSE_CANCEL,
601 _("_Save"), SD_RES_SAVE,
602 NULL);
603 g_object_set_data_full(G_OBJECT(shell), "save_dialog", pdialog,
604 (GDestroyNotify) free);
605 gtk_dialog_set_default_response(GTK_DIALOG(shell), GTK_RESPONSE_CANCEL);
606 gtk_dialog_set_response_sensitive(GTK_DIALOG(shell), SD_RES_DELETE, FALSE);
607 setup_dialog(shell, toplevel);
608 g_signal_connect(shell, "response",
609 G_CALLBACK(save_dialog_response_callback), pdialog);
610 pdialog->shell = GTK_DIALOG(shell);
611 vbox = GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(shell)));
612
613 /* Tree view. */
614 store = save_dialog_store_new();
615 view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
616 gtk_widget_set_hexpand(view, TRUE);
617 gtk_widget_set_vexpand(view, TRUE);
618 g_object_unref(store);
619 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view), FALSE);
620 g_signal_connect(view, "row-activated",
621 G_CALLBACK(save_dialog_row_callback), pdialog);
622 pdialog->tree_view = GTK_TREE_VIEW(view);
623
624 sbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 2);
625 gtk_box_append(vbox, sbox);
626
627 label = g_object_new(GTK_TYPE_LABEL,
628 "use-underline", TRUE,
629 "mnemonic-widget", view,
630 "label", savelabel,
631 "xalign", 0.0,
632 "yalign", 0.5,
633 NULL);
634 gtk_box_append(GTK_BOX(sbox), label);
635
636 sw = gtk_scrolled_window_new();
637 gtk_scrolled_window_set_min_content_width(GTK_SCROLLED_WINDOW(sw), 300);
638 gtk_scrolled_window_set_min_content_height(GTK_SCROLLED_WINDOW(sw), 300);
639 gtk_scrolled_window_set_has_frame(GTK_SCROLLED_WINDOW(sw), TRUE);
640 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
641 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
642 gtk_scrolled_window_set_child(GTK_SCROLLED_WINDOW(sw), view);
643 gtk_box_append(GTK_BOX(sbox), sw);
644
645 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
646 gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE);
647 g_signal_connect(selection, "changed",
648 G_CALLBACK(save_dialog_list_callback), pdialog);
649
650 rend = gtk_cell_renderer_text_new();
651 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
652 -1, NULL, rend, "text",
653 SD_COL_PRETTY_NAME, NULL);
654
655 /* Entry. */
656 entry = gtk_entry_new();
657 gtk_widget_set_hexpand(entry, TRUE);
658 g_signal_connect(entry, "activate",
659 G_CALLBACK(save_dialog_entry_callback), pdialog);
660 pdialog->entry = GTK_ENTRY(entry);
661
662 sbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 2);
663 gtk_widget_set_margin_bottom(sbox, 12);
664 gtk_widget_set_margin_end(sbox, 12);
665 gtk_widget_set_margin_start(sbox, 12);
666 gtk_widget_set_margin_top(sbox, 12);
667
668 label = g_object_new(GTK_TYPE_LABEL,
669 "use-underline", TRUE,
670 "mnemonic-widget", entry,
671 "label", savefilelabel,
672 "xalign", 0.0,
673 "yalign", 0.5,
674 NULL);
675 gtk_box_append(GTK_BOX(sbox), label);
676
677 gtk_box_append(GTK_BOX(sbox), entry);
678 gtk_box_append(vbox, sbox);
679
680 save_dialog_update(pdialog);
681 gtk_window_set_focus(GTK_WINDOW(shell), entry);
682 gtk_widget_set_visible(GTK_WIDGET(vbox), TRUE);
683
684 return shell;
685}
686
687/****************************************************************************
688 NETWORK PAGE
689****************************************************************************/
690 static GtkWidget *network_login_label, *network_login;
691 static GtkWidget *network_host_label, *network_host;
692 static GtkWidget *network_port_label, *network_port;
693 static GtkWidget *network_password_label, *network_password;
694 static GtkWidget *network_confirm_password_label, *network_confirm_password;
695
696/**********************************************************************/
699 static void update_server_list(enum server_scan_type sstype,
700 const struct server_list *list)
701{
702 GtkTreeSelection *sel = NULL;
703 GtkTreeView *view;
704 GtkTreeIter it;
705 GtkListStore *store;
706 const gchar *host, *portstr;
707 int port;
708
709 switch (sstype) {
710 case SERVER_SCAN_LOCAL:
711 sel = lan_selection;
712 break;
713 case SERVER_SCAN_GLOBAL:
714 sel = meta_selection;
715 break;
716 default:
717 break;
718 }
719
720 if (!sel) {
721 return;
722 }
723
724 view = gtk_tree_selection_get_tree_view(sel);
725 store = GTK_LIST_STORE(gtk_tree_view_get_model(view));
726 gtk_list_store_clear(store);
727
728 if (!list) {
729 return;
730 }
731
732 host = gtk_entry_buffer_get_text(gtk_entry_get_buffer(GTK_ENTRY(network_host)));
733 portstr = gtk_entry_buffer_get_text(gtk_entry_get_buffer(GTK_ENTRY(network_port)));
734 port = atoi(portstr);
735
736 server_list_iterate(list, pserver) {
737 char buf[35];
738
739 if (pserver->humans >= 0) {
740 fc_snprintf(buf, sizeof(buf), "%d", pserver->humans);
741 } else {
742 sz_strlcpy(buf, _("Unknown"));
743 }
744 gtk_list_store_append(store, &it);
745 gtk_list_store_set(store, &it,
746 0, pserver->host,
747 1, pserver->port,
748 2, pserver->version,
749 3, _(pserver->state),
750 4, pserver->nplayers,
751 5, buf,
752 6, pserver->message,
753 -1);
754 if (strcmp(host, pserver->host) == 0 && port == pserver->port) {
755 gtk_tree_selection_select_iter(sel, &it);
756 }
757 } server_list_iterate_end;
758}
759
760/**********************************************************************/
763 void destroy_server_scans(void)
764{
765 if (meta_scan.scan) {
766 server_scan_finish(meta_scan.scan);
767 meta_scan.scan = NULL;
768 }
769 if (meta_scan.timer != 0) {
770 g_source_remove(meta_scan.timer);
771 meta_scan.timer = 0;
772 }
773 if (lan_scan.scan) {
774 server_scan_finish(lan_scan.scan);
775 lan_scan.scan = NULL;
776 }
777 if (lan_scan.timer != 0) {
778 g_source_remove(lan_scan.timer);
779 lan_scan.timer = 0;
780 }
781}
782
783/**********************************************************************/
786 static gboolean check_server_scan(gpointer data)
787{
788 struct server_scan_timer_data *scan_data = data;
789 struct server_scan *scan = scan_data->scan;
790 enum server_scan_status stat;
791
792 if (!scan) {
793 return FALSE;
794 }
795
796 stat = server_scan_poll(scan);
797 if (stat >= SCAN_STATUS_PARTIAL) {
798 enum server_scan_type type;
799 struct srv_list *srvrs;
800
801 type = server_scan_get_type(scan);
802 srvrs = server_scan_get_list(scan);
803 fc_mutex_allocate(&srvrs->mutex);
804 holding_srv_list_mutex = TRUE;
805 update_server_list(type, srvrs->servers);
806 holding_srv_list_mutex = FALSE;
807 fc_mutex_release(&srvrs->mutex);
808 }
809
810 if (stat == SCAN_STATUS_ERROR || stat == SCAN_STATUS_DONE) {
811 scan_data->timer = 0;
812 return FALSE;
813 }
814 return TRUE;
815}
816
817/**********************************************************************/
820 static void server_scan_error(struct server_scan *scan,
821 const char *message)
822{
823 output_window_append(ftc_client, message);
824 log_error("%s", message);
825
826 /* Main thread will finalize the scan later (or even concurrently) -
827 * do not do anything here to cause double free or raze condition. */
828}
829
830/**********************************************************************/
833 static void update_network_lists(void)
834{
835 destroy_server_scans();
836
837 meta_scan.scan = server_scan_begin(SERVER_SCAN_GLOBAL, server_scan_error);
838 meta_scan.timer = g_timeout_add(200, check_server_scan, &meta_scan);
839
840 lan_scan.scan = server_scan_begin(SERVER_SCAN_LOCAL, server_scan_error);
841 lan_scan.timer = g_timeout_add(500, check_server_scan, &lan_scan);
842}
843
844/**************************************************************************
845 Network connection state defines.
846**************************************************************************/
847 enum connection_state {
848 LOGIN_TYPE,
849 NEW_PASSWORD_TYPE,
850 ENTER_PASSWORD_TYPE,
851 WAITING_TYPE
852};
853
854 static enum connection_state connection_status;
855
856/**********************************************************************/
859 static gboolean update_network_statusbar(gpointer data)
860{
861 if (!g_queue_is_empty(statusbar_queue)) {
862 char *txt;
863
864 txt = g_queue_pop_head(statusbar_queue);
865 gtk_label_set_text(GTK_LABEL(statusbar), txt);
866 free(txt);
867 }
868
869 return TRUE;
870}
871
872/**********************************************************************/
875 static void clear_network_statusbar(void)
876{
877 while (!g_queue_is_empty(statusbar_queue)) {
878 char *txt;
879
880 txt = g_queue_pop_head(statusbar_queue);
881 free(txt);
882 }
883
884 gtk_label_set_text(GTK_LABEL(statusbar), "");
885}
886
887/**********************************************************************/
890 void append_network_statusbar(const char *text, bool force)
891{
892 if (gtk_widget_get_visible(statusbar_frame)) {
893 if (force) {
894 clear_network_statusbar();
895 gtk_label_set_text(GTK_LABEL(statusbar), text);
896 } else {
897 g_queue_push_tail(statusbar_queue, fc_strdup(text));
898 }
899 }
900}
901
902/**********************************************************************/
905 GtkWidget *create_statusbar(void)
906{
907 statusbar_frame = gtk_frame_new(NULL);
908
909 statusbar = gtk_label_new("");
910 gtk_widget_set_margin_start(statusbar, 2);
911 gtk_widget_set_margin_end(statusbar, 2);
912 gtk_widget_set_margin_top(statusbar, 2);
913 gtk_widget_set_margin_bottom(statusbar, 2);
914 gtk_frame_set_child(GTK_FRAME(statusbar_frame), statusbar);
915
916 statusbar_queue = g_queue_new();
917 statusbar_timer = g_timeout_add(2000, update_network_statusbar, NULL);
918
919 return statusbar_frame;
920}
921
922/**********************************************************************/
925 static void set_connection_state(enum connection_state state)
926{
927 switch (state) {
928 case LOGIN_TYPE:
929 append_network_statusbar("", FALSE);
930
931 gtk_entry_buffer_set_text(gtk_entry_get_buffer(GTK_ENTRY(network_password)),
932 "", -1);
933 gtk_entry_buffer_set_text(gtk_entry_get_buffer(GTK_ENTRY(network_confirm_password)),
934 "", -1);
935
936 gtk_widget_set_sensitive(network_host, TRUE);
937 gtk_widget_set_sensitive(network_port, TRUE);
938 gtk_widget_set_sensitive(network_login, TRUE);
939 gtk_widget_set_sensitive(network_password_label, FALSE);
940 gtk_label_set_markup_with_mnemonic(GTK_LABEL(network_password_label), _("Pass_word:"));
941 gtk_widget_set_sensitive(network_password, FALSE);
942 gtk_widget_set_sensitive(network_confirm_password_label, FALSE);
943 gtk_widget_set_sensitive(network_confirm_password, FALSE);
944 break;
945 case NEW_PASSWORD_TYPE:
946 set_client_page(PAGE_NETWORK);
947 gtk_entry_buffer_set_text(gtk_entry_get_buffer(GTK_ENTRY(network_password)), "", -1);
948 gtk_entry_buffer_set_text(gtk_entry_get_buffer(GTK_ENTRY(network_confirm_password)),
949 "", -1);
950
951 gtk_widget_set_sensitive(network_host, FALSE);
952 gtk_widget_set_sensitive(network_port, FALSE);
953 gtk_widget_set_sensitive(network_login, FALSE);
954 gtk_widget_set_sensitive(network_password_label, TRUE);
955 gtk_label_set_markup_with_mnemonic(GTK_LABEL(network_password_label), _("New Pass_word:"));
956 gtk_widget_set_sensitive(network_password, TRUE);
957 gtk_widget_set_sensitive(network_confirm_password_label, TRUE);
958 gtk_widget_set_sensitive(network_confirm_password, TRUE);
959
960 gtk_widget_grab_focus(network_password);
961 break;
962 case ENTER_PASSWORD_TYPE:
963 set_client_page(PAGE_NETWORK);
964 gtk_entry_buffer_set_text(gtk_entry_get_buffer(GTK_ENTRY(network_password)), "", -1);
965 gtk_entry_buffer_set_text(gtk_entry_get_buffer(GTK_ENTRY(network_confirm_password)),
966 "", -1);
967
968 gtk_widget_set_sensitive(network_host, FALSE);
969 gtk_widget_set_sensitive(network_port, FALSE);
970 gtk_widget_set_sensitive(network_login, FALSE);
971 gtk_widget_set_sensitive(network_password_label, TRUE);
972 gtk_label_set_markup_with_mnemonic(GTK_LABEL(network_password_label), _("Pass_word:"));
973 gtk_widget_set_sensitive(network_password, TRUE);
974 gtk_widget_set_sensitive(network_confirm_password_label, FALSE);
975 gtk_widget_set_sensitive(network_confirm_password, FALSE);
976
977 gtk_widget_grab_focus(network_password);
978 break;
979 case WAITING_TYPE:
980 append_network_statusbar("", TRUE);
981
982 gtk_widget_set_sensitive(network_login, FALSE);
983 gtk_widget_set_sensitive(network_password_label, FALSE);
984 gtk_label_set_markup_with_mnemonic(GTK_LABEL(network_password_label), _("Pass_word:"));
985 gtk_widget_set_sensitive(network_password, FALSE);
986 gtk_widget_set_sensitive(network_confirm_password_label, FALSE);
987 gtk_widget_set_sensitive(network_confirm_password, FALSE);
988 break;
989 }
990
991 connection_status = state;
992}
993
994/**********************************************************************/
997 static void connection_state_reset(void)
998{
999 set_connection_state(LOGIN_TYPE);
1000}
1001
1002/**********************************************************************/
1006 void handle_authentication_req(enum authentication_type type,
1007 const char *message)
1008{
1009 append_network_statusbar(message, TRUE);
1010
1011 switch (type) {
1012 case AUTH_NEWUSER_FIRST:
1013 case AUTH_NEWUSER_RETRY:
1014 set_connection_state(NEW_PASSWORD_TYPE);
1015 return;
1016 case AUTH_LOGIN_FIRST:
1017 /* if we magically have a password already present in 'fc_password'
1018 * then, use that and skip the password entry dialog */
1019 if (fc_password[0] != '\0') {
1020 struct packet_authentication_reply reply;
1021
1022 sz_strlcpy(reply.password, fc_password);
1023 send_packet_authentication_reply(&client.conn, &reply);
1024 return;
1025 } else {
1026 set_connection_state(ENTER_PASSWORD_TYPE);
1027 }
1028 return;
1029 case AUTH_LOGIN_RETRY:
1030 set_connection_state(ENTER_PASSWORD_TYPE);
1031 return;
1032 }
1033
1034 log_error("Unsupported authentication type %d: %s.", type, message);
1035}
1036
1037/**********************************************************************/
1042 static void connect_callback(GtkWidget *w, gpointer data)
1043{
1044 char errbuf [512];
1045 struct packet_authentication_reply reply;
1046
1047 switch (connection_status) {
1048 case LOGIN_TYPE:
1049 sz_strlcpy(user_name,
1050 gtk_entry_buffer_get_text(gtk_entry_get_buffer(GTK_ENTRY(network_login))));
1051 sz_strlcpy(server_host,
1052 gtk_entry_buffer_get_text(gtk_entry_get_buffer(GTK_ENTRY(network_host))));
1053 server_port = atoi(gtk_entry_buffer_get_text(gtk_entry_get_buffer(GTK_ENTRY(network_port))));
1054
1055 if (connect_to_server(user_name, server_host, server_port,
1056 errbuf, sizeof(errbuf)) != -1) {
1057 } else {
1058 append_network_statusbar(errbuf, TRUE);
1059
1060 output_window_append(ftc_client, errbuf);
1061 }
1062 return;
1063 case NEW_PASSWORD_TYPE:
1064 if (w != network_password) {
1065 sz_strlcpy(fc_password,
1066 gtk_entry_buffer_get_text(gtk_entry_get_buffer(GTK_ENTRY(network_password))));
1067 sz_strlcpy(reply.password,
1068 gtk_entry_buffer_get_text(gtk_entry_get_buffer(GTK_ENTRY(network_confirm_password))));
1069 if (!fc_strncmp(reply.password, fc_password, MAX_LEN_NAME)) {
1070 fc_password[0] = '\0';
1071 send_packet_authentication_reply(&client.conn, &reply);
1072
1073 set_connection_state(WAITING_TYPE);
1074 } else {
1075 append_network_statusbar(_("Passwords don't match, enter password."),
1076 TRUE);
1077
1078 set_connection_state(NEW_PASSWORD_TYPE);
1079 }
1080 }
1081 return;
1082 case ENTER_PASSWORD_TYPE:
1083 sz_strlcpy(reply.password,
1084 gtk_entry_buffer_get_text(gtk_entry_get_buffer(GTK_ENTRY(network_password))));
1085 send_packet_authentication_reply(&client.conn, &reply);
1086
1087 set_connection_state(WAITING_TYPE);
1088 return;
1089 case WAITING_TYPE:
1090 return;
1091 }
1092
1093 log_error("Unsupported connection status: %d", connection_status);
1094}
1095
1096/**********************************************************************/
1099 static void network_activate_callback(GtkTreeView *view,
1100 GtkTreePath *arg1,
1101 GtkTreeViewColumn *arg2,
1102 gpointer data)
1103{
1104 connect_callback(NULL, data);
1105}
1106
1107/**********************************************************************/
1111 static void update_server_playerlist(const struct server *pserver)
1112{
1113 GtkListStore *store;
1114 GtkTreeIter iter;
1115 int n, i;
1116
1117 store = server_playerlist_store;
1118 fc_assert_ret(store != NULL);
1119
1120 gtk_list_store_clear(store);
1121 if (!pserver || !pserver->players) {
1122 return;
1123 }
1124
1125 n = pserver->nplayers;
1126 for (i = 0; i < n; i++) {
1127 gtk_list_store_append(store, &iter);
1128 gtk_list_store_set(store, &iter,
1129 0, pserver->players[i].name,
1130 1, pserver->players[i].type,
1131 2, pserver->players[i].host,
1132 3, pserver->players[i].nation,
1133 -1);
1134 }
1135}
1136
1137/**********************************************************************/
1140 static void network_list_callback(GtkTreeSelection *select, gpointer data)
1141{
1142 GtkTreeModel *model;
1143 GtkTreeIter it;
1144 const char *host;
1145 int port;
1146 char portstr[32];
1147 const struct server *pserver = NULL;
1148
1149 if (!gtk_tree_selection_get_selected(select, &model, &it)) {
1150 return;
1151 }
1152
1153 if (select == meta_selection) {
1154 GtkTreePath *path;
1155 struct srv_list *srvrs;
1156
1157 srvrs = server_scan_get_list(meta_scan.scan);
1158 path = gtk_tree_model_get_path(model, &it);
1159 if (!holding_srv_list_mutex) {
1160 /* We are not yet inside mutex protected block */
1161 fc_mutex_allocate(&srvrs->mutex);
1162 }
1163 if (srvrs->servers && path) {
1164 gint pos = gtk_tree_path_get_indices(path)[0];
1165
1166 pserver = server_list_get(srvrs->servers, pos);
1167 }
1168 if (!holding_srv_list_mutex) {
1169 /* We are not yet inside mutex protected block */
1170 fc_mutex_release(&srvrs->mutex);
1171 }
1172 gtk_tree_path_free(path);
1173 }
1174 update_server_playerlist(pserver);
1175
1176 gtk_tree_model_get(model, &it, 0, &host, 1, &port, -1);
1177
1178 gtk_entry_buffer_set_text(gtk_entry_get_buffer(GTK_ENTRY(network_host)), host, -1);
1179 fc_snprintf(portstr, sizeof(portstr), "%d", port);
1180 gtk_entry_buffer_set_text(gtk_entry_get_buffer(GTK_ENTRY(network_port)), portstr, -1);
1181}
1182
1183/**********************************************************************/
1186 static void update_network_page(void)
1187{
1188 char buf[256];
1189
1190 gtk_tree_selection_unselect_all(lan_selection);
1191 gtk_tree_selection_unselect_all(meta_selection);
1192
1193 gtk_entry_buffer_set_text(gtk_entry_get_buffer(GTK_ENTRY(network_login)), user_name, -1);
1194 gtk_entry_buffer_set_text(gtk_entry_get_buffer(GTK_ENTRY(network_host)), server_host, -1);
1195 fc_snprintf(buf, sizeof(buf), "%d", server_port);
1196 gtk_entry_buffer_set_text(gtk_entry_get_buffer(GTK_ENTRY(network_port)), buf, -1);
1197}
1198
1199/**********************************************************************/
1202 GtkWidget *create_network_page(void)
1203{
1204 GtkWidget *box, *sbox, *bbox, *hbox, *notebook;
1205 GtkWidget *button, *label, *view, *sw, *table;
1206 GtkTreeSelection *selection;
1207 GtkListStore *store;
1208 GtkEventController *controller;
1209
1210 box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 2);
1211 gtk_widget_set_margin_start(box, 4);
1212 gtk_widget_set_margin_end(box, 4);
1213 gtk_widget_set_margin_top(box, 4);
1214 gtk_widget_set_margin_bottom(box, 4);
1215
1216 notebook = gtk_notebook_new();
1217 gtk_box_append(GTK_BOX(box), notebook);
1218
1219 /* LAN pane. */
1220 lan_store = gtk_list_store_new(7, G_TYPE_STRING, /* host */
1221 G_TYPE_INT, /* port */
1222 G_TYPE_STRING, /* version */
1223 G_TYPE_STRING, /* state */
1224 G_TYPE_INT, /* nplayers */
1225 G_TYPE_STRING, /* humans */
1226 G_TYPE_STRING); /* message */
1227
1228 view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(lan_store));
1229 gtk_widget_set_hexpand(view, TRUE);
1230 gtk_widget_set_vexpand(view, TRUE);
1231 g_object_unref(lan_store);
1232 gtk_tree_view_columns_autosize(GTK_TREE_VIEW(view));
1233
1234 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
1235 lan_selection = selection;
1236 gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE);
1237
1238 controller = gtk_event_controller_focus_new();
1239 g_signal_connect(controller, "enter",
1240 G_CALLBACK(terminate_signal_processing), NULL);
1241 gtk_widget_add_controller(view, controller);
1242
1243 g_signal_connect(view, "row-activated",
1244 G_CALLBACK(network_activate_callback), NULL);
1245 g_signal_connect(selection, "changed",
1246 G_CALLBACK(network_list_callback), NULL);
1247
1248 add_treeview_column(view, _("Server Name"), G_TYPE_STRING, 0);
1249 add_treeview_column(view, _("Port"), G_TYPE_INT, 1);
1250 add_treeview_column(view, _("Version"), G_TYPE_STRING, 2);
1251 add_treeview_column(view, _("Status"), G_TYPE_STRING, 3);
1252 add_treeview_column(view, _("Players"), G_TYPE_INT, 4);
1253 add_treeview_column(view, _("Humans"), G_TYPE_STRING, 5);
1254 add_treeview_column(view, _("Comment"), G_TYPE_STRING, 6);
1255
1256 label = gtk_label_new_with_mnemonic(_("Local _Area Network"));
1257
1258 sw = gtk_scrolled_window_new();
1259 gtk_widget_set_margin_start(sw, 4);
1260 gtk_widget_set_margin_end(sw, 4);
1261 gtk_widget_set_margin_top(sw, 4);
1262 gtk_widget_set_margin_bottom(sw, 4);
1263 gtk_scrolled_window_set_has_frame(GTK_SCROLLED_WINDOW(sw), TRUE);
1264 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
1265 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1266 gtk_scrolled_window_set_child(GTK_SCROLLED_WINDOW(sw), view);
1267 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), sw, label);
1268
1269
1270 /* Metaserver pane. */
1271 meta_store = gtk_list_store_new(7, G_TYPE_STRING, /* host */
1272 G_TYPE_INT, /* port */
1273 G_TYPE_STRING, /* version */
1274 G_TYPE_STRING, /* state */
1275 G_TYPE_INT, /* nplayers */
1276 G_TYPE_STRING, /* humans */
1277 G_TYPE_STRING); /* message */
1278
1279 view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(meta_store));
1280 gtk_widget_set_hexpand(view, TRUE);
1281 gtk_widget_set_vexpand(view, TRUE);
1282 g_object_unref(meta_store);
1283 gtk_tree_view_columns_autosize(GTK_TREE_VIEW(view));
1284
1285 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
1286 meta_selection = selection;
1287 gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE);
1288
1289 controller = gtk_event_controller_focus_new();
1290 g_signal_connect(controller, "enter",
1291 G_CALLBACK(terminate_signal_processing), NULL);
1292 gtk_widget_add_controller(view, controller);
1293
1294 g_signal_connect(view, "row-activated",
1295 G_CALLBACK(network_activate_callback), NULL);
1296 g_signal_connect(selection, "changed",
1297 G_CALLBACK(network_list_callback), NULL);
1298
1299 add_treeview_column(view, _("Server Name"), G_TYPE_STRING, 0);
1300 add_treeview_column(view, _("Port"), G_TYPE_INT, 1);
1301 add_treeview_column(view, _("Version"), G_TYPE_STRING, 2);
1302 add_treeview_column(view, _("Status"), G_TYPE_STRING, 3);
1303 add_treeview_column(view, _("Players"), G_TYPE_INT, 4);
1304 add_treeview_column(view, _("Humans"), G_TYPE_STRING, 5);
1305 add_treeview_column(view, _("Comment"), G_TYPE_STRING, 6);
1306
1307 label = gtk_label_new_with_mnemonic(_("Internet _Metaserver"));
1308
1309 sw = gtk_scrolled_window_new();
1310 gtk_widget_set_margin_start(sw, 4);
1311 gtk_widget_set_margin_end(sw, 4);
1312 gtk_widget_set_margin_top(sw, 4);
1313 gtk_widget_set_margin_bottom(sw, 4);
1314 gtk_scrolled_window_set_has_frame(GTK_SCROLLED_WINDOW(sw), TRUE);
1315 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
1316 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1317 gtk_scrolled_window_set_child(GTK_SCROLLED_WINDOW(sw), view);
1318 if (GUI_GTK_OPTION(metaserver_tab_first)) {
1319 gtk_notebook_prepend_page(GTK_NOTEBOOK(notebook), sw, label);
1320 } else {
1321 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), sw, label);
1322 }
1323
1324 /* Bottom part of the page, outside the inner notebook. */
1325 sbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 2);
1326 gtk_box_append(GTK_BOX(box), sbox);
1327
1328 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 12);
1329 gtk_widget_set_margin_bottom(hbox, 8);
1330 gtk_widget_set_margin_end(hbox, 8);
1331 gtk_widget_set_margin_start(hbox, 8);
1332 gtk_widget_set_margin_top(hbox, 8);
1333 gtk_box_append(GTK_BOX(sbox), hbox);
1334
1335 table = gtk_grid_new();
1336 gtk_grid_set_row_spacing(GTK_GRID(table), 2);
1337 gtk_grid_set_column_spacing(GTK_GRID(table), 12);
1338 gtk_box_append(GTK_BOX(hbox), table);
1339
1340 network_host = gtk_entry_new();
1341 g_signal_connect(network_host, "activate",
1342 G_CALLBACK(connect_callback), NULL);
1343 gtk_grid_attach(GTK_GRID(table), network_host, 1, 0, 1, 1);
1344
1345 label = g_object_new(GTK_TYPE_LABEL,
1346 "use-underline", TRUE,
1347 "mnemonic-widget", network_host,
1348 "label", _("_Host:"),
1349 "xalign", 0.0,
1350 "yalign", 0.5,
1351 NULL);
1352 network_host_label = label;
1353 gtk_grid_attach(GTK_GRID(table), label, 0, 0, 1, 1);
1354
1355 network_port = gtk_entry_new();
1356 g_signal_connect(network_port, "activate",
1357 G_CALLBACK(connect_callback), NULL);
1358 gtk_grid_attach(GTK_GRID(table), network_port, 1, 1, 1, 1);
1359
1360 label = g_object_new(GTK_TYPE_LABEL,
1361 "use-underline", TRUE,
1362 "mnemonic-widget", network_port,
1363 "label", _("_Port:"),
1364 "xalign", 0.0,
1365 "yalign", 0.5,
1366 NULL);
1367 network_port_label = label;
1368 gtk_grid_attach(GTK_GRID(table), label, 0, 1, 1, 1);
1369
1370 network_login = gtk_entry_new();
1371 gtk_widget_set_margin_top(network_login, 10);
1372 g_signal_connect(network_login, "activate",
1373 G_CALLBACK(connect_callback), NULL);
1374 gtk_grid_attach(GTK_GRID(table), network_login, 1, 3, 1, 1);
1375
1376 label = g_object_new(GTK_TYPE_LABEL,
1377 "use-underline", TRUE,
1378 "mnemonic-widget", network_login,
1379 "label", _("_Login:"),
1380 "xalign", 0.0,
1381 "yalign", 0.5,
1382 NULL);
1383 gtk_widget_set_margin_top(label, 10);
1384 network_login_label = label;
1385 gtk_grid_attach(GTK_GRID(table), label, 0, 3, 1, 1);
1386
1387 network_password = gtk_entry_new();
1388 g_signal_connect(network_password, "activate",
1389 G_CALLBACK(connect_callback), NULL);
1390 gtk_entry_set_visibility(GTK_ENTRY(network_password), FALSE);
1391 gtk_grid_attach(GTK_GRID(table), network_password, 1, 4, 1, 1);
1392
1393 label = g_object_new(GTK_TYPE_LABEL,
1394 "use-underline", TRUE,
1395 "mnemonic-widget", network_password,
1396 "label", _("Pass_word:"),
1397 "xalign", 0.0,
1398 "yalign", 0.5,
1399 NULL);
1400 network_password_label = label;
1401 gtk_grid_attach(GTK_GRID(table), label, 0, 4, 1, 1);
1402
1403 network_confirm_password = gtk_entry_new();
1404 g_signal_connect(network_confirm_password, "activate",
1405 G_CALLBACK(connect_callback), NULL);
1406 gtk_entry_set_visibility(GTK_ENTRY(network_confirm_password), FALSE);
1407 gtk_grid_attach(GTK_GRID(table), network_confirm_password, 1, 5, 1, 1);
1408
1409 label = g_object_new(GTK_TYPE_LABEL,
1410 "use-underline", TRUE,
1411 "mnemonic-widget", network_confirm_password,
1412 "label", _("Conf_irm Password:"),
1413 "xalign", 0.0,
1414 "yalign", 0.5,
1415 NULL);
1416 network_confirm_password_label = label;
1417 gtk_grid_attach(GTK_GRID(table), label, 0, 5, 1, 1);
1418
1419 /* Server player list. */
1420 store = gtk_list_store_new(4, G_TYPE_STRING,
1421 G_TYPE_STRING,
1422 G_TYPE_STRING,
1423 G_TYPE_STRING);
1424 server_playerlist_store = store;
1425
1426 view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
1427 gtk_widget_set_hexpand(view, TRUE);
1428 add_treeview_column(view, _("Name"), G_TYPE_STRING, 0);
1429 add_treeview_column(view, _("Type"), G_TYPE_STRING, 1);
1430 add_treeview_column(view, _("Host"), G_TYPE_STRING, 2);
1431 add_treeview_column(view, _("Nation"), G_TYPE_STRING, 3);
1432 server_playerlist_view = view;
1433
1434 sw = gtk_scrolled_window_new();
1435 gtk_scrolled_window_set_has_frame(GTK_SCROLLED_WINDOW(sw), TRUE);
1436 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
1437 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1438 gtk_scrolled_window_set_child(GTK_SCROLLED_WINDOW(sw), view);
1439 gtk_box_append(GTK_BOX(hbox), sw);
1440
1441 bbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 2);
1442 gtk_widget_set_margin_bottom(bbox, 2);
1443 gtk_widget_set_margin_end(bbox, 2);
1444 gtk_widget_set_margin_start(bbox, 2);
1445 gtk_widget_set_margin_top(bbox, 2);
1446 gtk_box_set_spacing(GTK_BOX(bbox), 12);
1447 gtk_box_append(GTK_BOX(sbox), bbox);
1448
1449 button = gtk_button_new_from_icon_name("view-refresh");
1450 gtk_box_append(GTK_BOX(bbox), button);
1451 g_signal_connect(button, "clicked",
1452 G_CALLBACK(update_network_lists), NULL);
1453
1454 button = gtk_button_new_with_mnemonic(_("_Cancel"));
1455 gtk_box_append(GTK_BOX(bbox), button);
1456 g_signal_connect(button, "clicked",
1457 G_CALLBACK(main_callback), NULL);
1458
1459 button = gtk_button_new_with_mnemonic(_("C_onnect"));
1460 gtk_box_append(GTK_BOX(bbox), button);
1461 g_signal_connect(button, "clicked",
1462 G_CALLBACK(connect_callback), NULL);
1463
1464 return box;
1465}
1466
1467/****************************************************************************
1468 START PAGE
1469****************************************************************************/
1470 GtkWidget *start_message_area;
1471
1472 static GtkWidget *start_options_table;
1473 static GtkWidget *observe_button, *ready_button, *nation_button;
1474 static GtkTreeStore *connection_list_store;
1475 static GtkTreeView *connection_list_view;
1476 static GtkWidget *start_aifill_spin = NULL;
1477 static GtkWidget *ai_lvl_combobox = NULL;
1478
1479
1480/* NB: Must match creation arguments in connection_list_store_new(). */
1481 enum connection_list_columns {
1482 CL_COL_PLAYER_NUMBER = 0,
1483 CL_COL_USER_NAME,
1484 CL_COL_READY_STATE,
1485 CL_COL_PLAYER_NAME,
1486 CL_COL_FLAG,
1487 CL_COL_COLOR,
1488 CL_COL_NATION,
1489 CL_COL_TEAM,
1490 CL_COL_CONN_ID,
1491 CL_COL_STYLE,
1492 CL_COL_WEIGHT,
1493 CL_COL_COLLAPSED,
1494
1495 CL_NUM_COLUMNS
1496};
1497
1498/**********************************************************************/
1501 static inline GtkTreeStore *connection_list_store_new(void)
1502{
1503 return gtk_tree_store_new(CL_NUM_COLUMNS,
1504 G_TYPE_INT, /* CL_COL_PLAYER_NUMBER */
1505 G_TYPE_STRING, /* CL_COL_USER_NAME */
1506 G_TYPE_BOOLEAN, /* CL_COL_READY_STATE */
1507 G_TYPE_STRING, /* CL_COL_PLAYER_NAME */
1508 GDK_TYPE_PIXBUF, /* CL_COL_FLAG */
1509 GDK_TYPE_PIXBUF, /* CL_COL_COLOR */
1510 G_TYPE_STRING, /* CL_COL_NATION */
1511 G_TYPE_STRING, /* CL_COL_TEAM */
1512 G_TYPE_INT, /* CL_COL_CONN_ID */
1513 G_TYPE_INT, /* CL_COL_STYLE */
1514 G_TYPE_INT, /* CL_COL_WEIGHT */
1515 G_TYPE_BOOLEAN); /* CL_COL_COLLAPSED */
1516}
1517
1518/**********************************************************************/
1522 static void client_aitoggle_player(void *data)
1523{
1524 struct player *pplayer = player_by_number(FC_PTR_TO_INT(data));
1525
1526 if (NULL != pplayer
1527 && pplayer == client_player()
1528 && !is_human(pplayer)) {
1529 send_chat("/away");
1530 }
1531}
1532
1533/**********************************************************************/
1536 static void client_take_player(struct player *pplayer)
1537{
1538 int request_id = send_chat_printf("/take \"%s\"", player_name(pplayer));
1539 void *data = FC_INT_TO_PTR(player_number(pplayer));
1540
1541 update_queue_connect_processing_finished(request_id,
1542 client_aitoggle_player, data);
1543}
1544
1545/**********************************************************************/
1548 static void object_put(GObject *object, struct player *pplayer,
1549 struct connection *pconn)
1550{
1551 /* Note that passing -1 to GINT_TO_POINTER() is buggy with some versions
1552 * of gcc. player_slot_count() is not a valid player number. 0 is not
1553 * a valid connection id (see comment in server/sernet.c:
1554 * makeup_connection_name()). */
1555 g_object_set_data(object, "player_id",
1556 GINT_TO_POINTER(NULL != pplayer
1557 ? player_number(pplayer)
1558 : player_slot_count()));
1559 g_object_set_data(object, "connection_id",
1560 GINT_TO_POINTER(NULL != pconn ? pconn->id : 0));
1561}
1562
1563/**********************************************************************/
1567 static bool object_extract(GObject *object, struct player **ppplayer,
1568 struct connection **ppconn)
1569{
1570 bool ret = FALSE;
1571 int id;
1572
1573 if (NULL != ppplayer) {
1574 id = GPOINTER_TO_INT(g_object_get_data(object, "player_id"));
1575 *ppplayer = player_by_number(id);
1576 if (NULL != *ppplayer) {
1577 ret = TRUE;
1578 }
1579 }
1580 if (NULL != ppconn) {
1581 id = GPOINTER_TO_INT(g_object_get_data(object, "connection_id"));
1582 *ppconn = conn_by_number(id);
1583 if (NULL != *ppconn) {
1584 ret = TRUE;
1585 }
1586 }
1587
1588 return ret;
1589}
1590
1591/**********************************************************************/
1594 static void game_options_callback(GtkWidget *w, gpointer data)
1595{
1596 option_dialog_popup(_("Game Settings"), server_optset);
1597}
1598
1599/**********************************************************************/
1602 static void ai_skill_callback(GtkWidget *w, gpointer data)
1603{
1604 enum ai_level *levels = (enum ai_level *)data;
1605 const char *name;
1606 int i;
1607
1608 i = gtk_combo_box_get_active(GTK_COMBO_BOX(w));
1609
1610 if (i != -1) {
1611 enum ai_level level = levels[i];
1612
1613 /* Suppress changes provoked by server rather than local user */
1614 if (server_ai_level() != level) {
1615 name = ai_level_cmd(level);
1616 send_chat_printf("/%s", name);
1617 }
1618 }
1619}
1620
1621/* HACK: sometimes when creating the ruleset combo the value is set without
1622 * the user's control. In this case we don't want to do a /read. */
1623 static bool no_ruleset_callback = FALSE;
1624
1625/**********************************************************************/
1628 static void ruleset_selected(const char *name)
1629{
1630 if (name && name[0] != '\0' && !no_ruleset_callback) {
1631 set_ruleset(name);
1632 }
1633}
1634
1635/**********************************************************************/
1640 static void ruleset_entry_changed(GtkWidget *w, gpointer data)
1641{
1642 const char *name = NULL;
1643
1644 name = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(ruleset_combo));
1645
1646 if (name != NULL) {
1647 ruleset_selected(name);
1648 }
1649}
1650
1651/**********************************************************************/
1654 static bool send_new_aifill_to_server = TRUE;
1655 static void ai_fill_changed_by_user(GtkWidget *w, gpointer data)
1656{
1657 if (send_new_aifill_to_server) {
1658 option_int_set(optset_option_by_name(server_optset, "aifill"),
1659 gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(w)));
1660 }
1661}
1662
1663/**********************************************************************/
1666 void ai_fill_changed_by_server(int aifill)
1667{
1668 if (start_aifill_spin) {
1669 bool old = send_new_aifill_to_server;
1670 /* Suppress callback from this change to avoid a loop. */
1671 send_new_aifill_to_server = FALSE;
1672 /* HACK: this GUI control doesn't have quite the same semantics as the
1673 * server 'aifill' option, in that it claims to represent the minimum
1674 * number of players _including humans_. The GUI control has a minimum
1675 * value of 1, so aifill == 0 will not be represented correctly.
1676 * But there's generally exactly one human player because the control
1677 * only shows up for a locally spawned server, so we more or less
1678 * get away with this. */
1679 gtk_spin_button_set_value(GTK_SPIN_BUTTON(start_aifill_spin), aifill);
1680 send_new_aifill_to_server = old;
1681 }
1682}
1683
1684/**********************************************************************/
1687 void update_start_page(void)
1688{
1689 conn_list_dialog_update();
1690}
1691
1692/**********************************************************************/
1695 static void close_conn_menu_popover(void)
1696{
1697 if (conn_popover != NULL){
1698 gtk_widget_unparent(conn_popover);
1699 g_object_unref(conn_popover);
1700
1701 conn_popover = NULL;
1702 }
1703}
1704
1705/**********************************************************************/
1708 static void conn_menu_team_chosen(GSimpleAction *action, GVariant *parameter,
1709 gpointer data)
1710{
1711 struct player *pplayer;
1712 struct team_slot *tslot = g_object_get_data(G_OBJECT(action), "slot");
1713 GMenu *menu = data;
1714
1715 if (object_extract(G_OBJECT(menu), &pplayer, NULL)
1716 && NULL != tslot
1717 && team_slot_index(tslot) != team_number(pplayer->team)) {
1718 send_chat_printf("/team \"%s\" \"%s\"",
1719 player_name(pplayer),
1720 team_slot_rule_name(tslot));
1721 }
1722
1723 close_conn_menu_popover();
1724}
1725
1726/**********************************************************************/
1729 static void conn_menu_ready_chosen(GSimpleAction *action, GVariant *parameter,
1730 gpointer data)
1731{
1732 struct player *pplayer;
1733 GMenu *menu = data;
1734
1735 if (object_extract(G_OBJECT(menu), &pplayer, NULL)) {
1736 dsend_packet_player_ready(&client.conn,
1737 player_number(pplayer), !pplayer->is_ready);
1738 }
1739
1740 close_conn_menu_popover();
1741}
1742
1743/**********************************************************************/
1746 static void conn_menu_nation_chosen(GSimpleAction *action, GVariant *parameter,
1747 gpointer data)
1748{
1749 struct player *pplayer;
1750 GMenu *menu = data;
1751
1752 if (object_extract(G_OBJECT(menu), &pplayer, NULL)) {
1753 popup_races_dialog(pplayer);
1754 }
1755
1756 close_conn_menu_popover();
1757}
1758
1759/**********************************************************************/
1763 static void conn_menu_player_command(GSimpleAction *action, GVariant *parameter,
1764 gpointer data)
1765{
1766 struct player *pplayer;
1767 GMenu *menu = data;
1768
1769 if (object_extract(G_OBJECT(menu), &pplayer, NULL)) {
1770 send_chat_printf("/%s \"%s\"",
1771 (char *) g_object_get_data(G_OBJECT(action), "command"),
1772 player_name(pplayer));
1773 }
1774
1775 close_conn_menu_popover();
1776}
1777
1778/**********************************************************************/
1781 static void conn_menu_player_take(GSimpleAction *action, GVariant *parameter,
1782 gpointer data)
1783{
1784 struct player *pplayer;
1785 GMenu *menu = data;
1786
1787 if (object_extract(G_OBJECT(menu), &pplayer, NULL)) {
1788 client_take_player(pplayer);
1789 }
1790
1791 close_conn_menu_popover();
1792}
1793
1794/**********************************************************************/
1798 static void conn_menu_connection_command(GSimpleAction *action,
1799 GVariant *parameter, gpointer data)
1800{
1801 struct connection *pconn;
1802 GMenu *menu = data;
1803
1804 if (object_extract(G_OBJECT(menu), NULL, &pconn)) {
1805 send_chat_printf(SERVER_COMMAND_PREFIX_STR "%s \"%s\"",
1806 (char *) g_object_get_data(G_OBJECT(action), "command"),
1807 pconn->username);
1808 }
1809
1810 close_conn_menu_popover();
1811}
1812
1813/**********************************************************************/
1816 static void show_conn_popup(struct player *pplayer, struct connection *pconn)
1817{
1818 GtkWidget *popup;
1819 char buf[4096] = "";
1820
1821 if (pconn) {
1822 cat_snprintf(buf, sizeof(buf), _("Connection name: %s"),
1823 pconn->username);
1824 } else {
1825 cat_snprintf(buf, sizeof(buf), _("Player name: %s"),
1826 player_name(pplayer));
1827 }
1828 cat_snprintf(buf, sizeof(buf), "\n");
1829 if (pconn) {
1830 cat_snprintf(buf, sizeof(buf), _("Host: %s"), pconn->addr);
1831 }
1832 cat_snprintf(buf, sizeof(buf), "\n");
1833
1834 /* Show popup. */
1835 popup = gtk_message_dialog_new(NULL, 0,
1836 GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE,
1837 "%s", buf);
1838 gtk_window_set_title(GTK_WINDOW(popup), _("Player/conn info"));
1839 setup_dialog(popup, toplevel);
1840 g_signal_connect(popup, "response", G_CALLBACK(gtk_window_destroy), NULL);
1841 gtk_window_present(GTK_WINDOW(popup));
1842}
1843
1844/**********************************************************************/
1847 static void conn_menu_info_chosen(GSimpleAction *action, GVariant *parameter,
1848 gpointer data)
1849{
1850 struct player *pplayer;
1851 struct connection *pconn;
1852 GMenu *menu = data;
1853
1854 if (object_extract(G_OBJECT(menu), &pplayer, &pconn)) {
1855 show_conn_popup(pplayer, pconn);
1856 }
1857
1858 close_conn_menu_popover();
1859}
1860
1861/**********************************************************************/
1865 static GtkWidget *create_conn_menu(struct player *pplayer,
1866 struct connection *pconn)
1867{
1868 GMenu *menu;
1869 gchar *buf;
1870 GSimpleAction *act;
1871 GActionGroup *group;
1872
1873 group = G_ACTION_GROUP(g_simple_action_group_new());
1874
1875 menu = g_menu_new();
1876
1877 object_put(G_OBJECT(menu), pplayer, pconn);
1878
1879 buf = g_strdup_printf(_("%s info"),
1880 pconn ? pconn->username : player_name(pplayer));
1881
1882 act = g_simple_action_new("info", NULL);
1883 g_action_map_add_action(G_ACTION_MAP(group), G_ACTION(act));
1884 g_signal_connect(act, "activate", G_CALLBACK(conn_menu_info_chosen), menu);
1885 menu_item_append_unref(menu, g_menu_item_new(buf, "win.info"));
1886
1887 if (NULL != pplayer) {
1888 act = g_simple_action_new("toggle_ready", NULL);
1889 g_action_map_add_action(G_ACTION_MAP(group), G_ACTION(act));
1890 g_signal_connect(act, "activate", G_CALLBACK(conn_menu_ready_chosen), menu);
1891 g_simple_action_set_enabled(G_SIMPLE_ACTION(act), is_human(pplayer));
1892 menu_item_append_unref(menu, g_menu_item_new(_("Toggle player ready"),
1893 "win.toggle_ready"));
1894
1895 act = g_simple_action_new("pick_nation", NULL);
1896 g_action_map_add_action(G_ACTION_MAP(group), G_ACTION(act));
1897 g_signal_connect(act, "activate", G_CALLBACK(conn_menu_nation_chosen), menu);
1898 g_simple_action_set_enabled(G_SIMPLE_ACTION(act),
1899 can_conn_edit_players_nation(&client.conn,
1900 pplayer));
1901 menu_item_append_unref(menu, g_menu_item_new(_("Pick nation"), "win.pick_nation"));
1902
1903 act = g_simple_action_new("observe", NULL);
1904 g_object_set_data_full(G_OBJECT(act), "command", g_strdup("observe"),
1905 (GDestroyNotify) g_free);
1906 g_action_map_add_action(G_ACTION_MAP(group), G_ACTION(act));
1907 g_signal_connect(act, "activate", G_CALLBACK(conn_menu_player_command), menu);
1908 menu_item_append_unref(menu, g_menu_item_new(_("Observe this player"),
1909 "win.observe"));
1910
1911 act = g_simple_action_new("take_plr", NULL);
1912 g_action_map_add_action(G_ACTION_MAP(group), G_ACTION(act));
1913 g_signal_connect(act, "activate", G_CALLBACK(conn_menu_player_take), menu);
1914 menu_item_append_unref(menu, g_menu_item_new(_("Take this player"),
1915 "win.take_plr"));
1916 }
1917
1918 if (ALLOW_CTRL <= client.conn.access_level && NULL != pconn
1919 && pconn->id != client.conn.id) {
1920 act = g_simple_action_new("cut_conn", NULL);
1921 g_object_set_data_full(G_OBJECT(act), "command", g_strdup("cut"),
1922 (GDestroyNotify) g_free);
1923 g_action_map_add_action(G_ACTION_MAP(group), G_ACTION(act));
1924 g_signal_connect(act, "activate", G_CALLBACK(conn_menu_connection_command), menu);
1925 menu_item_append_unref(menu, g_menu_item_new(_("Cut connection"), "win.cut_conn"));
1926 }
1927
1928 if (ALLOW_CTRL <= client.conn.access_level && NULL != pplayer) {
1929 act = g_simple_action_new("aitoggle", NULL);
1930 g_object_set_data_full(G_OBJECT(act), "command", g_strdup("aitoggle"),
1931 (GDestroyNotify) g_free);
1932 g_action_map_add_action(G_ACTION_MAP(group), G_ACTION(act));
1933 g_signal_connect(act, "activate", G_CALLBACK(conn_menu_connection_command), menu);
1934 menu_item_append_unref(menu, g_menu_item_new(_("Aitoggle player"), "win.aitoggle"));
1935
1936 if (pplayer != client.conn.playing && game.info.is_new_game) {
1937 act = g_simple_action_new("remove", NULL);
1938 g_object_set_data_full(G_OBJECT(act), "command", g_strdup("remove"),
1939 (GDestroyNotify) g_free);
1940 g_action_map_add_action(G_ACTION_MAP(group), G_ACTION(act));
1941 g_signal_connect(act, "activate", G_CALLBACK(conn_menu_connection_command), menu);
1942 menu_item_append_unref(menu, g_menu_item_new(_("Remove player"), "win.remove"));
1943 }
1944 }
1945
1946 if (ALLOW_ADMIN <= client.conn.access_level && NULL != pconn
1947 && pconn->id != client.conn.id) {
1948 enum cmdlevel level;
1949
1950 /* No item for hack access; that would be a serious security hole. */
1951 for (level = cmdlevel_min(); level < client.conn.access_level; level++) {
1952 char actbuf[128];
1953
1954 buf = g_strdup_printf(_("Give %s access"), cmdlevel_name(level));
1955 fc_snprintf(actbuf, sizeof(actbuf), "cmdlevel_%d", level);
1956
1957 act = g_simple_action_new(actbuf, NULL);
1958 g_object_set_data_full(G_OBJECT(act), "command",
1959 g_strdup_printf("cmdlevel %s",
1960 cmdlevel_name(level)),
1961 (GDestroyNotify) g_free);
1962 g_action_map_add_action(G_ACTION_MAP(group), G_ACTION(act));
1963 g_signal_connect(act, "activate", G_CALLBACK(conn_menu_connection_command), menu);
1964 fc_snprintf(actbuf, sizeof(actbuf), "win.cmdlevel_%d", level);
1965 menu_item_append_unref(menu, g_menu_item_new(buf, actbuf));
1966 g_free(buf);
1967 }
1968 }
1969
1970 if (ALLOW_CTRL <= client.conn.access_level
1971 && NULL != pplayer && is_ai(pplayer)) {
1972 enum ai_level level;
1973
1974 for (level = 0; level < AI_LEVEL_COUNT; level++) {
1975 if (is_settable_ai_level(level)) {
1976 char actbuf[128];
1977
1978 buf = g_strdup_printf(_("Difficulty: %s"), ai_level_translated_name(level));
1979 fc_snprintf(actbuf, sizeof(actbuf), "ailevel_%d", level);
1980
1981 act = g_simple_action_new(actbuf, NULL);
1982 g_object_set_data_full(G_OBJECT(act), "command",
1983 g_strdup(ai_level_cmd(level)),
1984 (GDestroyNotify) g_free);
1985 g_action_map_add_action(G_ACTION_MAP(group), G_ACTION(act));
1986 g_signal_connect(act, "activate", G_CALLBACK(conn_menu_player_command), menu);
1987 fc_snprintf(actbuf, sizeof(actbuf), "win.ailevel_%d", level);
1988 menu_item_append_unref(menu, g_menu_item_new(buf, actbuf));
1989 g_free(buf);
1990 }
1991 }
1992 }
1993
1994 if (pplayer != NULL /* && game.info.is_new_game */) {
1995 const int count = pplayer->team
1996 ? player_list_size(team_members(pplayer->team)) : 0;
1997 bool need_empty_team = (count != 1);
1998
1999 /* Can't use team_iterate here since it skips empty teams. */
2000 team_slots_iterate(tslot) {
2001 char actbuf[128];
2002 int id;
2003
2004 if (!team_slot_is_used(tslot)) {
2005 if (!need_empty_team) {
2006 continue;
2007 }
2008 need_empty_team = FALSE;
2009 }
2010
2011 id = team_number(team_slot_get_team(tslot));
2012
2013 /* TRANS: e.g., "Put on Team 5" */
2014 buf = g_strdup_printf(_("Put on %s"),
2015 team_slot_name_translation(tslot));
2016 fc_snprintf(actbuf, sizeof(actbuf), "team_%d", id);
2017
2018 act = g_simple_action_new(actbuf, NULL);
2019 g_object_set_data(G_OBJECT(act), "slot", tslot);
2020 g_action_map_add_action(G_ACTION_MAP(group), G_ACTION(act));
2021 g_signal_connect(act, "activate", G_CALLBACK(conn_menu_team_chosen), menu);
2022 fc_snprintf(actbuf, sizeof(actbuf), "win.team_%d", id);
2023 menu_item_append_unref(menu, g_menu_item_new(buf, actbuf));
2024 g_free(buf);
2025 } team_slots_iterate_end;
2026 }
2027
2028 close_conn_menu_popover();
2029 conn_popover = gtk_popover_menu_new_from_model(G_MENU_MODEL(menu));
2030 g_object_ref(conn_popover);
2031 gtk_widget_insert_action_group(conn_popover, "win", group);
2032
2033 return conn_popover;
2034}
2035
2036/**********************************************************************/
2039 static gboolean delayed_unselect_path(gpointer data)
2040{
2041 if (NULL != connection_list_view) {
2042 GtkTreeSelection *selection =
2043 gtk_tree_view_get_selection(connection_list_view);
2044 GtkTreePath *path = data;
2045
2046 gtk_tree_selection_unselect_path(selection, path);
2047 gtk_tree_path_free(path);
2048 }
2049 return FALSE;
2050}
2051
2052/**********************************************************************/
2055 static gboolean connect_list_left_button(GtkGestureClick *gesture,
2056 int n_press,
2057 double x, double y, gpointer data)
2058{
2059 GtkEventController *controller = GTK_EVENT_CONTROLLER(gesture);
2060 GtkTreeView *tree = GTK_TREE_VIEW(gtk_event_controller_get_widget(controller));
2061 GtkTreePath *path = NULL;
2062 GtkTreeSelection *selection = gtk_tree_view_get_selection(tree);
2063
2064 if (!gtk_tree_view_get_path_at_pos(tree,
2065 x, y,
2066 &path, NULL, NULL, NULL)) {
2067 return FALSE;
2068 }
2069
2070 if (gtk_tree_selection_path_is_selected(selection, path)) {
2071 /* Need to delay to avoid problem with the expander. */
2072 g_idle_add(delayed_unselect_path, path);
2073 return FALSE; /* Return now, don't free the path. */
2074 }
2075
2076 gtk_tree_path_free(path);
2077
2078 return FALSE;
2079}
2080
2081/**********************************************************************/
2084 static gboolean connect_list_right_button(GtkGestureClick *gesture,
2085 int n_press,
2086 double x, double y, gpointer data)
2087{
2088 GtkEventController *controller = GTK_EVENT_CONTROLLER(gesture);
2089 GtkWidget *tree = gtk_event_controller_get_widget(controller);
2090 GtkWidget *parent = data;
2091 GtkTreePath *path = NULL;
2092 GtkWidget *menu;
2093 GtkTreeSelection *selection;
2094 GtkTreeModel *model;
2095 GtkTreeIter iter;
2096 int player_no, conn_id;
2097 struct player *pplayer;
2098 struct connection *pconn;
2099 int bx, by;
2100 GdkRectangle rect = { .x = x, .y = y, .width = 1, .height = 1};
2101
2102 gtk_tree_view_convert_widget_to_bin_window_coords(GTK_TREE_VIEW(tree), x, y, &bx, &by);
2103
2104 if (!gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(tree), bx, by,
2105 &path, NULL, NULL, NULL)) {
2106 return FALSE;
2107 }
2108
2109 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree));
2110 model = gtk_tree_view_get_model(GTK_TREE_VIEW(tree));
2111
2112 if (!gtk_tree_selection_path_is_selected(selection, path)) {
2113 gtk_tree_selection_select_path(selection, path);
2114 }
2115 gtk_tree_model_get_iter(model, &iter, path);
2116
2117 gtk_tree_model_get(model, &iter, CL_COL_PLAYER_NUMBER, &player_no, -1);
2118 pplayer = player_by_number(player_no);
2119
2120 gtk_tree_model_get(model, &iter, CL_COL_CONN_ID, &conn_id, -1);
2121 pconn = conn_by_number(conn_id);
2122
2123 menu = create_conn_menu(pplayer, pconn);
2124 gtk_widget_set_parent(menu, parent); /* Gtk bug prevents tree view parenting */
2125 gtk_popover_set_pointing_to(GTK_POPOVER(menu), &rect);
2126
2127 gtk_popover_popup(GTK_POPOVER(menu));
2128
2129 gtk_tree_path_free(path);
2130
2131 return TRUE;
2132}
2133
2134/**********************************************************************/
2137 static void connection_list_row_callback(GtkTreeView *tree_view,
2138 GtkTreeIter *iter,
2139 GtkTreePath *path,
2140 gpointer data)
2141{
2142 GtkTreeStore *store = GTK_TREE_STORE(gtk_tree_view_get_model(tree_view));
2143
2144 gtk_tree_store_set(store, iter,
2145 CL_COL_COLLAPSED, GPOINTER_TO_INT(data), -1);
2146}
2147
2148/**********************************************************************/
2152 static bool conn_list_selection(struct player **ppplayer,
2153 struct connection **ppconn)
2154{
2155 if (NULL != connection_list_view) {
2156 GtkTreeIter iter;
2157 GtkTreeModel *model;
2158 GtkTreeSelection *selection =
2159 gtk_tree_view_get_selection(connection_list_view);
2160
2161 if (gtk_tree_selection_get_selected(selection, &model, &iter)) {
2162 int id;
2163
2164 if (NULL != ppplayer) {
2165 gtk_tree_model_get(model, &iter, CL_COL_PLAYER_NUMBER, &id, -1);
2166 *ppplayer = player_by_number(id);
2167 }
2168 if (NULL != ppconn) {
2169 gtk_tree_model_get(model, &iter, CL_COL_CONN_ID, &id, -1);
2170 *ppconn = conn_by_number(id);
2171 }
2172 return TRUE;
2173 }
2174 }
2175
2176 if (NULL != ppplayer) {
2177 *ppplayer = NULL;
2178 }
2179 if (NULL != ppconn) {
2180 *ppconn = NULL;
2181 }
2182 return FALSE;
2183}
2184
2185/**********************************************************************/
2188 static void conn_list_select_conn(struct connection *pconn)
2189{
2190 GtkTreeModel *model;
2191 GtkTreeIter parent, child, *iter = NULL;
2192 GtkTreeSelection *selection;
2193 gboolean valid;
2194 const int search_id = pconn->id;
2195 int id;
2196
2197 if (NULL == connection_list_view) {
2198 return;
2199 }
2200
2201 model = gtk_tree_view_get_model(connection_list_view);
2202 selection = gtk_tree_view_get_selection(connection_list_view);
2203
2204 /* Main iteration. */
2205 valid = gtk_tree_model_get_iter_first(model, &parent);
2206 while (valid && NULL == iter) {
2207 gtk_tree_model_get(model, &parent, CL_COL_CONN_ID, &id, -1);
2208 if (search_id == id) {
2209 iter = &parent;
2210 break;
2211 }
2212
2213 /* Node children iteration. */
2214 valid = gtk_tree_model_iter_children(model, &child, &parent);
2215 while (valid && NULL == iter) {
2216 gtk_tree_model_get(model, &child, CL_COL_CONN_ID, &id, -1);
2217 if (search_id == id) {
2218 iter = &child;
2219 break;
2220 }
2221 valid = gtk_tree_model_iter_next(model, &child);
2222 }
2223
2224 valid = gtk_tree_model_iter_next(model, &parent);
2225 }
2226
2227 /* Select iterator. */
2228 if (NULL != iter) {
2229 gtk_tree_selection_select_iter(selection, iter);
2230 } else {
2231 log_error("%s(): connection %s not found.",
2232 __FUNCTION__, conn_description(pconn));
2233 }
2234}
2235
2236/**********************************************************************/
2239 static void ready_button_callback(GtkWidget *w, gpointer data)
2240{
2241 if (can_client_control()) {
2242 dsend_packet_player_ready(&client.conn,
2243 player_number(client_player()),
2244 !client_player()->is_ready);
2245 } else {
2246 dsend_packet_player_ready(&client.conn, 0, TRUE);
2247 }
2248}
2249
2250/**********************************************************************/
2253 static void nation_button_callback(GtkWidget *w, gpointer data)
2254{
2255 struct player *selected_plr;
2256 bool row_selected = conn_list_selection(&selected_plr, NULL);
2257
2258 if (row_selected && NULL != selected_plr) {
2259 /* "Take <player_name>" */
2260 client_take_player(selected_plr);
2261 } else if (can_client_control()) {
2262 /* "Pick Nation" */
2263 popup_races_dialog(client_player());
2264 } else {
2265 /* "Take a Player" */
2266 send_chat("/take -");
2267 }
2268}
2269
2270/**********************************************************************/
2273 static void observe_button_callback(GtkWidget *w, gpointer data)
2274{
2275 struct player *selected_plr;
2276 bool row_selected = conn_list_selection(&selected_plr, NULL);
2277
2278 if (row_selected && NULL != selected_plr) {
2279 /* "Observe <player_name>" */
2280 send_chat_printf("/observe \"%s\"", player_name(selected_plr));
2281 } else if (!client_is_global_observer()) {
2282 /* "Observe" */
2283 send_chat("/observe");
2284 } else {
2285 /* "Do not observe" */
2286 send_chat("/detach");
2287 }
2288}
2289
2290/**********************************************************************/
2293 static void update_start_page_buttons(void)
2294{
2295 char buf[2 * MAX_LEN_NAME];
2296 const char *text;
2297 struct player *selected_plr;
2298 bool row_selected = conn_list_selection(&selected_plr, NULL);
2299 bool sensitive;
2300
2301 /*** Ready button. ***/
2302 if (can_client_control()) {
2303 sensitive = client_player()->is_alive;
2304 if (client_player()->is_ready) {
2305 text = _("Not _ready");
2306 } else {
2307 int num_unready = 0;
2308
2309 players_iterate_alive(pplayer) {
2310 if (is_human(pplayer) && !pplayer->is_ready) {
2311 num_unready++;
2312 }
2313 } players_iterate_alive_end;
2314
2315 if (num_unready > 1) {
2316 text = _("_Ready");
2317 } else {
2318 /* We are the last unready player so clicking here will
2319 * immediately start the game. */
2320 text = _("_Start");
2321 }
2322 }
2323 } else {
2324 text = _("_Start");
2325 if (can_client_access_hack()) {
2326 sensitive = TRUE;
2327 players_iterate_alive(plr) {
2328 if (is_human(plr)) {
2329 /* There's human controlled player(s) in game, so it's their
2330 * job to start the game. */
2331 sensitive = FALSE;
2332 break;
2333 }
2334 } players_iterate_alive_end;
2335 } else {
2336 sensitive = FALSE;
2337 }
2338 }
2339 gtk_stockbutton_set_label(ready_button, text);
2340 gtk_widget_set_sensitive(ready_button, sensitive);
2341
2342 /*** Nation button. ***/
2343 if (row_selected && NULL != selected_plr) {
2344 fc_snprintf(buf, sizeof(buf), _("_Take %s"), player_name(selected_plr));
2345 text = buf;
2346 sensitive = (client_is_observer() || selected_plr != client_player());
2347 } else if (can_client_control()) {
2348 text = _("Pick _Nation");
2349 sensitive = game.info.is_new_game;
2350 } else {
2351 text = _("_Take a Player");
2352 sensitive = game.info.is_new_game;
2353 }
2354 gtk_stockbutton_set_label(nation_button, text);
2355 gtk_widget_set_sensitive(nation_button, sensitive);
2356
2357 /*** Observe button. ***/
2358 if (row_selected && NULL != selected_plr) {
2359 fc_snprintf(buf, sizeof(buf), _("_Observe %s"),
2360 player_name(selected_plr));
2361 text = buf;
2362 sensitive = (!client_is_observer() || selected_plr != client_player());
2363 } else if (!client_is_global_observer()) {
2364 text = _("_Observe");
2365 sensitive = TRUE;
2366 } else {
2367 text = _("Do not _observe");
2368 sensitive = TRUE;
2369 }
2370 gtk_stockbutton_set_label(observe_button, text);
2371 gtk_widget_set_sensitive(observe_button, sensitive);
2372}
2373
2374/**********************************************************************/
2378 static bool model_get_player_iter(GtkTreeModel *model,
2379 GtkTreeIter *iter,
2380 GtkTreeIter *start,
2381 const struct player *pplayer)
2382{
2383 const int search_id = player_number(pplayer);
2384 int id;
2385
2386 if (NULL != start) {
2387 *iter = *start;
2388 if (!gtk_tree_model_iter_next(model, iter)) {
2389 return FALSE;
2390 }
2391 } else if (!gtk_tree_model_get_iter_first(model, iter)) {
2392 return FALSE;
2393 }
2394
2395 do {
2396 gtk_tree_model_get(model, iter, CL_COL_PLAYER_NUMBER, &id, -1);
2397 if (id == search_id) {
2398 return TRUE;
2399 }
2400 } while (gtk_tree_model_iter_next(model, iter));
2401
2402 return FALSE;
2403}
2404
2405/**********************************************************************/
2409 static bool model_get_conn_iter(GtkTreeModel *model, GtkTreeIter *iter,
2410 GtkTreeIter *parent, GtkTreeIter *start,
2411 const struct connection *pconn)
2412{
2413 const int search_id = pconn->id;
2414 int id;
2415
2416 if (NULL != start) {
2417 *iter = *start;
2418 if (!gtk_tree_model_iter_next(model, iter)) {
2419 return FALSE;
2420 }
2421 } else if (!gtk_tree_model_iter_children(model, iter, parent)) {
2422 return FALSE;
2423 }
2424
2425 do {
2426 gtk_tree_model_get(model, iter, CL_COL_CONN_ID, &id, -1);
2427 if (id == search_id) {
2428 return TRUE;
2429 }
2430 } while (gtk_tree_model_iter_next(model, iter));
2431
2432 return FALSE;
2433}
2434
2435/**********************************************************************/
2438 void real_conn_list_dialog_update(void *unused)
2439{
2440 if (client_state() == C_S_PREPARING
2441 && get_client_page() == PAGE_START
2442 && connection_list_store != NULL) {
2443 GtkTreeStore *store = connection_list_store;
2444 GtkTreeModel *model = GTK_TREE_MODEL(store);
2445 GtkTreePath *path;
2446 GtkTreeIter child, prev_child, *pprev_child;
2447 GtkTreeIter parent, prev_parent, *pprev_parent = NULL;
2448 GdkPixbuf *flag, *color;
2449 gboolean collapsed;
2450 struct player *pselected_player;
2451 struct connection *pselected_conn;
2452 bool is_ready;
2453 const char *nation, *plr_name, *team;
2454 char name[MAX_LEN_NAME + 8];
2455 enum cmdlevel access_level;
2456 int conn_id;
2457
2458 /* Refresh the AI skill level control */
2459 if (ai_lvl_combobox) {
2460 enum ai_level new_level = server_ai_level(), level;
2461 int i = 0;
2462
2463 for (level = 0; level < AI_LEVEL_COUNT; level++) {
2464 if (is_settable_ai_level(level)) {
2465 if (level == new_level) {
2466 gtk_combo_box_set_active(GTK_COMBO_BOX(ai_lvl_combobox), i);
2467 break;
2468 }
2469 i++;
2470 }
2471 }
2472 if (level == AI_LEVEL_COUNT) {
2473 /* Probably ai_level_invalid() */
2474 gtk_combo_box_set_active(GTK_COMBO_BOX(ai_lvl_combobox), -1);
2475 }
2476 }
2477
2478 /* Save the selected connection. */
2479 (void) conn_list_selection(&pselected_player, &pselected_conn);
2480
2481 /* Insert players into the connection list. */
2482 players_iterate(pplayer) {
2483 if (!player_has_flag(pplayer, PLRF_SCENARIO_RESERVED)) {
2484 conn_id = -1;
2485 access_level = ALLOW_NONE;
2486 flag = pplayer->nation ? get_flag(pplayer->nation) : NULL;
2487 color = create_player_icon(pplayer);
2488
2489 conn_list_iterate(pplayer->connections, pconn) {
2490 if (pconn->playing == pplayer && !pconn->observer) {
2491 conn_id = pconn->id;
2492 access_level = pconn->access_level;
2493 break;
2494 }
2495 } conn_list_iterate_end;
2496
2497 if (is_ai(pplayer) && !pplayer->was_created
2498 && !pplayer->is_connected) {
2499 /* TRANS: "<Novice AI>" */
2500 fc_snprintf(name, sizeof(name), _("<%s AI>"),
2501 ai_level_translated_name(pplayer->ai_common.skill_level));
2502 } else {
2503 sz_strlcpy(name, pplayer->username);
2504 if (access_level > ALLOW_BASIC) {
2505 sz_strlcat(name, "*");
2506 }
2507 }
2508
2509 is_ready = !is_human(pplayer) ? TRUE : pplayer->is_ready;
2510
2511 if (pplayer->nation == NO_NATION_SELECTED) {
2512 nation = _("Random");
2513 if (pplayer->was_created) {
2514 plr_name = player_name(pplayer);
2515 } else {
2516 plr_name = "";
2517 }
2518 } else {
2519 nation = nation_adjective_for_player(pplayer);
2520 plr_name = player_name(pplayer);
2521 }
2522
2523 team = pplayer->team ? team_name_translation(pplayer->team) : "";
2524
2525 if (model_get_player_iter(model, &parent, pprev_parent, pplayer)) {
2526 gtk_tree_store_move_after(store, &parent, pprev_parent);
2527 } else {
2528 gtk_tree_store_insert_after(store, &parent, NULL, pprev_parent);
2529 }
2530
2531 gtk_tree_store_set(store, &parent,
2532 CL_COL_PLAYER_NUMBER, player_number(pplayer),
2533 CL_COL_USER_NAME, name,
2534 CL_COL_READY_STATE, is_ready,
2535 CL_COL_PLAYER_NAME, plr_name,
2536 CL_COL_FLAG, flag,
2537 CL_COL_COLOR, color,
2538 CL_COL_NATION, nation,
2539 CL_COL_TEAM, team,
2540 CL_COL_CONN_ID, conn_id,
2541 CL_COL_STYLE, PANGO_STYLE_NORMAL,
2542 CL_COL_WEIGHT, PANGO_WEIGHT_BOLD,
2543 -1);
2544
2545 /* Insert observers of this player as child nodes. */
2546 pprev_child = NULL;
2547 conn_list_iterate(pplayer->connections, pconn) {
2548 if (pconn->id == conn_id) {
2549 continue;
2550 }
2551 if (model_get_conn_iter(model, &child, &parent,
2552 pprev_child, pconn)) {
2553 gtk_tree_store_move_after(store, &child, pprev_child);
2554 } else {
2555 gtk_tree_store_insert_after(store, &child, &parent, pprev_child);
2556 }
2557
2558 gtk_tree_store_set(store, &child,
2559 CL_COL_PLAYER_NUMBER, -1,
2560 CL_COL_USER_NAME, pconn->username,
2561 CL_COL_TEAM, _("Observer"),
2562 CL_COL_CONN_ID, pconn->id,
2563 CL_COL_STYLE, PANGO_STYLE_NORMAL,
2564 CL_COL_WEIGHT, PANGO_WEIGHT_NORMAL,
2565 -1);
2566
2567 prev_child = child;
2568 pprev_child = &prev_child;
2569 } conn_list_iterate_end;
2570
2571 /* Expand node? */
2572 if (NULL != pprev_child) {
2573 gtk_tree_model_get(model, &parent, CL_COL_COLLAPSED, &collapsed, -1);
2574 if (!collapsed) {
2575 path = gtk_tree_model_get_path(model, &parent);
2576 gtk_tree_view_expand_row(GTK_TREE_VIEW(connection_list_view),
2577 path, FALSE);
2578 gtk_tree_path_free(path);
2579 }
2580 }
2581
2582 /* Remove trailing rows. */
2583 if (NULL != pprev_child) {
2584 child = prev_child;
2585 if (gtk_tree_model_iter_next(model, &child)) {
2586 while (gtk_tree_store_remove(store, &child)) {
2587 /* Do nothing more. */
2588 }
2589 }
2590 } else if (gtk_tree_model_iter_children(model, &child, &parent)) {
2591 while (gtk_tree_store_remove(store, &child)) {
2592 /* Do nothing more. */
2593 }
2594 }
2595
2596 prev_parent = parent;
2597 pprev_parent = &prev_parent;
2598 if (flag) {
2599 g_object_unref(flag);
2600 }
2601 if (color) {
2602 g_object_unref(color);
2603 }
2604 }
2605 } players_iterate_end;
2606
2607 /* Finally, insert global observers... */
2608 conn_list_iterate(game.est_connections, pconn) {
2609 if (NULL != pconn->playing || !pconn->observer) {
2610 continue;
2611 }
2612
2613 if (model_get_conn_iter(model, &parent, NULL, pprev_parent, pconn)) {
2614 gtk_tree_store_move_after(store, &parent, pprev_parent);
2615 } else {
2616 gtk_tree_store_insert_after(store, &parent, NULL, pprev_parent);
2617 }
2618
2619 gtk_tree_store_set(store, &parent,
2620 CL_COL_PLAYER_NUMBER, -1,
2621 CL_COL_USER_NAME, pconn->username,
2622 CL_COL_TEAM, _("Observer"),
2623 CL_COL_CONN_ID, pconn->id,
2624 CL_COL_STYLE, PANGO_STYLE_NORMAL,
2625 CL_COL_WEIGHT, PANGO_WEIGHT_NORMAL,
2626 -1);
2627
2628 prev_parent = parent;
2629 pprev_parent = &prev_parent;
2630 } conn_list_iterate_end;
2631
2632 /* ...and detached connections. */
2633 conn_list_iterate(game.est_connections, pconn) {
2634 if (NULL != pconn->playing || pconn->observer) {
2635 continue;
2636 }
2637
2638 if (model_get_conn_iter(model, &parent, NULL, pprev_parent, pconn)) {
2639 gtk_tree_store_move_after(store, &parent, pprev_parent);
2640 } else {
2641 gtk_tree_store_insert_after(store, &parent, NULL, pprev_parent);
2642 }
2643
2644 gtk_tree_store_set(store, &parent,
2645 CL_COL_PLAYER_NUMBER, -1,
2646 CL_COL_USER_NAME, pconn->username,
2647 CL_COL_TEAM, _("Detached"),
2648 CL_COL_CONN_ID, pconn->id,
2649 CL_COL_STYLE, PANGO_STYLE_ITALIC,
2650 CL_COL_WEIGHT, PANGO_WEIGHT_NORMAL,
2651 -1);
2652
2653 prev_parent = parent;
2654 pprev_parent = &prev_parent;
2655 } conn_list_iterate_end;
2656
2657 /* Remove trailing rows. */
2658 if (NULL != pprev_parent) {
2659 parent = prev_parent;
2660 if (gtk_tree_model_iter_next(model, &parent)) {
2661 while (gtk_tree_store_remove(store, &parent)) {
2662 /* Do nothing more. */
2663 }
2664 }
2665 } else {
2666 gtk_tree_store_clear(store);
2667 }
2668
2669 /* If we were selecting a single connection, let's try to reselect it. */
2670 if (NULL == pselected_player && NULL != pselected_conn) {
2671 conn_list_select_conn(pselected_conn);
2672 }
2673 }
2674
2675 update_start_page_buttons();
2676}
2677
2678/**********************************************************************/
2683 static void add_tree_col(GtkWidget *treeview, GType gtype,
2684 const char *title, int colnum, const char *key)
2685{
2686 GtkCellRenderer *rend;
2687 GtkTreeViewColumn *col;
2688
2689 if (gtype == G_TYPE_BOOLEAN) {
2690 rend = gtk_cell_renderer_toggle_new();
2691 col = gtk_tree_view_column_new_with_attributes(title, rend,
2692 "active", colnum, NULL);
2693 } else if (gtype == GDK_TYPE_PIXBUF) {
2694 rend = gtk_cell_renderer_pixbuf_new();
2695 col = gtk_tree_view_column_new_with_attributes(title, rend,
2696 "pixbuf", colnum, NULL);
2697 } else {
2698 rend = gtk_cell_renderer_text_new();
2699 col = gtk_tree_view_column_new_with_attributes(title, rend,
2700 "text", colnum,
2701 "style", CL_COL_STYLE,
2702 "weight", CL_COL_WEIGHT,
2703 NULL);
2704 }
2705
2706 gtk_tree_view_column_set_sizing(col, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
2707 gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), col);
2708
2709 if (key != NULL) {
2710 g_object_set_data(G_OBJECT(treeview), key, col);
2711 }
2712}
2713
2714/**********************************************************************/
2717 GtkWidget *create_start_page(void)
2718{
2719 GtkWidget *box, *sbox, *table, *vgrid;
2720 GtkWidget *view, *sw, *text, *toolkit_view, *button, *spin;
2721 GtkWidget *label;
2722 GtkTreeSelection *selection;
2723 enum ai_level level;
2724 /* There's less than AI_LEVEL_COUNT entries as not all levels have
2725 entries (that's the whole point of this array: index != value),
2726 but this is set safely to the max */
2727 static enum ai_level levels[AI_LEVEL_COUNT];
2728 int i = 0;
2729 int box_row = 0;
2730 int sbox_col = 0;
2731 int grid_row = 0;
2732 GtkGesture *gesture;
2733 GtkEventController *controller;
2734
2735 box = gtk_grid_new();
2736 gtk_orientable_set_orientation(GTK_ORIENTABLE(box),
2737 GTK_ORIENTATION_VERTICAL);
2738 gtk_grid_set_row_spacing(GTK_GRID(box), 8);
2739 gtk_widget_set_margin_start(box, 4);
2740 gtk_widget_set_margin_end(box, 4);
2741 gtk_widget_set_margin_top(box, 4);
2742 gtk_widget_set_margin_bottom(box, 4);
2743
2744 sbox = gtk_grid_new();
2745 gtk_grid_set_column_spacing(GTK_GRID(sbox), 12);
2746 gtk_grid_attach(GTK_GRID(box), sbox, 0, box_row++, 1, 1);
2747
2748 vgrid = gtk_grid_new();
2749 gtk_widget_set_margin_bottom(vgrid, 12);
2750 gtk_widget_set_margin_end(vgrid, 12);
2751 gtk_widget_set_margin_start(vgrid, 12);
2752 gtk_widget_set_margin_top(vgrid, 12);
2753 gtk_orientable_set_orientation(GTK_ORIENTABLE(vgrid),
2754 GTK_ORIENTATION_VERTICAL);
2755 gtk_grid_set_row_spacing(GTK_GRID(vgrid), 2);
2756 gtk_widget_set_halign(vgrid, GTK_ALIGN_CENTER);
2757 gtk_widget_set_valign(vgrid, GTK_ALIGN_CENTER);
2758 gtk_grid_attach(GTK_GRID(sbox), vgrid, sbox_col++, 0, 1, 1);
2759
2760 table = gtk_grid_new();
2761 start_options_table = table;
2762 gtk_grid_set_row_spacing(GTK_GRID(table), 2);
2763 gtk_grid_set_column_spacing(GTK_GRID(table), 12);
2764 gtk_grid_attach(GTK_GRID(vgrid), table, 0, grid_row++, 1, 1);
2765
2766 spin = gtk_spin_button_new_with_range(1, MAX_NUM_PLAYERS, 1);
2767 start_aifill_spin = spin;
2768 gtk_spin_button_set_digits(GTK_SPIN_BUTTON(spin), 0);
2769 gtk_spin_button_set_update_policy(GTK_SPIN_BUTTON(spin),
2770 GTK_UPDATE_IF_VALID);
2771 if (server_optset != NULL) {
2772 struct option *paifill = optset_option_by_name(server_optset, "aifill");
2773
2774 if (paifill) {
2775 gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin),
2776 option_int_get(paifill));
2777 } /* else it'll be updated later */
2778 }
2779 g_signal_connect_after(spin, "value_changed",
2780 G_CALLBACK(ai_fill_changed_by_user), NULL);
2781
2782 gtk_grid_attach(GTK_GRID(table), spin, 1, 0, 1, 1);
2783
2784 label = g_object_new(GTK_TYPE_LABEL,
2785 "use-underline", TRUE,
2786 "mnemonic-widget", spin,
2787 /* TRANS: Keep individual lines short */
2788 "label", _("Number of _Players\n(including AI):"),
2789 "xalign", 0.0,
2790 "yalign", 0.5,
2791 NULL);
2792 gtk_grid_attach(GTK_GRID(table), label, 0, 0, 1, 1);
2793
2794 ai_lvl_combobox = gtk_combo_box_text_new();
2795
2796 for (level = 0; level < AI_LEVEL_COUNT; level++) {
2797 if (is_settable_ai_level(level)) {
2798 const char *level_name = ai_level_translated_name(level);
2799
2800 gtk_combo_box_text_insert_text(GTK_COMBO_BOX_TEXT(ai_lvl_combobox), i, level_name);
2801 levels[i] = level;
2802 i++;
2803 }
2804 }
2805 gtk_combo_box_set_active(GTK_COMBO_BOX(ai_lvl_combobox), -1);
2806 g_signal_connect(ai_lvl_combobox, "changed",
2807 G_CALLBACK(ai_skill_callback), levels);
2808
2809 gtk_grid_attach(GTK_GRID(table), ai_lvl_combobox, 1, 1, 1, 1);
2810
2811 label = g_object_new(GTK_TYPE_LABEL,
2812 "use-underline", TRUE,
2813 "mnemonic-widget", ai_lvl_combobox,
2814 "label", _("AI Skill _Level:"),
2815 "xalign", 0.0,
2816 "yalign", 0.5,
2817 NULL);
2818 gtk_grid_attach(GTK_GRID(table), label, 0, 1, 1, 1);
2819
2820 ruleset_combo = gtk_combo_box_text_new();
2821 g_signal_connect(G_OBJECT(ruleset_combo), "changed",
2822 G_CALLBACK(ruleset_entry_changed), NULL);
2823
2824 gtk_grid_attach(GTK_GRID(table), ruleset_combo, 1, 2, 1, 1);
2825
2826 label = g_object_new(GTK_TYPE_LABEL,
2827 "use-underline", TRUE,
2828 "mnemonic-widget", GTK_COMBO_BOX_TEXT(ruleset_combo),
2829 "label", _("Ruleset:"),
2830 "xalign", 0.0,
2831 "yalign", 0.5,
2832 NULL);
2833 gtk_grid_attach(GTK_GRID(table), label, 0, 2, 1, 1);
2834
2835 button = icon_label_button_new("preferences-system",
2836 _("_More Game Options..."));
2837 gtk_widget_set_margin_bottom(button, 8);
2838 gtk_widget_set_margin_end(button, 8);
2839 gtk_widget_set_margin_start(button, 8);
2840 gtk_widget_set_margin_top(button, 8);
2841 gtk_widget_set_halign(button, GTK_ALIGN_CENTER);
2842 gtk_widget_set_valign(button, GTK_ALIGN_CENTER);
2843 g_signal_connect(button, "clicked",
2844 G_CALLBACK(game_options_callback), NULL);
2845 gtk_grid_attach(GTK_GRID(vgrid), button, 0, grid_row++, 1, 1);
2846
2847 connection_list_store = connection_list_store_new();
2848 view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(connection_list_store));
2849 gtk_widget_set_hexpand(view, TRUE);
2850 g_object_unref(G_OBJECT(connection_list_store));
2851 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view), TRUE);
2852 connection_list_view = GTK_TREE_VIEW(view);
2853
2854 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
2855 gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE);
2856 g_signal_connect(selection, "changed",
2857 G_CALLBACK(update_start_page_buttons), NULL);
2858
2859 add_tree_col(view, G_TYPE_STRING, _("Name"),
2860 CL_COL_USER_NAME, NULL);
2861 add_tree_col(view, G_TYPE_BOOLEAN, _("Ready"),
2862 CL_COL_READY_STATE, NULL);
2863 add_tree_col(view, G_TYPE_STRING, Q_("?player:Leader"),
2864 CL_COL_PLAYER_NAME, NULL);
2865 add_tree_col(view, GDK_TYPE_PIXBUF, _("Flag"),
2866 CL_COL_FLAG, NULL);
2867 add_tree_col(view, GDK_TYPE_PIXBUF, _("Border"),
2868 CL_COL_COLOR, NULL);
2869 add_tree_col(view, G_TYPE_STRING, _("Nation"),
2870 CL_COL_NATION, NULL);
2871 add_tree_col(view, G_TYPE_STRING, _("Team"),
2872 CL_COL_TEAM, NULL);
2873
2874 controller = GTK_EVENT_CONTROLLER(gtk_gesture_click_new());
2875 g_signal_connect(controller, "pressed",
2876 G_CALLBACK(connect_list_left_button), NULL);
2877 gtk_widget_add_controller(view, controller);
2878
2879 g_signal_connect(view, "row-collapsed",
2880 G_CALLBACK(connection_list_row_callback),
2881 GINT_TO_POINTER(TRUE));
2882 g_signal_connect(view, "row-expanded",
2883 G_CALLBACK(connection_list_row_callback),
2884 GINT_TO_POINTER(FALSE));
2885
2886 sw = gtk_scrolled_window_new();
2887 gtk_scrolled_window_set_has_frame(GTK_SCROLLED_WINDOW(sw), TRUE);
2888 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
2889 GTK_POLICY_AUTOMATIC,
2890 GTK_POLICY_ALWAYS);
2891 gtk_scrolled_window_set_min_content_height(GTK_SCROLLED_WINDOW(sw), 200);
2892 gtk_scrolled_window_set_child(GTK_SCROLLED_WINDOW(sw), view);
2893
2894 /* This is for a workaround against gtk bug that we can't parent
2895 * popup to the tree view - we have to parent it all the way to sw */
2896 gesture = gtk_gesture_click_new();
2897 gtk_gesture_single_set_button(GTK_GESTURE_SINGLE(gesture), 3);
2898 controller = GTK_EVENT_CONTROLLER(gesture);
2899 g_signal_connect(controller, "pressed",
2900 G_CALLBACK(connect_list_right_button), sw);
2901 gtk_widget_add_controller(view, controller);
2902
2903 gtk_grid_attach(GTK_GRID(sbox), sw, sbox_col++, 0, 1, 1);
2904
2905 sw = gtk_scrolled_window_new();
2906 gtk_scrolled_window_set_has_frame(GTK_SCROLLED_WINDOW(sw), TRUE);
2907 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
2908 GTK_POLICY_AUTOMATIC,
2909 GTK_POLICY_ALWAYS);
2910 gtk_grid_attach(GTK_GRID(box), sw, 0, box_row++, 1, 1);
2911
2912 text = gtk_text_view_new_with_buffer(message_buffer);
2913 gtk_widget_set_hexpand(text, TRUE);
2914 gtk_widget_set_vexpand(text, TRUE);
2915 start_message_area = text;
2916 gtk_widget_set_name(text, "chatline");
2917 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_WORD);
2918 gtk_text_view_set_left_margin(GTK_TEXT_VIEW(text), 5);
2919 gtk_text_view_set_editable(GTK_TEXT_VIEW(text), FALSE);
2920 gtk_scrolled_window_set_child(GTK_SCROLLED_WINDOW(sw), text);
2921
2922
2923 /* Vote widgets. */
2924 if (pregame_votebar == NULL) {
2925 pregame_votebar = voteinfo_bar_new(TRUE);
2926 }
2927 gtk_grid_attach(GTK_GRID(box), pregame_votebar, 0, box_row++, 1, 1);
2928
2929 toolkit_view = inputline_toolkit_view_new();
2930 gtk_grid_attach(GTK_GRID(box), toolkit_view, 0, box_row++, 1, 1);
2931
2932 button = gtk_button_new_with_mnemonic(_("_Cancel"));
2933 inputline_toolkit_view_append_button(toolkit_view, button);
2934 g_signal_connect(button, "clicked", G_CALLBACK(main_callback), NULL);
2935
2936 nation_button = icon_label_button_new("document-properties",
2937 _("Pick _Nation"));
2938 inputline_toolkit_view_append_button(toolkit_view, nation_button);
2939 g_signal_connect(nation_button, "clicked",
2940 G_CALLBACK(nation_button_callback), NULL);
2941
2942 observe_button = icon_label_button_new("zoom-in", _("_Observe"));
2943 inputline_toolkit_view_append_button(toolkit_view, observe_button);
2944 g_signal_connect(observe_button, "clicked",
2945 G_CALLBACK(observe_button_callback), NULL);
2946
2947 ready_button = icon_label_button_new("system-run", _("_Ready"));
2948 inputline_toolkit_view_append_button(toolkit_view, ready_button);
2949 g_signal_connect(ready_button, "clicked",
2950 G_CALLBACK(ready_button_callback), NULL);
2951
2952 return box;
2953}
2954
2955
2956/**********************************************************************/
2959 void handle_game_load(bool load_successful, const char *filename)
2960{
2961 if (load_successful) {
2962 set_client_page(PAGE_START);
2963
2964 if (game.info.is_new_game) {
2965 /* It's pregame. Create a player and connect to it */
2966 send_chat("/take -");
2967 }
2968 }
2969}
2970
2971/**********************************************************************/
2974 static void load_filename(const char *filename)
2975{
2976 send_chat_printf("/load %s", filename);
2977}
2978
2979/**********************************************************************/
2982 static void load_callback(void)
2983{
2984 GtkTreeIter it;
2985 const gchar *filename;
2986
2987 if (!gtk_tree_selection_get_selected(load_selection, NULL, &it)) {
2988 return;
2989 }
2990
2991 gtk_tree_model_get(GTK_TREE_MODEL(load_store), &it,
2992 SD_COL_FULL_PATH, &filename, -1);
2993 load_filename(filename);
2994}
2995
2996/**********************************************************************/
2999 static void load_browse_callback(GtkWidget *w, gpointer data)
3000{
3001 save_dialog_file_chooser_popup(_("Choose Saved Game to Load"),
3002 GTK_FILE_CHOOSER_ACTION_OPEN,
3003 load_filename);
3004}
3005
3006/**********************************************************************/
3009 static void update_load_page(void)
3010{
3011 /* Search for user saved games. */
3012 struct fileinfo_list *files = fileinfolist_infix(get_save_dirs(),
3013 ".sav", FALSE);
3014
3015 save_dialog_store_update(load_store, files);
3016 fileinfo_list_destroy(files);
3017}
3018
3019/**********************************************************************/
3022 GtkWidget *create_load_page(void)
3023{
3024 GtkWidget *box, *sbox, *bbox;
3025
3026 GtkWidget *button, *label, *view, *sw;
3027 GtkCellRenderer *rend;
3028 int box_row = 0;
3029 int sbox_row = 0;
3030
3031 box = gtk_grid_new();
3032 gtk_orientable_set_orientation(GTK_ORIENTABLE(box),
3033 GTK_ORIENTATION_VERTICAL);
3034 gtk_grid_set_row_spacing(GTK_GRID(box), 18);
3035 gtk_widget_set_margin_start(box, 4);
3036 gtk_widget_set_margin_end(box, 4);
3037 gtk_widget_set_margin_top(box, 4);
3038 gtk_widget_set_margin_bottom(box, 4);
3039
3040 load_store = save_dialog_store_new();
3041 view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(load_store));
3042 gtk_widget_set_vexpand(view, TRUE);
3043 g_object_unref(load_store);
3044
3045 rend = gtk_cell_renderer_text_new();
3046 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
3047 -1, NULL, rend, "text", 0, NULL);
3048
3049 load_selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
3050 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view), FALSE);
3051
3052 gtk_tree_selection_set_mode(load_selection, GTK_SELECTION_SINGLE);
3053
3054 g_signal_connect(view, "row-activated",
3055 G_CALLBACK(load_callback), NULL);
3056
3057 sbox = gtk_grid_new();
3058 gtk_widget_set_halign(sbox, GTK_ALIGN_CENTER);
3059 gtk_orientable_set_orientation(GTK_ORIENTABLE(sbox),
3060 GTK_ORIENTATION_VERTICAL);
3061 gtk_grid_set_row_spacing(GTK_GRID(sbox), 2);
3062 gtk_grid_attach(GTK_GRID(box), sbox, 0, box_row++, 1, 1);
3063
3064 label = g_object_new(GTK_TYPE_LABEL,
3065 "use-underline", TRUE,
3066 "mnemonic-widget", view,
3067 "label", _("Choose Saved Game to _Load:"),
3068 "xalign", 0.0,
3069 "yalign", 0.5,
3070 NULL);
3071 gtk_grid_attach(GTK_GRID(sbox), label, 0, sbox_row++, 1, 1);
3072
3073 sw = gtk_scrolled_window_new();
3074 gtk_scrolled_window_set_min_content_width(GTK_SCROLLED_WINDOW(sw), 300);
3075 gtk_scrolled_window_set_has_frame(GTK_SCROLLED_WINDOW(sw), TRUE);
3076 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_AUTOMATIC,
3077 GTK_POLICY_AUTOMATIC);
3078 gtk_scrolled_window_set_child(GTK_SCROLLED_WINDOW(sw), view);
3079 gtk_grid_attach(GTK_GRID(sbox), sw, 0, sbox_row++, 1, 1);
3080
3081 bbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 2);
3082 gtk_widget_set_hexpand(bbox, TRUE);
3083 gtk_box_set_spacing(GTK_BOX(bbox), 12);
3084 gtk_grid_attach(GTK_GRID(box), bbox, 0, box_row++, 1, 1);
3085
3086 button = gtk_button_new_with_mnemonic(_("_Browse..."));
3087 gtk_box_append(GTK_BOX(bbox), button);
3088 g_signal_connect(button, "clicked",
3089 G_CALLBACK(load_browse_callback), NULL);
3090
3091 button = gtk_button_new_with_mnemonic(_("_Cancel"));
3092 gtk_box_append(GTK_BOX(bbox), button);
3093 g_signal_connect(button, "clicked",
3094 G_CALLBACK(main_callback), NULL);
3095
3096 button = gtk_button_new_with_mnemonic(_("_OK"));
3097 gtk_box_append(GTK_BOX(bbox), button);
3098 g_signal_connect(button, "clicked",
3099 G_CALLBACK(load_callback), NULL);
3100
3101 return box;
3102}
3103
3104/**********************************************************************/
3107 static void scenario_list_callback(void)
3108{
3109 GtkTreeIter it;
3110 GtkTextBuffer *buffer;
3111 char *description;
3112 char *authors;
3113 char *filename;
3114 int ver;
3115 char vername[50];
3116
3117 if (gtk_tree_selection_get_selected(scenario_selection, NULL, &it)) {
3118 gtk_tree_model_get(GTK_TREE_MODEL(scenario_store), &it,
3119 2, &description, -1);
3120 gtk_tree_model_get(GTK_TREE_MODEL(scenario_store), &it,
3121 3, &authors, -1);
3122 gtk_tree_model_get(GTK_TREE_MODEL(scenario_store), &it,
3123 1, &filename, -1);
3124 gtk_tree_model_get(GTK_TREE_MODEL(scenario_store), &it,
3125 4, &ver, -1);
3126 filename = skip_to_basename(filename);
3127 if (ver > 0) {
3128 int maj;
3129 int min;
3130
3131 maj = ver / 1000000;
3132 ver %= 1000000;
3133 min = ver / 10000;
3134 ver %= 10000;
3135 if (ver >= 9000) {
3136 /* Development version, have '+' */
3137 fc_snprintf(vername, sizeof(vername), "%d.%d+", maj, min);
3138 } else {
3139 fc_snprintf(vername, sizeof(vername), "%d.%d", maj, min);
3140 }
3141 } else {
3142 /* TRANS: Old scenario format version */
3143 fc_snprintf(vername, sizeof(vername), _("pre-2.6"));
3144 }
3145 } else {
3146 description = "";
3147 authors = "";
3148 filename = "";
3149 vername[0] = '\0';
3150 }
3151
3152 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(scenario_description));
3153 gtk_text_buffer_set_text(buffer, description, -1);
3154 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(scenario_authors));
3155 gtk_text_buffer_set_text(buffer, authors, -1);
3156 gtk_label_set_text(GTK_LABEL(scenario_filename), filename);
3157 gtk_label_set_text(GTK_LABEL(scenario_version), vername);
3158}
3159
3160/**********************************************************************/
3163 static void scenario_callback(void)
3164{
3165 GtkTreeIter it;
3166 char *filename;
3167
3168 if (!gtk_tree_selection_get_selected(scenario_selection, NULL, &it)) {
3169 return;
3170 }
3171
3172 gtk_tree_model_get(GTK_TREE_MODEL(scenario_store), &it, 1, &filename, -1);
3173 load_filename(filename);
3174}
3175
3176/**********************************************************************/
3179 static void scenario_browse_callback(GtkWidget *w, gpointer data)
3180{
3181 save_dialog_file_chooser_popup(_("Choose a Scenario"),
3182 GTK_FILE_CHOOSER_ACTION_OPEN,
3183 load_filename);
3184}
3185
3186/**********************************************************************/
3189 static void update_scenario_page(void)
3190{
3191 struct fileinfo_list *files;
3192
3193 gtk_list_store_clear(scenario_store);
3194
3195 /* search for scenario files. */
3196 files = fileinfolist_infix(get_scenario_dirs(), ".sav", TRUE);
3197 fileinfo_list_iterate(files, pfile) {
3198 struct section_file *sf;
3199
3200 if ((sf = secfile_load_section(pfile->fullname, "scenario", TRUE))
3201 && secfile_lookup_bool_default(sf, TRUE, "scenario.is_scenario")) {
3202 const char *sname, *sdescription, *sauthors;
3203 int fcver;
3204 int fcdev;
3205 int current_ver = MAJOR_VERSION * 1000000 + MINOR_VERSION * 10000;
3206 int current_dev;
3207
3208 current_dev = current_ver;
3209 if (PATCH_VERSION >= 90) {
3210 /* Patch level matters on development versions */
3211 current_dev += PATCH_VERSION * 100;
3212 }
3213
3214 fcver = secfile_lookup_int_default(sf, 0, "scenario.game_version");
3215 if (fcver < 30000) {
3216 /* Pre-3.0 versions stored version number without emergency version
3217 * part in the end. To get comparable version number stored,
3218 * multiply by 100. */
3219 fcver *= 100;
3220 }
3221 if (fcver % 10000 >= 9000) {
3222 fcdev = fcver - (fcver % 100); /* Emergency version does not count. */
3223 } else {
3224 fcdev = fcver - (fcver % 10000); /* Patch version does not count. */
3225 }
3226 sname = secfile_lookup_str_default(sf, NULL, "scenario.name");
3227 sdescription = secfile_lookup_str_default(sf, NULL,
3228 "scenario.description");
3229 sauthors = secfile_lookup_str_default(sf, NULL, "scenario.authors");
3230 log_debug("scenario file: %s from %s", sname, pfile->fullname);
3231
3232 /* Ignore scenarios for newer freeciv versions than we are. */
3233 if (fcdev <= current_dev) {
3234 bool add_new = TRUE;
3235
3236 if (sname != NULL) {
3237 GtkTreeIter it;
3238 bool valid;
3239
3240 valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(scenario_store), &it);
3241 while (valid) {
3242 char *oname;
3243
3244 gtk_tree_model_get(GTK_TREE_MODEL(scenario_store), &it,
3245 0, &oname, -1);
3246
3247 if (!strcmp(sname, oname)) {
3248 /* Already listed scenario has the same name as the one we just found */
3249 int existing;
3250
3251 gtk_tree_model_get(GTK_TREE_MODEL(scenario_store), &it,
3252 4, &existing, -1);
3253 log_debug("Duplicate %s (%d vs %d)", sname, existing, fcver);
3254
3255 if (existing > fcver) {
3256 /* Already listed one has higher version number */
3257 add_new = FALSE;
3258 } else if (existing < fcver) {
3259 /* New one has higher version number */
3260 add_new = FALSE;
3261
3262 gtk_list_store_set(scenario_store, &it,
3263 0, sname && strlen(sname) ? Q_(sname) : pfile->name,
3264 1, pfile->fullname,
3265 2, (NULL != sdescription && '\0' != sdescription[0]
3266 ? Q_(sdescription) : ""),
3267 3, (NULL != sauthors && sauthors[0] != '\0'
3268 ? Q_(sauthors) : ""),
3269 4, fcver,
3270 -1);
3271 } else {
3272 /* Same version number -> list both */
3273 }
3274 }
3275 valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(scenario_store), &it);
3276 }
3277 }
3278
3279 if (add_new) {
3280 GtkTreeIter it;
3281
3282 gtk_list_store_append(scenario_store, &it);
3283 gtk_list_store_set(scenario_store, &it,
3284 0, sname && strlen(sname) ? Q_(sname) : pfile->name,
3285 1, pfile->fullname,
3286 2, (NULL != sdescription && '\0' != sdescription[0]
3287 ? Q_(sdescription) : ""),
3288 3, (NULL != sauthors && sauthors[0] != '\0'
3289 ? Q_(sauthors) : ""),
3290 4, fcver,
3291 -1);
3292 }
3293 }
3294
3295 secfile_destroy(sf);
3296 }
3297 } fileinfo_list_iterate_end;
3298
3299 fileinfo_list_destroy(files);
3300}
3301
3302/**********************************************************************/
3305 GtkWidget *create_scenario_page(void)
3306{
3307 GtkWidget *vgrid, *hbox, *sbox, *bbox, *filenamebox, *descbox;
3308 GtkWidget *versionbox, *vertext;
3309 GtkWidget *button, *label, *view, *sw, *swa, *text;
3310 GtkCellRenderer *rend;
3311 int grid_row = 0;
3312 int filenamecol = 0;
3313 int vercol = 0;
3314 int descrow = 0;
3315
3316 vgrid = gtk_grid_new();
3317 gtk_orientable_set_orientation(GTK_ORIENTABLE(vgrid),
3318 GTK_ORIENTATION_VERTICAL);
3319 gtk_grid_set_row_spacing(GTK_GRID(vgrid), 18);
3320 gtk_widget_set_margin_start(vgrid, 4);
3321 gtk_widget_set_margin_end(vgrid, 4);
3322 gtk_widget_set_margin_top(vgrid, 4);
3323 gtk_widget_set_margin_bottom(vgrid, 4);
3324
3325 scenario_store = gtk_list_store_new(5, G_TYPE_STRING,
3326 G_TYPE_STRING,
3327 G_TYPE_STRING,
3328 G_TYPE_STRING,
3329 G_TYPE_INT);
3330 view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(scenario_store));
3331 gtk_widget_set_hexpand(view, TRUE);
3332 gtk_widget_set_vexpand(view, TRUE);
3333 g_object_unref(scenario_store);
3334
3335 rend = gtk_cell_renderer_text_new();
3336 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
3337 -1, NULL, rend, "text", 0, NULL);
3338
3339 scenario_selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
3340 g_signal_connect(scenario_selection, "changed",
3341 G_CALLBACK(scenario_list_callback), NULL);
3342 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view), FALSE);
3343
3344 gtk_tree_selection_set_mode(scenario_selection, GTK_SELECTION_SINGLE);
3345
3346 g_signal_connect(view, "row-activated",
3347 G_CALLBACK(scenario_callback), NULL);
3348
3349 label = g_object_new(GTK_TYPE_LABEL,
3350 "use-underline", TRUE,
3351 "mnemonic-widget", view,
3352 "label", _("Choose a _Scenario:"),
3353 "xalign", 0.0,
3354 "yalign", 0.5,
3355 NULL);
3356 gtk_grid_attach(GTK_GRID(vgrid), label, 0, grid_row++, 1, 1);
3357
3358 sbox = gtk_grid_new();
3359 gtk_grid_set_column_spacing(GTK_GRID(sbox), 12);
3360 gtk_grid_set_row_homogeneous(GTK_GRID(sbox), TRUE);
3361 gtk_orientable_set_orientation(GTK_ORIENTABLE(sbox),
3362 GTK_ORIENTATION_VERTICAL);
3363 gtk_grid_set_row_spacing(GTK_GRID(sbox), 2);
3364 gtk_grid_attach(GTK_GRID(vgrid), sbox, 0, grid_row++, 1, 1);
3365
3366 hbox = gtk_grid_new();
3367 gtk_grid_set_column_homogeneous(GTK_GRID(hbox), TRUE);
3368 gtk_grid_set_column_spacing(GTK_GRID(hbox), 12);
3369
3370 sw = gtk_scrolled_window_new();
3371 gtk_scrolled_window_set_has_frame(GTK_SCROLLED_WINDOW(sw), TRUE);
3372 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_AUTOMATIC,
3373 GTK_POLICY_AUTOMATIC);
3374 gtk_scrolled_window_set_child(GTK_SCROLLED_WINDOW(sw), view);
3375 gtk_grid_attach(GTK_GRID(sbox), sw, 0, 0, 1, 2);
3376
3377 text = gtk_text_view_new();
3378 gtk_widget_set_hexpand(text, TRUE);
3379 gtk_widget_set_vexpand(text, TRUE);
3380 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_WORD);
3381 gtk_text_view_set_left_margin(GTK_TEXT_VIEW(text), 2);
3382 gtk_text_view_set_editable(GTK_TEXT_VIEW(text), FALSE);
3383 scenario_description = text;
3384
3385 sw = gtk_scrolled_window_new();
3386 gtk_scrolled_window_set_has_frame(GTK_SCROLLED_WINDOW(sw), TRUE);
3387 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_AUTOMATIC,
3388 GTK_POLICY_AUTOMATIC);
3389 gtk_scrolled_window_set_child(GTK_SCROLLED_WINDOW(sw), text);
3390
3391 text = gtk_text_view_new();
3392 gtk_widget_set_hexpand(text, TRUE);
3393 gtk_widget_set_vexpand(text, TRUE);
3394 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_WORD);
3395 gtk_text_view_set_left_margin(GTK_TEXT_VIEW(text), 2);
3396 gtk_text_view_set_editable(GTK_TEXT_VIEW(text), FALSE);
3397 scenario_authors = text;
3398
3399 swa = gtk_scrolled_window_new();
3400 gtk_scrolled_window_set_has_frame(GTK_SCROLLED_WINDOW(swa), TRUE);
3401 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(swa), GTK_POLICY_AUTOMATIC,
3402 GTK_POLICY_AUTOMATIC);
3403 gtk_scrolled_window_set_child(GTK_SCROLLED_WINDOW(swa), text);
3404
3405 text = gtk_label_new(_("Filename:"));
3406 scenario_filename = gtk_label_new("");
3407 gtk_widget_set_halign(scenario_filename, GTK_ALIGN_START);
3408 gtk_widget_set_valign(scenario_filename, GTK_ALIGN_CENTER);
3409 gtk_label_set_selectable(GTK_LABEL(scenario_filename), TRUE);
3410
3411 filenamebox = gtk_grid_new();
3412 gtk_grid_set_column_spacing(GTK_GRID(hbox), 12);
3413 gtk_widget_set_margin_bottom(filenamebox, 5);
3414 gtk_widget_set_margin_end(filenamebox, 5);
3415 gtk_widget_set_margin_start(filenamebox, 5);
3416 gtk_widget_set_margin_top(filenamebox, 5);
3417
3418 gtk_grid_attach(GTK_GRID(filenamebox), text, filenamecol++, 0, 1, 1);
3419 gtk_grid_attach(GTK_GRID(filenamebox), scenario_filename,
3420 filenamecol++, 0, 1, 1);
3421
3422 /* TRANS: Scenario format version */
3423 vertext = gtk_label_new(_("Format:"));
3424 scenario_version = gtk_label_new("");
3425 gtk_widget_set_halign(scenario_version, GTK_ALIGN_START);
3426 gtk_widget_set_valign(scenario_version, GTK_ALIGN_CENTER);
3427 gtk_label_set_selectable(GTK_LABEL(scenario_version), TRUE);
3428
3429 versionbox = gtk_grid_new();
3430 gtk_grid_set_column_spacing(GTK_GRID(hbox), 12);
3431 gtk_widget_set_margin_bottom(versionbox, 5);
3432 gtk_widget_set_margin_end(versionbox, 5);
3433 gtk_widget_set_margin_start(versionbox, 5);
3434 gtk_widget_set_margin_top(versionbox, 5);
3435
3436 gtk_grid_attach(GTK_GRID(versionbox), vertext, vercol++, 0, 1, 1);
3437 gtk_grid_attach(GTK_GRID(versionbox), scenario_version,
3438 vercol++, 0, 1, 1);
3439
3440 descbox = gtk_grid_new();
3441 gtk_orientable_set_orientation(GTK_ORIENTABLE(descbox),
3442 GTK_ORIENTATION_VERTICAL);
3443 gtk_grid_set_row_spacing(GTK_GRID(descbox), 6);
3444 gtk_grid_attach(GTK_GRID(descbox), sw, 0, descrow++, 1, 1);
3445 gtk_grid_attach(GTK_GRID(descbox), swa, 0, descrow++, 1, 1);
3446 gtk_grid_attach(GTK_GRID(descbox), filenamebox,
3447 0, descrow++, 1, 1);
3448 gtk_grid_attach(GTK_GRID(descbox), versionbox,
3449 0, descrow++, 1, 1);
3450 gtk_grid_attach(GTK_GRID(sbox), descbox, 1, 0, 1, 2);
3451
3452 bbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 2);
3453 gtk_box_set_spacing(GTK_BOX(bbox), 12);
3454 gtk_grid_attach(GTK_GRID(vgrid), bbox, 0, grid_row++, 1, 1);
3455
3456 button = gtk_button_new_with_mnemonic(_("_Browse..."));
3457 gtk_box_append(GTK_BOX(bbox), button);
3458 g_signal_connect(button, "clicked",
3459 G_CALLBACK(scenario_browse_callback), NULL);
3460
3461 button = gtk_button_new_with_mnemonic(_("_Cancel"));
3462 gtk_box_append(GTK_BOX(bbox), button);
3463 g_signal_connect(button, "clicked",
3464 G_CALLBACK(main_callback), NULL);
3465
3466 button = gtk_button_new_with_mnemonic(_("_OK"));
3467 gtk_box_append(GTK_BOX(bbox), button);
3468 g_signal_connect(button, "clicked",
3469 G_CALLBACK(scenario_callback), NULL);
3470
3471 return vgrid;
3472}
3473
3474/**********************************************************************/
3477 enum client_pages get_current_client_page(void)
3478{
3479 return current_page;
3480}
3481
3482/**********************************************************************/
3485 void real_set_client_page(enum client_pages new_page)
3486{
3487 /* Don't use current_page directly here because maybe it could be modified
3488 * before we reach the end of this function. */
3489 enum client_pages old_page = current_page;
3490
3491 /* If the page remains the same, don't do anything. */
3492 if (old_page == new_page) {
3493 return;
3494 }
3495
3496 log_debug("Switching client page from %s to %s.",
3497 -1 == old_page ? "(no page)" : client_pages_name(old_page),
3498 client_pages_name(new_page));
3499
3500 current_page = new_page;
3501
3502 switch (old_page) {
3503 case PAGE_SCENARIO:
3504 case PAGE_LOAD:
3505 break;
3506 case PAGE_GAME:
3507 {
3508 struct video_mode *vmode = resolution_request_get();
3509
3510 enable_menus(FALSE);
3511 if (vmode == NULL) {
3512 gtk_window_unmaximize(GTK_WINDOW(toplevel));
3513 }
3514 }
3515 break;
3516 default:
3517 break;
3518 }
3519
3520 switch (new_page) {
3521 case PAGE_MAIN:
3522 case PAGE_START:
3523 if (is_server_running()) {
3524 gtk_widget_set_visible(start_options_table, game.info.is_new_game);
3525 update_start_page();
3526 } else {
3527 gtk_widget_set_visible(start_options_table, FALSE);
3528 }
3529 voteinfo_gui_update();
3530 overview_size_changed();
3531 conn_list_dialog_update();
3532 break;
3533 case PAGE_GAME:
3534 {
3535 struct video_mode *vmode = resolution_request_get();
3536
3537 reset_unit_table();
3538 enable_menus(TRUE);
3539 if (vmode == NULL) {
3540 gtk_window_maximize(GTK_WINDOW(toplevel));
3541 }
3542 voteinfo_gui_update();
3543 mapview_freeze();
3544 }
3545 break;
3546 case PAGE_LOAD:
3547 update_load_page();
3548 break;
3549 case PAGE_SCENARIO:
3550 update_scenario_page();
3551 break;
3552 case PAGE_NETWORK:
3553 update_network_page();
3554 break;
3555 }
3556
3557 /* Hide/show statusbar. */
3558 if (new_page == PAGE_START || new_page == PAGE_GAME) {
3559 clear_network_statusbar();
3560 gtk_widget_set_visible(statusbar_frame, FALSE);
3561 } else {
3562 gtk_widget_set_visible(statusbar_frame, TRUE);
3563 }
3564
3565 gtk_notebook_set_current_page(GTK_NOTEBOOK(toplevel_tabs), new_page);
3566
3567 /* Update the GUI. */
3568 while (g_main_context_pending(NULL)) {
3569 g_main_context_iteration(NULL, FALSE);
3570 }
3571
3572 switch (new_page) {
3573 case PAGE_MAIN:
3574 break;
3575 case PAGE_START:
3576 chatline_scroll_to_bottom(FALSE);
3577 inputline_grab_focus();
3578 break;
3579 case PAGE_LOAD:
3580 gtk_tree_view_focus(gtk_tree_selection_get_tree_view(load_selection));
3581 break;
3582 case PAGE_SCENARIO:
3583 gtk_tree_view_focus(gtk_tree_selection_get_tree_view(scenario_selection));
3584 break;
3585 case PAGE_GAME:
3586 chatline_scroll_to_bottom(FALSE);
3587 refresh_chat_buttons();
3588 center_on_something();
3589 mapview_thaw();
3590 add_idle_callback(main_message_area_resize, NULL);
3591 add_idle_callback(animation_idle_cb, NULL);
3592 break;
3593 case PAGE_NETWORK:
3594 update_network_lists();
3595 gtk_widget_grab_focus(network_login);
3596 gtk_editable_set_position(GTK_EDITABLE(network_login), 0);
3597 set_connection_state(connection_status);
3598 break;
3599 }
3600}
3601
3602/****************************************************************************
3603 SAVE GAME DIALOGs
3604****************************************************************************/
3605
3606/**********************************************************************/
3609 static struct fileinfo_list *save_dialog_savegame_list(void)
3610{
3611 return fileinfolist_infix(get_save_dirs(), ".sav", FALSE);
3612}
3613
3614/**********************************************************************/
3617 void save_game_dialog_popup(void)
3618{
3619 static GtkWidget *shell = NULL;
3620
3621 if (NULL != shell) {
3622 return;
3623 }
3624
3625 shell = save_dialog_new(_("Save Game"), _("Saved _Games:"),
3626 _("Save _Filename:"), send_save_game,
3627 save_dialog_savegame_list);
3628 g_signal_connect(shell, "destroy", G_CALLBACK(widget_destroyed),
3629 &shell);
3630 gtk_window_present(GTK_WINDOW(shell));
3631}
3632
3633/**********************************************************************/
3636 static void save_dialog_save_scenario(const char *filename)
3637{
3638 dsend_packet_save_scenario(&client.conn, filename);
3639}
3640
3641/**********************************************************************/
3644 static struct fileinfo_list *save_dialog_scenario_list(void)
3645{
3646 return fileinfolist_infix(get_scenario_dirs(), ".sav", FALSE);
3647}
3648
3649/**********************************************************************/
3652 void save_scenario_dialog_popup(void)
3653{
3654 static GtkWidget *shell = NULL;
3655
3656 if (NULL != shell) {
3657 return;
3658 }
3659
3660 shell = save_dialog_new(_("Save Scenario"), _("Saved Sce_narios:"),
3661 _("Save Sc_enario:"), save_dialog_save_scenario,
3662 save_dialog_scenario_list);
3663 g_signal_connect(shell, "destroy", G_CALLBACK(widget_destroyed),
3664 &shell);
3665 gtk_window_present(GTK_WINDOW(shell));
3666}
3667
3668/**********************************************************************/
3673 static struct fileinfo_list *save_dialog_mapimg_list(void)
3674{
3675 return fileinfolist_infix(get_save_dirs(), ".map", FALSE);
3676}
3677
3678/**********************************************************************/
3681 void save_mapimg_dialog_popup(void)
3682{
3683 static GtkWidget *shell = NULL;
3684
3685 if (NULL != shell) {
3686 return;
3687 }
3688
3689 shell = save_dialog_new(_("Save Map Image"), _("Saved Map _Images:"),
3690 _("Save _Map Images:"), mapimg_client_save,
3691 save_dialog_mapimg_list);
3692 g_signal_connect(shell, "destroy", G_CALLBACK(widget_destroyed),
3693 &shell);
3694 gtk_window_present(GTK_WINDOW(shell));
3695}
3696
3697/**********************************************************************/
3700 void mapimg_client_save(const char *filename)
3701{
3702 if (!mapimg_client_createmap(filename)) {
3703 char msg[512];
3704
3705 fc_snprintf(msg, sizeof(msg), "(%s)", mapimg_error());
3706 popup_notify_dialog(_("Error"),
3707 _("Error Creating the Map Image!"), msg);
3708 }
3709}
3710
3711/**********************************************************************/
3716 void set_rulesets(int num_rulesets, char **rulesets)
3717{
3718 int i;
3719 int def_idx = -1;
3720
3721 gtk_combo_box_text_remove_all(GTK_COMBO_BOX_TEXT(ruleset_combo));
3722 for (i = 0; i < num_rulesets; i++) {
3723
3724 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(ruleset_combo), rulesets[i]);
3725 if (!strcmp("default", rulesets[i])) {
3726 def_idx = i;
3727 }
3728 }
3729
3730 no_ruleset_callback = TRUE;
3731
3732 /* HACK: Server should tell us the current ruleset. */
3733 gtk_combo_box_set_active(GTK_COMBO_BOX(ruleset_combo), def_idx);
3734
3735 no_ruleset_callback = FALSE;
3736}
n
#define n
Definition astring.c:77
height
struct canvas int int struct sprite int int int int height
Definition canvas_g.h:44
width
struct canvas int int struct sprite int int int width
Definition canvas_g.h:44
chat.h
SERVER_COMMAND_PREFIX_STR
#define SERVER_COMMAND_PREFIX_STR
Definition chat.h:29
send_chat_printf
int send_chat_printf(const char *format,...)
Definition chatline_common.c:55
send_chat
int send_chat(const char *message)
Definition chatline_common.c:46
output_window_append
void output_window_append(const struct ft_color color, const char *featured_text)
Definition chatline_common.c:104
can_client_control
bool can_client_control(void)
Definition client_main.c:1253
client_is_global_observer
bool client_is_global_observer(void)
Definition client_main.c:1345
client_is_observer
bool client_is_observer(void)
Definition client_main.c:1083
user_name
char user_name[512]
Definition client_main.c:142
server_host
char server_host[512]
Definition client_main.c:141
client
struct civclient client
Definition client_main.c:150
client_state
enum client_states client_state(void)
Definition client_main.c:1026
fc_password
char fc_password[MAX_LEN_PASSWORD]
Definition client_main.c:143
server_port
int server_port
Definition client_main.c:145
client_main.h
client_player
#define client_player()
Definition client_main.h:106
C_S_PREPARING
@ C_S_PREPARING
Definition client_main.h:46
server_ai_level
enum ai_level server_ai_level(void)
Definition climisc.c:1508
mapimg_client_createmap
bool mapimg_client_createmap(const char *filename)
Definition climisc.c:1455
center_on_something
void center_on_something(void)
Definition climisc.c:430
climisc.h
list
static struct fc_sockaddr_list * list
Definition clinet.c:102
connect_to_server
int connect_to_server(const char *username, const char *hostname, int port, char *errbuf, int errbufsize)
Definition clinet.c:249
disconnect_from_server
void disconnect_from_server(bool leaving_sound)
Definition clinet.c:306
clinet.h
incite_cost
char * incite_cost
Definition comments.c:74
authentication_type
authentication_type
Definition conn_types.h:41
AUTH_NEWUSER_RETRY
@ AUTH_NEWUSER_RETRY
Definition conn_types.h:45
AUTH_NEWUSER_FIRST
@ AUTH_NEWUSER_FIRST
Definition conn_types.h:43
AUTH_LOGIN_RETRY
@ AUTH_LOGIN_RETRY
Definition conn_types.h:44
AUTH_LOGIN_FIRST
@ AUTH_LOGIN_FIRST
Definition conn_types.h:42
send_save_game
void send_save_game(const char *filename)
Definition connectdlg_common.c:743
set_ruleset
void set_ruleset(const char *ruleset)
Definition connectdlg_common.c:784
is_server_running
bool is_server_running(void)
Definition connectdlg_common.c:124
client_start_server
bool client_start_server(void)
Definition connectdlg_common.c:224
can_client_access_hack
bool can_client_access_hack(void)
Definition connectdlg_common.c:141
connectdlg_common.h
conn_description
const char * conn_description(const struct connection *pconn)
Definition connection.c:474
conn_by_number
struct connection * conn_by_number(int id)
Definition connection.c:421
conn_list_iterate
#define conn_list_iterate(connlist, pconn)
Definition connection.h:108
conn_list_iterate_end
#define conn_list_iterate_end
Definition connection.h:110
dataio.h
popup_notify_dialog
popup_notify_dialog
Definition dialogs_g.h:37
id
int int id
Definition editgui_g.h:28
MAX_NUM_PLAYERS
#define MAX_NUM_PLAYERS
Definition fc_types.h:36
MAX_LEN_NAME
#define MAX_LEN_NAME
Definition fc_types.h:66
fcintl.h
Q_
#define Q_(String)
Definition fcintl.h:70
_
#define _(String)
Definition fcintl.h:67
fc_mutex_allocate
void fc_mutex_allocate(fc_mutex *mutex)
fc_mutex_release
void fc_mutex_release(fc_mutex *mutex)
ftc_client
const struct ft_color ftc_client
Definition featured_text.c:78
game
struct civ_game game
Definition game.c:62
game.h
layout
static PangoLayout * layout
Definition canvas.c:325
inputline_toolkit_view_append_button
void inputline_toolkit_view_append_button(GtkWidget *toolkit_view, GtkWidget *button)
Definition chatline.c:1293
inputline_toolkit_view_new
GtkWidget * inputline_toolkit_view_new(void)
Definition chatline.c:1271
inputline_grab_focus
void inputline_grab_focus(void)
Definition chatline.c:80
chatline_scroll_to_bottom
void chatline_scroll_to_bottom(bool delayed)
Definition chatline.c:1007
popup_races_dialog
void popup_races_dialog(struct player *pplayer)
Definition dialogs.c:1215
pos
static struct tile * pos
Definition finddlg.c:53
client_string
const char * client_string
Definition gui_main.c:105
message_buffer
GtkTextBuffer * message_buffer
Definition gui_main.c:178
resolution_request_get
struct video_mode * resolution_request_get(void)
Definition gui_main.c:2633
enable_menus
void enable_menus(bool enable)
Definition gui_main.c:1074
refresh_chat_buttons
void refresh_chat_buttons(void)
Definition gui_main.c:2531
add_idle_callback
void add_idle_callback(void(callback)(void *), void *data)
Definition gui_main.c:2427
reset_unit_table
void reset_unit_table(void)
Definition gui_main.c:1045
toplevel
GtkWidget * toplevel
Definition gui_main.c:125
quit_gtk_main
void quit_gtk_main(void)
Definition gui_main.c:2359
vmode
static struct video_mode vmode
Definition gui_main.c:191
toplevel_tabs
GtkWidget * toplevel_tabs
Definition gui_main.c:127
screen_height
int screen_height(void)
Definition gui_main.c:2615
GUI_GTK_OPTION
#define GUI_GTK_OPTION(optname)
Definition gui_main.h:25
gtk_tree_view_focus
void gtk_tree_view_focus(GtkTreeView *view)
Definition gui_stuff.c:236
gtk_stockbutton_set_label
void gtk_stockbutton_set_label(GtkWidget *button, const gchar *label_text)
Definition gui_stuff.c:96
icon_label_button_new
GtkWidget * icon_label_button_new(const gchar *icon_name, const gchar *label_text)
Definition gui_stuff.c:76
add_treeview_column
GtkTreeViewColumn * add_treeview_column(GtkWidget *view, const char *title, GType gtype, int model_index)
Definition gui_stuff.c:1123
setup_dialog
void setup_dialog(GtkWidget *shell, GtkWidget *parent)
Definition gui_stuff.c:287
mapview_freeze
void mapview_freeze(void)
Definition mapview.c:373
overview_size_changed
void overview_size_changed(void)
Definition mapview.c:326
mapview_thaw
void mapview_thaw(void)
Definition mapview.c:381
shell
static struct gui_dialog * shell
Definition messagedlg.c:39
option_dialog_popup
void option_dialog_popup(const char *name, const struct option_set *poptset)
Definition optiondlg.c:972
load_store
static GtkListStore * load_store
Definition pages.c:68
update_network_page
static void update_network_page(void)
Definition pages.c:1169
handle_game_load
void handle_game_load(bool load_successful, const char *filename)
Definition pages.c:2825
create_start_page
GtkWidget * create_start_page(void)
Definition pages.c:2607
create_network_page
GtkWidget * create_network_page(void)
Definition pages.c:1185
client_aitoggle_player
static void client_aitoggle_player(void *data)
Definition pages.c:1493
nation_button
static GtkWidget * nation_button
Definition pages.c:1444
update_server_list
static void update_server_list(enum server_scan_type sstype, const struct server_list *list)
Definition pages.c:688
start_scenario_callback
static void start_scenario_callback(GtkWidget *w, gpointer data)
Definition pages.c:115
scenario_selection
static GtkTreeSelection * scenario_selection
Definition pages.c:73
update_start_page_buttons
static void update_start_page_buttons(void)
Definition pages.c:2183
save_dialog_response_callback
static void save_dialog_response_callback(GtkWidget *w, gint response, gpointer data)
Definition pages.c:473
create_scenario_page
GtkWidget * create_scenario_page(void)
Definition pages.c:3169
show_conn_popup
static void show_conn_popup(struct player *pplayer, struct connection *pconn)
Definition pages.c:1751
network_confirm_password_label
static GtkWidget * network_confirm_password_label
Definition pages.c:683
save_mapimg_dialog_popup
void save_mapimg_dialog_popup(void)
Definition pages.c:3535
ruleset_selected
static void ruleset_selected(const char *name)
Definition pages.c:1599
ready_button_callback
static void ready_button_callback(GtkWidget *w, gpointer data)
Definition pages.c:2129
conn_list_selection
static bool conn_list_selection(struct player **ppplayer, struct connection **ppconn)
Definition pages.c:2042
meta_scan
static struct server_scan_timer_data meta_scan
Definition pages.c:86
update_network_lists
static void update_network_lists(void)
Definition pages.c:822
statusbar
static GtkWidget * statusbar
Definition pages.c:89
server_playerlist_view
static GtkWidget * server_playerlist_view
Definition pages.c:71
save_dialog_store_new
static GtkListStore * save_dialog_store_new(void)
Definition pages.c:383
append_network_statusbar
void append_network_statusbar(const char *text, bool force)
Definition pages.c:878
update_network_statusbar
static gboolean update_network_statusbar(gpointer data)
Definition pages.c:848
set_rulesets
void set_rulesets(int num_rulesets, char **rulesets)
Definition pages.c:3570
mapimg_client_save
void mapimg_client_save(const char *filename)
Definition pages.c:3554
conn_menu_player_command
static void conn_menu_player_command(GObject *object, gpointer data)
Definition pages.c:1710
load_filename
static void load_filename(const char *filename)
Definition pages.c:2840
conn_menu_nation_chosen
static void conn_menu_nation_chosen(GObject *object, gpointer data)
Definition pages.c:1697
scenario_description
static GtkWidget * scenario_description
Definition pages.c:63
save_game_dialog_popup
void save_game_dialog_popup(void)
Definition pages.c:3471
get_current_client_page
enum client_pages get_current_client_page(void)
Definition pages.c:3329
lan_store
static GtkListStore * lan_store
Definition pages.c:68
connection_status
static enum connection_state connection_status
Definition pages.c:843
save_dialog_columns
save_dialog_columns
Definition pages.c:367
SD_COL_NUM
@ SD_COL_NUM
Definition pages.c:371
SD_COL_FULL_PATH
@ SD_COL_FULL_PATH
Definition pages.c:369
SD_COL_PRETTY_NAME
@ SD_COL_PRETTY_NAME
Definition pages.c:368
lan_scan
static struct server_scan_timer_data lan_scan
Definition pages.c:87
save_dialog_list_callback
static void save_dialog_list_callback(GtkTreeSelection *selection, gpointer data)
Definition pages.c:541
connect_network_game_callback
static void connect_network_game_callback(GtkWidget *w, gpointer data)
Definition pages.c:132
connection_list_view
static GtkTreeView * connection_list_view
Definition pages.c:1446
network_login
static GtkWidget * network_login
Definition pages.c:679
network_login_label
static GtkWidget * network_login_label
Definition pages.c:679
connection_state
connection_state
Definition pages.c:836
LOGIN_TYPE
@ LOGIN_TYPE
Definition pages.c:837
NEW_PASSWORD_TYPE
@ NEW_PASSWORD_TYPE
Definition pages.c:838
WAITING_TYPE
@ WAITING_TYPE
Definition pages.c:840
ENTER_PASSWORD_TYPE
@ ENTER_PASSWORD_TYPE
Definition pages.c:839
connect_callback
static void connect_callback(GtkWidget *w, gpointer data)
Definition pages.c:1027
scenario_browse_callback
static void scenario_browse_callback(GtkWidget *w, gpointer data)
Definition pages.c:3043
meta_store
static GtkListStore * meta_store
Definition pages.c:68
connection_list_columns
connection_list_columns
Definition pages.c:1452
CL_COL_STYLE
@ CL_COL_STYLE
Definition pages.c:1462
CL_COL_USER_NAME
@ CL_COL_USER_NAME
Definition pages.c:1454
CL_COL_READY_STATE
@ CL_COL_READY_STATE
Definition pages.c:1455
CL_COL_WEIGHT
@ CL_COL_WEIGHT
Definition pages.c:1463
CL_COL_PLAYER_NAME
@ CL_COL_PLAYER_NAME
Definition pages.c:1456
CL_COL_NATION
@ CL_COL_NATION
Definition pages.c:1459
CL_COL_CONN_ID
@ CL_COL_CONN_ID
Definition pages.c:1461
CL_COL_PLAYER_NUMBER
@ CL_COL_PLAYER_NUMBER
Definition pages.c:1453
CL_NUM_COLUMNS
@ CL_NUM_COLUMNS
Definition pages.c:1466
CL_COL_TEAM
@ CL_COL_TEAM
Definition pages.c:1460
CL_COL_COLOR
@ CL_COL_COLOR
Definition pages.c:1458
CL_COL_COLLAPSED
@ CL_COL_COLLAPSED
Definition pages.c:1464
CL_COL_FLAG
@ CL_COL_FLAG
Definition pages.c:1457
update_load_page
static void update_load_page(void)
Definition pages.c:2875
save_dialog_update
static void save_dialog_update(struct save_dialog *pdialog)
Definition pages.c:411
scenario_authors
static GtkWidget * scenario_authors
Definition pages.c:64
start_aifill_spin
static GtkWidget * start_aifill_spin
Definition pages.c:1447
ruleset_entry_changed
static void ruleset_entry_changed(GtkWidget *w, gpointer data)
Definition pages.c:1611
save_dialog_action_fn_t
void(* save_dialog_action_fn_t)(const char *filename)
Definition pages.c:356
open_settings
static void open_settings(void)
Definition pages.c:141
set_connection_state
static void set_connection_state(enum connection_state state)
Definition pages.c:914
ruleset_combo
static GtkWidget * ruleset_combo
Definition pages.c:93
observe_button_callback
static void observe_button_callback(GtkWidget *w, gpointer data)
Definition pages.c:2163
conn_menu_ready_chosen
static void conn_menu_ready_chosen(GObject *object, gpointer data)
Definition pages.c:1684
server_scan_error
static void server_scan_error(struct server_scan *scan, const char *message)
Definition pages.c:809
load_callback
static void load_callback(void)
Definition pages.c:2848
save_dialog_file_chooser_callback
static void save_dialog_file_chooser_callback(GtkWidget *widget, gint response, gpointer data)
Definition pages.c:428
network_list_callback
static void network_list_callback(GtkTreeSelection *select, gpointer data)
Definition pages.c:1123
server_playerlist_store
static GtkListStore * server_playerlist_store
Definition pages.c:70
nation_button_callback
static void nation_button_callback(GtkWidget *w, gpointer data)
Definition pages.c:2143
real_set_client_page
void real_set_client_page(enum client_pages new_page)
Definition pages.c:3337
conn_menu_connection_command
static void conn_menu_connection_command(GObject *object, gpointer data)
Definition pages.c:1737
scenario_list_callback
static void scenario_list_callback(void)
Definition pages.c:2971
intro_expose
static gboolean intro_expose(GtkWidget *w, cairo_t *cr, gpointer *data)
Definition pages.c:164
load_browse_callback
static void load_browse_callback(GtkWidget *w, gpointer data)
Definition pages.c:2865
network_activate_callback
static void network_activate_callback(GtkTreeView *view, GtkTreePath *arg1, GtkTreeViewColumn *arg2, gpointer data)
Definition pages.c:1082
save_dialog_scenario_list
static struct fileinfo_list * save_dialog_scenario_list(void)
Definition pages.c:3498
connection_state_reset
static void connection_state_reset(void)
Definition pages.c:982
real_conn_list_dialog_update
void real_conn_list_dialog_update(void *unused)
Definition pages.c:2328
holding_srv_list_mutex
static bool holding_srv_list_mutex
Definition pages.c:95
connection_list_store
static GtkTreeStore * connection_list_store
Definition pages.c:1445
save_dialog_savegame_list
static struct fileinfo_list * save_dialog_savegame_list(void)
Definition pages.c:3463
start_new_game_callback
static void start_new_game_callback(GtkWidget *w, gpointer data)
Definition pages.c:102
destroy_server_scans
void destroy_server_scans(void)
Definition pages.c:752
save_scenario_dialog_popup
void save_scenario_dialog_popup(void)
Definition pages.c:3506
lan_selection
static GtkTreeSelection * lan_selection
Definition pages.c:74
save_dialog_save_scenario
static void save_dialog_save_scenario(const char *filename)
Definition pages.c:3490
save_dialog_files_fn_t
struct fileinfo_list *(* save_dialog_files_fn_t)(void)
Definition pages.c:357
check_server_scan
static gboolean check_server_scan(gpointer data)
Definition pages.c:775
save_dialog_store_update
static void save_dialog_store_update(GtkListStore *store, const struct fileinfo_list *files)
Definition pages.c:393
ai_fill_changed_by_user
static void ai_fill_changed_by_user(GtkWidget *w, gpointer data)
Definition pages.c:1626
delayed_unselect_path
static gboolean delayed_unselect_path(gpointer data)
Definition pages.c:1957
conn_menu_player_take
static void conn_menu_player_take(GObject *object, gpointer data)
Definition pages.c:1724
conn_menu_info_chosen
static void conn_menu_info_chosen(GObject *object, gpointer data)
Definition pages.c:1782
model_get_player_iter
static bool model_get_player_iter(GtkTreeModel *model, GtkTreeIter *iter, GtkTreeIter *start, const struct player *pplayer)
Definition pages.c:2268
load_selection
static GtkTreeSelection * load_selection
Definition pages.c:73
ai_skill_callback
static void ai_skill_callback(GtkWidget *w, gpointer data)
Definition pages.c:1573
current_page
static enum client_pages current_page
Definition pages.c:78
statusbar_frame
static GtkWidget * statusbar_frame
Definition pages.c:89
network_confirm_password
static GtkWidget * network_confirm_password
Definition pages.c:683
client_take_player
static void client_take_player(struct player *pplayer)
Definition pages.c:1507
clear_network_statusbar
static void clear_network_statusbar(void)
Definition pages.c:864
meta_selection
static GtkTreeSelection * meta_selection
Definition pages.c:74
save_dialog_row_callback
static void save_dialog_row_callback(GtkTreeView *tree_view, GtkTreePath *path, GtkTreeViewColumn *column, gpointer data)
Definition pages.c:522
connection_list_row_callback
static void connection_list_row_callback(GtkTreeView *tree_view, GtkTreeIter *iter, GtkTreePath *path, gpointer data)
Definition pages.c:2027
save_dialog_response
save_dialog_response
Definition pages.c:374
SD_RES_DELETE
@ SD_RES_DELETE
Definition pages.c:376
SD_RES_SAVE
@ SD_RES_SAVE
Definition pages.c:377
SD_RES_BROWSE
@ SD_RES_BROWSE
Definition pages.c:375
create_load_page
GtkWidget * create_load_page(void)
Definition pages.c:2888
ai_lvl_combobox
static GtkWidget * ai_lvl_combobox
Definition pages.c:1448
network_password_label
static GtkWidget * network_password_label
Definition pages.c:682
save_dialog_new
static GtkWidget * save_dialog_new(const char *title, const char *savelabel, const char *savefilelabel, save_dialog_action_fn_t action, save_dialog_files_fn_t files)
Definition pages.c:562
intro_free
static void intro_free(GtkWidget *w, gpointer *data)
Definition pages.c:219
network_password
static GtkWidget * network_password
Definition pages.c:682
network_host
static GtkWidget * network_host
Definition pages.c:680
handle_authentication_req
void handle_authentication_req(enum authentication_type type, const char *message)
Definition pages.c:991
connection_list_store_new
static GtkTreeStore * connection_list_store_new(void)
Definition pages.c:1472
send_new_aifill_to_server
static bool send_new_aifill_to_server
Definition pages.c:1625
save_dialog_file_chooser_popup
static void save_dialog_file_chooser_popup(const char *title, GtkFileChooserAction action, save_dialog_action_fn_t cb)
Definition pages.c:448
network_port
static GtkWidget * network_port
Definition pages.c:681
add_tree_col
static void add_tree_col(GtkWidget *treeview, GType gtype, const char *title, int colnum, const char *key)
Definition pages.c:2573
save_dialog_entry_callback
static void save_dialog_entry_callback(GtkEntry *entry, gpointer data)
Definition pages.c:533
main_callback
static void main_callback(GtkWidget *w, gpointer data)
Definition pages.c:149
update_start_page
void update_start_page(void)
Definition pages.c:1659
scenario_callback
static void scenario_callback(void)
Definition pages.c:3027
start_options_table
static GtkWidget * start_options_table
Definition pages.c:1443
no_ruleset_callback
static bool no_ruleset_callback
Definition pages.c:1594
ai_fill_changed_by_server
void ai_fill_changed_by_server(int aifill)
Definition pages.c:1637
update_server_playerlist
static void update_server_playerlist(const struct server *pserver)
Definition pages.c:1094
observe_button
static GtkWidget * observe_button
Definition pages.c:1444
scenario_version
static GtkWidget * scenario_version
Definition pages.c:66
create_statusbar
GtkWidget * create_statusbar(void)
Definition pages.c:893
game_options_callback
static void game_options_callback(GtkWidget *w, gpointer data)
Definition pages.c:1565
scenario_store
static GtkListStore * scenario_store
Definition pages.c:68
network_host_label
static GtkWidget * network_host_label
Definition pages.c:680
model_get_conn_iter
static bool model_get_conn_iter(GtkTreeModel *model, GtkTreeIter *iter, GtkTreeIter *parent, GtkTreeIter *start, const struct connection *pconn)
Definition pages.c:2299
statusbar_queue
static GQueue * statusbar_queue
Definition pages.c:90
start_message_area
GtkWidget * start_message_area
Definition pages.c:1441
network_port_label
static GtkWidget * network_port_label
Definition pages.c:681
update_scenario_page
static void update_scenario_page(void)
Definition pages.c:3053
scenario_filename
static GtkWidget * scenario_filename
Definition pages.c:65
conn_menu_team_chosen
static void conn_menu_team_chosen(GObject *object, gpointer data)
Definition pages.c:1667
create_conn_menu
static GtkWidget * create_conn_menu(struct player *pplayer, struct connection *pconn)
Definition pages.c:1796
load_saved_game_callback
static void load_saved_game_callback(GtkWidget *w, gpointer data)
Definition pages.c:124
statusbar_timer
static guint statusbar_timer
Definition pages.c:91
object_extract
static bool object_extract(GObject *object, struct player **ppplayer, struct connection **ppconn)
Definition pages.c:1538
object_put
static void object_put(GObject *object, struct player *pplayer, struct connection *pconn)
Definition pages.c:1519
save_dialog_mapimg_list
static struct fileinfo_list * save_dialog_mapimg_list(void)
Definition pages.c:3527
create_main_page
GtkWidget * create_main_page(void)
Definition pages.c:229
conn_list_select_conn
static void conn_list_select_conn(struct connection *pconn)
Definition pages.c:2078
ready_button
static GtkWidget * ready_button
Definition pages.c:1444
create_player_icon
GdkPixbuf * create_player_icon(const struct player *plr)
Definition plrdlg.c:117
get_flag
GdkPixbuf * get_flag(const struct nation_type *nation)
Definition plrdlg.c:607
title
const char * title
Definition repodlgs.c:1314
type
GType type
Definition repodlgs.c:1313
free_sprite
void free_sprite(struct sprite *s)
Definition sprite.c:278
sprite_scale
struct sprite * sprite_scale(struct sprite *src, int new_w, int new_h)
Definition sprite.c:291
load_gfxfile
struct sprite * load_gfxfile(const char *filename, bool svgflag)
Definition sprite.c:170
voteinfo_gui_update
void voteinfo_gui_update(void)
Definition voteinfo_bar.c:214
voteinfo_bar_new
GtkWidget * voteinfo_bar_new(bool split_bar)
Definition voteinfo_bar.c:92
pregame_votebar
GtkWidget * pregame_votebar
Definition voteinfo_bar.c:49
terminate_signal_processing
gboolean terminate_signal_processing(GtkEventControllerFocus *controller, gpointer data)
Definition gui_main.c:1050
animation_idle_cb
void animation_idle_cb(void *data)
Definition gui_main.c:2436
main_message_area_resize
void main_message_area_resize(void *data)
Definition gui_main.c:368
widget_destroyed
void widget_destroyed(GtkWidget *wdg, void *data)
Definition gui_stuff.c:1155
menu_item_append_unref
#define menu_item_append_unref(menu, item)
Definition gui_stuff.h:149
connect_list_right_button
static gboolean connect_list_right_button(GtkGestureClick *gesture, int n_press, double x, double y, gpointer data)
Definition pages.c:2084
close_conn_menu_popover
static void close_conn_menu_popover(void)
Definition pages.c:1695
connect_list_left_button
static gboolean connect_list_left_button(GtkGestureClick *gesture, int n_press, double x, double y, gpointer data)
Definition pages.c:2055
conn_popover
static GtkWidget * conn_popover
Definition pages.c:97
gui_stuff.h
save_dialog_action_fn_t
void(* save_dialog_action_fn_t)(const char *filename)
Definition pages.c:365
save_dialog_files_fn_t
struct fileinfo_list *(* save_dialog_files_fn_t)(void)
Definition pages.c:366
server_list
static struct server_list * server_list
Definition connectdlg.c:61
old_page
static enum client_pages old_page
Definition pages.c:46
chatline.h
connectdlg.h
dialogs.h
graphics.h
gui_main.h
mapview.h
menu.h
optiondlg.h
pages.h
plrdlg.h
repodlgs.h
voteinfo_bar.h
conn_list_dialog_update
void conn_list_dialog_update(void)
Definition update_queue.c:650
name
const char * name
Definition inputfile.c:127
log.h
fc_assert_ret
#define fc_assert_ret(condition)
Definition log.h:191
fc_assert_ret_val
#define fc_assert_ret_val(condition, val)
Definition log.h:194
log_debug
#define log_debug(message,...)
Definition log.h:115
log_error
#define log_error(message,...)
Definition log.h:103
mapimg_error
const char * mapimg_error(void)
Definition mapimg.c:759
mapimg.h
mem.h
fc_strdup
#define fc_strdup(str)
Definition mem.h:43
fc_malloc
#define fc_malloc(sz)
Definition mem.h:34
nation_adjective_for_player
const char * nation_adjective_for_player(const struct player *pplayer)
Definition nation.c:169
can_conn_edit_players_nation
bool can_conn_edit_players_nation(const struct connection *pconn, const struct player *pplayer)
Definition nation.c:1187
NO_NATION_SELECTED
#define NO_NATION_SELECTED
Definition nation.h:30
server_optset
const struct option_set * server_optset
Definition options.c:4281
client_optset
const struct option_set * client_optset
Definition options.c:1315
option_int_get
int option_int_get(const struct option *poption)
Definition options.c:869
optset_option_by_name
struct option * optset_option_by_name(const struct option_set *poptset, const char *name)
Definition options.c:466
option_int_set
bool option_int_set(struct option *poption, int val)
Definition options.c:913
send_packet_authentication_reply
int send_packet_authentication_reply(struct connection *pc, const struct packet_authentication_reply *packet)
Definition packets_gen.c:2355
dsend_packet_save_scenario
int dsend_packet_save_scenario(struct connection *pc, const char *name)
Definition packets_gen.c:79376
dsend_packet_player_ready
int dsend_packet_player_ready(struct connection *pc, int player_no, bool is_ready)
Definition packets_gen.c:2950
packhand.h
is_settable_ai_level
bool is_settable_ai_level(enum ai_level level)
Definition player.c:1923
player_by_number
struct player * player_by_number(const int player_id)
Definition player.c:849
player_slot_count
int player_slot_count(void)
Definition player.c:418
player_number
int player_number(const struct player *pplayer)
Definition player.c:837
player_name
const char * player_name(const struct player *pplayer)
Definition player.c:895
player_has_flag
bool player_has_flag(const struct player *pplayer, enum plr_flag_id flag)
Definition player.c:1994
ai_level_cmd
#define ai_level_cmd(_level_)
Definition player.h:569
players_iterate_end
#define players_iterate_end
Definition player.h:539
players_iterate
#define players_iterate(_pplayer)
Definition player.h:534
is_ai
#define is_ai(plr)
Definition player.h:232
players_iterate_alive_end
#define players_iterate_alive_end
Definition player.h:549
is_human
#define is_human(plr)
Definition player.h:231
players_iterate_alive
#define players_iterate_alive(_pplayer)
Definition player.h:544
secfile_destroy
void secfile_destroy(struct section_file *secfile)
Definition section_file.c:95
secfile_load_section
struct section_file * secfile_load_section(const char *filename, const char *section, bool allow_duplicates)
Definition registry_ini.c:596
secfile_lookup_bool_default
bool secfile_lookup_bool_default(const struct section_file *secfile, bool def, const char *path,...)
Definition registry_ini.c:1900
secfile_lookup_int_default
int secfile_lookup_int_default(const struct section_file *secfile, int def, const char *path,...)
Definition registry_ini.c:2000
secfile_lookup_str_default
const char * secfile_lookup_str_default(const struct section_file *secfile, const char *def, const char *path,...)
Definition registry_ini.c:2205
server_scan_get_list
struct srv_list * server_scan_get_list(struct server_scan *scan)
Definition servers.c:866
server_scan_finish
void server_scan_finish(struct server_scan *scan)
Definition servers.c:879
server_scan_begin
struct server_scan * server_scan_begin(enum server_scan_type type, ServerScanErrorFunc error_func)
Definition servers.c:755
server_scan_get_type
enum server_scan_type server_scan_get_type(const struct server_scan *scan)
Definition servers.c:809
server_scan_poll
enum server_scan_status server_scan_poll(struct server_scan *scan)
Definition servers.c:832
servers.h
server_list_iterate_end
#define server_list_iterate_end
Definition servers.h:57
server_scan_status
server_scan_status
Definition servers.h:79
SCAN_STATUS_PARTIAL
@ SCAN_STATUS_PARTIAL
Definition servers.h:82
SCAN_STATUS_ERROR
@ SCAN_STATUS_ERROR
Definition servers.h:80
SCAN_STATUS_DONE
@ SCAN_STATUS_DONE
Definition servers.h:83
server_list_iterate
#define server_list_iterate(serverlist, pserver)
Definition servers.h:55
server_scan_type
server_scan_type
Definition servers.h:67
SERVER_SCAN_LOCAL
@ SERVER_SCAN_LOCAL
Definition servers.h:68
SERVER_SCAN_GLOBAL
@ SERVER_SCAN_GLOBAL
Definition servers.h:69
level
struct setting_list * level[OLEVELS_NUM]
Definition settings.c:190
get_scenario_dirs
const struct strvec * get_scenario_dirs(void)
Definition shared.c:978
get_save_dirs
const struct strvec * get_save_dirs(void)
Definition shared.c:941
skip_to_basename
char * skip_to_basename(char *filepath)
Definition shared.c:1757
fileinfolist_infix
struct fileinfo_list * fileinfolist_infix(const struct strvec *dirs, const char *infix, bool nodups)
Definition shared.c:1211
shared.h
fileinfo_list_iterate
#define fileinfo_list_iterate(list, pnode)
Definition shared.h:176
FC_PTR_TO_INT
#define FC_PTR_TO_INT(p)
Definition shared.h:95
fileinfo_list_iterate_end
#define fileinfo_list_iterate_end
Definition shared.h:178
FC_INT_TO_PTR
#define FC_INT_TO_PTR(i)
Definition shared.h:94
size
size_t size
Definition specvec.h:72
y
struct sprite int int y
Definition sprite_g.h:31
scale
struct sprite int int int int struct sprite int int float scale
Definition sprite_g.h:33
x
struct sprite int x
Definition sprite_g.h:31
get_sprite_dimensions
struct sprite int int int int struct sprite int int float bool smooth get_sprite_dimensions
Definition sprite_g.h:36
aifill
const char * aifill(int amount)
Definition srv_main.c:2503
action
Definition actions.h:106
civ_game::est_connections
struct conn_list * est_connections
Definition game.h:97
civ_game::info
struct packet_game_info info
Definition game.h:89
civclient::conn
struct connection conn
Definition client_main.h:96
color
Definition colors.h:21
connection
Definition connection.h:136
connection::playing
struct player * playing
Definition connection.h:151
connection::access_level
enum cmdlevel access_level
Definition connection.h:177
connection::id
int id
Definition connection.h:137
connection::used
bool used
Definition connection.h:139
entry
Definition registry_ini.c:193
message
Definition messagewin_common.h:29
option
Definition options.c:514
packet_authentication_reply
Definition packets_gen.h:68
packet_game_info::is_new_game
bool is_new_game
Definition packets_gen.h:192
player
Definition player.h:249
player::team
struct team * team
Definition player.h:261
player::is_ready
bool is_ready
Definition player.h:262
save_dialog
Definition pages.c:359
save_dialog::action
save_dialog_action_fn_t action
Definition pages.c:363
save_dialog::entry
GtkEntry * entry
Definition pages.c:362
save_dialog::tree_view
GtkTreeView * tree_view
Definition pages.c:361
save_dialog::shell
GtkDialog * shell
Definition pages.c:360
save_dialog::files
save_dialog_files_fn_t files
Definition pages.c:364
section_file
Definition section_file.h:36
server_scan_timer_data
Definition pages.c:81
server_scan_timer_data::scan
struct server_scan * scan
Definition pages.c:82
server_scan_timer_data::timer
guint timer
Definition pages.c:83
server_scan
Definition servers.c:84
server
Definition servers.h:29
sprite
Definition sprite.h:22
srv_list
Definition servers.h:62
srv_list::mutex
fc_mutex mutex
Definition servers.h:64
srv_list::servers
struct server_list * servers
Definition servers.h:63
team_slot
Definition team.c:31
team
Definition team.c:40
tileset
Definition tilespec.c:481
video_mode
Definition options.h:46
view
Definition mapview_common.h:36
widget
Definition widget.h:112
fc_snprintf
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:960
cat_snprintf
int cat_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:986
fc_remove
int fc_remove(const char *filename)
Definition support.c:555
support.h
sz_strlcpy
#define sz_strlcpy(dest, src)
Definition support.h:189
TRUE
#define TRUE
Definition support.h:46
FALSE
#define FALSE
Definition support.h:47
sz_strlcat
#define sz_strlcat(dest, src)
Definition support.h:190
fc_strncmp
#define fc_strncmp(_s1_, _s2_, _len_)
Definition support.h:154
team_name_translation
const char * team_name_translation(const struct team *pteam)
Definition team.c:420
team_slot_get_team
struct team * team_slot_get_team(const struct team_slot *tslot)
Definition team.c:150
team_slot_name_translation
const char * team_slot_name_translation(const struct team_slot *tslot)
Definition team.c:253
team_number
int team_number(const struct team *pteam)
Definition team.c:391
team_slot_index
int team_slot_index(const struct team_slot *tslot)
Definition team.c:138
team_members
const struct player_list * team_members(const struct team *pteam)
Definition team.c:456
team_slot_is_used
bool team_slot_is_used(const struct team_slot *tslot)
Definition team.c:162
team_slot_rule_name
const char * team_slot_rule_name(const struct team_slot *tslot)
Definition team.c:233
team_slots_iterate_end
#define team_slots_iterate_end
Definition team.h:77
team_slots_iterate
#define team_slots_iterate(_tslot)
Definition team.h:72
tileset_main_intro_filename
const char * tileset_main_intro_filename(const struct tileset *t)
Definition tilespec.c:947
client_start_server_and_set_page
void client_start_server_and_set_page(enum client_pages page)
Definition update_queue.c:506
set_client_page
void set_client_page(enum client_pages page)
Definition update_queue.c:496
update_queue_connect_processing_finished
void update_queue_connect_processing_finished(int request_id, uq_callback_t callback, void *data)
Definition update_queue.c:450
get_client_page
enum client_pages get_client_page(void)
Definition update_queue.c:520
update_queue.h
fc_git_revision
const char * fc_git_revision(void)
Definition version.c:75
unstable_message
const char * unstable_message(void)
Definition version.c:160
word_version
const char * word_version(void)
Definition version.c:62
version.h