]> Pileus Git - ~andy/gtk/commitdiff
GtkAboutDialog: Make credits section extensible
authorMatthias Clasen <mclasen@redhat.com>
Wed, 25 Jan 2012 23:21:47 +0000 (18:21 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Wed, 25 Jan 2012 23:25:43 +0000 (18:25 -0500)
This commit adds API that allows to add new named sections
to the Credits part of GtkAboutDialog, in addition to the
hardcoded sections for authors, documenters, artists and
translators.

https://bugzilla.gnome.org/show_bug.cgi?id=484693

docs/reference/gtk/gtk3-sections.txt
gtk/gtk.symbols
gtk/gtkaboutdialog.c
gtk/gtkaboutdialog.h

index 41e42a9e18ea8c19a5e71d60f31aee6d8dfb411a..393e274eff3e8be29f15302d6487b59f3415e4aa 100644 (file)
@@ -37,6 +37,7 @@ gtk_about_dialog_get_logo
 gtk_about_dialog_set_logo
 gtk_about_dialog_get_logo_icon_name
 gtk_about_dialog_set_logo_icon_name
+gtk_about_dialog_add_credit_section
 gtk_show_about_dialog
 <SUBSECTION Standard>
 GTK_ABOUT_DIALOG
index 3f377b166dd53b2ffee521e710b3112eb95fcca4..4acba3d6625444c7be7b4000643fe19d1dd6eca5 100644 (file)
@@ -1,6 +1,7 @@
 /* This list defines the GTK+ ABI. It is used to generate the gtk.def
  * file.
  */
+gtk_about_dialog_add_credit_section
 gtk_about_dialog_get_artists
 gtk_about_dialog_get_authors
 gtk_about_dialog_get_comments
index 6d916b61d38f5b28a2678ed5a18df36fb80ca507..a4cc9c33adb6097d922f32880eca9a32f45d54ed 100644 (file)
@@ -122,6 +122,12 @@ static const gchar *gtk_license_urls[] = {
   "http://opensource.org/licenses/artistic-license-2.0.php"
 };
 
+typedef struct
+{
+  gchar *heading;
+  gchar **people;
+} CreditSection;
+
 struct _GtkAboutDialogPrivate 
 {
   gchar *name;
@@ -137,6 +143,9 @@ struct _GtkAboutDialogPrivate
   gchar **documenters;
   gchar **artists;
 
+
+  GSList *credit_sections;
+
   gint credits_page;
   gint license_page;
 
@@ -163,6 +172,8 @@ struct _GtkAboutDialogPrivate
   guint wrap_license : 1;
 };
 
+
+
 #define GTK_ABOUT_DIALOG_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_ABOUT_DIALOG, GtkAboutDialogPrivate))
 
 
@@ -561,6 +572,7 @@ update_credits_button_visibility (GtkAboutDialog *about)
   show = (priv->authors != NULL ||
           priv->documenters != NULL ||
           priv->artists != NULL ||
+          priv->credit_sections != NULL ||
          (priv->translator_credits != NULL &&
           strcmp (priv->translator_credits, "translator_credits") &&
           strcmp (priv->translator_credits, "translator-credits")));
@@ -775,6 +787,15 @@ gtk_about_dialog_init (GtkAboutDialog *about)
   gtk_about_dialog_set_logo (about, NULL);
 }
 
+
+void destroy_credit_section (gpointer data)
+{
+  CreditSection *cs = data;
+  g_free (cs->heading);
+  g_strfreev (cs->people);
+  g_slice_free (CreditSection, data);
+}
+
 static void
 gtk_about_dialog_finalize (GObject *object)
 {
@@ -794,6 +815,8 @@ gtk_about_dialog_finalize (GObject *object)
   g_strfreev (priv->documenters);
   g_strfreev (priv->artists);
 
+  g_slist_free_full (priv->credit_sections, destroy_credit_section);
+
   g_slist_foreach (priv->visited_links, (GFunc)g_free, NULL);
   g_slist_free (priv->visited_links);
 
@@ -2393,6 +2416,16 @@ create_credits_page (GtkAboutDialog *about)
   if (priv->artists != NULL)
     add_credits_section (about, GTK_GRID (grid), &row, _("Artwork by"), priv->artists);
 
+  if (priv->credit_sections != NULL)
+    {
+      GSList *cs;
+      for (cs = priv->credit_sections; cs != NULL; cs = cs->next)
+       {
+         CreditSection *section = cs->data;
+         add_credits_section (about, GTK_GRID (grid), &row, section->heading, section->people);
+       }
+    }
+
   gtk_widget_show_all (sw);
 }
 
@@ -2627,3 +2660,35 @@ gtk_about_dialog_get_license_type (GtkAboutDialog *about)
 
   return about->priv->license_type;
 }
+
+/**
+ * gtk_about_dialog_add_credit_section:
+ * @about: A #GtkAboutDialog
+ * @section_name: The name of the section
+ * @people: The people who belong to that section
+ *
+ * Creates a new section in the Credits page.
+ *
+ * Since: 3.4
+ */
+void
+gtk_about_dialog_add_credit_section (GtkAboutDialog  *about,
+                                     const gchar     *section_name,
+                                     const gchar    **people)
+{
+  GtkAboutDialogPrivate *priv;
+  CreditSection *new_entry;
+
+  g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
+  g_return_if_fail (section_name != NULL);
+  g_return_if_fail (people != NULL);
+
+  priv = about->priv;
+
+  new_entry = g_slice_new (CreditSection);
+  new_entry->heading = g_strdup ((gchar *)section_name);
+  new_entry->people = g_strdupv ((gchar **)people);
+
+  priv->credit_sections = g_slist_append (priv->credit_sections, new_entry);
+  update_credits_button_visibility (about);
+}
index 68c24d7b40e5b289d877d4d973f9a9ae29cfbccf..b174294fb3bfbacc17a19484dfb41747f75bcd8c 100644 (file)
@@ -159,6 +159,9 @@ void                   gtk_about_dialog_set_logo               (GtkAboutDialog
 const gchar *          gtk_about_dialog_get_logo_icon_name     (GtkAboutDialog  *about);
 void                   gtk_about_dialog_set_logo_icon_name     (GtkAboutDialog  *about,
                                                                 const gchar     *icon_name);
+void                  gtk_about_dialog_add_credit_section      (GtkAboutDialog  *about,
+                                                                const gchar     *section_name,
+                                                                const gchar    **people);
 
 G_END_DECLS