author | llornkcor <llornkcor> | 2002-03-20 00:50:29 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-03-20 00:50:29 (UTC) |
commit | 090ac02da739600c577ed6396e04ed0e121f7890 (patch) (side-by-side diff) | |
tree | b994655686701aa5482e98a455141eb1757cc952 | |
parent | 5f6144b48cac5cc058ee06461e865ce03cda00f1 (diff) | |
download | opie-090ac02da739600c577ed6396e04ed0e121f7890.zip opie-090ac02da739600c577ed6396e04ed0e121f7890.tar.gz opie-090ac02da739600c577ed6396e04ed0e121f7890.tar.bz2 |
added hidden file option.
-rw-r--r-- | noncore/unsupported/filebrowser/filebrowser.cpp | 39 | ||||
-rw-r--r-- | noncore/unsupported/filebrowser/filebrowser.h | 6 |
2 files changed, 39 insertions, 6 deletions
diff --git a/noncore/unsupported/filebrowser/filebrowser.cpp b/noncore/unsupported/filebrowser/filebrowser.cpp index 41e7634..d9aabfd 100644 --- a/noncore/unsupported/filebrowser/filebrowser.cpp +++ b/noncore/unsupported/filebrowser/filebrowser.cpp @@ -155,118 +155,126 @@ bool FileItem::rename( const QString & name ) oldpath = fileInfo.filePath(); 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 ) : QListView( parent, name ), menuTimer( this ), le( NULL ), itemToRename( NULL ) { addColumn( "Name" ); addColumn( "Date" ); addColumn( "Size" ); addColumn( "Type" ); + showingHidden=FALSE; + setMultiSelection( TRUE ); 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 ); QListView::resizeEvent( e ); } void FileView::updateDir() { + setCaption( "Boogie on boogieboy"); + //qDebug("Caption should be "+currentDir); + 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( d.exists() && !d.isReadable() ) return; currentDir = d.canonicalPath(); + if( !showingHidden) d.setFilter( QDir::Dirs | QDir::Files ); - d.setSorting( QDir::Name | QDir::DirsFirst | QDir::IgnoreCase | - QDir::Reversed ); + 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() == "..") ){ + if( (fi->fileName() == ".") || (fi->fileName() == "..") ){ ++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; if( ( pm = itemToRename->pixmap( 0 ) ) == NULL ) pmw = 0; else pmw = pm->width(); ensureItemVisible( itemToRename ); horizontalScrollBar()->setValue( 0 ); horizontalScrollBar()->setEnabled( FALSE ); verticalScrollBar()->setEnabled( FALSE ); selected = isSelected( itemToRename ); setSelected( itemToRename, FALSE ); @@ -634,53 +642,54 @@ void FileView::showFileMenu() if ( !i->isDir() ) { m->insertItem( tr( "Add to Documents" ), this, SLOT( addToDocuments() ) ); m->insertSeparator(); } MimeType mt(i->getFilePath()); const AppLnk* app = mt.application(); if ( !i->isDir() ) { if ( app ) m->insertItem( app->pixmap(), tr( "Open in " + app->name() ), this, SLOT( run() ) ); else if( i->isExecutable() ) m->insertItem( Resource::loadPixmap( i->text( 0 ) ), tr( "Run" ), this, SLOT( run() ) ); m->insertItem( Resource::loadPixmap( "txt" ), tr( "View as text" ), this, SLOT( viewAsText() ) ); m->insertSeparator(); } m->insertItem( tr( "Rename" ), this, SLOT( rename() ) ); m->insertItem( Resource::loadPixmap("cut"), tr( "Cut" ), this, SLOT( cut() ) ); m->insertItem( Resource::loadPixmap("copy"), + tr( "Copy" ), this, SLOT( copy() ) ); m->insertItem( Resource::loadPixmap("paste"), tr( "Paste" ), this, SLOT( paste() ) ); m->insertItem( tr( "Change Permissions" ), this, SLOT( chPerm() ) ); - m->insertItem( tr( "Delete" ), this, SLOT( del() ) ); + 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 // 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 ); } @@ -690,101 +699,110 @@ void FileBrowser::init(const QString & dir) setIcon( Resource::loadPixmap( "filebrowser_icon" ) ); fileView = new FileView( dir, this ); fileView->setAllColumnsShowFocus( TRUE ); 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 ); 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 ); QAction *a = new QAction( tr("New folder"), Resource::loadPixmap( "newfolder" ), QString::null, 0, this, 0 ); connect( a, SIGNAL( activated() ), fileView, SLOT( newFolder() ) ); a->addTo( toolBar ); a = new QAction( tr("Cut"), Resource::loadPixmap( "cut" ), QString::null, 0, this, 0 ); connect( a, SIGNAL( activated() ), fileView, SLOT( cut() ) ); a->addTo( toolBar ); a = new QAction( tr("Copy"), Resource::loadPixmap( "copy" ), QString::null, 0, this, 0 ); connect( a, SIGNAL( activated() ), fileView, SLOT( copy() ) ); a->addTo( toolBar ); pasteAction = new QAction( tr("Paste"), Resource::loadPixmap( "paste" ), QString::null, 0, this, 0 ); connect( pasteAction, SIGNAL( activated() ), fileView, SLOT( paste() ) ); pasteAction->addTo( toolBar ); +// dirLabel = new QLabel(this, "DirLabel"); connect( fileView, SIGNAL( dirChanged() ), SLOT( updateDirMenu() ) ); updateDirMenu(); QCopChannel* pcmciaChannel = new QCopChannel( "QPE/Card", this ); connect( pcmciaChannel, SIGNAL(received(const QCString &, const QByteArray &)), this, SLOT(pcmciaMessage( const QCString &, const QByteArray &)) ); } void FileBrowser::pcmciaMessage( const QCString &msg, const QByteArray &) { if ( msg == "mtabChanged()" ) { // ## Only really needed if current dir is on a card fileView->updateDir(); } } +void FileBrowser::changeCaption(const QString & dir) { + setCaption( dir); +} + void FileBrowser::dirSelected( int id ) { int i = 0, j; QString dir; // Bulid target dir from menu while( (j = dirMenu->idAt( i )) != id ){ dir += dirMenu->text( j ).stripWhiteSpace(); if( dirMenu->text( j ) != "/" ) dir += "/"; i++; } dir += dirMenu->text( dirMenu->idAt( i ) ).stripWhiteSpace(); fileView->setDir( dir ); } void FileBrowser::updateDirMenu() { QString spc, cd = fileView->cd(); QStringList l = QStringList::split( "/", cd ); int i = 0; dirMenu->clear(); dirMenu->insertItem( tr( "/" ), this, SLOT( dirSelected(int) ) ); @@ -833,48 +851,59 @@ void FileBrowser::sortDate() void FileBrowser::sortType() { fileView->setSorting( 3, sortMenu->isItemChecked( sortMenu->idAt( 5 ) ) ); fileView->sort(); sortMenu->setItemChecked( sortMenu->idAt( 0 ), FALSE ); sortMenu->setItemChecked( sortMenu->idAt( 1 ), FALSE ); sortMenu->setItemChecked( sortMenu->idAt( 2 ), FALSE ); sortMenu->setItemChecked( sortMenu->idAt( 3 ), TRUE ); } 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(); } i = (FileItem *) i->nextSibling(); } if( fl.count() < 1 ) return; if( QMessageBox::warning( this, tr("Change permissions"), tr("Are you sure?"), 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; diff --git a/noncore/unsupported/filebrowser/filebrowser.h b/noncore/unsupported/filebrowser/filebrowser.h index c214dbe..54856a0 100644 --- a/noncore/unsupported/filebrowser/filebrowser.h +++ b/noncore/unsupported/filebrowser/filebrowser.h @@ -5,80 +5,81 @@ ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ #ifndef FILEBROWSER_H #define FILEBROWSER_H #include <qlistview.h> #include <qmainwindow.h> #include <qfileinfo.h> #include <qaction.h> #include <qtimer.h> #include <qstringlist.h> - +class QLabel; class InlineEdit; class FileItem : public QListViewItem { public: FileItem( QListView * parent, const QFileInfo & fi ); QString key( int column, bool ascending = TRUE ) const; QString getFilePath(){ return fileInfo.filePath(); } QString getFileName(){ return fileInfo.fileName(); } bool isDir(){ return fileInfo.isDir(); } bool isExecutable(){ return fileInfo.isExecutable(); } bool isLib(); int launch(); bool rename( const QString & name ); 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 ); void setDir( const QString & dir ); QString cd(){ return currentDir; } QStringList history() const { return dirHistory; } + bool showingHidden; public slots: void updateDir(); void parentDir(); void lastDir(); void rename(); void copy(); void paste(); void del(); void cut(); void newFolder(); void viewAsText(); void chPerm(); protected: void generateDir( const QString & dir ); void resizeEvent( QResizeEvent* ); void contentsMousePressEvent( QMouseEvent * e ); void contentsMouseReleaseEvent( QMouseEvent * e ); protected slots: void itemClicked( QListViewItem * i ); void itemDblClicked( QListViewItem * i ); void showFileMenu(); @@ -93,49 +94,52 @@ private: QString currentDir; QStringList dirHistory, flist; QTimer menuTimer; InlineEdit * le; FileItem * itemToRename; bool selected; 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; 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 updateDirMenu(); void dirSelected( int id ); + void showHidden(); }; #endif |