gtkaboutdialog.c 58.6 KB
Newer Older
Matthias Clasen's avatar
Matthias Clasen committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/* GTK - The GIMP Toolkit
 * Copyright (C) 2001 CodeFactory AB
 * Copyright (C) 2001, 2002 Anders Carlsson
 * Copyright (C) 2003, 2004 Matthias Clasen <mclasen@redhat.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public 
 * License as published by the Free Software Foundation; either 
 * version 2 of the License, or (at your option) any later version.
 *
 * This library 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
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the 
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

/*
23
 * Author: Anders Carlsson <andersca@gnome.org>
Matthias Clasen's avatar
Matthias Clasen committed
24 25 26 27 28 29 30 31 32 33 34
 *
 * Modified by the GTK+ Team and others 1997-2004.  See the AUTHORS
 * file for a list of people on the GTK+ Team.  See the ChangeLog
 * files for a list of changes.  These files are distributed with
 * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
 */

#include <config.h>

#include <gdk/gdkkeysyms.h>

35 36 37
#include "gtkalias.h"

#include "gtkaboutdialog.h"
Matthias Clasen's avatar
Matthias Clasen committed
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
#include "gtkbutton.h"
#include "gtkbbox.h"
#include "gtkdialog.h"
#include "gtkhbox.h"
#include "gtkimage.h"
#include "gtklabel.h"
#include "gtkmarshalers.h"
#include "gtknotebook.h"
#include "gtkscrolledwindow.h"
#include "gtkstock.h"
#include "gtktextview.h"
#include "gtkvbox.h"
#include "gtkviewport.h"
#include "gtkiconfactory.h"
#include "gtkintl.h"

#include <string.h>

typedef struct _GtkAboutDialogPrivate GtkAboutDialogPrivate;
struct _GtkAboutDialogPrivate 
{
  gchar *name;
  gchar *version;
  gchar *copyright;
  gchar *comments;
  gchar *website;
  gchar *website_label;
  gchar *translator_credits;
  gchar *license;
  
  gchar **authors;
  gchar **documenters;
  gchar **artists;
  
  GtkWidget *logo_image;
  GtkWidget *name_label;
  GtkWidget *comments_label;
  GtkWidget *copyright_label;
  GtkWidget *website_button;

  GtkWidget *credits_button;
  GtkWidget *credits_dialog;
  GtkWidget *license_button;
  GtkWidget *license_dialog;
  
  GdkCursor *hand_cursor;
  GdkCursor *regular_cursor;
  gboolean hovering_over_link;
};

#define GTK_ABOUT_DIALOG_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_ABOUT_DIALOG, GtkAboutDialogPrivate))


enum 
{
  PROP_0,
  PROP_NAME,
  PROP_VERSION,
  PROP_COPYRIGHT,
  PROP_COMMENTS,
  PROP_WEBSITE,
  PROP_WEBSITE_LABEL,
  PROP_LICENSE,
  PROP_AUTHORS,
  PROP_DOCUMENTERS,
  PROP_TRANSLATOR_CREDITS,
  PROP_ARTISTS,
105 106
  PROP_LOGO,
  PROP_LOGO_ICON_NAME
Matthias Clasen's avatar
Matthias Clasen committed
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
};

static void                 gtk_about_dialog_finalize       (GObject            *object);
static void                 gtk_about_dialog_get_property   (GObject            *object,
							     guint               prop_id,
							     GValue             *value,
							     GParamSpec         *pspec);
static void                 gtk_about_dialog_set_property   (GObject            *object,
							     guint               prop_id,
							     const GValue       *value,
							     GParamSpec         *pspec);
static void                 update_name_version             (GtkAboutDialog     *about);
static GtkIconSet *         icon_set_new_from_pixbufs       (GList              *pixbufs);
static void                 activate_url                    (GtkWidget          *widget,
							     gpointer            data);
static void                 set_link_button_text            (GtkWidget          *about,
							     GtkWidget          *button,
							     gchar              *text);
static GtkWidget *          create_link_button              (GtkWidget          *about,
							     gchar              *text,
							     gchar              *url,
							     GCallback           callback,
							     gpointer            data);
static void                 follow_if_link                  (GtkAboutDialog     *about,
							     GtkTextIter        *iter);
static void                 set_cursor_if_appropriate       (GtkAboutDialog     *about,
							     GtkTextView        *text_view,
							     gint                x,
							     gint                y);
static void                 add_credits_page                (GtkAboutDialog     *about,
							     GtkWidget          *notebook,
							     gchar              *title,
							     gchar             **people);
static gboolean             credits_key_press_event         (GtkWidget          *text_view,
							     GdkEventKey        *event,
							     GtkAboutDialog     *about);
static gboolean             credits_event_after             (GtkWidget          *text_view,
							     GdkEvent           *event,
							     GtkAboutDialog     *about);
static gboolean             credits_motion_notify_event     (GtkWidget          *text_view,
							     GdkEventMotion     *event,
							     GtkAboutDialog     *about);
static gboolean             credits_visibility_notify_event (GtkWidget          *text_view,
							     GdkEventVisibility *event,
							     GtkAboutDialog     *about);
static void                 display_credits_dialog          (GtkWidget          *button,
							     gpointer            data);
static void                 display_license_dialog          (GtkWidget          *button,
							     gpointer            data);
				 
				 				       
static GtkAboutDialogActivateLinkFunc activate_email_hook = NULL;
159 160 161
static gpointer activate_email_hook_data = NULL;
static GDestroyNotify activate_email_hook_destroy = NULL;

Matthias Clasen's avatar
Matthias Clasen committed
162
static GtkAboutDialogActivateLinkFunc activate_url_hook = NULL;
163 164
static gpointer activate_url_hook_data = NULL;
static GDestroyNotify activate_url_hook_destroy = NULL;
Matthias Clasen's avatar
Matthias Clasen committed
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183

G_DEFINE_TYPE (GtkAboutDialog, gtk_about_dialog, GTK_TYPE_DIALOG);

static void
gtk_about_dialog_class_init (GtkAboutDialogClass *klass)
{
  GObjectClass *object_class;
  GtkWidgetClass *widget_class;
  GtkDialogClass *dialog_class;
	
  object_class = (GObjectClass *)klass;
  widget_class = (GtkWidgetClass *)klass;
  dialog_class = (GtkDialogClass *)klass;
	
  object_class->set_property = gtk_about_dialog_set_property;
  object_class->get_property = gtk_about_dialog_get_property;

  object_class->finalize = gtk_about_dialog_finalize;

Matthias Clasen's avatar
Matthias Clasen committed
184 185 186 187 188 189 190 191
  /**
   * GtkAboutDialog:name:
   *
   * The name of the program. 
   * If this is not set, it defaults to g_get_application_name().
   *
   * Since: 2.6
   */  
Matthias Clasen's avatar
Matthias Clasen committed
192 193 194 195 196 197 198 199
  g_object_class_install_property (object_class,
				   PROP_NAME,
				   g_param_spec_string ("name",
							P_("Program name"),
							P_("The name of the program. If this is not set, it defaults to g_get_application_name()"),
							NULL,
							G_PARAM_READWRITE));

Matthias Clasen's avatar
Matthias Clasen committed
200 201 202 203 204 205 206
  /**
   * GtkAboutDialog:version:
   *
   * The version of the program. 
   *
   * Since: 2.6
   */  
Matthias Clasen's avatar
Matthias Clasen committed
207 208 209 210 211 212 213
  g_object_class_install_property (object_class,
				   PROP_VERSION,
				   g_param_spec_string ("version",
							P_("Program version"),
							P_("The version of the program"),
							NULL,
							G_PARAM_READWRITE));
Matthias Clasen's avatar
Matthias Clasen committed
214 215 216 217 218 219 220 221

  /**
   * GtkAboutDialog:copyright:
   *
   * Copyright information for the program. 
   *
   * Since: 2.6
   */  
Matthias Clasen's avatar
Matthias Clasen committed
222 223 224 225 226 227 228 229
  g_object_class_install_property (object_class,
				   PROP_COPYRIGHT,
				   g_param_spec_string ("copyright",
							P_("Copyright string"),
							P_("Copyright information for the program"),
							NULL,
							G_PARAM_READWRITE));
	
Matthias Clasen's avatar
Matthias Clasen committed
230 231 232 233 234 235 236 237 238 239

  /**
   * GtkAboutDialog:comments:
   *
   * Comments about the program. This string is displayed in a label 
   * in the main dialog, thus it should be a short explanation of
   * the main purpose of the program, not a detailed list of features.
   *
   * Since: 2.6
   */  
Matthias Clasen's avatar
Matthias Clasen committed
240 241 242 243 244 245 246
  g_object_class_install_property (object_class,
				   PROP_COMMENTS,
				   g_param_spec_string ("comments",
							P_("Comments string"),
							P_("Comments about the program"),
							NULL,
							G_PARAM_READWRITE));
Matthias Clasen's avatar
Matthias Clasen committed
247 248 249 250 251 252 253 254 255 256

  /**
   * GtkAboutDialog:license:
   *
   * The license of the program. This string is displayed in a 
   * text view in a secondary dialog, therefore it is fine to use
   * a long multi-paragraph text.
   *
   * Since: 2.6
   */  
Matthias Clasen's avatar
Matthias Clasen committed
257 258 259 260 261 262 263 264
  g_object_class_install_property (object_class,
				   PROP_LICENSE,
				   g_param_spec_string ("license",
							_("License"),
							_("The license of the program"),
							NULL,
							G_PARAM_READWRITE));

Matthias Clasen's avatar
Matthias Clasen committed
265 266 267 268 269 270 271 272
  /**
   * GtkAboutDialog:website:
   *
   * The URL for the link to the website of the program. 
   * This should be a string starting with "http://.
   *
   * Since: 2.6
   */  
Matthias Clasen's avatar
Matthias Clasen committed
273 274 275 276 277 278 279 280
  g_object_class_install_property (object_class,
				   PROP_WEBSITE,
				   g_param_spec_string ("website",
							P_("Website URL"),
							P_("The URL for the link to the website of the program"),
							NULL,
							G_PARAM_READWRITE));

Matthias Clasen's avatar
Matthias Clasen committed
281 282 283 284 285 286 287 288 289
  /**
   * GtkAboutDialog:website-label:
   *
   * The label for the link to the website of the program. If this is not set, 
   * it defaults to the URL specified in the 
   * <link linkend="GtkAboutDialog--website">website</link> property.
   *
   * Since: 2.6
   */  
Matthias Clasen's avatar
Matthias Clasen committed
290 291 292 293 294 295 296 297
  g_object_class_install_property (object_class,
				   PROP_WEBSITE_LABEL,
				   g_param_spec_string ("website_label",
							P_("Website label"),
							P_("The label for the link to the website of the program. If this is not set, it defaults to the URL"),
							NULL,
							G_PARAM_READWRITE));

Matthias Clasen's avatar
Matthias Clasen committed
298 299 300 301 302 303 304 305 306
  /**
   * GtkAboutDialog:authors:
   *
   * The authors of the program, as a %NULL-terminated array of strings.
   * Each string may contain email addresses and URLs, which will be displayed
   * as links, see the introduction for more details.
   *
   * Since: 2.6
   */  
Matthias Clasen's avatar
Matthias Clasen committed
307 308 309 310
  g_object_class_install_property (object_class,
				   PROP_AUTHORS,
				   g_param_spec_boxed ("authors",
						       P_("Authors"),
Matthias Clasen's avatar
Matthias Clasen committed
311
						       P_("List of authors of the program"),
Matthias Clasen's avatar
Matthias Clasen committed
312 313
						       G_TYPE_STRV,
						       G_PARAM_READWRITE));
Matthias Clasen's avatar
Matthias Clasen committed
314 315 316 317 318 319 320 321 322 323

  /**
   * GtkAboutDialog:documenters:
   *
   * The people documenting the program, as a %NULL-terminated array of strings.
   * Each string may contain email addresses and URLs, which will be displayed
   * as links, see the introduction for more details.
   *
   * Since: 2.6
   */  
Matthias Clasen's avatar
Matthias Clasen committed
324 325 326 327 328 329 330 331
  g_object_class_install_property (object_class,
				   PROP_DOCUMENTERS,
				   g_param_spec_boxed ("documenters",
						       P_("Documenters"),
						       P_("List of people documenting the program"),
						       G_TYPE_STRV,
						       G_PARAM_READWRITE));

Matthias Clasen's avatar
Matthias Clasen committed
332 333 334 335 336 337 338 339 340
  /**
   * GtkAboutDialog:artists:
   *
   * The people who contributed artwork to the program, as a %NULL-terminated array of strings.
   * Each string may contain email addresses and URLs, which will be displayed
   * as links, see the introduction for more details.
   *
   * Since: 2.6
   */  
Matthias Clasen's avatar
Matthias Clasen committed
341 342 343 344 345 346 347 348
  g_object_class_install_property (object_class,
				   PROP_ARTISTS,
				   g_param_spec_boxed ("artists",
						       P_("Artists"),
						       P_("List of people who have contributed artwork to the program"),
						       G_TYPE_STRV,
						       G_PARAM_READWRITE));

Matthias Clasen's avatar
Matthias Clasen committed
349 350 351 352 353 354 355 356 357 358

  /**
   * GtkAboutDialog:translator-credits:
   *
   * Credits to the translators. This string should be marked as translatable.
   * The string may contain email addresses and URLs, which will be displayed
   * as links, see the introduction for more details.
   *
   * Since: 2.6
   */  
Matthias Clasen's avatar
Matthias Clasen committed
359 360 361 362 363 364 365 366
  g_object_class_install_property (object_class,
				   PROP_TRANSLATOR_CREDITS,
				   g_param_spec_string ("translator_credits",
							P_("Translator credits"),
							P_("Credits to the translators. This string should be marked as translatable"),
							NULL,
							G_PARAM_READWRITE));
	
Matthias Clasen's avatar
Matthias Clasen committed
367 368 369 370 371 372 373 374
  /**
   * GtkAboutDialog:logo:
   *
   * A logo for the about box. If this is not set, it defaults to 
   * gtk_window_get_default_icon_list().
   *
   * Since: 2.6
   */  
Matthias Clasen's avatar
Matthias Clasen committed
375 376 377 378 379 380 381 382
  g_object_class_install_property (object_class,
				   PROP_LOGO,
				   g_param_spec_object ("logo",
							P_("Logo"),
							P_("A logo for the about box. If this is not set, it defaults to gtk_window_get_default_icon_list()"),
							GDK_TYPE_PIXBUF,
							G_PARAM_READWRITE));

Matthias Clasen's avatar
Matthias Clasen committed
383 384 385 386 387 388 389 390
  /**
   * GtkAboutDialog:logo-icon-name:
   *
   * A named icon to use as the logo for the about box. This property
   * overrides the <link linkend="GtkAboutDialog--logo">logo</link> property.
   *
   * Since: 2.6
   */  
391 392 393 394 395 396 397 398
  g_object_class_install_property (object_class,
				   PROP_LOGO_ICON_NAME,
				   g_param_spec_string ("logo_icon_name",
							P_("Logo Icon Name"),
							P_("A named icon to use as the logo for the about box."),
							NULL,
							G_PARAM_READWRITE));

Matthias Clasen's avatar
Matthias Clasen committed
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426
  /* Style properties */
  gtk_widget_class_install_style_property (widget_class,
                                           g_param_spec_boxed ("link_color",
                                                               P_("Link Color"),
                                                               P_("Color of hyperlinks"),
                                                               GDK_TYPE_COLOR,
                                                               G_PARAM_READABLE));

  g_type_class_add_private (object_class, sizeof (GtkAboutDialogPrivate));
}

static void
gtk_about_dialog_init (GtkAboutDialog *about)
{
  GtkAboutDialogPrivate *priv;
  GtkWidget *vbox, *hbox, *button;

  /* Data */
  priv = GTK_ABOUT_DIALOG_GET_PRIVATE (about);
  about->private_data = priv;

  priv->name = NULL;
  priv->version = NULL;
  priv->copyright = NULL;
  priv->comments = NULL;
  priv->website = NULL;
  priv->website_label = NULL;
  priv->translator_credits = NULL;
427
  priv->license = NULL;
Matthias Clasen's avatar
Matthias Clasen committed
428 429 430 431 432 433 434 435
  priv->authors = NULL;
  priv->documenters = NULL;
  priv->artists = NULL;

  priv->hand_cursor = gdk_cursor_new (GDK_HAND2);
  priv->regular_cursor = gdk_cursor_new (GDK_XTERM);
  priv->hovering_over_link = FALSE;

436 437
  gtk_dialog_set_has_separator (GTK_DIALOG (about), FALSE);
  
Matthias Clasen's avatar
Matthias Clasen committed
438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477
  /* Widgets */
  gtk_widget_push_composite_child ();
  vbox = gtk_vbox_new (FALSE, 8);
  gtk_container_set_border_width (GTK_CONTAINER (vbox), 8);

  gtk_box_pack_start (GTK_BOX (GTK_DIALOG (about)->vbox), vbox, TRUE, TRUE, 0);

  priv->logo_image = gtk_image_new ();
  gtk_box_pack_start (GTK_BOX (vbox), priv->logo_image, FALSE, FALSE, 0);

  priv->name_label = gtk_label_new (NULL);
  gtk_label_set_selectable (GTK_LABEL (priv->name_label), TRUE);
  gtk_label_set_justify (GTK_LABEL (priv->name_label), GTK_JUSTIFY_CENTER);
  gtk_box_pack_start (GTK_BOX (vbox), priv->name_label, FALSE, FALSE, 0);

  priv->comments_label = gtk_label_new (NULL);
  gtk_label_set_selectable (GTK_LABEL (priv->comments_label), TRUE);
  gtk_label_set_justify (GTK_LABEL (priv->comments_label), GTK_JUSTIFY_CENTER);
  gtk_label_set_line_wrap (GTK_LABEL (priv->comments_label), TRUE);
  gtk_box_pack_start (GTK_BOX (vbox), priv->comments_label, FALSE, FALSE, 0);

  priv->copyright_label = gtk_label_new (NULL);
  gtk_label_set_selectable (GTK_LABEL (priv->copyright_label), TRUE);	
  gtk_label_set_justify (GTK_LABEL (priv->copyright_label), GTK_JUSTIFY_CENTER);
  gtk_box_pack_start (GTK_BOX (vbox), priv->copyright_label, FALSE, FALSE, 0);

  button = create_link_button (GTK_WIDGET (about), "", "", 
			       G_CALLBACK (activate_url), about);

  hbox = gtk_hbox_new (TRUE, 0);
  gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
  gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, FALSE, 0); 
  priv->website_button = button;
  
  gtk_widget_show (vbox);
  gtk_widget_show (priv->logo_image);
  gtk_widget_show (priv->name_label);
  gtk_widget_show (hbox);

  /* Add the OK button */
478 479
  gtk_dialog_add_button (GTK_DIALOG (about), GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
  gtk_dialog_set_default_response (GTK_DIALOG (about), GTK_RESPONSE_CLOSE);
Matthias Clasen's avatar
Matthias Clasen committed
480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522

  /* Add the credits button */
  button = gtk_button_new_from_stock (_("_Credits"));
  gtk_box_pack_end (GTK_BOX (GTK_DIALOG (about)->action_area), 
		    button, FALSE, TRUE, 0); 
  gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (GTK_DIALOG (about)->action_area), button, TRUE);
  g_signal_connect (button, "clicked", G_CALLBACK (display_credits_dialog), about);
  priv->credits_button = button;
  priv->credits_dialog = NULL;

  /* Add the license button */
  button = gtk_button_new_from_stock (_("_License"));
  gtk_box_pack_end (GTK_BOX (GTK_DIALOG (about)->action_area), 
		    button, FALSE, TRUE, 0); 
  gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (GTK_DIALOG (about)->action_area), button, TRUE);
  g_signal_connect (button, "clicked", G_CALLBACK (display_license_dialog), about);
  priv->license_button = button;
  priv->license_dialog = NULL;

  gtk_window_set_resizable (GTK_WINDOW (about), FALSE);

  gtk_widget_pop_composite_child ();
}

static void
gtk_about_dialog_finalize (GObject *object)
{
  GtkAboutDialog *about = GTK_ABOUT_DIALOG (object);
  GtkAboutDialogPrivate *priv = (GtkAboutDialogPrivate *)about->private_data;

  g_free (priv->name);
  g_free (priv->version);
  g_free (priv->copyright);
  g_free (priv->comments);
  g_free (priv->license);
  g_free (priv->website);
  g_free (priv->website_label);
  g_free (priv->translator_credits);

  g_strfreev (priv->authors);
  g_strfreev (priv->documenters);
  g_strfreev (priv->artists);

523 524 525
  gdk_cursor_unref (priv->hand_cursor);
  gdk_cursor_unref (priv->regular_cursor);

Matthias Clasen's avatar
Matthias Clasen committed
526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563
  G_OBJECT_CLASS (gtk_about_dialog_parent_class)->finalize (object);
}

static void
gtk_about_dialog_set_property (GObject      *object, 
			       guint         prop_id, 
			       const GValue *value, 
			       GParamSpec   *pspec)
{
  GtkAboutDialog *about = GTK_ABOUT_DIALOG (object);

  switch (prop_id) 
    {
    case PROP_NAME:
      gtk_about_dialog_set_name (about, g_value_get_string (value));
      break;
    case PROP_VERSION:
      gtk_about_dialog_set_version (about, g_value_get_string (value));
      break;
    case PROP_COMMENTS:
      gtk_about_dialog_set_comments (about, g_value_get_string (value));
      break;
    case PROP_WEBSITE:
      gtk_about_dialog_set_website (about, g_value_get_string (value));
      break;
    case PROP_WEBSITE_LABEL:
      gtk_about_dialog_set_website_label (about, g_value_get_string (value));
      break;
    case PROP_LICENSE:
      gtk_about_dialog_set_license (about, g_value_get_string (value));
      break;
    case PROP_COPYRIGHT:
      gtk_about_dialog_set_copyright (about, g_value_get_string (value));
      break;
    case PROP_LOGO:
      gtk_about_dialog_set_logo (about, g_value_get_object (value));
      break; 
    case PROP_AUTHORS:
564
      gtk_about_dialog_set_authors (about, (const gchar**)g_value_get_boxed (value));
Matthias Clasen's avatar
Matthias Clasen committed
565 566
      break;
    case PROP_DOCUMENTERS:
567
      gtk_about_dialog_set_documenters (about, (const gchar**)g_value_get_boxed (value));
Matthias Clasen's avatar
Matthias Clasen committed
568 569
      break;	
    case PROP_ARTISTS:
570
      gtk_about_dialog_set_artists (about, (const gchar**)g_value_get_boxed (value));
Matthias Clasen's avatar
Matthias Clasen committed
571 572 573 574
      break;	
    case PROP_TRANSLATOR_CREDITS:
      gtk_about_dialog_set_translator_credits (about, g_value_get_string (value));
      break;
575 576 577
    case PROP_LOGO_ICON_NAME:
      gtk_about_dialog_set_logo_icon_name (about, g_value_get_string (value));
      break;
Matthias Clasen's avatar
Matthias Clasen committed
578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
    }
}

static void
gtk_about_dialog_get_property (GObject    *object, 
			       guint       prop_id, 
			       GValue     *value, 
			       GParamSpec *pspec)
{
  GtkAboutDialog *about = GTK_ABOUT_DIALOG (object);
  GtkAboutDialogPrivate *priv = (GtkAboutDialogPrivate *)about->private_data;
	
  switch (prop_id) 
    {
    case PROP_NAME:
      g_value_set_string (value, priv->name);
      break;
    case PROP_VERSION:
      g_value_set_string (value, priv->version);
      break;
    case PROP_COPYRIGHT:
      g_value_set_string (value, priv->copyright);
      break;
    case PROP_COMMENTS:
      g_value_set_string (value, priv->comments);
      break;
    case PROP_WEBSITE:
      g_value_set_string (value, priv->website);
      break;
    case PROP_WEBSITE_LABEL:
      g_value_set_string (value, priv->website_label);
      break;
    case PROP_LICENSE:
      g_value_set_string (value, priv->license);
      break;
    case PROP_TRANSLATOR_CREDITS:
      g_value_set_string (value, priv->translator_credits);
      break;
    case PROP_AUTHORS:
      g_value_set_boxed (value, priv->authors);
      break;
    case PROP_DOCUMENTERS:
      g_value_set_boxed (value, priv->documenters);
      break;
    case PROP_ARTISTS:
      g_value_set_boxed (value, priv->artists);
      break;
    case PROP_LOGO:
629 630 631 632 633 634 635 636
      if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_PIXBUF)
	g_value_set_object (value, gtk_image_get_pixbuf (GTK_IMAGE (priv->logo_image)));
      else
	g_value_set_object (value, NULL);
      break;
    case PROP_LOGO_ICON_NAME:
      if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_ICON_NAME)
	{
Matthias Clasen's avatar
Matthias Clasen committed
637
	  const gchar *icon_name;
638 639 640 641 642 643

	  gtk_image_get_icon_name (GTK_IMAGE (priv->logo_image), &icon_name, NULL);
	  g_value_set_string (value, icon_name);
	}
      else
	g_value_set_string (value, NULL);
Matthias Clasen's avatar
Matthias Clasen committed
644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
    }
}

/**
 * gtk_about_dialog_get_name:
 * @about: a #GtkAboutDialog
 * 
 * Returns the program name displayed in the about dialog.
 * 
 * Return value: The program name. The string is owned by the about
 *  dialog and must not be modified.
 *
 * Since: 2.6
 **/
G_CONST_RETURN gchar *
gtk_about_dialog_get_name (GtkAboutDialog *about)
{
  GtkAboutDialogPrivate *priv;
  
  g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);

  priv = (GtkAboutDialogPrivate *)about->private_data;

  return priv->name;
}

static void
update_name_version (GtkAboutDialog *about)
{
  GtkAboutDialogPrivate *priv;
  gchar *title_string, *name_string;

  priv = (GtkAboutDialogPrivate *)about->private_data;

  title_string = g_strdup_printf (_("About %s"), priv->name);
  gtk_window_set_title (GTK_WINDOW (about), title_string);
  g_free (title_string);

  if (priv->version != NULL) 
    name_string = g_markup_printf_escaped ("<span size=\"xx-large\" weight=\"bold\">%s %s</span>", 
					     priv->name, priv->version);
  else
    name_string = g_markup_printf_escaped ("<span size=\"xx-large\" weight=\"bold\">%s</span>", 
					   priv->name);

  gtk_label_set_markup (GTK_LABEL (priv->name_label), name_string);

  g_free (name_string);
}

/**
 * gtk_about_dialog_set_name:
 * @about: a #GtkAboutDialog
 * @name: the program name
 *
 * Sets the name to display in the about dialog. 
 * If this is not set, it defaults to g_get_application_name().
 * 
 * Since: 2.6
 **/
void
gtk_about_dialog_set_name (GtkAboutDialog *about, 
			   const gchar    *name)
{
  GtkAboutDialogPrivate *priv;
  gchar *tmp;

  g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
	
  priv = (GtkAboutDialogPrivate *)about->private_data;
  tmp = priv->name;
  priv->name = g_strdup (name ? name : g_get_application_name ());
  g_free (tmp);

  update_name_version (about);

  g_object_notify (G_OBJECT (about), "name");
}

/**
 * gtk_about_dialog_get_version:
 * @about: a #GtkAboutDialog
 * 
 * Returns the version string.
 * 
 * Return value: The version string. The string is owned by the about
 *  dialog and must not be modified.
 *
 * Since: 2.6
 **/
G_CONST_RETURN gchar *
gtk_about_dialog_get_version (GtkAboutDialog *about)
{
  GtkAboutDialogPrivate *priv;
  
  g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);

  priv = (GtkAboutDialogPrivate *)about->private_data;

  return priv->version;
}

/**
 * gtk_about_dialog_set_version:
 * @about: a #GtkAboutDialog
 * @version: the version string 
 *
 * Sets the version string to display in the about dialog.
 * 
 * Since: 2.6
 **/
void
gtk_about_dialog_set_version (GtkAboutDialog *about, 
			      const gchar    *version)
{
  GtkAboutDialogPrivate *priv;
  gchar *tmp;

  g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));

  priv = (GtkAboutDialogPrivate *)about->private_data;
  
  tmp = priv->version;
  priv->version = version ? g_strdup (version) : NULL;
  g_free (tmp);

  update_name_version (about);

  g_object_notify (G_OBJECT (about), "version");
}

/**
 * gtk_about_dialog_get_copyright:
 * @about: a #GtkAboutDialog
 * 
 * Returns the copyright string.
 * 
 * Return value: The copyright string. The string is owned by the about
 *  dialog and must not be modified.
 *
 * Since: 2.6
 **/
G_CONST_RETURN gchar *
gtk_about_dialog_get_copyright (GtkAboutDialog *about)
{
  GtkAboutDialogPrivate *priv;
  
  g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);

  priv = (GtkAboutDialogPrivate *)about->private_data;

  return priv->copyright;
}

/**
 * gtk_about_dialog_set_copyright:
 * @about: a #GtkAboutDialog
 * @copyright: the copyright string
 * 
 * Sets the copyright string to display in the about dialog.
 * This should be a short string of one or two lines. 
 *
 * Since: 2.6
 **/
void
gtk_about_dialog_set_copyright (GtkAboutDialog *about, 
				const gchar    *copyright)
{
  GtkAboutDialogPrivate *priv;
  gchar *copyright_string, *tmp;

  g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));

  priv = (GtkAboutDialogPrivate *)about->private_data;
	
  tmp = priv->copyright;
  priv->copyright = copyright ? g_strdup (copyright) : NULL;
  g_free (tmp);
  
  if (priv->copyright != NULL) 
    {
      copyright_string = g_markup_printf_escaped ("<span size=\"small\">%s</span>", 
						  priv->copyright);
      gtk_label_set_markup (GTK_LABEL (priv->copyright_label), copyright_string);
      g_free (copyright_string);
  
      gtk_widget_show (priv->copyright_label);
    }
  else 
    gtk_widget_hide (priv->copyright_label);
  
  g_object_notify (G_OBJECT (about), "copyright");
}

/**
 * gtk_about_dialog_get_comments:
 * @about: a #GtkAboutDialog
 * 
 * Returns the comments string.
 * 
 * Return value: The comments. The string is owned by the about
 *  dialog and must not be modified.
 *
 * Since: 2.6
 **/
G_CONST_RETURN gchar *
gtk_about_dialog_get_comments (GtkAboutDialog *about)
{
  GtkAboutDialogPrivate *priv;
  
  g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);

  priv = (GtkAboutDialogPrivate *)about->private_data;

  return priv->comments;
}

/**
 * gtk_about_dialog_set_comments:
 * @about: a #GtkAboutDialog
 * @comments: a comments string
 * 
 * Sets the comments string to display in the about 
 * dialog. This should be a short string of one or
 * two lines.
 *
 * Since: 2.6
 **/
void
gtk_about_dialog_set_comments (GtkAboutDialog *about, 
			       const gchar    *comments)
{
  GtkAboutDialogPrivate *priv;
  gchar *tmp;

  g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));

  priv = (GtkAboutDialogPrivate *)about->private_data;
  
  tmp = priv->comments;
  if (comments) 
    {
      priv->comments = g_strdup (comments);
      gtk_label_set_text (GTK_LABEL (priv->comments_label), priv->comments);
      gtk_widget_show (priv->comments_label);
    }
  else
    {
      priv->comments = NULL;
      gtk_widget_hide (priv->comments_label);
    }
  g_free (tmp);

  g_object_notify (G_OBJECT (about), "comments");
}

/**
 * gtk_about_dialog_get_license:
 * @about: a #GtkAboutDialog
 * 
 * Returns the license information.
 * 
 * Return value: The license information. The string is owned by the about
 *  dialog and must not be modified.
 *
 * Since: 2.6
 **/
G_CONST_RETURN gchar *
gtk_about_dialog_get_license (GtkAboutDialog *about)
{
  GtkAboutDialogPrivate *priv;
  
  g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);

  priv = (GtkAboutDialogPrivate *)about->private_data;

  return priv->license;
}

/**
 * gtk_about_dialog_set_license:
 * @about: a #GtkAboutDialog
 * @license: the license information or %NULL
 *
 * Sets the license information to be displayed in the secondary
 * license dialog. If @license is %NULL, the license button is
 * hidden.
 * 
 * Since: 2.6
 **/
void
gtk_about_dialog_set_license (GtkAboutDialog *about, 
			      const gchar    *license)
{
  GtkAboutDialogPrivate *priv;
  gchar *tmp;

  g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));

  priv = (GtkAboutDialogPrivate *)about->private_data;

  tmp = priv->license;
  if (license) 
    {
      priv->license = g_strdup (license);
      gtk_widget_show (priv->license_button);
    }
  else
    {
      priv->license = NULL;
      gtk_widget_hide (priv->license_button);
    }
  g_free (tmp);

  g_object_notify (G_OBJECT (about), "license");
}

/**
 * gtk_about_dialog_get_website:
 * @about: a #GtkAboutDialog
 * 
 * Returns the website URL.
 * 
 * Return value: The website URL. The string is owned by the about
 *  dialog and must not be modified.
 *
 * Since: 2.6
 **/
G_CONST_RETURN gchar *
gtk_about_dialog_get_website (GtkAboutDialog *about)
{
  GtkAboutDialogPrivate *priv;
  
  g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);

  priv = (GtkAboutDialogPrivate *)about->private_data;

  return priv->website;
}

/**
 * gtk_about_dialog_set_website:
 * @about: a #GtkAboutDialog
 * @website: a URL string starting with "http://"
 * 
 * Sets the URL to use for the website link.
 *
 * Since: 2.6
 **/
void
gtk_about_dialog_set_website (GtkAboutDialog *about, 
			      const gchar    *website)
{
  GtkAboutDialogPrivate *priv;
  gchar *tmp;

  g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));

  priv = (GtkAboutDialogPrivate *)about->private_data;
  
  tmp = priv->website;
  if (website != NULL)
    {
      priv->website = g_strdup (website);
      if (activate_url_hook != NULL)
	{
	  g_object_set_data_full (G_OBJECT (priv->website_button), 
				  "url", g_strdup (website), g_free);  
	  if (priv->website_label == NULL) 
	    gtk_about_dialog_set_website_label (about, website);
	}
      else 
	{
	  GtkWidget *hbox = priv->website_button->parent;
	  gtk_widget_destroy (priv->website_button);
	  priv->website_button = gtk_label_new (website);
	  gtk_label_set_selectable (GTK_LABEL (priv->website_button), TRUE);
	  gtk_container_add (GTK_CONTAINER (hbox), priv->website_button);
	  gtk_widget_show (priv->website_button);
	}
    }
  else 
    {
      priv->website = NULL;
      g_object_set_data (G_OBJECT (priv->website_button), "url", NULL);
1033
      gtk_widget_hide (priv->website_button);
Matthias Clasen's avatar
Matthias Clasen committed
1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118
    }
  g_free (tmp);

  g_object_notify (G_OBJECT (about), "website");
}

/**
 * gtk_about_dialog_get_website_label:
 * @about: a #GtkAboutDialog
 * 
 * Returns the label used for the website link. 
 * 
 * Return value: The label used for the website link. The string is owned by the about
 *  dialog and must not be modified.
 *
 * Since: 2.6
 **/
G_CONST_RETURN gchar *
gtk_about_dialog_get_website_label (GtkAboutDialog *about)
{
  GtkAboutDialogPrivate *priv;
  
  g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);

  priv = (GtkAboutDialogPrivate *)about->private_data;

  return priv->website_label;
}

/**
 * gtk_about_dialog_set_website_label:
 * @about: a #GtkAboutDialog
 * @website_label: the label used for the website link
 * 
 * Sets the label to be used for the website link.
 * It defaults to the website URL.
 *
 * Since: 2.6
 **/
void
gtk_about_dialog_set_website_label (GtkAboutDialog *about, 
				    const gchar    *website_label)
{
  GtkAboutDialogPrivate *priv;
  gchar *tmp;

  g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));

  priv = (GtkAboutDialogPrivate *)about->private_data;

  tmp = priv->website_label;
  if (activate_url_hook != NULL)
    {
      if (website_label != NULL) 
	{
	  priv->website_label = g_strdup (website_label);
	  set_link_button_text (GTK_WIDGET (about),
				priv->website_button, 
				priv->website_label);
	  gtk_widget_show (priv->website_button);
	}
      else 
	{
	  priv->website_label = NULL;
	  gtk_widget_hide (priv->website_button);
	}
    }
  g_free (tmp);

  g_object_notify (G_OBJECT (about), "website_label");
}

/**
 * gtk_about_dialog_get_authors:
 * @about: a #GtkAboutDialog
 * 
 * Returns the string which are displayed in the authors tab
 * of the secondary credits dialog.
 * 
 * Return value: A %NULL-terminated string array containing
 *  the authors. The array is owned by the about dialog 
 *  and must not be modified.
 *
 * Since: 2.6
 **/
1119
G_CONST_RETURN gchar * G_CONST_RETURN *
Matthias Clasen's avatar
Matthias Clasen committed
1120 1121 1122 1123 1124 1125 1126 1127
gtk_about_dialog_get_authors (GtkAboutDialog *about)
{
  GtkAboutDialogPrivate *priv;
  
  g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);

  priv = (GtkAboutDialogPrivate *)about->private_data;

1128
  return (const gchar * const *) priv->authors;
Matthias Clasen's avatar
Matthias Clasen committed
1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142
}

/**
 * gtk_about_dialog_set_authors:
 * @about: a #GtkAboutDialog
 * @authors: a %NULL-terminated array of strings 
 *
 * Sets the strings which are displayed in the authors tab
 * of the secondary credits dialog. 
 * 
 * Since: 2.6
 **/
void
gtk_about_dialog_set_authors (GtkAboutDialog  *about, 
1143
			      const gchar    **authors)
Matthias Clasen's avatar
Matthias Clasen committed
1144 1145 1146 1147 1148 1149 1150 1151 1152
{
  GtkAboutDialogPrivate *priv;
  gchar **tmp;

  g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));

  priv = (GtkAboutDialogPrivate *)about->private_data;

  tmp = priv->authors;
1153
  priv->authors = g_strdupv ((gchar **)authors);
Matthias Clasen's avatar
Matthias Clasen committed
1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174
  g_strfreev (tmp);

  if (priv->authors != NULL)
    gtk_widget_show (priv->credits_button);

  g_object_notify (G_OBJECT (about), "authors");
}

/**
 * gtk_about_dialog_get_documenters:
 * @about: a #GtkAboutDialog
 * 
 * Returns the string which are displayed in the documenters 
 * tab of the secondary credits dialog.
 * 
 * Return value: A %NULL-terminated string array containing
 *  the documenters. The array is owned by the about dialog 
 *  and must not be modified.
 *
 * Since: 2.6
 **/
1175
G_CONST_RETURN gchar * G_CONST_RETURN *
Matthias Clasen's avatar
Matthias Clasen committed
1176 1177 1178 1179 1180 1181 1182 1183
gtk_about_dialog_get_documenters (GtkAboutDialog *about)
{
  GtkAboutDialogPrivate *priv;
  
  g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);

  priv = (GtkAboutDialogPrivate *)about->private_data;

1184
  return (const gchar * const *)priv->documenters;
Matthias Clasen's avatar
Matthias Clasen committed
1185 1186 1187 1188 1189
}

/**
 * gtk_about_dialog_set_documenters:
 * @about: a #GtkAboutDialog
Matthias Clasen's avatar
Matthias Clasen committed
1190
 * @documenters: a %NULL-terminated array of strings 
Matthias Clasen's avatar
Matthias Clasen committed
1191 1192 1193 1194 1195 1196 1197 1198
 *
 * Sets the strings which are displayed in the documenters tab
 * of the secondary credits dialog. 
 * 
 * Since: 2.6
 **/
void
gtk_about_dialog_set_documenters (GtkAboutDialog *about, 
1199
				  const gchar   **documenters)
Matthias Clasen's avatar
Matthias Clasen committed
1200 1201 1202 1203 1204 1205 1206 1207 1208
{
  GtkAboutDialogPrivate *priv;
  gchar **tmp;

  g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));

  priv = (GtkAboutDialogPrivate *)about->private_data;
  
  tmp = priv->documenters;
1209
  priv->documenters = g_strdupv ((gchar **)documenters);
Matthias Clasen's avatar
Matthias Clasen committed
1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230
  g_strfreev (tmp);

  if (priv->documenters != NULL)
    gtk_widget_show (priv->credits_button);

  g_object_notify (G_OBJECT (about), "documenters");
}

/**
 * gtk_about_dialog_get_artists:
 * @about: a #GtkAboutDialog
 * 
 * Returns the string which are displayed in the artists tab
 * of the secondary credits dialog.
 * 
 * Return value: A %NULL-terminated string array containing
 *  the artists. The array is owned by the about dialog 
 *  and must not be modified.
 *
 * Since: 2.6
 **/
1231
G_CONST_RETURN gchar * G_CONST_RETURN *
Matthias Clasen's avatar
Matthias Clasen committed
1232 1233 1234 1235 1236 1237 1238 1239
gtk_about_dialog_get_artists (GtkAboutDialog *about)
{
  GtkAboutDialogPrivate *priv;
  
  g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);

  priv = (GtkAboutDialogPrivate *)about->private_data;

1240
  return (const gchar * const *)priv->artists;
Matthias Clasen's avatar
Matthias Clasen committed
1241 1242 1243 1244 1245
}

/**
 * gtk_about_dialog_set_artists:
 * @about: a #GtkAboutDialog
Matthias Clasen's avatar
Matthias Clasen committed
1246
 * @artists: a %NULL-terminated array of strings 
Matthias Clasen's avatar
Matthias Clasen committed
1247 1248 1249 1250 1251 1252 1253 1254
 *
 * Sets the strings which are displayed in the artists tab
 * of the secondary credits dialog. 
 * 
 * Since: 2.6
 **/
void
gtk_about_dialog_set_artists (GtkAboutDialog *about, 
1255
			      const gchar   **artists)
Matthias Clasen's avatar
Matthias Clasen committed
1256 1257 1258 1259 1260 1261 1262 1263 1264
{
  GtkAboutDialogPrivate *priv;
  gchar **tmp;

  g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));

  priv = (GtkAboutDialogPrivate *)about->private_data;
  
  tmp = priv->artists;
1265
  priv->artists = g_strdupv ((gchar **)artists);
Matthias Clasen's avatar
Matthias Clasen committed
1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310
  g_strfreev (tmp);

  if (priv->artists != NULL)
    gtk_widget_show (priv->credits_button);

  g_object_notify (G_OBJECT (about), "artists");
}

/**
 * gtk_about_dialog_get_translator_credits:
 * @about: a #GtkAboutDialog
 * 
 * Returns the translator credits string which is displayed
 * in the translators tab of the secondary credits dialog.
 * 
 * Return value: The translator credits string. The string is
 *   owned by the about dialog and must not be modified.
 *
 * Since: 2.6
 **/
G_CONST_RETURN gchar *
gtk_about_dialog_get_translator_credits (GtkAboutDialog *about)
{
  GtkAboutDialogPrivate *priv;
  
  g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);

  priv = (GtkAboutDialogPrivate *)about->private_data;

  return priv->translator_credits;
}

/**
 * gtk_about_dialog_set_translator_credits:
 * @about: a #GtkAboutDialog
 * @translator_credits: the translator credits
 * 
 * Sets the translator credits string which is displayed in
 * the translators tab of the secondary credits dialog.
 * 
 * The intended use for this string is to display the translator
 * of the language which is currently used in the user interface.
 * Using gettext(), a simple way to achieve that is to mark the
 * string for translation:
 * <informalexample><programlisting>
1311
 *  gtk_about_dialog_set_translator_credits (about, _("translator-credits"));
Matthias Clasen's avatar
Matthias Clasen committed
1312
 * </programlisting></informalexample>
1313
 * It is a good idea to use the customary msgid "translator-credits" for this
1314
 * purpose, since translators will already know the purpose of that msgid, and
1315
 * since #GtkAboutDialog will detect if "translator-credits" is untranslated
1316
 * and hide the tab.
Matthias Clasen's avatar
Matthias Clasen committed
1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361
 *
 * Since: 2.6
 **/
void
gtk_about_dialog_set_translator_credits (GtkAboutDialog *about, 
					 const gchar    *translator_credits)
{
  GtkAboutDialogPrivate *priv;
  gchar *tmp;

  g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));

  priv = (GtkAboutDialogPrivate *)about->private_data;

  tmp = priv->translator_credits;
  priv->translator_credits = g_strdup (translator_credits);
  g_free (tmp);

  if (priv->translator_credits != NULL)
    gtk_widget_show (priv->credits_button);

  g_object_notify (G_OBJECT (about), "translator-credits");
}

/**
 * gtk_about_dialog_get_logo:
 * @about: a #GtkAboutDialog
 * 
 * Returns the pixbuf displayed as logo in the about dialog.
 * 
 * Return value: the pixbuf displayed as logo. The pixbuf is
 *   owned by the about dialog. If you want to keep a reference
 *   to it, you have to call g_object_ref() on it.
 *
 * Since: 2.6
 **/
GdkPixbuf *
gtk_about_dialog_get_logo (GtkAboutDialog *about)
{
  GtkAboutDialogPrivate *priv;
  
  g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);

  priv = (GtkAboutDialogPrivate *)about->private_data;

1362 1363 1364 1365
  if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_PIXBUF)
    return gtk_image_get_pixbuf (GTK_IMAGE (priv->logo_image));
  else
    return NULL;
Matthias Clasen's avatar
Matthias Clasen committed
1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379
}

static GtkIconSet *
icon_set_new_from_pixbufs (GList *pixbufs)
{
  GtkIconSet *icon_set = gtk_icon_set_new ();
  
  for (; pixbufs; pixbufs = pixbufs->next)
    {
      GdkPixbuf *pixbuf = GDK_PIXBUF (pixbufs->data);

      GtkIconSource *icon_source = gtk_icon_source_new ();
      gtk_icon_source_set_pixbuf (icon_source, pixbuf);
      gtk_icon_set_add_source (icon_set, icon_source);
Matthias Clasen's avatar
Matthias Clasen committed
1380
      gtk_icon_source_free (icon_source);
Matthias Clasen's avatar
Matthias Clasen committed
1381 1382 1383 1384 1385 1386 1387 1388
    }
  
  return icon_set;
}

/**
 * gtk_about_dialog_set_logo:
 * @about: a #GtkAboutDialog
Matthias Clasen's avatar
Matthias Clasen committed
1389
 * @logo: a #GdkPixbuf, or %NULL
Matthias Clasen's avatar
Matthias Clasen committed
1390 1391 1392 1393 1394 1395 1396 1397 1398 1399
 * 
 * Sets the pixbuf to be displayed as logo in 
 * the about dialog. If it is %NULL, the default
 * window icon set with gtk_window_set_default_icon ()
 * will be used.
 *
 * Since: 2.6
 **/
void
gtk_about_dialog_set_logo (GtkAboutDialog *about,
Matthias Clasen's avatar
Matthias Clasen committed
1400
			   GdkPixbuf      *logo)
Matthias Clasen's avatar
Matthias Clasen committed
1401 1402 1403 1404 1405 1406 1407
{
  GtkAboutDialogPrivate *priv;

  g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));

  priv = (GtkAboutDialogPrivate *)about->private_data;

1408 1409 1410 1411 1412
  g_object_freeze_notify (G_OBJECT (about));

  if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_ICON_NAME)
    g_object_notify (G_OBJECT (about), "logo_icon_name");

Matthias Clasen's avatar
Matthias Clasen committed
1413 1414
  if (logo != NULL) 
    gtk_image_set_from_pixbuf (GTK_IMAGE (priv->logo_image), logo);
Matthias Clasen's avatar
Matthias Clasen committed
1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431
  else 
    {
      GList *pixbufs = gtk_window_get_default_icon_list ();

      if (pixbufs != NULL)
	{
	  GtkIconSet *icon_set = icon_set_new_from_pixbufs (pixbufs); 
	  
	  gtk_image_set_from_icon_set (GTK_IMAGE (priv->logo_image),
				       icon_set, GTK_ICON_SIZE_DIALOG);
	  
	  gtk_icon_set_unref (icon_set);
	  g_list_free (pixbufs);
	}
    }

  g_object_notify (G_OBJECT (about), "logo");
1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442

  g_object_thaw_notify (G_OBJECT (about));
}

/**
 * gtk_about_dialog_get_logo_icon_name:
 * @about: a #GtkAboutDialog
 * 
 * Returns the icon name displayed as logo in the about dialog.
 * 
 * Return value: the icon name displayed as logo. The string is
1443
 *   owned by the dialog. If you want to keep a reference
1444 1445 1446 1447 1448 1449 1450 1451
 *   to it, you have to call g_strdup() on it.
 *
 * Since: 2.6
 **/
G_CONST_RETURN gchar *
gtk_about_dialog_get_logo_icon_name (GtkAboutDialog *about)
{
  GtkAboutDialogPrivate *priv;
1452
  const gchar *icon_name = NULL;
1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495
  
  g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);

  priv = (GtkAboutDialogPrivate *)about->private_data;

  if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_ICON_NAME)
    gtk_image_get_icon_name (GTK_IMAGE (priv->logo_image), &icon_name, NULL);

  return icon_name;
}

/**
 * gtk_about_dialog_set_logo_icon_name:
 * @about: a #GtkAboutDialog
 * @icon_name: an icon name, or %NULL
 * 
 * Sets the pixbuf to be displayed as logo in 
 * the about dialog. If it is %NULL, the default
 * window icon set with gtk_window_set_default_icon()
 * will be used.
 *
 * Since: 2.6
 **/
void
gtk_about_dialog_set_logo_icon_name (GtkAboutDialog *about,
				     const gchar    *icon_name)
{
  GtkAboutDialogPrivate *priv;

  g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));

  priv = (GtkAboutDialogPrivate *)about->private_data;

  g_object_freeze_notify (G_OBJECT (about));

  if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_PIXBUF)
    g_object_notify (G_OBJECT (about), "logo");

  gtk_image_set_from_icon_name (GTK_IMAGE (priv->logo_image), icon_name,
				GTK_ICON_SIZE_DIALOG);
  g_object_notify (G_OBJECT (about), "logo_icon_name");

  g_object_thaw_notify (G_OBJECT (about));
Matthias Clasen's avatar
Matthias Clasen committed
1496 1497 1498 1499 1500 1501 1502 1503 1504 1505
}

static void
activate_url (GtkWidget *widget, 
	      gpointer   data)
{
  GtkAboutDialog *about = GTK_ABOUT_DIALOG (data);
  gchar *url = g_object_get_data (G_OBJECT (widget), "url");
  
  if (activate_url_hook != NULL)
1506
    (* activate_url_hook) (about, url, activate_url_hook_data);
Matthias Clasen's avatar
Matthias Clasen committed
1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550
}

static void
set_link_button_text (GtkWidget *about,
		      GtkWidget *button, 
		      gchar     *text)
{
  GtkWidget *label;
  gchar *link;
  GdkColor *style_link_color;
  GdkColor link_color = { 0, 0, 0, 0xffff };

  gtk_widget_ensure_style (about);
  gtk_widget_style_get (about, "link_color", &style_link_color, NULL);
  if (style_link_color)
    {
      link_color = *style_link_color;
      gdk_color_free (style_link_color);
    }

  link = g_markup_printf_escaped ("<span foreground=\"#%04x%04x%04x\" underline=\"single\">%s</span>", 
				  link_color.red, link_color.green, link_color.blue, text);

  label = gtk_bin_get_child (GTK_BIN (button));  
  gtk_label_set_markup (GTK_LABEL (label), link);
  g_free (link);
}

static GtkWidget *
create_link_button (GtkWidget *about,
		    gchar     *text,
		    gchar     *url, 
		    GCallback  callback, 
		    gpointer   data)
{
  GtkWidget *button;

  button = gtk_button_new_with_label ("");
  GTK_WIDGET_UNSET_FLAGS (button, GTK_RECEIVES_DEFAULT);
  gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);

  g_object_set_data_full (G_OBJECT (button), "url", g_strdup (url), g_free);
  set_link_button_text (about, button, text);
  
1551
  g_signal_connect (button, "clicked", callback, data);
Matthias Clasen's avatar
Matthias Clasen committed
1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570

  return button;
}

static void
follow_if_link (GtkAboutDialog *about,
		GtkTextIter    *iter)
{
  GSList *tags = NULL, *tagp = NULL;

  tags = gtk_text_iter_get_tags (iter);
  for (tagp = tags;  tagp != NULL;  tagp = tagp->next)
    {
      GtkTextTag *tag = tagp->data;
      gchar *email = g_object_get_data (G_OBJECT (tag), "email");
      gchar *url = g_object_get_data (G_OBJECT (tag), "url");

      if (email != NULL && activate_email_hook != NULL)
        {
1571
	  (* activate_email_hook) (about, email, activate_email_hook_data);
Matthias Clasen's avatar
Matthias Clasen committed
1572 1573 1574 1575 1576
	  break;
        }

      if (url != NULL && activate_url_hook != NULL)
        {
1577
	  (* activate_url_hook) (about, url, activate_url_hook_data);
Matthias Clasen's avatar
Matthias Clasen committed
1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727
	  break;
        }
    }

  if (tags) 
    g_slist_free (tags);
}

static gboolean
credits_key_press_event (GtkWidget      *text_view,
			 GdkEventKey    *event,
			 GtkAboutDialog *about)
{
  GtkTextIter iter;
  GtkTextBuffer *buffer;

  switch (event->keyval)
    {
      case GDK_Return: 
      case GDK_KP_Enter:
        buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view));
        gtk_text_buffer_get_iter_at_mark (buffer, &iter, 
                                          gtk_text_buffer_get_insert (buffer));
        follow_if_link (about, &iter);
        break;

      default:
        break;
    }

  return FALSE;
}

static gboolean
credits_event_after (GtkWidget      *text_view,
		     GdkEvent       *event,
		     GtkAboutDialog *about)
{
  GtkTextIter start, end, iter;
  GtkTextBuffer *buffer;
  GdkEventButton *button_event;
  gint x, y;

  if (event->type != GDK_BUTTON_RELEASE)
    return FALSE;

  button_event = (GdkEventButton *)event;

  if (button_event->button != 1)
    return FALSE;

  buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view));

  /* we shouldn't follow a link if the user has selected something */
  gtk_text_buffer_get_selection_bounds (buffer, &start, &end);
  if (gtk_text_iter_get_offset (&start) != gtk_text_iter_get_offset (&end))
    return FALSE;

  gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (text_view), 
                                         GTK_TEXT_WINDOW_WIDGET,
                                         button_event->x, button_event->y, &x, &y);

  gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW (text_view), &iter, x, y);

  follow_if_link (about, &iter);

  return FALSE;
}

static void
set_cursor_if_appropriate (GtkAboutDialog *about,
			   GtkTextView    *text_view,
			   gint            x,
			   gint            y)
{
  GtkAboutDialogPrivate *priv = (GtkAboutDialogPrivate *)about->private_data;
  GSList *tags = NULL, *tagp = NULL;
  GtkTextBuffer *buffer;
  GtkTextIter iter;
  gboolean hovering_over_link = FALSE;

  buffer = gtk_text_view_get_buffer (text_view);

  gtk_text_view_get_iter_at_location (text_view, &iter, x, y);
  
  tags = gtk_text_iter_get_tags (&iter);
  for (tagp = tags;  tagp != NULL;  tagp = tagp->next)
    {
      GtkTextTag *tag = tagp->data;
      gchar *email = g_object_get_data (G_OBJECT (tag), "email");
      gchar *url = g_object_get_data (G_OBJECT (tag), "url");

      if (email != NULL || url != NULL) 
        {
          hovering_over_link = TRUE;
          break;
        }
    }

  if (hovering_over_link != priv->hovering_over_link)
    {
      priv->hovering_over_link = hovering_over_link;

      if (hovering_over_link)
        gdk_window_set_cursor (gtk_text_view_get_window (text_view, GTK_TEXT_WINDOW_TEXT), priv->hand_cursor);
      else
        gdk_window_set_cursor (gtk_text_view_get_window (text_view, GTK_TEXT_WINDOW_TEXT), priv->regular_cursor);
    }

  if (tags) 
    g_slist_free (tags);
}

static gboolean
credits_motion_notify_event (GtkWidget *text_view,
			     GdkEventMotion *event,
			     GtkAboutDialog *about)
{
  gint x, y;

  gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (text_view), 
                                         GTK_TEXT_WINDOW_WIDGET,
                                         event->x, event->y, &x, &y);

  set_cursor_if_appropriate (about, GTK_TEXT_VIEW (text_view), x, y);

  gdk_window_get_pointer (text_view->window, NULL, NULL, NULL);

  return FALSE;
}


static gboolean
credits_visibility_notify_event (GtkWidget          *text_view,
				 GdkEventVisibility *event,
				 GtkAboutDialog     *about)
{
  gint wx, wy, bx, by;

  gdk_window_get_pointer (text_view->window, &wx, &wy, NULL);

  gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (text_view), 
                                         GTK_TEXT_WINDOW_WIDGET,
                                         wx, wy, &bx, &by);

  set_cursor_if_appropriate (about, GTK_TEXT_VIEW (text_view), bx, by);

  return FALSE;
}

1728 1729 1730 1731 1732 1733 1734
static void
text_view_style_set (GtkWidget *widget, GtkStyle *prev_style, GtkWidget *text_view)
{
  gtk_widget_modify_base (text_view, GTK_STATE_NORMAL,
			  &widget->style->bg[GTK_STATE_NORMAL]);
}

Matthias Clasen's avatar
Matthias Clasen committed
1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760
static void
add_credits_page (GtkAboutDialog *about, 
		  GtkWidget      *notebook,
		  gchar          *title,
		  gchar         **people)
{
  gchar **p;
  gchar *q0, *q1, *q2, *r1, *r2;
  GtkWidget *sw, *view;
  GtkTextBuffer *buffer;
  gboolean linkify_email, linkify_urls;
  GdkColor *style_link_color;
  GdkColor link_color = { 0, 0, 0, 0xffff };

  linkify_email = (activate_email_hook != NULL);
  linkify_urls = (activate_url_hook != NULL);

  gtk_widget_ensure_style (GTK_WIDGET (about));
  gtk_widget_style_get (GTK_WIDGET (about), "link_color", &style_link_color, NULL);
  if (style_link_color)
    {
      link_color = *style_link_color;
      gdk_color_free (style_link_color);
    }

  view = gtk_text_view_new ();
1761 1762 1763
  g_signal_connect (about, "style_set",
		    G_CALLBACK (text_view_style_set), view);
  
Matthias Clasen's avatar
Matthias Clasen committed
1764 1765 1766 1767 1768 1769
  buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
  gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (view), FALSE);
  gtk_text_view_set_editable (GTK_TEXT_VIEW (view), FALSE);
  gtk_text_view_set_left_margin (GTK_TEXT_VIEW (view), 8);
  gtk_text_view_set_right_margin (GTK_TEXT_VIEW (view), 8);

1770
  g_signal_connect (view, "key-press-event",
Matthias Clasen's avatar
Matthias Clasen committed
1771
                    G_CALLBACK (credits_key_press_event), about);
1772
  g_signal_connect (view, "event-after",
Matthias Clasen's avatar
Matthias Clasen committed
1773
                    G_CALLBACK (credits_event_after), about);
1774
  g_signal_connect (view, "motion-notify-event", 
Matthias Clasen's avatar
Matthias Clasen committed
1775
                    G_CALLBACK (credits_motion_notify_event), about);
1776
  g_signal_connect (view, "visibility-notify-event", 
Matthias Clasen's avatar
Matthias Clasen committed
1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803
                    G_CALLBACK (credits_visibility_notify_event), about);

  sw = gtk_scrolled_window_new (NULL, NULL);
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
				  GTK_POLICY_AUTOMATIC,
				  GTK_POLICY_AUTOMATIC);
  gtk_container_add (GTK_CONTAINER (sw), view);
  
  gtk_notebook_append_page (GTK_NOTEBOOK (notebook), 
			    sw, gtk_label_new (title));

  if (people == NULL) 
    {
      gtk_widget_hide (view);
      return;
    }
  else 
    gtk_widget_show (view);
  
  for (p = people; *p; p++) 
    {
      q0  = *p;
      while (*q0) 
	{
	  q1 = linkify_email ? strchr (q0, '<') : NULL;
	  q2 = q1 ? strchr (q1, '>') : NULL;
	  r1 = linkify_urls ? strstr (q0, "http://") : NULL;