kioslave sort of works
This commit is contained in:
+68
-31
@@ -1,7 +1,11 @@
|
||||
#ifndef lint
|
||||
static char rcsid[] = "@(#$Id: reslistpager.cpp,v 1.1 2008-11-19 12:19:40 dockes Exp $ (C) 2007 J.F.Dockes";
|
||||
static char rcsid[] = "@(#$Id: reslistpager.cpp,v 1.2 2008-11-20 13:10:23 dockes Exp $ (C) 2007 J.F.Dockes";
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "reslistpager.h"
|
||||
#include "debuglog.h"
|
||||
#include "rclconfig.h"
|
||||
@@ -63,31 +67,9 @@ void ResListPager::resultPageNext()
|
||||
m_respage = npage;
|
||||
}
|
||||
|
||||
bool ResListPager::append(const string& data)
|
||||
{
|
||||
fprintf(stderr, "%s", data.c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
string ResListPager::tr(const string& in)
|
||||
{
|
||||
return in;
|
||||
}
|
||||
|
||||
void ResListPager::displayPage()
|
||||
{
|
||||
string chunk;
|
||||
if (pageEmpty()) {
|
||||
chunk = "<html><head></head><body>"
|
||||
"<p><font size=+1><b>";
|
||||
chunk += m_docSource->title();
|
||||
chunk += "</b></font>";
|
||||
chunk += "<a href=\"H-1\">";
|
||||
chunk += tr("Show query details");
|
||||
chunk += "</a><br>";
|
||||
append(chunk);
|
||||
return;
|
||||
}
|
||||
|
||||
// Display list header
|
||||
// We could use a <title> but the textedit doesnt display
|
||||
@@ -97,8 +79,12 @@ void ResListPager::displayPage()
|
||||
// gets confused. Hence the use of the 'chunk' text
|
||||
// accumulator
|
||||
// Also note that there can be results beyond the estimated resCnt.
|
||||
chunk = "<qt><head></head><body><p>"
|
||||
"<font size=+1><b>";
|
||||
chunk = "<html><head>"
|
||||
"<meta http-equiv=\"content-type\""
|
||||
"content=\"text/html; charset=utf-8\">"
|
||||
"</head><body>";
|
||||
chunk += pageTop();
|
||||
chunk += "<p><font size=+1><b>";
|
||||
chunk += m_docSource->title();
|
||||
chunk += "</b></font>"
|
||||
" ";
|
||||
@@ -121,9 +107,21 @@ void ResListPager::displayPage()
|
||||
chunk += buf;
|
||||
}
|
||||
}
|
||||
chunk += "<a href=\"H-1\">";
|
||||
chunk += tr("(show query)");
|
||||
chunk += "</a></p>";
|
||||
chunk += detailsLink();
|
||||
if (hasPrev() || hasNext()) {
|
||||
chunk += " ";
|
||||
if (hasPrev()) {
|
||||
chunk += "<a href=\"" + prevUrl() + "\"><b>";
|
||||
chunk += tr("Previous");
|
||||
chunk += "</b></a> ";
|
||||
}
|
||||
if (hasNext()) {
|
||||
chunk += "<a href=\""+ nextUrl() + "\"><b>";
|
||||
chunk += tr("Next");
|
||||
chunk += "</b></a>";
|
||||
}
|
||||
}
|
||||
chunk += "</p>";
|
||||
|
||||
append(chunk);
|
||||
if (pageEmpty())
|
||||
@@ -154,6 +152,7 @@ void ResListPager::displayPage()
|
||||
// Determine icon to display if any
|
||||
string iconpath;
|
||||
RclConfig::getMainConfig()->getMimeIconName(doc.mimetype, &iconpath);
|
||||
iconpath = string("file://") + iconpath;
|
||||
|
||||
// Printable url: either utf-8 if transcoding succeeds, or url-encoded
|
||||
string url;
|
||||
@@ -249,7 +248,7 @@ void ResListPager::displayPage()
|
||||
subs['U'] = url;
|
||||
|
||||
string formatted;
|
||||
pcSubst(m_parformat, formatted, subs);
|
||||
pcSubst(parFormat(), formatted, subs);
|
||||
chunk += formatted;
|
||||
|
||||
chunk += "</p>\n";
|
||||
@@ -262,12 +261,12 @@ void ResListPager::displayPage()
|
||||
chunk = "<p align=\"center\">";
|
||||
if (hasPrev() || hasNext()) {
|
||||
if (hasPrev()) {
|
||||
chunk += "<a href=\"p-1\"><b>";
|
||||
chunk += "<a href=\"" + prevUrl() + "\"><b>";
|
||||
chunk += tr("Previous");
|
||||
chunk += "</b></a> ";
|
||||
}
|
||||
if (hasNext()) {
|
||||
chunk += "<a href=\"n-1\"><b>";
|
||||
chunk += "<a href=\""+ nextUrl() + "\"><b>";
|
||||
chunk += tr("Next");
|
||||
chunk += "</b></a>";
|
||||
}
|
||||
@@ -276,3 +275,41 @@ void ResListPager::displayPage()
|
||||
chunk += "</body></html>\n";
|
||||
append(chunk);
|
||||
}
|
||||
|
||||
string ResListPager::nextUrl()
|
||||
{
|
||||
return "n-1";
|
||||
}
|
||||
string ResListPager::prevUrl()
|
||||
{
|
||||
return "p-1";
|
||||
}
|
||||
|
||||
// Default implementations for things that should be re-implemented by our user.
|
||||
bool ResListPager::append(const string& data)
|
||||
{
|
||||
fprintf(stderr, "%s", data.c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
string ResListPager::tr(const string& in)
|
||||
{
|
||||
return in;
|
||||
}
|
||||
|
||||
string ResListPager::detailsLink()
|
||||
{
|
||||
string chunk = "<a href=\"H-1\">";
|
||||
chunk += tr("(show query)") + "</a>";
|
||||
return chunk;
|
||||
}
|
||||
|
||||
const string &ResListPager::parFormat()
|
||||
{
|
||||
const static string format("<img src=\"%I\" align=\"left\">"
|
||||
"%R %S %L <b>%T</b><br>"
|
||||
"%M %D <i>%U</i><br>"
|
||||
"%A %K");
|
||||
return format;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#ifndef _reslistpager_h_included_
|
||||
#define _reslistpager_h_included_
|
||||
/* @(#$Id: reslistpager.h,v 1.1 2008-11-19 12:19:40 dockes Exp $ (C) 2007 J.F.Dockes */
|
||||
/* @(#$Id: reslistpager.h,v 1.2 2008-11-20 13:10:23 dockes Exp $ (C) 2007 J.F.Dockes */
|
||||
|
||||
#include <vector>
|
||||
using std::vector;
|
||||
@@ -13,12 +13,25 @@ using std::vector;
|
||||
*/
|
||||
class ResListPager {
|
||||
public:
|
||||
ResListPager(RefCntr<DocSequence> src, int pagesize,
|
||||
const string& parformat)
|
||||
: m_docSource(src), m_pagesize(pagesize), m_parformat(parformat),
|
||||
m_hasNext(false)
|
||||
ResListPager() : m_pagesize(10), m_hasNext(false) {}
|
||||
void setDocSource(RefCntr<DocSequence> src)
|
||||
{
|
||||
m_winfirst = -1;
|
||||
m_docSource = src;
|
||||
m_hasNext = false;
|
||||
m_respage.clear();
|
||||
}
|
||||
ResListPager(RefCntr<DocSequence> src, int pagesize)
|
||||
: m_winfirst(-1), m_docSource(src), m_pagesize(pagesize),
|
||||
m_hasNext(false)
|
||||
{}
|
||||
virtual ~ResListPager() {}
|
||||
int pageNumber()
|
||||
{
|
||||
if (m_winfirst < 0 || m_pagesize <= 0)
|
||||
return -1;
|
||||
return m_winfirst / m_pagesize;
|
||||
}
|
||||
void pageNext();
|
||||
bool hasNext() {return m_hasNext;}
|
||||
bool hasPrev() {return m_winfirst > 0;}
|
||||
@@ -35,14 +48,24 @@ public:
|
||||
void resultPageNext();
|
||||
void displayPage();
|
||||
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 string tr(const string& in);
|
||||
virtual string detailsLink();
|
||||
virtual const string &parFormat();
|
||||
virtual string nextUrl();
|
||||
virtual string prevUrl();
|
||||
virtual string pageTop() {return string();}
|
||||
|
||||
private:
|
||||
// First docnum (from docseq) in current page
|
||||
int m_winfirst;
|
||||
RefCntr<DocSequence> m_docSource;
|
||||
int m_pagesize;
|
||||
string m_parformat;
|
||||
|
||||
bool m_hasNext;
|
||||
vector<ResListEntry> m_respage;
|
||||
|
||||
Reference in New Issue
Block a user