Author: cazfi
Date: Thu Apr  7 21:24:16 2016
New Revision: 32316

URL: http://svn.gna.org/viewcvs/freeciv?rev=32316&view=rev
Log:
List only latest compatible version of the scenario in the scenario list of the 
gtk clients.

See patch #7085

Modified:
    branches/S2_6/client/gui-gtk-2.0/pages.c
    branches/S2_6/client/gui-gtk-3.0/pages.c

Modified: branches/S2_6/client/gui-gtk-2.0/pages.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-gtk-2.0/pages.c?rev=32316&r1=32315&r2=32316&view=diff
==============================================================================
--- branches/S2_6/client/gui-gtk-2.0/pages.c    (original)
+++ branches/S2_6/client/gui-gtk-2.0/pages.c    Thu Apr  7 21:24:16 2016
@@ -1,4 +1,4 @@
-/********************************************************************** 
+/**********************************************************************
  Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -2908,7 +2908,7 @@
 }
 
 /**************************************************************************
-  update the scenario page.
+  Update the scenario page.
 **************************************************************************/
 static void update_scenario_page(void)
 {
@@ -2924,19 +2924,75 @@
     if ((sf = secfile_load_section(pfile->fullname, "scenario", TRUE))
         && secfile_lookup_bool_default(sf, TRUE, "scenario.is_scenario")) {
       const char *sname, *sdescription;
-      GtkTreeIter it;
-
-      gtk_list_store_append(scenario_store, &it);
-
+      int fcver;
+      int current_ver = MAJOR_VERSION *10000 + MINOR_VERSION *100;
+
+      fcver = secfile_lookup_int_default(sf, 0, "scenario.game_version");
+      fcver -= (fcver % 100); /* Patch level does not affect compatibility */
       sname = secfile_lookup_str_default(sf, NULL, "scenario.name");
       sdescription = secfile_lookup_str_default(sf, NULL,
                                                 "scenario.description");
-      gtk_list_store_set(scenario_store, &it,
-                         0, sname && strlen(sname) ? Q_(sname) : pfile->name,
-                         1, pfile->fullname,
-                         2, (NULL != sdescription && '\0' != sdescription[0]
-                             ? Q_(sdescription) : ""),
-                         -1);
+      log_debug("scenario file: %s from %s", sname, pfile->fullname);
+
+      /* Ignore scenarios for newer freeciv versions than we are */
+      if (fcver <= current_ver) {
+        bool add_new = TRUE;
+
+        if (sname != NULL) {
+          GtkTreeIter it;
+          bool valid;
+
+          valid = 
gtk_tree_model_get_iter_first(GTK_TREE_MODEL(scenario_store), &it);
+          while (valid) {
+            char *oname;
+
+            gtk_tree_model_get(GTK_TREE_MODEL(scenario_store), &it,
+                               0, &oname, -1);
+
+            if (!strcmp(sname, oname)) {
+              /* Already listed scenario has the same name as the one we just 
found */
+              int existing;
+
+              gtk_tree_model_get(GTK_TREE_MODEL(scenario_store), &it,
+                                 3, &existing, -1);
+              log_debug("Duplicate %s (%d vs %d)", sname, existing, fcver);
+
+              if (existing > fcver) {
+                /* Already listed one has higher version number */
+                add_new = FALSE;
+              } else if (existing < fcver) {
+                /* New one has higher version number */
+                add_new = FALSE;
+
+                gtk_list_store_set(scenario_store, &it,
+                                   0, sname && strlen(sname) ? Q_(sname) : 
pfile->name,
+                                   1, pfile->fullname,
+                                   2, (NULL != sdescription && '\0' != 
sdescription[0]
+                                       ? Q_(sdescription) : ""),
+                                   3, fcver,
+                                   -1);
+              } else {
+                /* Same version number -> list both */
+              }
+            }
+            valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(scenario_store), 
&it);
+          }
+        }
+
+        if (add_new) {
+          GtkTreeIter it;
+
+          gtk_list_store_append(scenario_store, &it);
+          gtk_list_store_set(scenario_store, &it,
+                             0, sname && strlen(sname) ? Q_(sname) : 
pfile->name,
+                             1, pfile->fullname,
+                             2, (NULL != sdescription && '\0' != 
sdescription[0]
+                                 ? Q_(sdescription) : ""),
+                             3, fcver,
+                             -1);
+        }
+      }
+
       secfile_destroy(sf);
     }
   } fileinfo_list_iterate_end;
@@ -2945,7 +3001,7 @@
 }
 
 /**************************************************************************
-  create the scenario page.
+  Create the scenario page.
 **************************************************************************/
 GtkWidget *create_scenario_page(void)
 {
@@ -2957,9 +3013,10 @@
   vbox = gtk_vbox_new(FALSE, 18);
   gtk_container_set_border_width(GTK_CONTAINER(vbox), 4);
 
-  scenario_store = gtk_list_store_new(3, G_TYPE_STRING,
-                                        G_TYPE_STRING,
-                                        G_TYPE_STRING);
+  scenario_store = gtk_list_store_new(4, G_TYPE_STRING,
+                                         G_TYPE_STRING,
+                                         G_TYPE_STRING,
+                                         G_TYPE_INT);
   view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(scenario_store));
   g_object_unref(scenario_store);
 

Modified: branches/S2_6/client/gui-gtk-3.0/pages.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-gtk-3.0/pages.c?rev=32316&r1=32315&r2=32316&view=diff
==============================================================================
--- branches/S2_6/client/gui-gtk-3.0/pages.c    (original)
+++ branches/S2_6/client/gui-gtk-3.0/pages.c    Thu Apr  7 21:24:16 2016
@@ -2978,7 +2978,7 @@
 }
 
 /**************************************************************************
-  update the scenario page.
+  Update the scenario page.
 **************************************************************************/
 static void update_scenario_page(void)
 {
@@ -2994,19 +2994,75 @@
     if ((sf = secfile_load_section(pfile->fullname, "scenario", TRUE))
         && secfile_lookup_bool_default(sf, TRUE, "scenario.is_scenario")) {
       const char *sname, *sdescription;
-      GtkTreeIter it;
-
-      gtk_list_store_append(scenario_store, &it);
-
+      int fcver;
+      int current_ver = MAJOR_VERSION *10000 + MINOR_VERSION *100;
+
+      fcver = secfile_lookup_int_default(sf, 0, "scenario.game_version");
+      fcver -= (fcver % 100); /* Patch level does not affect compatibility */
       sname = secfile_lookup_str_default(sf, NULL, "scenario.name");
       sdescription = secfile_lookup_str_default(sf, NULL,
                                                 "scenario.description");
-      gtk_list_store_set(scenario_store, &it,
-                         0, sname && strlen(sname) ? Q_(sname) : pfile->name,
-                         1, pfile->fullname,
-                         2, (NULL != sdescription && '\0' != sdescription[0]
-                             ? Q_(sdescription) : ""),
-                         -1);
+      log_debug("scenario file: %s from %s", sname, pfile->fullname);
+
+      /* Ignore scenarios for newer freeciv versions than we are */
+      if (fcver <= current_ver) {
+        bool add_new = TRUE;
+
+        if (sname != NULL) {
+          GtkTreeIter it;
+          bool valid;
+
+          valid = 
gtk_tree_model_get_iter_first(GTK_TREE_MODEL(scenario_store), &it);
+          while (valid) {
+            char *oname;
+
+            gtk_tree_model_get(GTK_TREE_MODEL(scenario_store), &it,
+                               0, &oname, -1);
+
+            if (!strcmp(sname, oname)) {
+              /* Already listed scenario has the same name as the one we just 
found */
+              int existing;
+
+              gtk_tree_model_get(GTK_TREE_MODEL(scenario_store), &it,
+                                 3, &existing, -1);
+              log_debug("Duplicate %s (%d vs %d)", sname, existing, fcver);
+
+              if (existing > fcver) {
+                /* Already listed one has higher version number */
+                add_new = FALSE;
+              } else if (existing < fcver) {
+                /* New one has higher version number */
+                add_new = FALSE;
+
+                gtk_list_store_set(scenario_store, &it,
+                                   0, sname && strlen(sname) ? Q_(sname) : 
pfile->name,
+                                   1, pfile->fullname,
+                                   2, (NULL != sdescription && '\0' != 
sdescription[0]
+                                       ? Q_(sdescription) : ""),
+                                   3, fcver,
+                                   -1);
+              } else {
+                /* Same version number -> list both */
+              }
+            }
+            valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(scenario_store), 
&it);
+          }
+        }
+
+        if (add_new) {
+          GtkTreeIter it;
+
+          gtk_list_store_append(scenario_store, &it);
+          gtk_list_store_set(scenario_store, &it,
+                             0, sname && strlen(sname) ? Q_(sname) : 
pfile->name,
+                             1, pfile->fullname,
+                             2, (NULL != sdescription && '\0' != 
sdescription[0]
+                                 ? Q_(sdescription) : ""),
+                             3, fcver,
+                             -1);
+        }
+      }
+
       secfile_destroy(sf);
     }
   } fileinfo_list_iterate_end;
@@ -3015,7 +3071,7 @@
 }
 
 /**************************************************************************
-  create the scenario page.
+  Create the scenario page.
 **************************************************************************/
 GtkWidget *create_scenario_page(void)
 {
@@ -3030,9 +3086,10 @@
   gtk_grid_set_row_spacing(GTK_GRID(vbox), 18);
   gtk_container_set_border_width(GTK_CONTAINER(vbox), 4);
 
-  scenario_store = gtk_list_store_new(3, G_TYPE_STRING,
-                                        G_TYPE_STRING,
-                                        G_TYPE_STRING);
+  scenario_store = gtk_list_store_new(4, G_TYPE_STRING,
+                                         G_TYPE_STRING,
+                                         G_TYPE_STRING,
+                                         G_TYPE_INT);
   view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(scenario_store));
   gtk_widget_set_hexpand(view, TRUE);
   gtk_widget_set_vexpand(view, TRUE);


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to