Freeciv-3.2: /fast/freeciv/nightly/S3_2/client/gui-gtk-3.22/pages.c Source File

Freeciv-3.2

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