summaryrefslogtreecommitdiff
path: root/libopie/ofileselector.cpp
Side-by-side diff
Diffstat (limited to 'libopie/ofileselector.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/ofileselector.cpp14
1 files changed, 7 insertions, 7 deletions
diff --git a/libopie/ofileselector.cpp b/libopie/ofileselector.cpp
index 1ba94ae..2a6aed0 100644
--- a/libopie/ofileselector.cpp
+++ b/libopie/ofileselector.cpp
@@ -30,198 +30,198 @@ 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& ) ),
+ 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& ) ) );
+ 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() ) );
@@ -295,194 +295,194 @@ void OFileViewFileListView::reread( bool all ) {
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 ) ) );
+ 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 ) {
@@ -687,194 +687,194 @@ OFileSelector::OFileSelector( QWidget* parent, int mode, int sel,
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 *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& ) ) );
+ connect(m_cmbView, SIGNAL(activated(const QString&) ),
+ this, SLOT(slotViewChange(const QString&) ) );
m_views.insert( QObject::tr("Documents"), new ODocumentFileView(this) );
/* see above why add both */
OFileViewInterface* in = new OFileViewFileSystem( this );
m_views.insert( QObject::tr("Files"), in );
m_views.insert( QObject::tr("All Files"), in );
}
/**
* d'tor
*/
OFileSelector::~OFileSelector() {
}
/**
* Convience function for the fileselector
* make sure to delete the DocLnk
*
* @see DocLnk
* @todo remove in ODP
*/
const DocLnk* OFileSelector::selected() {
DocLnk* lnk = new DocLnk( currentView()->selectedDocument() );
return lnk;
}
/**
*
* @return the name of the selected file
*/
QString OFileSelector::selectedName()const{
return currentView()->selectedName();
}
/**
* @return the selected path
*/
QString OFileSelector::selectedPath()const {
return currentView()->selectedPath();
}
/**
* @return the directory name
*/
QString OFileSelector::directory()const {
return currentView()->directory();
}
/**
* @return a DocLnk for the selected document
*/
DocLnk OFileSelector::selectedDocument()const {
return currentView()->selectedDocument();
}
/**
* @return the number of items for the current view
*/
int OFileSelector::fileCount()const {
return currentView()->fileCount();
}
/**
* @return reparse the file content
*/
void OFileSelector::reread() {
return currentView()->reread();
}
OFileViewInterface* OFileSelector::currentView()const{
return m_current;
}
bool OFileSelector::showNew()const {
return m_shNew;
}
bool OFileSelector::showClose()const {
return m_shClose;
}
MimeTypes OFileSelector::mimeTypes()const {
return m_mimeType;
}
/**
* @return the Mode of the OFileSelector
*/
int OFileSelector::mode()const{
return m_mode;
}
/**
* @return the Selector of the OFileSelector
*/
int OFileSelector::selector()const{
return m_selector;