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