nmt-editor-page.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. /* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
  2. /*
  3. * This program is free software; you can redistribute it and/or
  4. * modify it under the terms of the GNU General Public License as
  5. * published by the Free Software Foundation; either version 2 of the
  6. * License, or (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. * General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. *
  16. * Copyright 2013 Red Hat, Inc.
  17. */
  18. /**
  19. * SECTION:nmt-editor-page:
  20. * @short_description: An #NmtEditor "page"
  21. *
  22. * #NmtEditorPage is the abstract base class for #NmtEditor "pages".
  23. * Note that despite the name, currently all "page" types except
  24. * #NmtPageMain are actually displayed as collapsible sections, not
  25. * separate tabs/forms.
  26. */
  27. #include "config.h"
  28. #include <glib/gi18n-lib.h>
  29. #include "nmt-editor-page.h"
  30. G_DEFINE_ABSTRACT_TYPE (NmtEditorPage, nmt_editor_page, NMT_TYPE_PAGE_GRID)
  31. #define NMT_EDITOR_PAGE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NMT_TYPE_EDITOR_PAGE, NmtEditorPagePrivate))
  32. typedef struct {
  33. char *title;
  34. NmtNewtWidget *header_widget;
  35. NMConnection *connection;
  36. } NmtEditorPagePrivate;
  37. enum {
  38. PROP_0,
  39. PROP_CONNECTION,
  40. PROP_TITLE,
  41. LAST_PROP
  42. };
  43. static void
  44. nmt_editor_page_init (NmtEditorPage *page)
  45. {
  46. NmtEditorPagePrivate *priv = NMT_EDITOR_PAGE_GET_PRIVATE (page);
  47. priv->header_widget = g_object_ref_sink (nmt_newt_separator_new ());
  48. }
  49. static void
  50. nmt_editor_page_finalize (GObject *object)
  51. {
  52. NmtEditorPagePrivate *priv = NMT_EDITOR_PAGE_GET_PRIVATE (object);
  53. g_free (priv->title);
  54. g_clear_object (&priv->header_widget);
  55. g_clear_object (&priv->connection);
  56. G_OBJECT_CLASS (nmt_editor_page_parent_class)->finalize (object);
  57. }
  58. /**
  59. * nmt_editor_page_get_connection:
  60. * @page: the #NmtEditorPage
  61. *
  62. * Gets the page's #NMConnection.
  63. *
  64. * Returns: (transfer none): the page's #NMConnection.
  65. */
  66. NMConnection *
  67. nmt_editor_page_get_connection (NmtEditorPage *page)
  68. {
  69. NmtEditorPagePrivate *priv = NMT_EDITOR_PAGE_GET_PRIVATE (page);
  70. return priv->connection;
  71. }
  72. /**
  73. * nmt_editor_page_set_header_widget:
  74. * @page: the #NmtEditorPage
  75. * @widget: an #NmtNewtWidget
  76. *
  77. * Sets the page's header widget. When displayed as a subpage of
  78. * #NmtPageMain, this widget will be put into the corresponding
  79. * #NmtNewtSection's header.
  80. *
  81. * FIXME: for consistency, this should be a property as well.
  82. */
  83. void
  84. nmt_editor_page_set_header_widget (NmtEditorPage *page,
  85. NmtNewtWidget *widget)
  86. {
  87. NmtEditorPagePrivate *priv = NMT_EDITOR_PAGE_GET_PRIVATE (page);
  88. g_clear_object (&priv->header_widget);
  89. if (!widget)
  90. widget = nmt_newt_separator_new ();
  91. priv->header_widget = g_object_ref_sink (widget);
  92. }
  93. /**
  94. * nmt_editor_page_get_header_widget:
  95. * @page: the #NmtEditorPage
  96. *
  97. * Gets the page's header widget. When displayed as a subpage of
  98. * #NmtPageMain, this widget will be put into the corresponding
  99. * #NmtNewtSection's header.
  100. *
  101. * Returns: (transfer none): the page's header widget.
  102. */
  103. NmtNewtWidget *
  104. nmt_editor_page_get_header_widget (NmtEditorPage *page)
  105. {
  106. NmtEditorPagePrivate *priv = NMT_EDITOR_PAGE_GET_PRIVATE (page);
  107. return priv->header_widget;
  108. }
  109. /**
  110. * nmt_editor_page_get_title:
  111. * @page: the #NmtEditorPage
  112. *
  113. * Gets the page's title.
  114. *
  115. * Returns: the page's title
  116. */
  117. const char *
  118. nmt_editor_page_get_title (NmtEditorPage *page)
  119. {
  120. NmtEditorPagePrivate *priv = NMT_EDITOR_PAGE_GET_PRIVATE (page);
  121. return priv->title;
  122. }
  123. static void
  124. nmt_editor_page_set_property (GObject *object,
  125. guint prop_id,
  126. const GValue *value,
  127. GParamSpec *pspec)
  128. {
  129. NmtEditorPagePrivate *priv = NMT_EDITOR_PAGE_GET_PRIVATE (object);
  130. switch (prop_id) {
  131. case PROP_CONNECTION:
  132. priv->connection = g_value_dup_object (value);
  133. break;
  134. case PROP_TITLE:
  135. priv->title = g_value_dup_string (value);
  136. break;
  137. default:
  138. G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
  139. break;
  140. }
  141. }
  142. static void
  143. nmt_editor_page_get_property (GObject *object,
  144. guint prop_id,
  145. GValue *value,
  146. GParamSpec *pspec)
  147. {
  148. NmtEditorPagePrivate *priv = NMT_EDITOR_PAGE_GET_PRIVATE (object);
  149. switch (prop_id) {
  150. case PROP_CONNECTION:
  151. g_value_set_object (value, priv->connection);
  152. break;
  153. case PROP_TITLE:
  154. g_value_set_string (value, priv->title);
  155. break;
  156. default:
  157. G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
  158. break;
  159. }
  160. }
  161. static void
  162. nmt_editor_page_class_init (NmtEditorPageClass *page_class)
  163. {
  164. GObjectClass *object_class = G_OBJECT_CLASS (page_class);
  165. g_type_class_add_private (page_class, sizeof (NmtEditorPagePrivate));
  166. /* virtual methods */
  167. object_class->set_property = nmt_editor_page_set_property;
  168. object_class->get_property = nmt_editor_page_get_property;
  169. object_class->finalize = nmt_editor_page_finalize;
  170. /* properties */
  171. /**
  172. * NmtEditorPage:connection:
  173. *
  174. * The page's #NMConnection.
  175. */
  176. g_object_class_install_property (object_class, PROP_CONNECTION,
  177. g_param_spec_object ("connection", "", "",
  178. NM_TYPE_CONNECTION,
  179. G_PARAM_READWRITE |
  180. G_PARAM_CONSTRUCT_ONLY |
  181. G_PARAM_STATIC_STRINGS));
  182. /**
  183. * NmtEditorPage:title:
  184. *
  185. * The page's title.
  186. */
  187. g_object_class_install_property (object_class, PROP_TITLE,
  188. g_param_spec_string ("title", "", "",
  189. NULL,
  190. G_PARAM_READWRITE |
  191. G_PARAM_CONSTRUCT_ONLY |
  192. G_PARAM_STATIC_STRINGS));
  193. }