Parent: [ab9330] (diff)

Child: [183c6d] (diff)

Download this file

rclm_wins.cpp    410 lines (380 with data), 11.6 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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
/* 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 <QShortcut>
#include <QMessageBox>
#include "debuglog.h"
#include "internfile.h"
#include "listdialog.h"
#include "confgui/confguiindex.h"
#include "idxsched.h"
#include "crontool.h"
#include "rtitool.h"
#include "snippets_w.h"
#include "fragbuts.h"
#include "specialindex.h"
#include "rclmain_w.h"
using namespace std;
static const QKeySequence quitKeySeq("Ctrl+q");
static const QKeySequence closeKeySeq("Ctrl+w");
// Open advanced search dialog.
void RclMain::showAdvSearchDialog()
{
if (asearchform == 0) {
asearchform = new AdvSearch(0);
if (asearchform == 0) {
return;
}
connect(new QShortcut(quitKeySeq, asearchform), SIGNAL (activated()),
this, SLOT (fileExit()));
connect(asearchform,
SIGNAL(startSearch(STD_SHARED_PTR<Rcl::SearchData>, bool)),
this, SLOT(startSearch(STD_SHARED_PTR<Rcl::SearchData>, bool)));
asearchform->show();
} else {
// Close and reopen, in hope that makes us visible...
asearchform->close();
asearchform->show();
}
}
void RclMain::showSpellDialog()
{
if (spellform == 0) {
spellform = new SpellW(0);
connect(new QShortcut(quitKeySeq, spellform), SIGNAL (activated()),
this, SLOT (fileExit()));
connect(spellform, SIGNAL(wordSelect(QString)),
sSearch, SLOT(addTerm(QString)));
spellform->show();
} else {
// Close and reopen, in hope that makes us visible...
spellform->close();
spellform->show();
}
}
void RclMain::showFragButs()
{
if (fragbuts && fragbuts->isStale(0)) {
deleteZ(fragbuts);
}
if (fragbuts == 0) {
fragbuts = new FragButs(0);
if (fragbuts->ok()) {
fragbuts->show();
connect(fragbuts, SIGNAL(fragmentsChanged()),
this, SLOT(onFragmentsChanged()));
} else {
deleteZ(fragbuts);
}
} else {
// Close and reopen, in hope that makes us visible...
fragbuts->close();
fragbuts->show();
}
}
void RclMain::showSpecIdx()
{
if (specidx == 0) {
specidx = new SpecIdxW(0);
connect(specidx, SIGNAL(accepted()), this, SLOT(specialIndex()));
specidx->show();
} else {
// Close and reopen, in hope that makes us visible...
specidx->close();
specidx->show();
}
}
void RclMain::showIndexConfig()
{
showIndexConfig(false);
}
void RclMain::execIndexConfig()
{
showIndexConfig(true);
}
void RclMain::showIndexConfig(bool modal)
{
LOGDEB(("showIndexConfig()\n"));
if (indexConfig == 0) {
indexConfig = new ConfIndexW(0, theconfig);
connect(new QShortcut(quitKeySeq, indexConfig), SIGNAL (activated()),
this, SLOT (fileExit()));
} else {
// Close and reopen, in hope that makes us visible...
indexConfig->close();
indexConfig->reloadPanels();
}
if (modal) {
indexConfig->exec();
indexConfig->setModal(false);
} else {
indexConfig->show();
}
}
void RclMain::showIndexSched()
{
showIndexSched(false);
}
void RclMain::execIndexSched()
{
showIndexSched(true);
}
void RclMain::showIndexSched(bool modal)
{
#ifdef _WIN32
QMessageBox::information(this, tr("Index scheduling"),
tr("Sorry, not available under Windows for now, use the File menu entries "
"to update the index"));
return;
#endif
LOGDEB(("showIndexSched()\n"));
if (indexSched == 0) {
indexSched = new IdxSchedW(this);
connect(new QShortcut(quitKeySeq, indexSched), SIGNAL (activated()),
this, SLOT (fileExit()));
connect(indexSched->cronCLB, SIGNAL(clicked()),
this, SLOT(execCronTool()));
if (theconfig && theconfig->isDefaultConfig()) {
#ifdef RCL_MONITOR
connect(indexSched->rtidxCLB, SIGNAL(clicked()),
this, SLOT(execRTITool()));
#else
indexSched->rtidxCLB->setEnabled(false);
indexSched->rtidxCLB->setToolTip(tr("Disabled because the real time indexer was not compiled in."));
#endif
} else {
indexSched->rtidxCLB->setEnabled(false);
indexSched->rtidxCLB->setToolTip(tr("This configuration tool only works for the main index."));
}
} else {
// Close and reopen, in hope that makes us visible...
indexSched->close();
}
if (modal) {
indexSched->exec();
indexSched->setModal(false);
} else {
indexSched->show();
}
}
void RclMain::showCronTool()
{
showCronTool(false);
}
void RclMain::execCronTool()
{
showCronTool(true);
}
void RclMain::showCronTool(bool modal)
{
LOGDEB(("showCronTool()\n"));
if (cronTool == 0) {
cronTool = new CronToolW(0);
connect(new QShortcut(quitKeySeq, cronTool), SIGNAL (activated()),
this, SLOT (fileExit()));
} else {
// Close and reopen, in hope that makes us visible...
cronTool->close();
}
if (modal) {
cronTool->exec();
cronTool->setModal(false);
} else {
cronTool->show();
}
}
void RclMain::showRTITool()
{
showRTITool(false);
}
void RclMain::execRTITool()
{
showRTITool(true);
}
void RclMain::showRTITool(bool modal)
{
LOGDEB(("showRTITool()\n"));
if (rtiTool == 0) {
rtiTool = new RTIToolW(0);
connect(new QShortcut(quitKeySeq, rtiTool), SIGNAL (activated()),
this, SLOT (fileExit()));
} else {
// Close and reopen, in hope that makes us visible...
rtiTool->close();
}
if (modal) {
rtiTool->exec();
rtiTool->setModal(false);
} else {
rtiTool->show();
}
}
void RclMain::showUIPrefs()
{
if (uiprefs == 0) {
uiprefs = new UIPrefsDialog(this);
connect(new QShortcut(quitKeySeq, uiprefs), SIGNAL (activated()),
this, SLOT (fileExit()));
connect(uiprefs, SIGNAL(uiprefsDone()), this, SLOT(setUIPrefs()));
connect(this, SIGNAL(stemLangChanged(const QString&)),
uiprefs, SLOT(setStemLang(const QString&)));
} else {
// Close and reopen, in hope that makes us visible...
uiprefs->close();
}
uiprefs->show();
}
void RclMain::showExtIdxDialog()
{
if (uiprefs == 0) {
uiprefs = new UIPrefsDialog(this);
connect(new QShortcut(quitKeySeq, uiprefs), SIGNAL (activated()),
this, SLOT (fileExit()));
connect(uiprefs, SIGNAL(uiprefsDone()), this, SLOT(setUIPrefs()));
} else {
// Close and reopen, in hope that makes us visible...
uiprefs->close();
}
uiprefs->tabWidget->setCurrentIndex(3);
uiprefs->show();
}
void RclMain::showAboutDialog()
{
string vstring = Rcl::version_string() +
string("<br> http://www.recoll.org") +
string("<br> http://www.xapian.org");
QMessageBox::information(this, tr("About Recoll"), vstring.c_str());
}
void RclMain::showMissingHelpers()
{
string miss;
if (!theconfig->getMissingHelperDesc(miss)) {
QMessageBox::information(this, "", tr("Indexing did not run yet"));
return;
}
QString msg = QString::fromUtf8("<p>") +
tr("External applications/commands needed for your file types "
"and not found, as stored by the last indexing pass in ");
msg += "<i>";
msg += QString::fromLocal8Bit(theconfig->getConfDir().c_str());
msg += "/missing</i>:<pre>\n";
if (!miss.empty()) {
msg += QString::fromUtf8(miss.c_str());
} else {
msg += tr("No helpers found missing");
}
msg += "</pre>";
QMessageBox::information(this, tr("Missing helper programs"), msg);
}
void RclMain::showActiveTypes()
{
if (rcldb == 0) {
QMessageBox::warning(0, tr("Error"),
tr("Index not open"),
QMessageBox::Ok,
QMessageBox::NoButton);
return;
}
// All mime types in index.
vector<string> vdbtypes;
if (!rcldb->getAllDbMimeTypes(vdbtypes)) {
QMessageBox::warning(0, tr("Error"),
tr("Index query error"),
QMessageBox::Ok,
QMessageBox::NoButton);
return;
}
set<string> mtypesfromdb;
mtypesfromdb.insert(vdbtypes.begin(), vdbtypes.end());
// All types listed in mimeconf:
vector<string> mtypesfromconfig = theconfig->getAllMimeTypes();
// Intersect file system types with config types (those not in the
// config can be indexed by name, not by content)
set<string> mtypesfromdbconf;
for (vector<string>::const_iterator it = mtypesfromconfig.begin();
it != mtypesfromconfig.end(); it++) {
if (mtypesfromdb.find(*it) != mtypesfromdb.end())
mtypesfromdbconf.insert(*it);
}
// Substract the types for missing helpers (the docs are indexed
// by name only):
string miss;
if (theconfig->getMissingHelperDesc(miss) && !miss.empty()) {
FIMissingStore st(miss);
map<string, set<string> >::const_iterator it;
for (it = st.m_typesForMissing.begin();
it != st.m_typesForMissing.end(); it++) {
set<string>::const_iterator it1;
for (it1 = it->second.begin();
it1 != it->second.end(); it1++) {
set<string>::iterator it2 = mtypesfromdbconf.find(*it1);
if (it2 != mtypesfromdbconf.end())
mtypesfromdbconf.erase(it2);
}
}
}
ListDialog dialog;
dialog.setWindowTitle(tr("Indexed MIME Types"));
// Turn the result into a string and display
dialog.groupBox->setTitle(tr("Content has been indexed for these mime types:"));
// We replace the list with an editor so that the user can copy/paste
delete dialog.listWidget;
QTextEdit *editor = new QTextEdit(dialog.groupBox);
editor->setReadOnly(true);
dialog.horizontalLayout->addWidget(editor);
for (set<string>::const_iterator it = mtypesfromdbconf.begin();
it != mtypesfromdbconf.end(); it++) {
editor->append(QString::fromUtf8(it->c_str()));
}
editor->moveCursor(QTextCursor::Start);
editor->ensureCursorVisible();
dialog.exec();
}
void RclMain::newDupsW(const Rcl::Doc, const vector<Rcl::Doc> dups)
{
ListDialog dialog;
dialog.setWindowTitle(tr("Duplicate documents"));
dialog.groupBox->setTitle(tr("These Urls ( | ipath) share the same"
" content:"));
// We replace the list with an editor so that the user can copy/paste
delete dialog.listWidget;
QTextEdit *editor = new QTextEdit(dialog.groupBox);
editor->setReadOnly(true);
dialog.horizontalLayout->addWidget(editor);
for (vector<Rcl::Doc>::const_iterator it = dups.begin();
it != dups.end(); it++) {
if (it->ipath.empty())
editor->append(QString::fromLocal8Bit(it->url.c_str()));
else
editor->append(QString::fromLocal8Bit(it->url.c_str()) + " | " +
QString::fromUtf8(it->ipath.c_str()));
}
editor->moveCursor(QTextCursor::Start);
editor->ensureCursorVisible();
dialog.exec();
}
void RclMain::showSnippets(Rcl::Doc doc)
{
SnippetsW *sp = new SnippetsW(doc, m_source);
connect(sp, SIGNAL(startNativeViewer(Rcl::Doc, int, QString)),
this, SLOT(startNativeViewer(Rcl::Doc, int, QString)));
connect(new QShortcut(quitKeySeq, sp), SIGNAL (activated()),
this, SLOT (fileExit()));
connect(new QShortcut(closeKeySeq, sp), SIGNAL (activated()),
sp, SLOT (close()));
sp->show();
}