23 #include "cfgfilepaths.h" 
   24 #include "configuration/doomseekerconfig.h" 
   25 #include "pathfinder/filesearchpath.h" 
   26 #include "ui_cfgfilepaths.h" 
   27 #include <QFileDialog> 
   29 static const int COL_PATH = 0;
 
   30 static const int COL_RECURSE = 1;
 
   31 static const int NUM_COLS = 2;
 
   33 DClass<CFGFilePaths> : 
public Ui::CFGFilePaths
 
   45         labels << CFGFilePaths::tr(
"Path") << CFGFilePaths::tr(
"Recurse");
 
   46         d->tblFilePaths->setColumnCount(NUM_COLS);
 
   47         d->tblFilePaths->setHorizontalHeaderLabels(labels);
 
   49         QHeaderView *header = d->tblFilePaths->horizontalHeader();
 
   50         header->setSectionResizeMode(COL_PATH, QHeaderView::Stretch);
 
   51         header->setSectionResizeMode(COL_RECURSE, QHeaderView::ResizeToContents);
 
   53         connect(d->btnAddWadPath, SIGNAL(clicked()), 
this, SLOT(btnAddWadPath_Click()));
 
   54         connect(d->btnRemoveWadPath, SIGNAL(clicked()), 
this, SLOT(btnRemoveWadPath_Click()));
 
   55         this->connect(d->tblFilePaths->itemDelegate(),
 
   56                 SIGNAL(closeEditor(QWidget*,QAbstractItemDelegate::EndEditHint)),
 
   57                 SIGNAL(validationRequested()));
 
   58         d->tblFilePaths->connect(d->tblFilePaths,
 
   59                 &TableWidgetReorderable::rowsReordered,
 
   60                 &QTableWidget::resizeRowsToContents);
 
   63 CFGFilePaths::~CFGFilePaths()
 
   69         if (fileSearchPath.isValid())
 
   72         if (!isPathAlreadyDefined(fileSearchPath.path()))
 
   74                 d->tblFilePaths->setSortingEnabled(
false);
 
   75                 int newRow = d->tblFilePaths->rowCount();
 
   76                 d->tblFilePaths->insertRow(newRow);
 
   77                 auto path = 
new QTableWidgetItem(fileSearchPath.path());
 
   78                 path->setData(Qt::ToolTipRole, fileSearchPath.path());
 
   79                 auto recurse = 
new QTableWidgetItem();
 
   80                 recurse->setCheckState(fileSearchPath.isRecursive() ? Qt::Checked : Qt::Unchecked);
 
   81                 recurse->setData(Qt::TextAlignmentRole, Qt::AlignCenter);
 
   83                 d->tblFilePaths->setItem(newRow, COL_PATH, path);
 
   84                 d->tblFilePaths->setItem(newRow, COL_RECURSE, recurse);
 
   85                 d->tblFilePaths->resizeRowsToContents();
 
   86                 d->tblFilePaths->setSortingEnabled(
true);
 
   90 void CFGFilePaths::btnAddWadPath_Click()
 
   92         QString strDir = QFileDialog::getExistingDirectory(
this, tr(
"Doomseeker - Add wad path"));
 
   97 void CFGFilePaths::btnRemoveWadPath_Click()
 
  100         for (
auto *item : d->tblFilePaths->selectedItems())
 
  101                 uniqueRows.insert(item->row());
 
  102         QList<int> rows = uniqueRows.values();
 
  104         std::sort(rows.begin(), rows.end(), [](
int a, 
int b) { 
return b < a; });
 
  106                 d->tblFilePaths->removeRow(row);
 
  112         return QApplication::style()->standardIcon(QStyle::SP_DirOpenIcon);
 
  115 bool CFGFilePaths::isPathAlreadyDefined(
const QString &path)
 
  117         Qt::CaseSensitivity caseSensitivity;
 
  120         caseSensitivity = Qt::CaseInsensitive;
 
  122         caseSensitivity = Qt::CaseSensitive;
 
  125         for (
int i = 0; i < d->tblFilePaths->rowCount(); ++i)
 
  127                 QTableWidgetItem *item = d->tblFilePaths->item(i, COL_PATH);
 
  128                 QString dir = item->text();
 
  130                 if (dir.compare(path, caseSensitivity) == 0)
 
  139         const QList<FileSearchPath> &wadPaths = gConfig.doomseeker.wadPaths;
 
  140         for (
int i = 0; i < wadPaths.count(); ++i)
 
  141                 addPath(wadPaths[i]);
 
  143         d->cbTellMeWhereAreMyWads->setChecked(gConfig.doomseeker.bTellMeWhereAreTheWADsWhenIHoverCursorOverWADSColumn);
 
  144         d->cbCheckTheIntegrityOfWads->setChecked(gConfig.doomseeker.bCheckTheIntegrityOfWads);
 
  149         QList<FileSearchPath> wadPaths;
 
  151         for (
int i = 0; i < d->tblFilePaths->rowCount(); ++i)
 
  153                 QTableWidgetItem *itemPath = d->tblFilePaths->item(i, COL_PATH);
 
  154                 QTableWidgetItem *itemRecurse = d->tblFilePaths->item(i, COL_RECURSE);
 
  156                 fileSearchPath.setRecursive(itemRecurse->checkState() == Qt::Checked);
 
  157                 wadPaths << fileSearchPath;
 
  160         gConfig.doomseeker.wadPaths = wadPaths;
 
  161         gConfig.doomseeker.bTellMeWhereAreTheWADsWhenIHoverCursorOverWADSColumn = d->cbTellMeWhereAreMyWads->isChecked();
 
  162         gConfig.doomseeker.bCheckTheIntegrityOfWads = d->cbCheckTheIntegrityOfWads->isChecked();
 
  167         bool allPathsValid = 
true;
 
  168         for (
int i = 0; i < d->tblFilePaths->rowCount(); ++i)
 
  170                 QTableWidgetItem *itemPath = d->tblFilePaths->item(i, COL_PATH);
 
  172                 QString validationError = validatePath(itemPath->text());
 
  173                 bool valid = validationError.isEmpty();
 
  174                 allPathsValid = allPathsValid && valid;
 
  176                 itemPath->setIcon(valid ? QIcon() : QIcon(
":/icons/exclamation_16.png"));
 
  177                 itemPath->setToolTip(validationError);
 
  182 QString CFGFilePaths::validatePath(
const QString &path)
 const 
  184         if (path.trimmed().isEmpty())
 
  185                 return tr(
"No path specified.");
 
  187         QFileInfo fileInfo(path.trimmed());
 
  188         if (!fileInfo.exists())
 
  189                 return tr(
"Path doesn't exist.");
 
  191         if (!fileInfo.isDir())
 
  192                 return tr(
"Path is not a directory.");