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

Freeciv-3.3

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