moved code from qtgui to smallut
This commit is contained in:
parent
191d1492f8
commit
77777aa106
@ -1,5 +1,5 @@
|
|||||||
#ifndef lint
|
#ifndef lint
|
||||||
static char rcsid[] = "@(#$Id: reslist.cpp,v 1.48 2008-11-08 11:00:35 dockes Exp $ (C) 2005 J.F.Dockes";
|
static char rcsid[] = "@(#$Id: reslist.cpp,v 1.49 2008-11-19 10:06:49 dockes Exp $ (C) 2005 J.F.Dockes";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
@ -336,23 +336,6 @@ void ResList::resultPageFirst()
|
|||||||
resultPageNext();
|
resultPageNext();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert byte count into unit (KB/MB...) appropriate for display
|
|
||||||
static string displayableBytes(long size)
|
|
||||||
{
|
|
||||||
char sizebuf[30];
|
|
||||||
const char * unit = " B ";
|
|
||||||
|
|
||||||
if (size > 1024 && size < 1024*1024) {
|
|
||||||
unit = " KB ";
|
|
||||||
size /= 1024;
|
|
||||||
} else if (size >= 1024*1204) {
|
|
||||||
unit = " MB ";
|
|
||||||
size /= (1024*1024);
|
|
||||||
}
|
|
||||||
sprintf(sizebuf, "%ld%s", size, unit);
|
|
||||||
return string(sizebuf);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ResList::append(const QString &text)
|
void ResList::append(const QString &text)
|
||||||
{
|
{
|
||||||
QTEXTBROWSER::append(text);
|
QTEXTBROWSER::append(text);
|
||||||
@ -438,7 +421,7 @@ void ResList::resultPageNext()
|
|||||||
// We could use a <title> but the textedit doesnt display
|
// We could use a <title> but the textedit doesnt display
|
||||||
// it prominently
|
// it prominently
|
||||||
// Note: have to append text in chunks that make sense
|
// Note: have to append text in chunks that make sense
|
||||||
// html-wise. If we break things up to much, the editor
|
// html-wise. If we break things up too much, the editor
|
||||||
// gets confused. Hence the use of the 'chunk' text
|
// gets confused. Hence the use of the 'chunk' text
|
||||||
// accumulator
|
// accumulator
|
||||||
// Also note that there can be results beyond the estimated resCnt.
|
// Also note that there can be results beyond the estimated resCnt.
|
||||||
@ -497,16 +480,8 @@ void ResList::resultPageNext()
|
|||||||
sprintf(perbuf, "%3d%% ", percent);
|
sprintf(perbuf, "%3d%% ", percent);
|
||||||
|
|
||||||
// Determine icon to display if any
|
// Determine icon to display if any
|
||||||
string img_name;
|
|
||||||
string iconpath;
|
string iconpath;
|
||||||
string iconname = rclconfig->getMimeIconName(doc.mimetype, &iconpath);
|
(void)rclconfig->getMimeIconName(doc.mimetype, &iconpath);
|
||||||
LOGDEB1(("Img file; %s\n", iconpath.c_str()));
|
|
||||||
QImage image(iconpath.c_str());
|
|
||||||
if (!image.isNull()) {
|
|
||||||
img_name = string("img_") + iconname;
|
|
||||||
QMimeSourceFactory::defaultFactory()->
|
|
||||||
setImage(img_name.c_str(), image);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Printable url: either utf-8 if transcoding succeeds, or url-encoded
|
// Printable url: either utf-8 if transcoding succeeds, or url-encoded
|
||||||
string url;
|
string url;
|
||||||
@ -590,7 +565,7 @@ void ResList::resultPageNext()
|
|||||||
map<char,string> subs;
|
map<char,string> subs;
|
||||||
subs['A'] = !richabst.empty() ? richabst + "<br>" : "";
|
subs['A'] = !richabst.empty() ? richabst + "<br>" : "";
|
||||||
subs['D'] = datebuf;
|
subs['D'] = datebuf;
|
||||||
subs['I'] = img_name;
|
subs['I'] = iconpath;
|
||||||
subs['K'] = !doc.meta[Rcl::Doc::keykw].empty() ?
|
subs['K'] = !doc.meta[Rcl::Doc::keykw].empty() ?
|
||||||
escapeHtml(doc.meta[Rcl::Doc::keykw]) + "<br>" : "";
|
escapeHtml(doc.meta[Rcl::Doc::keykw]) + "<br>" : "";
|
||||||
subs['L'] = linksbuf;
|
subs['L'] = linksbuf;
|
||||||
@ -806,44 +781,7 @@ QString ResList::getDescription()
|
|||||||
/** Show detailed expansion of a query */
|
/** Show detailed expansion of a query */
|
||||||
void ResList::showQueryDetails()
|
void ResList::showQueryDetails()
|
||||||
{
|
{
|
||||||
// Break query into lines of reasonable length, avoid cutting words,
|
string oq = breakIntoLines(m_docSource->getDescription(), 100, 50);
|
||||||
// Also limit the total number of lines.
|
QString desc = tr("Query details") + ": " + QString::fromUtf8(oq.c_str());
|
||||||
const unsigned int ll = 100;
|
|
||||||
const unsigned int maxlines = 50;
|
|
||||||
string query = m_docSource->getDescription();
|
|
||||||
string oq;
|
|
||||||
unsigned int nlines = 0;
|
|
||||||
while (query.length() > 0) {
|
|
||||||
string ss = query.substr(0, ll);
|
|
||||||
if (ss.length() == ll) {
|
|
||||||
string::size_type pos = ss.find_last_of(" ");
|
|
||||||
if (pos == string::npos) {
|
|
||||||
pos = query.find_first_of(" ");
|
|
||||||
if (pos != string::npos)
|
|
||||||
ss = query.substr(0, pos+1);
|
|
||||||
else
|
|
||||||
ss = query;
|
|
||||||
} else {
|
|
||||||
ss = ss.substr(0, pos+1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// This cant happen, but anyway. Be very sure to avoid an infinite loop
|
|
||||||
if (ss.length() == 0) {
|
|
||||||
LOGDEB(("showQueryDetails: Internal error!\n"));
|
|
||||||
oq = query;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
oq += ss + "\n";
|
|
||||||
if (nlines++ >= maxlines) {
|
|
||||||
oq += " ... \n";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
query= query.substr(ss.length());
|
|
||||||
LOGDEB1(("oq [%s]\n, query [%s]\n, ss [%s]\n",
|
|
||||||
oq.c_str(), query.c_str(), ss.c_str()));
|
|
||||||
}
|
|
||||||
|
|
||||||
QString desc = tr("Query details") + ": " +
|
|
||||||
QString::fromUtf8(oq.c_str());
|
|
||||||
QMessageBox::information(this, tr("Query details"), desc);
|
QMessageBox::information(this, tr("Query details"), desc);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
#ifndef lint
|
#ifndef lint
|
||||||
static char rcsid[] = "@(#$Id: smallut.cpp,v 1.34 2008-10-08 16:15:22 dockes Exp $ (C) 2004 J.F.Dockes";
|
static char rcsid[] = "@(#$Id: smallut.cpp,v 1.35 2008-11-19 10:06:49 dockes Exp $ (C) 2004 J.F.Dockes";
|
||||||
#endif
|
#endif
|
||||||
/*
|
/*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
@ -497,6 +497,58 @@ bool pcSubst(const string& in, string& out, map<char, string>& subs)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Convert byte count into unit (KB/MB...) appropriate for display
|
||||||
|
string displayableBytes(long size)
|
||||||
|
{
|
||||||
|
char sizebuf[30];
|
||||||
|
const char * unit = " B ";
|
||||||
|
|
||||||
|
if (size > 1024 && size < 1024*1024) {
|
||||||
|
unit = " KB ";
|
||||||
|
size /= 1024;
|
||||||
|
} else if (size >= 1024*1204) {
|
||||||
|
unit = " MB ";
|
||||||
|
size /= (1024*1024);
|
||||||
|
}
|
||||||
|
sprintf(sizebuf, "%ld%s", size, unit);
|
||||||
|
return string(sizebuf);
|
||||||
|
}
|
||||||
|
|
||||||
|
string breakIntoLines(const string& in, unsigned int ll,
|
||||||
|
unsigned int maxlines)
|
||||||
|
{
|
||||||
|
string query = in;
|
||||||
|
string oq;
|
||||||
|
unsigned int nlines = 0;
|
||||||
|
while (query.length() > 0) {
|
||||||
|
string ss = query.substr(0, ll);
|
||||||
|
if (ss.length() == ll) {
|
||||||
|
string::size_type pos = ss.find_last_of(" ");
|
||||||
|
if (pos == string::npos) {
|
||||||
|
pos = query.find_first_of(" ");
|
||||||
|
if (pos != string::npos)
|
||||||
|
ss = query.substr(0, pos+1);
|
||||||
|
else
|
||||||
|
ss = query;
|
||||||
|
} else {
|
||||||
|
ss = ss.substr(0, pos+1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// This cant happen, but anyway. Be very sure to avoid an infinite loop
|
||||||
|
if (ss.length() == 0) {
|
||||||
|
oq = query;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
oq += ss + "\n";
|
||||||
|
if (nlines++ >= maxlines) {
|
||||||
|
oq += " ... \n";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
query= query.substr(ss.length());
|
||||||
|
}
|
||||||
|
return oq;
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////
|
////////////////////
|
||||||
// Internal redefinition of system time interface to help with dependancies
|
// Internal redefinition of system time interface to help with dependancies
|
||||||
struct m_timespec {
|
struct m_timespec {
|
||||||
|
|||||||
@ -16,7 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
#ifndef _SMALLUT_H_INCLUDED_
|
#ifndef _SMALLUT_H_INCLUDED_
|
||||||
#define _SMALLUT_H_INCLUDED_
|
#define _SMALLUT_H_INCLUDED_
|
||||||
/* @(#$Id: smallut.h,v 1.31 2008-10-08 16:15:22 dockes Exp $ (C) 2004 J.F.Dockes */
|
/* @(#$Id: smallut.h,v 1.32 2008-11-19 10:06:49 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@ -90,6 +90,12 @@ extern string truncate_to_word(const string &input, string::size_type maxlen);
|
|||||||
/** Truncate in place in an utf8-legal way */
|
/** Truncate in place in an utf8-legal way */
|
||||||
extern void utf8truncate(string &s, int maxlen);
|
extern void utf8truncate(string &s, int maxlen);
|
||||||
|
|
||||||
|
/** Convert byte count into unit (KB/MB...) appropriate for display */
|
||||||
|
string displayableBytes(long size);
|
||||||
|
|
||||||
|
/** Break big string into lines */
|
||||||
|
string breakIntoLines(const string& in, unsigned int ll = 100,
|
||||||
|
unsigned int maxlines= 50);
|
||||||
/** Small utility to substitute printf-like percents cmds in a string */
|
/** Small utility to substitute printf-like percents cmds in a string */
|
||||||
bool pcSubst(const string& in, string& out, map<char, string>& subs);
|
bool pcSubst(const string& in, string& out, map<char, string>& subs);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user