1 // QtFileDialog.cxx - Qt5 implementation of FGFileDialog
3 // Written by Rebecca Palmer, started February 2016.
5 // Copyright (C) 2015 Rebecca Palmer <rebecca_palmer@zoho.com>
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #include "QtFileDialog.hxx"
22 #include "QtLauncher.hxx"
23 #include <simgear/debug/logstream.hxx>
26 #include <QFileDialog>
28 #include <QStringList>
30 QtFileDialog::QtFileDialog(FGFileDialog::Usage use) :
36 QtFileDialog::~QtFileDialog() {}
38 void QtFileDialog::exec()
41 static char fakeargv0[] = "fgfs";
42 static char * fakeargv[2] = {fakeargv0, 0};
43 // This does nothing if it has already been run, so the fake argc/argv
44 // are only used if run without launcher
45 flightgear::initApp(fakeargc, fakeargv);
47 // concatenate filter patterns, as Qt uses a single string
48 std::string filter="";
49 for( string_list::const_iterator it = _filterPatterns.begin(); it != _filterPatterns.end();++it ) {
55 QFileDialog dlg(0,QString::fromStdString(_title),QString::fromStdString(_initialPath.str()),QString::fromStdString(filter));
56 if (_usage==USE_SAVE_FILE) {
57 dlg.setAcceptMode(QFileDialog::AcceptSave);
59 if (_usage==USE_CHOOSE_DIR) {
60 dlg.setFileMode(QFileDialog::Directory);
62 if (_usage==USE_OPEN_FILE) {
63 dlg.setFileMode(QFileDialog::ExistingFile);
65 dlg.setLabelText(QFileDialog::Accept,QString::fromStdString(_buttonText));
66 dlg.selectFile(QString::fromStdString(_placeholder));
68 SG_LOG(SG_GENERAL, SG_ALERT, "QtFileDialog: can't show hidden files in Qt");
71 QStringList result = dlg.selectedFiles();
72 if(!(result.isEmpty())){
73 _callback->onFileDialogDone(this, SGPath(result[0].toStdString()));
78 void QtFileDialog::close(){}