Freeciv-3.4
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 "executable.h"
24#include "fc_cmdline.h"
25#include "fciconv.h"
26#include "fcintl.h"
27#include "log.h"
28#include "mem.h"
29
30/* common */
31#include "version.h"
32
33/* modinst */
34#include "download.h"
35#include "mpcmdline.h"
36#include "mpdb.h"
37
38#include "modinst.h"
39
48
49struct fcmp_params fcmp = {
51 .inst_prefix = NULL,
52 .autoinstall = NULL
53};
54
56
58
59#define ML_COL_NAME 0
60#define ML_COL_VER 1
61#define ML_COL_INST 2
62#define ML_COL_TYPE 3
63#define ML_COL_SUBTYPE 4
64#define ML_COL_LIC 5
65#define ML_COL_URL 6
66
67#define ML_COL_COUNT 7
68
69#define ML_TYPE 7
70#define ML_NOTES 8
71#define ML_STORE_SIZE 9
72
73/**********************************************************************/
76static void modinst_quit(void)
77{
79}
80
81/**********************************************************************/
85static void quit_dialog_response(GtkWidget *dialog, gint response)
86{
88 if (response == GTK_RESPONSE_YES) {
90 }
91}
92
93/**********************************************************************/
96static void quit_dialog_destroyed(GtkWidget *dialog, void *data)
97{
99}
100
101/**********************************************************************/
105{
106 if (downloading) {
107 /* Download in progress. Confirm quit from user. */
108
109 if (quit_dialog == NULL) {
111 0,
114 _("Modpack installation in progress.\nAre you sure you want to quit?"));
115
118
119 g_signal_connect(quit_dialog, "response",
121 g_signal_connect(quit_dialog, "destroy",
123 }
124
126
127 } else {
128 /* User loses no work by quitting, so let's not annoy them
129 * with confirmation dialog. */
130 modinst_quit();
131 }
132
133 /* Stop emission of event. */
134 return TRUE;
135}
136
137/**********************************************************************/
140static void msg_callback(const char *msg)
141{
142 log_verbose("%s", msg);
144}
145
146/**********************************************************************/
149static void pbar_callback(int downloaded, int max)
150{
151 /* Control file already downloaded */
152 double fraction = (double) downloaded / (max);
153
155}
156
157struct msg_data {
158 char *msg;
159};
160
161/**********************************************************************/
165{
166 struct msg_data *data = (struct msg_data *)user_data;
167
168 msg_callback(data->msg);
169
170 FC_FREE(data->msg);
171 FC_FREE(data);
172
173 return G_SOURCE_REMOVE;
174}
175
176/**********************************************************************/
179static void msg_dl_thread(const char *msg)
180{
181 struct msg_data *data = fc_malloc(sizeof(*data));
182
183 data->msg = fc_strdup(msg);
184
186}
187
188struct pbar_data {
189 int current;
190 int max;
191};
192
193/**********************************************************************/
197{
198 struct pbar_data *data = (struct pbar_data *)user_data;
199
200 pbar_callback(data->current, data->max);
201
202 FC_FREE(data);
203
204 return G_SOURCE_REMOVE;
205}
206
207/**********************************************************************/
210static void pbar_dl_thread(int current, int max)
211{
212 struct pbar_data *data = fc_malloc(sizeof(*data));
213
214 data->current = current;
215 data->max = max;
216
218}
219
220/**********************************************************************/
224{
226
228 do {
229 const char *name_str;
230 int type_int;
231 const char *new_inst;
232 enum modpack_type type;
233
236 ML_TYPE, &type_int,
237 -1);
238
239 type = type_int;
240
242
243 if (new_inst == NULL) {
244 new_inst = _("Not installed");
245 }
246
249 -1);
250
252 }
253
254 return G_SOURCE_REMOVE;
255}
256
257/**********************************************************************/
264
265/**********************************************************************/
269{
270 const char *errmsg;
271
273
274 if (errmsg == NULL) {
275 msg_dl_thread(_("Ready"));
276 } else {
278 }
279
280 free(data);
281
283
285
286 return NULL;
287}
288
289/**********************************************************************/
292static void gui_download_modpack(const char *URL)
293{
295 char *URLbuf;
296
297 if (downloading) {
299 _("Another download already active"));
300 return;
301 }
302
304
305 URLbuf = fc_malloc(strlen(URL) + 1);
306
307 strcpy(URLbuf, URL);
308
310 if (downloader == NULL) {
312 _("Failed to start downloader"));
313 free(URLbuf);
314 } else {
316 }
317}
318
319/**********************************************************************/
322static void install_clicked(GtkWidget *w, gpointer data)
323{
324 GtkEntry *URL_in = data;
326 const char *URL = gtk_entry_buffer_get_text(buffer);
327
329}
330
331/**********************************************************************/
334static void URL_return(GtkEntry *w, gpointer data)
335{
336 const char *URL;
338
339 URL = gtk_entry_buffer_get_text(buffer);
341}
342
343/**********************************************************************/
347 gint x, gint y,
350 gpointer data)
351{
353 GtkTreeView *tree_view = GTK_TREE_VIEW(widget);
354 GtkTreeModel *model;
355 const char *notes;
356
357 if (!gtk_tree_view_get_tooltip_context(tree_view, x, y,
359 &model, NULL, &iter)) {
360 return FALSE;
361 }
362
363 gtk_tree_model_get(model, &iter,
364 ML_NOTES, &notes,
365 -1);
366
367 if (notes != NULL) {
369
370 return TRUE;
371 }
372
373 return FALSE;
374}
375
376/**********************************************************************/
379static void setup_modpack_list(const char *name, const char *URL,
380 const char *version, const char *license,
381 enum modpack_type type, const char *subtype,
382 const char *notes)
383{
385 const char *type_str;
386 const char *lic_str;
387 const char *inst_str;
388
391 } else {
392 /* TRANS: Unknown modpack type */
393 type_str = _("?");
394 }
395
396 if (license != NULL) {
398 } else {
399 /* TRANS: License of modpack is not known */
400 lic_str = Q_("?license:Unknown");
401 }
402
404 if (inst_str == NULL) {
405 inst_str = _("Not installed");
406 }
407
411 ML_COL_VER, version,
414 ML_COL_SUBTYPE, subtype,
416 ML_COL_URL, URL,
417 ML_TYPE, type,
418 ML_NOTES, notes,
419 -1);
420}
421
422/**********************************************************************/
426{
427 GtkTreeModel *model;
428 GtkTreeIter it;
429 const char *URL;
430 GtkEntryBuffer *buffer;
431
432 if (!gtk_tree_selection_get_selected(select, &model, &it)) {
433 return;
434 }
435
436 gtk_tree_model_get(model, &it, ML_COL_URL, &URL, -1);
437
439 gtk_entry_buffer_set_text(buffer, URL, -1);
440}
441
442/**********************************************************************/
445static void modinst_setup_widgets(void)
446{
448 GtkWidget *version_label;
451 GtkCellRenderer *renderer;
452 GtkTreeSelection *selection;
453 const char *errmsg;
454 char verbuf[2048];
455 const char *rev_ver;
456
457 mbox = gtk_grid_new();
461
463
464 if (rev_ver == NULL) {
466 } else {
467 fc_snprintf(verbuf, sizeof(verbuf), _("%s%s\ncommit: %s"),
469 }
470
471 version_label = gtk_label_new(verbuf);
472
474 renderer = gtk_cell_renderer_text_new();
477 _("Name"), renderer, "text", 0,
478 NULL);
479 renderer = gtk_cell_renderer_text_new();
482 _("Version"), renderer, "text", 1,
483 NULL);
484 renderer = gtk_cell_renderer_text_new();
487 _("Installed"), renderer, "text", 2,
488 NULL);
489 renderer = gtk_cell_renderer_text_new();
492 Q_("?modpack:Type"),
493 renderer, "text", 3,
494 NULL);
495 renderer = gtk_cell_renderer_text_new();
498 _("Subtype"),
499 renderer, "text", 4,
500 NULL);
501 renderer = gtk_cell_renderer_text_new();
504 /* TRANS: noun */
505 _("License"), renderer, "text", 5,
506 NULL);
507 renderer = gtk_cell_renderer_text_new();
510 _("URL"), renderer, "text", 6,
511 NULL);
513 g_signal_connect(selection, "changed", G_CALLBACK(select_from_list), NULL);
514
516 gtk_button_set_label(GTK_BUTTON(install_button), _("Install modpack"));
517
518 Ubox = gtk_grid_new();
521 URL_label = gtk_label_new_with_mnemonic(_("Modpack URL"));
522
526 g_signal_connect(URL_input, "activate",
528
531
532 gtk_grid_attach(GTK_GRID(Ubox), URL_label, 0, 0, 1, 1);
533 gtk_grid_attach(GTK_GRID(Ubox), URL_input, 0, 1, 1, 1);
534
536
537 statusbar = gtk_label_new(_("Select modpack to install"));
538
541
542 gtk_grid_attach(GTK_GRID(mbox), version_label, 0, 0, 1, 1);
543 gtk_grid_attach(GTK_GRID(mbox), main_list, 0, 1, 1, 1);
544 gtk_grid_attach(GTK_GRID(mbox), Ubox, 0, 2, 1, 1);
547 gtk_grid_attach(GTK_GRID(mbox), statusbar, 0, 5, 1, 1);
548
550
557
558 g_object_set(main_list, "has-tooltip", TRUE, NULL);
559 g_signal_connect(main_list, "query-tooltip",
561
563
564 if (errmsg != NULL) {
566 }
567}
568
569/**********************************************************************/
573{
575
577
579 gtk_widget_set_name(toplevel, "Freeciv-modpack");
581 _("Freeciv modpack installer (gtk4)"));
582
583#if 0
584 /* Keep the icon of the executable on Windows */
585#ifndef FREECIV_MSWINDOWS
586 {
587 /* Unlike main client, this only works if installed. Ignore any
588 * errors loading the icon. */
589 GError *err;
590
592 &err);
593 }
594#endif /* FREECIV_MSWINDOWS */
595#endif /* 0 */
596
597 g_signal_connect(toplevel, "close_request",
599
601
603
604 if (fcmp.autoinstall != NULL) {
606 }
607}
608
609/**********************************************************************/
612int main(int argc, char *argv[])
613{
614 int ui_options;
615
617
618 fcmp_init();
619
620 /* This modifies argv! */
622
623 if (ui_options != -1) {
624 int i;
625
626 for (i = 1; i <= ui_options; i++) {
627 if (is_option("--help", argv[i])) {
628 /* TRANS: No full stop after the URL, could cause confusion. */
629 fc_fprintf(stderr, _("Report bugs at %s\n"), BUG_URL);
630
631 ui_options = -1;
632 }
633 }
634 }
635
636 if (ui_options != -1) {
638
639 if (gtk_init_check()) {
643
645 } else {
646 log_fatal(_("Failed to open graphical mode."));
647 }
648
649 close_mpdbs();
650 }
651
652 fcmp_deinit();
654
655 return EXIT_SUCCESS;
656}
char * incite_cost
Definition comments.c:76
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
void executable_init(void)
Definition executable.c:34
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:110
#define log_fatal(message,...)
Definition log.h:101
#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:63
static void quit_dialog_response(GtkWidget *dialog, gint response)
Definition mpgui_gtk4.c:85
static void msg_dl_thread(const char *msg)
Definition mpgui_gtk4.c:179
#define ML_TYPE
Definition mpgui_gtk4.c:69
int main(int argc, char *argv[])
Definition mpgui_gtk4.c:612
#define ML_NOTES
Definition mpgui_gtk4.c:70
static gboolean quit_dialog_callback(void)
Definition mpgui_gtk4.c:104
static GtkWidget * statusbar
Definition mpgui_gtk4.c:41
static gboolean query_main_list_tooltip_cb(GtkWidget *widget, gint x, gint y, gboolean keyboard_tip, GtkTooltip *tooltip, gpointer data)
Definition mpgui_gtk4.c:346
static void quit_dialog_destroyed(GtkWidget *dialog, void *data)
Definition mpgui_gtk4.c:96
static void select_from_list(GtkTreeSelection *select, gpointer data)
Definition mpgui_gtk4.c:425
#define ML_STORE_SIZE
Definition mpgui_gtk4.c:71
static GtkListStore * main_store
Definition mpgui_gtk4.c:44
static gboolean versionlist_update_main_thread(gpointer user_data)
Definition mpgui_gtk4.c:223
static void activate_gui(GtkApplication *app, gpointer data)
Definition mpgui_gtk4.c:572
#define ML_COL_NAME
Definition mpgui_gtk4.c:59
static GtkWidget * toplevel
Definition mpgui_gtk4.c:40
static void modinst_quit(void)
Definition mpgui_gtk4.c:76
#define ML_COL_LIC
Definition mpgui_gtk4.c:64
static void pbar_callback(int downloaded, int max)
Definition mpgui_gtk4.c:149
static void URL_return(GtkEntry *w, gpointer data)
Definition mpgui_gtk4.c:334
static GtkWidget * quit_dialog
Definition mpgui_gtk4.c:46
static GtkWidget * URL_input
Definition mpgui_gtk4.c:45
struct fcmp_params fcmp
Definition mpgui_gtk4.c:49
static gboolean downloading
Definition mpgui_gtk4.c:47
static GtkWidget * progressbar
Definition mpgui_gtk4.c:42
static void gui_download_modpack(const char *URL)
Definition mpgui_gtk4.c:292
static gboolean msg_main_thread(gpointer user_data)
Definition mpgui_gtk4.c:164
static void install_clicked(GtkWidget *w, gpointer data)
Definition mpgui_gtk4.c:322
#define ML_COL_TYPE
Definition mpgui_gtk4.c:62
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:379
static GtkApplication * fcmp_app
Definition mpgui_gtk4.c:55
static void pbar_dl_thread(int current, int max)
Definition mpgui_gtk4.c:210
static void msg_callback(const char *msg)
Definition mpgui_gtk4.c:140
#define ML_COL_INST
Definition mpgui_gtk4.c:61
static GtkWidget * main_list
Definition mpgui_gtk4.c:43
static void modinst_setup_widgets(void)
Definition mpgui_gtk4.c:445
static void versionlist_update_dl_thread(void)
Definition mpgui_gtk4.c:260
#define ML_COL_URL
Definition mpgui_gtk4.c:65
static gboolean pbar_main_thread(gpointer user_data)
Definition mpgui_gtk4.c:196
#define ML_COL_VER
Definition mpgui_gtk4.c:60
static gpointer download_thread(gpointer data)
Definition mpgui_gtk4.c:268
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:146
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:960
#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
#define VERSION_STRING
Definition version_gen.h:14