Switch to unified view

a/src/qtgui/uiprefs_w.cpp b/src/qtgui/uiprefs_w.cpp
1
#ifndef lint
1
#ifndef lint
2
static char rcsid[] = "@(#$Id: uiprefs_w.cpp,v 1.13 2006-12-14 13:53:43 dockes Exp $ (C) 2005 J.F.Dockes";
2
static char rcsid[] = "@(#$Id: uiprefs_w.cpp,v 1.14 2007-01-13 15:21:41 dockes Exp $ (C) 2005 J.F.Dockes";
3
#endif
3
#endif
4
/*
4
/*
5
 *   This program is free software; you can redistribute it and/or modify
5
 *   This program is free software; you can redistribute it and/or modify
6
 *   it under the terms of the GNU General Public License as published by
6
 *   it under the terms of the GNU General Public License as published by
7
 *   the Free Software Foundation; either version 2 of the License, or
7
 *   the Free Software Foundation; either version 2 of the License, or
...
...
35
#include <qlineedit.h>
35
#include <qlineedit.h>
36
#include <qcheckbox.h>
36
#include <qcheckbox.h>
37
#include <qcombobox.h>
37
#include <qcombobox.h>
38
#if QT_VERSION < 0x040000
38
#if QT_VERSION < 0x040000
39
#include <qlistbox.h>
39
#include <qlistbox.h>
40
#include <qlistview.h>
40
#include <qfiledialog.h>
41
#include <qfiledialog.h>
41
#else
42
#else
42
#include <q3listbox.h>
43
#include <q3listbox.h>
44
#include <q3listview.h>
43
#include <q3filedialog.h>
45
#include <q3filedialog.h>
46
#include <
44
#define QListBox Q3ListBox
47
#define QListView Q3ListView
45
#define QListBoxItem Q3ListBoxItem
48
#define QCheckListItem Q3CheckListItem
46
#define QFileDialog  Q3FileDialog
49
#define QFileDialog  Q3FileDialog
50
#define QListViewItemIterator Q3ListViewItemIterator
47
#endif
51
#endif
48
#include <qlayout.h>
52
#include <qlayout.h>
49
#include <qtooltip.h>
53
#include <qtooltip.h>
50
#include <qwhatsthis.h>
54
#include <qwhatsthis.h>
51
#include <qtextedit.h>
55
#include <qtextedit.h>
...
...
65
    connect(reslistFontPB, SIGNAL(clicked()), this, SLOT(showFontDialog()));
69
    connect(reslistFontPB, SIGNAL(clicked()), this, SLOT(showFontDialog()));
66
    connect(helpBrowserPB, SIGNAL(clicked()), this, SLOT(showBrowserDialog()));
70
    connect(helpBrowserPB, SIGNAL(clicked()), this, SLOT(showBrowserDialog()));
67
    connect(resetFontPB, SIGNAL(clicked()), this, SLOT(resetReslistFont()));
71
    connect(resetFontPB, SIGNAL(clicked()), this, SLOT(resetReslistFont()));
68
    connect(extraDbLE,SIGNAL(textChanged(const QString&)), this, 
72
    connect(extraDbLE,SIGNAL(textChanged(const QString&)), this, 
69
        SLOT(extraDbTextChanged(const QString&)));
73
        SLOT(extraDbTextChanged(const QString&)));
70
    connect(addAADbPB, SIGNAL(clicked()), this, SLOT(addAADbPB_clicked()));
74
71
    connect(addADbPB, SIGNAL(clicked()), this, SLOT(addADbPB_clicked()));
75
    connect(addExtraDbPB, SIGNAL(clicked()), 
72
    connect(delADbPB, SIGNAL(clicked()), this, SLOT(delADbPB_clicked()));
76
      this, SLOT(addExtraDbPB_clicked()));
73
    connect(delAADbPB, SIGNAL(clicked()), this, SLOT(delAADbPB_clicked()));
77
    connect(delExtraDbPB, SIGNAL(clicked()), 
74
    connect(addExtraDbPB, SIGNAL(clicked()), this, SLOT(addExtraDbPB_clicked()));
78
      this, SLOT(delExtraDbPB_clicked()));
79
    connect(togExtraDbPB, SIGNAL(clicked()), 
80
      this, SLOT(togExtraDbPB_clicked()));
81
    connect(actAllExtraDbPB, SIGNAL(clicked()), 
82
      this, SLOT(actAllExtraDbPB_clicked()));
83
    connect(unacAllExtraDbPB, SIGNAL(clicked()), 
84
      this, SLOT(unacAllExtraDbPB_clicked()));
85
75
    connect(browseDbPB, SIGNAL(clicked()), this, SLOT(browseDbPB_clicked()));
86
    connect(browseDbPB, SIGNAL(clicked()), this, SLOT(browseDbPB_clicked()));
76
    connect(buttonOk, SIGNAL(clicked()), this, SLOT(accept()));
87
    connect(buttonOk, SIGNAL(clicked()), this, SLOT(accept()));
77
    connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
88
    connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
78
    connect(buildAbsCB, SIGNAL(toggled(bool)), 
89
    connect(buildAbsCB, SIGNAL(toggled(bool)), 
79
        replAbsCB, SLOT(setEnabled(bool)));
90
        replAbsCB, SLOT(setEnabled(bool)));
91
80
    setFromPrefs();
92
    setFromPrefs();
81
}
93
}
82
94
83
// Update dialog state from stored prefs
95
// Update dialog state from stored prefs
84
void UIPrefsDialog::setFromPrefs()
96
void UIPrefsDialog::setFromPrefs()
...
...
136
    buildAbsCB->setChecked(prefs.queryBuildAbstract);
148
    buildAbsCB->setChecked(prefs.queryBuildAbstract);
137
    replAbsCB->setEnabled(prefs.queryBuildAbstract);
149
    replAbsCB->setEnabled(prefs.queryBuildAbstract);
138
    replAbsCB->setChecked(prefs.queryReplaceAbstract);
150
    replAbsCB->setChecked(prefs.queryReplaceAbstract);
139
151
140
    // Initialize the extra indexes listboxes
152
    // Initialize the extra indexes listboxes
141
    QStringList ql;
153
    idxLV->clear();
142
    for (list<string>::iterator it = prefs.allExtraDbs.begin(); 
154
    for (list<string>::iterator it = prefs.allExtraDbs.begin(); 
143
     it != prefs.allExtraDbs.end(); it++) {
155
     it != prefs.allExtraDbs.end(); it++) {
144
  ql.append(QString::fromLocal8Bit(it->c_str()));
156
  QCheckListItem *item = 
157
      new QCheckListItem(idxLV, QString::fromLocal8Bit(it->c_str()), 
158
                 QCheckListItem::CheckBox);
159
  if (item) item->setOn(false);
145
    }
160
    }
146
    allDbsLB->clear();
147
    allDbsLB->insertStringList(ql);
148
    ql.clear();
149
    for (list<string>::iterator it = prefs.activeExtraDbs.begin(); 
161
    for (list<string>::iterator it = prefs.activeExtraDbs.begin(); 
150
     it != prefs.activeExtraDbs.end(); it++) {
162
     it != prefs.activeExtraDbs.end(); it++) {
151
  ql.append(QString::fromLocal8Bit(it->c_str()));
163
  QCheckListItem *item;
164
  if ((item = (QCheckListItem *)
165
       idxLV->findItem (QString::fromLocal8Bit(it->c_str()), 0))) {
166
      item->setOn(true);
167
  }
152
    }
168
    }
153
    actDbsLB->clear();
154
    actDbsLB->insertStringList(ql);
155
    ql.clear();
156
}
169
}
157
170
158
void UIPrefsDialog::accept()
171
void UIPrefsDialog::accept()
159
{
172
{
160
    prefs.showicons = useIconsCB->isChecked();
173
    prefs.showicons = useIconsCB->isChecked();
...
...
181
    prefs.startWithSortToolOpen = initStartSortCB->isChecked();
194
    prefs.startWithSortToolOpen = initStartSortCB->isChecked();
182
195
183
    prefs.syntAbsLen = syntlenSB->value();
196
    prefs.syntAbsLen = syntlenSB->value();
184
    prefs.syntAbsCtx = syntctxSB->value();
197
    prefs.syntAbsCtx = syntctxSB->value();
185
198
199
    QListViewItemIterator it(idxLV);
200
    prefs.allExtraDbs.clear();
186
    prefs.activeExtraDbs.clear();
201
    prefs.activeExtraDbs.clear();
187
    for (unsigned int i = 0; i < actDbsLB->count(); i++) {
202
    while (it.current()) {
188
  QListBoxItem *item = actDbsLB->item(i);
203
  QCheckListItem *item = (QCheckListItem *)it.current();
189
  if (item)
190
      prefs.activeExtraDbs.push_back((const char *)item->text().local8Bit());
191
    }
192
    prefs.allExtraDbs.clear();
193
    for (unsigned int i = 0; i < allDbsLB->count(); i++) {
194
  QListBoxItem *item = allDbsLB->item(i);
195
  if (item)
196
        prefs.allExtraDbs.push_back((const char *)item->text().local8Bit());
204
    prefs.allExtraDbs.push_back((const char *)item->text().local8Bit());
205
  if (item->isOn()) {
206
      prefs.activeExtraDbs.push_back((const char *)
207
                     item->text().local8Bit());
208
  }
209
  ++it;
197
    }
210
    }
198
199
211
200
    rwSettings(true);
212
    rwSettings(true);
201
    string reason;
213
    string reason;
202
    maybeOpenDb(reason, true);
214
    maybeOpenDb(reason, true);
203
    emit uiprefsDone();
215
    emit uiprefsDone();
204
    QDialog::accept();
216
    QDialog::accept();
205
}
217
}
218
206
void UIPrefsDialog::reject()
219
void UIPrefsDialog::reject()
207
{
220
{
208
    setFromPrefs();
221
    setFromPrefs();
209
    QDialog::reject();
222
    QDialog::reject();
210
}
223
}
...
...
234
        reslistFontSize = 0;
247
        reslistFontSize = 0;
235
    }
248
    }
236
    }
249
    }
237
}
250
}
238
251
239
240
void UIPrefsDialog::resetReslistFont()
252
void UIPrefsDialog::resetReslistFont()
241
{
253
{
242
    reslistFontFamily = "";
254
    reslistFontFamily = "";
243
    reslistFontSize = 0;
255
    reslistFontSize = 0;
244
    reslistFontPB->setText(this->font().family() + "-" +
256
    reslistFontPB->setText(this->font().family() + "-" +
...
...
270
282
271
////////////////////////////////////////////
283
////////////////////////////////////////////
272
// External / extra search indexes setup
284
// External / extra search indexes setup
273
// TBD: a way to remove entry from 'all' list (del button?)
285
// TBD: a way to remove entry from 'all' list (del button?)
274
286
275
void UIPrefsDialog::extraDbTextChanged(const QString &text)
276
{
277
    if (text.isEmpty()) {
278
  addExtraDbPB->setEnabled(false);
279
    } else {
280
  addExtraDbPB->setEnabled(true);
281
    }
282
}
283
284
/** 
285
 * Add the selected extra dbs to the active list
286
 */
287
void UIPrefsDialog::addADbPB_clicked()
287
void UIPrefsDialog::togExtraDbPB_clicked()
288
{
288
{
289
    for (unsigned int i = 0; i < allDbsLB->count();i++) {
289
    QListViewItemIterator it(idxLV);
290
  QListBoxItem *item = allDbsLB->item(i);
290
    while (it.current()) {
291
  QCheckListItem *item = (QCheckListItem *)it.current();
291
    if (item && item->isSelected()) {
292
    if (item->isSelected()) {
292
      allDbsLB->setSelected(i, false);
293
      item->setOn(!item->isOn());
293
      if (!actDbsLB->findItem(item->text(), 
294
  }
294
#if QT_VERSION < 0x040000
295
  ++it;
295
              Qt::CaseSensitive|Qt::ExactMatch
296
#else
297
              Q3ListBox::CaseSensitive|Q3ListBox::ExactMatch
298
#endif
299
                  )) {
300
      actDbsLB->insertItem(item->text());
301
      }
296
    }
302
  }
297
}
303
    }
304
    actDbsLB->sort();
305
}
306
307
/**
308
 * Make all extra dbs active
309
 */
310
void UIPrefsDialog::addAADbPB_clicked()
298
void UIPrefsDialog::actAllExtraDbPB_clicked()
311
{
299
{
312
    for (unsigned int i = 0; i < allDbsLB->count();i++) {
300
    QListViewItemIterator it(idxLV);
313
  allDbsLB->setSelected(i, true);
301
    while (it.current()) {
302
  QCheckListItem *item = (QCheckListItem *)it.current();
303
  item->setOn(true);
304
  ++it;
314
    }
305
    }
315
    addADbPB_clicked();
316
}
306
}
317
318
/**
319
 * Remove the selected entries from the list of active extra search dbs
320
 */
321
void UIPrefsDialog::delADbPB_clicked()
307
void UIPrefsDialog::unacAllExtraDbPB_clicked()
322
{
308
{
323
    list<int> rmi;
309
    QListViewItemIterator it(idxLV);
324
    for (unsigned int i = 0; i < actDbsLB->count(); i++) {
310
    while (it.current()) {
325
  QListBoxItem *item = actDbsLB->item(i);
311
  QCheckListItem *item = (QCheckListItem *)it.current();
326
  if (item && item->isSelected()) {
312
  item->setOn(false);
327
      rmi.push_front(i);
313
  ++it;
328
  }
329
    }
314
    }
330
    for (list<int>::iterator ii = rmi.begin(); ii != rmi.end(); ii++) {
331
  actDbsLB->removeItem(*ii);
332
    }
333
}
334
335
/**
336
 * Remove all extra search indexes from the active list
337
 */
338
void UIPrefsDialog::delAADbPB_clicked()
339
{
340
    for (unsigned int i = 0; i < actDbsLB->count(); i++) {
341
  actDbsLB->setSelected(i, true);
342
    }
343
    delADbPB_clicked();
344
}
315
}
345
316
346
/** 
317
/** 
347
 * Add the current content of the extra db line editor to the list of all
318
 * Add the current content of the extra db line editor to the list of all
348
 * extra dbs. We do a textual comparison to check for duplicates, except for
319
 * extra dbs. We do a textual comparison to check for duplicates, except for
...
...
368
    if (st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino) {
339
    if (st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino) {
369
    QMessageBox::warning(0, "Recoll", 
340
    QMessageBox::warning(0, "Recoll", 
370
                 tr("This is the main/local index!"));
341
                 tr("This is the main/local index!"));
371
    return;
342
    return;
372
    }
343
    }
373
    if (allDbsLB->findItem(extraDbLE->text(), 
344
    if (idxLV->findItem(extraDbLE->text(), 
374
#if QT_VERSION < 0x040000
345
#if QT_VERSION < 0x040000
375
                Qt::CaseSensitive|Qt::ExactMatch
346
                Qt::CaseSensitive|Qt::ExactMatch
376
#else
347
#else
377
                Q3ListBox::CaseSensitive|Q3ListBox::ExactMatch
348
                Q3ListView::CaseSensitive|Q3ListView::ExactMatch
378
#endif
349
#endif
379
                    )) {
350
                    )) {
380
    QMessageBox::warning(0, "Recoll", 
351
    QMessageBox::warning(0, "Recoll", 
381
         tr("The selected directory is already in the index list"));
352
         tr("The selected directory is already in the index list"));
382
    return;
353
    return;
383
    }
354
    }
384
    allDbsLB->insertItem(extraDbLE->text());
355
    new QCheckListItem(idxLV, extraDbLE->text(), QCheckListItem::CheckBox);
385
    allDbsLB->sort();
356
    idxLV->sort();
357
}
358
359
void UIPrefsDialog::delExtraDbPB_clicked()
360
{
361
    list<QCheckListItem*> dlt;
362
    QListViewItemIterator it(idxLV);
363
    while (it.current()) {
364
  QCheckListItem *item = (QCheckListItem *)it.current();
365
  if (item->isSelected()) {
366
      dlt.push_back(item);
367
  }
368
  ++it;
369
    }
370
    for (list<QCheckListItem*>::iterator it = dlt.begin(); 
371
   it != dlt.end(); it++) 
372
  delete *it;
373
}
374
375
void UIPrefsDialog::extraDbTextChanged(const QString &text)
376
{
377
    if (text.isEmpty()) {
378
  addExtraDbPB->setEnabled(false);
379
    } else {
380
  addExtraDbPB->setEnabled(true);
381
    }
386
}
382
}
387
383
388
void UIPrefsDialog::browseDbPB_clicked()
384
void UIPrefsDialog::browseDbPB_clicked()
389
{
385
{
390
    QFileDialog fdia;
386
    QFileDialog fdia;