Switch to unified view

a/src/qtgui/uiprefs_w.cpp b/src/qtgui/uiprefs_w.cpp
...
...
39
#include <qtooltip.h>
39
#include <qtooltip.h>
40
#include <qwhatsthis.h>
40
#include <qwhatsthis.h>
41
#include <qtextedit.h>
41
#include <qtextedit.h>
42
#include <qlist.h>
42
#include <qlist.h>
43
#include <QTimer>
43
#include <QTimer>
44
#include <QListWidget>
44
45
45
#include "recoll.h"
46
#include "recoll.h"
46
#include "guiutils.h"
47
#include "guiutils.h"
47
#include "rcldb.h"
48
#include "rcldb.h"
48
#include "rclconfig.h"
49
#include "rclconfig.h"
...
...
443
     it != items.end(); it++) {
444
     it != items.end(); it++) {
444
    delete *it;
445
    delete *it;
445
    }
446
    }
446
}
447
}
447
448
449
static bool samedir(const string& dir1, const string& dir2)
450
{
451
    struct stat st1, st2;
452
    if (stat(dir1.c_str(), &st1))
453
  return false;
454
    if (stat(dir2.c_str(), &st2))
455
  return false;
456
    if (st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino) {
457
  return true;
458
    }
459
    return false;
460
}
461
448
/** 
462
/** 
449
 * Browse to add another index.
463
 * Browse to add another index.
450
 * We do a textual comparison to check for duplicates, except for
464
 * We do a textual comparison to check for duplicates, except for
451
 * the main db for which we check inode numbers. 
465
 * the main db for which we check inode numbers. 
452
 */
466
 */
453
void UIPrefsDialog::addExtraDbPB_clicked()
467
void UIPrefsDialog::addExtraDbPB_clicked()
454
{
468
{
455
    QString input = myGetFileName(true, 
469
    QString input = myGetFileName(true, 
470
                tr("Select recoll config directory or "
456
                  tr("Select xapian index directory "
471
                     "xapian index directory "
472
                   "(e.g.: /home/me/.recoll or "
457
                     "(ie: /home/buddy/.recoll/xapiandb)"));
473
                     "/home/me/.recoll/xapiandb)"));
458
474
459
    if (input.isEmpty())
475
    if (input.isEmpty())
460
    return;
476
    return;
461
462
    string dbdir = (const char *)input.toLocal8Bit();
477
    string dbdir = (const char *)input.toLocal8Bit();
478
    if (access(path_cat(dbdir, "recoll.conf").c_str(), 0) == 0) {
479
  // Chosen dir is config dir.
480
  RclConfig conf(&dbdir);
481
  dbdir = conf.getDbDir();
482
  if (dbdir.empty()) {
483
      QMessageBox::warning(
484
      0, "Recoll", tr("The selected directory looks like a Recoll "
485
              "configuration directory but the configuration "
486
              "could not be read"));
487
      return;
488
  }
489
    }
490
463
    LOGDEB(("ExtraDbDial: got: [%s]\n", dbdir.c_str()));
491
    LOGDEB(("ExtraDbDial: got: [%s]\n", dbdir.c_str()));
464
    path_catslash(dbdir);
492
    path_catslash(dbdir);
465
    if (!Rcl::Db::testDbDir(dbdir)) {
493
    if (!Rcl::Db::testDbDir(dbdir)) {
466
    QMessageBox::warning(0, "Recoll", 
494
    QMessageBox::warning(0, "Recoll", 
467
        tr("The selected directory does not appear to be a Xapian index"));
495
        tr("The selected directory does not appear to be a Xapian index"));
468
    return;
496
    return;
469
    }
497
    }
470
    struct stat st1, st2;
498
    if (samedir(dbdir, theconfig->getDbDir())) {
471
    stat(dbdir.c_str(), &st1);
472
    string rcldbdir = theconfig->getDbDir();
473
    stat(rcldbdir.c_str(), &st2);
474
    path_catslash(rcldbdir);
475
476
    if (st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino) {
477
    QMessageBox::warning(0, "Recoll", 
499
    QMessageBox::warning(0, "Recoll", 
478
                 tr("This is the main/local index!"));
500
                 tr("This is the main/local index!"));
479
    return;
501
    return;
480
    }
502
    }
481
503
482
    // For some reason, finditem (which we used to use to detect duplicates 
504
    for (int i = 0; i < idxLV->count(); i++) {
483
    // here) does not work anymore here: qt 4.6.3
505
  QListWidgetItem *item = idxLV->item(i);
484
    QList<QListWidgetItem *>items =
506
  string existingdir = (const char *)item->text().toLocal8Bit();
485
  idxLV->findItems (input, Qt::MatchFixedString|Qt::MatchCaseSensitive);
507
  if (samedir(dbdir, existingdir)) {
486
    if (!items.empty()) {
487
        QMessageBox::warning(0, "Recoll", 
508
        QMessageBox::warning(
488
         tr("The selected directory is already in the index list"));
509
        0, "Recoll", tr("The selected directory is already in the "
510
              "index list"));
489
        return;
511
        return;
490
    }
491
#if 0
492
    string nv = (const char *)input.toLocal8Bit();
493
    QListViewItemIterator it(idxLV);
494
    while (it.current()) {
495
  QCheckListItem *item = (QCheckListItem *)it.current();
496
  string ov = (const char *)item->text().toLocal8Bit();
497
  if (!ov.compare(nv)) {
498
      QMessageBox::warning(0, "Recoll", 
499
       tr("The selected directory is already in the index list"));
500
      return;
501
    }
512
    }
502
  ++it;
503
    }
513
    }
504
#endif
514
505
    QListWidgetItem *item = new QListWidgetItem(input, idxLV);
515
    QListWidgetItem *item = 
516
  new QListWidgetItem(QString::fromLocal8Bit(dbdir.c_str()), idxLV);
506
    item->setCheckState(Qt::Checked);
517
    item->setCheckState(Qt::Checked);
507
    idxLV->sortItems();
518
    idxLV->sortItems();
508
}
519
}