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