23 #include "cfgfilepaths.h" 24 #include "ui_cfgfilepaths.h" 25 #include "configuration/doomseekerconfig.h" 26 #include "pathfinder/filesearchpath.h" 27 #include <QFileDialog> 28 #include <QStandardItem> 30 const int COL_PATH = 0;
31 const int COL_RECURSE = 1;
33 DClass<CFGFilePaths> :
public Ui::CFGFilePaths
44 QStandardItemModel* model =
new QStandardItemModel(
this);
45 d->lstIwadAndPwadPaths->setModel(model);
48 labels << tr(
"Path") << tr(
"Recurse");
49 model->setHorizontalHeaderLabels(labels);
51 QHeaderView* header = d->lstIwadAndPwadPaths->horizontalHeader();
52 #if QT_VERSION >= 0x050000 53 header->setSectionResizeMode(COL_PATH, QHeaderView::Stretch);
54 header->setSectionResizeMode(COL_RECURSE, QHeaderView::ResizeToContents);
56 header->setResizeMode(COL_PATH, QHeaderView::Stretch);
57 header->setResizeMode(COL_RECURSE, QHeaderView::ResizeToContents);
60 connect(d->btnAddWadPath, SIGNAL( clicked() ),
this, SLOT( btnAddWadPath_Click()) );
61 connect(d->btnRemoveWadPath, SIGNAL( clicked() ),
this, SLOT( btnRemoveWadPath_Click()) );
62 this->connect(d->lstIwadAndPwadPaths->itemDelegate(),
63 SIGNAL(closeEditor(QWidget*, QAbstractItemDelegate::EndEditHint)),
64 SIGNAL(validationRequested()));
67 CFGFilePaths::~CFGFilePaths()
73 if (fileSearchPath.isValid())
78 QStandardItemModel *model =
static_cast<QStandardItemModel*
>(d->lstIwadAndPwadPaths->model());
80 if (!isPathAlreadyDefined(fileSearchPath.path()))
82 QStandardItem *path =
new QStandardItem(fileSearchPath.path());
83 path->setData(fileSearchPath.path(), Qt::ToolTipRole);
84 QStandardItem *recurse =
new QStandardItem();
85 recurse->setCheckable(
true);
86 recurse->setCheckState(fileSearchPath.isRecursive() ? Qt::Checked : Qt::Unchecked);
87 recurse->setData(Qt::AlignCenter, Qt::TextAlignmentRole);
88 QList<QStandardItem*> items;
91 model->appendRow(items);
92 d->lstIwadAndPwadPaths->resizeRowsToContents();
96 void CFGFilePaths::btnAddWadPath_Click()
98 QString strDir = QFileDialog::getExistingDirectory(
this, tr(
"Doomseeker - Add wad path"));
103 void CFGFilePaths::btnRemoveWadPath_Click()
105 QItemSelectionModel* selModel = d->lstIwadAndPwadPaths->selectionModel();
106 QModelIndexList indexList = selModel->selectedRows();
109 QStandardItemModel* model =
static_cast<QStandardItemModel*
>(d->lstIwadAndPwadPaths->model());
110 QList<QStandardItem*> itemList;
111 for (
int i = 0; i < indexList.count(); ++i)
113 itemList << model->itemFromIndex(indexList[i]);
116 for (
int i = 0; i < itemList.count(); ++i)
118 QModelIndex index = model->indexFromItem(itemList[i]);
119 model->removeRow(index.row());
126 return QApplication::style()->standardIcon(QStyle::SP_DirOpenIcon);
129 bool CFGFilePaths::isPathAlreadyDefined(
const QString& path)
131 QStandardItemModel* model =
static_cast<QStandardItemModel*
>(d->lstIwadAndPwadPaths->model());
133 Qt::CaseSensitivity caseSensitivity;
136 caseSensitivity = Qt::CaseInsensitive;
138 caseSensitivity = Qt::CaseSensitive;
141 for(
int i = 0; i < model->rowCount(); ++i)
143 QStandardItem* item = model->item(i);
144 QString dir = item->text();
146 if (dir.compare(path, caseSensitivity) == 0)
157 const QList<FileSearchPath>& wadPaths = gConfig.doomseeker.wadPaths;
158 for (
int i = 0; i < wadPaths.count(); ++i)
160 addPath(wadPaths[i]);
163 d->cbTellMeWhereAreMyWads->setChecked(gConfig.doomseeker.bTellMeWhereAreTheWADsWhenIHoverCursorOverWADSColumn);
168 QList<FileSearchPath> wadPaths;
170 QStandardItemModel* model =
static_cast<QStandardItemModel*
>(d->lstIwadAndPwadPaths->model());
171 for(
int i = 0; i < model->rowCount(); ++i)
173 QStandardItem* itemPath = model->item(i, COL_PATH);
174 QStandardItem* itemRecurse = model->item(i, COL_RECURSE);
176 fileSearchPath.setRecursive(itemRecurse->checkState() == Qt::Checked);
177 wadPaths << fileSearchPath;
180 gConfig.doomseeker.wadPaths = wadPaths;
181 gConfig.doomseeker.bTellMeWhereAreTheWADsWhenIHoverCursorOverWADSColumn = d->cbTellMeWhereAreMyWads->isChecked();
186 bool allPathsValid =
true;
187 QStandardItemModel *model =
static_cast<QStandardItemModel*
>(d->lstIwadAndPwadPaths->model());
188 for (
int i = 0; i < model->rowCount(); ++i)
190 QStandardItem *itemPath = model->item(i, COL_PATH);
192 QString validationError = validatePath(itemPath->text());
193 bool valid = validationError.isEmpty();
194 allPathsValid = allPathsValid && valid;
196 itemPath->setIcon(valid ? QIcon() : QIcon(
":/icons/exclamation_16.png"));
197 itemPath->setToolTip(validationError);
202 QString CFGFilePaths::validatePath(
const QString &path)
const 204 if (path.trimmed().isEmpty())
206 return tr(
"No path specified.");
209 QFileInfo fileInfo(path.trimmed());
210 if (!fileInfo.exists())
212 return tr(
"Path doesn't exist.");
215 if (!fileInfo.isDir())
217 return tr(
"Path is not a directory.");
Validation validate()
Validate settings on this page.
Validation
Result of validate()
void saveSettings()
Reimplement this to write settings to config from widgets.
void validationRequested()
Request that the page should be (re-)validated.
QIcon icon() const
Reimplement this to return a displayable icon for the ConfigPage.
Validation detected no problems.
void readSettings()
Reimplement this to read settings from config into widgets.
Validation detected at least one problem.
Base class for configuration pages.