summaryrefslogtreecommitdiff
path: root/noncore
Side-by-side diff
Diffstat (limited to 'noncore') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/unsupported/filebrowser/filebrowser.cpp132
-rw-r--r--noncore/unsupported/filebrowser/filebrowser.h18
-rw-r--r--noncore/unsupported/filebrowser/opie-filebrowser.control2
3 files changed, 117 insertions, 35 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
@@ -16,24 +16,25 @@
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
#include "inlineedit.h"
#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>
#include <qregexp.h>
#include <qheader.h>
#include <qpe/qpetoolbar.h>
#include <qpopupmenu.h>
#include <qpe/qpemenubar.h>
#include <qaction.h>
@@ -52,46 +53,55 @@
FileItem::FileItem( QListView * parent, const QFileInfo & fi )
: QListViewItem( parent ),
fileInfo( fi )
{
QDate d = fi.lastModified().date();
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() )
- setText( 3, "directory" );
+ if ( fi.isSymLink() )
+ setText( 3, "symlink" );
+ else if( fi.isDir() )
+ setText( 3, "directory" );
else if( isLib() )
setText( 3, "library" );
else
setText( 3, mt.description() );
QPixmap pm;
if( fi.isDir() ){
if( !QDir( fi.filePath() ).isReadable() )
pm = Resource::loadPixmap( "lockedfolder" );
else
pm = Resource::loadPixmap( "folder" );
}
else if( !fi.isReadable() )
pm = Resource::loadPixmap( "locked" );
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;
if ( size > 1024 * 1024 * 1024 )
return QString().sprintf( "%.1f", size / ( 1024 * 1024 * 1024 ) ) + "G";
else if ( size > 1024 * 1024 )
return QString().sprintf( "%.1f", size / ( 1024 * 1024 ) ) + "M";
else if ( size > 1024 )
@@ -156,108 +166,117 @@ bool FileItem::rename( const QString & name )
newpath = fileInfo.dirPath() + "/" + name;
if ( ::rename( (const char *) oldpath, (const char *) newpath ) != 0 )
return FALSE;
else
return TRUE;
}
//
// 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 );
generateDir( dir );
connect( this, SIGNAL( clicked( QListViewItem * )),
SLOT( itemClicked( QListViewItem * )) );
connect( this, SIGNAL( doubleClicked( QListViewItem * )),
SLOT( itemDblClicked( QListViewItem * )) );
connect( this, SIGNAL( selectionChanged() ), SLOT( cancelMenuTimer() ) );
connect( &menuTimer, SIGNAL( timeout() ), SLOT( showFileMenu() ) );
}
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 );
}
void FileView::setDir( const QString & dir )
{
if ( dir.startsWith( "/dev" ) ) {
QMessageBox::warning( this, tr( "File Manager" ),
tr( "Can't show /dev/ directory." ), tr( "&Ok" ) );
return;
}
dirHistory += currentDir;
generateDir( dir );
}
void FileView::generateDir( const QString & dir )
{
- QDir d( 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 );
const QFileInfoList * list = d.entryInfoList();
QFileInfoListIterator it( *list );
QFileInfo *fi;
clear();
while( (fi = it.current()) ){
if( (fi->fileName() == ".") || (fi->fileName() == "..") ){
++it;
continue;
}
- (void) new FileItem( (QListView *) this, *fi );
+ if(!showSymlinks && fi->isSymLink()){
+ ++it;
+ continue;
+ }
+ (void) new FileItem( (QListView *) this, *fi );
++it;
}
emit dirChanged();
}
void FileView::rename()
{
itemToRename = (FileItem *) currentItem();
const QPixmap * pm;
int pmw;
if( itemToRename == NULL ) return;
@@ -561,25 +580,29 @@ void FileView::viewAsText()
void FileView::itemClicked( QListViewItem * i)
{
FileItem * t = (FileItem *) i;
if( t == NULL ) return;
if( t->isDir() ){
setDir( t->getFilePath() );
}
}
void FileView::itemDblClicked( QListViewItem * i)
{
- FileItem * t = (FileItem *) 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" ) );
}
}
void FileView::parentDir()
{
setDir( currentDir + "./.." );
}
@@ -593,25 +616,28 @@ void FileView::lastDir()
generateDir( newDir );
}
void FileView::contentsMousePressEvent( QMouseEvent * e )
{
QListView::contentsMousePressEvent( e );
menuTimer.start( 750, TRUE );
}
void FileView::contentsMouseReleaseEvent( QMouseEvent * e )
{
QListView::contentsMouseReleaseEvent( e );
- menuTimer.stop();
+ if(!menuKeepsOpen){
+ menuTimer.stop();
+ }
+
}
void FileView::cancelMenuTimer()
{
if( menuTimer.isActive() )
menuTimer.stop();
}
void FileView::addToDocuments()
{
FileItem * i = (FileItem *) currentItem();
DocLnk f;
@@ -667,73 +693,102 @@ void FileView::showFileMenu()
m->insertItem( tr( "Change Permissions" ), this, SLOT( chPerm() ) );
m->insertItem(Resource::loadPixmap( "close" ), tr( "Delete" ), this, SLOT( del() ) );
m->insertSeparator();
m->insertItem( tr( "Select all" ), this, SLOT( selectAll() ) );
m->insertItem( tr( "Deselect all" ), this, SLOT( deselectAll() ) );
m->popup( QCursor::pos() );
}
//
// 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() );
}
FileBrowser::FileBrowser( const QString & dir, QWidget * parent,
const char * name, WFlags f ) :
QMainWindow( parent, name, f )
{
init( dir );
}
void FileBrowser::init(const QString & dir)
{
setCaption( tr("File Manager") );
setIcon( Resource::loadPixmap( "filebrowser_icon" ) );
- fileView = new FileView( dir, this );
- fileView->setAllColumnsShowFocus( TRUE );
+ 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 );
QPEMenuBar* menuBar = new QPEMenuBar( toolBar );
dirMenu = new QPopupMenu( this );
menuBar->insertItem( tr( "Dir" ), dirMenu );
sortMenu = new QPopupMenu( this );
menuBar->insertItem( tr( "Sort" ), sortMenu );
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 );
lastAction->setEnabled( FALSE );
upAction = new QAction( tr("Parent dir"), Resource::loadIconSet( "up" ),
QString::null, 0, this, 0 );
connect( upAction, SIGNAL( activated() ), fileView, SLOT( parentDir() ) );
upAction->addTo( toolBar );
@@ -861,35 +916,24 @@ void FileBrowser::updateSorting()
sortMenu->setItemChecked( sortMenu->idAt( 5 ), !sortMenu->isItemChecked( sortMenu->idAt( 5 ) ) );
if ( sortMenu->isItemChecked( sortMenu->idAt( 0 ) ) )
sortName();
else if ( sortMenu->isItemChecked( sortMenu->idAt( 1 ) ) )
sortSize();
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;
if((i = (FileItem *) firstChild()) == 0) return;
while( i ){
if( i->isSelected() ){
fl += i->getFilePath();
}
@@ -900,12 +944,40 @@ void FileView::chPerm() {
tr("Yes"), tr("No") ) == 0) {
for ( QStringList::Iterator it = fl.begin(); it != fl.end(); ++it ) {
filePermissions *filePerm;
filePerm = new filePermissions(this, "Permissions",true,0,(const QString &)(*it));
filePerm->exec();
if( filePerm)
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();
+}
diff --git a/noncore/unsupported/filebrowser/filebrowser.h b/noncore/unsupported/filebrowser/filebrowser.h
index 54856a0..983e58e 100644
--- a/noncore/unsupported/filebrowser/filebrowser.h
+++ b/noncore/unsupported/filebrowser/filebrowser.h
@@ -45,30 +45,37 @@ public:
private:
QString sizeString( unsigned int size );
QFileInfo fileInfo;
};
class FileView : public QListView
{
Q_OBJECT
public:
FileView( const QString & dir, QWidget * parent = 0,
- const char * name = 0 );
+ const char * name = 0,
+ bool hidden = FALSE,
+ bool symlinks = FALSE );
+
void setDir( const QString & dir );
QString cd(){ return currentDir; }
QStringList history() const { return dirHistory; }
bool showingHidden;
+ void setShowHidden(bool hidden);
+ void setShowSymlinks(bool symlinks);
+ void setMenuKeepsOpen(bool keepOpen);
+
public slots:
void updateDir();
void parentDir();
void lastDir();
void rename();
void copy();
void paste();
void del();
void cut();
void newFolder();
void viewAsText();
@@ -88,58 +95,61 @@ protected slots:
void deselectAll(){ QListView::selectAll( FALSE ); }
void addToDocuments();
void run();
void endRenaming();
private:
QString currentDir;
QStringList dirHistory, flist;
QTimer menuTimer;
InlineEdit * le;
FileItem * itemToRename;
bool selected;
+ bool showHidden;
+ bool showSymlinks;
+ bool menuKeepsOpen;
bool copyFile( const QString & dest, const QString & src );
signals:
void dirChanged();
void textViewActivated( QWidget * w );
void textViewDeactivated();
};
class FileBrowser : public QMainWindow
{
Q_OBJECT
public:
FileBrowser( QWidget * parent = 0,
const char * name = 0, WFlags f = 0 );
FileBrowser( const QString & dir, QWidget * parent = 0,
const char * name = 0, WFlags f = 0 );
public slots:
void changeCaption(const QString &);
private:
void init(const QString & dir);
QString fileToCopy;
- QPopupMenu * dirMenu, * sortMenu;
+ QPopupMenu * dirMenu, * sortMenu, *viewMenu;
FileView * fileView;
QAction * pasteAction;
QAction *lastAction;
QAction *upAction;
bool copyFile( const QString & dest, const QString & src );
private slots:
void pcmciaMessage( const QCString &msg, const QByteArray &);
void sortName();
void sortDate();
void sortSize();
void sortType();
void updateSorting();
-
+ void updateShowHidden();
+ void updateShowSymlinks();
void updateDirMenu();
void dirSelected( int id );
- void showHidden();
};
#endif
diff --git a/noncore/unsupported/filebrowser/opie-filebrowser.control b/noncore/unsupported/filebrowser/opie-filebrowser.control
index c15ae17..0b8528a 100644
--- a/noncore/unsupported/filebrowser/opie-filebrowser.control
+++ b/noncore/unsupported/filebrowser/opie-filebrowser.control
@@ -1,9 +1,9 @@
-Files: bin/filebrowser apps/Applications/filebrowser.desktop
+Files: bin/filebrowser apps/Applications/filebrowser.desktop pics/symlink.png
Priority: optional
Section: opie/applications
Maintainer: Warwick Allison <warwick@trolltech.com>
Architecture: arm
Version: $QPE_VERSION-$SUB_VERSION
Depends: opie-base ($QPE_VERSION)
Description: Browse the file system
The filebrowser for the Opie environment.