Parent: [b28eaf] (diff)

Child: [ef00bf] (diff)

Download this file

docseq.cpp    110 lines (99 with data), 3.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
/* Copyright (C) 2005 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.
*/
#include "docseq.h"
#include "filtseq.h"
#include "sortseq.h"
#include "debuglog.h"
string DocSequence::o_sort_trans;
string DocSequence::o_filt_trans;
int DocSequence::getSeqSlice(int offs, int cnt, vector<ResListEntry>& result)
{
int ret = 0;
for (int num = offs; num < offs + cnt; num++, ret++) {
result.push_back(ResListEntry());
if (!getDoc(num, result.back().doc, &result.back().subHeader)) {
result.pop_back();
return ret;
}
}
return ret;
}
// Remove stacked modifying sources (sort, filter) until we get to a real one
void DocSource::stripStack()
{
if (m_seq.isNull())
return;
while (m_seq->getSourceSeq().isNotNull()) {
m_seq = m_seq->getSourceSeq();
}
}
bool DocSource::buildStack()
{
LOGDEB2(("DocSource::buildStack()\n"));
stripStack();
if (m_seq.isNull())
return false;
// Filtering must be done before sorting, (which may
// truncates the original list)
if (m_seq->canFilter()) {
if (!m_seq->setFiltSpec(m_fspec)) {
LOGERR(("DocSource::buildStack: setfiltspec failed\n"));
}
} else {
if (m_fspec.isNotNull()) {
m_seq =
RefCntr<DocSequence>(new DocSeqFiltered(m_seq, m_fspec));
}
}
if (m_seq->canSort()) {
if (!m_seq->setSortSpec(m_sspec)) {
LOGERR(("DocSource::buildStack: setsortspec failed\n"));
}
} else {
if (m_sspec.isNotNull()) {
m_seq = RefCntr<DocSequence>(new DocSeqSorted(m_seq, m_sspec));
}
}
return true;
}
string DocSource::title()
{
if (m_seq.isNull())
return string();
string qual;
if (m_fspec.isNotNull() && !m_sspec.isNotNull())
qual = string(" (") + o_filt_trans + string(")");
else if (!m_fspec.isNotNull() && m_sspec.isNotNull())
qual = string(" (") + o_sort_trans + string(")");
else if (m_fspec.isNotNull() && m_sspec.isNotNull())
qual = string(" (") + o_sort_trans + string(",") + o_filt_trans + string(")");
return m_seq->title() + qual;
}
bool DocSource::setFiltSpec(const DocSeqFiltSpec &f)
{
LOGDEB2(("DocSource::setFiltSpec\n"));
m_fspec = f;
buildStack();
return true;
}
bool DocSource::setSortSpec(const DocSeqSortSpec &s)
{
LOGDEB2(("DocSource::setSortSpec\n"));
m_sspec = s;
buildStack();
return true;
}