diff options
-rw-r--r-- | endless/eospagemanager.c | 193 | ||||
-rw-r--r-- | endless/eospagemanager.h | 48 | ||||
-rw-r--r-- | test/test-page-manager.c | 115 |
3 files changed, 339 insertions, 17 deletions
diff --git a/endless/eospagemanager.c b/endless/eospagemanager.c index 051ccce..98f6108 100644 --- a/endless/eospagemanager.c +++ b/endless/eospagemanager.c @@ -94,6 +94,8 @@ struct _EosPageManagerPageInfo { GtkWidget *page; gchar *name; + gboolean fake_page_actions_visible; + GtkWidget *custom_toolbox_widget; }; struct _EosPageManagerPrivate @@ -117,6 +119,8 @@ enum { CHILD_PROP_0, CHILD_PROP_NAME, + CHILD_PROP_PAGE_ACTIONS, + CHILD_PROP_CUSTOM_TOOLBOX_WIDGET, NCHILDPROPS }; @@ -464,6 +468,17 @@ eos_page_manager_get_child_property (GtkContainer *container, g_value_set_string (value, eos_page_manager_get_page_name (self, child)); break; + case CHILD_PROP_PAGE_ACTIONS: + g_value_set_boolean (value, + eos_page_manager_get_page_actions (self, child)); + break; + + case CHILD_PROP_CUSTOM_TOOLBOX_WIDGET: + g_value_set_object (value, + eos_page_manager_get_page_custom_toolbox_widget (self, + child)); + break; + default: GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec); @@ -485,6 +500,16 @@ eos_page_manager_set_child_property (GtkContainer *container, eos_page_manager_set_page_name (self, child, g_value_get_string (value)); break; + case CHILD_PROP_PAGE_ACTIONS: + eos_page_manager_set_page_actions (self, child, + g_value_get_boolean (value)); + break; + + case CHILD_PROP_CUSTOM_TOOLBOX_WIDGET: + eos_page_manager_set_page_custom_toolbox_widget (self, child, + g_value_get_object (value)); + break; + default: GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec); @@ -563,8 +588,45 @@ eos_page_manager_class_init (EosPageManagerClass *klass) NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - gtk_container_class_install_child_property (container_class, CHILD_PROP_NAME, - eos_page_manager_child_props[CHILD_PROP_NAME]); + /** + * EosPageManager:page-actions: + * + * The actions exported by this page, to be displayed in the action area on + * the right of the window. + * + * <warning><para>Currently, this property is a boolean value. %TRUE means + * to display a fake action area, and %FALSE means don't display. + * </para></warning> + */ + eos_page_manager_child_props[CHILD_PROP_PAGE_ACTIONS] = + g_param_spec_boolean ("page-actions", "Page Actions", + "Actions the page exports into the action area", + FALSE, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + + /** + * EosPageManager:custom-toolbox-widget: + * + * The custom toolbox widget belonging to this page, to be displayed on the + * left of the window when the page is displaying. Setting this to %NULL + * indicates that there should be no toolbox widget. + * + * <warning><para>Currently, there is no such thing as a + * <emphasis>non-</emphasis>custom toolbox widget. + * </para></warning> + */ + eos_page_manager_child_props[CHILD_PROP_CUSTOM_TOOLBOX_WIDGET] = + g_param_spec_object ("custom-toolbox-widget", "Custom toolbox widget", + "Custom toolbox widget displayed left of the page", + GTK_TYPE_WIDGET, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + + /* Install child properties all at once, because there is no + gtk_container_class_install_child_properties() function */ + int count; + for (count = PROP_0 + 1; count < NCHILDPROPS; count++) + gtk_container_class_install_child_property (container_class, count, + eos_page_manager_child_props[count]); } static void @@ -784,6 +846,133 @@ eos_page_manager_set_page_name (EosPageManager *self, } /** + * eos_page_manager_get_page_actions: + * @self: the page manager + * @page: the page to be queried + * + * Gets whether to display a fake actions area when displaying @page. + * See #EosPageManager:page-actions for more information. + * + * <warning><para>This function is a temporary implementation, do not expect + * this API to remain stable. + * </para></warning> + * + * Returns: %TRUE if the fake actions area should be visible when displaying + * @page, or %FALSE if it should not. + */ +gboolean +eos_page_manager_get_page_actions (EosPageManager *self, + GtkWidget *page) +{ + g_return_val_if_fail (self != NULL && EOS_IS_PAGE_MANAGER (self), FALSE); + g_return_val_if_fail (page != NULL && GTK_IS_WIDGET (page), FALSE); + + EosPageManagerPageInfo *info = find_page_info_by_widget (self, page); + g_return_val_if_fail (info != NULL, FALSE); + + return info->fake_page_actions_visible; +} + +/** + * eos_page_manager_set_page_actions: + * @self: the page manager + * @page: the page + * @actions_visible: whether to display an action area beside @page + * + * Sets whether to display a fake actions area when displaying @page. + * See #EosPageManager:page-actions for more information. + * + * <warning><para>This function is a temporary implementation, do not expect + * this API to remain stable. + * </para></warning> + */ +void +eos_page_manager_set_page_actions (EosPageManager *self, + GtkWidget *page, + gboolean actions_visible) +{ + g_return_if_fail (self != NULL && EOS_IS_PAGE_MANAGER (self)); + g_return_if_fail (page != NULL && GTK_IS_WIDGET (page)); + + EosPageManagerPageInfo *info = find_page_info_by_widget (self, page); + g_return_if_fail (info != NULL); + + if (info->fake_page_actions_visible == actions_visible) + return; + + info->fake_page_actions_visible = actions_visible; + + gtk_container_child_notify (GTK_CONTAINER (self), page, "page-actions"); +} + +/** + * eos_page_manager_get_page_custom_toolbox_widget: + * @self: the page manager + * @page: the page to be queried + * + * Retrieves @page's custom toolbox widget, if it has one. + * See #EosPageManager:custom-toolbox-widget for more information. + * + * <note><para> + * Currently, there is no possible way to have a non-custom toolbox widget. + * </para></note> + * + * Returns: (transfer none): the custom toolbox #GtkWidget of @page, or %NULL if + * there is none. + */ +GtkWidget * +eos_page_manager_get_page_custom_toolbox_widget (EosPageManager *self, + GtkWidget *page) +{ + g_return_val_if_fail (self != NULL && EOS_IS_PAGE_MANAGER (self), NULL); + g_return_val_if_fail (page != NULL && GTK_IS_WIDGET (page), NULL); + + EosPageManagerPageInfo *info = find_page_info_by_widget (self, page); + g_return_val_if_fail (info != NULL, NULL); + + return info->custom_toolbox_widget; +} + +/** + * eos_page_manager_set_page_custom_toolbox_widget: + * @self: the page manager + * @page: the page + * @custom_toolbox_widget: (allow-none): custom toolbox widget for @page + * + * Sets the custom toolbox widget to display to the left of @page. + * See #EosPageManager:custom-toolbox-widget for more information. + * + * <note><para> + * Currently, there is no possible way to have a non-custom toolbox widget. + * </para></note> + */ +void +eos_page_manager_set_page_custom_toolbox_widget (EosPageManager *self, + GtkWidget *page, + GtkWidget *custom_toolbox_widget) +{ + g_return_if_fail (self != NULL && EOS_IS_PAGE_MANAGER (self)); + g_return_if_fail (page != NULL && GTK_IS_WIDGET (page)); + g_return_if_fail (custom_toolbox_widget == NULL || + GTK_IS_WIDGET (custom_toolbox_widget)); + + EosPageManagerPageInfo *info = find_page_info_by_widget (self, page); + g_return_if_fail (info != NULL); + + if (info->custom_toolbox_widget == custom_toolbox_widget) + return; + + if (info->custom_toolbox_widget) + g_object_unref (info->custom_toolbox_widget); + + g_object_ref (custom_toolbox_widget); + info->custom_toolbox_widget = custom_toolbox_widget; + + gtk_container_child_notify (GTK_CONTAINER (self), page, + "custom-toolbox-widget"); +} + +/** * eos_page_manager_remove_page_by_name: * @self: the page manager * @name: the name of the page to remove diff --git a/endless/eospagemanager.h b/endless/eospagemanager.h index 7f006ec..90b52e7 100644 --- a/endless/eospagemanager.h +++ b/endless/eospagemanager.h @@ -60,37 +60,55 @@ struct _EosPageManagerClass }; EOS_SDK_ALL_API_VERSIONS -GType eos_page_manager_get_type (void) G_GNUC_CONST; +GType eos_page_manager_get_type (void) G_GNUC_CONST; EOS_SDK_ALL_API_VERSIONS -GtkWidget *eos_page_manager_new (void); +GtkWidget *eos_page_manager_new (void); EOS_SDK_ALL_API_VERSIONS -GtkWidget *eos_page_manager_get_visible_page (EosPageManager *self); +GtkWidget *eos_page_manager_get_visible_page (EosPageManager *self); EOS_SDK_ALL_API_VERSIONS -void eos_page_manager_set_visible_page (EosPageManager *self, - GtkWidget *page); +void eos_page_manager_set_visible_page (EosPageManager *self, + GtkWidget *page); EOS_SDK_ALL_API_VERSIONS -const gchar *eos_page_manager_get_visible_page_name (EosPageManager *self); +const gchar *eos_page_manager_get_visible_page_name (EosPageManager *self); EOS_SDK_ALL_API_VERSIONS -void eos_page_manager_set_visible_page_name (EosPageManager *self, - const gchar *page_name); +void eos_page_manager_set_visible_page_name (EosPageManager *self, + const gchar *page_name); EOS_SDK_ALL_API_VERSIONS -const gchar *eos_page_manager_get_page_name (EosPageManager *self, - GtkWidget *page); +const gchar *eos_page_manager_get_page_name (EosPageManager *self, + GtkWidget *page); EOS_SDK_ALL_API_VERSIONS -void eos_page_manager_set_page_name (EosPageManager *self, - GtkWidget *page, - const gchar *name); +void eos_page_manager_set_page_name (EosPageManager *self, + GtkWidget *page, + const gchar *name); EOS_SDK_ALL_API_VERSIONS -void eos_page_manager_remove_page_by_name (EosPageManager *self, - const gchar *name); +gboolean eos_page_manager_get_page_actions (EosPageManager *self, + GtkWidget *page); + +EOS_SDK_ALL_API_VERSIONS +void eos_page_manager_set_page_actions (EosPageManager *self, + GtkWidget *page, + gboolean actions_visible); + +EOS_SDK_ALL_API_VERSIONS +GtkWidget *eos_page_manager_get_page_custom_toolbox_widget (EosPageManager *self, + GtkWidget *page); + +EOS_SDK_ALL_API_VERSIONS +void eos_page_manager_set_page_custom_toolbox_widget (EosPageManager *self, + GtkWidget *page, + GtkWidget *custom_toolbox_widget); + +EOS_SDK_ALL_API_VERSIONS +void eos_page_manager_remove_page_by_name (EosPageManager *self, + const gchar *name); G_END_DECLS diff --git a/test/test-page-manager.c b/test/test-page-manager.c index b1d862f..9fc6db1 100644 --- a/test/test-page-manager.c +++ b/test/test-page-manager.c @@ -25,6 +25,7 @@ typedef struct GtkWidget *page1; GtkWidget *page2; GtkWidget *page3; + GtkWidget *toolbox2; } PageManagerFixture; static void @@ -35,6 +36,7 @@ pm_fixture_setup (PageManagerFixture *fixture, fixture->page1 = gtk_label_new ("1"); fixture->page2 = gtk_label_new ("2"); fixture->page3 = gtk_label_new ("3"); + fixture->toolbox2 = gtk_label_new ("toolbox2"); gtk_container_add_with_properties (GTK_CONTAINER (fixture->pm), fixture->page1, "name", PAGE1_NAME, @@ -42,10 +44,12 @@ pm_fixture_setup (PageManagerFixture *fixture, gtk_container_add_with_properties (GTK_CONTAINER (fixture->pm), fixture->page2, "name", PAGE2_NAME, + "custom-toolbox-widget", fixture->toolbox2, NULL); gtk_container_add_with_properties (GTK_CONTAINER (fixture->pm), fixture->page3, "name", PAGE3_NAME, + "page-actions", TRUE, NULL); } @@ -168,6 +172,109 @@ test_pm_child_prop_name (PageManagerFixture *fixture, } static void +test_pm_get_set_page_actions (PageManagerFixture *fixture, + gconstpointer unused) +{ + gboolean actions; + actions = eos_page_manager_get_page_actions (EOS_PAGE_MANAGER (fixture->pm), + fixture->page1); + g_assert (actions == FALSE); + actions = eos_page_manager_get_page_actions (EOS_PAGE_MANAGER (fixture->pm), + fixture->page3); + g_assert (actions == TRUE); + eos_page_manager_set_page_actions (EOS_PAGE_MANAGER (fixture->pm), + fixture->page3, + FALSE); + actions = eos_page_manager_get_page_actions (EOS_PAGE_MANAGER (fixture->pm), + fixture->page3); + g_assert (actions == FALSE); +} + +static void +test_pm_child_prop_page_actions (PageManagerFixture *fixture, + gconstpointer unused) +{ + gboolean actions; + gtk_container_child_get (GTK_CONTAINER (fixture->pm), fixture->page1, + "page-actions", &actions, + NULL); + g_assert (actions == FALSE); + gtk_container_child_get (GTK_CONTAINER (fixture->pm), fixture->page3, + "page-actions", &actions, + NULL); + g_assert (actions == TRUE); + gtk_container_child_set (GTK_CONTAINER (fixture->pm), fixture->page3, + "page-actions", FALSE, + NULL); + gtk_container_child_get (GTK_CONTAINER (fixture->pm), fixture->page3, + "page-actions", &actions, + NULL); + g_assert (actions == FALSE); +} + +static void +test_pm_get_set_page_custom_toolbox (PageManagerFixture *fixture, + gconstpointer unused) +{ + GtkWidget *new_tb = gtk_label_new ("Another toolbox"); + GtkWidget *tb; + + tb = eos_page_manager_get_page_custom_toolbox_widget (EOS_PAGE_MANAGER (fixture->pm), + fixture->page1); + g_assert (tb == NULL); + tb = eos_page_manager_get_page_custom_toolbox_widget (EOS_PAGE_MANAGER (fixture->pm), + fixture->page2); + g_assert (tb == fixture->toolbox2); + + eos_page_manager_set_page_custom_toolbox_widget (EOS_PAGE_MANAGER (fixture->pm), + fixture->page1, + new_tb); + eos_page_manager_set_page_custom_toolbox_widget (EOS_PAGE_MANAGER (fixture->pm), + fixture->page2, + new_tb); + + tb = eos_page_manager_get_page_custom_toolbox_widget (EOS_PAGE_MANAGER (fixture->pm), + fixture->page1); + g_assert (tb == new_tb); + tb = eos_page_manager_get_page_custom_toolbox_widget (EOS_PAGE_MANAGER (fixture->pm), + fixture->page2); + g_assert (tb == new_tb); +} + +static void +test_pm_child_prop_custom_toolbox (PageManagerFixture *fixture, + gconstpointer unused) +{ + GtkWidget *new_tb = gtk_label_new ("Another toolbox"); + GtkWidget *tb; + + gtk_container_child_get (GTK_CONTAINER (fixture->pm), fixture->page1, + "custom-toolbox-widget", &tb, + NULL); + g_assert (tb == NULL); + gtk_container_child_get (GTK_CONTAINER (fixture->pm), fixture->page2, + "custom-toolbox-widget", &tb, + NULL); + g_assert (tb == fixture->toolbox2); + + gtk_container_child_set (GTK_CONTAINER (fixture->pm), fixture->page1, + "custom-toolbox-widget", new_tb, + NULL); + gtk_container_child_set (GTK_CONTAINER (fixture->pm), fixture->page2, + "custom-toolbox-widget", new_tb, + NULL); + + gtk_container_child_get (GTK_CONTAINER (fixture->pm), fixture->page1, + "custom-toolbox-widget", &tb, + NULL); + g_assert (tb == new_tb); + gtk_container_child_get (GTK_CONTAINER (fixture->pm), fixture->page2, + "custom-toolbox-widget", &tb, + NULL); + g_assert (tb == new_tb); +} + +static void test_pm_page_no_name (PageManagerFixture *fixture, gconstpointer unused) { @@ -323,6 +430,14 @@ add_page_manager_tests (void) test_pm_get_set_page_name); ADD_PAGE_MANAGER_TEST ("/page-manager/child-prop-name", test_pm_child_prop_name); + ADD_PAGE_MANAGER_TEST ("/page-manager/get-set-page-actions", + test_pm_get_set_page_actions); + ADD_PAGE_MANAGER_TEST ("/page-manager/child-prop-page-actions", + test_pm_child_prop_page_actions); + ADD_PAGE_MANAGER_TEST ("/page-manager/get-set-page-custom-toolbox", + test_pm_get_set_page_custom_toolbox); + ADD_PAGE_MANAGER_TEST ("/page-manager/child-prop-custom-toolbox", + test_pm_child_prop_custom_toolbox); ADD_PAGE_MANAGER_TEST ("/page-manager/page-no-name", test_pm_page_no_name); ADD_PAGE_MANAGER_TEST ("/page-manager/set-page-no-name", test_pm_set_page_no_name); |