Switch to unified view

a/src/qtgui/recollmain.ui.h b/src/qtgui/recollmain.ui.h
...
...
30
30
31
void RecollMain::helpAbout()
31
void RecollMain::helpAbout()
32
{
32
{
33
33
34
}
34
}
35
#include <qmessagebox.h>
35
36
37
#include "rcldb.h"
38
#include "rclconfig.h"
39
#include "debuglog.h"
40
#include "mimehandler.h"
41
42
extern RclConfig *rclconfig;
43
extern Rcl::Db *rcldb;
44
45
static string plaintorich(const string &in)
46
{
47
    string out = "<qt><head><title></title></head><body><p>";
48
    for (unsigned int i = 0; i < in.length() ; i++) {
49
  if (in[i] == '\n') {
50
      out += "<br>";
51
  } else {
52
      out += in[i];
53
  }
54
  if (i == 10) {
55
      out += "<mytag>";
56
  }
57
  if (i == 20) {
58
      out += "</mytag>";
59
  }       
60
61
    }
62
    return out;
63
}
36
64
37
void RecollMain::resTextEdit_clicked( int par, int car )
65
void RecollMain::resTextEdit_clicked( int par, int car )
38
{
66
{
39
    fprintf(stderr, "Clicked at paragraph %d, char %d\n", par, car);
67
    fprintf(stderr, "Clicked at paragraph %d, char %d\n", par, car);
68
    Rcl::Doc doc;
69
    doc.erase();
70
    if (rcldb->getDoc(par, doc)) {
71
  
72
  // Go to the file system to retrieve / convert the document text
73
  // for preview:
74
75
  // Look for appropriate handler
76
  MimeHandlerFunc fun = 
77
      getMimeHandler(doc.mimetype, rclconfig->getMimeConf());
78
  if (!fun) {
79
      QMessageBox::warning(0, "Recoll",
80
               QString("No mime handler for mime type ") +
81
               doc.mimetype.c_str());
82
      return;
83
  }
84
85
  string fn = doc.url.substr(6, string::npos);
86
  Rcl::Doc fdoc;
87
  if (!fun(rclconfig, fn,  doc.mimetype, fdoc)) {
88
      QMessageBox::warning(0, "Recoll",
89
               QString("Failed to convert document for preview!\n") +
90
               fn.c_str() + " mimetype " + 
91
               doc.mimetype.c_str());
92
      return;
93
  }
94
95
  string rich = plaintorich(fdoc.text);
96
97
#if 0
98
  //Highlighting; pass a list of (search term, style name) to plaintorich
99
  // and create the corresponding styles with different colors here
100
  // We need to :
101
  //  - Break the query into terms : wait for the query analyzer
102
  //  - Break the text into words. This should use a version of 
103
  //    textsplit with an option to keep the punctuation (see how to do
104
  //    this). We do want the same splitter code to be used here and 
105
  //    when indexing.
106
  QStyleSheetItem *item = 
107
      new QStyleSheetItem( previewTextEdit->styleSheet(), "mytag" );
108
  item->setColor("red");
109
  item->setFontWeight(QFont::Bold);
110
#endif
111
  QString str = QString::fromUtf8(rich.c_str(), rich.length());
112
113
  previewTextEdit->setTextFormat(RichText);
114
  previewTextEdit->setText(str);
115
    }
40
}
116
}
41
117
42
#include "qfontdialog.h"
118
void RecollMain::queryText_returnPressed()
119
{
120
    LOGDEB(("RecollMain::queryText_returnPressed()\n"));
121
    resTextEdit->clear();
122
    previewTextEdit->clear();
43
123
44
#define BS 200000     
124
    string rawq =  queryText->text();
45
void RecollMain::resTextEdit_returnPressed()
125
    rcldb->setQuery(rawq);
126
    Rcl::Doc doc;
127
128
    // Insert results if any in result list window 
129
    QString result;
130
    resTextEdit->append("<qt><head></head><body>");
131
    for (int i = 0;; i++) {
132
  doc.erase();
133
 if (!rcldb->getDoc(i, doc))
134
     break;
135
 LOGDEB(("Url: %s\n", doc.url.c_str()));
136
 LOGDEB(("Mimetype: \n", doc.mimetype.c_str()));
137
 LOGDEB(("Mtime: \n", doc.mtime.c_str()));
138
 LOGDEB(("Origcharset: \n", doc.origcharset.c_str()));
139
 LOGDEB(("Title: \n", doc.title.c_str()));
140
 LOGDEB(("Text: \n", doc.text.c_str()));
141
 LOGDEB(("Keywords: \n", doc.keywords.c_str()));
142
 LOGDEB(("Abstract: \n", doc.abstract.c_str()));
143
144
 result = "<p>" + doc.url + "</p>";
145
 resTextEdit->append(result);
146
    }
147
    resTextEdit->append("</body></qt>");
148
149
    // Display preview for 1st doc in list
150
    resTextEdit_clicked(0, 0);
151
}
152
153
154
void RecollMain::Search_clicked()
46
{
155
{
47
    fprintf(stderr, "ReturnPressed()\n");
156
    queryText_returnPressed();
48
    resTextEdit->setFont( QFontDialog::getFont( 0, resTextEdit->font() ) );
49
    const char *fname = "utf8.txt";
50
    FILE *fp = fopen(fname, "r"); 
51
    if (fp) {
52
 char buf[BS];
53
                memset(buf,0, sizeof(buf));
54
 int n = fread(buf, 1, BS-1, fp);
55
                fclose(fp);
56
               QString str = QString::fromUtf8(buf, n);
57
               resTextEdit->setTextFormat(RichText);
58
               resTextEdit->setText(str);
59
    }
60
61
}
157
}