-rw-r--r-- | noncore/unsupported/filebrowser/filebrowser.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/noncore/unsupported/filebrowser/filebrowser.cpp b/noncore/unsupported/filebrowser/filebrowser.cpp index 10dff07..41e7634 100644 --- a/noncore/unsupported/filebrowser/filebrowser.cpp +++ b/noncore/unsupported/filebrowser/filebrowser.cpp | |||
@@ -1,414 +1,414 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include "inlineedit.h" | 21 | #include "inlineedit.h" |
22 | #include "filebrowser.h" | 22 | #include "filebrowser.h" |
23 | #include "filePermissions.h" | 23 | #include "filePermissions.h" |
24 | #include <qpe/resource.h> | 24 | #include <qpe/resource.h> |
25 | #include <qpe/global.h> | 25 | #include <qpe/global.h> |
26 | #include <qpe/mimetype.h> | 26 | #include <qpe/mimetype.h> |
27 | #include <qpe/applnk.h> | 27 | #include <qpe/applnk.h> |
28 | 28 | ||
29 | #include <qcopchannel_qws.h> | 29 | #include <qcopchannel_qws.h> |
30 | #include <qcopenvelope_qws.h> | 30 | #include <qpe/qcopenvelope_qws.h> |
31 | 31 | ||
32 | #include <qmessagebox.h> | 32 | #include <qmessagebox.h> |
33 | #include <qdir.h> | 33 | #include <qdir.h> |
34 | #include <qregexp.h> | 34 | #include <qregexp.h> |
35 | #include <qheader.h> | 35 | #include <qheader.h> |
36 | #include <qpe/qpetoolbar.h> | 36 | #include <qpe/qpetoolbar.h> |
37 | #include <qpopupmenu.h> | 37 | #include <qpopupmenu.h> |
38 | #include <qpe/qpemenubar.h> | 38 | #include <qpe/qpemenubar.h> |
39 | #include <qaction.h> | 39 | #include <qaction.h> |
40 | #include <qstringlist.h> | 40 | #include <qstringlist.h> |
41 | #include <qcursor.h> | 41 | #include <qcursor.h> |
42 | #include <qmultilineedit.h> | 42 | #include <qmultilineedit.h> |
43 | #include <qfont.h> | 43 | #include <qfont.h> |
44 | 44 | ||
45 | #include <unistd.h> | 45 | #include <unistd.h> |
46 | #include <stdlib.h> | 46 | #include <stdlib.h> |
47 | #include <sys/stat.h> | 47 | #include <sys/stat.h> |
48 | 48 | ||
49 | // | 49 | // |
50 | // FileItem | 50 | // FileItem |
51 | // | 51 | // |
52 | FileItem::FileItem( QListView * parent, const QFileInfo & fi ) | 52 | FileItem::FileItem( QListView * parent, const QFileInfo & fi ) |
53 | : QListViewItem( parent ), | 53 | : QListViewItem( parent ), |
54 | fileInfo( fi ) | 54 | fileInfo( fi ) |
55 | { | 55 | { |
56 | QDate d = fi.lastModified().date(); | 56 | QDate d = fi.lastModified().date(); |
57 | 57 | ||
58 | setText( 0, fi.fileName() ); | 58 | setText( 0, fi.fileName() ); |
59 | setText( 1, sizeString( fi.size() ) + " " ); | 59 | setText( 1, sizeString( fi.size() ) + " " ); |
60 | setText( 2, QString().sprintf("%4d-%02d-%02d",d.year(), d.month(), d.day() ) ); | 60 | setText( 2, QString().sprintf("%4d-%02d-%02d",d.year(), d.month(), d.day() ) ); |
61 | 61 | ||
62 | MimeType mt(fi.filePath()); | 62 | MimeType mt(fi.filePath()); |
63 | 63 | ||
64 | if( fi.isDir() ) | 64 | if( fi.isDir() ) |
65 | setText( 3, "directory" ); | 65 | setText( 3, "directory" ); |
66 | else if( isLib() ) | 66 | else if( isLib() ) |
67 | setText( 3, "library" ); | 67 | setText( 3, "library" ); |
68 | else | 68 | else |
69 | setText( 3, mt.description() ); | 69 | setText( 3, mt.description() ); |
70 | 70 | ||
71 | QPixmap pm; | 71 | QPixmap pm; |
72 | if( fi.isDir() ){ | 72 | if( fi.isDir() ){ |
73 | if( !QDir( fi.filePath() ).isReadable() ) | 73 | if( !QDir( fi.filePath() ).isReadable() ) |
74 | pm = Resource::loadPixmap( "lockedfolder" ); | 74 | pm = Resource::loadPixmap( "lockedfolder" ); |
75 | else | 75 | else |
76 | pm = Resource::loadPixmap( "folder" ); | 76 | pm = Resource::loadPixmap( "folder" ); |
77 | } | 77 | } |
78 | else if( !fi.isReadable() ) | 78 | else if( !fi.isReadable() ) |
79 | pm = Resource::loadPixmap( "locked" ); | 79 | pm = Resource::loadPixmap( "locked" ); |
80 | else if( isLib() ) | 80 | else if( isLib() ) |
81 | pm = Resource::loadPixmap( "library" ); | 81 | pm = Resource::loadPixmap( "library" ); |
82 | else | 82 | else |
83 | pm = mt.pixmap(); | 83 | pm = mt.pixmap(); |
84 | if ( pm.isNull() ) | 84 | if ( pm.isNull() ) |
85 | pm = Resource::loadPixmap("UnknownDocument-14"); | 85 | pm = Resource::loadPixmap("UnknownDocument-14"); |
86 | setPixmap(0,pm); | 86 | setPixmap(0,pm); |
87 | } | 87 | } |
88 | 88 | ||
89 | QString FileItem::sizeString( unsigned int s ) | 89 | QString FileItem::sizeString( unsigned int s ) |
90 | { | 90 | { |
91 | double size = s; | 91 | double size = s; |
92 | 92 | ||
93 | if ( size > 1024 * 1024 * 1024 ) | 93 | if ( size > 1024 * 1024 * 1024 ) |
94 | return QString().sprintf( "%.1f", size / ( 1024 * 1024 * 1024 ) ) + "G"; | 94 | return QString().sprintf( "%.1f", size / ( 1024 * 1024 * 1024 ) ) + "G"; |
95 | else if ( size > 1024 * 1024 ) | 95 | else if ( size > 1024 * 1024 ) |
96 | return QString().sprintf( "%.1f", size / ( 1024 * 1024 ) ) + "M"; | 96 | return QString().sprintf( "%.1f", size / ( 1024 * 1024 ) ) + "M"; |
97 | else if ( size > 1024 ) | 97 | else if ( size > 1024 ) |
98 | return QString().sprintf( "%.1f", size / ( 1024 ) ) + "K"; | 98 | return QString().sprintf( "%.1f", size / ( 1024 ) ) + "K"; |
99 | else | 99 | else |
100 | return QString::number( size ) + "B"; | 100 | return QString::number( size ) + "B"; |
101 | } | 101 | } |
102 | 102 | ||
103 | QString FileItem::key( int column, bool ascending ) const | 103 | QString FileItem::key( int column, bool ascending ) const |
104 | { | 104 | { |
105 | QString tmp; | 105 | QString tmp; |
106 | 106 | ||
107 | ascending = ascending; | 107 | ascending = ascending; |
108 | 108 | ||
109 | if( (column == 0) && fileInfo.isDir() ){ // Sort by name | 109 | if( (column == 0) && fileInfo.isDir() ){ // Sort by name |
110 | // We want the directories to appear at the top of the list | 110 | // We want the directories to appear at the top of the list |
111 | tmp = (char) 0; | 111 | tmp = (char) 0; |
112 | return (tmp + text( column ).lower()); | 112 | return (tmp + text( column ).lower()); |
113 | } | 113 | } |
114 | else if( column == 2 ) { // Sort by date | 114 | else if( column == 2 ) { // Sort by date |
115 | QDateTime epoch( QDate( 1980, 1, 1 ) ); | 115 | QDateTime epoch( QDate( 1980, 1, 1 ) ); |
116 | tmp.sprintf( "%08d", epoch.secsTo( fileInfo.lastModified() ) ); | 116 | tmp.sprintf( "%08d", epoch.secsTo( fileInfo.lastModified() ) ); |
117 | return tmp; | 117 | return tmp; |
118 | } | 118 | } |
119 | else if( column == 1 ) { // Sort by size | 119 | else if( column == 1 ) { // Sort by size |
120 | return tmp.sprintf( "%08d", fileInfo.size() ); | 120 | return tmp.sprintf( "%08d", fileInfo.size() ); |
121 | } | 121 | } |
122 | 122 | ||
123 | return text( column ).lower(); | 123 | return text( column ).lower(); |
124 | } | 124 | } |
125 | 125 | ||
126 | bool FileItem::isLib() | 126 | bool FileItem::isLib() |
127 | { | 127 | { |
128 | // This is of course not foolproof | 128 | // This is of course not foolproof |
129 | if( !qstrncmp("lib", fileInfo.baseName(), 3) && | 129 | if( !qstrncmp("lib", fileInfo.baseName(), 3) && |
130 | ( fileInfo.extension().contains( "so" ) || | 130 | ( fileInfo.extension().contains( "so" ) || |
131 | fileInfo.extension().contains( "a" ) ) ) | 131 | fileInfo.extension().contains( "a" ) ) ) |
132 | return TRUE; | 132 | return TRUE; |
133 | else | 133 | else |
134 | return FALSE; | 134 | return FALSE; |
135 | } | 135 | } |
136 | 136 | ||
137 | int FileItem::launch() | 137 | int FileItem::launch() |
138 | { | 138 | { |
139 | DocLnk doc( fileInfo.filePath(), FALSE ); | 139 | DocLnk doc( fileInfo.filePath(), FALSE ); |
140 | doc.execute(); | 140 | doc.execute(); |
141 | listView()->clearSelection(); | 141 | listView()->clearSelection(); |
142 | return 1; | 142 | return 1; |
143 | } | 143 | } |
144 | 144 | ||
145 | bool FileItem::rename( const QString & name ) | 145 | bool FileItem::rename( const QString & name ) |
146 | { | 146 | { |
147 | QString oldpath, newpath; | 147 | QString oldpath, newpath; |
148 | 148 | ||
149 | if ( name.isEmpty() ) | 149 | if ( name.isEmpty() ) |
150 | return FALSE; | 150 | return FALSE; |
151 | 151 | ||
152 | if ( name.contains( QRegExp("[/\\$\"\'\\*\\?]") ) ) | 152 | if ( name.contains( QRegExp("[/\\$\"\'\\*\\?]") ) ) |
153 | return FALSE; | 153 | return FALSE; |
154 | 154 | ||
155 | oldpath = fileInfo.filePath(); | 155 | oldpath = fileInfo.filePath(); |
156 | newpath = fileInfo.dirPath() + "/" + name; | 156 | newpath = fileInfo.dirPath() + "/" + name; |
157 | 157 | ||
158 | if ( ::rename( (const char *) oldpath, (const char *) newpath ) != 0 ) | 158 | if ( ::rename( (const char *) oldpath, (const char *) newpath ) != 0 ) |
159 | return FALSE; | 159 | return FALSE; |
160 | else | 160 | else |
161 | return TRUE; | 161 | return TRUE; |
162 | } | 162 | } |
163 | 163 | ||
164 | // | 164 | // |
165 | // FileView | 165 | // FileView |
166 | // | 166 | // |
167 | FileView::FileView( const QString & dir, QWidget * parent, | 167 | FileView::FileView( const QString & dir, QWidget * parent, |
168 | const char * name ) | 168 | const char * name ) |
169 | : QListView( parent, name ), | 169 | : QListView( parent, name ), |
170 | menuTimer( this ), | 170 | menuTimer( this ), |
171 | le( NULL ), | 171 | le( NULL ), |
172 | itemToRename( NULL ) | 172 | itemToRename( NULL ) |
173 | { | 173 | { |
174 | addColumn( "Name" ); | 174 | addColumn( "Name" ); |
175 | addColumn( "Date" ); | 175 | addColumn( "Date" ); |
176 | addColumn( "Size" ); | 176 | addColumn( "Size" ); |
177 | addColumn( "Type" ); | 177 | addColumn( "Type" ); |
178 | 178 | ||
179 | setMultiSelection( TRUE ); | 179 | setMultiSelection( TRUE ); |
180 | header()->hide(); | 180 | header()->hide(); |
181 | 181 | ||
182 | setColumnWidthMode( 0, Manual ); | 182 | setColumnWidthMode( 0, Manual ); |
183 | setColumnWidthMode( 3, Manual ); | 183 | setColumnWidthMode( 3, Manual ); |
184 | 184 | ||
185 | // right align yize column | 185 | // right align yize column |
186 | setColumnAlignment( 1, AlignRight ); | 186 | setColumnAlignment( 1, AlignRight ); |
187 | 187 | ||
188 | generateDir( dir ); | 188 | generateDir( dir ); |
189 | 189 | ||
190 | connect( this, SIGNAL( clicked( QListViewItem * )), | 190 | connect( this, SIGNAL( clicked( QListViewItem * )), |
191 | SLOT( itemClicked( QListViewItem * )) ); | 191 | SLOT( itemClicked( QListViewItem * )) ); |
192 | connect( this, SIGNAL( doubleClicked( QListViewItem * )), | 192 | connect( this, SIGNAL( doubleClicked( QListViewItem * )), |
193 | SLOT( itemDblClicked( QListViewItem * )) ); | 193 | SLOT( itemDblClicked( QListViewItem * )) ); |
194 | connect( this, SIGNAL( selectionChanged() ), SLOT( cancelMenuTimer() ) ); | 194 | connect( this, SIGNAL( selectionChanged() ), SLOT( cancelMenuTimer() ) ); |
195 | connect( &menuTimer, SIGNAL( timeout() ), SLOT( showFileMenu() ) ); | 195 | connect( &menuTimer, SIGNAL( timeout() ), SLOT( showFileMenu() ) ); |
196 | } | 196 | } |
197 | 197 | ||
198 | void FileView::resizeEvent( QResizeEvent *e ) | 198 | void FileView::resizeEvent( QResizeEvent *e ) |
199 | { | 199 | { |
200 | setColumnWidth( 0, width() - 2 * lineWidth() - 20 - columnWidth( 1 ) - columnWidth( 2 ) ); | 200 | setColumnWidth( 0, width() - 2 * lineWidth() - 20 - columnWidth( 1 ) - columnWidth( 2 ) ); |
201 | 201 | ||
202 | // hide type column, we use it for "sort by type" only | 202 | // hide type column, we use it for "sort by type" only |
203 | setColumnWidth( 3, 0 ); | 203 | setColumnWidth( 3, 0 ); |
204 | QListView::resizeEvent( e ); | 204 | QListView::resizeEvent( e ); |
205 | } | 205 | } |
206 | 206 | ||
207 | void FileView::updateDir() | 207 | void FileView::updateDir() |
208 | { | 208 | { |
209 | generateDir( currentDir ); | 209 | generateDir( currentDir ); |
210 | } | 210 | } |
211 | 211 | ||
212 | void FileView::setDir( const QString & dir ) | 212 | void FileView::setDir( const QString & dir ) |
213 | { | 213 | { |
214 | if ( dir.startsWith( "/dev" ) ) { | 214 | if ( dir.startsWith( "/dev" ) ) { |
215 | QMessageBox::warning( this, tr( "File Manager" ), | 215 | QMessageBox::warning( this, tr( "File Manager" ), |
216 | tr( "Can't show /dev/ directory." ), tr( "&Ok" ) ); | 216 | tr( "Can't show /dev/ directory." ), tr( "&Ok" ) ); |
217 | return; | 217 | return; |
218 | } | 218 | } |
219 | dirHistory += currentDir; | 219 | dirHistory += currentDir; |
220 | generateDir( dir ); | 220 | generateDir( dir ); |
221 | } | 221 | } |
222 | 222 | ||
223 | void FileView::generateDir( const QString & dir ) | 223 | void FileView::generateDir( const QString & dir ) |
224 | { | 224 | { |
225 | QDir d( dir ); | 225 | QDir d( dir ); |
226 | 226 | ||
227 | if( d.exists() && !d.isReadable() ) return; | 227 | if( d.exists() && !d.isReadable() ) return; |
228 | 228 | ||
229 | currentDir = d.canonicalPath(); | 229 | currentDir = d.canonicalPath(); |
230 | 230 | ||
231 | d.setFilter( QDir::Dirs | QDir::Files ); | 231 | d.setFilter( QDir::Dirs | QDir::Files ); |
232 | d.setSorting( QDir::Name | QDir::DirsFirst | QDir::IgnoreCase | | 232 | d.setSorting( QDir::Name | QDir::DirsFirst | QDir::IgnoreCase | |
233 | QDir::Reversed ); | 233 | QDir::Reversed ); |
234 | 234 | ||
235 | const QFileInfoList * list = d.entryInfoList(); | 235 | const QFileInfoList * list = d.entryInfoList(); |
236 | QFileInfoListIterator it( *list ); | 236 | QFileInfoListIterator it( *list ); |
237 | QFileInfo *fi; | 237 | QFileInfo *fi; |
238 | 238 | ||
239 | clear(); | 239 | clear(); |
240 | while( (fi = it.current()) ){ | 240 | while( (fi = it.current()) ){ |
241 | if( (fi->fileName() == ".") || (fi->fileName() == "..") ){ | 241 | if( (fi->fileName() == ".") || (fi->fileName() == "..") ){ |
242 | ++it; | 242 | ++it; |
243 | continue; | 243 | continue; |
244 | } | 244 | } |
245 | (void) new FileItem( (QListView *) this, *fi ); | 245 | (void) new FileItem( (QListView *) this, *fi ); |
246 | ++it; | 246 | ++it; |
247 | } | 247 | } |
248 | 248 | ||
249 | emit dirChanged(); | 249 | emit dirChanged(); |
250 | } | 250 | } |
251 | 251 | ||
252 | void FileView::rename() | 252 | void FileView::rename() |
253 | { | 253 | { |
254 | itemToRename = (FileItem *) currentItem(); | 254 | itemToRename = (FileItem *) currentItem(); |
255 | const QPixmap * pm; | 255 | const QPixmap * pm; |
256 | int pmw; | 256 | int pmw; |
257 | 257 | ||
258 | if( itemToRename == NULL ) return; | 258 | if( itemToRename == NULL ) return; |
259 | 259 | ||
260 | if( ( pm = itemToRename->pixmap( 0 ) ) == NULL ) | 260 | if( ( pm = itemToRename->pixmap( 0 ) ) == NULL ) |
261 | pmw = 0; | 261 | pmw = 0; |
262 | else | 262 | else |
263 | pmw = pm->width(); | 263 | pmw = pm->width(); |
264 | 264 | ||
265 | ensureItemVisible( itemToRename ); | 265 | ensureItemVisible( itemToRename ); |
266 | horizontalScrollBar()->setValue( 0 ); | 266 | horizontalScrollBar()->setValue( 0 ); |
267 | horizontalScrollBar()->setEnabled( FALSE ); | 267 | horizontalScrollBar()->setEnabled( FALSE ); |
268 | verticalScrollBar()->setEnabled( FALSE ); | 268 | verticalScrollBar()->setEnabled( FALSE ); |
269 | 269 | ||
270 | selected = isSelected( itemToRename ); | 270 | selected = isSelected( itemToRename ); |
271 | setSelected( itemToRename, FALSE ); | 271 | setSelected( itemToRename, FALSE ); |
272 | 272 | ||
273 | if( le == NULL ){ | 273 | if( le == NULL ){ |
274 | le = new InlineEdit( this ); | 274 | le = new InlineEdit( this ); |
275 | le->setFrame( FALSE ); | 275 | le->setFrame( FALSE ); |
276 | connect( le, SIGNAL( lostFocus() ), SLOT( endRenaming() ) ); | 276 | connect( le, SIGNAL( lostFocus() ), SLOT( endRenaming() ) ); |
277 | } | 277 | } |
278 | 278 | ||
279 | QRect r = itemRect( itemToRename ); | 279 | QRect r = itemRect( itemToRename ); |
280 | r.setTop( r.top() + frameWidth() + 1 ); | 280 | r.setTop( r.top() + frameWidth() + 1 ); |
281 | r.setLeft( r.left() + frameWidth() + pmw ); | 281 | r.setLeft( r.left() + frameWidth() + pmw ); |
282 | r.setBottom( r.bottom() + frameWidth() ); | 282 | r.setBottom( r.bottom() + frameWidth() ); |
283 | r.setWidth( columnWidth( 0 ) - pmw ); | 283 | r.setWidth( columnWidth( 0 ) - pmw ); |
284 | 284 | ||
285 | le->setGeometry( r ); | 285 | le->setGeometry( r ); |
286 | le->setText( itemToRename->text( 0 ) ); | 286 | le->setText( itemToRename->text( 0 ) ); |
287 | le->selectAll(); | 287 | le->selectAll(); |
288 | le->show(); | 288 | le->show(); |
289 | le->setFocus(); | 289 | le->setFocus(); |
290 | } | 290 | } |
291 | 291 | ||
292 | void FileView::endRenaming() | 292 | void FileView::endRenaming() |
293 | { | 293 | { |
294 | if( le && itemToRename ){ | 294 | if( le && itemToRename ){ |
295 | le->hide(); | 295 | le->hide(); |
296 | setSelected( itemToRename, selected ); | 296 | setSelected( itemToRename, selected ); |
297 | 297 | ||
298 | if( !itemToRename->rename( le->text() ) ){ | 298 | if( !itemToRename->rename( le->text() ) ){ |
299 | QMessageBox::warning( this, tr( "Rename file" ), | 299 | QMessageBox::warning( this, tr( "Rename file" ), |
300 | tr( "Rename failed!" ), tr( "&Ok" ) ); | 300 | tr( "Rename failed!" ), tr( "&Ok" ) ); |
301 | } else { | 301 | } else { |
302 | updateDir(); | 302 | updateDir(); |
303 | } | 303 | } |
304 | itemToRename = NULL; | 304 | itemToRename = NULL; |
305 | horizontalScrollBar()->setEnabled( TRUE ); | 305 | horizontalScrollBar()->setEnabled( TRUE ); |
306 | verticalScrollBar()->setEnabled( TRUE ); | 306 | verticalScrollBar()->setEnabled( TRUE ); |
307 | } | 307 | } |
308 | } | 308 | } |
309 | 309 | ||
310 | void FileView::copy() | 310 | void FileView::copy() |
311 | { | 311 | { |
312 | // dont keep cut files any longer than necessary | 312 | // dont keep cut files any longer than necessary |
313 | // ##### a better inmplementation might be to rename the CUT file | 313 | // ##### a better inmplementation might be to rename the CUT file |
314 | // ##### to ".QPE-FILEBROWSER-MOVING" rather than copying it. | 314 | // ##### to ".QPE-FILEBROWSER-MOVING" rather than copying it. |
315 | system ( "rm -rf /tmp/qpemoving" ); | 315 | system ( "rm -rf /tmp/qpemoving" ); |
316 | 316 | ||
317 | FileItem * i; | 317 | FileItem * i; |
318 | 318 | ||
319 | if((i = (FileItem *) firstChild()) == 0) return; | 319 | if((i = (FileItem *) firstChild()) == 0) return; |
320 | 320 | ||
321 | flist.clear(); | 321 | flist.clear(); |
322 | while( i ){ | 322 | while( i ){ |
323 | if( i->isSelected() /*&& !i->isDir()*/ ){ | 323 | if( i->isSelected() /*&& !i->isDir()*/ ){ |
324 | flist += i->getFilePath(); | 324 | flist += i->getFilePath(); |
325 | } | 325 | } |
326 | i = (FileItem *) i->nextSibling(); | 326 | i = (FileItem *) i->nextSibling(); |
327 | } | 327 | } |
328 | } | 328 | } |
329 | 329 | ||
330 | void FileView::paste() | 330 | void FileView::paste() |
331 | { | 331 | { |
332 | int i, err; | 332 | int i, err; |
333 | QString cmd, dest, basename, cd = currentDir; | 333 | QString cmd, dest, basename, cd = currentDir; |
334 | 334 | ||
335 | if(cd == "/") cd = ""; | 335 | if(cd == "/") cd = ""; |
336 | 336 | ||
337 | for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it ) { | 337 | for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it ) { |
338 | basename = (*it).mid((*it).findRev("/") + 1, (*it).length()); | 338 | basename = (*it).mid((*it).findRev("/") + 1, (*it).length()); |
339 | 339 | ||
340 | dest = cd + "/" + basename; | 340 | dest = cd + "/" + basename; |
341 | if( QFile( dest ).exists() ){ | 341 | if( QFile( dest ).exists() ){ |
342 | i = 1; | 342 | i = 1; |
343 | dest = cd + "/Copy of " + basename; | 343 | dest = cd + "/Copy of " + basename; |
344 | while( QFile( dest ).exists() ){ | 344 | while( QFile( dest ).exists() ){ |
345 | dest.sprintf( "%s/Copy (%d) of %s", (const char *) cd, i++, | 345 | dest.sprintf( "%s/Copy (%d) of %s", (const char *) cd, i++, |
346 | (const char *) basename ); | 346 | (const char *) basename ); |
347 | } | 347 | } |
348 | } | 348 | } |
349 | 349 | ||
350 | // | 350 | // |
351 | // Copy a directory recursively using the "cp" command - | 351 | // Copy a directory recursively using the "cp" command - |
352 | // may have to be changed | 352 | // may have to be changed |
353 | // | 353 | // |
354 | if( QFileInfo( (*it) ).isDir() ){ | 354 | if( QFileInfo( (*it) ).isDir() ){ |
355 | cmd = "/bin/cp -fpR \"" + (*it) +"\" " + "\"" + dest + "\""; | 355 | cmd = "/bin/cp -fpR \"" + (*it) +"\" " + "\"" + dest + "\""; |
356 | err = system( (const char *) cmd ); | 356 | err = system( (const char *) cmd ); |
357 | } else if( !copyFile( dest, (*it) ) ){ | 357 | } else if( !copyFile( dest, (*it) ) ){ |
358 | err = -1; | 358 | err = -1; |
359 | } else { | 359 | } else { |
360 | err = 0; | 360 | err = 0; |
361 | } | 361 | } |
362 | 362 | ||
363 | if ( err != 0 ) { | 363 | if ( err != 0 ) { |
364 | QMessageBox::warning( this, tr("Paste file"), tr("Paste failed!"), | 364 | QMessageBox::warning( this, tr("Paste file"), tr("Paste failed!"), |
365 | tr("Ok") ); | 365 | tr("Ok") ); |
366 | break; | 366 | break; |
367 | } else { | 367 | } else { |
368 | updateDir(); | 368 | updateDir(); |
369 | QListViewItem * i = firstChild(); | 369 | QListViewItem * i = firstChild(); |
370 | basename = dest.mid( dest.findRev("/") + 1, dest.length() ); | 370 | basename = dest.mid( dest.findRev("/") + 1, dest.length() ); |
371 | 371 | ||
372 | while( i ){ | 372 | while( i ){ |
373 | if( i->text(0) == basename ){ | 373 | if( i->text(0) == basename ){ |
374 | setCurrentItem( i ); | 374 | setCurrentItem( i ); |
375 | ensureItemVisible( i ); | 375 | ensureItemVisible( i ); |
376 | break; | 376 | break; |
377 | } | 377 | } |
378 | i = i->nextSibling(); | 378 | i = i->nextSibling(); |
379 | } | 379 | } |
380 | } | 380 | } |
381 | } | 381 | } |
382 | } | 382 | } |
383 | 383 | ||
384 | bool FileView::copyFile( const QString & dest, const QString & src ) | 384 | bool FileView::copyFile( const QString & dest, const QString & src ) |
385 | { | 385 | { |
386 | char bf[ 50000 ]; | 386 | char bf[ 50000 ]; |
387 | int bytesRead; | 387 | int bytesRead; |
388 | bool success = TRUE; | 388 | bool success = TRUE; |
389 | struct stat status; | 389 | struct stat status; |
390 | 390 | ||
391 | QFile s( src ); | 391 | QFile s( src ); |
392 | QFile d( dest ); | 392 | QFile d( dest ); |
393 | 393 | ||
394 | if( s.open( IO_ReadOnly | IO_Raw ) && | 394 | if( s.open( IO_ReadOnly | IO_Raw ) && |
395 | d.open( IO_WriteOnly | IO_Raw ) ) | 395 | d.open( IO_WriteOnly | IO_Raw ) ) |
396 | { | 396 | { |
397 | while( (bytesRead = s.readBlock( bf, sizeof( bf ) )) == | 397 | while( (bytesRead = s.readBlock( bf, sizeof( bf ) )) == |
398 | sizeof( bf ) ) | 398 | sizeof( bf ) ) |
399 | { | 399 | { |
400 | if( d.writeBlock( bf, sizeof( bf ) ) != sizeof( bf ) ){ | 400 | if( d.writeBlock( bf, sizeof( bf ) ) != sizeof( bf ) ){ |
401 | success = FALSE; | 401 | success = FALSE; |
402 | break; | 402 | break; |
403 | } | 403 | } |
404 | } | 404 | } |
405 | if( success && (bytesRead > 0) ){ | 405 | if( success && (bytesRead > 0) ){ |
406 | d.writeBlock( bf, bytesRead ); | 406 | d.writeBlock( bf, bytesRead ); |
407 | } | 407 | } |
408 | } else { | 408 | } else { |
409 | success = FALSE; | 409 | success = FALSE; |
410 | } | 410 | } |
411 | 411 | ||
412 | // Set file permissions | 412 | // Set file permissions |
413 | if( stat( (const char *) src, &status ) == 0 ){ | 413 | if( stat( (const char *) src, &status ) == 0 ){ |
414 | chmod( (const char *) dest, status.st_mode ); | 414 | chmod( (const char *) dest, status.st_mode ); |