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