diff options
| author | Michael Biebl <biebl@debian.org> | 2020-10-05 22:27:18 +0200 |
|---|---|---|
| committer | Michael Biebl <biebl@debian.org> | 2020-10-05 22:27:18 +0200 |
| commit | aafc1dbe4712c86189bbc1d4d54ad8cb4c69be7e (patch) | |
| tree | a2a9bb4d007339a0b1304540388230ccedac32bd /clients/tui/nmt-editor-section.c | |
| parent | e7b44ef4c80907346ec7492a09c45277459924fc (diff) | |
New upstream version 1.27.90 upstream/1.27.90
Diffstat (limited to 'clients/tui/nmt-editor-section.c')
| -rw-r--r-- | clients/tui/nmt-editor-section.c | 317 |
1 files changed, 158 insertions, 159 deletions
diff --git a/clients/tui/nmt-editor-section.c b/clients/tui/nmt-editor-section.c index e92df70d..eac23ba6 100644 --- a/clients/tui/nmt-editor-section.c +++ b/clients/tui/nmt-editor-section.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0+ +/* SPDX-License-Identifier: GPL-2.0+ */ /* * Copyright (C) 2013 Red Hat, Inc. */ @@ -15,27 +15,28 @@ #include "nmt-editor-section.h" #include "nmt-newt-toggle-button.h" -G_DEFINE_TYPE (NmtEditorSection, nmt_editor_section, NMT_TYPE_NEWT_SECTION) +G_DEFINE_TYPE(NmtEditorSection, nmt_editor_section, NMT_TYPE_NEWT_SECTION) -#define NMT_EDITOR_SECTION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NMT_TYPE_EDITOR_SECTION, NmtEditorSectionPrivate)) +#define NMT_EDITOR_SECTION_GET_PRIVATE(o) \ + (G_TYPE_INSTANCE_GET_PRIVATE((o), NMT_TYPE_EDITOR_SECTION, NmtEditorSectionPrivate)) typedef struct { - NmtEditorGrid *header, *body; - char *title; - NmtNewtWidget *header_widget; - NmtNewtWidget *toggle; + NmtEditorGrid *header, *body; + char * title; + NmtNewtWidget *header_widget; + NmtNewtWidget *toggle; - gboolean show_by_default; + gboolean show_by_default; } NmtEditorSectionPrivate; enum { - PROP_0, + PROP_0, - PROP_TITLE, - PROP_SHOW_BY_DEFAULT, - PROP_HEADER_WIDGET, + PROP_TITLE, + PROP_SHOW_BY_DEFAULT, + PROP_HEADER_WIDGET, - LAST_PROP + LAST_PROP }; /** @@ -49,65 +50,61 @@ enum { * Returns: a new #NmtEditorSection */ NmtEditorSection * -nmt_editor_section_new (const char *title, - NmtNewtWidget *header_widget, - gboolean show_by_default) +nmt_editor_section_new(const char *title, NmtNewtWidget *header_widget, gboolean show_by_default) { - return g_object_new (NMT_TYPE_EDITOR_SECTION, - "title", title, - "header-widget", header_widget, - "show-by-default", show_by_default, - NULL); + return g_object_new(NMT_TYPE_EDITOR_SECTION, + "title", + title, + "header-widget", + header_widget, + "show-by-default", + show_by_default, + NULL); } static void -rebuild_header (NmtEditorSection *section) +rebuild_header(NmtEditorSection *section) { - NmtEditorSectionPrivate *priv = NMT_EDITOR_SECTION_GET_PRIVATE (section); - - /* Removing any widget in an NmtEditorGrid removes its whole row, so we can - * remove the existing title/widget/toggle by asking to remove toggle. - */ - nmt_newt_container_remove (NMT_NEWT_CONTAINER (priv->header), priv->toggle); - - nmt_editor_grid_append (priv->header, - priv->title, - priv->header_widget, - priv->toggle); - nmt_editor_grid_set_row_flags (priv->header, - priv->toggle, - NMT_EDITOR_GRID_ROW_LABEL_ALIGN_LEFT | - NMT_EDITOR_GRID_ROW_EXTRA_ALIGN_RIGHT); + NmtEditorSectionPrivate *priv = NMT_EDITOR_SECTION_GET_PRIVATE(section); + + /* Removing any widget in an NmtEditorGrid removes its whole row, so we can + * remove the existing title/widget/toggle by asking to remove toggle. + */ + nmt_newt_container_remove(NMT_NEWT_CONTAINER(priv->header), priv->toggle); + + nmt_editor_grid_append(priv->header, priv->title, priv->header_widget, priv->toggle); + nmt_editor_grid_set_row_flags(priv->header, + priv->toggle, + NMT_EDITOR_GRID_ROW_LABEL_ALIGN_LEFT + | NMT_EDITOR_GRID_ROW_EXTRA_ALIGN_RIGHT); } static void -nmt_editor_section_init (NmtEditorSection *section) +nmt_editor_section_init(NmtEditorSection *section) { - NmtEditorSectionPrivate *priv = NMT_EDITOR_SECTION_GET_PRIVATE (section); + NmtEditorSectionPrivate *priv = NMT_EDITOR_SECTION_GET_PRIVATE(section); - priv->header = NMT_EDITOR_GRID (nmt_editor_grid_new ()); - priv->body = NMT_EDITOR_GRID (nmt_editor_grid_new ()); - priv->toggle = nmt_newt_toggle_button_new (_("Hide"), _("Show")); - g_object_ref_sink (priv->toggle); + priv->header = NMT_EDITOR_GRID(nmt_editor_grid_new()); + priv->body = NMT_EDITOR_GRID(nmt_editor_grid_new()); + priv->toggle = nmt_newt_toggle_button_new(_("Hide"), _("Show")); + g_object_ref_sink(priv->toggle); - nmt_newt_section_set_header (NMT_NEWT_SECTION (section), NMT_NEWT_WIDGET (priv->header)); - nmt_newt_section_set_body (NMT_NEWT_SECTION (section), NMT_NEWT_WIDGET (priv->body)); + nmt_newt_section_set_header(NMT_NEWT_SECTION(section), NMT_NEWT_WIDGET(priv->header)); + nmt_newt_section_set_body(NMT_NEWT_SECTION(section), NMT_NEWT_WIDGET(priv->body)); - g_object_bind_property (priv->toggle, "active", - section, "open", - G_BINDING_SYNC_CREATE); + g_object_bind_property(priv->toggle, "active", section, "open", G_BINDING_SYNC_CREATE); } static void -nmt_editor_section_finalize (GObject *object) +nmt_editor_section_finalize(GObject *object) { - NmtEditorSectionPrivate *priv = NMT_EDITOR_SECTION_GET_PRIVATE (object); + NmtEditorSectionPrivate *priv = NMT_EDITOR_SECTION_GET_PRIVATE(object); - g_free (priv->title); - g_clear_object (&priv->header_widget); - g_clear_object (&priv->toggle); + g_free(priv->title); + g_clear_object(&priv->header_widget); + g_clear_object(&priv->toggle); - G_OBJECT_CLASS (nmt_editor_section_parent_class)->finalize (object); + G_OBJECT_CLASS(nmt_editor_section_parent_class)->finalize(object); } /** @@ -119,11 +116,11 @@ nmt_editor_section_finalize (GObject *object) * Returns: the section's header widget. */ NmtNewtWidget * -nmt_editor_section_get_header_widget (NmtEditorSection *section) +nmt_editor_section_get_header_widget(NmtEditorSection *section) { - NmtEditorSectionPrivate *priv = NMT_EDITOR_SECTION_GET_PRIVATE (section); + NmtEditorSectionPrivate *priv = NMT_EDITOR_SECTION_GET_PRIVATE(section); - return priv->header_widget; + return priv->header_widget; } /** @@ -135,11 +132,11 @@ nmt_editor_section_get_header_widget (NmtEditorSection *section) * Returns: the #NmtEditorGrid used for the section body */ NmtEditorGrid * -nmt_editor_section_get_body (NmtEditorSection *section) +nmt_editor_section_get_body(NmtEditorSection *section) { - NmtEditorSectionPrivate *priv = NMT_EDITOR_SECTION_GET_PRIVATE (section); + NmtEditorSectionPrivate *priv = NMT_EDITOR_SECTION_GET_PRIVATE(section); - return priv->body; + return priv->body; } /** @@ -151,117 +148,119 @@ nmt_editor_section_get_body (NmtEditorSection *section) * Returns: the section's title */ const char * -nmt_editor_section_get_title (NmtEditorSection *section) +nmt_editor_section_get_title(NmtEditorSection *section) { - NmtEditorSectionPrivate *priv = NMT_EDITOR_SECTION_GET_PRIVATE (section); + NmtEditorSectionPrivate *priv = NMT_EDITOR_SECTION_GET_PRIVATE(section); - return priv->title; + return priv->title; } static void -nmt_editor_section_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) +nmt_editor_section_set_property(GObject * object, + guint prop_id, + const GValue *value, + GParamSpec * pspec) { - NmtEditorSection *section = NMT_EDITOR_SECTION (object); - NmtEditorSectionPrivate *priv = NMT_EDITOR_SECTION_GET_PRIVATE (section); - - switch (prop_id) { - case PROP_TITLE: - priv->title = g_value_dup_string (value); - rebuild_header (section); - break; - case PROP_SHOW_BY_DEFAULT: - priv->show_by_default = g_value_get_boolean (value); - nmt_newt_toggle_button_set_active (NMT_NEWT_TOGGLE_BUTTON (priv->toggle), - priv->show_by_default); - break; - case PROP_HEADER_WIDGET: - priv->header_widget = g_value_get_object (value); - if (priv->header_widget) - g_object_ref_sink (priv->header_widget); - rebuild_header (section); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } + NmtEditorSection * section = NMT_EDITOR_SECTION(object); + NmtEditorSectionPrivate *priv = NMT_EDITOR_SECTION_GET_PRIVATE(section); + + switch (prop_id) { + case PROP_TITLE: + priv->title = g_value_dup_string(value); + rebuild_header(section); + break; + case PROP_SHOW_BY_DEFAULT: + priv->show_by_default = g_value_get_boolean(value); + nmt_newt_toggle_button_set_active(NMT_NEWT_TOGGLE_BUTTON(priv->toggle), + priv->show_by_default); + break; + case PROP_HEADER_WIDGET: + priv->header_widget = g_value_get_object(value); + if (priv->header_widget) + g_object_ref_sink(priv->header_widget); + rebuild_header(section); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + break; + } } static void -nmt_editor_section_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) +nmt_editor_section_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - NmtEditorSectionPrivate *priv = NMT_EDITOR_SECTION_GET_PRIVATE (object); - - switch (prop_id) { - case PROP_TITLE: - g_value_set_string (value, priv->title); - break; - case PROP_SHOW_BY_DEFAULT: - g_value_set_boolean (value, priv->show_by_default); - break; - case PROP_HEADER_WIDGET: - g_value_set_object (value, priv->header_widget); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } + NmtEditorSectionPrivate *priv = NMT_EDITOR_SECTION_GET_PRIVATE(object); + + switch (prop_id) { + case PROP_TITLE: + g_value_set_string(value, priv->title); + break; + case PROP_SHOW_BY_DEFAULT: + g_value_set_boolean(value, priv->show_by_default); + break; + case PROP_HEADER_WIDGET: + g_value_set_object(value, priv->header_widget); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + break; + } } static void -nmt_editor_section_class_init (NmtEditorSectionClass *section_class) +nmt_editor_section_class_init(NmtEditorSectionClass *section_class) { - GObjectClass *object_class = G_OBJECT_CLASS (section_class); - - g_type_class_add_private (section_class, sizeof (NmtEditorSectionPrivate)); - - /* virtual methods */ - object_class->set_property = nmt_editor_section_set_property; - object_class->get_property = nmt_editor_section_get_property; - object_class->finalize = nmt_editor_section_finalize; - - /* properties */ - - /** - * NmtEditorSection:title: - * - * The section's title. - */ - g_object_class_install_property - (object_class, PROP_TITLE, - g_param_spec_string ("title", "", "", - NULL, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS)); - - /** - * NmtEditorSection:show-by-default: - * - * Whether the section should be expanded by default. - */ - g_object_class_install_property - (object_class, PROP_SHOW_BY_DEFAULT, - g_param_spec_boolean ("show-by-default", "", "", - TRUE, - G_PARAM_READWRITE | - G_PARAM_STATIC_STRINGS)); - - /** - * NmtEditorSection:header-widget: - * - * The widget (if any) that appears between the section title and its toggle - * button. - */ - g_object_class_install_property - (object_class, PROP_HEADER_WIDGET, - g_param_spec_object ("header-widget", "", "", - NMT_TYPE_NEWT_WIDGET, - G_PARAM_READWRITE | - G_PARAM_STATIC_STRINGS)); + GObjectClass *object_class = G_OBJECT_CLASS(section_class); + + g_type_class_add_private(section_class, sizeof(NmtEditorSectionPrivate)); + + /* virtual methods */ + object_class->set_property = nmt_editor_section_set_property; + object_class->get_property = nmt_editor_section_get_property; + object_class->finalize = nmt_editor_section_finalize; + + /* properties */ + + /** + * NmtEditorSection:title: + * + * The section's title. + */ + g_object_class_install_property( + object_class, + PROP_TITLE, + g_param_spec_string("title", + "", + "", + NULL, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); + + /** + * NmtEditorSection:show-by-default: + * + * Whether the section should be expanded by default. + */ + g_object_class_install_property( + object_class, + PROP_SHOW_BY_DEFAULT, + g_param_spec_boolean("show-by-default", + "", + "", + TRUE, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + + /** + * NmtEditorSection:header-widget: + * + * The widget (if any) that appears between the section title and its toggle + * button. + */ + g_object_class_install_property( + object_class, + PROP_HEADER_WIDGET, + g_param_spec_object("header-widget", + "", + "", + NMT_TYPE_NEWT_WIDGET, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); } |