diff options
author | Philip Withnall <philip@tecnocode.co.uk> | 2009-03-18 18:33:15 +0000 |
---|---|---|
committer | Philip Withnall <philip@tecnocode.co.uk> | 2009-03-18 18:33:15 +0000 |
commit | c3b56e77b05a0f2ccd1f9854ae3d62b11f6c4d94 (patch) | |
tree | 1c63a536688f1b481017e0dc1a08050024cf86f2 /gdata/gdata-query.c | |
parent | 8a8f585051762101d500f15125c4316210b743fc (diff) | |
download | libgdata-c3b56e77b05a0f2ccd1f9854ae3d62b11f6c4d94.tar.gz |
Added pagination functionality to GDataQuery.
Diffstat (limited to 'gdata/gdata-query.c')
-rw-r--r-- | gdata/gdata-query.c | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/gdata/gdata-query.c b/gdata/gdata-query.c index ed45ec63..6d655e56 100644 --- a/gdata/gdata-query.c +++ b/gdata/gdata-query.c @@ -45,6 +45,11 @@ struct _GDataQueryPrivate { gboolean strict; gint max_results; gchar *entry_id; + + gchar *next_uri; + gchar *previous_uri; + gboolean use_next_uri; + gboolean use_previous_uri; }; enum { @@ -176,6 +181,9 @@ gdata_query_finalize (GObject *object) g_free (priv->published_max); g_free (priv->entry_id); + g_free (priv->next_uri); + g_free (priv->previous_uri); + /* Chain up to the parent class */ G_OBJECT_CLASS (gdata_query_parent_class)->finalize (object); } @@ -327,6 +335,12 @@ gdata_query_get_query_uri (GDataQuery *self, const gchar *feed_uri) #define APPEND_SEP g_string_append_c (query_uri, (params_started == FALSE) ? '?' : '&'); params_started = TRUE; + /* Check to see if we're paginating first */ + if (priv->use_next_uri == TRUE) + return priv->next_uri; + if (priv->use_previous_uri == TRUE) + return priv->previous_uri; + /* Check to see if any parameters have been set */ if ((priv->parameter_mask & GDATA_QUERY_PARAM_ALL) == 0) return g_strdup (feed_uri); @@ -662,3 +676,49 @@ gdata_query_set_entry_id (GDataQuery *self, const gchar *entry_id) g_object_notify (G_OBJECT (self), "entry-id"); } + +void +_gdata_query_set_next_uri (GDataQuery *self, const gchar *next_uri) +{ + g_return_if_fail (GDATA_IS_QUERY (self)); + g_free (self->priv->next_uri); + self->priv->next_uri = g_strdup (next_uri); + self->priv->use_next_uri = FALSE; + self->priv->use_previous_uri = FALSE; +} + +void +_gdata_query_set_previous_uri (GDataQuery *self, const gchar *previous_uri) +{ + g_return_if_fail (GDATA_IS_QUERY (self)); + g_free (self->priv->previous_uri); + self->priv->previous_uri = g_strdup (previous_uri); + self->priv->use_next_uri = FALSE; + self->priv->use_previous_uri = FALSE; +} + +void +gdata_query_next_page (GDataQuery *self) +{ + if (self->priv->next_uri != NULL) { + self->priv->use_next_uri = TRUE; + self->priv->use_previous_uri = FALSE; + } else { + self->priv->start_index += self->priv->max_results; + } +} + +gboolean +gdata_query_previous_page (GDataQuery *self) +{ + if (self->priv->next_uri != NULL) { + self->priv->use_previous_uri = TRUE; + self->priv->use_next_uri = FALSE; + } else if (self->priv->start_index < self->priv->max_results) { + return FALSE; + } else { + self->priv->start_index -= self->priv->max_results; + } + + return TRUE; +} |