author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 02 Feb 2010 00:43:10 +0200 | |
changeset 3 | 41300fa6a67c |
parent 0 | 1918ee327afb |
child 4 | 3b1da2848fc7 |
child 7 | f7bc934e204c |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 |
** All rights reserved. |
|
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the Qt3Support module of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
#include "qplatformdefs.h" |
|
43 |
||
44 |
#include "q3filedialog.h" |
|
45 |
||
46 |
#ifndef QT_NO_FILEDIALOG |
|
47 |
||
48 |
#include "private/qapplication_p.h" |
|
49 |
#include "q3buttongroup.h" |
|
50 |
#include "q3header.h" |
|
51 |
#include "q3listview.h" |
|
52 |
#include "qapplication.h" |
|
53 |
#include "qbitmap.h" |
|
54 |
#include "qcheckbox.h" |
|
55 |
#include "q3cleanuphandler.h" |
|
56 |
#include "qcombobox.h" |
|
57 |
#include "q3combobox.h" |
|
58 |
#include "q3cstring.h" |
|
59 |
#include "qcursor.h" |
|
60 |
#include "qdesktopwidget.h" |
|
61 |
#include "q3dragobject.h" |
|
62 |
#include "qevent.h" |
|
63 |
#include "qfile.h" |
|
64 |
#include "qlabel.h" |
|
65 |
#include "qlayout.h" |
|
66 |
#include "qlibrary.h" |
|
67 |
#include "qlineedit.h" |
|
68 |
#include "q3listbox.h" |
|
69 |
#include "qmap.h" |
|
70 |
#include "qmessagebox.h" |
|
71 |
#include "qmime.h" |
|
72 |
#include "qpainter.h" |
|
73 |
#include "qpointer.h" |
|
74 |
#include "q3popupmenu.h" |
|
75 |
#include "q3progressbar.h" |
|
76 |
#include "q3ptrvector.h" |
|
77 |
#include "qpushbutton.h" |
|
78 |
#include "qregexp.h" |
|
79 |
#include "qsplitter.h" |
|
80 |
#include "q3strlist.h" |
|
81 |
#include "qstyle.h" |
|
82 |
#include "qtimer.h" |
|
83 |
#include "qtoolbutton.h" |
|
84 |
#include "qtooltip.h" |
|
85 |
#include "q3widgetstack.h" |
|
86 |
#include "q3urloperator.h" |
|
87 |
#include "q3vbox.h" |
|
88 |
#include "qurlinfo.h" |
|
89 |
||
90 |
#ifdef Q_WS_WIN |
|
91 |
#ifndef QT_NO_THREAD |
|
92 |
# include "qwindowsstyle.h" |
|
93 |
# include "private/qmutexpool_p.h" |
|
94 |
#endif |
|
95 |
#endif // Q_WS_WIN |
|
96 |
||
97 |
#ifndef Q_OS_WINCE |
|
98 |
#include <time.h> |
|
99 |
#else |
|
100 |
#include <shellapi.h> |
|
101 |
#endif // Q_OS_WINCE |
|
102 |
#include <stdlib.h> |
|
103 |
#include <limits.h> |
|
104 |
#include <ctype.h> |
|
105 |
||
106 |
#ifdef Q_WS_MAC |
|
107 |
#include "qmacstyle_mac.h" |
|
108 |
#include "private/qt_mac_p.h" |
|
109 |
#include "private/qunicodetables_p.h" |
|
110 |
#undef check |
|
111 |
#endif |
|
112 |
||
113 |
#if defined(Q_OS_OPENBSD) |
|
114 |
#include <sys/param.h> |
|
115 |
#endif |
|
116 |
||
117 |
QT_BEGIN_NAMESPACE |
|
118 |
||
119 |
/* XPM */ |
|
120 |
static const char * const start_xpm[]={ |
|
121 |
"16 15 8 1", |
|
122 |
"a c #cec6bd", |
|
123 |
"# c #000000", |
|
124 |
"e c #ffff00", |
|
125 |
"b c #999999", |
|
126 |
"f c #cccccc", |
|
127 |
"d c #dcdcdc", |
|
128 |
"c c #ffffff", |
|
129 |
". c None", |
|
130 |
".....######aaaaa", |
|
131 |
"...bb#cccc##aaaa", |
|
132 |
"..bcc#cccc#d#aaa", |
|
133 |
".bcef#cccc#dd#aa", |
|
134 |
".bcfe#cccc#####a", |
|
135 |
".bcef#ccccccccc#", |
|
136 |
"bbbbbbbbbbbbccc#", |
|
137 |
"bccccccccccbbcc#", |
|
138 |
"bcefefefefee#bc#", |
|
139 |
".bcefefefefef#c#", |
|
140 |
".bcfefefefefe#c#", |
|
141 |
"..bcfefefefeeb##", |
|
142 |
"..bbbbbbbbbbbbb#", |
|
143 |
"...#############", |
|
144 |
"................"}; |
|
145 |
||
146 |
/* XPM */ |
|
147 |
static const char * const end_xpm[]={ |
|
148 |
"16 15 9 1", |
|
149 |
"d c #a0a0a0", |
|
150 |
"c c #c3c3c3", |
|
151 |
"# c #cec6bd", |
|
152 |
". c #000000", |
|
153 |
"f c #ffff00", |
|
154 |
"e c #999999", |
|
155 |
"g c #cccccc", |
|
156 |
"b c #ffffff", |
|
157 |
"a c None", |
|
158 |
"......####aaaaaa", |
|
159 |
".bbbb..###aaaaaa", |
|
160 |
".bbbb.c.##aaaaaa", |
|
161 |
".bbbb....ddeeeea", |
|
162 |
".bbbbbbb.bbbbbe.", |
|
163 |
".bbbbbbb.bcfgfe.", |
|
164 |
"eeeeeeeeeeeeefe.", |
|
165 |
"ebbbbbbbbbbeege.", |
|
166 |
"ebfgfgfgfgff.ee.", |
|
167 |
"aebfgfgfgfgfg.e.", |
|
168 |
"aebgfgfgfgfgf.e.", |
|
169 |
"aaebgfgfgfgffe..", |
|
170 |
"aaeeeeeeeeeeeee.", |
|
171 |
"aaa.............", |
|
172 |
"aaaaaaaaaaaaaaaa"}; |
|
173 |
||
174 |
/* XPM */ |
|
175 |
static const char* const open_xpm[]={ |
|
176 |
"16 16 6 1", |
|
177 |
". c None", |
|
178 |
"b c #ffff00", |
|
179 |
"d c #000000", |
|
180 |
"* c #999999", |
|
181 |
"c c #cccccc", |
|
182 |
"a c #ffffff", |
|
183 |
"................", |
|
184 |
"................", |
|
185 |
"...*****........", |
|
186 |
"..*aaaaa*.......", |
|
187 |
".*abcbcba******.", |
|
188 |
".*acbcbcaaaaaa*d", |
|
189 |
".*abcbcbcbcbcb*d", |
|
190 |
"*************b*d", |
|
191 |
"*aaaaaaaaaa**c*d", |
|
192 |
"*abcbcbcbcbbd**d", |
|
193 |
".*abcbcbcbcbcd*d", |
|
194 |
".*acbcbcbcbcbd*d", |
|
195 |
"..*acbcbcbcbb*dd", |
|
196 |
"..*************d", |
|
197 |
"...ddddddddddddd", |
|
198 |
"................"}; |
|
199 |
||
200 |
/* XPM */ |
|
201 |
static const char * const link_dir_xpm[]={ |
|
202 |
"16 16 10 1", |
|
203 |
"h c #808080", |
|
204 |
"g c #a0a0a0", |
|
205 |
"d c #000000", |
|
206 |
"b c #ffff00", |
|
207 |
"f c #303030", |
|
208 |
"# c #999999", |
|
209 |
"a c #cccccc", |
|
210 |
"e c #585858", |
|
211 |
"c c #ffffff", |
|
212 |
". c None", |
|
213 |
"................", |
|
214 |
"................", |
|
215 |
"..#####.........", |
|
216 |
".#ababa#........", |
|
217 |
"#abababa######..", |
|
218 |
"#cccccccccccc#d.", |
|
219 |
"#cbababababab#d.", |
|
220 |
"#cabababababa#d.", |
|
221 |
"#cbababdddddddd.", |
|
222 |
"#cababadccccccd.", |
|
223 |
"#cbababdcececcd.", |
|
224 |
"#cababadcefdfcd.", |
|
225 |
"#cbababdccgdhcd.", |
|
226 |
"#######dccchccd.", |
|
227 |
".dddddddddddddd.", |
|
228 |
"................"}; |
|
229 |
||
230 |
/* XPM */ |
|
231 |
static const char * const link_file_xpm[]={ |
|
232 |
"16 16 10 1", |
|
233 |
"h c #808080", |
|
234 |
"g c #a0a0a0", |
|
235 |
"d c #c3c3c3", |
|
236 |
". c #7f7f7f", |
|
237 |
"c c #000000", |
|
238 |
"b c #bfbfbf", |
|
239 |
"f c #303030", |
|
240 |
"e c #585858", |
|
241 |
"a c #ffffff", |
|
242 |
"# c None", |
|
243 |
"################", |
|
244 |
"..........######", |
|
245 |
".aaaaaaaab.#####", |
|
246 |
".aaaaaaaaba.####", |
|
247 |
".aaaaaaaacccc###", |
|
248 |
".aaaaaaaaaabc###", |
|
249 |
".aaaaaaaaaabc###", |
|
250 |
".aaaaaaaaaadc###", |
|
251 |
".aaaaaaaaaadc###", |
|
252 |
".aaaacccccccc###", |
|
253 |
".aaaacaaaaaac###", |
|
254 |
".aaaacaeaeaac###", |
|
255 |
".aaaacaefcfac###", |
|
256 |
".aaaacaagchac###", |
|
257 |
".ddddcaaahaac###", |
|
258 |
"ccccccccccccc###"}; |
|
259 |
||
260 |
/* XPM */ |
|
261 |
static const char* const file_xpm[]={ |
|
262 |
"16 16 5 1", |
|
263 |
". c #7f7f7f", |
|
264 |
"# c None", |
|
265 |
"c c #000000", |
|
266 |
"b c #bfbfbf", |
|
267 |
"a c #ffffff", |
|
268 |
"################", |
|
269 |
"..........######", |
|
270 |
".aaaaaaaab.#####", |
|
271 |
".aaaaaaaaba.####", |
|
272 |
".aaaaaaaacccc###", |
|
273 |
".aaaaaaaaaabc###", |
|
274 |
".aaaaaaaaaabc###", |
|
275 |
".aaaaaaaaaabc###", |
|
276 |
".aaaaaaaaaabc###", |
|
277 |
".aaaaaaaaaabc###", |
|
278 |
".aaaaaaaaaabc###", |
|
279 |
".aaaaaaaaaabc###", |
|
280 |
".aaaaaaaaaabc###", |
|
281 |
".aaaaaaaaaabc###", |
|
282 |
".bbbbbbbbbbbc###", |
|
283 |
"ccccccccccccc###"}; |
|
284 |
||
285 |
/* XPM */ |
|
286 |
static const char * const closed_xpm[]={ |
|
287 |
"16 16 6 1", |
|
288 |
". c None", |
|
289 |
"b c #ffff00", |
|
290 |
"d c #000000", |
|
291 |
"* c #999999", |
|
292 |
"a c #cccccc", |
|
293 |
"c c #ffffff", |
|
294 |
"................", |
|
295 |
"................", |
|
296 |
"..*****.........", |
|
297 |
".*ababa*........", |
|
298 |
"*abababa******..", |
|
299 |
"*cccccccccccc*d.", |
|
300 |
"*cbababababab*d.", |
|
301 |
"*cabababababa*d.", |
|
302 |
"*cbababababab*d.", |
|
303 |
"*cabababababa*d.", |
|
304 |
"*cbababababab*d.", |
|
305 |
"*cabababababa*d.", |
|
306 |
"*cbababababab*d.", |
|
307 |
"**************d.", |
|
308 |
".dddddddddddddd.", |
|
309 |
"................"}; |
|
310 |
||
311 |
||
312 |
/* XPM */ |
|
313 |
static const char* const cdtoparent_xpm[]={ |
|
314 |
"15 13 3 1", |
|
315 |
". c None", |
|
316 |
"* c #000000", |
|
317 |
"a c #ffff99", |
|
318 |
"..*****........", |
|
319 |
".*aaaaa*.......", |
|
320 |
"***************", |
|
321 |
"*aaaaaaaaaaaaa*", |
|
322 |
"*aaaa*aaaaaaaa*", |
|
323 |
"*aaa***aaaaaaa*", |
|
324 |
"*aa*****aaaaaa*", |
|
325 |
"*aaaa*aaaaaaaa*", |
|
326 |
"*aaaa*aaaaaaaa*", |
|
327 |
"*aaaa******aaa*", |
|
328 |
"*aaaaaaaaaaaaa*", |
|
329 |
"*aaaaaaaaaaaaa*", |
|
330 |
"***************"}; |
|
331 |
||
332 |
||
333 |
/* XPM */ |
|
334 |
static const char* const newfolder_xpm[] = { |
|
335 |
"15 14 4 1", |
|
336 |
" c None", |
|
337 |
". c #000000", |
|
338 |
"+ c #FFFF00", |
|
339 |
"@ c #FFFFFF", |
|
340 |
" . ", |
|
341 |
" ", |
|
342 |
" . ", |
|
343 |
" . . ", |
|
344 |
" .... . . . ", |
|
345 |
" .+@+@. . . ", |
|
346 |
".......... . .", |
|
347 |
".@+@+@+@+@.. ", |
|
348 |
".+@+@+@+@+. . ", |
|
349 |
".@+@+@+@+@. . ", |
|
350 |
".+@+@+@+@+. ", |
|
351 |
".@+@+@+@+@. ", |
|
352 |
".+@+@+@+@+. ", |
|
353 |
"........... "}; |
|
354 |
||
355 |
/* XPM */ |
|
356 |
static const char* const detailedview_xpm[]={ |
|
357 |
"14 11 3 1", |
|
358 |
". c None", |
|
359 |
"* c #000000", |
|
360 |
"a c #000099", |
|
361 |
".****.***.***.", |
|
362 |
"..............", |
|
363 |
"aaaaaaaaaaaaaa", |
|
364 |
"..............", |
|
365 |
".****.***.***.", |
|
366 |
"..............", |
|
367 |
".****.***.***.", |
|
368 |
"..............", |
|
369 |
".****.***.***.", |
|
370 |
"..............", |
|
371 |
".****.***.***."}; |
|
372 |
||
373 |
/* XPM */ |
|
374 |
static const char* const previewinfoview_xpm[]={ |
|
375 |
"13 13 4 1", |
|
376 |
". c #00007f", |
|
377 |
"a c black", |
|
378 |
"# c #cec6bd", |
|
379 |
"b c #000000", |
|
380 |
"..#####aaaaaa", |
|
381 |
".#.#bb#a#####", |
|
382 |
"...####a#bbb#", |
|
383 |
"#######a#####", |
|
384 |
"#######a#bb##", |
|
385 |
"..#####a#####", |
|
386 |
".#.#bb#a#bbb#", |
|
387 |
"...####a#####", |
|
388 |
"#######a#bb##", |
|
389 |
"#######a#####", |
|
390 |
"..#####a#bbb#", |
|
391 |
".#.#bb#a#####", |
|
392 |
"...####aaaaaa"}; |
|
393 |
||
394 |
/* XPM */ |
|
395 |
static const char* const previewcontentsview_xpm[]={ |
|
396 |
"14 13 5 1", |
|
397 |
". c #00007f", |
|
398 |
"a c black", |
|
399 |
"c c #7f007f", |
|
400 |
"# c #cec6bd", |
|
401 |
"b c #000000", |
|
402 |
"..#####aaaaaaa", |
|
403 |
".#.#bb#a#####a", |
|
404 |
"...####a#ccc#a", |
|
405 |
"#######a#ccc#a", |
|
406 |
"#######a#####a", |
|
407 |
"..#####a#bbb#a", |
|
408 |
".#.#bb#a#####a", |
|
409 |
"...####a#bbb#a", |
|
410 |
"#######a#####a", |
|
411 |
"#######a#bbb#a", |
|
412 |
"..#####a#####a", |
|
413 |
".#.#bb#a#####a", |
|
414 |
"...####aaaaaaa"}; |
|
415 |
||
416 |
/* XPM */ |
|
417 |
static const char* const mclistview_xpm[]={ |
|
418 |
"15 11 4 1", |
|
419 |
"* c None", |
|
420 |
"b c #000000", |
|
421 |
". c #000099", |
|
422 |
"a c #ffffff", |
|
423 |
"...*****...****", |
|
424 |
".a.*bbb*.a.*bbb", |
|
425 |
"...*****...****", |
|
426 |
"***************", |
|
427 |
"...*****...****", |
|
428 |
".a.*bbb*.a.*bbb", |
|
429 |
"...*****...****", |
|
430 |
"***************", |
|
431 |
"...*****...****", |
|
432 |
".a.*bbb*.a.*bbb", |
|
433 |
"...*****...****"}; |
|
434 |
||
435 |
/* XPM */ |
|
436 |
static const char * const back_xpm [] = { |
|
437 |
"13 11 3 1", |
|
438 |
"a c #00ffff", |
|
439 |
"# c #000000", |
|
440 |
". c None", |
|
441 |
".....#.......", |
|
442 |
"....##.......", |
|
443 |
"...#a#.......", |
|
444 |
"..#aa########", |
|
445 |
".#aaaaaaaaaa#", |
|
446 |
"#aaaaaaaaaaa#", |
|
447 |
".#aaaaaaaaaa#", |
|
448 |
"..#aa########", |
|
449 |
"...#a#.......", |
|
450 |
"....##.......", |
|
451 |
".....#......."}; |
|
452 |
||
453 |
static QPixmap * openFolderIcon = 0; |
|
454 |
static QPixmap * closedFolderIcon = 0; |
|
455 |
static QPixmap * detailViewIcon = 0; |
|
456 |
static QPixmap * multiColumnListViewIcon = 0; |
|
457 |
static QPixmap * cdToParentIcon = 0; |
|
458 |
static QPixmap * newFolderIcon = 0; |
|
459 |
static QPixmap * fifteenTransparentPixels = 0; |
|
460 |
static QPixmap * symLinkDirIcon = 0; |
|
461 |
static QPixmap * symLinkFileIcon = 0; |
|
462 |
static QPixmap * fileIcon = 0; |
|
463 |
static QPixmap * startCopyIcon = 0; |
|
464 |
static QPixmap * endCopyIcon = 0; |
|
465 |
static QPixmap * previewContentsViewIcon = 0; |
|
466 |
static QPixmap * previewInfoViewIcon = 0; |
|
467 |
static QPixmap *goBackIcon = 0; |
|
468 |
static Q3FileIconProvider * fileIconProvider = 0; |
|
469 |
static int lastWidth = 0; |
|
470 |
static int lastHeight = 0; |
|
471 |
static QString * workingDirectory = 0; |
|
472 |
||
473 |
static bool bShowHiddenFiles = false; |
|
474 |
static int sortFilesBy = (int)QDir::Name; |
|
475 |
static bool sortAscending = true; |
|
476 |
static bool detailViewMode = false; |
|
477 |
||
478 |
static Q3CleanupHandler<QPixmap> qfd_cleanup_pixmap; |
|
479 |
static Q3CleanupHandler<QString> qfd_cleanup_string; |
|
480 |
||
481 |
static QString toRootIfNotExists( const QString &path ) |
|
482 |
{ |
|
483 |
if ( !path.isEmpty() ) |
|
484 |
return path; |
|
485 |
||
486 |
QFileInfoList drives = QDir::drives(); |
|
487 |
Q_ASSERT( !drives.isEmpty() ); |
|
488 |
return drives.first().filePath(); |
|
489 |
} |
|
490 |
||
491 |
static bool isDirectoryMode(int m) |
|
492 |
{ |
|
493 |
return m == Q3FileDialog::Directory || m == Q3FileDialog::DirectoryOnly; |
|
494 |
} |
|
495 |
||
496 |
static void updateLastSize(Q3FileDialog *that) |
|
497 |
{ |
|
498 |
int extWidth = 0; |
|
499 |
int extHeight = 0; |
|
500 |
if (that->extension() && that->extension()->isVisible()) { |
|
501 |
if (that->orientation() == Qt::Vertical) |
|
502 |
extHeight = that->extension()->height(); |
|
503 |
else |
|
504 |
extWidth = that->extension()->width(); |
|
505 |
} |
|
506 |
lastWidth = that->width() - extWidth; |
|
507 |
lastHeight = that->height() - extHeight; |
|
508 |
} |
|
509 |
||
510 |
#if defined(Q_WS_WIN) |
|
511 |
class QWindowsIconProvider : public Q3FileIconProvider |
|
512 |
{ |
|
513 |
public: |
|
514 |
QWindowsIconProvider(QObject *parent=0, const char *name=0); |
|
515 |
~QWindowsIconProvider(); |
|
516 |
||
517 |
const QPixmap * pixmap(const QFileInfo &fi); |
|
518 |
||
519 |
private: |
|
520 |
QPixmap defaultFolder; |
|
521 |
QPixmap defaultFile; |
|
522 |
QPixmap defaultExe; |
|
523 |
QPixmap pix; |
|
524 |
int pixw, pixh; |
|
525 |
QMap< QString, QPixmap > cache; |
|
526 |
||
527 |
}; |
|
528 |
#endif |
|
529 |
||
530 |
static void makeVariables() { |
|
531 |
if (!openFolderIcon) { |
|
532 |
workingDirectory = new QString(toRootIfNotExists( QDir::currentDirPath() )); |
|
533 |
qfd_cleanup_string.add(&workingDirectory); |
|
534 |
||
535 |
openFolderIcon = new QPixmap((const char **)open_xpm); |
|
536 |
qfd_cleanup_pixmap.add(&openFolderIcon); |
|
537 |
symLinkDirIcon = new QPixmap((const char **)link_dir_xpm); |
|
538 |
qfd_cleanup_pixmap.add(&symLinkDirIcon); |
|
539 |
symLinkFileIcon = new QPixmap((const char **)link_file_xpm); |
|
540 |
qfd_cleanup_pixmap.add(&symLinkFileIcon); |
|
541 |
fileIcon = new QPixmap((const char **)file_xpm); |
|
542 |
qfd_cleanup_pixmap.add(&fileIcon); |
|
543 |
closedFolderIcon = new QPixmap((const char **)closed_xpm); |
|
544 |
qfd_cleanup_pixmap.add(&closedFolderIcon); |
|
545 |
detailViewIcon = new QPixmap((const char **)detailedview_xpm); |
|
546 |
qfd_cleanup_pixmap.add(&detailViewIcon); |
|
547 |
multiColumnListViewIcon = new QPixmap((const char **)mclistview_xpm); |
|
548 |
qfd_cleanup_pixmap.add(&multiColumnListViewIcon); |
|
549 |
cdToParentIcon = new QPixmap((const char **)cdtoparent_xpm); |
|
550 |
qfd_cleanup_pixmap.add(&cdToParentIcon); |
|
551 |
newFolderIcon = new QPixmap((const char **)newfolder_xpm); |
|
552 |
qfd_cleanup_pixmap.add(&newFolderIcon); |
|
553 |
previewInfoViewIcon |
|
554 |
= new QPixmap((const char **)previewinfoview_xpm); |
|
555 |
qfd_cleanup_pixmap.add(&previewInfoViewIcon); |
|
556 |
previewContentsViewIcon |
|
557 |
= new QPixmap((const char **)previewcontentsview_xpm); |
|
558 |
qfd_cleanup_pixmap.add(&previewContentsViewIcon); |
|
559 |
startCopyIcon = new QPixmap((const char **)start_xpm); |
|
560 |
qfd_cleanup_pixmap.add(&startCopyIcon); |
|
561 |
endCopyIcon = new QPixmap((const char **)end_xpm); |
|
562 |
qfd_cleanup_pixmap.add(&endCopyIcon); |
|
563 |
goBackIcon = new QPixmap((const char **)back_xpm); |
|
564 |
qfd_cleanup_pixmap.add(&goBackIcon); |
|
565 |
fifteenTransparentPixels = new QPixmap(closedFolderIcon->width(), 1); |
|
566 |
qfd_cleanup_pixmap.add(&fifteenTransparentPixels); |
|
567 |
QBitmap m(fifteenTransparentPixels->width(), 1); |
|
568 |
m.fill(Qt::color0); |
|
569 |
fifteenTransparentPixels->setMask(m); |
|
570 |
bShowHiddenFiles = false; |
|
571 |
sortFilesBy = (int)QDir::Name; |
|
572 |
detailViewMode = false; |
|
573 |
#if defined(Q_WS_WIN) |
|
574 |
if (!fileIconProvider) |
|
575 |
fileIconProvider = new QWindowsIconProvider(qApp); |
|
576 |
#endif |
|
577 |
} |
|
578 |
} |
|
579 |
||
580 |
/****************************************************************** |
|
581 |
* |
|
582 |
* Definitions of view classes |
|
583 |
* |
|
584 |
******************************************************************/ |
|
585 |
||
586 |
class QRenameEdit : public QLineEdit |
|
587 |
{ |
|
588 |
Q_OBJECT |
|
589 |
||
590 |
public: |
|
591 |
QRenameEdit(QWidget *parent); |
|
592 |
||
593 |
protected: |
|
594 |
void keyPressEvent(QKeyEvent *e); |
|
595 |
void focusOutEvent(QFocusEvent *e); |
|
596 |
void emitDoRename(); |
|
597 |
||
598 |
signals: |
|
599 |
void cancelRename(); |
|
600 |
void doRename(); |
|
601 |
||
602 |
private slots: |
|
603 |
void slotReturnPressed(); |
|
604 |
||
605 |
private: |
|
606 |
bool doRenameAlreadyEmitted; |
|
607 |
}; |
|
608 |
||
609 |
QRenameEdit::QRenameEdit(QWidget *parent) |
|
610 |
: QLineEdit(parent, "qt_rename_edit"), doRenameAlreadyEmitted(false) |
|
611 |
{ |
|
612 |
connect(this, SIGNAL(returnPressed()), SLOT(slotReturnPressed())); |
|
613 |
} |
|
614 |
||
615 |
class QFileListBox : public Q3ListBox |
|
616 |
{ |
|
617 |
friend class Q3FileDialog; |
|
618 |
||
619 |
Q_OBJECT |
|
620 |
||
621 |
private: |
|
622 |
QFileListBox(QWidget *parent, Q3FileDialog *d); |
|
623 |
||
624 |
void clear(); |
|
625 |
void show(); |
|
626 |
void startRename(bool check = true); |
|
627 |
void viewportMousePressEvent(QMouseEvent *e); |
|
628 |
void viewportMouseReleaseEvent(QMouseEvent *e); |
|
629 |
void viewportMouseDoubleClickEvent(QMouseEvent *e); |
|
630 |
void viewportMouseMoveEvent(QMouseEvent *e); |
|
631 |
#ifndef QT_NO_DRAGANDDROP |
|
632 |
void viewportDragEnterEvent(QDragEnterEvent *e); |
|
633 |
void viewportDragMoveEvent(QDragMoveEvent *e); |
|
634 |
void viewportDragLeaveEvent(QDragLeaveEvent *e); |
|
635 |
void viewportDropEvent(QDropEvent *e); |
|
636 |
bool acceptDrop(const QPoint &pnt, QWidget *source); |
|
637 |
void setCurrentDropItem(const QPoint &pnt); |
|
638 |
#endif |
|
639 |
void keyPressEvent(QKeyEvent *e); |
|
640 |
||
641 |
private slots: |
|
642 |
void rename(); |
|
643 |
void cancelRename(); |
|
644 |
void doubleClickTimeout(); |
|
645 |
void changeDirDuringDrag(); |
|
646 |
void dragObjDestroyed(); |
|
647 |
void contentsMoved(int, int); |
|
648 |
||
649 |
private: |
|
650 |
QRenameEdit *lined; |
|
651 |
Q3FileDialog *filedialog; |
|
652 |
bool renaming; |
|
653 |
QTimer* renameTimer; |
|
654 |
Q3ListBoxItem *renameItem, *dragItem; |
|
655 |
QPoint pressPos, oldDragPos; |
|
656 |
bool mousePressed; |
|
657 |
int urls; |
|
658 |
QString startDragDir; |
|
659 |
Q3ListBoxItem *currDropItem; |
|
660 |
QTimer *changeDirTimer; |
|
661 |
bool firstMousePressEvent; |
|
662 |
Q3UrlOperator startDragUrl; |
|
663 |
||
664 |
}; |
|
665 |
||
666 |
||
667 |
class Q3FileDialogQFileListView : public Q3ListView |
|
668 |
{ |
|
669 |
Q_OBJECT |
|
670 |
||
671 |
public: |
|
672 |
Q3FileDialogQFileListView(QWidget *parent, Q3FileDialog *d); |
|
673 |
||
674 |
void clear(); |
|
675 |
void startRename(bool check = true); |
|
676 |
void setSorting(int column, bool increasing = true); |
|
677 |
||
678 |
QRenameEdit *lined; |
|
679 |
bool renaming; |
|
680 |
Q3ListViewItem *renameItem; |
|
681 |
||
682 |
private: |
|
683 |
void viewportMousePressEvent(QMouseEvent *e); |
|
684 |
void viewportMouseDoubleClickEvent(QMouseEvent *e); |
|
685 |
void keyPressEvent(QKeyEvent *e); |
|
686 |
void viewportMouseReleaseEvent(QMouseEvent *e); |
|
687 |
void viewportMouseMoveEvent(QMouseEvent *e); |
|
688 |
#ifndef QT_NO_DRAGANDDROP |
|
689 |
void viewportDragEnterEvent(QDragEnterEvent *e); |
|
690 |
void viewportDragMoveEvent(QDragMoveEvent *e); |
|
691 |
void viewportDragLeaveEvent(QDragLeaveEvent *e); |
|
692 |
void viewportDropEvent(QDropEvent *e); |
|
693 |
bool acceptDrop(const QPoint &pnt, QWidget *source); |
|
694 |
void setCurrentDropItem(const QPoint &pnt); |
|
695 |
#endif |
|
696 |
||
697 |
private slots: |
|
698 |
void rename(); |
|
699 |
void cancelRename(); |
|
700 |
void changeSortColumn2(int column); |
|
701 |
void doubleClickTimeout(); |
|
702 |
void changeDirDuringDrag(); |
|
703 |
void dragObjDestroyed(); |
|
704 |
void contentsMoved(int, int); |
|
705 |
||
706 |
private: |
|
707 |
Q3FileDialog *filedialog; |
|
708 |
QTimer* renameTimer; |
|
709 |
QPoint pressPos, oldDragPos; |
|
710 |
bool mousePressed; |
|
711 |
int urls; |
|
712 |
QString startDragDir; |
|
713 |
Q3ListViewItem *currDropItem, *dragItem; |
|
714 |
QTimer *changeDirTimer; |
|
715 |
bool firstMousePressEvent; |
|
716 |
bool ascending; |
|
717 |
int sortcolumn; |
|
718 |
Q3UrlOperator startDragUrl; |
|
719 |
||
720 |
}; |
|
721 |
||
722 |
/**************************************************************************** |
|
723 |
* |
|
724 |
* Classes for copy progress dialog |
|
725 |
* |
|
726 |
****************************************************************************/ |
|
727 |
||
728 |
class QFDProgressAnimation : public QWidget |
|
729 |
{ |
|
730 |
Q_OBJECT |
|
731 |
||
732 |
public: |
|
733 |
QFDProgressAnimation(QWidget *parent); |
|
734 |
void start(); |
|
735 |
||
736 |
private slots: |
|
737 |
void next(); |
|
738 |
||
739 |
protected: |
|
740 |
void paintEvent(QPaintEvent *e); |
|
741 |
||
742 |
private: |
|
743 |
int step; |
|
744 |
QTimer *timer; |
|
745 |
||
746 |
}; |
|
747 |
||
748 |
QFDProgressAnimation::QFDProgressAnimation(QWidget *parent) |
|
749 |
: QWidget(parent, "qt_progressanimation") |
|
750 |
{ |
|
751 |
setFixedSize(300, 50); |
|
752 |
step = -1; |
|
753 |
next(); |
|
754 |
timer = new QTimer(this); |
|
755 |
connect(timer, SIGNAL(timeout()), |
|
756 |
this, SLOT(next())); |
|
757 |
} |
|
758 |
||
759 |
void QFDProgressAnimation::start() |
|
760 |
{ |
|
761 |
timer->start(150, false); |
|
762 |
} |
|
763 |
||
764 |
void QFDProgressAnimation::next() |
|
765 |
{ |
|
766 |
++step; |
|
767 |
if (step > 10) |
|
768 |
step = 0; |
|
769 |
repaint(); |
|
770 |
} |
|
771 |
||
772 |
void QFDProgressAnimation::paintEvent(QPaintEvent *) |
|
773 |
{ |
|
774 |
erase(); |
|
775 |
||
776 |
QPainter p; |
|
777 |
p.begin(this); |
|
778 |
if (step == 0) { |
|
779 |
p.drawPixmap(5, (height() - startCopyIcon->height()) / 2, |
|
780 |
*startCopyIcon); |
|
781 |
p.drawPixmap(width() - 5 - openFolderIcon->width(), |
|
782 |
(height() - openFolderIcon->height()) / 2 , *openFolderIcon); |
|
783 |
} else if (step == 10) { |
|
784 |
p.drawPixmap(5, (height() - openFolderIcon->height()) / 2, |
|
785 |
*openFolderIcon); |
|
786 |
p.drawPixmap(width() - 5 - endCopyIcon->width(), |
|
787 |
(height() - endCopyIcon->height()) / 2 , *endCopyIcon); |
|
788 |
} else { |
|
789 |
p.drawPixmap(5, (height() - openFolderIcon->height()) / 2, |
|
790 |
*openFolderIcon); |
|
791 |
p.drawPixmap(width() - 5 - openFolderIcon->width(), |
|
792 |
(height() - openFolderIcon->height()) / 2 , *openFolderIcon); |
|
793 |
int x = 10 + openFolderIcon->width(); |
|
794 |
int w = width() - 2 * x; |
|
795 |
int s = w / 9; |
|
796 |
p.drawPixmap(x + s * step, (height() - fileIcon->height()) / 2 - fileIcon->height(), |
|
797 |
*fileIcon); |
|
798 |
} |
|
799 |
} |
|
800 |
||
801 |
||
802 |
class QFDProgressDialog : public QDialog |
|
803 |
{ |
|
804 |
Q_OBJECT |
|
805 |
||
806 |
public: |
|
807 |
QFDProgressDialog(QWidget *parent, const QString &fn, int steps); |
|
808 |
||
809 |
void setReadProgress(int p); |
|
810 |
void setWriteProgress(int p); |
|
811 |
void setWriteLabel(const QString &s); |
|
812 |
||
813 |
signals: |
|
814 |
void cancelled(); |
|
815 |
||
816 |
private: |
|
817 |
Q3ProgressBar *readBar; |
|
818 |
Q3ProgressBar *writeBar; |
|
819 |
QLabel *writeLabel; |
|
820 |
QFDProgressAnimation *animation; |
|
821 |
||
822 |
}; |
|
823 |
||
824 |
QFDProgressDialog::QFDProgressDialog(QWidget *parent, const QString &fn, int steps) |
|
825 |
: QDialog(parent, "", true) |
|
826 |
{ |
|
827 |
setWindowTitle(Q3FileDialog::tr("Copy or Move a File")); |
|
828 |
QVBoxLayout *layout = new QVBoxLayout(this); |
|
829 |
layout->setSpacing(5); |
|
830 |
layout->setMargin(5); |
|
831 |
||
832 |
animation = new QFDProgressAnimation(this); |
|
833 |
layout->addWidget(animation); |
|
834 |
||
835 |
layout->addWidget(new QLabel(Q3FileDialog::tr("Read: %1").arg(fn), |
|
836 |
this, "qt_read_lbl")); |
|
837 |
readBar = new Q3ProgressBar(steps, this, "qt_readbar"); |
|
838 |
readBar->reset(); |
|
839 |
readBar->setProgress(0); |
|
840 |
layout->addWidget(readBar); |
|
841 |
writeLabel = new QLabel(Q3FileDialog::tr("Write: %1").arg(QString()), |
|
842 |
this, "qt_write_lbl"); |
|
843 |
layout->addWidget(writeLabel); |
|
844 |
writeBar = new Q3ProgressBar(steps, this, "qt_writebar"); |
|
845 |
writeBar->reset(); |
|
846 |
writeBar->setProgress(0); |
|
847 |
layout->addWidget(writeBar); |
|
848 |
||
849 |
QPushButton *b = new QPushButton(Q3FileDialog::tr("Cancel"), this, |
|
850 |
"qt_cancel_btn"); |
|
851 |
b->setFixedSize(b->sizeHint()); |
|
852 |
layout->addWidget(b); |
|
853 |
connect(b, SIGNAL(clicked()), |
|
854 |
this, SIGNAL(cancelled())); |
|
855 |
||
856 |
animation->start(); |
|
857 |
} |
|
858 |
||
859 |
void QFDProgressDialog::setReadProgress(int p) |
|
860 |
{ |
|
861 |
readBar->setProgress(p); |
|
862 |
} |
|
863 |
||
864 |
void QFDProgressDialog::setWriteProgress(int p) |
|
865 |
{ |
|
866 |
writeBar->setProgress(p); |
|
867 |
} |
|
868 |
||
869 |
void QFDProgressDialog::setWriteLabel(const QString &s) |
|
870 |
{ |
|
871 |
writeLabel->setText(Q3FileDialog::tr("Write: %1").arg(s)); |
|
872 |
} |
|
873 |
||
874 |
/************************************************************************ |
|
875 |
* |
|
876 |
* Private Q3FileDialog members |
|
877 |
* |
|
878 |
************************************************************************/ |
|
879 |
||
880 |
class Q3FileDialogPrivate { |
|
881 |
public: |
|
882 |
~Q3FileDialogPrivate(); |
|
883 |
||
884 |
QStringList history; |
|
885 |
||
886 |
bool geometryDirty; |
|
887 |
Q3ComboBox * paths; |
|
888 |
QComboBox * types; |
|
889 |
QLabel * pathL; |
|
890 |
QLabel * fileL; |
|
891 |
QLabel * typeL; |
|
892 |
||
893 |
QVBoxLayout * topLevelLayout; |
|
894 |
QHBoxLayout *buttonLayout, *leftLayout, *rightLayout; |
|
895 |
Q3PtrList<QHBoxLayout> extraWidgetsLayouts; |
|
896 |
Q3PtrList<QLabel> extraLabels; |
|
897 |
Q3PtrList<QWidget> extraWidgets; |
|
898 |
Q3PtrList<QWidget> extraButtons; |
|
899 |
Q3PtrList<QAbstractButton> toolButtons; |
|
900 |
||
901 |
Q3WidgetStack * stack; |
|
902 |
||
903 |
QToolButton * cdToParent, *newFolder, * detailView, * mcView, |
|
904 |
*previewInfo, *previewContents, *goBack; |
|
905 |
Q3ButtonGroup * modeButtons; |
|
906 |
||
907 |
QString currentFileName; |
|
908 |
Q3ListViewItem *last; |
|
909 |
||
910 |
Q3ListBoxItem *lastEFSelected; |
|
911 |
||
912 |
struct File: public Q3ListViewItem { |
|
913 |
File(Q3FileDialogPrivate * dlgp, |
|
914 |
const QUrlInfo * fi, Q3ListViewItem * parent) |
|
915 |
: Q3ListViewItem(parent, dlgp->last), info(*fi), d(dlgp), i(0), hasMimePixmap(false) |
|
916 |
{ setup(); dlgp->last = this; } |
|
917 |
File(Q3FileDialogPrivate * dlgp, |
|
918 |
const QUrlInfo * fi, Q3ListView * parent) |
|
919 |
: Q3ListViewItem(parent, dlgp->last), info(*fi), d(dlgp), i(0), hasMimePixmap(false) |
|
920 |
{ setup(); dlgp->last = this; } |
|
921 |
File(Q3FileDialogPrivate * dlgp, |
|
922 |
const QUrlInfo * fi, Q3ListView * parent, Q3ListViewItem * after) |
|
923 |
: Q3ListViewItem(parent, after), info(*fi), d(dlgp), i(0), hasMimePixmap(false) |
|
924 |
{ setup(); if (!nextSibling()) dlgp->last = this; } |
|
925 |
~File(); |
|
926 |
||
927 |
QString text(int column) const; |
|
928 |
const QPixmap * pixmap(int) const; |
|
929 |
||
930 |
QUrlInfo info; |
|
931 |
Q3FileDialogPrivate * d; |
|
932 |
Q3ListBoxItem *i; |
|
933 |
bool hasMimePixmap; |
|
934 |
}; |
|
935 |
||
936 |
class MCItem: public Q3ListBoxItem { |
|
937 |
public: |
|
938 |
MCItem(Q3ListBox *, Q3ListViewItem * item); |
|
939 |
MCItem(Q3ListBox *, Q3ListViewItem * item, Q3ListBoxItem *after); |
|
940 |
QString text() const; |
|
941 |
const QPixmap *pixmap() const; |
|
942 |
int height(const Q3ListBox *) const; |
|
943 |
int width(const Q3ListBox *) const; |
|
944 |
void paint(QPainter *); |
|
945 |
Q3ListViewItem * i; |
|
946 |
}; |
|
947 |
||
948 |
class UrlInfoList : public Q3PtrList<QUrlInfo> { |
|
949 |
public: |
|
950 |
UrlInfoList() { setAutoDelete(true); } |
|
951 |
int compareItems(Q3PtrCollection::Item n1, Q3PtrCollection::Item n2) { |
|
952 |
if (!n1 || !n2) |
|
953 |
return 0; |
|
954 |
||
955 |
QUrlInfo *i1 = (QUrlInfo *)n1; |
|
956 |
QUrlInfo *i2 = (QUrlInfo *)n2; |
|
957 |
||
958 |
if (i1->isDir() && !i2->isDir()) |
|
959 |
return -1; |
|
960 |
if (!i1->isDir() && i2->isDir()) |
|
961 |
return 1; |
|
962 |
||
963 |
if (i1->name() == QLatin1String("..")) |
|
964 |
return -1; |
|
965 |
if (i2->name() == QLatin1String("..")) |
|
966 |
return 1; |
|
967 |
||
968 |
if (sortFilesBy == QDir::Name) { |
|
969 |
#if defined(Q_OS_WIN32) |
|
970 |
QString name1 = i1->name().lower(); |
|
971 |
QString name2 = i2->name().lower(); |
|
972 |
return name1.localeAwareCompare( name2 ); |
|
973 |
#else |
|
974 |
QString name1 = i1->name(); |
|
975 |
QString name2 = i2->name(); |
|
976 |
return name1.localeAwareCompare( name2 ); |
|
977 |
#endif |
|
978 |
} |
|
979 |
if (QUrlInfo::equal(*i1, *i2, sortFilesBy)) |
|
980 |
return 0; |
|
981 |
else if (QUrlInfo::greaterThan(*i1, *i2, sortFilesBy)) |
|
982 |
return 1; |
|
983 |
else if (QUrlInfo::lessThan(*i1, *i2, sortFilesBy)) |
|
984 |
return -1; |
|
985 |
// can't happen... |
|
986 |
return 0; |
|
987 |
} |
|
988 |
QUrlInfo *operator[](int i) { |
|
989 |
return at(i); |
|
990 |
} |
|
991 |
}; |
|
992 |
||
993 |
UrlInfoList sortedList; |
|
994 |
Q3PtrList<File> pendingItems; |
|
995 |
||
996 |
QFileListBox * moreFiles; |
|
997 |
||
998 |
Q3FileDialog::Mode mode; |
|
999 |
||
1000 |
QString rw; |
|
1001 |
QString ro; |
|
1002 |
QString wo; |
|
1003 |
QString inaccessible; |
|
1004 |
||
1005 |
QString symLinkToFile; |
|
1006 |
QString file; |
|
1007 |
QString symLinkToDir; |
|
1008 |
QString dir; |
|
1009 |
QString symLinkToSpecial; |
|
1010 |
QString special; |
|
1011 |
Q3WidgetStack *preview; |
|
1012 |
bool infoPreview, contentsPreview; |
|
1013 |
QSplitter *splitter; |
|
1014 |
Q3UrlOperator url, oldUrl; |
|
1015 |
QWidget *infoPreviewWidget, *contentsPreviewWidget; |
|
1016 |
Q3FilePreview *infoPreviewer, *contentsPreviewer; |
|
1017 |
bool hadDotDot; |
|
1018 |
||
1019 |
bool ignoreNextKeyPress; |
|
1020 |
// ignores the next refresh operation in case the user forced a selection |
|
1021 |
bool ignoreNextRefresh; |
|
1022 |
QFDProgressDialog *progressDia; |
|
1023 |
bool checkForFilter; |
|
1024 |
bool ignoreStop; |
|
1025 |
||
1026 |
QTimer *mimeTypeTimer; |
|
1027 |
const Q3NetworkOperation *currListChildren; |
|
1028 |
||
1029 |
// this is similar to QUrl::encode but does encode "*" and |
|
1030 |
// doesn't encode whitespaces |
|
1031 |
static QString encodeFileName(const QString& fName) { |
|
1032 |
||
1033 |
QString newStr; |
|
1034 |
Q3CString cName = fName.utf8(); |
|
1035 |
const Q3CString sChars( |
|
1036 |
#ifdef Q_WS_WIN |
|
1037 |
"#%" |
|
1038 |
#else |
|
1039 |
"<>#@\"&%$:,;?={}|^~[]\'`\\*" |
|
1040 |
#endif |
|
1041 |
); |
|
1042 |
||
1043 |
int len = cName.length(); |
|
1044 |
if (!len) |
|
1045 |
return QString(); |
|
1046 |
for (int i = 0; i < len ;++i) { |
|
1047 |
uchar inCh = (uchar)cName[i]; |
|
1048 |
if (inCh >= 128 || sChars.contains(inCh)) |
|
1049 |
{ |
|
1050 |
newStr += QLatin1Char('%'); |
|
1051 |
ushort c = inCh / 16; |
|
1052 |
c += c > 9 ? 'A' - 10 : '0'; |
|
1053 |
newStr += QLatin1Char((char)c); |
|
1054 |
c = inCh % 16; |
|
1055 |
c += c > 9 ? 'A' - 10 : '0'; |
|
1056 |
newStr += QLatin1Char((char)c); |
|
1057 |
} else { |
|
1058 |
newStr += QLatin1Char((char)inCh); |
|
1059 |
} |
|
1060 |
} |
|
1061 |
return newStr; |
|
1062 |
} |
|
1063 |
||
1064 |
static bool fileExists(const Q3UrlOperator &url, const QString& name) |
|
1065 |
{ |
|
1066 |
Q3Url u(url, Q3FileDialogPrivate::encodeFileName(name)); |
|
1067 |
if (u.isLocalFile()) { |
|
1068 |
QFileInfo f(u.path()); |
|
1069 |
return f.exists(); |
|
1070 |
} else { |
|
1071 |
Q3NetworkProtocol *p = Q3NetworkProtocol::getNetworkProtocol(url.protocol()); |
|
1072 |
if (p && (p->supportedOperations()&Q3NetworkProtocol::OpListChildren)) { |
|
1073 |
QUrlInfo ui(url.info(name.isEmpty() ? QString::fromLatin1(".") : name)); |
|
1074 |
return ui.isValid(); |
|
1075 |
} |
|
1076 |
} |
|
1077 |
return true; |
|
1078 |
} |
|
1079 |
||
1080 |
#ifndef Q_NO_CURSOR |
|
1081 |
bool cursorOverride; // Remember if the cursor was overridden or not. |
|
1082 |
#endif |
|
1083 |
}; |
|
1084 |
||
1085 |
Q3FileDialogPrivate::~Q3FileDialogPrivate() |
|
1086 |
{ |
|
1087 |
delete modeButtons; |
|
1088 |
} |
|
1089 |
||
1090 |
||
1091 |
||
1092 |
/************************************************************************ |
|
1093 |
* |
|
1094 |
* Internal class QRenameEdit |
|
1095 |
* |
|
1096 |
************************************************************************/ |
|
1097 |
||
1098 |
void QRenameEdit::keyPressEvent(QKeyEvent *e) |
|
1099 |
{ |
|
1100 |
if (e->key() == Qt::Key_Escape) |
|
1101 |
emit cancelRename(); |
|
1102 |
else |
|
1103 |
QLineEdit::keyPressEvent(e); |
|
1104 |
e->accept(); |
|
1105 |
} |
|
1106 |
||
1107 |
void QRenameEdit::focusOutEvent(QFocusEvent *) |
|
1108 |
{ |
|
1109 |
if (!doRenameAlreadyEmitted) |
|
1110 |
emitDoRename(); |
|
1111 |
} |
|
1112 |
||
1113 |
void QRenameEdit::slotReturnPressed() |
|
1114 |
{ |
|
1115 |
emitDoRename(); |
|
1116 |
} |
|
1117 |
||
1118 |
void QRenameEdit::emitDoRename() |
|
1119 |
{ |
|
1120 |
doRenameAlreadyEmitted = true; |
|
1121 |
emit doRename(); |
|
1122 |
doRenameAlreadyEmitted = false; |
|
1123 |
} |
|
1124 |
||
1125 |
/************************************************************************ |
|
1126 |
* |
|
1127 |
* Internal class QFileListBox |
|
1128 |
* |
|
1129 |
************************************************************************/ |
|
1130 |
||
1131 |
QFileListBox::QFileListBox(QWidget *parent, Q3FileDialog *dlg) |
|
1132 |
: Q3ListBox(parent, "filelistbox"), filedialog(dlg), |
|
1133 |
renaming(false), renameItem(0), mousePressed(false), |
|
1134 |
firstMousePressEvent(true) |
|
1135 |
{ |
|
1136 |
changeDirTimer = new QTimer(this); |
|
1137 |
Q3VBox *box = new Q3VBox(viewport(), "qt_vbox"); |
|
1138 |
box->setFrameStyle(QFrame::Box | QFrame::Plain); |
|
1139 |
lined = new QRenameEdit(box); |
|
1140 |
lined->setFixedHeight(lined->sizeHint().height()); |
|
1141 |
box->hide(); |
|
1142 |
box->setBackgroundRole(QPalette::Base); |
|
1143 |
renameTimer = new QTimer(this); |
|
1144 |
connect(lined, SIGNAL(doRename()), |
|
1145 |
this, SLOT (rename())); |
|
1146 |
connect(lined, SIGNAL(cancelRename()), |
|
1147 |
this, SLOT(cancelRename())); |
|
1148 |
connect(renameTimer, SIGNAL(timeout()), |
|
1149 |
this, SLOT(doubleClickTimeout())); |
|
1150 |
connect(changeDirTimer, SIGNAL(timeout()), |
|
1151 |
this, SLOT(changeDirDuringDrag())); |
|
1152 |
connect(this, SIGNAL(contentsMoving(int,int)), |
|
1153 |
this, SLOT(contentsMoved(int,int))); |
|
1154 |
viewport()->setAcceptDrops(true); |
|
1155 |
dragItem = 0; |
|
1156 |
} |
|
1157 |
||
1158 |
void QFileListBox::show() |
|
1159 |
{ |
|
1160 |
setBackgroundRole(QPalette::Base); |
|
1161 |
viewport()->setBackgroundRole(QPalette::Base); |
|
1162 |
Q3ListBox::show(); |
|
1163 |
} |
|
1164 |
||
1165 |
void QFileListBox::keyPressEvent(QKeyEvent *e) |
|
1166 |
{ |
|
1167 |
if ((e->key() == Qt::Key_Enter || |
|
1168 |
e->key() == Qt::Key_Return) && |
|
1169 |
renaming) |
|
1170 |
return; |
|
1171 |
||
1172 |
QString keyPressed = ((QKeyEvent *)e)->text().toLower(); |
|
1173 |
QChar keyChar = keyPressed[0]; |
|
1174 |
if (keyChar.isLetterOrNumber()) { |
|
1175 |
Q3ListBoxItem * i = 0; |
|
1176 |
if (currentItem() != -1) |
|
1177 |
i = item(currentItem()); |
|
1178 |
else |
|
1179 |
i = firstItem(); |
|
1180 |
if (i->next()) |
|
1181 |
i = i->next(); |
|
1182 |
else |
|
1183 |
i = firstItem(); |
|
1184 |
while (i != item(currentItem())) { |
|
1185 |
QString it = text(index(i)); |
|
1186 |
if (it[0].toLower() == keyChar) { |
|
1187 |
clearSelection(); |
|
1188 |
setCurrentItem(i); |
|
1189 |
} else { |
|
1190 |
if (i->next()) |
|
1191 |
i = i->next(); |
|
1192 |
else { |
|
1193 |
if (!item(currentItem())) { |
|
1194 |
clearSelection(); |
|
1195 |
break; |
|
1196 |
} |
|
1197 |
i = firstItem(); |
|
1198 |
} |
|
1199 |
} |
|
1200 |
} |
|
1201 |
} |
|
1202 |
cancelRename(); |
|
1203 |
Q3ListBox::keyPressEvent(e); |
|
1204 |
} |
|
1205 |
||
1206 |
void QFileListBox::viewportMousePressEvent(QMouseEvent *e) |
|
1207 |
{ |
|
1208 |
pressPos = e->pos(); |
|
1209 |
mousePressed = false; |
|
1210 |
||
1211 |
bool didRename = renaming; |
|
1212 |
||
1213 |
cancelRename(); |
|
1214 |
if (!hasFocus() && !viewport()->hasFocus()) |
|
1215 |
setFocus(); |
|
1216 |
||
1217 |
if (e->button() != Qt::LeftButton) { |
|
1218 |
Q3ListBox::viewportMousePressEvent(e); |
|
1219 |
firstMousePressEvent = false; |
|
1220 |
return; |
|
1221 |
} |
|
1222 |
||
1223 |
int i = currentItem(); |
|
1224 |
bool wasSelected = false; |
|
1225 |
if (i != -1) |
|
1226 |
wasSelected = item(i)->isSelected(); |
|
1227 |
Q3ListBox::mousePressEvent(e); |
|
1228 |
||
1229 |
Q3FileDialogPrivate::MCItem *i1 = (Q3FileDialogPrivate::MCItem*)item(currentItem()); |
|
1230 |
if (i1) |
|
1231 |
mousePressed = (!((Q3FileDialogPrivate::File*)i1->i)->info.isDir()) |
|
1232 |
|| (filedialog->mode() == Q3FileDialog::Directory) || (filedialog->mode() == Q3FileDialog::DirectoryOnly); |
|
1233 |
||
1234 |
if (itemAt(e->pos()) != item(i)) { |
|
1235 |
firstMousePressEvent = false; |
|
1236 |
return; |
|
1237 |
} |
|
1238 |
||
1239 |
if (!firstMousePressEvent && !didRename && i == currentItem() && currentItem() != -1 && |
|
1240 |
wasSelected && QUrlInfo(filedialog->d->url.info(QString(QLatin1Char('.')))).isWritable() && item(currentItem())->text() != QLatin1String("..")) { |
|
1241 |
renameTimer->start(QApplication::doubleClickInterval(), true); |
|
1242 |
renameItem = item(i); |
|
1243 |
} |
|
1244 |
||
1245 |
firstMousePressEvent = false; |
|
1246 |
} |
|
1247 |
||
1248 |
void QFileListBox::viewportMouseReleaseEvent(QMouseEvent *e) |
|
1249 |
{ |
|
1250 |
dragItem = 0; |
|
1251 |
Q3ListBox::viewportMouseReleaseEvent(e); |
|
1252 |
mousePressed = false; |
|
1253 |
} |
|
1254 |
||
1255 |
void QFileListBox::viewportMouseDoubleClickEvent(QMouseEvent *e) |
|
1256 |
{ |
|
1257 |
renameTimer->stop(); |
|
1258 |
Q3ListBox::viewportMouseDoubleClickEvent(e); |
|
1259 |
} |
|
1260 |
||
1261 |
void QFileListBox::viewportMouseMoveEvent(QMouseEvent *e) |
|
1262 |
{ |
|
1263 |
if (!dragItem) |
|
1264 |
dragItem = itemAt(e->pos()); |
|
1265 |
renameTimer->stop(); |
|
1266 |
#ifndef QT_NO_DRAGANDDROP |
|
1267 |
if ( (pressPos - e->pos()).manhattanLength() > QApplication::startDragDistance() && mousePressed) { |
|
1268 |
Q3ListBoxItem *item = dragItem; |
|
1269 |
dragItem = 0; |
|
1270 |
if (item) { |
|
1271 |
if (!itemRect(item).contains(e->pos())) |
|
1272 |
return; |
|
1273 |
Q3UriDrag* drag = new Q3UriDrag(viewport()); |
|
1274 |
QStringList files; |
|
1275 |
if (filedialog->mode() == Q3FileDialog::ExistingFiles) |
|
1276 |
files = filedialog->selectedFiles(); |
|
1277 |
else |
|
1278 |
files = QStringList(filedialog->selectedFile()); |
|
1279 |
drag->setFileNames(files); |
|
1280 |
||
1281 |
if (lined->parentWidget()->isVisible()) |
|
1282 |
cancelRename(); |
|
1283 |
||
1284 |
connect(drag, SIGNAL(destroyed()), |
|
1285 |
this, SLOT(dragObjDestroyed())); |
|
1286 |
drag->drag(); |
|
1287 |
||
1288 |
mousePressed = false; |
|
1289 |
} |
|
1290 |
} else |
|
1291 |
#endif |
|
1292 |
{ |
|
1293 |
Q3ListBox::viewportMouseMoveEvent(e); |
|
1294 |
} |
|
1295 |
||
1296 |
} |
|
1297 |
||
1298 |
void QFileListBox::dragObjDestroyed() |
|
1299 |
{ |
|
1300 |
#ifndef QT_NO_DRAGANDDROP |
|
1301 |
//####### |
|
1302 |
//filedialog->rereadDir(); |
|
1303 |
#endif |
|
1304 |
} |
|
1305 |
||
1306 |
#ifndef QT_NO_DRAGANDDROP |
|
1307 |
void QFileListBox::viewportDragEnterEvent(QDragEnterEvent *e) |
|
1308 |
{ |
|
1309 |
startDragUrl = filedialog->d->url; |
|
1310 |
startDragDir = filedialog->dirPath(); |
|
1311 |
currDropItem = 0; |
|
1312 |
||
1313 |
if (!Q3UriDrag::canDecode(e)) { |
|
1314 |
e->ignore(); |
|
1315 |
return; |
|
1316 |
} |
|
1317 |
||
1318 |
QStringList l; |
|
1319 |
Q3UriDrag::decodeLocalFiles(e, l); |
|
1320 |
urls = (int)l.count(); |
|
1321 |
||
1322 |
if (acceptDrop(e->pos(), e->source())) { |
|
1323 |
e->accept(); |
|
1324 |
setCurrentDropItem(e->pos()); |
|
1325 |
} else { |
|
1326 |
e->ignore(); |
|
1327 |
setCurrentDropItem(QPoint(-1, -1)); |
|
1328 |
} |
|
1329 |
||
1330 |
oldDragPos = e->pos(); |
|
1331 |
} |
|
1332 |
||
1333 |
void QFileListBox::viewportDragMoveEvent(QDragMoveEvent *e) |
|
1334 |
{ |
|
1335 |
if (acceptDrop(e->pos(), e->source())) { |
|
1336 |
switch (e->action()) { |
|
1337 |
case QDropEvent::Copy: |
|
1338 |
e->acceptAction(); |
|
1339 |
break; |
|
1340 |
case QDropEvent::Move: |
|
1341 |
e->acceptAction(); |
|
1342 |
break; |
|
1343 |
case QDropEvent::Link: |
|
1344 |
break; |
|
1345 |
default: |
|
1346 |
break; |
|
1347 |
} |
|
1348 |
if (oldDragPos != e->pos()) |
|
1349 |
setCurrentDropItem(e->pos()); |
|
1350 |
} else { |
|
1351 |
changeDirTimer->stop(); |
|
1352 |
e->ignore(); |
|
1353 |
setCurrentDropItem(QPoint(-1, -1)); |
|
1354 |
} |
|
1355 |
||
1356 |
oldDragPos = e->pos(); |
|
1357 |
} |
|
1358 |
||
1359 |
void QFileListBox::viewportDragLeaveEvent(QDragLeaveEvent *) |
|
1360 |
{ |
|
1361 |
changeDirTimer->stop(); |
|
1362 |
setCurrentDropItem(QPoint(-1, -1)); |
|
1363 |
//######## |
|
1364 |
// if (startDragDir != filedialog->d->url) |
|
1365 |
// filedialog->setUrl(startDragUrl); |
|
1366 |
} |
|
1367 |
||
1368 |
void QFileListBox::viewportDropEvent(QDropEvent *e) |
|
1369 |
{ |
|
1370 |
changeDirTimer->stop(); |
|
1371 |
||
1372 |
if (!Q3UriDrag::canDecode(e)) { |
|
1373 |
e->ignore(); |
|
1374 |
return; |
|
1375 |
} |
|
1376 |
||
1377 |
Q3StrList l; |
|
1378 |
Q3UriDrag::decode(e, l); |
|
1379 |
||
1380 |
bool move = e->action() == QDropEvent::Move; |
|
1381 |
// bool supportAction = move || e->action() == QDropEvent::Copy; |
|
1382 |
||
1383 |
Q3UrlOperator dest; |
|
1384 |
if (currDropItem) |
|
1385 |
dest = Q3UrlOperator(filedialog->d->url, Q3FileDialogPrivate::encodeFileName(currDropItem->text())); |
|
1386 |
else |
|
1387 |
dest = filedialog->d->url; |
|
1388 |
QStringList lst; |
|
1389 |
for (uint i = 0; i < l.count(); ++i) { |
|
1390 |
lst << QLatin1String(l.at(i)); |
|
1391 |
} |
|
1392 |
||
1393 |
filedialog->d->url.copy(lst, dest, move); |
|
1394 |
||
1395 |
// ##### what is supportAction for? |
|
1396 |
e->acceptAction(); |
|
1397 |
currDropItem = 0; |
|
1398 |
} |
|
1399 |
||
1400 |
bool QFileListBox::acceptDrop(const QPoint &pnt, QWidget *source) |
|
1401 |
{ |
|
1402 |
Q3ListBoxItem *item = itemAt(pnt); |
|
1403 |
if (!item || (item && !itemRect(item).contains(pnt))) { |
|
1404 |
if (source == viewport() && startDragDir == filedialog->dirPath()) |
|
1405 |
return false; |
|
1406 |
return true; |
|
1407 |
} |
|
1408 |
||
1409 |
QUrlInfo fi(filedialog->d->url.info(item->text().isEmpty() ? QString::fromLatin1(".") : item->text())); |
|
1410 |
||
1411 |
if (fi.isDir() && itemRect(item).contains(pnt)) |
|
1412 |
return true; |
|
1413 |
return false; |
|
1414 |
} |
|
1415 |
||
1416 |
void QFileListBox::setCurrentDropItem(const QPoint &pnt) |
|
1417 |
{ |
|
1418 |
changeDirTimer->stop(); |
|
1419 |
||
1420 |
Q3ListBoxItem *item = 0; |
|
1421 |
if (pnt != QPoint(-1, -1)) |
|
1422 |
item = itemAt(pnt); |
|
1423 |
if (item && !QUrlInfo(filedialog->d->url.info(item->text().isEmpty() ? QString::fromLatin1(".") : item->text())).isDir()) |
|
1424 |
item = 0; |
|
1425 |
if (item && !itemRect(item).contains(pnt)) |
|
1426 |
item = 0; |
|
1427 |
||
1428 |
currDropItem = item; |
|
1429 |
if (currDropItem) |
|
1430 |
setCurrentItem(currDropItem); |
|
1431 |
changeDirTimer->start(750); |
|
1432 |
} |
|
1433 |
#endif // QT_NO_DRAGANDDROP |
|
1434 |
||
1435 |
void QFileListBox::changeDirDuringDrag() |
|
1436 |
{ |
|
1437 |
#ifndef QT_NO_DRAGANDDROP |
|
1438 |
if (!currDropItem) |
|
1439 |
return; |
|
1440 |
changeDirTimer->stop(); |
|
1441 |
Q3Url u(filedialog->d->url, Q3FileDialogPrivate::encodeFileName(currDropItem->text())); |
|
1442 |
filedialog->setDir(u); |
|
1443 |
currDropItem = 0; |
|
1444 |
#endif |
|
1445 |
} |
|
1446 |
||
1447 |
void QFileListBox::doubleClickTimeout() |
|
1448 |
{ |
|
1449 |
startRename(); |
|
1450 |
renameTimer->stop(); |
|
1451 |
} |
|
1452 |
||
1453 |
void QFileListBox::startRename(bool check) |
|
1454 |
{ |
|
1455 |
if (check && (!renameItem || renameItem != item(currentItem()))) |
|
1456 |
return; |
|
1457 |
||
1458 |
int i = currentItem(); |
|
1459 |
setSelected(i, true); |
|
1460 |
QRect r = itemRect(item(i)); |
|
1461 |
int bdr = item(i)->pixmap() ? |
|
1462 |
item(i)->pixmap()->width() : 16; |
|
1463 |
int x = r.x() + bdr; |
|
1464 |
int y = r.y(); |
|
1465 |
int w = item(i)->width(this) - bdr; |
|
1466 |
int h = qMax(lined->height() + 2, r.height()); |
|
1467 |
y = y + r.height() / 2 - h / 2; |
|
1468 |
||
1469 |
lined->parentWidget()->setGeometry(x, y, w + 6, h); |
|
1470 |
lined->setFocus(); |
|
1471 |
lined->setText(item(i)->text()); |
|
1472 |
lined->selectAll(); |
|
1473 |
lined->setFrame(false); |
|
1474 |
lined->parentWidget()->show(); |
|
1475 |
viewport()->setFocusProxy(lined); |
|
1476 |
renaming = true; |
|
1477 |
} |
|
1478 |
||
1479 |
void QFileListBox::clear() |
|
1480 |
{ |
|
1481 |
cancelRename(); |
|
1482 |
Q3ListBox::clear(); |
|
1483 |
} |
|
1484 |
||
1485 |
void QFileListBox::rename() |
|
1486 |
{ |
|
1487 |
if (!lined->text().isEmpty()) { |
|
1488 |
QString file = currentText(); |
|
1489 |
||
1490 |
if (lined->text() != file) |
|
1491 |
filedialog->d->url.rename(file, lined->text()); |
|
1492 |
} |
|
1493 |
cancelRename(); |
|
1494 |
} |
|
1495 |
||
1496 |
void QFileListBox::cancelRename() |
|
1497 |
{ |
|
1498 |
renameItem = 0; |
|
1499 |
lined->parentWidget()->hide(); |
|
1500 |
viewport()->setFocusProxy(this); |
|
1501 |
renaming = false; |
|
1502 |
updateItem(currentItem()); |
|
1503 |
if (lined->hasFocus()) |
|
1504 |
viewport()->setFocus(); |
|
1505 |
} |
|
1506 |
||
1507 |
void QFileListBox::contentsMoved(int, int) |
|
1508 |
{ |
|
1509 |
changeDirTimer->stop(); |
|
1510 |
#ifndef QT_NO_DRAGANDDROP |
|
1511 |
setCurrentDropItem(QPoint(-1, -1)); |
|
1512 |
#endif |
|
1513 |
} |
|
1514 |
||
1515 |
/************************************************************************ |
|
1516 |
* |
|
1517 |
* Internal class QFileListView |
|
1518 |
* |
|
1519 |
************************************************************************/ |
|
1520 |
||
1521 |
Q3FileDialogQFileListView::Q3FileDialogQFileListView(QWidget *parent, Q3FileDialog *dlg) |
|
1522 |
: Q3ListView(parent, "qt_filedlg_listview"), renaming(false), renameItem(0), |
|
1523 |
filedialog(dlg), mousePressed(false), |
|
1524 |
firstMousePressEvent(true) |
|
1525 |
{ |
|
1526 |
changeDirTimer = new QTimer(this); |
|
1527 |
Q3VBox *box = new Q3VBox(viewport(), "qt_vbox"); |
|
1528 |
box->setFrameStyle(QFrame::Box | QFrame::Plain); |
|
1529 |
lined = new QRenameEdit(box); |
|
1530 |
lined->setFixedHeight(lined->sizeHint().height()); |
|
1531 |
box->hide(); |
|
1532 |
box->setBackgroundRole(QPalette::Base); |
|
1533 |
renameTimer = new QTimer(this); |
|
1534 |
connect(lined, SIGNAL(doRename()), |
|
1535 |
this, SLOT (rename())); |
|
1536 |
connect(lined, SIGNAL(cancelRename()), |
|
1537 |
this, SLOT(cancelRename())); |
|
1538 |
header()->setMovingEnabled(false); |
|
1539 |
connect(renameTimer, SIGNAL(timeout()), |
|
1540 |
this, SLOT(doubleClickTimeout())); |
|
1541 |
connect(changeDirTimer, SIGNAL(timeout()), |
|
1542 |
this, SLOT(changeDirDuringDrag())); |
|
1543 |
disconnect(header(), SIGNAL(sectionClicked(int)), |
|
1544 |
this, SLOT(changeSortColumn(int))); |
|
1545 |
connect(header(), SIGNAL(sectionClicked(int)), |
|
1546 |
this, SLOT(changeSortColumn2(int))); |
|
1547 |
connect(this, SIGNAL(contentsMoving(int,int)), |
|
1548 |
this, SLOT(contentsMoved(int,int))); |
|
1549 |
||
1550 |
viewport()->setAcceptDrops(true); |
|
1551 |
sortcolumn = 0; |
|
1552 |
ascending = true; |
|
1553 |
dragItem = 0; |
|
1554 |
} |
|
1555 |
||
1556 |
void Q3FileDialogQFileListView::setSorting(int column, bool increasing) |
|
1557 |
{ |
|
1558 |
if (column == -1) { |
|
1559 |
Q3ListView::setSorting(column, increasing); |
|
1560 |
return; |
|
1561 |
} |
|
1562 |
||
1563 |
sortAscending = ascending = increasing; |
|
1564 |
sortcolumn = column; |
|
1565 |
switch (column) { |
|
1566 |
case 0: |
|
1567 |
sortFilesBy = QDir::Name; |
|
1568 |
break; |
|
1569 |
case 1: |
|
1570 |
sortFilesBy = QDir::Size; |
|
1571 |
break; |
|
1572 |
case 3: |
|
1573 |
sortFilesBy = QDir::Time; |
|
1574 |
break; |
|
1575 |
default: |
|
1576 |
sortFilesBy = QDir::Name; // #### ??? |
|
1577 |
break; |
|
1578 |
} |
|
1579 |
||
1580 |
filedialog->resortDir(); |
|
1581 |
} |
|
1582 |
||
1583 |
void Q3FileDialogQFileListView::changeSortColumn2(int column) |
|
1584 |
{ |
|
1585 |
int lcol = header()->mapToLogical(column); |
|
1586 |
setSorting(lcol, sortcolumn == lcol ? !ascending : true); |
|
1587 |
} |
|
1588 |
||
1589 |
void Q3FileDialogQFileListView::keyPressEvent(QKeyEvent *e) |
|
1590 |
{ |
|
1591 |
if ((e->key() == Qt::Key_Enter || |
|
1592 |
e->key() == Qt::Key_Return) && |
|
1593 |
renaming) |
|
1594 |
return; |
|
1595 |
||
1596 |
QString keyPressed = e->text().toLower(); |
|
1597 |
QChar keyChar = keyPressed[0]; |
|
1598 |
if (keyChar.isLetterOrNumber()) { |
|
1599 |
Q3ListViewItem * i = 0; |
|
1600 |
if (currentItem()) |
|
1601 |
i = currentItem(); |
|
1602 |
else |
|
1603 |
i = firstChild(); |
|
1604 |
if (i->nextSibling()) |
|
1605 |
i = i->nextSibling(); |
|
1606 |
else |
|
1607 |
i = firstChild(); |
|
1608 |
while (i != currentItem()) { |
|
1609 |
QString it = i->text(0); |
|
1610 |
if (it[0].toLower() == keyChar) { |
|
1611 |
clearSelection(); |
|
1612 |
ensureItemVisible(i); |
|
1613 |
setCurrentItem(i); |
|
1614 |
} else { |
|
1615 |
if (i->nextSibling()) |
|
1616 |
i = i->nextSibling(); |
|
1617 |
else |
|
1618 |
i = firstChild(); |
|
1619 |
} |
|
1620 |
} |
|
1621 |
return; |
|
1622 |
} |
|
1623 |
||
1624 |
cancelRename(); |
|
1625 |
Q3ListView::keyPressEvent(e); |
|
1626 |
} |
|
1627 |
||
1628 |
void Q3FileDialogQFileListView::viewportMousePressEvent(QMouseEvent *e) |
|
1629 |
{ |
|
1630 |
pressPos = e->pos(); |
|
1631 |
mousePressed = false; |
|
1632 |
||
1633 |
bool didRename = renaming; |
|
1634 |
cancelRename(); |
|
1635 |
if (!hasFocus() && !viewport()->hasFocus()) |
|
1636 |
setFocus(); |
|
1637 |
||
1638 |
if (e->button() != Qt::LeftButton) { |
|
1639 |
Q3ListView::viewportMousePressEvent(e); |
|
1640 |
firstMousePressEvent = false; |
|
1641 |
return; |
|
1642 |
} |
|
1643 |
||
1644 |
Q3ListViewItem *i = currentItem(); |
|
1645 |
Q3ListView::viewportMousePressEvent(e); |
|
1646 |
||
1647 |
Q3FileDialogPrivate::File *i1 = (Q3FileDialogPrivate::File*)currentItem(); |
|
1648 |
if (i1) |
|
1649 |
mousePressed = !i1->info.isDir() || (filedialog->mode() == Q3FileDialog::Directory) || (filedialog->mode() == Q3FileDialog::DirectoryOnly); |
|
1650 |
||
1651 |
||
1652 |
if (itemAt(e->pos()) != i || |
|
1653 |
e->x() + contentsX() > columnWidth(0)) { |
|
1654 |
firstMousePressEvent = false; |
|
1655 |
return; |
|
1656 |
} |
|
1657 |
||
1658 |
if (!firstMousePressEvent && !didRename && i == currentItem() && currentItem() && |
|
1659 |
QUrlInfo(filedialog->d->url.info(QString(QLatin1Char('.')))).isWritable() && currentItem()->text(0) != QLatin1String("..")) { |
|
1660 |
renameTimer->start(QApplication::doubleClickInterval(), true); |
|
1661 |
renameItem = currentItem(); |
|
1662 |
} |
|
1663 |
||
1664 |
firstMousePressEvent = false; |
|
1665 |
} |
|
1666 |
||
1667 |
void Q3FileDialogQFileListView::viewportMouseDoubleClickEvent(QMouseEvent *e) |
|
1668 |
{ |
|
1669 |
renameTimer->stop(); |
|
1670 |
Q3ListView::viewportMouseDoubleClickEvent(e); |
|
1671 |
} |
|
1672 |
||
1673 |
void Q3FileDialogQFileListView::viewportMouseReleaseEvent(QMouseEvent *e) |
|
1674 |
{ |
|
1675 |
Q3ListView::viewportMouseReleaseEvent(e); |
|
1676 |
mousePressed = false; |
|
1677 |
dragItem = 0; |
|
1678 |
} |
|
1679 |
||
1680 |
void Q3FileDialogQFileListView::viewportMouseMoveEvent(QMouseEvent *e) |
|
1681 |
{ |
|
1682 |
renameTimer->stop(); |
|
1683 |
if (!dragItem) |
|
1684 |
dragItem = itemAt(e->pos()); |
|
1685 |
#ifndef QT_NO_DRAGANDDROP |
|
1686 |
if ( (pressPos - e->pos()).manhattanLength() > QApplication::startDragDistance() && mousePressed) { |
|
1687 |
Q3ListViewItem *item = dragItem; |
|
1688 |
dragItem = 0; |
|
1689 |
if (item) { |
|
1690 |
Q3UriDrag* drag = new Q3UriDrag(viewport()); |
|
1691 |
QStringList files; |
|
1692 |
if (filedialog->mode() == Q3FileDialog::ExistingFiles) |
|
1693 |
files = filedialog->selectedFiles(); |
|
1694 |
else |
|
1695 |
files = QStringList(filedialog->selectedFile()); |
|
1696 |
drag->setFileNames(files); |
|
1697 |
||
1698 |
if (lined->isVisible()) |
|
1699 |
cancelRename(); |
|
1700 |
||
1701 |
connect(drag, SIGNAL(destroyed()), |
|
1702 |
this, SLOT(dragObjDestroyed())); |
|
1703 |
drag->drag(); |
|
1704 |
||
1705 |
mousePressed = false; |
|
1706 |
} |
|
1707 |
} |
|
1708 |
#endif |
|
1709 |
} |
|
1710 |
||
1711 |
void Q3FileDialogQFileListView::dragObjDestroyed() |
|
1712 |
{ |
|
1713 |
#ifndef QT_NO_DRAGANDDROP |
|
1714 |
//###### |
|
1715 |
//filedialog->rereadDir(); |
|
1716 |
#endif |
|
1717 |
} |
|
1718 |
||
1719 |
#ifndef QT_NO_DRAGANDDROP |
|
1720 |
void Q3FileDialogQFileListView::viewportDragEnterEvent(QDragEnterEvent *e) |
|
1721 |
{ |
|
1722 |
startDragUrl = filedialog->d->url; |
|
1723 |
startDragDir = filedialog->dirPath(); |
|
1724 |
currDropItem = 0; |
|
1725 |
||
1726 |
if (!Q3UriDrag::canDecode(e)) { |
|
1727 |
e->ignore(); |
|
1728 |
return; |
|
1729 |
} |
|
1730 |
||
1731 |
QStringList l; |
|
1732 |
Q3UriDrag::decodeLocalFiles(e, l); |
|
1733 |
urls = (int)l.count(); |
|
1734 |
||
1735 |
if (acceptDrop(e->pos(), e->source())) { |
|
1736 |
e->accept(); |
|
1737 |
setCurrentDropItem(e->pos()); |
|
1738 |
} else { |
|
1739 |
e->ignore(); |
|
1740 |
setCurrentDropItem(QPoint(-1, -1)); |
|
1741 |
} |
|
1742 |
||
1743 |
oldDragPos = e->pos(); |
|
1744 |
} |
|
1745 |
||
1746 |
void Q3FileDialogQFileListView::viewportDragMoveEvent(QDragMoveEvent *e) |
|
1747 |
{ |
|
1748 |
if (acceptDrop(e->pos(), e->source())) { |
|
1749 |
if (oldDragPos != e->pos()) |
|
1750 |
setCurrentDropItem(e->pos()); |
|
1751 |
switch (e->action()) { |
|
1752 |
case QDropEvent::Copy: |
|
1753 |
e->acceptAction(); |
|
1754 |
break; |
|
1755 |
case QDropEvent::Move: |
|
1756 |
e->acceptAction(); |
|
1757 |
break; |
|
1758 |
case QDropEvent::Link: |
|
1759 |
break; |
|
1760 |
default: |
|
1761 |
break; |
|
1762 |
} |
|
1763 |
} else { |
|
1764 |
changeDirTimer->stop(); |
|
1765 |
e->ignore(); |
|
1766 |
setCurrentDropItem(QPoint(-1, -1)); |
|
1767 |
} |
|
1768 |
||
1769 |
oldDragPos = e->pos(); |
|
1770 |
} |
|
1771 |
||
1772 |
void Q3FileDialogQFileListView::viewportDragLeaveEvent(QDragLeaveEvent *) |
|
1773 |
{ |
|
1774 |
changeDirTimer->stop(); |
|
1775 |
setCurrentDropItem(QPoint(-1, -1)); |
|
1776 |
//######## |
|
1777 |
// if (startDragDir != filedialog->d->url) |
|
1778 |
// filedialog->setUrl(startDragUrl); |
|
1779 |
} |
|
1780 |
||
1781 |
void Q3FileDialogQFileListView::viewportDropEvent(QDropEvent *e) |
|
1782 |
{ |
|
1783 |
changeDirTimer->stop(); |
|
1784 |
||
1785 |
if (!Q3UriDrag::canDecode(e)) { |
|
1786 |
e->ignore(); |
|
1787 |
return; |
|
1788 |
} |
|
1789 |
||
1790 |
QStringList l; |
|
1791 |
Q3UriDrag::decodeToUnicodeUris(e, l); |
|
1792 |
||
1793 |
bool move = e->action() == QDropEvent::Move; |
|
1794 |
// bool supportAction = move || e->action() == QDropEvent::Copy; |
|
1795 |
||
1796 |
Q3UrlOperator dest; |
|
1797 |
if (currDropItem) |
|
1798 |
dest = Q3UrlOperator(filedialog->d->url, Q3FileDialogPrivate::encodeFileName(currDropItem->text(0))); |
|
1799 |
else |
|
1800 |
dest = filedialog->d->url; |
|
1801 |
filedialog->d->url.copy(l, dest, move); |
|
1802 |
||
1803 |
// ##### what is supportAction for? |
|
1804 |
e->acceptAction(); |
|
1805 |
currDropItem = 0; |
|
1806 |
} |
|
1807 |
||
1808 |
bool Q3FileDialogQFileListView::acceptDrop(const QPoint &pnt, QWidget *source) |
|
1809 |
{ |
|
1810 |
Q3ListViewItem *item = itemAt(pnt); |
|
1811 |
if (!item || (item && !itemRect(item).contains(pnt))) { |
|
1812 |
if (source == viewport() && startDragDir == filedialog->dirPath()) |
|
1813 |
return false; |
|
1814 |
return true; |
|
1815 |
} |
|
1816 |
||
1817 |
QUrlInfo fi(filedialog->d->url.info(item->text(0).isEmpty() ? QString::fromLatin1(".") : item->text(0))); |
|
1818 |
||
1819 |
if (fi.isDir() && itemRect(item).contains(pnt)) |
|
1820 |
return true; |
|
1821 |
return false; |
|
1822 |
} |
|
1823 |
||
1824 |
void Q3FileDialogQFileListView::setCurrentDropItem(const QPoint &pnt) |
|
1825 |
{ |
|
1826 |
changeDirTimer->stop(); |
|
1827 |
||
1828 |
Q3ListViewItem *item = itemAt(pnt); |
|
1829 |
if (pnt == QPoint(-1, -1)) |
|
1830 |
item = 0; |
|
1831 |
if (item && !QUrlInfo(filedialog->d->url.info(item->text(0).isEmpty() ? QString::fromLatin1(".") : item->text(0))).isDir()) |
|
1832 |
item = 0; |
|
1833 |
||
1834 |
if (item && !itemRect(item).contains(pnt)) |
|
1835 |
item = 0; |
|
1836 |
||
1837 |
currDropItem = item; |
|
1838 |
||
1839 |
if (currDropItem) |
|
1840 |
setCurrentItem(currDropItem); |
|
1841 |
||
1842 |
changeDirTimer->start(750); |
|
1843 |
} |
|
1844 |
#endif // QT_NO_DRAGANDDROP |
|
1845 |
||
1846 |
void Q3FileDialogQFileListView::changeDirDuringDrag() |
|
1847 |
{ |
|
1848 |
#ifndef QT_NO_DRAGANDDROP |
|
1849 |
if (!currDropItem) |
|
1850 |
return; |
|
1851 |
changeDirTimer->stop(); |
|
1852 |
Q3Url u(filedialog->d->url, Q3FileDialogPrivate::encodeFileName(currDropItem->text(0))); |
|
1853 |
filedialog->setDir(u); |
|
1854 |
currDropItem = 0; |
|
1855 |
#endif // QT_NO_DRAGANDDROP |
|
1856 |
} |
|
1857 |
||
1858 |
||
1859 |
void Q3FileDialogQFileListView::doubleClickTimeout() |
|
1860 |
{ |
|
1861 |
startRename(); |
|
1862 |
renameTimer->stop(); |
|
1863 |
} |
|
1864 |
||
1865 |
void Q3FileDialogQFileListView::startRename(bool check) |
|
1866 |
{ |
|
1867 |
if (check && (!renameItem || renameItem != currentItem())) |
|
1868 |
return; |
|
1869 |
||
1870 |
Q3ListViewItem *i = currentItem(); |
|
1871 |
setSelected(i, true); |
|
1872 |
||
1873 |
QRect r = itemRect(i); |
|
1874 |
int bdr = i->pixmap(0) ? |
|
1875 |
i->pixmap(0)->width() : 16; |
|
1876 |
int x = r.x() + bdr; |
|
1877 |
int y = r.y(); |
|
1878 |
int w = columnWidth(0) - bdr; |
|
1879 |
int h = qMax(lined->height() + 2, r.height()); |
|
1880 |
y = y + r.height() / 2 - h / 2; |
|
1881 |
||
1882 |
lined->parentWidget()->setGeometry(x, y, w + 6, h); |
|
1883 |
lined->setFocus(); |
|
1884 |
lined->setText(i->text(0)); |
|
1885 |
lined->selectAll(); |
|
1886 |
lined->setFrame(false); |
|
1887 |
lined->parentWidget()->show(); |
|
1888 |
viewport()->setFocusProxy(lined); |
|
1889 |
renaming = true; |
|
1890 |
} |
|
1891 |
||
1892 |
void Q3FileDialogQFileListView::clear() |
|
1893 |
{ |
|
1894 |
cancelRename(); |
|
1895 |
Q3ListView::clear(); |
|
1896 |
} |
|
1897 |
||
1898 |
void Q3FileDialogQFileListView::rename() |
|
1899 |
{ |
|
1900 |
if (!lined->text().isEmpty()) { |
|
1901 |
QString file = currentItem()->text(0); |
|
1902 |
||
1903 |
if (lined->text() != file) |
|
1904 |
filedialog->d->url.rename(file, lined->text()); |
|
1905 |
} |
|
1906 |
cancelRename(); |
|
1907 |
} |
|
1908 |
||
1909 |
void Q3FileDialogQFileListView::cancelRename() |
|
1910 |
{ |
|
1911 |
renameItem = 0; |
|
1912 |
lined->parentWidget()->hide(); |
|
1913 |
viewport()->setFocusProxy(this); |
|
1914 |
renaming = false; |
|
1915 |
if (currentItem()) |
|
1916 |
currentItem()->repaint(); |
|
1917 |
if (lined->hasFocus()) |
|
1918 |
viewport()->setFocus(); |
|
1919 |
} |
|
1920 |
||
1921 |
void Q3FileDialogQFileListView::contentsMoved(int, int) |
|
1922 |
{ |
|
1923 |
changeDirTimer->stop(); |
|
1924 |
#ifndef QT_NO_DRAGANDDROP |
|
1925 |
setCurrentDropItem(QPoint(-1, -1)); |
|
1926 |
#endif |
|
1927 |
} |
|
1928 |
||
1929 |
||
1930 |
Q3FileDialogPrivate::File::~File() |
|
1931 |
{ |
|
1932 |
if (d->pendingItems.findRef(this)) |
|
1933 |
d->pendingItems.removeRef(this); |
|
1934 |
} |
|
1935 |
||
1936 |
QString Q3FileDialogPrivate::File::text(int column) const |
|
1937 |
{ |
|
1938 |
makeVariables(); |
|
1939 |
||
1940 |
switch(column) { |
|
1941 |
case 0: |
|
1942 |
return info.name(); |
|
1943 |
case 1: |
|
1944 |
if (info.isFile()) { |
|
1945 |
QIODevice::Offset size = info.size(); |
|
1946 |
return QString::number(size); |
|
1947 |
} else { |
|
1948 |
return QString::fromLatin1(""); |
|
1949 |
} |
|
1950 |
case 2: |
|
1951 |
if (info.isFile() && info.isSymLink()) { |
|
1952 |
return d->symLinkToFile; |
|
1953 |
} else if (info.isFile()) { |
|
1954 |
return d->file; |
|
1955 |
} else if (info.isDir() && info.isSymLink()) { |
|
1956 |
return d->symLinkToDir; |
|
1957 |
} else if (info.isDir()) { |
|
1958 |
return d->dir; |
|
1959 |
} else if (info.isSymLink()) { |
|
1960 |
return d->symLinkToSpecial; |
|
1961 |
} else { |
|
1962 |
return d->special; |
|
1963 |
} |
|
1964 |
case 3: { |
|
1965 |
return info.lastModified().toString(Qt::LocalDate); |
|
1966 |
} |
|
1967 |
case 4: |
|
1968 |
if (info.isReadable()) |
|
1969 |
return info.isWritable() ? d->rw : d->ro; |
|
1970 |
else |
|
1971 |
return info.isWritable() ? d->wo : d->inaccessible; |
|
1972 |
} |
|
1973 |
||
1974 |
return QString::fromLatin1("<--->"); |
|
1975 |
} |
|
1976 |
||
1977 |
const QPixmap * Q3FileDialogPrivate::File::pixmap(int column) const |
|
1978 |
{ |
|
1979 |
if (column) { |
|
1980 |
return 0; |
|
1981 |
} else if (Q3ListViewItem::pixmap(column)) { |
|
1982 |
return Q3ListViewItem::pixmap(column); |
|
1983 |
} else if (info.isSymLink()) { |
|
1984 |
if (info.isFile()) |
|
1985 |
return symLinkFileIcon; |
|
1986 |
else |
|
1987 |
return symLinkDirIcon; |
|
1988 |
} else if (info.isDir()) { |
|
1989 |
return closedFolderIcon; |
|
1990 |
} else if (info.isFile()) { |
|
1991 |
return fileIcon; |
|
1992 |
} else { |
|
1993 |
return fifteenTransparentPixels; |
|
1994 |
} |
|
1995 |
} |
|
1996 |
||
1997 |
Q3FileDialogPrivate::MCItem::MCItem(Q3ListBox * lb, Q3ListViewItem * item) |
|
1998 |
: Q3ListBoxItem() |
|
1999 |
{ |
|
2000 |
i = item; |
|
2001 |
if (lb) |
|
2002 |
lb->insertItem(this); |
|
2003 |
} |
|
2004 |
||
2005 |
Q3FileDialogPrivate::MCItem::MCItem(Q3ListBox * lb, Q3ListViewItem * item, Q3ListBoxItem *after) |
|
2006 |
: Q3ListBoxItem() |
|
2007 |
{ |
|
2008 |
i = item; |
|
2009 |
if (lb) |
|
2010 |
lb->insertItem(this, after); |
|
2011 |
} |
|
2012 |
||
2013 |
QString Q3FileDialogPrivate::MCItem::text() const |
|
2014 |
{ |
|
2015 |
return i->text(0); |
|
2016 |
} |
|
2017 |
||
2018 |
||
2019 |
const QPixmap *Q3FileDialogPrivate::MCItem::pixmap() const |
|
2020 |
{ |
|
2021 |
return i->pixmap(0); |
|
2022 |
} |
|
2023 |
||
2024 |
||
2025 |
int Q3FileDialogPrivate::MCItem::height(const Q3ListBox * lb) const |
|
2026 |
{ |
|
2027 |
int hf = lb->fontMetrics().height(); |
|
2028 |
int hp = pixmap() ? pixmap()->height() : 0; |
|
2029 |
return qMax(hf, hp) + 2; |
|
2030 |
} |
|
2031 |
||
2032 |
||
2033 |
int Q3FileDialogPrivate::MCItem::width(const Q3ListBox * lb) const |
|
2034 |
{ |
|
2035 |
QFontMetrics fm = lb->fontMetrics(); |
|
2036 |
int w = 2; |
|
2037 |
if (pixmap()) |
|
2038 |
w += pixmap()->width() + 4; |
|
2039 |
else |
|
2040 |
w += 18; |
|
2041 |
w += fm.width(text()); |
|
2042 |
w += -fm.minLeftBearing(); |
|
2043 |
w += -fm.minRightBearing(); |
|
2044 |
w += 6; |
|
2045 |
return w; |
|
2046 |
} |
|
2047 |
||
2048 |
||
2049 |
void Q3FileDialogPrivate::MCItem::paint(QPainter * ptr) |
|
2050 |
{ |
|
2051 |
QFontMetrics fm = ptr->fontMetrics(); |
|
2052 |
||
2053 |
int h; |
|
2054 |
||
2055 |
if (pixmap()) |
|
2056 |
h = qMax(fm.height(), pixmap()->height()) + 2; |
|
2057 |
else |
|
2058 |
h = fm.height() + 2; |
|
2059 |
||
2060 |
const QPixmap * pm = pixmap(); |
|
2061 |
if (pm) |
|
2062 |
ptr->drawPixmap(2, 1, *pm); |
|
2063 |
||
2064 |
ptr->drawText(pm ? pm->width() + 4 : 22, h - fm.descent() - 2, |
|
2065 |
text()); |
|
2066 |
} |
|
2067 |
||
2068 |
static QStringList makeFiltersList(const QString &filter) |
|
2069 |
{ |
|
2070 |
if (filter.isEmpty()) |
|
2071 |
return QStringList(); |
|
2072 |
||
2073 |
int i = filter.indexOf(QLatin1String(";;"), 0); |
|
2074 |
QString sep(QLatin1String(";;")); |
|
2075 |
if (i == -1) { |
|
2076 |
if (filter.contains(QLatin1Char('\n'))) { |
|
2077 |
sep = QLatin1Char('\n'); |
|
2078 |
i = filter.indexOf(sep); |
|
2079 |
} |
|
2080 |
} |
|
2081 |
||
2082 |
return QStringList::split(sep, filter); |
|
2083 |
} |
|
2084 |
||
2085 |
/*! |
|
2086 |
\class Q3FileDialog |
|
2087 |
\brief The Q3FileDialog class provides dialogs that allow users to select files or directories. |
|
2088 |
||
2089 |
\compat |
|
2090 |
||
2091 |
The Q3FileDialog class enables a user to traverse their file system in |
|
2092 |
order to select one or many files or a directory. |
|
2093 |
||
2094 |
The easiest way to create a Q3FileDialog is to use the static |
|
2095 |
functions. On Windows, these static functions will call the native |
|
2096 |
Windows file dialog and on Mac OS X, these static function will call |
|
2097 |
the native Mac OS X file dialog. |
|
2098 |
||
2099 |
\snippet doc/src/snippets/code/src_qt3support_dialogs_q3filedialog.cpp 0 |
|
2100 |
||
2101 |
In the above example, a modal Q3FileDialog is created using a static |
|
2102 |
function. The startup directory is set to "/home". The file filter |
|
2103 |
is set to "Images (*.png *.xpm *.jpg)". The parent of the file dialog |
|
2104 |
is set to \e this and it is given the identification name - "open file |
|
2105 |
dialog". The caption at the top of file dialog is set to "Choose a |
|
2106 |
file". If you want to use multiple filters, separate each one with |
|
2107 |
\e two semicolons, e.g. |
|
2108 |
\snippet doc/src/snippets/code/src_qt3support_dialogs_q3filedialog.cpp 1 |
|
2109 |
||
2110 |
You can create your own Q3FileDialog without using the static |
|
2111 |
functions. By calling setMode(), you can set what can be returned by |
|
2112 |
the Q3FileDialog. |
|
2113 |
||
2114 |
\snippet doc/src/snippets/code/src_qt3support_dialogs_q3filedialog.cpp 2 |
|
2115 |
||
2116 |
In the above example, the mode of the file dialog is set to \l |
|
2117 |
AnyFile, meaning that the user can select any file, or even specify a |
|
2118 |
file that doesn't exist. This mode is useful for creating a "File Save |
|
2119 |
As" file dialog. Use \l ExistingFile if the user must select an |
|
2120 |
existing file or \l Directory if only a directory may be selected. |
|
2121 |
(See the \l Q3FileDialog::Mode enum for the complete list of modes.) |
|
2122 |
||
2123 |
You can retrieve the dialog's mode with mode(). Use setFilter() to set |
|
2124 |
the dialog's file filter, e.g. |
|
2125 |
||
2126 |
\snippet doc/src/snippets/code/src_qt3support_dialogs_q3filedialog.cpp 3 |
|
2127 |
||
2128 |
In the above example, the filter is set to "Images (*.png *.xpm |
|
2129 |
*.jpg)", this means that only files with the extension \c png, \c xpm |
|
2130 |
or \c jpg will be shown in the Q3FileDialog. You can apply |
|
2131 |
several filters by using setFilters() and add additional filters with |
|
2132 |
addFilter(). Use setSelectedFilter() to select one of the filters |
|
2133 |
you've given as the file dialog's default filter. Whenever the user |
|
2134 |
changes the filter the filterSelected() signal is emitted. |
|
2135 |
||
2136 |
The file dialog has two view modes, Q3FileDialog::List which simply |
|
2137 |
lists file and directory names and Q3FileDialog::Detail which |
|
2138 |
displays additional information alongside each name, e.g. file size, |
|
2139 |
modification date, etc. Set the mode with setViewMode(). |
|
2140 |
||
2141 |
\snippet doc/src/snippets/code/src_qt3support_dialogs_q3filedialog.cpp 4 |
|
2142 |
||
2143 |
The last important function you will need to use when creating your |
|
2144 |
own file dialog is selectedFile(). |
|
2145 |
||
2146 |
\snippet doc/src/snippets/code/src_qt3support_dialogs_q3filedialog.cpp 5 |
|
2147 |
||
2148 |
In the above example, a modal file dialog is created and shown. If |
|
2149 |
the user clicked OK, then the file they selected is put in \c |
|
2150 |
fileName. |
|
2151 |
||
2152 |
If you are using the \l ExistingFiles mode then you will need to use |
|
2153 |
selectedFiles() which will return the selected files in a QStringList. |
|
2154 |
||
2155 |
The dialog's working directory can be set with setDir(). The display |
|
2156 |
of hidden files is controlled with setShowHiddenFiles(). The dialog |
|
2157 |
can be forced to re-read the directory with rereadDir() and re-sort |
|
2158 |
the directory with resortDir(). All the files in the current directory |
|
2159 |
can be selected with selectAll(). |
|
2160 |
||
2161 |
\section1 Creating and using preview widgets |
|
2162 |
||
2163 |
There are two kinds of preview widgets that can be used with |
|
2164 |
Q3FileDialogs: \e content preview widgets and \e information preview |
|
2165 |
widgets. They are created and used in the same way except that the |
|
2166 |
function names differ, e.g. setContentsPreview() and setInfoPreview(). |
|
2167 |
||
2168 |
A preview widget is a widget that is placed inside a Q3FileDialog so |
|
2169 |
that the user can see either the contents of the file, or information |
|
2170 |
about the file. |
|
2171 |
||
2172 |
\snippet doc/src/snippets/code/src_qt3support_dialogs_q3filedialog.cpp 6 |
|
2173 |
||
2174 |
In the above snippet, we create a preview widget which inherits from |
|
2175 |
QLabel and Q3FilePreview. File preview widgets \e must inherit from |
|
2176 |
Q3FilePreview. |
|
2177 |
||
2178 |
Inside the class we reimplement Q3FilePreview::previewUrl(), this is |
|
2179 |
where we determine what happens when a file is selected. In the |
|
2180 |
above example we only show a preview of the file if it is a valid |
|
2181 |
pixmap. Here's how to make a file dialog use a preview widget: |
|
2182 |
||
2183 |
\snippet doc/src/snippets/code/src_qt3support_dialogs_q3filedialog.cpp 7 |
|
2184 |
||
2185 |
The first line creates an instance of our preview widget. We then |
|
2186 |
create our file dialog and call setContentsPreviewEnabled(true), |
|
2187 |
this tell the file dialog to preview the contents of the currently |
|
2188 |
selected file. We then call setContentsPreview() -- note that we pass |
|
2189 |
the same preview widget twice. Finally, before showing the file |
|
2190 |
dialog, we call setPreviewMode() setting the mode to \e Contents which |
|
2191 |
will show the contents preview of the file that the user has selected. |
|
2192 |
||
2193 |
If you create another preview widget that is used for displaying |
|
2194 |
information about a file, create it in the same way as the contents |
|
2195 |
preview widget and call setInfoPreviewEnabled(), and |
|
2196 |
setInfoPreview(). Then the user will be able to switch between the |
|
2197 |
two preview modes. |
|
2198 |
||
2199 |
For more information about creating a Q3FilePreview widget see |
|
2200 |
\l{Q3FilePreview}. |
|
2201 |
*/ |
|
2202 |
||
2203 |
||
2204 |
/*! \enum Q3FileDialog::Mode |
|
2205 |
||
2206 |
This enum is used to indicate what the user may select in the file |
|
2207 |
dialog, i.e. what the dialog will return if the user clicks OK. |
|
2208 |
||
2209 |
\value AnyFile The name of a file, whether it exists or not. |
|
2210 |
\value ExistingFile The name of a single existing file. |
|
2211 |
\value Directory The name of a directory. Both files and directories |
|
2212 |
are displayed. |
|
2213 |
\value DirectoryOnly The name of a directory. The file dialog will only display directories. |
|
2214 |
\value ExistingFiles The names of zero or more existing files. |
|
2215 |
||
2216 |
See setMode(). |
|
2217 |
*/ |
|
2218 |
||
2219 |
/*! |
|
2220 |
\enum Q3FileDialog::ViewMode |
|
2221 |
||
2222 |
This enum describes the view mode of the file dialog, i.e. what |
|
2223 |
information about each file will be displayed. |
|
2224 |
||
2225 |
\value List Display file and directory names with icons. |
|
2226 |
\value Detail Display file and directory names with icons plus |
|
2227 |
additional information, such as file size and modification date. |
|
2228 |
||
2229 |
See setViewMode(). |
|
2230 |
*/ |
|
2231 |
||
2232 |
/*! |
|
2233 |
\enum Q3FileDialog::PreviewMode |
|
2234 |
||
2235 |
This enum describes the preview mode of the file dialog. |
|
2236 |
||
2237 |
\value NoPreview No preview is shown at all. |
|
2238 |
\value Contents Show a preview of the contents of the current file |
|
2239 |
using the contents preview widget. |
|
2240 |
\value Info Show information about the current file using the |
|
2241 |
info preview widget. |
|
2242 |
||
2243 |
See setPreviewMode(), setContentsPreview() and setInfoPreview(). |
|
2244 |
*/ |
|
2245 |
||
2246 |
/*! |
|
2247 |
\fn void Q3FileDialog::detailViewSelectionChanged() |
|
2248 |
\internal |
|
2249 |
*/ |
|
2250 |
||
2251 |
/*! |
|
2252 |
\fn void Q3FileDialog::listBoxSelectionChanged() |
|
2253 |
\internal |
|
2254 |
*/ |
|
2255 |
||
2256 |
extern const char qt3_file_dialog_filter_reg_exp[] = "([a-zA-Z0-9]*)\\(([a-zA-Z0-9_.*? +;#\\[\\]]*)\\)$"; |
|
2257 |
||
2258 |
/*! |
|
2259 |
Constructs a file dialog called \a name, with the parent, \a parent. |
|
2260 |
If \a modal is true then the file dialog is modal; otherwise it is |
|
2261 |
modeless. |
|
2262 |
*/ |
|
2263 |
||
2264 |
Q3FileDialog::Q3FileDialog(QWidget *parent, const char *name, bool modal) |
|
2265 |
: QDialog(parent, name, modal, |
|
2266 |
(modal ? |
|
2267 |
(Qt::WStyle_Customize | Qt::WStyle_DialogBorder | Qt::WStyle_Title | Qt::WStyle_SysMenu) : Qt::WindowFlags(0))) |
|
2268 |
{ |
|
2269 |
init(); |
|
2270 |
d->mode = ExistingFile; |
|
2271 |
d->types->insertItem(tr("All Files (*)")); |
|
2272 |
d->cursorOverride = false; |
|
2273 |
emit dirEntered(d->url.dirPath()); |
|
2274 |
rereadDir(); |
|
2275 |
} |
|
2276 |
||
2277 |
||
2278 |
/*! |
|
2279 |
Constructs a file dialog called \a name with the parent, \a parent. |
|
2280 |
If \a modal is true then the file dialog is modal; otherwise it is |
|
2281 |
modeless. |
|
2282 |
||
2283 |
If \a dirName is specified then it will be used as the dialog's |
|
2284 |
working directory, i.e. it will be the directory that is shown when |
|
2285 |
the dialog appears. If \a filter is specified it will be used as the |
|
2286 |
dialog's file filter. |
|
2287 |
||
2288 |
*/ |
|
2289 |
||
2290 |
Q3FileDialog::Q3FileDialog(const QString& dirName, const QString & filter, |
|
2291 |
QWidget *parent, const char *name, bool modal) |
|
2292 |
: QDialog(parent, name, modal, |
|
2293 |
(modal ? (Qt::WStyle_Customize | Qt::WStyle_DialogBorder | Qt::WStyle_Title | Qt::WStyle_SysMenu) |
|
2294 |
: Qt::WindowFlags(0))) |
|
2295 |
{ |
|
2296 |
init(); |
|
2297 |
d->mode = ExistingFile; |
|
2298 |
rereadDir(); |
|
2299 |
Q3UrlOperator u(dirName); |
|
2300 |
if (!dirName.isEmpty() && (!u.isLocalFile() || QDir(dirName).exists())) |
|
2301 |
setSelection(dirName); |
|
2302 |
else if (workingDirectory && !workingDirectory->isEmpty()) |
|
2303 |
setDir(*workingDirectory); |
|
2304 |
||
2305 |
if (!filter.isEmpty()) { |
|
2306 |
setFilters(filter); |
|
2307 |
if (!dirName.isEmpty()) { |
|
2308 |
int dotpos = dirName.indexOf(QLatin1Char('.'), 0, Qt::CaseInsensitive); |
|
2309 |
if (dotpos != -1) { |
|
2310 |
for (int b=0 ; b<d->types->count() ; b++) { |
|
2311 |
if (d->types->text(b).contains(dirName.right(dirName.length() - dotpos))) { |
|
2312 |
d->types->setCurrentItem(b); |
|
2313 |
setFilter(d->types->text(b)); |
|
2314 |
return; |
|
2315 |
} |
|
2316 |
} |
|
2317 |
} |
|
2318 |
} |
|
2319 |
} else { |
|
2320 |
d->types->insertItem(tr("All Files (*)")); |
|
2321 |
} |
|
2322 |
} |
|
2323 |
||
2324 |
||
2325 |
/*! |
|
2326 |
\internal |
|
2327 |
Initializes the file dialog. |
|
2328 |
*/ |
|
2329 |
||
2330 |
void Q3FileDialog::init() |
|
2331 |
{ |
|
2332 |
setSizeGripEnabled(true); |
|
2333 |
d = new Q3FileDialogPrivate(); |
|
2334 |
d->mode = AnyFile; |
|
2335 |
d->last = 0; |
|
2336 |
d->lastEFSelected = 0; |
|
2337 |
d->moreFiles = 0; |
|
2338 |
d->infoPreview = false; |
|
2339 |
d->contentsPreview = false; |
|
2340 |
d->hadDotDot = false; |
|
2341 |
d->ignoreNextKeyPress = false; |
|
2342 |
d->progressDia = 0; |
|
2343 |
d->checkForFilter = false; |
|
2344 |
d->ignoreNextRefresh = false; |
|
2345 |
d->ignoreStop = false; |
|
2346 |
d->mimeTypeTimer = new QTimer(this); |
|
2347 |
d->cursorOverride = false; |
|
2348 |
connect(d->mimeTypeTimer, SIGNAL(timeout()), |
|
2349 |
this, SLOT(doMimeTypeLookup())); |
|
2350 |
||
2351 |
d->url = Q3UrlOperator(toRootIfNotExists( QDir::currentDirPath() )); |
|
2352 |
d->oldUrl = d->url; |
|
2353 |
d->currListChildren = 0; |
|
2354 |
||
2355 |
connect(&d->url, SIGNAL(start(Q3NetworkOperation*)), |
|
2356 |
this, SLOT(urlStart(Q3NetworkOperation*))); |
|
2357 |
connect(&d->url, SIGNAL(finished(Q3NetworkOperation*)), |
|
2358 |
this, SLOT(urlFinished(Q3NetworkOperation*))); |
|
2359 |
connect(&d->url, SIGNAL(newChildren(Q3ValueList<QUrlInfo>,Q3NetworkOperation*)), |
|
2360 |
this, SLOT(insertEntry(Q3ValueList<QUrlInfo>,Q3NetworkOperation*))); |
|
2361 |
connect(&d->url, SIGNAL(removed(Q3NetworkOperation*)), |
|
2362 |
this, SLOT(removeEntry(Q3NetworkOperation*))); |
|
2363 |
connect(&d->url, SIGNAL(createdDirectory(QUrlInfo,Q3NetworkOperation*)), |
|
2364 |
this, SLOT(createdDirectory(QUrlInfo,Q3NetworkOperation*))); |
|
2365 |
connect(&d->url, SIGNAL(itemChanged(Q3NetworkOperation*)), |
|
2366 |
this, SLOT(itemChanged(Q3NetworkOperation*))); |
|
2367 |
connect(&d->url, SIGNAL(dataTransferProgress(int,int,Q3NetworkOperation*)), |
|
2368 |
this, SLOT(dataTransferProgress(int,int,Q3NetworkOperation*))); |
|
2369 |
||
2370 |
nameEdit = new QLineEdit(this, "name/filter editor"); |
|
2371 |
nameEdit->setMaxLength(255); //_POSIX_MAX_PATH |
|
2372 |
connect(nameEdit, SIGNAL(textChanged(QString)), |
|
2373 |
this, SLOT(fileNameEditDone())); |
|
2374 |
nameEdit->installEventFilter(this); |
|
2375 |
||
2376 |
d->splitter = new QSplitter(this, "qt_splitter"); |
|
2377 |
||
2378 |
d->stack = new Q3WidgetStack(d->splitter, "files and more files"); |
|
2379 |
||
2380 |
d->splitter->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); |
|
2381 |
||
2382 |
files = new Q3FileDialogQFileListView(d->stack, this); |
|
2383 |
QFontMetrics fm = fontMetrics(); |
|
2384 |
files->addColumn(tr("Name")); |
|
2385 |
files->addColumn(tr("Size")); |
|
2386 |
files->setColumnAlignment(1, Qt::AlignRight); |
|
2387 |
files->addColumn(tr("Type")); |
|
2388 |
files->addColumn(tr("Date")); |
|
2389 |
files->addColumn(tr("Attributes")); |
|
2390 |
files->header()->setStretchEnabled(true, 0); |
|
2391 |
||
2392 |
files->setMinimumSize(50, 25 + 2*fm.lineSpacing()); |
|
2393 |
||
2394 |
connect(files, SIGNAL(selectionChanged()), |
|
2395 |
this, SLOT(detailViewSelectionChanged())); |
|
2396 |
connect(files, SIGNAL(currentChanged(Q3ListViewItem*)), |
|
2397 |
this, SLOT(updateFileNameEdit(Q3ListViewItem*))); |
|
2398 |
connect(files, SIGNAL(doubleClicked(Q3ListViewItem*)), |
|
2399 |
this, SLOT(selectDirectoryOrFile(Q3ListViewItem*))); |
|
2400 |
connect(files, SIGNAL(returnPressed(Q3ListViewItem*)), |
|
2401 |
this, SLOT(selectDirectoryOrFile(Q3ListViewItem*))); |
|
2402 |
connect(files, SIGNAL(contextMenuRequested(Q3ListViewItem*,QPoint,int)), |
|
2403 |
this, SLOT(popupContextMenu(Q3ListViewItem*,QPoint,int))); |
|
2404 |
||
2405 |
files->installEventFilter(this); |
|
2406 |
files->viewport()->installEventFilter(this); |
|
2407 |
||
2408 |
d->moreFiles = new QFileListBox(d->stack, this); |
|
2409 |
d->moreFiles->setRowMode(Q3ListBox::FitToHeight); |
|
2410 |
d->moreFiles->setVariableWidth(true); |
|
2411 |
||
2412 |
connect(d->moreFiles, SIGNAL(selected(Q3ListBoxItem*)), |
|
2413 |
this, SLOT(selectDirectoryOrFile(Q3ListBoxItem*))); |
|
2414 |
connect(d->moreFiles, SIGNAL(selectionChanged()), |
|
2415 |
this, SLOT(listBoxSelectionChanged())); |
|
2416 |
connect(d->moreFiles, SIGNAL(highlighted(Q3ListBoxItem*)), |
|
2417 |
this, SLOT(updateFileNameEdit(Q3ListBoxItem*))); |
|
2418 |
connect(d->moreFiles, SIGNAL(contextMenuRequested(Q3ListBoxItem*,QPoint)), |
|
2419 |
this, SLOT(popupContextMenu(Q3ListBoxItem*,QPoint))); |
|
2420 |
||
2421 |
d->moreFiles->installEventFilter(this); |
|
2422 |
d->moreFiles->viewport()->installEventFilter(this); |
|
2423 |
||
2424 |
okB = new QPushButton(tr("&OK"), this, "OK"); //### Or "Save (see other "OK") |
|
2425 |
okB->setDefault(true); |
|
2426 |
okB->setEnabled(false); |
|
2427 |
connect(okB, SIGNAL(clicked()), this, SLOT(okClicked())); |
|
2428 |
cancelB = new QPushButton(tr("Cancel") , this, "Cancel"); |
|
2429 |
connect(cancelB, SIGNAL(clicked()), this, SLOT(cancelClicked())); |
|
2430 |
||
2431 |
d->paths = new Q3ComboBox(true, this, "directory history/editor"); |
|
2432 |
d->paths->setDuplicatesEnabled(false); |
|
2433 |
d->paths->setInsertionPolicy(Q3ComboBox::NoInsertion); |
|
2434 |
makeVariables(); |
|
2435 |
||
2436 |
QFileInfoList rootDrives = QDir::drives(); |
|
2437 |
for (int i = 0; i < rootDrives.size(); ++i) { |
|
2438 |
QFileInfo fi = rootDrives.at(i); |
|
2439 |
d->paths->insertItem(*openFolderIcon, fi.absFilePath()); |
|
2440 |
} |
|
2441 |
||
2442 |
if (QDir::homeDirPath().size()) { |
|
2443 |
if (!d->paths->listBox()->findItem(QDir::homeDirPath())) |
|
2444 |
d->paths->insertItem(*openFolderIcon, QDir::homeDirPath()); |
|
2445 |
} |
|
2446 |
||
2447 |
connect(d->paths, SIGNAL(activated(QString)), |
|
2448 |
this, SLOT(setDir(QString))); |
|
2449 |
||
2450 |
d->paths->installEventFilter(this); |
|
2451 |
QObjectList ol = d->paths->queryList("QLineEdit"); |
|
2452 |
if (ol.size()) |
|
2453 |
ol.at(0)->installEventFilter(this); |
|
2454 |
||
2455 |
d->geometryDirty = true; |
|
2456 |
d->types = new QComboBox(true, this, "file types"); |
|
2457 |
d->types->setDuplicatesEnabled(false); |
|
2458 |
d->types->setEditable(false); |
|
2459 |
connect(d->types, SIGNAL(activated(QString)), |
|
2460 |
this, SLOT(setFilter(QString))); |
|
2461 |
connect(d->types, SIGNAL(activated(QString)), |
|
2462 |
this, SIGNAL(filterSelected(QString))); |
|
2463 |
||
2464 |
d->pathL = new QLabel(d->paths, tr("Look &in:"), this, "qt_looin_lbl"); |
|
2465 |
d->fileL = new QLabel(nameEdit, tr("File &name:"), this, "qt_filename_lbl"); |
|
2466 |
d->typeL = new QLabel(d->types, tr("File &type:"), this, "qt_filetype_lbl"); |
|
2467 |
||
2468 |
d->goBack = new QToolButton(this, "go back"); |
|
2469 |
d->goBack->setEnabled(false); |
|
2470 |
d->goBack->setFocusPolicy(Qt::TabFocus); |
|
2471 |
connect(d->goBack, SIGNAL(clicked()), this, SLOT(goBack())); |
|
2472 |
#ifndef QT_NO_TOOLTIP |
|
2473 |
QToolTip::add(d->goBack, tr("Back")); |
|
2474 |
#endif |
|
2475 |
d->goBack->setIconSet(*goBackIcon); |
|
2476 |
||
2477 |
d->cdToParent = new QToolButton(this, "cd to parent"); |
|
2478 |
d->cdToParent->setFocusPolicy(Qt::TabFocus); |
|
2479 |
#ifndef QT_NO_TOOLTIP |
|
2480 |
QToolTip::add(d->cdToParent, tr("One directory up")); |
|
2481 |
#endif |
|
2482 |
d->cdToParent->setIconSet(*cdToParentIcon); |
|
2483 |
connect(d->cdToParent, SIGNAL(clicked()), |
|
2484 |
this, SLOT(cdUpClicked())); |
|
2485 |
||
2486 |
d->newFolder = new QToolButton(this, "new folder"); |
|
2487 |
d->newFolder->setFocusPolicy(Qt::TabFocus); |
|
2488 |
#ifndef QT_NO_TOOLTIP |
|
2489 |
QToolTip::add(d->newFolder, tr("Create New Folder")); |
|
2490 |
#endif |
|
2491 |
d->newFolder->setIconSet(*newFolderIcon); |
|
2492 |
connect(d->newFolder, SIGNAL(clicked()), |
|
2493 |
this, SLOT(newFolderClicked())); |
|
2494 |
||
2495 |
d->modeButtons = new Q3ButtonGroup(0, "invisible group"); |
|
2496 |
connect(d->modeButtons, SIGNAL(destroyed()), |
|
2497 |
this, SLOT(modeButtonsDestroyed())); |
|
2498 |
d->modeButtons->setExclusive(true); |
|
2499 |
connect(d->modeButtons, SIGNAL(clicked(int)), |
|
2500 |
d->stack, SLOT(raiseWidget(int))); |
|
2501 |
connect(d->modeButtons, SIGNAL(clicked(int)), |
|
2502 |
this, SLOT(changeMode(int))); |
|
2503 |
||
2504 |
d->mcView = new QToolButton(this, "mclistbox view"); |
|
2505 |
d->mcView->setFocusPolicy(Qt::TabFocus); |
|
2506 |
#ifndef QT_NO_TOOLTIP |
|
2507 |
QToolTip::add(d->mcView, tr("List View")); |
|
2508 |
#endif |
|
2509 |
d->mcView->setIconSet(*multiColumnListViewIcon); |
|
2510 |
d->mcView->setToggleButton(true); |
|
2511 |
d->stack->addWidget(d->moreFiles, d->modeButtons->insert(d->mcView)); |
|
2512 |
d->detailView = new QToolButton(this, "list view"); |
|
2513 |
d->detailView->setFocusPolicy(Qt::TabFocus); |
|
2514 |
#ifndef QT_NO_TOOLTIP |
|
2515 |
QToolTip::add(d->detailView, tr("Detail View")); |
|
2516 |
#endif |
|
2517 |
d->detailView->setIconSet(*detailViewIcon); |
|
2518 |
d->detailView->setToggleButton(true); |
|
2519 |
d->stack->addWidget(files, d->modeButtons->insert(d->detailView)); |
|
2520 |
||
2521 |
d->previewInfo = new QToolButton(this, "preview info view"); |
|
2522 |
d->previewInfo->setFocusPolicy(Qt::TabFocus); |
|
2523 |
#ifndef QT_NO_TOOLTIP |
|
2524 |
QToolTip::add(d->previewInfo, tr("Preview File Info")); |
|
2525 |
#endif |
|
2526 |
d->previewInfo->setIconSet(*previewInfoViewIcon); |
|
2527 |
d->previewInfo->setToggleButton(true); |
|
2528 |
d->modeButtons->insert(d->previewInfo); |
|
2529 |
||
2530 |
d->previewContents = new QToolButton(this, "preview info view"); |
|
2531 |
if (!qstrcmp(style()->className(), "QWindowsStyle")) |
|
2532 |
{ |
|
2533 |
d->goBack->setAutoRaise(true); |
|
2534 |
d->cdToParent->setAutoRaise(true); |
|
2535 |
d->newFolder->setAutoRaise(true); |
|
2536 |
d->mcView->setAutoRaise(true); |
|
2537 |
d->detailView->setAutoRaise(true); |
|
2538 |
d->previewInfo->setAutoRaise(true); |
|
2539 |
d->previewContents->setAutoRaise(true); |
|
2540 |
} |
|
2541 |
d->previewContents->setFocusPolicy(Qt::TabFocus); |
|
2542 |
#ifndef QT_NO_TOOLTIP |
|
2543 |
QToolTip::add(d->previewContents, tr("Preview File Contents")); |
|
2544 |
#endif |
|
2545 |
d->previewContents->setIconSet(*previewContentsViewIcon); |
|
2546 |
d->previewContents->setToggleButton(true); |
|
2547 |
d->modeButtons->insert(d->previewContents); |
|
2548 |
||
2549 |
connect(d->detailView, SIGNAL(clicked()), |
|
2550 |
d->moreFiles, SLOT(cancelRename())); |
|
2551 |
connect(d->detailView, SIGNAL(clicked()), |
|
2552 |
files, SLOT(cancelRename())); |
|
2553 |
connect(d->mcView, SIGNAL(clicked()), |
|
2554 |
d->moreFiles, SLOT(cancelRename())); |
|
2555 |
connect(d->mcView, SIGNAL(clicked()), |
|
2556 |
files, SLOT(cancelRename())); |
|
2557 |
||
2558 |
d->stack->raiseWidget(d->moreFiles); |
|
2559 |
d->mcView->setOn(true); |
|
2560 |
||
2561 |
QHBoxLayout *lay = new QHBoxLayout(this); |
|
2562 |
lay->setMargin(6); |
|
2563 |
d->leftLayout = new QHBoxLayout(lay, 5); |
|
2564 |
d->topLevelLayout = new QVBoxLayout((QWidget*)0, 5); |
|
2565 |
lay->addLayout(d->topLevelLayout, 1); |
|
2566 |
||
2567 |
QHBoxLayout * h; |
|
2568 |
||
2569 |
d->preview = new Q3WidgetStack(d->splitter, "qt_preview"); |
|
2570 |
||
2571 |
d->infoPreviewWidget = new QWidget(d->preview, "qt_preview_info"); |
|
2572 |
d->contentsPreviewWidget = new QWidget(d->preview, "qt_preview_contents"); |
|
2573 |
d->infoPreviewer = d->contentsPreviewer = 0; |
|
2574 |
||
2575 |
h = new QHBoxLayout(0); |
|
2576 |
d->buttonLayout = h; |
|
2577 |
d->topLevelLayout->addLayout(h); |
|
2578 |
h->addWidget(d->pathL); |
|
2579 |
h->addSpacing(8); |
|
2580 |
h->addWidget(d->paths); |
|
2581 |
h->addSpacing(8); |
|
2582 |
if (d->goBack) |
|
2583 |
h->addWidget(d->goBack); |
|
2584 |
h->addWidget(d->cdToParent); |
|
2585 |
h->addSpacing(2); |
|
2586 |
h->addWidget(d->newFolder); |
|
2587 |
h->addSpacing(4); |
|
2588 |
h->addWidget(d->mcView); |
|
2589 |
h->addWidget(d->detailView); |
|
2590 |
h->addWidget(d->previewInfo); |
|
2591 |
h->addWidget(d->previewContents); |
|
2592 |
||
2593 |
d->topLevelLayout->addWidget(d->splitter); |
|
2594 |
||
2595 |
h = new QHBoxLayout(); |
|
2596 |
d->topLevelLayout->addLayout(h); |
|
2597 |
h->addWidget(d->fileL); |
|
2598 |
h->addWidget(nameEdit); |
|
2599 |
h->addSpacing(15); |
|
2600 |
h->addWidget(okB); |
|
2601 |
||
2602 |
h = new QHBoxLayout(); |
|
2603 |
d->topLevelLayout->addLayout(h); |
|
2604 |
h->addWidget(d->typeL); |
|
2605 |
h->addWidget(d->types); |
|
2606 |
h->addSpacing(15); |
|
2607 |
h->addWidget(cancelB); |
|
2608 |
||
2609 |
d->rightLayout = new QHBoxLayout(lay, 5); |
|
2610 |
d->topLevelLayout->setStretchFactor(d->mcView, 1); |
|
2611 |
d->topLevelLayout->setStretchFactor(files, 1); |
|
2612 |
||
2613 |
updateGeometries(); |
|
2614 |
||
2615 |
if (d->goBack) { |
|
2616 |
setTabOrder(d->paths, d->goBack); |
|
2617 |
setTabOrder(d->goBack, d->cdToParent); |
|
2618 |
} else { |
|
2619 |
setTabOrder(d->paths, d->cdToParent); |
|
2620 |
} |
|
2621 |
setTabOrder(d->cdToParent, d->newFolder); |
|
2622 |
setTabOrder(d->newFolder, d->mcView); |
|
2623 |
setTabOrder(d->mcView, d->detailView); |
|
2624 |
setTabOrder(d->detailView, d->moreFiles); |
|
2625 |
setTabOrder(d->moreFiles, files); |
|
2626 |
setTabOrder(files, nameEdit); |
|
2627 |
setTabOrder(nameEdit, d->types); |
|
2628 |
setTabOrder(d->types, okB); |
|
2629 |
setTabOrder(okB, cancelB); |
|
2630 |
||
2631 |
d->rw = tr("Read-write"); |
|
2632 |
d->ro = tr("Read-only"); |
|
2633 |
d->wo = tr("Write-only"); |
|
2634 |
d->inaccessible = tr("Inaccessible"); |
|
2635 |
||
2636 |
d->symLinkToFile = tr("Symlink to File"); |
|
2637 |
d->symLinkToDir = tr("Symlink to Directory"); |
|
2638 |
d->symLinkToSpecial = tr("Symlink to Special"); |
|
2639 |
d->file = tr("File"); |
|
2640 |
d->dir = tr("Dir"); |
|
2641 |
d->special = tr("Special"); |
|
2642 |
||
2643 |
if (lastWidth == 0) { |
|
2644 |
QRect screen = QApplication::desktop()->screenGeometry(pos()); |
|
2645 |
if (screen.width() < 1024 || screen.height() < 768) { |
|
2646 |
resize(qMin(screen.width(), 420), qMin(screen.height(), 236)); |
|
2647 |
} else { |
|
2648 |
QSize s = files->sizeHint(); |
|
2649 |
s = QSize(s.width() + 300, s.height() + 82); |
|
2650 |
||
2651 |
if (s.width() * 3 > screen.width() * 2) |
|
2652 |
s.setWidth(screen.width() * 2 / 3); |
|
2653 |
||
2654 |
if (s.height() * 3 > screen.height() * 2) |
|
2655 |
s.setHeight(screen.height() * 2 / 3); |
|
2656 |
else if (s.height() * 3 < screen.height()) |
|
2657 |
s.setHeight(screen.height() / 3); |
|
2658 |
||
2659 |
resize(s); |
|
2660 |
} |
|
2661 |
updateLastSize(this); |
|
2662 |
} else { |
|
2663 |
resize(lastWidth, lastHeight); |
|
2664 |
} |
|
2665 |
||
2666 |
if (detailViewMode) { |
|
2667 |
d->stack->raiseWidget(files); |
|
2668 |
d->mcView->setOn(false); |
|
2669 |
d->detailView->setOn(true); |
|
2670 |
} |
|
2671 |
||
2672 |
d->preview->hide(); |
|
2673 |
nameEdit->setFocus(); |
|
2674 |
||
2675 |
connect(nameEdit, SIGNAL(returnPressed()), |
|
2676 |
this, SLOT(fileNameEditReturnPressed())); |
|
2677 |
} |
|
2678 |
||
2679 |
/*! |
|
2680 |
\internal |
|
2681 |
*/ |
|
2682 |
||
2683 |
void Q3FileDialog::fileNameEditReturnPressed() |
|
2684 |
{ |
|
2685 |
d->oldUrl = d->url; |
|
2686 |
if (!isDirectoryMode(d->mode)) { |
|
2687 |
okClicked(); |
|
2688 |
} else { |
|
2689 |
d->currentFileName.clear(); |
|
2690 |
if (nameEdit->text().isEmpty()) { |
|
2691 |
emit fileSelected(selectedFile()); |
|
2692 |
accept(); |
|
2693 |
} else { |
|
2694 |
QUrlInfo f; |
|
2695 |
Q3FileDialogPrivate::File * c |
|
2696 |
= (Q3FileDialogPrivate::File *)files->currentItem(); |
|
2697 |
if (c && files->isSelected(c)) |
|
2698 |
f = c->info; |
|
2699 |
else |
|
2700 |
f = QUrlInfo(d->url.info(nameEdit->text().isEmpty() ? QString::fromLatin1(".") : nameEdit->text())); |
|
2701 |
if (f.isDir()) { |
|
2702 |
setUrl(Q3UrlOperator(d->url, |
|
2703 |
Q3FileDialogPrivate::encodeFileName(nameEdit->text() + QLatin1Char('/')))); |
|
2704 |
d->checkForFilter = true; |
|
2705 |
trySetSelection(true, d->url, true); |
|
2706 |
d->checkForFilter = false; |
|
2707 |
} |
|
2708 |
} |
|
2709 |
nameEdit->setText(QString()); |
|
2710 |
} |
|
2711 |
} |
|
2712 |
||
2713 |
/*! |
|
2714 |
\internal |
|
2715 |
Update the info and content preview widgets to display \a u. |
|
2716 |
*/ |
|
2717 |
||
2718 |
void Q3FileDialog::updatePreviews(const Q3Url &u) |
|
2719 |
{ |
|
2720 |
if (d->infoPreviewer) |
|
2721 |
d->infoPreviewer->previewUrl(u); |
|
2722 |
if (d->contentsPreviewer) |
|
2723 |
d->contentsPreviewer->previewUrl(u); |
|
2724 |
} |
|
2725 |
||
2726 |
/*! |
|
2727 |
\internal |
|
2728 |
Changes the preview mode to the mode specified at \a id. |
|
2729 |
*/ |
|
2730 |
||
2731 |
void Q3FileDialog::changeMode(int id) |
|
2732 |
{ |
|
2733 |
if (!d->infoPreview && !d->contentsPreview) |
|
2734 |
return; |
|
2735 |
||
2736 |
QAbstractButton*btn = d->modeButtons->find(id); |
|
2737 |
if (!btn) |
|
2738 |
return; |
|
2739 |
||
2740 |
if (btn == d->previewContents && !d->contentsPreview) |
|
2741 |
return; |
|
2742 |
if (btn == d->previewInfo && !d->infoPreview) |
|
2743 |
return; |
|
2744 |
||
2745 |
if (btn != d->previewContents && btn != d->previewInfo) { |
|
2746 |
d->preview->hide(); |
|
2747 |
} else { |
|
2748 |
if (files->currentItem()) |
|
2749 |
updatePreviews(Q3Url(d->url, files->currentItem()->text(0))); |
|
2750 |
if (btn == d->previewInfo) |
|
2751 |
d->preview->raiseWidget(d->infoPreviewWidget); |
|
2752 |
else |
|
2753 |
d->preview->raiseWidget(d->contentsPreviewWidget); |
|
2754 |
d->preview->show(); |
|
2755 |
} |
|
2756 |
} |
|
2757 |
||
2758 |
/*! |
|
2759 |
Destroys the file dialog. |
|
2760 |
*/ |
|
2761 |
||
2762 |
Q3FileDialog::~Q3FileDialog() |
|
2763 |
{ |
|
2764 |
// since clear might call setContentsPos which would emit |
|
2765 |
// a signal and thus cause a recompute of sizes... |
|
2766 |
files->blockSignals(true); |
|
2767 |
d->moreFiles->blockSignals(true); |
|
2768 |
files->clear(); |
|
2769 |
d->moreFiles->clear(); |
|
2770 |
d->moreFiles->blockSignals(false); |
|
2771 |
files->blockSignals(false); |
|
2772 |
||
2773 |
#ifndef QT_NO_CURSOR |
|
2774 |
if (d->cursorOverride) |
|
2775 |
QApplication::restoreOverrideCursor(); |
|
2776 |
#endif |
|
2777 |
||
2778 |
delete d; |
|
2779 |
d = 0; |
|
2780 |
} |
|
2781 |
||
2782 |
||
2783 |
/*! |
|
2784 |
\property Q3FileDialog::selectedFile |
|
2785 |
||
2786 |
\brief the name of the selected file |
|
2787 |
||
2788 |
If a file was selected selectedFile contains the file's name including |
|
2789 |
its absolute path; otherwise selectedFile is empty. |
|
2790 |
||
2791 |
\sa QString::isEmpty(), selectedFiles, selectedFilter |
|
2792 |
*/ |
|
2793 |
||
2794 |
QString Q3FileDialog::selectedFile() const |
|
2795 |
{ |
|
2796 |
QString s = d->currentFileName; |
|
2797 |
// remove the protocol because we do not want to encode it... |
|
2798 |
QString prot = Q3Url(s).protocol(); |
|
2799 |
if (!prot.isEmpty()) { |
|
2800 |
prot += QLatin1Char(':'); |
|
2801 |
s.remove(0, prot.length()); |
|
2802 |
} |
|
2803 |
Q3Url u(prot + Q3FileDialogPrivate::encodeFileName(s)); |
|
2804 |
if (u.isLocalFile()) { |
|
2805 |
QString s = u.toString(); |
|
2806 |
if (s.left(5) == QLatin1String("file:")) |
|
2807 |
s.remove((uint)0, 5); |
|
2808 |
return s; |
|
2809 |
} |
|
2810 |
return d->currentFileName; |
|
2811 |
} |
|
2812 |
||
2813 |
/*! |
|
2814 |
\property Q3FileDialog::selectedFilter |
|
2815 |
||
2816 |
\brief the filter which the user has selected in the file dialog |
|
2817 |
||
2818 |
\sa filterSelected(), selectedFiles, selectedFile |
|
2819 |
*/ |
|
2820 |
||
2821 |
QString Q3FileDialog::selectedFilter() const |
|
2822 |
{ |
|
2823 |
return d->types->currentText(); |
|
2824 |
} |
|
2825 |
||
2826 |
/*! \overload |
|
2827 |
||
2828 |
Sets the current filter selected in the file dialog to the |
|
2829 |
\a{n}-th filter in the filter list. |
|
2830 |
||
2831 |
\sa filterSelected(), selectedFilter(), selectedFiles(), selectedFile() |
|
2832 |
*/ |
|
2833 |
||
2834 |
void Q3FileDialog::setSelectedFilter(int n) |
|
2835 |
{ |
|
2836 |
d->types->setCurrentItem(n); |
|
2837 |
QString f = d->types->currentText(); |
|
2838 |
QRegExp r(QString::fromLatin1(qt3_file_dialog_filter_reg_exp)); |
|
2839 |
int index = r.indexIn(f); |
|
2840 |
if (index >= 0) |
|
2841 |
f = r.cap(2); |
|
2842 |
d->url.setNameFilter(f); |
|
2843 |
rereadDir(); |
|
2844 |
} |
|
2845 |
||
2846 |
/*! |
|
2847 |
Sets the current filter selected in the file dialog to the first |
|
2848 |
one that contains the text \a mask. |
|
2849 |
*/ |
|
2850 |
||
2851 |
void Q3FileDialog::setSelectedFilter(const QString& mask) |
|
2852 |
{ |
|
2853 |
int n; |
|
2854 |
||
2855 |
for (n = 0; n < d->types->count(); n++) { |
|
2856 |
if (d->types->text(n).contains(mask, Qt::CaseInsensitive)) { |
|
2857 |
d->types->setCurrentItem(n); |
|
2858 |
QString f = mask; |
|
2859 |
QRegExp r(QString::fromLatin1(qt3_file_dialog_filter_reg_exp)); |
|
2860 |
int index = r.indexIn(f); |
|
2861 |
if (index >= 0) |
|
2862 |
f = r.cap(2); |
|
2863 |
d->url.setNameFilter(f); |
|
2864 |
rereadDir(); |
|
2865 |
return; |
|
2866 |
} |
|
2867 |
} |
|
2868 |
} |
|
2869 |
||
2870 |
/*! |
|
2871 |
\property Q3FileDialog::selectedFiles |
|
2872 |
||
2873 |
\brief the list of selected files |
|
2874 |
||
2875 |
If one or more files are selected, selectedFiles contains their |
|
2876 |
names including their absolute paths. If no files are selected or |
|
2877 |
the mode isn't ExistingFiles selectedFiles is an empty list. |
|
2878 |
||
2879 |
It is more convenient to use selectedFile() if the mode is |
|
2880 |
\l ExistingFile, \c Directory or \c DirectoryOnly. |
|
2881 |
||
2882 |
Note that if you want to iterate over the list, you should |
|
2883 |
iterate over a copy, e.g. |
|
2884 |
\snippet doc/src/snippets/code/src_qt3support_dialogs_q3filedialog.cpp 8 |
|
2885 |
||
2886 |
\sa selectedFile, selectedFilter, QList::isEmpty() |
|
2887 |
*/ |
|
2888 |
||
2889 |
QStringList Q3FileDialog::selectedFiles() const |
|
2890 |
{ |
|
2891 |
QStringList lst; |
|
2892 |
||
2893 |
if (mode() == ExistingFiles) { |
|
2894 |
QStringList selectedLst; |
|
2895 |
QString selectedFiles = nameEdit->text(); |
|
2896 |
if (selectedFiles.lastIndexOf(QLatin1Char('\"')) == -1) { |
|
2897 |
//probably because Enter was pressed on the nameEdit, so we have one file |
|
2898 |
//not in "" but raw |
|
2899 |
selectedLst.append(selectedFiles); |
|
2900 |
} else { |
|
2901 |
selectedFiles.truncate(selectedFiles.lastIndexOf(QLatin1Char('\"'))); |
|
2902 |
selectedLst = selectedLst.split(QLatin1String("\" "), selectedFiles); |
|
2903 |
} |
|
2904 |
for (QStringList::Iterator it = selectedLst.begin(); it != selectedLst.end(); ++it) { |
|
2905 |
Q3Url u; |
|
2906 |
if ((*it)[0] == QLatin1Char('\"')) { |
|
2907 |
u = Q3Url(d->url, Q3FileDialogPrivate::encodeFileName((*it).mid(1))); |
|
2908 |
} else { |
|
2909 |
u = Q3Url(d->url, Q3FileDialogPrivate::encodeFileName((*it))); |
|
2910 |
} |
|
2911 |
if (u.isLocalFile()) { |
|
2912 |
QString s = u.toString(); |
|
2913 |
if (s.left(5) == QLatin1String("file:")) |
|
2914 |
s.remove((uint)0, 5); |
|
2915 |
lst << s; |
|
2916 |
} else { |
|
2917 |
lst << u.toString(); |
|
2918 |
} |
|
2919 |
} |
|
2920 |
} |
|
2921 |
||
2922 |
return lst; |
|
2923 |
} |
|
2924 |
||
2925 |
/*! |
|
2926 |
Sets the default selection to \a filename. If \a filename is |
|
2927 |
absolute, setDir() is also called to set the file dialog's working |
|
2928 |
directory to the filename's directory. |
|
2929 |
||
2930 |
\omit |
|
2931 |
Only for external use. Not useful inside Q3FileDialog. |
|
2932 |
\endomit |
|
2933 |
*/ |
|
2934 |
||
2935 |
void Q3FileDialog::setSelection(const QString & filename) |
|
2936 |
{ |
|
2937 |
d->oldUrl = d->url; |
|
2938 |
QString nf = d->url.nameFilter(); |
|
2939 |
if (Q3Url::isRelativeUrl(filename)) |
|
2940 |
d->url = Q3UrlOperator(d->url, Q3FileDialogPrivate::encodeFileName(filename)); |
|
2941 |
else |
|
2942 |
d->url = Q3UrlOperator(filename); |
|
2943 |
d->url.setNameFilter(nf); |
|
2944 |
d->checkForFilter = true; |
|
2945 |
bool isDirOk; |
|
2946 |
bool isDir = d->url.isDir(&isDirOk); |
|
2947 |
if (!isDirOk) |
|
2948 |
isDir = d->url.path().right(1) == QString(QLatin1Char('/')); |
|
2949 |
if (!isDir) { |
|
2950 |
Q3UrlOperator u(d->url); |
|
2951 |
d->url.setPath(d->url.dirPath()); |
|
2952 |
trySetSelection(false, u, true); |
|
2953 |
d->ignoreNextRefresh = true; |
|
2954 |
nameEdit->selectAll(); |
|
2955 |
rereadDir(); |
|
2956 |
emit dirEntered(d->url.dirPath()); |
|
2957 |
} else { |
|
2958 |
if (!d->url.path().isEmpty() && |
|
2959 |
d->url.path().right(1) != QString(QLatin1Char('/'))) { |
|
2960 |
QString p = d->url.path(); |
|
2961 |
p += QLatin1Char('/'); |
|
2962 |
d->url.setPath(p); |
|
2963 |
} |
|
2964 |
trySetSelection(true, d->url, false); |
|
2965 |
rereadDir(); |
|
2966 |
emit dirEntered(d->url.dirPath()); |
|
2967 |
nameEdit->setText(QString::fromLatin1("")); |
|
2968 |
} |
|
2969 |
d->checkForFilter = false; |
|
2970 |
} |
|
2971 |
||
2972 |
/*! |
|
2973 |
\property Q3FileDialog::dirPath |
|
2974 |
||
2975 |
\brief the file dialog's working directory |
|
2976 |
||
2977 |
\sa dir(), setDir() |
|
2978 |
*/ |
|
2979 |
||
2980 |
QString Q3FileDialog::dirPath() const |
|
2981 |
{ |
|
2982 |
return d->url.dirPath(); |
|
2983 |
} |
|
2984 |
||
2985 |
||
2986 |
/*! |
|
2987 |
||
2988 |
Sets the filter used in the file dialog to \a newFilter. |
|
2989 |
||
2990 |
If \a newFilter contains a pair of parentheses containing one or more |
|
2991 |
of "anything*something" separated by spaces or by |
|
2992 |
semicolons then only the text contained in the parentheses is used as |
|
2993 |
the filter. This means that these calls are all equivalent: |
|
2994 |
||
2995 |
\snippet doc/src/snippets/code/src_qt3support_dialogs_q3filedialog.cpp 9 |
|
2996 |
||
2997 |
\sa setFilters() |
|
2998 |
*/ |
|
2999 |
||
3000 |
void Q3FileDialog::setFilter(const QString & newFilter) |
|
3001 |
{ |
|
3002 |
if (newFilter.isEmpty()) |
|
3003 |
return; |
|
3004 |
QString f = newFilter; |
|
3005 |
QRegExp r(QString::fromLatin1(qt3_file_dialog_filter_reg_exp)); |
|
3006 |
int index = r.indexIn(f); |
|
3007 |
if (index >= 0) |
|
3008 |
f = r.cap(2); |
|
3009 |
d->url.setNameFilter(f); |
|
3010 |
if (d->types->count() == 1) { |
|
3011 |
d->types->clear(); |
|
3012 |
d->types->insertItem(newFilter); |
|
3013 |
} else { |
|
3014 |
for (int i = 0; i < d->types->count(); ++i) { |
|
3015 |
if (d->types->text(i).left(newFilter.length()) == newFilter || |
|
3016 |
d->types->text(i).left(f.length()) == f) { |
|
3017 |
d->types->setCurrentItem(i); |
|
3018 |
break; |
|
3019 |
} |
|
3020 |
} |
|
3021 |
} |
|
3022 |
rereadDir(); |
|
3023 |
} |
|
3024 |
||
3025 |
||
3026 |
/*! \overload |
|
3027 |
Sets the file dialog's working directory to \a pathstr. |
|
3028 |
||
3029 |
\sa dir() |
|
3030 |
*/ |
|
3031 |
||
3032 |
void Q3FileDialog::setDir(const QString & pathstr) |
|
3033 |
{ |
|
3034 |
QString dr = pathstr; |
|
3035 |
if (dr.isEmpty()) |
|
3036 |
return; |
|
3037 |
||
3038 |
#if defined(Q_OS_UNIX) |
|
3039 |
if (dr.length() && dr[0] == QLatin1Char('~')) { |
|
3040 |
int i = 0; |
|
3041 |
while(i < (int)dr.length() && dr[i] != QLatin1Char('/')) |
|
3042 |
i++; |
|
3043 |
Q3CString user; |
|
3044 |
if (i == 1) { |
|
3045 |
#if !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) |
|
3046 |
||
3047 |
# ifndef _POSIX_LOGIN_NAME_MAX |
|
3048 |
# define _POSIX_LOGIN_NAME_MAX 9 |
|
3049 |
# endif |
|
3050 |
||
3051 |
char name[_POSIX_LOGIN_NAME_MAX]; |
|
3052 |
if (::getlogin_r(name, _POSIX_LOGIN_NAME_MAX) == 0) |
|
3053 |
user = name; |
|
3054 |
else |
|
3055 |
#else |
|
3056 |
user = ::getlogin(); |
|
3057 |
if (user.isEmpty()) |
|
3058 |
#endif |
|
3059 |
user = qgetenv("LOGNAME"); |
|
3060 |
} else |
|
3061 |
user = dr.mid(1, i-1).local8Bit(); |
|
3062 |
dr = dr.mid(i, dr.length()); |
|
3063 |
struct passwd *pw; |
|
3064 |
#if !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) && !defined(Q_OS_FREEBSD) && !defined(Q_OS_OPENBSD) |
|
3065 |
struct passwd mt_pw; |
|
3066 |
char buffer[2048]; |
|
3067 |
if (::getpwnam_r(user, &mt_pw, buffer, 2048, &pw) == 0 && pw == &mt_pw) |
|
3068 |
#else |
|
3069 |
pw = ::getpwnam(user); |
|
3070 |
if (pw) |
|
3071 |
#endif |
|
3072 |
dr.prepend(QString::fromLocal8Bit(pw->pw_dir)); |
|
3073 |
} |
|
3074 |
#endif |
|
3075 |
||
3076 |
setUrl(dr); |
|
3077 |
} |
|
3078 |
||
3079 |
/*! |
|
3080 |
Returns the current directory shown in the file dialog. |
|
3081 |
||
3082 |
The ownership of the QDir pointer is transferred to the caller, so |
|
3083 |
it must be deleted by the caller when no longer required. |
|
3084 |
||
3085 |
\sa setDir() |
|
3086 |
*/ |
|
3087 |
||
3088 |
const QDir *Q3FileDialog::dir() const |
|
3089 |
{ |
|
3090 |
if (d->url.isLocalFile()) |
|
3091 |
return new QDir(d->url.path()); |
|
3092 |
else |
|
3093 |
return 0; |
|
3094 |
} |
|
3095 |
||
3096 |
/*! |
|
3097 |
Sets the file dialog's working directory to \a dir. |
|
3098 |
\sa dir() |
|
3099 |
*/ |
|
3100 |
||
3101 |
void Q3FileDialog::setDir(const QDir &dir) |
|
3102 |
{ |
|
3103 |
d->oldUrl = d->url; |
|
3104 |
QString nf(d->url.nameFilter()); |
|
3105 |
d->url = dir.canonicalPath(); |
|
3106 |
d->url.setNameFilter(nf); |
|
3107 |
QUrlInfo i(d->url.info(nameEdit->text().isEmpty()? QString::fromLatin1(".") : nameEdit->text())); |
|
3108 |
d->checkForFilter = true; |
|
3109 |
trySetSelection(i.isDir(), Q3UrlOperator(d->url, Q3FileDialogPrivate::encodeFileName(nameEdit->text())), false); |
|
3110 |
d->checkForFilter = false; |
|
3111 |
rereadDir(); |
|
3112 |
emit dirEntered(d->url.path()); |
|
3113 |
} |
|
3114 |
||
3115 |
/*! |
|
3116 |
Sets the file dialog's working directory to the directory specified at \a url. |
|
3117 |
||
3118 |
\sa url() |
|
3119 |
*/ |
|
3120 |
||
3121 |
void Q3FileDialog::setUrl(const Q3UrlOperator &url) |
|
3122 |
{ |
|
3123 |
d->oldUrl = d->url; |
|
3124 |
QString nf = d->url.nameFilter(); |
|
3125 |
||
3126 |
QString operatorPath = url.toString(false, false); |
|
3127 |
if (Q3Url::isRelativeUrl(operatorPath)) { |
|
3128 |
d->url = Q3Url(d->url, operatorPath); |
|
3129 |
} else { |
|
3130 |
d->url = url; |
|
3131 |
} |
|
3132 |
d->url.setNameFilter(nf); |
|
3133 |
||
3134 |
d->checkForFilter = true; |
|
3135 |
if (!d->url.isDir()) { |
|
3136 |
Q3UrlOperator u = d->url; |
|
3137 |
d->url.setPath(d->url.dirPath()); |
|
3138 |
trySetSelection(false, u, false); |
|
3139 |
rereadDir(); |
|
3140 |
emit dirEntered(d->url.dirPath()); |
|
3141 |
QString fn = u.fileName(); |
|
3142 |
nameEdit->setText(fn); |
|
3143 |
} else { |
|
3144 |
trySetSelection(true, d->url, false); |
|
3145 |
rereadDir(); |
|
3146 |
emit dirEntered(d->url.dirPath()); |
|
3147 |
} |
|
3148 |
d->checkForFilter = false; |
|
3149 |
} |
|
3150 |
||
3151 |
/*! |
|
3152 |
\property Q3FileDialog::showHiddenFiles |
|
3153 |
||
3154 |
\brief whether hidden files are shown in the file dialog |
|
3155 |
||
3156 |
The default is false, i.e. don't show hidden files. |
|
3157 |
*/ |
|
3158 |
||
3159 |
void Q3FileDialog::setShowHiddenFiles(bool s) |
|
3160 |
{ |
|
3161 |
if (s == bShowHiddenFiles) |
|
3162 |
return; |
|
3163 |
||
3164 |
bShowHiddenFiles = s; |
|
3165 |
rereadDir(); |
|
3166 |
} |
|
3167 |
||
3168 |
bool Q3FileDialog::showHiddenFiles() const |
|
3169 |
{ |
|
3170 |
return bShowHiddenFiles; |
|
3171 |
} |
|
3172 |
||
3173 |
/*! |
|
3174 |
Rereads the current directory shown in the file dialog. |
|
3175 |
||
3176 |
The only time you will need to call this function is if the contents of |
|
3177 |
the directory change and you wish to refresh the file dialog to reflect |
|
3178 |
the change. |
|
3179 |
||
3180 |
\sa resortDir() |
|
3181 |
*/ |
|
3182 |
||
3183 |
void Q3FileDialog::rereadDir() |
|
3184 |
{ |
|
3185 |
#ifndef QT_NO_CURSOR |
|
3186 |
if (!d->cursorOverride) { |
|
3187 |
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); |
|
3188 |
d->cursorOverride = true; |
|
3189 |
} |
|
3190 |
#endif |
|
3191 |
d->pendingItems.clear(); |
|
3192 |
if (d->mimeTypeTimer->isActive()) |
|
3193 |
d->mimeTypeTimer->stop(); |
|
3194 |
d->currListChildren = d->url.listChildren(); |
|
3195 |
#ifndef QT_NO_CURSOR |
|
3196 |
if (d->cursorOverride) { |
|
3197 |
QApplication::restoreOverrideCursor(); |
|
3198 |
d->cursorOverride = false; |
|
3199 |
} |
|
3200 |
#endif |
|
3201 |
} |
|
3202 |
||
3203 |
||
3204 |
/*! |
|
3205 |
\fn void Q3FileDialog::fileHighlighted(const QString& file) |
|
3206 |
||
3207 |
This signal is emitted when the user highlights the given \a file, |
|
3208 |
i.e. makes it the current file. |
|
3209 |
||
3210 |
\sa fileSelected(), filesSelected() |
|
3211 |
*/ |
|
3212 |
||
3213 |
/*! |
|
3214 |
\fn void Q3FileDialog::fileSelected(const QString& file) |
|
3215 |
||
3216 |
This signal is emitted when the user selects the given \a file. |
|
3217 |
||
3218 |
\sa filesSelected(), fileHighlighted(), selectedFile() |
|
3219 |
*/ |
|
3220 |
||
3221 |
/*! |
|
3222 |
\fn void Q3FileDialog::filesSelected(const QStringList& files) |
|
3223 |
||
3224 |
This signal is emitted when the user selects the given \a files in \e |
|
3225 |
ExistingFiles mode. |
|
3226 |
||
3227 |
\sa fileSelected(), fileHighlighted(), selectedFiles() |
|
3228 |
*/ |
|
3229 |
||
3230 |
/*! |
|
3231 |
\fn void Q3FileDialog::dirEntered(const QString& directory) |
|
3232 |
||
3233 |
This signal is emitted when the user enters the given \a directory. |
|
3234 |
||
3235 |
\sa dir() |
|
3236 |
*/ |
|
3237 |
||
3238 |
/*! |
|
3239 |
\fn void Q3FileDialog::filterSelected(const QString& filter) |
|
3240 |
||
3241 |
This signal is emitted when the user selects the given \a filter. |
|
3242 |
||
3243 |
\sa selectedFilter() |
|
3244 |
*/ |
|
3245 |
||
3246 |
extern bool qt_resolve_symlinks; // defined in q3url.cpp |
|
3247 |
extern Q_GUI_EXPORT bool qt_use_native_dialogs; //qtgui |
|
3248 |
||
3249 |
/*! |
|
3250 |
This is a convenience static function that returns an existing file |
|
3251 |
selected by the user. If the user pressed Cancel, it returns a null |
|
3252 |
string. |
|
3253 |
||
3254 |
\snippet doc/src/snippets/code/src_qt3support_dialogs_q3filedialog.cpp 10 |
|
3255 |
||
3256 |
The function creates a modal file dialog called \a name, with |
|
3257 |
parent, \a parent. If a parent is not 0, the dialog will be shown |
|
3258 |
centered over the parent. |
|
3259 |
||
3260 |
The file dialog's working directory will be set to \a startWith. If \a |
|
3261 |
startWith includes a file name, the file will be selected. The filter |
|
3262 |
is set to \a filter so that only those files which match the filter |
|
3263 |
are shown. The filter selected is set to \a selectedFilter. The parameters |
|
3264 |
\a startWith, \a selectedFilter and \a filter may be an empty string. |
|
3265 |
||
3266 |
The dialog's caption is set to \a caption. If \a caption is not |
|
3267 |
specified then a default caption will be used. |
|
3268 |
||
3269 |
Under Windows and Mac OS X, this static function will use the native |
|
3270 |
file dialog and not a Q3FileDialog, unless the style of the application |
|
3271 |
is set to something other than the native style (Note that on Windows the |
|
3272 |
dialog will spin a blocking modal event loop that will not dispatch any |
|
3273 |
QTimers and if parent is not 0 then it will position the dialog just under |
|
3274 |
the parent's title bar). |
|
3275 |
||
3276 |
Under Unix/X11, the normal behavior of the file dialog is to resolve |
|
3277 |
and follow symlinks. For example, if /usr/tmp is a symlink to /var/tmp, |
|
3278 |
the file dialog will change to /var/tmp after entering /usr/tmp. |
|
3279 |
If \a resolveSymlinks is false, the file dialog will treat |
|
3280 |
symlinks as regular directories. |
|
3281 |
||
3282 |
\sa getOpenFileNames(), getSaveFileName(), getExistingDirectory() |
|
3283 |
*/ |
|
3284 |
||
3285 |
QString Q3FileDialog::getOpenFileName(const QString & startWith, |
|
3286 |
const QString& filter, |
|
3287 |
QWidget *parent, const char* name, |
|
3288 |
const QString& caption, |
|
3289 |
QString *selectedFilter, |
|
3290 |
bool resolveSymlinks) |
|
3291 |
{ |
|
3292 |
bool save_qt_resolve_symlinks = qt_resolve_symlinks; |
|
3293 |
qt_resolve_symlinks = resolveSymlinks; |
|
3294 |
||
3295 |
QStringList filters; |
|
3296 |
if (!filter.isEmpty()) |
|
3297 |
filters = makeFiltersList(filter); |
|
3298 |
||
3299 |
makeVariables(); |
|
3300 |
QString initialSelection; |
|
3301 |
//### Problem with the logic here: If a startWith is given and a file |
|
3302 |
// with that name exists in D->URL, the box will be opened at D->URL instead of |
|
3303 |
// the last directory used ('workingDirectory'). |
|
3304 |
// |
|
3305 |
// hm... isn't that problem exactly the documented behaviour? the |
|
3306 |
// documented behaviour sounds meaningful. |
|
3307 |
if (!startWith.isEmpty()) { |
|
3308 |
Q3UrlOperator u(Q3FileDialogPrivate::encodeFileName(startWith)); |
|
3309 |
if (u.isLocalFile() && QFileInfo(u.path()).isDir()) { |
|
3310 |
*workingDirectory = startWith; |
|
3311 |
} else { |
|
3312 |
if (u.isLocalFile()) { |
|
3313 |
QFileInfo fi(u.dirPath()); |
|
3314 |
if (fi.exists()) { |
|
3315 |
*workingDirectory = u.dirPath(); |
|
3316 |
initialSelection = u.fileName(); |
|
3317 |
} |
|
3318 |
} else { |
|
3319 |
*workingDirectory = u.toString(); |
|
3320 |
initialSelection.clear(); |
|
3321 |
} |
|
3322 |
} |
|
3323 |
} |
|
3324 |
||
3325 |
if (workingDirectory->isNull()) |
|
3326 |
*workingDirectory = toRootIfNotExists( QDir::currentDirPath() ); |
|
3327 |
||
3328 |
#if defined(Q_WS_WIN) |
|
3329 |
if (qt_use_native_dialogs && qobject_cast<QWindowsStyle *>(qApp->style())) |
|
3330 |
return winGetOpenFileName(initialSelection, filter, workingDirectory, |
|
3331 |
parent, name, caption, selectedFilter); |
|
3332 |
#elif defined(Q_WS_MAC) |
|
3333 |
if(qt_use_native_dialogs && qobject_cast<QMacStyle *>(qApp->style())) { |
|
3334 |
QStringList files = macGetOpenFileNames(filter, startWith.isEmpty() ? 0 : workingDirectory, |
|
3335 |
parent, name, caption, selectedFilter, false); |
|
3336 |
return files.isEmpty() ? QString() : files.first().normalized(QString::NormalizationForm_C); |
|
3337 |
} |
|
3338 |
#endif |
|
3339 |
||
3340 |
Q3FileDialog *dlg = new Q3FileDialog(*workingDirectory, QString(), parent, name ? name : "qt_filedlg_gofn", true); |
|
3341 |
||
3342 |
if (!caption.isNull()) |
|
3343 |
dlg->setWindowTitle(caption); |
|
3344 |
else |
|
3345 |
dlg->setWindowTitle(Q3FileDialog::tr("Open")); |
|
3346 |
||
3347 |
dlg->setFilters(filters); |
|
3348 |
if (selectedFilter) |
|
3349 |
dlg->setFilter(*selectedFilter); |
|
3350 |
dlg->setMode(Q3FileDialog::ExistingFile); |
|
3351 |
QString result; |
|
3352 |
if (!initialSelection.isEmpty()) |
|
3353 |
dlg->setSelection(initialSelection); |
|
3354 |
if (dlg->exec() == QDialog::Accepted) { |
|
3355 |
result = dlg->selectedFile(); |
|
3356 |
*workingDirectory = dlg->d->url; |
|
3357 |
if (selectedFilter) |
|
3358 |
*selectedFilter = dlg->selectedFilter(); |
|
3359 |
} |
|
3360 |
delete dlg; |
|
3361 |
||
3362 |
qt_resolve_symlinks = save_qt_resolve_symlinks; |
|
3363 |
||
3364 |
return result; |
|
3365 |
} |
|
3366 |
||
3367 |
/*! |
|
3368 |
This is a convenience static function that will return a file name |
|
3369 |
selected by the user. The file does not have to exist. |
|
3370 |
||
3371 |
It creates a modal file dialog called \a name, with parent, \a parent. |
|
3372 |
If a parent is not 0, the dialog will be shown centered over the |
|
3373 |
parent. |
|
3374 |
||
3375 |
\snippet doc/src/snippets/code/src_qt3support_dialogs_q3filedialog.cpp 11 |
|
3376 |
||
3377 |
The file dialog's working directory will be set to \a startWith. If \a |
|
3378 |
startWith includes a file name, the file will be selected. The filter |
|
3379 |
is set to \a filter so that only those files which match the filter |
|
3380 |
are shown. The filter selected is set to \a selectedFilter. The parameters |
|
3381 |
\a startWith, \a selectedFilter and \a filter may be an empty string. |
|
3382 |
||
3383 |
The dialog's caption is set to \a caption. If \a caption is not |
|
3384 |
specified then a default caption will be used. |
|
3385 |
||
3386 |
Under Windows and Mac OS X, this static function will use the native |
|
3387 |
file dialog and not a Q3FileDialog, unless the style of the application |
|
3388 |
is set to something other than the native style. (Note that on Windows the |
|
3389 |
dialog will spin a blocking modal event loop that will not dispatch any |
|
3390 |
QTimers and if parent is not 0 then it will position the dialog just under |
|
3391 |
the parent's title bar. And on the Mac the filter argument is ignored). |
|
3392 |
||
3393 |
Under Unix/X11, the normal behavior of the file dialog is to resolve |
|
3394 |
and follow symlinks. For example, if /usr/tmp is a symlink to /var/tmp, |
|
3395 |
the file dialog will change to /var/tmp after entering /usr/tmp. |
|
3396 |
If \a resolveSymlinks is false, the file dialog will treat |
|
3397 |
symlinks as regular directories. |
|
3398 |
||
3399 |
\sa getOpenFileName(), getOpenFileNames(), getExistingDirectory() |
|
3400 |
*/ |
|
3401 |
||
3402 |
QString Q3FileDialog::getSaveFileName(const QString & startWith, |
|
3403 |
const QString& filter, |
|
3404 |
QWidget *parent, const char* name, |
|
3405 |
const QString& caption, |
|
3406 |
QString *selectedFilter, |
|
3407 |
bool resolveSymlinks) |
|
3408 |
{ |
|
3409 |
bool save_qt_resolve_symlinks = qt_resolve_symlinks; |
|
3410 |
qt_resolve_symlinks = resolveSymlinks; |
|
3411 |
||
3412 |
QStringList filters; |
|
3413 |
if (!filter.isEmpty()) |
|
3414 |
filters = makeFiltersList(filter); |
|
3415 |
||
3416 |
makeVariables(); |
|
3417 |
QString initialSelection; |
|
3418 |
if (!startWith.isEmpty()) { |
|
3419 |
Q3UrlOperator u(Q3FileDialogPrivate::encodeFileName(startWith)); |
|
3420 |
if (u.isLocalFile() && QFileInfo(u.path()).isDir()) { |
|
3421 |
*workingDirectory = startWith; |
|
3422 |
} else { |
|
3423 |
if (u.isLocalFile()) { |
|
3424 |
QFileInfo fi(u.dirPath()); |
|
3425 |
if (fi.exists()) { |
|
3426 |
*workingDirectory = u.dirPath(); |
|
3427 |
initialSelection = u.fileName(); |
|
3428 |
} |
|
3429 |
} else { |
|
3430 |
*workingDirectory = u.toString(); |
|
3431 |
initialSelection.clear(); |
|
3432 |
} |
|
3433 |
} |
|
3434 |
} |
|
3435 |
||
3436 |
if (workingDirectory->isNull()) |
|
3437 |
*workingDirectory = toRootIfNotExists( QDir::currentDirPath() ); |
|
3438 |
||
3439 |
#if defined(Q_WS_WIN) |
|
3440 |
if (qt_use_native_dialogs && qobject_cast<QWindowsStyle *>(qApp->style())) |
|
3441 |
return winGetSaveFileName(initialSelection, filter, workingDirectory, |
|
3442 |
parent, name, caption, selectedFilter); |
|
3443 |
#elif defined(Q_WS_MAC) |
|
3444 |
if(qt_use_native_dialogs && qobject_cast<QMacStyle *>(qApp->style())) |
|
3445 |
return macGetSaveFileName(initialSelection.isNull() ? startWith : initialSelection, |
|
3446 |
filter, startWith.isEmpty() ? 0 : workingDirectory, parent, name, |
|
3447 |
caption, selectedFilter).normalized(QString::NormalizationForm_C); |
|
3448 |
#endif |
|
3449 |
||
3450 |
Q3FileDialog *dlg = new Q3FileDialog(*workingDirectory, QString(), parent, name ? name : "qt_filedlg_gsfn", true); |
|
3451 |
||
3452 |
if (!caption.isNull()) |
|
3453 |
dlg->setWindowTitle(caption); |
|
3454 |
else |
|
3455 |
dlg->setWindowTitle(Q3FileDialog::tr("Save As")); |
|
3456 |
||
3457 |
QString result; |
|
3458 |
dlg->setFilters(filters); |
|
3459 |
if (selectedFilter) |
|
3460 |
dlg->setFilter(*selectedFilter); |
|
3461 |
dlg->setMode(Q3FileDialog::AnyFile); |
|
3462 |
if (!initialSelection.isEmpty()) |
|
3463 |
dlg->setSelection(initialSelection); |
|
3464 |
if (dlg->exec() == QDialog::Accepted) { |
|
3465 |
result = dlg->selectedFile(); |
|
3466 |
*workingDirectory = dlg->d->url; |
|
3467 |
if (selectedFilter) |
|
3468 |
*selectedFilter = dlg->selectedFilter(); |
|
3469 |
} |
|
3470 |
delete dlg; |
|
3471 |
||
3472 |
qt_resolve_symlinks = save_qt_resolve_symlinks; |
|
3473 |
||
3474 |
return result; |
|
3475 |
} |
|
3476 |
||
3477 |
/*! |
|
3478 |
\internal |
|
3479 |
Activated when the "OK" button is clicked. |
|
3480 |
*/ |
|
3481 |
||
3482 |
void Q3FileDialog::okClicked() |
|
3483 |
{ |
|
3484 |
QString fn(nameEdit->text()); |
|
3485 |
||
3486 |
#if defined(Q_WS_WIN) |
|
3487 |
QFileInfo fi(d->url.path() + fn); |
|
3488 |
if (fi.isSymLink()) { |
|
3489 |
nameEdit->setText(fi.symLinkTarget()); |
|
3490 |
} |
|
3491 |
#endif |
|
3492 |
||
3493 |
if (fn.contains(QLatin1Char('*'))) { |
|
3494 |
addFilter(fn); |
|
3495 |
nameEdit->blockSignals(true); |
|
3496 |
nameEdit->setText(QString::fromLatin1("")); |
|
3497 |
nameEdit->blockSignals(false); |
|
3498 |
return; |
|
3499 |
} |
|
3500 |
||
3501 |
*workingDirectory = d->url; |
|
3502 |
detailViewMode = files->isVisible(); |
|
3503 |
updateLastSize(this); |
|
3504 |
||
3505 |
if (isDirectoryMode(d->mode)) { |
|
3506 |
QUrlInfo f(d->url.info(nameEdit->text().isEmpty() ? QString::fromLatin1(".") : nameEdit->text())); |
|
3507 |
if (f.isDir()) { |
|
3508 |
d->currentFileName = d->url; |
|
3509 |
if (d->currentFileName.right(1) != QString(QLatin1Char('/'))) |
|
3510 |
d->currentFileName += QLatin1Char('/'); |
|
3511 |
if (f.name() != QString(QLatin1Char('.'))) |
|
3512 |
d->currentFileName += f.name(); |
|
3513 |
accept(); |
|
3514 |
return; |
|
3515 |
} |
|
3516 |
// Since it's not a directory and we clicked ok, we |
|
3517 |
// don't really want to do anything else |
|
3518 |
return; |
|
3519 |
} |
|
3520 |
||
3521 |
// if we're in multi-selection mode and something is selected, |
|
3522 |
// accept it and be done. |
|
3523 |
if (mode() == ExistingFiles) { |
|
3524 |
if (! nameEdit->text().isEmpty()) { |
|
3525 |
QStringList sf = selectedFiles(); |
|
3526 |
bool isdir = false; |
|
3527 |
if (sf.count() == 1) { |
|
3528 |
Q3UrlOperator u(d->url, sf[0]); |
|
3529 |
bool ok; |
|
3530 |
isdir = u.isDir(&ok) && ok; |
|
3531 |
} |
|
3532 |
if (!isdir) { |
|
3533 |
emit filesSelected(sf); |
|
3534 |
accept(); |
|
3535 |
return; |
|
3536 |
} |
|
3537 |
} |
|
3538 |
} |
|
3539 |
||
3540 |
if (mode() == AnyFile) { |
|
3541 |
Q3UrlOperator u(d->url, Q3FileDialogPrivate::encodeFileName(nameEdit->text())); |
|
3542 |
if (!u.isDir()) { |
|
3543 |
d->currentFileName = u; |
|
3544 |
emit fileSelected(selectedFile()); |
|
3545 |
accept(); |
|
3546 |
return; |
|
3547 |
} |
|
3548 |
} |
|
3549 |
||
3550 |
if (mode() == ExistingFile) { |
|
3551 |
if (!Q3FileDialogPrivate::fileExists(d->url, nameEdit->text())) |
|
3552 |
return; |
|
3553 |
} |
|
3554 |
||
3555 |
// If selection is valid, return it, else try |
|
3556 |
// using selection as a directory to change to. |
|
3557 |
if (!d->currentFileName.isNull() && !d->currentFileName.contains(QLatin1Char('*'))) { |
|
3558 |
emit fileSelected(selectedFile()); |
|
3559 |
accept(); |
|
3560 |
} else { |
|
3561 |
QUrlInfo f; |
|
3562 |
Q3FileDialogPrivate::File * c |
|
3563 |
= (Q3FileDialogPrivate::File *)files->currentItem(); |
|
3564 |
Q3FileDialogPrivate::MCItem * m |
|
3565 |
= (Q3FileDialogPrivate::MCItem *)d->moreFiles->item(d->moreFiles->currentItem()); |
|
3566 |
if ((c && files->isVisible() && files->hasFocus()) |
|
3567 |
|| (m && d->moreFiles->isVisible())) { |
|
3568 |
if (c && files->isVisible()) |
|
3569 |
f = c->info; |
|
3570 |
else |
|
3571 |
f = ((Q3FileDialogPrivate::File*)m->i)->info; |
|
3572 |
} else { |
|
3573 |
f = QUrlInfo(d->url.info(nameEdit->text().isEmpty() ? QString::fromLatin1(".") : nameEdit->text())); |
|
3574 |
} |
|
3575 |
if (f.isDir()) { |
|
3576 |
#if defined(Q_WS_WIN) |
|
3577 |
if (f.isSymLink()) |
|
3578 |
setUrl(Q3UrlOperator(d->url, Q3FileDialogPrivate::encodeFileName(fn + QLatin1Char('/')))); |
|
3579 |
else |
|
3580 |
#else |
|
3581 |
setUrl(Q3UrlOperator(d->url, Q3FileDialogPrivate::encodeFileName(f.name() + QLatin1Char('/')))); |
|
3582 |
#endif |
|
3583 |
d->checkForFilter = true; |
|
3584 |
trySetSelection(true, d->url, true); |
|
3585 |
d->checkForFilter = false; |
|
3586 |
} else { |
|
3587 |
if (!nameEdit->text().contains(QLatin1Char('/')) && |
|
3588 |
!nameEdit->text().contains(QLatin1String("\\")) |
|
3589 |
#if defined(Q_OS_WIN32) |
|
3590 |
&& nameEdit->text()[1] != QLatin1Char(':') |
|
3591 |
#endif |
|
3592 |
) |
|
3593 |
addFilter(nameEdit->text()); |
|
3594 |
else if (nameEdit->text()[0] == QLatin1Char('/') || |
|
3595 |
nameEdit->text()[0] == QLatin1Char('\\') |
|
3596 |
#if defined(Q_OS_WIN32) |
|
3597 |
|| nameEdit->text()[1] == QLatin1Char(':') |
|
3598 |
#endif |
|
3599 |
) |
|
3600 |
setDir(nameEdit->text()); |
|
3601 |
else if (nameEdit->text().left(3) == QLatin1String("../") || nameEdit->text().left(3) == QLatin1String("..\\")) |
|
3602 |
setDir(Q3Url(d->url.toString(), Q3FileDialogPrivate::encodeFileName(nameEdit->text())).toString()); |
|
3603 |
} |
|
3604 |
nameEdit->setText(QLatin1String("")); |
|
3605 |
} |
|
3606 |
} |
|
3607 |
||
3608 |
/*! |
|
3609 |
\internal |
|
3610 |
Activated when the "Filter" button is clicked. |
|
3611 |
*/ |
|
3612 |
||
3613 |
void Q3FileDialog::filterClicked() |
|
3614 |
{ |
|
3615 |
// unused |
|
3616 |
} |
|
3617 |
||
3618 |
/*! |
|
3619 |
\internal |
|
3620 |
Activated when the "Cancel" button is clicked. |
|
3621 |
*/ |
|
3622 |
||
3623 |
void Q3FileDialog::cancelClicked() |
|
3624 |
{ |
|
3625 |
*workingDirectory = d->url; |
|
3626 |
detailViewMode = files->isVisible(); |
|
3627 |
updateLastSize(this); |
|
3628 |
reject(); |
|
3629 |
} |
|
3630 |
||
3631 |
||
3632 |
/*!\reimp |
|
3633 |
*/ |
|
3634 |
||
3635 |
void Q3FileDialog::resizeEvent(QResizeEvent * e) |
|
3636 |
{ |
|
3637 |
QDialog::resizeEvent(e); |
|
3638 |
updateGeometries(); |
|
3639 |
} |
|
3640 |
||
3641 |
/* |
|
3642 |
\internal |
|
3643 |
The only correct way to try to set currentFileName |
|
3644 |
*/ |
|
3645 |
bool Q3FileDialog::trySetSelection(bool isDir, const Q3UrlOperator &u, bool updatelined) |
|
3646 |
{ |
|
3647 |
if (!isDir && !u.path().isEmpty() && u.path().right(1) == QString(QLatin1Char('/'))) |
|
3648 |
isDir = true; |
|
3649 |
if (u.fileName().contains(QLatin1Char('*')) && d->checkForFilter) { |
|
3650 |
QString fn(u.fileName()); |
|
3651 |
if (fn.contains(QLatin1Char('*'))) { |
|
3652 |
addFilter(fn); |
|
3653 |
d->currentFileName.clear(); |
|
3654 |
d->url.setFileName(QString()); |
|
3655 |
nameEdit->setText(QString::fromLatin1("")); |
|
3656 |
return false; |
|
3657 |
} |
|
3658 |
} |
|
3659 |
||
3660 |
if (isDir && d->preview && d->preview->isVisible()) |
|
3661 |
updatePreviews(u); |
|
3662 |
||
3663 |
QString old = d->currentFileName; |
|
3664 |
||
3665 |
if (isDirectoryMode(mode())) { |
|
3666 |
if (isDir) |
|
3667 |
d->currentFileName = u; |
|
3668 |
else |
|
3669 |
d->currentFileName.clear(); |
|
3670 |
} else if (!isDir && mode() == ExistingFiles) { |
|
3671 |
d->currentFileName = u; |
|
3672 |
} else if (!isDir || (mode() == AnyFile && !isDir)) { |
|
3673 |
d->currentFileName = u; |
|
3674 |
} else { |
|
3675 |
d->currentFileName.clear(); |
|
3676 |
} |
|
3677 |
if (updatelined && !d->currentFileName.isEmpty()) { |
|
3678 |
// If the selection is valid, or if its a directory, allow OK. |
|
3679 |
if (!d->currentFileName.isNull() || isDir) { |
|
3680 |
if (u.fileName() != QLatin1String("..")) { |
|
3681 |
QString fn = u.fileName(); |
|
3682 |
nameEdit->setText(fn); |
|
3683 |
} else { |
|
3684 |
nameEdit->setText(QLatin1String("")); |
|
3685 |
} |
|
3686 |
} else |
|
3687 |
nameEdit->setText(QString::fromLatin1("")); |
|
3688 |
} |
|
3689 |
||
3690 |
if (!d->currentFileName.isNull() || isDir) { |
|
3691 |
okB->setEnabled(true); |
|
3692 |
} else if (!isDirectoryMode(d->mode)) { |
|
3693 |
okB->setEnabled(false); |
|
3694 |
} |
|
3695 |
||
3696 |
if (d->currentFileName.length() && old != d->currentFileName) |
|
3697 |
emit fileHighlighted(selectedFile()); |
|
3698 |
||
3699 |
return !d->currentFileName.isNull(); |
|
3700 |
} |
|
3701 |
||
3702 |
||
3703 |
/*! Make sure the minimum and maximum sizes of everything are sane. |
|
3704 |
*/ |
|
3705 |
||
3706 |
void Q3FileDialog::updateGeometries() |
|
3707 |
{ |
|
3708 |
if (!d || !d->geometryDirty) |
|
3709 |
return; |
|
3710 |
||
3711 |
d->geometryDirty = false; |
|
3712 |
||
3713 |
QSize r, t; |
|
3714 |
||
3715 |
// we really should use QSize::expandedTo() |
|
3716 |
#define RM r.setWidth(qMax(r.width(),t.width())); \ |
|
3717 |
r.setHeight(qMax(r.height(),t.height())) |
|
3718 |
||
3719 |
// labels first |
|
3720 |
r = d->pathL->sizeHint(); |
|
3721 |
t = d->fileL->sizeHint(); |
|
3722 |
RM; |
|
3723 |
t = d->typeL->sizeHint(); |
|
3724 |
RM; |
|
3725 |
d->pathL->setFixedSize(d->pathL->sizeHint()); |
|
3726 |
d->fileL->setFixedSize(r); |
|
3727 |
d->typeL->setFixedSize(r); |
|
3728 |
||
3729 |
// single-line input areas |
|
3730 |
r = d->paths->sizeHint(); |
|
3731 |
t = nameEdit->sizeHint(); |
|
3732 |
RM; |
|
3733 |
t = d->types->sizeHint(); |
|
3734 |
RM; |
|
3735 |
r.setWidth(t.width() * 2 / 3); |
|
3736 |
t.setWidth(QWIDGETSIZE_MAX); |
|
3737 |
t.setHeight(r.height()); |
|
3738 |
d->paths->setMinimumSize(r); |
|
3739 |
d->paths->setMaximumSize(t); |
|
3740 |
nameEdit->setMinimumSize(r); |
|
3741 |
nameEdit->setMaximumSize(t); |
|
3742 |
d->types->setMinimumSize(r); |
|
3743 |
d->types->setMaximumSize(t); |
|
3744 |
||
3745 |
// buttons on top row |
|
3746 |
r = QSize(0, d->paths->minimumSize().height()); |
|
3747 |
t = QSize(21, 20); |
|
3748 |
RM; |
|
3749 |
if (r.height()+1 > r.width()) |
|
3750 |
r.setWidth(r.height()+1); |
|
3751 |
if (d->goBack) |
|
3752 |
d->goBack->setFixedSize(r); |
|
3753 |
d->cdToParent->setFixedSize(r); |
|
3754 |
d->newFolder->setFixedSize(r); |
|
3755 |
d->mcView->setFixedSize(r); |
|
3756 |
d->detailView->setFixedSize(r); |
|
3757 |
||
3758 |
QAbstractButton *b = 0; |
|
3759 |
if (!d->toolButtons.isEmpty()) { |
|
3760 |
for (b = d->toolButtons.first(); b; b = d->toolButtons.next()) |
|
3761 |
b->setFixedSize(b->sizeHint().width(), r.height()); |
|
3762 |
} |
|
3763 |
||
3764 |
if (d->infoPreview) { |
|
3765 |
d->previewInfo->show(); |
|
3766 |
d->previewInfo->setFixedSize(r); |
|
3767 |
} else { |
|
3768 |
d->previewInfo->hide(); |
|
3769 |
d->previewInfo->setFixedSize(QSize(0, 0)); |
|
3770 |
} |
|
3771 |
||
3772 |
if (d->contentsPreview) { |
|
3773 |
d->previewContents->show(); |
|
3774 |
d->previewContents->setFixedSize(r); |
|
3775 |
} else { |
|
3776 |
d->previewContents->hide(); |
|
3777 |
d->previewContents->setFixedSize(QSize(0, 0)); |
|
3778 |
} |
|
3779 |
||
3780 |
// open/save, cancel |
|
3781 |
r = QSize(75, 20); |
|
3782 |
t = okB->sizeHint(); |
|
3783 |
RM; |
|
3784 |
t = cancelB->sizeHint(); |
|
3785 |
RM; |
|
3786 |
||
3787 |
okB->setFixedSize(r); |
|
3788 |
cancelB->setFixedSize(r); |
|
3789 |
||
3790 |
d->topLevelLayout->activate(); |
|
3791 |
||
3792 |
#undef RM |
|
3793 |
} |
|
3794 |
||
3795 |
||
3796 |
/*! Updates the file name edit box to \a newItem in the file dialog |
|
3797 |
when the cursor moves in the listview. |
|
3798 |
*/ |
|
3799 |
||
3800 |
void Q3FileDialog::updateFileNameEdit(Q3ListViewItem * newItem) |
|
3801 |
{ |
|
3802 |
if (!newItem) |
|
3803 |
return; |
|
3804 |
||
3805 |
if (mode() == ExistingFiles) { |
|
3806 |
detailViewSelectionChanged(); |
|
3807 |
Q3Url u(d->url, Q3FileDialogPrivate::encodeFileName(((Q3FileDialogPrivate::File*)files->currentItem())->info.name())); |
|
3808 |
QFileInfo fi(u.toString(false, false)); |
|
3809 |
if (!fi.isDir()) |
|
3810 |
emit fileHighlighted(u.toString(false, false)); |
|
3811 |
} else if (files->isSelected(newItem)) { |
|
3812 |
Q3FileDialogPrivate::File * i = (Q3FileDialogPrivate::File *)newItem; |
|
3813 |
if (i && i->i && !i->i->isSelected()) { |
|
3814 |
d->moreFiles->blockSignals(true); |
|
3815 |
d->moreFiles->setSelected(i->i, true); |
|
3816 |
d->moreFiles->blockSignals(false); |
|
3817 |
} |
|
3818 |
// Encode the filename in case it had any special characters in it |
|
3819 |
QString encFile = Q3FileDialogPrivate::encodeFileName(newItem->text(0)); |
|
3820 |
trySetSelection(i->info.isDir(), Q3UrlOperator(d->url, encFile), true); |
|
3821 |
} |
|
3822 |
} |
|
3823 |
||
3824 |
void Q3FileDialog::detailViewSelectionChanged() |
|
3825 |
{ |
|
3826 |
if (d->mode != ExistingFiles) |
|
3827 |
return; |
|
3828 |
||
3829 |
nameEdit->clear(); |
|
3830 |
QString str; |
|
3831 |
Q3ListViewItem * i = files->firstChild(); |
|
3832 |
d->moreFiles->blockSignals(true); |
|
3833 |
while(i) { |
|
3834 |
if (d->moreFiles && isVisible()) { |
|
3835 |
Q3FileDialogPrivate::File *f = (Q3FileDialogPrivate::File *)i; |
|
3836 |
if (f->i && f->i->isSelected() != i->isSelected()) |
|
3837 |
d->moreFiles->setSelected(f->i, i->isSelected()); |
|
3838 |
} |
|
3839 |
if (i->isSelected() && !((Q3FileDialogPrivate::File *)i)->info.isDir()) |
|
3840 |
str += QString::fromLatin1("\"%1\" ").arg(i->text(0)); |
|
3841 |
i = i->nextSibling(); |
|
3842 |
} |
|
3843 |
d->moreFiles->blockSignals(false); |
|
3844 |
nameEdit->setText(str); |
|
3845 |
nameEdit->setCursorPosition(str.length()); |
|
3846 |
okB->setEnabled(true); |
|
3847 |
if (d->preview && d->preview->isVisible() && files->currentItem()) { |
|
3848 |
Q3Url u = Q3Url(d->url, Q3FileDialogPrivate::encodeFileName(((Q3FileDialogPrivate::File*)files->currentItem())->info.name())); |
|
3849 |
updatePreviews(u); |
|
3850 |
} |
|
3851 |
} |
|
3852 |
||
3853 |
void Q3FileDialog::listBoxSelectionChanged() |
|
3854 |
{ |
|
3855 |
if (d->mode != ExistingFiles) |
|
3856 |
return; |
|
3857 |
||
3858 |
if (d->ignoreNextRefresh) { |
|
3859 |
d->ignoreNextRefresh = false; |
|
3860 |
return; |
|
3861 |
} |
|
3862 |
||
3863 |
nameEdit->clear(); |
|
3864 |
QString str; |
|
3865 |
Q3ListBoxItem * i = d->moreFiles->item(0); |
|
3866 |
Q3ListBoxItem * j = 0; |
|
3867 |
int index = 0; |
|
3868 |
files->blockSignals(true); |
|
3869 |
while(i) { |
|
3870 |
Q3FileDialogPrivate::MCItem *mcitem = (Q3FileDialogPrivate::MCItem *)i; |
|
3871 |
if (files && isVisible()) { |
|
3872 |
if (mcitem->i->isSelected() != mcitem->isSelected()) { |
|
3873 |
files->setSelected(mcitem->i, mcitem->isSelected()); |
|
3874 |
||
3875 |
// What happens here is that we want to emit signal highlighted for |
|
3876 |
// newly added items. But Q3ListBox apparently emits selectionChanged even |
|
3877 |
// when a user clicks on the same item twice. So, basically emulate the behaivor |
|
3878 |
// we have in the "Details" view which only emits highlighted the first time we |
|
3879 |
// click on the item. Perhaps at some point we should have a call to |
|
3880 |
// updateFileNameEdit(Q3ListViewItem) which also emits fileHighlighted() for |
|
3881 |
// ExistingFiles. For better or for worse, this clones the behaivor of the |
|
3882 |
// "Details" view quite well. |
|
3883 |
if (mcitem->isSelected() && i != d->lastEFSelected) { |
|
3884 |
Q3Url u(d->url, Q3FileDialogPrivate::encodeFileName(((Q3FileDialogPrivate::File*)(mcitem)->i)->info.name())); |
|
3885 |
d->lastEFSelected = i; |
|
3886 |
emit fileHighlighted(u.toString(false, false)); |
|
3887 |
} |
|
3888 |
} |
|
3889 |
} |
|
3890 |
if (d->moreFiles->isSelected(i) |
|
3891 |
&& !((Q3FileDialogPrivate::File*)(mcitem)->i)->info.isDir()) { |
|
3892 |
str += QString::fromLatin1("\"%1\" ").arg(i->text()); |
|
3893 |
if (j == 0) |
|
3894 |
j = i; |
|
3895 |
} |
|
3896 |
i = d->moreFiles->item(++index); |
|
3897 |
} |
|
3898 |
||
3899 |
files->blockSignals(false); |
|
3900 |
nameEdit->setText(str); |
|
3901 |
nameEdit->setCursorPosition(str.length()); |
|
3902 |
okB->setEnabled(true); |
|
3903 |
if (d->preview && d->preview->isVisible() && j) { |
|
3904 |
Q3Url u = Q3Url(d->url, |
|
3905 |
Q3FileDialogPrivate::encodeFileName(((Q3FileDialogPrivate::File*)((Q3FileDialogPrivate::MCItem*)j)->i)->info.name())); |
|
3906 |
updatePreviews(u); |
|
3907 |
} |
|
3908 |
} |
|
3909 |
||
3910 |
/*! \overload */ |
|
3911 |
||
3912 |
void Q3FileDialog::updateFileNameEdit(Q3ListBoxItem * newItem) |
|
3913 |
{ |
|
3914 |
if (!newItem) |
|
3915 |
return; |
|
3916 |
Q3FileDialogPrivate::MCItem * i = (Q3FileDialogPrivate::MCItem *)newItem; |
|
3917 |
if (i->i) { |
|
3918 |
i->i->listView()->setSelected(i->i, i->isSelected()); |
|
3919 |
updateFileNameEdit(i->i); |
|
3920 |
} |
|
3921 |
} |
|
3922 |
||
3923 |
||
3924 |
/*! Updates the dialog when the file name edit changes. */ |
|
3925 |
||
3926 |
void Q3FileDialog::fileNameEditDone() |
|
3927 |
{ |
|
3928 |
QUrlInfo f(d->url.info(nameEdit->text().isEmpty() ? QString::fromLatin1(".") : nameEdit->text())); |
|
3929 |
if (mode() != Q3FileDialog::ExistingFiles) { |
|
3930 |
Q3UrlOperator u(d->url, Q3FileDialogPrivate::encodeFileName(nameEdit->text())); |
|
3931 |
trySetSelection(f.isDir(), u, false); |
|
3932 |
if (d->preview && d->preview->isVisible()) |
|
3933 |
updatePreviews(u); |
|
3934 |
} |
|
3935 |
} |
|
3936 |
||
3937 |
||
3938 |
||
3939 |
/*! This private slot reacts to double-clicks in the list view. The item that |
|
3940 |
was double-clicked is specified in \a newItem */ |
|
3941 |
||
3942 |
void Q3FileDialog::selectDirectoryOrFile(Q3ListViewItem * newItem) |
|
3943 |
{ |
|
3944 |
||
3945 |
*workingDirectory = d->url; |
|
3946 |
detailViewMode = files->isVisible(); |
|
3947 |
updateLastSize(this); |
|
3948 |
||
3949 |
if (!newItem) |
|
3950 |
return; |
|
3951 |
||
3952 |
if (d->url.isLocalFile()) { |
|
3953 |
QFileInfo fi(d->url.path() + newItem->text(0)); |
|
3954 |
#if defined(Q_WS_WIN) |
|
3955 |
if (fi.isSymLink()) { |
|
3956 |
nameEdit->setText(fi.symLinkTarget()); |
|
3957 |
okClicked(); |
|
3958 |
return; |
|
3959 |
} |
|
3960 |
#endif |
|
3961 |
} |
|
3962 |
||
3963 |
Q3FileDialogPrivate::File * i = (Q3FileDialogPrivate::File *)newItem; |
|
3964 |
||
3965 |
QString oldName = nameEdit->text(); |
|
3966 |
if (i->info.isDir()) { |
|
3967 |
setUrl(Q3UrlOperator(d->url, Q3FileDialogPrivate::encodeFileName(i->info.name()) + QLatin1Char('/'))); |
|
3968 |
if (isDirectoryMode(mode())) { |
|
3969 |
QUrlInfo f (d->url.info(QString::fromLatin1("."))); |
|
3970 |
trySetSelection(f.isDir(), d->url, true); |
|
3971 |
} |
|
3972 |
} else if (newItem->isSelectable() && |
|
3973 |
trySetSelection(i->info.isDir(), Q3UrlOperator(d->url, Q3FileDialogPrivate::encodeFileName(i->info.name())), true)) { |
|
3974 |
if (!isDirectoryMode(mode())) { |
|
3975 |
if (mode() == ExistingFile) { |
|
3976 |
if (Q3FileDialogPrivate::fileExists(d->url, nameEdit->text())) { |
|
3977 |
emit fileSelected(selectedFile()); |
|
3978 |
accept(); |
|
3979 |
} |
|
3980 |
} else { |
|
3981 |
emit fileSelected(selectedFile()); |
|
3982 |
accept(); |
|
3983 |
} |
|
3984 |
} |
|
3985 |
} else if (isDirectoryMode(d->mode)) { |
|
3986 |
d->currentFileName = d->url; |
|
3987 |
accept(); |
|
3988 |
} |
|
3989 |
if (!oldName.isEmpty() && !isDirectoryMode(mode())) |
|
3990 |
nameEdit->setText(oldName); |
|
3991 |
} |
|
3992 |
||
3993 |
||
3994 |
void Q3FileDialog::selectDirectoryOrFile(Q3ListBoxItem * newItem) |
|
3995 |
{ |
|
3996 |
if (!newItem) |
|
3997 |
return; |
|
3998 |
||
3999 |
Q3FileDialogPrivate::MCItem * i = (Q3FileDialogPrivate::MCItem *)newItem; |
|
4000 |
if (i->i) { |
|
4001 |
i->i->listView()->setSelected(i->i, i->isSelected()); |
|
4002 |
selectDirectoryOrFile(i->i); |
|
4003 |
} |
|
4004 |
} |
|
4005 |
||
4006 |
||
4007 |
void Q3FileDialog::popupContextMenu(Q3ListViewItem *item, const QPoint &p, |
|
4008 |
int) |
|
4009 |
{ |
|
4010 |
if (item) { |
|
4011 |
files->setCurrentItem(item); |
|
4012 |
files->setSelected(item, true); |
|
4013 |
} |
|
4014 |
||
4015 |
PopupAction action; |
|
4016 |
popupContextMenu(item ? item->text(0) : QString(), true, action, p); |
|
4017 |
||
4018 |
if (action == PA_Open) |
|
4019 |
selectDirectoryOrFile(item); |
|
4020 |
else if (action == PA_Rename) |
|
4021 |
files->startRename(false); |
|
4022 |
else if (action == PA_Delete) |
|
4023 |
deleteFile(item ? item->text(0) : QString()); |
|
4024 |
else if (action == PA_Reload) |
|
4025 |
rereadDir(); |
|
4026 |
else if (action == PA_Hidden) { |
|
4027 |
bShowHiddenFiles = !bShowHiddenFiles; |
|
4028 |
rereadDir(); |
|
4029 |
} else if (action == PA_SortName) { |
|
4030 |
sortFilesBy = (int)QDir::Name; |
|
4031 |
sortAscending = true; |
|
4032 |
resortDir(); |
|
4033 |
} else if (action == PA_SortSize) { |
|
4034 |
sortFilesBy = (int)QDir::Size; |
|
4035 |
sortAscending = true; |
|
4036 |
resortDir(); |
|
4037 |
} else if (action == PA_SortDate) { |
|
4038 |
sortFilesBy = (int)QDir::Time; |
|
4039 |
sortAscending = true; |
|
4040 |
resortDir(); |
|
4041 |
} else if (action == PA_SortUnsorted) { |
|
4042 |
sortFilesBy = (int)QDir::Unsorted; |
|
4043 |
sortAscending = true; |
|
4044 |
resortDir(); |
|
4045 |
} |
|
4046 |
||
4047 |
} |
|
4048 |
||
4049 |
void Q3FileDialog::popupContextMenu(Q3ListBoxItem *item, const QPoint & p) |
|
4050 |
{ |
|
4051 |
PopupAction action; |
|
4052 |
popupContextMenu(item ? item->text() : QString(), false, action, p); |
|
4053 |
||
4054 |
if (action == PA_Open) |
|
4055 |
selectDirectoryOrFile(item); |
|
4056 |
else if (action == PA_Rename) |
|
4057 |
d->moreFiles->startRename(false); |
|
4058 |
else if (action == PA_Delete) |
|
4059 |
deleteFile(item->text()); |
|
4060 |
else if (action == PA_Reload) |
|
4061 |
rereadDir(); |
|
4062 |
else if (action == PA_Hidden) { |
|
4063 |
bShowHiddenFiles = !bShowHiddenFiles; |
|
4064 |
rereadDir(); |
|
4065 |
} else if (action == PA_SortName) { |
|
4066 |
sortFilesBy = (int)QDir::Name; |
|
4067 |
sortAscending = true; |
|
4068 |
resortDir(); |
|
4069 |
} else if (action == PA_SortSize) { |
|
4070 |
sortFilesBy = (int)QDir::Size; |
|
4071 |
sortAscending = true; |
|
4072 |
resortDir(); |
|
4073 |
} else if (action == PA_SortDate) { |
|
4074 |
sortFilesBy = (int)QDir::Time; |
|
4075 |
sortAscending = true; |
|
4076 |
resortDir(); |
|
4077 |
} else if (action == PA_SortUnsorted) { |
|
4078 |
sortFilesBy = (int)QDir::Unsorted; |
|
4079 |
sortAscending = true; |
|
4080 |
resortDir(); |
|
4081 |
} |
|
4082 |
} |
|
4083 |
||
4084 |
void Q3FileDialog::popupContextMenu(const QString &filename, bool, |
|
4085 |
PopupAction &action, const QPoint &p) |
|
4086 |
{ |
|
4087 |
action = PA_Cancel; |
|
4088 |
||
4089 |
bool glob = filename.isEmpty(); |
|
4090 |
||
4091 |
Q3PopupMenu m(0, "file dialog context menu"); |
|
4092 |
m.setCheckable(true); |
|
4093 |
||
4094 |
if (!glob) { |
|
4095 |
QString okt; |
|
4096 |
if (QUrlInfo(d->url.info(filename.isEmpty() ? QString::fromLatin1(".") : fileName)).isDir()) { |
|
4097 |
okt = tr("&Open"); |
|
4098 |
} else { |
|
4099 |
if (mode() == AnyFile) |
|
4100 |
okt = tr("&Save"); |
|
4101 |
else |
|
4102 |
okt = tr("&Open"); |
|
4103 |
} |
|
4104 |
int ok = m.insertItem(okt); |
|
4105 |
||
4106 |
m.insertSeparator(); |
|
4107 |
int rename = m.insertItem(tr("&Rename")); |
|
4108 |
int del = m.insertItem(tr("&Delete")); |
|
4109 |
||
4110 |
if (filename.isEmpty() || !QUrlInfo(d->url.info(filename)).isWritable() || |
|
4111 |
filename == QLatin1String("..")) { |
|
4112 |
if (filename.isEmpty() || !QUrlInfo(d->url.info(filename)).isReadable()) |
|
4113 |
m.setItemEnabled(ok, false); |
|
4114 |
m.setItemEnabled(rename, false); |
|
4115 |
m.setItemEnabled(del, false); |
|
4116 |
} |
|
4117 |
||
4118 |
m.move(p); |
|
4119 |
int res = m.exec(QCursor::pos(), -1); |
|
4120 |
||
4121 |
if (res == ok) |
|
4122 |
action = PA_Open; |
|
4123 |
else if (res == rename) |
|
4124 |
action = PA_Rename; |
|
4125 |
else if (res == del) |
|
4126 |
action = PA_Delete; |
|
4127 |
} else { |
|
4128 |
int reload = m.insertItem(tr("R&eload")); |
|
4129 |
||
4130 |
Q3PopupMenu m2(0, "sort menu"); |
|
4131 |
||
4132 |
int sname = m2.insertItem(tr("Sort by &Name")); |
|
4133 |
//int stype = m2.insertItem(tr("Sort by &Type")); |
|
4134 |
int ssize = m2.insertItem(tr("Sort by &Size")); |
|
4135 |
int sdate = m2.insertItem(tr("Sort by &Date")); |
|
4136 |
m2.insertSeparator(); |
|
4137 |
int sunsorted = m2.insertItem(tr("&Unsorted")); |
|
4138 |
||
4139 |
//m2.setItemEnabled(stype, false); |
|
4140 |
||
4141 |
if (sortFilesBy == (int)QDir::Name) |
|
4142 |
m2.setItemChecked(sname, true); |
|
4143 |
else if (sortFilesBy == (int)QDir::Size) |
|
4144 |
m2.setItemChecked(ssize, true); |
|
4145 |
// else if (sortFilesBy == 0x16) |
|
4146 |
// m2.setItemChecked(stype, true); |
|
4147 |
else if (sortFilesBy == (int)QDir::Time) |
|
4148 |
m2.setItemChecked(sdate, true); |
|
4149 |
else if (sortFilesBy == (int)QDir::Unsorted) |
|
4150 |
m2.setItemChecked(sunsorted, true); |
|
4151 |
||
4152 |
m.insertItem(tr("Sort"), &m2); |
|
4153 |
||
4154 |
m.insertSeparator(); |
|
4155 |
||
4156 |
int hidden = m.insertItem(tr("Show &hidden files")); |
|
4157 |
m.setItemChecked(hidden, bShowHiddenFiles); |
|
4158 |
||
4159 |
m.move(p); |
|
4160 |
int res = m.exec(QCursor::pos(), -1); |
|
4161 |
||
4162 |
if (res == reload) |
|
4163 |
action = PA_Reload; |
|
4164 |
else if (res == hidden) |
|
4165 |
action = PA_Hidden; |
|
4166 |
else if (res == sname) |
|
4167 |
action = PA_SortName; |
|
4168 |
// else if (res == stype) |
|
4169 |
// action = PA_SortType; |
|
4170 |
else if (res == sdate) |
|
4171 |
action = PA_SortDate; |
|
4172 |
else if (res == ssize) |
|
4173 |
action = PA_SortSize; |
|
4174 |
else if (res == sunsorted) |
|
4175 |
action = PA_SortUnsorted; |
|
4176 |
} |
|
4177 |
||
4178 |
} |
|
4179 |
||
4180 |
void Q3FileDialog::deleteFile(const QString &filename) |
|
4181 |
{ |
|
4182 |
if (filename.isEmpty()) |
|
4183 |
return; |
|
4184 |
||
4185 |
QString encoded = Q3FileDialogPrivate::encodeFileName(filename); |
|
4186 |
QUrlInfo fi(d->url.info(encoded.isEmpty() ? QString::fromLatin1(".") : encoded)); |
|
4187 |
QString t = tr("the file"); |
|
4188 |
if (fi.isDir()) |
|
4189 |
t = tr("the directory"); |
|
4190 |
if (fi.isSymLink()) |
|
4191 |
t = tr("the symlink"); |
|
4192 |
||
4193 |
if (QMessageBox::warning(this, |
|
4194 |
tr("Delete %1").arg(t), |
|
4195 |
tr("<qt>Are you sure you wish to delete %1 \"%2\"?</qt>") |
|
4196 |
.arg(t).arg(filename), |
|
4197 |
tr("&Yes"), tr("&No"), QString(), 1) == 0) |
|
4198 |
d->url.remove(Q3FileDialogPrivate::encodeFileName(filename)); |
|
4199 |
||
4200 |
} |
|
4201 |
||
4202 |
void Q3FileDialog::fileSelected(int ) |
|
4203 |
{ |
|
4204 |
// unused |
|
4205 |
} |
|
4206 |
||
4207 |
void Q3FileDialog::fileHighlighted(int) |
|
4208 |
{ |
|
4209 |
// unused |
|
4210 |
} |
|
4211 |
||
4212 |
void Q3FileDialog::dirSelected(int) |
|
4213 |
{ |
|
4214 |
// unused |
|
4215 |
} |
|
4216 |
||
4217 |
void Q3FileDialog::pathSelected(int) |
|
4218 |
{ |
|
4219 |
// unused |
|
4220 |
} |
|
4221 |
||
4222 |
||
4223 |
void Q3FileDialog::cdUpClicked() |
|
4224 |
{ |
|
4225 |
QString oldName = nameEdit->text(); |
|
4226 |
setUrl(Q3UrlOperator(d->url, QLatin1String(".."))); |
|
4227 |
if (!oldName.isEmpty()) |
|
4228 |
nameEdit->setText(oldName); |
|
4229 |
} |
|
4230 |
||
4231 |
void Q3FileDialog::newFolderClicked() |
|
4232 |
{ |
|
4233 |
QString foldername(tr("New Folder 1")); |
|
4234 |
int i = 0; |
|
4235 |
QStringList lst; |
|
4236 |
Q3ListViewItemIterator it(files); |
|
4237 |
for (; it.current(); ++it) |
|
4238 |
if (it.current()->text(0).contains(tr("New Folder"))) |
|
4239 |
lst.append(it.current()->text(0)); |
|
4240 |
||
4241 |
if (!lst.count() == 0) |
|
4242 |
while (lst.contains(foldername)) |
|
4243 |
foldername = tr("New Folder %1").arg(++i); |
|
4244 |
||
4245 |
d->url.mkdir(foldername); |
|
4246 |
} |
|
4247 |
||
4248 |
void Q3FileDialog::createdDirectory(const QUrlInfo &info, Q3NetworkOperation *) |
|
4249 |
{ |
|
4250 |
resortDir(); |
|
4251 |
if (d->moreFiles->isVisible()) { |
|
4252 |
for (uint i = 0; i < d->moreFiles->count(); ++i) { |
|
4253 |
if (d->moreFiles->text(i) == info.name()) { |
|
4254 |
d->moreFiles->setCurrentItem(i); |
|
4255 |
d->moreFiles->startRename(false); |
|
4256 |
break; |
|
4257 |
} |
|
4258 |
} |
|
4259 |
} else { |
|
4260 |
Q3ListViewItem *item = files->firstChild(); |
|
4261 |
while (item) { |
|
4262 |
if (item->text(0) == info.name()) { |
|
4263 |
files->setSelected(item, true); |
|
4264 |
files->setCurrentItem(item); |
|
4265 |
files->startRename(false); |
|
4266 |
break; |
|
4267 |
} |
|
4268 |
item = item->nextSibling(); |
|
4269 |
} |
|
4270 |
} |
|
4271 |
} |
|
4272 |
||
4273 |
||
4274 |
/*! |
|
4275 |
This is a convenience static function that will return an existing directory |
|
4276 |
selected by the user. |
|
4277 |
||
4278 |
\snippet doc/src/snippets/code/src_qt3support_dialogs_q3filedialog.cpp 12 |
|
4279 |
||
4280 |
This function creates a modal file dialog called \a name, with |
|
4281 |
parent, \a parent. If parent is not 0, the dialog will be shown |
|
4282 |
centered over the parent. |
|
4283 |
||
4284 |
The dialog's working directory is set to \a dir, and the caption is |
|
4285 |
set to \a caption. Either of these may be an empty string in which case |
|
4286 |
the current directory and a default caption will be used respectively. |
|
4287 |
||
4288 |
If \a dirOnly is true, then only directories will be shown in |
|
4289 |
the file dialog; otherwise both directories and files will be shown. |
|
4290 |
||
4291 |
Under Unix/X11, the normal behavior of the file dialog is to resolve |
|
4292 |
and follow symlinks. For example, if /usr/tmp is a symlink to /var/tmp, |
|
4293 |
the file dialog will change to /var/tmp after entering /usr/tmp. |
|
4294 |
If \a resolveSymlinks is false, the file dialog will treat |
|
4295 |
symlinks as regular directories. |
|
4296 |
||
4297 |
Note that on Windows the dialog will spin a blocking modal event loop |
|
4298 |
that will not dispatch any QTimers and if parent is not 0 then it will |
|
4299 |
position the dialog just under the parent's title bar. |
|
4300 |
||
4301 |
\sa getOpenFileName(), getOpenFileNames(), getSaveFileName() |
|
4302 |
*/ |
|
4303 |
||
4304 |
QString Q3FileDialog::getExistingDirectory(const QString & dir, |
|
4305 |
QWidget *parent, |
|
4306 |
const char* name, |
|
4307 |
const QString& caption, |
|
4308 |
bool dirOnly, |
|
4309 |
bool resolveSymlinks) |
|
4310 |
{ |
|
4311 |
bool save_qt_resolve_symlinks = qt_resolve_symlinks; |
|
4312 |
qt_resolve_symlinks = resolveSymlinks; |
|
4313 |
||
4314 |
makeVariables(); |
|
4315 |
QString wd; |
|
4316 |
if (workingDirectory) |
|
4317 |
wd = *workingDirectory; |
|
4318 |
||
4319 |
#if defined(Q_WS_WIN) |
|
4320 |
QString initialDir; |
|
4321 |
if (!dir.isEmpty()) { |
|
4322 |
Q3UrlOperator u(dir); |
|
4323 |
if (QFileInfo(u.path()).isDir()) |
|
4324 |
initialDir = dir; |
|
4325 |
} else |
|
4326 |
initialDir.clear(); |
|
4327 |
if (qt_use_native_dialogs && qobject_cast<QWindowsStyle *>(qApp->style()) && dirOnly) |
|
4328 |
return winGetExistingDirectory(initialDir, parent, name, caption); |
|
4329 |
#endif |
|
4330 |
#if defined(Q_WS_MAC) |
|
4331 |
if(qt_use_native_dialogs && qobject_cast<QMacStyle *>(qApp->style())) |
|
4332 |
return macGetOpenFileNames(QLatin1String(""), 0, parent, name, caption, |
|
4333 |
0, false, true).first().normalized(QString::NormalizationForm_C); |
|
4334 |
#endif |
|
4335 |
||
4336 |
Q3FileDialog *dlg = new Q3FileDialog(parent, name ? name : "qt_filedlg_ged", true); |
|
4337 |
||
4338 |
if (!caption.isNull()) |
|
4339 |
dlg->setWindowTitle(caption); |
|
4340 |
else |
|
4341 |
dlg->setWindowTitle(Q3FileDialog::tr("Find Directory")); |
|
4342 |
||
4343 |
dlg->setMode(dirOnly ? DirectoryOnly : Directory); |
|
4344 |
||
4345 |
dlg->d->types->clear(); |
|
4346 |
dlg->d->types->insertItem(Q3FileDialog::tr("Directories")); |
|
4347 |
dlg->d->types->setEnabled(false); |
|
4348 |
||
4349 |
QString dir_(dir); |
|
4350 |
dir_ = dir_.simplified(); |
|
4351 |
if (dir_.isEmpty() && !wd.isEmpty()) |
|
4352 |
dir_ = wd; |
|
4353 |
Q3UrlOperator u(dir_); |
|
4354 |
if (u.isLocalFile()) { |
|
4355 |
if (!dir_.isEmpty()) { |
|
4356 |
QFileInfo f(u.path()); |
|
4357 |
if (f.exists()) |
|
4358 |
if (f.isDir()) { |
|
4359 |
dlg->setDir(dir_); |
|
4360 |
wd = dir_; |
|
4361 |
} |
|
4362 |
} else if (!wd.isEmpty()) { |
|
4363 |
Q3Url tempUrl(wd); |
|
4364 |
QFileInfo f(tempUrl.path()); |
|
4365 |
if (f.isDir()) { |
|
4366 |
dlg->setDir(wd); |
|
4367 |
} |
|
4368 |
} else { |
|
4369 |
QString theDir = dir_; |
|
4370 |
if (theDir.isEmpty()) { |
|
4371 |
theDir = toRootIfNotExists( QDir::currentDirPath() ); |
|
4372 |
} if (!theDir.isEmpty()) { |
|
4373 |
Q3Url tempUrl(theDir); |
|
4374 |
QFileInfo f(tempUrl.path()); |
|
4375 |
if (f.isDir()) { |
|
4376 |
wd = theDir; |
|
4377 |
dlg->setDir(theDir); |
|
4378 |
} |
|
4379 |
} |
|
4380 |
} |
|
4381 |
} else { |
|
4382 |
dlg->setUrl(dir_); |
|
4383 |
} |
|
4384 |
||
4385 |
QString result; |
|
4386 |
dlg->setSelection(dlg->d->url.toString()); |
|
4387 |
||
4388 |
if (dlg->exec() == QDialog::Accepted) { |
|
4389 |
result = dlg->selectedFile(); |
|
4390 |
wd = result; |
|
4391 |
} |
|
4392 |
delete dlg; |
|
4393 |
||
4394 |
if (!result.isEmpty() && result.right(1) != QString(QLatin1Char('/'))) |
|
4395 |
result += QLatin1Char('/'); |
|
4396 |
||
4397 |
qt_resolve_symlinks = save_qt_resolve_symlinks; |
|
4398 |
||
4399 |
return result; |
|
4400 |
} |
|
4401 |
||
4402 |
||
4403 |
/*! |
|
4404 |
\property Q3FileDialog::mode |
|
4405 |
\brief the file dialog's mode |
|
4406 |
||
4407 |
The default mode is \l ExistingFile. |
|
4408 |
*/ |
|
4409 |
||
4410 |
void Q3FileDialog::setMode(Mode newMode) |
|
4411 |
{ |
|
4412 |
if (d->mode != newMode) { |
|
4413 |
d->mode = newMode; |
|
4414 |
QString sel = d->currentFileName; |
|
4415 |
int maxnamelen = 255; // _POSIX_MAX_PATH |
|
4416 |
if (isDirectoryMode(newMode)) { |
|
4417 |
files->setSelectionMode(Q3ListView::Single); |
|
4418 |
d->moreFiles->setSelectionMode(Q3ListBox::Single); |
|
4419 |
if (sel.isNull()) |
|
4420 |
sel = QString::fromLatin1("."); |
|
4421 |
d->types->setEnabled(false); |
|
4422 |
} else if (newMode == ExistingFiles) { |
|
4423 |
maxnamelen = INT_MAX; |
|
4424 |
files->setSelectionMode(Q3ListView::Extended); |
|
4425 |
d->moreFiles->setSelectionMode(Q3ListBox::Extended); |
|
4426 |
d->types->setEnabled(true); |
|
4427 |
} else { |
|
4428 |
files->setSelectionMode(Q3ListView::Single); |
|
4429 |
d->moreFiles->setSelectionMode(Q3ListBox::Single); |
|
4430 |
d->types->setEnabled(true); |
|
4431 |
} |
|
4432 |
nameEdit->setMaxLength(maxnamelen); |
|
4433 |
rereadDir(); |
|
4434 |
QUrlInfo f(d->url.info(QString(QLatin1Char('.')))); |
|
4435 |
trySetSelection(f.isDir(), d->url, false); |
|
4436 |
} |
|
4437 |
||
4438 |
QString okt; |
|
4439 |
bool changeFilters = false; |
|
4440 |
if (mode() == AnyFile) { |
|
4441 |
okt = tr("&Save"); |
|
4442 |
d->fileL->setText(tr("File &name:")); |
|
4443 |
if (d->types->count() == 1) { |
|
4444 |
d->types->setCurrentItem(0); |
|
4445 |
if (d->types->currentText() == QLatin1String("Directories")) { |
|
4446 |
changeFilters = true; |
|
4447 |
} |
|
4448 |
} |
|
4449 |
} |
|
4450 |
else if (mode() == Directory || mode() == DirectoryOnly) { |
|
4451 |
okt = tr("&OK"); |
|
4452 |
d->fileL->setText(tr("Directory:")); |
|
4453 |
d->types->clear(); |
|
4454 |
d->types->insertItem(tr("Directories")); |
|
4455 |
} |
|
4456 |
else { |
|
4457 |
okt = tr("&Open"); |
|
4458 |
d->fileL->setText(tr("File &name:")); |
|
4459 |
if (d->types->count() == 1) { |
|
4460 |
d->types->setCurrentItem(0); |
|
4461 |
if (d->types->currentText() == QLatin1String("Directories")) { |
|
4462 |
changeFilters = true; |
|
4463 |
} |
|
4464 |
} |
|
4465 |
} |
|
4466 |
||
4467 |
if (changeFilters) { |
|
4468 |
d->types->clear(); |
|
4469 |
d->types->insertItem(tr("All Files (*)")); |
|
4470 |
} |
|
4471 |
||
4472 |
okB->setText(okt); |
|
4473 |
} |
|
4474 |
||
4475 |
Q3FileDialog::Mode Q3FileDialog::mode() const |
|
4476 |
{ |
|
4477 |
return d->mode; |
|
4478 |
} |
|
4479 |
||
4480 |
/*! \reimp |
|
4481 |
*/ |
|
4482 |
||
4483 |
void Q3FileDialog::done(int i) |
|
4484 |
{ |
|
4485 |
if (i == QDialog::Accepted && (d->mode == ExistingFile || d->mode == ExistingFiles)) { |
|
4486 |
QStringList selection = selectedFiles(); |
|
4487 |
for (int f = 0; f < selection.count(); f++) { |
|
4488 |
QString file = selection[f]; |
|
4489 |
if (file.isNull()) |
|
4490 |
continue; |
|
4491 |
if (d->url.isLocalFile() && !QFile::exists(file)) { |
|
4492 |
QMessageBox::information(this, tr("Error"), |
|
4493 |
tr("%1\nFile not found.\nCheck path and filename.").arg(file)); |
|
4494 |
return; |
|
4495 |
} |
|
4496 |
} |
|
4497 |
} |
|
4498 |
QDialog::done(i); |
|
4499 |
} |
|
4500 |
||
4501 |
/*! |
|
4502 |
\property Q3FileDialog::viewMode |
|
4503 |
||
4504 |
\brief the file dialog's view mode |
|
4505 |
||
4506 |
If you set the view mode to be \e Detail (the default), then you |
|
4507 |
will see the file's details, such as the size of the file and the |
|
4508 |
date the file was last modified in addition to the file's name. |
|
4509 |
||
4510 |
If you set the view mode to be \e List, then you will just |
|
4511 |
see a list of the files and folders. |
|
4512 |
||
4513 |
See \l Q3FileDialog::ViewMode |
|
4514 |
*/ |
|
4515 |
||
4516 |
||
4517 |
Q3FileDialog::ViewMode Q3FileDialog::viewMode() const |
|
4518 |
{ |
|
4519 |
if (detailViewMode) |
|
4520 |
return Detail; |
|
4521 |
else |
|
4522 |
return List; |
|
4523 |
} |
|
4524 |
||
4525 |
void Q3FileDialog::setViewMode(ViewMode m) |
|
4526 |
{ |
|
4527 |
if (m == Detail) { |
|
4528 |
detailViewMode = true; |
|
4529 |
d->stack->raiseWidget(files); |
|
4530 |
d->detailView->setOn(true); |
|
4531 |
d->mcView->setOn(false); |
|
4532 |
} else if (m == List) { |
|
4533 |
detailViewMode = false; |
|
4534 |
d->stack->raiseWidget(d->moreFiles); |
|
4535 |
d->detailView->setOn(false); |
|
4536 |
d->mcView->setOn(true); |
|
4537 |
} |
|
4538 |
} |
|
4539 |
||
4540 |
||
4541 |
/*! |
|
4542 |
\property Q3FileDialog::previewMode |
|
4543 |
||
4544 |
\brief the preview mode for the file dialog |
|
4545 |
||
4546 |
If you set the mode to be a mode other than \e NoPreview, you must |
|
4547 |
use setInfoPreview() or setContentsPreview() to set the dialog's |
|
4548 |
preview widget to your preview widget and enable the preview |
|
4549 |
widget(s) with setInfoPreviewEnabled() or |
|
4550 |
setContentsPreviewEnabled(). |
|
4551 |
||
4552 |
\sa infoPreview, contentsPreview, viewMode |
|
4553 |
*/ |
|
4554 |
||
4555 |
void Q3FileDialog::setPreviewMode(PreviewMode m) |
|
4556 |
{ |
|
4557 |
if (m == NoPreview) { |
|
4558 |
d->previewInfo->setOn(false); |
|
4559 |
d->previewContents->setOn(false); |
|
4560 |
} else if (m == Info && d->infoPreview) { |
|
4561 |
d->previewInfo->setOn(true); |
|
4562 |
d->previewContents->setOn(false); |
|
4563 |
changeMode(d->modeButtons->id(d->previewInfo)); |
|
4564 |
} else if (m == Contents && d->contentsPreview) { |
|
4565 |
d->previewInfo->setOn(false); |
|
4566 |
d->previewContents->setOn(true); |
|
4567 |
changeMode(d->modeButtons->id(d->previewContents)); |
|
4568 |
} |
|
4569 |
} |
|
4570 |
Q3FileDialog::PreviewMode Q3FileDialog::previewMode() const |
|
4571 |
{ |
|
4572 |
if (d->infoPreview && d->infoPreviewWidget->isVisibleTo(const_cast<Q3FileDialog *>(this))) |
|
4573 |
return Info; |
|
4574 |
else if (d->contentsPreview |
|
4575 |
&& d->contentsPreviewWidget->isVisibleTo(const_cast<Q3FileDialog *>(this))) |
|
4576 |
return Contents; |
|
4577 |
return NoPreview; |
|
4578 |
} |
|
4579 |
||
4580 |
||
4581 |
/*! |
|
4582 |
Adds the specified widgets to the bottom of the file dialog. The |
|
4583 |
label \a l is placed underneath the "file name" and the "file types" |
|
4584 |
labels. The widget \a w is placed underneath the file types combobox. |
|
4585 |
The button \a b is placed underneath the Cancel push button. |
|
4586 |
||
4587 |
\snippet doc/src/snippets/code/src_qt3support_dialogs_q3filedialog.cpp 13 |
|
4588 |
||
4589 |
If you don't want to have one of the widgets added, pass 0 in that |
|
4590 |
widget's position. |
|
4591 |
||
4592 |
Every time you call this function, a new row of widgets will be added |
|
4593 |
to the bottom of the file dialog. |
|
4594 |
||
4595 |
\sa addToolButton(), addLeftWidget(), addRightWidget() |
|
4596 |
*/ |
|
4597 |
||
4598 |
void Q3FileDialog::addWidgets(QLabel * l, QWidget * w, QPushButton * b) |
|
4599 |
{ |
|
4600 |
if (!l && !w && !b) |
|
4601 |
return; |
|
4602 |
||
4603 |
d->geometryDirty = true; |
|
4604 |
||
4605 |
QHBoxLayout *lay = new QHBoxLayout(); |
|
4606 |
d->extraWidgetsLayouts.append(lay); |
|
4607 |
d->topLevelLayout->addLayout(lay); |
|
4608 |
||
4609 |
if (!l) |
|
4610 |
l = new QLabel(this, "qt_intern_lbl"); |
|
4611 |
d->extraLabels.append(l); |
|
4612 |
lay->addWidget(l); |
|
4613 |
||
4614 |
if (!w) |
|
4615 |
w = new QWidget(this, "qt_intern_widget"); |
|
4616 |
d->extraWidgets.append(w); |
|
4617 |
lay->addWidget(w); |
|
4618 |
lay->addSpacing(15); |
|
4619 |
||
4620 |
if (b) { |
|
4621 |
d->extraButtons.append(b); |
|
4622 |
lay->addWidget(b); |
|
4623 |
} else { |
|
4624 |
QWidget *wid = new QWidget(this, "qt_extrabuttons_widget"); |
|
4625 |
d->extraButtons.append(wid); |
|
4626 |
lay->addWidget(wid); |
|
4627 |
} |
|
4628 |
||
4629 |
updateGeometries(); |
|
4630 |
} |
|
4631 |
||
4632 |
/*! |
|
4633 |
Adds the tool button \a b to the row of tool buttons at the top of the |
|
4634 |
file dialog. The button is appended to the right of |
|
4635 |
this row. If \a separator is true, a small space is inserted between the |
|
4636 |
last button of the row and the new button \a b. |
|
4637 |
||
4638 |
\sa addWidgets(), addLeftWidget(), addRightWidget() |
|
4639 |
*/ |
|
4640 |
||
4641 |
void Q3FileDialog::addToolButton(QAbstractButton *b, bool separator) |
|
4642 |
{ |
|
4643 |
if (!b || !d->buttonLayout) |
|
4644 |
return; |
|
4645 |
||
4646 |
d->geometryDirty = true; |
|
4647 |
||
4648 |
d->toolButtons.append(b); |
|
4649 |
if (separator) |
|
4650 |
d->buttonLayout->addSpacing(8); |
|
4651 |
d->buttonLayout->addWidget(b); |
|
4652 |
||
4653 |
updateGeometries(); |
|
4654 |
} |
|
4655 |
||
4656 |
/*! |
|
4657 |
Adds the widget \a w to the left-hand side of the file dialog. |
|
4658 |
||
4659 |
\sa addRightWidget(), addWidgets(), addToolButton() |
|
4660 |
*/ |
|
4661 |
||
4662 |
void Q3FileDialog::addLeftWidget(QWidget *w) |
|
4663 |
{ |
|
4664 |
if (!w) |
|
4665 |
return; |
|
4666 |
d->geometryDirty = true; |
|
4667 |
||
4668 |
d->leftLayout->addWidget(w); |
|
4669 |
d->leftLayout->addSpacing(5); |
|
4670 |
||
4671 |
updateGeometries(); |
|
4672 |
} |
|
4673 |
||
4674 |
/*! |
|
4675 |
Adds the widget \a w to the right-hand side of the file dialog. |
|
4676 |
||
4677 |
\sa addLeftWidget(), addWidgets(), addToolButton() |
|
4678 |
*/ |
|
4679 |
||
4680 |
void Q3FileDialog::addRightWidget(QWidget *w) |
|
4681 |
{ |
|
4682 |
if (!w) |
|
4683 |
return; |
|
4684 |
d->geometryDirty = true; |
|
4685 |
||
4686 |
d->rightLayout->addSpacing(5); |
|
4687 |
d->rightLayout->addWidget(w); |
|
4688 |
||
4689 |
updateGeometries(); |
|
4690 |
} |
|
4691 |
||
4692 |
/*! \reimp */ |
|
4693 |
||
4694 |
void Q3FileDialog::keyPressEvent(QKeyEvent * ke) |
|
4695 |
{ |
|
4696 |
if (!d->ignoreNextKeyPress && |
|
4697 |
ke && (ke->key() == Qt::Key_Enter || |
|
4698 |
ke->key() == Qt::Key_Return)) { |
|
4699 |
ke->ignore(); |
|
4700 |
if (d->paths->hasFocus()) { |
|
4701 |
ke->accept(); |
|
4702 |
if (d->url == Q3Url(d->paths->currentText())) |
|
4703 |
nameEdit->setFocus(); |
|
4704 |
} else if (d->types->hasFocus()) { |
|
4705 |
ke->accept(); |
|
4706 |
// ### is there a suitable condition for this? only valid |
|
4707 |
// wildcards? |
|
4708 |
nameEdit->setFocus(); |
|
4709 |
} else if (nameEdit->hasFocus()) { |
|
4710 |
if (d->currentFileName.isNull()) { |
|
4711 |
// maybe change directory |
|
4712 |
QUrlInfo i(d->url.info(nameEdit->text().isEmpty() ? QString::fromLatin1(".") :nameEdit->text())); |
|
4713 |
if (i.isDir()) { |
|
4714 |
nameEdit->setText(QString::fromLatin1("")); |
|
4715 |
setDir(Q3UrlOperator(d->url, Q3FileDialogPrivate::encodeFileName(i.name()))); |
|
4716 |
} |
|
4717 |
ke->accept(); |
|
4718 |
} else if (mode() == ExistingFiles) { |
|
4719 |
QUrlInfo i(d->url.info(nameEdit->text().isEmpty() ? QString::fromLatin1(".") : nameEdit->text())); |
|
4720 |
if (i.isFile()) { |
|
4721 |
Q3ListViewItem * i = files->firstChild(); |
|
4722 |
while (i && nameEdit->text() != i->text(0)) |
|
4723 |
i = i->nextSibling(); |
|
4724 |
if (i) |
|
4725 |
files->setSelected(i, true); |
|
4726 |
else |
|
4727 |
ke->accept(); // strangely, means to ignore that event |
|
4728 |
} |
|
4729 |
} |
|
4730 |
} else if (files->hasFocus() || d->moreFiles->hasFocus()) { |
|
4731 |
ke->accept(); |
|
4732 |
} |
|
4733 |
} else if (ke->key() == Qt::Key_Escape) { |
|
4734 |
ke->ignore(); |
|
4735 |
} |
|
4736 |
||
4737 |
d->ignoreNextKeyPress = false; |
|
4738 |
||
4739 |
if (!ke->isAccepted()) { |
|
4740 |
QDialog::keyPressEvent(ke); |
|
4741 |
} |
|
4742 |
} |
|
4743 |
||
4744 |
||
4745 |
/*! \class Q3FileIconProvider |
|
4746 |
||
4747 |
\brief The Q3FileIconProvider class provides icons for Q3FileDialog to |
|
4748 |
use. |
|
4749 |
||
4750 |
\compat |
|
4751 |
||
4752 |
By default Q3FileIconProvider is not used, but any application or |
|
4753 |
library can subclass it, reimplement pixmap() to return a suitable |
|
4754 |
icon, and make all Q3FileDialog objects use it by calling the static |
|
4755 |
function Q3FileDialog::setIconProvider(). |
|
4756 |
||
4757 |
It is advisable to make all the icons that Q3FileIconProvider returns be |
|
4758 |
the same size or at least the same width. This makes the list view |
|
4759 |
look much better. |
|
4760 |
||
4761 |
\sa Q3FileDialog |
|
4762 |
*/ |
|
4763 |
||
4764 |
||
4765 |
/*! Constructs an empty file icon provider called \a name, with the |
|
4766 |
parent \a parent. |
|
4767 |
*/ |
|
4768 |
||
4769 |
Q3FileIconProvider::Q3FileIconProvider(QObject * parent, const char* name) |
|
4770 |
: QObject(parent, name) |
|
4771 |
{ |
|
4772 |
// nothing necessary |
|
4773 |
} |
|
4774 |
||
4775 |
||
4776 |
/*! |
|
4777 |
Returns a pointer to a pixmap that should be used to |
|
4778 |
signify the file with the information \a info. |
|
4779 |
||
4780 |
If pixmap() returns 0, Q3FileDialog draws the default pixmap. |
|
4781 |
||
4782 |
The default implementation returns particular icons for files, directories, |
|
4783 |
link-files and link-directories. It returns a blank "icon" for other types. |
|
4784 |
||
4785 |
If you return a pixmap here, it should measure 16x16 pixels. |
|
4786 |
*/ |
|
4787 |
||
4788 |
const QPixmap * Q3FileIconProvider::pixmap(const QFileInfo & info) |
|
4789 |
{ |
|
4790 |
if (info.isSymLink()) { |
|
4791 |
if (info.isFile()) |
|
4792 |
return symLinkFileIcon; |
|
4793 |
else |
|
4794 |
return symLinkDirIcon; |
|
4795 |
} else if (info.isDir()) { |
|
4796 |
return closedFolderIcon; |
|
4797 |
} else if (info.isFile()) { |
|
4798 |
return fileIcon; |
|
4799 |
} else { |
|
4800 |
return fifteenTransparentPixels; |
|
4801 |
} |
|
4802 |
} |
|
4803 |
||
4804 |
/*! |
|
4805 |
Sets the Q3FileIconProvider used by the file dialog to \a provider. |
|
4806 |
||
4807 |
The default is that there is no Q3FileIconProvider and Q3FileDialog |
|
4808 |
just draws a folder icon next to each directory and nothing next |
|
4809 |
to files. |
|
4810 |
||
4811 |
\sa Q3FileIconProvider, iconProvider() |
|
4812 |
*/ |
|
4813 |
||
4814 |
void Q3FileDialog::setIconProvider(Q3FileIconProvider * provider) |
|
4815 |
{ |
|
4816 |
fileIconProvider = provider; |
|
4817 |
} |
|
4818 |
||
4819 |
||
4820 |
/*! |
|
4821 |
Returns a pointer to the icon provider currently set on the file dialog. |
|
4822 |
By default there is no icon provider, and this function returns 0. |
|
4823 |
||
4824 |
\sa setIconProvider(), Q3FileIconProvider |
|
4825 |
*/ |
|
4826 |
||
4827 |
Q3FileIconProvider * Q3FileDialog::iconProvider() |
|
4828 |
{ |
|
4829 |
return fileIconProvider; |
|
4830 |
} |
|
4831 |
||
4832 |
||
4833 |
#if defined(Q_WS_WIN) |
|
4834 |
||
4835 |
// ### FIXME: this code is duplicated in qdns.cpp |
|
4836 |
static QString getWindowsRegString(HKEY key, const QString &subKey) |
|
4837 |
{ |
|
4838 |
QString s; |
|
4839 |
||
4840 |
wchar_t buf[1024]; |
|
4841 |
DWORD bsz = sizeof(buf) / sizeof(wchar_t); |
|
4842 |
int r = RegQueryValueEx(key, (wchar_t*)subKey.utf16(), 0, 0, (LPBYTE)buf, &bsz); |
|
4843 |
if (r == ERROR_SUCCESS) { |
|
4844 |
s = QString::fromWCharArray(buf); |
|
4845 |
} else if (r == ERROR_MORE_DATA) { |
|
4846 |
char *ptr = new char[bsz+1]; |
|
4847 |
r = RegQueryValueEx(key, (wchar_t*)subKey.utf16(), 0, 0, (LPBYTE)ptr, &bsz); |
|
4848 |
if (r == ERROR_SUCCESS) |
|
4849 |
s = QLatin1String(ptr); |
|
4850 |
delete [] ptr; |
|
4851 |
} |
|
4852 |
||
4853 |
return s; |
|
4854 |
} |
|
4855 |
||
4856 |
QPixmap fromHICON(HICON hIcon) |
|
4857 |
{ |
|
4858 |
ICONINFO icoInfo; |
|
4859 |
if (GetIconInfo(hIcon, &icoInfo) && icoInfo.hbmColor) { |
|
4860 |
return QPixmap::fromWinHBITMAP(icoInfo.hbmColor); |
|
4861 |
} |
|
4862 |
return QPixmap(); |
|
4863 |
} |
|
4864 |
||
4865 |
QWindowsIconProvider::QWindowsIconProvider(QObject *parent, const char *name) |
|
4866 |
: Q3FileIconProvider(parent, name) |
|
4867 |
{ |
|
4868 |
pixw = GetSystemMetrics(SM_CXSMICON); |
|
4869 |
pixh = GetSystemMetrics(SM_CYSMICON); |
|
4870 |
||
4871 |
HKEY k; |
|
4872 |
HICON si; |
|
4873 |
QString s; |
|
4874 |
UINT res = 0; |
|
4875 |
||
4876 |
// ---------- get default folder pixmap |
|
4877 |
const wchar_t iconFolder[] = L"folder\\DefaultIcon"; // workaround for Borland |
|
4878 |
int r = RegOpenKeyEx(HKEY_CLASSES_ROOT, iconFolder, 0, KEY_READ, &k); |
|
4879 |
||
4880 |
if (r == ERROR_SUCCESS) { |
|
4881 |
s = getWindowsRegString(k, QString()); |
|
4882 |
RegCloseKey(k); |
|
4883 |
||
4884 |
QStringList lst = QStringList::split(QLatin1String(","), s); |
|
4885 |
||
4886 |
if (lst.count() >= 2) { // don't just assume that lst has two entries |
|
4887 |
res = ExtractIconEx((wchar_t*)lst[0].simplifyWhiteSpace().utf16(), lst[1].simplifyWhiteSpace().toInt(), 0, &si, 1); |
|
4888 |
} |
|
4889 |
||
4890 |
if (res) { |
|
4891 |
defaultFolder = fromHICON(si); |
|
4892 |
defaultFolder.setMask(defaultFolder.createHeuristicMask()); |
|
4893 |
*closedFolderIcon = defaultFolder; |
|
4894 |
DestroyIcon(si); |
|
4895 |
} else { |
|
4896 |
defaultFolder = *closedFolderIcon; |
|
4897 |
} |
|
4898 |
} else { |
|
4899 |
RegCloseKey(k); |
|
4900 |
} |
|
4901 |
||
4902 |
//------------------------------- get default file pixmap |
|
4903 |
res = ExtractIconEx(L"shell32.dll", 0, 0, &si, 1); |
|
4904 |
||
4905 |
if (res) { |
|
4906 |
defaultFile = fromHICON(si); |
|
4907 |
defaultFile.setMask(defaultFile.createHeuristicMask()); |
|
4908 |
*fileIcon = defaultFile; |
|
4909 |
DestroyIcon(si); |
|
4910 |
} else { |
|
4911 |
defaultFile = *fileIcon; |
|
4912 |
} |
|
4913 |
||
4914 |
//------------------------------- get default exe pixmap |
|
4915 |
#ifndef Q_OS_WINCE |
|
4916 |
res = ExtractIconEx(L"shell32.dll", 2, 0, &si, 1); |
|
4917 |
#else |
|
4918 |
res = ExtractIconEx(L"ceshell.dll", 10, 0, &si, 1); |
|
4919 |
#endif |
|
4920 |
||
4921 |
if (res) { |
|
4922 |
defaultExe = fromHICON(si); |
|
4923 |
defaultExe.setMask(defaultExe.createHeuristicMask()); |
|
4924 |
DestroyIcon(si); |
|
4925 |
} else { |
|
4926 |
defaultExe = *fileIcon; |
|
4927 |
} |
|
4928 |
} |
|
4929 |
||
4930 |
QWindowsIconProvider::~QWindowsIconProvider() |
|
4931 |
{ |
|
4932 |
if (this == fileIconProvider) |
|
4933 |
fileIconProvider = 0; |
|
4934 |
} |
|
4935 |
||
4936 |
const QPixmap * QWindowsIconProvider::pixmap(const QFileInfo &fi) |
|
4937 |
{ |
|
4938 |
if (fi.isSymLink()) { |
|
4939 |
QString real = fi.symLinkTarget(); |
|
4940 |
if (!real.isEmpty()) |
|
4941 |
return pixmap(QFileInfo(real)); |
|
4942 |
} |
|
4943 |
||
4944 |
QString ext = fi.extension(false).upper(); |
|
4945 |
QString key = ext; |
|
4946 |
ext.prepend(QLatin1String(".")); |
|
4947 |
QMap< QString, QPixmap >::Iterator it; |
|
4948 |
||
4949 |
if (fi.isDir()) { |
|
4950 |
return &defaultFolder; |
|
4951 |
} else if (ext.toLower() != QLatin1String(".exe")) { |
|
4952 |
it = cache.find(key); |
|
4953 |
if (it != cache.end()) |
|
4954 |
return &(*it); |
|
4955 |
||
4956 |
HKEY k, k2; |
|
4957 |
int r = RegOpenKeyEx(HKEY_CLASSES_ROOT, (wchar_t*)ext.utf16(), 0, KEY_READ, &k); |
|
4958 |
QString s; |
|
4959 |
if (r == ERROR_SUCCESS) { |
|
4960 |
s = getWindowsRegString(k, QString()); |
|
4961 |
} else { |
|
4962 |
cache[key] = defaultFile; |
|
4963 |
RegCloseKey(k); |
|
4964 |
return &defaultFile; |
|
4965 |
} |
|
4966 |
RegCloseKey(k); |
|
4967 |
||
4968 |
r = RegOpenKeyEx(HKEY_CLASSES_ROOT, (wchar_t*)QString(s + QLatin1String("\\DefaultIcon")).utf16(), |
|
4969 |
0, KEY_READ, &k2); |
|
4970 |
if (r == ERROR_SUCCESS) { |
|
4971 |
s = getWindowsRegString(k2, QString()); |
|
4972 |
} else { |
|
4973 |
cache[key] = defaultFile; |
|
4974 |
RegCloseKey(k2); |
|
4975 |
return &defaultFile; |
|
4976 |
} |
|
4977 |
RegCloseKey(k2); |
|
4978 |
||
4979 |
if (s.isEmpty()) |
|
4980 |
return &defaultFile; |
|
4981 |
||
4982 |
QStringList lst = QStringList::split(QLatin1String(","), s); |
|
4983 |
||
4984 |
HICON si; |
|
4985 |
UINT res = 0; |
|
4986 |
if (lst.count() >= 2) { // don't just assume that lst has two entries |
|
4987 |
QString filepath = lst[0].stripWhiteSpace(); |
|
4988 |
if (!filepath.isEmpty()) { |
|
4989 |
if (filepath.find(QLatin1String("%1")) != -1) { |
|
4990 |
filepath = filepath.arg(fi.filePath()); |
|
4991 |
if (ext.toLower() == QLatin1String(".dll")) { |
|
4992 |
pix = defaultFile; |
|
4993 |
return &pix; |
|
4994 |
} |
|
4995 |
} |
|
4996 |
if (filepath[0] == QLatin1Char('"') && filepath[(int)filepath.length()-1] == QLatin1Char('"')) |
|
4997 |
filepath = filepath.mid(1, filepath.length()-2); |
|
4998 |
||
4999 |
res = ExtractIconEx((wchar_t*)filepath.utf16(), lst[1].stripWhiteSpace().toInt(), 0, &si, 1); |
|
5000 |
} |
|
5001 |
} |
|
5002 |
if (res) { |
|
5003 |
pix = fromHICON(si); |
|
5004 |
pix.setMask(pix.createHeuristicMask()); |
|
5005 |
DestroyIcon(si); |
|
5006 |
} else { |
|
5007 |
pix = defaultFile; |
|
5008 |
} |
|
5009 |
||
5010 |
cache[key] = pix; |
|
5011 |
return &pix; |
|
5012 |
} else { |
|
5013 |
HICON si; |
|
5014 |
UINT res = 0; |
|
5015 |
if (!fi.absFilePath().isEmpty()) { |
|
5016 |
res = ExtractIconEx((wchar_t*)fi.absFilePath().utf16(), -1, 0, 0, 1); |
|
5017 |
if (res) |
|
5018 |
res = ExtractIconEx((wchar_t*)fi.absFilePath().utf16(), res - 1, 0, &si, 1); |
|
5019 |
} |
|
5020 |
||
5021 |
if (res) { |
|
5022 |
pix = fromHICON(si); |
|
5023 |
pix.setMask(pix.createHeuristicMask()); |
|
5024 |
DestroyIcon(si); |
|
5025 |
} else { |
|
5026 |
pix = defaultExe; |
|
5027 |
} |
|
5028 |
||
5029 |
return &pix; |
|
5030 |
} |
|
5031 |
||
5032 |
// can't happen! |
|
5033 |
return 0; |
|
5034 |
} |
|
5035 |
#endif |
|
5036 |
||
5037 |
||
5038 |
||
5039 |
/*! |
|
5040 |
\reimp |
|
5041 |
*/ |
|
5042 |
bool Q3FileDialog::eventFilter(QObject * o, QEvent * e) |
|
5043 |
{ |
|
5044 |
if (e->type() == QEvent::KeyPress && ((QKeyEvent*)e)->key() == Qt::Key_F5) { |
|
5045 |
rereadDir(); |
|
5046 |
((QKeyEvent *)e)->accept(); |
|
5047 |
return true; |
|
5048 |
} else if (e->type() == QEvent::KeyPress && ((QKeyEvent*)e)->key() == Qt::Key_F2 && |
|
5049 |
(o == files || o == files->viewport())) { |
|
5050 |
if (files->isVisible() && files->currentItem()) { |
|
5051 |
if (QUrlInfo(d->url.info(QString(QLatin1Char('.')))).isWritable() && files->currentItem()->text(0) != QLatin1String("..")) { |
|
5052 |
files->renameItem = files->currentItem(); |
|
5053 |
files->startRename(true); |
|
5054 |
} |
|
5055 |
} |
|
5056 |
((QKeyEvent *)e)->accept(); |
|
5057 |
return true; |
|
5058 |
} else if (e->type() == QEvent::KeyPress && ((QKeyEvent*)e)->key() == Qt::Key_F2 && |
|
5059 |
(o == d->moreFiles || o == d->moreFiles->viewport())) { |
|
5060 |
if (d->moreFiles->isVisible() && d->moreFiles->currentItem() != -1) { |
|
5061 |
if (QUrlInfo(d->url.info(QString(QLatin1Char('.')))).isWritable() && |
|
5062 |
d->moreFiles->item(d->moreFiles->currentItem())->text() != QLatin1String("..")) { |
|
5063 |
d->moreFiles->renameItem = d->moreFiles->item(d->moreFiles->currentItem()); |
|
5064 |
d->moreFiles->startRename(true); |
|
5065 |
} |
|
5066 |
} |
|
5067 |
((QKeyEvent *)e)->accept(); |
|
5068 |
return true; |
|
5069 |
} else if (e->type() == QEvent::KeyPress && d->moreFiles->renaming) { |
|
5070 |
d->moreFiles->lined->setFocus(); |
|
5071 |
QApplication::sendEvent(d->moreFiles->lined, e); |
|
5072 |
((QKeyEvent *)e)->accept(); |
|
5073 |
return true; |
|
5074 |
} else if (e->type() == QEvent::KeyPress && files->renaming) { |
|
5075 |
files->lined->setFocus(); |
|
5076 |
QApplication::sendEvent(files->lined, e); |
|
5077 |
((QKeyEvent *)e)->accept(); |
|
5078 |
return true; |
|
5079 |
} else if (e->type() == QEvent::KeyPress && |
|
5080 |
((QKeyEvent *)e)->key() == Qt::Key_Backspace && |
|
5081 |
(o == files || |
|
5082 |
o == d->moreFiles || |
|
5083 |
o == files->viewport() || |
|
5084 |
o == d->moreFiles->viewport())) { |
|
5085 |
cdUpClicked(); |
|
5086 |
((QKeyEvent *)e)->accept(); |
|
5087 |
return true; |
|
5088 |
} else if (e->type() == QEvent::KeyPress && |
|
5089 |
((QKeyEvent *)e)->key() == Qt::Key_Delete && |
|
5090 |
(o == files || |
|
5091 |
o == files->viewport())) { |
|
5092 |
if (files->currentItem()) |
|
5093 |
deleteFile(files->currentItem()->text(0)); |
|
5094 |
((QKeyEvent *)e)->accept(); |
|
5095 |
return true; |
|
5096 |
} else if (e->type() == QEvent::KeyPress && |
|
5097 |
((QKeyEvent *)e)->key() == Qt::Key_Delete && |
|
5098 |
(o == d->moreFiles || |
|
5099 |
o == d->moreFiles->viewport())) { |
|
5100 |
int c = d->moreFiles->currentItem(); |
|
5101 |
if (c >= 0) |
|
5102 |
deleteFile(d->moreFiles->item(c)->text()); |
|
5103 |
((QKeyEvent *)e)->accept(); |
|
5104 |
return true; |
|
5105 |
} else if (o == files && e->type() == QEvent::FocusOut && files->currentItem()) { |
|
5106 |
} else if (o == files && e->type() == QEvent::KeyPress) { |
|
5107 |
QTimer::singleShot(0, this, SLOT(fixupNameEdit())); |
|
5108 |
} else if (o == nameEdit && e->type() == QEvent::KeyPress && d->mode != AnyFile) { |
|
5109 |
if ((nameEdit->cursorPosition() == (int)nameEdit->text().length() || nameEdit->hasSelectedText()) && |
|
5110 |
isprint(((QKeyEvent *)e)->ascii())) { |
|
5111 |
#if defined(Q_WS_WIN) |
|
5112 |
QString nt(nameEdit->text().toLower()); |
|
5113 |
#else |
|
5114 |
QString nt(nameEdit->text()); |
|
5115 |
#endif |
|
5116 |
nt.truncate(nameEdit->cursorPosition()); |
|
5117 |
nt += QLatin1Char((char)(((QKeyEvent *)e)->ascii())); |
|
5118 |
Q3ListViewItem * i = files->firstChild(); |
|
5119 |
#if defined(Q_WS_WIN) |
|
5120 |
while(i && i->text(0).left(nt.length()).toLower() != nt) |
|
5121 |
#else |
|
5122 |
while(i && i->text(0).left(nt.length()) != nt) |
|
5123 |
#endif |
|
5124 |
i = i->nextSibling(); |
|
5125 |
if (i) { |
|
5126 |
nt = i->text(0); |
|
5127 |
int cp = nameEdit->cursorPosition()+1; |
|
5128 |
nameEdit->validateAndSet(nt, cp, cp, nt.length()); |
|
5129 |
return true; |
|
5130 |
} |
|
5131 |
} |
|
5132 |
} else if (o == nameEdit && e->type() == QEvent::FocusIn) { |
|
5133 |
fileNameEditDone(); |
|
5134 |
} else if (d->moreFiles->renaming && o != d->moreFiles->lined && e->type() == QEvent::FocusIn) { |
|
5135 |
d->moreFiles->lined->setFocus(); |
|
5136 |
return true; |
|
5137 |
} else if (files->renaming && o != files->lined && e->type() == QEvent::FocusIn) { |
|
5138 |
files->lined->setFocus(); |
|
5139 |
return true; |
|
5140 |
} else if ((o == d->moreFiles || o == d->moreFiles->viewport()) && |
|
5141 |
e->type() == QEvent::FocusIn) { |
|
5142 |
if ((o == d->moreFiles->viewport() && !d->moreFiles->viewport()->hasFocus()) |
|
5143 |
|| (o == d->moreFiles && !d->moreFiles->hasFocus())) |
|
5144 |
((QWidget*)o)->setFocus(); |
|
5145 |
return false; |
|
5146 |
} |
|
5147 |
||
5148 |
return QDialog::eventFilter(o, e); |
|
5149 |
} |
|
5150 |
||
5151 |
/*! |
|
5152 |
Sets the filters used in the file dialog to \a filters. Each group |
|
5153 |
of filters must be separated by \c{;;} (\e two semicolons). |
|
5154 |
||
5155 |
\snippet doc/src/snippets/code/src_qt3support_dialogs_q3filedialog.cpp 14 |
|
5156 |
||
5157 |
*/ |
|
5158 |
||
5159 |
void Q3FileDialog::setFilters(const QString &filters) |
|
5160 |
{ |
|
5161 |
QStringList lst = makeFiltersList(filters); |
|
5162 |
setFilters(lst); |
|
5163 |
} |
|
5164 |
||
5165 |
/*! |
|
5166 |
\overload |
|
5167 |
||
5168 |
\a types must be a null-terminated list of strings. |
|
5169 |
||
5170 |
*/ |
|
5171 |
||
5172 |
void Q3FileDialog::setFilters(const char ** types) |
|
5173 |
{ |
|
5174 |
if (!types || !*types) |
|
5175 |
return; |
|
5176 |
||
5177 |
d->types->clear(); |
|
5178 |
while(types && *types) { |
|
5179 |
d->types->insertItem(QString::fromLatin1(*types)); |
|
5180 |
types++; |
|
5181 |
} |
|
5182 |
d->types->setCurrentItem(0); |
|
5183 |
setFilter(d->types->text(0)); |
|
5184 |
} |
|
5185 |
||
5186 |
||
5187 |
/*! |
|
5188 |
\overload |
|
5189 |
||
5190 |
\a types is a list of filter strings. |
|
5191 |
*/ |
|
5192 |
||
5193 |
void Q3FileDialog::setFilters(const QStringList & types) |
|
5194 |
{ |
|
5195 |
if (types.count() < 1) |
|
5196 |
return; |
|
5197 |
||
5198 |
d->types->clear(); |
|
5199 |
for (QStringList::ConstIterator it = types.begin(); it != types.end(); ++it) |
|
5200 |
d->types->insertItem(*it); |
|
5201 |
d->types->setCurrentItem(0); |
|
5202 |
setFilter(d->types->text(0)); |
|
5203 |
} |
|
5204 |
||
5205 |
/*! |
|
5206 |
Adds the filter \a filter to the list of filters and makes it the |
|
5207 |
current filter. |
|
5208 |
||
5209 |
\snippet doc/src/snippets/code/src_qt3support_dialogs_q3filedialog.cpp 15 |
|
5210 |
||
5211 |
In the above example, a file dialog is created, and the file filter "Images |
|
5212 |
(*.png *.jpg *.xpm)" is added and is set as the current filter. The original |
|
5213 |
filter, "All Files (*)", is still available. |
|
5214 |
||
5215 |
\sa setFilter(), setFilters() |
|
5216 |
*/ |
|
5217 |
||
5218 |
void Q3FileDialog::addFilter(const QString &filter) |
|
5219 |
{ |
|
5220 |
if (filter.isEmpty()) |
|
5221 |
return; |
|
5222 |
QString f = filter; |
|
5223 |
QRegExp r(QString::fromLatin1(qt3_file_dialog_filter_reg_exp)); |
|
5224 |
int index = r.indexIn(f); |
|
5225 |
if (index >= 0) |
|
5226 |
f = r.cap(2); |
|
5227 |
for (int i = 0; i < d->types->count(); ++i) { |
|
5228 |
QString f2(d->types->text(i)); |
|
5229 |
int index = r.indexIn(f2); |
|
5230 |
if (index >= 0) |
|
5231 |
f2 = r.cap(1); |
|
5232 |
if (f2 == f) { |
|
5233 |
d->types->setCurrentItem(i); |
|
5234 |
setFilter(f2); |
|
5235 |
return; |
|
5236 |
} |
|
5237 |
} |
|
5238 |
||
5239 |
d->types->insertItem(filter); |
|
5240 |
d->types->setCurrentItem(d->types->count() - 1); |
|
5241 |
setFilter(d->types->text(d->types->count() - 1)); |
|
5242 |
} |
|
5243 |
||
5244 |
/*! |
|
5245 |
Since modeButtons is a top-level widget, it may be destroyed by the |
|
5246 |
kernel at application exit. Notice if this happens to |
|
5247 |
avoid double deletion. |
|
5248 |
*/ |
|
5249 |
||
5250 |
void Q3FileDialog::modeButtonsDestroyed() |
|
5251 |
{ |
|
5252 |
if (d) |
|
5253 |
d->modeButtons = 0; |
|
5254 |
} |
|
5255 |
||
5256 |
||
5257 |
/*! |
|
5258 |
This is a convenience static function that will return one or more |
|
5259 |
existing files selected by the user. |
|
5260 |
||
5261 |
\snippet doc/src/snippets/code/src_qt3support_dialogs_q3filedialog.cpp 16 |
|
5262 |
||
5263 |
This function creates a modal file dialog called \a name, with |
|
5264 |
parent \a parent. If \a parent is not 0, the dialog will be shown |
|
5265 |
centered over the parent. |
|
5266 |
||
5267 |
The file dialog's working directory will be set to \a dir. If \a |
|
5268 |
dir includes a file name, the file will be selected. The filter |
|
5269 |
is set to \a filter so that only those files which match the filter |
|
5270 |
are shown. The filter selected is set to \a selectedFilter. The parameters |
|
5271 |
\a dir, \a selectedFilter and \a filter may be empty strings. |
|
5272 |
||
5273 |
The dialog's caption is set to \a caption. If \a caption is not |
|
5274 |
specified then a default caption will be used. |
|
5275 |
||
5276 |
Under Windows and Mac OS X, this static function will use the native |
|
5277 |
file dialog and not a Q3FileDialog, unless the style of the application |
|
5278 |
is set to something other than the native style. (Note that on Windows the |
|
5279 |
dialog will spin a blocking modal event loop that will not dispatch any |
|
5280 |
QTimers and if parent is not 0 then it will position the dialog just under |
|
5281 |
the parent's title bar). |
|
5282 |
||
5283 |
Under Unix/X11, the normal behavior of the file dialog is to resolve |
|
5284 |
and follow symlinks. For example, if /usr/tmp is a symlink to /var/tmp, |
|
5285 |
the file dialog will change to /var/tmp after entering /usr/tmp. |
|
5286 |
If \a resolveSymlinks is false, the file dialog will treat |
|
5287 |
symlinks as regular directories. |
|
5288 |
||
5289 |
Note that if you want to iterate over the list of files, you should |
|
5290 |
iterate over a copy, e.g. |
|
5291 |
\snippet doc/src/snippets/code/src_qt3support_dialogs_q3filedialog.cpp 17 |
|
5292 |
||
5293 |
\sa getOpenFileName(), getSaveFileName(), getExistingDirectory() |
|
5294 |
*/ |
|
5295 |
||
5296 |
QStringList Q3FileDialog::getOpenFileNames(const QString & filter, |
|
5297 |
const QString& dir, |
|
5298 |
QWidget *parent, |
|
5299 |
const char* name, |
|
5300 |
const QString& caption, |
|
5301 |
QString *selectedFilter, |
|
5302 |
bool resolveSymlinks) |
|
5303 |
{ |
|
5304 |
bool save_qt_resolve_symlinks = qt_resolve_symlinks; |
|
5305 |
qt_resolve_symlinks = resolveSymlinks; |
|
5306 |
||
5307 |
QStringList filters; |
|
5308 |
if (!filter.isEmpty()) |
|
5309 |
filters = makeFiltersList(filter); |
|
5310 |
||
5311 |
makeVariables(); |
|
5312 |
||
5313 |
if (workingDirectory->isNull()) |
|
5314 |
*workingDirectory = toRootIfNotExists( QDir::currentDirPath() ); |
|
5315 |
||
5316 |
if (!dir.isEmpty()) { |
|
5317 |
// #### works only correct for local files |
|
5318 |
Q3UrlOperator u(Q3FileDialogPrivate::encodeFileName(dir)); |
|
5319 |
if (u.isLocalFile() && QFileInfo(u.path()).isDir()) { |
|
5320 |
*workingDirectory = dir; |
|
5321 |
} else { |
|
5322 |
*workingDirectory = u.toString(); |
|
5323 |
} |
|
5324 |
} |
|
5325 |
||
5326 |
#if defined(Q_WS_WIN) |
|
5327 |
if (qt_use_native_dialogs && qobject_cast<QWindowsStyle *>(qApp->style())) |
|
5328 |
return winGetOpenFileNames(filter, workingDirectory, parent, name, caption, selectedFilter); |
|
5329 |
#elif defined(Q_WS_MAC) |
|
5330 |
if (qt_use_native_dialogs && qobject_cast<QMacStyle *>(qApp->style())) { |
|
5331 |
QStringList sl = macGetOpenFileNames(filter, dir.isEmpty() ? 0 : workingDirectory, |
|
5332 |
parent, name, caption, selectedFilter); |
|
5333 |
for (int i = 0; i < sl.count(); ++i) |
|
5334 |
sl.replace(i, sl.at(i).normalized(QString::NormalizationForm_C)); |
|
5335 |
return sl; |
|
5336 |
} |
|
5337 |
#endif |
|
5338 |
||
5339 |
Q3FileDialog *dlg = new Q3FileDialog(*workingDirectory, QString(), parent, name ? name : "qt_filedlg_gofns", true); |
|
5340 |
||
5341 |
if (!caption.isNull()) |
|
5342 |
dlg->setWindowTitle(caption); |
|
5343 |
else |
|
5344 |
dlg->setWindowTitle(Q3FileDialog::tr("Open")); |
|
5345 |
||
5346 |
dlg->setFilters(filters); |
|
5347 |
if (selectedFilter) |
|
5348 |
dlg->setFilter(*selectedFilter); |
|
5349 |
dlg->setMode(Q3FileDialog::ExistingFiles); |
|
5350 |
QString result; |
|
5351 |
QStringList lst; |
|
5352 |
if (dlg->exec() == QDialog::Accepted) { |
|
5353 |
lst = dlg->selectedFiles(); |
|
5354 |
*workingDirectory = dlg->d->url; |
|
5355 |
if (selectedFilter) |
|
5356 |
*selectedFilter = dlg->selectedFilter(); |
|
5357 |
} |
|
5358 |
delete dlg; |
|
5359 |
||
5360 |
qt_resolve_symlinks = save_qt_resolve_symlinks; |
|
5361 |
||
5362 |
return lst; |
|
5363 |
} |
|
5364 |
||
5365 |
/*! Updates the line edit to match the speed-key usage in Q3ListView. */ |
|
5366 |
||
5367 |
void Q3FileDialog::fixupNameEdit() |
|
5368 |
{ |
|
5369 |
if (files->currentItem()) { |
|
5370 |
if (((Q3FileDialogPrivate::File*)files->currentItem())->info.isFile()) |
|
5371 |
nameEdit->setText(files->currentItem()->text(0)); |
|
5372 |
} |
|
5373 |
} |
|
5374 |
||
5375 |
/*! |
|
5376 |
Returns the URL of the current working directory in the file dialog. |
|
5377 |
||
5378 |
\sa setUrl() |
|
5379 |
*/ |
|
5380 |
||
5381 |
Q3Url Q3FileDialog::url() const |
|
5382 |
{ |
|
5383 |
return d->url; |
|
5384 |
} |
|
5385 |
||
5386 |
static bool isRoot(const Q3Url &u) |
|
5387 |
{ |
|
5388 |
#if defined(Q_OS_UNIX) |
|
5389 |
if (u.path() == QString(QLatin1Char('/'))) |
|
5390 |
return true; |
|
5391 |
#elif defined(Q_OS_WIN32) |
|
5392 |
QString p = u.path(); |
|
5393 |
if (p.length() == 3 && |
|
5394 |
p.right(2) == QLatin1String(":/")) |
|
5395 |
return true; |
|
5396 |
if (p[0] == QLatin1Char('/') && p[1] == QLatin1Char('/')) { |
|
5397 |
int slashes = p.count(QLatin1Char('/')); |
|
5398 |
if (slashes <= 3) |
|
5399 |
return true; |
|
5400 |
if (slashes == 4 && p[(int)p.length() - 1] == QLatin1Char('/')) |
|
5401 |
return true; |
|
5402 |
} |
|
5403 |
#else |
|
5404 |
#if defined(Q_CC_GNU) |
|
5405 |
#warning "case not covered.." |
|
5406 |
#endif |
|
5407 |
#endif |
|
5408 |
||
5409 |
if (!u.isLocalFile() && u.path() == QString(QLatin1Char('/'))) |
|
5410 |
return true; |
|
5411 |
||
5412 |
return false; |
|
5413 |
} |
|
5414 |
||
5415 |
#if defined(Q_WS_WIN) |
|
5416 |
extern Q_CORE_EXPORT int qt_ntfs_permission_lookup; |
|
5417 |
#endif |
|
5418 |
||
5419 |
void Q3FileDialog::urlStart(Q3NetworkOperation *op) |
|
5420 |
{ |
|
5421 |
if (!op) |
|
5422 |
return; |
|
5423 |
||
5424 |
#if defined(Q_WS_WIN) |
|
5425 |
old_qt_ntfs_permission_lookup = qt_ntfs_permission_lookup; |
|
5426 |
qt_ntfs_permission_lookup = 0; |
|
5427 |
#endif |
|
5428 |
if (op->operation() == Q3NetworkProtocol::OpListChildren) { |
|
5429 |
#ifndef QT_NO_CURSOR |
|
5430 |
if (!d->cursorOverride) { |
|
5431 |
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); |
|
5432 |
d->cursorOverride = true; |
|
5433 |
} |
|
5434 |
#endif |
|
5435 |
if (isRoot(d->url)) |
|
5436 |
d->cdToParent->setEnabled(false); |
|
5437 |
else |
|
5438 |
d->cdToParent->setEnabled(true); |
|
5439 |
d->mimeTypeTimer->stop(); |
|
5440 |
d->sortedList.clear(); |
|
5441 |
d->pendingItems.clear(); |
|
5442 |
d->moreFiles->clearSelection(); |
|
5443 |
files->clearSelection(); |
|
5444 |
d->moreFiles->clear(); |
|
5445 |
files->clear(); |
|
5446 |
files->setSorting(-1); |
|
5447 |
||
5448 |
QString s = d->url.toString(false, false); |
|
5449 |
bool found = false; |
|
5450 |
for (int i = 0; i < d->paths->count(); ++i) { |
|
5451 |
#if defined(Q_WS_WIN) |
|
5452 |
if (d->paths->text(i).toLower() == s.toLower()) { |
|
5453 |
#else |
|
5454 |
if (d->paths->text(i) == s) { |
|
5455 |
#endif |
|
5456 |
found = true; |
|
5457 |
d->paths->setCurrentItem(i); |
|
5458 |
break; |
|
5459 |
} |
|
5460 |
} |
|
5461 |
if (!found) { |
|
5462 |
d->paths->insertItem(*openFolderIcon, s, -1); |
|
5463 |
d->paths->setCurrentItem(d->paths->count() - 1); |
|
5464 |
} |
|
5465 |
d->last = 0; |
|
5466 |
d->hadDotDot = false; |
|
5467 |
||
5468 |
if (d->goBack && (d->history.isEmpty() || d->history.last() != d->url.toString())) { |
|
5469 |
d->history.append(d->url.toString()); |
|
5470 |
if (d->history.count() > 1) |
|
5471 |
d->goBack->setEnabled(true); |
|
5472 |
} |
|
5473 |
} |
|
5474 |
} |
|
5475 |
||
5476 |
void Q3FileDialog::urlFinished(Q3NetworkOperation *op) |
|
5477 |
{ |
|
5478 |
if (!op) |
|
5479 |
return; |
|
5480 |
||
5481 |
#ifndef QT_NO_CURSOR |
|
5482 |
if (op->operation() == Q3NetworkProtocol::OpListChildren && |
|
5483 |
d->cursorOverride) { |
|
5484 |
QApplication::restoreOverrideCursor(); |
|
5485 |
d->cursorOverride = false; |
|
5486 |
} |
|
5487 |
#endif |
|
5488 |
||
5489 |
if (op->state() == Q3NetworkProtocol::StFailed) { |
|
5490 |
if (d->paths->hasFocus()) |
|
5491 |
d->ignoreNextKeyPress = true; |
|
5492 |
||
5493 |
if (d->progressDia) { |
|
5494 |
d->ignoreStop = true; |
|
5495 |
d->progressDia->close(); |
|
5496 |
delete d->progressDia; |
|
5497 |
d->progressDia = 0; |
|
5498 |
} |
|
5499 |
||
5500 |
int ecode = op->errorCode(); |
|
5501 |
QMessageBox::critical(this, tr("Error"), op->protocolDetail()); |
|
5502 |
||
5503 |
if (ecode == Q3NetworkProtocol::ErrListChildren || ecode == Q3NetworkProtocol::ErrParse || |
|
5504 |
ecode == Q3NetworkProtocol::ErrUnknownProtocol || ecode == Q3NetworkProtocol::ErrLoginIncorrect || |
|
5505 |
ecode == Q3NetworkProtocol::ErrValid || ecode == Q3NetworkProtocol::ErrHostNotFound || |
|
5506 |
ecode == Q3NetworkProtocol::ErrFileNotExisting) { |
|
5507 |
d->url = d->oldUrl; |
|
5508 |
rereadDir(); |
|
5509 |
} else { |
|
5510 |
// another error happened, no need to go back to last dir |
|
5511 |
} |
|
5512 |
} else if (op->operation() == Q3NetworkProtocol::OpListChildren && |
|
5513 |
op == d->currListChildren) { |
|
5514 |
if (!d->hadDotDot && !isRoot(d->url)) { |
|
5515 |
bool ok = true; |
|
5516 |
#if defined(Q_WS_WIN) |
|
5517 |
if (d->url.path().left(2) == QLatin1String("//")) |
|
5518 |
ok = false; |
|
5519 |
#endif |
|
5520 |
if (ok) { |
|
5521 |
QUrlInfo ui(d->url.info(QLatin1String(".."))); |
|
5522 |
ui.setName(QLatin1String("..")); |
|
5523 |
ui.setDir(true); |
|
5524 |
ui.setFile(false); |
|
5525 |
ui.setSymLink(false); |
|
5526 |
ui.setSize(0); |
|
5527 |
Q3ValueList<QUrlInfo> lst; |
|
5528 |
lst << ui; |
|
5529 |
insertEntry(lst, 0); |
|
5530 |
} |
|
5531 |
} |
|
5532 |
resortDir(); |
|
5533 |
} else if (op->operation() == Q3NetworkProtocol::OpGet) { |
|
5534 |
} else if (op->operation() == Q3NetworkProtocol::OpPut) { |
|
5535 |
rereadDir(); |
|
5536 |
if (d->progressDia) { |
|
5537 |
d->ignoreStop = true; |
|
5538 |
d->progressDia->close(); |
|
5539 |
} |
|
5540 |
delete d->progressDia; |
|
5541 |
d->progressDia = 0; |
|
5542 |
} |
|
5543 |
||
5544 |
#if defined(Q_WS_WIN) |
|
5545 |
qt_ntfs_permission_lookup = old_qt_ntfs_permission_lookup; |
|
5546 |
#endif |
|
5547 |
} |
|
5548 |
||
5549 |
void Q3FileDialog::dataTransferProgress(int bytesDone, int bytesTotal, Q3NetworkOperation *op) |
|
5550 |
{ |
|
5551 |
if (!op) |
|
5552 |
return; |
|
5553 |
||
5554 |
QString label; |
|
5555 |
Q3Url u(op->arg(0)); |
|
5556 |
if (u.isLocalFile()) { |
|
5557 |
label = u.path(); |
|
5558 |
} else { |
|
5559 |
label = QLatin1String("%1 (on %2)"); |
|
5560 |
label = label.arg(u.path()).arg(u.host()); |
|
5561 |
} |
|
5562 |
||
5563 |
if (!d->progressDia) { |
|
5564 |
if (bytesDone < bytesTotal) { |
|
5565 |
d->ignoreStop = false; |
|
5566 |
d->progressDia = new QFDProgressDialog(this, label, bytesTotal); |
|
5567 |
connect(d->progressDia, SIGNAL(cancelled()), |
|
5568 |
this, SLOT(stopCopy())); |
|
5569 |
d->progressDia->show(); |
|
5570 |
} else |
|
5571 |
return; |
|
5572 |
} |
|
5573 |
||
5574 |
if (d->progressDia) { |
|
5575 |
if (op->operation() == Q3NetworkProtocol::OpGet) { |
|
5576 |
if (d->progressDia) { |
|
5577 |
d->progressDia->setReadProgress(bytesDone); |
|
5578 |
} |
|
5579 |
} else if (op->operation() == Q3NetworkProtocol::OpPut) { |
|
5580 |
if (d->progressDia) { |
|
5581 |
d->progressDia->setWriteLabel(label); |
|
5582 |
d->progressDia->setWriteProgress(bytesDone); |
|
5583 |
} |
|
5584 |
} else { |
|
5585 |
return; |
|
5586 |
} |
|
5587 |
} |
|
5588 |
} |
|
5589 |
||
5590 |
void Q3FileDialog::insertEntry(const Q3ValueList<QUrlInfo> &lst, Q3NetworkOperation *op) |
|
5591 |
{ |
|
5592 |
if (op && op->operation() == Q3NetworkProtocol::OpListChildren && |
|
5593 |
op != d->currListChildren) |
|
5594 |
return; |
|
5595 |
Q3ValueList<QUrlInfo>::ConstIterator it = lst.begin(); |
|
5596 |
for (; it != lst.end(); ++it) { |
|
5597 |
const QUrlInfo &inf = *it; |
|
5598 |
if (d->mode == DirectoryOnly && !inf.isDir()) |
|
5599 |
continue; |
|
5600 |
if (inf.name() == QLatin1String("..")) { |
|
5601 |
d->hadDotDot = true; |
|
5602 |
if (isRoot(d->url)) |
|
5603 |
continue; |
|
5604 |
#if defined(Q_WS_WIN) |
|
5605 |
if (d->url.path().left(2) == QLatin1String("//")) |
|
5606 |
continue; |
|
5607 |
#endif |
|
5608 |
} else if (inf.name() == QString(QLatin1Char('.'))) |
|
5609 |
continue; |
|
5610 |
||
5611 |
#if defined(Q_WS_WIN) |
|
5612 |
// Workaround a Windows bug, '..' is apparantly hidden in directories |
|
5613 |
// that are one level away from root |
|
5614 |
if (!bShowHiddenFiles && inf.name() != QLatin1String("..")) { |
|
5615 |
if (d->url.isLocalFile()) { |
|
5616 |
QString file = d->url.path(); |
|
5617 |
if (!file.endsWith(QLatin1Char('/'))) |
|
5618 |
file.append(QLatin1Char('/')); |
|
5619 |
file += inf.name(); |
|
5620 |
if (GetFileAttributes((wchar_t*)file.utf16()) & FILE_ATTRIBUTE_HIDDEN) |
|
5621 |
continue; |
|
5622 |
} else { |
|
5623 |
if (inf.name() != QLatin1String("..") && inf.name()[0] == QLatin1Char('.')) |
|
5624 |
continue; |
|
5625 |
} |
|
5626 |
} |
|
5627 |
#else |
|
5628 |
if (!bShowHiddenFiles && inf.name() != QLatin1String("..")) { |
|
5629 |
if (inf.name()[0] == QLatin1Char('.')) |
|
5630 |
continue; |
|
5631 |
} |
|
5632 |
#endif |
|
5633 |
if (!d->url.isLocalFile()) { |
|
5634 |
Q3FileDialogPrivate::File * i = 0; |
|
5635 |
Q3FileDialogPrivate::MCItem *i2 = 0; |
|
5636 |
i = new Q3FileDialogPrivate::File(d, &inf, files); |
|
5637 |
i2 = new Q3FileDialogPrivate::MCItem(d->moreFiles, i); |
|
5638 |
||
5639 |
if ((d->mode == ExistingFiles && inf.isDir()) |
|
5640 |
|| (isDirectoryMode(d->mode) && inf.isFile())) { |
|
5641 |
i->setSelectable(false); |
|
5642 |
i2->setSelectable(false); |
|
5643 |
} |
|
5644 |
||
5645 |
i->i = i2; |
|
5646 |
} |
|
5647 |
||
5648 |
d->sortedList.append(new QUrlInfo(inf)); |
|
5649 |
} |
|
5650 |
} |
|
5651 |
||
5652 |
void Q3FileDialog::removeEntry(Q3NetworkOperation *op) |
|
5653 |
{ |
|
5654 |
if (!op) |
|
5655 |
return; |
|
5656 |
||
5657 |
QUrlInfo *i = 0; |
|
5658 |
Q3ListViewItemIterator it(files); |
|
5659 |
bool ok1 = false, ok2 = false; |
|
5660 |
for (i = d->sortedList.first(); it.current(); ++it, i = d->sortedList.next()) { |
|
5661 |
QString encName = Q3FileDialogPrivate::encodeFileName( |
|
5662 |
((Q3FileDialogPrivate::File*)it.current())->info.name()); |
|
5663 |
if (encName == op->arg(0)) { |
|
5664 |
d->pendingItems.removeRef((Q3FileDialogPrivate::File*)it.current()); |
|
5665 |
delete ((Q3FileDialogPrivate::File*)it.current())->i; |
|
5666 |
delete it.current(); |
|
5667 |
ok1 = true; |
|
5668 |
} |
|
5669 |
if (i && i->name() == op->arg(0)) { |
|
5670 |
d->sortedList.removeRef(i); |
|
5671 |
i = d->sortedList.prev(); |
|
5672 |
ok2 = true; |
|
5673 |
} |
|
5674 |
if (ok1 && ok2) |
|
5675 |
break; |
|
5676 |
} |
|
5677 |
} |
|
5678 |
||
5679 |
void Q3FileDialog::itemChanged(Q3NetworkOperation *op) |
|
5680 |
{ |
|
5681 |
if (!op) |
|
5682 |
return; |
|
5683 |
||
5684 |
QUrlInfo *i = 0; |
|
5685 |
Q3ListViewItemIterator it1(files); |
|
5686 |
bool ok1 = false, ok2 = false; |
|
5687 |
// first check whether the new file replaces an existing file. |
|
5688 |
for (i = d->sortedList.first(); it1.current(); ++it1, i = d->sortedList.next()) { |
|
5689 |
if (((Q3FileDialogPrivate::File*)it1.current())->info.name() == op->arg(1)) { |
|
5690 |
delete ((Q3FileDialogPrivate::File*)it1.current())->i; |
|
5691 |
delete it1.current(); |
|
5692 |
ok1 = true; |
|
5693 |
} |
|
5694 |
if (i && i->name() == op->arg(1)) { |
|
5695 |
d->sortedList.removeRef(i); |
|
5696 |
i = d->sortedList.prev(); |
|
5697 |
ok2 = true; |
|
5698 |
} |
|
5699 |
if (ok1 && ok2) |
|
5700 |
break; |
|
5701 |
} |
|
5702 |
||
5703 |
i = 0; |
|
5704 |
Q3ListViewItemIterator it(files); |
|
5705 |
ok1 = false; |
|
5706 |
ok2 = false; |
|
5707 |
for (i = d->sortedList.first(); it.current(); ++it, i = d->sortedList.next()) { |
|
5708 |
if (((Q3FileDialogPrivate::File*)it.current())->info.name() == op->arg(0)) { |
|
5709 |
((Q3FileDialogPrivate::File*)it.current())->info.setName(op->arg(1)); |
|
5710 |
ok1 = true; |
|
5711 |
} |
|
5712 |
if (i && i->name() == op->arg(0)) { |
|
5713 |
i->setName(op->arg(1)); |
|
5714 |
ok2 = true; |
|
5715 |
} |
|
5716 |
if (ok1 && ok2) |
|
5717 |
break; |
|
5718 |
} |
|
5719 |
||
5720 |
resortDir(); |
|
5721 |
} |
|
5722 |
||
5723 |
/*! |
|
5724 |
\property Q3FileDialog::infoPreview |
|
5725 |
||
5726 |
\brief whether the file dialog can provide preview information about |
|
5727 |
the currently selected file |
|
5728 |
||
5729 |
The default is false. |
|
5730 |
*/ |
|
5731 |
bool Q3FileDialog::isInfoPreviewEnabled() const |
|
5732 |
{ |
|
5733 |
return d->infoPreview; |
|
5734 |
} |
|
5735 |
||
5736 |
void Q3FileDialog::setInfoPreviewEnabled(bool info) |
|
5737 |
{ |
|
5738 |
if (info == d->infoPreview) |
|
5739 |
return; |
|
5740 |
d->geometryDirty = true; |
|
5741 |
d->infoPreview = info; |
|
5742 |
updateGeometries(); |
|
5743 |
} |
|
5744 |
||
5745 |
||
5746 |
/*! |
|
5747 |
\property Q3FileDialog::contentsPreview |
|
5748 |
||
5749 |
\brief whether the file dialog can provide a contents preview of the |
|
5750 |
currently selected file |
|
5751 |
||
5752 |
The default is false. |
|
5753 |
||
5754 |
\sa setContentsPreview() setInfoPreviewEnabled() |
|
5755 |
*/ |
|
5756 |
// ### improve the above documentation: how is the preview done, how can I add |
|
5757 |
// support for customized preview, etc. |
|
5758 |
||
5759 |
bool Q3FileDialog::isContentsPreviewEnabled() const |
|
5760 |
{ |
|
5761 |
return d->contentsPreview; |
|
5762 |
} |
|
5763 |
||
5764 |
void Q3FileDialog::setContentsPreviewEnabled(bool contents) |
|
5765 |
{ |
|
5766 |
if (contents == d->contentsPreview) |
|
5767 |
return; |
|
5768 |
d->geometryDirty = true; |
|
5769 |
d->contentsPreview = contents; |
|
5770 |
updateGeometries(); |
|
5771 |
} |
|
5772 |
||
5773 |
||
5774 |
/*! |
|
5775 |
Sets the widget to be used for displaying information about the file |
|
5776 |
to the widget \a w and a preview of that information to the |
|
5777 |
Q3FilePreview \a preview. |
|
5778 |
||
5779 |
Normally you would create a preview widget that derives from both QWidget and |
|
5780 |
Q3FilePreview, so you should pass the same widget twice. |
|
5781 |
||
5782 |
\snippet doc/src/snippets/code/src_qt3support_dialogs_q3filedialog.cpp 18 |
|
5783 |
||
5784 |
\sa setContentsPreview(), setInfoPreviewEnabled(), setPreviewMode() |
|
5785 |
||
5786 |
*/ |
|
5787 |
||
5788 |
void Q3FileDialog::setInfoPreview(QWidget *w, Q3FilePreview *preview) |
|
5789 |
{ |
|
5790 |
if (!w || !preview) |
|
5791 |
return; |
|
5792 |
||
5793 |
if (d->infoPreviewWidget) { |
|
5794 |
d->preview->removeWidget(d->infoPreviewWidget); |
|
5795 |
if ((void*)d->infoPreviewer == (void*)d->infoPreviewWidget) |
|
5796 |
d->infoPreviewer = 0; |
|
5797 |
delete d->infoPreviewWidget; |
|
5798 |
} |
|
5799 |
if (d->infoPreviewer) |
|
5800 |
delete d->infoPreviewer; |
|
5801 |
d->infoPreviewWidget = w; |
|
5802 |
d->infoPreviewer = preview; |
|
5803 |
w->reparent(d->preview, 0, QPoint(0, 0)); |
|
5804 |
} |
|
5805 |
||
5806 |
/*! |
|
5807 |
Sets the widget to be used for displaying the contents of the file |
|
5808 |
to the widget \a w and a preview of those contents to the |
|
5809 |
Q3FilePreview \a preview. |
|
5810 |
||
5811 |
Normally you would create a preview widget that derives from both QWidget and |
|
5812 |
Q3FilePreview, so you should pass the same widget twice. |
|
5813 |
||
5814 |
\snippet doc/src/snippets/code/src_qt3support_dialogs_q3filedialog.cpp 19 |
|
5815 |
||
5816 |
\sa setContentsPreviewEnabled(), setInfoPreview(), setPreviewMode() |
|
5817 |
*/ |
|
5818 |
||
5819 |
void Q3FileDialog::setContentsPreview(QWidget *w, Q3FilePreview *preview) |
|
5820 |
{ |
|
5821 |
if (!w || !preview) |
|
5822 |
return; |
|
5823 |
||
5824 |
if (d->contentsPreviewWidget) { |
|
5825 |
d->preview->removeWidget(d->contentsPreviewWidget); |
|
5826 |
if ((void*)d->contentsPreviewWidget == (void*)d->contentsPreviewer) |
|
5827 |
d->contentsPreviewer = 0; |
|
5828 |
delete d->contentsPreviewWidget; |
|
5829 |
} |
|
5830 |
if (d->contentsPreviewer) |
|
5831 |
delete d->contentsPreviewer; |
|
5832 |
d->contentsPreviewWidget = w; |
|
5833 |
d->contentsPreviewer = preview; |
|
5834 |
w->reparent(d->preview, 0, QPoint(0, 0)); |
|
5835 |
} |
|
5836 |
||
5837 |
/*! |
|
5838 |
Re-sorts the displayed directory. |
|
5839 |
||
5840 |
\sa rereadDir() |
|
5841 |
*/ |
|
5842 |
||
5843 |
void Q3FileDialog::resortDir() |
|
5844 |
{ |
|
5845 |
d->mimeTypeTimer->stop(); |
|
5846 |
d->pendingItems.clear(); |
|
5847 |
||
5848 |
Q3FileDialogPrivate::File *item = 0; |
|
5849 |
Q3FileDialogPrivate::MCItem *item2 = 0; |
|
5850 |
||
5851 |
d->sortedList.sort(); |
|
5852 |
||
5853 |
if (files->childCount() > 0 || d->moreFiles->count() > 0) { |
|
5854 |
d->moreFiles->clear(); |
|
5855 |
files->clear(); |
|
5856 |
d->last = 0; |
|
5857 |
files->setSorting(-1); |
|
5858 |
} |
|
5859 |
||
5860 |
QUrlInfo *i = sortAscending ? d->sortedList.first() : d->sortedList.last(); |
|
5861 |
for (; i; i = sortAscending ? d->sortedList.next() : d->sortedList.prev()) { |
|
5862 |
item = new Q3FileDialogPrivate::File(d, i, files); |
|
5863 |
item2 = new Q3FileDialogPrivate::MCItem(d->moreFiles, item, item2); |
|
5864 |
item->i = item2; |
|
5865 |
d->pendingItems.append(item); |
|
5866 |
if ((d->mode == ExistingFiles && item->info.isDir()) || |
|
5867 |
(isDirectoryMode(d->mode) && item->info.isFile())) { |
|
5868 |
item->setSelectable(false); |
|
5869 |
item2->setSelectable(false); |
|
5870 |
} |
|
5871 |
} |
|
5872 |
||
5873 |
// ##### As the Q3FileIconProvider only support QFileInfo and no |
|
5874 |
// QUrlInfo it can be only used for local files at the moment. In |
|
5875 |
// 3.0 we have to change the API of Q3FileIconProvider to work on |
|
5876 |
// QUrlInfo so that also remote filesystems can be show mime-type |
|
5877 |
// specific icons. |
|
5878 |
if (d->url.isLocalFile()) |
|
5879 |
d->mimeTypeTimer->start(0); |
|
5880 |
} |
|
5881 |
||
5882 |
/*! |
|
5883 |
Stops the current copy operation. |
|
5884 |
*/ |
|
5885 |
||
5886 |
void Q3FileDialog::stopCopy() |
|
5887 |
{ |
|
5888 |
if (d->ignoreStop) |
|
5889 |
return; |
|
5890 |
||
5891 |
d->url.blockSignals(true); |
|
5892 |
d->url.stop(); |
|
5893 |
if (d->progressDia) { |
|
5894 |
d->ignoreStop = true; |
|
5895 |
QTimer::singleShot(100, this, SLOT(removeProgressDia())); |
|
5896 |
} |
|
5897 |
d->url.blockSignals(false); |
|
5898 |
} |
|
5899 |
||
5900 |
/*! |
|
5901 |
\internal |
|
5902 |
*/ |
|
5903 |
||
5904 |
void Q3FileDialog::removeProgressDia() |
|
5905 |
{ |
|
5906 |
if (d->progressDia) |
|
5907 |
delete d->progressDia; |
|
5908 |
d->progressDia = 0; |
|
5909 |
} |
|
5910 |
||
5911 |
/*! |
|
5912 |
\internal |
|
5913 |
*/ |
|
5914 |
||
5915 |
void Q3FileDialog::doMimeTypeLookup() |
|
5916 |
{ |
|
5917 |
if (!iconProvider()) { |
|
5918 |
d->pendingItems.clear(); |
|
5919 |
d->mimeTypeTimer->stop(); |
|
5920 |
return; |
|
5921 |
} |
|
5922 |
||
5923 |
d->mimeTypeTimer->stop(); |
|
5924 |
if (d->pendingItems.count() == 0) { |
|
5925 |
return; |
|
5926 |
} |
|
5927 |
||
5928 |
QRect r; |
|
5929 |
Q3FileDialogPrivate::File *item = d->pendingItems.first(); |
|
5930 |
if (item) { |
|
5931 |
QFileInfo fi; |
|
5932 |
if (d->url.isLocalFile()) { |
|
5933 |
fi.setFile(Q3Url(d->url.path(), Q3FileDialogPrivate::encodeFileName(item->info.name())).path(false)); |
|
5934 |
} else |
|
5935 |
fi.setFile(item->info.name()); // ##### |
|
5936 |
const QPixmap *p = iconProvider()->pixmap(fi); |
|
5937 |
if (p && p != item->pixmap(0) && |
|
5938 |
(!item->pixmap(0) || p->serialNumber() != item->pixmap(0)->serialNumber()) && |
|
5939 |
p != fifteenTransparentPixels) { |
|
5940 |
item->hasMimePixmap = true; |
|
5941 |
||
5942 |
// evil hack to avoid much too much repaints! |
|
5943 |
QPointer<Q3FileDialog> that(this); // this may be deleted by an event handler |
|
5944 |
qApp->processEvents(); |
|
5945 |
if (that.isNull()) |
|
5946 |
return; |
|
5947 |
files->setUpdatesEnabled(false); |
|
5948 |
files->viewport()->setUpdatesEnabled(false); |
|
5949 |
if (item != d->pendingItems.first()) |
|
5950 |
return; |
|
5951 |
item->setPixmap(0, *p); |
|
5952 |
qApp->processEvents(); |
|
5953 |
if (that.isNull()) |
|
5954 |
return; |
|
5955 |
files->setUpdatesEnabled(true); |
|
5956 |
files->viewport()->setUpdatesEnabled(true); |
|
5957 |
||
5958 |
if (files->isVisible()) { |
|
5959 |
QRect ir(files->itemRect(item)); |
|
5960 |
if (ir != QRect(0, 0, -1, -1)) { |
|
5961 |
r = r.united(ir); |
|
5962 |
} |
|
5963 |
} else { |
|
5964 |
QRect ir(d->moreFiles->itemRect(item->i)); |
|
5965 |
if (ir != QRect(0, 0, -1, -1)) { |
|
5966 |
r = r.united(ir); |
|
5967 |
} |
|
5968 |
} |
|
5969 |
} |
|
5970 |
if (d->pendingItems.count()) |
|
5971 |
d->pendingItems.removeFirst(); |
|
5972 |
} |
|
5973 |
||
5974 |
if (d->moreFiles->isVisible()) { |
|
5975 |
d->moreFiles->viewport()->repaint(r); |
|
5976 |
} else { |
|
5977 |
files->viewport()->repaint(r); |
|
5978 |
} |
|
5979 |
||
5980 |
if (d->pendingItems.count()) |
|
5981 |
d->mimeTypeTimer->start(0); |
|
5982 |
else if (d->moreFiles->isVisible()) |
|
5983 |
d->moreFiles->triggerUpdate(true); |
|
5984 |
} |
|
5985 |
||
5986 |
/*! |
|
5987 |
If \a b is true then all the files in the current directory are selected; |
|
5988 |
otherwise, they are deselected. |
|
5989 |
*/ |
|
5990 |
||
5991 |
void Q3FileDialog::selectAll(bool b) |
|
5992 |
{ |
|
5993 |
if (d->mode != ExistingFiles) |
|
5994 |
return; |
|
5995 |
d->moreFiles->selectAll(b); |
|
5996 |
files->selectAll(b); |
|
5997 |
} |
|
5998 |
||
5999 |
void Q3FileDialog::goBack() |
|
6000 |
{ |
|
6001 |
if (!d->goBack || !d->goBack->isEnabled() || d->history.isEmpty()) |
|
6002 |
return; |
|
6003 |
d->history.removeLast(); |
|
6004 |
if (d->history.size() < 2) |
|
6005 |
d->goBack->setEnabled(false); |
|
6006 |
setUrl(d->history.last()); |
|
6007 |
} |
|
6008 |
||
6009 |
// a class with wonderfully inflexible flexibility. why doesn't it |
|
6010 |
// just subclass QWidget in the first place? 'you have to derive your |
|
6011 |
// preview widget from QWidget and from this class' indeed. |
|
6012 |
||
6013 |
/*! |
|
6014 |
\class Q3FilePreview |
|
6015 |
\brief The Q3FilePreview class provides file previewing in Q3FileDialog. |
|
6016 |
||
6017 |
\compat |
|
6018 |
||
6019 |
This class is an abstract base class which is used to implement |
|
6020 |
widgets that can display a preview of a file in a Q3FileDialog. |
|
6021 |
||
6022 |
You must derive the preview widget from both QWidget and from this |
|
6023 |
class. Then you must reimplement this class's previewUrl() function, |
|
6024 |
which is called by the file dialog if the preview of a file |
|
6025 |
(specified as a URL) should be shown. |
|
6026 |
||
6027 |
See also Q3FileDialog::setPreviewMode(), Q3FileDialog::setContentsPreview(), |
|
6028 |
Q3FileDialog::setInfoPreview(), Q3FileDialog::setInfoPreviewEnabled(), |
|
6029 |
Q3FileDialog::setContentsPreviewEnabled(). |
|
6030 |
*/ |
|
6031 |
||
6032 |
/*! |
|
6033 |
Constructs the Q3FilePreview. |
|
6034 |
*/ |
|
6035 |
||
6036 |
Q3FilePreview::Q3FilePreview() |
|
6037 |
{ |
|
6038 |
} |
|
6039 |
||
6040 |
/*! |
|
6041 |
\fn Q3FilePreview::~Q3FilePreview() |
|
6042 |
||
6043 |
Destroys the file preview object. |
|
6044 |
*/ |
|
6045 |
||
6046 |
/*! |
|
6047 |
\fn void Q3FilePreview::previewUrl(const Q3Url &url) |
|
6048 |
||
6049 |
This function is called by Q3FileDialog if a preview |
|
6050 |
for the \a url should be shown. Reimplement this |
|
6051 |
function to provide file previewing. |
|
6052 |
*/ |
|
6053 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6054 |
|
0 | 6055 |
QT_END_NAMESPACE |
6056 |
||
6057 |
#include "moc_q3filedialog.cpp" |
|
6058 |
#include "q3filedialog.moc" |
|
6059 |
||
6060 |
#endif |