Parent: [64b0c9] (diff)

Child: [bbdb96] (diff)

Download this file

rclm_preview.cpp    260 lines (230 with data), 8.3 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
/* 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 "autoconfig.h"
#include <QMessageBox>
#include <QShortcut>
#include "debuglog.h"
#include "internfile.h"
#include "rclzg.h"
#include "rclmain_w.h"
static const QKeySequence quitKeySeq("Ctrl+q");
// If a preview (toplevel) window gets closed by the user, we need to
// clean up because there is no way to reopen it. And check the case
// where the current one is closed
void RclMain::previewClosed(Preview *w)
{
LOGDEB(("RclMain::previewClosed(%p)\n", w));
if (w == curPreview) {
LOGDEB(("Active preview closed\n"));
curPreview = 0;
} else {
LOGDEB(("Old preview closed\n"));
}
delete w;
}
// Document up to date check. The main problem we try to solve is
// displaying the wrong message from a compacted mail folder.
//
// Also we should re-run the query after updating the index because
// the ipaths may be wrong in the current result list. For now, the
// user does this by clicking search again once the indexing is done
//
// We only do this for the main index, else jump and prey (cant update
// anyway, even the makesig() call might not make sense for our base
// config)
bool RclMain::containerUpToDate(Rcl::Doc& doc)
{
// If ipath is empty, we decide we don't care. Also, we need an index,
if (doc.ipath.empty() || rcldb == 0)
return true;
string udi;
doc.getmeta(Rcl::Doc::keyudi, &udi);
if (udi.empty()) {
// Whatever...
return true;
}
string sig;
if (!FileInterner::makesig(theconfig, doc, sig)) {
QMessageBox::warning(0, "Recoll", tr("Can't access file: ") +
QString::fromLocal8Bit(doc.url.c_str()));
// Let's try the preview anyway...
return true;
}
if (!rcldb->needUpdate(udi, sig)) {
// Alles ist in ordnung
return true;
}
// We can only run indexing on the main index (dbidx 0)
bool ismainidx = rcldb->whatDbIdx(doc) == 0;
// Indexer already running?
bool ixnotact = (m_indexerState == IXST_NOTRUNNING);
QString msg = tr("Index not up to date for this file. "
"Refusing to risk showing the wrong entry. ");
if (ixnotact && ismainidx) {
msg += tr("Click Ok to update the "
"index for this file, then you will need to "
"re-run the query when indexing is done. ");
} else if (ismainidx) {
msg += tr("The indexer is running so things should "
"improve when it's done. ");
} else if (ixnotact) {
// Not main index
msg += tr("The document belongs to an external index"
"which I can't update. ");
}
msg += tr("Click Cancel to return to the list. "
"Click Ignore to show the preview anyway. ");
QMessageBox::StandardButtons bts =
QMessageBox::Ignore | QMessageBox::Cancel;
if (ixnotact &&ismainidx)
bts |= QMessageBox::Ok;
int rep =
QMessageBox::warning(0, tr("Warning"), msg, bts,
(ixnotact && ismainidx) ?
QMessageBox::Cancel : QMessageBox::NoButton);
if (m_indexerState == IXST_NOTRUNNING && rep == QMessageBox::Ok) {
LOGDEB(("Requesting index update for %s\n", doc.url.c_str()));
vector<Rcl::Doc> docs(1, doc);
updateIdxForDocs(docs);
}
if (rep != QMessageBox::Ignore)
return false;
return true;
}
/**
* Open a preview window for a given document, or load it into new tab of
* existing window.
*
* @param docnum db query index
* @param mod keyboards modifiers like ControlButton, ShiftButton
*/
void RclMain::startPreview(int docnum, Rcl::Doc doc, int mod)
{
LOGDEB(("startPreview(%d, doc, %d)\n", docnum, mod));
if (!containerUpToDate(doc))
return;
// Do the zeitgeist thing
zg_send_event(ZGSEND_PREVIEW, doc);
if (mod & Qt::ShiftModifier) {
// User wants new preview window
curPreview = 0;
}
if (curPreview == 0) {
HighlightData hdata;
m_source->getTerms(hdata);
curPreview = new Preview(reslist->listId(), hdata);
if (curPreview == 0) {
QMessageBox::warning(0, tr("Warning"),
tr("Can't create preview window"),
QMessageBox::Ok,
QMessageBox::NoButton);
return;
}
connect(new QShortcut(quitKeySeq, curPreview), SIGNAL (activated()),
this, SLOT (fileExit()));
connect(curPreview, SIGNAL(previewClosed(Preview *)),
this, SLOT(previewClosed(Preview *)));
connect(curPreview, SIGNAL(wordSelect(QString)),
sSearch, SLOT(addTerm(QString)));
connect(curPreview, SIGNAL(showNext(Preview *, int, int)),
this, SLOT(previewNextInTab(Preview *, int, int)));
connect(curPreview, SIGNAL(showPrev(Preview *, int, int)),
this, SLOT(previewPrevInTab(Preview *, int, int)));
connect(curPreview, SIGNAL(previewExposed(Preview *, int, int)),
this, SLOT(previewExposed(Preview *, int, int)));
connect(curPreview, SIGNAL(saveDocToFile(Rcl::Doc)),
this, SLOT(saveDocToFile(Rcl::Doc)));
curPreview->setWindowTitle(getQueryDescription());
curPreview->show();
}
curPreview->makeDocCurrent(doc, docnum);
}
/**
* Open a preview window for a given document, no linking to result list
*
* This is used to show ie parent documents, which have no corresponding
* entry in the result list.
*
*/
void RclMain::startPreview(Rcl::Doc doc)
{
Preview *preview = new Preview(0, HighlightData());
if (preview == 0) {
QMessageBox::warning(0, tr("Warning"),
tr("Can't create preview window"),
QMessageBox::Ok,
QMessageBox::NoButton);
return;
}
connect(new QShortcut(quitKeySeq, preview), SIGNAL (activated()),
this, SLOT (fileExit()));
connect(preview, SIGNAL(wordSelect(QString)),
sSearch, SLOT(addTerm(QString)));
// Do the zeitgeist thing
zg_send_event(ZGSEND_PREVIEW, doc);
preview->show();
preview->makeDocCurrent(doc, 0);
}
// Show next document from result list in current preview tab
void RclMain::previewNextInTab(Preview * w, int sid, int docnum)
{
previewPrevOrNextInTab(w, sid, docnum, true);
}
// Show previous document from result list in current preview tab
void RclMain::previewPrevInTab(Preview * w, int sid, int docnum)
{
previewPrevOrNextInTab(w, sid, docnum, false);
}
// Combined next/prev from result list in current preview tab
void RclMain::previewPrevOrNextInTab(Preview * w, int sid, int docnum, bool nxt)
{
LOGDEB(("RclMain::previewNextInTab sid %d docnum %d, listId %d\n",
sid, docnum, reslist->listId()));
if (w == 0) // ??
return;
if (sid != reslist->listId()) {
QMessageBox::warning(0, "Recoll",
tr("This search is not active any more"));
return;
}
if (nxt)
docnum++;
else
docnum--;
if (docnum < 0 || !m_source || docnum >= m_source->getResCnt()) {
QApplication::beep();
return;
}
Rcl::Doc doc;
if (!reslist->getDoc(docnum, doc)) {
QMessageBox::warning(0, "Recoll",
tr("Cannot retrieve document info from database"));
return;
}
w->makeDocCurrent(doc, docnum, true);
}
// Preview tab exposed: if the preview comes from the currently
// displayed result list, tell reslist (to color the paragraph)
void RclMain::previewExposed(Preview *, int sid, int docnum)
{
LOGDEB2(("RclMain::previewExposed: sid %d docnum %d, m_sid %d\n",
sid, docnum, reslist->listId()));
if (sid != reslist->listId()) {
return;
}
reslist->previewExposed(docnum);
}