[frogr] New helper files for GTK compatibility, to avoid if-defs all over the place.



commit 9171c343914dd780dd79c7a086d288f4d323fed0
Author: Mario Sanchez Prada <msanchez igalia com>
Date:   Wed Apr 4 12:46:19 2012 +0200

    New helper files for GTK compatibility, to avoid if-defs all over the place.

 src/Makefile.am             |   18 +++++----
 src/frogr-details-dialog.c  |   78 +++++++++-------------------------------
 src/frogr-gtk-compat.c      |   84 +++++++++++++++++++++++++++++++++++++++++++
 src/frogr-gtk-compat.h      |   39 ++++++++++++++++++++
 src/frogr-settings-dialog.c |   69 +++++++----------------------------
 5 files changed, 164 insertions(+), 124 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 5c9b0d1..47b05e1 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -48,14 +48,10 @@ frogr_SOURCES = \
 	frogr-account.h \
 	frogr-add-tags-dialog.c \
 	frogr-add-tags-dialog.h \
-	frogr-live-entry.c \
-	frogr-live-entry.h \
-	frogr-add-to-set-dialog.c \
-	frogr-add-to-set-dialog.h \
 	frogr-add-to-group-dialog.c \
 	frogr-add-to-group-dialog.h \
-	frogr-photoset.c \
-	frogr-photoset.h \
+	frogr-add-to-set-dialog.c \
+	frogr-add-to-set-dialog.h \
 	frogr-auth-dialog.c \
 	frogr-auth-dialog.h \
 	frogr-config.c \
@@ -69,12 +65,18 @@ frogr_SOURCES = \
 	frogr-global-defs.h \
 	frogr-group.c \
 	frogr-group.h \
+	frogr-gtk-compat.c \
+	frogr-gtk-compat.h \
+	frogr-live-entry.c \
+	frogr-live-entry.h \
+	frogr-location.c \
+	frogr-location.h \
 	frogr-main-view-model.c \
 	frogr-main-view-model.h \
 	frogr-main-view.c \
 	frogr-main-view.h \
-	frogr-location.c \
-	frogr-location.h \
+	frogr-photoset.c \
+	frogr-photoset.h \
 	frogr-picture-loader.c \
 	frogr-picture-loader.h \
 	frogr-picture-uploader.c \
diff --git a/src/frogr-details-dialog.c b/src/frogr-details-dialog.c
index 52d2027..0ae3b6a 100644
--- a/src/frogr-details-dialog.c
+++ b/src/frogr-details-dialog.c
@@ -23,6 +23,7 @@
 #include "frogr-config.h"
 #include "frogr-controller.h"
 #include "frogr-global-defs.h"
+#include "frogr-gtk-compat.h"
 #include "frogr-live-entry.h"
 #include "frogr-picture.h"
 #include "frogr-util.h"
@@ -153,13 +154,8 @@ _create_widgets (FrogrDetailsDialog *self)
 
   main_vbox = gtk_dialog_get_content_area (GTK_DIALOG (self));
 
-#ifdef GTK_API_VERSION_3
-  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
-  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
-#else
-  hbox = gtk_hbox_new (FALSE, 0);
-  vbox = gtk_vbox_new (FALSE, 0);
-#endif
+  hbox = frogr_gtk_compat_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
+  vbox = frogr_gtk_compat_box_new (GTK_ORIENTATION_VERTICAL, 0);
 
   /* Left side (image, radio buttons, checkboxes...) */
 
@@ -183,13 +179,8 @@ _create_widgets (FrogrDetailsDialog *self)
 
   /* Visibility */
 
-#ifdef GTK_API_VERSION_3
-  section_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
-  visibility_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
-#else
-  section_vbox = gtk_vbox_new (FALSE, 6);
-  visibility_vbox = gtk_vbox_new (FALSE, 6);
-#endif
+  section_vbox = frogr_gtk_compat_box_new (GTK_ORIENTATION_VERTICAL, 6);
+  visibility_vbox = frogr_gtk_compat_box_new (GTK_ORIENTATION_VERTICAL, 6);
 
   markup = g_markup_printf_escaped ("<span weight=\"bold\">%s</span>",
                                     _("Visibility"));
@@ -201,11 +192,7 @@ _create_widgets (FrogrDetailsDialog *self)
   gtk_container_add (GTK_CONTAINER (align), widget);
   gtk_box_pack_start (GTK_BOX (section_vbox), align, FALSE, FALSE, 0);
 
-#ifdef GTK_API_VERSION_3
-  internal_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
-#else
-  internal_hbox = gtk_hbox_new (FALSE, 6);
-#endif
+  internal_hbox = frogr_gtk_compat_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
 
   widget = gtk_radio_button_new_with_mnemonic (NULL, _("_Private"));
   gtk_box_pack_start (GTK_BOX (internal_hbox), widget, FALSE, FALSE, 0);
@@ -217,11 +204,7 @@ _create_widgets (FrogrDetailsDialog *self)
 
   gtk_box_pack_start (GTK_BOX (visibility_vbox), internal_hbox, FALSE, FALSE, 0);
 
-#ifdef GTK_API_VERSION_3
-  private_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
-#else
-  private_vbox = gtk_vbox_new (FALSE, 6);
-#endif
+  private_vbox = frogr_gtk_compat_box_new (GTK_ORIENTATION_VERTICAL, 6);
 
   widget = gtk_check_button_new_with_mnemonic (_("Visible to _Family"));
   gtk_box_pack_start (GTK_BOX (private_vbox), widget, FALSE, FALSE, 0);
@@ -231,20 +214,12 @@ _create_widgets (FrogrDetailsDialog *self)
   gtk_box_pack_start (GTK_BOX (private_vbox), widget, FALSE, FALSE, 0);
   priv->friend_cb = widget;
 
-#ifdef GTK_API_VERSION_3
-  internal_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
-#else
-  internal_hbox = gtk_hbox_new (FALSE, 0);
-#endif
+  internal_hbox = frogr_gtk_compat_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
 
   gtk_box_pack_start (GTK_BOX (internal_hbox), private_vbox, FALSE, FALSE, 12);
   gtk_box_pack_start (GTK_BOX (visibility_vbox), internal_hbox, FALSE, FALSE, 0);
 
-#ifdef GTK_API_VERSION_3
-  internal_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
-#else
-  internal_hbox = gtk_hbox_new (FALSE, 0);
-#endif
+  internal_hbox = frogr_gtk_compat_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
 
   gtk_box_pack_start (GTK_BOX (internal_hbox), visibility_vbox, FALSE, FALSE, 0);
   gtk_box_pack_start (GTK_BOX (section_vbox), internal_hbox, FALSE, FALSE, 0);
@@ -261,13 +236,8 @@ _create_widgets (FrogrDetailsDialog *self)
 
   /* Content type */
 
-#ifdef GTK_API_VERSION_3
-  section_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
-  content_type_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
-#else
-  section_vbox = gtk_vbox_new (FALSE, 6);
-  content_type_hbox = gtk_hbox_new (FALSE, 6);
-#endif
+  section_vbox = frogr_gtk_compat_box_new (GTK_ORIENTATION_VERTICAL, 6);
+  content_type_hbox = frogr_gtk_compat_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
 
   markup = g_markup_printf_escaped ("<span weight=\"bold\">%s</span>",
                                     _("Content type"));
@@ -297,13 +267,8 @@ _create_widgets (FrogrDetailsDialog *self)
 
   /* Safety level */
 
-#ifdef GTK_API_VERSION_3
-  section_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
-  safety_level_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
-#else
-  section_vbox = gtk_vbox_new (FALSE, 6);
-  safety_level_hbox = gtk_hbox_new (FALSE, 6);
-#endif
+  section_vbox = frogr_gtk_compat_box_new (GTK_ORIENTATION_VERTICAL, 6);
+  safety_level_hbox = frogr_gtk_compat_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
 
   markup = g_markup_printf_escaped ("<span weight=\"bold\">%s</span>",
                                     _("Safety level"));
@@ -333,11 +298,7 @@ _create_widgets (FrogrDetailsDialog *self)
 
   /* License type */
 
-#ifdef GTK_API_VERSION_3
-  section_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
-#else
-  section_vbox = gtk_vbox_new (FALSE, 6);
-#endif
+  section_vbox = frogr_gtk_compat_box_new (GTK_ORIENTATION_VERTICAL, 6);
 
   markup = g_markup_printf_escaped ("<span weight=\"bold\">%s</span>",
                                     _("License type"));
@@ -349,15 +310,10 @@ _create_widgets (FrogrDetailsDialog *self)
   gtk_container_add (GTK_CONTAINER (align), widget);
   gtk_box_pack_start (GTK_BOX (section_vbox), align, FALSE, FALSE, 0);
 
-#if GTK_CHECK_VERSION (2,24,0)
-  widget = gtk_combo_box_text_new ();
+  widget = frogr_gtk_compat_combo_box_text_new ();
   for (i = 0; license_descriptions[i]; i++)
-    gtk_combo_box_text_insert_text (GTK_COMBO_BOX_TEXT (widget), i, _(license_descriptions[i]));
-#else
-  widget = gtk_combo_box_new_text ();
-  for (i = 0; license_descriptions[i]; i++)
-    gtk_combo_box_insert_text (GTK_COMBO_BOX (widget), i, _(license_descriptions[i]));
-#endif
+    frogr_gtk_compat_combo_box_text_insert (GTK_COMBO_BOX_TEXT (widget), i, _(license_descriptions[i]));
+
   priv->license_cb = widget;
   gtk_box_pack_start (GTK_BOX (section_vbox), widget, FALSE, FALSE, 0);
 
diff --git a/src/frogr-gtk-compat.c b/src/frogr-gtk-compat.c
new file mode 100644
index 0000000..8295965
--- /dev/null
+++ b/src/frogr-gtk-compat.c
@@ -0,0 +1,84 @@
+/*
+ * frogr-gtk-compat.c -- Helper functions for GTK compatibility.
+ *
+ * Copyright (C) 2012 Mario Sanchez Prada
+ * Authors: Mario Sanchez Prada <msanchez igalia com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 3 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * 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 <http://www.gnu.org/licenses/>
+ *
+ */
+
+#include "frogr-gtk-compat.h"
+#include "frogr-global-defs.h"
+
+#include <config.h>
+#include <glib/gi18n.h>
+#include <gtk/gtk.h>
+#include <libexif/exif-byte-order.h>
+#include <libexif/exif-data.h>
+#include <libexif/exif-entry.h>
+#include <libexif/exif-format.h>
+#include <libexif/exif-loader.h>
+#include <libexif/exif-tag.h>
+
+GtkWidget *
+frogr_gtk_compat_box_new (GtkOrientation orientation, gint spacing)
+{
+#ifdef GTK_API_VERSION_3
+  GtkWidget *box = gtk_box_new (orientation, spacing);
+  gtk_box_set_homogeneous (GTK_BOX (box), FALSE);
+  return box;
+#else
+  if (orientation == GTK_ORIENTATION_VERTICAL)
+    return gtk_vbox_new (FALSE, spacing);
+  else
+    return gtk_hbox_new (FALSE, spacing);
+#endif
+}
+
+GtkWidget *
+frogr_gtk_compat_separator_new (GtkOrientation orientation)
+{
+#ifdef GTK_API_VERSION_3
+  return gtk_separator_new (orientation);
+#else
+  if (orientation == GTK_ORIENTATION_VERTICAL)
+    return gtk_vseparator_new ();
+  else
+    return gtk_hseparator_new ();
+#endif
+}
+
+GtkWidget *
+frogr_gtk_compat_combo_box_text_new (void)
+{
+#if GTK_CHECK_VERSION (2,24,0)
+  return gtk_combo_box_text_new ();
+#else
+  return gtk_combo_box_new_text ();
+#endif
+}
+
+void
+frogr_gtk_compat_combo_box_text_insert (GtkComboBoxText *combo_box,
+                                        gint position,
+                                        const gchar *text)
+{
+#ifdef GTK_API_VERSION_3
+  gtk_combo_box_text_insert (combo_box, position, NULL, text);
+#elif GTK_CHECK_VERSION (2,24,0)
+  gtk_combo_box_text_insert_text (combo_box, position, text);
+#else
+  gtk_combo_box_insert_text (combo_box, position, text);
+#endif
+}
diff --git a/src/frogr-gtk-compat.h b/src/frogr-gtk-compat.h
new file mode 100644
index 0000000..dc42ff1
--- /dev/null
+++ b/src/frogr-gtk-compat.h
@@ -0,0 +1,39 @@
+/*
+ * frogr-gtk-compat.h -- Helper functions for GTK compatibility.
+ *
+ * Copyright (C) 2012 Mario Sanchez Prada
+ * Authors: Mario Sanchez Prada <msanchez igalia com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 3 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * 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 <http://www.gnu.org/licenses/>
+ *
+ */
+
+#ifndef FROGR_COMPAT_GTK_H
+#define FROGR_COMPAT_GTK_H
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+GtkWidget *frogr_gtk_compat_box_new (GtkOrientation orientation, gint spacing);
+
+GtkWidget *frogr_gtk_compat_separator_new (GtkOrientation orientation);
+
+GtkWidget *frogr_gtk_compat_combo_box_text_new (void);
+
+void frogr_gtk_compat_combo_box_text_insert (GtkComboBoxText *combo_box,
+                                             gint position,
+                                             const gchar *text);
+G_END_DECLS
+
+#endif /* FROGR_GTK_COMPAT_H */
diff --git a/src/frogr-settings-dialog.c b/src/frogr-settings-dialog.c
index 2077f8a..7d9a7e6 100644
--- a/src/frogr-settings-dialog.c
+++ b/src/frogr-settings-dialog.c
@@ -23,6 +23,7 @@
 #include "frogr-config.h"
 #include "frogr-controller.h"
 #include "frogr-global-defs.h"
+#include "frogr-gtk-compat.h"
 #include "frogr-util.h"
 
 #include <config.h>
@@ -175,11 +176,7 @@ _add_general_page (FrogrSettingsDialog *self, GtkNotebook *notebook)
 
   priv = FROGR_SETTINGS_DIALOG_GET_PRIVATE (self);
 
-#ifdef GTK_API_VERSION_3
-  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
-#else
-  vbox = gtk_vbox_new (FALSE, 6);
-#endif
+  vbox = frogr_gtk_compat_box_new (GTK_ORIENTATION_VERTICAL, 6);
 
   /* Default Visibility */
 
@@ -194,13 +191,8 @@ _add_general_page (FrogrSettingsDialog *self, GtkNotebook *notebook)
   gtk_container_add (GTK_CONTAINER (align), label);
   gtk_box_pack_start (GTK_BOX (vbox), align, FALSE, FALSE, 6);
 
-#ifdef GTK_API_VERSION_3
-  box1 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
-  box2 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
-#else
-  box1 = gtk_vbox_new (FALSE, 6);
-  box2 = gtk_hbox_new (FALSE, 12);
-#endif
+  box1 = frogr_gtk_compat_box_new (GTK_ORIENTATION_VERTICAL, 6);
+  box2 = frogr_gtk_compat_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
 
   _add_toggleable_item (self, GTK_BOX (box2), NULL, TRUE, _("_Private"), &priv->private_rb);
   _add_toggleable_item (self, GTK_BOX (box2), GTK_RADIO_BUTTON (priv->private_rb),
@@ -208,22 +200,14 @@ _add_general_page (FrogrSettingsDialog *self, GtkNotebook *notebook)
 
   gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0);
 
-#ifdef GTK_API_VERSION_3
-  box2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
-#else
-  box2 = gtk_vbox_new (FALSE, 6);
-#endif
+  box2 = frogr_gtk_compat_box_new (GTK_ORIENTATION_VERTICAL, 6);
 
   _add_toggleable_item (self, GTK_BOX (box2), NULL, FALSE,
                         _("Visible to _Family"), &priv->family_cb);
   _add_toggleable_item (self, GTK_BOX (box2), NULL, FALSE,
                         _("Visible to F_riends"), &priv->friend_cb);
 
-#ifdef GTK_API_VERSION_3
-  padding_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
-#else
-  padding_hbox = gtk_hbox_new (FALSE, 0);
-#endif
+  padding_hbox = frogr_gtk_compat_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
 
   gtk_box_pack_start (GTK_BOX (padding_hbox), box2, FALSE, FALSE, 12);
   gtk_box_pack_start (GTK_BOX (box1), padding_hbox, FALSE, FALSE, 0);
@@ -250,11 +234,7 @@ _add_general_page (FrogrSettingsDialog *self, GtkNotebook *notebook)
   gtk_container_add (GTK_CONTAINER (align), label);
   gtk_box_pack_start (GTK_BOX (vbox), align, FALSE, FALSE, 6);
 
-#ifdef GTK_API_VERSION_3
-  box1 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
-#else
-  box1 = gtk_hbox_new (FALSE, 12);
-#endif
+  box1 = frogr_gtk_compat_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
 
   _add_toggleable_item (self, GTK_BOX (box1), NULL, TRUE,
                         _("P_hoto"), &priv->photo_content_rb);
@@ -278,11 +258,7 @@ _add_general_page (FrogrSettingsDialog *self, GtkNotebook *notebook)
   gtk_container_add (GTK_CONTAINER (align), label);
   gtk_box_pack_start (GTK_BOX (vbox), align, FALSE, FALSE, 6);
 
-#ifdef GTK_API_VERSION_3
-  box1 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
-#else
-  box1 = gtk_hbox_new (FALSE, 12);
-#endif
+  box1 = frogr_gtk_compat_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
 
   _add_toggleable_item (self, GTK_BOX (box1), NULL, TRUE,
                         _("S_afe"), &priv->safe_rb);
@@ -306,15 +282,10 @@ _add_general_page (FrogrSettingsDialog *self, GtkNotebook *notebook)
   gtk_container_add (GTK_CONTAINER (align), label);
   gtk_box_pack_start (GTK_BOX (vbox), align, FALSE, FALSE, 6);
 
-#if GTK_CHECK_VERSION (2,24,0)
-  combo = gtk_combo_box_text_new ();
+  combo = frogr_gtk_compat_combo_box_text_new ();
   for (i = 0; license_descriptions[i]; i++)
-    gtk_combo_box_text_insert_text (GTK_COMBO_BOX_TEXT (combo), i, _(license_descriptions[i]));
-#else
-  combo = gtk_combo_box_new_text ();
-  for (i = 0; license_descriptions[i]; i++)
-    gtk_combo_box_insert_text (GTK_COMBO_BOX (combo), i, _(license_descriptions[i]));
-#endif
+    frogr_gtk_compat_combo_box_text_insert (GTK_COMBO_BOX_TEXT (combo), i, _(license_descriptions[i]));
+
   gtk_box_pack_start (GTK_BOX (vbox), combo, FALSE, FALSE, 0);
   priv->license_cb = combo;
 
@@ -340,11 +311,7 @@ _add_connection_page (FrogrSettingsDialog *self, GtkNotebook *notebook)
 
   priv = FROGR_SETTINGS_DIALOG_GET_PRIVATE (self);
 
-#ifdef GTK_API_VERSION_3
-  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
-#else
-  vbox = gtk_vbox_new (FALSE, 6);
-#endif
+  vbox = frogr_gtk_compat_box_new (GTK_ORIENTATION_VERTICAL, 6);
 
   /* Proxy settings */
 
@@ -487,11 +454,7 @@ _add_misc_page (FrogrSettingsDialog *self, GtkNotebook *notebook)
 
   priv = FROGR_SETTINGS_DIALOG_GET_PRIVATE (self);
 
-#ifdef GTK_API_VERSION_3
-  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
-#else
-  vbox = gtk_vbox_new (FALSE, 6);
-#endif
+  vbox = frogr_gtk_compat_box_new (GTK_ORIENTATION_VERTICAL, 6);
 
   /* Other Stuff */
 
@@ -506,11 +469,7 @@ _add_misc_page (FrogrSettingsDialog *self, GtkNotebook *notebook)
   gtk_container_add (GTK_CONTAINER (align), label);
   gtk_box_pack_start (GTK_BOX (vbox), align, FALSE, FALSE, 6);
 
-#ifdef GTK_API_VERSION_3
-  box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
-#else
-  box = gtk_vbox_new (FALSE, 6);
-#endif
+  box = frogr_gtk_compat_box_new (GTK_ORIENTATION_VERTICAL, 6);
 
   _add_toggleable_item (self, GTK_BOX (box), NULL, FALSE,
                         _("Disa_ble Tags Auto-Completion"),



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]