This commit is contained in:
dockes
2005-01-26 11:47:27 +00:00
parent c14b34647a
commit 0b18276947
9 changed files with 562 additions and 136 deletions
+173 -95
View File
@@ -8,106 +8,177 @@
<rect>
<x>0</x>
<y>0</y>
<width>774</width>
<height>619</height>
<width>782</width>
<height>622</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy>
<hsizetype>7</hsizetype>
<vsizetype>7</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="caption">
<string>recoll</string>
</property>
<widget class="QLayoutWidget">
<hbox>
<property name="name">
<cstring>layout7</cstring>
<cstring>unnamed</cstring>
</property>
<property name="geometry">
<rect>
<x>11</x>
<y>11</y>
<width>752</width>
<height>41</height>
</rect>
</property>
<hbox>
<widget class="QLayoutWidget">
<property name="name">
<cstring>unnamed</cstring>
<cstring>layout3</cstring>
</property>
<widget class="QLineEdit">
<vbox>
<property name="name">
<cstring>queryText</cstring>
<cstring>unnamed</cstring>
</property>
<property name="frameShape">
<enum>LineEditPanel</enum>
</property>
<property name="frameShadow">
<enum>Sunken</enum>
</property>
</widget>
<widget class="QPushButton">
<property name="name">
<cstring>Search</cstring>
</property>
<property name="text">
<string>pushButton1</string>
</property>
</widget>
<spacer>
<property name="name">
<cstring>spacer1</cstring>
</property>
<property name="orientation">
<enum>Horizontal</enum>
</property>
<property name="sizeType">
<enum>Expanding</enum>
</property>
<property name="sizeHint">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</hbox>
</widget>
<widget class="QSplitter">
<property name="name">
<cstring>splitter9</cstring>
</property>
<property name="geometry">
<rect>
<x>11</x>
<y>58</y>
<width>752</width>
<height>491</height>
</rect>
</property>
<property name="orientation">
<enum>Horizontal</enum>
</property>
<widget class="QTextEdit">
<property name="name">
<cstring>resTextEdit</cstring>
</property>
<widget class="QLayoutWidget">
<property name="name">
<cstring>layout2</cstring>
</property>
<hbox>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="QLineEdit">
<property name="name">
<cstring>queryText</cstring>
</property>
<property name="frameShape">
<enum>LineEditPanel</enum>
</property>
<property name="frameShadow">
<enum>Sunken</enum>
</property>
</widget>
<widget class="QPushButton">
<property name="name">
<cstring>Search</cstring>
</property>
<property name="text">
<string>Search</string>
</property>
</widget>
<spacer>
<property name="name">
<cstring>spacer1</cstring>
</property>
<property name="orientation">
<enum>Horizontal</enum>
</property>
<property name="sizeType">
<enum>Expanding</enum>
</property>
<property name="sizeHint">
<size>
<width>329</width>
<height>20</height>
</size>
</property>
</spacer>
</hbox>
</widget>
<widget class="QSplitter">
<property name="name">
<cstring>splitter9</cstring>
</property>
<property name="sizePolicy">
<sizepolicy>
<hsizetype>7</hsizetype>
<vsizetype>7</vsizetype>
<horstretch>1</horstretch>
<verstretch>1</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="orientation">
<enum>Horizontal</enum>
</property>
<widget class="QTextEdit">
<property name="name">
<cstring>resTextEdit</cstring>
</property>
<property name="sizePolicy">
<sizepolicy>
<hsizetype>7</hsizetype>
<vsizetype>7</vsizetype>
<horstretch>2</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="textFormat">
<enum>RichText</enum>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
<widget class="QSplitter">
<property name="name">
<cstring>splitter8</cstring>
</property>
<property name="sizePolicy">
<sizepolicy>
<hsizetype>7</hsizetype>
<vsizetype>7</vsizetype>
<horstretch>3</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="orientation">
<enum>Vertical</enum>
</property>
<widget class="QTextEdit">
<property name="name">
<cstring>previewTextEdit</cstring>
</property>
<property name="sizePolicy">
<sizepolicy>
<hsizetype>7</hsizetype>
<vsizetype>7</vsizetype>
<horstretch>0</horstretch>
<verstretch>2</verstretch>
</sizepolicy>
</property>
<property name="textFormat">
<enum>RichText</enum>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
<widget class="QTextEdit">
<property name="name">
<cstring>metaTextEdit</cstring>
</property>
<property name="sizePolicy">
<sizepolicy>
<hsizetype>7</hsizetype>
<vsizetype>7</vsizetype>
<horstretch>0</horstretch>
<verstretch>1</verstretch>
</sizepolicy>
</property>
<property name="textFormat">
<enum>RichText</enum>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</widget>
</widget>
</vbox>
</widget>
<widget class="QSplitter">
<property name="name">
<cstring>splitter8</cstring>
</property>
<property name="orientation">
<enum>Vertical</enum>
</property>
<widget class="QTextEdit">
<property name="name">
<cstring>textEdit12</cstring>
</property>
</widget>
<widget class="QTextEdit">
<property name="name">
<cstring>textEdit13</cstring>
</property>
</widget>
</widget>
</widget>
</hbox>
</widget>
<menubar>
<property name="name">
@@ -216,18 +287,24 @@
<receiver>RecollMain</receiver>
<slot>resTextEdit_clicked(int,int)</slot>
</connection>
<connection>
<sender>resTextEdit</sender>
<signal>returnPressed()</signal>
<receiver>RecollMain</receiver>
<slot>resTextEdit_returnPressed()</slot>
</connection>
<connection>
<sender>fileExitAction</sender>
<signal>activated()</signal>
<receiver>RecollMain</receiver>
<slot>fileExit()</slot>
</connection>
<connection>
<sender>queryText</sender>
<signal>returnPressed()</signal>
<receiver>RecollMain</receiver>
<slot>queryText_returnPressed()</slot>
</connection>
<connection>
<sender>Search</sender>
<signal>clicked()</signal>
<receiver>RecollMain</receiver>
<slot>Search_clicked()</slot>
</connection>
</connections>
<includes>
<include location="local" impldecl="in implementation">recollmain.ui.h</include>
@@ -238,7 +315,8 @@
<slot>helpContents()</slot>
<slot>helpAbout()</slot>
<slot>resTextEdit_clicked( int par, int car )</slot>
<slot>resTextEdit_returnPressed()</slot>
<slot>queryText_returnPressed()</slot>
<slot>Search_clicked()</slot>
</slots>
<pixmapinproject/>
<layoutdefaults spacing="6" margin="11"/>
+114 -18
View File
@@ -32,30 +32,126 @@ void RecollMain::helpAbout()
{
}
#include <qmessagebox.h>
#include "rcldb.h"
#include "rclconfig.h"
#include "debuglog.h"
#include "mimehandler.h"
extern RclConfig *rclconfig;
extern Rcl::Db *rcldb;
static string plaintorich(const string &in)
{
string out = "<qt><head><title></title></head><body><p>";
for (unsigned int i = 0; i < in.length() ; i++) {
if (in[i] == '\n') {
out += "<br>";
} else {
out += in[i];
}
if (i == 10) {
out += "<mytag>";
}
if (i == 20) {
out += "</mytag>";
}
}
return out;
}
void RecollMain::resTextEdit_clicked( int par, int car )
{
fprintf(stderr, "Clicked at paragraph %d, char %d\n", par, car);
}
Rcl::Doc doc;
doc.erase();
if (rcldb->getDoc(par, doc)) {
// Go to the file system to retrieve / convert the document text
// for preview:
#include "qfontdialog.h"
// Look for appropriate handler
MimeHandlerFunc fun =
getMimeHandler(doc.mimetype, rclconfig->getMimeConf());
if (!fun) {
QMessageBox::warning(0, "Recoll",
QString("No mime handler for mime type ") +
doc.mimetype.c_str());
return;
}
#define BS 200000
void RecollMain::resTextEdit_returnPressed()
{
fprintf(stderr, "ReturnPressed()\n");
resTextEdit->setFont( QFontDialog::getFont( 0, resTextEdit->font() ) );
const char *fname = "utf8.txt";
FILE *fp = fopen(fname, "r");
if (fp) {
char buf[BS];
memset(buf,0, sizeof(buf));
int n = fread(buf, 1, BS-1, fp);
fclose(fp);
QString str = QString::fromUtf8(buf, n);
resTextEdit->setTextFormat(RichText);
resTextEdit->setText(str);
string fn = doc.url.substr(6, string::npos);
Rcl::Doc fdoc;
if (!fun(rclconfig, fn, doc.mimetype, fdoc)) {
QMessageBox::warning(0, "Recoll",
QString("Failed to convert document for preview!\n") +
fn.c_str() + " mimetype " +
doc.mimetype.c_str());
return;
}
string rich = plaintorich(fdoc.text);
#if 0
//Highlighting; pass a list of (search term, style name) to plaintorich
// and create the corresponding styles with different colors here
// We need to :
// - Break the query into terms : wait for the query analyzer
// - Break the text into words. This should use a version of
// textsplit with an option to keep the punctuation (see how to do
// this). We do want the same splitter code to be used here and
// when indexing.
QStyleSheetItem *item =
new QStyleSheetItem( previewTextEdit->styleSheet(), "mytag" );
item->setColor("red");
item->setFontWeight(QFont::Bold);
#endif
QString str = QString::fromUtf8(rich.c_str(), rich.length());
previewTextEdit->setTextFormat(RichText);
previewTextEdit->setText(str);
}
}
void RecollMain::queryText_returnPressed()
{
LOGDEB(("RecollMain::queryText_returnPressed()\n"));
resTextEdit->clear();
previewTextEdit->clear();
string rawq = queryText->text();
rcldb->setQuery(rawq);
Rcl::Doc doc;
// Insert results if any in result list window
QString result;
resTextEdit->append("<qt><head></head><body>");
for (int i = 0;; i++) {
doc.erase();
if (!rcldb->getDoc(i, doc))
break;
LOGDEB(("Url: %s\n", doc.url.c_str()));
LOGDEB(("Mimetype: \n", doc.mimetype.c_str()));
LOGDEB(("Mtime: \n", doc.mtime.c_str()));
LOGDEB(("Origcharset: \n", doc.origcharset.c_str()));
LOGDEB(("Title: \n", doc.title.c_str()));
LOGDEB(("Text: \n", doc.text.c_str()));
LOGDEB(("Keywords: \n", doc.keywords.c_str()));
LOGDEB(("Abstract: \n", doc.abstract.c_str()));
result = "<p>" + doc.url + "</p>";
resTextEdit->append(result);
}
resTextEdit->append("</body></qt>");
// Display preview for 1st doc in list
resTextEdit_clicked(0, 0);
}
void RecollMain::Search_clicked()
{
queryText_returnPressed();
}