2 * This file is part of jSpeed.
4 * jSpeed is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * jSpeed is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with jSpeed. If not, see <http://www.gnu.org/licenses/>.
19 #include <QtGui/QFileDialog>
20 #include <QtGui/QMessageBox>
21 #include <QtCore/QString>
22 #include <QtCore/QDir>
23 #include <QtCore/QStringList>
24 #include "fileselector.h"
26 FileSelector::FileSelector(QString const& text, QWidget* parent): ButtonSelector(text, parent)
30 bool FileSelector::loadFiles(QString const& dir, QString const& pattern)
34 if(directory.exists() && directory.isReadable())
38 directory.setNameFilters(filters);
39 directory.setFilter(QDir::Files);
40 QStringList files = directory.entryList();
42 for(int i = 0; i < files.size(); i++)
53 bool FileSelector::importFile(QString const& dir,
55 QString const& pattern,
59 QString filename = QFileDialog::getOpenFileName(this, tr("Open file"),
61 name + "(" + pattern + ")");
63 if(filename.isEmpty())
70 int i = filename.lastIndexOf(QDir::separator());
78 basename = filename.mid(i + 1);
81 QString targetFile = dir + basename;
85 if(!targetDir.exists())
87 if(!targetDir.mkpath(dir))
95 if(QFile::exists(targetFile))
97 ok = confirmCopy(basename);
101 QFile::remove(targetFile);
107 if(!QFile::copy(filename, targetFile))
114 *addedFile = basename;
120 selectByValue(basename);
131 bool FileSelector::confirmCopy(QString const& filename)
133 QMessageBox::StandardButton result = QMessageBox::question(this, tr("File exists"),
134 tr("File %1 already exists in directory, overwrite?").arg(filename),
135 QMessageBox::Yes | QMessageBox::No);
137 return (result == QMessageBox::Yes);