| 1 |
/****************************************************************************** |
| 2 |
This source file is part of the Avogadro project. |
| 3 |
This source code is released under the 3-Clause BSD License, (see "LICENSE"). |
| 4 |
******************************************************************************/ |
| 5 |
|
| 6 |
#ifndef AVOGADRO_QTGUI_FILEBROWSEWIDGET_H |
| 7 |
#define AVOGADRO_QTGUI_FILEBROWSEWIDGET_H |
| 8 |
|
| 9 |
#include "avogadroqtguiexport.h" |
| 10 |
|
| 11 |
#include <QtWidgets/QWidget> |
| 12 |
|
| 13 |
class QFileSystemModel; |
| 14 |
class QLineEdit; |
| 15 |
class QPushButton; |
| 16 |
|
| 17 |
namespace Avogadro { |
| 18 |
namespace QtGui { |
| 19 |
|
| 20 |
class AVOGADROQTGUI_EXPORT FileBrowseWidget : public QWidget |
| 21 |
{ |
| 22 |
Q_OBJECT |
| 23 |
|
| 24 |
public: |
| 25 |
enum Mode |
| 26 |
{ |
| 27 |
ExistingFile = 0, |
| 28 |
ExecutableFile |
| 29 |
}; |
| 30 |
|
| 31 |
explicit FileBrowseWidget(QWidget* theParent = nullptr); |
| 32 |
~FileBrowseWidget() override; |
| 33 |
|
| 34 |
QString fileName() const; |
| 35 |
|
| 36 |
bool validFileName() const { return m_valid; } |
| 37 |
|
| 38 |
QPushButton* browseButton() const; |
| 39 |
QLineEdit* lineEdit() const; |
| 40 |
|
| 41 |
void setMode(Mode m); |
| 42 |
Mode mode() const; |
| 43 |
|
| 44 |
/** |
| 45 |
* @brief Search the environment variable PATH for a file with the specified |
| 46 |
* name. |
| 47 |
* @param exec The name of the file. |
| 48 |
* @return The absolute path to the file on the system, or a null QString if |
| 49 |
* not found. |
| 50 |
*/ |
| 51 |
static QString searchSystemPathForFile(const QString& exec); |
| 52 |
|
| 53 |
/** |
| 54 |
* @brief Search the environment variable PATH for files with the specified |
| 55 |
* names. |
| 56 |
* @param execs The names of the files. |
| 57 |
* @return The absolute paths to the files on the system, or an empty list if |
| 58 |
* not found. |
| 59 |
*/ |
| 60 |
static QStringList searchSystemPathForFiles(const QStringList& execs); |
| 61 |
|
| 62 |
signals: |
| 63 |
void fileNameChanged(const QString& filename); |
| 64 |
|
| 65 |
public slots: |
| 66 |
void setFileName(const QString& fname); |
| 67 |
|
| 68 |
private slots: |
| 69 |
void browse(); |
| 70 |
void testFileName(); |
| 71 |
void fileNameMatch(); |
| 72 |
void fileNameNoMatch(); |
| 73 |
|
| 74 |
private: |
| 75 |
Mode m_mode; |
| 76 |
bool m_valid; |
| 77 |
QFileSystemModel* m_fileSystemModel; |
| 78 |
QPushButton* m_button; |
| 79 |
QLineEdit* m_edit; |
| 80 |
}; |
| 81 |
|
| 82 |
} // namespace QtGui |
| 83 |
} // namespace Avogadro |
| 84 |
|
| 85 |
#endif // AVOGADRO_QTGUI_FILEBROWSEWIDGET_H |