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