author | zecke <zecke> | 2004-02-07 09:58:31 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-02-07 09:58:31 (UTC) |
commit | a41eba9e8404fb6321097e86736e23fbce4ead7a (patch) (side-by-side diff) | |
tree | bae6341fa67fdbccaf21e470fa8bb5f13a9460af | |
parent | d4a72f6f428cb764330f07e9499ef9a4795b8228 (diff) | |
download | opie-a41eba9e8404fb6321097e86736e23fbce4ead7a.zip opie-a41eba9e8404fb6321097e86736e23fbce4ead7a.tar.gz opie-a41eba9e8404fb6321097e86736e23fbce4ead7a.tar.bz2 |
Forward port the recent API docu of the FileSelector
-rw-r--r-- | libopie2/opieui/fileselector/ofileselector.cpp | 72 | ||||
-rw-r--r-- | libopie2/opieui/fileselector/ofileselector.h | 60 |
2 files changed, 131 insertions, 1 deletions
diff --git a/libopie2/opieui/fileselector/ofileselector.cpp b/libopie2/opieui/fileselector/ofileselector.cpp index 71d765c..600daff 100644 --- a/libopie2/opieui/fileselector/ofileselector.cpp +++ b/libopie2/opieui/fileselector/ofileselector.cpp @@ -766,137 +766,170 @@ QString OFileViewFileSystem::selectedName()const QString OFileViewFileSystem::selectedPath()const { return QString::null; } QString OFileViewFileSystem::directory()const { if (!m_view) return QString::null; OFileSelectorItem* item = m_view->currentItem(); if (!item ) return QString::null; return QDir(item->directory() ).absPath(); } 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") ); } /* 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> + * + * + * @param parent the parent of this widget + * @param mode The mode from the enum Mode (Open,Save,FILESELECTOR) + * @param sel The selector to be used + * @param dirName The name of the dir to start int + * @param fileName The fileName placed in the fileselector lineedit + * @param mimetypes The MimeType map of used mimetypes + * @param showNew Show a New Button. Most likely to be used in the FileSelector view. + * @param showClose Show a Close Button. Most likely to be used in FileSelector view. + * + */ 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: str = QObject::tr("Documents"); m_cmbView->setCurrentItem( 0 ); break; case Extended: str = QObject::tr("Files"); m_cmbView->setCurrentItem( 1 ); break; case ExtendedAll: 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; initUI(); initMime(); initViews(); m_cmbView->setCurrentItem( 0 ); slotViewChange( QObject::tr("Documents") ); } /* * INIT UI will set up the basic GUI * Layout: Simple VBoxLayout * On top a WidgetStack containing the Views... * - List View * - Document View * Below we will have a Label + LineEdit * Below we will have two ComoBoxes one for choosing the view one for * choosing the mimetype */ void OFileSelector::initUI() { QVBoxLayout* lay = new QVBoxLayout( this ); m_stack = new QWidgetStack( this ); lay->addWidget( m_stack, 1000 ); m_nameBox = new QHBox( this ); (void)new QLabel( tr("Name:"), m_nameBox ); m_lneEdit = new QLineEdit( m_nameBox ); m_lneEdit ->installEventFilter(this); lay->addWidget( m_nameBox ); m_cmbBox = new QHBox( this ); m_cmbView = new QComboBox( m_cmbBox ); m_cmbMime = new QComboBox( m_cmbBox ); @@ -913,161 +946,200 @@ bool OFileSelector::eventFilter (QObject *o, QEvent *e) { QKeyEvent *k = (QKeyEvent *)e; if ( (k->key()==Key_Enter) || (k->key()==Key_Return)) { emit ok(); return true; } } return false; } /* * 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() { 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 ); m_views.insert( QObject::tr("Files"), in ); m_views.insert( QObject::tr("All Files"), in ); } +/** + * d'tor + */ OFileSelector::~OFileSelector() { } + + +/** + * Convience function for the fileselector + * make sure to delete the DocLnk + * + * @see DocLnk + * @todo remove in ODP + */ const DocLnk* OFileSelector::selected() { DocLnk* lnk = new DocLnk( currentView()->selectedDocument() ); return lnk; } +/** + * + * @return the name of the selected file + */ QString OFileSelector::selectedName()const { return currentView()->selectedName(); } + +/** + * @return the selected path + */ QString OFileSelector::selectedPath()const { return currentView()->selectedPath(); } +/** + * @return the directory name + */ QString OFileSelector::directory()const { return currentView()->directory(); } +/** + * @return a DocLnk for the selected document + */ DocLnk OFileSelector::selectedDocument()const { return currentView()->selectedDocument(); } +/** + * @return the number of items for the current view + */ int OFileSelector::fileCount()const { return currentView()->fileCount(); } +/** + * @return reparse the file content + */ void OFileSelector::reread() { return currentView()->reread(); } OFileViewInterface* OFileSelector::currentView()const { return m_current; } bool OFileSelector::showNew()const { return m_shNew; } bool OFileSelector::showClose()const { return m_shClose; } MimeTypes OFileSelector::mimeTypes()const { return m_mimeType; } +/** + * @return the Mode of the OFileSelector + */ int OFileSelector::mode()const { return m_mode; } + +/** + * @return the Selector of the OFileSelector + */ int OFileSelector::selector()const { return m_selector; } QStringList OFileSelector::currentMimeType()const { return m_mimeType[m_cmbMime->currentText()]; } void OFileSelector::slotMimeTypeChanged() { reread(); } void OFileSelector::slotDocLnkBridge( const DocLnk& lnk) { m_lneEdit->setText( lnk.name() ); emit fileSelected( lnk ); emit fileSelected( lnk.name() ); } void OFileSelector::slotFileBridge( const QString& str) { DocLnk lnk( str ); emit fileSelected( lnk ); } void OFileSelector::slotViewChange( const QString& view ) { OFileViewInterface* interface = m_views[view]; if (!interface) return; interface->activate( view ); if (m_current) m_stack->removeWidget( m_current->widget( m_stack ) ); static int id = 1; m_stack->addWidget( interface->widget(m_stack), id ); m_stack->raiseWidget( id ); interface->reread(); m_current = interface; id++; } diff --git a/libopie2/opieui/fileselector/ofileselector.h b/libopie2/opieui/fileselector/ofileselector.h index 7abe8b7..7fa657b 100644 --- a/libopie2/opieui/fileselector/ofileselector.h +++ b/libopie2/opieui/fileselector/ofileselector.h @@ -13,143 +13,201 @@ + . -:. = 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. */ /* This is based on code and ideas of L. J. Potter ljp@llornkcor.com Thanks a lot */ #ifndef OFILESELECTOR_H #define OFILESELECTOR_H /* OPIE */ #include <qpe/applnk.h> /* QT */ #include <qlist.h> #include <qwidget.h> #include <qmap.h> #include <qvaluelist.h> #include <qstringlist.h> class QLineEdit; class QComboBox; class QWidgetStack; class QHBox; typedef QMap<QString, QStringList> MimeTypes; namespace Opie { class OFileViewInterface; class OFileViewFileListView; + +/** + * @short a dropin replacement for the FileSelector + * + * This class is first used insert the OFileDialog. + * It supports multiple view and mimetype filtering for now. + * + * @see OFileDialog + * @see FileSelector + * @author zecke + * @version 0.1 + */ class OFileSelector : public QWidget { Q_OBJECT friend class Opie::OFileViewInterface; friend class Opie::OFileViewFileListView; public: + /** + * The Mode of the Fileselector + * Open = Open A File + * Save = Save a File + * FILESELECTOR = As A GUI in a screen to select a file + */ enum Mode { Open=1, Save=2, FileSelector=4, OPEN=1, SAVE=2, FILESELECTOR=4 }; // enum OldMode { OPEN=1, SAVE=2, FILESELECTOR = 4 }; + /** + * Normal = The old FileSelector + * Extended = Dir View + * ExtendedAll = Dir View with all hidden files + * Default = What the vendor considers best + */ enum Selector { Normal = 0, Extended=1, ExtendedAll =2, Default=3, NORMAL=0,EXTENDED=1, EXTENDED_ALL =2, DEFAULT=3 }; // enum OldSelector { NORMAL = 0, EXTENDED =1, EXTENDED_ALL = 2}; OFileSelector(QWidget* parent, int mode, int selector, const QString& dirName, const QString& fileName, const MimeTypes& mimetypes = MimeTypes(), bool newVisible = FALSE, bool closeVisible = FALSE ); OFileSelector(const QString& mimeFilter, QWidget* parent, const char* name = 0, bool newVisible = TRUE, bool closeVisible = FALSE ); ~OFileSelector(); const DocLnk* selected(); QString selectedName()const; QString selectedPath()const; QString directory()const; DocLnk selectedDocument()const; int fileCount()const; void reread(); int mode()const; int selector()const; - + /** + * Set the Icon visible + * @param b Show or Hide the New Button + */ void setNewVisible( bool b ); + + /** + * Set the Icon visible + */ void setCloseVisible( bool b ); + + /** + * Set the Name Line visible + */ void setNameVisible( bool b ); signals: + /** + * dirSelected is emitted whenever changed into a different dir + */ void dirSelected( const QString& ); + + /** + * fileSelected is emitted when a file is selected + * it uses a DocLnk as parameter + */ void fileSelected( const DocLnk& ); + + /** + * fileSelected is emitted when a file is selected + * the complete path is a parameter + */ void fileSelected( const QString& ); + + /** + * Create a new File with a DocLnk + */ void newSelected( const DocLnk& ); + void closeMe(); + + /** + * Ok is emitted on a Qt::Key_Return or Q::Key_Enter + * in the line edit + */ void ok(); void cancel(); /* used by the ViewInterface */ private: bool showNew()const; bool showClose()const; MimeTypes mimeTypes()const; QStringList currentMimeType()const; private: /* inits the Widgets */ void initUI(); /* inits the MimeType ComboBox content + connects signals and slots */ void initMime(); /* init the Views :) */ void initViews(); private: QLineEdit* m_lneEdit; // the LineEdit for the Name QComboBox *m_cmbView, *m_cmbMime; // two ComboBoxes to select the View and MimeType QWidgetStack* m_stack; // our widget stack which will contain the views OFileViewInterface* currentView() const; // returns the currentView OFileViewInterface* m_current; // here is the view saved bool m_shNew : 1; // should we show New? bool m_shClose : 1; // should we show Close? MimeTypes m_mimeType; // list of mimetypes QMap<QString, OFileViewInterface*> m_views; // QString translated view name + ViewInterface Ptr QHBox* m_nameBox; // the LineEdit + Label is hold here QHBox* m_cmbBox; // this holds the two combo boxes QString m_startDir; int m_mode; int m_selector; struct Data; // used for future versions Data *d; private slots: void slotMimeTypeChanged(); /* will set the text of the lineedit and emit a fileChanged signal */ void slotDocLnkBridge( const DocLnk& ); void slotFileBridge( const QString& ); void slotViewChange( const QString& ); bool eventFilter (QObject *o, QEvent *e); |