summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/unsupported/filebrowser/filebrowser.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/noncore/unsupported/filebrowser/filebrowser.cpp b/noncore/unsupported/filebrowser/filebrowser.cpp
index eaf5eeb..10dff07 100644
--- a/noncore/unsupported/filebrowser/filebrowser.cpp
+++ b/noncore/unsupported/filebrowser/filebrowser.cpp
@@ -1,221 +1,223 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#include "inlineedit.h" 21#include "inlineedit.h"
22#include "filebrowser.h" 22#include "filebrowser.h"
23#include "filePermissions.h" 23#include "filePermissions.h"
24#include <qpe/resource.h> 24#include <qpe/resource.h>
25#include <qpe/global.h> 25#include <qpe/global.h>
26#include <qpe/mimetype.h> 26#include <qpe/mimetype.h>
27#include <qpe/applnk.h> 27#include <qpe/applnk.h>
28 28
29#include <qcopchannel_qws.h> 29#include <qcopchannel_qws.h>
30#include <qcopenvelope_qws.h>
31
30#include <qmessagebox.h> 32#include <qmessagebox.h>
31#include <qdir.h> 33#include <qdir.h>
32#include <qregexp.h> 34#include <qregexp.h>
33#include <qheader.h> 35#include <qheader.h>
34#include <qpe/qpetoolbar.h> 36#include <qpe/qpetoolbar.h>
35#include <qpopupmenu.h> 37#include <qpopupmenu.h>
36#include <qpe/qpemenubar.h> 38#include <qpe/qpemenubar.h>
37#include <qaction.h> 39#include <qaction.h>
38#include <qstringlist.h> 40#include <qstringlist.h>
39#include <qcursor.h> 41#include <qcursor.h>
40#include <qmultilineedit.h> 42#include <qmultilineedit.h>
41#include <qfont.h> 43#include <qfont.h>
42 44
43#include <unistd.h> 45#include <unistd.h>
44#include <stdlib.h> 46#include <stdlib.h>
45#include <sys/stat.h> 47#include <sys/stat.h>
46 48
47// 49//
48// FileItem 50// FileItem
49// 51//
50FileItem::FileItem( QListView * parent, const QFileInfo & fi ) 52FileItem::FileItem( QListView * parent, const QFileInfo & fi )
51 : QListViewItem( parent ), 53 : QListViewItem( parent ),
52 fileInfo( fi ) 54 fileInfo( fi )
53{ 55{
54 QDate d = fi.lastModified().date(); 56 QDate d = fi.lastModified().date();
55 57
56 setText( 0, fi.fileName() ); 58 setText( 0, fi.fileName() );
57 setText( 1, sizeString( fi.size() ) + " " ); 59 setText( 1, sizeString( fi.size() ) + " " );
58 setText( 2, QString().sprintf("%4d-%02d-%02d",d.year(), d.month(), d.day() ) ); 60 setText( 2, QString().sprintf("%4d-%02d-%02d",d.year(), d.month(), d.day() ) );
59 61
60 MimeType mt(fi.filePath()); 62 MimeType mt(fi.filePath());
61 63
62 if( fi.isDir() ) 64 if( fi.isDir() )
63 setText( 3, "directory" ); 65 setText( 3, "directory" );
64 else if( isLib() ) 66 else if( isLib() )
65 setText( 3, "library" ); 67 setText( 3, "library" );
66 else 68 else
67 setText( 3, mt.description() ); 69 setText( 3, mt.description() );
68 70
69 QPixmap pm; 71 QPixmap pm;
70 if( fi.isDir() ){ 72 if( fi.isDir() ){
71 if( !QDir( fi.filePath() ).isReadable() ) 73 if( !QDir( fi.filePath() ).isReadable() )
72 pm = Resource::loadPixmap( "lockedfolder" ); 74 pm = Resource::loadPixmap( "lockedfolder" );
73 else 75 else
74 pm = Resource::loadPixmap( "folder" ); 76 pm = Resource::loadPixmap( "folder" );
75 } 77 }
76 else if( !fi.isReadable() ) 78 else if( !fi.isReadable() )
77 pm = Resource::loadPixmap( "locked" ); 79 pm = Resource::loadPixmap( "locked" );
78 else if( isLib() ) 80 else if( isLib() )
79 pm = Resource::loadPixmap( "library" ); 81 pm = Resource::loadPixmap( "library" );
80 else 82 else
81 pm = mt.pixmap(); 83 pm = mt.pixmap();
82 if ( pm.isNull() ) 84 if ( pm.isNull() )
83 pm = Resource::loadPixmap("UnknownDocument-14"); 85 pm = Resource::loadPixmap("UnknownDocument-14");
84 setPixmap(0,pm); 86 setPixmap(0,pm);
85} 87}
86 88
87QString FileItem::sizeString( unsigned int s ) 89QString FileItem::sizeString( unsigned int s )
88{ 90{
89 double size = s; 91 double size = s;
90 92
91 if ( size > 1024 * 1024 * 1024 ) 93 if ( size > 1024 * 1024 * 1024 )
92 return QString().sprintf( "%.1f", size / ( 1024 * 1024 * 1024 ) ) + "G"; 94 return QString().sprintf( "%.1f", size / ( 1024 * 1024 * 1024 ) ) + "G";
93 else if ( size > 1024 * 1024 ) 95 else if ( size > 1024 * 1024 )
94 return QString().sprintf( "%.1f", size / ( 1024 * 1024 ) ) + "M"; 96 return QString().sprintf( "%.1f", size / ( 1024 * 1024 ) ) + "M";
95 else if ( size > 1024 ) 97 else if ( size > 1024 )
96 return QString().sprintf( "%.1f", size / ( 1024 ) ) + "K"; 98 return QString().sprintf( "%.1f", size / ( 1024 ) ) + "K";
97 else 99 else
98 return QString::number( size ) + "B"; 100 return QString::number( size ) + "B";
99} 101}
100 102
101QString FileItem::key( int column, bool ascending ) const 103QString FileItem::key( int column, bool ascending ) const
102{ 104{
103 QString tmp; 105 QString tmp;
104 106
105 ascending = ascending; 107 ascending = ascending;
106 108
107 if( (column == 0) && fileInfo.isDir() ){ // Sort by name 109 if( (column == 0) && fileInfo.isDir() ){ // Sort by name
108 // We want the directories to appear at the top of the list 110 // We want the directories to appear at the top of the list
109 tmp = (char) 0; 111 tmp = (char) 0;
110 return (tmp + text( column ).lower()); 112 return (tmp + text( column ).lower());
111 } 113 }
112 else if( column == 2 ) { // Sort by date 114 else if( column == 2 ) { // Sort by date
113 QDateTime epoch( QDate( 1980, 1, 1 ) ); 115 QDateTime epoch( QDate( 1980, 1, 1 ) );
114 tmp.sprintf( "%08d", epoch.secsTo( fileInfo.lastModified() ) ); 116 tmp.sprintf( "%08d", epoch.secsTo( fileInfo.lastModified() ) );
115 return tmp; 117 return tmp;
116 } 118 }
117 else if( column == 1 ) { // Sort by size 119 else if( column == 1 ) { // Sort by size
118 return tmp.sprintf( "%08d", fileInfo.size() ); 120 return tmp.sprintf( "%08d", fileInfo.size() );
119 } 121 }
120 122
121 return text( column ).lower(); 123 return text( column ).lower();
122} 124}
123 125
124bool FileItem::isLib() 126bool FileItem::isLib()
125{ 127{
126 // This is of course not foolproof 128 // This is of course not foolproof
127 if( !qstrncmp("lib", fileInfo.baseName(), 3) && 129 if( !qstrncmp("lib", fileInfo.baseName(), 3) &&
128 ( fileInfo.extension().contains( "so" ) || 130 ( fileInfo.extension().contains( "so" ) ||
129 fileInfo.extension().contains( "a" ) ) ) 131 fileInfo.extension().contains( "a" ) ) )
130 return TRUE; 132 return TRUE;
131 else 133 else
132 return FALSE; 134 return FALSE;
133} 135}
134 136
135int FileItem::launch() 137int FileItem::launch()
136{ 138{
137 DocLnk doc( fileInfo.filePath(), FALSE ); 139 DocLnk doc( fileInfo.filePath(), FALSE );
138 doc.execute(); 140 doc.execute();
139 listView()->clearSelection(); 141 listView()->clearSelection();
140 return 1; 142 return 1;
141} 143}
142 144
143bool FileItem::rename( const QString & name ) 145bool FileItem::rename( const QString & name )
144{ 146{
145 QString oldpath, newpath; 147 QString oldpath, newpath;
146 148
147 if ( name.isEmpty() ) 149 if ( name.isEmpty() )
148 return FALSE; 150 return FALSE;
149 151
150 if ( name.contains( QRegExp("[/\\$\"\'\\*\\?]") ) ) 152 if ( name.contains( QRegExp("[/\\$\"\'\\*\\?]") ) )
151 return FALSE; 153 return FALSE;
152 154
153 oldpath = fileInfo.filePath(); 155 oldpath = fileInfo.filePath();
154 newpath = fileInfo.dirPath() + "/" + name; 156 newpath = fileInfo.dirPath() + "/" + name;
155 157
156 if ( ::rename( (const char *) oldpath, (const char *) newpath ) != 0 ) 158 if ( ::rename( (const char *) oldpath, (const char *) newpath ) != 0 )
157 return FALSE; 159 return FALSE;
158 else 160 else
159 return TRUE; 161 return TRUE;
160} 162}
161 163
162// 164//
163// FileView 165// FileView
164// 166//
165FileView::FileView( const QString & dir, QWidget * parent, 167FileView::FileView( const QString & dir, QWidget * parent,
166 const char * name ) 168 const char * name )
167 : QListView( parent, name ), 169 : QListView( parent, name ),
168 menuTimer( this ), 170 menuTimer( this ),
169 le( NULL ), 171 le( NULL ),
170 itemToRename( NULL ) 172 itemToRename( NULL )
171{ 173{
172 addColumn( "Name" ); 174 addColumn( "Name" );
173 addColumn( "Date" ); 175 addColumn( "Date" );
174 addColumn( "Size" ); 176 addColumn( "Size" );
175 addColumn( "Type" ); 177 addColumn( "Type" );
176 178
177 setMultiSelection( TRUE ); 179 setMultiSelection( TRUE );
178 header()->hide(); 180 header()->hide();
179 181
180 setColumnWidthMode( 0, Manual ); 182 setColumnWidthMode( 0, Manual );
181 setColumnWidthMode( 3, Manual ); 183 setColumnWidthMode( 3, Manual );
182 184
183 // right align yize column 185 // right align yize column
184 setColumnAlignment( 1, AlignRight ); 186 setColumnAlignment( 1, AlignRight );
185 187
186 generateDir( dir ); 188 generateDir( dir );
187 189
188 connect( this, SIGNAL( clicked( QListViewItem * )), 190 connect( this, SIGNAL( clicked( QListViewItem * )),
189 SLOT( itemClicked( QListViewItem * )) ); 191 SLOT( itemClicked( QListViewItem * )) );
190 connect( this, SIGNAL( doubleClicked( QListViewItem * )), 192 connect( this, SIGNAL( doubleClicked( QListViewItem * )),
191 SLOT( itemDblClicked( QListViewItem * )) ); 193 SLOT( itemDblClicked( QListViewItem * )) );
192 connect( this, SIGNAL( selectionChanged() ), SLOT( cancelMenuTimer() ) ); 194 connect( this, SIGNAL( selectionChanged() ), SLOT( cancelMenuTimer() ) );
193 connect( &menuTimer, SIGNAL( timeout() ), SLOT( showFileMenu() ) ); 195 connect( &menuTimer, SIGNAL( timeout() ), SLOT( showFileMenu() ) );
194} 196}
195 197
196void FileView::resizeEvent( QResizeEvent *e ) 198void FileView::resizeEvent( QResizeEvent *e )
197{ 199{
198 setColumnWidth( 0, width() - 2 * lineWidth() - 20 - columnWidth( 1 ) - columnWidth( 2 ) ); 200 setColumnWidth( 0, width() - 2 * lineWidth() - 20 - columnWidth( 1 ) - columnWidth( 2 ) );
199 201
200 // hide type column, we use it for "sort by type" only 202 // hide type column, we use it for "sort by type" only
201 setColumnWidth( 3, 0 ); 203 setColumnWidth( 3, 0 );
202 QListView::resizeEvent( e ); 204 QListView::resizeEvent( e );
203} 205}
204 206
205void FileView::updateDir() 207void FileView::updateDir()
206{ 208{
207 generateDir( currentDir ); 209 generateDir( currentDir );
208} 210}
209 211
210void FileView::setDir( const QString & dir ) 212void FileView::setDir( const QString & dir )
211{ 213{
212 if ( dir.startsWith( "/dev" ) ) { 214 if ( dir.startsWith( "/dev" ) ) {
213 QMessageBox::warning( this, tr( "File Manager" ), 215 QMessageBox::warning( this, tr( "File Manager" ),
214 tr( "Can't show /dev/ directory." ), tr( "&Ok" ) ); 216 tr( "Can't show /dev/ directory." ), tr( "&Ok" ) );
215 return; 217 return;
216 } 218 }
217 dirHistory += currentDir; 219 dirHistory += currentDir;
218 generateDir( dir ); 220 generateDir( dir );
219} 221}
220 222
221void FileView::generateDir( const QString & dir ) 223void FileView::generateDir( const QString & dir )
@@ -357,385 +359,387 @@ void FileView::paste()
357 } else { 359 } else {
358 err = 0; 360 err = 0;
359 } 361 }
360 362
361 if ( err != 0 ) { 363 if ( err != 0 ) {
362 QMessageBox::warning( this, tr("Paste file"), tr("Paste failed!"), 364 QMessageBox::warning( this, tr("Paste file"), tr("Paste failed!"),
363 tr("Ok") ); 365 tr("Ok") );
364 break; 366 break;
365 } else { 367 } else {
366 updateDir(); 368 updateDir();
367 QListViewItem * i = firstChild(); 369 QListViewItem * i = firstChild();
368 basename = dest.mid( dest.findRev("/") + 1, dest.length() ); 370 basename = dest.mid( dest.findRev("/") + 1, dest.length() );
369 371
370 while( i ){ 372 while( i ){
371 if( i->text(0) == basename ){ 373 if( i->text(0) == basename ){
372 setCurrentItem( i ); 374 setCurrentItem( i );
373 ensureItemVisible( i ); 375 ensureItemVisible( i );
374 break; 376 break;
375 } 377 }
376 i = i->nextSibling(); 378 i = i->nextSibling();
377 } 379 }
378 } 380 }
379 } 381 }
380} 382}
381 383
382bool FileView::copyFile( const QString & dest, const QString & src ) 384bool FileView::copyFile( const QString & dest, const QString & src )
383{ 385{
384 char bf[ 50000 ]; 386 char bf[ 50000 ];
385 int bytesRead; 387 int bytesRead;
386 bool success = TRUE; 388 bool success = TRUE;
387 struct stat status; 389 struct stat status;
388 390
389 QFile s( src ); 391 QFile s( src );
390 QFile d( dest ); 392 QFile d( dest );
391 393
392 if( s.open( IO_ReadOnly | IO_Raw ) && 394 if( s.open( IO_ReadOnly | IO_Raw ) &&
393 d.open( IO_WriteOnly | IO_Raw ) ) 395 d.open( IO_WriteOnly | IO_Raw ) )
394 { 396 {
395 while( (bytesRead = s.readBlock( bf, sizeof( bf ) )) == 397 while( (bytesRead = s.readBlock( bf, sizeof( bf ) )) ==
396 sizeof( bf ) ) 398 sizeof( bf ) )
397 { 399 {
398 if( d.writeBlock( bf, sizeof( bf ) ) != sizeof( bf ) ){ 400 if( d.writeBlock( bf, sizeof( bf ) ) != sizeof( bf ) ){
399 success = FALSE; 401 success = FALSE;
400 break; 402 break;
401 } 403 }
402 } 404 }
403 if( success && (bytesRead > 0) ){ 405 if( success && (bytesRead > 0) ){
404 d.writeBlock( bf, bytesRead ); 406 d.writeBlock( bf, bytesRead );
405 } 407 }
406 } else { 408 } else {
407 success = FALSE; 409 success = FALSE;
408 } 410 }
409 411
410 // Set file permissions 412 // Set file permissions
411 if( stat( (const char *) src, &status ) == 0 ){ 413 if( stat( (const char *) src, &status ) == 0 ){
412 chmod( (const char *) dest, status.st_mode ); 414 chmod( (const char *) dest, status.st_mode );
413 } 415 }
414 416
415 return success; 417 return success;
416} 418}
417 419
418void FileView::cut() 420void FileView::cut()
419{ 421{
420 int err; 422 int err;
421 // ##### a better inmplementation might be to rename the CUT file 423 // ##### a better inmplementation might be to rename the CUT file
422 // ##### to ".QPE-FILEBROWSER-MOVING" rather than copying it. 424 // ##### to ".QPE-FILEBROWSER-MOVING" rather than copying it.
423 QString cmd, dest, basename, cd = "/tmp/qpemoving"; 425 QString cmd, dest, basename, cd = "/tmp/qpemoving";
424 QStringList newflist; 426 QStringList newflist;
425 newflist.clear(); 427 newflist.clear();
426 428
427 cmd = "rm -rf " + cd; 429 cmd = "rm -rf " + cd;
428 system ( (const char *) cmd ); 430 system ( (const char *) cmd );
429 cmd = "mkdir " + cd; 431 cmd = "mkdir " + cd;
430 system( (const char *) cmd ); 432 system( (const char *) cmd );
431 433
432// get the names of the files to cut 434// get the names of the files to cut
433 FileItem * item; 435 FileItem * item;
434 436
435 if((item = (FileItem *) firstChild()) == 0) return; 437 if((item = (FileItem *) firstChild()) == 0) return;
436 438
437 flist.clear(); 439 flist.clear();
438 while( item ){ 440 while( item ){
439 if( item->isSelected() /*&& !item->isDir()*/ ){ 441 if( item->isSelected() /*&& !item->isDir()*/ ){
440 flist += item->getFilePath(); 442 flist += item->getFilePath();
441 } 443 }
442 item = (FileItem *) item->nextSibling(); 444 item = (FileItem *) item->nextSibling();
443 } 445 }
444 446
445// move these files into a tmp dir 447// move these files into a tmp dir
446 for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it ) { 448 for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it ) {
447 basename = (*it).mid((*it).findRev("/") + 1, (*it).length()); 449 basename = (*it).mid((*it).findRev("/") + 1, (*it).length());
448 450
449 dest = cd + "/" + basename; 451 dest = cd + "/" + basename;
450 452
451 newflist += dest; 453 newflist += dest;
452 454
453 cmd = "/bin/mv -f \"" + (*it) +"\" " + "\"" + dest + "\""; 455 cmd = "/bin/mv -f \"" + (*it) +"\" " + "\"" + dest + "\"";
454 err = system( (const char *) cmd ); 456 err = system( (const char *) cmd );
455 457
456 if ( err != 0 ) { 458 if ( err != 0 ) {
457 QMessageBox::warning( this, tr("Cut file"), tr("Cut failed!"), 459 QMessageBox::warning( this, tr("Cut file"), tr("Cut failed!"),
458 tr("Ok") ); 460 tr("Ok") );
459 break; 461 break;
460 } else { 462 } else {
461 updateDir(); 463 updateDir();
462 QListViewItem * im = firstChild(); 464 QListViewItem * im = firstChild();
463 basename = dest.mid( dest.findRev("/") + 1, dest.length() ); 465 basename = dest.mid( dest.findRev("/") + 1, dest.length() );
464 466
465 while( im ){ 467 while( im ){
466 if( im->text(0) == basename ){ 468 if( im->text(0) == basename ){
467 setCurrentItem( im ); 469 setCurrentItem( im );
468 ensureItemVisible( im ); 470 ensureItemVisible( im );
469 break; 471 break;
470 } 472 }
471 im = im->nextSibling(); 473 im = im->nextSibling();
472 } 474 }
473 } 475 }
474 } 476 }
475 477
476 // update the filelist to point to tmp dir so paste works nicely 478 // update the filelist to point to tmp dir so paste works nicely
477 flist = newflist; 479 flist = newflist;
478} 480}
479 481
480void FileView::del() 482void FileView::del()
481{ 483{
482 FileItem * i; 484 FileItem * i;
483 QStringList fl; 485 QStringList fl;
484 QString cmd; 486 QString cmd;
485 int err; 487 int err;
486 488
487 if((i = (FileItem *) firstChild()) == 0) return; 489 if((i = (FileItem *) firstChild()) == 0) return;
488 490
489 while( i ){ 491 while( i ){
490 if( i->isSelected() ){ 492 if( i->isSelected() ){
491 fl += i->getFilePath(); 493 fl += i->getFilePath();
492 } 494 }
493 i = (FileItem *) i->nextSibling(); 495 i = (FileItem *) i->nextSibling();
494 } 496 }
495 if( fl.count() < 1 ) return; 497 if( fl.count() < 1 ) return;
496 498
497 if( QMessageBox::warning( this, tr("Delete"), tr("Are you sure?"), 499 if( QMessageBox::warning( this, tr("Delete"), tr("Are you sure?"),
498 tr("Yes"), tr("No") ) == 0) 500 tr("Yes"), tr("No") ) == 0)
499 { 501 {
500 // 502 //
501 // Dependant upon the "rm" command - will probably have to be replaced 503 // Dependant upon the "rm" command - will probably have to be replaced
502 // 504 //
503 for ( QStringList::Iterator it = fl.begin(); it != fl.end(); ++it ) { 505 for ( QStringList::Iterator it = fl.begin(); it != fl.end(); ++it ) {
504 cmd = "/bin/rm -rf \"" + (*it) + "\""; 506 cmd = "/bin/rm -rf \"" + (*it) + "\"";
505 err = system( (const char *) cmd ); 507 err = system( (const char *) cmd );
506 if ( err != 0 ) { 508 if ( err != 0 ) {
507 QMessageBox::warning( this, tr("Delete"), tr("Delete failed!"), 509 QMessageBox::warning( this, tr("Delete"), tr("Delete failed!"),
508 tr("Ok") ); 510 tr("Ok") );
509 break; 511 break;
510 } 512 }
511 } 513 }
512 updateDir(); 514 updateDir();
513 } 515 }
514} 516}
515 517
516void FileView::newFolder() 518void FileView::newFolder()
517{ 519{
518 int t = 1; 520 int t = 1;
519 FileItem * i; 521 FileItem * i;
520 QString nd = currentDir + "/NewFolder"; 522 QString nd = currentDir + "/NewFolder";
521 523
522 while( QFile( nd ).exists() ){ 524 while( QFile( nd ).exists() ){
523 nd.sprintf( "%s/NewFolder (%d)", (const char *) currentDir, t++ ); 525 nd.sprintf( "%s/NewFolder (%d)", (const char *) currentDir, t++ );
524 } 526 }
525 527
526 if( mkdir( (const char *) nd, 0777 ) != 0){ 528 if( mkdir( (const char *) nd, 0777 ) != 0){
527 QMessageBox::warning( this, tr( "New folder" ), 529 QMessageBox::warning( this, tr( "New folder" ),
528 tr( "Folder creation failed!" ), 530 tr( "Folder creation failed!" ),
529 tr( "Ok" ) ); 531 tr( "Ok" ) );
530 return; 532 return;
531 } 533 }
532 updateDir(); 534 updateDir();
533 535
534 if((i = (FileItem *) firstChild()) == 0) return; 536 if((i = (FileItem *) firstChild()) == 0) return;
535 537
536 while( i ){ 538 while( i ){
537 if( i->isDir() && ( i->getFilePath() == nd ) ){ 539 if( i->isDir() && ( i->getFilePath() == nd ) ){
538 setCurrentItem( i ); 540 setCurrentItem( i );
539 rename(); 541 rename();
540 break; 542 break;
541 } 543 }
542 i = (FileItem *) i->nextSibling(); 544 i = (FileItem *) i->nextSibling();
543 } 545 }
544} 546}
545 547
546void FileView::viewAsText() 548void FileView::viewAsText()
547{ 549{
548 FileItem * i = (FileItem *) currentItem(); 550 FileItem * i = (FileItem *) currentItem();
549 Global::execute( "textedit -f ", i->getFilePath() ); 551 QCopEnvelope e("QPE/Application/textedit","setDocument(QString)");
552 e << i->getFilePath();
553// Global::execute( "textedit -f ", i->getFilePath() );
550} 554}
551 555
552void FileView::itemClicked( QListViewItem * i) 556void FileView::itemClicked( QListViewItem * i)
553{ 557{
554 FileItem * t = (FileItem *) i; 558 FileItem * t = (FileItem *) i;
555 559
556 if( t == NULL ) return; 560 if( t == NULL ) return;
557 if( t->isDir() ){ 561 if( t->isDir() ){
558 setDir( t->getFilePath() ); 562 setDir( t->getFilePath() );
559 } 563 }
560} 564}
561 565
562void FileView::itemDblClicked( QListViewItem * i) 566void FileView::itemDblClicked( QListViewItem * i)
563{ 567{
564 FileItem * t = (FileItem *) i; 568 FileItem * t = (FileItem *) i;
565 569
566 if(t == NULL) return; 570 if(t == NULL) return;
567 if(t->launch() == -1){ 571 if(t->launch() == -1){
568 QMessageBox::warning( this, tr( "Launch Application" ), 572 QMessageBox::warning( this, tr( "Launch Application" ),
569 tr( "Launch failed!" ), tr( "Ok" ) ); 573 tr( "Launch failed!" ), tr( "Ok" ) );
570 } 574 }
571} 575}
572 576
573void FileView::parentDir() 577void FileView::parentDir()
574{ 578{
575 setDir( currentDir + "./.." ); 579 setDir( currentDir + "./.." );
576} 580}
577 581
578void FileView::lastDir() 582void FileView::lastDir()
579{ 583{
580 if( dirHistory.count() == 0 ) return; 584 if( dirHistory.count() == 0 ) return;
581 585
582 QString newDir = dirHistory.last(); 586 QString newDir = dirHistory.last();
583 dirHistory.remove( dirHistory.last() ); 587 dirHistory.remove( dirHistory.last() );
584 generateDir( newDir ); 588 generateDir( newDir );
585} 589}
586 590
587void FileView::contentsMousePressEvent( QMouseEvent * e ) 591void FileView::contentsMousePressEvent( QMouseEvent * e )
588{ 592{
589 QListView::contentsMousePressEvent( e ); 593 QListView::contentsMousePressEvent( e );
590 menuTimer.start( 750, TRUE ); 594 menuTimer.start( 750, TRUE );
591} 595}
592 596
593void FileView::contentsMouseReleaseEvent( QMouseEvent * e ) 597void FileView::contentsMouseReleaseEvent( QMouseEvent * e )
594{ 598{
595 QListView::contentsMouseReleaseEvent( e ); 599 QListView::contentsMouseReleaseEvent( e );
596 menuTimer.stop(); 600 menuTimer.stop();
597} 601}
598 602
599void FileView::cancelMenuTimer() 603void FileView::cancelMenuTimer()
600{ 604{
601 if( menuTimer.isActive() ) 605 if( menuTimer.isActive() )
602 menuTimer.stop(); 606 menuTimer.stop();
603} 607}
604 608
605void FileView::addToDocuments() 609void FileView::addToDocuments()
606{ 610{
607 FileItem * i = (FileItem *) currentItem(); 611 FileItem * i = (FileItem *) currentItem();
608 DocLnk f; 612 DocLnk f;
609 QString n = i->text(0); 613 QString n = i->text(0);
610 n.replace(QRegExp("\\..*"),""); 614 n.replace(QRegExp("\\..*"),"");
611 f.setName( n ); 615 f.setName( n );
612 f.setFile( i->getFilePath() ); 616 f.setFile( i->getFilePath() );
613 f.writeLink(); 617 f.writeLink();
614} 618}
615 619
616void FileView::run() 620void FileView::run()
617{ 621{
618 FileItem * i = (FileItem *) currentItem(); 622 FileItem * i = (FileItem *) currentItem();
619 i->launch(); 623 i->launch();
620} 624}
621 625
622void FileView::showFileMenu() 626void FileView::showFileMenu()
623{ 627{
624 FileItem * i = (FileItem *) currentItem(); 628 FileItem * i = (FileItem *) currentItem();
625 if ( !i ) 629 if ( !i )
626 return; 630 return;
627 631
628 QPopupMenu * m = new QPopupMenu( this ); 632 QPopupMenu * m = new QPopupMenu( this );
629 633
630 if ( !i->isDir() ) { 634 if ( !i->isDir() ) {
631 m->insertItem( tr( "Add to Documents" ), this, SLOT( addToDocuments() ) ); 635 m->insertItem( tr( "Add to Documents" ), this, SLOT( addToDocuments() ) );
632 m->insertSeparator(); 636 m->insertSeparator();
633 } 637 }
634 638
635 MimeType mt(i->getFilePath()); 639 MimeType mt(i->getFilePath());
636 const AppLnk* app = mt.application(); 640 const AppLnk* app = mt.application();
637 641
638 if ( !i->isDir() ) { 642 if ( !i->isDir() ) {
639 if ( app ) 643 if ( app )
640 m->insertItem( app->pixmap(), tr( "Open in " + app->name() ), this, SLOT( run() ) ); 644 m->insertItem( app->pixmap(), tr( "Open in " + app->name() ), this, SLOT( run() ) );
641 else if( i->isExecutable() ) 645 else if( i->isExecutable() )
642 m->insertItem( Resource::loadPixmap( i->text( 0 ) ), tr( "Run" ), this, SLOT( run() ) ); 646 m->insertItem( Resource::loadPixmap( i->text( 0 ) ), tr( "Run" ), this, SLOT( run() ) );
643 647
644 m->insertItem( Resource::loadPixmap( "txt" ), tr( "View as text" ), 648 m->insertItem( Resource::loadPixmap( "txt" ), tr( "View as text" ),
645 this, SLOT( viewAsText() ) ); 649 this, SLOT( viewAsText() ) );
646 650
647 m->insertSeparator(); 651 m->insertSeparator();
648 } 652 }
649 653
650 m->insertItem( tr( "Rename" ), this, SLOT( rename() ) ); 654 m->insertItem( tr( "Rename" ), this, SLOT( rename() ) );
651 m->insertItem( Resource::loadPixmap("cut"), 655 m->insertItem( Resource::loadPixmap("cut"),
652 tr( "Cut" ), this, SLOT( cut() ) ); 656 tr( "Cut" ), this, SLOT( cut() ) );
653 m->insertItem( Resource::loadPixmap("copy"), 657 m->insertItem( Resource::loadPixmap("copy"),
654 tr( "Copy" ), this, SLOT( copy() ) ); 658 tr( "Copy" ), this, SLOT( copy() ) );
655 m->insertItem( Resource::loadPixmap("paste"), 659 m->insertItem( Resource::loadPixmap("paste"),
656 tr( "Paste" ), this, SLOT( paste() ) ); 660 tr( "Paste" ), this, SLOT( paste() ) );
657 m->insertItem( tr( "Change Permissions" ), this, SLOT( chPerm() ) ); 661 m->insertItem( tr( "Change Permissions" ), this, SLOT( chPerm() ) );
658 m->insertItem( tr( "Delete" ), this, SLOT( del() ) ); 662 m->insertItem( tr( "Delete" ), this, SLOT( del() ) );
659 m->insertSeparator(); 663 m->insertSeparator();
660 m->insertItem( tr( "Select all" ), this, SLOT( selectAll() ) ); 664 m->insertItem( tr( "Select all" ), this, SLOT( selectAll() ) );
661 m->insertItem( tr( "Deselect all" ), this, SLOT( deselectAll() ) ); 665 m->insertItem( tr( "Deselect all" ), this, SLOT( deselectAll() ) );
662 m->popup( QCursor::pos() ); 666 m->popup( QCursor::pos() );
663} 667}
664 668
665// 669//
666// FileBrowser 670// FileBrowser
667// 671//
668 672
669FileBrowser::FileBrowser( QWidget * parent, 673FileBrowser::FileBrowser( QWidget * parent,
670 const char * name, WFlags f ) : 674 const char * name, WFlags f ) :
671 QMainWindow( parent, name, f ) 675 QMainWindow( parent, name, f )
672{ 676{
673 init( QDir::current().canonicalPath() ); 677 init( QDir::current().canonicalPath() );
674} 678}
675 679
676FileBrowser::FileBrowser( const QString & dir, QWidget * parent, 680FileBrowser::FileBrowser( const QString & dir, QWidget * parent,
677 const char * name, WFlags f ) : 681 const char * name, WFlags f ) :
678 QMainWindow( parent, name, f ) 682 QMainWindow( parent, name, f )
679{ 683{
680 init( dir ); 684 init( dir );
681} 685}
682 686
683void FileBrowser::init(const QString & dir) 687void FileBrowser::init(const QString & dir)
684{ 688{
685 setCaption( tr("File Manager") ); 689 setCaption( tr("File Manager") );
686 setIcon( Resource::loadPixmap( "filebrowser_icon" ) ); 690 setIcon( Resource::loadPixmap( "filebrowser_icon" ) );
687 691
688 fileView = new FileView( dir, this ); 692 fileView = new FileView( dir, this );
689 fileView->setAllColumnsShowFocus( TRUE ); 693 fileView->setAllColumnsShowFocus( TRUE );
690 694
691 setCentralWidget( fileView ); 695 setCentralWidget( fileView );
692 setToolBarsMovable( FALSE ); 696 setToolBarsMovable( FALSE );
693 697
694 QPEToolBar* toolBar = new QPEToolBar( this ); 698 QPEToolBar* toolBar = new QPEToolBar( this );
695 toolBar->setHorizontalStretchable( TRUE ); 699 toolBar->setHorizontalStretchable( TRUE );
696 700
697 QPEMenuBar* menuBar = new QPEMenuBar( toolBar ); 701 QPEMenuBar* menuBar = new QPEMenuBar( toolBar );
698 702
699 dirMenu = new QPopupMenu( this ); 703 dirMenu = new QPopupMenu( this );
700 menuBar->insertItem( tr( "Dir" ), dirMenu ); 704 menuBar->insertItem( tr( "Dir" ), dirMenu );
701 705
702 sortMenu = new QPopupMenu( this ); 706 sortMenu = new QPopupMenu( this );
703 menuBar->insertItem( tr( "Sort" ), sortMenu ); 707 menuBar->insertItem( tr( "Sort" ), sortMenu );
704 sortMenu->insertItem( tr( "by Name "), this, SLOT( sortName() ) ); 708 sortMenu->insertItem( tr( "by Name "), this, SLOT( sortName() ) );
705 sortMenu->insertItem( tr( "by Size "), this, SLOT( sortSize() ) ); 709 sortMenu->insertItem( tr( "by Size "), this, SLOT( sortSize() ) );
706 sortMenu->insertItem( tr( "by Date "), this, SLOT( sortDate() ) ); 710 sortMenu->insertItem( tr( "by Date "), this, SLOT( sortDate() ) );
707 sortMenu->insertItem( tr( "by Type "), this, SLOT( sortType() ) ); 711 sortMenu->insertItem( tr( "by Type "), this, SLOT( sortType() ) );
708 sortMenu->insertSeparator(); 712 sortMenu->insertSeparator();
709 sortMenu->insertItem( tr( "Ascending" ), this, SLOT( updateSorting() ) ); 713 sortMenu->insertItem( tr( "Ascending" ), this, SLOT( updateSorting() ) );
710 sortMenu->setItemChecked( sortMenu->idAt( 5 ), TRUE ); 714 sortMenu->setItemChecked( sortMenu->idAt( 5 ), TRUE );
711 sortMenu->setItemChecked( sortMenu->idAt( 0 ), TRUE ); 715 sortMenu->setItemChecked( sortMenu->idAt( 0 ), TRUE );
712 716
713 toolBar = new QPEToolBar( this ); 717 toolBar = new QPEToolBar( this );
714 718
715 lastAction = new QAction( tr("Previous dir"), Resource::loadIconSet( "back" ), 719 lastAction = new QAction( tr("Previous dir"), Resource::loadIconSet( "back" ),
716 QString::null, 0, this, 0 ); 720 QString::null, 0, this, 0 );
717 connect( lastAction, SIGNAL( activated() ), fileView, SLOT( lastDir() ) ); 721 connect( lastAction, SIGNAL( activated() ), fileView, SLOT( lastDir() ) );
718 lastAction->addTo( toolBar ); 722 lastAction->addTo( toolBar );
719 lastAction->setEnabled( FALSE ); 723 lastAction->setEnabled( FALSE );
720 724
721 upAction = new QAction( tr("Parent dir"), Resource::loadIconSet( "up" ), 725 upAction = new QAction( tr("Parent dir"), Resource::loadIconSet( "up" ),
722 QString::null, 0, this, 0 ); 726 QString::null, 0, this, 0 );
723 connect( upAction, SIGNAL( activated() ), fileView, SLOT( parentDir() ) ); 727 connect( upAction, SIGNAL( activated() ), fileView, SLOT( parentDir() ) );
724 upAction->addTo( toolBar ); 728 upAction->addTo( toolBar );
725 729
726 QAction *a = new QAction( tr("New folder"), Resource::loadPixmap( "newfolder" ), 730 QAction *a = new QAction( tr("New folder"), Resource::loadPixmap( "newfolder" ),
727 QString::null, 0, this, 0 ); 731 QString::null, 0, this, 0 );
728 connect( a, SIGNAL( activated() ), fileView, SLOT( newFolder() ) ); 732 connect( a, SIGNAL( activated() ), fileView, SLOT( newFolder() ) );
729 a->addTo( toolBar ); 733 a->addTo( toolBar );
730 734
731 a = new QAction( tr("Cut"), Resource::loadPixmap( "cut" ), 735 a = new QAction( tr("Cut"), Resource::loadPixmap( "cut" ),
732 QString::null, 0, this, 0 ); 736 QString::null, 0, this, 0 );
733 connect( a, SIGNAL( activated() ), fileView, SLOT( cut() ) ); 737 connect( a, SIGNAL( activated() ), fileView, SLOT( cut() ) );
734 a->addTo( toolBar ); 738 a->addTo( toolBar );
735 739
736 a = new QAction( tr("Copy"), Resource::loadPixmap( "copy" ), 740 a = new QAction( tr("Copy"), Resource::loadPixmap( "copy" ),
737 QString::null, 0, this, 0 ); 741 QString::null, 0, this, 0 );
738 connect( a, SIGNAL( activated() ), fileView, SLOT( copy() ) ); 742 connect( a, SIGNAL( activated() ), fileView, SLOT( copy() ) );
739 a->addTo( toolBar ); 743 a->addTo( toolBar );
740 744
741 pasteAction = new QAction( tr("Paste"), Resource::loadPixmap( "paste" ), 745 pasteAction = new QAction( tr("Paste"), Resource::loadPixmap( "paste" ),