-rw-r--r-- | libopie/ofileselector/odefaultfactories.cpp | 15 | ||||
-rw-r--r-- | libopie/ofileselector/odefaultfactories.h | 14 | ||||
-rw-r--r-- | libopie/ofileselector/ofileselector.cpp | 34 | ||||
-rw-r--r-- | libopie/ofileselector/ofileselector.h | 4 |
4 files changed, 50 insertions, 17 deletions
diff --git a/libopie/ofileselector/odefaultfactories.cpp b/libopie/ofileselector/odefaultfactories.cpp new file mode 100644 index 0000000..c41fbca --- a/dev/null +++ b/libopie/ofileselector/odefaultfactories.cpp @@ -0,0 +1,15 @@ +#include "ofilelistview.h" +#include "olocallister.h" + +#include "odefaultfactories.h" + +extern "C" { + + OFileView* newFileListView( OFileSelector* sel, QWidget* par ) { + return new OFileListView(par, sel ); + } + OLister* newLocalLister( OFileSelector* sel) { + return new OLocalLister( sel ); + } + +}; diff --git a/libopie/ofileselector/odefaultfactories.h b/libopie/ofileselector/odefaultfactories.h new file mode 100644 index 0000000..eb698d3 --- a/dev/null +++ b/libopie/ofileselector/odefaultfactories.h @@ -0,0 +1,14 @@ +#ifndef OPIE_DEFAULT_FACTORIES_H +#define OPIE_DEFAULT_FACTORIES_H + +#include "ofilefactory.h" + +extern "C" { + + OFileView* newFileListView( OFileSelector*, QWidget* parent ); + OLister* newLocalLister(OFileSelector* ); + +}; + + +#endif diff --git a/libopie/ofileselector/ofileselector.cpp b/libopie/ofileselector/ofileselector.cpp index 458d432..91a510f 100644 --- a/libopie/ofileselector/ofileselector.cpp +++ b/libopie/ofileselector/ofileselector.cpp @@ -1,84 +1,85 @@ #include <qcheckbox.h> #include <qcombobox.h> #include <qheader.h> #include <qlabel.h> #include <qabstractlayout.h> #include <qlayout.h> #include <qlineedit.h> #include <qlistview.h> #include <qmessagebox.h> #include <qpainter.h> #include <qpushbutton.h> #include <qwidgetstack.h> #include <qpopupmenu.h> #include <qdir.h> #include <qfile.h> #include <qfileinfo.h> #include <qtimer.h> #include <qpe/qpeapplication.h> #include <qpe/applnk.h> #include <qpe/global.h> #include <qpe/mimetype.h> #include <qpe/resource.h> #include <qpe/storage.h> #include <unistd.h> #include <stdlib.h> #include <sys/stat.h> #include "ofileview.h" #include "ofileselectormain.h" #include "ofileselector.h" #include "olocallister.h" #include "olister.h" +#include "odefaultfactories.h" QMap<QString,QPixmap> *OFileSelector::m_pixmaps = 0; namespace { /* let's find the index for a specified string */ int indexByString( const QComboBox *box, const QString &str ){ int index= 0; for(int i= 0; i < box->count(); i++ ){ /* found */ 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 QMap<QString,QStringList>& mimeTypes) : QWidget( wid, "OFileSelector") { m_mimetypes = mimeTypes; if (mode == Save ) m_name = fileName; initVars(); m_mode = mode; m_selector = selector; m_currentDir = dirName; init(); } OFileSelector::OFileSelector(const QString &mimeFilter, QWidget *parent, const char *name, bool newVisible, bool closeVisible ) : QWidget( parent, name ) { /* update the mimefilter */ if (!mimeFilter.isEmpty() ) { QStringList list = QStringList::split(";", mimeFilter ); m_mimetypes.insert(mimeFilter, list ); } initVars(); m_currentDir = QPEApplication::documentDir(); @@ -252,273 +253,265 @@ void OFileSelector::setSelector(int mode ) 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(); - } /*else if( m_selector == Extended || m_selector == ExtendedAll ){ - ; - }*/ + } /* 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) { if( sel == tr("Documents" ) ){ initializeOldSelector(); m_selector = Normal; - }else if( sel == tr("Files") ){ - m_selector = Extended; - - // FIXME call the factory - //reparse(); - }else if( sel == tr("All Files") ){ - m_selector = ExtendedAll; -/* see above - reparse(); */ + }else { +; } } 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(); /* initialize the file lister */ initLister(); 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_shChooser ) // the Chooser for the view and Mimetypes initializeChooser(); 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() ) ) @@ -608,100 +601,96 @@ 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 ); //m_boxOk->addWidget( m_cancel ); m_boxOk->setMargin( 5 ); m_boxOk->setSpacing( 10 ); m_lay->addWidget( m_boxOk, 0 ); connect( m_ok, SIGNAL( clicked() ), this, SLOT(slotOk() ) ); connect( m_cancel, SIGNAL( clicked() ), this, SLOT( slotCancel() ) ); } } /* * OK m_mimeCheck is a QComboBox we now want to fill * out that combobox * if automime we need to update the mimetypes */ void OFileSelector::updateMimeCheck() { m_mimeCheck->clear(); if (m_autoMime ) { //m_mimeCheck->insertItem( tr("All") ); updateMimes(); } QMap<QString, QStringList>::Iterator it; for (it = m_mimetypes.begin(); it != m_mimetypes.end(); ++it ) { m_mimeCheck->insertItem( it.key() ); } } void OFileSelector::initializeChooser() { if( m_boxView == 0 ){ m_boxView = new QHBox( this ); m_viewCheck = new QComboBox( m_boxView, "view check"); m_mimeCheck = new QComboBox( m_boxView, "mime check"); m_boxView->setSpacing( 8 ); m_lay->addWidget(m_boxView, 0 ); - m_viewCheck->insertItem( tr("Documents") ); - m_viewCheck->insertItem( tr("Files") ); - m_viewCheck->insertItem( tr("All Files") ); - /* update to custom views */ updateMimeCheck(); connect( m_viewCheck, SIGNAL( activated(const QString & ) ), this, SLOT( slotViewCheck(const QString & ) ) ); connect( m_mimeCheck, SIGNAL( activated(const QString & ) ), this, SLOT( slotMimeCheck( const QString & ) ) ); } } /* generate the buttons for the toolbar */ void OFileSelector::initToolbar() { m_mainView = new OFileSelectorMain( this ); /* now generate the tool bar */ qWarning( "toolbar" ); m_pseudo = new QWidget( m_mainView, "Pseudo Widget" ); m_pseudoLayout = new QVBoxLayout( m_pseudo ); m_boxToolbar = new QHBox( m_pseudo ); m_boxToolbar->setSpacing( 0 ); // tool bar members now m_location = new QComboBox( m_boxToolbar ); m_location->setEditable( TRUE ); m_location->setDuplicatesEnabled( FALSE ); connect( m_location, SIGNAL(activated(const QString& ) ), this, SLOT(slotLocationActivated(const QString& )) ); connect( m_location->lineEdit(), SIGNAL(returnPressed() ) , this, SLOT(locationComboChanged() ) ); // UP Button m_up = new QPushButton( Resource::loadIconSet("up"), QString::null, m_boxToolbar, "cdUpButton" ); m_up->setFixedSize( QSize(20, 20 ) ); connect( m_up, SIGNAL( clicked() ), this, SLOT(cdUP() ) ); m_up->setFlat( TRUE ); // Home Button m_homeButton = new QPushButton(Resource::loadIconSet("home"), QString::null, m_boxToolbar ); m_homeButton->setFixedSize( QSize(20, 20 ) ); connect(m_homeButton, SIGNAL(clicked() ), this, SLOT(slotHome() ) ); m_homeButton->setFlat( TRUE ); // Documents Button m_docButton = new QPushButton( Resource::loadIconSet("DocsIcon"), QString::null, m_boxToolbar, "docsButton" ); @@ -906,119 +895,130 @@ void OFileSelector::reparse() { if( m_selector == Normal ) return; currentView()->clear(); if( m_shChooser) qWarning("reparse %s", m_mimeCheck->currentText().latin1() ); QString currentMimeType; // let's update the mimetype if( m_autoMime ){ m_mimetypes.clear(); // ok we can change mimetype so we need to be able to give a selection if( m_shChooser ) { currentMimeType = m_mimeCheck->currentText(); m_mimeCheck->clear(); // let's find possible mimetypes m_mimetypes = currentLister()->mimeTypes( m_currentDir ); // add them to the chooser updateMimeCheck(); m_mimeCheck->setCurrentItem( indexByString( m_mimeCheck, currentMimeType ) ); currentMimeType = m_mimeCheck->currentText(); } }else { // no autoMime // let the mimetype be set from out side the m_mimeCheck FEATURE if( m_shChooser ) currentMimeType = m_mimeCheck->currentText(); } // now we got our mimetypes we can add the files currentLister()->reparse( m_currentDir ); /* we're done with adding let's sort */ currentView()->sort(); if( m_shTool ){ m_location->insertItem( m_currentDir ); } // reenable painting and updates } +/* + * the factory + */ +void OFileSelector::initFactory() { + m_fileFactory = new OFileFactory(); + m_fileFactory->addLister(tr("Files"), newLocalLister ); + m_fileFactory->addView(tr("List View"), newFileListView ); + /* the factory is just a dummy */ + m_fileFactory->addView(tr("Documents"), newFileListView ); +} + OFileView* OFileSelector::currentView() { return m_fileView; } OFileView* OFileSelector::currentView() const{ return m_fileView; } int OFileSelector::filter() { int filter; if ( m_selector == ExtendedAll ) filter = QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All; else filter = QDir::Files | QDir::Dirs | QDir::All ; return filter; } int OFileSelector::sorting() { int sort; if (m_case ) sort = ( QDir::IgnoreCase | QDir::Name | QDir::DirsFirst | QDir::Reversed ); else sort = ( QDir::Name | QDir::DirsFirst | QDir::Reversed ); return sort; } void OFileSelector::internFileSelected( const QString& s) { emit fileSelected( s ); } void OFileSelector::internFileSelected( const DocLnk& d ) { emit fileSelected( d ); } void OFileSelector::internContextMenu() { emit contextMenu(); } void OFileSelector::internChangedDir( const QString& s) { emit dirSelected( s ); cd(s ); } void OFileSelector::internChangedDir( const QDir& s) { emit dirSelected( s ); } QPixmap OFileSelector::pixmap( const QString& s ) { return (*m_pixmaps)[s]; } OLister* OFileSelector::currentLister()const { return m_lister; } void OFileSelector::initializeOldSelector() { qWarning("initializeOldSelector"); delete m_select; // we need to initialize but keep the selected mimetype /* we default not to show close and new buttons */ QString mime = currentMimeType(); qWarning("MimeType " + mime ); m_select = new FileSelector( mime , m_mainView, "fileselector", FALSE, FALSE); m_select->setCategorySelectVisible( FALSE ); - m_select->setTypeComboVisible( FALSE ); + m_select->setTypeComboVisible( FALSE ); connect(m_select, SIGNAL(fileSelected( const DocLnk & ) ), this, SLOT( slotFileBridgeSelected(const DocLnk & ) ) ); connect(m_select, SIGNAL(closeMe() ), this, SIGNAL(closeMe() ) ); //connect to close me and other signals as well m_mainView->setWidget( m_select ); } diff --git a/libopie/ofileselector/ofileselector.h b/libopie/ofileselector/ofileselector.h index bf9a26b..3e834fb 100644 --- a/libopie/ofileselector/ofileselector.h +++ b/libopie/ofileselector/ofileselector.h @@ -25,96 +25,97 @@ -. .:....=;==+<; 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 opiefileselector_h #define opiefileselector_h #include <qpe/fileselector.h> #include <qdir.h> #include <qwidget.h> #include <qstring.h> #include <qpixmap.h> #include <qstringlist.h> #include <qmap.h> #include <qvaluelist.h> #include <qpe/applnk.h> #include <qlistview.h> /** This is OPIEs FileDialog Widget. You can use it * as a dropin replacement of the fileselector and * or use any of the new features. * This is also a complete FileSave and FileLoad widget * If you look for a Dialog check OFileDialog * */ class DocLnk; class QCheckBox; class QComboBox; class QPushButton; class QGridLayout; class QLineEdit; class QLabel; class QWidgetStack; class QHBoxLayout; class QVBoxLayout; class QPopupMenu; class QFileInfo; class QHBox; class OFileView; class OLister; class OFileSelectorMain; +class OFileFactory; // /* the mimetypes one name and a list of mimetypes */ typedef QMap< QString, QStringList> MimeTypes; /** * FIXME later */ struct OPopupMenuFactory { OPopupMenuFactory() {} }; /** * Opie the default OFileSelector * It features multiple views. */ class OFileSelector : public QWidget { Q_OBJECT /* friends are evil but I don't want to make the * methods public */ friend class OLister; friend class OFileView; public: /** * The mode of the file selector * Either open, save, fileselector or dir browsing mode * */ enum Mode {Open = 1, Save = 2, Fileselector = 4, Dir = 8 }; /** * Selector. Either Normal for the one shipped with * libqpe or Extended. for the Extended * ExtendedAll also shows 'hidden' files */ enum Selector{Normal=0, Extended = 1, ExtendedAll = 2}; /** * This is reserved for futrue views */ enum View { Dirs = 1, Files = 2, Tree = 4, Icon = 8 }; /** * A c'tor which should be used for advanced mode @@ -295,190 +296,193 @@ class OFileSelector : public QWidget { * set the popup factory */ void setPopupFactory( OPopupMenuFactory * ); /** * reparse the current directory and updates * the views + mimetypes */ void reparse(); // re reads the dir /** * return the selected name */ QString selectedName( )const; /** * for multiple selections return multiple * filenames */ QStringList selectedNames()const; /** * return the complete to the file */ QString selectedPath() const; /** * return the completed paths */ QStringList selectedPaths() const; /** * the current directory */ QString directory()const; /** * fileCount */ int fileCount(); DocLnk selectedDocument()const; QValueList<DocLnk> selectedDocuments()const; OFileView* currentView(); OFileView* currentView()const; OLister* currentLister()const; + OFileFactory* factory(); int filter(); int sorting(); QPixmap pixmap( const QString& ); /* our tool bar */ QWidget* toolBar(); signals: void fileSelected( const DocLnk & ); void fileSelected( const QString & ); void dirSelected(const QString &dir ); void dirSelected( const QDir& ); void closeMe(); void ok(); void cancel(); void contextMenu(); private slots: void slotOk(); void slotCancel(); void slotViewCheck(const QString & ); void slotMimeCheck(const QString & ); void slotLocationActivated(const QString & ); void slotInsertLocationPath(const QString &, int); void locationComboChanged(); private: void init(); void updateMimes(); private: + OFileFactory* m_fileFactory; OFileSelectorMain* m_mainView; OLister* m_lister; OFileView* m_fileView; FileSelector* m_select; int m_mode, m_selector; QComboBox *m_location, *m_mimeCheck, *m_viewCheck; QPushButton *m_homeButton, *m_docButton, *m_hideButton, *m_ok, *m_cancel; QPushButton *m_reread, *m_up, *m_new, *m_close; QListView *m_View; QCheckBox *m_checkPerm; QWidget *m_pseudo; QVBoxLayout *m_pseudoLayout; QString m_currentDir; QString m_name; QMap<QString, QStringList> m_mimetypes; QVBoxLayout *m_lay; QGridLayout *m_Oselector; QHBox *m_boxToolbar; QHBox *m_boxOk; QHBox *m_boxName; QHBox *m_boxView; QLineEdit *m_edit; QLabel *m_fnLabel; bool m_shClose : 1; bool m_shNew : 1; bool m_shTool : 1; bool m_shPerm : 1; bool m_shLne : 1; bool m_shChooser : 1; bool m_shYesNo : 1; bool m_boCheckPerm : 1; bool m_autoMime : 1; bool m_case : 1; bool m_dir : 1; bool m_files : 1; bool m_showPopup : 1; bool m_showHidden : 1; void initVars(); void delItems(); void initializeName(); void initializeYes(); void initializeChooser(); void initializePerm(); void initPics(); bool compliesMime(const QString &path, const QString &mime); bool compliesMime(const QString& mime ); /** * Updates the QComboBox with the current mimetypes */ void updateMimeCheck(); void initializeOldSelector(); void initLister(); void initToolbar(); void initLocations(); void initializeView() {}; // FIXME + void initFactory(); /** * Returns the current mimetype */ QString currentMimeType()const; class OFileSelectorPrivate; OFileSelectorPrivate *d; static QMap<QString,QPixmap> *m_pixmaps; private slots: void slotFileSelected(const QString & ); // not really meant to be a slot void slotFileBridgeSelected( const DocLnk & ); // listview above // popup below virtual void slotDelete(); virtual void cdUP(); virtual void slotHome(); virtual void slotDoc(); virtual void slotNavigate( ); /* for OLister */ private: /* for OFileView */ private: void internFileSelected( const QString& ); void internFileSelected( const DocLnk& ); void internContextMenu(); void internChangedDir( const QString& ); void internChangedDir( const QDir& ) ; }; #endif |