-rw-r--r-- | libopie/ofileselector.cc | 168 |
1 files changed, 142 insertions, 26 deletions
diff --git a/libopie/ofileselector.cc b/libopie/ofileselector.cc index b911d37..61ab2c4 100644 --- a/libopie/ofileselector.cc +++ b/libopie/ofileselector.cc @@ -40,2 +40,3 @@ #include <qdir.h> +#include <qpainter.h> @@ -46,2 +47,3 @@ #include <qpe/mimetype.h> +#include <qpe/resource.h> @@ -49,2 +51,3 @@ +QMap<QString,QPixmap> *OFileSelector::m_pixmaps = 0; @@ -91,2 +94,8 @@ OFileSelector::OFileSelector(QWidget *wid, int mode, int selector, const QString + m_dir = true; + m_files = true; + + if(m_pixmaps == 0 ) // init the pixmaps + initPics(); + m_lay = new QVBoxLayout(this); @@ -95,3 +104,13 @@ OFileSelector::OFileSelector(QWidget *wid, int mode, int selector, const QString } +void OFileSelector::initPics() +{ + m_pixmaps = new QMap<QString,QPixmap>; + QPixmap pm = Resource::loadPixmap( "folder " ); + QPixmap lnk = Resource::loadPixmap( "symlink" ); + QPainter painter( &pm ); + painter.drawPixmap( pm.width()-lnk.width(), pm.height()-lnk.height(), lnk ); + pm.setMask( pm.createHeuristicMask( FALSE ) ); + m_pixmaps->insert("dirsymlink", pm ); +}; // let's initialize the gui @@ -151,3 +170,3 @@ void OFileSelector::init() -void OFileSelector::setShowYesCancel( bool show ) +void OFileSelector::setYesCancelVisible( bool show ) { @@ -166,3 +185,3 @@ void OFileSelector::setShowYesCancel( bool show ) -void OFileSelector::setShowToolbar( bool show ) +void OFileSelector::setToolbarVisible( bool show ) { @@ -177,3 +196,3 @@ void OFileSelector::setShowToolbar( bool show ) -void OFileSelector::setShowPermissionBar( bool show ) +void OFileSelector::setPermissionBarVisible( bool show ) { @@ -186,3 +205,3 @@ void OFileSelector::setShowPermissionBar( bool show ) } -void OFileSelector::setShowLineEdit( bool show ) +void OFileSelector::setLineEditVisible( bool show ) { @@ -201,3 +220,3 @@ void OFileSelector::setShowLineEdit( bool show ) } -void OFileSelector::setShowChooser( bool show ) +void OFileSelector::setChooserVisible( bool show ) { @@ -218,2 +237,16 @@ QCheckBox* OFileSelector::permissionCheckbox( ) } +void OFileSelector::setCaseSensetive( bool caSe ) +{ + m_case = caSe; + reparse(); +} +void OFileSelector::setShowFiles(bool files ){ + m_files = files; + reparse(); +} +void OFileSelector::setPopupMenu(const QPopupMenu * ) +{ + //delete oldpopup; + +} bool OFileSelector::setPermission( ) const @@ -231,10 +264,25 @@ void OFileSelector::setPermissionChecked( bool check ) } -QString OFileSelector::selectedName( ) +QString OFileSelector::selectedName( )const { QString string; + if( m_selector == NORMAL ){ + const DocLnk *lnk = m_select->selected(); + string = lnk->file(); + }else if(m_selector == EXTENDED || m_selector == EXTENDED_ALL ) { + QListViewItem *item = m_View->currentItem(); + if(item != 0 ){ + string = item->text( 1 ); + } + } return string; } -const DocLnk* OFileSelector::selectedDocument( )const +QStringList OFileSelector::selectedNames()const { - return 0; + QStringList list; + +} +DocLnk OFileSelector::selectedDocument( )const +{ + DocLnk lnk; + return lnk; } @@ -288,3 +336,3 @@ void OFileSelector::reparse() { - if(m_View== 0) + if(m_View== 0 || m_selector == NORMAL) return; @@ -293,3 +341,3 @@ void OFileSelector::reparse() - QDir dir( m_currentDir ); + QString currMime =m_mimeCheck->currentText(); @@ -297,2 +345,3 @@ void OFileSelector::reparse() if( m_autoMime ) { + QDir dir( m_currentDir ); m_mimetypes.clear(); @@ -315,2 +364,3 @@ void OFileSelector::reparse() } + m_mimetypes.prepend("All" ); m_mimeCheck->insertStringList(m_mimetypes ); @@ -318,4 +368,5 @@ void OFileSelector::reparse() }; - dir.setFilter(QDir::All ); - dir.setSorting(QDir::Name | QDir::DirsFirst ); + QDir dir( m_currentDir ); + //dir.setFilter(-1 ); + dir.setSorting(QDir::Name | QDir::DirsFirst | QDir::Reversed | QDir::IgnoreCase ); const QFileInfoList *list = dir.entryInfoList(); @@ -324,17 +375,31 @@ void OFileSelector::reparse() while( (fi=it.current()) ){ + if(fi->fileName() == ".." || fi->fileName() == "." ){ + ++it; + continue; + } + qWarning("Test: %s", fi->fileName().latin1() ); if(fi->isSymLink() ){ + qWarning("Symlink %s", fi->fileName().latin1() ); QString file = fi->readLink(); + qWarning("File ->%s", file.latin1() ); for(int i=0; i<=4; i++ ){ // prepend from dos - QFileInfo info( file ); + QFileInfo info( fi->dirPath()+ "/"+file ); if( !info.exists() ){ - addSymlink(m_currentDir, info.fileName(), TRUE ); + qWarning("does not exist" ); + addSymlink(currMime, fi, TRUE ); break; }else if( info.isDir() ){ - //addDir( ); + qWarning("isDir" ); + addDir(currMime, fi, TRUE ); + break; }else if( info.isFile() ){ - + qWarning("isFile" ); + addFile(currMime, fi, TRUE ); + break; }else if( info.isSymLink() ){ file = info.readLink(); + qWarning("isSymlink again %s", file.latin1() ); }else if( i == 4 ){ // just insert it and have the symlink symbol - addSymlink(m_currentDir, info.fileName() ); + addSymlink(currMime, fi ); + qWarning("level too deep" ); } @@ -342,6 +407,5 @@ void OFileSelector::reparse() }else if( fi->isDir() ){ - + addDir(currMime, fi ); }else if( fi->isFile() ) { // file ? - - + addFile(currMime, fi ); } @@ -349,7 +413,7 @@ void OFileSelector::reparse() } + m_View->sort(); } -QString OFileSelector::directory() +QString OFileSelector::directory()const { - QString string; - return string; + return m_currentDir; } @@ -450,4 +514,8 @@ void OFileSelector::slotViewCheck(const QString &view ){ m_stack->addWidget( m_select, NORMAL ); - m_stack->raiseWidget( NORMAL ); + m_mimeCheck->clear(); m_selector = NORMAL; + updateMimes(); + m_mimeCheck->insertStringList( m_mimetypes ); + m_stack->raiseWidget( NORMAL ); + @@ -512,8 +580,56 @@ void OFileSelector::initializeListView() header->hide(); + m_View->setSorting(1 ); }; +void OFileSelector::addFile(const QString &mime, QFileInfo *info, bool symlink ){ + qWarning("Add Files" ); + if( !m_files ){ + qWarning("not mfiles" ); + return; + } + MimeType type( info->filePath() ); + if(mime == "All" ){ + ; + }else if( type.id() != mime ) { + return; + } + QPixmap pix = type.pixmap(); + if(pix.isNull() ) + pix = Resource::loadPixmap( "UnknownDocument-14" ); + if( symlink ) // have a blended pic sometime + new OFileSelectorItem( m_View, pix, info->fileName(), + info->lastModified().toString(), + QString::number(info->size() ), + info->dirPath(true) ); + else + new OFileSelectorItem( m_View, pix, info->fileName(), + info->lastModified().toString(), + QString::number(info->size() ), + info->dirPath(true) ); +} +void OFileSelector::addDir(const QString &mime, QFileInfo *info, bool symlink ) +{ + if(!m_dir ) + return; + //if( showDirs ) + { + if( symlink){ + QPixmap map = (*m_pixmaps)["dirsymlink" ]; + qWarning("Symlink" ); + new OFileSelectorItem(m_View, map, + info->fileName(), info->lastModified().toString() , + QString::number(info->size() ),info->dirPath(true), true ); + }else + new OFileSelectorItem(m_View, Resource::loadPixmap("folder" ), + info->fileName(), info->lastModified().toString(), + QString::number(info->size() ),info->dirPath(true), true ); - - + } +} +void OFileSelector::setShowDirs(bool dir ) +{ + m_dir = dir; + reparse(); +} |