-rw-r--r-- | libopie/ofileselector/ofilelistview.cpp | 20 | ||||
-rw-r--r-- | libopie/ofileselector/ofilelistview.h | 15 | ||||
-rw-r--r-- | libopie/ofileselector/ofileselector.cpp | 1 | ||||
-rw-r--r-- | libopie/ofileselector/ofileselectoritem.cpp | 5 | ||||
-rw-r--r-- | libopie/ofileselector/ofileselectoritem.h | 5 | ||||
-rw-r--r-- | libopie/ofileselector/ofileview.cpp | 14 | ||||
-rw-r--r-- | libopie/ofileselector/ofileview.h | 29 | ||||
-rw-r--r-- | libopie/ofileselector/olister.cpp | 58 | ||||
-rw-r--r-- | libopie/ofileselector/olister.h | 61 | ||||
-rw-r--r-- | libopie/ofileselector/olocallister.cpp | 3 |
10 files changed, 185 insertions, 26 deletions
diff --git a/libopie/ofileselector/ofilelistview.cpp b/libopie/ofileselector/ofilelistview.cpp index 691bf42..9cfdc48 100644 --- a/libopie/ofileselector/ofilelistview.cpp +++ b/libopie/ofileselector/ofilelistview.cpp @@ -1,193 +1,203 @@ #include <qheader.h> #include <qpe/mimetype.h> #include <qpe/resource.h> #include <qpe/qpeapplication.h> #include "ofileselector.h" #include "ofileselectoritem.h" #include "ofilelistview.h" OFileListView::OFileListView( QWidget* parent, OFileSelector* sel) : QListView( parent ), OFileView( sel ) { QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold); addColumn(" " ); addColumn(tr("Name"), 135 ); addColumn(tr("Size"), -1 ); addColumn(tr("Date"), 60 ); addColumn(tr("Mime Type"), -1 ); QHeader *head = header(); head->hide(); setSorting( 1 ); setAllColumnsShowFocus( TRUE ); connect(this, SIGNAL(selectionChanged() ), this, SLOT(slotSelectionChanged() ) ); connect(this, SIGNAL(currentChanged(QListViewItem *) ), this, SLOT(slotCurrentChanged(QListViewItem * ) ) ); connect(this, SIGNAL(mouseButtonClicked(int, QListViewItem*, const QPoint &, int) ), this, SLOT(slotClicked( int, QListViewItem *, const QPoint &, int) ) ); connect(this, SIGNAL(mouseButtonPressed(int, QListViewItem *, const QPoint &, int )), this, SLOT(slotRightButton(int, QListViewItem *, const QPoint &, int ) ) ); } OFileListView::~OFileListView() { } void OFileListView::clear() { QListView::clear(); } void OFileListView::addFile( const QPixmap& pix, const QString&, QFileInfo* info, + const QString& /*extra*/, bool isSymlink ) { QString dir; QString name; bool locked = false; dir = info->dirPath( true ); if( isSymlink ) name = info->fileName() + " -> " +info->dirPath() + "/" + info->readLink(); else { name = info->fileName(); if( ( selector()->mode() == OFileSelector::Open && !info->isReadable() ) || ( selector()->mode() == OFileSelector::Save && !info->isWritable() ) ){ locked = true; } } new OFileSelectorItem( this, pix, name, info->lastModified().toString(), QString::number( info->size() ), dir, locked ); } void OFileListView::addFile( const QPixmap&, const QString& /*mime*/, const QString& /*dir*/, - const QString& /*file*/, bool /*isSyml*/ ) { + const QString& /*file*/, + const QString& /*extra*/, + bool /*isSyml*/ ) { } void OFileListView::addDir( const QPixmap& pix, const QString&, - QFileInfo* info, bool symlink ) { + QFileInfo* info, + const QString& /*extra */, + bool symlink ) { bool locked = false; QString name; name = symlink ? info->fileName() + "->" + info->dirPath(true) + "/" +info->readLink() : info->fileName() ; new OFileSelectorItem( this, pix, name, info->lastModified().toString(), QString::number( info->size() ), info->dirPath( true ), locked, true ); } void OFileListView::addDir( const QPixmap&, const QString& /*mime*/, const QString& /*dir*/, - const QString& /*file*/, bool ) { + const QString& /*file*/, + const QString& /*extra*/, + bool ) { } void OFileListView::addSymlink( const QPixmap&, const QString& /*mime*/, QFileInfo* /*info*/, + const QString& /*extra*/, bool /*isSym*/ ) { } void OFileListView::addSymlink(const QPixmap&, const QString& /*m*/, const QString& /*path*/, - const QString& /*file*/, bool /*isSym*/ ) { + const QString& /*file*/, + const QString& /*extra*/, + bool /*isSym*/ ) { } void OFileListView::cd( const QString& ) { } QWidget* OFileListView::widget() { return this; } QString OFileListView::selectedName()const{ QListViewItem *item = currentItem(); if (!item ) return QString::null; return item->text( 1 ); } QStringList OFileListView::selectedNames()const { QStringList list; list << selectedName(); return list; } QString OFileListView::selectedPath()const { return QString::null; } QStringList OFileListView::selectedPaths()const { QStringList list; - list << selectedPath(); +b list << selectedPath(); return list; } int OFileListView::fileCount() { return childCount(); } void OFileListView::sort() { QListView::sort(); } void OFileListView::slotSelectionChanged() { } void OFileListView::slotCurrentChanged( QListViewItem* item) { if (!item ) return; OFileSelectorItem* sel = (OFileSelectorItem*) item; qWarning("current changed"); if(!sel->isDir() ){ updateLine( sel->text(1) ); if (selector()->mode() == OFileSelector::Fileselector ) { QStringList str = QStringList::split("->", sel->text(1) ); QString path =sel->directory() + "/" + str[0].stripWhiteSpace(); DocLnk lnk( path ); fileSelected(lnk ); fileSelected( path ); } } } void OFileListView::slotClicked( int button, QListViewItem* item, const QPoint&, int ) { if ( !item ) return; if( button != Qt::LeftButton ) return; OFileSelectorItem *sel = (OFileSelectorItem*)item; if(!sel->isLocked() ){ QStringList str = QStringList::split("->", sel->text(1) ); if( sel->isDir() ){ changedDir( sel->directory() + "/" + str[0].stripWhiteSpace() ); }else{ updateLine( str[0].stripWhiteSpace() ); QString path = sel->directory(); path += "/"; path += str[0].stripWhiteSpace(); DocLnk lnk( path ); fileSelected( path ); fileSelected( lnk ); } } } void OFileListView::slotRightButton( int button, QListViewItem* item, const QPoint&, int ) { if (!item || (button != Qt::RightButton )) return; /* raise contextmenu */ } diff --git a/libopie/ofileselector/ofilelistview.h b/libopie/ofileselector/ofilelistview.h index c8cdfd1..0f625ec 100644 --- a/libopie/ofileselector/ofilelistview.h +++ b/libopie/ofileselector/ofilelistview.h @@ -1,58 +1,67 @@ #ifndef OPIE_FILE_LIST_VIEW_H #define OPIE_FILE_LIST_VIEW_H #include <qlistview.h> #include <qpixmap.h> #include "ofileview.h" class OFileListView : public QListView, public OFileView { Q_OBJECT public: OFileListView( QWidget* parent, OFileSelector* ); ~OFileListView(); void clear(); void addFile( const QPixmap&, const QString& mine, QFileInfo* info, + const QString& extra = QString::null, bool isSymlink = FALSE ); void addFile( const QPixmap&, const QString& mime, const QString& dir, const QString& file, + const QString& extra = QString::null, bool = false ); void addDir( const QPixmap&, const QString& mime, + const QString& extra = QString::null, QFileInfo* info, bool = FALSE ); void addDir( const QPixmap&, const QString& mime, const QString& dir, - const QString& file, bool = FALSE ); + const QString& file, + const QString& extra = QString::null, + bool = FALSE ); void addSymlink( const QPixmap&, const QString& mime, - QFileInfo* info, bool = FALSE ); + QFileInfo* info, + const QString& extra = QString::null, + bool = FALSE ); void addSymlink( const QPixmap&, const QString& mine, const QString& path, - const QString& file, bool isSymlink = FALSE ); + const QString& file, + const QString& extra, + bool isSymlink = FALSE ); void cd( const QString& path ); QWidget* widget(); void sort(); QString selectedName()const ; QStringList selectedNames()const; QString selectedPath()const; QStringList selectedPaths()const; int fileCount(); private slots: void slotSelectionChanged(); void slotCurrentChanged(QListViewItem* ); void slotClicked( int, QListViewItem*, const QPoint&, int ); void slotRightButton(int, QListViewItem*, const QPoint&, int ); }; #endif diff --git a/libopie/ofileselector/ofileselector.cpp b/libopie/ofileselector/ofileselector.cpp index 4ab744c..0ccb3cb 100644 --- a/libopie/ofileselector/ofileselector.cpp +++ b/libopie/ofileselector/ofileselector.cpp @@ -218,385 +218,384 @@ void OFileSelector::setShowDirs(bool dir) m_dir = dir; if ( m_selector != Fileselector ) reparse(); } void OFileSelector::setCaseSensetive(bool caSe ) { m_case = caSe; if ( m_selector != Fileselector ) reparse(); } void OFileSelector::setShowFiles(bool show ) { m_files = show; reparse(); } /// bool OFileSelector::cd(const QString &path ) { m_currentDir = path; reparse(); return true; } void OFileSelector::setSelector(int mode ) { QString text; switch( mode ){ case Normal: text = tr("Documents"); break; case Extended: text = tr("List View"); break; case ExtendedAll: text = tr("All List View"); break; } slotViewCheck( text ); } void OFileSelector::setPopupFactory(OPopupMenuFactory */*popup*/ ) { /* m_custom = popup; m_showPopup = true; */ } //void OFileSelector::updateL QString OFileSelector::selectedName() const { QString name; if( m_selector == Normal ){ DocLnk lnk = m_select->selectedDocument(); name = lnk.file(); }else { if ( m_shLne ) { name = m_currentDir + "/" +m_edit->text(); }else{ name = m_currentDir + "/" + currentView()->selectedName(); } } return name; } QStringList OFileSelector::selectedNames()const { QStringList list; if( m_selector == Normal ){ list << selectedName(); }else { list << selectedName(); // FIXME implement multiple Selections } return list; } /** If mode is set to the Dir selection this will return the selected path. * * */ QString OFileSelector::selectedPath()const { QString path; if( m_selector == Normal ){ path = QPEApplication::documentDir(); } /* normal case to do */ return path; } QStringList OFileSelector::selectedPaths() const { QStringList list; list << selectedPath(); return list; } QString OFileSelector::directory()const { if( m_selector == Normal ) return QPEApplication::documentDir(); return QDir(m_currentDir).absPath(); } int OFileSelector::fileCount() { int count; switch( m_selector ){ case Normal: count = m_select->fileCount(); break; case Extended: case ExtendedAll: default: count = currentView()->fileCount(); break; } return count; } DocLnk OFileSelector::selectedDocument() const { DocLnk lnk; switch( m_selector ){ case Normal:{ lnk = m_select->selectedDocument(); break; } case Extended: case ExtendedAll: default: lnk = DocLnk( selectedName() ); break; } return lnk; } QValueList<DocLnk> OFileSelector::selectedDocuments() const { QValueList<DocLnk> docs; docs.append( selectedDocument() ); return docs; } // slots internal void OFileSelector::slotOk() { emit ok(); } void OFileSelector::slotCancel() { emit cancel(); } /* switch the views */ void OFileSelector::slotViewCheck(const QString &sel) { setView( sel ); } QString OFileSelector::currentMimeType() const{ QString mime; QString currentText; if (m_shChooser && m_mimeCheck ) currentText = m_mimeCheck->currentText(); qWarning("CurrentText" + currentText ); if (tr("All") == currentText ) return QString::null; else if (currentText.isEmpty() ) { ; }else { QMap<QString, QStringList>::ConstIterator it; it = m_mimetypes.find( currentText ); if ( it != m_mimetypes.end() ) { mime = it.data().join(";"); }else{ mime = currentText; } } return mime; } void OFileSelector::slotMimeCheck(const QString &mime) { if( m_selector == Normal ){ initializeOldSelector(); updateMimes(); updateMimeCheck(); m_mimeCheck->setCurrentItem(indexByString( m_mimeCheck, mime) ); }else{ // others qWarning("Mime %s", mime.latin1() ); if(m_shChooser ){ qWarning("Current Text %s", m_mimeCheck->currentText().latin1() ); //m_mimeCheck->setCurrentItem(indexByString( m_mimeCheck, mime) ); } reparse(); } - } /* * Ok if a non dir gets inserted into this combobox * we need to change it * QFileInfo and dirPath will give us the right Dir */ void OFileSelector::slotLocationActivated(const QString &file) { qWarning("slotLocationActivated"); QString name = file.left( file.find("<-", 0, TRUE ) ); QFileInfo info( name ); if ( info.isFile() ) cd(info.dirPath( TRUE ) ); //absolute else cd(name ); reparse(); } void OFileSelector::slotInsertLocationPath(const QString ¤tPath, int count) { QStringList pathList; bool underDog = FALSE; for(int i=0;i<count;i++) { pathList << m_location->text(i); if( m_location->text(i) == currentPath) underDog = TRUE; } if( !underDog) { m_location->clear(); if( currentPath.left(2)=="//") pathList.append( currentPath.right(currentPath.length()-1) ); else pathList.append( currentPath ); m_location->insertStringList( pathList,-1); } } /* * Do not crash anymore * don't try to change dir to a file */ void OFileSelector::locationComboChanged() { QFileInfo info( m_location->lineEdit()->text() ); qWarning("info %s %s", info.dirPath(true).latin1(), m_location->lineEdit()->text().latin1() ); if (info.isFile() ) cd(info.dirPath(TRUE) ); //absolute path else cd( m_location->lineEdit()->text() ); reparse(); } void OFileSelector::init() { initFactory(); m_lay = new QVBoxLayout( this ); m_lay->setSpacing(0 ); /* take care of the main view... */ initToolbar(); //if( m_shChooser ) // the Chooser for the view and Mimetypes initializeChooser(); /* initialize the file lister */ if( m_selector == Normal ){ QString mime; if (!m_autoMime) { if (!m_mimetypes.isEmpty() ) { QMap<QString, QStringList>::Iterator it; it = m_mimetypes.begin(); // cause we're in the init mime = it.data().join(";"); } } initializeOldSelector(); }else{ initializeView(); } if( m_shLne ) // the LineEdit with the current FileName initializeName(); if( m_shPerm ) // the Permission QCheckBox initializePerm(); if( m_shYesNo ) // the Yes No button row initializeYes( ); if (m_selector != Normal ) reparse(); } void OFileSelector::updateMimes() { if( m_autoMime ){ m_mimetypes.clear(); m_mimetypes.insert( tr("All"), QString::null ); if( m_selector == Normal ){ DocLnkSet set; Global::findDocuments(&set, QString::null ); QListIterator<DocLnk> dit( set.children() ); for( ; dit.current(); ++dit ){ if( !m_mimetypes.contains( (*dit)->type() ) ) m_mimetypes.insert( (*dit)->type(), (*dit)->type() ); } }// else done in reparse } } void OFileSelector::initVars() { if( m_mimetypes.isEmpty() ) m_autoMime = true; else m_autoMime = false; m_shClose = false; m_shNew = false; m_shTool = true; m_shPerm = false; m_shLne = true; m_shChooser = true; m_shYesNo = true; m_case = false; m_dir = true; m_files = true; m_showPopup = false; m_mainView = 0l; m_fileView = 0l; m_lister = 0l; if(m_pixmaps == 0 ) // init the pixmaps initPics(); // pointers m_location = 0; m_mimeCheck = 0; m_viewCheck = 0; m_homeButton = 0; m_docButton = 0; m_hideButton = 0; m_ok = 0; m_cancel = 0; m_reread = 0; m_up = 0; m_View = 0; m_checkPerm = 0; m_pseudo = 0; m_pseudoLayout = 0; m_select = 0; m_lay = 0; m_Oselector = 0; m_boxToolbar = 0; m_boxOk = 0; m_boxName = 0; m_boxView = 0; m_edit = 0; m_fnLabel = 0; m_new = 0; m_close = 0; } void OFileSelector::initializeName() { /** Name Layout Line * This is the Layout line arranged in * horizontal way each components * are next to each other * but we will only do this if * we didn't initialize a while ago. */ if( m_boxName == 0 ){ m_boxName = new QHBox( this ); // remove this this? or use a QHBox m_fnLabel = new QLabel( m_boxName ); m_fnLabel->setText( tr("Name:") ); m_edit = new QLineEdit( m_boxName ); m_edit->setText( m_name ); //m_boxName->addWidget( m_fnLabel ); m_boxName->setMargin( 5 ); m_boxName->setSpacing( 8 ); //m_boxName->setStretchFactor(m_edit, 100 ); // 100 is stretch factor m_lay->addWidget( m_boxName, 0 ); // add it to the topLevel layout }// else we already initialized // maybe show the components? // } void OFileSelector::initializeYes() { /** The Save Cancel bar * */ if( m_boxOk == 0 ){ m_boxOk = new QHBox( this ); m_ok = new QPushButton( tr("&Save"),m_boxOk , "save" ); m_cancel = new QPushButton( tr("C&ancel"), m_boxOk, "cancel" ); //m_boxOk->addWidget( m_ok ); diff --git a/libopie/ofileselector/ofileselectoritem.cpp b/libopie/ofileselector/ofileselectoritem.cpp index 1e745a1..d31046b 100644 --- a/libopie/ofileselector/ofileselectoritem.cpp +++ b/libopie/ofileselector/ofileselectoritem.cpp @@ -1,53 +1,58 @@ #include "ofileselectoritem.h" OFileSelectorItem::OFileSelectorItem( QListView*view, const QPixmap& pix, const QString& path, const QString& date, const QString& size, const QString& dir, + const QString& extra, bool isLocked, bool isDir ) : QListViewItem( view ) { setPixmap( 0, pix ); setText( 1, path ); setText( 2, size ); setText( 3, date ); m_dir = isDir; m_locked = isLocked; m_dirStr = dir; + m_extra = extra; } OFileSelectorItem::~OFileSelectorItem() { } bool OFileSelectorItem::isLocked()const { return m_locked; } QString OFileSelectorItem::directory()const { return m_dirStr; } bool OFileSelectorItem::isDir()const { return m_dir; } QString OFileSelectorItem::path() const { return text(1); } QString OFileSelectorItem::key( int id, bool ) { QString ke; if( id == 0 || id == 1 ){ // name if( m_dir ){ ke.append("0" ); ke.append( text(1) ); }else{ ke.append("1" ); ke.append( text(1) ); } }else if( id == 2 ){ // size return text(2); }else if( id == 3 ){ // date return text(3); } return ke; } +QString OFileSelector::extra()const { + return m_extra; +} diff --git a/libopie/ofileselector/ofileselectoritem.h b/libopie/ofileselector/ofileselectoritem.h index 21460c4..81966ae 100644 --- a/libopie/ofileselector/ofileselectoritem.h +++ b/libopie/ofileselector/ofileselectoritem.h @@ -1,30 +1,35 @@ #ifndef OPIE_FILE_SELECTOR_ITEM_H #define OPIE_FILE_SELECTOR_ITEM_H #include <qlistview.h> class OFileSelectorItem : public QListViewItem { public: OFileSelectorItem( QListView* view, const QPixmap&, const QString& path, const QString& date, const QString& size, const QString& dir, bool isLocked, + const QString& extra, bool isDir = false); ~OFileSelectorItem(); bool isLocked() const; QString directory()const; bool isDir()const; QString path()const; QString key(int id, bool ); + QString extra()const; private: bool m_locked : 1; bool m_dir : 1; QString m_dirStr; + QString m_extra; + class Private; + Private* d; }; #endif diff --git a/libopie/ofileselector/ofileview.cpp b/libopie/ofileselector/ofileview.cpp index 38f722c..72d2f60 100644 --- a/libopie/ofileselector/ofileview.cpp +++ b/libopie/ofileselector/ofileview.cpp @@ -1,36 +1,30 @@ #include <qlineedit.h> #include <qpe/applnk.h> #include "ofileselector.h" #include "ofileview.h" OFileView::OFileView( OFileSelector* sel) : m_sel( sel ) { } OFileView::~OFileView() { } -void OFileView::fileSelected( const QString& s ) { - m_sel->internFileSelected( s ); -} -void OFileView::fileSelected( const DocLnk& s) { - m_sel->internFileSelected( s ); +void OFileView::fileSelected( const QString& dir,const QString& file,const QString& extra ) { + m_sel->currentLister()->fileSelected( dir,file,extra ); } void OFileView::contextMenu() { m_sel->internContextMenu(); } -void OFileView::changedDir( const QString& s) { - m_sel->internChangedDir( s ); -} -void OFileView::changedDir( const QDir& d ) { - m_sel->internChangedDir( d ); +void OFileView::changedDir( const QString& s, const QString& file, const QString& extra) { + m_sel->currentLister()->changedDir( s, file,extra ); } OFileSelector* OFileView::selector() const { return m_sel; } void OFileView::updateLine( const QString& str ) { if (m_sel->m_shLne ) m_sel->m_edit->setText( str ); } diff --git a/libopie/ofileselector/ofileview.h b/libopie/ofileselector/ofileview.h index d7ea4a2..808587f 100644 --- a/libopie/ofileselector/ofileview.h +++ b/libopie/ofileselector/ofileview.h @@ -1,121 +1,140 @@ /* =. This file is part of the OPIE Project .=l. Copyright (c) 2002 zecke <zecke@handhelds.org> .>+-= _;:, .> :=|. This library is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU Library General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. This library is distributed in the hope that + . -:. = it will be useful, but WITHOUT ANY WARRANTY; : .. .:, . . . without even the implied warranty of =_ + =;=|` MERCHANTABILITY or FITNESS FOR A _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU ..}^=.= = ; Library General Public License for more ++= -. .` .: details. : = ...= . :.=- -. .:....=;==+<; You should have received a copy of the GNU -_. . . )=. = Library General Public License along with -- :-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef ofileview_h #define ofileview_h #include <qobject.h> #include <qwidget.h> #include <qpopupmenu.h> class QFileInfo; class QDir; class DocLnk; /** * A OFileView is a specialised View for the * OFileSelector * With a View you can chage the user visible * representation of a OFileLister * OFileView is just a basic interface which helps you to * write new views */ class OFileSelector; class OFileView { public: OFileView( OFileSelector* ); OFileView(); virtual ~OFileView(); virtual void clear() = 0; virtual void addFile(const QPixmap&, const QString &mine, QFileInfo *info, + const QString& extra = QString::null, bool isSymlink = FALSE ) = 0; virtual void addFile(const QPixmap&, const QString& mine, const QString& dir, - const QString& file, bool = FALSE ) = 0; + const QString& file, + const QString& extra = QString::null, + bool = FALSE ) = 0; virtual void addDir (const QPixmap&, const QString &mine, QFileInfo *info, + const QString& extra = QString::null, bool isSymlink = FALSE ) = 0; virtual void addDir (const QPixmap&, const QString& mine, const QString& dir, - const QString& file, bool = FALSE) = 0; + const QString& file, + const QString& extra = QString::null, + bool = FALSE) = 0; virtual void addSymlink(const QPixmap&, const QString &mime, QFileInfo *info, + const QString& extra = QString::null, bool isSymlink = FALSE ) = 0; virtual void addSymlink(const QPixmap&, const QString& mine, const QString& path, const QString& file, + const QString& extra = QString::null, bool isSymlink = FALSE ) = 0; virtual void cd(const QString &path ) = 0; virtual QWidget* widget() = 0; virtual QString selectedName()const = 0; virtual QStringList selectedNames()const = 0; virtual QString selectedPath()const = 0; virtual QStringList selectedPaths()const = 0; virtual int fileCount() = 0; virtual void sort() =0; /*signals:*/ protected: - void fileSelected(const QString &); - void fileSelected(const DocLnk & ); + /** + * @param dir The dir name + * @param file The file name + * @param extra The extra information + */ + void fileSelected(const QString &dir, const QString& file, const QString& extra = QString::nulll); void contextMenu(); - void changedDir(const QString &); + + /** + * + * @param dir The dir name + * @param file The file name + * @param extra The extra informations + */ + void changedDir(const QString &dir, const QString& file, const QString& extra = QString::null); void changedDir(const QDir & ); /* updates the file name line of the FileSelector */ void updateLine( const QString& ); OFileSelector* selector()const; private: OFileSelector* m_sel; }; class OFileViewFactory { public: OFileViewFactory() {} ; virtual ~OFileViewFactory() = 0; OFileView* newView(QWidget *parent, const char *name ); QString name()const; }; #endif diff --git a/libopie/ofileselector/olister.cpp b/libopie/ofileselector/olister.cpp index b6b03cd..378c69d 100644 --- a/libopie/ofileselector/olister.cpp +++ b/libopie/ofileselector/olister.cpp @@ -1,106 +1,162 @@ +#include <qcombobox.h> + #include "olister.h" #include "ofileview.h" #include "opixmapprovider.h" #include "ofileselector.h" OLister::OLister( OFileSelector* view) - : m_view( view ) + : m_view( view ), m_acc( 0l ) { m_prov = new OPixmapProvider( view ); } OLister::~OLister() { delete m_prov; } void OLister::setPixmapProvider( OPixmapProvider* prov ) { delete m_prov; m_prov = prov; } bool OLister::showFiles()const { return m_view->showFiles(); } bool OLister::showDirs()const { return m_view->showDirs(); } void OLister::addFile( const QString& mine, QFileInfo* info, + const QString& extra, bool isSymlink ) { int t = isSymlink ? OPixmapProvider::File | OPixmapProvider::Symlink : OPixmapProvider::File; QPixmap pix = provider()->pixmap(t, mine, info); view()->currentView()->addFile( pix, mine, info, + extra, isSymlink ); } void OLister::addFile( const QString& mine, const QString& path, const QString& file, + const QString& extra, bool isSymlink ) { int t = isSymlink ? OPixmapProvider::File | OPixmapProvider::Symlink : OPixmapProvider::File; QPixmap pix = provider()->pixmap(t, mine, path, file ); view()->currentView()->addFile( pix, mine, path, file, + extra, isSymlink ); } void OLister::addDir( const QString& mine, QFileInfo* info, + const QString& extra, bool isSymlink ) { int t = isSymlink ? OPixmapProvider::Dir | OPixmapProvider::Symlink : OPixmapProvider::Dir; QPixmap pix = provider()->pixmap(t, mine, info ); view()->currentView()->addDir( pix, mine, info, + extra, isSymlink ); } void OLister::addDir( const QString& mine, const QString& path, const QString& dir, + const QString& extra, bool isSymlink ) { int t = isSymlink ? OPixmapProvider::Dir | OPixmapProvider::Symlink : OPixmapProvider::Dir; QPixmap pix = provider()->pixmap(t, mine, path, dir ); view()->currentView()->addDir( pix, mine, path, dir, + extra, isSymlink ); } void OLister::addSymlink( const QString& mine, QFileInfo* info, + const QString& extra, bool isSymlink ) { QPixmap pix = provider()->pixmap( OPixmapProvider::Symlink, mine, info ); view()->currentView()->addSymlink( pix, mine, info, + extra, isSymlink ); } void OLister::addSymlink( const QString& mine, const QString& path, const QString& name, + const QString& extra, bool isSymlink ) { QPixmap pix = provider()->pixmap( OPixmapProvider::Symlink, mine, path, name ); view()->currentView()->addSymlink( pix, mine, path, name, + extra, isSymlink ); } OFileSelector* OLister::view() { return m_view; } OPixmapProvider* OLister::provider() { return m_prov; } bool OLister::compliesMime( const QString& mime ) { return view()->compliesMime( mime ); } +OListerCmbAccess* OLister::comboBox() { + if (!m_acc ) + m_acc = new OListerCmbAccess( view()->m_location ); + + return m_acc; +} + + +OListerCmbAccess::OListerCmbAccess(QComboBox* box ) + : m_cmb( cmb ) +{} +OListerCmbAccess::~OListerCmbAccess() { +} +void OListerCmbAccess::clear() { + if ( m_cmb ) + m_cmb->clear(); +} +void OListerCmbAccess::setCurrentItem( const QString& add, bool FORCE_ADD) { + if ( !m_cmb ) return; + + + int c = m_cmb->count(); + for ( int i = 0; i < m_cmb->count(); i++ ) { + if ( m_cmb->text(i) == add ) { + bo->setCurrentItem( i ); + return; + } + } + m_cmb->insertItem(add ); + m_cmb->setCurrentItem( c ); +} +void OListerCmbAccess::insert( const QString& str ) { + if ( m_cmb ) + m_cmb->insertItem( str ); +} +QString OListerCmbAccess::currentText()const { + QString str; + if (m_cmb ) + str = m_cmb->currentText(); + + return str; +} diff --git a/libopie/ofileselector/olister.h b/libopie/ofileselector/olister.h index 0885525..79d5409 100644 --- a/libopie/ofileselector/olister.h +++ b/libopie/ofileselector/olister.h @@ -1,64 +1,125 @@ #ifndef OPIE_FILE_LISTER_H #define OPIE_FILE_LISTER_H #include <qfileinfo.h> #include <qmap.h> #include <qstring.h> #include <qstringlist.h> +class QComboBox; class OPixmapProvider; class OFileSelector; + +class OListerCmbAccess; /** * lister is something like KIO but very * very basic and currently only for * populating our views. * This is a base class which needs to be implemented. * @see OLocalLister for a filesystem based implementation */ + class OLister { public: OLister( OFileSelector* ); virtual ~OLister(); virtual void reparse(const QString& path) = 0; /** * return a list of available mimetypes */ virtual QMap<QString, QStringList> mimeTypes( const QString& dir ) = 0; void setPixmapProvider( OPixmapProvider* ); + + /* some way a slot */ + void fileSelected( const QString& dir, const QString& file, const QString& extra ) = 0; + void changeDir( const QString& dir, const QString& file, const QString& extra ) = 0; protected: + /** + * I hate too big classes + * this is a way to group + * access to a ComboBox + * which might exist or + * not in a secure way + */ + OListerCmbAccess* comboBox(); + bool showFiles()const; bool showDirs()const; bool compliesMime( const QString& mime ); void addFile( const QString& mine, QFileInfo*, + const QString& extra = QString::null, bool isSymlink = FALSE ); + void addFile( const QString& mine, const QString& path, const QString& file, + const QString& extra = QString::null, bool isSymlink = FALSE ); void addDir( const QString& mine, QFileInfo*, bool isSymlink = FALSE ); void addDir( const QString& mine, const QString& path, const QString& dir, + const QString& extra = QString::null, bool isSymlink = FALSE ); void addSymlink( const QString& mine, QFileInfo* info, + const QString& extra = QString::null, bool isSymlink = FALSE); void addSymlink( const QString& mine, const QString& path, const QString& name, + const QString& extra = QString::null, bool isSymlink = FALSE ); OFileSelector* view(); OPixmapProvider* provider(); private: OFileSelector* m_view; OPixmapProvider* m_prov; + OListerCmbAccess* m_acc; + + class Private; + Private *d; +}; + +class OListerCmbAccess { + friend class OLister; +public: + OListerCmbAccess( QComboBox* = 0l); + ~OListerCmbAccess(); + + /** + * clears the combobox + */ + void clear(); + + /** + * set's @param add to be the current Item + * if the item is not present it'll be removed + */ + void setCurrentItem( const QString& add, bool FORECE_ADD = TRUE ); + + /** + * inserts the the String at + * a non predictable position... The position is determined + * by the QComboBox code + */ + void insert( const QString& ); + + /** + * + */ + QString currentText()const; +private: + class Private; + Private* d; + QComboBox* m_cmb; }; #endif diff --git a/libopie/ofileselector/olocallister.cpp b/libopie/ofileselector/olocallister.cpp index 6ffcf1e..2306b14 100644 --- a/libopie/ofileselector/olocallister.cpp +++ b/libopie/ofileselector/olocallister.cpp @@ -1,118 +1,119 @@ #include <qdir.h> #include <qfileinfo.h> #include <qmap.h> #include <qpe/mimetype.h> #include "ofileselector.h" #include "olocallister.h" OLocalLister::OLocalLister( OFileSelector* file ) : OLister( file ) { } OLocalLister::~OLocalLister() { } QMap<QString, QStringList> OLocalLister::mimeTypes( const QString& curDir ) { QMap<QString, QStringList> mimes; // let's find possible mimetypes QDir dir( curDir ); dir.setFilter( QDir::Files | QDir::Readable ); dir.setSorting( QDir::Size ); const QFileInfoList *list = dir.entryInfoList(); QFileInfoListIterator it( *list ); QFileInfo *fi; while( (fi=it.current() ) ) { /* skip .desktop */ if( fi->extension() == QString::fromLatin1("desktop") ){ ++it; continue; } MimeType type( fi->absFilePath() ); if( !mimes.contains( type.id() ) ){ mimes.insert( type.id(), type.id() ); } ++it; } return mimes; } -/* FIXME mimecheck +/** + * FIXME mimecheck * use mime check for that * filter dirs * filter filters * filter files * filter mimetypes */ void OLocalLister::reparse( const QString& path ) { QString currentMimeType; QDir dir( path ); dir.setSorting( view()->sorting() ); dir.setFilter( view()->filter() ); const QFileInfoList *list = dir.entryInfoList(); QFileInfoListIterator it( *list ); QFileInfo *fi; while( (fi=it.current() ) ){ if( fi->fileName() == QString::fromLatin1("..") || fi->fileName() == QString::fromLatin1(".") ){ ++it; continue; } if( fi->isSymLink() ){ QString file = fi->dirPath( true ) + "/" + fi->readLink(); /* * 5 tries to prevent dos attack */ for( int i = 0; i<=4; i++) { QFileInfo info( file ); if( !info.exists() ){ addSymlink( currentMimeType, fi, TRUE ); break; }else if( info.isDir() ){ if (!showDirs() ) break; addDir( currentMimeType, fi, TRUE ); break; }else if( info.isFile() ){ /* if not show files skip it */ if (!showFiles() ) break; /* check if we comply to the mimetype */ MimeType type( info.absFilePath() ); if (compliesMime( type.id() ) ) addFile( currentMimeType, fi, TRUE ); break; }else if( info.isSymLink() ){ file = info.dirPath(true ) + "/" + info.readLink() ; break; }else if( i == 4){ addSymlink( currentMimeType, fi ); } } }else if( fi->isDir() ){ if (showDirs() ) addDir( currentMimeType, fi ); }else if( fi->isFile() ){ if ( showFiles() ) addFile( currentMimeType, fi ); } ++it; } // of while loop } |