Freeciv-3.4
Loading...
Searching...
No Matches
mpgui_gtk3.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
46
47struct fcmp_params fcmp = {
49 .inst_prefix = NULL,
50 .autoinstall = NULL
51};
52
54
55#define ML_COL_NAME 0
56#define ML_COL_VER 1
57#define ML_COL_INST 2
58#define ML_COL_TYPE 3
59#define ML_COL_SUBTYPE 4
60#define ML_COL_LIC 5
61#define ML_COL_URL 6
62
63#define ML_COL_COUNT 7
64
65#define ML_TYPE 7
66#define ML_NOTES 8
67#define ML_STORE_SIZE 9
68
69/**********************************************************************/
72static void modinst_quit(void)
73{
75}
76
77/**********************************************************************/
81static void quit_dialog_response(GtkWidget *dialog, gint response)
82{
83 gtk_widget_destroy(dialog);
84 if (response == GTK_RESPONSE_YES) {
86 }
87}
88
89/**********************************************************************/
93{
94 if (downloading) {
95 /* Download in progress. Confirm quit from user. */
96 static GtkWidget *dialog;
97
98 if (!dialog) {
100 0,
103 _("Modpack installation in progress.\nAre you sure you want to quit?"));
104
106
107 g_signal_connect(dialog, "response",
109 g_signal_connect(dialog, "destroy",
111 }
112
114
115 } else {
116 /* User loses no work by quitting, so let's not annoy them
117 * with confirmation dialog. */
118 modinst_quit();
119 }
120
121 /* Stop emission of event. */
122 return TRUE;
123}
124
125/**********************************************************************/
128static void msg_callback(const char *msg)
129{
130 log_verbose("%s", msg);
132}
133
134/**********************************************************************/
137static void pbar_callback(int downloaded, int max)
138{
139 /* Control file already downloaded */
140 double fraction = (double) downloaded / (max);
141
143}
144
145struct msg_data {
146 char *msg;
147};
148
149/**********************************************************************/
153{
154 struct msg_data *data = (struct msg_data *)user_data;
155
156 msg_callback(data->msg);
157
158 FC_FREE(data->msg);
159 FC_FREE(data);
160
161 return G_SOURCE_REMOVE;
162}
163
164/**********************************************************************/
167static void msg_dl_thread(const char *msg)
168{
169 struct msg_data *data = fc_malloc(sizeof(*data));
170
171 data->msg = fc_strdup(msg);
172
174}
175
176struct pbar_data {
178 int max;
179};
180
181/**********************************************************************/
185{
186 struct pbar_data *data = (struct pbar_data *)user_data;
187
188 pbar_callback(data->current, data->max);
189
190 FC_FREE(data);
191
192 return G_SOURCE_REMOVE;
193}
194
195/**********************************************************************/
198static void pbar_dl_thread(int current, int max)
199{
200 struct pbar_data *data = fc_malloc(sizeof(*data));
201
202 data->current = current;
203 data->max = max;
204
206}
207
208/**********************************************************************/
212{
214
216 do {
217 const char *name_str;
218 int type_int;
219 const char *new_inst;
220 enum modpack_type type;
221
224 ML_TYPE, &type_int,
225 -1);
226
227 type = type_int;
228
230
231 if (new_inst == NULL) {
232 new_inst = _("Not installed");
233 }
234
237 -1);
238
240 }
241
242 return G_SOURCE_REMOVE;
243}
244
245/**********************************************************************/
252
253/**********************************************************************/
257{
258 const char *errmsg;
259
261
262 if (errmsg == NULL) {
263 msg_dl_thread(_("Ready"));
264 } else {
266 }
267
268 free(data);
269
271
273
274 return NULL;
275}
276
277/**********************************************************************/
280static void gui_download_modpack(const char *URL)
281{
283 char *URLbuf;
284
285 if (downloading) {
287 _("Another download already active"));
288 return;
289 }
290
292
293 URLbuf = fc_malloc(strlen(URL) + 1);
294
295 strcpy(URLbuf, URL);
296
298 if (downloader == NULL) {
300 _("Failed to start downloader"));
301 free(URLbuf);
302 } else {
304 }
305}
306
307/**********************************************************************/
310static void install_clicked(GtkWidget *w, gpointer data)
311{
312 GtkEntry *URL_in = data;
313 const char *URL = gtk_entry_get_text(URL_in);
314
316}
317
318/**********************************************************************/
321static void URL_return(GtkEntry *w, gpointer data)
322{
323 const char *URL;
324
325 URL = gtk_entry_get_text(w);
327}
328
329/**********************************************************************/
333 gint x, gint y,
336 gpointer data)
337{
339 GtkTreeView *tree_view = GTK_TREE_VIEW(widget);
340 GtkTreeModel *model;
341 const char *notes;
342
343 if (!gtk_tree_view_get_tooltip_context(tree_view, &x, &y,
345 &model, NULL, &iter)) {
346 return FALSE;
347 }
348
349 gtk_tree_model_get(model, &iter,
350 ML_NOTES, &notes,
351 -1);
352
353 if (notes != NULL) {
355
356 return TRUE;
357 }
358
359 return FALSE;
360}
361
362/**********************************************************************/
365static void setup_modpack_list(const char *name, const char *URL,
366 const char *version, const char *license,
367 enum modpack_type type, const char *subtype,
368 const char *notes)
369{
371 const char *type_str;
372 const char *lic_str;
373 const char *inst_str;
374
377 } else {
378 /* TRANS: Unknown modpack type */
379 type_str = _("?");
380 }
381
382 if (license != NULL) {
384 } else {
385 /* TRANS: License of modpack is not known */
386 lic_str = Q_("?license:Unknown");
387 }
388
390 if (inst_str == NULL) {
391 inst_str = _("Not installed");
392 }
393
397 ML_COL_VER, version,
400 ML_COL_SUBTYPE, subtype,
402 ML_COL_URL, URL,
403 ML_TYPE, type,
404 ML_NOTES, notes,
405 -1);
406}
407
408/**********************************************************************/
412{
413 GtkTreeModel *model;
414 GtkTreeIter it;
415 const char *URL;
416
417 if (!gtk_tree_selection_get_selected(select, &model, &it)) {
418 return;
419 }
420
421 gtk_tree_model_get(model, &it, ML_COL_URL, &URL, -1);
422
424}
425
426/**********************************************************************/
430{
432 GtkWidget *version_label;
435 GtkCellRenderer *renderer;
436 GtkTreeSelection *selection;
437 const char *errmsg;
438 char verbuf[2048];
439 const char *rev_ver;
440
441 mbox = gtk_grid_new();
445
447
448 if (rev_ver == NULL) {
450 } else {
451 fc_snprintf(verbuf, sizeof(verbuf), _("%s%s\ncommit: %s"),
453 }
454
455 version_label = gtk_label_new(verbuf);
456
458 renderer = gtk_cell_renderer_text_new();
461 _("Name"), renderer, "text", 0,
462 NULL);
463 renderer = gtk_cell_renderer_text_new();
466 _("Version"), renderer, "text", 1,
467 NULL);
468 renderer = gtk_cell_renderer_text_new();
471 _("Installed"), renderer, "text", 2,
472 NULL);
473 renderer = gtk_cell_renderer_text_new();
476 Q_("?modpack:Type"),
477 renderer, "text", 3,
478 NULL);
479 renderer = gtk_cell_renderer_text_new();
482 _("Subtype"),
483 renderer, "text", 4,
484 NULL);
485 renderer = gtk_cell_renderer_text_new();
488 /* TRANS: noun */
489 _("License"), renderer, "text", 5,
490 NULL);
491 renderer = gtk_cell_renderer_text_new();
494 _("URL"), renderer, "text", 6,
495 NULL);
497 g_signal_connect(selection, "changed", G_CALLBACK(select_from_list), NULL);
498
500 install_label = gtk_label_new(_("Install modpack"));
504
505 Ubox = gtk_grid_new();
508 URL_label = gtk_label_new_with_mnemonic(_("Modpack URL"));
509
514 g_signal_connect(URL_input, "activate",
516
519
522
524
525 statusbar = gtk_label_new(_("Select modpack to install"));
526
529
530 gtk_container_add(GTK_CONTAINER(mbox), version_label);
536
538
545
546 g_object_set(main_list, "has-tooltip", TRUE, NULL);
547 g_signal_connect(main_list, "query-tooltip",
549
551
552 if (errmsg != NULL) {
554 }
555}
556
557/**********************************************************************/
560int main(int argc, char *argv[])
561{
563 int ui_options;
564
566
567 fcmp_init();
568
569 /* This modifies argv! */
571
572 if (ui_options != -1) {
573 int i;
574
575 for (i = 1; i <= ui_options; i++) {
576 if (is_option("--help", argv[i])) {
578 _("This modpack installer accepts the standard Gtk command-line options\n"
579 "after '--'. See the Gtk documentation.\n\n"));
580
581 /* TRANS: No full stop after the URL, could cause confusion. */
582 fc_fprintf(stderr, _("Report bugs at %s\n"), BUG_URL);
583
584 ui_options = -1;
585 }
586 }
587 }
588
589 if (ui_options != -1) {
590
592
593 /* Process GTK arguments */
596
598 gtk_widget_set_name(toplevel, "Freeciv-modpack");
600 _("Freeciv modpack installer (gtk3)"));
601
602 /* Keep the icon of the executable on Windows */
603#ifndef FREECIV_MSWINDOWS
604 {
605 /* Unlike main client, this only works if installed. Ignore any
606 * errors loading the icon. */
607 GError *err;
608
610 &err);
611 }
612#endif /* FREECIV_MSWINDOWS */
613
614 g_signal_connect(toplevel, "delete_event",
616
618
620
621 if (fcmp.autoinstall != NULL) {
623 }
624
625 gtk_main();
626
628 } else {
629 log_fatal(_("Failed to open graphical mode."));
630 }
631
632 close_mpdbs();
633 }
634
635 fcmp_deinit();
637
638 return EXIT_SUCCESS;
639}
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
GtkWidget * toplevel
Definition gui_main.c:126
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
#define EXAMPLE_URL
Definition modinst.h:35
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_gtk3.c:59
static void quit_dialog_response(GtkWidget *dialog, gint response)
Definition mpgui_gtk3.c:81
static void msg_dl_thread(const char *msg)
Definition mpgui_gtk3.c:167
#define ML_TYPE
Definition mpgui_gtk3.c:65
int main(int argc, char *argv[])
Definition mpgui_gtk3.c:560
#define ML_NOTES
Definition mpgui_gtk3.c:66
static gboolean quit_dialog_callback(void)
Definition mpgui_gtk3.c:92
static GtkWidget * statusbar
Definition mpgui_gtk3.c:40
static gboolean query_main_list_tooltip_cb(GtkWidget *widget, gint x, gint y, gboolean keyboard_tip, GtkTooltip *tooltip, gpointer data)
Definition mpgui_gtk3.c:332
static void select_from_list(GtkTreeSelection *select, gpointer data)
Definition mpgui_gtk3.c:411
#define ML_STORE_SIZE
Definition mpgui_gtk3.c:67
static GtkListStore * main_store
Definition mpgui_gtk3.c:43
static gboolean versionlist_update_main_thread(gpointer user_data)
Definition mpgui_gtk3.c:211
#define ML_COL_NAME
Definition mpgui_gtk3.c:55
static void modinst_quit(void)
Definition mpgui_gtk3.c:72
#define ML_COL_LIC
Definition mpgui_gtk3.c:60
static void pbar_callback(int downloaded, int max)
Definition mpgui_gtk3.c:137
static void URL_return(GtkEntry *w, gpointer data)
Definition mpgui_gtk3.c:321
static GtkWidget * URL_input
Definition mpgui_gtk3.c:44
struct fcmp_params fcmp
Definition mpgui_gtk3.c:47
static gboolean downloading
Definition mpgui_gtk3.c:45
static GtkWidget * progressbar
Definition mpgui_gtk3.c:41
static void gui_download_modpack(const char *URL)
Definition mpgui_gtk3.c:280
static gboolean msg_main_thread(gpointer user_data)
Definition mpgui_gtk3.c:152
static void install_clicked(GtkWidget *w, gpointer data)
Definition mpgui_gtk3.c:310
#define ML_COL_TYPE
Definition mpgui_gtk3.c:58
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_gtk3.c:365
static void pbar_dl_thread(int current, int max)
Definition mpgui_gtk3.c:198
static void msg_callback(const char *msg)
Definition mpgui_gtk3.c:128
#define ML_COL_INST
Definition mpgui_gtk3.c:57
static GtkWidget * main_list
Definition mpgui_gtk3.c:42
static void versionlist_update_dl_thread(void)
Definition mpgui_gtk3.c:248
#define ML_COL_URL
Definition mpgui_gtk3.c:61
static gboolean pbar_main_thread(gpointer user_data)
Definition mpgui_gtk3.c:184
#define ML_COL_VER
Definition mpgui_gtk3.c:56
static gpointer download_thread(gpointer data)
Definition mpgui_gtk3.c:256
static void modinst_setup_widgets(void)
Definition mpgui_gtk4.c:445
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