Freeciv-3.1: /fast/freeciv/nightly/S3_1/client/gui-gtk-3.0/pages.c Source File

Freeciv-3.1

Loading...
Searching...
No Matches
pages.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12***********************************************************************/
13
14#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18#include <stdio.h>
19#include <time.h>
20
21#include <sys/stat.h>
22
23#include <gtk/gtk.h>
24
25/* utility */
26#include "fcintl.h"
27#include "log.h"
28#include "mem.h"
29#include "shared.h"
30#include "support.h"
31
32/* common */
33#include "dataio.h"
34#include "game.h"
35#include "mapimg.h"
36#include "version.h"
37
38/* client */
39#include "client_main.h"
40#include "climisc.h"
41#include "clinet.h"
42#include "connectdlg_common.h"
43#include "packhand.h"
44#include "servers.h"
45#include "update_queue.h"
46
47/* client/gui-gtk-3.0 */
48#include "chatline.h"
49#include "connectdlg.h"
50#include "dialogs.h"
51#include "graphics.h"
52#include "gui_main.h"
53#include "gui_stuff.h"
54#include "mapview.h"
55#include "optiondlg.h"
56#include "plrdlg.h" /* get_flag() */
57#include "repodlgs.h"
58#include "voteinfo_bar.h"
59
60#include "pages.h"
61
62
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();
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.0 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.0 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/**********************************************************************/
229GtkWidget *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));
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 = gtk_button_new_from_stock(GTK_STOCK_QUIT);
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 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
457 action == GTK_FILE_CHOOSER_ACTION_SAVE ? GTK_STOCK_SAVE : GTK_STOCK_OPEN,
458 GTK_RESPONSE_OK, NULL);
459 setup_dialog(filechoose, toplevel);
460 gtk_window_set_position(GTK_WINDOW(filechoose), GTK_WIN_POS_MOUSE);
461
462 g_signal_connect(filechoose, "response",
463 G_CALLBACK(save_dialog_file_chooser_callback), cb);
464
465 /* Display that dialog */
466 gtk_window_present(GTK_WINDOW(filechoose));
467}
468
469/**********************************************************************/
472 static void save_dialog_response_callback(GtkWidget *w, gint response,
473 gpointer data)
474{
475 struct save_dialog *pdialog = data;
476
477 switch (response) {
478 case SD_RES_BROWSE:
479 save_dialog_file_chooser_popup(_("Select Location to Save"),
480 GTK_FILE_CHOOSER_ACTION_SAVE,
481 pdialog->action);
482 break;
483 case SD_RES_DELETE:
484 {
485 GtkTreeSelection *selection;
486 GtkTreeModel *model;
487 GtkTreeIter iter;
488 const gchar *full_path;
489
490 selection = gtk_tree_view_get_selection(pdialog->tree_view);
491 if (!gtk_tree_selection_get_selected(selection, &model, &iter)) {
492 return;
493 }
494
495 gtk_tree_model_get(model, &iter, SD_COL_FULL_PATH, &full_path, -1);
496 fc_remove(full_path);
497 save_dialog_update(pdialog);
498 }
499 return;
500 case SD_RES_SAVE:
501 {
502 const char *text = gtk_entry_get_text(pdialog->entry);
503 gchar *filename = g_filename_from_utf8(text, -1, NULL, NULL, NULL);
504
505 if (NULL == filename) {
506 return;
507 }
508 pdialog->action(filename);
509 g_free(filename);
510 }
511 break;
512 default:
513 break;
514 }
515 gtk_widget_destroy(GTK_WIDGET(pdialog->shell));
516}
517
518/**********************************************************************/
521 static void save_dialog_row_callback(GtkTreeView *tree_view,
522 GtkTreePath *path,
523 GtkTreeViewColumn *column,
524 gpointer data)
525{
526 save_dialog_response_callback(NULL, SD_RES_SAVE, data);
527}
528
529/**********************************************************************/
532 static void save_dialog_entry_callback(GtkEntry *entry, gpointer data)
533{
534 save_dialog_response_callback(NULL, SD_RES_SAVE, data);
535}
536
537/**********************************************************************/
540 static void save_dialog_list_callback(GtkTreeSelection *selection,
541 gpointer data)
542{
543 struct save_dialog *pdialog = data;
544 GtkTreeModel *model;
545 GtkTreeIter iter;
546 const gchar *filename;
547
548 if (!gtk_tree_selection_get_selected(selection, &model, &iter)) {
549 gtk_dialog_set_response_sensitive(pdialog->shell, SD_RES_DELETE, FALSE);
550 return;
551 }
552
553 gtk_dialog_set_response_sensitive(pdialog->shell, SD_RES_DELETE, TRUE);
554 gtk_tree_model_get(model, &iter, SD_COL_PRETTY_NAME, &filename, -1);
555 gtk_entry_set_text(pdialog->entry, filename);
556}
557
558/**********************************************************************/
561 static GtkWidget *save_dialog_new(const char *title, const char *savelabel,
562 const char *savefilelabel,
563 save_dialog_action_fn_t action,
564 save_dialog_files_fn_t files)
565{
566 GtkWidget *shell, *sbox, *sw, *label, *view, *entry;
567 GtkContainer *vbox;
568 GtkListStore *store;
569 GtkCellRenderer *rend;
570 GtkTreeSelection *selection;
571 struct save_dialog *pdialog;
572
573 fc_assert_ret_val(NULL != action, NULL);
574 fc_assert_ret_val(NULL != files, NULL);
575
576 /* Save dialog structure. */
577 pdialog = fc_malloc(sizeof(*pdialog));
578 pdialog->action = action;
579 pdialog->files = files;
580
581 /* Shell. */
582 shell = gtk_dialog_new_with_buttons(title, NULL, 0,
583 _("_Browse..."), SD_RES_BROWSE,
584 GTK_STOCK_DELETE, SD_RES_DELETE,
585 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
586 GTK_STOCK_SAVE, SD_RES_SAVE,
587 NULL);
588 g_object_set_data_full(G_OBJECT(shell), "save_dialog", pdialog,
589 (GDestroyNotify) free);
590 gtk_dialog_set_default_response(GTK_DIALOG(shell), GTK_RESPONSE_CANCEL);
591 gtk_dialog_set_response_sensitive(GTK_DIALOG(shell), SD_RES_DELETE, FALSE);
592 setup_dialog(shell, toplevel);
593 g_signal_connect(shell, "response",
594 G_CALLBACK(save_dialog_response_callback), pdialog);
595 pdialog->shell = GTK_DIALOG(shell);
596 vbox = GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(shell)));
597
598 /* Tree view. */
599 store = save_dialog_store_new();
600 view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
601 gtk_widget_set_hexpand(view, TRUE);
602 gtk_widget_set_vexpand(view, TRUE);
603 g_object_unref(store);
604 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view), FALSE);
605 g_signal_connect(view, "row-activated",
606 G_CALLBACK(save_dialog_row_callback), pdialog);
607 pdialog->tree_view = GTK_TREE_VIEW(view);
608
609 sbox = gtk_grid_new();
610 gtk_orientable_set_orientation(GTK_ORIENTABLE(sbox),
611 GTK_ORIENTATION_VERTICAL);
612 gtk_grid_set_row_spacing(GTK_GRID(sbox), 2);
613 gtk_container_add(vbox, sbox);
614
615 label = g_object_new(GTK_TYPE_LABEL,
616 "use-underline", TRUE,
617 "mnemonic-widget", view,
618 "label", savelabel,
619 "xalign", 0.0,
620 "yalign", 0.5,
621 NULL);
622 gtk_container_add(GTK_CONTAINER(sbox), label);
623
624 sw = gtk_scrolled_window_new(NULL, NULL);
625 gtk_scrolled_window_set_min_content_width(GTK_SCROLLED_WINDOW(sw), 300);
626 gtk_scrolled_window_set_min_content_height(GTK_SCROLLED_WINDOW(sw), 300);
627 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw),
628 GTK_SHADOW_ETCHED_IN);
629 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
630 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
631 gtk_container_add(GTK_CONTAINER(sw), view);
632 gtk_container_add(GTK_CONTAINER(sbox), sw);
633
634 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
635 gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE);
636 g_signal_connect(selection, "changed",
637 G_CALLBACK(save_dialog_list_callback), pdialog);
638
639 rend = gtk_cell_renderer_text_new();
640 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
641 -1, NULL, rend, "text",
642 SD_COL_PRETTY_NAME, NULL);
643
644 /* Entry. */
645 entry = gtk_entry_new();
646 gtk_widget_set_hexpand(entry, TRUE);
647 g_signal_connect(entry, "activate",
648 G_CALLBACK(save_dialog_entry_callback), pdialog);
649 pdialog->entry = GTK_ENTRY(entry);
650
651 sbox = gtk_grid_new();
652 g_object_set(sbox, "margin", 12, NULL);
653 gtk_orientable_set_orientation(GTK_ORIENTABLE(sbox),
654 GTK_ORIENTATION_VERTICAL);
655 gtk_grid_set_row_spacing(GTK_GRID(sbox), 2);
656
657 label = g_object_new(GTK_TYPE_LABEL,
658 "use-underline", TRUE,
659 "mnemonic-widget", entry,
660 "label", savefilelabel,
661 "xalign", 0.0,
662 "yalign", 0.5,
663 NULL);
664 gtk_container_add(GTK_CONTAINER(sbox), label);
665
666 gtk_container_add(GTK_CONTAINER(sbox), entry);
667 gtk_container_add(vbox, sbox);
668
669 save_dialog_update(pdialog);
670 gtk_window_set_focus(GTK_WINDOW(shell), entry);
671 gtk_widget_show_all(GTK_WIDGET(vbox));
672 return shell;
673}
674
675/****************************************************************************
676 NETWORK PAGE
677****************************************************************************/
678 static GtkWidget *network_login_label, *network_login;
679 static GtkWidget *network_host_label, *network_host;
680 static GtkWidget *network_port_label, *network_port;
681 static GtkWidget *network_password_label, *network_password;
682 static GtkWidget *network_confirm_password_label, *network_confirm_password;
683
684/**********************************************************************/
687 static void update_server_list(enum server_scan_type sstype,
688 const struct server_list *list)
689{
690 GtkTreeSelection *sel = NULL;
691 GtkTreeView *view;
692 GtkTreeIter it;
693 GtkListStore *store;
694 const gchar *host, *portstr;
695 int port;
696
697 switch (sstype) {
698 case SERVER_SCAN_LOCAL:
699 sel = lan_selection;
700 break;
701 case SERVER_SCAN_GLOBAL:
702 sel = meta_selection;
703 break;
704 default:
705 break;
706 }
707
708 if (!sel) {
709 return;
710 }
711
712 view = gtk_tree_selection_get_tree_view(sel);
713 store = GTK_LIST_STORE(gtk_tree_view_get_model(view));
714 gtk_list_store_clear(store);
715
716 if (!list) {
717 return;
718 }
719
720 host = gtk_entry_get_text(GTK_ENTRY(network_host));
721 portstr = gtk_entry_get_text(GTK_ENTRY(network_port));
722 port = atoi(portstr);
723
724 server_list_iterate(list, pserver) {
725 char buf[35];
726
727 if (pserver->humans >= 0) {
728 fc_snprintf(buf, sizeof(buf), "%d", pserver->humans);
729 } else {
730 sz_strlcpy(buf, _("Unknown"));
731 }
732 gtk_list_store_append(store, &it);
733 gtk_list_store_set(store, &it,
734 0, pserver->host,
735 1, pserver->port,
736 2, pserver->version,
737 3, _(pserver->state),
738 4, pserver->nplayers,
739 5, buf,
740 6, pserver->message,
741 -1);
742 if (strcmp(host, pserver->host) == 0 && port == pserver->port) {
743 gtk_tree_selection_select_iter(sel, &it);
744 }
745 } server_list_iterate_end;
746}
747
748/**********************************************************************/
751 void destroy_server_scans(void)
752{
753 if (meta_scan.scan) {
754 server_scan_finish(meta_scan.scan);
755 meta_scan.scan = NULL;
756 }
757 if (meta_scan.timer != 0) {
758 g_source_remove(meta_scan.timer);
759 meta_scan.timer = 0;
760 }
761 if (lan_scan.scan) {
762 server_scan_finish(lan_scan.scan);
763 lan_scan.scan = NULL;
764 }
765 if (lan_scan.timer != 0) {
766 g_source_remove(lan_scan.timer);
767 lan_scan.timer = 0;
768 }
769}
770
771/**********************************************************************/
774 static gboolean check_server_scan(gpointer data)
775{
776 struct server_scan_timer_data *scan_data = data;
777 struct server_scan *scan = scan_data->scan;
778 enum server_scan_status stat;
779
780 if (!scan) {
781 return FALSE;
782 }
783
784 stat = server_scan_poll(scan);
785 if (stat >= SCAN_STATUS_PARTIAL) {
786 enum server_scan_type type;
787 struct srv_list *srvrs;
788
789 type = server_scan_get_type(scan);
790 srvrs = server_scan_get_list(scan);
791 fc_allocate_mutex(&srvrs->mutex);
792 holding_srv_list_mutex = TRUE;
793 update_server_list(type, srvrs->servers);
794 holding_srv_list_mutex = FALSE;
795 fc_release_mutex(&srvrs->mutex);
796 }
797
798 if (stat == SCAN_STATUS_ERROR || stat == SCAN_STATUS_DONE) {
799 scan_data->timer = 0;
800 return FALSE;
801 }
802 return TRUE;
803}
804
805/**********************************************************************/
808 static void server_scan_error(struct server_scan *scan,
809 const char *message)
810{
811 output_window_append(ftc_client, message);
812 log_error("%s", message);
813
814 /* Main thread will finalize the scan later (or even concurrently) -
815 * do not do anything here to cause double free or raze condition. */
816}
817
818/**********************************************************************/
821 static void update_network_lists(void)
822{
823 destroy_server_scans();
824
825 meta_scan.scan = server_scan_begin(SERVER_SCAN_GLOBAL, server_scan_error);
826 meta_scan.timer = g_timeout_add(200, check_server_scan, &meta_scan);
827
828 lan_scan.scan = server_scan_begin(SERVER_SCAN_LOCAL, server_scan_error);
829 lan_scan.timer = g_timeout_add(500, check_server_scan, &lan_scan);
830}
831
832/**************************************************************************
833 Network connection state defines.
834**************************************************************************/
835 enum connection_state {
836 LOGIN_TYPE,
837 NEW_PASSWORD_TYPE,
838 ENTER_PASSWORD_TYPE,
839 WAITING_TYPE
840};
841
842 static enum connection_state connection_status;
843
844/**********************************************************************/
847 static gboolean update_network_statusbar(gpointer data)
848{
849 if (!g_queue_is_empty(statusbar_queue)) {
850 char *txt;
851
852 txt = g_queue_pop_head(statusbar_queue);
853 gtk_label_set_text(GTK_LABEL(statusbar), txt);
854 free(txt);
855 }
856
857 return TRUE;
858}
859
860/**********************************************************************/
863 static void clear_network_statusbar(void)
864{
865 while (!g_queue_is_empty(statusbar_queue)) {
866 char *txt;
867
868 txt = g_queue_pop_head(statusbar_queue);
869 free(txt);
870 }
871 gtk_label_set_text(GTK_LABEL(statusbar), "");
872}
873
874/**********************************************************************/
877 void append_network_statusbar(const char *text, bool force)
878{
879 if (gtk_widget_get_visible(statusbar_frame)) {
880 if (force) {
881 clear_network_statusbar();
882 gtk_label_set_text(GTK_LABEL(statusbar), text);
883 } else {
884 g_queue_push_tail(statusbar_queue, fc_strdup(text));
885 }
886 }
887}
888
889/**********************************************************************/
892GtkWidget *create_statusbar(void)
893{
894 statusbar_frame = gtk_frame_new(NULL);
895 gtk_frame_set_shadow_type(GTK_FRAME(statusbar_frame), GTK_SHADOW_IN);
896
897 statusbar = gtk_label_new("");
898 gtk_widget_set_margin_left(statusbar, 2);
899 gtk_widget_set_margin_right(statusbar, 2);
900 gtk_widget_set_margin_top(statusbar, 2);
901 gtk_widget_set_margin_bottom(statusbar, 2);
902 gtk_container_add(GTK_CONTAINER(statusbar_frame), statusbar);
903
904 statusbar_queue = g_queue_new();
905 statusbar_timer = g_timeout_add(2000, update_network_statusbar, NULL);
906
907 return statusbar_frame;
908}
909
910/**********************************************************************/
913 static void set_connection_state(enum connection_state state)
914{
915 switch (state) {
916 case LOGIN_TYPE:
917 append_network_statusbar("", FALSE);
918
919 gtk_entry_set_text(GTK_ENTRY(network_password), "");
920 gtk_entry_set_text(GTK_ENTRY(network_confirm_password), "");
921
922 gtk_widget_set_sensitive(network_host, TRUE);
923 gtk_widget_set_sensitive(network_port, TRUE);
924 gtk_widget_set_sensitive(network_login, TRUE);
925 gtk_widget_set_sensitive(network_password_label, FALSE);
926 gtk_label_set_markup_with_mnemonic(GTK_LABEL(network_password_label), _("Pass_word:"));
927 gtk_widget_set_sensitive(network_password, FALSE);
928 gtk_widget_set_sensitive(network_confirm_password_label, FALSE);
929 gtk_widget_set_sensitive(network_confirm_password, FALSE);
930 break;
931 case NEW_PASSWORD_TYPE:
932 set_client_page(PAGE_NETWORK);
933 gtk_entry_set_text(GTK_ENTRY(network_password), "");
934 gtk_entry_set_text(GTK_ENTRY(network_confirm_password), "");
935
936 gtk_widget_set_sensitive(network_host, FALSE);
937 gtk_widget_set_sensitive(network_port, FALSE);
938 gtk_widget_set_sensitive(network_login, FALSE);
939 gtk_widget_set_sensitive(network_password_label, TRUE);
940 gtk_label_set_markup_with_mnemonic(GTK_LABEL(network_password_label), _("New Pass_word:"));
941 gtk_widget_set_sensitive(network_password, TRUE);
942 gtk_widget_set_sensitive(network_confirm_password_label, TRUE);
943 gtk_widget_set_sensitive(network_confirm_password, TRUE);
944
945 gtk_widget_grab_focus(network_password);
946 break;
947 case ENTER_PASSWORD_TYPE:
948 set_client_page(PAGE_NETWORK);
949 gtk_entry_set_text(GTK_ENTRY(network_password), "");
950 gtk_entry_set_text(GTK_ENTRY(network_confirm_password), "");
951
952 gtk_widget_set_sensitive(network_host, FALSE);
953 gtk_widget_set_sensitive(network_port, FALSE);
954 gtk_widget_set_sensitive(network_login, FALSE);
955 gtk_widget_set_sensitive(network_password_label, TRUE);
956 gtk_label_set_markup_with_mnemonic(GTK_LABEL(network_password_label), _("Pass_word:"));
957 gtk_widget_set_sensitive(network_password, TRUE);
958 gtk_widget_set_sensitive(network_confirm_password_label, FALSE);
959 gtk_widget_set_sensitive(network_confirm_password, FALSE);
960
961 gtk_widget_grab_focus(network_password);
962 break;
963 case WAITING_TYPE:
964 append_network_statusbar("", TRUE);
965
966 gtk_widget_set_sensitive(network_login, FALSE);
967 gtk_widget_set_sensitive(network_password_label, FALSE);
968 gtk_label_set_markup_with_mnemonic(GTK_LABEL(network_password_label), _("Pass_word:"));
969 gtk_widget_set_sensitive(network_password, FALSE);
970 gtk_widget_set_sensitive(network_confirm_password_label, FALSE);
971 gtk_widget_set_sensitive(network_confirm_password, FALSE);
972 break;
973 }
974
975 connection_status = state;
976}
977
978/**********************************************************************/
981 static void connection_state_reset(void)
982{
983 set_connection_state(LOGIN_TYPE);
984}
985
986/**********************************************************************/
990 void handle_authentication_req(enum authentication_type type,
991 const char *message)
992{
993 append_network_statusbar(message, TRUE);
994
995 switch (type) {
996 case AUTH_NEWUSER_FIRST:
997 case AUTH_NEWUSER_RETRY:
998 set_connection_state(NEW_PASSWORD_TYPE);
999 return;
1000 case AUTH_LOGIN_FIRST:
1001 /* if we magically have a password already present in 'fc_password'
1002 * then, use that and skip the password entry dialog */
1003 if (fc_password[0] != '\0') {
1004 struct packet_authentication_reply reply;
1005
1006 sz_strlcpy(reply.password, fc_password);
1007 send_packet_authentication_reply(&client.conn, &reply);
1008 return;
1009 } else {
1010 set_connection_state(ENTER_PASSWORD_TYPE);
1011 }
1012 return;
1013 case AUTH_LOGIN_RETRY:
1014 set_connection_state(ENTER_PASSWORD_TYPE);
1015 return;
1016 }
1017
1018 log_error("Unsupported authentication type %d: %s.", type, message);
1019}
1020
1021/**********************************************************************/
1026 static void connect_callback(GtkWidget *w, gpointer data)
1027{
1028 char errbuf [512];
1029 struct packet_authentication_reply reply;
1030
1031 switch (connection_status) {
1032 case LOGIN_TYPE:
1033 sz_strlcpy(user_name, gtk_entry_get_text(GTK_ENTRY(network_login)));
1034 sz_strlcpy(server_host, gtk_entry_get_text(GTK_ENTRY(network_host)));
1035 server_port = atoi(gtk_entry_get_text(GTK_ENTRY(network_port)));
1036
1037 if (connect_to_server(user_name, server_host, server_port,
1038 errbuf, sizeof(errbuf)) != -1) {
1039 } else {
1040 append_network_statusbar(errbuf, TRUE);
1041
1042 output_window_append(ftc_client, errbuf);
1043 }
1044 return;
1045 case NEW_PASSWORD_TYPE:
1046 if (w != network_password) {
1047 sz_strlcpy(fc_password,
1048 gtk_entry_get_text(GTK_ENTRY(network_password)));
1049 sz_strlcpy(reply.password,
1050 gtk_entry_get_text(GTK_ENTRY(network_confirm_password)));
1051 if (strncmp(reply.password, fc_password, MAX_LEN_NAME) == 0) {
1052 fc_password[0] = '\0';
1053 send_packet_authentication_reply(&client.conn, &reply);
1054
1055 set_connection_state(WAITING_TYPE);
1056 } else {
1057 append_network_statusbar(_("Passwords don't match, enter password."),
1058 TRUE);
1059
1060 set_connection_state(NEW_PASSWORD_TYPE);
1061 }
1062 }
1063 return;
1064 case ENTER_PASSWORD_TYPE:
1065 sz_strlcpy(reply.password,
1066 gtk_entry_get_text(GTK_ENTRY(network_password)));
1067 send_packet_authentication_reply(&client.conn, &reply);
1068
1069 set_connection_state(WAITING_TYPE);
1070 return;
1071 case WAITING_TYPE:
1072 return;
1073 }
1074
1075 log_error("Unsupported connection status: %d", connection_status);
1076}
1077
1078/**********************************************************************/
1081 static void network_activate_callback(GtkTreeView *view,
1082 GtkTreePath *arg1,
1083 GtkTreeViewColumn *arg2,
1084 gpointer data)
1085{
1086 connect_callback(NULL, data);
1087}
1088
1089/**********************************************************************/
1093 static void update_server_playerlist(const struct server *pserver)
1094{
1095 GtkListStore *store;
1096 GtkTreeIter iter;
1097 int n, i;
1098
1099 store = server_playerlist_store;
1100 fc_assert_ret(store != NULL);
1101
1102 gtk_list_store_clear(store);
1103 if (!pserver || !pserver->players) {
1104 return;
1105 }
1106
1107 n = pserver->nplayers;
1108 for (i = 0; i < n; i++) {
1109 gtk_list_store_append(store, &iter);
1110 gtk_list_store_set(store, &iter,
1111 0, pserver->players[i].name,
1112 1, pserver->players[i].type,
1113 2, pserver->players[i].host,
1114 3, pserver->players[i].nation,
1115 -1);
1116 }
1117}
1118
1119/**********************************************************************/
1122 static void network_list_callback(GtkTreeSelection *select, gpointer data)
1123{
1124 GtkTreeModel *model;
1125 GtkTreeIter it;
1126 const char *host;
1127 int port;
1128 char portstr[32];
1129 const struct server *pserver = NULL;
1130
1131 if (!gtk_tree_selection_get_selected(select, &model, &it)) {
1132 return;
1133 }
1134
1135 if (select == meta_selection) {
1136 GtkTreePath *path;
1137 struct srv_list *srvrs;
1138
1139 srvrs = server_scan_get_list(meta_scan.scan);
1140 path = gtk_tree_model_get_path(model, &it);
1141 if (!holding_srv_list_mutex) {
1142 /* We are not yet inside mutex protected block */
1143 fc_allocate_mutex(&srvrs->mutex);
1144 }
1145 if (srvrs->servers && path) {
1146 gint pos = gtk_tree_path_get_indices(path)[0];
1147 pserver = server_list_get(srvrs->servers, pos);
1148 }
1149 if (!holding_srv_list_mutex) {
1150 /* We are not yet inside mutex protected block */
1151 fc_release_mutex(&srvrs->mutex);
1152 }
1153 gtk_tree_path_free(path);
1154 }
1155 update_server_playerlist(pserver);
1156
1157 gtk_tree_model_get(model, &it, 0, &host, 1, &port, -1);
1158
1159 gtk_entry_set_text(GTK_ENTRY(network_host), host);
1160 fc_snprintf(portstr, sizeof(portstr), "%d", port);
1161 gtk_entry_set_text(GTK_ENTRY(network_port), portstr);
1162}
1163
1164/**********************************************************************/
1167 static void update_network_page(void)
1168{
1169 char buf[256];
1170
1171 gtk_tree_selection_unselect_all(lan_selection);
1172 gtk_tree_selection_unselect_all(meta_selection);
1173
1174 gtk_entry_set_text(GTK_ENTRY(network_login), user_name);
1175 gtk_entry_set_text(GTK_ENTRY(network_host), server_host);
1176 fc_snprintf(buf, sizeof(buf), "%d", server_port);
1177 gtk_entry_set_text(GTK_ENTRY(network_port), buf);
1178}
1179
1180/**********************************************************************/
1183GtkWidget *create_network_page(void)
1184{
1185 GtkWidget *box, *sbox, *bbox, *hbox, *notebook;
1186 GtkWidget *button, *label, *view, *sw, *table;
1187 GtkTreeSelection *selection;
1188 GtkListStore *store;
1189
1190 box = gtk_grid_new();
1191 gtk_orientable_set_orientation(GTK_ORIENTABLE(box),
1192 GTK_ORIENTATION_VERTICAL);
1193 gtk_container_set_border_width(GTK_CONTAINER(box), 4);
1194
1195 notebook = gtk_notebook_new();
1196 gtk_container_add(GTK_CONTAINER(box), notebook);
1197
1198 /* LAN pane. */
1199 lan_store = gtk_list_store_new(7, G_TYPE_STRING, /* host */
1200 G_TYPE_INT, /* port */
1201 G_TYPE_STRING, /* version */
1202 G_TYPE_STRING, /* state */
1203 G_TYPE_INT, /* nplayers */
1204 G_TYPE_STRING, /* humans */
1205 G_TYPE_STRING); /* message */
1206
1207 view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(lan_store));
1208 gtk_widget_set_hexpand(view, TRUE);
1209 gtk_widget_set_vexpand(view, TRUE);
1210 g_object_unref(lan_store);
1211 gtk_tree_view_columns_autosize(GTK_TREE_VIEW(view));
1212
1213 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
1214 lan_selection = selection;
1215 gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE);
1216 g_signal_connect(view, "focus",
1217 G_CALLBACK(gtk_true), NULL);
1218 g_signal_connect(view, "row-activated",
1219 G_CALLBACK(network_activate_callback), NULL);
1220 g_signal_connect(selection, "changed",
1221 G_CALLBACK(network_list_callback), NULL);
1222
1223 add_treeview_column(view, _("Server Name"), G_TYPE_STRING, 0);
1224 add_treeview_column(view, _("Port"), G_TYPE_INT, 1);
1225 add_treeview_column(view, _("Version"), G_TYPE_STRING, 2);
1226 add_treeview_column(view, _("Status"), G_TYPE_STRING, 3);
1227 add_treeview_column(view, Q_("?count:Players"), G_TYPE_INT, 4);
1228 add_treeview_column(view, _("Humans"), G_TYPE_STRING, 5);
1229 add_treeview_column(view, _("Comment"), G_TYPE_STRING, 6);
1230
1231 label = gtk_label_new_with_mnemonic(_("Local _Area Network"));
1232
1233 sw = gtk_scrolled_window_new(NULL, NULL);
1234 gtk_container_set_border_width(GTK_CONTAINER(sw), 4);
1235 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw),
1236 GTK_SHADOW_ETCHED_IN);
1237 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
1238 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1239 gtk_container_add(GTK_CONTAINER(sw), view);
1240 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), sw, label);
1241
1242
1243 /* Metaserver pane. */
1244 meta_store = gtk_list_store_new(7, G_TYPE_STRING, /* host */
1245 G_TYPE_INT, /* port */
1246 G_TYPE_STRING, /* version */
1247 G_TYPE_STRING, /* state */
1248 G_TYPE_INT, /* nplayers */
1249 G_TYPE_STRING, /* humans */
1250 G_TYPE_STRING); /* message */
1251
1252 view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(meta_store));
1253 gtk_widget_set_hexpand(view, TRUE);
1254 gtk_widget_set_vexpand(view, TRUE);
1255 g_object_unref(meta_store);
1256 gtk_tree_view_columns_autosize(GTK_TREE_VIEW(view));
1257
1258 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
1259 meta_selection = selection;
1260 gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE);
1261 g_signal_connect(view, "focus",
1262 G_CALLBACK(gtk_true), NULL);
1263 g_signal_connect(view, "row-activated",
1264 G_CALLBACK(network_activate_callback), NULL);
1265 g_signal_connect(selection, "changed",
1266 G_CALLBACK(network_list_callback), NULL);
1267
1268 add_treeview_column(view, _("Server Name"), G_TYPE_STRING, 0);
1269 add_treeview_column(view, _("Port"), G_TYPE_INT, 1);
1270 add_treeview_column(view, _("Version"), G_TYPE_STRING, 2);
1271 add_treeview_column(view, _("Status"), G_TYPE_STRING, 3);
1272 add_treeview_column(view, Q_("?count:Players"), G_TYPE_INT, 4);
1273 add_treeview_column(view, _("Humans"), G_TYPE_STRING, 5);
1274 add_treeview_column(view, _("Comment"), G_TYPE_STRING, 6);
1275
1276 label = gtk_label_new_with_mnemonic(_("Internet _Metaserver"));
1277
1278 sw = gtk_scrolled_window_new(NULL, NULL);
1279 gtk_container_set_border_width(GTK_CONTAINER(sw), 4);
1280 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw),
1281 GTK_SHADOW_ETCHED_IN);
1282 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
1283 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1284 gtk_container_add(GTK_CONTAINER(sw), view);
1285 if (GUI_GTK_OPTION(metaserver_tab_first)) {
1286 gtk_notebook_prepend_page(GTK_NOTEBOOK(notebook), sw, label);
1287 } else {
1288 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), sw, label);
1289 }
1290
1291 /* Bottom part of the page, outside the inner notebook. */
1292 sbox = gtk_grid_new();
1293 gtk_orientable_set_orientation(GTK_ORIENTABLE(sbox),
1294 GTK_ORIENTATION_VERTICAL);
1295 gtk_container_add(GTK_CONTAINER(box), sbox);
1296
1297 hbox = gtk_grid_new();
1298 gtk_grid_set_column_spacing(GTK_GRID(hbox), 12);
1299 g_object_set(hbox, "margin", 8, NULL);
1300 gtk_container_add(GTK_CONTAINER(sbox), hbox);
1301
1302 table = gtk_grid_new();
1303 gtk_grid_set_row_spacing(GTK_GRID(table), 2);
1304 gtk_grid_set_column_spacing(GTK_GRID(table), 12);
1305 gtk_container_add(GTK_CONTAINER(hbox), table);
1306
1307 network_host = gtk_entry_new();
1308 g_signal_connect(network_host, "activate",
1309 G_CALLBACK(connect_callback), NULL);
1310 gtk_grid_attach(GTK_GRID(table), network_host, 1, 0, 1, 1);
1311
1312 label = g_object_new(GTK_TYPE_LABEL,
1313 "use-underline", TRUE,
1314 "mnemonic-widget", network_host,
1315 "label", _("_Host:"),
1316 "xalign", 0.0,
1317 "yalign", 0.5,
1318 NULL);
1319 network_host_label = label;
1320 gtk_grid_attach(GTK_GRID(table), label, 0, 0, 1, 1);
1321
1322 network_port = gtk_entry_new();
1323 g_signal_connect(network_port, "activate",
1324 G_CALLBACK(connect_callback), NULL);
1325 gtk_grid_attach(GTK_GRID(table), network_port, 1, 1, 1, 1);
1326
1327 label = g_object_new(GTK_TYPE_LABEL,
1328 "use-underline", TRUE,
1329 "mnemonic-widget", network_port,
1330 "label", _("_Port:"),
1331 "xalign", 0.0,
1332 "yalign", 0.5,
1333 NULL);
1334 network_port_label = label;
1335 gtk_grid_attach(GTK_GRID(table), label, 0, 1, 1, 1);
1336
1337 network_login = gtk_entry_new();
1338 gtk_widget_set_margin_top(network_login, 10);
1339 g_signal_connect(network_login, "activate",
1340 G_CALLBACK(connect_callback), NULL);
1341 gtk_grid_attach(GTK_GRID(table), network_login, 1, 3, 1, 1);
1342
1343 label = g_object_new(GTK_TYPE_LABEL,
1344 "use-underline", TRUE,
1345 "mnemonic-widget", network_login,
1346 "label", _("_Login:"),
1347 "xalign", 0.0,
1348 "yalign", 0.5,
1349 NULL);
1350 gtk_widget_set_margin_top(label, 10);
1351 network_login_label = label;
1352 gtk_grid_attach(GTK_GRID(table), label, 0, 3, 1, 1);
1353
1354 network_password = gtk_entry_new();
1355 g_signal_connect(network_password, "activate",
1356 G_CALLBACK(connect_callback), NULL);
1357 gtk_entry_set_visibility(GTK_ENTRY(network_password), FALSE);
1358 gtk_grid_attach(GTK_GRID(table), network_password, 1, 4, 1, 1);
1359
1360 label = g_object_new(GTK_TYPE_LABEL,
1361 "use-underline", TRUE,
1362 "mnemonic-widget", network_password,
1363 "label", _("Pass_word:"),
1364 "xalign", 0.0,
1365 "yalign", 0.5,
1366 NULL);
1367 network_password_label = label;
1368 gtk_grid_attach(GTK_GRID(table), label, 0, 4, 1, 1);
1369
1370 network_confirm_password = gtk_entry_new();
1371 g_signal_connect(network_confirm_password, "activate",
1372 G_CALLBACK(connect_callback), NULL);
1373 gtk_entry_set_visibility(GTK_ENTRY(network_confirm_password), FALSE);
1374 gtk_grid_attach(GTK_GRID(table), network_confirm_password, 1, 5, 1, 1);
1375
1376 label = g_object_new(GTK_TYPE_LABEL,
1377 "use-underline", TRUE,
1378 "mnemonic-widget", network_confirm_password,
1379 "label", _("Conf_irm Password:"),
1380 "xalign", 0.0,
1381 "yalign", 0.5,
1382 NULL);
1383 network_confirm_password_label = label;
1384 gtk_grid_attach(GTK_GRID(table), label, 0, 5, 1, 1);
1385
1386 /* Server player list. */
1387 store = gtk_list_store_new(4, G_TYPE_STRING,
1388 G_TYPE_STRING,
1389 G_TYPE_STRING,
1390 G_TYPE_STRING);
1391 server_playerlist_store = store;
1392
1393 view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
1394 gtk_widget_set_hexpand(view, TRUE);
1395 add_treeview_column(view, _("Name"), G_TYPE_STRING, 0);
1396 add_treeview_column(view, _("Type"), G_TYPE_STRING, 1);
1397 add_treeview_column(view, _("Host"), G_TYPE_STRING, 2);
1398 add_treeview_column(view, _("Nation"), G_TYPE_STRING, 3);
1399 server_playerlist_view = view;
1400
1401 sw = gtk_scrolled_window_new(NULL, NULL);
1402 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw),
1403 GTK_SHADOW_ETCHED_IN);
1404 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
1405 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1406 gtk_container_add(GTK_CONTAINER(sw), view);
1407 gtk_container_add(GTK_CONTAINER(hbox), sw);
1408
1409
1410 bbox = gtk_button_box_new(GTK_ORIENTATION_HORIZONTAL);
1411 g_object_set(bbox, "margin", 2, NULL);
1412 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END);
1413 gtk_box_set_spacing(GTK_BOX(bbox), 12);
1414 gtk_container_add(GTK_CONTAINER(sbox), bbox);
1415
1416 button = gtk_button_new_from_stock(GTK_STOCK_REFRESH);
1417 gtk_container_add(GTK_CONTAINER(bbox), button);
1418 gtk_button_box_set_child_secondary(GTK_BUTTON_BOX(bbox), button, TRUE);
1419 g_signal_connect(button, "clicked",
1420 G_CALLBACK(update_network_lists), NULL);
1421
1422 button = gtk_button_new_from_stock(GTK_STOCK_CANCEL);
1423 gtk_container_add(GTK_CONTAINER(bbox), button);
1424 g_signal_connect(button, "clicked",
1425 G_CALLBACK(main_callback), NULL);
1426
1427 button = gtk_button_new_with_mnemonic(_("C_onnect"));
1428 gtk_container_add(GTK_CONTAINER(bbox), button);
1429 g_signal_connect(button, "clicked",
1430 G_CALLBACK(connect_callback), NULL);
1431
1432 return box;
1433}
1434
1435
1436/****************************************************************************
1437 START PAGE
1438****************************************************************************/
1439GtkWidget *start_message_area;
1440
1441 static GtkWidget *start_options_table;
1442 static GtkWidget *observe_button, *ready_button, *nation_button;
1443 static GtkTreeStore *connection_list_store;
1444 static GtkTreeView *connection_list_view;
1445 static GtkWidget *start_aifill_spin = NULL;
1446 static GtkWidget *ai_lvl_combobox = NULL;
1447
1448
1449/* NB: Must match creation arguments in connection_list_store_new(). */
1450 enum connection_list_columns {
1451 CL_COL_PLAYER_NUMBER = 0,
1452 CL_COL_USER_NAME,
1453 CL_COL_READY_STATE,
1454 CL_COL_PLAYER_NAME,
1455 CL_COL_FLAG,
1456 CL_COL_COLOR,
1457 CL_COL_NATION,
1458 CL_COL_TEAM,
1459 CL_COL_CONN_ID,
1460 CL_COL_STYLE,
1461 CL_COL_WEIGHT,
1462 CL_COL_COLLAPSED,
1463
1464 CL_NUM_COLUMNS
1465};
1466
1467/**********************************************************************/
1470 static inline GtkTreeStore *connection_list_store_new(void)
1471{
1472 return gtk_tree_store_new(CL_NUM_COLUMNS,
1473 G_TYPE_INT, /* CL_COL_PLAYER_NUMBER */
1474 G_TYPE_STRING, /* CL_COL_USER_NAME */
1475 G_TYPE_BOOLEAN, /* CL_COL_READY_STATE */
1476 G_TYPE_STRING, /* CL_COL_PLAYER_NAME */
1477 GDK_TYPE_PIXBUF, /* CL_COL_FLAG */
1478 GDK_TYPE_PIXBUF, /* CL_COL_COLOR */
1479 G_TYPE_STRING, /* CL_COL_NATION */
1480 G_TYPE_STRING, /* CL_COL_TEAM */
1481 G_TYPE_INT, /* CL_COL_CONN_ID */
1482 G_TYPE_INT, /* CL_COL_STYLE */
1483 G_TYPE_INT, /* CL_COL_WEIGHT */
1484 G_TYPE_BOOLEAN); /* CL_COL_COLLAPSED */
1485}
1486
1487/**********************************************************************/
1491 static void client_aitoggle_player(void *data)
1492{
1493 struct player *pplayer = player_by_number(FC_PTR_TO_INT(data));
1494
1495 if (NULL != pplayer
1496 && pplayer == client_player()
1497 && !is_human(pplayer)) {
1498 send_chat("/away");
1499 }
1500}
1501
1502/**********************************************************************/
1505 static void client_take_player(struct player *pplayer)
1506{
1507 int request_id = send_chat_printf("/take \"%s\"", player_name(pplayer));
1508 void *data = FC_INT_TO_PTR(player_number(pplayer));
1509
1510 update_queue_connect_processing_finished(request_id,
1511 client_aitoggle_player, data);
1512}
1513
1514/**********************************************************************/
1517 static void object_put(GObject *object, struct player *pplayer,
1518 struct connection *pconn)
1519{
1520 /* Note that passing -1 to GINT_TO_POINTER() is buggy with some versions
1521 * of gcc. player_slot_count() is not a valid player number. 0 is not
1522 * a valid connection id (see comment in server/sernet.c:
1523 * makeup_connection_name()). */
1524 g_object_set_data(object, "player_id",
1525 GINT_TO_POINTER(NULL != pplayer
1526 ? player_number(pplayer)
1527 : player_slot_count()));
1528 g_object_set_data(object, "connection_id",
1529 GINT_TO_POINTER(NULL != pconn ? pconn->id : 0));
1530}
1531
1532/**********************************************************************/
1536 static bool object_extract(GObject *object, struct player **ppplayer,
1537 struct connection **ppconn)
1538{
1539 bool ret = FALSE;
1540 int id;
1541
1542 if (NULL != ppplayer) {
1543 id = GPOINTER_TO_INT(g_object_get_data(object, "player_id"));
1544 *ppplayer = player_by_number(id);
1545 if (NULL != *ppplayer) {
1546 ret = TRUE;
1547 }
1548 }
1549 if (NULL != ppconn) {
1550 id = GPOINTER_TO_INT(g_object_get_data(object, "connection_id"));
1551 *ppconn = conn_by_number(id);
1552 if (NULL != *ppconn) {
1553 ret = TRUE;
1554 }
1555 }
1556
1557 return ret;
1558}
1559
1560/**********************************************************************/
1563 static void game_options_callback(GtkWidget *w, gpointer data)
1564{
1565 option_dialog_popup(_("Game Settings"), server_optset);
1566}
1567
1568/**********************************************************************/
1571 static void ai_skill_callback(GtkWidget *w, gpointer data)
1572{
1573 enum ai_level *levels = (enum ai_level *)data;
1574 const char *name;
1575 int i;
1576
1577 i = gtk_combo_box_get_active(GTK_COMBO_BOX(w));
1578
1579 if (i != -1) {
1580 enum ai_level level = levels[i];
1581
1582 /* Suppress changes provoked by server rather than local user */
1583 if (server_ai_level() != level) {
1584 name = ai_level_cmd(level);
1585 send_chat_printf("/%s", name);
1586 }
1587 }
1588}
1589
1590/* HACK: sometimes when creating the ruleset combo the value is set without
1591 * the user's control. In this case we don't want to do a /read. */
1592 static bool no_ruleset_callback = FALSE;
1593
1594/**********************************************************************/
1597 static void ruleset_selected(const char *name)
1598{
1599 if (name && name[0] != '\0' && !no_ruleset_callback) {
1600 set_ruleset(name);
1601 }
1602}
1603
1604/**********************************************************************/
1609 static void ruleset_entry_changed(GtkWidget *w, gpointer data)
1610{
1611 const char *name = NULL;
1612
1613 name = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(ruleset_combo));
1614
1615 if (name != NULL) {
1616 ruleset_selected(name);
1617 }
1618}
1619
1620/**********************************************************************/
1623 static bool send_new_aifill_to_server = TRUE;
1624 static void ai_fill_changed_by_user(GtkWidget *w, gpointer data)
1625{
1626 if (send_new_aifill_to_server) {
1627 option_int_set(optset_option_by_name(server_optset, "aifill"),
1628 gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(w)));
1629 }
1630}
1631
1632/**********************************************************************/
1635 void ai_fill_changed_by_server(int aifill)
1636{
1637 if (start_aifill_spin) {
1638 bool old = send_new_aifill_to_server;
1639 /* Suppress callback from this change to avoid a loop. */
1640 send_new_aifill_to_server = FALSE;
1641 /* HACK: this GUI control doesn't have quite the same semantics as the
1642 * server 'aifill' option, in that it claims to represent the minimum
1643 * number of players _including humans_. The GUI control has a minimum
1644 * value of 1, so aifill == 0 will not be represented correctly.
1645 * But there's generally exactly one human player because the control
1646 * only shows up for a locally spawned server, so we more or less
1647 * get away with this. */
1648 gtk_spin_button_set_value(GTK_SPIN_BUTTON(start_aifill_spin), aifill);
1649 send_new_aifill_to_server = old;
1650 }
1651}
1652
1653/**********************************************************************/
1656 void update_start_page(void)
1657{
1658 conn_list_dialog_update();
1659}
1660
1661/**********************************************************************/
1664 static void conn_menu_team_chosen(GObject *object, gpointer data)
1665{
1666 struct player *pplayer;
1667 struct team_slot *tslot = data;
1668
1669 if (object_extract(object, &pplayer, NULL)
1670 && NULL != tslot
1671 && team_slot_index(tslot) != team_number(pplayer->team)) {
1672 send_chat_printf("/team \"%s\" \"%s\"",
1673 player_name(pplayer),
1674 team_slot_rule_name(tslot));
1675 }
1676}
1677
1678/**********************************************************************/
1681 static void conn_menu_ready_chosen(GObject *object, gpointer data)
1682{
1683 struct player *pplayer;
1684
1685 if (object_extract(object, &pplayer, NULL)) {
1686 dsend_packet_player_ready(&client.conn,
1687 player_number(pplayer), !pplayer->is_ready);
1688 }
1689}
1690
1691/**********************************************************************/
1694 static void conn_menu_nation_chosen(GObject *object, gpointer data)
1695{
1696 struct player *pplayer;
1697
1698 if (object_extract(object, &pplayer, NULL)) {
1699 popup_races_dialog(pplayer);
1700 }
1701}
1702
1703/**********************************************************************/
1707 static void conn_menu_player_command(GObject *object, gpointer data)
1708{
1709 struct player *pplayer;
1710
1711 if (object_extract(object, &pplayer, NULL)) {
1712 send_chat_printf("/%s \"%s\"",
1713 (char *) g_object_get_data(G_OBJECT(data), "command"),
1714 player_name(pplayer));
1715 }
1716}
1717
1718/**********************************************************************/
1721 static void conn_menu_player_take(GObject *object, gpointer data)
1722{
1723 struct player *pplayer;
1724
1725 if (object_extract(object, &pplayer, NULL)) {
1726 client_take_player(pplayer);
1727 }
1728}
1729
1730/**********************************************************************/
1734 static void conn_menu_connection_command(GObject *object, gpointer data)
1735{
1736 struct connection *pconn;
1737
1738 if (object_extract(object, NULL, &pconn)) {
1739 send_chat_printf("/%s \"%s\"",
1740 (char *) g_object_get_data(G_OBJECT(data), "command"),
1741 pconn->username);
1742 }
1743}
1744
1745/**********************************************************************/
1748 static void show_conn_popup(struct player *pplayer, struct connection *pconn)
1749{
1750 GtkWidget *popup;
1751 char buf[4096] = "";
1752
1753 if (pconn) {
1754 cat_snprintf(buf, sizeof(buf), _("Connection name: %s"),
1755 pconn->username);
1756 } else {
1757 cat_snprintf(buf, sizeof(buf), _("Player name: %s"),
1758 player_name(pplayer));
1759 }
1760 cat_snprintf(buf, sizeof(buf), "\n");
1761 if (pconn) {
1762 cat_snprintf(buf, sizeof(buf), _("Host: %s"), pconn->addr);
1763 }
1764 cat_snprintf(buf, sizeof(buf), "\n");
1765
1766 /* Show popup. */
1767 popup = gtk_message_dialog_new(NULL, 0,
1768 GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE,
1769 "%s", buf);
1770 gtk_window_set_title(GTK_WINDOW(popup), _("Player/conn info"));
1771 setup_dialog(popup, toplevel);
1772 g_signal_connect(popup, "response", G_CALLBACK(gtk_widget_destroy), NULL);
1773 gtk_window_present(GTK_WINDOW(popup));
1774}
1775
1776/**********************************************************************/
1779 static void conn_menu_info_chosen(GObject *object, gpointer data)
1780{
1781 struct player *pplayer;
1782 struct connection *pconn;
1783
1784 if (object_extract(object, &pplayer, &pconn)) {
1785 show_conn_popup(pplayer, pconn);
1786 }
1787}
1788
1789/**********************************************************************/
1793 static GtkWidget *create_conn_menu(struct player *pplayer,
1794 struct connection *pconn)
1795{
1796 GtkWidget *menu;
1797 GtkWidget *item;
1798 gchar *buf;
1799
1800 menu = gtk_menu_new();
1801 object_put(G_OBJECT(menu), pplayer, pconn);
1802
1803 buf = g_strdup_printf(_("%s info"),
1804 pconn ? pconn->username : player_name(pplayer));
1805 item = gtk_menu_item_new_with_label(buf);
1806 g_free(buf);
1807 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1808 g_signal_connect_swapped(item, "activate",
1809 G_CALLBACK(conn_menu_info_chosen), menu);
1810
1811 if (NULL != pplayer) {
1812 item = gtk_menu_item_new_with_label(_("Toggle player ready"));
1813 gtk_widget_set_sensitive(item, is_human(pplayer));
1814 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1815 g_signal_connect_swapped(item, "activate",
1816 G_CALLBACK(conn_menu_ready_chosen), menu);
1817
1818 item = gtk_menu_item_new_with_label(_("Pick nation"));
1819 gtk_widget_set_sensitive(item,
1820 can_conn_edit_players_nation(&client.conn,
1821 pplayer));
1822 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1823 g_signal_connect_swapped(item, "activate",
1824 G_CALLBACK(conn_menu_nation_chosen), menu);
1825
1826 item = gtk_menu_item_new_with_label(_("Observe this player"));
1827 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1828 g_object_set_data_full(G_OBJECT(item), "command", g_strdup("observe"),
1829 (GDestroyNotify) g_free);
1830 g_signal_connect_swapped(item, "activate",
1831 G_CALLBACK(conn_menu_player_command), menu);
1832
1833 item = gtk_menu_item_new_with_label(_("Take this player"));
1834 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1835 g_signal_connect_swapped(item, "activate",
1836 G_CALLBACK(conn_menu_player_take), menu);
1837 }
1838
1839 if (ALLOW_CTRL <= client.conn.access_level && NULL != pconn
1840 && (pconn->id != client.conn.id || NULL != pplayer)) {
1841 item = gtk_separator_menu_item_new();
1842 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1843
1844 if (pconn->id != client.conn.id) {
1845 item = gtk_menu_item_new_with_label(_("Cut connection"));
1846 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1847 g_object_set_data_full(G_OBJECT(item), "command", g_strdup("cut"),
1848 (GDestroyNotify) g_free);
1849 g_signal_connect_swapped(item, "activate",
1850 G_CALLBACK(conn_menu_connection_command),
1851 menu);
1852 }
1853 }
1854
1855 if (ALLOW_CTRL <= client.conn.access_level && NULL != pplayer) {
1856 item = gtk_menu_item_new_with_label(_("Aitoggle player"));
1857 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1858 g_object_set_data_full(G_OBJECT(item), "command", g_strdup("aitoggle"),
1859 (GDestroyNotify) g_free);
1860 g_signal_connect_swapped(item, "activate",
1861 G_CALLBACK(conn_menu_player_command), menu);
1862
1863 if (pplayer != client.conn.playing && game.info.is_new_game) {
1864 item = gtk_menu_item_new_with_label(_("Remove player"));
1865 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1866 g_object_set_data_full(G_OBJECT(item), "command", g_strdup("remove"),
1867 (GDestroyNotify) g_free);
1868 g_signal_connect_swapped(item, "activate",
1869 G_CALLBACK(conn_menu_player_command), menu);
1870 }
1871 }
1872
1873 if (ALLOW_ADMIN <= client.conn.access_level && NULL != pconn
1874 && pconn->id != client.conn.id) {
1875 enum cmdlevel level;
1876
1877 /* No item for hack access; that would be a serious security hole. */
1878 for (level = cmdlevel_min(); level < client.conn.access_level; level++) {
1879 /* TRANS: Give access level to a connection. */
1880 buf = g_strdup_printf(_("Give %s access"),
1881 cmdlevel_name(level));
1882 item = gtk_menu_item_new_with_label(buf);
1883 g_free(buf);
1884 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1885 g_object_set_data_full(G_OBJECT(item), "command",
1886 g_strdup_printf("cmdlevel %s",
1887 cmdlevel_name(level)),
1888 (GDestroyNotify) g_free);
1889 g_signal_connect_swapped(item, "activate",
1890 G_CALLBACK(conn_menu_connection_command),
1891 menu);
1892 }
1893 }
1894
1895 if (ALLOW_CTRL <= client.conn.access_level
1896 && NULL != pplayer && is_ai(pplayer)) {
1897 enum ai_level level;
1898
1899 item = gtk_separator_menu_item_new();
1900 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1901
1902 for (level = 0; level < AI_LEVEL_COUNT; level++) {
1903 if (is_settable_ai_level(level)) {
1904 const char *level_name = ai_level_translated_name(level);
1905 const char *level_cmd = ai_level_cmd(level);
1906
1907 item = gtk_menu_item_new_with_label(level_name);
1908 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1909 g_object_set_data_full(G_OBJECT(item), "command",
1910 g_strdup(level_cmd), (GDestroyNotify) g_free);
1911 g_signal_connect_swapped(item, "activate",
1912 G_CALLBACK(conn_menu_player_command), menu);
1913 }
1914 }
1915 }
1916
1917 if (pplayer && game.info.is_new_game) {
1918 const int count = pplayer->team
1919 ? player_list_size(team_members(pplayer->team)) : 0;
1920 bool need_empty_team = (count != 1);
1921
1922 item = gtk_separator_menu_item_new();
1923 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1924
1925 /* Can't use team_iterate here since it skips empty teams. */
1926 team_slots_iterate(tslot) {
1927 if (!team_slot_is_used(tslot)) {
1928 if (!need_empty_team) {
1929 continue;
1930 }
1931 need_empty_team = FALSE;
1932 }
1933
1934 /* TRANS: e.g., "Put on Team 5" */
1935 buf = g_strdup_printf(_("Put on %s"),
1936 team_slot_name_translation(tslot));
1937 item = gtk_menu_item_new_with_label(buf);
1938 g_free(buf);
1939 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1940 object_put(G_OBJECT(item), pplayer, NULL);
1941 g_signal_connect(item, "activate", G_CALLBACK(conn_menu_team_chosen),
1942 tslot);
1943 } team_slots_iterate_end;
1944 }
1945
1946 gtk_widget_show_all(menu);
1947
1948 return menu;
1949}
1950
1951/**********************************************************************/
1954 static gboolean delayed_unselect_path(gpointer data)
1955{
1956 if (NULL != connection_list_view) {
1957 GtkTreeSelection *selection =
1958 gtk_tree_view_get_selection(connection_list_view);
1959 GtkTreePath *path = data;
1960
1961 gtk_tree_selection_unselect_path(selection, path);
1962 gtk_tree_path_free(path);
1963 }
1964 return FALSE;
1965}
1966
1967/**********************************************************************/
1970 static gboolean connection_list_event(GtkWidget *widget,
1971 GdkEventButton *event,
1972 gpointer data)
1973{
1974 GtkTreeView *tree = GTK_TREE_VIEW(widget);
1975 GtkTreePath *path = NULL;
1976 GtkTreeSelection *selection = gtk_tree_view_get_selection(tree);
1977 gboolean ret = FALSE;
1978
1979 if ((1 != event->button && 3 != event->button)
1980 || GDK_BUTTON_PRESS != event->type
1981 || !gtk_tree_view_get_path_at_pos(tree,
1982 event->x, event->y,
1983 &path, NULL, NULL, NULL)) {
1984 return FALSE;
1985 }
1986
1987 if (1 == event->button) {
1988 if (gtk_tree_selection_path_is_selected(selection, path)) {
1989 /* Need to delay to avoid problem with the expander. */
1990 g_idle_add(delayed_unselect_path, path);
1991 return FALSE; /* Return now, don't free the path. */
1992 }
1993 } else if (3 == event->button) {
1994 GtkTreeModel *model = gtk_tree_view_get_model(tree);
1995 GtkTreeIter iter;
1996 GtkWidget *menu;
1997 int player_no, conn_id;
1998 struct player *pplayer;
1999 struct connection *pconn;
2000
2001 if (!gtk_tree_selection_path_is_selected(selection, path)) {
2002 gtk_tree_selection_select_path(selection, path);
2003 }
2004 gtk_tree_model_get_iter(model, &iter, path);
2005
2006 gtk_tree_model_get(model, &iter, CL_COL_PLAYER_NUMBER, &player_no, -1);
2007 pplayer = player_by_number(player_no);
2008
2009 gtk_tree_model_get(model, &iter, CL_COL_CONN_ID, &conn_id, -1);
2010 pconn = conn_by_number(conn_id);
2011
2012 menu = create_conn_menu(pplayer, pconn);
2013 gtk_menu_popup(GTK_MENU(menu), NULL, NULL,
2014 NULL, NULL, event->button, event->time);
2015 ret = TRUE;
2016 }
2017
2018 gtk_tree_path_free(path);
2019 return ret;
2020}
2021
2022/**********************************************************************/
2025 static void connection_list_row_callback(GtkTreeView *tree_view,
2026 GtkTreeIter *iter,
2027 GtkTreePath *path,
2028 gpointer data)
2029{
2030 GtkTreeStore *store = GTK_TREE_STORE(gtk_tree_view_get_model(tree_view));
2031
2032 gtk_tree_store_set(store, iter,
2033 CL_COL_COLLAPSED, GPOINTER_TO_INT(data), -1);
2034}
2035
2036/**********************************************************************/
2040 static bool conn_list_selection(struct player **ppplayer,
2041 struct connection **ppconn)
2042{
2043 if (NULL != connection_list_view) {
2044 GtkTreeIter iter;
2045 GtkTreeModel *model;
2046 GtkTreeSelection *selection =
2047 gtk_tree_view_get_selection(connection_list_view);
2048
2049 if (gtk_tree_selection_get_selected(selection, &model, &iter)) {
2050 int id;
2051
2052 if (NULL != ppplayer) {
2053 gtk_tree_model_get(model, &iter, CL_COL_PLAYER_NUMBER, &id, -1);
2054 *ppplayer = player_by_number(id);
2055 }
2056 if (NULL != ppconn) {
2057 gtk_tree_model_get(model, &iter, CL_COL_CONN_ID, &id, -1);
2058 *ppconn = conn_by_number(id);
2059 }
2060 return TRUE;
2061 }
2062 }
2063
2064 if (NULL != ppplayer) {
2065 *ppplayer = NULL;
2066 }
2067 if (NULL != ppconn) {
2068 *ppconn = NULL;
2069 }
2070 return FALSE;
2071}
2072
2073/**********************************************************************/
2076 static void conn_list_select_conn(struct connection *pconn)
2077{
2078 GtkTreeModel *model;
2079 GtkTreeIter parent, child, *iter = NULL;
2080 GtkTreeSelection *selection;
2081 gboolean valid;
2082 const int search_id = pconn->id;
2083 int id;
2084
2085 if (NULL == connection_list_view) {
2086 return;
2087 }
2088
2089 model = gtk_tree_view_get_model(connection_list_view);
2090 selection = gtk_tree_view_get_selection(connection_list_view);
2091
2092 /* Main iteration. */
2093 valid = gtk_tree_model_get_iter_first(model, &parent);
2094 while (valid && NULL == iter) {
2095 gtk_tree_model_get(model, &parent, CL_COL_CONN_ID, &id, -1);
2096 if (search_id == id) {
2097 iter = &parent;
2098 break;
2099 }
2100
2101 /* Node children iteration. */
2102 valid = gtk_tree_model_iter_children(model, &child, &parent);
2103 while (valid && NULL == iter) {
2104 gtk_tree_model_get(model, &child, CL_COL_CONN_ID, &id, -1);
2105 if (search_id == id) {
2106 iter = &child;
2107 break;
2108 }
2109 valid = gtk_tree_model_iter_next(model, &child);
2110 }
2111
2112 valid = gtk_tree_model_iter_next(model, &parent);
2113 }
2114
2115 /* Select iterator. */
2116 if (NULL != iter) {
2117 gtk_tree_selection_select_iter(selection, iter);
2118 } else {
2119 log_error("%s(): connection %s not found.",
2120 __FUNCTION__, conn_description(pconn));
2121 }
2122}
2123
2124/**********************************************************************/
2127 static void ready_button_callback(GtkWidget *w, gpointer data)
2128{
2129 if (can_client_control()) {
2130 dsend_packet_player_ready(&client.conn,
2131 player_number(client_player()),
2132 !client_player()->is_ready);
2133 } else {
2134 dsend_packet_player_ready(&client.conn, 0, TRUE);
2135 }
2136}
2137
2138/**********************************************************************/
2141 static void nation_button_callback(GtkWidget *w, gpointer data)
2142{
2143 struct player *selected_plr;
2144 bool row_selected = conn_list_selection(&selected_plr, NULL);
2145
2146 if (row_selected && NULL != selected_plr) {
2147 /* "Take <player_name>" */
2148 client_take_player(selected_plr);
2149 } else if (can_client_control()) {
2150 /* "Pick Nation" */
2151 popup_races_dialog(client_player());
2152 } else {
2153 /* "Take a Player" */
2154 send_chat("/take -");
2155 }
2156}
2157
2158/**********************************************************************/
2161 static void observe_button_callback(GtkWidget *w, gpointer data)
2162{
2163 struct player *selected_plr;
2164 bool row_selected = conn_list_selection(&selected_plr, NULL);
2165
2166 if (row_selected && NULL != selected_plr) {
2167 /* "Observe <player_name>" */
2168 send_chat_printf("/observe \"%s\"", player_name(selected_plr));
2169 } else if (!client_is_global_observer()) {
2170 /* "Observe" */
2171 send_chat("/observe");
2172 } else {
2173 /* "Do not observe" */
2174 send_chat("/detach");
2175 }
2176}
2177
2178/**********************************************************************/
2181 static void update_start_page_buttons(void)
2182{
2183 char buf[2 * MAX_LEN_NAME];
2184 const char *text;
2185 struct player *selected_plr;
2186 bool row_selected = conn_list_selection(&selected_plr, NULL);
2187 bool sensitive;
2188
2189 /*** Ready button. ***/
2190 if (can_client_control()) {
2191 sensitive = client_player()->is_alive;
2192 if (client_player()->is_ready) {
2193 text = _("Not _ready");
2194 } else {
2195 int num_unready = 0;
2196
2197 players_iterate_alive(pplayer) {
2198 if (is_human(pplayer) && !pplayer->is_ready) {
2199 num_unready++;
2200 }
2201 } players_iterate_alive_end;
2202
2203 if (num_unready > 1) {
2204 text = _("_Ready");
2205 } else {
2206 /* We are the last unready player so clicking here will
2207 * immediately start the game. */
2208 text = _("_Start");
2209 }
2210 }
2211 } else {
2212 text = _("_Start");
2213 if (can_client_access_hack()) {
2214 sensitive = TRUE;
2215 players_iterate_alive(plr) {
2216 if (is_human(plr)) {
2217 /* There's human controlled player(s) in game, so it's their
2218 * job to start the game. */
2219 sensitive = FALSE;
2220 break;
2221 }
2222 } players_iterate_alive_end;
2223 } else {
2224 sensitive = FALSE;
2225 }
2226 }
2227 gtk_stockbutton_set_label(ready_button, text);
2228 gtk_widget_set_sensitive(ready_button, sensitive);
2229
2230 /*** Nation button. ***/
2231 if (row_selected && NULL != selected_plr) {
2232 fc_snprintf(buf, sizeof(buf), _("_Take %s"), player_name(selected_plr));
2233 text = buf;
2234 sensitive = (client_is_observer() || selected_plr != client_player());
2235 } else if (can_client_control()) {
2236 text = _("Pick _Nation");
2237 sensitive = game.info.is_new_game;
2238 } else {
2239 text = _("_Take a Player");
2240 sensitive = game.info.is_new_game;
2241 }
2242 gtk_stockbutton_set_label(nation_button, text);
2243 gtk_widget_set_sensitive(nation_button, sensitive);
2244
2245 /*** Observe button. ***/
2246 if (row_selected && NULL != selected_plr) {
2247 fc_snprintf(buf, sizeof(buf), _("_Observe %s"),
2248 player_name(selected_plr));
2249 text = buf;
2250 sensitive = (!client_is_observer() || selected_plr != client_player());
2251 } else if (!client_is_global_observer()) {
2252 text = _("_Observe");
2253 sensitive = TRUE;
2254 } else {
2255 text = _("Do not _observe");
2256 sensitive = TRUE;
2257 }
2258 gtk_stockbutton_set_label(observe_button, text);
2259 gtk_widget_set_sensitive(observe_button, sensitive);
2260}
2261
2262/**********************************************************************/
2266 static bool model_get_player_iter(GtkTreeModel *model,
2267 GtkTreeIter *iter,
2268 GtkTreeIter *start,
2269 const struct player *pplayer)
2270{
2271 const int search_id = player_number(pplayer);
2272 int id;
2273
2274 if (NULL != start) {
2275 *iter = *start;
2276 if (!gtk_tree_model_iter_next(model, iter)) {
2277 return FALSE;
2278 }
2279 } else if (!gtk_tree_model_get_iter_first(model, iter)) {
2280 return FALSE;
2281 }
2282
2283 do {
2284 gtk_tree_model_get(model, iter, CL_COL_PLAYER_NUMBER, &id, -1);
2285 if (id == search_id) {
2286 return TRUE;
2287 }
2288 } while (gtk_tree_model_iter_next(model, iter));
2289
2290 return FALSE;
2291}
2292
2293/**********************************************************************/
2297 static bool model_get_conn_iter(GtkTreeModel *model, GtkTreeIter *iter,
2298 GtkTreeIter *parent, GtkTreeIter *start,
2299 const struct connection *pconn)
2300{
2301 const int search_id = pconn->id;
2302 int id;
2303
2304 if (NULL != start) {
2305 *iter = *start;
2306 if (!gtk_tree_model_iter_next(model, iter)) {
2307 return FALSE;
2308 }
2309 } else if (!gtk_tree_model_iter_children(model, iter, parent)) {
2310 return FALSE;
2311 }
2312
2313 do {
2314 gtk_tree_model_get(model, iter, CL_COL_CONN_ID, &id, -1);
2315 if (id == search_id) {
2316 return TRUE;
2317 }
2318 } while (gtk_tree_model_iter_next(model, iter));
2319
2320 return FALSE;
2321}
2322
2323/**********************************************************************/
2326 void real_conn_list_dialog_update(void *unused)
2327{
2328 if (client_state() == C_S_PREPARING
2329 && get_client_page() == PAGE_START
2330 && connection_list_store != NULL) {
2331 GtkTreeStore *store = connection_list_store;
2332 GtkTreeModel *model = GTK_TREE_MODEL(store);
2333 GtkTreePath *path;
2334 GtkTreeIter child, prev_child, *pprev_child;
2335 GtkTreeIter parent, prev_parent, *pprev_parent = NULL;
2336 GdkPixbuf *flag, *color;
2337 gboolean collapsed;
2338 struct player *pselected_player;
2339 struct connection *pselected_conn;
2340 bool is_ready;
2341 const char *nation, *plr_name, *team;
2342 char name[MAX_LEN_NAME + 8];
2343 enum cmdlevel access_level;
2344 int conn_id;
2345
2346 /* Refresh the AI skill level control */
2347 if (ai_lvl_combobox) {
2348 enum ai_level new_level = server_ai_level(), level;
2349 int i = 0;
2350
2351 for (level = 0; level < AI_LEVEL_COUNT; level++) {
2352 if (is_settable_ai_level(level)) {
2353 if (level == new_level) {
2354 gtk_combo_box_set_active(GTK_COMBO_BOX(ai_lvl_combobox), i);
2355 break;
2356 }
2357 i++;
2358 }
2359 }
2360 if (level == AI_LEVEL_COUNT) {
2361 /* Probably ai_level_invalid() */
2362 gtk_combo_box_set_active(GTK_COMBO_BOX(ai_lvl_combobox), -1);
2363 }
2364 }
2365
2366 /* Save the selected connection. */
2367 (void) conn_list_selection(&pselected_player, &pselected_conn);
2368
2369 /* Insert players into the connection list. */
2370 players_iterate(pplayer) {
2371 if (!player_has_flag(pplayer, PLRF_SCENARIO_RESERVED)) {
2372 conn_id = -1;
2373 access_level = ALLOW_NONE;
2374 flag = pplayer->nation ? get_flag(pplayer->nation) : NULL;
2375 color = create_player_icon(pplayer);
2376
2377 conn_list_iterate(pplayer->connections, pconn) {
2378 if (pconn->playing == pplayer && !pconn->observer) {
2379 conn_id = pconn->id;
2380 access_level = pconn->access_level;
2381 break;
2382 }
2383 } conn_list_iterate_end;
2384
2385 if (is_ai(pplayer) && !pplayer->was_created
2386 && !pplayer->is_connected) {
2387 /* TRANS: "<Novice AI>" */
2388 fc_snprintf(name, sizeof(name), _("<%s AI>"),
2389 ai_level_translated_name(pplayer->ai_common.skill_level));
2390 } else {
2391 sz_strlcpy(name, pplayer->username);
2392 if (access_level > ALLOW_BASIC) {
2393 sz_strlcat(name, "*");
2394 }
2395 }
2396
2397 is_ready = !is_human(pplayer) ? TRUE : pplayer->is_ready;
2398
2399 if (pplayer->nation == NO_NATION_SELECTED) {
2400 nation = _("Random");
2401 if (pplayer->was_created) {
2402 plr_name = player_name(pplayer);
2403 } else {
2404 plr_name = "";
2405 }
2406 } else {
2407 nation = nation_adjective_for_player(pplayer);
2408 plr_name = player_name(pplayer);
2409 }
2410
2411 team = pplayer->team ? team_name_translation(pplayer->team) : "";
2412
2413 if (model_get_player_iter(model, &parent, pprev_parent, pplayer)) {
2414 gtk_tree_store_move_after(store, &parent, pprev_parent);
2415 } else {
2416 gtk_tree_store_insert_after(store, &parent, NULL, pprev_parent);
2417 }
2418
2419 gtk_tree_store_set(store, &parent,
2420 CL_COL_PLAYER_NUMBER, player_number(pplayer),
2421 CL_COL_USER_NAME, name,
2422 CL_COL_READY_STATE, is_ready,
2423 CL_COL_PLAYER_NAME, plr_name,
2424 CL_COL_FLAG, flag,
2425 CL_COL_COLOR, color,
2426 CL_COL_NATION, nation,
2427 CL_COL_TEAM, team,
2428 CL_COL_CONN_ID, conn_id,
2429 CL_COL_STYLE, PANGO_STYLE_NORMAL,
2430 CL_COL_WEIGHT, PANGO_WEIGHT_BOLD,
2431 -1);
2432
2433 /* Insert observers of this player as child nodes. */
2434 pprev_child = NULL;
2435 conn_list_iterate(pplayer->connections, pconn) {
2436 if (pconn->id == conn_id) {
2437 continue;
2438 }
2439 if (model_get_conn_iter(model, &child, &parent,
2440 pprev_child, pconn)) {
2441 gtk_tree_store_move_after(store, &child, pprev_child);
2442 } else {
2443 gtk_tree_store_insert_after(store, &child, &parent, pprev_child);
2444 }
2445
2446 gtk_tree_store_set(store, &child,
2447 CL_COL_PLAYER_NUMBER, -1,
2448 CL_COL_USER_NAME, pconn->username,
2449 CL_COL_TEAM, _("Observer"),
2450 CL_COL_CONN_ID, pconn->id,
2451 CL_COL_STYLE, PANGO_STYLE_NORMAL,
2452 CL_COL_WEIGHT, PANGO_WEIGHT_NORMAL,
2453 -1);
2454
2455 prev_child = child;
2456 pprev_child = &prev_child;
2457 } conn_list_iterate_end;
2458
2459 /* Expand node? */
2460 if (NULL != pprev_child) {
2461 gtk_tree_model_get(model, &parent, CL_COL_COLLAPSED, &collapsed, -1);
2462 if (!collapsed) {
2463 path = gtk_tree_model_get_path(model, &parent);
2464 gtk_tree_view_expand_row(GTK_TREE_VIEW(connection_list_view),
2465 path, FALSE);
2466 gtk_tree_path_free(path);
2467 }
2468 }
2469
2470 /* Remove trailing rows. */
2471 if (NULL != pprev_child) {
2472 child = prev_child;
2473 if (gtk_tree_model_iter_next(model, &child)) {
2474 while (gtk_tree_store_remove(store, &child)) {
2475 /* Do nothing more. */
2476 }
2477 }
2478 } else if (gtk_tree_model_iter_children(model, &child, &parent)) {
2479 while (gtk_tree_store_remove(store, &child)) {
2480 /* Do nothing more. */
2481 }
2482 }
2483
2484 prev_parent = parent;
2485 pprev_parent = &prev_parent;
2486 if (flag) {
2487 g_object_unref(flag);
2488 }
2489 if (color) {
2490 g_object_unref(color);
2491 }
2492 }
2493 } players_iterate_end;
2494
2495 /* Finally, insert global observers... */
2496 conn_list_iterate(game.est_connections, pconn) {
2497 if (NULL != pconn->playing || !pconn->observer) {
2498 continue;
2499 }
2500
2501 if (model_get_conn_iter(model, &parent, NULL, pprev_parent, pconn)) {
2502 gtk_tree_store_move_after(store, &parent, pprev_parent);
2503 } else {
2504 gtk_tree_store_insert_after(store, &parent, NULL, pprev_parent);
2505 }
2506
2507 gtk_tree_store_set(store, &parent,
2508 CL_COL_PLAYER_NUMBER, -1,
2509 CL_COL_USER_NAME, pconn->username,
2510 CL_COL_TEAM, _("Observer"),
2511 CL_COL_CONN_ID, pconn->id,
2512 CL_COL_STYLE, PANGO_STYLE_NORMAL,
2513 CL_COL_WEIGHT, PANGO_WEIGHT_NORMAL,
2514 -1);
2515
2516 prev_parent = parent;
2517 pprev_parent = &prev_parent;
2518 } conn_list_iterate_end;
2519
2520 /* ...and detached connections. */
2521 conn_list_iterate(game.est_connections, pconn) {
2522 if (NULL != pconn->playing || pconn->observer) {
2523 continue;
2524 }
2525
2526 if (model_get_conn_iter(model, &parent, NULL, pprev_parent, pconn)) {
2527 gtk_tree_store_move_after(store, &parent, pprev_parent);
2528 } else {
2529 gtk_tree_store_insert_after(store, &parent, NULL, pprev_parent);
2530 }
2531
2532 gtk_tree_store_set(store, &parent,
2533 CL_COL_PLAYER_NUMBER, -1,
2534 CL_COL_USER_NAME, pconn->username,
2535 CL_COL_TEAM, _("Detached"),
2536 CL_COL_CONN_ID, pconn->id,
2537 CL_COL_STYLE, PANGO_STYLE_ITALIC,
2538 CL_COL_WEIGHT, PANGO_WEIGHT_NORMAL,
2539 -1);
2540
2541 prev_parent = parent;
2542 pprev_parent = &prev_parent;
2543 } conn_list_iterate_end;
2544
2545 /* Remove trailing rows. */
2546 if (NULL != pprev_parent) {
2547 parent = prev_parent;
2548 if (gtk_tree_model_iter_next(model, &parent)) {
2549 while (gtk_tree_store_remove(store, &parent)) {
2550 /* Do nothing more. */
2551 }
2552 }
2553 } else {
2554 gtk_tree_store_clear(store);
2555 }
2556
2557 /* If we were selecting a single connection, let's try to reselect it. */
2558 if (NULL == pselected_player && NULL != pselected_conn) {
2559 conn_list_select_conn(pselected_conn);
2560 }
2561 }
2562
2563 update_start_page_buttons();
2564}
2565
2566/**********************************************************************/
2571 static void add_tree_col(GtkWidget *treeview, GType gtype,
2572 const char *title, int colnum, const char *key)
2573{
2574 GtkCellRenderer *rend;
2575 GtkTreeViewColumn *col;
2576
2577 if (gtype == G_TYPE_BOOLEAN) {
2578 rend = gtk_cell_renderer_toggle_new();
2579 col = gtk_tree_view_column_new_with_attributes(title, rend,
2580 "active", colnum, NULL);
2581 } else if (gtype == GDK_TYPE_PIXBUF) {
2582 rend = gtk_cell_renderer_pixbuf_new();
2583 col = gtk_tree_view_column_new_with_attributes(title, rend,
2584 "pixbuf", colnum, NULL);
2585 } else {
2586 rend = gtk_cell_renderer_text_new();
2587 col = gtk_tree_view_column_new_with_attributes(title, rend,
2588 "text", colnum,
2589 "style", CL_COL_STYLE,
2590 "weight", CL_COL_WEIGHT,
2591 NULL);
2592 }
2593
2594 gtk_tree_view_column_set_sizing(col, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
2595 gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), col);
2596
2597 if (key != NULL) {
2598 g_object_set_data(G_OBJECT(treeview), key, col);
2599 }
2600}
2601
2602/**********************************************************************/
2605GtkWidget *create_start_page(void)
2606{
2607 GtkWidget *box, *sbox, *table, *vbox;
2608 GtkWidget *view, *sw, *text, *toolkit_view, *button, *spin;
2609 GtkWidget *label;
2610 GtkTreeSelection *selection;
2611 enum ai_level level;
2612 /* There's less than AI_LEVEL_COUNT entries as not all levels have
2613 entries (that's the whole point of this array: index != value),
2614 but this is set safely to the max */
2615 static enum ai_level levels[AI_LEVEL_COUNT];
2616 int i = 0;
2617
2618 box = gtk_grid_new();
2619 gtk_orientable_set_orientation(GTK_ORIENTABLE(box),
2620 GTK_ORIENTATION_VERTICAL);
2621 gtk_grid_set_row_spacing(GTK_GRID(box), 8);
2622 gtk_container_set_border_width(GTK_CONTAINER(box), 4);
2623
2624 sbox = gtk_grid_new();
2625 gtk_grid_set_column_spacing(GTK_GRID(sbox), 12);
2626 gtk_container_add(GTK_CONTAINER(box), sbox);
2627
2628 vbox = gtk_grid_new();
2629 g_object_set(vbox, "margin", 12, NULL);
2630 gtk_orientable_set_orientation(GTK_ORIENTABLE(vbox),
2631 GTK_ORIENTATION_VERTICAL);
2632 gtk_grid_set_row_spacing(GTK_GRID(vbox), 2);
2633 gtk_widget_set_halign(vbox, GTK_ALIGN_CENTER);
2634 gtk_widget_set_valign(vbox, GTK_ALIGN_CENTER);
2635 gtk_container_add(GTK_CONTAINER(sbox), vbox);
2636
2637 table = gtk_grid_new();
2638 start_options_table = table;
2639 gtk_grid_set_row_spacing(GTK_GRID(table), 2);
2640 gtk_grid_set_column_spacing(GTK_GRID(table), 12);
2641 gtk_container_add(GTK_CONTAINER(vbox), table);
2642
2643 spin = gtk_spin_button_new_with_range(1, MAX_NUM_PLAYERS, 1);
2644 start_aifill_spin = spin;
2645 gtk_spin_button_set_digits(GTK_SPIN_BUTTON(spin), 0);
2646 gtk_spin_button_set_update_policy(GTK_SPIN_BUTTON(spin),
2647 GTK_UPDATE_IF_VALID);
2648 if (server_optset != NULL) {
2649 struct option *paifill = optset_option_by_name(server_optset, "aifill");
2650 if (paifill) {
2651 gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin),
2652 option_int_get(paifill));
2653 } /* else it'll be updated later */
2654 }
2655 g_signal_connect_after(spin, "value_changed",
2656 G_CALLBACK(ai_fill_changed_by_user), NULL);
2657
2658 gtk_grid_attach(GTK_GRID(table), spin, 1, 0, 1, 1);
2659
2660 label = g_object_new(GTK_TYPE_LABEL,
2661 "use-underline", TRUE,
2662 "mnemonic-widget", spin,
2663 /* TRANS: Keep individual lines short */
2664 "label", _("Number of _Players\n(including AI):"),
2665 "xalign", 0.0,
2666 "yalign", 0.5,
2667 NULL);
2668 gtk_grid_attach(GTK_GRID(table), label, 0, 0, 1, 1);
2669
2670 ai_lvl_combobox = gtk_combo_box_text_new();
2671
2672 for (level = 0; level < AI_LEVEL_COUNT; level++) {
2673 if (is_settable_ai_level(level)) {
2674 const char *level_name = ai_level_translated_name(level);
2675
2676 gtk_combo_box_text_insert_text(GTK_COMBO_BOX_TEXT(ai_lvl_combobox), i, level_name);
2677 levels[i] = level;
2678 i++;
2679 }
2680 }
2681 gtk_combo_box_set_active(GTK_COMBO_BOX(ai_lvl_combobox), -1);
2682 g_signal_connect(ai_lvl_combobox, "changed",
2683 G_CALLBACK(ai_skill_callback), levels);
2684
2685 gtk_grid_attach(GTK_GRID(table), ai_lvl_combobox, 1, 1, 1, 1);
2686
2687 label = g_object_new(GTK_TYPE_LABEL,
2688 "use-underline", TRUE,
2689 "mnemonic-widget", ai_lvl_combobox,
2690 "label", _("AI Skill _Level:"),
2691 "xalign", 0.0,
2692 "yalign", 0.5,
2693 NULL);
2694 gtk_grid_attach(GTK_GRID(table), label, 0, 1, 1, 1);
2695
2696 ruleset_combo = gtk_combo_box_text_new();
2697 g_signal_connect(G_OBJECT(ruleset_combo), "changed",
2698 G_CALLBACK(ruleset_entry_changed), NULL);
2699
2700 gtk_grid_attach(GTK_GRID(table), ruleset_combo, 1, 2, 1, 1);
2701
2702 label = g_object_new(GTK_TYPE_LABEL,
2703 "use-underline", TRUE,
2704 "mnemonic-widget", GTK_COMBO_BOX_TEXT(ruleset_combo),
2705 "label", _("Ruleset:"),
2706 "xalign", 0.0,
2707 "yalign", 0.5,
2708 NULL);
2709 gtk_grid_attach(GTK_GRID(table), label, 0, 2, 1, 1);
2710
2711 button = gtk_stockbutton_new(GTK_STOCK_PREFERENCES,
2712 _("_More Game Options..."));
2713 g_object_set(button, "margin", 8, NULL);
2714 gtk_widget_set_halign(button, GTK_ALIGN_CENTER);
2715 gtk_widget_set_valign(button, GTK_ALIGN_CENTER);
2716 g_signal_connect(button, "clicked",
2717 G_CALLBACK(game_options_callback), NULL);
2718 gtk_container_add(GTK_CONTAINER(vbox), button);
2719
2720 connection_list_store = connection_list_store_new();
2721 view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(connection_list_store));
2722 gtk_widget_set_hexpand(view, TRUE);
2723 g_object_unref(G_OBJECT(connection_list_store));
2724 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view), TRUE);
2725 connection_list_view = GTK_TREE_VIEW(view);
2726
2727 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
2728 gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE);
2729 g_signal_connect(selection, "changed",
2730 G_CALLBACK(update_start_page_buttons), NULL);
2731
2732 add_tree_col(view, G_TYPE_STRING, _("Name"),
2733 CL_COL_USER_NAME, NULL);
2734 add_tree_col(view, G_TYPE_BOOLEAN, _("Ready"),
2735 CL_COL_READY_STATE, NULL);
2736 add_tree_col(view, G_TYPE_STRING, Q_("?player:Leader"),
2737 CL_COL_PLAYER_NAME, NULL);
2738 add_tree_col(view, GDK_TYPE_PIXBUF, _("Flag"),
2739 CL_COL_FLAG, NULL);
2740 add_tree_col(view, GDK_TYPE_PIXBUF, _("Border"),
2741 CL_COL_COLOR, NULL);
2742 add_tree_col(view, G_TYPE_STRING, _("Nation"),
2743 CL_COL_NATION, NULL);
2744 add_tree_col(view, G_TYPE_STRING, _("Team"),
2745 CL_COL_TEAM, NULL);
2746
2747 g_signal_connect(view, "button-press-event",
2748 G_CALLBACK(connection_list_event), NULL);
2749 g_signal_connect(view, "row-collapsed",
2750 G_CALLBACK(connection_list_row_callback),
2751 GINT_TO_POINTER(TRUE));
2752 g_signal_connect(view, "row-expanded",
2753 G_CALLBACK(connection_list_row_callback),
2754 GINT_TO_POINTER(FALSE));
2755
2756 sw = gtk_scrolled_window_new(NULL, NULL);
2757 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw),
2758 GTK_SHADOW_ETCHED_IN);
2759 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
2760 GTK_POLICY_AUTOMATIC,
2761 GTK_POLICY_ALWAYS);
2762 gtk_scrolled_window_set_min_content_height(GTK_SCROLLED_WINDOW(sw), 200);
2763 gtk_container_add(GTK_CONTAINER(sw), view);
2764 gtk_container_add(GTK_CONTAINER(sbox), sw);
2765
2766
2767 sw = gtk_scrolled_window_new(NULL, NULL);
2768 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw),
2769 GTK_SHADOW_ETCHED_IN);
2770 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
2771 GTK_POLICY_AUTOMATIC,
2772 GTK_POLICY_ALWAYS);
2773 gtk_container_add(GTK_CONTAINER(box), sw);
2774
2775 text = gtk_text_view_new_with_buffer(message_buffer);
2776 gtk_widget_set_hexpand(text, TRUE);
2777 gtk_widget_set_vexpand(text, TRUE);
2778 start_message_area = text;
2779 gtk_widget_set_name(text, "chatline");
2780 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_WORD);
2781 gtk_text_view_set_left_margin(GTK_TEXT_VIEW(text), 5);
2782 gtk_text_view_set_editable(GTK_TEXT_VIEW(text), FALSE);
2783 gtk_container_add(GTK_CONTAINER(sw), text);
2784
2785
2786 /* Vote widgets. */
2787 if (pregame_votebar == NULL) {
2788 pregame_votebar = voteinfo_bar_new(TRUE);
2789 }
2790 gtk_container_add(GTK_CONTAINER(box), pregame_votebar);
2791
2792
2793 toolkit_view = inputline_toolkit_view_new();
2794 gtk_container_add(GTK_CONTAINER(box), toolkit_view);
2795
2796 button = gtk_button_new_from_stock(GTK_STOCK_CANCEL);
2797 inputline_toolkit_view_append_button(toolkit_view, button);
2798 g_signal_connect(button, "clicked", G_CALLBACK(main_callback), NULL);
2799
2800 nation_button = gtk_stockbutton_new(GTK_STOCK_PROPERTIES,
2801 _("Pick _Nation"));
2802 inputline_toolkit_view_append_button(toolkit_view, nation_button);
2803 g_signal_connect(nation_button, "clicked",
2804 G_CALLBACK(nation_button_callback), NULL);
2805
2806 observe_button = gtk_stockbutton_new(GTK_STOCK_ZOOM_IN, _("_Observe"));
2807 inputline_toolkit_view_append_button(toolkit_view, observe_button);
2808 g_signal_connect(observe_button, "clicked",
2809 G_CALLBACK(observe_button_callback), NULL);
2810
2811 ready_button = gtk_stockbutton_new(GTK_STOCK_EXECUTE, _("_Ready"));
2812 inputline_toolkit_view_append_button(toolkit_view, ready_button);
2813 g_signal_connect(ready_button, "clicked",
2814 G_CALLBACK(ready_button_callback), NULL);
2815
2816 return box;
2817}
2818
2819
2820/**********************************************************************/
2823 void handle_game_load(bool load_successful, const char *filename)
2824{
2825 if (load_successful) {
2826 set_client_page(PAGE_START);
2827
2828 if (game.info.is_new_game) {
2829 /* It's pregame. Create a player and connect to it */
2830 send_chat("/take -");
2831 }
2832 }
2833}
2834
2835/**********************************************************************/
2838 static void load_filename(const char *filename)
2839{
2840 send_chat_printf("/load %s", filename);
2841}
2842
2843/**********************************************************************/
2846 static void load_callback(void)
2847{
2848 GtkTreeIter it;
2849 const gchar *filename;
2850
2851 if (!gtk_tree_selection_get_selected(load_selection, NULL, &it)) {
2852 return;
2853 }
2854
2855 gtk_tree_model_get(GTK_TREE_MODEL(load_store), &it,
2856 SD_COL_FULL_PATH, &filename, -1);
2857 load_filename(filename);
2858}
2859
2860/**********************************************************************/
2863 static void load_browse_callback(GtkWidget *w, gpointer data)
2864{
2865 save_dialog_file_chooser_popup(_("Choose Saved Game to Load"),
2866 GTK_FILE_CHOOSER_ACTION_OPEN,
2867 load_filename);
2868}
2869
2870/**********************************************************************/
2873 static void update_load_page(void)
2874{
2875 /* Search for user saved games. */
2876 struct fileinfo_list *files = fileinfolist_infix(get_save_dirs(),
2877 ".sav", FALSE);
2878
2879 save_dialog_store_update(load_store, files);
2880 fileinfo_list_destroy(files);
2881}
2882
2883/**********************************************************************/
2886GtkWidget *create_load_page(void)
2887{
2888 GtkWidget *box, *sbox, *bbox;
2889
2890 GtkWidget *button, *label, *view, *sw;
2891 GtkCellRenderer *rend;
2892
2893 box = gtk_grid_new();
2894 gtk_orientable_set_orientation(GTK_ORIENTABLE(box),
2895 GTK_ORIENTATION_VERTICAL);
2896 gtk_grid_set_row_spacing(GTK_GRID(box), 18);
2897 gtk_container_set_border_width(GTK_CONTAINER(box), 4);
2898
2899 load_store = save_dialog_store_new();
2900 view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(load_store));
2901 gtk_widget_set_vexpand(view, TRUE);
2902 g_object_unref(load_store);
2903
2904 rend = gtk_cell_renderer_text_new();
2905 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
2906 -1, NULL, rend, "text", 0, NULL);
2907
2908 load_selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
2909 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view), FALSE);
2910
2911 gtk_tree_selection_set_mode(load_selection, GTK_SELECTION_SINGLE);
2912
2913 g_signal_connect(view, "row-activated",
2914 G_CALLBACK(load_callback), NULL);
2915
2916 sbox = gtk_grid_new();
2917 gtk_widget_set_halign(sbox, GTK_ALIGN_CENTER);
2918 gtk_orientable_set_orientation(GTK_ORIENTABLE(sbox),
2919 GTK_ORIENTATION_VERTICAL);
2920 gtk_grid_set_row_spacing(GTK_GRID(sbox), 2);
2921 gtk_container_add(GTK_CONTAINER(box), sbox);
2922
2923 label = g_object_new(GTK_TYPE_LABEL,
2924 "use-underline", TRUE,
2925 "mnemonic-widget", view,
2926 "label", _("Choose Saved Game to _Load:"),
2927 "xalign", 0.0,
2928 "yalign", 0.5,
2929 NULL);
2930 gtk_container_add(GTK_CONTAINER(sbox), label);
2931
2932 sw = gtk_scrolled_window_new(NULL, NULL);
2933 gtk_scrolled_window_set_min_content_width(GTK_SCROLLED_WINDOW(sw), 300);
2934 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw),
2935 GTK_SHADOW_ETCHED_IN);
2936 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_AUTOMATIC,
2937 GTK_POLICY_AUTOMATIC);
2938 gtk_container_add(GTK_CONTAINER(sw), view);
2939 gtk_container_add(GTK_CONTAINER(sbox), sw);
2940
2941 bbox = gtk_button_box_new(GTK_ORIENTATION_HORIZONTAL);
2942 gtk_widget_set_hexpand(bbox, TRUE);
2943 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END);
2944 gtk_box_set_spacing(GTK_BOX(bbox), 12);
2945 gtk_container_add(GTK_CONTAINER(box), bbox);
2946
2947 button = gtk_button_new_with_mnemonic(_("_Browse..."));
2948 gtk_container_add(GTK_CONTAINER(bbox), button);
2949 gtk_button_box_set_child_secondary(GTK_BUTTON_BOX(bbox), button, TRUE);
2950 g_signal_connect(button, "clicked",
2951 G_CALLBACK(load_browse_callback), NULL);
2952
2953 button = gtk_button_new_from_stock(GTK_STOCK_CANCEL);
2954 gtk_container_add(GTK_CONTAINER(bbox), button);
2955 g_signal_connect(button, "clicked",
2956 G_CALLBACK(main_callback), NULL);
2957
2958 button = gtk_button_new_from_stock(GTK_STOCK_OK);
2959 gtk_container_add(GTK_CONTAINER(bbox), button);
2960 g_signal_connect(button, "clicked",
2961 G_CALLBACK(load_callback), NULL);
2962
2963 return box;
2964}
2965
2966
2967/**********************************************************************/
2970 static void scenario_list_callback(void)
2971{
2972 GtkTreeIter it;
2973 GtkTextBuffer *buffer;
2974 char *description;
2975 char *authors;
2976 char *filename;
2977 int ver;
2978 char vername[50];
2979
2980 if (gtk_tree_selection_get_selected(scenario_selection, NULL, &it)) {
2981 gtk_tree_model_get(GTK_TREE_MODEL(scenario_store), &it,
2982 2, &description, -1);
2983 gtk_tree_model_get(GTK_TREE_MODEL(scenario_store), &it,
2984 3, &authors, -1);
2985 gtk_tree_model_get(GTK_TREE_MODEL(scenario_store), &it,
2986 1, &filename, -1);
2987 gtk_tree_model_get(GTK_TREE_MODEL(scenario_store), &it,
2988 4, &ver, -1);
2989 filename = skip_to_basename(filename);
2990 if (ver > 0) {
2991 int maj;
2992 int min;
2993
2994 maj = ver / 1000000;
2995 ver %= 1000000;
2996 min = ver / 10000;
2997 ver %= 10000;
2998 if (ver >= 9000) {
2999 /* Development version, have '+' */
3000 fc_snprintf(vername, sizeof(vername), "%d.%d+", maj, min);
3001 } else {
3002 fc_snprintf(vername, sizeof(vername), "%d.%d", maj, min);
3003 }
3004 } else {
3005 /* TRANS: Old scenario format version */
3006 fc_snprintf(vername, sizeof(vername), _("pre-2.6"));
3007 }
3008 } else {
3009 description = "";
3010 authors = "";
3011 filename = "";
3012 vername[0] = '\0';
3013 }
3014
3015 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(scenario_description));
3016 gtk_text_buffer_set_text(buffer, description, -1);
3017 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(scenario_authors));
3018 gtk_text_buffer_set_text(buffer, authors, -1);
3019 gtk_label_set_text(GTK_LABEL(scenario_filename), filename);
3020 gtk_label_set_text(GTK_LABEL(scenario_version), vername);
3021}
3022
3023/**********************************************************************/
3026 static void scenario_callback(void)
3027{
3028 GtkTreeIter it;
3029 char *filename;
3030
3031 if (!gtk_tree_selection_get_selected(scenario_selection, NULL, &it)) {
3032 return;
3033 }
3034
3035 gtk_tree_model_get(GTK_TREE_MODEL(scenario_store), &it, 1, &filename, -1);
3036 load_filename(filename);
3037}
3038
3039/**********************************************************************/
3042 static void scenario_browse_callback(GtkWidget *w, gpointer data)
3043{
3044 save_dialog_file_chooser_popup(_("Choose a Scenario"),
3045 GTK_FILE_CHOOSER_ACTION_OPEN,
3046 load_filename);
3047}
3048
3049/**********************************************************************/
3052 static void update_scenario_page(void)
3053{
3054 struct fileinfo_list *files;
3055
3056 gtk_list_store_clear(scenario_store);
3057
3058 /* search for scenario files. */
3059 files = fileinfolist_infix(get_scenario_dirs(), ".sav", TRUE);
3060 fileinfo_list_iterate(files, pfile) {
3061 struct section_file *sf;
3062
3063 if ((sf = secfile_load_section(pfile->fullname, "scenario", TRUE))
3064 && secfile_lookup_bool_default(sf, TRUE, "scenario.is_scenario")) {
3065 const char *sname, *sdescription, *sauthors;
3066 int fcver;
3067 int fcdev;
3068 int current_ver = MAJOR_VERSION * 1000000 + MINOR_VERSION * 10000;
3069 int current_dev;
3070
3071 current_dev = current_ver;
3072 if (PATCH_VERSION >= 90) {
3073 /* Patch level matters on development versions */
3074 current_dev += PATCH_VERSION * 100;
3075 }
3076
3077 fcver = secfile_lookup_int_default(sf, 0, "scenario.game_version");
3078 if (fcver < 30000) {
3079 /* Pre-3.0 versions stored version number without emergency version
3080 * part in the end. To get comparable version number stored,
3081 * multiply by 100. */
3082 fcver *= 100;
3083 }
3084 if (fcver % 10000 >= 9000) {
3085 fcdev = fcver - (fcver % 100); /* Emergency version does not count. */
3086 } else {
3087 fcdev = fcver - (fcver % 10000); /* Patch version does not count. */
3088 }
3089 sname = secfile_lookup_str_default(sf, NULL, "scenario.name");
3090 sdescription = secfile_lookup_str_default(sf, NULL,
3091 "scenario.description");
3092 sauthors = secfile_lookup_str_default(sf, NULL, "scenario.authors");
3093 log_debug("scenario file: %s from %s", sname, pfile->fullname);
3094
3095 /* Ignore scenarios for newer freeciv versions than we are. */
3096 if (fcdev <= current_dev) {
3097 bool add_new = TRUE;
3098
3099 if (sname != NULL) {
3100 GtkTreeIter it;
3101 bool valid;
3102
3103 valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(scenario_store), &it);
3104 while (valid) {
3105 char *oname;
3106
3107 gtk_tree_model_get(GTK_TREE_MODEL(scenario_store), &it,
3108 0, &oname, -1);
3109
3110 if (!strcmp(sname, oname)) {
3111 /* Already listed scenario has the same name as the one we just found */
3112 int existing;
3113
3114 gtk_tree_model_get(GTK_TREE_MODEL(scenario_store), &it,
3115 4, &existing, -1);
3116 log_debug("Duplicate %s (%d vs %d)", sname, existing, fcver);
3117
3118 if (existing > fcver) {
3119 /* Already listed one has higher version number */
3120 add_new = FALSE;
3121 } else if (existing < fcver) {
3122 /* New one has higher version number */
3123 add_new = FALSE;
3124
3125 gtk_list_store_set(scenario_store, &it,
3126 0, sname && strlen(sname) ? Q_(sname) : pfile->name,
3127 1, pfile->fullname,
3128 2, (NULL != sdescription && '\0' != sdescription[0]
3129 ? Q_(sdescription) : ""),
3130 3, (NULL != sauthors && sauthors[0] != '\0'
3131 ? Q_(sauthors) : ""),
3132 4, fcver,
3133 -1);
3134 } else {
3135 /* Same version number -> list both */
3136 }
3137 }
3138 valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(scenario_store), &it);
3139 }
3140 }
3141
3142 if (add_new) {
3143 GtkTreeIter it;
3144
3145 gtk_list_store_append(scenario_store, &it);
3146 gtk_list_store_set(scenario_store, &it,
3147 0, sname && strlen(sname) ? Q_(sname) : pfile->name,
3148 1, pfile->fullname,
3149 2, (NULL != sdescription && '\0' != sdescription[0]
3150 ? Q_(sdescription) : ""),
3151 3, (NULL != sauthors && sauthors[0] != '\0'
3152 ? Q_(sauthors) : ""),
3153 4, fcver,
3154 -1);
3155 }
3156 }
3157
3158 secfile_destroy(sf);
3159 }
3160 } fileinfo_list_iterate_end;
3161
3162 fileinfo_list_destroy(files);
3163}
3164
3165/**********************************************************************/
3168GtkWidget *create_scenario_page(void)
3169{
3170 GtkWidget *vbox, *hbox, *sbox, *bbox, *filenamebox, *descbox;
3171 GtkWidget *versionbox, *vertext;
3172 GtkWidget *button, *label, *view, *sw, *swa, *text;
3173 GtkCellRenderer *rend;
3174
3175 vbox = gtk_grid_new();
3176 gtk_orientable_set_orientation(GTK_ORIENTABLE(vbox),
3177 GTK_ORIENTATION_VERTICAL);
3178 gtk_grid_set_row_spacing(GTK_GRID(vbox), 18);
3179 gtk_container_set_border_width(GTK_CONTAINER(vbox), 4);
3180
3181 scenario_store = gtk_list_store_new(5, G_TYPE_STRING,
3182 G_TYPE_STRING,
3183 G_TYPE_STRING,
3184 G_TYPE_STRING,
3185 G_TYPE_INT);
3186 view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(scenario_store));
3187 gtk_widget_set_hexpand(view, TRUE);
3188 gtk_widget_set_vexpand(view, TRUE);
3189 g_object_unref(scenario_store);
3190
3191 rend = gtk_cell_renderer_text_new();
3192 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
3193 -1, NULL, rend, "text", 0, NULL);
3194
3195 scenario_selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
3196 g_signal_connect(scenario_selection, "changed",
3197 G_CALLBACK(scenario_list_callback), NULL);
3198 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view), FALSE);
3199
3200 gtk_tree_selection_set_mode(scenario_selection, GTK_SELECTION_SINGLE);
3201
3202 g_signal_connect(view, "row-activated",
3203 G_CALLBACK(scenario_callback), NULL);
3204
3205 label = g_object_new(GTK_TYPE_LABEL,
3206 "use-underline", TRUE,
3207 "mnemonic-widget", view,
3208 "label", _("Choose a _Scenario:"),
3209 "xalign", 0.0,
3210 "yalign", 0.5,
3211 NULL);
3212 gtk_container_add(GTK_CONTAINER(vbox), label);
3213
3214 sbox = gtk_grid_new();
3215 gtk_grid_set_column_spacing(GTK_GRID(sbox), 12);
3216 gtk_grid_set_row_homogeneous(GTK_GRID(sbox), TRUE);
3217 gtk_orientable_set_orientation(GTK_ORIENTABLE(sbox),
3218 GTK_ORIENTATION_VERTICAL);
3219 gtk_grid_set_row_spacing(GTK_GRID(sbox), 2);
3220 gtk_container_add(GTK_CONTAINER(vbox), sbox);
3221
3222 hbox = gtk_grid_new();
3223 gtk_grid_set_column_homogeneous(GTK_GRID(hbox), TRUE);
3224 gtk_grid_set_column_spacing(GTK_GRID(hbox), 12);
3225
3226 sw = gtk_scrolled_window_new(NULL, NULL);
3227 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw),
3228 GTK_SHADOW_ETCHED_IN);
3229 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_AUTOMATIC,
3230 GTK_POLICY_AUTOMATIC);
3231 gtk_container_add(GTK_CONTAINER(sw), view);
3232 gtk_grid_attach(GTK_GRID(sbox), sw, 0, 0, 1, 2);
3233
3234 text = gtk_text_view_new();
3235 gtk_widget_set_hexpand(text, TRUE);
3236 gtk_widget_set_vexpand(text, TRUE);
3237 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_WORD);
3238 gtk_text_view_set_left_margin(GTK_TEXT_VIEW(text), 2);
3239 gtk_text_view_set_editable(GTK_TEXT_VIEW(text), FALSE);
3240 scenario_description = text;
3241
3242 sw = gtk_scrolled_window_new(NULL, NULL);
3243 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw),
3244 GTK_SHADOW_ETCHED_IN);
3245 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_AUTOMATIC,
3246 GTK_POLICY_AUTOMATIC);
3247 gtk_container_add(GTK_CONTAINER(sw), text);
3248
3249 text = gtk_text_view_new();
3250 gtk_widget_set_hexpand(text, TRUE);
3251 gtk_widget_set_vexpand(text, TRUE);
3252 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_WORD);
3253 gtk_text_view_set_left_margin(GTK_TEXT_VIEW(text), 2);
3254 gtk_text_view_set_editable(GTK_TEXT_VIEW(text), FALSE);
3255 scenario_authors = text;
3256
3257 swa = gtk_scrolled_window_new(NULL, NULL);
3258 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(swa),
3259 GTK_SHADOW_ETCHED_IN);
3260 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(swa), GTK_POLICY_AUTOMATIC,
3261 GTK_POLICY_AUTOMATIC);
3262 gtk_container_add(GTK_CONTAINER(swa), text);
3263
3264 text = gtk_label_new(_("Filename:"));
3265 scenario_filename = gtk_label_new("");
3266 gtk_widget_set_halign(scenario_filename, GTK_ALIGN_START);
3267 gtk_widget_set_valign(scenario_filename, GTK_ALIGN_CENTER);
3268 gtk_label_set_selectable(GTK_LABEL(scenario_filename), TRUE);
3269
3270 filenamebox = gtk_grid_new();
3271 gtk_grid_set_column_spacing(GTK_GRID(hbox), 12);
3272 g_object_set(filenamebox, "margin", 5, NULL);
3273
3274 gtk_container_add(GTK_CONTAINER(filenamebox), text);
3275 gtk_container_add(GTK_CONTAINER(filenamebox), scenario_filename);
3276
3277 /* TRANS: Scenario format version */
3278 vertext = gtk_label_new(_("Format:"));
3279 scenario_version = gtk_label_new("");
3280 gtk_widget_set_halign(scenario_version, GTK_ALIGN_START);
3281 gtk_widget_set_valign(scenario_version, GTK_ALIGN_CENTER);
3282 gtk_label_set_selectable(GTK_LABEL(scenario_version), TRUE);
3283
3284 versionbox = gtk_grid_new();
3285 gtk_grid_set_column_spacing(GTK_GRID(hbox), 12);
3286 g_object_set(versionbox, "margin", 5, NULL);
3287
3288 gtk_container_add(GTK_CONTAINER(versionbox), vertext);
3289 gtk_container_add(GTK_CONTAINER(versionbox), scenario_version);
3290
3291 descbox = gtk_grid_new();
3292 gtk_orientable_set_orientation(GTK_ORIENTABLE(descbox),
3293 GTK_ORIENTATION_VERTICAL);
3294 gtk_grid_set_row_spacing(GTK_GRID(descbox), 6);
3295 gtk_container_add(GTK_CONTAINER(descbox), sw);
3296 gtk_container_add(GTK_CONTAINER(descbox), swa);
3297 gtk_container_add(GTK_CONTAINER(descbox), filenamebox);
3298 gtk_container_add(GTK_CONTAINER(descbox), versionbox);
3299 gtk_grid_attach(GTK_GRID(sbox), descbox, 1, 0, 1, 2);
3300
3301 bbox = gtk_button_box_new(GTK_ORIENTATION_HORIZONTAL);
3302 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END);
3303 gtk_box_set_spacing(GTK_BOX(bbox), 12);
3304 gtk_container_add(GTK_CONTAINER(vbox), bbox);
3305
3306 button = gtk_button_new_with_mnemonic(_("_Browse..."));
3307 gtk_container_add(GTK_CONTAINER(bbox), button);
3308 gtk_button_box_set_child_secondary(GTK_BUTTON_BOX(bbox), button, TRUE);
3309 g_signal_connect(button, "clicked",
3310 G_CALLBACK(scenario_browse_callback), NULL);
3311
3312 button = gtk_button_new_from_stock(GTK_STOCK_CANCEL);
3313 gtk_container_add(GTK_CONTAINER(bbox), button);
3314 g_signal_connect(button, "clicked",
3315 G_CALLBACK(main_callback), NULL);
3316
3317 button = gtk_button_new_from_stock(GTK_STOCK_OK);
3318 gtk_container_add(GTK_CONTAINER(bbox), button);
3319 g_signal_connect(button, "clicked",
3320 G_CALLBACK(scenario_callback), NULL);
3321
3322 return vbox;
3323}
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:1254
client_is_global_observer
bool client_is_global_observer(void)
Definition client_main.c:1346
client_is_observer
bool client_is_observer(void)
Definition client_main.c:1086
user_name
char user_name[512]
Definition client_main.c:141
server_host
char server_host[512]
Definition client_main.c:140
client
struct civclient client
Definition client_main.c:149
client_state
enum client_states client_state(void)
Definition client_main.c:1029
fc_password
char fc_password[MAX_LEN_PASSWORD]
Definition client_main.c:142
server_port
int server_port
Definition client_main.c:144
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:1501
mapimg_client_createmap
bool mapimg_client_createmap(const char *filename)
Definition climisc.c:1448
center_on_something
void center_on_something(void)
Definition climisc.c:424
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:248
disconnect_from_server
void disconnect_from_server(void)
Definition clinet.c:305
clinet.h
send_save_game
void send_save_game(const char *filename)
Definition connectdlg_common.c:733
set_ruleset
void set_ruleset(const char *ruleset)
Definition connectdlg_common.c:774
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:473
conn_by_number
struct connection * conn_by_number(int id)
Definition connection.c:420
conn_list_iterate
#define conn_list_iterate(connlist, pconn)
Definition connection.h:113
conn_list_iterate_end
#define conn_list_iterate_end
Definition connection.h:115
dataio.h
popup_notify_dialog
popup_notify_dialog
Definition dialogs_g.h:36
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_allocate_mutex
void fc_allocate_mutex(fc_mutex *mutex)
fc_release_mutex
void fc_release_mutex(fc_mutex *mutex)
ftc_client
const struct ft_color ftc_client
Definition featured_text.c:78
game
struct civ_game game
Definition game.c:57
game.h
layout
static PangoLayout * layout
Definition canvas.c:331
inputline_toolkit_view_append_button
void inputline_toolkit_view_append_button(GtkWidget *toolkit_view, GtkWidget *button)
Definition chatline.c:1288
inputline_toolkit_view_new
GtkWidget * inputline_toolkit_view_new(void)
Definition chatline.c:1266
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:1223
pos
static struct tile * pos
Definition finddlg.c:53
client_string
const char * client_string
Definition gui_main.c:104
message_buffer
GtkTextBuffer * message_buffer
Definition gui_main.c:177
resolution_request_get
struct video_mode * resolution_request_get(void)
Definition gui_main.c:2395
enable_menus
void enable_menus(bool enable)
Definition gui_main.c:1000
refresh_chat_buttons
void refresh_chat_buttons(void)
Definition gui_main.c:2312
reset_unit_table
void reset_unit_table(void)
Definition gui_main.c:971
toplevel
GtkWidget * toplevel
Definition gui_main.c:124
quit_gtk_main
void quit_gtk_main(void)
Definition gui_main.c:2141
vmode
static struct video_mode vmode
Definition gui_main.c:187
toplevel_tabs
GtkWidget * toplevel_tabs
Definition gui_main.c:126
screen_height
int screen_height(void)
Definition gui_main.c:2375
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:230
gtk_stockbutton_set_label
void gtk_stockbutton_set_label(GtkWidget *button, const gchar *label_text)
Definition gui_stuff.c:90
gtk_stockbutton_new
GtkWidget * gtk_stockbutton_new(const gchar *stock, const gchar *label_text)
Definition gui_stuff.c:74
add_treeview_column
GtkTreeViewColumn * add_treeview_column(GtkWidget *view, const char *title, GType gtype, int model_index)
Definition gui_stuff.c:1120
setup_dialog
void setup_dialog(GtkWidget *shell, GtkWidget *parent)
Definition gui_stuff.c:281
mapview_freeze
void mapview_freeze(void)
Definition mapview.c:356
overview_size_changed
void overview_size_changed(void)
Definition mapview.c:309
mapview_thaw
void mapview_thaw(void)
Definition mapview.c:364
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:979
load_store
static GtkListStore * load_store
Definition pages.c:68
update_network_page
static void update_network_page(void)
Definition pages.c:1167
handle_game_load
void handle_game_load(bool load_successful, const char *filename)
Definition pages.c:2823
create_start_page
GtkWidget * create_start_page(void)
Definition pages.c:2605
create_network_page
GtkWidget * create_network_page(void)
Definition pages.c:1183
client_aitoggle_player
static void client_aitoggle_player(void *data)
Definition pages.c:1491
nation_button
static GtkWidget * nation_button
Definition pages.c:1442
update_server_list
static void update_server_list(enum server_scan_type sstype, const struct server_list *list)
Definition pages.c:687
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:2181
save_dialog_response_callback
static void save_dialog_response_callback(GtkWidget *w, gint response, gpointer data)
Definition pages.c:472
create_scenario_page
GtkWidget * create_scenario_page(void)
Definition pages.c:3168
show_conn_popup
static void show_conn_popup(struct player *pplayer, struct connection *pconn)
Definition pages.c:1748
network_confirm_password_label
static GtkWidget * network_confirm_password_label
Definition pages.c:682
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:1597
ready_button_callback
static void ready_button_callback(GtkWidget *w, gpointer data)
Definition pages.c:2127
conn_list_selection
static bool conn_list_selection(struct player **ppplayer, struct connection **ppconn)
Definition pages.c:2040
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:821
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:877
update_network_statusbar
static gboolean update_network_statusbar(gpointer data)
Definition pages.c:847
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:1707
load_filename
static void load_filename(const char *filename)
Definition pages.c:2838
conn_menu_nation_chosen
static void conn_menu_nation_chosen(GObject *object, gpointer data)
Definition pages.c:1694
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:842
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:540
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:1444
network_login
static GtkWidget * network_login
Definition pages.c:678
network_login_label
static GtkWidget * network_login_label
Definition pages.c:678
connection_state
connection_state
Definition pages.c:835
LOGIN_TYPE
@ LOGIN_TYPE
Definition pages.c:836
NEW_PASSWORD_TYPE
@ NEW_PASSWORD_TYPE
Definition pages.c:837
WAITING_TYPE
@ WAITING_TYPE
Definition pages.c:839
ENTER_PASSWORD_TYPE
@ ENTER_PASSWORD_TYPE
Definition pages.c:838
connect_callback
static void connect_callback(GtkWidget *w, gpointer data)
Definition pages.c:1026
scenario_browse_callback
static void scenario_browse_callback(GtkWidget *w, gpointer data)
Definition pages.c:3042
meta_store
static GtkListStore * meta_store
Definition pages.c:68
connection_list_columns
connection_list_columns
Definition pages.c:1450
CL_COL_STYLE
@ CL_COL_STYLE
Definition pages.c:1460
CL_COL_USER_NAME
@ CL_COL_USER_NAME
Definition pages.c:1452
CL_COL_READY_STATE
@ CL_COL_READY_STATE
Definition pages.c:1453
CL_COL_WEIGHT
@ CL_COL_WEIGHT
Definition pages.c:1461
CL_COL_PLAYER_NAME
@ CL_COL_PLAYER_NAME
Definition pages.c:1454
CL_COL_NATION
@ CL_COL_NATION
Definition pages.c:1457
CL_COL_CONN_ID
@ CL_COL_CONN_ID
Definition pages.c:1459
CL_COL_PLAYER_NUMBER
@ CL_COL_PLAYER_NUMBER
Definition pages.c:1451
CL_NUM_COLUMNS
@ CL_NUM_COLUMNS
Definition pages.c:1464
CL_COL_TEAM
@ CL_COL_TEAM
Definition pages.c:1458
CL_COL_COLOR
@ CL_COL_COLOR
Definition pages.c:1456
CL_COL_COLLAPSED
@ CL_COL_COLLAPSED
Definition pages.c:1462
CL_COL_FLAG
@ CL_COL_FLAG
Definition pages.c:1455
update_load_page
static void update_load_page(void)
Definition pages.c:2873
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:1445
ruleset_entry_changed
static void ruleset_entry_changed(GtkWidget *w, gpointer data)
Definition pages.c:1609
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:913
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:2161
conn_menu_ready_chosen
static void conn_menu_ready_chosen(GObject *object, gpointer data)
Definition pages.c:1681
server_scan_error
static void server_scan_error(struct server_scan *scan, const char *message)
Definition pages.c:808
load_callback
static void load_callback(void)
Definition pages.c:2846
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:1122
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:2141
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:1734
scenario_list_callback
static void scenario_list_callback(void)
Definition pages.c:2970
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:2863
network_activate_callback
static void network_activate_callback(GtkTreeView *view, GtkTreePath *arg1, GtkTreeViewColumn *arg2, gpointer data)
Definition pages.c:1081
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:981
real_conn_list_dialog_update
void real_conn_list_dialog_update(void *unused)
Definition pages.c:2326
connection_list_event
static gboolean connection_list_event(GtkWidget *widget, GdkEventButton *event, gpointer data)
Definition pages.c:1970
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:1443
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:751
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:774
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:1624
delayed_unselect_path
static gboolean delayed_unselect_path(gpointer data)
Definition pages.c:1954
conn_menu_player_take
static void conn_menu_player_take(GObject *object, gpointer data)
Definition pages.c:1721
conn_menu_info_chosen
static void conn_menu_info_chosen(GObject *object, gpointer data)
Definition pages.c:1779
model_get_player_iter
static bool model_get_player_iter(GtkTreeModel *model, GtkTreeIter *iter, GtkTreeIter *start, const struct player *pplayer)
Definition pages.c:2266
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:1571
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:682
client_take_player
static void client_take_player(struct player *pplayer)
Definition pages.c:1505
clear_network_statusbar
static void clear_network_statusbar(void)
Definition pages.c:863
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:521
connection_list_row_callback
static void connection_list_row_callback(GtkTreeView *tree_view, GtkTreeIter *iter, GtkTreePath *path, gpointer data)
Definition pages.c:2025
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:2886
ai_lvl_combobox
static GtkWidget * ai_lvl_combobox
Definition pages.c:1446
network_password_label
static GtkWidget * network_password_label
Definition pages.c:681
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:561
intro_free
static void intro_free(GtkWidget *w, gpointer *data)
Definition pages.c:219
network_password
static GtkWidget * network_password
Definition pages.c:681
network_host
static GtkWidget * network_host
Definition pages.c:679
handle_authentication_req
void handle_authentication_req(enum authentication_type type, const char *message)
Definition pages.c:990
connection_list_store_new
static GtkTreeStore * connection_list_store_new(void)
Definition pages.c:1470
send_new_aifill_to_server
static bool send_new_aifill_to_server
Definition pages.c:1623
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:680
add_tree_col
static void add_tree_col(GtkWidget *treeview, GType gtype, const char *title, int colnum, const char *key)
Definition pages.c:2571
save_dialog_entry_callback
static void save_dialog_entry_callback(GtkEntry *entry, gpointer data)
Definition pages.c:532
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:1656
scenario_callback
static void scenario_callback(void)
Definition pages.c:3026
start_options_table
static GtkWidget * start_options_table
Definition pages.c:1441
no_ruleset_callback
static bool no_ruleset_callback
Definition pages.c:1592
ai_fill_changed_by_server
void ai_fill_changed_by_server(int aifill)
Definition pages.c:1635
update_server_playerlist
static void update_server_playerlist(const struct server *pserver)
Definition pages.c:1093
observe_button
static GtkWidget * observe_button
Definition pages.c:1442
scenario_version
static GtkWidget * scenario_version
Definition pages.c:66
create_statusbar
GtkWidget * create_statusbar(void)
Definition pages.c:892
game_options_callback
static void game_options_callback(GtkWidget *w, gpointer data)
Definition pages.c:1563
scenario_store
static GtkListStore * scenario_store
Definition pages.c:68
network_host_label
static GtkWidget * network_host_label
Definition pages.c:679
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:2297
statusbar_queue
static GQueue * statusbar_queue
Definition pages.c:90
start_message_area
GtkWidget * start_message_area
Definition pages.c:1439
network_port_label
static GtkWidget * network_port_label
Definition pages.c:680
update_scenario_page
static void update_scenario_page(void)
Definition pages.c:3052
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:1664
create_conn_menu
static GtkWidget * create_conn_menu(struct player *pplayer, struct connection *pconn)
Definition pages.c:1793
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:1536
object_put
static void object_put(GObject *object, struct player *pplayer, struct connection *pconn)
Definition pages.c:1517
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:2076
ready_button
static GtkWidget * ready_button
Definition pages.c:1442
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:609
title
const char * title
Definition repodlgs.c:1313
type
GType type
Definition repodlgs.c:1312
get_sprite_dimensions
void get_sprite_dimensions(struct sprite *sprite, int *width, int *height)
Definition sprite.c:107
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)
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:758
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:168
can_conn_edit_players_nation
bool can_conn_edit_players_nation(const struct connection *pconn, const struct player *pplayer)
Definition nation.c:1186
NO_NATION_SELECTED
#define NO_NATION_SELECTED
Definition nation.h:29
server_optset
const struct option_set * server_optset
Definition options.c:4009
client_optset
const struct option_set * client_optset
Definition options.c:1255
option_int_get
int option_int_get(const struct option *poption)
Definition options.c:809
optset_option_by_name
struct option * optset_option_by_name(const struct option_set *poptset, const char *name)
Definition options.c:406
option_int_set
bool option_int_set(struct option *poption, int val)
Definition options.c:853
authentication_type
authentication_type
Definition packets.h:88
AUTH_NEWUSER_RETRY
@ AUTH_NEWUSER_RETRY
Definition packets.h:92
AUTH_NEWUSER_FIRST
@ AUTH_NEWUSER_FIRST
Definition packets.h:90
AUTH_LOGIN_RETRY
@ AUTH_LOGIN_RETRY
Definition packets.h:91
AUTH_LOGIN_FIRST
@ AUTH_LOGIN_FIRST
Definition packets.h:89
send_packet_authentication_reply
int send_packet_authentication_reply(struct connection *pc, const struct packet_authentication_reply *packet)
Definition packets_gen.c:2464
dsend_packet_save_scenario
int dsend_packet_save_scenario(struct connection *pc, const char *name)
Definition packets_gen.c:84064
dsend_packet_player_ready
int dsend_packet_player_ready(struct connection *pc, int player_no, bool is_ready)
Definition packets_gen.c:2969
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:1883
player_by_number
struct player * player_by_number(const int player_id)
Definition player.c:840
player_slot_count
int player_slot_count(void)
Definition player.c:411
player_number
int player_number(const struct player *pplayer)
Definition player.c:828
player_name
const char * player_name(const struct player *pplayer)
Definition player.c:886
player_has_flag
bool player_has_flag(const struct player *pplayer, enum plr_flag_id flag)
Definition player.c:1954
ai_level_cmd
#define ai_level_cmd(_level_)
Definition player.h:565
players_iterate_end
#define players_iterate_end
Definition player.h:535
players_iterate
#define players_iterate(_pplayer)
Definition player.h:530
is_ai
#define is_ai(plr)
Definition player.h:234
players_iterate_alive_end
#define players_iterate_alive_end
Definition player.h:545
is_human
#define is_human(plr)
Definition player.h:233
players_iterate_alive
#define players_iterate_alive(_pplayer)
Definition player.h:540
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:593
secfile_lookup_bool_default
bool secfile_lookup_bool_default(const struct section_file *secfile, bool def, const char *path,...)
Definition registry_ini.c:1837
secfile_lookup_int_default
int secfile_lookup_int_default(const struct section_file *secfile, int def, const char *path,...)
Definition registry_ini.c:1937
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:2142
server_scan_get_list
struct srv_list * server_scan_get_list(struct server_scan *scan)
Definition servers.c:855
server_scan_finish
void server_scan_finish(struct server_scan *scan)
Definition servers.c:868
server_scan_begin
struct server_scan * server_scan_begin(enum server_scan_type type, ServerScanErrorFunc error_func)
Definition servers.c:744
server_scan_get_type
enum server_scan_type server_scan_get_type(const struct server_scan *scan)
Definition servers.c:798
server_scan_poll
enum server_scan_status server_scan_poll(struct server_scan *scan)
Definition servers.c:821
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:183
get_scenario_dirs
const struct strvec * get_scenario_dirs(void)
Definition shared.c:971
get_save_dirs
const struct strvec * get_save_dirs(void)
Definition shared.c:934
skip_to_basename
char * skip_to_basename(char *filepath)
Definition shared.c:1748
fileinfolist_infix
struct fileinfo_list * fileinfolist_infix(const struct strvec *dirs, const char *infix, bool nodups)
Definition shared.c:1204
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
aifill
const char * aifill(int amount)
Definition srv_main.c:2395
action
Definition actions.h:379
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:20
connection
Definition connection.h:141
connection::playing
struct player * playing
Definition connection.h:156
connection::access_level
enum cmdlevel access_level
Definition connection.h:182
connection::username
char username[MAX_LEN_NAME]
Definition connection.h:169
connection::addr
char addr[MAX_LEN_ADDR]
Definition connection.h:170
connection::id
int id
Definition connection.h:142
connection::used
bool used
Definition connection.h:144
entry
Definition registry_ini.c:193
item
Definition climisc.h:80
message
Definition messagewin_common.h:29
option
Definition options.c:454
packet_authentication_reply
Definition packets_gen.h:67
packet_authentication_reply::password
char password[MAX_LEN_PASSWORD]
Definition packets_gen.h:68
packet_game_info::is_new_game
bool is_new_game
Definition packets_gen.h:186
player
Definition player.h:249
player::team
struct team * team
Definition player.h:261
player::is_ready
bool is_ready
Definition player.h:262
save_dialog
Definition pages.c:359
save_dialog::action
save_dialog_action_fn_t action
Definition pages.c:363
save_dialog::entry
GtkEntry * entry
Definition pages.c:362
save_dialog::tree_view
GtkTreeView * tree_view
Definition pages.c:361
save_dialog::shell
GtkDialog * shell
Definition pages.c:360
save_dialog::files
save_dialog_files_fn_t files
Definition pages.c:364
section_file
Definition section_file.h:36
server::players::host
char * host
Definition servers.h:43
server::players::name
char * name
Definition servers.h:41
server::players::nation
char * nation
Definition servers.h:44
server::players::type
char * type
Definition servers.h:42
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:83
server
Definition servers.h:29
server::players
struct server::players * players
server::nplayers
int nplayers
Definition servers.h:47
sprite
Definition sprite.h:22
sprite::surface
cairo_surface_t * surface
Definition sprite.h:23
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:459
video_mode
Definition options.h:45
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:969
cat_snprintf
int cat_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:995
fc_remove
int fc_remove(const char *filename)
Definition support.c:556
support.h
sz_strlcpy
#define sz_strlcpy(dest, src)
Definition support.h:161
TRUE
#define TRUE
Definition support.h:46
FALSE
#define FALSE
Definition support.h:47
sz_strlcat
#define sz_strlcat(dest, src)
Definition support.h:162
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:75
team_slots_iterate
#define team_slots_iterate(_tslot)
Definition team.h:70
tileset_main_intro_filename
const char * tileset_main_intro_filename(const struct tileset *t)
Definition tilespec.c:910
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