author | zecke <zecke> | 2002-06-26 18:58:37 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-06-26 18:58:37 (UTC) |
commit | f6800ca0bed431aac90f09ec98e481fb424c7b31 (patch) (unidiff) | |
tree | a9c9687cc0cecc9a5f4b9caf77662f7735faf941 | |
parent | 8896b1ffe8ffd4da2395a050de63473ba37a2dec (diff) | |
download | opie-f6800ca0bed431aac90f09ec98e481fb424c7b31.zip opie-f6800ca0bed431aac90f09ec98e481fb424c7b31.tar.gz opie-f6800ca0bed431aac90f09ec98e481fb424c7b31.tar.bz2 |
Fix mimetype handling
-rw-r--r-- | libopie/ofileselector.cc | 58 |
1 files changed, 55 insertions, 3 deletions
diff --git a/libopie/ofileselector.cc b/libopie/ofileselector.cc index 6c59f89..74b308e 100644 --- a/libopie/ofileselector.cc +++ b/libopie/ofileselector.cc | |||
@@ -646,34 +646,35 @@ void OFileSelector::initVars() | |||
646 | m_boxOk = 0; | 646 | m_boxOk = 0; |
647 | m_boxName = 0; | 647 | m_boxName = 0; |
648 | m_boxView = 0; | 648 | m_boxView = 0; |
649 | m_custom = 0; | 649 | m_custom = 0; |
650 | m_edit = 0; | 650 | m_edit = 0; |
651 | m_fnLabel = 0; | 651 | m_fnLabel = 0; |
652 | m_new = 0; | 652 | m_new = 0; |
653 | m_close = 0; | 653 | m_close = 0; |
654 | } | 654 | } |
655 | void OFileSelector::addFile(const QString &mime, QFileInfo *info, bool symlink) | 655 | void OFileSelector::addFile(const QString &mime, QFileInfo *info, bool symlink) |
656 | { | 656 | { |
657 | if(!m_files) | 657 | if(!m_files) |
658 | return; | 658 | return; |
659 | // if( !compliesMime(info->absFilePath(), mime ) ) | 659 | // if( !compliesMime(info->absFilePath(), mime ) ) |
660 | // return; | 660 | // return; |
661 | MimeType type( info->absFilePath() ); | 661 | MimeType type( info->absFilePath() ); |
662 | if( mime != tr("All") && type.id() != mime ) | 662 | if (!compliesMime( type.id() ) ) |
663 | return; | 663 | return; |
664 | |||
664 | QPixmap pix = type.pixmap(); | 665 | QPixmap pix = type.pixmap(); |
665 | QString dir; | 666 | QString dir; |
666 | QString name; | 667 | QString name; |
667 | bool locked; | 668 | bool locked; |
668 | if( pix.isNull() ) | 669 | if( pix.isNull() ) |
669 | pix = Resource::loadPixmap( "UnknownDocument-14"); | 670 | pix = Resource::loadPixmap( "UnknownDocument-14"); |
670 | dir = info->dirPath( true ); | 671 | dir = info->dirPath( true ); |
671 | if( symlink ) | 672 | if( symlink ) |
672 | name = info->fileName() + " -> " +info->dirPath() + "/" + info->readLink(); | 673 | name = info->fileName() + " -> " +info->dirPath() + "/" + info->readLink(); |
673 | else { | 674 | else { |
674 | name = info->fileName(); | 675 | name = info->fileName(); |
675 | if( ( m_mode == OPEN && !info->isReadable() )|| | 676 | if( ( m_mode == OPEN && !info->isReadable() )|| |
676 | ( m_mode == SAVE && !info->isWritable() ) ){ | 677 | ( m_mode == SAVE && !info->isWritable() ) ){ |
677 | 678 | ||
678 | locked = true; pix = Resource::loadPixmap("locked"); | 679 | locked = true; pix = Resource::loadPixmap("locked"); |
679 | } | 680 | } |
@@ -927,34 +928,85 @@ void OFileSelector::initPics() | |||
927 | pm2.setMask( pm2.createHeuristicMask( FALSE ) ); | 928 | pm2.setMask( pm2.createHeuristicMask( FALSE ) ); |
928 | m_pixmaps->insert("symlinkedlocked", pm2 ); | 929 | m_pixmaps->insert("symlinkedlocked", pm2 ); |
929 | } | 930 | } |
930 | // if a mime complies with the m_mimeCheck->currentItem | 931 | // if a mime complies with the m_mimeCheck->currentItem |
931 | bool OFileSelector::compliesMime( const QString &path, const QString &mime ) | 932 | bool OFileSelector::compliesMime( const QString &path, const QString &mime ) |
932 | { | 933 | { |
933 | if( mime == "All" ) | 934 | if( mime == "All" ) |
934 | return true; | 935 | return true; |
935 | MimeType type( path ); | 936 | MimeType type( path ); |
936 | if( type.id() == mime ) | 937 | if( type.id() == mime ) |
937 | return true; | 938 | return true; |
938 | return false; | 939 | return false; |
939 | } | 940 | } |
940 | /* check if the mimetype in mime | 941 | /* check if the mimetype in mime |
941 | * complies with the one which is current | 942 | * complies with the one which is current |
942 | */ | 943 | */ |
944 | /* | ||
945 | * We've the mimetype of the file | ||
946 | * We need to get the stringlist of the current mimetype | ||
947 | * | ||
948 | * mime = image/jpeg | ||
949 | * QStringList = 'image/*' | ||
950 | * or QStringList = image/jpeg;image/png;application/x-ogg | ||
951 | * or QStringList = application/x-ogg;image/*; | ||
952 | * with all these mime filters it should get acceptes | ||
953 | * to do so we need to look if mime is contained inside | ||
954 | * the stringlist | ||
955 | * if it's contained return true | ||
956 | * if not ( I'm no RegExp expert at all ) we'll look if a '/*' | ||
957 | * is contained in the mimefilter and then we will | ||
958 | * look if both are equal until the '/' | ||
959 | */ | ||
943 | bool OFileSelector::compliesMime( const QString& mime ) { | 960 | bool OFileSelector::compliesMime( const QString& mime ) { |
961 | qWarning("mimetype is %s", mime.latin1() ); | ||
962 | QString currentText; | ||
963 | if (m_shChooser ) | ||
964 | currentText = m_mimeCheck->currentText(); | ||
944 | 965 | ||
966 | qWarning("current text is %s", currentText.latin1() ); | ||
967 | QMap<QString, QStringList>::Iterator it; | ||
968 | QStringList list; | ||
969 | if ( currentText == tr("All") ) return true; | ||
970 | else if ( currentText.isEmpty() && !m_mimetypes.isEmpty() ) { | ||
971 | it = m_mimetypes.begin(); | ||
972 | list = it.data(); | ||
973 | }else if ( currentText.isEmpty() ) return true; | ||
974 | else{ | ||
975 | it = m_mimetypes.find(currentText ); | ||
976 | if ( it == m_mimetypes.end() ) qWarning("not there"), list << currentText; | ||
977 | else qWarning("found"), list = it.data(); | ||
978 | } | ||
979 | // dump it now | ||
980 | //for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { | ||
981 | // qWarning( "%s", (*it).latin1() ); | ||
982 | //} | ||
983 | |||
984 | |||
985 | if ( list.contains(mime) ) return true; | ||
986 | qWarning("list doesn't contain it "); | ||
987 | QStringList::Iterator it2; | ||
988 | int pos; | ||
989 | int pos2; | ||
990 | for ( it2 = list.begin(); it2 != list.end(); ++it2 ) { | ||
991 | pos = (*it2).findRev("/*"); | ||
992 | if ( pos >= 0 ) { | ||
993 | if ( mime.contains( (*it2).left(pos) ) ) return true; | ||
994 | } | ||
995 | } | ||
996 | return false; | ||
945 | } | 997 | } |
946 | void OFileSelector::slotFileSelected( const QString &string ) | 998 | void OFileSelector::slotFileSelected( const QString &string ) |
947 | { | 999 | { |
948 | if( m_shLne ) | 1000 | if( m_shLne ) |
949 | m_edit->setText( string ); | 1001 | m_edit->setText( string ); |
950 | emit fileSelected( string ); | 1002 | emit fileSelected( string ); |
951 | } | 1003 | } |
952 | void OFileSelector::slotFileBridgeSelected( const DocLnk &lnk ) | 1004 | void OFileSelector::slotFileBridgeSelected( const DocLnk &lnk ) |
953 | { | 1005 | { |
954 | slotFileSelected( lnk.name() ); | 1006 | slotFileSelected( lnk.name() ); |
955 | // emit fileSelected( lnk ); | 1007 | // emit fileSelected( lnk ); |
956 | } | 1008 | } |
957 | void OFileSelector::slotSelectionChanged() | 1009 | void OFileSelector::slotSelectionChanged() |
958 | { | 1010 | { |
959 | 1011 | ||
960 | } | 1012 | } |
@@ -1118,33 +1170,33 @@ void OFileSelector::reparse() | |||
1118 | //qWarning("Type %s", type.id().latin1() ); | 1170 | //qWarning("Type %s", type.id().latin1() ); |
1119 | m_mimetypes.insert( type.id(), type.id() ); | 1171 | m_mimetypes.insert( type.id(), type.id() ); |
1120 | } | 1172 | } |
1121 | 1173 | ||
1122 | ++it; | 1174 | ++it; |
1123 | } | 1175 | } |
1124 | // add them to the chooser | 1176 | // add them to the chooser |
1125 | updateMimeCheck(); | 1177 | updateMimeCheck(); |
1126 | m_mimeCheck->setCurrentItem( indexByString( m_mimeCheck, currentMimeType ) ); | 1178 | m_mimeCheck->setCurrentItem( indexByString( m_mimeCheck, currentMimeType ) ); |
1127 | currentMimeType = m_mimeCheck->currentText(); | 1179 | currentMimeType = m_mimeCheck->currentText(); |
1128 | } | 1180 | } |
1129 | }else { // no autoMime | 1181 | }else { // no autoMime |
1130 | // let the mimetype be set from out side the m_mimeCheck FEATURE | 1182 | // let the mimetype be set from out side the m_mimeCheck FEATURE |
1131 | 1183 | ||
1132 | if( m_shChooser ){ | 1184 | if( m_shChooser ){ |
1133 | currentMimeType = m_mimeCheck->currentText(); | 1185 | currentMimeType = m_mimeCheck->currentText(); |
1134 | updateMimeCheck(); | 1186 | // updateMimeCheck(); |
1135 | } | 1187 | } |
1136 | } | 1188 | } |
1137 | // now we got our mimetypes we can add the files | 1189 | // now we got our mimetypes we can add the files |
1138 | 1190 | ||
1139 | QDir dir( m_currentDir ); | 1191 | QDir dir( m_currentDir ); |
1140 | 1192 | ||
1141 | int sort; | 1193 | int sort; |
1142 | if ( m_case ) | 1194 | if ( m_case ) |
1143 | sort = (QDir::IgnoreCase | QDir::Name | QDir::DirsFirst | QDir::Reversed); | 1195 | sort = (QDir::IgnoreCase | QDir::Name | QDir::DirsFirst | QDir::Reversed); |
1144 | else | 1196 | else |
1145 | sort = (QDir::Name | QDir::DirsFirst | QDir::Reversed); | 1197 | sort = (QDir::Name | QDir::DirsFirst | QDir::Reversed); |
1146 | dir.setSorting( sort ); | 1198 | dir.setSorting( sort ); |
1147 | 1199 | ||
1148 | int filter; | 1200 | int filter; |
1149 | if( m_selector == EXTENDED_ALL /*|| m_selector ==CUSTOM_ALL */ ){ | 1201 | if( m_selector == EXTENDED_ALL /*|| m_selector ==CUSTOM_ALL */ ){ |
1150 | filter = QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All; | 1202 | filter = QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All; |