summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-reader/Navigation.cpp
Unidiff
Diffstat (limited to 'noncore/apps/opie-reader/Navigation.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-reader/Navigation.cpp112
1 files changed, 67 insertions, 45 deletions
diff --git a/noncore/apps/opie-reader/Navigation.cpp b/noncore/apps/opie-reader/Navigation.cpp
index 4f11887..36e33b4 100644
--- a/noncore/apps/opie-reader/Navigation.cpp
+++ b/noncore/apps/opie-reader/Navigation.cpp
@@ -1,62 +1,80 @@
1#include "Navigation.h" 1#ifdef _WINDOWS
2
3#include <string.h> 2#include <string.h>
3#endif
4#include "Navigation.h"
5//#include <stdio.h>
4 6
7/*
8 void saveposn(size_t posn)
9 save/push position to history buffer for future use of back() function
10*/
5void CNavigation::saveposn(size_t posn) 11void CNavigation::saveposn(size_t posn)
6{ 12{
7// qDebug("Saved:%u [%u,%u,%u]", posn, historystart, historycurrent, historyend); 13 //printf("saving position %u, depth %u\n",posn,historycurrent);
8 historycurrent = historyend = (historycurrent+1)%NAVIGATION_HISTORY_SIZE;
9 history[historycurrent] = posn; 14 history[historycurrent] = posn;
10 if (historystart == historyend) historystart = (historystart+1)%NAVIGATION_HISTORY_SIZE; 15 historycurrent=(historycurrent+1)%NAVIGATION_HISTORY_SIZE;
11// qDebug("Saved:%u [%u,%u,%u]", posn, historystart, historycurrent, historyend); 16 if (historycurrent==historystart)
17 // circular buffer full, forget oldest record
18 historystart=(historystart+1)%NAVIGATION_HISTORY_SIZE;
19 // no forward possible after saveposn
20 historyend = historycurrent;
12} 21}
13 22
14bool CNavigation::forward(size_t& loc) 23/*
24 void writeposn(size_t posn)
25 overwrite current (unused) position
26 useful for saving current position before using back button
27*/
28void CNavigation::writeposn(size_t posn)
15{ 29{
16 if (historycurrent != historyend) 30 //printf("witing position %u, depth %u\n",posn,historycurrent);
17 { 31 history[historycurrent] = posn;
18 historycurrent = (historycurrent + 1)%NAVIGATION_HISTORY_SIZE;
19 loc = history[historycurrent];
20 //qDebug("Forward:%u [%u,%u,%u]", loc, historystart, historycurrent, historyend);
21 return true;
22 }
23 else
24 {
25 return false;
26 }
27} 32}
28 33
29bool CNavigation::back(size_t& loc) 34/*
35 bool back(size_t& posn)
36 go back in history
37 restore last position saved with saveposn() and return true
38 return false if there is nothing saved in history
39*/
40bool CNavigation::back(size_t& posn)
30{ 41{
31 if (historyend != historystart) 42 if (historycurrent!=historystart) {
32 { 43 // buffer is not empty
33 //qDebug("Back:%u [%u,%u,%u]", loc, historystart, historycurrent, historyend); 44 if (historycurrent==0)
34 if (historycurrent == historyend && history[historycurrent] != loc) 45 historycurrent=NAVIGATION_HISTORY_SIZE-1;
35 { 46 else
36 historyend = (historyend+1) % NAVIGATION_HISTORY_SIZE; 47 historycurrent--;
37 history[historyend] = loc; 48 posn=history[historycurrent];
38 } 49 //printf("back(): going back to %u depth %u\n",posn,historycurrent);
39 else 50 return true;
40 { 51
41 size_t sv = historycurrent; 52 } else {
42 historycurrent = (historycurrent + NAVIGATION_HISTORY_SIZE - 1) % NAVIGATION_HISTORY_SIZE; 53 // circular buffer empty
43 if (historycurrent == historystart) 54 //printf("back(): empty history\n");
44 { 55 return false;
45 historycurrent = sv;
46 return false;
47 }
48 }
49 loc = history[historycurrent];
50 //qDebug("Back:%u [%u,%u,%u]", loc, historystart, historycurrent, historyend);
51 return true;
52 }
53 else
54 {
55 return false;
56 } 56 }
57} 57}
58 58
59#include <stdio.h> 59/*
60 bool forward(size_t& posn)
61 go forward in history, if possible
62 undo calling of back()
63*/
64bool CNavigation::forward(size_t& posn)
65{
66 if (historycurrent!=historyend) {
67 // [historycurrent] = current position
68 // [historycurrent+1] = position we need
69 historycurrent=(historycurrent+1)%NAVIGATION_HISTORY_SIZE;
70 posn = history[historycurrent];
71 //printf("forward(): going to position %d\n",posn);
72 return true;
73 } else {
74 //printf("forward(): there is no future :)\n");
75 return false;
76 }
77}
60 78
61void CNavigation::setSaveData(unsigned char*& data, unsigned short& len, unsigned char* src, unsigned short srclen) 79void CNavigation::setSaveData(unsigned char*& data, unsigned short& len, unsigned char* src, unsigned short srclen)
62{ 80{
@@ -72,10 +90,12 @@ void CNavigation::setSaveData(unsigned char*& data, unsigned short& len, unsigne
72 memcpy(p, &historycurrent, sizeof(size_t)); 90 memcpy(p, &historycurrent, sizeof(size_t));
73 p += sizeof(size_t); 91 p += sizeof(size_t);
74 memcpy(p, history, sizeof(size_t)*NAVIGATION_HISTORY_SIZE); 92 memcpy(p, history, sizeof(size_t)*NAVIGATION_HISTORY_SIZE);
93/*
75 printf("<%u,%u,%u>\n", historystart, historyend, historycurrent); 94 printf("<%u,%u,%u>\n", historystart, historyend, historycurrent);
76 for (int i = historystart; i <= historyend; i++) 95 for (int i = historystart; i <= historyend; i++)
77 printf("<%u> ", history[i]); 96 printf("<%u> ", history[i]);
78 printf("\n"); 97 printf("\n");
98*/
79} 99}
80 100
81void CNavigation::putSaveData(unsigned char*& src, unsigned short& srclen) 101void CNavigation::putSaveData(unsigned char*& src, unsigned short& srclen)
@@ -93,8 +113,10 @@ void CNavigation::putSaveData(unsigned char*& src, unsigned short& srclen)
93 src = p + sizeof(size_t)*NAVIGATION_HISTORY_SIZE; 113 src = p + sizeof(size_t)*NAVIGATION_HISTORY_SIZE;
94 srclen -= sizeof(size_t)*(3+NAVIGATION_HISTORY_SIZE); 114 srclen -= sizeof(size_t)*(3+NAVIGATION_HISTORY_SIZE);
95 } 115 }
116/*
96 printf("<%u,%u,%u>\n", historystart, historyend, historycurrent); 117 printf("<%u,%u,%u>\n", historystart, historyend, historycurrent);
97 for (int i = historystart; i <= historyend; i++) 118 for (int i = historystart; i <= historyend; i++)
98 printf("<%u> ", history[i]); 119 printf("<%u> ", history[i]);
99 printf("\n"); 120 printf("\n");
121*/
100} 122}