-
Notifications
You must be signed in to change notification settings - Fork 16
/
specialpages.cpp
98 lines (84 loc) · 2.35 KB
/
specialpages.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include "specialpages.h"
using namespace vbit;
SpecialPages::SpecialPages(Debug *debug) :
_debug(debug)
{
ResetIter();
}
SpecialPages::~SpecialPages()
{
}
void SpecialPages::addPage(TTXPageStream* p)
{
_specialPagesList.push_front(p);
}
void SpecialPages::deletePage(TTXPageStream* p)
{
_specialPagesList.remove(p);
ResetIter();
}
TTXPageStream* SpecialPages::NextPage()
{
if (_page == nullptr)
{
++_iter;
_page = *_iter;
}
else
{
if (_page->IsCarousel())
{
_page->StepNextSubpageNoLoop();
if (_page->GetCarouselPage() != NULL)
{
return _page;
}
}
++_iter;
_page = *_iter;
}
loop:
if (_iter == _specialPagesList.end())
{
_page = nullptr;
}
else if (_page->IsCarousel() && _page->GetCarouselPage() == NULL)
{
_page->StepNextSubpageNoLoop(); // ensure we don't point at a null subpage
}
if (_page)
{
if (_page->GetStatusFlag()==TTXPageStream::MARKED && _page->GetSpecialFlag()) // only remove it once
{
_debug->Log(Debug::LogLevels::logINFO,"[SpecialPages::NextPage] Deleted " + _page->GetSourcePage());
_page->SetState(TTXPageStream::GONE);
_iter = _specialPagesList.erase(_iter);
_page->SetSpecialFlag(false);
if (!(_page->GetNormalFlag() || _page->GetCarouselFlag() || _page->GetUpdatedFlag()))
_page->SetState(TTXPageStream::GONE); // if we are last mark it gone
_page = *_iter;
goto loop;
}
else if (!(_page->Special()))
{
std::stringstream ss;
ss << "[SpecialPages::NextPage()] no longer special " << std::hex << _page->GetPageNumber();
_debug->Log(Debug::LogLevels::logINFO,ss.str());
_iter = _specialPagesList.erase(_iter);
_page->SetSpecialFlag(false);
_page = *_iter;
goto loop;
}
if (((_page->GetPageNumber()>>8) & 0xFF) == 0xFF){ // never return page mFF from the page list
++_iter;
_page = *_iter;
goto loop; // jump back to try for the next page
}
}
return _page;
}
void SpecialPages::ResetIter()
{
_iter=_specialPagesList.begin();
_page=nullptr;
}