summaryrefslogtreecommitdiff
authordwmw2 <dwmw2>2002-05-09 11:59:51 (UTC)
committer dwmw2 <dwmw2>2002-05-09 11:59:51 (UTC)
commit67077883f382bd73bf4bdceda8994fa4e47ee5e6 (patch) (side-by-side diff)
tree66433081886ad27170f95e23ccd36d487d90c95a
parentd9b40786a885451caf3f22612ec401df1edff983 (diff)
downloadopie-67077883f382bd73bf4bdceda8994fa4e47ee5e6.zip
opie-67077883f382bd73bf4bdceda8994fa4e47ee5e6.tar.gz
opie-67077883f382bd73bf4bdceda8994fa4e47ee5e6.tar.bz2
#include <qpainter.h>
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/unsupported/filebrowser/filebrowser.cpp1
1 files changed, 1 insertions, 0 deletions
diff --git a/noncore/unsupported/filebrowser/filebrowser.cpp b/noncore/unsupported/filebrowser/filebrowser.cpp
index 1bb7984..8c01655 100644
--- a/noncore/unsupported/filebrowser/filebrowser.cpp
+++ b/noncore/unsupported/filebrowser/filebrowser.cpp
@@ -1,428 +1,429 @@
/**********************************************************************
** Copyright (C) 2000 Trolltech AS. All rights reserved.
**
** This file is part of Qtopia Environment.
**
** 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.
**
**********************************************************************/
#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>
#include <qstringlist.h>
#include <qcursor.h>
#include <qmultilineedit.h>
#include <qfont.h>
+#include <qpainter.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/stat.h>
//
// FileItem
//
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.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( "filebrowser/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 )
return QString().sprintf( "%.1f", size / ( 1024 ) ) + "K";
else
return QString::number( size ) + "B";
}
QString FileItem::key( int column, bool ascending ) const
{
QString tmp;
ascending = ascending;
if( (column == 0) && fileInfo.isDir() ){ // Sort by name
// We want the directories to appear at the top of the list
tmp = (char) 0;
return (tmp + text( column ).lower());
}
else if( column == 2 ) { // Sort by date
QDateTime epoch( QDate( 1980, 1, 1 ) );
tmp.sprintf( "%08d", epoch.secsTo( fileInfo.lastModified() ) );
return tmp;
}
else if( column == 1 ) { // Sort by size
return tmp.sprintf( "%08d", fileInfo.size() );
}
return text( column ).lower();
}
bool FileItem::isLib()
{
// This is of course not foolproof
if( !qstrncmp("lib", fileInfo.baseName(), 3) &&
( fileInfo.extension().contains( "so" ) ||
fileInfo.extension().contains( "a" ) ) )
return TRUE;
else
return FALSE;
}
int FileItem::launch()
{
DocLnk doc( fileInfo.filePath(), FALSE );
doc.execute();
listView()->clearSelection();
return 1;
}
bool FileItem::rename( const QString & name )
{
QString oldpath, newpath;
if ( name.isEmpty() )
return FALSE;
if ( name.contains( QRegExp("[/\\$\"\'\\*\\?]") ) )
return FALSE;
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,
bool hidden, bool symlinks )
: QListView( parent, name ),
menuTimer( this ),
le( NULL ),
itemToRename( NULL ),
showHidden( hidden ),
showSymlinks( symlinks),
menuKeepsOpen( FALSE )
{
addColumn( "Name" );
addColumn( "Size" );
addColumn( "Date" );
addColumn( "Type" );
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()
{
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 )
{
if(menuKeepsOpen){
cancelMenuTimer();
}
QDir d( dir );
if( d.exists() && !d.isReadable() ) return;
currentDir = d.canonicalPath();
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;
}
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;
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 );
if( le == NULL ){
le = new InlineEdit( this );
le->setFrame( FALSE );
connect( le, SIGNAL( lostFocus() ), SLOT( endRenaming() ) );
}
QRect r = itemRect( itemToRename );
r.setTop( r.top() + frameWidth() + 1 );
r.setLeft( r.left() + frameWidth() + pmw );
r.setBottom( r.bottom() + frameWidth() );
r.setWidth( columnWidth( 0 ) - pmw );
le->setGeometry( r );
le->setText( itemToRename->text( 0 ) );
le->selectAll();
le->show();
le->setFocus();
}
void FileView::endRenaming()
{
if( le && itemToRename ){
le->hide();
setSelected( itemToRename, selected );
if( !itemToRename->rename( le->text() ) ){
QMessageBox::warning( this, tr( "Rename file" ),
tr( "Rename failed!" ), tr( "&Ok" ) );
} else {
updateDir();
}
itemToRename = NULL;
horizontalScrollBar()->setEnabled( TRUE );
verticalScrollBar()->setEnabled( TRUE );
}
}
void FileView::copy()
{
// dont keep cut files any longer than necessary
// ##### a better inmplementation might be to rename the CUT file
// ##### to ".QPE-FILEBROWSER-MOVING" rather than copying it.
system ( "rm -rf /tmp/qpemoving" );
FileItem * i;
if((i = (FileItem *) firstChild()) == 0) return;
flist.clear();
while( i ){
if( i->isSelected() /*&& !i->isDir()*/ ){
flist += i->getFilePath();
}
i = (FileItem *) i->nextSibling();
}
}
void FileView::paste()
{
int i, err;
QString cmd, dest, basename, cd = currentDir;
if(cd == "/") cd = "";
for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it ) {
basename = (*it).mid((*it).findRev("/") + 1, (*it).length());
dest = cd + "/" + basename;
if( QFile( dest ).exists() ){
i = 1;
dest = cd + "/Copy of " + basename;
while( QFile( dest ).exists() ){
dest.sprintf( "%s/Copy (%d) of %s", (const char *) cd, i++,
(const char *) basename );
}
}
//
// Copy a directory recursively using the "cp" command -
// may have to be changed
//
if( QFileInfo( (*it) ).isDir() ){
cmd = "/bin/cp -fpR \"" + (*it) +"\" " + "\"" + dest + "\"";
err = system( (const char *) cmd );
} else if( !copyFile( dest, (*it) ) ){
err = -1;
} else {
err = 0;
}
if ( err != 0 ) {
QMessageBox::warning( this, tr("Paste file"), tr("Paste failed!"),
tr("Ok") );
break;
} else {
updateDir();
QListViewItem * i = firstChild();
basename = dest.mid( dest.findRev("/") + 1, dest.length() );
while( i ){
if( i->text(0) == basename ){
setCurrentItem( i );
ensureItemVisible( i );
break;
}
i = i->nextSibling();
}
}
}
}
bool FileView::copyFile( const QString & dest, const QString & src )
{
char bf[ 50000 ];
int bytesRead;
bool success = TRUE;
struct stat status;
QFile s( src );
QFile d( dest );
if( s.open( IO_ReadOnly | IO_Raw ) &&
d.open( IO_WriteOnly | IO_Raw ) )
{
while( (bytesRead = s.readBlock( bf, sizeof( bf ) )) ==
sizeof( bf ) )
{
if( d.writeBlock( bf, sizeof( bf ) ) != sizeof( bf ) ){
success = FALSE;
break;
}
}