Rev 19168 | Rev 21369 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
10242 | subik | 1 | /* |
2 | For general Scribus (>=1.3.2) copyright and licensing information please refer |
||
3 | to the COPYING file provided with the program. Following this notice may exist |
||
4 | a copyright and/or license notice that predates the release of Scribus 1.3.2 |
||
5 | for which a new license (GPL+exception) is in place. |
||
6 | */ |
||
15422 | craig | 7 | |
19180 | craig | 8 | #include <QDebug> |
9 | #include <QStandardPaths> |
||
18154 | jghali | 10 | #include <QListView> |
10242 | subik | 11 | #include <QPushButton> |
19180 | craig | 12 | #include <QStringList> |
15422 | craig | 13 | #include <QUrl> |
10242 | subik | 14 | |
19153 | craig | 15 | #include "filedialogeventcatcher.h" |
10242 | subik | 16 | #include "scfilewidget.h" |
17 | |||
18 | |||
15422 | craig | 19 | ScFileWidget::ScFileWidget(QWidget * parent) : QFileDialog(parent, Qt::Widget) |
10242 | subik | 20 | { |
18771 | jghali | 21 | setOption(QFileDialog::DontUseNativeDialog); |
10242 | subik | 22 | setSizeGripEnabled(false); |
23 | setModal(false); |
||
24 | setViewMode(QFileDialog::List); |
||
25 | setWindowFlags(Qt::Widget); |
||
15422 | craig | 26 | |
27 | #ifdef Q_OS_MAC |
||
28 | QList<QUrl> urls; |
||
29 | QUrl computer(QUrl::fromLocalFile(QLatin1String(""))); |
||
30 | if (!urls.contains(computer)) |
||
31 | urls << computer; |
||
32 | QUrl volumes(QUrl::fromLocalFile("/Volumes")); |
||
33 | if (!urls.contains(volumes)) |
||
34 | urls << volumes; |
||
19180 | craig | 35 | QUrl dt(QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::DesktopLocation))); |
36 | if (!urls.contains(dt)) |
||
37 | urls << dt; |
||
15422 | craig | 38 | setSidebarUrls(urls); |
39 | #endif |
||
40 | |||
19153 | craig | 41 | FileDialogEventCatcher* keyCatcher = new FileDialogEventCatcher(this); |
18154 | jghali | 42 | QList<QListView *> lv = findChildren<QListView *>(); |
43 | QListIterator<QListView *> lvi(lv); |
||
44 | while (lvi.hasNext()) |
||
45 | lvi.next()->installEventFilter(keyCatcher); |
||
46 | connect(keyCatcher, SIGNAL(escapePressed()), this, SLOT(reject())); |
||
19153 | craig | 47 | connect(keyCatcher, SIGNAL(dropLocation(QString)), this, SLOT(locationDropped(QString))); |
19180 | craig | 48 | connect(keyCatcher, SIGNAL(desktopPressed()), this, SLOT(gotoDesktopDirectory())); |
49 | connect(keyCatcher, SIGNAL(homePressed()), this, SLOT(gotoHomeDirectory())); |
||
50 | connect(keyCatcher, SIGNAL(parentPressed()), this, SLOT(gotoParentDirectory())); |
||
51 | connect(keyCatcher, SIGNAL(enterSelectedPressed()), this, SLOT(gotoSelectedDirectory())); |
||
18154 | jghali | 52 | |
10250 | fschmid | 53 | QList<QPushButton *> b = findChildren<QPushButton *>(); |
10245 | cbradney | 54 | QListIterator<QPushButton *> i(b); |
55 | while (i.hasNext()) |
||
56 | i.next()->setVisible(false); |
||
10242 | subik | 57 | setMinimumSize(QSize(480, 310)); |
58 | setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); |
||
59 | } |
||
60 | |||
61 | QString ScFileWidget::selectedFile() |
||
62 | { |
||
63 | QStringList l(selectedFiles()); |
||
64 | if (l.count() == 0) |
||
65 | return QString(); |
||
66 | return l.at(0); |
||
67 | } |
||
14198 | fschmid | 68 | |
18611 | jghali | 69 | /* Hack to make the previews in our file dialogs useable again |
14198 | fschmid | 70 | needed e.g on OpenSuse patched Qt versions */ |
71 | void ScFileWidget::accept() |
||
72 | { |
||
18204 | fschmid | 73 | #ifndef Q_OS_LINUX |
14243 | jghali | 74 | QFileDialog::accept(); |
75 | #endif |
||
14198 | fschmid | 76 | } |
19153 | craig | 77 | |
19168 | craig | 78 | void ScFileWidget::locationDropped(QString fileUrl) |
19153 | craig | 79 | { |
19168 | craig | 80 | QFileInfo fi(fileUrl); |
81 | if (fi.isDir()) |
||
82 | setDirectory(fi.absoluteFilePath()); |
||
83 | else |
||
84 | { |
||
85 | setDirectory(fi.absolutePath()); |
||
86 | selectFile(fi.fileName()); |
||
87 | } |
||
19153 | craig | 88 | } |
19180 | craig | 89 | |
90 | void ScFileWidget::gotoParentDirectory() |
||
91 | { |
||
92 | QDir d(directory()); |
||
93 | d.cdUp(); |
||
94 | setDirectory(d); |
||
95 | } |
||
96 | |||
97 | void ScFileWidget::gotoSelectedDirectory() |
||
98 | { |
||
99 | QStringList s(selectedFiles()); |
||
100 | if (s.count()>0) |
||
101 | { |
||
102 | QFileInfo fi(s.first()); |
||
103 | qDebug()<<s.first()<<fi.absoluteFilePath(); |
||
104 | if (fi.isDir()) |
||
105 | setDirectory(fi.absoluteFilePath()); |
||
106 | } |
||
107 | } |
||
108 | |||
109 | void ScFileWidget::gotoDesktopDirectory() |
||
110 | { |
||
111 | QString dp=QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); |
||
112 | QFileInfo fi(dp); |
||
113 | if (fi.exists()) |
||
114 | setDirectory(dp); |
||
115 | } |
||
116 | |||
117 | void ScFileWidget::gotoHomeDirectory() |
||
118 | { |
||
119 | QString dp=QStandardPaths::writableLocation(QStandardPaths::HomeLocation); |
||
120 | QFileInfo fi(dp); |
||
121 | if (fi.exists()) |
||
122 | setDirectory(dp); |
||
123 | } |
||
124 |