author | zecke <zecke> | 2005-02-07 22:41:59 (UTC) |
---|---|---|
committer | zecke <zecke> | 2005-02-07 22:41:59 (UTC) |
commit | f112fe72adcfb8d3c6745c6ff878cbfbbdfbfa24 (patch) (unidiff) | |
tree | 95f03410ad60ed5d04486821e9bc76cf1e3664ec | |
parent | 2e4fd59ce900490ccbbb6c0f7b2fcd4811ac8a07 (diff) | |
download | opie-f112fe72adcfb8d3c6745c6ff878cbfbbdfbfa24.zip opie-f112fe72adcfb8d3c6745c6ff878cbfbbdfbfa24.tar.gz opie-f112fe72adcfb8d3c6745c6ff878cbfbbdfbfa24.tar.bz2 |
Fix for #1482, do not start a path with "//". We do that by having
a method to assemble paths to avoid adding a second "/"
-rw-r--r-- | libopie2/opieui/fileselector/ofileselector.cpp | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/libopie2/opieui/fileselector/ofileselector.cpp b/libopie2/opieui/fileselector/ofileselector.cpp index 718f743..74aca96 100644 --- a/libopie2/opieui/fileselector/ofileselector.cpp +++ b/libopie2/opieui/fileselector/ofileselector.cpp | |||
@@ -1,128 +1,138 @@ | |||
1 | 1 | ||
2 | /* | 2 | /* |
3 | =. This file is part of the OPIE Project | 3 | =. This file is part of the OPIE Project |
4 | .=l. Copyright (C) 2002,2003 Holger Freyther <zecke@handhelds.org> | 4 | .=l. Copyright (C) 2002,2003 Holger Freyther <zecke@handhelds.org> |
5 | .>+-= | 5 | .>+-= |
6 | _;:, .> :=|. This library is free software; you can | 6 | _;:, .> :=|. This library is free software; you can |
7 | .> <`_, > . <= redistribute it and/or modify it under | 7 | .> <`_, > . <= redistribute it and/or modify it under |
8 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 8 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
9 | .="- .-=="i, .._ License as published by the Free Software | 9 | .="- .-=="i, .._ License as published by the Free Software |
10 | - . .-<_> .<> Foundation; either version 2 of the License, | 10 | - . .-<_> .<> Foundation; either version 2 of the License, |
11 | ._= =} : or (at your option) any later version. | 11 | ._= =} : or (at your option) any later version. |
12 | .%`+i> _;_. | 12 | .%`+i> _;_. |
13 | .i_,=:_. -<s. This library is distributed in the hope that | 13 | .i_,=:_. -<s. This library is distributed in the hope that |
14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
15 | : .. .:, . . . without even the implied warranty of | 15 | : .. .:, . . . without even the implied warranty of |
16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
18 | ..}^=.= = ; Library General Public License for more | 18 | ..}^=.= = ; Library General Public License for more |
19 | ++= -. .` .: details. | 19 | ++= -. .` .: details. |
20 | : = ...= . :.=- | 20 | : = ...= . :.=- |
21 | -. .:....=;==+<; You should have received a copy of the GNU | 21 | -. .:....=;==+<; You should have received a copy of the GNU |
22 | -_. . . )=. = Library General Public License along with | 22 | -_. . . )=. = Library General Public License along with |
23 | -- :-=` this library; see the file COPYING.LIB. | 23 | -- :-=` this library; see the file COPYING.LIB. |
24 | If not, write to the Free Software Foundation, | 24 | If not, write to the Free Software Foundation, |
25 | Inc., 59 Temple Place - Suite 330, | 25 | Inc., 59 Temple Place - Suite 330, |
26 | Boston, MA 02111-1307, USA. | 26 | Boston, MA 02111-1307, USA. |
27 | 27 | ||
28 | */ | 28 | */ |
29 | 29 | ||
30 | /* hacky but we need to get FileSelector::filter */ | 30 | /* hacky but we need to get FileSelector::filter */ |
31 | #define private public | 31 | #define private public |
32 | #include <qpe/fileselector.h> | 32 | #include <qpe/fileselector.h> |
33 | #undef private | 33 | #undef private |
34 | 34 | ||
35 | #include "ofileselector_p.h" | 35 | #include "ofileselector_p.h" |
36 | 36 | ||
37 | /* OPIE */ | 37 | /* OPIE */ |
38 | #include <opie2/ofileselector.h> | 38 | #include <opie2/ofileselector.h> |
39 | #include <opie2/odebug.h> | 39 | #include <opie2/odebug.h> |
40 | 40 | ||
41 | #include <qpe/qpeapplication.h> | 41 | #include <qpe/qpeapplication.h> |
42 | #include <qpe/mimetype.h> | 42 | #include <qpe/mimetype.h> |
43 | #include <qpe/resource.h> | 43 | #include <qpe/resource.h> |
44 | #include <qpe/storage.h> | 44 | #include <qpe/storage.h> |
45 | 45 | ||
46 | /* QT */ | 46 | /* QT */ |
47 | #include <qcombobox.h> | 47 | #include <qcombobox.h> |
48 | #include <qdir.h> | 48 | #include <qdir.h> |
49 | #include <qhbox.h> | 49 | #include <qhbox.h> |
50 | #include <qheader.h> | 50 | #include <qheader.h> |
51 | #include <qlabel.h> | 51 | #include <qlabel.h> |
52 | #include <qlayout.h> | 52 | #include <qlayout.h> |
53 | #include <qlineedit.h> | 53 | #include <qlineedit.h> |
54 | #include <qlistview.h> | 54 | #include <qlistview.h> |
55 | #include <qpopupmenu.h> | 55 | #include <qpopupmenu.h> |
56 | #include <qwidgetstack.h> | 56 | #include <qwidgetstack.h> |
57 | #include <qregexp.h> | 57 | #include <qregexp.h> |
58 | #include <qobjectlist.h> | 58 | #include <qobjectlist.h> |
59 | 59 | ||
60 | using namespace Opie::Ui::Internal; | 60 | using namespace Opie::Ui::Internal; |
61 | 61 | ||
62 | namespace Opie { | 62 | namespace Opie { |
63 | namespace Ui { | 63 | namespace Ui { |
64 | namespace Internal { | 64 | namespace Internal { |
65 | /* | ||
66 | * Create a path by adding a '/'/QDir::seperator in between | ||
67 | * base and ending, but only if base is not empty | ||
68 | */ | ||
69 | static inline QString createNewPath(const QString& base, const QString &ending) { | ||
70 | return base == QString::fromLatin1("/") ? | ||
71 | base + ending : base + "/" + ending; | ||
72 | } | ||
73 | |||
74 | |||
65 | OFileViewInterface::OFileViewInterface( OFileSelector* _selector ) | 75 | OFileViewInterface::OFileViewInterface( OFileSelector* _selector ) |
66 | : m_selector( _selector ) | 76 | : m_selector( _selector ) |
67 | { | 77 | { |
68 | selector()->registerView( this ); | 78 | selector()->registerView( this ); |
69 | } | 79 | } |
70 | 80 | ||
71 | OFileViewInterface::~OFileViewInterface() | 81 | OFileViewInterface::~OFileViewInterface() |
72 | {} | 82 | {} |
73 | 83 | ||
74 | QString OFileViewInterface::name()const | 84 | QString OFileViewInterface::name()const |
75 | { | 85 | { |
76 | return m_name; | 86 | return m_name; |
77 | } | 87 | } |
78 | 88 | ||
79 | void OFileViewInterface::setName( const QString& name ) | 89 | void OFileViewInterface::setName( const QString& name ) |
80 | { | 90 | { |
81 | m_name = name; | 91 | m_name = name; |
82 | } | 92 | } |
83 | 93 | ||
84 | OFileSelector* OFileViewInterface::selector()const | 94 | OFileSelector* OFileViewInterface::selector()const |
85 | { | 95 | { |
86 | return m_selector; | 96 | return m_selector; |
87 | } | 97 | } |
88 | 98 | ||
89 | DocLnk OFileViewInterface::selectedDocument()const | 99 | DocLnk OFileViewInterface::selectedDocument()const |
90 | { | 100 | { |
91 | return DocLnk( selectedName() ); | 101 | return DocLnk( selectedName() ); |
92 | } | 102 | } |
93 | 103 | ||
94 | bool OFileViewInterface::showNew()const | 104 | bool OFileViewInterface::showNew()const |
95 | { | 105 | { |
96 | return selector()->showNew(); | 106 | return selector()->showNew(); |
97 | } | 107 | } |
98 | 108 | ||
99 | bool OFileViewInterface::showClose()const | 109 | bool OFileViewInterface::showClose()const |
100 | { | 110 | { |
101 | return selector()->showClose(); | 111 | return selector()->showClose(); |
102 | } | 112 | } |
103 | 113 | ||
104 | MimeTypes OFileViewInterface::mimeTypes()const | 114 | MimeTypes OFileViewInterface::mimeTypes()const |
105 | { | 115 | { |
106 | return selector()->mimeTypes(); | 116 | return selector()->mimeTypes(); |
107 | } | 117 | } |
108 | 118 | ||
109 | QStringList OFileViewInterface::currentMimeType()const | 119 | QStringList OFileViewInterface::currentMimeType()const |
110 | { | 120 | { |
111 | return selector()->currentMimeType(); | 121 | return selector()->currentMimeType(); |
112 | } | 122 | } |
113 | 123 | ||
114 | void OFileViewInterface::activate( const QString& ) | 124 | void OFileViewInterface::activate( const QString& ) |
115 | { | 125 | { |
116 | // not implemented here | 126 | // not implemented here |
117 | } | 127 | } |
118 | 128 | ||
119 | void OFileViewInterface::ok() | 129 | void OFileViewInterface::ok() |
120 | { | 130 | { |
121 | emit selector()->ok(); | 131 | emit selector()->ok(); |
122 | } | 132 | } |
123 | 133 | ||
124 | void OFileViewInterface::cancel() | 134 | void OFileViewInterface::cancel() |
125 | { | 135 | { |
126 | emit selector()->cancel(); | 136 | emit selector()->cancel(); |
127 | } | 137 | } |
128 | 138 | ||
@@ -409,307 +419,307 @@ OFileSelectorItem* OFileViewFileListView::currentItem()const | |||
409 | { | 419 | { |
410 | QListViewItem* item = m_view->currentItem(); | 420 | QListViewItem* item = m_view->currentItem(); |
411 | if (!item ) | 421 | if (!item ) |
412 | return 0l; | 422 | return 0l; |
413 | 423 | ||
414 | return static_cast<OFileSelectorItem*>(item); | 424 | return static_cast<OFileSelectorItem*>(item); |
415 | } | 425 | } |
416 | 426 | ||
417 | void OFileViewFileListView::reread( bool all ) | 427 | void OFileViewFileListView::reread( bool all ) |
418 | { | 428 | { |
419 | m_view->clear(); | 429 | m_view->clear(); |
420 | 430 | ||
421 | if (selector()->showClose() ) | 431 | if (selector()->showClose() ) |
422 | m_btnClose->show(); | 432 | m_btnClose->show(); |
423 | else | 433 | else |
424 | m_btnClose->hide(); | 434 | m_btnClose->hide(); |
425 | 435 | ||
426 | if (selector()->showNew() ) | 436 | if (selector()->showNew() ) |
427 | m_btnNew->show(); | 437 | m_btnNew->show(); |
428 | else | 438 | else |
429 | m_btnNew->hide(); | 439 | m_btnNew->hide(); |
430 | 440 | ||
431 | m_mimes = selector()->currentMimeType(); | 441 | m_mimes = selector()->currentMimeType(); |
432 | m_all = all; | 442 | m_all = all; |
433 | 443 | ||
434 | QDir dir( m_currentDir ); | 444 | QDir dir( m_currentDir ); |
435 | if (!dir.exists() ) | 445 | if (!dir.exists() ) |
436 | return; | 446 | return; |
437 | 447 | ||
438 | dir.setSorting( QDir::Name | QDir::DirsFirst | QDir::Reversed ); | 448 | dir.setSorting( QDir::Name | QDir::DirsFirst | QDir::Reversed ); |
439 | int filter; | 449 | int filter; |
440 | filter = QDir::Dirs; | 450 | filter = QDir::Dirs; |
441 | if ( selector()->mode() != OFileSelector::DIRECTORYSELECTOR ) | 451 | if ( selector()->mode() != OFileSelector::DIRECTORYSELECTOR ) |
442 | filter = filter | QDir::Files | QDir::All; | 452 | filter = filter | QDir::Files | QDir::All; |
443 | 453 | ||
444 | if ( m_all ) | 454 | if ( m_all ) |
445 | filter = filter | QDir::Hidden; | 455 | filter = filter | QDir::Hidden; |
446 | 456 | ||
447 | dir.setFilter( filter ); | 457 | dir.setFilter( filter ); |
448 | 458 | ||
449 | // now go through all files | 459 | // now go through all files |
450 | const QFileInfoList *list = dir.entryInfoList(); | 460 | const QFileInfoList *list = dir.entryInfoList(); |
451 | if (!list) | 461 | if (!list) |
452 | { | 462 | { |
453 | cdUP(); | 463 | cdUP(); |
454 | return; | 464 | return; |
455 | } | 465 | } |
456 | 466 | ||
457 | QFileInfoListIterator it( *list ); | 467 | QFileInfoListIterator it( *list ); |
458 | QFileInfo *fi; | 468 | QFileInfo *fi; |
459 | while( (fi=it.current() ) ) | 469 | while( (fi=it.current() ) ) |
460 | { | 470 | { |
461 | if( fi->fileName() == QString::fromLatin1("..") || fi->fileName() == QString::fromLatin1(".") ) | 471 | if( fi->fileName() == QString::fromLatin1("..") || fi->fileName() == QString::fromLatin1(".") ) |
462 | { | 472 | { |
463 | ++it; | 473 | ++it; |
464 | continue; | 474 | continue; |
465 | } | 475 | } |
466 | 476 | ||
467 | /* | 477 | /* |
468 | * It is a symlink we try to resolve it now but don't let us attack by DOS | 478 | * It is a symlink we try to resolve it now but don't let us attack by DOS |
469 | * | 479 | * |
470 | */ | 480 | */ |
471 | if( fi->isSymLink() ) | 481 | if( fi->isSymLink() ) |
472 | { | 482 | { |
473 | QString file = fi->dirPath( true ) + "/" + fi->readLink(); | 483 | QString file = createNewPath(fi->dirPath( true ),fi->readLink()); |
474 | for( int i = 0; i<=4; i++) | 484 | for( int i = 0; i<=4; i++) |
475 | { // 5 tries to prevent dos | 485 | { // 5 tries to prevent dos |
476 | QFileInfo info( file ); | 486 | QFileInfo info( file ); |
477 | if( !info.exists() ) | 487 | if( !info.exists() ) |
478 | { | 488 | { |
479 | addSymlink( fi, TRUE ); | 489 | addSymlink( fi, TRUE ); |
480 | break; | 490 | break; |
481 | } | 491 | } |
482 | else if( info.isDir() ) | 492 | else if( info.isDir() ) |
483 | { | 493 | { |
484 | addDir( fi, TRUE ); | 494 | addDir( fi, TRUE ); |
485 | break; | 495 | break; |
486 | } | 496 | } |
487 | else if( info.isFile() ) | 497 | else if( info.isFile() ) |
488 | { | 498 | { |
489 | addFile( fi, TRUE ); | 499 | addFile( fi, TRUE ); |
490 | break; | 500 | break; |
491 | } | 501 | } |
492 | else if( info.isSymLink() ) | 502 | else if( info.isSymLink() ) |
493 | { | 503 | { |
494 | file = info.dirPath(true ) + "/" + info.readLink() ; | 504 | file = createNewPath(info.dirPath(true ),info.readLink()); |
495 | break; | 505 | break; |
496 | } | 506 | } |
497 | else if( i == 4) | 507 | else if( i == 4) |
498 | { // couldn't resolve symlink add it as symlink | 508 | { // couldn't resolve symlink add it as symlink |
499 | addSymlink( fi ); | 509 | addSymlink( fi ); |
500 | } | 510 | } |
501 | } // off for loop for symlink resolving | 511 | } // off for loop for symlink resolving |
502 | } | 512 | } |
503 | else if( fi->isDir() ) | 513 | else if( fi->isDir() ) |
504 | addDir( fi ); | 514 | addDir( fi ); |
505 | else if( fi->isFile() ) | 515 | else if( fi->isFile() ) |
506 | addFile( fi ); | 516 | addFile( fi ); |
507 | 517 | ||
508 | ++it; | 518 | ++it; |
509 | } // of while loop | 519 | } // of while loop |
510 | m_view->sort(); | 520 | m_view->sort(); |
511 | 521 | ||
512 | } | 522 | } |
513 | int OFileViewFileListView::fileCount()const | 523 | int OFileViewFileListView::fileCount()const |
514 | { | 524 | { |
515 | return m_view->childCount(); | 525 | return m_view->childCount(); |
516 | } | 526 | } |
517 | 527 | ||
518 | QString OFileViewFileListView::currentDir()const | 528 | QString OFileViewFileListView::currentDir()const |
519 | { | 529 | { |
520 | return m_currentDir; | 530 | return m_currentDir; |
521 | } | 531 | } |
522 | 532 | ||
523 | OFileSelector* OFileViewFileListView::selector() | 533 | OFileSelector* OFileViewFileListView::selector() |
524 | { | 534 | { |
525 | return m_sel; | 535 | return m_sel; |
526 | } | 536 | } |
527 | 537 | ||
528 | bool OFileViewFileListView::eventFilter (QObject *, QEvent *e) | 538 | bool OFileViewFileListView::eventFilter (QObject *, QEvent *e) |
529 | { | 539 | { |
530 | if ( e->type() == QEvent::KeyPress ) | 540 | if ( e->type() == QEvent::KeyPress ) |
531 | { | 541 | { |
532 | QKeyEvent *k = (QKeyEvent *)e; | 542 | QKeyEvent *k = (QKeyEvent *)e; |
533 | if ( (k->key()==Key_Enter) || (k->key()==Key_Return)) | 543 | if ( (k->key()==Key_Enter) || (k->key()==Key_Return)) |
534 | { | 544 | { |
535 | slotClicked( Qt::LeftButton,m_view->currentItem(),QPoint(0,0),0); | 545 | slotClicked( Qt::LeftButton,m_view->currentItem(),QPoint(0,0),0); |
536 | return true; | 546 | return true; |
537 | } | 547 | } |
538 | } | 548 | } |
539 | return false; | 549 | return false; |
540 | } | 550 | } |
541 | 551 | ||
542 | void OFileViewFileListView::connectSlots() | 552 | void OFileViewFileListView::connectSlots() |
543 | { | 553 | { |
544 | connect(m_view, SIGNAL(clicked(QListViewItem*) ), | 554 | connect(m_view, SIGNAL(clicked(QListViewItem*) ), |
545 | this, SLOT(slotCurrentChanged(QListViewItem*) ) ); | 555 | this, SLOT(slotCurrentChanged(QListViewItem*) ) ); |
546 | connect(m_view, SIGNAL(mouseButtonClicked(int,QListViewItem*,const QPoint&,int) ), | 556 | connect(m_view, SIGNAL(mouseButtonClicked(int,QListViewItem*,const QPoint&,int) ), |
547 | this, SLOT(slotClicked(int,QListViewItem*,const QPoint&,int) ) ); | 557 | this, SLOT(slotClicked(int,QListViewItem*,const QPoint&,int) ) ); |
548 | } | 558 | } |
549 | 559 | ||
550 | void OFileViewFileListView::slotCurrentChanged( QListViewItem* item) | 560 | void OFileViewFileListView::slotCurrentChanged( QListViewItem* item) |
551 | { | 561 | { |
552 | if (!item) | 562 | if (!item) |
553 | return; | 563 | return; |
554 | #if 0 | 564 | #if 0 |
555 | 565 | ||
556 | OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item); | 566 | OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item); |
557 | 567 | ||
558 | if (!sel->isDir() ) | 568 | if (!sel->isDir() ) |
559 | { | 569 | { |
560 | selector()->m_lneEdit->setText( sel->text(1) ); | 570 | selector()->m_lneEdit->setText( sel->text(1) ); |
561 | // if in fileselector mode we will emit selected | 571 | // if in fileselector mode we will emit selected |
562 | if ( selector()->mode() == OFileSelector::FileSelector ) | 572 | if ( selector()->mode() == OFileSelector::FileSelector ) |
563 | { | 573 | { |
564 | odebug << "slot Current Changed" << oendl; | 574 | odebug << "slot Current Changed" << oendl; |
565 | QStringList str = QStringList::split("->", sel->text(1) ); | 575 | QStringList str = QStringList::split("->", sel->text(1) ); |
566 | QString path = sel->directory() + "/" + str[0].stripWhiteSpace(); | 576 | QString path = createNewPath(sel->directory(),str[0].stripWhiteSpace()); |
567 | emit selector()->fileSelected( path ); | 577 | emit selector()->fileSelected( path ); |
568 | DocLnk lnk( path ); | 578 | DocLnk lnk( path ); |
569 | emit selector()->fileSelected( lnk ); | 579 | emit selector()->fileSelected( lnk ); |
570 | } | 580 | } |
571 | } | 581 | } |
572 | #endif | 582 | #endif |
573 | } | 583 | } |
574 | 584 | ||
575 | void OFileViewFileListView::slotClicked(int button , QListViewItem* item, const QPoint&, int ) | 585 | void OFileViewFileListView::slotClicked(int button , QListViewItem* item, const QPoint&, int ) |
576 | { | 586 | { |
577 | if (!item || ( button != Qt::LeftButton) ) | 587 | if (!item || ( button != Qt::LeftButton) ) |
578 | return; | 588 | return; |
579 | 589 | ||
580 | OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item); | 590 | OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item); |
581 | if (!sel->isLocked() ) | 591 | if (!sel->isLocked() ) |
582 | { | 592 | { |
583 | QStringList str = QStringList::split("->", sel->text(1) ); | 593 | QStringList str = QStringList::split("->", sel->text(1) ); |
584 | if (sel->isDir() ) | 594 | if (sel->isDir() ) |
585 | { | 595 | { |
586 | m_currentDir = sel->directory() + "/" + str[0].stripWhiteSpace(); | 596 | m_currentDir = createNewPath(sel->directory(),str[0].stripWhiteSpace()); |
587 | emit selector()->dirSelected( m_currentDir ); | 597 | emit selector()->dirSelected( m_currentDir ); |
588 | reread( m_all ); | 598 | reread( m_all ); |
589 | } | 599 | } |
590 | else | 600 | else |
591 | { // file | 601 | { // file |
592 | odebug << "slot Clicked" << oendl; | 602 | odebug << "slot Clicked" << oendl; |
593 | selector()->m_lneEdit->setText( str[0].stripWhiteSpace() ); | 603 | selector()->m_lneEdit->setText( str[0].stripWhiteSpace() ); |
594 | QString path = sel->directory() + "/" + str[0].stripWhiteSpace(); | 604 | QString path = createNewPath(sel->directory(),str[0].stripWhiteSpace()); |
595 | emit selector()->fileSelected( path ); | 605 | emit selector()->fileSelected( path ); |
596 | DocLnk lnk( path ); | 606 | DocLnk lnk( path ); |
597 | emit selector()->fileSelected( lnk ); | 607 | emit selector()->fileSelected( lnk ); |
598 | } | 608 | } |
599 | } // not locked | 609 | } // not locked |
600 | } | 610 | } |
601 | 611 | ||
602 | void OFileViewFileListView::addFile( QFileInfo* info, bool symlink ) | 612 | void OFileViewFileListView::addFile( QFileInfo* info, bool symlink ) |
603 | { | 613 | { |
604 | MimeType type( info->absFilePath() ); | 614 | MimeType type( info->absFilePath() ); |
605 | if (!compliesMime( type.id() ) ) | 615 | if (!compliesMime( type.id() ) ) |
606 | return; | 616 | return; |
607 | 617 | ||
608 | QPixmap pix = type.pixmap(); | 618 | QPixmap pix = type.pixmap(); |
609 | QString dir, name; bool locked; | 619 | QString dir, name; bool locked; |
610 | if ( pix.isNull() ) | 620 | if ( pix.isNull() ) |
611 | { | 621 | { |
612 | QWMatrix matrix; | 622 | QWMatrix matrix; |
613 | QPixmap pixer(Resource::loadPixmap("UnknownDocument") ); | 623 | QPixmap pixer(Resource::loadPixmap("UnknownDocument") ); |
614 | matrix.scale( .4, .4 ); | 624 | matrix.scale( .4, .4 ); |
615 | pix = pixer.xForm( matrix ); | 625 | pix = pixer.xForm( matrix ); |
616 | } | 626 | } |
617 | dir = info->dirPath( true ); | 627 | dir = info->dirPath( true ); |
618 | locked = false; | 628 | locked = false; |
619 | if ( symlink ) | 629 | if ( symlink ) |
620 | name = info->fileName() + " -> " + info->dirPath() + "/" + info->readLink(); | 630 | name = info->fileName() + " -> " + createNewPath(info->dirPath(),info->readLink()); |
621 | else | 631 | else |
622 | { | 632 | { |
623 | name = info->fileName(); | 633 | name = info->fileName(); |
624 | if ( ( (selector()->mode() == OFileSelector::Open)&& !info->isReadable() ) || | 634 | if ( ( (selector()->mode() == OFileSelector::Open)&& !info->isReadable() ) || |
625 | ( (selector()->mode() == OFileSelector::Save)&& !info->isWritable() ) ) | 635 | ( (selector()->mode() == OFileSelector::Save)&& !info->isWritable() ) ) |
626 | { | 636 | { |
627 | locked = true; pix = Resource::loadPixmap("locked"); | 637 | locked = true; pix = Resource::loadPixmap("locked"); |
628 | } | 638 | } |
629 | } | 639 | } |
630 | (void)new OFileSelectorItem( m_view, pix, name, | 640 | (void)new OFileSelectorItem( m_view, pix, name, |
631 | info->lastModified().toString(), QString::number( info->size() ), | 641 | info->lastModified().toString(), QString::number( info->size() ), |
632 | dir, locked ); | 642 | dir, locked ); |
633 | } | 643 | } |
634 | 644 | ||
635 | void OFileViewFileListView::addDir( QFileInfo* info, bool symlink ) | 645 | void OFileViewFileListView::addDir( QFileInfo* info, bool symlink ) |
636 | { | 646 | { |
637 | bool locked = false; QString name; QPixmap pix; | 647 | bool locked = false; QString name; QPixmap pix; |
638 | 648 | ||
639 | if ( ( ( selector()->mode() == OFileSelector::Open ) && !info->isReadable() ) || | 649 | if ( ( ( selector()->mode() == OFileSelector::Open ) && !info->isReadable() ) || |
640 | ( ( selector()->mode() == OFileSelector::Save ) && !info->isWritable() ) ) | 650 | ( ( selector()->mode() == OFileSelector::Save ) && !info->isWritable() ) ) |
641 | { | 651 | { |
642 | locked = true; | 652 | locked = true; |
643 | if ( symlink ) | 653 | if ( symlink ) |
644 | pix = Resource::loadPixmap( "opie/symlink" ); | 654 | pix = Resource::loadPixmap( "opie/symlink" ); |
645 | else | 655 | else |
646 | pix = Resource::loadPixmap( "lockedfolder" ); | 656 | pix = Resource::loadPixmap( "lockedfolder" ); |
647 | } | 657 | } |
648 | else | 658 | else |
649 | pix = symlink ? Resource::loadPixmap( "opie/symlink") : Resource::loadPixmap("folder"); | 659 | pix = symlink ? Resource::loadPixmap( "opie/symlink") : Resource::loadPixmap("folder"); |
650 | 660 | ||
651 | name = symlink ? info->fileName() + " -> " + info->dirPath(true) + "/" + info->readLink() : | 661 | name = symlink ? info->fileName() + " -> " + createNewPath(info->dirPath(true),info->readLink()) : |
652 | info->fileName(); | 662 | info->fileName(); |
653 | 663 | ||
654 | (void)new OFileSelectorItem( m_view, pix, name, | 664 | (void)new OFileSelectorItem( m_view, pix, name, |
655 | info->lastModified().toString(), | 665 | info->lastModified().toString(), |
656 | QString::number( info->size() ), | 666 | QString::number( info->size() ), |
657 | info->dirPath( true ), locked, true ); | 667 | info->dirPath( true ), locked, true ); |
658 | 668 | ||
659 | 669 | ||
660 | } | 670 | } |
661 | 671 | ||
662 | void OFileViewFileListView::addSymlink( QFileInfo* , bool ) | 672 | void OFileViewFileListView::addSymlink( QFileInfo* , bool ) |
663 | { | 673 | { |
664 | } | 674 | } |
665 | 675 | ||
666 | void OFileViewFileListView::cdUP() | 676 | void OFileViewFileListView::cdUP() |
667 | { | 677 | { |
668 | QDir dir( m_currentDir ); | 678 | QDir dir( m_currentDir ); |
669 | dir.cdUp(); | 679 | dir.cdUp(); |
670 | 680 | ||
671 | if (!dir.exists() ) | 681 | if (!dir.exists() ) |
672 | m_currentDir = "/"; | 682 | m_currentDir = "/"; |
673 | else | 683 | else |
674 | m_currentDir = dir.absPath(); | 684 | m_currentDir = dir.absPath(); |
675 | 685 | ||
676 | emit selector()->dirSelected( m_currentDir ); | 686 | emit selector()->dirSelected( m_currentDir ); |
677 | reread( m_all ); | 687 | reread( m_all ); |
678 | } | 688 | } |
679 | 689 | ||
680 | void OFileViewFileListView::cdHome() | 690 | void OFileViewFileListView::cdHome() |
681 | { | 691 | { |
682 | m_currentDir = QDir::homeDirPath(); | 692 | m_currentDir = QDir::homeDirPath(); |
683 | emit selector()->dirSelected( m_currentDir ); | 693 | emit selector()->dirSelected( m_currentDir ); |
684 | reread( m_all ); | 694 | reread( m_all ); |
685 | } | 695 | } |
686 | 696 | ||
687 | void OFileViewFileListView::cdDoc() | 697 | void OFileViewFileListView::cdDoc() |
688 | { | 698 | { |
689 | m_currentDir = QPEApplication::documentDir(); | 699 | m_currentDir = QPEApplication::documentDir(); |
690 | emit selector()->dirSelected( m_currentDir ); | 700 | emit selector()->dirSelected( m_currentDir ); |
691 | reread( m_all ); | 701 | reread( m_all ); |
692 | } | 702 | } |
693 | 703 | ||
694 | void OFileViewFileListView::changeDir( const QString& dir ) | 704 | void OFileViewFileListView::changeDir( const QString& dir ) |
695 | { | 705 | { |
696 | m_currentDir = dir; | 706 | m_currentDir = dir; |
697 | emit selector()->dirSelected( m_currentDir ); | 707 | emit selector()->dirSelected( m_currentDir ); |
698 | reread( m_all ); | 708 | reread( m_all ); |
699 | } | 709 | } |
700 | 710 | ||
701 | void OFileViewFileListView::slotFSActivated( int id ) | 711 | void OFileViewFileListView::slotFSActivated( int id ) |
702 | { | 712 | { |
703 | changeDir ( m_dev[m_fsPop->text(id)] ); | 713 | changeDir ( m_dev[m_fsPop->text(id)] ); |
704 | } | 714 | } |
705 | 715 | ||
706 | /* check if the mimetype in mime | 716 | /* check if the mimetype in mime |
707 | * complies with the one which is current | 717 | * complies with the one which is current |
708 | */ | 718 | */ |
709 | /* | 719 | /* |
710 | * We've the mimetype of the file | 720 | * We've the mimetype of the file |
711 | * We need to get the stringlist of the current mimetype | 721 | * We need to get the stringlist of the current mimetype |
712 | * | 722 | * |
713 | * mime = image@slashjpeg | 723 | * mime = image@slashjpeg |
714 | * QStringList = 'image@slash*' | 724 | * QStringList = 'image@slash*' |
715 | * or QStringList = image/jpeg;image/png;application/x-ogg | 725 | * or QStringList = image/jpeg;image/png;application/x-ogg |
@@ -719,129 +729,129 @@ void OFileViewFileListView::slotFSActivated( int id ) | |||
719 | * the stringlist | 729 | * the stringlist |
720 | * if it's contained return true | 730 | * if it's contained return true |
721 | * if not ( I'm no RegExp expert at all ) we'll look if a '@slash*' | 731 | * if not ( I'm no RegExp expert at all ) we'll look if a '@slash*' |
722 | * is contained in the mimefilter and then we will | 732 | * is contained in the mimefilter and then we will |
723 | * look if both are equal until the '/' | 733 | * look if both are equal until the '/' |
724 | */ | 734 | */ |
725 | 735 | ||
726 | bool OFileViewFileListView::compliesMime( const QString& str) | 736 | bool OFileViewFileListView::compliesMime( const QString& str) |
727 | { | 737 | { |
728 | if (str.isEmpty() || m_mimes.isEmpty() || str.stripWhiteSpace().isEmpty() ) | 738 | if (str.isEmpty() || m_mimes.isEmpty() || str.stripWhiteSpace().isEmpty() ) |
729 | return true; | 739 | return true; |
730 | 740 | ||
731 | for (QStringList::Iterator it = m_mimes.begin(); it != m_mimes.end(); ++it ) | 741 | for (QStringList::Iterator it = m_mimes.begin(); it != m_mimes.end(); ++it ) |
732 | { | 742 | { |
733 | QRegExp reg( (*it) ); | 743 | QRegExp reg( (*it) ); |
734 | reg.setWildcard( true ); | 744 | reg.setWildcard( true ); |
735 | if ( str.find( reg ) != -1 ) | 745 | if ( str.find( reg ) != -1 ) |
736 | return true; | 746 | return true; |
737 | 747 | ||
738 | } | 748 | } |
739 | return false; | 749 | return false; |
740 | } | 750 | } |
741 | /* | 751 | /* |
742 | * The listView giving access to the file system! | 752 | * The listView giving access to the file system! |
743 | */ | 753 | */ |
744 | 754 | ||
745 | class OFileViewFileSystem : public OFileViewInterface | 755 | class OFileViewFileSystem : public OFileViewInterface |
746 | { | 756 | { |
747 | public: | 757 | public: |
748 | OFileViewFileSystem( OFileSelector* ); | 758 | OFileViewFileSystem( OFileSelector* ); |
749 | ~OFileViewFileSystem(); | 759 | ~OFileViewFileSystem(); |
750 | 760 | ||
751 | QString selectedName() const; | 761 | QString selectedName() const; |
752 | QString selectedPath() const; | 762 | QString selectedPath() const; |
753 | 763 | ||
754 | QString directory()const; | 764 | QString directory()const; |
755 | void reread(); | 765 | void reread(); |
756 | int fileCount()const; | 766 | int fileCount()const; |
757 | 767 | ||
758 | QWidget* widget( QWidget* parent ); | 768 | QWidget* widget( QWidget* parent ); |
759 | void activate( const QString& ); | 769 | void activate( const QString& ); |
760 | private: | 770 | private: |
761 | OFileViewFileListView* m_view; | 771 | OFileViewFileListView* m_view; |
762 | bool m_all : 1; | 772 | bool m_all : 1; |
763 | }; | 773 | }; |
764 | 774 | ||
765 | OFileViewFileSystem::OFileViewFileSystem( OFileSelector* sel) | 775 | OFileViewFileSystem::OFileViewFileSystem( OFileSelector* sel) |
766 | : OFileViewInterface( sel ) | 776 | : OFileViewInterface( sel ) |
767 | { | 777 | { |
768 | m_view = 0; | 778 | m_view = 0; |
769 | m_all = false; | 779 | m_all = false; |
770 | } | 780 | } |
771 | 781 | ||
772 | OFileViewFileSystem::~OFileViewFileSystem() | 782 | OFileViewFileSystem::~OFileViewFileSystem() |
773 | { | 783 | { |
774 | } | 784 | } |
775 | 785 | ||
776 | QString OFileViewFileSystem::selectedName()const | 786 | QString OFileViewFileSystem::selectedName()const |
777 | { | 787 | { |
778 | if (!m_view ) | 788 | if (!m_view ) |
779 | return QString::null; | 789 | return QString::null; |
780 | 790 | ||
781 | QString cFN=currentFileName(); | 791 | QString cFN=currentFileName(); |
782 | if (cFN.startsWith("/")) return cFN; | 792 | if (cFN.startsWith("/")) return cFN; |
783 | return m_view->currentDir() + "/" + cFN; | 793 | return createNewPath(m_view->currentDir(),cFN); |
784 | } | 794 | } |
785 | 795 | ||
786 | QString OFileViewFileSystem::selectedPath()const | 796 | QString OFileViewFileSystem::selectedPath()const |
787 | { | 797 | { |
788 | return QString::null; | 798 | return QString::null; |
789 | } | 799 | } |
790 | 800 | ||
791 | QString OFileViewFileSystem::directory()const | 801 | QString OFileViewFileSystem::directory()const |
792 | { | 802 | { |
793 | if (!m_view) | 803 | if (!m_view) |
794 | return QString::null; | 804 | return QString::null; |
795 | 805 | ||
796 | OFileSelectorItem* item = m_view->currentItem(); | 806 | OFileSelectorItem* item = m_view->currentItem(); |
797 | if (!item ) | 807 | if (!item ) |
798 | return QString::null; | 808 | return QString::null; |
799 | 809 | ||
800 | return QDir(item->directory() ).absPath(); | 810 | return QDir(item->directory() ).absPath(); |
801 | } | 811 | } |
802 | 812 | ||
803 | void OFileViewFileSystem::reread() | 813 | void OFileViewFileSystem::reread() |
804 | { | 814 | { |
805 | if (!m_view) | 815 | if (!m_view) |
806 | return; | 816 | return; |
807 | 817 | ||
808 | m_view->reread( m_all ); | 818 | m_view->reread( m_all ); |
809 | } | 819 | } |
810 | 820 | ||
811 | int OFileViewFileSystem::fileCount()const | 821 | int OFileViewFileSystem::fileCount()const |
812 | { | 822 | { |
813 | if (!m_view ) | 823 | if (!m_view ) |
814 | return -1; | 824 | return -1; |
815 | return m_view->fileCount(); | 825 | return m_view->fileCount(); |
816 | } | 826 | } |
817 | 827 | ||
818 | QWidget* OFileViewFileSystem::widget( QWidget* parent ) | 828 | QWidget* OFileViewFileSystem::widget( QWidget* parent ) |
819 | { | 829 | { |
820 | if (!m_view ) | 830 | if (!m_view ) |
821 | { | 831 | { |
822 | m_view = new OFileViewFileListView( parent, startDirectory(), selector() ); | 832 | m_view = new OFileViewFileListView( parent, startDirectory(), selector() ); |
823 | } | 833 | } |
824 | return m_view; | 834 | return m_view; |
825 | } | 835 | } |
826 | 836 | ||
827 | void OFileViewFileSystem::activate( const QString& str ) | 837 | void OFileViewFileSystem::activate( const QString& str ) |
828 | { | 838 | { |
829 | m_all = allItem( str ); | 839 | m_all = allItem( str ); |
830 | } | 840 | } |
831 | 841 | ||
832 | 842 | ||
833 | } | 843 | } |
834 | /* Selector */ | 844 | /* Selector */ |
835 | /** | 845 | /** |
836 | * @short new and complete c'tor | 846 | * @short new and complete c'tor |
837 | * | 847 | * |
838 | * Create a OFileSelector to let the user select a file. It can | 848 | * Create a OFileSelector to let the user select a file. It can |
839 | * either be used to open a file, select a save name in a dir or | 849 | * either be used to open a file, select a save name in a dir or |
840 | * as a dropin for the FileSelector. | 850 | * as a dropin for the FileSelector. |
841 | * | 851 | * |
842 | * <pre> | 852 | * <pre> |
843 | * QMap<QString, QStringList> mimeTypes; | 853 | * QMap<QString, QStringList> mimeTypes; |
844 | * QStringList types; | 854 | * QStringList types; |
845 | * types << "text@slash* "; | 855 | * types << "text@slash* "; |
846 | * types << "audio@slash*"; | 856 | * types << "audio@slash*"; |
847 | * mimeTypes.insert( tr("Audio and Text"), types ); | 857 | * mimeTypes.insert( tr("Audio and Text"), types ); |