summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opieui/fileselector/ofiledialog.cpp4
-rw-r--r--libopie2/opieui/fileselector/ofileselector.cpp56
2 files changed, 26 insertions, 34 deletions
diff --git a/libopie2/opieui/fileselector/ofiledialog.cpp b/libopie2/opieui/fileselector/ofiledialog.cpp
index 2d38961..11a9e33 100644
--- a/libopie2/opieui/fileselector/ofiledialog.cpp
+++ b/libopie2/opieui/fileselector/ofiledialog.cpp
@@ -1,202 +1,202 @@
/*
               =. This file is part of the OPIE Project
             .=l. Copyright (C) Holger Freyther <freyther@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.
+ - .   .-<_>     .<> Foundation; version 2 of the License.
+     ._= =}       :
    .%`+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>
/* TRANSLATOR Opie::Ui::OFileDialog */
using namespace Opie::Ui;
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 );
if ( inf.isFile() )
cfg.writeEntry("LastDir", inf.dirPath( true ) );
else
cfg.writeEntry("LastDir", file );
}
};
/**
* 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 );
file = new OFileSelector(this , mode, selector,
dirName, fileName,
mimetypes );
lay->addWidget( file );
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&) ) );
}
/**
* @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);
if( QPEApplication::execDialog(&dlg ) )
{
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);
/*
* For the save mode we do not want a file to be written
* if the user just clicked on it
* #1522
*/
dlg.file->disconnect( &dlg );
if( QPEApplication::execDialog(&dlg) )
{
diff --git a/libopie2/opieui/fileselector/ofileselector.cpp b/libopie2/opieui/fileselector/ofileselector.cpp
index 02404e5..5b5dc2f 100644
--- a/libopie2/opieui/fileselector/ofileselector.cpp
+++ b/libopie2/opieui/fileselector/ofileselector.cpp
@@ -1,220 +1,218 @@
/*
-                 This file is part of the Opie Project
-
- Copyright (C) 2002,2003 Holger Freyther <zecke@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.
+               =. This file is part of the OPIE Project
+             .=l. Copyright (C) Holger Freyther <freyther@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; version 2 of the License.
+     ._= =}       :
+    .%`+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/odebug.h>
#include <opie2/ofileselector.h>
#include <opie2/oresource.h>
#include <qpe/qpeapplication.h>
#include <qpe/mimetype.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::Ui::Internal;
namespace Opie {
namespace Ui {
namespace Internal {
/*
* Create a path by adding a '/'/QDir::seperator in between
* base and ending, but only if base is not empty
*/
static inline QString createNewPath(const QString& base, const QString &ending) {
return base == QString::fromLatin1("/") ?
base + ending : base + "/" + ending;
}
OFileViewInterface::OFileViewInterface( OFileSelector* _selector )
: m_selector( _selector )
{
selector()->registerView( this );
}
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;
}
bool OFileViewInterface::allItem( const QString& item )const
{
return selector()->m_allList.contains( item );
}
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;
@@ -442,403 +440,397 @@ 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 = createNewPath(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 = createNewPath(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;
}
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 = createNewPath(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 = createNewPath(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 = createNewPath(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( Opie::Core::OResource::loadPixmap( "UnknownDocument" ) );
- matrix.scale( .4, .4 );
- pix = pixer.xForm( matrix );
- }
+ if ( pix.isNull() ) pix = Opie::Core::OResource::loadPixmap( "UnknownDocument", Opie::Core::OResource::SmallIcon );
dir = info->dirPath( true );
locked = false;
if ( symlink )
name = info->fileName() + " -> " + createNewPath(info->dirPath(),info->readLink());
else
{
name = info->fileName();
if ( ( (selector()->mode() == OFileSelector::Open)&& !info->isReadable() ) ||
( (selector()->mode() == OFileSelector::Save)&& !info->isWritable() ) )
{
locked = true;
- pix = Opie::Core::OResource::loadPixmap( "locked" );
+ pix = Opie::Core::OResource::loadPixmap( "locked", Opie::Core::OResource::SmallIcon );
}
}
(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 = Opie::Core::OResource::loadPixmap( "opie/symlink" );
else
pix = Opie::Core::OResource::loadPixmap( "lockedfolder" );
}
else
pix = symlink ? Opie::Core::OResource::loadPixmap( "opie/symlink" ) : Opie::Core::OResource::loadPixmap( "folder" );
name = symlink ? info->fileName() + " -> " + createNewPath(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 createNewPath(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 )
{