Freeciv-3.2
Loading...
Searching...
No Matches
mpgui_gtk4.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 <stdlib.h>
19
20#include <gtk/gtk.h>
21
22/* utility */
23#include "fc_cmdline.h"
24#include "fciconv.h"
25#include "fcintl.h"
26#include "log.h"
27#include "mem.h"
28
29/* common */
30#include "version.h"
31
32/* modinst */
33#include "download.h"
34#include "mpcmdline.h"
35#include "mpdb.h"
36
37#include "modinst.h"
38
47
48struct fcmp_params fcmp = {
50 .inst_prefix = NULL,
51 .autoinstall = NULL
52};
53
55
57
58#define ML_COL_NAME 0
59#define ML_COL_VER 1
60#define ML_COL_INST 2
61#define ML_COL_TYPE 3
62#define ML_COL_SUBTYPE 4
63#define ML_COL_LIC 5
64#define ML_COL_URL 6
65
66#define ML_COL_COUNT 7
67
68#define ML_TYPE 7
69#define ML_NOTES 8
70#define ML_STORE_SIZE 9
71
72/**********************************************************************/
75static void modinst_quit(void)
76{
78}
79
80/**********************************************************************/
84static void quit_dialog_response(GtkWidget *dialog, gint response)
85{
87 if (response == GTK_RESPONSE_YES) {
89 }
90}
91
92/**********************************************************************/
95static void quit_dialog_destroyed(GtkWidget *dialog, void *data)
96{
98}
99
100/**********************************************************************/
104{
105 if (downloading) {
106 /* Download in progress. Confirm quit from user. */
107
108 if (quit_dialog == NULL) {
110 0,
113 _("Modpack installation in progress.\nAre you sure you want to quit?"));
114
117
118 g_signal_connect(quit_dialog, "response",
120 g_signal_connect(quit_dialog, "destroy",
122 }
123
125
126 } else {
127 /* User loses no work by quitting, so let's not annoy them
128 * with confirmation dialog. */
129 modinst_quit();
130 }
131
132 /* Stop emission of event. */
133 return TRUE;
134}
135
136/**********************************************************************/
139static void msg_callback(const char *msg)
140{
141 log_verbose("%s", msg);
143}
144
145/**********************************************************************/
148static void pbar_callback(int downloaded, int max)
149{
150 /* Control file already downloaded */
151 double fraction = (double) downloaded / (max);
152
154}
155
156struct msg_data {
157 char *msg;
158};
159
160/**********************************************************************/
164{
165 struct msg_data *data = (struct msg_data *)user_data;
166
167 msg_callback(data->msg);
168
169 FC_FREE(data->msg);
170 FC_FREE(data);
171
172 return G_SOURCE_REMOVE;
173}
174
175/**********************************************************************/
178static void msg_dl_thread(const char *msg)
179{
180 struct msg_data *data = fc_malloc(sizeof(*data));
181
182 data->msg = fc_strdup(msg);
183
185}
186
187struct pbar_data {
188 int current;
189 int max;
190};
191
192/**********************************************************************/
196{
197 struct pbar_data *data = (struct pbar_data *)user_data;
198
199 pbar_callback(data->current, data->max);
200
201 FC_FREE(data);
202
203 return G_SOURCE_REMOVE;
204}
205
206/**********************************************************************/
209static void pbar_dl_thread(int current, int max)
210{
211 struct pbar_data *data = fc_malloc(sizeof(*data));
212
213 data->current = current;
214 data->max = max;
215
217}
218
219/**********************************************************************/
223{
225
227 do {
228 const char *name_str;
229 int type_int;
230 const char *new_inst;
231 enum modpack_type type;
232
236 -1);
237
238 type = type_int;
239
241
242 if (new_inst == NULL) {
243 new_inst = _("Not installed");
244 }
245
248 -1);
249
251 }
252
253 return G_SOURCE_REMOVE;
254}
255
256/**********************************************************************/
263
264/**********************************************************************/
268{
269 const char *errmsg;
270
272
273 if (errmsg == NULL) {
274 msg_dl_thread(_("Ready"));
275 } else {
277 }
278
279 free(data);
280
282
284
285 return NULL;
286}
287
288/**********************************************************************/
291static void gui_download_modpack(const char *URL)
292{
294 char *URLbuf;
295
296 if (downloading) {
298 _("Another download already active"));
299 return;
300 }
301
303
304 URLbuf = fc_malloc(strlen(URL) + 1);
305
306 strcpy(URLbuf, URL);
307
309 if (downloader == NULL) {
311 _("Failed to start downloader"));
312 free(URLbuf);
313 } else {
315 }
316}
317
318/**********************************************************************/
321static void install_clicked(GtkWidget *w, gpointer data)
322{
323 GtkEntry *URL_in = data;
325 const char *URL = gtk_entry_buffer_get_text(buffer);
326
328}
329
330/**********************************************************************/
333static void URL_return(GtkEntry *w, gpointer data)
334{
335 const char *URL;
337
338 URL = gtk_entry_buffer_get_text(buffer);
340}
341
342/**********************************************************************/
346 gint x, gint y,
349 gpointer data)
350{
352 GtkTreeView *tree_view = GTK_TREE_VIEW(widget);
353 GtkTreeModel *model;
354 const char *notes;
355
356 if (!gtk_tree_view_get_tooltip_context(tree_view, x, y,
358 &model, NULL, &iter)) {
359 return FALSE;
360 }
361
362 gtk_tree_model_get(model, &iter,
363 ML_NOTES, &notes,
364 -1);
365
366 if (notes != NULL) {
368
369 return TRUE;
370 }
371
372 return FALSE;
373}
374
375/**********************************************************************/
378static void setup_modpack_list(const char *name, const char *URL,
379 const char *version, const char *license,
380 enum modpack_type type, const char *subtype,
381 const char *notes)
382{
384 const char *type_str;
385 const char *lic_str;
386 const char *inst_str;
387
390 } else {
391 /* TRANS: Unknown modpack type */
392 type_str = _("?");
393 }
394
395 if (license != NULL) {
397 } else {
398 /* TRANS: License of modpack is not known */
399 lic_str = Q_("?license:Unknown");
400 }
401
403 if (inst_str == NULL) {
404 inst_str = _("Not installed");
405 }
406
410 ML_COL_VER, version,
415 ML_COL_URL, URL,
416 ML_TYPE, type,
418 -1);
419}
420
421/**********************************************************************/
425{
426 GtkTreeModel *model;
427 GtkTreeIter it;
428 const char *URL;
429 GtkEntryBuffer *buffer;
430
431 if (!gtk_tree_selection_get_selected(select, &model, &it)) {
432 return;
433 }
434
435 gtk_tree_model_get(model, &it, ML_COL_URL, &URL, -1);
436
438 gtk_entry_buffer_set_text(buffer, URL, -1);
439}
440
441/**********************************************************************/
444static void modinst_setup_widgets(void)
445{
447 GtkWidget *version_label;
450 GtkCellRenderer *renderer;
451 GtkTreeSelection *selection;
452 const char *errmsg;
453 char verbuf[2048];
454 const char *rev_ver;
455
456 mbox = gtk_grid_new();
460
462
463 if (rev_ver == NULL) {
465 } else {
466 fc_snprintf(verbuf, sizeof(verbuf), _("%s%s\ncommit: %s"),
468 }
469
470 version_label = gtk_label_new(verbuf);
471
473 renderer = gtk_cell_renderer_text_new();
476 _("Name"), renderer, "text", 0,
477 NULL);
478 renderer = gtk_cell_renderer_text_new();
481 _("Version"), renderer, "text", 1,
482 NULL);
483 renderer = gtk_cell_renderer_text_new();
486 _("Installed"), renderer, "text", 2,
487 NULL);
488 renderer = gtk_cell_renderer_text_new();
491 Q_("?modpack:Type"),
492 renderer, "text", 3,
493 NULL);
494 renderer = gtk_cell_renderer_text_new();
497 _("Subtype"),
498 renderer, "text", 4,
499 NULL);
500 renderer = gtk_cell_renderer_text_new();
503 /* TRANS: noun */
504 _("License"), renderer, "text", 5,
505 NULL);
506 renderer = gtk_cell_renderer_text_new();
509 _("URL"), renderer, "text", 6,
510 NULL);
512 g_signal_connect(selection, "changed", G_CALLBACK(select_from_list), NULL);
513
515 gtk_button_set_label(GTK_BUTTON(install_button), _("Install modpack"));
516
517 Ubox = gtk_grid_new();
520 URL_label = gtk_label_new_with_mnemonic(_("Modpack URL"));
521
525 g_signal_connect(URL_input, "activate",
527
530
531 gtk_grid_attach(GTK_GRID(Ubox), URL_label, 0, 0, 1, 1);
532 gtk_grid_attach(GTK_GRID(Ubox), URL_input, 0, 1, 1, 1);
533
535
536 statusbar = gtk_label_new(_("Select modpack to install"));
537
540
541 gtk_grid_attach(GTK_GRID(mbox), version_label, 0, 0, 1, 1);
542 gtk_grid_attach(GTK_GRID(mbox), main_list, 0, 1, 1, 1);
543 gtk_grid_attach(GTK_GRID(mbox), Ubox, 0, 2, 1, 1);
546 gtk_grid_attach(GTK_GRID(mbox), statusbar, 0, 5, 1, 1);
547
549
556
557 g_object_set(main_list, "has-tooltip", TRUE, NULL);
558 g_signal_connect(main_list, "query-tooltip",
560
562
563 if (errmsg != NULL) {
565 }
566}
567
568/**********************************************************************/
572{
574
576
578 gtk_widget_set_name(toplevel, "Freeciv-modpack");
580 _("Freeciv modpack installer (gtk4)"));
581
582#if 0
583 /* Keep the icon of the executable on Windows */
584#ifndef FREECIV_MSWINDOWS
585 {
586 /* Unlike main client, this only works if installed. Ignore any
587 * errors loading the icon. */
588 GError *err;
589
591 &err);
592 }
593#endif /* FREECIV_MSWINDOWS */
594#endif /* 0 */
595
596 g_signal_connect(toplevel, "close_request",
598
600
602
603 if (fcmp.autoinstall != NULL) {
605 }
606}
607
608/**********************************************************************/
611int main(int argc, char *argv[])
612{
613 int ui_options;
614
615 fcmp_init();
616
617 /* This modifies argv! */
619
620 if (ui_options != -1) {
621 int i;
622
623 for (i = 1; i <= ui_options; i++) {
624 if (is_option("--help", argv[i])) {
625 /* TRANS: No full stop after the URL, could cause confusion. */
626 fc_fprintf(stderr, _("Report bugs at %s\n"), BUG_URL);
627
628 ui_options = -1;
629 }
630 }
631 }
632
633 if (ui_options != -1) {
635
636 if (gtk_init_check()) {
640
642 } else {
643 log_fatal(_("Failed to open graphical mode."));
644 }
645
646 close_mpdbs();
647 }
648
649 fcmp_deinit();
651
652 return EXIT_SUCCESS;
653}
char * incite_cost
Definition comments.c:75
const char * download_modpack(const char *URL, const struct fcmp_params *fcmp, dl_msg_callback mcb, dl_pb_callback pbcb)
Definition download.c:66
const char * download_modpack_list(const struct fcmp_params *fcmp, modpack_list_setup_cb cb, dl_msg_callback mcb)
Definition download.c:427
bool is_option(const char *option_name, char *option)
Definition fc_cmdline.c:112
void cmdline_option_values_free(void)
Definition fc_cmdline.c:97
void fc_fprintf(FILE *stream, const char *format,...) fc__attribute((__format__(__printf__
#define Q_(String)
Definition fcintl.h:70
#define _(String)
Definition fcintl.h:67
const char * tooltip
Definition repodlgs.c:1315
GType type
Definition repodlgs.c:1313
const char * name
Definition inputfile.c:127
#define log_verbose(message,...)
Definition log.h:109
#define log_fatal(message,...)
Definition log.h:100
#define FC_FREE(ptr)
Definition mem.h:41
#define fc_strdup(str)
Definition mem.h:43
#define fc_malloc(sz)
Definition mem.h:34
void load_install_info_lists(struct fcmp_params *fcmp)
Definition modinst.c:44
void fcmp_deinit(void)
Definition modinst.c:98
void fcmp_init(void)
Definition modinst.c:82
#define DEFAULT_URL_START
Definition modinst.h:32
#define MODPACK_LIST_URL
Definition modinst.h:30
int fcmp_parse_cmdline(int argc, char *argv[])
Definition mpcmdline.c:45
const char * mpdb_installed_version(const char *name, enum modpack_type type)
Definition mpdb.c:253
void close_mpdbs(void)
Definition mpdb.c:202
#define ML_COL_SUBTYPE
Definition mpgui_gtk4.c:62
static void quit_dialog_response(GtkWidget *dialog, gint response)
Definition mpgui_gtk4.c:84
static void msg_dl_thread(const char *msg)
Definition mpgui_gtk4.c:178
#define ML_TYPE
Definition mpgui_gtk4.c:68
int main(int argc, char *argv[])
Definition mpgui_gtk4.c:611
#define ML_NOTES
Definition mpgui_gtk4.c:69
static gboolean quit_dialog_callback(void)
Definition mpgui_gtk4.c:103
static GtkWidget * statusbar
Definition mpgui_gtk4.c:40
static gboolean query_main_list_tooltip_cb(GtkWidget *widget, gint x, gint y, gboolean keyboard_tip, GtkTooltip *tooltip, gpointer data)
Definition mpgui_gtk4.c:345
static void quit_dialog_destroyed(GtkWidget *dialog, void *data)
Definition mpgui_gtk4.c:95
static void select_from_list(GtkTreeSelection *select, gpointer data)
Definition mpgui_gtk4.c:424
#define ML_STORE_SIZE
Definition mpgui_gtk4.c:70
static GtkListStore * main_store
Definition mpgui_gtk4.c:43
static gboolean versionlist_update_main_thread(gpointer user_data)
Definition mpgui_gtk4.c:222
static void activate_gui(GtkApplication *app, gpointer data)
Definition mpgui_gtk4.c:571
#define ML_COL_NAME
Definition mpgui_gtk4.c:58
static GtkWidget * toplevel
Definition mpgui_gtk4.c:39
static void modinst_quit(void)
Definition mpgui_gtk4.c:75
#define ML_COL_LIC
Definition mpgui_gtk4.c:63
static void pbar_callback(int downloaded, int max)
Definition mpgui_gtk4.c:148
static void URL_return(GtkEntry *w, gpointer data)
Definition mpgui_gtk4.c:333
static GtkWidget * quit_dialog
Definition mpgui_gtk4.c:45
static GtkWidget * URL_input
Definition mpgui_gtk4.c:44
struct fcmp_params fcmp
Definition mpgui_gtk4.c:48
static gboolean downloading
Definition mpgui_gtk4.c:46
static GtkWidget * progressbar
Definition mpgui_gtk4.c:41
static void gui_download_modpack(const char *URL)
Definition mpgui_gtk4.c:291
static gboolean msg_main_thread(gpointer user_data)
Definition mpgui_gtk4.c:163
static void install_clicked(GtkWidget *w, gpointer data)
Definition mpgui_gtk4.c:321
#define ML_COL_TYPE
Definition mpgui_gtk4.c:61
static void setup_modpack_list(const char *name, const char *URL, const char *version, const char *license, enum modpack_type type, const char *subtype, const char *notes)
Definition mpgui_gtk4.c:378
static GtkApplication * fcmp_app
Definition mpgui_gtk4.c:54
static void pbar_dl_thread(int current, int max)
Definition mpgui_gtk4.c:209
static void msg_callback(const char *msg)
Definition mpgui_gtk4.c:139
#define ML_COL_INST
Definition mpgui_gtk4.c:60
static GtkWidget * main_list
Definition mpgui_gtk4.c:42
static void modinst_setup_widgets(void)
Definition mpgui_gtk4.c:444
static void versionlist_update_dl_thread(void)
Definition mpgui_gtk4.c:259
#define ML_COL_URL
Definition mpgui_gtk4.c:64
static gboolean pbar_main_thread(gpointer user_data)
Definition mpgui_gtk4.c:195
#define ML_COL_VER
Definition mpgui_gtk4.c:59
static gpointer download_thread(gpointer data)
Definition mpgui_gtk4.c:267
struct sprite int int y
Definition sprite_g.h:31
struct sprite int x
Definition sprite_g.h:31
const char * list_url
Definition modinst.h:18
const char * autoinstall
Definition modinst.h:20
char * msg
Definition mpgui_gtk3.c:145
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:974
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
const char * fc_git_revision(void)
Definition version.c:75
const char * word_version(void)
Definition version.c:62