Freeciv-3.2
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 "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
45
46struct fcmp_params fcmp = {
48 .inst_prefix = NULL,
49 .autoinstall = NULL
50};
51
53
54#define ML_COL_NAME 0
55#define ML_COL_VER 1
56#define ML_COL_INST 2
57#define ML_COL_TYPE 3
58#define ML_COL_SUBTYPE 4
59#define ML_COL_LIC 5
60#define ML_COL_URL 6
61
62#define ML_COL_COUNT 7
63
64#define ML_TYPE 7
65#define ML_NOTES 8
66#define ML_STORE_SIZE 9
67
68/**********************************************************************/
71static void modinst_quit(void)
72{
74}
75
76/**********************************************************************/
80static void quit_dialog_response(GtkWidget *dialog, gint response)
81{
82 gtk_widget_destroy(dialog);
83 if (response == GTK_RESPONSE_YES) {
85 }
86}
87
88/**********************************************************************/
92{
93 if (downloading) {
94 /* Download in progress. Confirm quit from user. */
95 static GtkWidget *dialog;
96
97 if (!dialog) {
99 0,
102 _("Modpack installation in progress.\nAre you sure you want to quit?"));
103
105
106 g_signal_connect(dialog, "response",
108 g_signal_connect(dialog, "destroy",
110 }
111
113
114 } else {
115 /* User loses no work by quitting, so let's not annoy them
116 * with confirmation dialog. */
117 modinst_quit();
118 }
119
120 /* Stop emission of event. */
121 return TRUE;
122}
123
124/**********************************************************************/
127static void msg_callback(const char *msg)
128{
129 log_verbose("%s", msg);
131}
132
133/**********************************************************************/
136static void pbar_callback(int downloaded, int max)
137{
138 /* Control file already downloaded */
139 double fraction = (double) downloaded / (max);
140
142}
143
144struct msg_data {
145 char *msg;
146};
147
148/**********************************************************************/
152{
153 struct msg_data *data = (struct msg_data *)user_data;
154
155 msg_callback(data->msg);
156
157 FC_FREE(data->msg);
158 FC_FREE(data);
159
160 return G_SOURCE_REMOVE;
161}
162
163/**********************************************************************/
166static void msg_dl_thread(const char *msg)
167{
168 struct msg_data *data = fc_malloc(sizeof(*data));
169
170 data->msg = fc_strdup(msg);
171
173}
174
175struct pbar_data {
177 int max;
178};
179
180/**********************************************************************/
184{
185 struct pbar_data *data = (struct pbar_data *)user_data;
186
187 pbar_callback(data->current, data->max);
188
189 FC_FREE(data);
190
191 return G_SOURCE_REMOVE;
192}
193
194/**********************************************************************/
197static void pbar_dl_thread(int current, int max)
198{
199 struct pbar_data *data = fc_malloc(sizeof(*data));
200
201 data->current = current;
202 data->max = max;
203
205}
206
207/**********************************************************************/
211{
213
215 do {
216 const char *name_str;
217 int type_int;
218 const char *new_inst;
219 enum modpack_type type;
220
224 -1);
225
226 type = type_int;
227
229
230 if (new_inst == NULL) {
231 new_inst = _("Not installed");
232 }
233
236 -1);
237
239 }
240
241 return G_SOURCE_REMOVE;
242}
243
244/**********************************************************************/
251
252/**********************************************************************/
256{
257 const char *errmsg;
258
260
261 if (errmsg == NULL) {
262 msg_dl_thread(_("Ready"));
263 } else {
265 }
266
267 free(data);
268
270
272
273 return NULL;
274}
275
276/**********************************************************************/
279static void gui_download_modpack(const char *URL)
280{
282 char *URLbuf;
283
284 if (downloading) {
286 _("Another download already active"));
287 return;
288 }
289
291
292 URLbuf = fc_malloc(strlen(URL) + 1);
293
294 strcpy(URLbuf, URL);
295
297 if (downloader == NULL) {
299 _("Failed to start downloader"));
300 free(URLbuf);
301 } else {
303 }
304}
305
306/**********************************************************************/
309static void install_clicked(GtkWidget *w, gpointer data)
310{
311 GtkEntry *URL_in = data;
312 const char *URL = gtk_entry_get_text(URL_in);
313
315}
316
317/**********************************************************************/
320static void URL_return(GtkEntry *w, gpointer data)
321{
322 const char *URL;
323
324 URL = gtk_entry_get_text(w);
326}
327
328/**********************************************************************/
332 gint x, gint y,
335 gpointer data)
336{
338 GtkTreeView *tree_view = GTK_TREE_VIEW(widget);
339 GtkTreeModel *model;
340 const char *notes;
341
342 if (!gtk_tree_view_get_tooltip_context(tree_view, &x, &y,
344 &model, NULL, &iter)) {
345 return FALSE;
346 }
347
348 gtk_tree_model_get(model, &iter,
349 ML_NOTES, &notes,
350 -1);
351
352 if (notes != NULL) {
354
355 return TRUE;
356 }
357
358 return FALSE;
359}
360
361/**********************************************************************/
364static void setup_modpack_list(const char *name, const char *URL,
365 const char *version, const char *license,
366 enum modpack_type type, const char *subtype,
367 const char *notes)
368{
370 const char *type_str;
371 const char *lic_str;
372 const char *inst_str;
373
376 } else {
377 /* TRANS: Unknown modpack type */
378 type_str = _("?");
379 }
380
381 if (license != NULL) {
383 } else {
384 /* TRANS: License of modpack is not known */
385 lic_str = Q_("?license:Unknown");
386 }
387
389 if (inst_str == NULL) {
390 inst_str = _("Not installed");
391 }
392
396 ML_COL_VER, version,
401 ML_COL_URL, URL,
402 ML_TYPE, type,
404 -1);
405}
406
407/**********************************************************************/
411{
412 GtkTreeModel *model;
413 GtkTreeIter it;
414 const char *URL;
415
416 if (!gtk_tree_selection_get_selected(select, &model, &it)) {
417 return;
418 }
419
420 gtk_tree_model_get(model, &it, ML_COL_URL, &URL, -1);
421
423}
424
425/**********************************************************************/
429{
431 GtkWidget *version_label;
434 GtkCellRenderer *renderer;
435 GtkTreeSelection *selection;
436 const char *errmsg;
437 char verbuf[2048];
438 const char *rev_ver;
439
440 mbox = gtk_grid_new();
444
446
447 if (rev_ver == NULL) {
449 } else {
450 fc_snprintf(verbuf, sizeof(verbuf), _("%s%s\ncommit: %s"),
452 }
453
454 version_label = gtk_label_new(verbuf);
455
457 renderer = gtk_cell_renderer_text_new();
460 _("Name"), renderer, "text", 0,
461 NULL);
462 renderer = gtk_cell_renderer_text_new();
465 _("Version"), renderer, "text", 1,
466 NULL);
467 renderer = gtk_cell_renderer_text_new();
470 _("Installed"), renderer, "text", 2,
471 NULL);
472 renderer = gtk_cell_renderer_text_new();
475 Q_("?modpack:Type"),
476 renderer, "text", 3,
477 NULL);
478 renderer = gtk_cell_renderer_text_new();
481 _("Subtype"),
482 renderer, "text", 4,
483 NULL);
484 renderer = gtk_cell_renderer_text_new();
487 /* TRANS: noun */
488 _("License"), renderer, "text", 5,
489 NULL);
490 renderer = gtk_cell_renderer_text_new();
493 _("URL"), renderer, "text", 6,
494 NULL);
496 g_signal_connect(selection, "changed", G_CALLBACK(select_from_list), NULL);
497
499 install_label = gtk_label_new(_("Install modpack"));
503
504 Ubox = gtk_grid_new();
507 URL_label = gtk_label_new_with_mnemonic(_("Modpack URL"));
508
513 g_signal_connect(URL_input, "activate",
515
518
521
523
524 statusbar = gtk_label_new(_("Select modpack to install"));
525
528
529 gtk_container_add(GTK_CONTAINER(mbox), version_label);
535
537
544
545 g_object_set(main_list, "has-tooltip", TRUE, NULL);
546 g_signal_connect(main_list, "query-tooltip",
548
550
551 if (errmsg != NULL) {
553 }
554}
555
556/**********************************************************************/
559int main(int argc, char *argv[])
560{
562 int ui_options;
563
564 fcmp_init();
565
566 /* This modifies argv! */
568
569 if (ui_options != -1) {
570 int i;
571
572 for (i = 1; i <= ui_options; i++) {
573 if (is_option("--help", argv[i])) {
575 _("This modpack installer accepts the standard Gtk command-line options\n"
576 "after '--'. See the Gtk documentation.\n\n"));
577
578 /* TRANS: No full stop after the URL, could cause confusion. */
579 fc_fprintf(stderr, _("Report bugs at %s\n"), BUG_URL);
580
581 ui_options = -1;
582 }
583 }
584 }
585
586 if (ui_options != -1) {
587
589
590 /* Process GTK arguments */
593
595 gtk_widget_set_name(toplevel, "Freeciv-modpack");
597 _("Freeciv modpack installer (gtk3)"));
598
599 /* Keep the icon of the executable on Windows */
600#ifndef FREECIV_MSWINDOWS
601 {
602 /* Unlike main client, this only works if installed. Ignore any
603 * errors loading the icon. */
604 GError *err;
605
607 &err);
608 }
609#endif /* FREECIV_MSWINDOWS */
610
611 g_signal_connect(toplevel, "delete_event",
613
615
617
618 if (fcmp.autoinstall != NULL) {
620 }
621
622 gtk_main();
623
625 } else {
626 log_fatal(_("Failed to open graphical mode."));
627 }
628
629 close_mpdbs();
630 }
631
632 fcmp_deinit();
634
635 return EXIT_SUCCESS;
636}
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
GtkWidget * toplevel
Definition gui_main.c:125
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
#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:58
static void quit_dialog_response(GtkWidget *dialog, gint response)
Definition mpgui_gtk3.c:80
static void msg_dl_thread(const char *msg)
Definition mpgui_gtk3.c:166
#define ML_TYPE
Definition mpgui_gtk3.c:64
int main(int argc, char *argv[])
Definition mpgui_gtk3.c:559
#define ML_NOTES
Definition mpgui_gtk3.c:65
static gboolean quit_dialog_callback(void)
Definition mpgui_gtk3.c:91
static GtkWidget * statusbar
Definition mpgui_gtk3.c:39
static gboolean query_main_list_tooltip_cb(GtkWidget *widget, gint x, gint y, gboolean keyboard_tip, GtkTooltip *tooltip, gpointer data)
Definition mpgui_gtk3.c:331
static void select_from_list(GtkTreeSelection *select, gpointer data)
Definition mpgui_gtk3.c:410
#define ML_STORE_SIZE
Definition mpgui_gtk3.c:66
static GtkListStore * main_store
Definition mpgui_gtk3.c:42
static gboolean versionlist_update_main_thread(gpointer user_data)
Definition mpgui_gtk3.c:210
#define ML_COL_NAME
Definition mpgui_gtk3.c:54
static void modinst_quit(void)
Definition mpgui_gtk3.c:71
#define ML_COL_LIC
Definition mpgui_gtk3.c:59
static void pbar_callback(int downloaded, int max)
Definition mpgui_gtk3.c:136
static void URL_return(GtkEntry *w, gpointer data)
Definition mpgui_gtk3.c:320
static GtkWidget * URL_input
Definition mpgui_gtk3.c:43
struct fcmp_params fcmp
Definition mpgui_gtk3.c:46
static gboolean downloading
Definition mpgui_gtk3.c:44
static GtkWidget * progressbar
Definition mpgui_gtk3.c:40
static void gui_download_modpack(const char *URL)
Definition mpgui_gtk3.c:279
static gboolean msg_main_thread(gpointer user_data)
Definition mpgui_gtk3.c:151
static void install_clicked(GtkWidget *w, gpointer data)
Definition mpgui_gtk3.c:309
#define ML_COL_TYPE
Definition mpgui_gtk3.c:57
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:364
static void pbar_dl_thread(int current, int max)
Definition mpgui_gtk3.c:197
static void msg_callback(const char *msg)
Definition mpgui_gtk3.c:127
#define ML_COL_INST
Definition mpgui_gtk3.c:56
static GtkWidget * main_list
Definition mpgui_gtk3.c:41
static void versionlist_update_dl_thread(void)
Definition mpgui_gtk3.c:247
#define ML_COL_URL
Definition mpgui_gtk3.c:60
static gboolean pbar_main_thread(gpointer user_data)
Definition mpgui_gtk3.c:183
#define ML_COL_VER
Definition mpgui_gtk3.c:55
static gpointer download_thread(gpointer data)
Definition mpgui_gtk3.c:255
static void modinst_setup_widgets(void)
Definition mpgui_gtk4.c:444
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