Diffstat (limited to 'noncore/unsupported/filebrowser/filebrowser.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/unsupported/filebrowser/filebrowser.cpp | 120 |
1 files changed, 96 insertions, 24 deletions
diff --git a/noncore/unsupported/filebrowser/filebrowser.cpp b/noncore/unsupported/filebrowser/filebrowser.cpp index 6f82f95..34d5177 100644 --- a/noncore/unsupported/filebrowser/filebrowser.cpp +++ b/noncore/unsupported/filebrowser/filebrowser.cpp @@ -22,12 +22,13 @@ #include "filebrowser.h" #include "filePermissions.h" #include <qpe/resource.h> #include <qpe/global.h> #include <qpe/mimetype.h> #include <qpe/applnk.h> +#include <qpe/config.h> #include <qcopchannel_qws.h> #include <qpe/qcopenvelope_qws.h> #include <qmessagebox.h> #include <qdir.h> @@ -58,13 +59,15 @@ FileItem::FileItem( QListView * parent, const QFileInfo & fi ) setText( 0, fi.fileName() ); setText( 1, sizeString( fi.size() ) + " " ); setText( 2, QString().sprintf("%4d-%02d-%02d",d.year(), d.month(), d.day() ) ); MimeType mt(fi.filePath()); - if( fi.isDir() ) + if ( fi.isSymLink() ) + setText( 3, "symlink" ); + else if( fi.isDir() ) setText( 3, "directory" ); else if( isLib() ) setText( 3, "library" ); else setText( 3, mt.description() ); @@ -80,12 +83,19 @@ FileItem::FileItem( QListView * parent, const QFileInfo & fi ) else if( isLib() ) pm = Resource::loadPixmap( "library" ); else pm = mt.pixmap(); if ( pm.isNull() ) pm = Resource::loadPixmap("UnknownDocument-14"); + if( fi.isSymLink() ){ + // overlay link image + QPixmap lnk = Resource::loadPixmap( "symlink" ); + QPainter painter( &pm ); + painter.drawPixmap( pm.width()-lnk.width(), pm.height()-lnk.height(), lnk ); + pm.setMask( pm.createHeuristicMask( FALSE ) ); + } setPixmap(0,pm); } QString FileItem::sizeString( unsigned int s ) { double size = s; @@ -162,27 +172,29 @@ bool FileItem::rename( const QString & name ) } // // FileView // FileView::FileView( const QString & dir, QWidget * parent, - const char * name ) + const char * name, + bool hidden, bool symlinks ) : QListView( parent, name ), menuTimer( this ), le( NULL ), - itemToRename( NULL ) + itemToRename( NULL ), + showHidden( hidden ), + showSymlinks( symlinks), + menuKeepsOpen( FALSE ) { addColumn( "Name" ); addColumn( "Date" ); addColumn( "Size" ); addColumn( "Type" ); - showingHidden=FALSE; - setMultiSelection( TRUE ); - header()->hide(); + //header()->hide(); setColumnWidthMode( 0, Manual ); setColumnWidthMode( 3, Manual ); // right align yize column setColumnAlignment( 1, AlignRight ); @@ -199,13 +211,13 @@ FileView::FileView( const QString & dir, QWidget * parent, void FileView::resizeEvent( QResizeEvent *e ) { setColumnWidth( 0, width() - 2 * lineWidth() - 20 - columnWidth( 1 ) - columnWidth( 2 ) ); // hide type column, we use it for "sort by type" only - setColumnWidth( 3, 0 ); + //setColumnWidth( 3, 0 ); QListView::resizeEvent( e ); } void FileView::updateDir() { generateDir( currentDir ); @@ -221,19 +233,22 @@ void FileView::setDir( const QString & dir ) dirHistory += currentDir; generateDir( dir ); } void FileView::generateDir( const QString & dir ) { + if(menuKeepsOpen){ + cancelMenuTimer(); + } QDir d( dir ); if( d.exists() && !d.isReadable() ) return; currentDir = d.canonicalPath(); - if( !showingHidden) + if( !showHidden) d.setFilter( QDir::Dirs | QDir::Files ); else d.setFilter( QDir::Dirs | QDir::Files |QDir::Hidden | QDir::All); d.setSorting( QDir::Name | QDir::DirsFirst | QDir::IgnoreCase | QDir::Reversed ); @@ -245,12 +260,16 @@ void FileView::generateDir( const QString & dir ) clear(); while( (fi = it.current()) ){ if( (fi->fileName() == ".") || (fi->fileName() == "..") ){ ++it; continue; } + if(!showSymlinks && fi->isSymLink()){ + ++it; + continue; + } (void) new FileItem( (QListView *) this, *fi ); ++it; } emit dirChanged(); } @@ -567,12 +586,16 @@ void FileView::itemClicked( QListViewItem * i) setDir( t->getFilePath() ); } } void FileView::itemDblClicked( QListViewItem * i) { + if(menuKeepsOpen){ + cancelMenuTimer(); + } + FileItem * t = (FileItem *) i; if(t == NULL) return; if(t->launch() == -1){ QMessageBox::warning( this, tr( "Launch Application" ), tr( "Launch failed!" ), tr( "Ok" ) ); @@ -599,15 +622,18 @@ void FileView::contentsMousePressEvent( QMouseEvent * e ) menuTimer.start( 750, TRUE ); } void FileView::contentsMouseReleaseEvent( QMouseEvent * e ) { QListView::contentsMouseReleaseEvent( e ); + if(!menuKeepsOpen){ menuTimer.stop(); } +} + void FileView::cancelMenuTimer() { if( menuTimer.isActive() ) menuTimer.stop(); } @@ -673,12 +699,27 @@ void FileView::showFileMenu() } // // FileBrowser // +void FileView::setShowHidden(bool hidden) +{ + showHidden=hidden; +} + +void FileView::setShowSymlinks(bool symlinks) +{ + showSymlinks=symlinks; +} + +void FileView::setMenuKeepsOpen(bool keepOpen) +{ + menuKeepsOpen=keepOpen; +} + FileBrowser::FileBrowser( QWidget * parent, const char * name, WFlags f ) : QMainWindow( parent, name, f ) { init( QDir::current().canonicalPath() ); } @@ -692,14 +733,24 @@ FileBrowser::FileBrowser( const QString & dir, QWidget * parent, void FileBrowser::init(const QString & dir) { setCaption( tr("File Manager") ); setIcon( Resource::loadPixmap( "filebrowser_icon" ) ); - fileView = new FileView( dir, this ); + Config cfg("Filebrowser"); + cfg.setGroup("View"); + bool showHidden=(cfg.readEntry("Hidden","FALSE") == "TRUE"); + bool showSymlinks=(cfg.readEntry("Symlinks","FALSE") == "TRUE"); + + cfg.setGroup("Menu"); + bool menuKeepsOpen=(cfg.readEntry("KeepOpen", "FALSE") == "TRUE"); + + + fileView = new FileView( dir, this, 0, showHidden, showSymlinks ); fileView->setAllColumnsShowFocus( TRUE ); + fileView->setMenuKeepsOpen(menuKeepsOpen); setCentralWidget( fileView ); setToolBarsMovable( FALSE ); QPEToolBar* toolBar = new QPEToolBar( this ); toolBar->setHorizontalStretchable( TRUE ); @@ -714,20 +765,24 @@ void FileBrowser::init(const QString & dir) sortMenu->insertItem( tr( "by Name "), this, SLOT( sortName() ) ); sortMenu->insertItem( tr( "by Size "), this, SLOT( sortSize() ) ); sortMenu->insertItem( tr( "by Date "), this, SLOT( sortDate() ) ); sortMenu->insertItem( tr( "by Type "), this, SLOT( sortType() ) ); sortMenu->insertSeparator(); sortMenu->insertItem( tr( "Ascending" ), this, SLOT( updateSorting() ) ); - sortMenu->insertSeparator(); - sortMenu->insertItem( tr( "Show Hidden "), this, SLOT( showHidden() ) ); - -// fileView->showingHidden=FALSE; sortMenu->setItemChecked( sortMenu->idAt( 5 ), TRUE ); sortMenu->setItemChecked( sortMenu->idAt( 0 ), TRUE ); + viewMenu = new QPopupMenu( this); + viewMenu->insertItem( tr( "Hidden"), this, SLOT( updateShowHidden() ) ); + viewMenu->insertItem( tr( "Symlinks"), this, SLOT( updateShowSymlinks() ) ); + viewMenu->setItemChecked( viewMenu->idAt( 0 ), showHidden ); + viewMenu->setItemChecked( viewMenu->idAt( 1 ), showSymlinks ); + + menuBar->insertItem( tr("View"), viewMenu ); + toolBar = new QPEToolBar( this ); lastAction = new QAction( tr("Previous dir"), Resource::loadIconSet( "back" ), QString::null, 0, this, 0 ); connect( lastAction, SIGNAL( activated() ), fileView, SLOT( lastDir() ) ); lastAction->addTo( toolBar ); @@ -867,23 +922,12 @@ void FileBrowser::updateSorting() else if ( sortMenu->isItemChecked( sortMenu->idAt( 2 ) ) ) sortDate(); else sortType(); } -void FileBrowser::showHidden() { - if(!fileView->showingHidden) { - fileView->showingHidden=TRUE; - sortMenu->setItemChecked( sortMenu->idAt( 7),TRUE); - } else { - fileView->showingHidden=FALSE; - sortMenu->setItemChecked( sortMenu->idAt( 7),FALSE); - } - fileView->updateDir(); -} - void FileView::chPerm() { FileItem * i; QStringList fl; QString cmd; int err; @@ -906,6 +950,34 @@ void FileView::chPerm() { delete filePerm; break; } updateDir(); } } + +void FileBrowser::updateShowHidden() +{ + bool valShowHidden=viewMenu->isItemChecked( viewMenu->idAt( 0 ) ); + valShowHidden=!valShowHidden; + viewMenu->setItemChecked( viewMenu->idAt( 0 ), valShowHidden ); + fileView->setShowHidden(valShowHidden); + + Config cfg("Filebrowser"); + cfg.setGroup("View"); + cfg.writeEntry("Hidden",valShowHidden?"TRUE":"FALSE"); + + fileView->updateDir(); +} + +void FileBrowser::updateShowSymlinks() +{ + bool valShowSymlinks=viewMenu->isItemChecked( viewMenu->idAt( 1 ) ); + valShowSymlinks=!valShowSymlinks; + viewMenu->setItemChecked( viewMenu->idAt( 1 ), valShowSymlinks ); + fileView->setShowSymlinks(valShowSymlinks); + + Config cfg("Filebrowser"); + cfg.setGroup("View"); + cfg.writeEntry("Symlinks",valShowSymlinks?"TRUE":"FALSE"); + + fileView->updateDir(); +} |