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