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