23 #include "filepickwidget.h" 25 #include "filefilter.h" 26 #include "ini/inisection.h" 27 #include "ini/inivariable.h" 28 #include "pathfinder/pathfind.h" 29 #include "serverapi/gamefile.h" 30 #include "ui_filepickwidget.h" 31 #include <QFileDialog> 34 DClass<FilePickWidget> :
public Ui::FilePickWidget
39 QSharedPointer< ::FilePickWidget::NeighbourStrategy> neighbourStrategy;
48 d->neighbourStrategy = QSharedPointer<NeighbourStrategy>(
new NeighbourStrategy);
49 d->lblWarning->hide();
50 this->connect(d->lePath, SIGNAL(editingFinished()), SLOT(emitPathChangedIfChanged()));
51 this->connect(d->lePath, SIGNAL(textEdited(QString)), SLOT(trackEdit()));
54 FilePickWidget::~FilePickWidget()
58 void FilePickWidget::browsePath()
60 QString filepath = QFileDialog::getOpenFileName(
this,
61 tr(
"Doomseeker - choose executable file"),
62 d->lePath->text(), FileFilter::executableFilesFilter());
63 if (!filepath.isEmpty())
65 d->lePath->setText(filepath);
70 void FilePickWidget::findPath()
72 QFileInfo currentFile = path();
73 if (currentFile.isFile() && d->file.isSameFile(currentFile.fileName()))
75 QString path = PathFind::findGameFile(d->neighbourStrategy->neighbours(), d->file);
78 d->lePath->setText(path);
85 bool FilePickWidget::isEmpty()
const 87 return path().trimmed().isEmpty();
90 void FilePickWidget::setFile(
const GameFile &file)
93 d->lblTitle->setText(tr(
"Path to %1 executable:").arg(file.
niceName()));
94 d->btnFind->setVisible(canSearch());
97 void FilePickWidget::setNeighbourStrategy(QSharedPointer<NeighbourStrategy> strategy)
99 d->neighbourStrategy = strategy;
102 QString FilePickWidget::path()
const 104 return d->lePath->text().trimmed();
107 bool FilePickWidget::canSearch()
const 109 return !d->file.fileName().isEmpty();
112 void FilePickWidget::emitPathChangedIfChanged()
121 void FilePickWidget::trackEdit()
126 void FilePickWidget::load(
const IniSection &cfg)
128 d->lePath->setText(cfg[d->file.configName()].valueString());
133 cfg[d->file.configName()].
setValue(d->lePath->text());
136 bool FilePickWidget::validate()
140 QFileInfo fileInfo = path();
141 if (!path().isEmpty())
143 if (error.isEmpty() && !fileInfo.exists())
144 error = tr(
"File doesn't exist.");
146 if (error.isEmpty() && fileInfo.isDir() && !fileInfo.isBundle())
147 error = tr(
"This is a directory.");
150 d->lblWarning->setVisible(!error.isEmpty());
151 d->lblWarning->setToolTip(error);
152 return error.isEmpty();
const QString & niceName() const
Descriptive name, ie. "client executable", "server executable", etc.
void setValue(const QString &key, const QVariant &value)
Sets a variable directly. Omits the IniVariable system.
INI section representation.
Game file definition allows to browse this file in configuration box.