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