[112] | 1 | /* smplayer, GUI front-end for mplayer.
|
---|
[188] | 2 | Copyright (C) 2006-2017 Ricardo Villalba <rvm@users.sourceforge.net>
|
---|
[112] | 3 |
|
---|
| 4 | This program 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 2 of the License, or
|
---|
| 7 | (at your option) any later version.
|
---|
| 8 |
|
---|
| 9 | This program 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.
|
---|
| 13 |
|
---|
| 14 | You should have received a copy of the GNU General Public License
|
---|
| 15 | along with this program; if not, write to the Free Software
|
---|
| 16 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
| 17 | */
|
---|
| 18 |
|
---|
| 19 | #include "filechooser.h"
|
---|
[124] | 20 | #include <QToolButton>
|
---|
| 21 | #include <QStyle>
|
---|
[112] | 22 |
|
---|
| 23 | //#define NO_SMPLAYER_SUPPORT
|
---|
| 24 |
|
---|
| 25 | #ifndef NO_SMPLAYER_SUPPORT
|
---|
| 26 | #include "filedialog.h"
|
---|
| 27 | #include "images.h"
|
---|
| 28 | #else
|
---|
| 29 | #include <QFileDialog>
|
---|
| 30 | #endif
|
---|
| 31 |
|
---|
[124] | 32 | QString FileChooser::last_dir;
|
---|
| 33 |
|
---|
| 34 | FileChooser::FileChooser(QWidget * parent) : LineEditWithIcon(parent)
|
---|
[112] | 35 | {
|
---|
| 36 | setDialogType(GetFileName);
|
---|
| 37 | setOptions(0);
|
---|
| 38 |
|
---|
[124] | 39 | setupButton();
|
---|
| 40 | button->setCursor( Qt::PointingHandCursor );
|
---|
[112] | 41 |
|
---|
[124] | 42 | connect(button, SIGNAL(clicked()), this, SLOT(openFileDialog()));
|
---|
[112] | 43 | }
|
---|
| 44 |
|
---|
[124] | 45 | FileChooser::~FileChooser() {
|
---|
[112] | 46 | }
|
---|
| 47 |
|
---|
[124] | 48 | void FileChooser::setupButton() {
|
---|
| 49 | #ifdef NO_SMPLAYER_SUPPORT
|
---|
| 50 | setIcon( QPixmap(":/folder_open") );
|
---|
| 51 | #else
|
---|
| 52 | setIcon( Images::icon("folder_open") );
|
---|
| 53 | #endif
|
---|
| 54 | button->setToolTip( tr("Click to select a file or folder") );
|
---|
[112] | 55 | }
|
---|
| 56 |
|
---|
[124] | 57 | void FileChooser::openFileDialog() {
|
---|
| 58 | qDebug("FileChooser::openFileDialog");
|
---|
[112] | 59 |
|
---|
| 60 | QString result;
|
---|
| 61 | QString f;
|
---|
| 62 |
|
---|
| 63 | if (dialogType() == GetFileName) {
|
---|
| 64 | QFileDialog::Options opts = options();
|
---|
| 65 | if (opts == 0) opts = QFileDialog::DontResolveSymlinks;
|
---|
| 66 |
|
---|
[124] | 67 | QString dir = QFileInfo(text()).absolutePath();
|
---|
| 68 | if (dir.isEmpty()) dir = last_dir;
|
---|
| 69 | if (dir.isEmpty()) dir = QDir::homePath();
|
---|
| 70 |
|
---|
[112] | 71 | #ifndef NO_SMPLAYER_SUPPORT
|
---|
| 72 | result = MyFileDialog::getOpenFileName(
|
---|
| 73 | #else
|
---|
| 74 | result = QFileDialog::getOpenFileName(
|
---|
| 75 | #endif
|
---|
| 76 | this, caption(),
|
---|
[124] | 77 | dir,
|
---|
[112] | 78 | filter(), &f, opts );
|
---|
[124] | 79 | if (!result.isEmpty()) last_dir = QFileInfo(result).absolutePath();
|
---|
[112] | 80 | }
|
---|
| 81 | else
|
---|
| 82 | if (dialogType() == GetDirectory) {
|
---|
| 83 | QFileDialog::Options opts = options();
|
---|
| 84 | if (opts == 0) opts = QFileDialog::ShowDirsOnly;
|
---|
| 85 |
|
---|
[124] | 86 | QString dir = text();
|
---|
| 87 | if (dir.isEmpty()) dir = last_dir;
|
---|
| 88 | if (dir.isEmpty()) dir = QDir::homePath();
|
---|
| 89 |
|
---|
[112] | 90 | #ifndef NO_SMPLAYER_SUPPORT
|
---|
| 91 | result = MyFileDialog::getExistingDirectory(
|
---|
| 92 | #else
|
---|
| 93 | result = QFileDialog::getExistingDirectory(
|
---|
| 94 | #endif
|
---|
| 95 | this, caption(),
|
---|
[124] | 96 | dir, opts );
|
---|
| 97 | if (!result.isEmpty()) last_dir = result;
|
---|
[112] | 98 | }
|
---|
| 99 |
|
---|
| 100 | if (!result.isEmpty()) {
|
---|
[124] | 101 | QString old_file = text();
|
---|
| 102 | setText(result);
|
---|
[112] | 103 | if (old_file != result) emit fileChanged(result);
|
---|
| 104 | }
|
---|
| 105 | }
|
---|
| 106 |
|
---|
| 107 | #include "moc_filechooser.cpp"
|
---|