gtkaboutdialog.c 75.4 KB
Newer Older
Cody Russell's avatar
Cody Russell committed
1
/* GTK - The GIMP Toolkit
2 3 4 5 6
 * 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
Matthias Clasen's avatar
Matthias Clasen committed
7 8
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
9 10 11 12 13 14 15 16
 * 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
Javier Jardón's avatar
Javier Jardón committed
17
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
18 19 20
 */

/*
21
 * Author: Anders Carlsson <andersca@gnome.org>
22 23 24 25
 *
 * 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
Matthias Clasen's avatar
Matthias Clasen committed
26
 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
27 28
 */

29
#include "config.h"
30

31 32
#include <string.h>

33
#include "gtkaboutdialog.h"
34 35 36
#include "gtkbutton.h"
#include "gtkbbox.h"
#include "gtkdialog.h"
37
#include "gtkgrid.h"
Matthias Clasen's avatar
Matthias Clasen committed
38
#include "gtkbox.h"
39
#include "gtkicontheme.h"
40 41
#include "gtkimage.h"
#include "gtklabel.h"
42
#include "gtklinkbutton.h"
43
#include "gtkmarshalers.h"
44
#include "gtkstack.h"
45
#include "gtkorientable.h"
46 47
#include "gtkscrolledwindow.h"
#include "gtktextview.h"
48
#include "gtkshow.h"
49
#include "gtkmain.h"
50
#include "gtkmessagedialog.h"
51
#include "gtktogglebutton.h"
52
#include "gtktypebuiltins.h"
53 54 55 56
#include "gtkstack.h"
#include "gtkstackswitcher.h"
#include "gtksettings.h"
#include "gtkheaderbar.h"
57
#include "gtkprivate.h"
58
#include "gtkintl.h"
59
#include "gtkdialogprivate.h"
60

61 62 63 64 65 66

/**
 * SECTION:gtkaboutdialog
 * @Short_description: Display information about an application
 * @Title: GtkAboutDialog
 *
67
 * The GtkAboutDialog offers a simple way to display information about
68 69 70
 * a program like its logo, name, copyright, website and license. It is
 * also possible to give credits to the authors, documenters, translators
 * and artists who have worked on the program. An about dialog is typically
71 72
 * opened when the user selects the `About` option from the `Help` menu.
 * All parts of the dialog are optional.
73
 *
Matthias Clasen's avatar
Matthias Clasen committed
74
 * About dialogs often contain links and email addresses. GtkAboutDialog
75 76 77
 * displays these as clickable links. By default, it calls gtk_show_uri()
 * when a user clicks one. The behaviour can be overridden with the
 * #GtkAboutDialog::activate-link signal.
78
 *
79 80 81 82
 * To specify a person with an email address, use a string like
 * "Edgar Allan Poe <edgar@poe.com>". To specify a website with a title,
 * use a string like "GTK+ team http://www.gtk.org".
 *
83
 * To make constructing a GtkAboutDialog as convenient as possible, you can
84 85 86
 * use the function gtk_show_about_dialog() which constructs and shows a dialog
 * and keeps it around so that it can be shown again.
 *
87
 * Note that GTK+ sets a default title of `_("About %s")` on the dialog
88 89 90 91
 * window (where \%s is replaced by the name of the application, but in
 * order to ensure proper translation of the title, applications should
 * set the title property explicitly when constructing a GtkAboutDialog,
 * as shown in the following example:
92
 * |[<!-- language="C" -->
93 94 95 96 97
 * gtk_show_about_dialog (NULL,
 *                        "program-name", "ExampleCode",
 *                        "logo", example_logo,
 *                        "title" _("About ExampleCode"),
 *                        NULL);
98
 * ]|
99 100 101
 *
 * It is also possible to show a #GtkAboutDialog like any other #GtkDialog,
 * e.g. using gtk_dialog_run(). In this case, you might need to know that
102
 * the “Close” button returns the #GTK_RESPONSE_CANCEL response id.
103 104
 */

105 106 107 108 109 110 111 112 113 114 115
typedef struct
{
  const gchar *name;
  const gchar *url;
} LicenseInfo;

/* LicenseInfo for each GtkLicense type; keep in the same order as the enumeration */
static const LicenseInfo gtk_license_info [] = {
  { N_("License"), NULL },
  { N_("Custom License") , NULL },
  { N_("GNU General Public License, version 2 or later"), "http://www.gnu.org/licenses/old-licenses/gpl-2.0.html" },
116
  { N_("GNU General Public License, version 3 or later"), "http://www.gnu.org/licenses/gpl-3.0.html" },
117
  { N_("GNU Lesser General Public License, version 2.1 or later"), "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html" },
118
  { N_("GNU Lesser General Public License, version 3 or later"), "http://www.gnu.org/licenses/lgpl-3.0.html" },
119 120 121 122
  { N_("BSD 2-Clause License"), "http://opensource.org/licenses/bsd-license.php" },
  { N_("The MIT License (MIT)"), "http://opensource.org/licenses/mit-license.php" },
  { N_("Artistic License 2.0"), "http://opensource.org/licenses/artistic-license-2.0.php" },
  { N_("GNU General Public License, version 2 only"), "http://www.gnu.org/licenses/old-licenses/gpl-2.0.html" },
123
  { N_("GNU General Public License, version 3 only"), "http://www.gnu.org/licenses/gpl-3.0.html" },
124
  { N_("GNU Lesser General Public License, version 2.1 only"), "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html" },
125 126
  { N_("GNU Lesser General Public License, version 3 only"), "http://www.gnu.org/licenses/lgpl-3.0.html" },
  { N_("GNU Affero General Public License, version 3 or later"), "http://www.gnu.org/licenses/agpl-3.0.html" }
127 128
};

129 130 131 132 133 134
typedef struct
{
  gchar *heading;
  gchar **people;
} CreditSection;

135
struct _GtkAboutDialogPrivate
136 137 138 139 140
{
  gchar *name;
  gchar *version;
  gchar *copyright;
  gchar *comments;
141 142
  gchar *website_url;
  gchar *website_text;
143 144
  gchar *translator_credits;
  gchar *license;
Matthias Clasen's avatar
Matthias Clasen committed
145

146 147 148
  gchar **authors;
  gchar **documenters;
  gchar **artists;
Matthias Clasen's avatar
Matthias Clasen committed
149

150 151
  GSList *credit_sections;

152 153
  gboolean credits_page_initialized;
  gboolean license_page_initialized;
154

155
  GtkWidget *stack;
156
  GtkWidget *stack_switcher;
157 158 159
  GtkWidget *credits_button;
  GtkWidget *license_button;

160 161
  GtkWidget *logo_image;
  GtkWidget *name_label;
162
  GtkWidget *version_label;
163 164
  GtkWidget *comments_label;
  GtkWidget *copyright_label;
165
  GtkWidget *license_label;
166
  GtkWidget *website_label;
167

168 169
  GtkWidget *credits_page;
  GtkWidget *license_page;
Matthias Clasen's avatar
Matthias Clasen committed
170

171 172 173
  GtkWidget *credits_grid;
  GtkWidget *license_view;

174 175
  GdkCursor *hand_cursor;
  GdkCursor *regular_cursor;
Matthias Clasen's avatar
Matthias Clasen committed
176

177 178
  GSList *visited_links;

179 180
  GtkLicense license_type;

181 182
  guint hovering_over_link : 1;
  guint wrap_license : 1;
183
  guint in_child_changed : 1;
184
  guint in_switch_page : 1;
185 186
};

Matthias Clasen's avatar
Matthias Clasen committed
187
enum
188 189 190 191 192 193 194 195 196 197 198 199 200
{
  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,
201
  PROP_LOGO,
202
  PROP_LOGO_ICON_NAME,
203
  PROP_WRAP_LICENSE,
204 205
  PROP_LICENSE_TYPE,
  LAST_PROP
206 207 208 209
};

static void                 gtk_about_dialog_finalize       (GObject            *object);
static void                 gtk_about_dialog_get_property   (GObject            *object,
Matthias Clasen's avatar
Matthias Clasen committed
210 211 212
                                                             guint               prop_id,
                                                             GValue             *value,
                                                             GParamSpec         *pspec);
213
static void                 gtk_about_dialog_set_property   (GObject            *object,
Matthias Clasen's avatar
Matthias Clasen committed
214 215 216
                                                             guint               prop_id,
                                                             const GValue       *value,
                                                             GParamSpec         *pspec);
217 218 219
static void                 gtk_about_dialog_realize        (GtkWidget          *widget);
static void                 gtk_about_dialog_unrealize      (GtkWidget          *widget);
static void                 gtk_about_dialog_show           (GtkWidget          *widget);
220 221
static void                 update_name_version             (GtkAboutDialog     *about);
static void                 follow_if_link                  (GtkAboutDialog     *about,
Matthias Clasen's avatar
Matthias Clasen committed
222 223
                                                             GtkTextView        *text_view,
                                                             GtkTextIter        *iter);
224
static void                 set_cursor_if_appropriate       (GtkAboutDialog     *about,
225
                                                             GtkTextView        *text_view,
226
                                                             GdkDevice          *device,
227 228
                                                             gint                x,
                                                             gint                y);
229 230
static void                 populate_credits_page           (GtkAboutDialog     *about);
static void                 populate_license_page           (GtkAboutDialog     *about);
231
static void                 close_cb                        (GtkAboutDialog     *about);
232 233
static gboolean             gtk_about_dialog_activate_link  (GtkAboutDialog     *about,
                                                             const gchar        *uri);
234 235 236 237 238 239 240 241 242 243 244
static gboolean             emit_activate_link              (GtkAboutDialog     *about,
							     const gchar        *uri);
static gboolean             text_view_key_press_event       (GtkWidget          *text_view,
							     GdkEventKey        *event,
							     GtkAboutDialog     *about);
static gboolean             text_view_event_after           (GtkWidget          *text_view,
							     GdkEvent           *event,
							     GtkAboutDialog     *about);
static gboolean             text_view_motion_notify_event   (GtkWidget          *text_view,
							     GdkEventMotion     *event,
							     GtkAboutDialog     *about);
245 246 247 248
static void                 toggle_credits                  (GtkToggleButton    *button,
                                                             gpointer            user_data);
static void                 toggle_license                  (GtkToggleButton    *button,
                                                             gpointer            user_data);
249

250 251 252 253
enum {
  ACTIVATE_LINK,
  LAST_SIGNAL
};
254

255
static guint signals[LAST_SIGNAL] = { 0 };
256
static GParamSpec *props[LAST_PROP] = { NULL, };
257

258
G_DEFINE_TYPE_WITH_PRIVATE (GtkAboutDialog, gtk_about_dialog, GTK_TYPE_DIALOG)
259

260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287
static gboolean
stack_visible_child_notify (GtkStack       *stack,
                            GParamSpec     *pspec,
                            GtkAboutDialog *about)
{
  GtkAboutDialogPrivate *priv = about->priv;
  GtkWidget *child;

  child = gtk_stack_get_visible_child (stack);
  if (child == priv->credits_page)
    {
      if (!priv->credits_page_initialized)
        {
          populate_credits_page (about);
          priv->credits_page_initialized = TRUE;
        }
    }
  else if (child == priv->license_page)
    {
      if (!priv->license_page_initialized)
        {
          populate_license_page (about);
          priv->license_page_initialized = TRUE;
        }
    }

  return FALSE;
}
288

289 290 291 292 293
static void
gtk_about_dialog_class_init (GtkAboutDialogClass *klass)
{
  GObjectClass *object_class;
  GtkWidgetClass *widget_class;
Matthias Clasen's avatar
Matthias Clasen committed
294

295 296
  object_class = (GObjectClass *)klass;
  widget_class = (GtkWidgetClass *)klass;
Matthias Clasen's avatar
Matthias Clasen committed
297

298 299 300 301 302
  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;

303
  widget_class->show = gtk_about_dialog_show;
304 305
  widget_class->realize = gtk_about_dialog_realize;
  widget_class->unrealize = gtk_about_dialog_unrealize;
306

307 308 309 310 311 312 313 314 315 316 317 318 319
  klass->activate_link = gtk_about_dialog_activate_link;

  /**
   * GtkAboutDialog::activate-link:
   * @label: The object on which the signal was emitted
   * @uri: the URI that is activated
   *
   * The signal which gets emitted to activate a URI.
   * Applications may connect to it to override the default behaviour,
   * which is to call gtk_show_uri().
   *
   * Returns: %TRUE if the link has been activated
   *
320
   * Since: 2.24
321 322
   */
  signals[ACTIVATE_LINK] =
323
    g_signal_new (I_("activate-link"),
324 325 326 327 328 329 330
                  G_TYPE_FROM_CLASS (object_class),
                  G_SIGNAL_RUN_LAST,
                  G_STRUCT_OFFSET (GtkAboutDialogClass, activate_link),
                  _gtk_boolean_handled_accumulator, NULL,
                  _gtk_marshal_BOOLEAN__STRING,
                  G_TYPE_BOOLEAN, 1, G_TYPE_STRING);

Matthias Clasen's avatar
Matthias Clasen committed
331
  /**
332
   * GtkAboutDialog:program-name:
Matthias Clasen's avatar
Matthias Clasen committed
333
   *
Matthias Clasen's avatar
Matthias Clasen committed
334
   * The name of the program.
Matthias Clasen's avatar
Matthias Clasen committed
335 336
   * If this is not set, it defaults to g_get_application_name().
   *
337
   * Since: 2.12
Matthias Clasen's avatar
Matthias Clasen committed
338
   */
339 340 341 342 343
  props[PROP_NAME] =
    g_param_spec_string ("program-name",
                         P_("Program name"),
                         P_("The name of the program. If this is not set, it defaults to g_get_application_name()"),
                         NULL,
344
                         GTK_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
345

Matthias Clasen's avatar
Matthias Clasen committed
346 347 348
  /**
   * GtkAboutDialog:version:
   *
Matthias Clasen's avatar
Matthias Clasen committed
349
   * The version of the program.
Matthias Clasen's avatar
Matthias Clasen committed
350 351
   *
   * Since: 2.6
Matthias Clasen's avatar
Matthias Clasen committed
352
   */
353 354 355 356 357
  props[PROP_VERSION] =
    g_param_spec_string ("version",
                         P_("Program version"),
                         P_("The version of the program"),
                         NULL,
358
                         GTK_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
Matthias Clasen's avatar
Matthias Clasen committed
359 360 361 362

  /**
   * GtkAboutDialog:copyright:
   *
Matthias Clasen's avatar
Matthias Clasen committed
363
   * Copyright information for the program.
Matthias Clasen's avatar
Matthias Clasen committed
364 365
   *
   * Since: 2.6
Matthias Clasen's avatar
Matthias Clasen committed
366
   */
367 368 369 370
  props[PROP_COPYRIGHT] =
    g_param_spec_string ("copyright",
                         P_("Copyright string"),
                         P_("Copyright information for the program"),
Matthias Clasen's avatar
Matthias Clasen committed
371
                        NULL,
372
                         GTK_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
Matthias Clasen's avatar
Matthias Clasen committed
373 374 375 376

  /**
   * GtkAboutDialog:comments:
   *
Matthias Clasen's avatar
Matthias Clasen committed
377
   * Comments about the program. This string is displayed in a label
Matthias Clasen's avatar
Matthias Clasen committed
378 379 380 381
   * 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
382
   */
383 384 385 386 387
  props[PROP_COMMENTS] =
    g_param_spec_string ("comments",
                         P_("Comments string"),
                         P_("Comments about the program"),
                         NULL,
388
                         GTK_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
Matthias Clasen's avatar
Matthias Clasen committed
389 390 391 392

  /**
   * GtkAboutDialog:license:
   *
Matthias Clasen's avatar
Matthias Clasen committed
393
   * The license of the program. This string is displayed in a
Matthias Clasen's avatar
Matthias Clasen committed
394
   * text view in a secondary dialog, therefore it is fine to use
395 396 397
   * a long multi-paragraph text. Note that the text is only wrapped
   * in the text view if the "wrap-license" property is set to %TRUE;
   * otherwise the text itself must contain the intended linebreaks.
398 399 400
   * When setting this property to a non-%NULL value, the
   * #GtkAboutDialog:license-type property is set to %GTK_LICENSE_CUSTOM
   * as a side effect.
Matthias Clasen's avatar
Matthias Clasen committed
401 402
   *
   * Since: 2.6
Matthias Clasen's avatar
Matthias Clasen committed
403
   */
404 405
  props[PROP_LICENSE] =
    g_param_spec_string ("license",
406 407
                         P_("License"),
                         P_("The license of the program"),
408
                         NULL,
409
                         GTK_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
410

411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431
  /**
   * GtkAboutDialog:license-type:
   *
   * The license of the program, as a value of the %GtkLicense enumeration.
   *
   * The #GtkAboutDialog will automatically fill out a standard disclaimer
   * and link the user to the appropriate online resource for the license
   * text.
   *
   * If %GTK_LICENSE_UNKNOWN is used, the link used will be the same
   * specified in the #GtkAboutDialog:website property.
   *
   * If %GTK_LICENSE_CUSTOM is used, the current contents of the
   * #GtkAboutDialog:license property are used.
   *
   * For any other #GtkLicense value, the contents of the
   * #GtkAboutDialog:license property are also set by this property as
   * a side effect.
   *
   * Since: 3.0
   */
432 433 434 435 436 437
  props[PROP_LICENSE_TYPE] =
    g_param_spec_enum ("license-type",
                       P_("License Type"),
                       P_("The license type of the program"),
                       GTK_TYPE_LICENSE,
                       GTK_LICENSE_UNKNOWN,
438
                       GTK_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
439

Matthias Clasen's avatar
Matthias Clasen committed
440 441 442
  /**
   * GtkAboutDialog:website:
   *
Matthias Clasen's avatar
Matthias Clasen committed
443
   * The URL for the link to the website of the program.
Matthias Clasen's avatar
Matthias Clasen committed
444 445 446
   * This should be a string starting with "http://.
   *
   * Since: 2.6
Matthias Clasen's avatar
Matthias Clasen committed
447
   */
448 449 450 451 452
  props[PROP_WEBSITE] =
    g_param_spec_string ("website",
                         P_("Website URL"),
                         P_("The URL for the link to the website of the program"),
                         NULL,
453
                         GTK_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
454

Matthias Clasen's avatar
Matthias Clasen committed
455 456 457
  /**
   * GtkAboutDialog:website-label:
   *
458
   * The label for the link to the website of the program.
Matthias Clasen's avatar
Matthias Clasen committed
459 460
   *
   * Since: 2.6
Matthias Clasen's avatar
Matthias Clasen committed
461
   */
462 463 464 465 466
  props[PROP_WEBSITE_LABEL] =
    g_param_spec_string ("website-label",
                         P_("Website label"),
                         P_("The label for the link to the website of the program"),
                         NULL,
467
                         GTK_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
468

Matthias Clasen's avatar
Matthias Clasen committed
469 470 471 472 473 474 475 476
  /**
   * 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
477
   */
478 479 480 481 482
  props[PROP_AUTHORS] =
    g_param_spec_boxed ("authors",
                        P_("Authors"),
                        P_("List of authors of the program"),
                        G_TYPE_STRV,
483
                        GTK_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
Matthias Clasen's avatar
Matthias Clasen committed
484 485 486 487 488 489 490 491 492

  /**
   * 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
493
   */
494 495 496 497 498
  props[PROP_DOCUMENTERS] =
    g_param_spec_boxed ("documenters",
                        P_("Documenters"),
                        P_("List of people documenting the program"),
                        G_TYPE_STRV,
499
                        GTK_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
500

Matthias Clasen's avatar
Matthias Clasen committed
501 502 503
  /**
   * GtkAboutDialog:artists:
   *
Matthias Clasen's avatar
Matthias Clasen committed
504 505 506
   * 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.
Matthias Clasen's avatar
Matthias Clasen committed
507 508
   *
   * Since: 2.6
Matthias Clasen's avatar
Matthias Clasen committed
509
   */
510 511 512 513 514
  props[PROP_ARTISTS] =
    g_param_spec_boxed ("artists",
                        P_("Artists"),
                        P_("List of people who have contributed artwork to the program"),
                        G_TYPE_STRV,
515
                        GTK_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
Matthias Clasen's avatar
Matthias Clasen committed
516 517 518 519 520 521 522 523 524

  /**
   * 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
525
   */
526 527 528 529 530
  props[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,
531
                         GTK_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
532

Matthias Clasen's avatar
Matthias Clasen committed
533 534 535
  /**
   * GtkAboutDialog:logo:
   *
536 537
   * A logo for the about box. If it is %NULL, the default window icon
   * set with gtk_window_set_default_icon() will be used.
Matthias Clasen's avatar
Matthias Clasen committed
538 539
   *
   * Since: 2.6
Matthias Clasen's avatar
Matthias Clasen committed
540
   */
541 542 543 544 545
  props[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,
546
                         GTK_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
547

Matthias Clasen's avatar
Matthias Clasen committed
548 549 550 551
  /**
   * GtkAboutDialog:logo-icon-name:
   *
   * A named icon to use as the logo for the about box. This property
Matthias Clasen's avatar
Matthias Clasen committed
552
   * overrides the #GtkAboutDialog:logo property.
Matthias Clasen's avatar
Matthias Clasen committed
553 554
   *
   * Since: 2.6
Matthias Clasen's avatar
Matthias Clasen committed
555
   */
556 557 558 559 560
  props[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."),
                         "image-missing",
561
                         GTK_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
562

563 564 565 566 567
  /**
   * GtkAboutDialog:wrap-license:
   *
   * Whether to wrap the text in the license dialog.
   *
Matthias Clasen's avatar
Matthias Clasen committed
568
   * Since: 2.8
Matthias Clasen's avatar
Matthias Clasen committed
569
   */
570 571 572 573 574
  props[PROP_WRAP_LICENSE] =
    g_param_spec_boolean ("wrap-license",
                          P_("Wrap license"),
                          P_("Whether to wrap the license text."),
                          FALSE,
575
                          GTK_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
576 577

  g_object_class_install_properties (object_class, LAST_PROP, props);
578

579 580 581
  /* Bind class to template
   */
  gtk_widget_class_set_template_from_resource (widget_class,
582
					       "/org/gtk/libgtk/ui/gtkaboutdialog.ui");
583

584
  gtk_widget_class_bind_template_child_private (widget_class, GtkAboutDialog, stack);
585
  gtk_widget_class_bind_template_child_private (widget_class, GtkAboutDialog, stack_switcher);
586 587 588 589 590 591 592
  gtk_widget_class_bind_template_child_private (widget_class, GtkAboutDialog, logo_image);
  gtk_widget_class_bind_template_child_private (widget_class, GtkAboutDialog, name_label);
  gtk_widget_class_bind_template_child_private (widget_class, GtkAboutDialog, version_label);
  gtk_widget_class_bind_template_child_private (widget_class, GtkAboutDialog, comments_label);
  gtk_widget_class_bind_template_child_private (widget_class, GtkAboutDialog, copyright_label);
  gtk_widget_class_bind_template_child_private (widget_class, GtkAboutDialog, license_label);
  gtk_widget_class_bind_template_child_private (widget_class, GtkAboutDialog, website_label);
593 594
  gtk_widget_class_bind_template_child_private (widget_class, GtkAboutDialog, credits_page);
  gtk_widget_class_bind_template_child_private (widget_class, GtkAboutDialog, license_page);
595 596
  gtk_widget_class_bind_template_child_private (widget_class, GtkAboutDialog, credits_grid);
  gtk_widget_class_bind_template_child_private (widget_class, GtkAboutDialog, license_view);
597 598 599 600 601

  gtk_widget_class_bind_template_callback (widget_class, emit_activate_link);
  gtk_widget_class_bind_template_callback (widget_class, text_view_event_after);
  gtk_widget_class_bind_template_callback (widget_class, text_view_key_press_event);
  gtk_widget_class_bind_template_callback (widget_class, text_view_motion_notify_event);
602
  gtk_widget_class_bind_template_callback (widget_class, stack_visible_child_notify);
603 604
}

605
static gboolean
606 607
emit_activate_link (GtkAboutDialog *about,
                    const gchar    *uri)
608
{
609
  gboolean handled = FALSE;
610

611
  g_signal_emit (about, signals[ACTIVATE_LINK], 0, uri, &handled);
612 613 614 615

  return TRUE;
}

616 617 618 619 620 621 622 623 624 625 626 627
static void
update_stack_switcher_visibility (GtkAboutDialog *about)
{
  GtkAboutDialogPrivate *priv = about->priv;

  if (gtk_widget_get_visible (priv->credits_page) ||
      gtk_widget_get_visible (priv->license_page))
    gtk_widget_show (priv->stack_switcher);
  else
    gtk_widget_hide (priv->stack_switcher);
}

628 629 630 631 632
static void
update_license_button_visibility (GtkAboutDialog *about)
{
  GtkAboutDialogPrivate *priv = about->priv;

633
  if (priv->license_type == GTK_LICENSE_CUSTOM && priv->license != NULL && priv->license[0] != '\0')
634
    gtk_widget_show (priv->license_page);
635
  else
636 637 638
    gtk_widget_hide (priv->license_page);

  update_stack_switcher_visibility (about);
639 640 641 642 643 644 645 646 647 648 649
}

static void
update_credits_button_visibility (GtkAboutDialog *about)
{
  GtkAboutDialogPrivate *priv = about->priv;
  gboolean show;

  show = (priv->authors != NULL ||
          priv->documenters != NULL ||
          priv->artists != NULL ||
650
          priv->credit_sections != NULL ||
Matthias Clasen's avatar
Matthias Clasen committed
651 652 653
          (priv->translator_credits != NULL &&
           strcmp (priv->translator_credits, "translator_credits") &&
           strcmp (priv->translator_credits, "translator-credits")));
654
  if (show)
655
    gtk_widget_show (priv->credits_page);
656
  else
657 658 659
    gtk_widget_hide (priv->credits_page);

  update_stack_switcher_visibility (about);
660 661 662 663
}

static void
switch_page (GtkAboutDialog *about,
664
             const gchar    *name)
665 666 667
{
  GtkAboutDialogPrivate *priv = about->priv;

668
  gtk_stack_set_visible_child_name (GTK_STACK (priv->stack), name);
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

  priv->in_switch_page = TRUE;
  if (priv->credits_button)
    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->credits_button),
                                  g_str_equal (name, "credits"));
  if (priv->license_button)
    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->license_button),
                                  g_str_equal (name, "license"));
  priv->in_switch_page = FALSE;
}

static void
apply_use_header_bar (GtkAboutDialog *about)
{
  GtkAboutDialogPrivate *priv = about->priv;
  gboolean use_header_bar;

  g_object_get (about, "use-header-bar", &use_header_bar, NULL);
  if (!use_header_bar)
    {
      GtkWidget *action_area;

      G_GNUC_BEGIN_IGNORE_DEPRECATIONS
      action_area = gtk_dialog_get_action_area (GTK_DIALOG (about));
      G_GNUC_END_IGNORE_DEPRECATIONS

695
      priv->credits_button = gtk_toggle_button_new_with_mnemonic (_("C_redits"));
696 697 698 699 700 701 702
      g_object_bind_property (priv->credits_page, "visible",
                              priv->credits_button, "visible", G_BINDING_SYNC_CREATE);
      g_signal_connect (priv->credits_button, "toggled", G_CALLBACK (toggle_credits), about);
      gtk_container_add_with_properties (GTK_CONTAINER (action_area), priv->credits_button,
                                         "secondary", TRUE,
                                         NULL);

703
      priv->license_button = gtk_toggle_button_new_with_mnemonic (_("_License"));
704 705 706 707 708 709 710 711
      g_object_bind_property (priv->license_page, "visible",
                              priv->license_button, "visible", G_BINDING_SYNC_CREATE);
      g_signal_connect (priv->license_button, "toggled", G_CALLBACK (toggle_license), about);
      gtk_container_add_with_properties (GTK_CONTAINER (action_area), priv->license_button,
                                         "secondary", TRUE,
                                         NULL);


712
      gtk_dialog_add_button (GTK_DIALOG (about), _("_Close"), GTK_RESPONSE_DELETE_EVENT);
713
    }
714 715
}

716 717 718 719 720 721
static void
gtk_about_dialog_init (GtkAboutDialog *about)
{
  GtkAboutDialogPrivate *priv;

  /* Data */
722
  priv = gtk_about_dialog_get_instance_private (about);
723
  about->priv = priv;
724 725 726 727 728

  priv->name = NULL;
  priv->version = NULL;
  priv->copyright = NULL;
  priv->comments = NULL;
729 730
  priv->website_url = NULL;
  priv->website_text = NULL;
731
  priv->translator_credits = NULL;
732
  priv->license = NULL;
733 734 735 736 737
  priv->authors = NULL;
  priv->documenters = NULL;
  priv->artists = NULL;

  priv->hovering_over_link = FALSE;
738
  priv->wrap_license = FALSE;
739

740 741
  priv->license_type = GTK_LICENSE_UNKNOWN;

742
  gtk_dialog_set_default_response (GTK_DIALOG (about), GTK_RESPONSE_CANCEL);
743

744
  gtk_widget_init_template (GTK_WIDGET (about));
745 746 747
  gtk_dialog_set_use_header_bar_from_setting (GTK_DIALOG (about));

  apply_use_header_bar (about);
748

749
  switch_page (about, "main");
750
  update_stack_switcher_visibility (about);
751

752
  /* force defaults */
753
  gtk_about_dialog_set_program_name (about, NULL);
754
  gtk_about_dialog_set_logo (about, NULL);
755 756
}

Matthias Clasen's avatar
Matthias Clasen committed
757 758
static void
destroy_credit_section (gpointer data)
759 760 761 762 763 764 765
{
  CreditSection *cs = data;
  g_free (cs->heading);
  g_strfreev (cs->people);
  g_slice_free (CreditSection, data);
}

766 767 768 769
static void
gtk_about_dialog_finalize (GObject *object)
{
  GtkAboutDialog *about = GTK_ABOUT_DIALOG (object);
Cody Russell's avatar
Cody Russell committed
770
  GtkAboutDialogPrivate *priv = about->priv;
771 772 773 774 775 776

  g_free (priv->name);
  g_free (priv->version);
  g_free (priv->copyright);
  g_free (priv->comments);
  g_free (priv->license);
777 778
  g_free (priv->website_url);
  g_free (priv->website_text);
779 780 781 782 783 784
  g_free (priv->translator_credits);

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

785
  g_slist_free_full (priv->credit_sections, destroy_credit_section);
Matthias Clasen's avatar
Matthias Clasen committed
786
  g_slist_free_full (priv->visited_links, g_free);
787

788 789 790
  G_OBJECT_CLASS (gtk_about_dialog_parent_class)->finalize (object);
}

791 792 793 794 795 796 797 798 799 800
static void
gtk_about_dialog_realize (GtkWidget *widget)
{
  GtkAboutDialog *about = GTK_ABOUT_DIALOG (widget);
  GtkAboutDialogPrivate *priv = about->priv;
  GdkDisplay *display;

  GTK_WIDGET_CLASS (gtk_about_dialog_parent_class)->realize (widget);

  display = gtk_widget_get_display (widget);
Matthias Clasen's avatar
Matthias Clasen committed
801 802
  priv->hand_cursor = gdk_cursor_new_from_name (display, "pointer");
  priv->regular_cursor = gdk_cursor_new_from_name (display, "text");
803 804 805 806 807 808 809 810 811 812 813 814 815 816
}

static void
gtk_about_dialog_unrealize (GtkWidget *widget)
{
  GtkAboutDialog *about = GTK_ABOUT_DIALOG (widget);
  GtkAboutDialogPrivate *priv = about->priv;

  g_clear_object (&priv->hand_cursor);
  g_clear_object (&priv->regular_cursor);

  GTK_WIDGET_CLASS (gtk_about_dialog_parent_class)->unrealize (widget);
}

817
static void
Matthias Clasen's avatar
Matthias Clasen committed
818 819 820 821
gtk_about_dialog_set_property (GObject      *object,
                               guint         prop_id,
                               const GValue *value,
                               GParamSpec   *pspec)
822 823 824
{
  GtkAboutDialog *about = GTK_ABOUT_DIALOG (object);

Matthias Clasen's avatar
Matthias Clasen committed
825
  switch (prop_id)
826 827
    {
    case PROP_NAME:
828
      gtk_about_dialog_set_program_name (about, g_value_get_string (value));
829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844
      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;
845 846 847
    case PROP_LICENSE_TYPE:
      gtk_about_dialog_set_license_type (about, g_value_get_enum (value));
      break;
848 849 850 851 852
    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));
Matthias Clasen's avatar
Matthias Clasen committed
853
      break;
854
    case PROP_AUTHORS:
855
      gtk_about_dialog_set_authors (about, (const gchar**)g_value_get_boxed (value));
856 857
      break;
    case PROP_DOCUMENTERS:
858
      gtk_about_dialog_set_documenters (about, (const gchar**)g_value_get_boxed (value));
Matthias Clasen's avatar
Matthias Clasen committed
859
      break;
860
    case PROP_ARTISTS:
861
      gtk_about_dialog_set_artists (about, (const gchar**)g_value_get_boxed (value));
Matthias Clasen's avatar
Matthias Clasen committed
862
      break;
863 864 865
    case PROP_TRANSLATOR_CREDITS:
      gtk_about_dialog_set_translator_credits (about, g_value_get_string (value));
      break;
866 867 868
    case PROP_LOGO_ICON_NAME:
      gtk_about_dialog_set_logo_icon_name (about, g_value_get_string (value));
      break;
869
    case PROP_WRAP_LICENSE:
870
      gtk_about_dialog_set_wrap_license (about, g_value_get_boolean (value));
871
      break;
872 873 874 875 876 877 878
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
    }
}

static void
Matthias Clasen's avatar
Matthias Clasen committed
879 880 881 882
gtk_about_dialog_get_property (GObject    *object,
                               guint       prop_id,
                               GValue     *value,
                               GParamSpec *pspec)
883 884
{
  GtkAboutDialog *about = GTK_ABOUT_DIALOG (object);
Cody Russell's avatar
Cody Russell committed
885
  GtkAboutDialogPrivate *priv = about->priv;
Matthias Clasen's avatar
Matthias Clasen committed
886 887

  switch (prop_id)
888 889 890 891 892 893 894 895 896 897 898 899 900 901
    {
    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:
902
      g_value_set_string (value, priv->website_url);
903 904
      break;
    case PROP_WEBSITE_LABEL:
905
      g_value_set_string (value, priv->website_text);
906 907 908 909
      break;
    case PROP_LICENSE:
      g_value_set_string (value, priv->license);
      break;
910 911 912
    case PROP_LICENSE_TYPE:
      g_value_set_enum (value, priv->license_type);
      break;
913 914 915 916 917 918 919 920 921 922 923 924 925
    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:
926
      if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_PIXBUF)
Matthias Clasen's avatar
Matthias Clasen committed
927
        g_value_set_object (value, gtk_image_get_pixbuf (GTK_IMAGE (priv->logo_image)));
928
      else
Matthias Clasen's avatar
Matthias Clasen committed
929
        g_value_set_object (value, NULL);
930 931 932
      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
933 934
        {
          const gchar *icon_name;
935

Matthias Clasen's avatar
Matthias Clasen committed
936 937 938
          gtk_image_get_icon_name (GTK_IMAGE (priv->logo_image), &icon_name, NULL);
          g_value_set_string (value, icon_name);
        }
939
      else
Matthias Clasen's avatar
Matthias Clasen committed
940
        g_value_set_string (value, NULL);
941
      break;
942 943 944
    case PROP_WRAP_LICENSE:
      g_value_set_boolean (value, priv->wrap_license);
      break;
945 946 947 948 949 950
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
    }
}

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
static void
toggle_credits (GtkToggleButton *button,
                gpointer         user_data)
{
  GtkAboutDialog *about = user_data;
  GtkAboutDialogPrivate *priv = about->priv;
  gboolean show_credits;

  if (priv->in_switch_page)
    return;

  show_credits = gtk_toggle_button_get_active (button);
  switch_page (about, show_credits ? "credits" : "main");
}

static void
toggle_license (GtkToggleButton *button,
                gpointer         user_data)
{
  GtkAboutDialog *about = user_data;
  GtkAboutDialogPrivate *priv = about->priv;
  gboolean show_license;

  if (priv->in_switch_page)
    return;

  show_license = gtk_toggle_button_get_active (button);
  switch_page (about, show_license ? "license" : "main");
}

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
static gboolean
gtk_about_dialog_activate_link (GtkAboutDialog *about,
                                const gchar    *uri)
{
  GdkScreen *screen;
  GError *error = NULL;

  screen = gtk_widget_get_screen (GTK_WIDGET (about));

  if (!gtk_show_uri (screen, uri, gtk_get_current_event_time (), &error))
    {
      GtkWidget *dialog;

      dialog = gtk_message_dialog_new (GTK_WINDOW (about),
                                       GTK_DIALOG_DESTROY_WITH_PARENT |
                                       GTK_DIALOG_MODAL,
                                       GTK_MESSAGE_ERROR,
                                       GTK_BUTTONS_CLOSE,
                                       "%s", _("Could not show link"));
      gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
                                                "%s", error->message);
      g_error_free (error);

      g_signal_connect (dialog, "response",
                        G_CALLBACK (gtk_widget_destroy), NULL);

      gtk_window_present (GTK_WINDOW (dialog));
    }

  return TRUE;
}

1013 1014 1015
static void
update_website (GtkAboutDialog *about)
{
Cody Russell's avatar
Cody Russell committed
1016
  GtkAboutDialogPrivate *priv = about->priv;
1017

1018 1019
  gtk_widget_show (priv->website_label);

1020
  if (priv->website_url)
1021
    {
1022
      gchar *markup;
1023 1024

      if (priv->website_text)
1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035
        {
          gchar *escaped;

          escaped = g_markup_escape_text (priv->website_text, -1);
          markup = g_strdup_printf ("<a href=\"%s\">%s</a>",
                                    priv->website_url, escaped);
          g_free (escaped);
        }
      else
        {
          markup = g_strdup_printf ("<a href=\"%s\">%s</a>",
1036
                                    priv->website_url, _("Website"));
1037 1038
        }

1039
      gtk_label_set_markup (GTK_LABEL (priv->website_label), markup);
1040
      g_free (markup);
1041 1042 1043
    }
  else
    {
1044
      if (priv->website_text)
1045 1046 1047 1048 1049 1050 1051 1052 1053 1054
        gtk_label_set_text (GTK_LABEL (priv->website_label), priv->website_text);
      else
        gtk_widget_hide (priv->website_label);
    }
}

static void
gtk_about_dialog_show (GtkWidget *widget)
{
  update_website (GTK_ABOUT_DIALOG (widget));
Matthias Clasen's avatar
Matthias Clasen committed
1055

1056 1057 1058
  GTK_WIDGET_CLASS (gtk_about_dialog_parent_class)->show (widget);
}

1059 1060 1061
/**
 * gtk_about_dialog_get_program_name:
 * @about: a #GtkAboutDialog
Matthias Clasen's avatar
Matthias Clasen committed
1062
 *
1063
 * Returns the program name displayed in the about dialog.
Matthias Clasen's avatar
Matthias Clasen committed
1064
 *
1065
 * Returns: The program name. The string is owned by the about
1066 1067 1068
 *  dialog and must not be modified.
 *
 * Since: 2.12
Matthias Clasen's avatar
Matthias Clasen committed
1069
 */
1070
const gchar *
1071
gtk_about_dialog_get_program_name (GtkAboutDialog *about)
1072 1073 1074
{
  g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);

Matthias Clasen's avatar
Matthias Clasen committed
1075
  return about->priv->name;
1076 1077 1078 1079 1080 1081 1082 1083
}

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

Cody Russell's avatar
Cody Russell committed
1084
  priv = about->priv;
1085 1086 1087 1088 1089

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

Matthias Clasen's avatar
Matthias Clasen committed
1090
  if (priv->version != NULL)
1091 1092 1093 1094
    {
      gtk_label_set_markup (GTK_LABEL (priv->version_label), priv->version);
      gtk_widget_show (priv->version_label);
    }
1095
  else
1096
    gtk_widget_hide (priv->version_label);
1097

1098 1099
  name_string = g_markup_printf_escaped ("<span weight=\"bold\">%s</span>",
                                         priv->name);
1100 1101 1102 1103
  gtk_label_set_markup (GTK_LABEL (priv->name_label), name_string);
  g_free (name_string);
}

1104 1105 1106 1107 1108
/**
 * gtk_about_dialog_set_program_name:
 * @about: a #GtkAboutDialog
 * @name: the program name
 *
Matthias Clasen's avatar
Matthias Clasen committed
1109
 * Sets the name to display in the about dialog.
1110
 * If this is not set, it defaults to g_get_application_name().
Matthias Clasen's avatar
Matthias Clasen committed
1111
 *
1112
 * Since: 2.12
Matthias Clasen's avatar
Matthias Clasen committed
1113
 */
1114
void
Matthias Clasen's avatar
Matthias Clasen committed
1115
gtk_about_dialog_set_program_name (GtkAboutDialog *about,
1116
                                   const gchar    *name)
1117 1118 1119 1120 1121
{
  GtkAboutDialogPrivate *priv;
  gchar *tmp;

  g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
Matthias Clasen's avatar
Matthias Clasen committed
1122

Cody Russell's avatar
Cody Russell committed
1123 1124
  priv = about->priv;

1125 1126 1127 1128 1129 1130
  tmp = priv->name;
  priv->name = g_strdup (name ? name : g_get_application_name ());
  g_free (tmp);

  update_name_version (about);

1131
  g_object_notify_by_pspec (G_OBJECT (about), props[PROP_NAME]);
1132 1133
}

1134

1135 1136 1137
/**
 * gtk_about_dialog_get_version:
 * @about: a #GtkAboutDialog
Matthias Clasen's avatar
Matthias Clasen committed
1138
 *
1139
 * Returns the version string.
Matthias Clasen's avatar
Matthias Clasen committed
1140
 *
1141
 * Returns: The version string. The string is owned by the about
1142 1143 1144
 *  dialog and must not be modified.
 *
 * Since: 2.6
Matthias Clasen's avatar
Matthias Clasen committed
1145
 */
1146
const gchar *
1147 1148 1149 1150
gtk_about_dialog_get_version (GtkAboutDialog *about)
{
  g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);

Cody Russell's avatar
Cody Russell committed
1151
  return about->priv->version;
1152 1153 1154 1155 1156
}

/**
 * gtk_about_dialog_set_version:
 * @about: a #GtkAboutDialog
1157
 * @version: (allow-none): the version string
1158 1159
 *
 * Sets the version string to display in the about dialog.
Matthias Clasen's avatar
Matthias Clasen committed
1160
 *
1161
 * Since: 2.6
Matthias Clasen's avatar
Matthias Clasen committed
1162
 */
1163
void
Matthias Clasen's avatar
Matthias Clasen committed
1164 1165
gtk_about_dialog_set_version (GtkAboutDialog *about,
                              const gchar    *version)
1166 1167 1168 1169 1170 1171
{
  GtkAboutDialogPrivate *priv;
  gchar *tmp;

  g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));

Cody Russell's avatar
Cody Russell committed
1172 1173
  priv = about->priv;

1174
  tmp = priv->version;
1175
  priv->version = g_strdup (version);
Matthias Clasen's avatar
Matthias Clasen committed
1176
  g_free (tmp);
1177 1178 1179

  update_name_version (about);

1180
  g_object_notify_by_pspec (G_OBJECT (about), props[PROP_VERSION]);
1181 1182 1183 1184 1185
}

/**
 * gtk_about_dialog_get_copyright:
 * @about: a #GtkAboutDialog
Matthias Clasen's avatar
Matthias Clasen committed
1186
 *
1187
 * Returns the copyright string.
Matthias Clasen's avatar
Matthias Clasen committed
1188
 *
1189
 * Returns: The copyright string. The string is owned by the about
1190 1191 1192
 *  dialog and must not be modified.
 *
 * Since: 2.6
Matthias Clasen's avatar
Matthias Clasen committed
1193
 */
1194
const gchar *
1195 1196 1197 1198
gtk_about_dialog_get_copyright (GtkAboutDialog *about)
{
  g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);

Cody Russell's avatar
Cody Russell committed
1199
  return about->priv->copyright;
1200 1201 1202 1203 1204
}

/**
 * gtk_about_dialog_set_copyright:
 * @about: a #GtkAboutDialog
Jasper St. Pierre's avatar
Jasper St. Pierre committed
1205
 * @copyright: (allow-none): the copyright string
Matthias Clasen's avatar
Matthias Clasen committed
1206
 *
1207
 * Sets the copyright string to display in the about dialog.
Matthias Clasen's avatar
Matthias Clasen committed
1208
 * This should be a short string of one or two lines.