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