author | llornkcor <llornkcor> | 2002-04-22 12:11:02 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-04-22 12:11:02 (UTC) |
commit | e79c930fb498f2bc3387da7133a57cd085244346 (patch) (unidiff) | |
tree | c98e0d3fb6c634bdb4404eebd11d7b532093d927 | |
parent | f4c084cb531d8ee036514e4cfb2fcd0f5ffc6b8c (diff) | |
download | opie-e79c930fb498f2bc3387da7133a57cd085244346.zip opie-e79c930fb498f2bc3387da7133a57cd085244346.tar.gz opie-e79c930fb498f2bc3387da7133a57cd085244346.tar.bz2 |
fixed columns mixup
-rw-r--r-- | noncore/unsupported/filebrowser/filebrowser.cpp | 102 |
1 files changed, 51 insertions, 51 deletions
diff --git a/noncore/unsupported/filebrowser/filebrowser.cpp b/noncore/unsupported/filebrowser/filebrowser.cpp index d9e2afa..1bb7984 100644 --- a/noncore/unsupported/filebrowser/filebrowser.cpp +++ b/noncore/unsupported/filebrowser/filebrowser.cpp | |||
@@ -33,93 +33,93 @@ | |||
33 | #include <qmessagebox.h> | 33 | #include <qmessagebox.h> |
34 | #include <qdir.h> | 34 | #include <qdir.h> |
35 | #include <qregexp.h> | 35 | #include <qregexp.h> |
36 | #include <qheader.h> | 36 | #include <qheader.h> |
37 | #include <qpe/qpetoolbar.h> | 37 | #include <qpe/qpetoolbar.h> |
38 | #include <qpopupmenu.h> | 38 | #include <qpopupmenu.h> |
39 | #include <qpe/qpemenubar.h> | 39 | #include <qpe/qpemenubar.h> |
40 | #include <qaction.h> | 40 | #include <qaction.h> |
41 | #include <qstringlist.h> | 41 | #include <qstringlist.h> |
42 | #include <qcursor.h> | 42 | #include <qcursor.h> |
43 | #include <qmultilineedit.h> | 43 | #include <qmultilineedit.h> |
44 | #include <qfont.h> | 44 | #include <qfont.h> |
45 | 45 | ||
46 | #include <unistd.h> | 46 | #include <unistd.h> |
47 | #include <stdlib.h> | 47 | #include <stdlib.h> |
48 | #include <sys/stat.h> | 48 | #include <sys/stat.h> |
49 | 49 | ||
50 | // | 50 | // |
51 | // FileItem | 51 | // FileItem |
52 | // | 52 | // |
53 | FileItem::FileItem( QListView * parent, const QFileInfo & fi ) | 53 | FileItem::FileItem( QListView * parent, const QFileInfo & fi ) |
54 | : QListViewItem( parent ), | 54 | : QListViewItem( parent ), |
55 | fileInfo( fi ) | 55 | fileInfo( fi ) |
56 | { | 56 | { |
57 | QDate d = fi.lastModified().date(); | 57 | QDate d = fi.lastModified().date(); |
58 | 58 | ||
59 | setText( 0, fi.fileName() ); | 59 | setText( 0, fi.fileName() ); |
60 | setText( 1, sizeString( fi.size() ) + " " ); | 60 | setText( 1, sizeString( fi.size() ) + " " ); |
61 | 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() ) ); |
62 | 62 | ||
63 | MimeType mt(fi.filePath()); | 63 | MimeType mt(fi.filePath()); |
64 | 64 | ||
65 | if ( fi.isSymLink() ) | 65 | if ( fi.isSymLink() ) |
66 | setText( 3, "symlink" ); | 66 | setText( 3, "symlink" ); |
67 | else if( fi.isDir() ) | 67 | else if( fi.isDir() ) |
68 | setText( 3, "directory" ); | 68 | setText( 3, "directory" ); |
69 | else if( isLib() ) | 69 | else if( isLib() ) |
70 | setText( 3, "library" ); | 70 | setText( 3, "library" ); |
71 | else | 71 | else |
72 | setText( 3, mt.description() ); | 72 | setText( 3, mt.description() ); |
73 | 73 | ||
74 | QPixmap pm; | 74 | QPixmap pm; |
75 | if( fi.isDir() ){ | 75 | if( fi.isDir() ){ |
76 | if( !QDir( fi.filePath() ).isReadable() ) | 76 | if( !QDir( fi.filePath() ).isReadable() ) |
77 | pm = Resource::loadPixmap( "lockedfolder" ); | 77 | pm = Resource::loadPixmap( "lockedfolder" ); |
78 | else | 78 | else |
79 | pm = Resource::loadPixmap( "folder" ); | 79 | pm = Resource::loadPixmap( "folder" ); |
80 | } | 80 | } |
81 | else if( !fi.isReadable() ) | 81 | else if( !fi.isReadable() ) |
82 | pm = Resource::loadPixmap( "locked" ); | 82 | pm = Resource::loadPixmap( "locked" ); |
83 | else if( isLib() ) | 83 | else if( isLib() ) |
84 | pm = Resource::loadPixmap( "library" ); | 84 | pm = Resource::loadPixmap( "library" ); |
85 | else | 85 | else |
86 | pm = mt.pixmap(); | 86 | pm = mt.pixmap(); |
87 | if ( pm.isNull() ) | 87 | if ( pm.isNull() ) |
88 | pm = Resource::loadPixmap("UnknownDocument-14"); | 88 | pm = Resource::loadPixmap("UnknownDocument-14"); |
89 | if( fi.isSymLink() ){ | 89 | if( fi.isSymLink() ){ |
90 | // overlay link image | 90 | // overlay link image |
91 | QPixmap lnk = Resource::loadPixmap( "filebrowser/symlink" ); | 91 | QPixmap lnk = Resource::loadPixmap( "filebrowser/symlink" ); |
92 | QPainter painter( &pm ); | 92 | QPainter painter( &pm ); |
93 | painter.drawPixmap( pm.width()-lnk.width(), pm.height()-lnk.height(), lnk ); | 93 | painter.drawPixmap( pm.width()-lnk.width(), pm.height()-lnk.height(), lnk ); |
94 | pm.setMask( pm.createHeuristicMask( FALSE ) ); | 94 | pm.setMask( pm.createHeuristicMask( FALSE ) ); |
95 | } | 95 | } |
96 | setPixmap(0,pm); | 96 | setPixmap(0,pm); |
97 | } | 97 | } |
98 | 98 | ||
99 | QString FileItem::sizeString( unsigned int s ) | 99 | QString FileItem::sizeString( unsigned int s ) |
100 | { | 100 | { |
101 | double size = s; | 101 | double size = s; |
102 | 102 | ||
103 | if ( size > 1024 * 1024 * 1024 ) | 103 | if ( size > 1024 * 1024 * 1024 ) |
104 | return QString().sprintf( "%.1f", size / ( 1024 * 1024 * 1024 ) ) + "G"; | 104 | return QString().sprintf( "%.1f", size / ( 1024 * 1024 * 1024 ) ) + "G"; |
105 | else if ( size > 1024 * 1024 ) | 105 | else if ( size > 1024 * 1024 ) |
106 | return QString().sprintf( "%.1f", size / ( 1024 * 1024 ) ) + "M"; | 106 | return QString().sprintf( "%.1f", size / ( 1024 * 1024 ) ) + "M"; |
107 | else if ( size > 1024 ) | 107 | else if ( size > 1024 ) |
108 | return QString().sprintf( "%.1f", size / ( 1024 ) ) + "K"; | 108 | return QString().sprintf( "%.1f", size / ( 1024 ) ) + "K"; |
109 | else | 109 | else |
110 | return QString::number( size ) + "B"; | 110 | return QString::number( size ) + "B"; |
111 | } | 111 | } |
112 | 112 | ||
113 | QString FileItem::key( int column, bool ascending ) const | 113 | QString FileItem::key( int column, bool ascending ) const |
114 | { | 114 | { |
115 | QString tmp; | 115 | QString tmp; |
116 | 116 | ||
117 | ascending = ascending; | 117 | ascending = ascending; |
118 | 118 | ||
119 | if( (column == 0) && fileInfo.isDir() ){ // Sort by name | 119 | if( (column == 0) && fileInfo.isDir() ){ // Sort by name |
120 | // 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 |
121 | tmp = (char) 0; | 121 | tmp = (char) 0; |
122 | return (tmp + text( column ).lower()); | 122 | return (tmp + text( column ).lower()); |
123 | } | 123 | } |
124 | else if( column == 2 ) { // Sort by date | 124 | else if( column == 2 ) { // Sort by date |
125 | QDateTime epoch( QDate( 1980, 1, 1 ) ); | 125 | QDateTime epoch( QDate( 1980, 1, 1 ) ); |
@@ -146,156 +146,156 @@ bool FileItem::isLib() | |||
146 | 146 | ||
147 | int FileItem::launch() | 147 | int FileItem::launch() |
148 | { | 148 | { |
149 | DocLnk doc( fileInfo.filePath(), FALSE ); | 149 | DocLnk doc( fileInfo.filePath(), FALSE ); |
150 | doc.execute(); | 150 | doc.execute(); |
151 | listView()->clearSelection(); | 151 | listView()->clearSelection(); |
152 | return 1; | 152 | return 1; |
153 | } | 153 | } |
154 | 154 | ||
155 | bool FileItem::rename( const QString & name ) | 155 | bool FileItem::rename( const QString & name ) |
156 | { | 156 | { |
157 | QString oldpath, newpath; | 157 | QString oldpath, newpath; |
158 | 158 | ||
159 | if ( name.isEmpty() ) | 159 | if ( name.isEmpty() ) |
160 | return FALSE; | 160 | return FALSE; |
161 | 161 | ||
162 | if ( name.contains( QRegExp("[/\\$\"\'\\*\\?]") ) ) | 162 | if ( name.contains( QRegExp("[/\\$\"\'\\*\\?]") ) ) |
163 | return FALSE; | 163 | return FALSE; |
164 | 164 | ||
165 | oldpath = fileInfo.filePath(); | 165 | oldpath = fileInfo.filePath(); |
166 | newpath = fileInfo.dirPath() + "/" + name; | 166 | newpath = fileInfo.dirPath() + "/" + name; |
167 | 167 | ||
168 | if ( ::rename( (const char *) oldpath, (const char *) newpath ) != 0 ) | 168 | if ( ::rename( (const char *) oldpath, (const char *) newpath ) != 0 ) |
169 | return FALSE; | 169 | return FALSE; |
170 | else | 170 | else |
171 | return TRUE; | 171 | return TRUE; |
172 | } | 172 | } |
173 | 173 | ||
174 | // | 174 | // |
175 | // FileView | 175 | // FileView |
176 | // | 176 | // |
177 | FileView::FileView( const QString & dir, QWidget * parent, | 177 | FileView::FileView( const QString & dir, QWidget * parent, |
178 | const char * name, | 178 | const char * name, |
179 | bool hidden, bool symlinks ) | 179 | bool hidden, bool symlinks ) |
180 | : QListView( parent, name ), | 180 | : QListView( parent, name ), |
181 | menuTimer( this ), | 181 | menuTimer( this ), |
182 | le( NULL ), | 182 | le( NULL ), |
183 | itemToRename( NULL ), | 183 | itemToRename( NULL ), |
184 | showHidden( hidden ), | 184 | showHidden( hidden ), |
185 | showSymlinks( symlinks), | 185 | showSymlinks( symlinks), |
186 | menuKeepsOpen( FALSE ) | 186 | menuKeepsOpen( FALSE ) |
187 | { | 187 | { |
188 | addColumn( "Name" ); | 188 | addColumn( "Name" ); |
189 | addColumn( "Date" ); | ||
190 | addColumn( "Size" ); | 189 | addColumn( "Size" ); |
190 | addColumn( "Date" ); | ||
191 | addColumn( "Type" ); | 191 | addColumn( "Type" ); |
192 | 192 | ||
193 | setMultiSelection( TRUE ); | 193 | setMultiSelection( TRUE ); |
194 | //header()->hide(); | 194 | //header()->hide(); |
195 | 195 | ||
196 | setColumnWidthMode( 0, Manual ); | 196 | setColumnWidthMode( 0, Manual ); |
197 | setColumnWidthMode( 3, Manual ); | 197 | setColumnWidthMode( 3, Manual ); |
198 | 198 | ||
199 | // right align yize column | 199 | // right align yize column |
200 | setColumnAlignment( 1, AlignRight ); | 200 | setColumnAlignment( 1, AlignRight ); |
201 | 201 | ||
202 | generateDir( dir ); | 202 | generateDir( dir ); |
203 | 203 | ||
204 | connect( this, SIGNAL( clicked( QListViewItem * )), | 204 | connect( this, SIGNAL( clicked( QListViewItem * )), |
205 | SLOT( itemClicked( QListViewItem * )) ); | 205 | SLOT( itemClicked( QListViewItem * )) ); |
206 | connect( this, SIGNAL( doubleClicked( QListViewItem * )), | 206 | connect( this, SIGNAL( doubleClicked( QListViewItem * )), |
207 | SLOT( itemDblClicked( QListViewItem * )) ); | 207 | SLOT( itemDblClicked( QListViewItem * )) ); |
208 | connect( this, SIGNAL( selectionChanged() ), SLOT( cancelMenuTimer() ) ); | 208 | connect( this, SIGNAL( selectionChanged() ), SLOT( cancelMenuTimer() ) ); |
209 | connect( &menuTimer, SIGNAL( timeout() ), SLOT( showFileMenu() ) ); | 209 | connect( &menuTimer, SIGNAL( timeout() ), SLOT( showFileMenu() ) ); |
210 | } | 210 | } |
211 | 211 | ||
212 | void FileView::resizeEvent( QResizeEvent *e ) | 212 | void FileView::resizeEvent( QResizeEvent *e ) |
213 | { | 213 | { |
214 | setColumnWidth( 0, width() - 2 * lineWidth() - 20 - columnWidth( 1 ) - columnWidth( 2 ) ); | 214 | setColumnWidth( 0, width() - 2 * lineWidth() - 20 - columnWidth( 1 ) - columnWidth( 2 ) ); |
215 | 215 | ||
216 | // hide type column, we use it for "sort by type" only | 216 | // hide type column, we use it for "sort by type" only |
217 | //setColumnWidth( 3, 0 ); | 217 | //setColumnWidth( 3, 0 ); |
218 | QListView::resizeEvent( e ); | 218 | QListView::resizeEvent( e ); |
219 | } | 219 | } |
220 | 220 | ||
221 | void FileView::updateDir() | 221 | void FileView::updateDir() |
222 | { | 222 | { |
223 | generateDir( currentDir ); | 223 | generateDir( currentDir ); |
224 | } | 224 | } |
225 | 225 | ||
226 | void FileView::setDir( const QString & dir ) | 226 | void FileView::setDir( const QString & dir ) |
227 | { | 227 | { |
228 | if ( dir.startsWith( "/dev" ) ) { | 228 | if ( dir.startsWith( "/dev" ) ) { |
229 | QMessageBox::warning( this, tr( "File Manager" ), | 229 | QMessageBox::warning( this, tr( "File Manager" ), |
230 | tr( "Can't show /dev/ directory." ), tr( "&Ok" ) ); | 230 | tr( "Can't show /dev/ directory." ), tr( "&Ok" ) ); |
231 | return; | 231 | return; |
232 | } | 232 | } |
233 | dirHistory += currentDir; | 233 | dirHistory += currentDir; |
234 | generateDir( dir ); | 234 | generateDir( dir ); |
235 | } | 235 | } |
236 | 236 | ||
237 | void FileView::generateDir( const QString & dir ) | 237 | void FileView::generateDir( const QString & dir ) |
238 | { | 238 | { |
239 | if(menuKeepsOpen){ | 239 | if(menuKeepsOpen){ |
240 | cancelMenuTimer(); | 240 | cancelMenuTimer(); |
241 | } | 241 | } |
242 | QDir d( dir ); | 242 | QDir d( dir ); |
243 | 243 | ||
244 | if( d.exists() && !d.isReadable() ) return; | 244 | if( d.exists() && !d.isReadable() ) return; |
245 | 245 | ||
246 | currentDir = d.canonicalPath(); | 246 | currentDir = d.canonicalPath(); |
247 | 247 | ||
248 | if( !showHidden) | 248 | if( !showHidden) |
249 | d.setFilter( QDir::Dirs | QDir::Files ); | 249 | d.setFilter( QDir::Dirs | QDir::Files ); |
250 | else | 250 | else |
251 | d.setFilter( QDir::Dirs | QDir::Files |QDir::Hidden | QDir::All); | 251 | d.setFilter( QDir::Dirs | QDir::Files |QDir::Hidden | QDir::All); |
252 | 252 | ||
253 | d.setSorting( QDir::Name | QDir::DirsFirst | QDir::IgnoreCase | QDir::Reversed ); | 253 | d.setSorting( QDir::Name | QDir::DirsFirst | QDir::IgnoreCase | QDir::Reversed ); |
254 | 254 | ||
255 | 255 | ||
256 | const QFileInfoList * list = d.entryInfoList(); | 256 | const QFileInfoList * list = d.entryInfoList(); |
257 | QFileInfoListIterator it( *list ); | 257 | QFileInfoListIterator it( *list ); |
258 | QFileInfo *fi; | 258 | QFileInfo *fi; |
259 | 259 | ||
260 | clear(); | 260 | clear(); |
261 | while( (fi = it.current()) ){ | 261 | while( (fi = it.current()) ){ |
262 | if( (fi->fileName() == ".") || (fi->fileName() == "..") ){ | 262 | if( (fi->fileName() == ".") || (fi->fileName() == "..") ){ |
263 | ++it; | 263 | ++it; |
264 | continue; | 264 | continue; |
265 | } | 265 | } |
266 | if(!showSymlinks && fi->isSymLink()){ | 266 | if(!showSymlinks && fi->isSymLink()){ |
267 | ++it; | 267 | ++it; |
268 | continue; | 268 | continue; |
269 | } | 269 | } |
270 | (void) new FileItem( (QListView *) this, *fi ); | 270 | (void) new FileItem( (QListView *) this, *fi ); |
271 | ++it; | 271 | ++it; |
272 | } | 272 | } |
273 | emit dirChanged(); | 273 | emit dirChanged(); |
274 | } | 274 | } |
275 | 275 | ||
276 | void FileView::rename() | 276 | void FileView::rename() |
277 | { | 277 | { |
278 | itemToRename = (FileItem *) currentItem(); | 278 | itemToRename = (FileItem *) currentItem(); |
279 | const QPixmap * pm; | 279 | const QPixmap * pm; |
280 | int pmw; | 280 | int pmw; |
281 | 281 | ||
282 | if( itemToRename == NULL ) return; | 282 | if( itemToRename == NULL ) return; |
283 | 283 | ||
284 | if( ( pm = itemToRename->pixmap( 0 ) ) == NULL ) | 284 | if( ( pm = itemToRename->pixmap( 0 ) ) == NULL ) |
285 | pmw = 0; | 285 | pmw = 0; |
286 | else | 286 | else |
287 | pmw = pm->width(); | 287 | pmw = pm->width(); |
288 | 288 | ||
289 | ensureItemVisible( itemToRename ); | 289 | ensureItemVisible( itemToRename ); |
290 | horizontalScrollBar()->setValue( 0 ); | 290 | horizontalScrollBar()->setValue( 0 ); |
291 | horizontalScrollBar()->setEnabled( FALSE ); | 291 | horizontalScrollBar()->setEnabled( FALSE ); |
292 | verticalScrollBar()->setEnabled( FALSE ); | 292 | verticalScrollBar()->setEnabled( FALSE ); |
293 | 293 | ||
294 | selected = isSelected( itemToRename ); | 294 | selected = isSelected( itemToRename ); |
295 | setSelected( itemToRename, FALSE ); | 295 | setSelected( itemToRename, FALSE ); |
296 | 296 | ||
297 | if( le == NULL ){ | 297 | if( le == NULL ){ |
298 | le = new InlineEdit( this ); | 298 | le = new InlineEdit( this ); |
299 | le->setFrame( FALSE ); | 299 | le->setFrame( FALSE ); |
300 | connect( le, SIGNAL( lostFocus() ), SLOT( endRenaming() ) ); | 300 | connect( le, SIGNAL( lostFocus() ), SLOT( endRenaming() ) ); |
301 | } | 301 | } |
@@ -560,104 +560,104 @@ void FileView::newFolder() | |||
560 | if((i = (FileItem *) firstChild()) == 0) return; | 560 | if((i = (FileItem *) firstChild()) == 0) return; |
561 | 561 | ||
562 | while( i ){ | 562 | while( i ){ |
563 | if( i->isDir() && ( i->getFilePath() == nd ) ){ | 563 | if( i->isDir() && ( i->getFilePath() == nd ) ){ |
564 | setCurrentItem( i ); | 564 | setCurrentItem( i ); |
565 | rename(); | 565 | rename(); |
566 | break; | 566 | break; |
567 | } | 567 | } |
568 | i = (FileItem *) i->nextSibling(); | 568 | i = (FileItem *) i->nextSibling(); |
569 | } | 569 | } |
570 | } | 570 | } |
571 | 571 | ||
572 | void FileView::viewAsText() | 572 | void FileView::viewAsText() |
573 | { | 573 | { |
574 | FileItem * i = (FileItem *) currentItem(); | 574 | FileItem * i = (FileItem *) currentItem(); |
575 | QCopEnvelope e("QPE/Application/textedit","setDocument(QString)"); | 575 | QCopEnvelope e("QPE/Application/textedit","setDocument(QString)"); |
576 | e << i->getFilePath(); | 576 | e << i->getFilePath(); |
577 | // Global::execute( "textedit -f ", i->getFilePath() ); | 577 | // Global::execute( "textedit -f ", i->getFilePath() ); |
578 | } | 578 | } |
579 | 579 | ||
580 | void FileView::itemClicked( QListViewItem * i) | 580 | void FileView::itemClicked( QListViewItem * i) |
581 | { | 581 | { |
582 | FileItem * t = (FileItem *) i; | 582 | FileItem * t = (FileItem *) i; |
583 | 583 | ||
584 | if( t == NULL ) return; | 584 | if( t == NULL ) return; |
585 | if( t->isDir() ){ | 585 | if( t->isDir() ){ |
586 | setDir( t->getFilePath() ); | 586 | setDir( t->getFilePath() ); |
587 | } | 587 | } |
588 | } | 588 | } |
589 | 589 | ||
590 | void FileView::itemDblClicked( QListViewItem * i) | 590 | void FileView::itemDblClicked( QListViewItem * i) |
591 | { | 591 | { |
592 | if(menuKeepsOpen){ | 592 | if(menuKeepsOpen){ |
593 | cancelMenuTimer(); | 593 | cancelMenuTimer(); |
594 | } | 594 | } |
595 | 595 | ||
596 | FileItem * t = (FileItem *) i; | 596 | FileItem * t = (FileItem *) i; |
597 | 597 | ||
598 | if(t == NULL) return; | 598 | if(t == NULL) return; |
599 | if(t->launch() == -1){ | 599 | if(t->launch() == -1){ |
600 | QMessageBox::warning( this, tr( "Launch Application" ), | 600 | QMessageBox::warning( this, tr( "Launch Application" ), |
601 | tr( "Launch failed!" ), tr( "Ok" ) ); | 601 | tr( "Launch failed!" ), tr( "Ok" ) ); |
602 | } | 602 | } |
603 | } | 603 | } |
604 | 604 | ||
605 | void FileView::parentDir() | 605 | void FileView::parentDir() |
606 | { | 606 | { |
607 | setDir( currentDir + "./.." ); | 607 | setDir( currentDir + "./.." ); |
608 | } | 608 | } |
609 | 609 | ||
610 | void FileView::lastDir() | 610 | void FileView::lastDir() |
611 | { | 611 | { |
612 | if( dirHistory.count() == 0 ) return; | 612 | if( dirHistory.count() == 0 ) return; |
613 | 613 | ||
614 | QString newDir = dirHistory.last(); | 614 | QString newDir = dirHistory.last(); |
615 | dirHistory.remove( dirHistory.last() ); | 615 | dirHistory.remove( dirHistory.last() ); |
616 | generateDir( newDir ); | 616 | generateDir( newDir ); |
617 | } | 617 | } |
618 | 618 | ||
619 | void FileView::contentsMousePressEvent( QMouseEvent * e ) | 619 | void FileView::contentsMousePressEvent( QMouseEvent * e ) |
620 | { | 620 | { |
621 | QListView::contentsMousePressEvent( e ); | 621 | QListView::contentsMousePressEvent( e ); |
622 | menuTimer.start( 750, TRUE ); | 622 | menuTimer.start( 750, TRUE ); |
623 | } | 623 | } |
624 | 624 | ||
625 | void FileView::contentsMouseReleaseEvent( QMouseEvent * e ) | 625 | void FileView::contentsMouseReleaseEvent( QMouseEvent * e ) |
626 | { | 626 | { |
627 | QListView::contentsMouseReleaseEvent( e ); | 627 | QListView::contentsMouseReleaseEvent( e ); |
628 | if(!menuKeepsOpen){ | 628 | if(!menuKeepsOpen){ |
629 | menuTimer.stop(); | 629 | menuTimer.stop(); |
630 | } | 630 | } |
631 | 631 | ||
632 | } | 632 | } |
633 | 633 | ||
634 | void FileView::cancelMenuTimer() | 634 | void FileView::cancelMenuTimer() |
635 | { | 635 | { |
636 | if( menuTimer.isActive() ) | 636 | if( menuTimer.isActive() ) |
637 | menuTimer.stop(); | 637 | menuTimer.stop(); |
638 | } | 638 | } |
639 | 639 | ||
640 | void FileView::addToDocuments() | 640 | void FileView::addToDocuments() |
641 | { | 641 | { |
642 | FileItem * i = (FileItem *) currentItem(); | 642 | FileItem * i = (FileItem *) currentItem(); |
643 | DocLnk f; | 643 | DocLnk f; |
644 | QString n = i->text(0); | 644 | QString n = i->text(0); |
645 | n.replace(QRegExp("\\..*"),""); | 645 | n.replace(QRegExp("\\..*"),""); |
646 | f.setName( n ); | 646 | f.setName( n ); |
647 | f.setFile( i->getFilePath() ); | 647 | f.setFile( i->getFilePath() ); |
648 | f.writeLink(); | 648 | f.writeLink(); |
649 | } | 649 | } |
650 | 650 | ||
651 | void FileView::run() | 651 | void FileView::run() |
652 | { | 652 | { |
653 | FileItem * i = (FileItem *) currentItem(); | 653 | FileItem * i = (FileItem *) currentItem(); |
654 | i->launch(); | 654 | i->launch(); |
655 | } | 655 | } |
656 | 656 | ||
657 | void FileView::showFileMenu() | 657 | void FileView::showFileMenu() |
658 | { | 658 | { |
659 | FileItem * i = (FileItem *) currentItem(); | 659 | FileItem * i = (FileItem *) currentItem(); |
660 | if ( !i ) | 660 | if ( !i ) |
661 | return; | 661 | return; |
662 | 662 | ||
663 | QPopupMenu * m = new QPopupMenu( this ); | 663 | QPopupMenu * m = new QPopupMenu( this ); |
@@ -675,139 +675,139 @@ void FileView::showFileMenu() | |||
675 | 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() ) ); |
676 | else if( i->isExecutable() ) | 676 | else if( i->isExecutable() ) |
677 | 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() ) ); |
678 | 678 | ||
679 | m->insertItem( Resource::loadPixmap( "txt" ), tr( "View as text" ), | 679 | m->insertItem( Resource::loadPixmap( "txt" ), tr( "View as text" ), |
680 | this, SLOT( viewAsText() ) ); | 680 | this, SLOT( viewAsText() ) ); |
681 | 681 | ||
682 | m->insertSeparator(); | 682 | m->insertSeparator(); |
683 | } | 683 | } |
684 | 684 | ||
685 | m->insertItem( tr( "Rename" ), this, SLOT( rename() ) ); | 685 | m->insertItem( tr( "Rename" ), this, SLOT( rename() ) ); |
686 | m->insertItem( Resource::loadPixmap("cut"), | 686 | m->insertItem( Resource::loadPixmap("cut"), |
687 | tr( "Cut" ), this, SLOT( cut() ) ); | 687 | tr( "Cut" ), this, SLOT( cut() ) ); |
688 | m->insertItem( Resource::loadPixmap("copy"), | 688 | m->insertItem( Resource::loadPixmap("copy"), |
689 | 689 | ||
690 | tr( "Copy" ), this, SLOT( copy() ) ); | 690 | tr( "Copy" ), this, SLOT( copy() ) ); |
691 | m->insertItem( Resource::loadPixmap("paste"), | 691 | m->insertItem( Resource::loadPixmap("paste"), |
692 | tr( "Paste" ), this, SLOT( paste() ) ); | 692 | tr( "Paste" ), this, SLOT( paste() ) ); |
693 | m->insertItem( tr( "Change Permissions" ), this, SLOT( chPerm() ) ); | 693 | m->insertItem( tr( "Change Permissions" ), this, SLOT( chPerm() ) ); |
694 | m->insertItem(Resource::loadPixmap( "close" ), tr( "Delete" ), this, SLOT( del() ) ); | 694 | m->insertItem(Resource::loadPixmap( "close" ), tr( "Delete" ), this, SLOT( del() ) ); |
695 | m->insertSeparator(); | 695 | m->insertSeparator(); |
696 | m->insertItem( tr( "Select all" ), this, SLOT( selectAll() ) ); | 696 | m->insertItem( tr( "Select all" ), this, SLOT( selectAll() ) ); |
697 | m->insertItem( tr( "Deselect all" ), this, SLOT( deselectAll() ) ); | 697 | m->insertItem( tr( "Deselect all" ), this, SLOT( deselectAll() ) ); |
698 | m->popup( QCursor::pos() ); | 698 | m->popup( QCursor::pos() ); |
699 | } | 699 | } |
700 | 700 | ||
701 | // | 701 | // |
702 | // FileBrowser | 702 | // FileBrowser |
703 | // | 703 | // |
704 | 704 | ||
705 | void FileView::setShowHidden(bool hidden) | 705 | void FileView::setShowHidden(bool hidden) |
706 | { | 706 | { |
707 | showHidden=hidden; | 707 | showHidden=hidden; |
708 | } | 708 | } |
709 | 709 | ||
710 | void FileView::setShowSymlinks(bool symlinks) | 710 | void FileView::setShowSymlinks(bool symlinks) |
711 | { | 711 | { |
712 | showSymlinks=symlinks; | 712 | showSymlinks=symlinks; |
713 | } | 713 | } |
714 | 714 | ||
715 | void FileView::setMenuKeepsOpen(bool keepOpen) | 715 | void FileView::setMenuKeepsOpen(bool keepOpen) |
716 | { | 716 | { |
717 | menuKeepsOpen=keepOpen; | 717 | menuKeepsOpen=keepOpen; |
718 | } | 718 | } |
719 | 719 | ||
720 | FileBrowser::FileBrowser( QWidget * parent, | 720 | FileBrowser::FileBrowser( QWidget * parent, |
721 | const char * name, WFlags f ) : | 721 | const char * name, WFlags f ) : |
722 | QMainWindow( parent, name, f ) | 722 | QMainWindow( parent, name, f ) |
723 | { | 723 | { |
724 | init( QDir::current().canonicalPath() ); | 724 | init( QDir::current().canonicalPath() ); |
725 | } | 725 | } |
726 | 726 | ||
727 | FileBrowser::FileBrowser( const QString & dir, QWidget * parent, | 727 | FileBrowser::FileBrowser( const QString & dir, QWidget * parent, |
728 | const char * name, WFlags f ) : | 728 | const char * name, WFlags f ) : |
729 | QMainWindow( parent, name, f ) | 729 | QMainWindow( parent, name, f ) |
730 | { | 730 | { |
731 | init( dir ); | 731 | init( dir ); |
732 | } | 732 | } |
733 | 733 | ||
734 | void FileBrowser::init(const QString & dir) | 734 | void FileBrowser::init(const QString & dir) |
735 | { | 735 | { |
736 | setCaption( tr("File Manager") ); | 736 | setCaption( tr("File Manager") ); |
737 | setIcon( Resource::loadPixmap( "filebrowser_icon" ) ); | 737 | setIcon( Resource::loadPixmap( "filebrowser_icon" ) ); |
738 | 738 | ||
739 | Config cfg("Filebrowser"); | 739 | Config cfg("Filebrowser"); |
740 | cfg.setGroup("View"); | 740 | cfg.setGroup("View"); |
741 | bool showHidden=(cfg.readEntry("Hidden","FALSE") == "TRUE"); | 741 | bool showHidden=(cfg.readEntry("Hidden","FALSE") == "TRUE"); |
742 | bool showSymlinks=(cfg.readEntry("Symlinks","FALSE") == "TRUE"); | 742 | bool showSymlinks=(cfg.readEntry("Symlinks","FALSE") == "TRUE"); |
743 | 743 | ||
744 | cfg.setGroup("Menu"); | 744 | cfg.setGroup("Menu"); |
745 | bool menuKeepsOpen=(cfg.readEntry("KeepOpen", "FALSE") == "TRUE"); | 745 | bool menuKeepsOpen=(cfg.readEntry("KeepOpen", "FALSE") == "TRUE"); |
746 | 746 | ||
747 | 747 | ||
748 | fileView = new FileView( dir, this, 0, showHidden, showSymlinks ); | 748 | fileView = new FileView( dir, this, 0, showHidden, showSymlinks ); |
749 | fileView->setAllColumnsShowFocus( TRUE ); | 749 | fileView->setAllColumnsShowFocus( TRUE ); |
750 | fileView->setMenuKeepsOpen(menuKeepsOpen); | 750 | fileView->setMenuKeepsOpen(menuKeepsOpen); |
751 | 751 | ||
752 | setCentralWidget( fileView ); | 752 | setCentralWidget( fileView ); |
753 | setToolBarsMovable( FALSE ); | 753 | setToolBarsMovable( FALSE ); |
754 | 754 | ||
755 | QPEToolBar* toolBar = new QPEToolBar( this ); | 755 | QPEToolBar* toolBar = new QPEToolBar( this ); |
756 | toolBar->setHorizontalStretchable( TRUE ); | 756 | toolBar->setHorizontalStretchable( TRUE ); |
757 | 757 | ||
758 | QPEMenuBar* menuBar = new QPEMenuBar( toolBar ); | 758 | QPEMenuBar* menuBar = new QPEMenuBar( toolBar ); |
759 | 759 | ||
760 | dirMenu = new QPopupMenu( this ); | 760 | dirMenu = new QPopupMenu( this ); |
761 | menuBar->insertItem( tr( "Dir" ), dirMenu ); | 761 | menuBar->insertItem( tr( "Dir" ), dirMenu ); |
762 | 762 | ||
763 | sortMenu = new QPopupMenu( this ); | 763 | sortMenu = new QPopupMenu( this ); |
764 | menuBar->insertItem( tr( "Sort" ), sortMenu ); | 764 | menuBar->insertItem( tr( "Sort" ), sortMenu ); |
765 | sortMenu->insertItem( tr( "by Name "), this, SLOT( sortName() ) ); | 765 | sortMenu->insertItem( tr( "by Name "), this, SLOT( sortName() ) ); |
766 | sortMenu->insertItem( tr( "by Size "), this, SLOT( sortSize() ) ); | 766 | sortMenu->insertItem( tr( "by Size "), this, SLOT( sortSize() ) ); |
767 | sortMenu->insertItem( tr( "by Date "), this, SLOT( sortDate() ) ); | 767 | sortMenu->insertItem( tr( "by Date "), this, SLOT( sortDate() ) ); |
768 | sortMenu->insertItem( tr( "by Type "), this, SLOT( sortType() ) ); | 768 | sortMenu->insertItem( tr( "by Type "), this, SLOT( sortType() ) ); |
769 | sortMenu->insertSeparator(); | 769 | sortMenu->insertSeparator(); |
770 | sortMenu->insertItem( tr( "Ascending" ), this, SLOT( updateSorting() ) ); | 770 | sortMenu->insertItem( tr( "Ascending" ), this, SLOT( updateSorting() ) ); |
771 | 771 | ||
772 | sortMenu->setItemChecked( sortMenu->idAt( 5 ), TRUE ); | 772 | sortMenu->setItemChecked( sortMenu->idAt( 5 ), TRUE ); |
773 | sortMenu->setItemChecked( sortMenu->idAt( 0 ), TRUE ); | 773 | sortMenu->setItemChecked( sortMenu->idAt( 0 ), TRUE ); |
774 | 774 | ||
775 | viewMenu = new QPopupMenu( this); | 775 | viewMenu = new QPopupMenu( this); |
776 | viewMenu->insertItem( tr( "Hidden"), this, SLOT( updateShowHidden() ) ); | 776 | viewMenu->insertItem( tr( "Hidden"), this, SLOT( updateShowHidden() ) ); |
777 | viewMenu->insertItem( tr( "Symlinks"), this, SLOT( updateShowSymlinks() ) ); | 777 | viewMenu->insertItem( tr( "Symlinks"), this, SLOT( updateShowSymlinks() ) ); |
778 | viewMenu->setItemChecked( viewMenu->idAt( 0 ), showHidden ); | 778 | viewMenu->setItemChecked( viewMenu->idAt( 0 ), showHidden ); |
779 | viewMenu->setItemChecked( viewMenu->idAt( 1 ), showSymlinks ); | 779 | viewMenu->setItemChecked( viewMenu->idAt( 1 ), showSymlinks ); |
780 | 780 | ||
781 | menuBar->insertItem( tr("View"), viewMenu ); | 781 | menuBar->insertItem( tr("View"), viewMenu ); |
782 | 782 | ||
783 | toolBar = new QPEToolBar( this ); | 783 | toolBar = new QPEToolBar( this ); |
784 | 784 | ||
785 | lastAction = new QAction( tr("Previous dir"), Resource::loadIconSet( "back" ), | 785 | lastAction = new QAction( tr("Previous dir"), Resource::loadIconSet( "back" ), |
786 | QString::null, 0, this, 0 ); | 786 | QString::null, 0, this, 0 ); |
787 | connect( lastAction, SIGNAL( activated() ), fileView, SLOT( lastDir() ) ); | 787 | connect( lastAction, SIGNAL( activated() ), fileView, SLOT( lastDir() ) ); |
788 | lastAction->addTo( toolBar ); | 788 | lastAction->addTo( toolBar ); |
789 | lastAction->setEnabled( FALSE ); | 789 | lastAction->setEnabled( FALSE ); |
790 | 790 | ||
791 | upAction = new QAction( tr("Parent dir"), Resource::loadIconSet( "up" ), | 791 | upAction = new QAction( tr("Parent dir"), Resource::loadIconSet( "up" ), |
792 | QString::null, 0, this, 0 ); | 792 | QString::null, 0, this, 0 ); |
793 | connect( upAction, SIGNAL( activated() ), fileView, SLOT( parentDir() ) ); | 793 | connect( upAction, SIGNAL( activated() ), fileView, SLOT( parentDir() ) ); |
794 | upAction->addTo( toolBar ); | 794 | upAction->addTo( toolBar ); |
795 | 795 | ||
796 | QAction *a = new QAction( tr("New folder"), Resource::loadPixmap( "newfolder" ), | 796 | QAction *a = new QAction( tr("New folder"), Resource::loadPixmap( "newfolder" ), |
797 | QString::null, 0, this, 0 ); | 797 | QString::null, 0, this, 0 ); |
798 | connect( a, SIGNAL( activated() ), fileView, SLOT( newFolder() ) ); | 798 | connect( a, SIGNAL( activated() ), fileView, SLOT( newFolder() ) ); |
799 | a->addTo( toolBar ); | 799 | a->addTo( toolBar ); |
800 | 800 | ||
801 | a = new QAction( tr("Cut"), Resource::loadPixmap( "cut" ), | 801 | a = new QAction( tr("Cut"), Resource::loadPixmap( "cut" ), |
802 | QString::null, 0, this, 0 ); | 802 | QString::null, 0, this, 0 ); |
803 | connect( a, SIGNAL( activated() ), fileView, SLOT( cut() ) ); | 803 | connect( a, SIGNAL( activated() ), fileView, SLOT( cut() ) ); |
804 | a->addTo( toolBar ); | 804 | a->addTo( toolBar ); |
805 | 805 | ||
806 | a = new QAction( tr("Copy"), Resource::loadPixmap( "copy" ), | 806 | a = new QAction( tr("Copy"), Resource::loadPixmap( "copy" ), |
807 | QString::null, 0, this, 0 ); | 807 | QString::null, 0, this, 0 ); |
808 | connect( a, SIGNAL( activated() ), fileView, SLOT( copy() ) ); | 808 | connect( a, SIGNAL( activated() ), fileView, SLOT( copy() ) ); |
809 | a->addTo( toolBar ); | 809 | a->addTo( toolBar ); |
810 | 810 | ||
811 | pasteAction = new QAction( tr("Paste"), Resource::loadPixmap( "paste" ), | 811 | pasteAction = new QAction( tr("Paste"), Resource::loadPixmap( "paste" ), |
812 | QString::null, 0, this, 0 ); | 812 | QString::null, 0, this, 0 ); |
813 | connect( pasteAction, SIGNAL( activated() ), fileView, SLOT( paste() ) ); | 813 | connect( pasteAction, SIGNAL( activated() ), fileView, SLOT( paste() ) ); |
@@ -927,57 +927,57 @@ void FileBrowser::updateSorting() | |||
927 | 927 | ||
928 | void FileView::chPerm() { | 928 | void FileView::chPerm() { |
929 | FileItem * i; | 929 | FileItem * i; |
930 | QStringList fl; | 930 | QStringList fl; |
931 | QString cmd; | 931 | QString cmd; |
932 | int err; | 932 | int err; |
933 | 933 | ||
934 | if((i = (FileItem *) firstChild()) == 0) return; | 934 | if((i = (FileItem *) firstChild()) == 0) return; |
935 | 935 | ||
936 | while( i ){ | 936 | while( i ){ |
937 | if( i->isSelected() ){ | 937 | if( i->isSelected() ){ |
938 | fl += i->getFilePath(); | 938 | fl += i->getFilePath(); |
939 | } | 939 | } |
940 | i = (FileItem *) i->nextSibling(); | 940 | i = (FileItem *) i->nextSibling(); |
941 | } | 941 | } |
942 | if( fl.count() < 1 ) return; | 942 | if( fl.count() < 1 ) return; |
943 | if( QMessageBox::warning( this, tr("Change permissions"), tr("Are you sure?"), | 943 | if( QMessageBox::warning( this, tr("Change permissions"), tr("Are you sure?"), |
944 | tr("Yes"), tr("No") ) == 0) { | 944 | tr("Yes"), tr("No") ) == 0) { |
945 | for ( QStringList::Iterator it = fl.begin(); it != fl.end(); ++it ) { | 945 | for ( QStringList::Iterator it = fl.begin(); it != fl.end(); ++it ) { |
946 | filePermissions *filePerm; | 946 | filePermissions *filePerm; |
947 | filePerm = new filePermissions(this, "Permissions",true,0,(const QString &)(*it)); | 947 | filePerm = new filePermissions(this, "Permissions",true,0,(const QString &)(*it)); |
948 | filePerm->exec(); | 948 | filePerm->exec(); |
949 | if( filePerm) | 949 | if( filePerm) |
950 | delete filePerm; | 950 | delete filePerm; |
951 | break; | 951 | break; |
952 | } | 952 | } |
953 | updateDir(); | 953 | updateDir(); |
954 | } | 954 | } |
955 | } | 955 | } |
956 | 956 | ||
957 | void FileBrowser::updateShowHidden() | 957 | void FileBrowser::updateShowHidden() |
958 | { | 958 | { |
959 | bool valShowHidden=viewMenu->isItemChecked( viewMenu->idAt( 0 ) ); | 959 | bool valShowHidden=viewMenu->isItemChecked( viewMenu->idAt( 0 ) ); |
960 | valShowHidden=!valShowHidden; | 960 | valShowHidden=!valShowHidden; |
961 | viewMenu->setItemChecked( viewMenu->idAt( 0 ), valShowHidden ); | 961 | viewMenu->setItemChecked( viewMenu->idAt( 0 ), valShowHidden ); |
962 | fileView->setShowHidden(valShowHidden); | 962 | fileView->setShowHidden(valShowHidden); |
963 | 963 | ||
964 | Config cfg("Filebrowser"); | 964 | Config cfg("Filebrowser"); |
965 | cfg.setGroup("View"); | 965 | cfg.setGroup("View"); |
966 | cfg.writeEntry("Hidden",valShowHidden?"TRUE":"FALSE"); | 966 | cfg.writeEntry("Hidden",valShowHidden?"TRUE":"FALSE"); |
967 | 967 | ||
968 | fileView->updateDir(); | 968 | fileView->updateDir(); |
969 | } | 969 | } |
970 | 970 | ||
971 | void FileBrowser::updateShowSymlinks() | 971 | void FileBrowser::updateShowSymlinks() |
972 | { | 972 | { |
973 | bool valShowSymlinks=viewMenu->isItemChecked( viewMenu->idAt( 1 ) ); | 973 | bool valShowSymlinks=viewMenu->isItemChecked( viewMenu->idAt( 1 ) ); |
974 | valShowSymlinks=!valShowSymlinks; | 974 | valShowSymlinks=!valShowSymlinks; |
975 | viewMenu->setItemChecked( viewMenu->idAt( 1 ), valShowSymlinks ); | 975 | viewMenu->setItemChecked( viewMenu->idAt( 1 ), valShowSymlinks ); |
976 | fileView->setShowSymlinks(valShowSymlinks); | 976 | fileView->setShowSymlinks(valShowSymlinks); |
977 | 977 | ||
978 | Config cfg("Filebrowser"); | 978 | Config cfg("Filebrowser"); |
979 | cfg.setGroup("View"); | 979 | cfg.setGroup("View"); |
980 | cfg.writeEntry("Symlinks",valShowSymlinks?"TRUE":"FALSE"); | 980 | cfg.writeEntry("Symlinks",valShowSymlinks?"TRUE":"FALSE"); |
981 | 981 | ||
982 | fileView->updateDir(); | 982 | fileView->updateDir(); |
983 | } | 983 | } |