summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/unsupported/filebrowser/filebrowser.cpp2
-rw-r--r--noncore/unsupported/filebrowser/opie-filebrowser.control2
-rw-r--r--pics/filebrowser/symlink.png (renamed from pics/symlink.png)bin103 -> 103 bytes
3 files changed, 2 insertions, 2 deletions
diff --git a/noncore/unsupported/filebrowser/filebrowser.cpp b/noncore/unsupported/filebrowser/filebrowser.cpp
index 34d5177..d9e2afa 100644
--- a/noncore/unsupported/filebrowser/filebrowser.cpp
+++ b/noncore/unsupported/filebrowser/filebrowser.cpp
@@ -1,983 +1,983 @@
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#include <qpe/config.h> 28#include <qpe/config.h>
29 29
30#include <qcopchannel_qws.h> 30#include <qcopchannel_qws.h>
31#include <qpe/qcopenvelope_qws.h> 31#include <qpe/qcopenvelope_qws.h>
32 32
33#include <qmessagebox.h> 33#include <qmessagebox.h>
34#include <qdir.h> 34#include <qdir.h>
35#include <qregexp.h> 35#include <qregexp.h>
36#include <qheader.h> 36#include <qheader.h>
37#include <qpe/qpetoolbar.h> 37#include <qpe/qpetoolbar.h>
38#include <qpopupmenu.h> 38#include <qpopupmenu.h>
39#include <qpe/qpemenubar.h> 39#include <qpe/qpemenubar.h>
40#include <qaction.h> 40#include <qaction.h>
41#include <qstringlist.h> 41#include <qstringlist.h>
42#include <qcursor.h> 42#include <qcursor.h>
43#include <qmultilineedit.h> 43#include <qmultilineedit.h>
44#include <qfont.h> 44#include <qfont.h>
45 45
46#include <unistd.h> 46#include <unistd.h>
47#include <stdlib.h> 47#include <stdlib.h>
48#include <sys/stat.h> 48#include <sys/stat.h>
49 49
50// 50//
51// FileItem 51// FileItem
52// 52//
53FileItem::FileItem( QListView * parent, const QFileInfo & fi ) 53FileItem::FileItem( QListView * parent, const QFileInfo & fi )
54 : QListViewItem( parent ), 54 : QListViewItem( parent ),
55 fileInfo( fi ) 55 fileInfo( fi )
56{ 56{
57 QDate d = fi.lastModified().date(); 57 QDate d = fi.lastModified().date();
58 58
59 setText( 0, fi.fileName() ); 59 setText( 0, fi.fileName() );
60 setText( 1, sizeString( fi.size() ) + " " ); 60 setText( 1, sizeString( fi.size() ) + " " );
61 setText( 2, QString().sprintf("%4d-%02d-%02d",d.year(), d.month(), d.day() ) ); 61 setText( 2, QString().sprintf("%4d-%02d-%02d",d.year(), d.month(), d.day() ) );
62 62
63 MimeType mt(fi.filePath()); 63 MimeType mt(fi.filePath());
64 64
65 if ( fi.isSymLink() ) 65 if ( fi.isSymLink() )
66 setText( 3, "symlink" ); 66 setText( 3, "symlink" );
67 else if( fi.isDir() ) 67 else if( fi.isDir() )
68 setText( 3, "directory" ); 68 setText( 3, "directory" );
69 else if( isLib() ) 69 else if( isLib() )
70 setText( 3, "library" ); 70 setText( 3, "library" );
71 else 71 else
72 setText( 3, mt.description() ); 72 setText( 3, mt.description() );
73 73
74 QPixmap pm; 74 QPixmap pm;
75 if( fi.isDir() ){ 75 if( fi.isDir() ){
76 if( !QDir( fi.filePath() ).isReadable() ) 76 if( !QDir( fi.filePath() ).isReadable() )
77 pm = Resource::loadPixmap( "lockedfolder" ); 77 pm = Resource::loadPixmap( "lockedfolder" );
78 else 78 else
79 pm = Resource::loadPixmap( "folder" ); 79 pm = Resource::loadPixmap( "folder" );
80 } 80 }
81 else if( !fi.isReadable() ) 81 else if( !fi.isReadable() )
82 pm = Resource::loadPixmap( "locked" ); 82 pm = Resource::loadPixmap( "locked" );
83 else if( isLib() ) 83 else if( isLib() )
84 pm = Resource::loadPixmap( "library" ); 84 pm = Resource::loadPixmap( "library" );
85 else 85 else
86 pm = mt.pixmap(); 86 pm = mt.pixmap();
87 if ( pm.isNull() ) 87 if ( pm.isNull() )
88 pm = Resource::loadPixmap("UnknownDocument-14"); 88 pm = Resource::loadPixmap("UnknownDocument-14");
89 if( fi.isSymLink() ){ 89 if( fi.isSymLink() ){
90 // overlay link image 90 // overlay link image
91 QPixmap lnk = Resource::loadPixmap( "symlink" ); 91 QPixmap lnk = Resource::loadPixmap( "filebrowser/symlink" );
92 QPainter painter( &pm ); 92 QPainter painter( &pm );
93 painter.drawPixmap( pm.width()-lnk.width(), pm.height()-lnk.height(), lnk ); 93 painter.drawPixmap( pm.width()-lnk.width(), pm.height()-lnk.height(), lnk );
94 pm.setMask( pm.createHeuristicMask( FALSE ) ); 94 pm.setMask( pm.createHeuristicMask( FALSE ) );
95 } 95 }
96 setPixmap(0,pm); 96 setPixmap(0,pm);
97} 97}
98 98
99QString FileItem::sizeString( unsigned int s ) 99QString FileItem::sizeString( unsigned int s )
100{ 100{
101 double size = s; 101 double size = s;
102 102
103 if ( size > 1024 * 1024 * 1024 ) 103 if ( size > 1024 * 1024 * 1024 )
104 return QString().sprintf( "%.1f", size / ( 1024 * 1024 * 1024 ) ) + "G"; 104 return QString().sprintf( "%.1f", size / ( 1024 * 1024 * 1024 ) ) + "G";
105 else if ( size > 1024 * 1024 ) 105 else if ( size > 1024 * 1024 )
106 return QString().sprintf( "%.1f", size / ( 1024 * 1024 ) ) + "M"; 106 return QString().sprintf( "%.1f", size / ( 1024 * 1024 ) ) + "M";
107 else if ( size > 1024 ) 107 else if ( size > 1024 )
108 return QString().sprintf( "%.1f", size / ( 1024 ) ) + "K"; 108 return QString().sprintf( "%.1f", size / ( 1024 ) ) + "K";
109 else 109 else
110 return QString::number( size ) + "B"; 110 return QString::number( size ) + "B";
111} 111}
112 112
113QString FileItem::key( int column, bool ascending ) const 113QString FileItem::key( int column, bool ascending ) const
114{ 114{
115 QString tmp; 115 QString tmp;
116 116
117 ascending = ascending; 117 ascending = ascending;
118 118
119 if( (column == 0) && fileInfo.isDir() ){ // Sort by name 119 if( (column == 0) && fileInfo.isDir() ){ // Sort by name
120 // We want the directories to appear at the top of the list 120 // We want the directories to appear at the top of the list
121 tmp = (char) 0; 121 tmp = (char) 0;
122 return (tmp + text( column ).lower()); 122 return (tmp + text( column ).lower());
123 } 123 }
124 else if( column == 2 ) { // Sort by date 124 else if( column == 2 ) { // Sort by date
125 QDateTime epoch( QDate( 1980, 1, 1 ) ); 125 QDateTime epoch( QDate( 1980, 1, 1 ) );
126 tmp.sprintf( "%08d", epoch.secsTo( fileInfo.lastModified() ) ); 126 tmp.sprintf( "%08d", epoch.secsTo( fileInfo.lastModified() ) );
127 return tmp; 127 return tmp;
128 } 128 }
129 else if( column == 1 ) { // Sort by size 129 else if( column == 1 ) { // Sort by size
130 return tmp.sprintf( "%08d", fileInfo.size() ); 130 return tmp.sprintf( "%08d", fileInfo.size() );
131 } 131 }
132 132
133 return text( column ).lower(); 133 return text( column ).lower();
134} 134}
135 135
136bool FileItem::isLib() 136bool FileItem::isLib()
137{ 137{
138 // This is of course not foolproof 138 // This is of course not foolproof
139 if( !qstrncmp("lib", fileInfo.baseName(), 3) && 139 if( !qstrncmp("lib", fileInfo.baseName(), 3) &&
140 ( fileInfo.extension().contains( "so" ) || 140 ( fileInfo.extension().contains( "so" ) ||
141 fileInfo.extension().contains( "a" ) ) ) 141 fileInfo.extension().contains( "a" ) ) )
142 return TRUE; 142 return TRUE;
143 else 143 else
144 return FALSE; 144 return FALSE;
145} 145}
146 146
147int FileItem::launch() 147int FileItem::launch()
148{ 148{
149 DocLnk doc( fileInfo.filePath(), FALSE ); 149 DocLnk doc( fileInfo.filePath(), FALSE );
150 doc.execute(); 150 doc.execute();
151 listView()->clearSelection(); 151 listView()->clearSelection();
152 return 1; 152 return 1;
153} 153}
154 154
155bool FileItem::rename( const QString & name ) 155bool FileItem::rename( const QString & name )
156{ 156{
157 QString oldpath, newpath; 157 QString oldpath, newpath;
158 158
159 if ( name.isEmpty() ) 159 if ( name.isEmpty() )
160 return FALSE; 160 return FALSE;
161 161
162 if ( name.contains( QRegExp("[/\\$\"\'\\*\\?]") ) ) 162 if ( name.contains( QRegExp("[/\\$\"\'\\*\\?]") ) )
163 return FALSE; 163 return FALSE;
164 164
165 oldpath = fileInfo.filePath(); 165 oldpath = fileInfo.filePath();
166 newpath = fileInfo.dirPath() + "/" + name; 166 newpath = fileInfo.dirPath() + "/" + name;
167 167
168 if ( ::rename( (const char *) oldpath, (const char *) newpath ) != 0 ) 168 if ( ::rename( (const char *) oldpath, (const char *) newpath ) != 0 )
169 return FALSE; 169 return FALSE;
170 else 170 else
171 return TRUE; 171 return TRUE;
172} 172}
173 173
174// 174//
175// FileView 175// FileView
176// 176//
177FileView::FileView( const QString & dir, QWidget * parent, 177FileView::FileView( const QString & dir, QWidget * parent,
178 const char * name, 178 const char * name,
179 bool hidden, bool symlinks ) 179 bool hidden, bool symlinks )
180 : QListView( parent, name ), 180 : QListView( parent, name ),
181 menuTimer( this ), 181 menuTimer( this ),
182 le( NULL ), 182 le( NULL ),
183 itemToRename( NULL ), 183 itemToRename( NULL ),
184 showHidden( hidden ), 184 showHidden( hidden ),
185 showSymlinks( symlinks), 185 showSymlinks( symlinks),
186 menuKeepsOpen( FALSE ) 186 menuKeepsOpen( FALSE )
187{ 187{
188 addColumn( "Name" ); 188 addColumn( "Name" );
189 addColumn( "Date" ); 189 addColumn( "Date" );
190 addColumn( "Size" ); 190 addColumn( "Size" );
191 addColumn( "Type" ); 191 addColumn( "Type" );
192 192
193 setMultiSelection( TRUE ); 193 setMultiSelection( TRUE );
194 //header()->hide(); 194 //header()->hide();
195 195
196 setColumnWidthMode( 0, Manual ); 196 setColumnWidthMode( 0, Manual );
197 setColumnWidthMode( 3, Manual ); 197 setColumnWidthMode( 3, Manual );
198 198
199 // right align yize column 199 // right align yize column
200 setColumnAlignment( 1, AlignRight ); 200 setColumnAlignment( 1, AlignRight );
201 201
202 generateDir( dir ); 202 generateDir( dir );
203 203
204 connect( this, SIGNAL( clicked( QListViewItem * )), 204 connect( this, SIGNAL( clicked( QListViewItem * )),
205 SLOT( itemClicked( QListViewItem * )) ); 205 SLOT( itemClicked( QListViewItem * )) );
206 connect( this, SIGNAL( doubleClicked( QListViewItem * )), 206 connect( this, SIGNAL( doubleClicked( QListViewItem * )),
207 SLOT( itemDblClicked( QListViewItem * )) ); 207 SLOT( itemDblClicked( QListViewItem * )) );
208 connect( this, SIGNAL( selectionChanged() ), SLOT( cancelMenuTimer() ) ); 208 connect( this, SIGNAL( selectionChanged() ), SLOT( cancelMenuTimer() ) );
209 connect( &menuTimer, SIGNAL( timeout() ), SLOT( showFileMenu() ) ); 209 connect( &menuTimer, SIGNAL( timeout() ), SLOT( showFileMenu() ) );
210} 210}
211 211
212void FileView::resizeEvent( QResizeEvent *e ) 212void FileView::resizeEvent( QResizeEvent *e )
213{ 213{
214 setColumnWidth( 0, width() - 2 * lineWidth() - 20 - columnWidth( 1 ) - columnWidth( 2 ) ); 214 setColumnWidth( 0, width() - 2 * lineWidth() - 20 - columnWidth( 1 ) - columnWidth( 2 ) );
215 215
216 // hide type column, we use it for "sort by type" only 216 // hide type column, we use it for "sort by type" only
217 //setColumnWidth( 3, 0 ); 217 //setColumnWidth( 3, 0 );
218 QListView::resizeEvent( e ); 218 QListView::resizeEvent( e );
219} 219}
220 220
221void FileView::updateDir() 221void FileView::updateDir()
222{ 222{
223 generateDir( currentDir ); 223 generateDir( currentDir );
224} 224}
225 225
226void FileView::setDir( const QString & dir ) 226void FileView::setDir( const QString & dir )
227{ 227{
228 if ( dir.startsWith( "/dev" ) ) { 228 if ( dir.startsWith( "/dev" ) ) {
229 QMessageBox::warning( this, tr( "File Manager" ), 229 QMessageBox::warning( this, tr( "File Manager" ),
230 tr( "Can't show /dev/ directory." ), tr( "&Ok" ) ); 230 tr( "Can't show /dev/ directory." ), tr( "&Ok" ) );
231 return; 231 return;
232 } 232 }
233 dirHistory += currentDir; 233 dirHistory += currentDir;
234 generateDir( dir ); 234 generateDir( dir );
235} 235}
236 236
237void FileView::generateDir( const QString & dir ) 237void FileView::generateDir( const QString & dir )
238{ 238{
239 if(menuKeepsOpen){ 239 if(menuKeepsOpen){
240 cancelMenuTimer(); 240 cancelMenuTimer();
241 } 241 }
242 QDir d( dir ); 242 QDir d( dir );
243 243
244 if( d.exists() && !d.isReadable() ) return; 244 if( d.exists() && !d.isReadable() ) return;
245 245
246 currentDir = d.canonicalPath(); 246 currentDir = d.canonicalPath();
247 247
248 if( !showHidden) 248 if( !showHidden)
249 d.setFilter( QDir::Dirs | QDir::Files ); 249 d.setFilter( QDir::Dirs | QDir::Files );
250 else 250 else
251 d.setFilter( QDir::Dirs | QDir::Files |QDir::Hidden | QDir::All); 251 d.setFilter( QDir::Dirs | QDir::Files |QDir::Hidden | QDir::All);
252 252
253 d.setSorting( QDir::Name | QDir::DirsFirst | QDir::IgnoreCase | QDir::Reversed ); 253 d.setSorting( QDir::Name | QDir::DirsFirst | QDir::IgnoreCase | QDir::Reversed );
254 254
255 255
256 const QFileInfoList * list = d.entryInfoList(); 256 const QFileInfoList * list = d.entryInfoList();
257 QFileInfoListIterator it( *list ); 257 QFileInfoListIterator it( *list );
258 QFileInfo *fi; 258 QFileInfo *fi;
259 259
260 clear(); 260 clear();
261 while( (fi = it.current()) ){ 261 while( (fi = it.current()) ){
262 if( (fi->fileName() == ".") || (fi->fileName() == "..") ){ 262 if( (fi->fileName() == ".") || (fi->fileName() == "..") ){
263 ++it; 263 ++it;
264 continue; 264 continue;
265 } 265 }
266 if(!showSymlinks && fi->isSymLink()){ 266 if(!showSymlinks && fi->isSymLink()){
267 ++it; 267 ++it;
268 continue; 268 continue;
269 } 269 }
270 (void) new FileItem( (QListView *) this, *fi ); 270 (void) new FileItem( (QListView *) this, *fi );
271 ++it; 271 ++it;
272 } 272 }
273 emit dirChanged(); 273 emit dirChanged();
274} 274}
275 275
276void FileView::rename() 276void FileView::rename()
277{ 277{
278 itemToRename = (FileItem *) currentItem(); 278 itemToRename = (FileItem *) currentItem();
279 const QPixmap * pm; 279 const QPixmap * pm;
280 int pmw; 280 int pmw;
281 281
282 if( itemToRename == NULL ) return; 282 if( itemToRename == NULL ) return;
283 283
284 if( ( pm = itemToRename->pixmap( 0 ) ) == NULL ) 284 if( ( pm = itemToRename->pixmap( 0 ) ) == NULL )
285 pmw = 0; 285 pmw = 0;
286 else 286 else
287 pmw = pm->width(); 287 pmw = pm->width();
288 288
289 ensureItemVisible( itemToRename ); 289 ensureItemVisible( itemToRename );
290 horizontalScrollBar()->setValue( 0 ); 290 horizontalScrollBar()->setValue( 0 );
291 horizontalScrollBar()->setEnabled( FALSE ); 291 horizontalScrollBar()->setEnabled( FALSE );
292 verticalScrollBar()->setEnabled( FALSE ); 292 verticalScrollBar()->setEnabled( FALSE );
293 293
294 selected = isSelected( itemToRename ); 294 selected = isSelected( itemToRename );
295 setSelected( itemToRename, FALSE ); 295 setSelected( itemToRename, FALSE );
296 296
297 if( le == NULL ){ 297 if( le == NULL ){
298 le = new InlineEdit( this ); 298 le = new InlineEdit( this );
299 le->setFrame( FALSE ); 299 le->setFrame( FALSE );
300 connect( le, SIGNAL( lostFocus() ), SLOT( endRenaming() ) ); 300 connect( le, SIGNAL( lostFocus() ), SLOT( endRenaming() ) );
301 } 301 }
302 302
303 QRect r = itemRect( itemToRename ); 303 QRect r = itemRect( itemToRename );
304 r.setTop( r.top() + frameWidth() + 1 ); 304 r.setTop( r.top() + frameWidth() + 1 );
305 r.setLeft( r.left() + frameWidth() + pmw ); 305 r.setLeft( r.left() + frameWidth() + pmw );
306 r.setBottom( r.bottom() + frameWidth() ); 306 r.setBottom( r.bottom() + frameWidth() );
307 r.setWidth( columnWidth( 0 ) - pmw ); 307 r.setWidth( columnWidth( 0 ) - pmw );
308 308
309 le->setGeometry( r ); 309 le->setGeometry( r );
310 le->setText( itemToRename->text( 0 ) ); 310 le->setText( itemToRename->text( 0 ) );
311 le->selectAll(); 311 le->selectAll();
312 le->show(); 312 le->show();
313 le->setFocus(); 313 le->setFocus();
314} 314}
315 315
316void FileView::endRenaming() 316void FileView::endRenaming()
317{ 317{
318 if( le && itemToRename ){ 318 if( le && itemToRename ){
319 le->hide(); 319 le->hide();
320 setSelected( itemToRename, selected ); 320 setSelected( itemToRename, selected );
321 321
322 if( !itemToRename->rename( le->text() ) ){ 322 if( !itemToRename->rename( le->text() ) ){
323 QMessageBox::warning( this, tr( "Rename file" ), 323 QMessageBox::warning( this, tr( "Rename file" ),
324 tr( "Rename failed!" ), tr( "&Ok" ) ); 324 tr( "Rename failed!" ), tr( "&Ok" ) );
325 } else { 325 } else {
326 updateDir(); 326 updateDir();
327 } 327 }
328 itemToRename = NULL; 328 itemToRename = NULL;
329 horizontalScrollBar()->setEnabled( TRUE ); 329 horizontalScrollBar()->setEnabled( TRUE );
330 verticalScrollBar()->setEnabled( TRUE ); 330 verticalScrollBar()->setEnabled( TRUE );
331 } 331 }
332} 332}
333 333
334void FileView::copy() 334void FileView::copy()
335{ 335{
336 // dont keep cut files any longer than necessary 336 // dont keep cut files any longer than necessary
337 // ##### a better inmplementation might be to rename the CUT file 337 // ##### a better inmplementation might be to rename the CUT file
338 // ##### to ".QPE-FILEBROWSER-MOVING" rather than copying it. 338 // ##### to ".QPE-FILEBROWSER-MOVING" rather than copying it.
339 system ( "rm -rf /tmp/qpemoving" ); 339 system ( "rm -rf /tmp/qpemoving" );
340 340
341 FileItem * i; 341 FileItem * i;
342 342
343 if((i = (FileItem *) firstChild()) == 0) return; 343 if((i = (FileItem *) firstChild()) == 0) return;
344 344
345 flist.clear(); 345 flist.clear();
346 while( i ){ 346 while( i ){
347 if( i->isSelected() /*&& !i->isDir()*/ ){ 347 if( i->isSelected() /*&& !i->isDir()*/ ){
348 flist += i->getFilePath(); 348 flist += i->getFilePath();
349 } 349 }
350 i = (FileItem *) i->nextSibling(); 350 i = (FileItem *) i->nextSibling();
351 } 351 }
352} 352}
353 353
354void FileView::paste() 354void FileView::paste()
355{ 355{
356 int i, err; 356 int i, err;
357 QString cmd, dest, basename, cd = currentDir; 357 QString cmd, dest, basename, cd = currentDir;
358 358
359 if(cd == "/") cd = ""; 359 if(cd == "/") cd = "";
360 360
361 for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it ) { 361 for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it ) {
362 basename = (*it).mid((*it).findRev("/") + 1, (*it).length()); 362 basename = (*it).mid((*it).findRev("/") + 1, (*it).length());
363 363
364 dest = cd + "/" + basename; 364 dest = cd + "/" + basename;
365 if( QFile( dest ).exists() ){ 365 if( QFile( dest ).exists() ){
366 i = 1; 366 i = 1;
367 dest = cd + "/Copy of " + basename; 367 dest = cd + "/Copy of " + basename;
368 while( QFile( dest ).exists() ){ 368 while( QFile( dest ).exists() ){
369 dest.sprintf( "%s/Copy (%d) of %s", (const char *) cd, i++, 369 dest.sprintf( "%s/Copy (%d) of %s", (const char *) cd, i++,
370 (const char *) basename ); 370 (const char *) basename );
371 } 371 }
372 } 372 }
373 373
374 // 374 //
375 // Copy a directory recursively using the "cp" command - 375 // Copy a directory recursively using the "cp" command -
376 // may have to be changed 376 // may have to be changed
377 // 377 //
378 if( QFileInfo( (*it) ).isDir() ){ 378 if( QFileInfo( (*it) ).isDir() ){
379 cmd = "/bin/cp -fpR \"" + (*it) +"\" " + "\"" + dest + "\""; 379 cmd = "/bin/cp -fpR \"" + (*it) +"\" " + "\"" + dest + "\"";
380 err = system( (const char *) cmd ); 380 err = system( (const char *) cmd );
381 } else if( !copyFile( dest, (*it) ) ){ 381 } else if( !copyFile( dest, (*it) ) ){
382 err = -1; 382 err = -1;
383 } else { 383 } else {
384 err = 0; 384 err = 0;
385 } 385 }
386 386
387 if ( err != 0 ) { 387 if ( err != 0 ) {
388 QMessageBox::warning( this, tr("Paste file"), tr("Paste failed!"), 388 QMessageBox::warning( this, tr("Paste file"), tr("Paste failed!"),
389 tr("Ok") ); 389 tr("Ok") );
390 break; 390 break;
391 } else { 391 } else {
392 updateDir(); 392 updateDir();
393 QListViewItem * i = firstChild(); 393 QListViewItem * i = firstChild();
394 basename = dest.mid( dest.findRev("/") + 1, dest.length() ); 394 basename = dest.mid( dest.findRev("/") + 1, dest.length() );
395 395
396 while( i ){ 396 while( i ){
397 if( i->text(0) == basename ){ 397 if( i->text(0) == basename ){
398 setCurrentItem( i ); 398 setCurrentItem( i );
399 ensureItemVisible( i ); 399 ensureItemVisible( i );
400 break; 400 break;
401 } 401 }
402 i = i->nextSibling(); 402 i = i->nextSibling();
403 } 403 }
404 } 404 }
405 } 405 }
406} 406}
407 407
408bool FileView::copyFile( const QString & dest, const QString & src ) 408bool FileView::copyFile( const QString & dest, const QString & src )
409{ 409{
410 char bf[ 50000 ]; 410 char bf[ 50000 ];
411 int bytesRead; 411 int bytesRead;
412 bool success = TRUE; 412 bool success = TRUE;
413 struct stat status; 413 struct stat status;
414 414
415 QFile s( src ); 415 QFile s( src );
416 QFile d( dest ); 416 QFile d( dest );
417 417
418 if( s.open( IO_ReadOnly | IO_Raw ) && 418 if( s.open( IO_ReadOnly | IO_Raw ) &&
419 d.open( IO_WriteOnly | IO_Raw ) ) 419 d.open( IO_WriteOnly | IO_Raw ) )
420 { 420 {
421 while( (bytesRead = s.readBlock( bf, sizeof( bf ) )) == 421 while( (bytesRead = s.readBlock( bf, sizeof( bf ) )) ==
422 sizeof( bf ) ) 422 sizeof( bf ) )
423 { 423 {
424 if( d.writeBlock( bf, sizeof( bf ) ) != sizeof( bf ) ){ 424 if( d.writeBlock( bf, sizeof( bf ) ) != sizeof( bf ) ){
425 success = FALSE; 425 success = FALSE;
426 break; 426 break;
427 } 427 }
428 } 428 }
429 if( success && (bytesRead > 0) ){ 429 if( success && (bytesRead > 0) ){
430 d.writeBlock( bf, bytesRead ); 430 d.writeBlock( bf, bytesRead );
431 } 431 }
432 } else { 432 } else {
433 success = FALSE; 433 success = FALSE;
434 } 434 }
435 435
436 // Set file permissions 436 // Set file permissions
437 if( stat( (const char *) src, &status ) == 0 ){ 437 if( stat( (const char *) src, &status ) == 0 ){
438 chmod( (const char *) dest, status.st_mode ); 438 chmod( (const char *) dest, status.st_mode );
439 } 439 }
440 440
441 return success; 441 return success;
442} 442}
443 443
444void FileView::cut() 444void FileView::cut()
445{ 445{
446 int err; 446 int err;
447 // ##### a better inmplementation might be to rename the CUT file 447 // ##### a better inmplementation might be to rename the CUT file
448 // ##### to ".QPE-FILEBROWSER-MOVING" rather than copying it. 448 // ##### to ".QPE-FILEBROWSER-MOVING" rather than copying it.
449 QString cmd, dest, basename, cd = "/tmp/qpemoving"; 449 QString cmd, dest, basename, cd = "/tmp/qpemoving";
450 QStringList newflist; 450 QStringList newflist;
451 newflist.clear(); 451 newflist.clear();
452 452
453 cmd = "rm -rf " + cd; 453 cmd = "rm -rf " + cd;
454 system ( (const char *) cmd ); 454 system ( (const char *) cmd );
455 cmd = "mkdir " + cd; 455 cmd = "mkdir " + cd;
456 system( (const char *) cmd ); 456 system( (const char *) cmd );
457 457
458// get the names of the files to cut 458// get the names of the files to cut
459 FileItem * item; 459 FileItem * item;
460 460
461 if((item = (FileItem *) firstChild()) == 0) return; 461 if((item = (FileItem *) firstChild()) == 0) return;
462 462
463 flist.clear(); 463 flist.clear();
464 while( item ){ 464 while( item ){
465 if( item->isSelected() /*&& !item->isDir()*/ ){ 465 if( item->isSelected() /*&& !item->isDir()*/ ){
466 flist += item->getFilePath(); 466 flist += item->getFilePath();
467 } 467 }
468 item = (FileItem *) item->nextSibling(); 468 item = (FileItem *) item->nextSibling();
469 } 469 }
470 470
471// move these files into a tmp dir 471// move these files into a tmp dir
472 for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it ) { 472 for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it ) {
473 basename = (*it).mid((*it).findRev("/") + 1, (*it).length()); 473 basename = (*it).mid((*it).findRev("/") + 1, (*it).length());
474 474
475 dest = cd + "/" + basename; 475 dest = cd + "/" + basename;
476 476
477 newflist += dest; 477 newflist += dest;
478 478
479 cmd = "/bin/mv -f \"" + (*it) +"\" " + "\"" + dest + "\""; 479 cmd = "/bin/mv -f \"" + (*it) +"\" " + "\"" + dest + "\"";
480 err = system( (const char *) cmd ); 480 err = system( (const char *) cmd );
481 481
482 if ( err != 0 ) { 482 if ( err != 0 ) {
483 QMessageBox::warning( this, tr("Cut file"), tr("Cut failed!"), 483 QMessageBox::warning( this, tr("Cut file"), tr("Cut failed!"),
484 tr("Ok") ); 484 tr("Ok") );
485 break; 485 break;
486 } else { 486 } else {
487 updateDir(); 487 updateDir();
488 QListViewItem * im = firstChild(); 488 QListViewItem * im = firstChild();
489 basename = dest.mid( dest.findRev("/") + 1, dest.length() ); 489 basename = dest.mid( dest.findRev("/") + 1, dest.length() );
490 490
491 while( im ){ 491 while( im ){
492 if( im->text(0) == basename ){ 492 if( im->text(0) == basename ){
493 setCurrentItem( im ); 493 setCurrentItem( im );
494 ensureItemVisible( im ); 494 ensureItemVisible( im );
495 break; 495 break;
496 } 496 }
497 im = im->nextSibling(); 497 im = im->nextSibling();
498 } 498 }
499 } 499 }
500 } 500 }
501 501
502 // update the filelist to point to tmp dir so paste works nicely 502 // update the filelist to point to tmp dir so paste works nicely
503 flist = newflist; 503 flist = newflist;
504} 504}
505 505
506void FileView::del() 506void FileView::del()
507{ 507{
508 FileItem * i; 508 FileItem * i;
509 QStringList fl; 509 QStringList fl;
510 QString cmd; 510 QString cmd;
511 int err; 511 int err;
512 512
513 if((i = (FileItem *) firstChild()) == 0) return; 513 if((i = (FileItem *) firstChild()) == 0) return;
514 514
515 while( i ){ 515 while( i ){
516 if( i->isSelected() ){ 516 if( i->isSelected() ){
517 fl += i->getFilePath(); 517 fl += i->getFilePath();
518 } 518 }
519 i = (FileItem *) i->nextSibling(); 519 i = (FileItem *) i->nextSibling();
520 } 520 }
521 if( fl.count() < 1 ) return; 521 if( fl.count() < 1 ) return;
522 522
523 if( QMessageBox::warning( this, tr("Delete"), tr("Are you sure?"), 523 if( QMessageBox::warning( this, tr("Delete"), tr("Are you sure?"),
524 tr("Yes"), tr("No") ) == 0) 524 tr("Yes"), tr("No") ) == 0)
525 { 525 {
526 // 526 //
527 // Dependant upon the "rm" command - will probably have to be replaced 527 // Dependant upon the "rm" command - will probably have to be replaced
528 // 528 //
529 for ( QStringList::Iterator it = fl.begin(); it != fl.end(); ++it ) { 529 for ( QStringList::Iterator it = fl.begin(); it != fl.end(); ++it ) {
530 cmd = "/bin/rm -rf \"" + (*it) + "\""; 530 cmd = "/bin/rm -rf \"" + (*it) + "\"";
531 err = system( (const char *) cmd ); 531 err = system( (const char *) cmd );
532 if ( err != 0 ) { 532 if ( err != 0 ) {
533 QMessageBox::warning( this, tr("Delete"), tr("Delete failed!"), 533 QMessageBox::warning( this, tr("Delete"), tr("Delete failed!"),
534 tr("Ok") ); 534 tr("Ok") );
535 break; 535 break;
536 } 536 }
537 } 537 }
538 updateDir(); 538 updateDir();
539 } 539 }
540} 540}
541 541
542void FileView::newFolder() 542void FileView::newFolder()
543{ 543{
544 int t = 1; 544 int t = 1;
545 FileItem * i; 545 FileItem * i;
546 QString nd = currentDir + "/NewFolder"; 546 QString nd = currentDir + "/NewFolder";
547 547
548 while( QFile( nd ).exists() ){ 548 while( QFile( nd ).exists() ){
549 nd.sprintf( "%s/NewFolder (%d)", (const char *) currentDir, t++ ); 549 nd.sprintf( "%s/NewFolder (%d)", (const char *) currentDir, t++ );
550 } 550 }
551 551
552 if( mkdir( (const char *) nd, 0777 ) != 0){ 552 if( mkdir( (const char *) nd, 0777 ) != 0){
553 QMessageBox::warning( this, tr( "New folder" ), 553 QMessageBox::warning( this, tr( "New folder" ),
554 tr( "Folder creation failed!" ), 554 tr( "Folder creation failed!" ),
555 tr( "Ok" ) ); 555 tr( "Ok" ) );
556 return; 556 return;
557 } 557 }
558 updateDir(); 558 updateDir();
559 559
560 if((i = (FileItem *) firstChild()) == 0) return; 560 if((i = (FileItem *) firstChild()) == 0) return;
561 561
562 while( i ){ 562 while( i ){
563 if( i->isDir() && ( i->getFilePath() == nd ) ){ 563 if( i->isDir() && ( i->getFilePath() == nd ) ){
564 setCurrentItem( i ); 564 setCurrentItem( i );
565 rename(); 565 rename();
566 break; 566 break;
567 } 567 }
568 i = (FileItem *) i->nextSibling(); 568 i = (FileItem *) i->nextSibling();
569 } 569 }
570} 570}
571 571
572void FileView::viewAsText() 572void FileView::viewAsText()
573{ 573{
574 FileItem * i = (FileItem *) currentItem(); 574 FileItem * i = (FileItem *) currentItem();
575 QCopEnvelope e("QPE/Application/textedit","setDocument(QString)"); 575 QCopEnvelope e("QPE/Application/textedit","setDocument(QString)");
576 e << i->getFilePath(); 576 e << i->getFilePath();
577// Global::execute( "textedit -f ", i->getFilePath() ); 577// Global::execute( "textedit -f ", i->getFilePath() );
578} 578}
579 579
580void FileView::itemClicked( QListViewItem * i) 580void FileView::itemClicked( QListViewItem * i)
581{ 581{
582 FileItem * t = (FileItem *) i; 582 FileItem * t = (FileItem *) i;
583 583
584 if( t == NULL ) return; 584 if( t == NULL ) return;
585 if( t->isDir() ){ 585 if( t->isDir() ){
586 setDir( t->getFilePath() ); 586 setDir( t->getFilePath() );
587 } 587 }
588} 588}
589 589
590void FileView::itemDblClicked( QListViewItem * i) 590void FileView::itemDblClicked( QListViewItem * i)
591{ 591{
592 if(menuKeepsOpen){ 592 if(menuKeepsOpen){
593 cancelMenuTimer(); 593 cancelMenuTimer();
594 } 594 }
595 595
596 FileItem * t = (FileItem *) i; 596 FileItem * t = (FileItem *) i;
597 597
598 if(t == NULL) return; 598 if(t == NULL) return;
599 if(t->launch() == -1){ 599 if(t->launch() == -1){
600 QMessageBox::warning( this, tr( "Launch Application" ), 600 QMessageBox::warning( this, tr( "Launch Application" ),
601 tr( "Launch failed!" ), tr( "Ok" ) ); 601 tr( "Launch failed!" ), tr( "Ok" ) );
602 } 602 }
603} 603}
604 604
605void FileView::parentDir() 605void FileView::parentDir()
606{ 606{
607 setDir( currentDir + "./.." ); 607 setDir( currentDir + "./.." );
608} 608}
609 609
610void FileView::lastDir() 610void FileView::lastDir()
611{ 611{
612 if( dirHistory.count() == 0 ) return; 612 if( dirHistory.count() == 0 ) return;
613 613
614 QString newDir = dirHistory.last(); 614 QString newDir = dirHistory.last();
615 dirHistory.remove( dirHistory.last() ); 615 dirHistory.remove( dirHistory.last() );
616 generateDir( newDir ); 616 generateDir( newDir );
617} 617}
618 618
619void FileView::contentsMousePressEvent( QMouseEvent * e ) 619void FileView::contentsMousePressEvent( QMouseEvent * e )
620{ 620{
621 QListView::contentsMousePressEvent( e ); 621 QListView::contentsMousePressEvent( e );
622 menuTimer.start( 750, TRUE ); 622 menuTimer.start( 750, TRUE );
623} 623}
624 624
625void FileView::contentsMouseReleaseEvent( QMouseEvent * e ) 625void FileView::contentsMouseReleaseEvent( QMouseEvent * e )
626{ 626{
627 QListView::contentsMouseReleaseEvent( e ); 627 QListView::contentsMouseReleaseEvent( e );
628 if(!menuKeepsOpen){ 628 if(!menuKeepsOpen){
629 menuTimer.stop(); 629 menuTimer.stop();
630 } 630 }
631 631
632} 632}
633 633
634void FileView::cancelMenuTimer() 634void FileView::cancelMenuTimer()
635{ 635{
636 if( menuTimer.isActive() ) 636 if( menuTimer.isActive() )
637 menuTimer.stop(); 637 menuTimer.stop();
638} 638}
639 639
640void FileView::addToDocuments() 640void FileView::addToDocuments()
641{ 641{
642 FileItem * i = (FileItem *) currentItem(); 642 FileItem * i = (FileItem *) currentItem();
643 DocLnk f; 643 DocLnk f;
644 QString n = i->text(0); 644 QString n = i->text(0);
645 n.replace(QRegExp("\\..*"),""); 645 n.replace(QRegExp("\\..*"),"");
646 f.setName( n ); 646 f.setName( n );
647 f.setFile( i->getFilePath() ); 647 f.setFile( i->getFilePath() );
648 f.writeLink(); 648 f.writeLink();
649} 649}
650 650
651void FileView::run() 651void FileView::run()
652{ 652{
653 FileItem * i = (FileItem *) currentItem(); 653 FileItem * i = (FileItem *) currentItem();
654 i->launch(); 654 i->launch();
655} 655}
656 656
657void FileView::showFileMenu() 657void FileView::showFileMenu()
658{ 658{
659 FileItem * i = (FileItem *) currentItem(); 659 FileItem * i = (FileItem *) currentItem();
660 if ( !i ) 660 if ( !i )
661 return; 661 return;
662 662
663 QPopupMenu * m = new QPopupMenu( this ); 663 QPopupMenu * m = new QPopupMenu( this );
664 664
665 if ( !i->isDir() ) { 665 if ( !i->isDir() ) {
666 m->insertItem( tr( "Add to Documents" ), this, SLOT( addToDocuments() ) ); 666 m->insertItem( tr( "Add to Documents" ), this, SLOT( addToDocuments() ) );
667 m->insertSeparator(); 667 m->insertSeparator();
668 } 668 }
669 669
670 MimeType mt(i->getFilePath()); 670 MimeType mt(i->getFilePath());
671 const AppLnk* app = mt.application(); 671 const AppLnk* app = mt.application();
672 672
673 if ( !i->isDir() ) { 673 if ( !i->isDir() ) {
674 if ( app ) 674 if ( app )
675 m->insertItem( app->pixmap(), tr( "Open in " + app->name() ), this, SLOT( run() ) ); 675 m->insertItem( app->pixmap(), tr( "Open in " + app->name() ), this, SLOT( run() ) );
676 else if( i->isExecutable() ) 676 else if( i->isExecutable() )
677 m->insertItem( Resource::loadPixmap( i->text( 0 ) ), tr( "Run" ), this, SLOT( run() ) ); 677 m->insertItem( Resource::loadPixmap( i->text( 0 ) ), tr( "Run" ), this, SLOT( run() ) );
678 678
679 m->insertItem( Resource::loadPixmap( "txt" ), tr( "View as text" ), 679 m->insertItem( Resource::loadPixmap( "txt" ), tr( "View as text" ),
680 this, SLOT( viewAsText() ) ); 680 this, SLOT( viewAsText() ) );
681 681
682 m->insertSeparator(); 682 m->insertSeparator();
683 } 683 }
684 684
685 m->insertItem( tr( "Rename" ), this, SLOT( rename() ) ); 685 m->insertItem( tr( "Rename" ), this, SLOT( rename() ) );
686 m->insertItem( Resource::loadPixmap("cut"), 686 m->insertItem( Resource::loadPixmap("cut"),
687 tr( "Cut" ), this, SLOT( cut() ) ); 687 tr( "Cut" ), this, SLOT( cut() ) );
688 m->insertItem( Resource::loadPixmap("copy"), 688 m->insertItem( Resource::loadPixmap("copy"),
689 689
690 tr( "Copy" ), this, SLOT( copy() ) ); 690 tr( "Copy" ), this, SLOT( copy() ) );
691 m->insertItem( Resource::loadPixmap("paste"), 691 m->insertItem( Resource::loadPixmap("paste"),
692 tr( "Paste" ), this, SLOT( paste() ) ); 692 tr( "Paste" ), this, SLOT( paste() ) );
693 m->insertItem( tr( "Change Permissions" ), this, SLOT( chPerm() ) ); 693 m->insertItem( tr( "Change Permissions" ), this, SLOT( chPerm() ) );
694 m->insertItem(Resource::loadPixmap( "close" ), tr( "Delete" ), this, SLOT( del() ) ); 694 m->insertItem(Resource::loadPixmap( "close" ), tr( "Delete" ), this, SLOT( del() ) );
695 m->insertSeparator(); 695 m->insertSeparator();
696 m->insertItem( tr( "Select all" ), this, SLOT( selectAll() ) ); 696 m->insertItem( tr( "Select all" ), this, SLOT( selectAll() ) );
697 m->insertItem( tr( "Deselect all" ), this, SLOT( deselectAll() ) ); 697 m->insertItem( tr( "Deselect all" ), this, SLOT( deselectAll() ) );
698 m->popup( QCursor::pos() ); 698 m->popup( QCursor::pos() );
699} 699}
700 700
701// 701//
702// FileBrowser 702// FileBrowser
703// 703//
704 704
705void FileView::setShowHidden(bool hidden) 705void FileView::setShowHidden(bool hidden)
706{ 706{
707 showHidden=hidden; 707 showHidden=hidden;
708} 708}
709 709
710void FileView::setShowSymlinks(bool symlinks) 710void FileView::setShowSymlinks(bool symlinks)
711{ 711{
712 showSymlinks=symlinks; 712 showSymlinks=symlinks;
713} 713}
714 714
715void FileView::setMenuKeepsOpen(bool keepOpen) 715void FileView::setMenuKeepsOpen(bool keepOpen)
716{ 716{
717 menuKeepsOpen=keepOpen; 717 menuKeepsOpen=keepOpen;
718} 718}
719 719
720FileBrowser::FileBrowser( QWidget * parent, 720FileBrowser::FileBrowser( QWidget * parent,
721 const char * name, WFlags f ) : 721 const char * name, WFlags f ) :
722 QMainWindow( parent, name, f ) 722 QMainWindow( parent, name, f )
723{ 723{
724 init( QDir::current().canonicalPath() ); 724 init( QDir::current().canonicalPath() );
725} 725}
726 726
727FileBrowser::FileBrowser( const QString & dir, QWidget * parent, 727FileBrowser::FileBrowser( const QString & dir, QWidget * parent,
728 const char * name, WFlags f ) : 728 const char * name, WFlags f ) :
729 QMainWindow( parent, name, f ) 729 QMainWindow( parent, name, f )
730{ 730{
731 init( dir ); 731 init( dir );
732} 732}
733 733
734void FileBrowser::init(const QString & dir) 734void FileBrowser::init(const QString & dir)
735{ 735{
736 setCaption( tr("File Manager") ); 736 setCaption( tr("File Manager") );
737 setIcon( Resource::loadPixmap( "filebrowser_icon" ) ); 737 setIcon( Resource::loadPixmap( "filebrowser_icon" ) );
738 738
739 Config cfg("Filebrowser"); 739 Config cfg("Filebrowser");
740 cfg.setGroup("View"); 740 cfg.setGroup("View");
741 bool showHidden=(cfg.readEntry("Hidden","FALSE") == "TRUE"); 741 bool showHidden=(cfg.readEntry("Hidden","FALSE") == "TRUE");
742 bool showSymlinks=(cfg.readEntry("Symlinks","FALSE") == "TRUE"); 742 bool showSymlinks=(cfg.readEntry("Symlinks","FALSE") == "TRUE");
743 743
744 cfg.setGroup("Menu"); 744 cfg.setGroup("Menu");
745 bool menuKeepsOpen=(cfg.readEntry("KeepOpen", "FALSE") == "TRUE"); 745 bool menuKeepsOpen=(cfg.readEntry("KeepOpen", "FALSE") == "TRUE");
746 746
747 747
748 fileView = new FileView( dir, this, 0, showHidden, showSymlinks ); 748 fileView = new FileView( dir, this, 0, showHidden, showSymlinks );
749 fileView->setAllColumnsShowFocus( TRUE ); 749 fileView->setAllColumnsShowFocus( TRUE );
750 fileView->setMenuKeepsOpen(menuKeepsOpen); 750 fileView->setMenuKeepsOpen(menuKeepsOpen);
751 751
752 setCentralWidget( fileView ); 752 setCentralWidget( fileView );
753 setToolBarsMovable( FALSE ); 753 setToolBarsMovable( FALSE );
754 754
755 QPEToolBar* toolBar = new QPEToolBar( this ); 755 QPEToolBar* toolBar = new QPEToolBar( this );
756 toolBar->setHorizontalStretchable( TRUE ); 756 toolBar->setHorizontalStretchable( TRUE );
757 757
758 QPEMenuBar* menuBar = new QPEMenuBar( toolBar ); 758 QPEMenuBar* menuBar = new QPEMenuBar( toolBar );
759 759
760 dirMenu = new QPopupMenu( this ); 760 dirMenu = new QPopupMenu( this );
761 menuBar->insertItem( tr( "Dir" ), dirMenu ); 761 menuBar->insertItem( tr( "Dir" ), dirMenu );
762 762
763 sortMenu = new QPopupMenu( this ); 763 sortMenu = new QPopupMenu( this );
764 menuBar->insertItem( tr( "Sort" ), sortMenu ); 764 menuBar->insertItem( tr( "Sort" ), sortMenu );
765 sortMenu->insertItem( tr( "by Name "), this, SLOT( sortName() ) ); 765 sortMenu->insertItem( tr( "by Name "), this, SLOT( sortName() ) );
766 sortMenu->insertItem( tr( "by Size "), this, SLOT( sortSize() ) ); 766 sortMenu->insertItem( tr( "by Size "), this, SLOT( sortSize() ) );
767 sortMenu->insertItem( tr( "by Date "), this, SLOT( sortDate() ) ); 767 sortMenu->insertItem( tr( "by Date "), this, SLOT( sortDate() ) );
768 sortMenu->insertItem( tr( "by Type "), this, SLOT( sortType() ) ); 768 sortMenu->insertItem( tr( "by Type "), this, SLOT( sortType() ) );
769 sortMenu->insertSeparator(); 769 sortMenu->insertSeparator();
770 sortMenu->insertItem( tr( "Ascending" ), this, SLOT( updateSorting() ) ); 770 sortMenu->insertItem( tr( "Ascending" ), this, SLOT( updateSorting() ) );
771 771
772 sortMenu->setItemChecked( sortMenu->idAt( 5 ), TRUE ); 772 sortMenu->setItemChecked( sortMenu->idAt( 5 ), TRUE );
773 sortMenu->setItemChecked( sortMenu->idAt( 0 ), TRUE ); 773 sortMenu->setItemChecked( sortMenu->idAt( 0 ), TRUE );
774 774
775 viewMenu = new QPopupMenu( this); 775 viewMenu = new QPopupMenu( this);
776 viewMenu->insertItem( tr( "Hidden"), this, SLOT( updateShowHidden() ) ); 776 viewMenu->insertItem( tr( "Hidden"), this, SLOT( updateShowHidden() ) );
777 viewMenu->insertItem( tr( "Symlinks"), this, SLOT( updateShowSymlinks() ) ); 777 viewMenu->insertItem( tr( "Symlinks"), this, SLOT( updateShowSymlinks() ) );
778 viewMenu->setItemChecked( viewMenu->idAt( 0 ), showHidden ); 778 viewMenu->setItemChecked( viewMenu->idAt( 0 ), showHidden );
779 viewMenu->setItemChecked( viewMenu->idAt( 1 ), showSymlinks ); 779 viewMenu->setItemChecked( viewMenu->idAt( 1 ), showSymlinks );
780 780
781 menuBar->insertItem( tr("View"), viewMenu ); 781 menuBar->insertItem( tr("View"), viewMenu );
782 782
783 toolBar = new QPEToolBar( this ); 783 toolBar = new QPEToolBar( this );
784 784
785 lastAction = new QAction( tr("Previous dir"), Resource::loadIconSet( "back" ), 785 lastAction = new QAction( tr("Previous dir"), Resource::loadIconSet( "back" ),
786 QString::null, 0, this, 0 ); 786 QString::null, 0, this, 0 );
787 connect( lastAction, SIGNAL( activated() ), fileView, SLOT( lastDir() ) ); 787 connect( lastAction, SIGNAL( activated() ), fileView, SLOT( lastDir() ) );
788 lastAction->addTo( toolBar ); 788 lastAction->addTo( toolBar );
789 lastAction->setEnabled( FALSE ); 789 lastAction->setEnabled( FALSE );
790 790
791 upAction = new QAction( tr("Parent dir"), Resource::loadIconSet( "up" ), 791 upAction = new QAction( tr("Parent dir"), Resource::loadIconSet( "up" ),
792 QString::null, 0, this, 0 ); 792 QString::null, 0, this, 0 );
793 connect( upAction, SIGNAL( activated() ), fileView, SLOT( parentDir() ) ); 793 connect( upAction, SIGNAL( activated() ), fileView, SLOT( parentDir() ) );
794 upAction->addTo( toolBar ); 794 upAction->addTo( toolBar );
795 795
796 QAction *a = new QAction( tr("New folder"), Resource::loadPixmap( "newfolder" ), 796 QAction *a = new QAction( tr("New folder"), Resource::loadPixmap( "newfolder" ),
797 QString::null, 0, this, 0 ); 797 QString::null, 0, this, 0 );
798 connect( a, SIGNAL( activated() ), fileView, SLOT( newFolder() ) ); 798 connect( a, SIGNAL( activated() ), fileView, SLOT( newFolder() ) );
799 a->addTo( toolBar ); 799 a->addTo( toolBar );
800 800
801 a = new QAction( tr("Cut"), Resource::loadPixmap( "cut" ), 801 a = new QAction( tr("Cut"), Resource::loadPixmap( "cut" ),
802 QString::null, 0, this, 0 ); 802 QString::null, 0, this, 0 );
803 connect( a, SIGNAL( activated() ), fileView, SLOT( cut() ) ); 803 connect( a, SIGNAL( activated() ), fileView, SLOT( cut() ) );
804 a->addTo( toolBar ); 804 a->addTo( toolBar );
805 805
806 a = new QAction( tr("Copy"), Resource::loadPixmap( "copy" ), 806 a = new QAction( tr("Copy"), Resource::loadPixmap( "copy" ),
807 QString::null, 0, this, 0 ); 807 QString::null, 0, this, 0 );
808 connect( a, SIGNAL( activated() ), fileView, SLOT( copy() ) ); 808 connect( a, SIGNAL( activated() ), fileView, SLOT( copy() ) );
809 a->addTo( toolBar ); 809 a->addTo( toolBar );
810 810
811 pasteAction = new QAction( tr("Paste"), Resource::loadPixmap( "paste" ), 811 pasteAction = new QAction( tr("Paste"), Resource::loadPixmap( "paste" ),
812 QString::null, 0, this, 0 ); 812 QString::null, 0, this, 0 );
813 connect( pasteAction, SIGNAL( activated() ), fileView, SLOT( paste() ) ); 813 connect( pasteAction, SIGNAL( activated() ), fileView, SLOT( paste() ) );
814 pasteAction->addTo( toolBar ); 814 pasteAction->addTo( toolBar );
815 815
816// dirLabel = new QLabel(this, "DirLabel"); 816// dirLabel = new QLabel(this, "DirLabel");
817 817
818 connect( fileView, SIGNAL( dirChanged() ), SLOT( updateDirMenu() ) ); 818 connect( fileView, SIGNAL( dirChanged() ), SLOT( updateDirMenu() ) );
819 updateDirMenu(); 819 updateDirMenu();
820 820
821 QCopChannel* pcmciaChannel = new QCopChannel( "QPE/Card", this ); 821 QCopChannel* pcmciaChannel = new QCopChannel( "QPE/Card", this );
822 connect( pcmciaChannel, SIGNAL(received(const QCString &, const QByteArray &)), 822 connect( pcmciaChannel, SIGNAL(received(const QCString &, const QByteArray &)),
823 this, SLOT(pcmciaMessage( const QCString &, const QByteArray &)) ); 823 this, SLOT(pcmciaMessage( const QCString &, const QByteArray &)) );
824} 824}
825 825
826void FileBrowser::pcmciaMessage( const QCString &msg, const QByteArray &) 826void FileBrowser::pcmciaMessage( const QCString &msg, const QByteArray &)
827{ 827{
828 if ( msg == "mtabChanged()" ) { 828 if ( msg == "mtabChanged()" ) {
829 // ## Only really needed if current dir is on a card 829 // ## Only really needed if current dir is on a card
830 fileView->updateDir(); 830 fileView->updateDir();
831 } 831 }
832} 832}
833 833
834void FileBrowser::changeCaption(const QString & dir) { 834void FileBrowser::changeCaption(const QString & dir) {
835 setCaption( dir); 835 setCaption( dir);
836} 836}
837 837
838void FileBrowser::dirSelected( int id ) 838void FileBrowser::dirSelected( int id )
839{ 839{
840 int i = 0, j; 840 int i = 0, j;
841 QString dir; 841 QString dir;
842 842
843 // Bulid target dir from menu 843 // Bulid target dir from menu
844 while( (j = dirMenu->idAt( i )) != id ){ 844 while( (j = dirMenu->idAt( i )) != id ){
845 dir += dirMenu->text( j ).stripWhiteSpace(); 845 dir += dirMenu->text( j ).stripWhiteSpace();
846 if( dirMenu->text( j ) != "/" ) dir += "/"; 846 if( dirMenu->text( j ) != "/" ) dir += "/";
847 i++; 847 i++;
848 } 848 }
849 dir += dirMenu->text( dirMenu->idAt( i ) ).stripWhiteSpace(); 849 dir += dirMenu->text( dirMenu->idAt( i ) ).stripWhiteSpace();
850 850
851 fileView->setDir( dir ); 851 fileView->setDir( dir );
852} 852}
853 853
854void FileBrowser::updateDirMenu() 854void FileBrowser::updateDirMenu()
855{ 855{
856 QString spc, cd = fileView->cd(); 856 QString spc, cd = fileView->cd();
857 QStringList l = QStringList::split( "/", cd ); 857 QStringList l = QStringList::split( "/", cd );
858 int i = 0; 858 int i = 0;
859 859
860 dirMenu->clear(); 860 dirMenu->clear();
861 dirMenu->insertItem( tr( "/" ), this, SLOT( dirSelected(int) ) ); 861 dirMenu->insertItem( tr( "/" ), this, SLOT( dirSelected(int) ) );
862 862
863 for ( QStringList::Iterator it = l.begin(); it != l.end(); ++it ) { 863 for ( QStringList::Iterator it = l.begin(); it != l.end(); ++it ) {
864 spc.fill( ' ', i++); 864 spc.fill( ' ', i++);
865 dirMenu->insertItem( spc + (*it), this, 865 dirMenu->insertItem( spc + (*it), this,
866 SLOT( dirSelected(int) ) ); 866 SLOT( dirSelected(int) ) );
867 } 867 }
868 dirMenu->setItemChecked( dirMenu->idAt( l.count() ), TRUE ); 868 dirMenu->setItemChecked( dirMenu->idAt( l.count() ), TRUE );
869 869
870 lastAction->setEnabled( fileView->history().count() != 0 ); 870 lastAction->setEnabled( fileView->history().count() != 0 );
871 upAction->setEnabled( cd != "/" ); 871 upAction->setEnabled( cd != "/" );
872} 872}
873 873
874void FileBrowser::sortName() 874void FileBrowser::sortName()
875{ 875{
876 fileView->setSorting( 0, sortMenu->isItemChecked( sortMenu->idAt( 5 ) ) ); 876 fileView->setSorting( 0, sortMenu->isItemChecked( sortMenu->idAt( 5 ) ) );
877 fileView->sort(); 877 fileView->sort();
878 sortMenu->setItemChecked( sortMenu->idAt( 0 ), TRUE ); 878 sortMenu->setItemChecked( sortMenu->idAt( 0 ), TRUE );
879 sortMenu->setItemChecked( sortMenu->idAt( 1 ), FALSE ); 879 sortMenu->setItemChecked( sortMenu->idAt( 1 ), FALSE );
880 sortMenu->setItemChecked( sortMenu->idAt( 2 ), FALSE ); 880 sortMenu->setItemChecked( sortMenu->idAt( 2 ), FALSE );
881 sortMenu->setItemChecked( sortMenu->idAt( 3 ), FALSE ); 881 sortMenu->setItemChecked( sortMenu->idAt( 3 ), FALSE );
882} 882}
883 883
884void FileBrowser::sortSize() 884void FileBrowser::sortSize()
885{ 885{
886 fileView->setSorting( 1, sortMenu->isItemChecked( sortMenu->idAt( 5 ) ) ); 886 fileView->setSorting( 1, sortMenu->isItemChecked( sortMenu->idAt( 5 ) ) );
887 fileView->sort(); 887 fileView->sort();
888 sortMenu->setItemChecked( sortMenu->idAt( 0 ), FALSE ); 888 sortMenu->setItemChecked( sortMenu->idAt( 0 ), FALSE );
889 sortMenu->setItemChecked( sortMenu->idAt( 1 ), TRUE ); 889 sortMenu->setItemChecked( sortMenu->idAt( 1 ), TRUE );
890 sortMenu->setItemChecked( sortMenu->idAt( 2 ), FALSE ); 890 sortMenu->setItemChecked( sortMenu->idAt( 2 ), FALSE );
891 sortMenu->setItemChecked( sortMenu->idAt( 3 ), FALSE ); 891 sortMenu->setItemChecked( sortMenu->idAt( 3 ), FALSE );
892} 892}
893 893
894void FileBrowser::sortDate() 894void FileBrowser::sortDate()
895{ 895{
896 fileView->setSorting( 2, sortMenu->isItemChecked( sortMenu->idAt( 5 ) ) ); 896 fileView->setSorting( 2, sortMenu->isItemChecked( sortMenu->idAt( 5 ) ) );
897 fileView->sort(); 897 fileView->sort();
898 sortMenu->setItemChecked( sortMenu->idAt( 0 ), FALSE ); 898 sortMenu->setItemChecked( sortMenu->idAt( 0 ), FALSE );
899 sortMenu->setItemChecked( sortMenu->idAt( 1 ), FALSE ); 899 sortMenu->setItemChecked( sortMenu->idAt( 1 ), FALSE );
900 sortMenu->setItemChecked( sortMenu->idAt( 2 ), TRUE ); 900 sortMenu->setItemChecked( sortMenu->idAt( 2 ), TRUE );
901 sortMenu->setItemChecked( sortMenu->idAt( 3 ), FALSE ); 901 sortMenu->setItemChecked( sortMenu->idAt( 3 ), FALSE );
902} 902}
903 903
904void FileBrowser::sortType() 904void FileBrowser::sortType()
905{ 905{
906 fileView->setSorting( 3, sortMenu->isItemChecked( sortMenu->idAt( 5 ) ) ); 906 fileView->setSorting( 3, sortMenu->isItemChecked( sortMenu->idAt( 5 ) ) );
907 fileView->sort(); 907 fileView->sort();
908 sortMenu->setItemChecked( sortMenu->idAt( 0 ), FALSE ); 908 sortMenu->setItemChecked( sortMenu->idAt( 0 ), FALSE );
909 sortMenu->setItemChecked( sortMenu->idAt( 1 ), FALSE ); 909 sortMenu->setItemChecked( sortMenu->idAt( 1 ), FALSE );
910 sortMenu->setItemChecked( sortMenu->idAt( 2 ), FALSE ); 910 sortMenu->setItemChecked( sortMenu->idAt( 2 ), FALSE );
911 sortMenu->setItemChecked( sortMenu->idAt( 3 ), TRUE ); 911 sortMenu->setItemChecked( sortMenu->idAt( 3 ), TRUE );
912} 912}
913 913
914void FileBrowser::updateSorting() 914void FileBrowser::updateSorting()
915{ 915{
916 sortMenu->setItemChecked( sortMenu->idAt( 5 ), !sortMenu->isItemChecked( sortMenu->idAt( 5 ) ) ); 916 sortMenu->setItemChecked( sortMenu->idAt( 5 ), !sortMenu->isItemChecked( sortMenu->idAt( 5 ) ) );
917 917
918 if ( sortMenu->isItemChecked( sortMenu->idAt( 0 ) ) ) 918 if ( sortMenu->isItemChecked( sortMenu->idAt( 0 ) ) )
919 sortName(); 919 sortName();
920 else if ( sortMenu->isItemChecked( sortMenu->idAt( 1 ) ) ) 920 else if ( sortMenu->isItemChecked( sortMenu->idAt( 1 ) ) )
921 sortSize(); 921 sortSize();
922 else if ( sortMenu->isItemChecked( sortMenu->idAt( 2 ) ) ) 922 else if ( sortMenu->isItemChecked( sortMenu->idAt( 2 ) ) )
923 sortDate(); 923 sortDate();
924 else 924 else
925 sortType(); 925 sortType();
926} 926}
927 927
928void FileView::chPerm() { 928void FileView::chPerm() {
929 FileItem * i; 929 FileItem * i;
930 QStringList fl; 930 QStringList fl;
931 QString cmd; 931 QString cmd;
932 int err; 932 int err;
933 933
934 if((i = (FileItem *) firstChild()) == 0) return; 934 if((i = (FileItem *) firstChild()) == 0) return;
935 935
936 while( i ){ 936 while( i ){
937 if( i->isSelected() ){ 937 if( i->isSelected() ){
938 fl += i->getFilePath(); 938 fl += i->getFilePath();
939 } 939 }
940 i = (FileItem *) i->nextSibling(); 940 i = (FileItem *) i->nextSibling();
941 } 941 }
942 if( fl.count() < 1 ) return; 942 if( fl.count() < 1 ) return;
943 if( QMessageBox::warning( this, tr("Change permissions"), tr("Are you sure?"), 943 if( QMessageBox::warning( this, tr("Change permissions"), tr("Are you sure?"),
944 tr("Yes"), tr("No") ) == 0) { 944 tr("Yes"), tr("No") ) == 0) {
945 for ( QStringList::Iterator it = fl.begin(); it != fl.end(); ++it ) { 945 for ( QStringList::Iterator it = fl.begin(); it != fl.end(); ++it ) {
946 filePermissions *filePerm; 946 filePermissions *filePerm;
947 filePerm = new filePermissions(this, "Permissions",true,0,(const QString &)(*it)); 947 filePerm = new filePermissions(this, "Permissions",true,0,(const QString &)(*it));
948 filePerm->exec(); 948 filePerm->exec();
949 if( filePerm) 949 if( filePerm)
950 delete filePerm; 950 delete filePerm;
951 break; 951 break;
952 } 952 }
953 updateDir(); 953 updateDir();
954 } 954 }
955} 955}
956 956
957void FileBrowser::updateShowHidden() 957void FileBrowser::updateShowHidden()
958{ 958{
959 bool valShowHidden=viewMenu->isItemChecked( viewMenu->idAt( 0 ) ); 959 bool valShowHidden=viewMenu->isItemChecked( viewMenu->idAt( 0 ) );
960 valShowHidden=!valShowHidden; 960 valShowHidden=!valShowHidden;
961 viewMenu->setItemChecked( viewMenu->idAt( 0 ), valShowHidden ); 961 viewMenu->setItemChecked( viewMenu->idAt( 0 ), valShowHidden );
962 fileView->setShowHidden(valShowHidden); 962 fileView->setShowHidden(valShowHidden);
963 963
964 Config cfg("Filebrowser"); 964 Config cfg("Filebrowser");
965 cfg.setGroup("View"); 965 cfg.setGroup("View");
966 cfg.writeEntry("Hidden",valShowHidden?"TRUE":"FALSE"); 966 cfg.writeEntry("Hidden",valShowHidden?"TRUE":"FALSE");
967 967
968 fileView->updateDir(); 968 fileView->updateDir();
969} 969}
970 970
971void FileBrowser::updateShowSymlinks() 971void FileBrowser::updateShowSymlinks()
972{ 972{
973 bool valShowSymlinks=viewMenu->isItemChecked( viewMenu->idAt( 1 ) ); 973 bool valShowSymlinks=viewMenu->isItemChecked( viewMenu->idAt( 1 ) );
974 valShowSymlinks=!valShowSymlinks; 974 valShowSymlinks=!valShowSymlinks;
975 viewMenu->setItemChecked( viewMenu->idAt( 1 ), valShowSymlinks ); 975 viewMenu->setItemChecked( viewMenu->idAt( 1 ), valShowSymlinks );
976 fileView->setShowSymlinks(valShowSymlinks); 976 fileView->setShowSymlinks(valShowSymlinks);
977 977
978 Config cfg("Filebrowser"); 978 Config cfg("Filebrowser");
979 cfg.setGroup("View"); 979 cfg.setGroup("View");
980 cfg.writeEntry("Symlinks",valShowSymlinks?"TRUE":"FALSE"); 980 cfg.writeEntry("Symlinks",valShowSymlinks?"TRUE":"FALSE");
981 981
982 fileView->updateDir(); 982 fileView->updateDir();
983} 983}
diff --git a/noncore/unsupported/filebrowser/opie-filebrowser.control b/noncore/unsupported/filebrowser/opie-filebrowser.control
index c15ae17..9de926f 100644
--- a/noncore/unsupported/filebrowser/opie-filebrowser.control
+++ b/noncore/unsupported/filebrowser/opie-filebrowser.control
@@ -1,9 +1,9 @@
1Files: bin/filebrowser apps/Applications/filebrowser.desktop 1Files: bin/filebrowser apps/Applications/filebrowser.desktop pics/filebrowser/symlink.png
2Priority: optional 2Priority: optional
3Section: opie/applications 3Section: opie/applications
4Maintainer: Warwick Allison <warwick@trolltech.com> 4Maintainer: Warwick Allison <warwick@trolltech.com>
5Architecture: arm 5Architecture: arm
6Version: $QPE_VERSION-$SUB_VERSION 6Version: $QPE_VERSION-$SUB_VERSION
7Depends: opie-base ($QPE_VERSION) 7Depends: opie-base ($QPE_VERSION)
8Description: Browse the file system 8Description: Browse the file system
9 The filebrowser for the Opie environment. 9 The filebrowser for the Opie environment.
diff --git a/pics/symlink.png b/pics/filebrowser/symlink.png
index a0b267a..a0b267a 100644
--- a/pics/symlink.png
+++ b/pics/filebrowser/symlink.png
Binary files differ