author | mickeyl <mickeyl> | 2004-01-15 13:59:58 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2004-01-15 13:59:58 (UTC) |
commit | dde789ef19fa3a3913805e452ac1e3400688e8a0 (patch) (side-by-side diff) | |
tree | a33a0ce31750ad56cfd3362585d4e7b32ca0a456 /libopie2/opieui | |
parent | 3c74c5343a8432c494ace71d94cca354c01ef1d3 (diff) | |
download | opie-dde789ef19fa3a3913805e452ac1e3400688e8a0.zip opie-dde789ef19fa3a3913805e452ac1e3400688e8a0.tar.gz opie-dde789ef19fa3a3913805e452ac1e3400688e8a0.tar.bz2 |
more libopie1 --> libopie2 with namespace cleanups and code layout cleanups
-rw-r--r-- | libopie2/opieui/fileselector/ofiledialog.cpp | 222 | ||||
-rw-r--r-- | libopie2/opieui/fileselector/ofiledialog.h | 109 | ||||
-rw-r--r-- | libopie2/opieui/fileselector/ofileselector.cpp | 1094 | ||||
-rw-r--r-- | libopie2/opieui/fileselector/ofileselector.h | 161 | ||||
-rw-r--r-- | libopie2/opieui/fileselector/ofileselector_p.h | 191 | ||||
-rw-r--r-- | libopie2/opieui/fileselector/ofileview.h | 95 | ||||
-rw-r--r-- | libopie2/opieui/ocheckitem.cpp | 127 | ||||
-rw-r--r-- | libopie2/opieui/ocheckitem.h | 86 | ||||
-rw-r--r-- | libopie2/opieui/oclickablelabel.cpp | 173 | ||||
-rw-r--r-- | libopie2/opieui/oclickablelabel.h | 103 | ||||
-rw-r--r-- | libopie2/opieui/opieui.pro | 18 |
11 files changed, 2375 insertions, 4 deletions
diff --git a/libopie2/opieui/fileselector/ofiledialog.cpp b/libopie2/opieui/fileselector/ofiledialog.cpp new file mode 100644 index 0000000..2a89c5d --- a/dev/null +++ b/libopie2/opieui/fileselector/ofiledialog.cpp @@ -0,0 +1,222 @@ +/* + =. This file is part of the OPIE Project + .=l. Copyright (C) Holger Freyther <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. + +*/ + + +/* OPIE */ +#include <opie2/ofiledialog.h> +#include <qpe/applnk.h> +#include <qpe/config.h> +#include <qpe/qpeapplication.h> + +/* QT */ +#include <qfileinfo.h> +#include <qstring.h> +#include <qapplication.h> +#include <qlayout.h> + +using namespace Opie; + +namespace +{ +/* + * helper functions to load the start dir + * and to save it + * helper to extract the dir out of a file name + */ +/** + * This method will use Config( argv[0] ); + * @param key The group key used + */ +QString lastUsedDir( const QString& key ) +{ + if ( qApp->argc() < 1 ) + return QString::null; + + Config cfg( QFileInfo(qApp->argv()[0]).fileName() ); // appname + cfg.setGroup( key ); + return cfg.readEntry("LastDir", QPEApplication::documentDir() ); +} + +void saveLastDir( const QString& key, const QString& file ) +{ + if ( qApp->argc() < 1 ) + return; + + Config cfg( QFileInfo(qApp->argv()[0]).fileName() ); + cfg.setGroup( key ); + QFileInfo inf( file ); + cfg.writeEntry("LastDir", inf.dirPath( true ) ); +} +}; + +/** + * This constructs a modal dialog + * + * @param caption The caption of the dialog + * @param wid The parent widget + * @param mode The mode of the OFileSelector @see OFileSelector + * @param selector The selector of the OFileSelector + * @param dirName the dir or resource to start from + * @param fileName a proposed or existing filename + * @param mimetypes The mimeTypes + */ +OFileDialog::OFileDialog(const QString &caption, + QWidget *wid, int mode, int selector, + const QString &dirName, + const QString &fileName, + const QMap<QString,QStringList>& mimetypes ) + : QDialog( wid, "OFileDialog", true ) +{ + // QVBoxLayout *lay = new QVBoxLayout(this); + //showMaximized(); + QVBoxLayout *lay = new QVBoxLayout(this ); + file = new OFileSelector(this , mode, selector, + dirName, fileName, + mimetypes ); + lay->addWidget( file ); + + //lay->addWidget( file ); + //showFullScreen(); + setCaption( caption.isEmpty() ? tr("FileDialog") : caption ); + connect(file, SIGNAL(fileSelected(const QString&) ), + this, SLOT(slotFileSelected(const QString&) ) ); + connect(file, SIGNAL(ok() ), + this, SLOT(slotSelectorOk()) ) ; + + connect(file, SIGNAL(dirSelected(const QString&) ), this, SLOT(slotDirSelected(const QString&) ) ); + +#if 0 + connect(file, SIGNAL(dirSelected(const QString &) ), + this, SLOT(slotDirSelected(const QString &) ) ); +#endif +} +/** + * @returns the mimetype of the selected + * currently it return QString::null + */ +QString OFileDialog::mimetype()const +{ + return QString::null; +} + +/** + * @return the fileName + */ +QString OFileDialog::fileName()const +{ + return file->selectedName(); +} + +/** + * return a DocLnk to the current file + */ +DocLnk OFileDialog::selectedDocument()const +{ + return file->selectedDocument(); +} + +/** + * This opens up a filedialog in Open mode + * + * @param selector the Selector Mode + * @param startDir Where to start from + * @param file A proposed filename + * @param mimes A list of MimeTypes + * @param wid the parent + * @param caption of the dialog if QString::null tr("Open") will be used + * @return the fileName or QString::null + */ +QString OFileDialog::getOpenFileName(int selector, + const QString &_startDir, + const QString &file, + const MimeTypes &mimes, + QWidget *wid, + const QString &caption ) +{ + QString ret; + QString startDir = _startDir; + if (startDir.isEmpty() ) + startDir = lastUsedDir( "FileDialog-OPEN" ); + + + OFileDialog dlg( caption.isEmpty() ? tr("Open") : caption, + wid, OFileSelector::Open, selector, startDir, file, mimes); + dlg.showMaximized(); + if( dlg.exec() ) + { + ret = dlg.fileName(); + saveLastDir( "FileDialog-OPEN", ret ); + } + + return ret; +} + +/** + * This opens up a file dialog in save mode + * @see getOpenFileName + */ +QString OFileDialog::getSaveFileName(int selector, + const QString &_startDir, + const QString &file, + const MimeTypes &mimes, + QWidget *wid, + const QString &caption ) +{ + QString ret; + QString startDir = _startDir; + if (startDir.isEmpty() ) + startDir = lastUsedDir( "FileDialog-SAVE" ); + + OFileDialog dlg( caption.isEmpty() ? tr("Save") : caption, + wid, OFileSelector::Save, selector, startDir, file, mimes); + dlg.showMaximized(); + if( dlg.exec() ) + { + ret = dlg.fileName(); + saveLastDir( "FileDialog-SAVE", ret ); + } + + return ret; +} + +void OFileDialog::slotFileSelected(const QString & ) +{ + accept(); +} + +void OFileDialog::slotSelectorOk( ) +{ + accept(); +} + +void OFileDialog::slotDirSelected(const QString &dir ) +{ + setCaption( dir ); + // if mode + //accept(); +} diff --git a/libopie2/opieui/fileselector/ofiledialog.h b/libopie2/opieui/fileselector/ofiledialog.h new file mode 100644 index 0000000..01a599b --- a/dev/null +++ b/libopie2/opieui/fileselector/ofiledialog.h @@ -0,0 +1,109 @@ +/* + =. 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 OFILEDIALOG_H +#define OFILEDIALOG_H + +/* OPIE */ +#include <opie2/ofileselector.h> + +/* QT */ +#include <qdialog.h> + +namespace Opie +{ + +/** + * This class places a OFileSelector inside a QDialog. + * It provides static method for letting a user chose + * a file for either opening or saving. + * Most of the time the c'tor will not be used instead using + * the static member functions is prefered. + * + * <pre> + * QMap<QString, QStringList> mimeTypes; + * QStringList types; + * types << "text[slash]* "; + * mimeTypes.insert( tr("Text"), types ); + * mimeTypes.insert( tr("All"), " * / * " ); // remove the spaces in the 2nd comment + * QString fileName= OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL, + * "foo","bar", mimeTypes); + * </pre> + * + * @short A small QDialog swalloing a FileSelector + * @see QDialog + * @see OFileSelector + * @version 0.1-unfinished + * @author Holger Freyther ( zecke@handhelds.org ) + */ +class OFileDialog : public QDialog +{ + Q_OBJECT +public: + OFileDialog(const QString &caption, + QWidget *, int mode, int selector, + const QString &dirName, + const QString &fileName = QString::null, + const MimeTypes &mimetypes = MimeTypes() ); + QString mimetype() const; + QString fileName() const; + DocLnk selectedDocument()const; + + // static methods + static QString getOpenFileName(int selector, + const QString& startDir = QString::null, + const QString &fileName = QString::null, + const MimeTypes& mime = MimeTypes(), + QWidget *wid = 0, + const QString &caption = QString::null ); + + static QString getSaveFileName(int selector, + const QString& startDir = QString::null, + const QString& fileName = QString::null, + const MimeTypes& mimefilter = MimeTypes(), + QWidget *wid = 0, + const QString &caption = QString::null ); + + //let's OFileSelector catch up first + //static QString getExistingDirectory(const QString& startDir = QString::null, + //QWidget *parent = 0, const QString& caption = QString::null ); + +private: + class OFileDialogPrivate; + OFileDialogPrivate *d; + OFileSelector *file; + +private slots: + void slotFileSelected( const QString & ); + void slotDirSelected(const QString & ); + void slotSelectorOk(); +}; + +}; + +#endif diff --git a/libopie2/opieui/fileselector/ofileselector.cpp b/libopie2/opieui/fileselector/ofileselector.cpp new file mode 100644 index 0000000..71d765c --- a/dev/null +++ b/libopie2/opieui/fileselector/ofileselector.cpp @@ -0,0 +1,1094 @@ +/* + =. This file is part of the OPIE Project + .=l. Copyright (C) 2002,2003 Holger Freyther <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. + +*/ + +/* hacky but we need to get FileSelector::filter */ +#define private public +#include <qpe/fileselector.h> +#undef private + +#include "ofileselector_p.h" + +/* OPIE */ +#include <opie2/ofileselector.h> + +#include <qpe/qpeapplication.h> +#include <qpe/mimetype.h> +#include <qpe/resource.h> +#include <qpe/storage.h> + +/* QT */ +#include <qcombobox.h> +#include <qdir.h> +#include <qhbox.h> +#include <qheader.h> +#include <qlabel.h> +#include <qlayout.h> +#include <qlineedit.h> +#include <qlistview.h> +#include <qpopupmenu.h> +#include <qwidgetstack.h> +#include <qregexp.h> +#include <qobjectlist.h> + +using namespace Opie; + +OFileViewInterface::OFileViewInterface( OFileSelector* selector ) + : m_selector( selector ) +{} + +OFileViewInterface::~OFileViewInterface() +{} + +QString OFileViewInterface::name()const +{ + return m_name; +} + +void OFileViewInterface::setName( const QString& name ) +{ + m_name = name; +} + +OFileSelector* OFileViewInterface::selector()const +{ + return m_selector; +} + +DocLnk OFileViewInterface::selectedDocument()const +{ + return DocLnk( selectedName() ); +} + +bool OFileViewInterface::showNew()const +{ + return selector()->showNew(); +} + +bool OFileViewInterface::showClose()const +{ + return selector()->showClose(); +} + +MimeTypes OFileViewInterface::mimeTypes()const +{ + return selector()->mimeTypes(); +} + +QStringList OFileViewInterface::currentMimeType()const +{ + return selector()->currentMimeType(); +} + +void OFileViewInterface::activate( const QString& ) +{ + // not implemented here +} + +void OFileViewInterface::ok() +{ + emit selector()->ok(); +} + +void OFileViewInterface::cancel() +{ + emit selector()->cancel(); +} + +void OFileViewInterface::closeMe() +{ + emit selector()->closeMe(); +} + +void OFileViewInterface::fileSelected( const QString& str) +{ + emit selector()->fileSelected( str); +} + +void OFileViewInterface::fileSelected( const DocLnk& lnk) +{ + emit selector()->fileSelected( lnk ); +} + +void OFileViewInterface::setCurrentFileName( const QString& str ) +{ + selector()->m_lneEdit->setText( str ); +} + +QString OFileViewInterface::currentFileName()const +{ + return selector()->m_lneEdit->text(); +} + +QString OFileViewInterface::startDirectory()const +{ + return selector()->m_startDir; +} + +ODocumentFileView::ODocumentFileView( OFileSelector* selector ) + :OFileViewInterface( selector ) +{ + m_selector = 0; + setName( QObject::tr("Documents") ); +} + +ODocumentFileView::~ODocumentFileView() +{ +} + +QString ODocumentFileView::selectedName()const +{ + if (!m_selector) + return QString::null; + + return m_selector->selectedDocument().file(); +} + +QString ODocumentFileView::selectedPath()const +{ + return QPEApplication::documentDir(); +} + +QString ODocumentFileView::directory()const +{ + return selectedPath(); +} + +void ODocumentFileView::reread() +{ + if (!m_selector) + return; + + m_selector->setNewVisible( showNew() ); + m_selector->setCloseVisible( showClose() ); + m_selector->filter = currentMimeType().join(";"); + m_selector->reread(); +} + +int ODocumentFileView::fileCount()const +{ + if (!m_selector) + return -1; + + return m_selector->fileCount(); +} + +DocLnk ODocumentFileView::selectedDocument()const +{ + if (!m_selector) + return DocLnk(); + + return m_selector->selectedDocument(); +} + +QWidget* ODocumentFileView::widget( QWidget* parent ) +{ + if (!m_selector ) + { + m_selector = new FileSelector(currentMimeType().join(";"), parent, "fileselector", showNew(), showClose() ); + QObject::connect(m_selector, SIGNAL(fileSelected( const DocLnk& ) ), + selector(), SLOT(slotDocLnkBridge(const DocLnk&) ) ); + QObject::connect(m_selector, SIGNAL(closeMe() ), + selector(), SIGNAL(closeMe() ) ); + QObject::connect(m_selector, SIGNAL(newSelected(const DocLnk& ) ), + selector(), SIGNAL(newSelected(const DocLnk& ) ) ); + } + + return m_selector; +} + +/* + * This is the file system view used + * we use a QListView + QListViewItems for it + */ + +OFileSelectorItem::OFileSelectorItem( QListView* view, const QPixmap& pixmap, + const QString& path, const QString& date, + const QString& size, const QString& dir, + bool isLocked, bool isDir ) + : QListViewItem( view ) +{ + setPixmap(0, pixmap ); + setText(1, path ); + setText(2, size ); + setText(3, date ); + m_isDir = isDir; + m_dir = dir; + m_locked = isLocked; +} + +OFileSelectorItem::~OFileSelectorItem() +{ +} + +bool OFileSelectorItem::isLocked()const +{ + return m_locked; +} + +QString OFileSelectorItem::directory()const +{ + return m_dir; +} + +bool OFileSelectorItem::isDir()const +{ + return m_isDir; +} + +QString OFileSelectorItem::path()const +{ + return text( 1 ); +} + +QString OFileSelectorItem::key( int id, bool )const +{ + QString ke; + if( id == 0 || id == 1 ) + { // name + if( m_isDir ) + { + ke.append("0" ); + ke.append( text(1) ); + } + else + { + ke.append("1" ); + ke.append( text(1) ); + } + return ke; + } + else + return text( id ); + +} + +OFileViewFileListView::OFileViewFileListView( QWidget* parent, const QString& startDir, OFileSelector* sel) + :QWidget( parent ), m_sel( sel ) +{ + m_all = false; + QVBoxLayout* lay = new QVBoxLayout( this ); + m_currentDir = startDir; + + /* + * now we add a special bar + * One Button For Up + * Home + * Doc + * And a dropdown menu with FileSystems + * FUTURE: one to change dir with lineedit + * Bookmarks + * Create Dir + */ + QHBox* box = new QHBox(this ); + box->setBackgroundMode( PaletteButton ); + box->setSpacing( 0 ); + + QToolButton *btn = new QToolButton( box ); + btn->setIconSet( Resource::loadIconSet("up") ); + connect(btn, SIGNAL(clicked() ), + this, SLOT( cdUP() ) ); + + btn = new QToolButton( box ); + btn->setIconSet( Resource::loadIconSet("home") ); + connect(btn, SIGNAL(clicked() ), + this, SLOT( cdHome() ) ); + + btn = new QToolButton( box ); + btn->setIconSet( Resource::loadIconSet("DocsIcon") ); + connect(btn, SIGNAL(clicked() ), + this, SLOT(cdDoc() ) ); + + m_btnNew = new QToolButton( box ); + m_btnNew->setIconSet( Resource::loadIconSet("new") ); + connect(m_btnNew, SIGNAL(clicked() ), + this, SLOT(slotNew() ) ); + + + m_btnClose = new QToolButton( box ); + m_btnClose->setIconSet( Resource::loadIconSet("close") ); + connect(m_btnClose, SIGNAL(clicked() ), + selector(), SIGNAL(closeMe() ) ); + + btn = new QToolButton( box ); + btn->setIconSet( Resource::loadIconSet("cardmon/pcmcia") ); + + /* let's fill device parts */ + QPopupMenu* pop = new QPopupMenu(this); + connect(pop, SIGNAL( activated(int) ), + this, SLOT(slotFSActivated(int) ) ); + + StorageInfo storage; + const QList<FileSystem> &fs = storage.fileSystems(); + QListIterator<FileSystem> it(fs); + for ( ; it.current(); ++it ) + { + const QString disk = (*it)->name(); + const QString path = (*it)->path(); + m_dev.insert( disk, path ); + pop->insertItem( disk ); + } + m_fsPop = pop; + + + btn->setPopup( pop ); + + lay->addWidget( box ); + + m_view = new QListView( this ); + + m_view->installEventFilter(this); + + QPEApplication::setStylusOperation( m_view->viewport(), + QPEApplication::RightOnHold); + m_view->addColumn(" " ); + m_view->addColumn(tr("Name"), 135 ); + m_view->addColumn(tr("Size"), -1 ); + m_view->addColumn(tr("Date"), 60 ); + m_view->addColumn(tr("Mime Type"), -1 ); + + + m_view->setSorting( 1 ); + m_view->setAllColumnsShowFocus( TRUE ); + + lay->addWidget( m_view, 1000 ); + connectSlots(); +} + +OFileViewFileListView::~OFileViewFileListView() +{ +} + +void OFileViewFileListView::slotNew() +{ + DocLnk lnk; + emit selector()->newSelected( lnk ); +} + +OFileSelectorItem* OFileViewFileListView::currentItem()const +{ + QListViewItem* item = m_view->currentItem(); + if (!item ) + return 0l; + + return static_cast<OFileSelectorItem*>(item); +} + +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; + if (m_all ) + filter = QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All; + else + filter = QDir::Files | QDir::Dirs | QDir::All; + 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 + * + */ + if( fi->isSymLink() ) + { + QString file = fi->dirPath( true ) + "/" + fi->readLink(); + for( int i = 0; i<=4; i++) + { // 5 tries to prevent dos + QFileInfo info( file ); + if( !info.exists() ) + { + addSymlink( fi, TRUE ); + break; + } + else if( info.isDir() ) + { + addDir( fi, TRUE ); + break; + } + else if( info.isFile() ) + { + addFile( fi, TRUE ); + break; + } + else if( info.isSymLink() ) + { + file = info.dirPath(true ) + "/" + info.readLink() ; + break; + } + else if( i == 4) + { // couldn't resolve symlink add it as symlink + addSymlink( fi ); + } + } // off for loop for symlink resolving + } + else if( fi->isDir() ) + addDir( fi ); + else if( fi->isFile() ) + addFile( fi ); + + ++it; + } // of while loop + m_view->sort(); + +} +int OFileViewFileListView::fileCount()const +{ + return m_view->childCount(); +} + +QString OFileViewFileListView::currentDir()const +{ + return m_currentDir; +} + +OFileSelector* OFileViewFileListView::selector() +{ + return m_sel; +} + +bool OFileViewFileListView::eventFilter (QObject *o, QEvent *e) +{ + if ( e->type() == QEvent::KeyPress ) + { + QKeyEvent *k = (QKeyEvent *)e; + if ( (k->key()==Key_Enter) || (k->key()==Key_Return)) + { + slotClicked( Qt::LeftButton,m_view->currentItem(),QPoint(0,0),0); + return true; + } + } + return false; +} + +void OFileViewFileListView::connectSlots() +{ + connect(m_view, SIGNAL(clicked(QListViewItem*) ), + this, SLOT(slotCurrentChanged(QListViewItem*) ) ); + connect(m_view, SIGNAL(mouseButtonClicked(int, QListViewItem*, const QPoint&, int ) ), + this, SLOT(slotClicked(int, QListViewItem*, const QPoint&, int ) ) ); +} + +void OFileViewFileListView::slotCurrentChanged( QListViewItem* item) +{ + if (!item) + return; +#if 0 + + OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item); + + if (!sel->isDir() ) + { + selector()->m_lneEdit->setText( sel->text(1) ); + // if in fileselector mode we will emit selected + if ( selector()->mode() == OFileSelector::FileSelector ) + { + qWarning("slot Current Changed"); + QStringList str = QStringList::split("->", sel->text(1) ); + QString path = sel->directory() + "/" + str[0].stripWhiteSpace(); + emit selector()->fileSelected( path ); + DocLnk lnk( path ); + emit selector()->fileSelected( lnk ); + } + } +#endif +} + +void OFileViewFileListView::slotClicked(int button , QListViewItem* item, const QPoint&, int ) +{ + if (!item || ( button != Qt::LeftButton) ) + return; + + OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item); + if (!sel->isLocked() ) + { + QStringList str = QStringList::split("->", sel->text(1) ); + if (sel->isDir() ) + { + m_currentDir = sel->directory() + "/" + str[0].stripWhiteSpace(); + emit selector()->dirSelected( m_currentDir ); + reread( m_all ); + } + else + { // file + qWarning("slot Clicked"); + selector()->m_lneEdit->setText( str[0].stripWhiteSpace() ); + QString path = sel->directory() + "/" + str[0].stripWhiteSpace(); + emit selector()->fileSelected( path ); + DocLnk lnk( path ); + emit selector()->fileSelected( lnk ); + } + } // not locked +} + +void OFileViewFileListView::addFile( QFileInfo* info, bool symlink ) +{ + MimeType type( info->absFilePath() ); + if (!compliesMime( type.id() ) ) + return; + + QPixmap pix = type.pixmap(); + QString dir, name; bool locked; + if ( pix.isNull() ) + { + QWMatrix matrix; + QPixmap pixer(Resource::loadPixmap("UnknownDocument") ); + matrix.scale( .4, .4 ); + pix = pixer.xForm( matrix ); + } + dir = info->dirPath( true ); + locked = false; + if ( symlink ) + 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; pix = Resource::loadPixmap("locked"); + } + } + (void)new OFileSelectorItem( m_view, pix, name, + info->lastModified().toString(), QString::number( info->size() ), + dir, locked ); +} + +void OFileViewFileListView::addDir( QFileInfo* info, bool symlink ) +{ + bool locked = false; QString name; QPixmap pix; + + if ( ( ( selector()->mode() == OFileSelector::Open ) && !info->isReadable() ) || + ( ( selector()->mode() == OFileSelector::Save ) && !info->isWritable() ) ) + { + locked = true; + if ( symlink ) + pix = Resource::loadPixmap( "opie/symlink" ); + else + pix = Resource::loadPixmap( "lockedfolder" ); + } + else + pix = symlink ? Resource::loadPixmap( "opie/symlink") : Resource::loadPixmap("folder"); + + name = symlink ? info->fileName() + " -> " + info->dirPath(true) + "/" + info->readLink() : + info->fileName(); + + (void)new OFileSelectorItem( m_view, pix, name, + info->lastModified().toString(), + QString::number( info->size() ), + info->dirPath( true ), locked, true ); + + +} + +void OFileViewFileListView::addSymlink( QFileInfo* , bool ) +{ +} + +void OFileViewFileListView::cdUP() +{ + QDir dir( m_currentDir ); + dir.cdUp(); + + if (!dir.exists() ) + m_currentDir = "/"; + else + m_currentDir = dir.absPath(); + + emit selector()->dirSelected( m_currentDir ); + reread( m_all ); +} + +void OFileViewFileListView::cdHome() +{ + m_currentDir = QDir::homeDirPath(); + emit selector()->dirSelected( m_currentDir ); + reread( m_all ); +} + +void OFileViewFileListView::cdDoc() +{ + m_currentDir = QPEApplication::documentDir(); + emit selector()->dirSelected( m_currentDir ); + reread( m_all ); +} + +void OFileViewFileListView::changeDir( const QString& dir ) +{ + m_currentDir = dir; + emit selector()->dirSelected( m_currentDir ); + reread( m_all ); +} + +void OFileViewFileListView::slotFSActivated( int id ) +{ + changeDir ( m_dev[m_fsPop->text(id)] ); +} + +/* check if the mimetype in mime + * complies with the one which is current + */ +/* + * We've the mimetype of the file + * We need to get the stringlist of the current mimetype + * + * mime = image@slashjpeg + * QStringList = 'image@slash*' + * or QStringList = image/jpeg;image/png;application/x-ogg + * or QStringList = application/x-ogg;image@slash*; + * with all these mime filters it should get acceptes + * to do so we need to look if mime is contained inside + * the stringlist + * if it's contained return true + * if not ( I'm no RegExp expert at all ) we'll look if a '@slash*' + * is contained in the mimefilter and then we will + * look if both are equal until the '/' + */ + +bool OFileViewFileListView::compliesMime( const QString& str) +{ + if (str.isEmpty() || m_mimes.isEmpty() || str.stripWhiteSpace().isEmpty() ) + return true; + + for (QStringList::Iterator it = m_mimes.begin(); it != m_mimes.end(); ++it ) + { + QRegExp reg( (*it) ); + reg.setWildcard( true ); + if ( str.find( reg ) != -1 ) + return true; + + } + return false; +} +/* + * The listView giving access to the file system! + */ + +class OFileViewFileSystem : public OFileViewInterface +{ +public: + OFileViewFileSystem( OFileSelector* ); + ~OFileViewFileSystem(); + + QString selectedName() const; + QString selectedPath() const; + + QString directory()const; + void reread(); + int fileCount()const; + + QWidget* widget( QWidget* parent ); + void activate( const QString& ); +private: + OFileViewFileListView* m_view; + bool m_all : 1; +}; + +OFileViewFileSystem::OFileViewFileSystem( OFileSelector* sel) + : OFileViewInterface( sel ) +{ + m_view = 0; + m_all = false; +} + +OFileViewFileSystem::~OFileViewFileSystem() +{ +} + +QString OFileViewFileSystem::selectedName()const +{ + if (!m_view ) + return QString::null; + + QString cFN=currentFileName(); + if (cFN.startsWith("/")) return cFN; + return m_view->currentDir() + "/" + cFN; +} + +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 */ +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 ); + +} + +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 ); + lay->addWidget( m_cmbBox ); +} + +/* + * This will make sure that the return key in the name edit causes dialogs to close + */ + +bool OFileSelector::eventFilter (QObject *o, QEvent *e) +{ + if ( e->type() == QEvent::KeyPress ) + { + 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 ); +} + +OFileSelector::~OFileSelector() +{ +} + +const DocLnk* OFileSelector::selected() +{ + DocLnk* lnk = new DocLnk( currentView()->selectedDocument() ); + return lnk; +} + +QString OFileSelector::selectedName()const +{ + return currentView()->selectedName(); +} + +QString OFileSelector::selectedPath()const +{ + return currentView()->selectedPath(); +} + +QString OFileSelector::directory()const +{ + return currentView()->directory(); +} + +DocLnk OFileSelector::selectedDocument()const +{ + return currentView()->selectedDocument(); +} + +int OFileSelector::fileCount()const +{ + return currentView()->fileCount(); +} + +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; +} + +int OFileSelector::mode()const +{ + return m_mode; +} + +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++; +} + +void OFileSelector::setNewVisible( bool b ) +{ + m_shNew = b; + currentView()->reread(); +} + +void OFileSelector::setCloseVisible( bool b ) +{ + m_shClose = b; + currentView()->reread(); +} + +void OFileSelector::setNameVisible( bool b ) +{ + if ( b ) + m_nameBox->show(); + else + m_nameBox->hide(); +} + diff --git a/libopie2/opieui/fileselector/ofileselector.h b/libopie2/opieui/fileselector/ofileselector.h new file mode 100644 index 0000000..7abe8b7 --- a/dev/null +++ b/libopie2/opieui/fileselector/ofileselector.h @@ -0,0 +1,161 @@ +/* + =. This file is part of the OPIE Project + .=l. Copyright (C) 2002,2003 Holger Freyther <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. + +*/ + +/* + 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; + +class OFileSelector : public QWidget +{ + Q_OBJECT + friend class Opie::OFileViewInterface; + friend class Opie::OFileViewFileListView; + +public: + enum Mode { Open=1, Save=2, FileSelector=4, OPEN=1, SAVE=2, FILESELECTOR=4 }; + // enum OldMode { OPEN=1, SAVE=2, FILESELECTOR = 4 }; + 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; + + + void setNewVisible( bool b ); + void setCloseVisible( bool b ); + void setNameVisible( bool b ); + +signals: + void dirSelected( const QString& ); + void fileSelected( const DocLnk& ); + void fileSelected( const QString& ); + void newSelected( const DocLnk& ); + void closeMe(); + 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); + +}; + +}; + +#endif diff --git a/libopie2/opieui/fileselector/ofileselector_p.h b/libopie2/opieui/fileselector/ofileselector_p.h new file mode 100644 index 0000000..818ced9 --- a/dev/null +++ b/libopie2/opieui/fileselector/ofileselector_p.h @@ -0,0 +1,191 @@ +/* + =. This file is part of the OPIE Project + .=l. Copyright (C) Holger Freyther <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 OFILESELECTOR_PRIVATE_H +#define OFILESELECTOR_PRIVATE_H + +/* OPIE */ +#include <qpe/applnk.h> +#include <qpe/fileselector.h> + +/* QT */ +#include <qmap.h> +#include <qstringlist.h> +#include <qwidget.h> +#include <qlistview.h> + +/* + * How to avoid having really two different objects + * for Extended and ExtendedAll + * The only difference is the Lister... + * a) static object? + * b) leave some object inside the OFileSelector which can be used? + * c) when switching views tell which view we want o have.. internally we can switch then + * + * I'll take c) -zecke + */ + +typedef QMap<QString, QStringList> MimeTypes; + +/* the View Interface */ +class QFileInfo; +class QToolButton; + +namespace Opie +{ + +class OFileSelector; + +class OFileViewInterface +{ +public: + OFileViewInterface( OFileSelector* selector ); + virtual ~OFileViewInterface(); + virtual QString selectedName()const = 0; + virtual QString selectedPath()const = 0; + virtual QString directory()const = 0; + virtual void reread() = 0; + virtual int fileCount()const = 0; + virtual DocLnk selectedDocument()const; + virtual QWidget* widget( QWidget* parent) = 0; + virtual void activate( const QString& ); + QString name()const; +protected: + OFileSelector* selector()const; + void setName( const QString& ); + bool showNew()const; + bool showClose()const; + MimeTypes mimeTypes()const; + QStringList currentMimeType()const; + QString startDirectory()const; +protected: + void ok(); + void cancel(); + void closeMe(); + void fileSelected( const QString& ); + void fileSelected( const DocLnk& ); + void setCurrentFileName( const QString& ); + QString currentFileName()const; + +private: + QString m_name; + OFileSelector* m_selector; +}; + + +/* THE Document View hosting a FileSelector*/ +class ODocumentFileView : public OFileViewInterface +{ +public: + ODocumentFileView( OFileSelector* selector ); + ~ODocumentFileView(); + + QString selectedName() const; + QString selectedPath() const; + + QString directory() const; + void reread(); + int fileCount()const; + DocLnk selectedDocument()const; + + QWidget* widget( QWidget* parent ); + +private: + mutable FileSelector* m_selector; + +}; + + +class OFileSelectorItem : public QListViewItem +{ +public: + OFileSelectorItem( QListView* view, const QPixmap& pixmap, + const QString& path, const QString& date, + const QString& size, const QString& mDir, + bool isLocked = false, bool isDir = false ); + ~OFileSelectorItem(); + bool isLocked()const; + bool isDir()const; + QString directory()const; + QString path()const; + QString key(int id, bool )const; + +private: + bool m_locked : 1; + bool m_isDir : 1; + QString m_dir; +}; + +class OFileViewFileListView : public QWidget +{ + Q_OBJECT +public: + OFileViewFileListView( QWidget* parent, const QString& dir, OFileSelector* selector ); + ~OFileViewFileListView(); + + OFileSelectorItem* currentItem()const; + void reread( bool all = false ); + int fileCount()const; + QString currentDir()const; +protected: + bool eventFilter (QObject *o, QEvent *e); +private slots: + void slotNew(); // will emit newSelected + void cdUP(); + void cdHome(); + void cdDoc(); + void changeDir( const QString& ); + void slotCurrentChanged( QListViewItem* ); + void slotClicked(int, QListViewItem*, const QPoint&, int ); + void slotFSActivated(int); + +protected: + OFileSelector* selector(); + +private: + QMap<QString, QString> m_dev; + bool m_all : 1; + OFileSelector* m_sel; + QPopupMenu* m_fsPop; + bool compliesMime( const QString& ); + QStringList m_mimes; // used in compy mime + QString m_currentDir; + QToolButton *m_btnNew, *m_btnClose; + void connectSlots(); + void addFile( QFileInfo* info, bool symlink = FALSE ); + void addDir ( QFileInfo* info, bool symlink = FALSE ); + void addSymlink( QFileInfo* info, bool = FALSE ); + + +private: + QListView* m_view; +}; + +}; + +#endif diff --git a/libopie2/opieui/fileselector/ofileview.h b/libopie2/opieui/fileselector/ofileview.h new file mode 100644 index 0000000..495401b --- a/dev/null +++ b/libopie2/opieui/fileselector/ofileview.h @@ -0,0 +1,95 @@ +/* + =. This file is part of the OPIE Project + .=l. Copyright (C) 2002 Holger Freyther <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 + +/* QT */ +#include <qobject.h> +#include <qwidget.h> + +class QFileInfo; +class QDir; +class DocLnk; + +namespace Opie +{ + +/** + * 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 OFileView : public QWidget +{ + Q_OBJECT +public: + OFileView(QWidget *widget, + const char *name ); + + OFileView(); + + virtual void addFile(const QString &mine, + QFileInfo *info, + bool isSymlink = FALSE ) = 0; + + virtual void addDir (const QString &mine, + QFileInfo *info, + bool isSymlink = FALSE ) = 0; + + virtual void addSymlink(const QString &mime, + QFileInfo *info, + bool isSymlink = FALSE ) = 0; + + virtual void cd(const QString &path ) = 0; +signals: + void fileSelected(const QString &); + void fileSelected(const DocLnk & ); + void contextMenu(); + void changedDir(const QString &); + void changedDir(const QDir & ); +}; + + +class OFileViewFactory +{ + // Q_OBJECT +public: + OFileViewFactory() {} ; + virtual ~OFileViewFactory() = 0; + + OFileView* newView(QWidget *parent, const char *name ); + QString name()const; +}; + +}; + +#endif diff --git a/libopie2/opieui/ocheckitem.cpp b/libopie2/opieui/ocheckitem.cpp new file mode 100644 index 0000000..45f27ee --- a/dev/null +++ b/libopie2/opieui/ocheckitem.cpp @@ -0,0 +1,127 @@ +/* + This file is part of the Opie Project + Copyright (C) Stefan Eilers <eilers.stefan@epost.de> + =. Copyright (C) The Opie Team <opie-devel@handhelds.org> + .=l. + .>+-= + _;:, .> :=|. This program 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 program 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. +*/ + +#include <opie2/ocheckitem.h> + +/* QT */ +#include <qpainter.h> + +using namespace Opie; + +/** + * Constructs an CheckItem with a QTable as parent + * and a sort key for. + * The sort key will be used by QTable to sort the table later + * @param t The parent QTable where the check item belongs + * @param key A sort key + */ +OCheckItem::OCheckItem( QTable *t, const QString &key ) + :QTableItem( t, Never, "" ), m_checked( FALSE ), m_sortKey( key ) +{} + +/** + * reimplemted for internal reasons + * @return Returns the sort key of the Item + * @see QTableItem + */ +QString OCheckItem::key() const +{ + return m_sortKey; +} + +/** + * This method can check or uncheck the item. It will + * call QTable to update the cell. + * + * @param b Whether to check or uncheck the item + */ +void OCheckItem::setChecked( bool b ) +{ + m_checked = b; + table()->updateCell( row(), col() ); +} + +/** + * This will toggle the item. If it is checked it'll get + * unchecked by this method or vice versa. + */ +void OCheckItem::toggle() +{ + m_checked = !m_checked; +} + +/** + * This will return the state of the item. + * + * @return Returns true if the item is checked + */ +bool OCheckItem::isChecked() const +{ + return m_checked; +} + +/** + * @internal + * This paints the item + */ +void OCheckItem::paint( QPainter *p, const QColorGroup &cg, const QRect &cr, bool ) +{ + p->fillRect( 0, 0, cr.width(), cr.height(), cg.brush( QColorGroup::Base ) ); + + int marg = ( cr.width() - BoxSize ) / 2; + int x = 0; + int y = ( cr.height() - BoxSize ) / 2; + p->setPen( QPen( cg.text() ) ); + p->drawRect( x + marg, y, BoxSize, BoxSize ); + p->drawRect( x + marg+1, y+1, BoxSize-2, BoxSize-2 ); + p->setPen( darkGreen ); + x += 1; + y += 1; + if ( m_checked ) + { + QPointArray a( 7*2 ); + int i, xx, yy; + xx = x+1+marg; + yy = y+2; + for ( i=0; i<3; i++ ) + { + a.setPoint( 2*i, xx, yy ); + a.setPoint( 2*i+1, xx, yy+2 ); + xx++; yy++; + } + yy -= 2; + for ( i=3; i<7; i++ ) + { + a.setPoint( 2*i, xx, yy ); + a.setPoint( 2*i+1, xx, yy+2 ); + xx++; yy--; + } + p->drawLineSegments( a ); + } +} diff --git a/libopie2/opieui/ocheckitem.h b/libopie2/opieui/ocheckitem.h new file mode 100644 index 0000000..db2e832 --- a/dev/null +++ b/libopie2/opieui/ocheckitem.h @@ -0,0 +1,86 @@ +/* + This file is part of the Opie Project + Copyright (C) Stefan Eilers <eilers.stefan@epost.de> + =. Copyright (C) The Opie Team <opie-devel@handhelds.org> + .=l. + .>+-= + _;:, .> :=|. This program 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 program 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 OCHECKITEM_H_ +#define OCHECKITEM_H_ + +/* QT */ +#include <qtable.h> + +namespace Opie +{ + +/** + * This class represents a checkable QTableItem. This can + * be added to any QTable. + * + * + * @see QTable + * @see QTableItem + * @short An checkable QTableItem + * @version 1.0 + * @author Stefan Eilers ( eilers@handhelds.org ) + **/ + +class OCheckItem : public QTableItem +{ +public: + /** The size of a box currently unused */ + enum Size { BoxSize = 10 }; + OCheckItem( QTable *t, const QString &sortkey ); + + virtual void setChecked( bool b ); + virtual void toggle(); + bool isChecked() const; + /** + * @short Set the sort key + * @reimp + */ + void setKey( const QString &key ) { m_sortKey = key; } + virtual QString key() const; + + /** + * @short Paint the Checkitem + * @reimp + */ + void paint( QPainter *p, const QColorGroup &cg, const QRect &cr, bool selected ); + + //static const int BoxSize = 10; + +private: + class OCheckItemPrivate; + OCheckItemPrivate *d; + bool m_checked : 1; + QString m_sortKey; + +}; + +}; + +#endif diff --git a/libopie2/opieui/oclickablelabel.cpp b/libopie2/opieui/oclickablelabel.cpp new file mode 100644 index 0000000..4c4e581 --- a/dev/null +++ b/libopie2/opieui/oclickablelabel.cpp @@ -0,0 +1,173 @@ +/* + This file is part of the Opie Project + Copyright (C) Maximillian Reiß <harlekin@handhelds.org> + =. Copyright (C) The Opie Team <opie-devel@handhelds.org> + .=l. + .>+-= + _;:, .> :=|. This program 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 program 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. +*/ + +#include <opie2/oclickablelabel.h> + +using namespace Opie; + +/** + * This constructs the clickable ButtonLabel + * + * @param parent The parent of this label + * @param name A name of this label @see QObject + * @param fl The windowing flags + */ +OClickableLabel::OClickableLabel(QWidget* parent, const char* name, WFlags fl) + :QLabel(parent,name,fl) +{ + textInverted=false; + isToggle=false; + isDown=false; + showState(false); + setFrameShadow(Sunken); +} + +/** + * This method makes the label behave as a toggle button + * + * @param t Whether or not to behave like a toggle button + */ +void OClickableLabel::setToggleButton(bool t) +{ + isToggle=t; +} + +/** + * @internal + */ +void OClickableLabel::mousePressEvent( QMouseEvent * /*e*/ ) +{ + if (isToggle && isDown) + { + showState(false); + } + else + { + showState(true); + } +} + +/** + * @internal + */ +void OClickableLabel::mouseReleaseEvent( QMouseEvent *e ) +{ + if (rect().contains(e->pos()) && isToggle) isDown=!isDown; + + if (isToggle && isDown) + { + showState(true); + } + else + { + showState(false); + } + + if (rect().contains(e->pos())) + { + if (isToggle) + { + emit toggled(isDown); + } + emit clicked(); + } +} + +/** + * @internal + */ +void OClickableLabel::mouseMoveEvent( QMouseEvent *e ) +{ + if (rect().contains(e->pos())) + { + if (isToggle && isDown) + { + showState(false); + } + else + { + showState(true); + } + } + else + { + if (isToggle && isDown) + { + showState(true); + } + else + { + showState(false); + } + } +} + +/** + * this toggles the label and inverts the color of + * the label + * @param on + */ +void OClickableLabel::showState(bool on) +{ + if (on) + { + //setFrameShape(Panel); + setInverted(true); + setBackgroundMode(PaletteHighlight); + } + else + { + //setFrameShape(NoFrame); + setInverted(false); + setBackgroundMode(PaletteBackground); + } + repaint(); +} + +void OClickableLabel::setInverted(bool on) +{ + if ( (!textInverted && on) || (textInverted && !on) ) + { + QPalette pal=palette(); + QColor col=pal.color(QPalette::Normal, QColorGroup::Foreground); + col.setRgb(255-col.red(),255-col.green(),255-col.blue()); + pal.setColor(QPalette::Normal, QColorGroup::Foreground, col); + setPalette(pal); + textInverted=!textInverted; + } +} + +/** + * @param on if the Label is down or up + */ +void OClickableLabel::setOn(bool on) +{ + isDown=on; + showState(isDown); +} diff --git a/libopie2/opieui/oclickablelabel.h b/libopie2/opieui/oclickablelabel.h new file mode 100644 index 0000000..b224d61 --- a/dev/null +++ b/libopie2/opieui/oclickablelabel.h @@ -0,0 +1,103 @@ +/* + This file is part of the Opie Project + Copyright (C) Maximillian Reiß <harlekin@handhelds.org> + =. Copyright (C) The Opie Team <opie-devel@handhelds.org> + .=l. + .>+-= + _;:, .> :=|. This program 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 program 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 OCLICKABLELABEL_H +#define OCLICKABLELABEL_H + +/* QT */ +#include <qlabel.h> + +namespace Opie +{ + +/** + * This class is a special QLabel which can behave + * as a QPushButton or QToggleButton. + * The reason to use a clickable is if you want to save space + * or you want to skip the border of a normal button + * + * <pre> + * QLabel* lbl = new OClickableLabel( parent, "PushLabel" ); + * lbl->setPixmap( "config" ); + * QWhatsThis::add( lbl, tr("Click here to do something") ); + * </pre> + * + * @short A Label behaving as button + * @author Hakan Ardo, Maximillian Reiß ( harlekin@handhelds.org ) + * @see QLabel + * @see QPushButton + * @see QToggleButton + * @version 1.0 + */ + +class OClickableLabel: public QLabel +{ + Q_OBJECT +public: + OClickableLabel(QWidget* parent = 0, const char* name = 0, + WFlags fl = 0); + void setToggleButton(bool t); + +protected: + /** @internal */ + void mousePressEvent( QMouseEvent *e ); + /** @internal */ + void mouseReleaseEvent( QMouseEvent *e ); + /** @internal */ + void mouseMoveEvent( QMouseEvent *e ); + +public slots: + void setOn(bool on); +signals: + /** + * emitted when the labels gets clicked + */ + void clicked(); + + /** + * emitted when the labels gets toggled + * @param on the new new state of the label + */ + void toggled(bool on); +private: + bool isToggle : 1; + bool isDown : 1; + bool textInverted : 1; + + void showState(bool on); + void setInverted(bool on); + +private: + class Private; + Private *d; // private d pointer +}; + +}; + +#endif diff --git a/libopie2/opieui/opieui.pro b/libopie2/opieui/opieui.pro index 61f9bbb..41db153 100644 --- a/libopie2/opieui/opieui.pro +++ b/libopie2/opieui/opieui.pro @@ -1,22 +1,32 @@ TEMPLATE = lib CONFIG += qt warn_on debug DESTDIR = $(OPIEDIR)/lib -HEADERS = olistview.h \ +HEADERS = ocheckitem.h \ + oclickablelabel.h \ + odialog.h \ + ofileselector.h \ + ofileselector_p.h \ + ofiledialog.h \ + ofileview.h \ oimageeffect.h \ + olistview.h \ opixmapeffect.h \ opopupmenu.h \ opixmapprovider.h \ oselector.h \ oversatileview.h \ oversatileviewitem.h \ - odialog.h \ omessagebox.h \ oresource.h \ otaskbarapplet.h \ oseparator.h -SOURCES = olistview.cpp \ +SOURCES = ocheckitem.cpp \ + oclickablelabel.cpp \ + ofileselector.cpp \ + ofiledialog.cpp \ oimageeffect.cpp \ + olistview.cpp \ opixmapeffect.cpp \ opopupmenu.cpp \ opixmapprovider.cpp \ @@ -30,7 +40,7 @@ SOURCES = olistview.cpp \ INTERFACES = TARGET = opieui2 -VERSION = 1.8.2 +VERSION = 1.8.3 INCLUDEPATH += $(OPIEDIR)/include DEPENDPATH += $(OPIEDIR)/include |