Switch to unified view

a/src/qtgui/uiprefs.ui.h b/src/qtgui/uiprefs.ui.h
...
...
23
** You should not define a constructor or destructor in this file.
23
** You should not define a constructor or destructor in this file.
24
** Instead, write your code in functions called init() and destroy().
24
** Instead, write your code in functions called init() and destroy().
25
** These will automatically be called by the form's constructor and
25
** These will automatically be called by the form's constructor and
26
** destructor.
26
** destructor.
27
*****************************************************************************/
27
*****************************************************************************/
28
#include <sys/stat.h>
29
28
#include <string>
30
#include <string>
29
#include <algorithm>
31
#include <algorithm>
30
#include <list>
32
#include <list>
31
33
32
#include "qfontdialog.h"
34
#include "qfontdialog.h"
...
...
35
#include "qmessagebox.h"
37
#include "qmessagebox.h"
36
38
37
#include "recoll.h"
39
#include "recoll.h"
38
#include "guiutils.h"
40
#include "guiutils.h"
39
#include "rcldb.h"
41
#include "rcldb.h"
42
#include "pathut.h"
40
43
41
void UIPrefsDialog::init()
44
void UIPrefsDialog::init()
42
{
45
{
43
    // Entries per result page spinbox
46
    // Entries per result page spinbox
44
    pageLenSB->setValue(prefs.respagesize);
47
    pageLenSB->setValue(prefs.respagesize);
...
...
133
    prefs.queryStemLang = stemLangCMB->currentText();
136
    prefs.queryStemLang = stemLangCMB->currentText();
134
    }
137
    }
135
    prefs.queryBuildAbstract = buildAbsCB->isChecked();
138
    prefs.queryBuildAbstract = buildAbsCB->isChecked();
136
    prefs.queryReplaceAbstract = buildAbsCB->isChecked() && 
139
    prefs.queryReplaceAbstract = buildAbsCB->isChecked() && 
137
    replAbsCB->isChecked();
140
    replAbsCB->isChecked();
141
142
    prefs.activeExtraDbs.clear();
143
    for (unsigned int i = 0; i < actDbsLB->count(); i++) {
144
  QListBoxItem *item = actDbsLB->item(i);
145
  if (item)
146
      prefs.activeExtraDbs.push_back((const char *)item->text().local8Bit());
147
    }
148
    prefs.allExtraDbs.clear();
149
    for (unsigned int i = 0; i < allDbsLB->count(); i++) {
150
  QListBoxItem *item = allDbsLB->item(i);
151
  if (item)
152
      prefs.allExtraDbs.push_back((const char *)item->text().local8Bit());
153
    }
154
155
138
    rwSettings(true);
156
    rwSettings(true);
139
    string reason;
157
    string reason;
140
    maybeOpenDb(reason, true);
158
    maybeOpenDb(reason, true);
141
    emit uiprefsDone();
159
    emit uiprefsDone();
142
    QDialog::accept();
160
    QDialog::accept();
...
...
188
    if (s) 
206
    if (s) 
189
    helpBrowserLE->setText(s);
207
    helpBrowserLE->setText(s);
190
}
208
}
191
209
192
////////////////////////////////////////////
210
////////////////////////////////////////////
193
// External / extra search databases setup: this should modify to take 
211
// External / extra search databases setup
194
// effect only when Ok is clicked. Currently modifs take effect as soon as
195
// done in the Gui
196
// Also needed: means to remove entry from 'all' list (del button? )
212
// TBD: a way to remove entry from 'all' list (del button? )
197
213
198
void UIPrefsDialog::extraDbTextChanged(const QString &text)
214
void UIPrefsDialog::extraDbTextChanged(const QString &text)
199
{
215
{
200
    if (text.isEmpty()) {
216
    if (text.isEmpty()) {
201
    addExtraDbPB->setEnabled(false);
217
    addExtraDbPB->setEnabled(false);
202
    } else {
218
    } else {
203
    addExtraDbPB->setEnabled(true);
219
    addExtraDbPB->setEnabled(true);
204
    }
220
    }
205
}
221
}
206
222
223
/** 
207
// Add selected dbs to the active list
224
 * Add the selected extra dbs to the active list
225
 */
208
void UIPrefsDialog::addADbPB_clicked()
226
void UIPrefsDialog::addADbPB_clicked()
209
{
227
{
210
    for (unsigned int i = 0; i < allDbsLB->count();i++) {
228
    for (unsigned int i = 0; i < allDbsLB->count();i++) {
211
    QListBoxItem *item = allDbsLB->item(i);
229
    QListBoxItem *item = allDbsLB->item(i);
212
    if (item && item->isSelected()) {
230
    if (item && item->isSelected()) {
213
        allDbsLB->setSelected(i, false);
231
        allDbsLB->setSelected(i, false);
214
      string dbname = (const char*)item->text().local8Bit();
232
      if (!actDbsLB->findItem(item->text(), 
215
      if (std::find(prefs.activeExtraDbs.begin(), prefs.activeExtraDbs.end(), 
233
                  Qt::CaseSensitive|Qt::ExactMatch)) {
216
           dbname) == prefs.activeExtraDbs.end()) {
217
        actDbsLB->insertItem(item->text());
234
        actDbsLB->insertItem(item->text());
218
      prefs.activeExtraDbs.push_back(dbname);
219
        }
235
        }
220
    }
236
    }
221
    }
237
    }
222
    actDbsLB->sort();
238
    actDbsLB->sort();
223
}
239
}
224
240
241
/**
242
 * Make all extra dbs active
243
 */
225
void UIPrefsDialog::addAADbPB_clicked()
244
void UIPrefsDialog::addAADbPB_clicked()
226
{
245
{
227
    for (unsigned int i = 0; i < allDbsLB->count();i++) {
246
    for (unsigned int i = 0; i < allDbsLB->count();i++) {
228
    allDbsLB->setSelected(i, true);
247
    allDbsLB->setSelected(i, true);
229
    }
248
    }
230
    addADbPB_clicked();
249
    addADbPB_clicked();
231
}
250
}
232
251
252
/**
253
 * Remove the selected entries from the list of active extra search dbs
254
 */
233
void UIPrefsDialog::delADbPB_clicked()
255
void UIPrefsDialog::delADbPB_clicked()
234
{
256
{
235
    list<int> rmi;
257
    list<int> rmi;
236
    for (unsigned int i = 0; i < actDbsLB->count(); i++) {
258
    for (unsigned int i = 0; i < actDbsLB->count(); i++) {
237
    QListBoxItem *item = actDbsLB->item(i);
259
    QListBoxItem *item = actDbsLB->item(i);
238
    if (item && item->isSelected()) {
260
    if (item && item->isSelected()) {
239
      string dbname = (const char*)item->text().local8Bit();
240
      list<string>::iterator sit;
241
      if ((sit = ::std::find(prefs.activeExtraDbs.begin(), 
242
              prefs.activeExtraDbs.end(), dbname)) != 
243
       prefs.activeExtraDbs.end()) {
244
      prefs.activeExtraDbs.erase(sit);
245
      }
246
        rmi.push_front(i);
261
        rmi.push_front(i);
247
    }
262
    }
248
    }
263
    }
249
    for (list<int>::iterator ii = rmi.begin(); ii != rmi.end(); ii++) {
264
    for (list<int>::iterator ii = rmi.begin(); ii != rmi.end(); ii++) {
250
    actDbsLB->removeItem(*ii);
265
    actDbsLB->removeItem(*ii);
251
    }
266
    }
252
}
267
}
253
268
269
/**
270
 * Remove all extra search databases from the active list
271
 */
254
void UIPrefsDialog::delAADbPB_clicked()
272
void UIPrefsDialog::delAADbPB_clicked()
255
{
273
{
256
    for (unsigned int i = 0; i < actDbsLB->count(); i++) {
274
    for (unsigned int i = 0; i < actDbsLB->count(); i++) {
257
    actDbsLB->setSelected(i, true);
275
    actDbsLB->setSelected(i, true);
258
    }
276
    }
259
    delADbPB_clicked();
277
    delADbPB_clicked();
260
}
278
}
261
279
280
/** 
281
 * Add the current content of the extra db line editor to the list of all
282
 * extra dbs. We do a textual comparison to check for duplicates, except for
283
 * the main db for which we check inode numbers. 
284
 */
262
void UIPrefsDialog::addExtraDbPB_clicked()
285
void UIPrefsDialog::addExtraDbPB_clicked()
263
{
286
{
264
    string dbdir = (const char *)extraDbLE->text().local8Bit();
287
    string dbdir = (const char *)extraDbLE->text().local8Bit();
288
    path_catslash(dbdir);
265
    if (!Rcl::Db::testDbDir(dbdir)) {
289
    if (!Rcl::Db::testDbDir(dbdir)) {
266
    QMessageBox::warning(0, "Recoll", 
290
    QMessageBox::warning(0, "Recoll", 
267
     tr("The selected directory does not appear to be a Xapian database"));
291
        tr("The selected directory does not appear to be a Xapian database"));
268
    return;
292
    return;
269
    }
293
    }
270
294
    struct stat st1, st2;
271
    if (::std::find(prefs.allExtraDbs.begin(), prefs.allExtraDbs.end(), 
295
    stat(dbdir.c_str(), &st1);
272
          dbdir) != prefs.allExtraDbs.end()) {
296
    string rcldbdir;
297
    if (rcldb) 
298
  rcldbdir = rcldb->getDbDir();
299
    stat(rcldbdir.c_str(), &st2);
300
    path_catslash(rcldbdir);
301
    fprintf(stderr, "rcldbdir: [%s]\n", rcldbdir.c_str());
302
    if (st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino) {
303
  QMessageBox::warning(0, "Recoll", 
304
               tr("This is the main/local database!"));
305
  return;
306
    }
307
    if (allDbsLB->findItem(extraDbLE->text(), 
308
              Qt::CaseSensitive|Qt::ExactMatch)) {
273
    QMessageBox::warning(0, "Recoll", 
309
    QMessageBox::warning(0, "Recoll", 
274
         tr("The selected directory is already in the database list"));
310
         tr("The selected directory is already in the database list"));
275
    return;
311
    return;
276
    }
312
    }
277
    prefs.allExtraDbs.push_back(dbdir);
278
    allDbsLB->insertItem(extraDbLE->text());
313
    allDbsLB->insertItem(extraDbLE->text());
279
    allDbsLB->sort();
314
    allDbsLB->sort();
280
}
315
}
281
316
282
void UIPrefsDialog::browseDbPB_clicked()
317
void UIPrefsDialog::browseDbPB_clicked()