-rw-r--r-- | libopie/ofileselector.cc | 134 |
1 files changed, 103 insertions, 31 deletions
diff --git a/libopie/ofileselector.cc b/libopie/ofileselector.cc index 61ab2c4..1807575 100644 --- a/libopie/ofileselector.cc +++ b/libopie/ofileselector.cc @@ -48,12 +48,29 @@ #include <qpe/resource.h> #include "ofileselector.h" QMap<QString,QPixmap> *OFileSelector::m_pixmaps = 0; +namespace { + + int indexByString( const QComboBox *box, const QString &str ){ + int index= -1; + for(int i= 0; i < box->count(); i++ ){ + qWarning("str T%sT boxT%sT", str.latin1(), box->text(i).latin1() ); + if( str == box->text(i ) ){ + index= i; + break; + } + } + return index; + } + +}; + + OFileSelector::OFileSelector(QWidget *wid, int mode, int selector, const QString &dirName, const QString &fileName, const QStringList mimetypes ) : QWidget( wid ) { m_selector = selector; m_currentDir = dirName; m_name = fileName; @@ -101,20 +118,27 @@ OFileSelector::OFileSelector(QWidget *wid, int mode, int selector, const QString m_lay = new QVBoxLayout(this); init(); m_edit->setText( fileName ); } void OFileSelector::initPics() { + qWarning("init pics" ); m_pixmaps = new QMap<QString,QPixmap>; - QPixmap pm = Resource::loadPixmap( "folder " ); + 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 ); + QPixmap pm2 = Resource::loadPixmap( "lockedfolder" ); + QPainter pen(&pm2 ); + pen.drawPixmap(pm2.width()-lnk.width(), pm2.height()-lnk.height(), lnk ); + pm2.setMask( pm2.createHeuristicMask( FALSE ) ); + m_pixmaps->insert("symlinkedlocked", pm2 ); + }; // let's initialize the gui /** -------------------- | cmbBox Button | -------------------- @@ -141,16 +165,24 @@ void OFileSelector::delItems() } } void OFileSelector::init() { m_stack = new QWidgetStack(this, "wstack" ); - m_select = new FileSelector(m_mimetypes.join(";"), m_stack, "fileselector", FALSE, FALSE ); - m_stack->addWidget(m_select, NORMAL ); - m_lay->addWidget(m_stack ); - m_stack->raiseWidget(NORMAL ); + if( m_selector == NORMAL ){ + QString currMime; + if( m_mimeCheck != 0 ) + currMime = m_mimeCheck->currentText(); + updateMimes(); + m_select = new FileSelector( currMime == "All" ? QString::null : currMime , m_stack, "fileselector", FALSE, FALSE ); + m_stack->addWidget(m_select, NORMAL ); + m_lay->addWidget(m_stack ); + m_stack->raiseWidget(NORMAL ); + }else { + initializeListView(); + } if(m_shLne ){ initializeName(); } if(m_shPerm ){ @@ -276,13 +308,13 @@ QString OFileSelector::selectedName( )const } return string; } QStringList OFileSelector::selectedNames()const { QStringList list; - + return list; } DocLnk OFileSelector::selectedDocument( )const { DocLnk lnk; return lnk; } @@ -362,12 +394,13 @@ void OFileSelector::reparse() ++it; } m_mimetypes.prepend("All" ); m_mimeCheck->insertStringList(m_mimetypes ); // set it to the current mimetype + m_mimeCheck->setCurrentItem( indexByString( m_mimeCheck, currMime ) ); }; QDir dir( m_currentDir ); //dir.setFilter(-1 ); dir.setSorting(QDir::Name | QDir::DirsFirst | QDir::Reversed | QDir::IgnoreCase ); const QFileInfoList *list = dir.entryInfoList(); QFileInfoListIterator it( *list ); @@ -377,16 +410,16 @@ void OFileSelector::reparse() ++it; continue; } qWarning("Test: %s", fi->fileName().latin1() ); if(fi->isSymLink() ){ qWarning("Symlink %s", fi->fileName().latin1() ); - QString file = fi->readLink(); + QString file = fi->dirPath(true)+"/"+ fi->readLink(); qWarning("File ->%s", file.latin1() ); for(int i=0; i<=4; i++ ){ // prepend from dos - QFileInfo info( fi->dirPath()+ "/"+file ); + QFileInfo info( file ); if( !info.exists() ){ qWarning("does not exist" ); addSymlink(currMime, fi, TRUE ); break; }else if( info.isDir() ){ qWarning("isDir" ); @@ -394,13 +427,13 @@ void OFileSelector::reparse() break; }else if( info.isFile() ){ qWarning("isFile" ); addFile(currMime, fi, TRUE ); break; }else if( info.isSymLink() ){ - file = info.readLink(); + file = info.dirPath(true)+ "/"+ info.readLink(); qWarning("isSymlink again %s", file.latin1() ); }else if( i == 4 ){ // just insert it and have the symlink symbol addSymlink(currMime, fi ); qWarning("level too deep" ); } } @@ -490,14 +523,13 @@ void OFileSelector::slotMimeCheck(const QString &view ){ delete m_select; m_select = new FileSelector(view == "All" ? QString::null : view , m_stack, "fileselector", FALSE, FALSE ); m_stack->addWidget( m_select, NORMAL ); m_stack->raiseWidget( NORMAL ); }else{ - - + reparse(); } } void OFileSelector::slotViewCheck(const QString &view ){ qWarning("changed: show %s", view.latin1() ); // if the current view is the one @@ -555,13 +587,13 @@ void OFileSelector::updateMimes() // lets check which mode is active for ( ; dit.current(); ++dit ) { if( !m_mimetypes.contains((*dit)->type() ) ) m_mimetypes.append( (*dit)->type() ); } }else{ // should be allreday updatet - + ; } }; void OFileSelector::initializeListView() { m_View = new QListView(m_stack, "Extended view" ); m_stack->addWidget( m_View, EXTENDED ); @@ -577,56 +609,96 @@ void OFileSelector::initializeListView() m_View->addColumn(tr("Date"), 60 ); m_View->addColumn(tr("Mime Type") ); QHeader *header = m_View->header(); header->hide(); m_View->setSorting(1 ); }; +/* If a item is locked depends on the mode + if we're in OPEN !isReadable is locked + if we're in SAVE !isWriteable is locked + + + */ + void OFileSelector::addFile(const QString &mime, QFileInfo *info, bool symlink ){ qWarning("Add Files" ); if( !m_files ){ qWarning("not mfiles" ); return; } MimeType type( info->filePath() ); + QString name; + QString dir; + bool locked= false; 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) ); + dir = info->dirPath( true ); + if( symlink ) { // check if the readLink is readable + // do it right later + name = info->fileName() + " -> " + info->dirPath() + "/" + info->readLink(); + }else{ // keep track of the icons + name = info->fileName(); + if( m_mode == OPEN ){ + if( !info->isReadable() ){ + locked = true; + pix = Resource::loadPixmap("locked" ); + } + }else if( m_mode == SAVE ){ + if( !info->isWritable() ){ + locked = true; + pix = Resource::loadPixmap("locked" ); + } + } + } + new OFileSelectorItem( m_View, pix, name, + info->lastModified().toString(), + QString::number( info->size() ), + dir, locked ); } void OFileSelector::addDir(const QString &mime, QFileInfo *info, bool symlink ) { if(!m_dir ) return; //if( showDirs ) { + bool locked; + QString name; + QPixmap pix; + if( ( m_mode == OPEN && !info->isReadable() ) || ( m_mode == SAVE && !info->isWritable() ) ){ + locked = true; + if( symlink ){ + pix = (*m_pixmaps)["symlinkedlocked"]; + }else{ + pix = Resource::loadPixmap("lockedfolder" ); + } + }else{ + if( symlink ){ + pix = (*m_pixmaps)["dirsymlink" ]; + }else{ + pix = Resource::loadPixmap("folder" ); + } + } 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 ); + name = info->fileName()+ "->"+ info->dirPath(true) +"/" +info->readLink(); + + }else{ + //if(info->isReadable() ) + name = info->fileName(); + } + + new OFileSelectorItem(m_View, pix, + name, info->lastModified().toString(), + QString::number(info->size() ),info->dirPath(true), locked, true ); } } void OFileSelector::setShowDirs(bool dir ) { m_dir = dir; |