summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormatt <mattdangerw@gmail.com>2013-05-09 18:17:13 -0700
committerP. F. Chimento <philip.chimento@gmail.com>2013-05-17 17:47:08 +0200
commite645ce320460a091344ff3ad40b830edf8614d1d (patch)
treea5920ad355bf4eb46692d27c5b70522d5e7a2286
parent9b8eff4ad1bff9dd2973d1799d364e878cafa198 (diff)
Added a visible-page-background property and tests.
visible-page-background property points to the URI of the background of the current page. Should probably be extended to give the correct background when page-managers are nested. [endlessm/eos-sdk#59]
-rw-r--r--endless/eospagemanager.c48
-rw-r--r--endless/eospagemanager.h7
-rw-r--r--endless/eoswindow.c25
-rw-r--r--test/test-page-manager.c97
4 files changed, 156 insertions, 21 deletions
diff --git a/endless/eospagemanager.c b/endless/eospagemanager.c
index 9bf6de4..9d23bd5 100644
--- a/endless/eospagemanager.c
+++ b/endless/eospagemanager.c
@@ -113,6 +113,7 @@ enum
PROP_0,
PROP_VISIBLE_PAGE,
PROP_VISIBLE_PAGE_NAME,
+ PROP_VISIBLE_PAGE_BACKGROUND,
NPROPS
};
@@ -225,6 +226,7 @@ set_visible_page_from_info (EosPageManager *self,
GObject *self_object = G_OBJECT (self);
g_object_notify(self_object, "visible-page");
g_object_notify(self_object, "visible-page-name");
+ g_object_notify(self_object, "visible-page-background");
}
static void
@@ -245,6 +247,10 @@ eos_page_manager_get_property (GObject *object,
g_value_set_string (value, eos_page_manager_get_visible_page_name (self));
break;
+ case PROP_VISIBLE_PAGE_BACKGROUND:
+ g_value_set_string (value, eos_page_manager_get_visible_page_background (self));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
@@ -583,6 +589,21 @@ eos_page_manager_class_init (EosPageManagerClass *klass)
"",
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+ /**
+ * EosPageManager:visible-page-background:
+ *
+ * The name of URI for the page that is currently being displayed by the
+ * page manager. If the page manager has no pages, then this is %NULL.
+ * However, if there is a page currently being displayed but it has no name,
+ * then this is the empty string (<code>""</code>).
+ */
+ eos_page_manager_props[PROP_VISIBLE_PAGE_BACKGROUND] =
+ g_param_spec_string ("visible-page-background", "Visible background URI",
+ "URI for the background of page currently displaying"
+ "in the page manager",
+ "",
+ G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+
g_object_class_install_properties (object_class, NPROPS,
eos_page_manager_props);
@@ -702,7 +723,7 @@ eos_page_manager_get_visible_page (EosPageManager *self)
{
g_return_val_if_fail (EOS_IS_PAGE_MANAGER (self), NULL);
- if(self->priv->visible_page_info == NULL)
+ if (self->priv->visible_page_info == NULL)
return NULL;
return self->priv->visible_page_info->page;
@@ -748,7 +769,7 @@ eos_page_manager_get_visible_page_name (EosPageManager *self)
{
g_return_val_if_fail (EOS_IS_PAGE_MANAGER (self), NULL);
- if(self->priv->visible_page_info == NULL)
+ if (self->priv->visible_page_info == NULL)
return NULL;
return self->priv->visible_page_info->name;
@@ -781,6 +802,29 @@ eos_page_manager_set_visible_page_name (EosPageManager *self,
}
/**
+ * eos_page_manager_get_visible_page_background:
+ * @self: the page manager
+ *
+ * Gets the background of the page widget that @self is currently displaying.
+ * See #EosPageManager:visible-page for more information.
+ *
+ * Returns: the background of the page, or %NULL if @self does not have any pages,
+ * or the empty string if the page does not have a background.
+ */
+const gchar *
+eos_page_manager_get_visible_page_background (EosPageManager *self)
+{
+ // TODO: if page managers are nested, this shows the value for the leaf
+ // (non-page manager) page background URI.
+ g_return_val_if_fail (self != NULL && EOS_IS_PAGE_MANAGER (self), NULL);
+
+ if (self->priv->visible_page_info == NULL)
+ return NULL;
+
+ return self->priv->visible_page_info->background;
+}
+
+/**
* eos_page_manager_get_page_name:
* @self: the page manager
* @page: the page to be queried
diff --git a/endless/eospagemanager.h b/endless/eospagemanager.h
index 07f03b5..40de4bc 100644
--- a/endless/eospagemanager.h
+++ b/endless/eospagemanager.h
@@ -80,6 +80,9 @@ void eos_page_manager_set_visible_page_name (EosPageManager *se
const gchar *page_name);
EOS_SDK_ALL_API_VERSIONS
+const gchar *eos_page_manager_get_visible_page_background (EosPageManager *self);
+
+EOS_SDK_ALL_API_VERSIONS
const gchar *eos_page_manager_get_page_name (EosPageManager *self,
GtkWidget *page);
@@ -107,10 +110,6 @@ void eos_page_manager_set_page_custom_toolbox_widget (EosPageManager *se
GtkWidget *custom_toolbox_widget);
EOS_SDK_ALL_API_VERSIONS
-void eos_page_manager_remove_page_by_name (EosPageManager *self,
- const gchar *name);
-
-EOS_SDK_ALL_API_VERSIONS
const gchar *eos_page_manager_get_page_background (EosPageManager *self,
GtkWidget *page);
diff --git a/endless/eoswindow.c b/endless/eoswindow.c
index a739a60..80fd118 100644
--- a/endless/eoswindow.c
+++ b/endless/eoswindow.c
@@ -1,6 +1,7 @@
/* Copyright 2013 Endless Mobile, Inc. */
#include "config.h"
+#include "string.h"
#include "eoswindow.h"
#include "eosapplication.h"
@@ -33,7 +34,11 @@
* ]|
*/
-#define _BACKGROUND_IMAGE_CSS_TEMPLATE "EosWindow { background-image: url(\"%s\"); }"
+// Put in a transition for fun, should be part of API though someday...
+#define _BACKGROUND_IMAGE_CSS_TEMPLATE "EosWindow { background-image: url(\"%s\");" \
+ "transition-property: background-image;" \
+ "transition-duration: 0.5s;" \
+ "background-size:100%% 100%%; }"
G_DEFINE_TYPE (EosWindow, eos_window, GTK_TYPE_APPLICATION_WINDOW)
@@ -326,22 +331,20 @@ static void
set_background_to_page (EosWindow *self,
EosPageManager *page_manager)
{
- gint length;
- GError *error = NULL;
GtkCssProvider *provider = self->priv->background_provider;
GdkScreen *screen = gdk_screen_get_default ();
- GtkWidget *visible_page = eos_page_manager_get_visible_page (page_manager);
- const gchar *background;
- gchar background_css[128];
+ const gchar *background = eos_page_manager_get_visible_page_background (page_manager);
+ gint background_css_length = strlen (background) + strlen (_BACKGROUND_IMAGE_CSS_TEMPLATE) + 1;
+ gchar background_css[background_css_length];
+ GError *error = NULL;
- if (visible_page != NULL)
+ if (background != NULL && strlen (background) > 0)
{
- background = eos_page_manager_get_page_background (page_manager, visible_page);
- length = sprintf (background_css, _BACKGROUND_IMAGE_CSS_TEMPLATE, background);
+ sprintf (background_css, _BACKGROUND_IMAGE_CSS_TEMPLATE, background);
gtk_style_context_remove_provider_for_screen (screen, GTK_STYLE_PROVIDER (provider));
gtk_css_provider_load_from_data (provider,
background_css,
- length,
+ background_css_length,
&error);
gtk_style_context_add_provider_for_screen (screen,
GTK_STYLE_PROVIDER (provider),
@@ -369,7 +372,7 @@ eos_window_add (GtkContainer *container,
if (EOS_IS_PAGE_MANAGER (widget))
{
set_background_to_page (EOS_WINDOW (container), EOS_PAGE_MANAGER (widget));
- g_signal_connect (widget, "notify::visible-page",
+ g_signal_connect (widget, "notify::visible-page-background",
G_CALLBACK (on_background_changed_cb), container);
}
GTK_CONTAINER_CLASS (eos_window_parent_class)->add (container, widget);
diff --git a/test/test-page-manager.c b/test/test-page-manager.c
index 9fc6db1..ce5bf35 100644
--- a/test/test-page-manager.c
+++ b/test/test-page-manager.c
@@ -6,12 +6,17 @@
#define PAGE1_NAME "page1"
#define PAGE2_NAME "page2"
#define PAGE3_NAME "page3"
+#define PAGE1_BACKGROUND "back1"
+#define PAGE2_BACKGROUND "back2"
+#define PAGE3_BACKGROUND "back3"
#define EXPECTED_PAGE_NAME PAGE2_NAME
#define EXPECTED_CHANGED_PAGE_NAME "changed-name"
#define DUPLICATE_PAGE_NAME "duplicate-name"
#define EXPECTED_DUPLICATE_PAGE_NAME_ERRMSG "*Not setting page name to \"" \
DUPLICATE_PAGE_NAME "\", because page manager already contains a page by " \
"that name*"
+#define EXPECTED_PAGE_BACKGROUND PAGE2_BACKGROUND
+#define EXPECTED_CHANGED_NAME "changed-name"
#define ADD_PAGE_MANAGER_TEST(path, test_func) \
g_test_add ((path), PageManagerFixture, NULL, \
pm_fixture_setup, (test_func), pm_fixture_teardown)
@@ -40,16 +45,19 @@ pm_fixture_setup (PageManagerFixture *fixture,
gtk_container_add_with_properties (GTK_CONTAINER (fixture->pm),
fixture->page1,
"name", PAGE1_NAME,
+ "background", PAGE1_BACKGROUND,
NULL);
gtk_container_add_with_properties (GTK_CONTAINER (fixture->pm),
fixture->page2,
"name", PAGE2_NAME,
"custom-toolbox-widget", fixture->toolbox2,
+ "background", PAGE2_BACKGROUND,
NULL);
gtk_container_add_with_properties (GTK_CONTAINER (fixture->pm),
fixture->page3,
"name", PAGE3_NAME,
"page-actions", TRUE,
+ "background", PAGE3_BACKGROUND,
NULL);
}
@@ -120,6 +128,20 @@ test_pm_prop_visible_page_name (PageManagerFixture *fixture,
}
static void
+test_pm_prop_visible_page_background (PageManagerFixture *fixture,
+ gconstpointer unused)
+{
+ gchar *name;
+ g_object_get (fixture->pm, "visible-page-background", &name, NULL);
+ g_assert_cmpstr (name, !=, EXPECTED_PAGE_BACKGROUND);
+ g_free (name);
+ g_object_set (fixture->pm, "visible-page-name", EXPECTED_PAGE_NAME, NULL);
+ g_object_get (fixture->pm, "visible-page-background", &name, NULL);
+ g_assert_cmpstr (name, ==, EXPECTED_PAGE_BACKGROUND);
+ g_free (name);
+}
+
+static void
test_pm_get_set_page_name (PageManagerFixture *fixture,
gconstpointer unused)
{
@@ -135,10 +157,10 @@ test_pm_get_set_page_name (PageManagerFixture *fixture,
g_assert_cmpstr (name, ==, PAGE3_NAME);
eos_page_manager_set_page_name (EOS_PAGE_MANAGER (fixture->pm),
fixture->page2,
- EXPECTED_CHANGED_PAGE_NAME);
+ EXPECTED_CHANGED_NAME);
name = eos_page_manager_get_page_name (EOS_PAGE_MANAGER (fixture->pm),
fixture->page2);
- g_assert_cmpstr (name, ==, EXPECTED_CHANGED_PAGE_NAME);
+ g_assert_cmpstr (name, ==, EXPECTED_CHANGED_NAME);
}
static void
@@ -162,12 +184,12 @@ test_pm_child_prop_name (PageManagerFixture *fixture,
g_assert_cmpstr (name, ==, PAGE3_NAME);
g_free (name);
gtk_container_child_set (GTK_CONTAINER (fixture->pm), fixture->page2,
- "name", EXPECTED_CHANGED_PAGE_NAME,
+ "name", EXPECTED_CHANGED_NAME,
NULL);
gtk_container_child_get (GTK_CONTAINER (fixture->pm), fixture->page2,
"name", &name,
NULL);
- g_assert_cmpstr (name, ==, EXPECTED_CHANGED_PAGE_NAME);
+ g_assert_cmpstr (name, ==, EXPECTED_CHANGED_NAME);
g_free (name);
}
@@ -275,6 +297,36 @@ test_pm_child_prop_custom_toolbox (PageManagerFixture *fixture,
}
static void
+test_pm_child_prop_background (PageManagerFixture *fixture,
+ gconstpointer unused)
+{
+ gchar *background;
+ gtk_container_child_get (GTK_CONTAINER (fixture->pm), fixture->page1,
+ "background", &background,
+ NULL);
+ g_assert_cmpstr (background, ==, PAGE1_BACKGROUND);
+ g_free (background);
+ gtk_container_child_get (GTK_CONTAINER (fixture->pm), fixture->page2,
+ "background", &background,
+ NULL);
+ g_assert_cmpstr (background, ==, PAGE2_BACKGROUND);
+ g_free (background);
+ gtk_container_child_get (GTK_CONTAINER (fixture->pm), fixture->page3,
+ "background", &background,
+ NULL);
+ g_assert_cmpstr (background, ==, PAGE3_BACKGROUND);
+ g_free (background);
+ gtk_container_child_set (GTK_CONTAINER (fixture->pm), fixture->page2,
+ "background", EXPECTED_CHANGED_NAME,
+ NULL);
+ gtk_container_child_get (GTK_CONTAINER (fixture->pm), fixture->page2,
+ "background", &background,
+ NULL);
+ g_assert_cmpstr (background, ==, EXPECTED_CHANGED_NAME);
+ g_free (background);
+}
+
+static void
test_pm_page_no_name (PageManagerFixture *fixture,
gconstpointer unused)
{
@@ -306,6 +358,23 @@ test_pm_set_page_no_name (PageManagerFixture *fixture,
}
static void
+test_pm_page_no_background (PageManagerFixture *fixture,
+ gconstpointer unused)
+{
+ const gchar *background_get;
+ gchar *background_prop;
+ GtkWidget *new_page = gtk_label_new("new");
+ gtk_container_add (GTK_CONTAINER (fixture->pm), new_page);
+ background_get = eos_page_manager_get_page_background (EOS_PAGE_MANAGER (fixture->pm), new_page);
+ g_assert_cmpstr (background_get, ==, "");
+ gtk_container_child_get (GTK_CONTAINER (fixture->pm), new_page,
+ "background", &background_prop,
+ NULL);
+ g_assert_cmpstr (background_prop, ==, "");
+ g_free (background_prop);
+}
+
+static void
test_pm_remove_page_behavior (PageManagerFixture *fixture,
gconstpointer unused)
{
@@ -401,6 +470,18 @@ test_empty_pm_visible_page_name (PageManagerFixture *fixture,
}
static void
+test_empty_pm_visible_page_background (PageManagerFixture *fixture,
+ gconstpointer unused)
+{
+ const gchar *background_get;
+ gchar *background_prop;
+ background_get = eos_page_manager_get_visible_page_background (EOS_PAGE_MANAGER (fixture->pm));
+ g_assert (background_get == NULL);
+ g_object_get (fixture->pm, "visible-page-background", &background_prop, NULL);
+ g_assert (background_prop == NULL);
+}
+
+static void
test_empty_pm_add_page_behavior (PageManagerFixture *fixture,
gconstpointer unused)
{
@@ -428,6 +509,8 @@ add_page_manager_tests (void)
test_pm_prop_visible_page_name);
ADD_PAGE_MANAGER_TEST ("/page-manager/get-set-page-name",
test_pm_get_set_page_name);
+ ADD_PAGE_MANAGER_TEST ("/page-manager/prop-visible-page-background",
+ test_pm_prop_visible_page_background);
ADD_PAGE_MANAGER_TEST ("/page-manager/child-prop-name",
test_pm_child_prop_name);
ADD_PAGE_MANAGER_TEST ("/page-manager/get-set-page-actions",
@@ -438,9 +521,13 @@ add_page_manager_tests (void)
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/child-prop-background",
+ test_pm_child_prop_background);
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);
+ ADD_PAGE_MANAGER_TEST ("/page-manager/page-no-background",
+ test_pm_page_no_background);
ADD_PAGE_MANAGER_TEST ("/page-manager/remove-page-by-name",
test_pm_remove_page_by_name);
ADD_PAGE_MANAGER_TEST ("/page-manager/duplicate-page-name",
@@ -449,6 +536,8 @@ add_page_manager_tests (void)
test_empty_pm_visible_page);
ADD_EMPTY_PAGE_MANAGER_TEST ("/page-manager/empty-visible-page-name",
test_empty_pm_visible_page_name);
+ ADD_EMPTY_PAGE_MANAGER_TEST ("/page-manager/empty-visible-page-background",
+ test_empty_pm_visible_page_background);
ADD_EMPTY_PAGE_MANAGER_TEST ("/page-manager/add-page-behavior",
test_empty_pm_add_page_behavior);