summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-reader/Navigation.cpp
Unidiff
Diffstat (limited to 'noncore/apps/opie-reader/Navigation.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/apps/opie-reader/Navigation.cpp98
1 files changed, 98 insertions, 0 deletions
diff --git a/noncore/apps/opie-reader/Navigation.cpp b/noncore/apps/opie-reader/Navigation.cpp
new file mode 100644
index 0000000..7b392ba
--- a/dev/null
+++ b/noncore/apps/opie-reader/Navigation.cpp
@@ -0,0 +1,98 @@
1#include "Navigation.h"
2
3void CNavigation::saveposn(size_t posn)
4{
5// qDebug("Saved:%u [%u,%u,%u]", posn, historystart, historycurrent, historyend);
6 historycurrent = historyend = (historycurrent+1)%NAVIGATION_HISTORY_SIZE;
7 history[historycurrent] = posn;
8 if (historystart == historyend) historystart = (historystart+1)%NAVIGATION_HISTORY_SIZE;
9// qDebug("Saved:%u [%u,%u,%u]", posn, historystart, historycurrent, historyend);
10}
11
12bool CNavigation::forward(size_t& loc)
13{
14 if (historycurrent != historyend)
15 {
16 historycurrent = (historycurrent + 1)%NAVIGATION_HISTORY_SIZE;
17 loc = history[historycurrent];
18 //qDebug("Forward:%u [%u,%u,%u]", loc, historystart, historycurrent, historyend);
19 return true;
20 }
21 else
22 {
23 return false;
24 }
25}
26
27bool CNavigation::back(size_t& loc)
28{
29 if (historyend != historystart)
30 {
31 //qDebug("Back:%u [%u,%u,%u]", loc, historystart, historycurrent, historyend);
32 if (historycurrent == historyend && history[historycurrent] != loc)
33 {
34 historyend = (historyend+1) % NAVIGATION_HISTORY_SIZE;
35 history[historyend] = loc;
36 }
37 else
38 {
39 size_t sv = historycurrent;
40 historycurrent = (historycurrent + NAVIGATION_HISTORY_SIZE - 1) % NAVIGATION_HISTORY_SIZE;
41 if (historycurrent == historystart)
42 {
43 historycurrent = sv;
44 return false;
45 }
46 }
47 loc = history[historycurrent];
48 //qDebug("Back:%u [%u,%u,%u]", loc, historystart, historycurrent, historyend);
49 return true;
50 }
51 else
52 {
53 return false;
54 }
55}
56
57#include <stdio.h>
58
59void CNavigation::setSaveData(unsigned char*& data, unsigned short& len, unsigned char* src, unsigned short srclen)
60{
61 len = srclen+sizeof(size_t)*(3+NAVIGATION_HISTORY_SIZE);
62 data = new unsigned char[len];
63 unsigned char* p = data;
64 memcpy(p, src, srclen);
65 p += srclen;
66 memcpy(p, &historystart, sizeof(size_t));
67 p += sizeof(size_t);
68 memcpy(p, &historyend, sizeof(size_t));
69 p += sizeof(size_t);
70 memcpy(p, &historycurrent, sizeof(size_t));
71 p += sizeof(size_t);
72 memcpy(p, history, sizeof(size_t)*NAVIGATION_HISTORY_SIZE);
73 printf("<%u,%u,%u>\n", historystart, historyend, historycurrent);
74 for (int i = historystart; i <= historyend; i++)
75 printf("<%u> ", history[i]);
76 printf("\n");
77}
78
79void CNavigation::putSaveData(unsigned char*& src, unsigned short& srclen)
80{
81 if (srclen >= sizeof(size_t)*(3+NAVIGATION_HISTORY_SIZE))
82 {
83 unsigned char* p = src;
84 memcpy(&historystart, p, sizeof(size_t));
85 p += sizeof(size_t);
86 memcpy(&historyend, p, sizeof(size_t));
87 p += sizeof(size_t);
88 memcpy(&historycurrent, p, sizeof(size_t));
89 p += sizeof(size_t);
90 memcpy(history, p, sizeof(size_t)*NAVIGATION_HISTORY_SIZE);
91 src = p + sizeof(size_t)*NAVIGATION_HISTORY_SIZE;
92 srclen -= sizeof(size_t)*(3+NAVIGATION_HISTORY_SIZE);
93 }
94 printf("<%u,%u,%u>\n", historystart, historyend, historycurrent);
95 for (int i = historystart; i <= historyend; i++)
96 printf("<%u> ", history[i]);
97 printf("\n");
98}