summaryrefslogtreecommitdiff
authorar <ar>2004-09-15 21:11:32 (UTC)
committer ar <ar>2004-09-15 21:11:32 (UTC)
commit6a60be54b98f1eb50df5a37454bb71bd52475f43 (patch) (side-by-side diff)
treeb14d617d0108f9612ce16e95d03c9b55b5d0cbd7
parente3709ce5db7f07cbac94900cb7b66ad3e7a6f791 (diff)
downloadopie-6a60be54b98f1eb50df5a37454bb71bd52475f43.zip
opie-6a60be54b98f1eb50df5a37454bb71bd52475f43.tar.gz
opie-6a60be54b98f1eb50df5a37454bb71bd52475f43.tar.bz2
- implement a QStringList* m_allList for show all files/directories if a "All Item" is selected. (hope the description is not too confused ;) )
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opieui/fileselector/ofileselector.cpp26
-rw-r--r--libopie2/opieui/fileselector/ofileselector.h3
-rw-r--r--libopie2/opieui/fileselector/ofileselector_p.h1
3 files changed, 27 insertions, 3 deletions
diff --git a/libopie2/opieui/fileselector/ofileselector.cpp b/libopie2/opieui/fileselector/ofileselector.cpp
index 346eeae..e8d502f 100644
--- a/libopie2/opieui/fileselector/ofileselector.cpp
+++ b/libopie2/opieui/fileselector/ofileselector.cpp
@@ -341,874 +341,894 @@ OFileViewFileListView::OFileViewFileListView( QWidget* parent, const QString& st
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;
filter = QDir::Dirs;
if ( selector()->mode() != OFileSelector::DIRECTORYSELECTOR )
filter = filter | QDir::Files | QDir::All;
if ( m_all )
filter = filter | QDir::Hidden;
dir.setFilter( filter );
// now go through all files
const QFileInfoList *list = dir.entryInfoList();
if (!list)
{
cdUP();
return;
}
QFileInfoListIterator it( *list );
QFileInfo *fi;
while( (fi=it.current() ) )
{
if( fi->fileName() == QString::fromLatin1("..") || fi->fileName() == QString::fromLatin1(".") )
{
++it;
continue;
}
/*
* It is a symlink we try to resolve it now but don't let us attack by DOS
*
*/
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 *, 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;
}
+/**
+ * @return true if the item show all files or directories
+ */
+bool OFileViewFileListView::allItem( const QString& item )const
+{
+ return m_sel->allItem( item );
+}
+
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 )
{
odebug << "slot Current Changed" << oendl;
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
odebug << "slot Clicked" << oendl;
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)
+void OFileViewFileSystem::activate( const QString& str )
{
- m_all = ( str.find( "All" ) != -1 );
+ m_all = m_view->allItem( str );
}
}
/* 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;
+ m_allList = new QStringList();
+
initUI();
m_lneEdit->setText( fileName );
initMime();
initViews();
QString str;
switch ( m_selector )
{
default:
case Normal:
if ( m_mode == DIRECTORYSELECTOR )
str = QObject::tr("Directories");
else
str = QObject::tr("Documents");
m_cmbView->setCurrentItem( 0 );
break;
case Extended:
if ( m_mode == DIRECTORYSELECTOR )
{
str = QObject::tr("Directories");
m_cmbView->setCurrentItem( 0 );
} else {
str = QObject::tr("Files");
m_cmbView->setCurrentItem( 1 );
}
break;
case ExtendedAll:
if ( m_mode == DIRECTORYSELECTOR )
{
str = QObject::tr("All Directories");
m_cmbView->setCurrentItem( 1 );
} else {
str = QObject::tr("All Files");
m_cmbView->setCurrentItem( 2 );
}
break;
}
slotViewChange( str );
}
/**
* This a convience c'tor to just substitute the use of FileSelector
*/
OFileSelector::OFileSelector( const QString& mimeFilter, QWidget* parent, const char* name,
bool showNew, bool showClose )
: QWidget( parent, name )
{
m_current = 0;
m_shNew = showNew;
m_shClose = showClose;
m_startDir = QPEApplication::documentDir();
if (!mimeFilter.isEmpty() )
m_mimeType.insert(mimeFilter, QStringList::split(";", mimeFilter ) );
m_mode = OFileSelector::FileSelector;
m_selector = OFileSelector::Normal;
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 *, 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()
{
if ( m_mode == OFileSelector::DIRECTORYSELECTOR )
{
m_cmbView->insertItem( QObject::tr("Directories") );
m_cmbView->insertItem( QObject::tr("All Directories") );
} else {
m_cmbView->insertItem( QObject::tr("Documents") );
m_cmbView->insertItem( QObject::tr("Files") );
m_cmbView->insertItem( QObject::tr("All Files") );
}
connect(m_cmbView, SIGNAL(activated(const QString&) ),
this, SLOT(slotViewChange(const QString&) ) );
/* see above why add both */
OFileViewInterface* in = new OFileViewFileSystem( this );
if ( m_mode == OFileSelector::DIRECTORYSELECTOR )
{
m_views.insert( QObject::tr("Directories"), in );
m_views.insert( QObject::tr("All Directories"), in );
+ m_allList->append( QObject::tr("All Directories") );
} else {
m_views.insert( QObject::tr("Documents"), new ODocumentFileView(this) );
m_views.insert( QObject::tr("Files"), in );
m_views.insert( QObject::tr("All Files"), in );
+ m_allList->append( QObject::tr("All Files") );
}
}
void OFileSelector::registerView( const Internal::OFileViewInterface* iface ) {
m_viewsPtr.append( iface );
}
/**
* d'tor
*/
OFileSelector::~OFileSelector()
{
m_viewsPtr.setAutoDelete( true );
m_viewsPtr.clear();
}
/**
* Convience function for the fileselector
* make sure to delete the DocLnk
*
* @see DocLnk
* @todo remove in ODP
*/
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;
}
+/**
+ * @return true if the item show all files or directories
+ */
+bool OFileSelector::allItem( const QString& item )const
+{
+ return ( m_allList->findIndex( item ) != -1 );
+}
+
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->activate( view );
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
index b1cd405..d96712a 100644
--- a/libopie2/opieui/fileselector/ofileselector.h
+++ b/libopie2/opieui/fileselector/ofileselector.h
@@ -1,233 +1,236 @@
/*
               =. 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>
#include <qlist.h>
class QLineEdit;
class QComboBox;
class QWidgetStack;
class QHBox;
typedef QMap<QString, QStringList> MimeTypes;
namespace Opie {
namespace Ui {
namespace Internal {
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 Internal::OFileViewInterface;
friend class Internal::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
* SelectDir = Select a Directory
*/
enum Mode { Open = 1, Save = 2, DirectorySelector = 3, FileSelector = 4, OPEN = 1, SAVE = 2, DIRECTORYSELECTOR = 3, 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;
+ bool allItem( const QString& )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();
/*
* register a view for deletion.
* This happens on creation of a OFileViewInterface
*/
void registerView( const Internal::OFileViewInterface* );
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
Internal::OFileViewInterface* currentView() const; // returns the currentView
Internal::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, Internal::OFileViewInterface*> m_views; // QString translated view name + ViewInterface Ptr
/* views register themselves automatically */
QList<Internal::OFileViewInterface> m_viewsPtr;
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;
+ QStringList* m_allList;
+
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
index a3ef8e2..252a7f5 100644
--- a/libopie2/opieui/fileselector/ofileselector_p.h
+++ b/libopie2/opieui/fileselector/ofileselector_p.h
@@ -1,193 +1,194 @@
/*
               =. 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{
namespace Ui{
class OFileSelector;
namespace Internal {
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;
+ bool allItem( const QString& )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