Skip to content

Commit c213ae0

Browse files
author
Laszlo Ersek
committed
remove old GLIB2 / GTK3 compat code
Open-code conditional compilation directives that evaluate to constant values when virt-p2v is built with GLIB >= 2.56 and GTK >= 3.22. Signed-off-by: Laszlo Ersek <[email protected]> Message-Id: <[email protected]> Reviewed-by: Richard W.M. Jones <[email protected]>
1 parent dd423e2 commit c213ae0

File tree

2 files changed

+4
-111
lines changed

2 files changed

+4
-111
lines changed

gui-gtk3-compat.h

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,6 @@
1616
*/
1717

1818
/* Backwards compatibility for some deprecated functions in Gtk 3. */
19-
#if !GTK_CHECK_VERSION(3,2,0) /* gtk < 3.2 */
20-
static gboolean
21-
gdk_event_get_button (const GdkEvent *event, guint *button)
22-
{
23-
if (event->type != GDK_BUTTON_PRESS)
24-
return FALSE;
25-
26-
*button = ((const GdkEventButton *) event)->button;
27-
return TRUE;
28-
}
29-
#endif
30-
31-
#if GTK_CHECK_VERSION(3,2,0) /* gtk >= 3.2 */
3219
#define hbox_new(box, homogeneous, spacing) \
3320
do { \
3421
(box) = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, spacing); \
@@ -41,14 +28,7 @@ gdk_event_get_button (const GdkEvent *event, guint *button)
4128
if (homogeneous) \
4229
gtk_box_set_homogeneous (GTK_BOX (box), TRUE); \
4330
} while (0)
44-
#else /* gtk < 3.2 */
45-
#define hbox_new(box, homogeneous, spacing) \
46-
(box) = gtk_hbox_new ((homogeneous), (spacing))
47-
#define vbox_new(box, homogeneous, spacing) \
48-
(box) = gtk_vbox_new ((homogeneous), (spacing))
49-
#endif
5031

51-
#if GTK_CHECK_VERSION(3,4,0) /* gtk >= 3.4 */
5232
/* Copy this enum from GtkTable, as when building without deprecated
5333
* functions this is not automatically pulled in.
5434
*/
@@ -77,34 +57,14 @@ typedef enum
7757
gtk_grid_attach (GTK_GRID (grid), (child), \
7858
(left), (top), (right)-(left), 1); \
7959
} while (0)
80-
#else
81-
#define table_new(table, rows, columns) \
82-
(table) = gtk_table_new ((rows), (columns), FALSE)
83-
#define table_attach(table, child, left, right,top, xoptions, yoptions, xpadding, ypadding) \
84-
gtk_table_attach (GTK_TABLE (table), (child), \
85-
(left), (right), (top), (top + 1), \
86-
(xoptions), (yoptions), (xpadding), (ypadding))
87-
#endif
8860

89-
#if GTK_CHECK_VERSION(3,8,0) /* gtk >= 3.8 */
9061
#define scrolled_window_add_with_viewport(container, child) \
9162
gtk_container_add (GTK_CONTAINER (container), child)
92-
#else
93-
#define scrolled_window_add_with_viewport(container, child) \
94-
gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (container), child)
95-
#endif
9663

97-
#if !GTK_CHECK_VERSION(3,10,0) /* gtk < 3.10 */
98-
#define gdk_event_get_event_type(event) ((event)->type)
99-
#endif
100-
101-
#if GTK_CHECK_VERSION(3,10,0) /* gtk >= 3.10 */
10264
#undef GTK_STOCK_DIALOG_WARNING
10365
#define GTK_STOCK_DIALOG_WARNING "dialog-warning"
10466
#define gtk_image_new_from_stock gtk_image_new_from_icon_name
105-
#endif
10667

107-
#if GTK_CHECK_VERSION(3,14,0) /* gtk >= 3.14 */
10868
#define set_padding(widget, xpad, ypad) \
10969
do { \
11070
if ((xpad) != 0) { \
@@ -131,9 +91,3 @@ typedef enum
13191
else \
13292
gtk_widget_set_valign ((widget), GTK_ALIGN_CENTER); \
13393
} while (0)
134-
#else /* gtk < 3.14 */
135-
#define set_padding(widget, xpad, ypad) \
136-
gtk_misc_set_padding(GTK_MISC(widget),(xpad),(ypad))
137-
#define set_alignment(widget, xalign, yalign) \
138-
gtk_misc_set_alignment(GTK_MISC(widget),(xalign),(yalign))
139-
#endif

gui.c

Lines changed: 4 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,10 @@
4747
* handled entirely by NetworkManager's L<nm-connection-editor(1)>
4848
* program and has nothing to do with this code.
4949
*
50-
* This file is written in a kind of "pseudo-Gtk" which is backwards compatible
51-
* from Gtk 3.0 through at least Gtk 3.22. This is done using a few macros to
52-
* implement old C<gtk_*> functions or map them to newer functions.
50+
* This file is written in a kind of "pseudo-Gtk" that currently targets Gtk
51+
* 3.22 exclusively, but may later be extended to a broader Gtk version range.
52+
* This is done using a few macros to implement old C<gtk_*> functions or map
53+
* them to newer functions.
5354
*/
5455

5556
#include <config.h>
@@ -92,10 +93,6 @@
9293
#define MAX_SUPPORTED_VCPUS 160
9394
#define MAX_SUPPORTED_MEMORY_MB (UINT64_C (4000 * 1024))
9495

95-
#if GLIB_CHECK_VERSION(2,32,0) && GTK_CHECK_VERSION(3,12,0) /* glib >= 2.32 && gtk >= 3.12 */
96-
#define USE_POPOVERS
97-
#endif
98-
9996
static void create_connection_dialog (struct config *);
10097
static void create_conversion_dialog (struct config *config,
10198
const char * const *disks,
@@ -247,10 +244,8 @@ create_connection_dialog (struct config *config)
247244
password_entry = gtk_entry_new ();
248245
gtk_label_set_mnemonic_widget (GTK_LABEL (password_label), password_entry);
249246
gtk_entry_set_visibility (GTK_ENTRY (password_entry), FALSE);
250-
#ifdef GTK_INPUT_PURPOSE_PASSWORD /* guaranteed if gtk >= 3.5.12 */
251247
gtk_entry_set_input_purpose (GTK_ENTRY (password_entry),
252248
GTK_INPUT_PURPOSE_PASSWORD);
253-
#endif
254249
if (config->auth.password != NULL)
255250
gtk_entry_set_text (GTK_ENTRY (password_entry), config->auth.password);
256251
table_attach (table, password_entry,
@@ -1747,21 +1742,15 @@ static void *start_conversion_thread (void *data);
17471742
static gboolean conversion_error (gpointer user_data);
17481743
static gboolean conversion_finished (gpointer user_data);
17491744
static void cancel_conversion_dialog (GtkWidget *w, gpointer data);
1750-
#ifdef USE_POPOVERS
17511745
static void activate_action (GSimpleAction *action, GVariant *parameter, gpointer user_data);
1752-
#else
1753-
static void shutdown_button_clicked (GtkToolButton *w, gpointer data);
1754-
#endif
17551746
static void shutdown_clicked (GtkWidget *w, gpointer data);
17561747
static void reboot_clicked (GtkWidget *w, gpointer data);
17571748
static gboolean close_running_dialog (GtkWidget *w, GdkEvent *event, gpointer data);
17581749

1759-
#ifdef USE_POPOVERS
17601750
static const GActionEntry shutdown_actions[] = {
17611751
{ .name = "shutdown", .activate = activate_action },
17621752
{ .name = "reboot", .activate = activate_action },
17631753
};
1764-
#endif
17651754

17661755
/**
17671756
* Create the running dialog.
@@ -1777,14 +1766,8 @@ create_running_dialog (void)
17771766
{ "black", "maroon", "green", "olive", "navy", "purple", "teal", "silver",
17781767
"gray", "red", "lime", "yellow", "blue", "fuchsia", "cyan", "white" };
17791768
GtkTextBuffer *buf;
1780-
#ifdef USE_POPOVERS
17811769
GMenu *shutdown_menu;
17821770
GSimpleActionGroup *shutdown_group;
1783-
#else
1784-
GtkWidget *shutdown_menu;
1785-
GtkWidget *shutdown_menu_item;
1786-
GtkWidget *reboot_menu_item;
1787-
#endif
17881771

17891772
run_dlg = gtk_dialog_new ();
17901773
gtk_window_set_title (GTK_WINDOW (run_dlg), g_get_prgname ());
@@ -1810,19 +1793,12 @@ create_running_dialog (void)
18101793
gtk_text_buffer_create_tag (buf, tag_name, "foreground", tags[i], NULL);
18111794
}
18121795

1813-
#if GTK_CHECK_VERSION(3,16,0) /* gtk >= 3.16 */
18141796
/* XXX This only sets the "CSS" style. It's not clear how to set
18151797
* the particular font. However (by accident) this does at least
18161798
* set the widget to use a monospace font.
18171799
*/
18181800
GtkStyleContext *context = gtk_widget_get_style_context (v2v_output);
18191801
gtk_style_context_add_class (context, "monospace");
1820-
#else
1821-
PangoFontDescription *font;
1822-
font = pango_font_description_from_string ("Monospace 11");
1823-
gtk_widget_override_font (v2v_output, font);
1824-
pango_font_description_free (font);
1825-
#endif
18261802

18271803
log_label = gtk_label_new (NULL);
18281804
set_alignment (log_label, 0., 0.5);
@@ -1845,7 +1821,6 @@ create_running_dialog (void)
18451821
status_label, TRUE, TRUE, 0);
18461822

18471823
/* Shutdown popup menu. */
1848-
#ifdef USE_POPOVERS
18491824
shutdown_menu = g_menu_new ();
18501825
g_menu_append (shutdown_menu, _("_Shutdown"), "shutdown.shutdown");
18511826
g_menu_append (shutdown_menu, _("_Reboot"), "shutdown.reboot");
@@ -1854,23 +1829,13 @@ create_running_dialog (void)
18541829
g_action_map_add_action_entries (G_ACTION_MAP (shutdown_group),
18551830
shutdown_actions,
18561831
G_N_ELEMENTS (shutdown_actions), NULL);
1857-
#else
1858-
shutdown_menu = gtk_menu_new ();
1859-
shutdown_menu_item = gtk_menu_item_new_with_mnemonic (_("_Shutdown"));
1860-
gtk_menu_shell_append (GTK_MENU_SHELL (shutdown_menu), shutdown_menu_item);
1861-
gtk_widget_show (shutdown_menu_item);
1862-
reboot_menu_item = gtk_menu_item_new_with_mnemonic (_("_Reboot"));
1863-
gtk_menu_shell_append (GTK_MENU_SHELL (shutdown_menu), reboot_menu_item);
1864-
gtk_widget_show (reboot_menu_item);
1865-
#endif
18661832

18671833
/* Buttons. */
18681834
gtk_dialog_add_buttons (GTK_DIALOG (run_dlg),
18691835
_("_Cancel conversion ..."), 1,
18701836
NULL);
18711837
cancel_button = gtk_dialog_get_widget_for_response (GTK_DIALOG (run_dlg), 1);
18721838
gtk_widget_set_sensitive (cancel_button, FALSE);
1873-
#ifdef USE_POPOVERS
18741839
shutdown_button = gtk_menu_button_new ();
18751840
gtk_button_set_use_underline (GTK_BUTTON (shutdown_button), TRUE);
18761841
gtk_button_set_label (GTK_BUTTON (shutdown_button), _("_Shutdown ..."));
@@ -1880,13 +1845,6 @@ create_running_dialog (void)
18801845
gtk_menu_button_set_use_popover (GTK_MENU_BUTTON (shutdown_button), TRUE);
18811846
gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (shutdown_button),
18821847
G_MENU_MODEL (shutdown_menu));
1883-
#else
1884-
shutdown_button = GTK_WIDGET (gtk_menu_tool_button_new (NULL,
1885-
_("_Shutdown ...")));
1886-
gtk_tool_button_set_use_underline (GTK_TOOL_BUTTON (shutdown_button), TRUE);
1887-
gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (shutdown_button),
1888-
shutdown_menu);
1889-
#endif
18901848
gtk_widget_set_sensitive (shutdown_button, FALSE);
18911849
gtk_dialog_add_action_widget (GTK_DIALOG (run_dlg), shutdown_button, 2);
18921850

@@ -1897,14 +1855,6 @@ create_running_dialog (void)
18971855
G_CALLBACK (gtk_main_quit), NULL);
18981856
g_signal_connect (G_OBJECT (cancel_button), "clicked",
18991857
G_CALLBACK (cancel_conversion_dialog), NULL);
1900-
#ifndef USE_POPOVERS
1901-
g_signal_connect (G_OBJECT (shutdown_button), "clicked",
1902-
G_CALLBACK (shutdown_button_clicked), shutdown_menu);
1903-
g_signal_connect (G_OBJECT (shutdown_menu_item), "activate",
1904-
G_CALLBACK (shutdown_clicked), NULL);
1905-
g_signal_connect (G_OBJECT (reboot_menu_item), "activate",
1906-
G_CALLBACK (reboot_clicked), NULL);
1907-
#endif
19081858
}
19091859

19101860
/**
@@ -2367,7 +2317,6 @@ cancel_conversion_dialog (GtkWidget *w, gpointer data)
23672317
gtk_widget_destroy (dlg);
23682318
}
23692319

2370-
#ifdef USE_POPOVERS
23712320
static void
23722321
activate_action (GSimpleAction *action, GVariant *parameter, gpointer user_data)
23732322
{
@@ -2377,16 +2326,6 @@ activate_action (GSimpleAction *action, GVariant *parameter, gpointer user_data)
23772326
else if (STREQ (action_name, "reboot"))
23782327
reboot_clicked (NULL, user_data);
23792328
}
2380-
#else
2381-
static void
2382-
shutdown_button_clicked (GtkToolButton *w, gpointer data)
2383-
{
2384-
GtkMenu *menu = data;
2385-
2386-
gtk_menu_popup (menu, NULL, NULL, NULL, NULL, 1,
2387-
gtk_get_current_event_time ());
2388-
}
2389-
#endif
23902329

23912330
static void
23922331
shutdown_clicked (GtkWidget *w, gpointer data)

0 commit comments

Comments
 (0)