Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/backend
diff options
context:
space:
mode:
authorJonathan Blandford <jrb@redhat.com>2005-04-01 07:03:05 (GMT)
committer Jonathan Blandford <jrb@src.gnome.org>2005-04-01 07:03:05 (GMT)
commit5120e3dbe4ca81eb71136a8cde7c4b17f14f23a8 (patch)
tree07da08ee1f47f6d2dcbe9690b3e2f47483b7a23a /backend
parent4fc3718204b76424618ea5d577551aede676ffee (diff)
Changed to use page labels now. Rewrote completely because I didn't
Fri Apr 1 01:59:39 2005 Jonathan Blandford <jrb@redhat.com> * shell/ev-page-action.c: Changed to use page labels now. Rewrote completely because I didn't understand GtkActions. I should read Marco's code more carefully in the future. * backend/ev-page-cache.h (ev_page_cache_set_page_label): New function
Diffstat (limited to 'backend')
-rw-r--r--backend/ev-page-cache.c41
-rw-r--r--backend/ev-page-cache.h2
2 files changed, 43 insertions, 0 deletions
diff --git a/backend/ev-page-cache.c b/backend/ev-page-cache.c
index 2042394..08d1be4 100644
--- a/backend/ev-page-cache.c
+++ b/backend/ev-page-cache.c
@@ -1,5 +1,7 @@
#include "ev-page-cache.h"
#include "ev-job-queue.h"
+#include <stdlib.h>
+#include <string.h>
typedef struct _EvPageCacheInfo
{
@@ -181,6 +183,45 @@ ev_page_cache_set_current_page (EvPageCache *page_cache,
g_signal_emit (page_cache, signals[PAGE_CHANGED], 0, page);
}
+gboolean
+ev_page_cache_set_page_label (EvPageCache *page_cache,
+ const char *page_label)
+{
+ gint i, page;
+ long value;
+ char *endptr = NULL;
+
+ g_return_val_if_fail (EV_IS_PAGE_CACHE (page_cache), FALSE);
+ g_return_val_if_fail (page_label != NULL, FALSE);
+
+ /* First, look for a literal label match */
+ for (i = 0; i < page_cache->n_pages; i ++) {
+ if (page_cache->page_labels[i] != NULL &&
+ ! strcmp (page_label, page_cache->page_labels[i])) {
+ ev_page_cache_set_current_page (page_cache, i);
+ return TRUE;
+ }
+ }
+
+ /* Next, parse the label, and see if the number fits */
+ value = strtol (page_label, &endptr, 10);
+ if (endptr[0] == '\0') {
+ /* Page number is an integer */
+ page = MIN (G_MAXINT, value);
+
+ /* convert from a page label to a page offset */
+ page --;
+ if (page >= 0 &&
+ page < page_cache->n_pages &&
+ page_cache->page_labels[page] == NULL) {
+ ev_page_cache_set_current_page (page_cache, page);
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
void
ev_page_cache_set_link (EvPageCache *page_cache,
EvLink *link)
diff --git a/backend/ev-page-cache.h b/backend/ev-page-cache.h
index bf5e3d1..24f5262 100644
--- a/backend/ev-page-cache.h
+++ b/backend/ev-page-cache.h
@@ -45,6 +45,8 @@ char *ev_page_cache_get_page_label (EvPageCache *page_cache,
gint ev_page_cache_get_current_page (EvPageCache *page_cache);
void ev_page_cache_set_current_page (EvPageCache *page_cache,
int page);
+gboolean ev_page_cache_set_page_label (EvPageCache *page_cache,
+ const char *page_label);
void ev_page_cache_set_link (EvPageCache *page_cache,
EvLink *link);
gboolean ev_page_cache_next_page (EvPageCache *page_cache);