[Libguestfs] [p2v PATCH 6/7] remove GTK2 compat code

Laszlo Ersek lersek at redhat.com
Mon Sep 26 08:18:11 UTC 2022


Remove GTK2 compat code.  Open-code conditional compilation directives
that evaluate to constant values when virt-p2v is built with GTK3.

A special note regarding GTK_SPINNER (because the code does not use a
version check for the spinner widget's availability): upstream GTK
introduced GTK_SPINNER in commit d21700f5105c ("Bug 319607 – Add a
throbber (activity widget) to GTK+", 2009-10-14), which commit was first
released in version 2.19.0, and is also contained within release 3.0.0.

Even within GTK3, we have multiple compatibility layers.  If we only
concentrated on RHEL-9+ and Fedora-35+, we could much simplify
"gui-gtk3-compat.h" as well (potentially flattening the whole header file
into C sources).  Given that we build virt-p2v on multiple distro
families, establishing a common base version for GTK3, higher than version
3.0.0, is not so simple.  So preserve "gui-gtk3-compat.h" for now.

Signed-off-by: Laszlo Ersek <lersek at redhat.com>
---
 Makefile.am       |   1 -
 gui-gtk2-compat.h | 116 --------------------
 gui.c             |  45 +-------
 3 files changed, 3 insertions(+), 159 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 126ee726278a..eaa98270fd9a 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -106,7 +106,6 @@ virt_p2v_SOURCES = \
 	cpuid.c \
 	disks.c \
 	gui.c \
-	gui-gtk2-compat.h \
 	gui-gtk3-compat.h \
 	inhibit.c \
 	kernel.c \
diff --git a/gui-gtk2-compat.h b/gui-gtk2-compat.h
deleted file mode 100644
index ac9cb6022154..000000000000
--- a/gui-gtk2-compat.h
+++ /dev/null
@@ -1,116 +0,0 @@
-/* virt-p2v
- * Copyright (C) 2009-2019 Red Hat Inc.
- *
- * 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
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <https://www.gnu.org/licenses/>.
- */
-
-/* Backwards compatibility for ancient RHEL 5 Gtk 2.10. */
-#ifndef GTK_COMBO_BOX_TEXT
-#define GTK_COMBO_BOX_TEXT GTK_COMBO_BOX
-#define gtk_combo_box_text_new() gtk_combo_box_new_text()
-#define gtk_combo_box_text_append_text(combo, text)	\
-  gtk_combo_box_append_text((combo), (text))
-#define gtk_combo_box_text_get_active_text(combo)	\
-  gtk_combo_box_get_active_text((combo))
-#endif
-
-#if !GTK_CHECK_VERSION(2,12,0)	/* gtk < 2.12 */
-#define gtk_widget_set_tooltip_markup(widget, text) /* nothing */
-#endif
-
-#if !GTK_CHECK_VERSION(2,14,0)	/* gtk < 2.14 */
-#define gtk_dialog_get_content_area(dlg) ((dlg)->vbox)
-#endif
-
-#if !GTK_CHECK_VERSION(2,18,0)	/* gtk < 2.18 */
-static void
-gtk_cell_renderer_set_alignment (GtkCellRenderer *cell,
-                                 gfloat xalign, gfloat yalign)
-{
-  if ((xalign != cell->xalign) || (yalign != cell->yalign)) {
-    g_object_freeze_notify (G_OBJECT (cell));
-
-    if (xalign != cell->xalign) {
-      cell->xalign = xalign;
-      g_object_notify (G_OBJECT (cell), "xalign");
-    }
-
-    if (yalign != cell->yalign) {
-      cell->yalign = yalign;
-      g_object_notify (G_OBJECT (cell), "yalign");
-    }
-
-    g_object_thaw_notify (G_OBJECT (cell));
-  }
-}
-#endif
-
-#if !GTK_CHECK_VERSION(2,20,0)	/* gtk < 2.20 */
-typedef struct _ResponseData ResponseData;
-
-struct _ResponseData
-{
-  gint response_id;
-};
-
-static void
-response_data_free (gpointer data)
-{
-  g_slice_free (ResponseData, data);
-}
-
-static ResponseData *
-get_response_data (GtkWidget *widget, gboolean create)
-{
-  ResponseData *ad = g_object_get_data (G_OBJECT (widget),
-                                        "gtk-dialog-response-data");
-
-  if (ad == NULL && create) {
-    ad = g_slice_new (ResponseData);
-
-    g_object_set_data_full (G_OBJECT (widget),
-			    g_intern_static_string ("gtk-dialog-response-data"),
-			    ad,
-			    response_data_free);
-  }
-
-  return ad;
-}
-
-static GtkWidget *
-gtk_dialog_get_widget_for_response (GtkDialog *dialog, gint response_id)
-{
-  GList *children;
-  GList *tmp_list;
-
-  children = gtk_container_get_children (GTK_CONTAINER (dialog->action_area));
-
-  tmp_list = children;
-  while (tmp_list != NULL) {
-    GtkWidget *widget = tmp_list->data;
-    ResponseData *rd = get_response_data (widget, FALSE);
-
-    if (rd && rd->response_id == response_id) {
-      g_list_free (children);
-      return widget;
-    }
-
-    tmp_list = tmp_list->next;
-  }
-
-  g_list_free (children);
-
-  return NULL;
-}
-#endif /* gtk < 2.20 */
diff --git a/gui.c b/gui.c
index 5d1771266605..6e785497b968 100644
--- a/gui.c
+++ b/gui.c
@@ -47,12 +47,9 @@
  * handled entirely by NetworkManager's L<nm-connection-editor(1)>
  * program and has nothing to do with this code.
  *
- * This file is written in a kind of "pseudo-Gtk" which is backwards
- * compatible from Gtk 2.10 (RHEL 5) through at least Gtk 3.22.  This
- * is done using a few macros to implement old C<gtk_*> functions or
- * map them to newer functions.  Supporting ancient Gtk is important
- * because we want to provide a virt-p2v binary that can run on very
- * old kernels, to support 32 bit and proprietary SCSI drivers.
+ * This file is written in a kind of "pseudo-Gtk" which is backwards compatible
+ * from Gtk 3.0 through at least Gtk 3.22.  This is done using a few macros to
+ * implement old C<gtk_*> functions or map them to newer functions.
  */
 
 #include <config.h>
@@ -86,7 +83,6 @@
 #include "p2v.h"
 
 /* See note about "pseudo-Gtk" above. */
-#include "gui-gtk2-compat.h"
 #include "gui-gtk3-compat.h"
 
 /* Maximum vCPUs and guest memory that we will allow users to set.
@@ -116,9 +112,7 @@ static GtkWidget *conn_dlg,
   *server_entry, *port_entry,
   *username_entry, *password_entry, *identity_entry, *sudo_button,
   *spinner_hbox,
-#ifdef GTK_SPINNER
   *spinner,
-#endif
   *spinner_message, *next_button;
 
 /* The conversion dialog. */
@@ -138,23 +132,6 @@ static GtkWidget *run_dlg,
 /* Colour tags used in the v2v_output GtkTextBuffer. */
 static GtkTextTag *v2v_output_tags[16];
 
-#if !GTK_CHECK_VERSION(3,0,0)   /* gtk < 3 */
-/* The license of virt-p2v, for the About dialog. */
-static const char gplv2plus[] =
-  "This program is free software; you can redistribute it and/or modify\n"
-  "it under the terms of the GNU General Public License as published by\n"
-  "the Free Software Foundation; either version 2 of the License, or\n"
-  "(at your option) any later version.\n"
-  "\n"
-  "This program is distributed in the hope that it will be useful,\n"
-  "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
-  "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n"
-  "GNU General Public License for more details.\n"
-  "\n"
-  "You should have received a copy of the GNU General Public License\n"
-  "along with this program.  If not, see <https://www.gnu.org/licenses/>.\n";
-#endif
-
 /**
  * The entry point from the main program.
  *
@@ -304,10 +281,8 @@ create_connection_dialog (struct config *config)
   gtk_box_pack_start (GTK_BOX (test_hbox), test, TRUE, FALSE, 0);
 
   hbox_new (spinner_hbox, FALSE, 10);
-#ifdef GTK_SPINNER
   spinner = gtk_spinner_new ();
   gtk_box_pack_start (GTK_BOX (spinner_hbox), spinner, FALSE, FALSE, 0);
-#endif
   spinner_message = gtk_label_new (NULL);
   gtk_label_set_line_wrap (GTK_LABEL (spinner_message), TRUE);
   set_padding (spinner_message, 10, 10);
@@ -452,9 +427,7 @@ test_connection_clicked (GtkWidget *w, gpointer data)
 
   gtk_label_set_text (GTK_LABEL (spinner_message), "");
   gtk_widget_show_all (spinner_hbox);
-#ifdef GTK_SPINNER
   gtk_widget_hide (spinner);
-#endif
 
   /* Get the fields from the various widgets. */
   free (config->remote.server);
@@ -550,10 +523,8 @@ start_spinner (gpointer user_data)
 {
   gtk_label_set_text (GTK_LABEL (spinner_message),
                       _("Testing the connection to the conversion server ..."));
-#ifdef GTK_SPINNER
   gtk_widget_show (spinner);
   gtk_spinner_start (GTK_SPINNER (spinner));
-#endif
   return FALSE;
 }
 
@@ -564,10 +535,8 @@ start_spinner (gpointer user_data)
 static gboolean
 stop_spinner (gpointer user_data)
 {
-#ifdef GTK_SPINNER
   gtk_spinner_stop (GTK_SPINNER (spinner));
   gtk_widget_hide (spinner);
-#endif
   return FALSE;
 }
 
@@ -652,11 +621,7 @@ about_button_clicked (GtkWidget *w, gpointer data)
                 "copyright", "\u00A9 2009-2019 Red Hat Inc.",
                 "comments",
                   _("Virtualize a physical machine to run on KVM"),
-#if GTK_CHECK_VERSION(3,0,0)   /* gtk >= 3 */
                 "license-type", GTK_LICENSE_GPL_2_0,
-#else
-                "license", gplv2plus,
-#endif
                 "website", "http://libguestfs.org/",
                 "authors", authors,
                 NULL);
@@ -1855,11 +1820,7 @@ create_running_dialog (void)
 #else
   PangoFontDescription *font;
   font = pango_font_description_from_string ("Monospace 11");
-#if GTK_CHECK_VERSION(3,0,0)	/* gtk >= 3 */
   gtk_widget_override_font (v2v_output, font);
-#else
-  gtk_widget_modify_font (v2v_output, font);
-#endif
   pango_font_description_free (font);
 #endif
 



More information about the Libguestfs mailing list