Parent: [c11a64] (diff)

Child: [c5b545] (diff)

Download this file

uiprefs.ui.h    331 lines (299 with data), 9.9 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
/*
* 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.
*/
/****************************************************************************
** ui.h extension file, included from the uic-generated form implementation.
**
** If you want to add, delete, or rename functions or slots, use
** Qt Designer to update this file, preserving your code.
**
** You should not define a constructor or destructor in this file.
** Instead, write your code in functions called init() and destroy().
** These will automatically be called by the form's constructor and
** destructor.
*****************************************************************************/
#include <sys/stat.h>
#include <string>
#include <algorithm>
#include <list>
#include "qfontdialog.h"
#include "qfiledialog.h"
#include "qspinbox.h"
#include "qmessagebox.h"
#include "recoll.h"
#include "guiutils.h"
#include "rcldb.h"
#include "pathut.h"
void UIPrefsDialog::init()
{
// Entries per result page spinbox
pageLenSB->setValue(prefs.respagesize);
// Show icons checkbox
useIconsCB->setChecked(prefs.showicons);
autoSearchCB->setChecked(prefs.autoSearchOnWS);
// Result list font family and size
reslistFontFamily = prefs.reslistfontfamily;
reslistFontSize = prefs.reslistfontsize;
QString s;
if (prefs.reslistfontfamily.length() == 0) {
reslistFontPB->setText(this->font().family() + "-" +
s.setNum(this->font().pointSize()));
} else {
reslistFontPB->setText(reslistFontFamily + "-" +
s.setNum(reslistFontSize));
}
helpBrowserLE->setText(prefs.htmlBrowser);
// Stemming language combobox
stemLangCMB->insertItem("(no stemming)");
list<string> langs;
string reason;
if (!maybeOpenDb(reason)) {
QMessageBox::critical(0, "Recoll", QString(reason.c_str()));
exit(1);
}
langs = rcldb->getStemLangs();
int i = 0, cur = -1;
for (list<string>::const_iterator it = langs.begin();
it != langs.end(); it++) {
stemLangCMB->
insertItem(QString::fromAscii(it->c_str(), it->length()));
i++;
if (cur == -1) {
if (!strcmp(prefs.queryStemLang.ascii(), it->c_str()))
cur = i;
}
}
if (cur < 0)
cur = 0;
stemLangCMB->setCurrentItem(cur);
buildAbsCB->setDown(prefs.queryBuildAbstract);
if (!prefs.queryBuildAbstract) {
replAbsCB->setEnabled(false);
}
replAbsCB->setDown(prefs.queryReplaceAbstract);
// Initialize the extra databases listboxes
QStringList ql;
for (list<string>::iterator it = prefs.allExtraDbs.begin();
it != prefs.allExtraDbs.end(); it++) {
ql.append(QString::fromLocal8Bit(it->c_str()));
}
allDbsLB->insertStringList(ql);
ql.clear();
for (list<string>::iterator it = prefs.activeExtraDbs.begin();
it != prefs.activeExtraDbs.end(); it++) {
ql.append(QString::fromLocal8Bit(it->c_str()));
}
actDbsLB->insertStringList(ql);
ql.clear();
connect(reslistFontPB, SIGNAL(clicked()), this, SLOT(showFontDialog()));
connect(helpBrowserPB, SIGNAL(clicked()), this, SLOT(showBrowserDialog()));
connect(resetFontPB, SIGNAL(clicked()), this, SLOT(resetReslistFont()));
connect(extraDbLE,SIGNAL(textChanged(const QString&)), this,
SLOT(extraDbTextChanged(const QString&)));
connect(addAADbPB, SIGNAL(clicked()), this, SLOT(addAADbPB_clicked()));
connect(addADbPB, SIGNAL(clicked()), this, SLOT(addADbPB_clicked()));
connect(delADbPB, SIGNAL(clicked()), this, SLOT(delADbPB_clicked()));
connect(delAADbPB, SIGNAL(clicked()), this, SLOT(delAADbPB_clicked()));
connect(addExtraDbPB, SIGNAL(clicked()), this, SLOT(addExtraDbPB_clicked()));
connect(browseDbPB, SIGNAL(clicked()), this, SLOT(browseDbPB_clicked()));
}
void UIPrefsDialog::accept()
{
prefs.showicons = useIconsCB->isChecked();
prefs.autoSearchOnWS = autoSearchCB->isChecked();
prefs.respagesize = pageLenSB->value();
prefs.reslistfontfamily = reslistFontFamily;
prefs.reslistfontsize = reslistFontSize;
prefs.htmlBrowser = helpBrowserLE->text();
if (stemLangCMB->currentItem() == 0) {
prefs.queryStemLang = "";
} else {
prefs.queryStemLang = stemLangCMB->currentText();
}
prefs.queryBuildAbstract = buildAbsCB->isChecked();
prefs.queryReplaceAbstract = buildAbsCB->isChecked() &&
replAbsCB->isChecked();
prefs.activeExtraDbs.clear();
for (unsigned int i = 0; i < actDbsLB->count(); i++) {
QListBoxItem *item = actDbsLB->item(i);
if (item)
prefs.activeExtraDbs.push_back((const char *)item->text().local8Bit());
}
prefs.allExtraDbs.clear();
for (unsigned int i = 0; i < allDbsLB->count(); i++) {
QListBoxItem *item = allDbsLB->item(i);
if (item)
prefs.allExtraDbs.push_back((const char *)item->text().local8Bit());
}
rwSettings(true);
string reason;
maybeOpenDb(reason, true);
emit uiprefsDone();
QDialog::accept();
}
void UIPrefsDialog::showFontDialog()
{
bool ok;
QFont font;
if (prefs.reslistfontfamily.length()) {
font.setFamily(prefs.reslistfontfamily);
font.setPointSize(prefs.reslistfontsize);
}
font = QFontDialog::getFont(&ok, font, this );
if (ok) {
// Check if the default font was set, in which case we
// erase the preference
if (font.family().compare(this->font().family()) ||
font.pointSize() != this->font().pointSize()) {
reslistFontFamily = font.family();
reslistFontSize = font.pointSize();
QString s;
reslistFontPB->setText(reslistFontFamily + "-" +
s.setNum(reslistFontSize));
} else {
reslistFontFamily = "";
reslistFontSize = 0;
}
}
}
void UIPrefsDialog::resetReslistFont()
{
reslistFontFamily = "";
reslistFontSize = 0;
reslistFontPB->setText(this->font().family() + "-" +
QString().setNum(this->font().pointSize()));
}
void UIPrefsDialog::showBrowserDialog()
{
QString s = QFileDialog::getOpenFileName("/usr",
"",
this,
"open file dialog",
"Choose a file" );
if (s)
helpBrowserLE->setText(s);
}
////////////////////////////////////////////
// External / extra search databases setup
// TBD: a way to remove entry from 'all' list (del button? )
void UIPrefsDialog::extraDbTextChanged(const QString &text)
{
if (text.isEmpty()) {
addExtraDbPB->setEnabled(false);
} else {
addExtraDbPB->setEnabled(true);
}
}
/**
* Add the selected extra dbs to the active list
*/
void UIPrefsDialog::addADbPB_clicked()
{
for (unsigned int i = 0; i < allDbsLB->count();i++) {
QListBoxItem *item = allDbsLB->item(i);
if (item && item->isSelected()) {
allDbsLB->setSelected(i, false);
if (!actDbsLB->findItem(item->text(),
Qt::CaseSensitive|Qt::ExactMatch)) {
actDbsLB->insertItem(item->text());
}
}
}
actDbsLB->sort();
}
/**
* Make all extra dbs active
*/
void UIPrefsDialog::addAADbPB_clicked()
{
for (unsigned int i = 0; i < allDbsLB->count();i++) {
allDbsLB->setSelected(i, true);
}
addADbPB_clicked();
}
/**
* Remove the selected entries from the list of active extra search dbs
*/
void UIPrefsDialog::delADbPB_clicked()
{
list<int> rmi;
for (unsigned int i = 0; i < actDbsLB->count(); i++) {
QListBoxItem *item = actDbsLB->item(i);
if (item && item->isSelected()) {
rmi.push_front(i);
}
}
for (list<int>::iterator ii = rmi.begin(); ii != rmi.end(); ii++) {
actDbsLB->removeItem(*ii);
}
}
/**
* Remove all extra search databases from the active list
*/
void UIPrefsDialog::delAADbPB_clicked()
{
for (unsigned int i = 0; i < actDbsLB->count(); i++) {
actDbsLB->setSelected(i, true);
}
delADbPB_clicked();
}
/**
* Add the current content of the extra db line editor to the list of all
* extra dbs. We do a textual comparison to check for duplicates, except for
* the main db for which we check inode numbers.
*/
void UIPrefsDialog::addExtraDbPB_clicked()
{
string dbdir = (const char *)extraDbLE->text().local8Bit();
path_catslash(dbdir);
if (!Rcl::Db::testDbDir(dbdir)) {
QMessageBox::warning(0, "Recoll",
tr("The selected directory does not appear to be a Xapian database"));
return;
}
struct stat st1, st2;
stat(dbdir.c_str(), &st1);
string rcldbdir;
if (rcldb)
rcldbdir = rcldb->getDbDir();
stat(rcldbdir.c_str(), &st2);
path_catslash(rcldbdir);
fprintf(stderr, "rcldbdir: [%s]\n", rcldbdir.c_str());
if (st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino) {
QMessageBox::warning(0, "Recoll",
tr("This is the main/local database!"));
return;
}
if (allDbsLB->findItem(extraDbLE->text(),
Qt::CaseSensitive|Qt::ExactMatch)) {
QMessageBox::warning(0, "Recoll",
tr("The selected directory is already in the database list"));
return;
}
allDbsLB->insertItem(extraDbLE->text());
allDbsLB->sort();
}
void UIPrefsDialog::browseDbPB_clicked()
{
QFileDialog fdia;
bool savedh = fdia.showHiddenFiles();
fdia.setShowHiddenFiles(true);
QString s = QFileDialog::getExistingDirectory("", this, 0,
tr("Select directory holding xapian database (ie: /home/someone/.recoll/xapiandb)"));
fdia.setShowHiddenFiles(savedh);
if (s)
extraDbLE->setText(s);
}