Parent: [469c54] (diff)

Child: [2a091e] (diff)

Download this file

reslistpager.h    130 lines (120 with data), 4.0 kB

  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
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/* Copyright (C) 2007 J.F.Dockes
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef _reslistpager_h_included_
#define _reslistpager_h_included_
#include <vector>
using std::vector;
#include "refcntr.h"
#include "docseq.h"
class RclConfig;
class PlainToRich;
class HiliteData;
/**
* Manage a paged HTML result list.
*/
class ResListPager {
public:
ResListPager(int pagesize=10);
virtual ~ResListPager() {}
void setHighLighter(PlainToRich *ptr)
{
m_hiliter = ptr;
}
void setDocSource(RefCntr<DocSequence> src, int winfirst = -1)
{
m_pagesize = m_newpagesize;
m_winfirst = winfirst;
m_hasNext = false;
m_docSource = src;
m_respage.clear();
}
void setPageSize(int ps)
{
m_newpagesize = ps;
}
int pageNumber()
{
if (m_winfirst < 0 || m_pagesize <= 0)
return -1;
return m_winfirst / m_pagesize;
}
int pageFirstDocNum() {
return m_winfirst;
}
int pageLastDocNum() {
if (m_winfirst < 0 || m_respage.size() == 0)
return -1;
return m_winfirst + m_respage.size() - 1;
}
virtual int pageSize() const {return m_pagesize;}
void pageNext();
bool hasNext() {return m_hasNext;}
bool hasPrev() {return m_winfirst > 0;}
bool atBot() {return m_winfirst <= 0;}
void resultPageFirst() {
m_winfirst = -1;
m_pagesize = m_newpagesize;
resultPageNext();
}
void resultPageBack() {
if (m_winfirst <= 0) return;
m_winfirst -= 2 * m_pagesize;
resultPageNext();
}
void resultPageNext();
void resultPageFor(int docnum);
void displayPage(RclConfig *);
void displayDoc(RclConfig *, int idx, Rcl::Doc& doc,
const HiliteData& hdata, const string& sh = "");
bool pageEmpty() {return m_respage.size() == 0;}
string queryDescription() {return m_docSource.isNull() ? "" :
m_docSource->getDescription();}
// Things that need to be reimplemented in the subclass:
virtual bool append(const string& data);
virtual bool append(const string& data, int, const Rcl::Doc&)
{
return append(data);
}
// Translation function. This is reimplemented in the qt reslist
// object For this to work, the strings must be duplicated inside
// reslist.cpp (see the QT_TR_NOOP in there). Very very unwieldy.
// To repeat: any change to a string used with trans() inside
// reslistpager.cpp must be reflected in the string table inside
// reslist.cpp for translation to work.
virtual string trans(const string& in);
virtual string detailsLink();
virtual const string &parFormat();
virtual const string &dateFormat();
virtual string nextUrl();
virtual string prevUrl();
virtual string pageTop() {return string();}
virtual string iconPath(RclConfig *, const string& mtype);
virtual void suggest(const vector<string>, vector<string>&sugg) {
sugg.clear();
}
virtual string absSep() {return "&hellip;";}
private:
int m_pagesize;
int m_newpagesize;
// First docnum (from docseq) in current page
int m_winfirst;
bool m_hasNext;
PlainToRich *m_hiliter;
RefCntr<DocSequence> m_docSource;
vector<ResListEntry> m_respage;
};
#endif /* _reslistpager_h_included_ */