summaryrefslogtreecommitdiff
path: root/libopie/ofileselector.cc
Unidiff
Diffstat (limited to 'libopie/ofileselector.cc') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/ofileselector.cc160
1 files changed, 113 insertions, 47 deletions
diff --git a/libopie/ofileselector.cc b/libopie/ofileselector.cc
index 7a67ab2..6c59f89 100644
--- a/libopie/ofileselector.cc
+++ b/libopie/ofileselector.cc
@@ -99,17 +99,19 @@ namespace {
99 99
100OFileSelector::OFileSelector( QWidget *wid, int mode, int selector, 100OFileSelector::OFileSelector( QWidget *wid, int mode, int selector,
101 const QString &dirName, 101 const QString &dirName,
102 const QString &fileName, 102 const QString &fileName,
103 const QStringList &mimeTypes ) 103 const QMap<QString,QStringList>& mimeTypes)
104 : QWidget( wid, "OFileSelector") 104 : QWidget( wid, "OFileSelector")
105{ 105{
106 m_mimetypes = mimeTypes; 106 m_mimetypes = mimeTypes;
107 if (mode == SAVE )
108 m_name = fileName;
107 initVars(); 109 initVars();
108 m_mode = mode; 110 m_mode = mode;
109 m_selector = selector; 111 m_selector = selector;
110 m_currentDir = dirName; 112 m_currentDir = dirName;
111 init(); 113 init();
112QTimer::singleShot(6*1000, this, SLOT( slotTest() ) ); 114 //QTimer::singleShot(6*1000, this, SLOT( slotTest() ) );
113} 115}
114 116
115OFileSelector::OFileSelector(const QString &mimeFilter, QWidget *parent, 117OFileSelector::OFileSelector(const QString &mimeFilter, QWidget *parent,
@@ -117,9 +119,12 @@ OFileSelector::OFileSelector(const QString &mimeFilter, QWidget *parent,
117 bool closeVisible ) 119 bool closeVisible )
118 : QWidget( parent, name ) 120 : QWidget( parent, name )
119{ 121{
120 m_mimetypes = QStringList::split(";", mimeFilter ); 122 if (!mimeFilter.isEmpty() ) {
123 QStringList list = QStringList::split(";", mimeFilter );
124 m_mimetypes.insert(mimeFilter, list );
125 }
121 initVars(); 126 initVars();
122 m_currentDir = QPEApplication::documentDir(); 127 m_currentDir = QPEApplication::documentDir();
123 m_mode = OPEN; 128 m_mode = OPEN;
124 m_selector = NORMAL; 129 m_selector = NORMAL;
125 m_shClose = closeVisible; 130 m_shClose = closeVisible;
@@ -129,12 +134,13 @@ OFileSelector::OFileSelector(const QString &mimeFilter, QWidget *parent,
129 m_shYesNo = false; 134 m_shYesNo = false;
130 init(); 135 init();
131 136
132 137
133} 138}
134 139
135OFileSelector::~OFileSelector() 140OFileSelector::~OFileSelector()
136{ 141{
137 142
143
138} 144}
139 145
140void OFileSelector::setNewVisible( bool visible ) 146void OFileSelector::setNewVisible( bool visible )
@@ -143,8 +149,8 @@ void OFileSelector::setNewVisible( bool visible )
143 if( m_selector == NORMAL ){ 149 if( m_selector == NORMAL ){
144 delete m_select; 150 delete m_select;
145 // we need to initialize but keep the selected mimetype 151 // we need to initialize but keep the selected mimetype
146 QString mime = m_mimeCheck == 0 ? QString::null : m_mimeCheck->currentText() ; 152 QString mime = currentMimeType();
147 m_select = new FileSelector( m_autoMime ? mime : m_mimetypes.join(";") , 153 m_select = new FileSelector( mime ,
148 m_stack, "fileselector", 154 m_stack, "fileselector",
149 m_shNew, m_shClose); 155 m_shNew, m_shClose);
150 connect(m_select, SIGNAL(fileSelected( const DocLnk & ) ), 156 connect(m_select, SIGNAL(fileSelected( const DocLnk & ) ),
@@ -341,7 +347,7 @@ QStringList OFileSelector::selectedNames()const
341 return list; 347 return list;
342} 348}
343/** If mode is set to the Dir selection this will return the selected path. 349/** If mode is set to the Dir selection this will return the selected path.
344 * 350 *
345 * 351 *
346 */ 352 */
347QString OFileSelector::selectedPath()const 353QString OFileSelector::selectedPath()const
@@ -364,7 +370,7 @@ QString OFileSelector::directory()const
364{ 370{
365 if( m_selector == NORMAL ) 371 if( m_selector == NORMAL )
366 return QPEApplication::documentDir(); 372 return QPEApplication::documentDir();
367 373
368 return QDir(m_currentDir).absPath(); 374 return QDir(m_currentDir).absPath();
369} 375}
370 376
@@ -425,13 +431,15 @@ void OFileSelector::slotViewCheck(const QString &sel)
425 if( sel == tr("Documents" ) ){ 431 if( sel == tr("Documents" ) ){
426 if( m_select == 0 ){ 432 if( m_select == 0 ){
427 // autMime? fix cause now we use All and not the current 433 // autMime? fix cause now we use All and not the current
428 m_select = new FileSelector(m_autoMime ? QString::null : m_mimetypes.join(";"), 434 // yes currentMime fixes that for us
435 QString mime = currentMimeType();
436 m_select = new FileSelector(mime,
429 m_stack, "fileselector", 437 m_stack, "fileselector",
430 FALSE, FALSE); 438 FALSE, FALSE);
431 connect(m_select, SIGNAL(fileSelected( const DocLnk & ) ), 439 connect(m_select, SIGNAL(fileSelected( const DocLnk & ) ),
432 this, SLOT( slotFileBridgeSelected(const DocLnk & ) ) ); 440 this, SLOT( slotFileBridgeSelected(const DocLnk & ) ) );
433 //connect to close me and other signals as well 441 //connect to close me and other signals as well
434 442
435 m_stack->addWidget( m_select, NORMAL ); 443 m_stack->addWidget( m_select, NORMAL );
436 } 444 }
437 m_stack->raiseWidget( NORMAL ); 445 m_stack->raiseWidget( NORMAL );
@@ -445,17 +453,48 @@ void OFileSelector::slotViewCheck(const QString &sel)
445 m_selector = EXTENDED_ALL; 453 m_selector = EXTENDED_ALL;
446 initializeListView(); 454 initializeListView();
447 reparse(); 455 reparse();
448 m_stack->raiseWidget( EXTENDED ); // same widget other QFileFilter 456 m_stack->raiseWidget( EXTENDED ); // same widget other QFileFilter
449 } 457 }
450} 458}
459// not yet finished.....
460QString OFileSelector::currentMimeType() const{
461 QString mime;
462 QString currentText;
463 if (m_shChooser )
464 currentText = m_mimeCheck->currentText();
465
466 if (tr("All") == currentText ) return QString::null;
467 else if (currentText.isEmpty() ) {
468 ;
469 }else {
470 QMap<QString, QStringList>::ConstIterator it;
471 it = m_mimetypes.find( currentText );
472 if ( it == m_mimetypes.end() ) {
473 mime = it.data().join(";");
474 }else{
475 mime = currentText;
476 }
477 }
478 return mime;
479}
451void OFileSelector::slotMimeCheck(const QString &mime) 480void OFileSelector::slotMimeCheck(const QString &mime)
452{ 481{
453 if( m_selector == NORMAL ){ 482 if( m_selector == NORMAL ){
454 if( m_autoMime ){ 483 //if( m_autoMime ){
484 QString newMimeType;
485 if (mime != tr("All") ) {
486 QMap<QString, QStringList>::Iterator it;
487 it = m_mimetypes.find(mime);
488 if ( it != m_mimetypes.end() ) {
489 newMimeType = it.data().join(";");
490 }else{
491 newMimeType = mime;
492 }
493 }
455 delete m_select; 494 delete m_select;
456 m_select = new FileSelector( mime == tr("All") ? QString::null : mime, 495 m_select = new FileSelector( newMimeType,
457 m_stack, "fileselector", 496 m_stack, "fileselector",
458 FALSE, FALSE); 497 FALSE, FALSE);
459 498
460 connect(m_select, SIGNAL(fileSelected( const DocLnk & ) ), 499 connect(m_select, SIGNAL(fileSelected( const DocLnk & ) ),
461 this, SLOT( slotFileBridgeSelected(const DocLnk & ) ) ); 500 this, SLOT( slotFileBridgeSelected(const DocLnk & ) ) );
@@ -463,10 +502,9 @@ void OFileSelector::slotMimeCheck(const QString &mime)
463 m_stack->addWidget( m_select, NORMAL ); 502 m_stack->addWidget( m_select, NORMAL );
464 m_stack->raiseWidget( NORMAL ); 503 m_stack->raiseWidget( NORMAL );
465 updateMimes(); 504 updateMimes();
466 m_mimeCheck->clear(); 505 updateMimeCheck();
467 m_mimeCheck->insertStringList(m_mimetypes );
468 m_mimeCheck->setCurrentItem(indexByString( m_mimeCheck, mime) ); 506 m_mimeCheck->setCurrentItem(indexByString( m_mimeCheck, mime) );
469 } 507 //}
470 }else{ // others 508 }else{ // others
471 qWarning("Mime %s", mime.latin1() ); 509 qWarning("Mime %s", mime.latin1() );
472 if(m_shChooser ){ 510 if(m_shChooser ){
@@ -512,7 +550,15 @@ void OFileSelector::init()
512 550
513 m_stack = new QWidgetStack( this ); 551 m_stack = new QWidgetStack( this );
514 if( m_selector == NORMAL ){ 552 if( m_selector == NORMAL ){
515 m_select = new FileSelector(m_autoMime ? QString::null : m_mimetypes.join(";"), 553 QString mime;
554 if (!m_autoMime) {
555 if (!m_mimetypes.isEmpty() ) {
556 QMap<QString, QStringList>::Iterator it;
557 it = m_mimetypes.begin(); // cause we're in the init
558 mime = it.data().join(";");
559 }
560 }
561 m_select = new FileSelector(mime,
516 m_stack, "fileselector", 562 m_stack, "fileselector",
517 FALSE, FALSE); 563 FALSE, FALSE);
518 564
@@ -545,14 +591,14 @@ void OFileSelector::updateMimes()
545{ 591{
546 if( m_autoMime ){ 592 if( m_autoMime ){
547 m_mimetypes.clear(); 593 m_mimetypes.clear();
548 m_mimetypes.append( tr("All") ); 594 m_mimetypes.insert( tr("All"), QString::null );
549 if( m_selector == NORMAL ){ 595 if( m_selector == NORMAL ){
550 DocLnkSet set; 596 DocLnkSet set;
551 Global::findDocuments(&set, QString::null ); 597 Global::findDocuments(&set, QString::null );
552 QListIterator<DocLnk> dit( set.children() ); 598 QListIterator<DocLnk> dit( set.children() );
553 for( ; dit.current(); ++dit ){ 599 for( ; dit.current(); ++dit ){
554 if( !m_mimetypes.contains( (*dit)->type() ) ) 600 if( !m_mimetypes.contains( (*dit)->type() ) )
555 m_mimetypes.append( (*dit)->type() ); 601 m_mimetypes.insert( (*dit)->type(), (*dit)->type() );
556 } 602 }
557 }// else done in reparse 603 }// else done in reparse
558 } 604 }
@@ -628,7 +674,7 @@ void OFileSelector::addFile(const QString &mime, QFileInfo *info, bool symlink)
628 name = info->fileName(); 674 name = info->fileName();
629 if( ( m_mode == OPEN && !info->isReadable() )|| 675 if( ( m_mode == OPEN && !info->isReadable() )||
630 ( m_mode == SAVE && !info->isWritable() ) ){ 676 ( m_mode == SAVE && !info->isWritable() ) ){
631 677
632 locked = true; pix = Resource::loadPixmap("locked"); 678 locked = true; pix = Resource::loadPixmap("locked");
633 } 679 }
634 } 680 }
@@ -657,7 +703,7 @@ void OFileSelector::addDir(const QString &mime, QFileInfo *info, bool symlink )
657 name = symlink ? info->fileName() + "->" + info->dirPath(true) + "/" +info->readLink() : info->fileName() ; 703 name = symlink ? info->fileName() + "->" + info->dirPath(true) + "/" +info->readLink() : info->fileName() ;
658 new OFileSelectorItem( m_View, pix, name, 704 new OFileSelectorItem( m_View, pix, name,
659 info->lastModified().toString(), 705 info->lastModified().toString(),
660 QString::number( info->size() ), 706 QString::number( info->size() ),
661 info->dirPath( true ), locked, 707 info->dirPath( true ), locked,
662 true ); 708 true );
663 709
@@ -670,8 +716,8 @@ void OFileSelector::delItems()
670void OFileSelector::initializeName() 716void OFileSelector::initializeName()
671{ 717{
672 /** Name Layout Line 718 /** Name Layout Line
673 * This is the Layout line arranged in 719 * This is the Layout line arranged in
674 * horizontal way each components 720 * horizontal way each components
675 * are next to each other 721 * are next to each other
676 * but we will only do this if 722 * but we will only do this if
677 * we didn't initialize a while ago. 723 * we didn't initialize a while ago.
@@ -681,6 +727,7 @@ void OFileSelector::initializeName()
681 m_fnLabel = new QLabel( m_boxName ); 727 m_fnLabel = new QLabel( m_boxName );
682 m_fnLabel->setText( tr("Name:") ); 728 m_fnLabel->setText( tr("Name:") );
683 m_edit = new QLineEdit( m_boxName ); 729 m_edit = new QLineEdit( m_boxName );
730 m_edit->setText( m_name );
684 //m_boxName->addWidget( m_fnLabel ); 731 //m_boxName->addWidget( m_fnLabel );
685 m_boxName->setMargin( 5 ); 732 m_boxName->setMargin( 5 );
686 m_boxName->setSpacing( 8 ); 733 m_boxName->setSpacing( 8 );
@@ -688,7 +735,7 @@ void OFileSelector::initializeName()
688 735
689 m_lay->addWidget( m_boxName, 0 ); // add it to the topLevel layout 736 m_lay->addWidget( m_boxName, 0 ); // add it to the topLevel layout
690 }// else we already initialized 737 }// else we already initialized
691 // maybe show the components? 738 // maybe show the components?
692 // 739 //
693} 740}
694void OFileSelector::initializeYes() 741void OFileSelector::initializeYes()
@@ -713,6 +760,24 @@ void OFileSelector::initializeYes()
713 this, SLOT( slotCancel() ) ); 760 this, SLOT( slotCancel() ) );
714 } 761 }
715} 762}
763/*
764 * OK m_mimeCheck is a QComboBox we now want to fill
765 * out that combobox
766 * if automime we need to update the mimetypes
767 */
768void OFileSelector::updateMimeCheck() {
769 m_mimeCheck->clear();
770 if (m_autoMime ) {
771 //m_mimeCheck->insertItem( tr("All") );
772 updateMimes();
773 }
774
775 QMap<QString, QStringList>::Iterator it;
776 for (it = m_mimetypes.begin(); it != m_mimetypes.end(); ++it ) {
777 m_mimeCheck->insertItem( it.key() );
778 }
779}
780
716void OFileSelector::initializeChooser() 781void OFileSelector::initializeChooser()
717{ 782{
718 if( m_boxView == 0 ){ 783 if( m_boxView == 0 ){
@@ -725,12 +790,8 @@ void OFileSelector::initializeChooser()
725 m_viewCheck->insertItem( tr("Documents") ); 790 m_viewCheck->insertItem( tr("Documents") );
726 m_viewCheck->insertItem( tr("Files") ); 791 m_viewCheck->insertItem( tr("Files") );
727 m_viewCheck->insertItem( tr("All Files") ); 792 m_viewCheck->insertItem( tr("All Files") );
728 if(!m_autoMime ) 793 updateMimeCheck();
729 m_mimeCheck->insertItem(m_mimetypes.join(",") ); 794
730 else{
731 updateMimes();
732 m_mimeCheck->insertStringList( m_mimetypes );
733 }
734 connect( m_viewCheck, SIGNAL( activated(const QString & ) ), 795 connect( m_viewCheck, SIGNAL( activated(const QString & ) ),
735 this, SLOT( slotViewCheck(const QString & ) ) ); 796 this, SLOT( slotViewCheck(const QString & ) ) );
736 connect( m_mimeCheck, SIGNAL( activated(const QString & ) ), 797 connect( m_mimeCheck, SIGNAL( activated(const QString & ) ),
@@ -746,11 +807,11 @@ void OFileSelector::initializeListView()
746 m_boxToolbar = new QHBox( m_pseudo ); 807 m_boxToolbar = new QHBox( m_pseudo );
747 m_boxToolbar->setSpacing(0 ); // next to each other please 808 m_boxToolbar->setSpacing(0 ); // next to each other please
748 809
749 // toolbar members 810 // toolbar members
750 { 811 {
751 // location QComboBox 812 // location QComboBox
752 m_location = new QComboBox( m_boxToolbar ); 813 m_location = new QComboBox( m_boxToolbar );
753 m_location->setEditable( TRUE ); 814 m_location->setEditable( TRUE );
754 m_location->setDuplicatesEnabled( FALSE ); 815 m_location->setDuplicatesEnabled( FALSE );
755 connect( m_location, SIGNAL(activated(const QString &) ), 816 connect( m_location, SIGNAL(activated(const QString &) ),
756 this, SLOT( slotLocationActivated(const QString &) ) ); 817 this, SLOT( slotLocationActivated(const QString &) ) );
@@ -831,13 +892,13 @@ void OFileSelector::initializeListView()
831 connect(m_View, SIGNAL(currentChanged(QListViewItem *) ), 892 connect(m_View, SIGNAL(currentChanged(QListViewItem *) ),
832 this, SLOT(slotCurrentChanged(QListViewItem * ) ) ); 893 this, SLOT(slotCurrentChanged(QListViewItem * ) ) );
833 894
834 connect(m_View, SIGNAL(mouseButtonClicked(int, QListViewItem*, const QPoint &, int) ), 895 connect(m_View, SIGNAL(mouseButtonClicked(int, QListViewItem*, const QPoint &, int) ),
835 this, SLOT(slotClicked( int, QListViewItem *, const QPoint &, int) ) ); 896 this, SLOT(slotClicked( int, QListViewItem *, const QPoint &, int) ) );
836 897
837 connect(m_View, SIGNAL(mouseButtonPressed(int, QListViewItem *, const QPoint &, int )), 898 connect(m_View, SIGNAL(mouseButtonPressed(int, QListViewItem *, const QPoint &, int )),
838 this, SLOT(slotRightButton(int, QListViewItem *, const QPoint &, int ) ) ); 899 this, SLOT(slotRightButton(int, QListViewItem *, const QPoint &, int ) ) );
839 900
840 m_pseudoLayout->addWidget( m_View, 288 ); 901 m_pseudoLayout->addWidget( m_View, 288 );
841 m_stack->addWidget( m_pseudo, EXTENDED ); 902 m_stack->addWidget( m_pseudo, EXTENDED );
842 } 903 }
843} 904}
@@ -876,7 +937,12 @@ bool OFileSelector::compliesMime( const QString &path, const QString &mime )
876 return true; 937 return true;
877 return false; 938 return false;
878} 939}
940/* check if the mimetype in mime
941 * complies with the one which is current
942 */
943bool OFileSelector::compliesMime( const QString& mime ) {
879 944
945}
880void OFileSelector::slotFileSelected( const QString &string ) 946void OFileSelector::slotFileSelected( const QString &string )
881{ 947{
882 if( m_shLne ) 948 if( m_shLne )
@@ -1050,22 +1116,22 @@ void OFileSelector::reparse()
1050 MimeType type( fi->absFilePath() ); 1116 MimeType type( fi->absFilePath() );
1051 if( !m_mimetypes.contains( type.id() ) ){ 1117 if( !m_mimetypes.contains( type.id() ) ){
1052 //qWarning("Type %s", type.id().latin1() ); 1118 //qWarning("Type %s", type.id().latin1() );
1053 m_mimetypes.append( type.id() ); 1119 m_mimetypes.insert( type.id(), type.id() );
1054 } 1120 }
1055 1121
1056 ++it; 1122 ++it;
1057 } 1123 }
1058 // add them to the chooser 1124 // add them to the chooser
1059 m_mimeCheck->insertItem( tr("All") ); 1125 updateMimeCheck();
1060 m_mimeCheck->insertStringList( m_mimetypes );
1061 m_mimeCheck->setCurrentItem( indexByString( m_mimeCheck, currentMimeType ) ); 1126 m_mimeCheck->setCurrentItem( indexByString( m_mimeCheck, currentMimeType ) );
1062 currentMimeType = m_mimeCheck->currentText(); 1127 currentMimeType = m_mimeCheck->currentText();
1063 } 1128 }
1064 }else { // no autoMime 1129 }else { // no autoMime
1065 currentMimeType = m_mimetypes.join(";"); 1130 // let the mimetype be set from out side the m_mimeCheck FEATURE
1131
1066 if( m_shChooser ){ 1132 if( m_shChooser ){
1067 m_mimeCheck->clear(); 1133 currentMimeType = m_mimeCheck->currentText();
1068 m_mimeCheck->insertItem(m_mimetypes.join(",") ); 1134 updateMimeCheck();
1069 } 1135 }
1070 } 1136 }
1071 // now we got our mimetypes we can add the files 1137 // now we got our mimetypes we can add the files
@@ -1075,7 +1141,7 @@ void OFileSelector::reparse()
1075 int sort; 1141 int sort;
1076 if ( m_case ) 1142 if ( m_case )
1077 sort = (QDir::IgnoreCase | QDir::Name | QDir::DirsFirst | QDir::Reversed); 1143 sort = (QDir::IgnoreCase | QDir::Name | QDir::DirsFirst | QDir::Reversed);
1078 else 1144 else
1079 sort = (QDir::Name | QDir::DirsFirst | QDir::Reversed); 1145 sort = (QDir::Name | QDir::DirsFirst | QDir::Reversed);
1080 dir.setSorting( sort ); 1146 dir.setSorting( sort );
1081 1147
@@ -1125,7 +1191,7 @@ void OFileSelector::reparse()
1125 //qWarning( "%s", fi->fileName().latin1() ); 1191 //qWarning( "%s", fi->fileName().latin1() );
1126 ++it; 1192 ++it;
1127 } // of while loop 1193 } // of while loop
1128 m_View->sort(); 1194 m_View->sort();
1129 if( m_shTool ){ 1195 if( m_shTool ){
1130 m_location->insertItem( m_currentDir ); 1196 m_location->insertItem( m_currentDir );
1131 1197