Diffstat (limited to 'libopie2/opieui/fileselector/ofileselector.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | libopie2/opieui/fileselector/ofileselector.cpp | 44 |
1 files changed, 37 insertions, 7 deletions
diff --git a/libopie2/opieui/fileselector/ofileselector.cpp b/libopie2/opieui/fileselector/ofileselector.cpp index b06defd..346eeae 100644 --- a/libopie2/opieui/fileselector/ofileselector.cpp +++ b/libopie2/opieui/fileselector/ofileselector.cpp @@ -407,52 +407,55 @@ OFileSelectorItem* OFileViewFileListView::currentItem()const void OFileViewFileListView::reread( bool all ) { m_view->clear(); if (selector()->showClose() ) m_btnClose->show(); else m_btnClose->hide(); if (selector()->showNew() ) m_btnNew->show(); else m_btnNew->hide(); m_mimes = selector()->currentMimeType(); m_all = all; QDir dir( m_currentDir ); if (!dir.exists() ) return; dir.setSorting( QDir::Name | QDir::DirsFirst | QDir::Reversed ); int filter; + filter = QDir::Dirs; + if ( selector()->mode() != OFileSelector::DIRECTORYSELECTOR ) + filter = filter | QDir::Files | QDir::All; + if (m_all ) - filter = QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All; - else - filter = QDir::Files | QDir::Dirs | QDir::All; + filter = filter | QDir::Hidden; + dir.setFilter( filter ); // now go through all files const QFileInfoList *list = dir.entryInfoList(); if (!list) { cdUP(); return; } QFileInfoListIterator it( *list ); QFileInfo *fi; while( (fi=it.current() ) ) { if( fi->fileName() == QString::fromLatin1("..") || fi->fileName() == QString::fromLatin1(".") ) { ++it; continue; } /* * It is a symlink we try to resolve it now but don't let us attack by DOS * */ @@ -793,49 +796,49 @@ void OFileViewFileSystem::reread() if (!m_view) return; m_view->reread( m_all ); } int OFileViewFileSystem::fileCount()const { if (!m_view ) return -1; return m_view->fileCount(); } QWidget* OFileViewFileSystem::widget( QWidget* parent ) { if (!m_view ) { m_view = new OFileViewFileListView( parent, startDirectory(), selector() ); } return m_view; } void OFileViewFileSystem::activate( const QString& str) { - m_all = (str != QObject::tr("Files") ); + m_all = ( str.find( "All" ) != -1 ); } } /* Selector */ /** * @short new and complete c'tor * * Create a OFileSelector to let the user select a file. It can * either be used to open a file, select a save name in a dir or * as a dropin for the FileSelector. * * <pre> * QMap<QString, QStringList> mimeTypes; * QStringList types; * types << "text@slash* "; * types << "audio@slash*"; * mimeTypes.insert( tr("Audio and Text"), types ); * mimeTypes.insert( tr("All"), "*@slash*); * * now you could create your fileselector * </pre> * * @@ -853,58 +856,73 @@ OFileSelector::OFileSelector( QWidget* parent, int mode, int sel, const QString& dirName, const QString& fileName, const MimeTypes& mimetypes, bool showNew, bool showClose) :QWidget( parent, "OFileSelector" ) { m_current = 0; m_shNew = showNew; m_shClose = showClose; m_mimeType = mimetypes; m_startDir = dirName; m_mode = mode; m_selector = sel; initUI(); m_lneEdit->setText( fileName ); initMime(); initViews(); QString str; switch ( m_selector ) { default: case Normal: + if ( m_mode == DIRECTORYSELECTOR ) + str = QObject::tr("Directories"); + else str = QObject::tr("Documents"); m_cmbView->setCurrentItem( 0 ); break; case Extended: + if ( m_mode == DIRECTORYSELECTOR ) + { + str = QObject::tr("Directories"); + m_cmbView->setCurrentItem( 0 ); + } else { str = QObject::tr("Files"); m_cmbView->setCurrentItem( 1 ); + } break; case ExtendedAll: + if ( m_mode == DIRECTORYSELECTOR ) + { + str = QObject::tr("All Directories"); + m_cmbView->setCurrentItem( 1 ); + } else { str = QObject::tr("All Files"); m_cmbView->setCurrentItem( 2 ); + } break; } slotViewChange( str ); } /** * This a convience c'tor to just substitute the use of FileSelector */ OFileSelector::OFileSelector( const QString& mimeFilter, QWidget* parent, const char* name, bool showNew, bool showClose ) : QWidget( parent, name ) { m_current = 0; m_shNew = showNew; m_shClose = showClose; m_startDir = QPEApplication::documentDir(); if (!mimeFilter.isEmpty() ) m_mimeType.insert(mimeFilter, QStringList::split(";", mimeFilter ) ); m_mode = OFileSelector::FileSelector; m_selector = OFileSelector::Normal; @@ -964,62 +982,74 @@ bool OFileSelector::eventFilter (QObject *, QEvent *e) } /* * This will insert the MimeTypes into the Combo Box * And also connect the changed signal * * AutoMimeTyping is disabled for now. It used to reparse a dir and then set available mimetypes */ void OFileSelector::initMime() { MimeTypes::Iterator it; for ( it = m_mimeType.begin(); it != m_mimeType.end(); ++it ) { m_cmbMime->insertItem( it.key() ); } m_cmbMime->setCurrentItem( 0 ); connect( m_cmbMime, SIGNAL(activated(int) ), this, SLOT(slotMimeTypeChanged() ) ); } void OFileSelector::initViews() { + if ( m_mode == OFileSelector::DIRECTORYSELECTOR ) + { + m_cmbView->insertItem( QObject::tr("Directories") ); + m_cmbView->insertItem( QObject::tr("All Directories") ); + } else { m_cmbView->insertItem( QObject::tr("Documents") ); m_cmbView->insertItem( QObject::tr("Files") ); m_cmbView->insertItem( QObject::tr("All Files") ); + } + connect(m_cmbView, SIGNAL(activated(const QString&) ), this, SLOT(slotViewChange(const QString&) ) ); - - m_views.insert( QObject::tr("Documents"), new ODocumentFileView(this) ); - /* see above why add both */ OFileViewInterface* in = new OFileViewFileSystem( this ); + + if ( m_mode == OFileSelector::DIRECTORYSELECTOR ) + { + m_views.insert( QObject::tr("Directories"), in ); + m_views.insert( QObject::tr("All Directories"), in ); + } else { + m_views.insert( QObject::tr("Documents"), new ODocumentFileView(this) ); m_views.insert( QObject::tr("Files"), in ); m_views.insert( QObject::tr("All Files"), in ); } +} void OFileSelector::registerView( const Internal::OFileViewInterface* iface ) { m_viewsPtr.append( iface ); } /** * d'tor */ OFileSelector::~OFileSelector() { m_viewsPtr.setAutoDelete( true ); m_viewsPtr.clear(); } /** * Convience function for the fileselector * make sure to delete the DocLnk * * @see DocLnk * @todo remove in ODP */ |