source: smplayer/vendor/current/src/filechooser.cpp@ 175

Last change on this file since 175 was 175, checked in by Silvan Scherrer, 9 years ago

smplayer: update vendor to version 16.4

File size: 2.9 KB
Line 
1/* smplayer, GUI front-end for mplayer.
2 Copyright (C) 2006-2016 Ricardo Villalba <rvm@users.sourceforge.net>
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"
20#include <QToolButton>
21#include <QStyle>
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
32QString FileChooser::last_dir;
33
34FileChooser::FileChooser(QWidget * parent) : LineEditWithIcon(parent)
35{
36 setDialogType(GetFileName);
37 setOptions(0);
38
39 setupButton();
40 button->setCursor( Qt::PointingHandCursor );
41
42 connect(button, SIGNAL(clicked()), this, SLOT(openFileDialog()));
43}
44
45FileChooser::~FileChooser() {
46}
47
48void 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") );
55}
56
57void FileChooser::openFileDialog() {
58 qDebug("FileChooser::openFileDialog");
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
67 QString dir = QFileInfo(text()).absolutePath();
68 if (dir.isEmpty()) dir = last_dir;
69 if (dir.isEmpty()) dir = QDir::homePath();
70
71#ifndef NO_SMPLAYER_SUPPORT
72 result = MyFileDialog::getOpenFileName(
73#else
74 result = QFileDialog::getOpenFileName(
75#endif
76 this, caption(),
77 dir,
78 filter(), &f, opts );
79 if (!result.isEmpty()) last_dir = QFileInfo(result).absolutePath();
80 }
81 else
82 if (dialogType() == GetDirectory) {
83 QFileDialog::Options opts = options();
84 if (opts == 0) opts = QFileDialog::ShowDirsOnly;
85
86 QString dir = text();
87 if (dir.isEmpty()) dir = last_dir;
88 if (dir.isEmpty()) dir = QDir::homePath();
89
90#ifndef NO_SMPLAYER_SUPPORT
91 result = MyFileDialog::getExistingDirectory(
92#else
93 result = QFileDialog::getExistingDirectory(
94#endif
95 this, caption(),
96 dir, opts );
97 if (!result.isEmpty()) last_dir = result;
98 }
99
100 if (!result.isEmpty()) {
101 QString old_file = text();
102 setText(result);
103 if (old_file != result) emit fileChanged(result);
104 }
105}
106
107#include "moc_filechooser.cpp"
Note: See TracBrowser for help on using the repository browser.