Diffstat (limited to 'noncore/unsupported/filebrowser') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/unsupported/filebrowser/.cvsignore | 2 | ||||
-rw-r--r-- | noncore/unsupported/filebrowser/Makefile.in | 136 | ||||
-rw-r--r-- | noncore/unsupported/filebrowser/filebrowser.cpp | 850 | ||||
-rw-r--r-- | noncore/unsupported/filebrowser/filebrowser.h | 141 | ||||
-rw-r--r-- | noncore/unsupported/filebrowser/filebrowser.pro | 12 | ||||
-rw-r--r-- | noncore/unsupported/filebrowser/inlineedit.cpp | 30 | ||||
-rw-r--r-- | noncore/unsupported/filebrowser/inlineedit.h | 39 | ||||
-rw-r--r-- | noncore/unsupported/filebrowser/main.cpp | 41 | ||||
-rw-r--r-- | noncore/unsupported/filebrowser/qpe-filebrowser.control | 9 |
9 files changed, 1260 insertions, 0 deletions
diff --git a/noncore/unsupported/filebrowser/.cvsignore b/noncore/unsupported/filebrowser/.cvsignore new file mode 100644 index 0000000..6fe2396 --- a/dev/null +++ b/noncore/unsupported/filebrowser/.cvsignore | |||
@@ -0,0 +1,2 @@ | |||
1 | moc_* | ||
2 | Makefile | ||
diff --git a/noncore/unsupported/filebrowser/Makefile.in b/noncore/unsupported/filebrowser/Makefile.in new file mode 100644 index 0000000..c7238ea --- a/dev/null +++ b/noncore/unsupported/filebrowser/Makefile.in | |||
@@ -0,0 +1,136 @@ | |||
1 | ############################################################################# | ||
2 | |||
3 | ####### Compiler, tools and options | ||
4 | |||
5 | CXX =$(SYSCONF_CXX) $(QT_CXX_MT) | ||
6 | CXXFLAGS=$(SYSCONF_CXXFLAGS_QT) $(SYSCONF_CXXFLAGS) | ||
7 | CC =$(SYSCONF_CC) $(QT_C_MT) | ||
8 | CFLAGS =$(SYSCONF_CFLAGS) | ||
9 | INCPATH =-I$(QPEDIR)/include | ||
10 | LFLAGS =$(SYSCONF_LFLAGS_QT) $(SYSCONF_RPATH_QT) $(SYSCONF_LFLAGS) $(QT_LFLAGS_MT) | ||
11 | LIBS =$(SUBLIBS) -lqpe $(SYSCONF_LIBS_QT) $(SYSCONF_LIBS) $(SYSCONF_LIBS_QTAPP) | ||
12 | MOC =$(SYSCONF_MOC) | ||
13 | UIC =$(SYSCONF_UIC) | ||
14 | |||
15 | ####### Target | ||
16 | |||
17 | DESTDIR = $(QPEDIR)/bin/ | ||
18 | VER_MAJ = 1 | ||
19 | VER_MIN = 0 | ||
20 | VER_PATCH = 0 | ||
21 | TARGET= filebrowser | ||
22 | TARGET1 = lib$(TARGET).so.$(VER_MAJ) | ||
23 | |||
24 | ####### Files | ||
25 | |||
26 | HEADERS =inlineedit.h \ | ||
27 | filebrowser.h | ||
28 | SOURCES =filebrowser.cpp \ | ||
29 | inlineedit.cpp \ | ||
30 | main.cpp | ||
31 | OBJECTS =filebrowser.o \ | ||
32 | inlineedit.o \ | ||
33 | main.o | ||
34 | INTERFACES = | ||
35 | UICDECLS = | ||
36 | UICIMPLS = | ||
37 | SRCMOC =moc_inlineedit.cpp \ | ||
38 | moc_filebrowser.cpp | ||
39 | OBJMOC =moc_inlineedit.o \ | ||
40 | moc_filebrowser.o | ||
41 | |||
42 | |||
43 | ####### Implicit rules | ||
44 | |||
45 | .SUFFIXES: .cpp .cxx .cc .C .c | ||
46 | |||
47 | .cpp.o: | ||
48 | $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $< | ||
49 | |||
50 | .cxx.o: | ||
51 | $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $< | ||
52 | |||
53 | .cc.o: | ||
54 | $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $< | ||
55 | |||
56 | .C.o: | ||
57 | $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $< | ||
58 | |||
59 | .c.o: | ||
60 | $(CC) -c $(CFLAGS) $(INCPATH) -o $@ $< | ||
61 | |||
62 | ####### Build rules | ||
63 | |||
64 | |||
65 | all: $(DESTDIR)$(TARGET) | ||
66 | |||
67 | $(DESTDIR)$(TARGET): $(UICDECLS) $(OBJECTS) $(OBJMOC) $(SUBLIBS) | ||
68 | $(SYSCONF_LINK) $(LFLAGS) -o $(DESTDIR)$(TARGET) $(OBJECTS) $(OBJMOC) $(LIBS) | ||
69 | |||
70 | moc: $(SRCMOC) | ||
71 | |||
72 | tmake: | ||
73 | tmake filebrowser.pro | ||
74 | |||
75 | clean: | ||
76 | -rm -f $(OBJECTS) $(OBJMOC) $(SRCMOC) $(UICIMPLS) $(UICDECLS) | ||
77 | -rm -f *~ core | ||
78 | -rm -f allmoc.cpp | ||
79 | |||
80 | ####### Extension Modules | ||
81 | |||
82 | listpromodules: | ||
83 | @echo | ||
84 | |||
85 | listallmodules: | ||
86 | @echo | ||
87 | |||
88 | listaddonpromodules: | ||
89 | @echo | ||
90 | |||
91 | listaddonentmodules: | ||
92 | @echo | ||
93 | |||
94 | |||
95 | REQUIRES= | ||
96 | |||
97 | ####### Sub-libraries | ||
98 | |||
99 | |||
100 | ###### Combined headers | ||
101 | |||
102 | |||
103 | |||
104 | ####### Compile | ||
105 | |||
106 | filebrowser.o: filebrowser.cpp \ | ||
107 | inlineedit.h \ | ||
108 | filebrowser.h \ | ||
109 | $(QPEDIR)/include/qpe/resource.h \ | ||
110 | $(QPEDIR)/include/qpe/global.h \ | ||
111 | $(QPEDIR)/include/qpe/mimetype.h \ | ||
112 | $(QPEDIR)/include/qpe/applnk.h \ | ||
113 | $(QPEDIR)/include/qpe/qpetoolbar.h \ | ||
114 | $(QPEDIR)/include/qpe/qpemenubar.h | ||
115 | |||
116 | inlineedit.o: inlineedit.cpp \ | ||
117 | inlineedit.h | ||
118 | |||
119 | main.o: main.cpp \ | ||
120 | filebrowser.h \ | ||
121 | $(QPEDIR)/include/qpe/qpeapplication.h \ | ||
122 | $(QPEDIR)/include/qpe/mimetype.h | ||
123 | |||
124 | moc_inlineedit.o: moc_inlineedit.cpp \ | ||
125 | inlineedit.h | ||
126 | |||
127 | moc_filebrowser.o: moc_filebrowser.cpp \ | ||
128 | filebrowser.h | ||
129 | |||
130 | moc_inlineedit.cpp: inlineedit.h | ||
131 | $(MOC) inlineedit.h -o moc_inlineedit.cpp | ||
132 | |||
133 | moc_filebrowser.cpp: filebrowser.h | ||
134 | $(MOC) filebrowser.h -o moc_filebrowser.cpp | ||
135 | |||
136 | |||
diff --git a/noncore/unsupported/filebrowser/filebrowser.cpp b/noncore/unsupported/filebrowser/filebrowser.cpp new file mode 100644 index 0000000..9439bb8 --- a/dev/null +++ b/noncore/unsupported/filebrowser/filebrowser.cpp | |||
@@ -0,0 +1,850 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
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 | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
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. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | |||
21 | #include "inlineedit.h" | ||
22 | #include "filebrowser.h" | ||
23 | |||
24 | #include <qpe/resource.h> | ||
25 | #include <qpe/global.h> | ||
26 | #include <qpe/mimetype.h> | ||
27 | #include <qpe/applnk.h> | ||
28 | |||
29 | #include <qcopchannel_qws.h> | ||
30 | #include <qmessagebox.h> | ||
31 | #include <qdir.h> | ||
32 | #include <qregexp.h> | ||
33 | #include <qheader.h> | ||
34 | #include <qpe/qpetoolbar.h> | ||
35 | #include <qpopupmenu.h> | ||
36 | #include <qpe/qpemenubar.h> | ||
37 | #include <qaction.h> | ||
38 | #include <qstringlist.h> | ||
39 | #include <qcursor.h> | ||
40 | #include <qmultilineedit.h> | ||
41 | #include <qfont.h> | ||
42 | |||
43 | #include <unistd.h> | ||
44 | #include <stdlib.h> | ||
45 | #include <sys/stat.h> | ||
46 | |||
47 | // | ||
48 | // FileItem | ||
49 | // | ||
50 | FileItem::FileItem( QListView * parent, const QFileInfo & fi ) | ||
51 | : QListViewItem( parent ), | ||
52 | fileInfo( fi ) | ||
53 | { | ||
54 | QDate d = fi.lastModified().date(); | ||
55 | |||
56 | setText( 0, fi.fileName() ); | ||
57 | setText( 1, sizeString( fi.size() ) + " " ); | ||
58 | setText( 2, QString().sprintf("%4d-%02d-%02d",d.year(), d.month(), d.day() ) ); | ||
59 | |||
60 | MimeType mt(fi.filePath()); | ||
61 | |||
62 | if( fi.isDir() ) | ||
63 | setText( 3, "directory" ); | ||
64 | else if( isLib() ) | ||
65 | setText( 3, "library" ); | ||
66 | else | ||
67 | setText( 3, mt.description() ); | ||
68 | |||
69 | QPixmap pm; | ||
70 | if( fi.isDir() ){ | ||
71 | if( !QDir( fi.filePath() ).isReadable() ) | ||
72 | pm = Resource::loadPixmap( "lockedfolder" ); | ||
73 | else | ||
74 | pm = Resource::loadPixmap( "folder" ); | ||
75 | } | ||
76 | else if( !fi.isReadable() ) | ||
77 | pm = Resource::loadPixmap( "locked" ); | ||
78 | else if( isLib() ) | ||
79 | pm = Resource::loadPixmap( "library" ); | ||
80 | else | ||
81 | pm = mt.pixmap(); | ||
82 | if ( pm.isNull() ) | ||
83 | pm = Resource::loadPixmap("UnknownDocument-14"); | ||
84 | setPixmap(0,pm); | ||
85 | } | ||
86 | |||
87 | QString FileItem::sizeString( unsigned int s ) | ||
88 | { | ||
89 | double size = s; | ||
90 | |||
91 | if ( size > 1024 * 1024 * 1024 ) | ||
92 | return QString().sprintf( "%.1f", size / ( 1024 * 1024 * 1024 ) ) + "G"; | ||
93 | else if ( size > 1024 * 1024 ) | ||
94 | return QString().sprintf( "%.1f", size / ( 1024 * 1024 ) ) + "M"; | ||
95 | else if ( size > 1024 ) | ||
96 | return QString().sprintf( "%.1f", size / ( 1024 ) ) + "K"; | ||
97 | else | ||
98 | return QString::number( size ) + "B"; | ||
99 | } | ||
100 | |||
101 | QString FileItem::key( int column, bool ascending ) const | ||
102 | { | ||
103 | QString tmp; | ||
104 | |||
105 | ascending = ascending; | ||
106 | |||
107 | if( (column == 0) && fileInfo.isDir() ){ // Sort by name | ||
108 | // We want the directories to appear at the top of the list | ||
109 | tmp = (char) 0; | ||
110 | return (tmp + text( column ).lower()); | ||
111 | } | ||
112 | else if( column == 2 ) { // Sort by date | ||
113 | QDateTime epoch( QDate( 1980, 1, 1 ) ); | ||
114 | tmp.sprintf( "%08d", epoch.secsTo( fileInfo.lastModified() ) ); | ||
115 | return tmp; | ||
116 | } | ||
117 | else if( column == 1 ) { // Sort by size | ||
118 | return tmp.sprintf( "%08d", fileInfo.size() ); | ||
119 | } | ||
120 | |||
121 | return text( column ).lower(); | ||
122 | } | ||
123 | |||
124 | bool FileItem::isLib() | ||
125 | { | ||
126 | // This is of course not foolproof | ||
127 | if( !qstrncmp("lib", fileInfo.baseName(), 3) && | ||
128 | ( fileInfo.extension().contains( "so" ) || | ||
129 | fileInfo.extension().contains( "a" ) ) ) | ||
130 | return TRUE; | ||
131 | else | ||
132 | return FALSE; | ||
133 | } | ||
134 | |||
135 | int FileItem::launch() | ||
136 | { | ||
137 | DocLnk doc( fileInfo.filePath(), FALSE ); | ||
138 | doc.execute(); | ||
139 | listView()->clearSelection(); | ||
140 | return 1; | ||
141 | } | ||
142 | |||
143 | bool FileItem::rename( const QString & name ) | ||
144 | { | ||
145 | QString oldpath, newpath; | ||
146 | |||
147 | if ( name.isEmpty() ) | ||
148 | return FALSE; | ||
149 | |||
150 | if ( name.contains( QRegExp("[/\\$\"\'\\*\\?]") ) ) | ||
151 | return FALSE; | ||
152 | |||
153 | oldpath = fileInfo.filePath(); | ||
154 | newpath = fileInfo.dirPath() + "/" + name; | ||
155 | |||
156 | if ( ::rename( (const char *) oldpath, (const char *) newpath ) != 0 ) | ||
157 | return FALSE; | ||
158 | else | ||
159 | return TRUE; | ||
160 | } | ||
161 | |||
162 | // | ||
163 | // FileView | ||
164 | // | ||
165 | FileView::FileView( const QString & dir, QWidget * parent, | ||
166 | const char * name ) | ||
167 | : QListView( parent, name ), | ||
168 | menuTimer( this ), | ||
169 | le( NULL ), | ||
170 | itemToRename( NULL ) | ||
171 | { | ||
172 | addColumn( "Name" ); | ||
173 | addColumn( "Date" ); | ||
174 | addColumn( "Size" ); | ||
175 | addColumn( "Type" ); | ||
176 | |||
177 | setMultiSelection( TRUE ); | ||
178 | header()->hide(); | ||
179 | |||
180 | setColumnWidthMode( 0, Manual ); | ||
181 | setColumnWidthMode( 3, Manual ); | ||
182 | |||
183 | // right align yize column | ||
184 | setColumnAlignment( 1, AlignRight ); | ||
185 | |||
186 | generateDir( dir ); | ||
187 | |||
188 | connect( this, SIGNAL( clicked( QListViewItem * )), | ||
189 | SLOT( itemClicked( QListViewItem * )) ); | ||
190 | connect( this, SIGNAL( doubleClicked( QListViewItem * )), | ||
191 | SLOT( itemDblClicked( QListViewItem * )) ); | ||
192 | connect( this, SIGNAL( selectionChanged() ), SLOT( cancelMenuTimer() ) ); | ||
193 | connect( &menuTimer, SIGNAL( timeout() ), SLOT( showFileMenu() ) ); | ||
194 | } | ||
195 | |||
196 | void FileView::resizeEvent( QResizeEvent *e ) | ||
197 | { | ||
198 | setColumnWidth( 0, width() - 2 * lineWidth() - 20 - columnWidth( 1 ) - columnWidth( 2 ) ); | ||
199 | |||
200 | // hide type column, we use it for "sort by type" only | ||
201 | setColumnWidth( 3, 0 ); | ||
202 | QListView::resizeEvent( e ); | ||
203 | } | ||
204 | |||
205 | void FileView::updateDir() | ||
206 | { | ||
207 | generateDir( currentDir ); | ||
208 | } | ||
209 | |||
210 | void FileView::setDir( const QString & dir ) | ||
211 | { | ||
212 | if ( dir.startsWith( "/dev" ) ) { | ||
213 | QMessageBox::warning( this, tr( "File Manager" ), | ||
214 | tr( "Can't show /dev/ directory." ), tr( "&Ok" ) ); | ||
215 | return; | ||
216 | } | ||
217 | dirHistory += currentDir; | ||
218 | generateDir( dir ); | ||
219 | } | ||
220 | |||
221 | void FileView::generateDir( const QString & dir ) | ||
222 | { | ||
223 | QDir d( dir ); | ||
224 | |||
225 | if( d.exists() && !d.isReadable() ) return; | ||
226 | |||
227 | currentDir = d.canonicalPath(); | ||
228 | |||
229 | d.setFilter( QDir::Dirs | QDir::Files ); | ||
230 | d.setSorting( QDir::Name | QDir::DirsFirst | QDir::IgnoreCase | | ||
231 | QDir::Reversed ); | ||
232 | |||
233 | const QFileInfoList * list = d.entryInfoList(); | ||
234 | QFileInfoListIterator it( *list ); | ||
235 | QFileInfo *fi; | ||
236 | |||
237 | clear(); | ||
238 | while( (fi = it.current()) ){ | ||
239 | if( (fi->fileName() == ".") || (fi->fileName() == "..") ){ | ||
240 | ++it; | ||
241 | continue; | ||
242 | } | ||
243 | (void) new FileItem( (QListView *) this, *fi ); | ||
244 | ++it; | ||
245 | } | ||
246 | |||
247 | emit dirChanged(); | ||
248 | } | ||
249 | |||
250 | void FileView::rename() | ||
251 | { | ||
252 | itemToRename = (FileItem *) currentItem(); | ||
253 | const QPixmap * pm; | ||
254 | int pmw; | ||
255 | |||
256 | if( itemToRename == NULL ) return; | ||
257 | |||
258 | if( ( pm = itemToRename->pixmap( 0 ) ) == NULL ) | ||
259 | pmw = 0; | ||
260 | else | ||
261 | pmw = pm->width(); | ||
262 | |||
263 | ensureItemVisible( itemToRename ); | ||
264 | horizontalScrollBar()->setValue( 0 ); | ||
265 | horizontalScrollBar()->setEnabled( FALSE ); | ||
266 | verticalScrollBar()->setEnabled( FALSE ); | ||
267 | |||
268 | selected = isSelected( itemToRename ); | ||
269 | setSelected( itemToRename, FALSE ); | ||
270 | |||
271 | if( le == NULL ){ | ||
272 | le = new InlineEdit( this ); | ||
273 | le->setFrame( FALSE ); | ||
274 | connect( le, SIGNAL( lostFocus() ), SLOT( endRenaming() ) ); | ||
275 | } | ||
276 | |||
277 | QRect r = itemRect( itemToRename ); | ||
278 | r.setTop( r.top() + frameWidth() + 1 ); | ||
279 | r.setLeft( r.left() + frameWidth() + pmw ); | ||
280 | r.setBottom( r.bottom() + frameWidth() ); | ||
281 | r.setWidth( columnWidth( 0 ) - pmw ); | ||
282 | |||
283 | le->setGeometry( r ); | ||
284 | le->setText( itemToRename->text( 0 ) ); | ||
285 | le->selectAll(); | ||
286 | le->show(); | ||
287 | le->setFocus(); | ||
288 | } | ||
289 | |||
290 | void FileView::endRenaming() | ||
291 | { | ||
292 | if( le && itemToRename ){ | ||
293 | le->hide(); | ||
294 | setSelected( itemToRename, selected ); | ||
295 | |||
296 | if( !itemToRename->rename( le->text() ) ){ | ||
297 | QMessageBox::warning( this, tr( "Rename file" ), | ||
298 | tr( "Rename failed!" ), tr( "&Ok" ) ); | ||
299 | } else { | ||
300 | updateDir(); | ||
301 | } | ||
302 | itemToRename = NULL; | ||
303 | horizontalScrollBar()->setEnabled( TRUE ); | ||
304 | verticalScrollBar()->setEnabled( TRUE ); | ||
305 | } | ||
306 | } | ||
307 | |||
308 | void FileView::copy() | ||
309 | { | ||
310 | // dont keep cut files any longer than necessary | ||
311 | // ##### a better inmplementation might be to rename the CUT file | ||
312 | // ##### to ".QPE-FILEBROWSER-MOVING" rather than copying it. | ||
313 | system ( "rm -rf /tmp/qpemoving" ); | ||
314 | |||
315 | FileItem * i; | ||
316 | |||
317 | if((i = (FileItem *) firstChild()) == 0) return; | ||
318 | |||
319 | flist.clear(); | ||
320 | while( i ){ | ||
321 | if( i->isSelected() /*&& !i->isDir()*/ ){ | ||
322 | flist += i->getFilePath(); | ||
323 | } | ||
324 | i = (FileItem *) i->nextSibling(); | ||
325 | } | ||
326 | } | ||
327 | |||
328 | void FileView::paste() | ||
329 | { | ||
330 | int i, err; | ||
331 | QString cmd, dest, basename, cd = currentDir; | ||
332 | |||
333 | if(cd == "/") cd = ""; | ||
334 | |||
335 | for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it ) { | ||
336 | basename = (*it).mid((*it).findRev("/") + 1, (*it).length()); | ||
337 | |||
338 | dest = cd + "/" + basename; | ||
339 | if( QFile( dest ).exists() ){ | ||
340 | i = 1; | ||
341 | dest = cd + "/Copy of " + basename; | ||
342 | while( QFile( dest ).exists() ){ | ||
343 | dest.sprintf( "%s/Copy (%d) of %s", (const char *) cd, i++, | ||
344 | (const char *) basename ); | ||
345 | } | ||
346 | } | ||
347 | |||
348 | // | ||
349 | // Copy a directory recursively using the "cp" command - | ||
350 | // may have to be changed | ||
351 | // | ||
352 | if( QFileInfo( (*it) ).isDir() ){ | ||
353 | cmd = "/bin/cp -fpR \"" + (*it) +"\" " + "\"" + dest + "\""; | ||
354 | err = system( (const char *) cmd ); | ||
355 | } else if( !copyFile( dest, (*it) ) ){ | ||
356 | err = -1; | ||
357 | } else { | ||
358 | err = 0; | ||
359 | } | ||
360 | |||
361 | if ( err != 0 ) { | ||
362 | QMessageBox::warning( this, tr("Paste file"), tr("Paste failed!"), | ||
363 | tr("Ok") ); | ||
364 | break; | ||
365 | } else { | ||
366 | updateDir(); | ||
367 | QListViewItem * i = firstChild(); | ||
368 | basename = dest.mid( dest.findRev("/") + 1, dest.length() ); | ||
369 | |||
370 | while( i ){ | ||
371 | if( i->text(0) == basename ){ | ||
372 | setCurrentItem( i ); | ||
373 | ensureItemVisible( i ); | ||
374 | break; | ||
375 | } | ||
376 | i = i->nextSibling(); | ||
377 | } | ||
378 | } | ||
379 | } | ||
380 | } | ||
381 | |||
382 | bool FileView::copyFile( const QString & dest, const QString & src ) | ||
383 | { | ||
384 | char bf[ 50000 ]; | ||
385 | int bytesRead; | ||
386 | bool success = TRUE; | ||
387 | struct stat status; | ||
388 | |||
389 | QFile s( src ); | ||
390 | QFile d( dest ); | ||
391 | |||
392 | if( s.open( IO_ReadOnly | IO_Raw ) && | ||
393 | d.open( IO_WriteOnly | IO_Raw ) ) | ||
394 | { | ||
395 | while( (bytesRead = s.readBlock( bf, sizeof( bf ) )) == | ||
396 | sizeof( bf ) ) | ||
397 | { | ||
398 | if( d.writeBlock( bf, sizeof( bf ) ) != sizeof( bf ) ){ | ||
399 | success = FALSE; | ||
400 | break; | ||
401 | } | ||
402 | } | ||
403 | if( success && (bytesRead > 0) ){ | ||
404 | d.writeBlock( bf, bytesRead ); | ||
405 | } | ||
406 | } else { | ||
407 | success = FALSE; | ||
408 | } | ||
409 | |||
410 | // Set file permissions | ||
411 | if( stat( (const char *) src, &status ) == 0 ){ | ||
412 | chmod( (const char *) dest, status.st_mode ); | ||
413 | } | ||
414 | |||
415 | return success; | ||
416 | } | ||
417 | |||
418 | void FileView::cut() | ||
419 | { | ||
420 | int err; | ||
421 | // ##### a better inmplementation might be to rename the CUT file | ||
422 | // ##### to ".QPE-FILEBROWSER-MOVING" rather than copying it. | ||
423 | QString cmd, dest, basename, cd = "/tmp/qpemoving"; | ||
424 | QStringList newflist; | ||
425 | newflist.clear(); | ||
426 | |||
427 | cmd = "rm -rf " + cd; | ||
428 | system ( (const char *) cmd ); | ||
429 | cmd = "mkdir " + cd; | ||
430 | system( (const char *) cmd ); | ||
431 | |||
432 | // get the names of the files to cut | ||
433 | FileItem * item; | ||
434 | |||
435 | if((item = (FileItem *) firstChild()) == 0) return; | ||
436 | |||
437 | flist.clear(); | ||
438 | while( item ){ | ||
439 | if( item->isSelected() /*&& !item->isDir()*/ ){ | ||
440 | flist += item->getFilePath(); | ||
441 | } | ||
442 | item = (FileItem *) item->nextSibling(); | ||
443 | } | ||
444 | |||
445 | // move these files into a tmp dir | ||
446 | for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it ) { | ||
447 | basename = (*it).mid((*it).findRev("/") + 1, (*it).length()); | ||
448 | |||
449 | dest = cd + "/" + basename; | ||
450 | |||
451 | newflist += dest; | ||
452 | |||
453 | cmd = "/bin/mv -f \"" + (*it) +"\" " + "\"" + dest + "\""; | ||
454 | err = system( (const char *) cmd ); | ||
455 | |||
456 | if ( err != 0 ) { | ||
457 | QMessageBox::warning( this, tr("Cut file"), tr("Cut failed!"), | ||
458 | tr("Ok") ); | ||
459 | break; | ||
460 | } else { | ||
461 | updateDir(); | ||
462 | QListViewItem * im = firstChild(); | ||
463 | basename = dest.mid( dest.findRev("/") + 1, dest.length() ); | ||
464 | |||
465 | while( im ){ | ||
466 | if( im->text(0) == basename ){ | ||
467 | setCurrentItem( im ); | ||
468 | ensureItemVisible( im ); | ||
469 | break; | ||
470 | } | ||
471 | im = im->nextSibling(); | ||
472 | } | ||
473 | } | ||
474 | } | ||
475 | |||
476 | // update the filelist to point to tmp dir so paste works nicely | ||
477 | flist = newflist; | ||
478 | } | ||
479 | |||
480 | void FileView::del() | ||
481 | { | ||
482 | FileItem * i; | ||
483 | QStringList fl; | ||
484 | QString cmd; | ||
485 | int err; | ||
486 | |||
487 | if((i = (FileItem *) firstChild()) == 0) return; | ||
488 | |||
489 | while( i ){ | ||
490 | if( i->isSelected() ){ | ||
491 | fl += i->getFilePath(); | ||
492 | } | ||
493 | i = (FileItem *) i->nextSibling(); | ||
494 | } | ||
495 | if( fl.count() < 1 ) return; | ||
496 | |||
497 | if( QMessageBox::warning( this, tr("Delete"), tr("Are you sure?"), | ||
498 | tr("Yes"), tr("No") ) == 0) | ||
499 | { | ||
500 | // | ||
501 | // Dependant upon the "rm" command - will probably have to be replaced | ||
502 | // | ||
503 | for ( QStringList::Iterator it = fl.begin(); it != fl.end(); ++it ) { | ||
504 | cmd = "/bin/rm -rf \"" + (*it) + "\""; | ||
505 | err = system( (const char *) cmd ); | ||
506 | if ( err != 0 ) { | ||
507 | QMessageBox::warning( this, tr("Delete"), tr("Delete failed!"), | ||
508 | tr("Ok") ); | ||
509 | break; | ||
510 | } | ||
511 | } | ||
512 | updateDir(); | ||
513 | } | ||
514 | } | ||
515 | |||
516 | void FileView::newFolder() | ||
517 | { | ||
518 | int t = 1; | ||
519 | FileItem * i; | ||
520 | QString nd = currentDir + "/NewFolder"; | ||
521 | |||
522 | while( QFile( nd ).exists() ){ | ||
523 | nd.sprintf( "%s/NewFolder (%d)", (const char *) currentDir, t++ ); | ||
524 | } | ||
525 | |||
526 | if( mkdir( (const char *) nd, 0777 ) != 0){ | ||
527 | QMessageBox::warning( this, tr( "New folder" ), | ||
528 | tr( "Folder creation failed!" ), | ||
529 | tr( "Ok" ) ); | ||
530 | return; | ||
531 | } | ||
532 | updateDir(); | ||
533 | |||
534 | if((i = (FileItem *) firstChild()) == 0) return; | ||
535 | |||
536 | while( i ){ | ||
537 | if( i->isDir() && ( i->getFilePath() == nd ) ){ | ||
538 | setCurrentItem( i ); | ||
539 | rename(); | ||
540 | break; | ||
541 | } | ||
542 | i = (FileItem *) i->nextSibling(); | ||
543 | } | ||
544 | } | ||
545 | |||
546 | void FileView::viewAsText() | ||
547 | { | ||
548 | FileItem * i = (FileItem *) currentItem(); | ||
549 | Global::execute( "textedit -f ", i->getFilePath() ); | ||
550 | } | ||
551 | |||
552 | void FileView::itemClicked( QListViewItem * i) | ||
553 | { | ||
554 | FileItem * t = (FileItem *) i; | ||
555 | |||
556 | if( t == NULL ) return; | ||
557 | if( t->isDir() ){ | ||
558 | setDir( t->getFilePath() ); | ||
559 | } | ||
560 | } | ||
561 | |||
562 | void FileView::itemDblClicked( QListViewItem * i) | ||
563 | { | ||
564 | FileItem * t = (FileItem *) i; | ||
565 | |||
566 | if(t == NULL) return; | ||
567 | if(t->launch() == -1){ | ||
568 | QMessageBox::warning( this, tr( "Launch Application" ), | ||
569 | tr( "Launch failed!" ), tr( "Ok" ) ); | ||
570 | } | ||
571 | } | ||
572 | |||
573 | void FileView::parentDir() | ||
574 | { | ||
575 | setDir( currentDir + "./.." ); | ||
576 | } | ||
577 | |||
578 | void FileView::lastDir() | ||
579 | { | ||
580 | if( dirHistory.count() == 0 ) return; | ||
581 | |||
582 | QString newDir = dirHistory.last(); | ||
583 | dirHistory.remove( dirHistory.last() ); | ||
584 | generateDir( newDir ); | ||
585 | } | ||
586 | |||
587 | void FileView::contentsMousePressEvent( QMouseEvent * e ) | ||
588 | { | ||
589 | QListView::contentsMousePressEvent( e ); | ||
590 | menuTimer.start( 750, TRUE ); | ||
591 | } | ||
592 | |||
593 | void FileView::contentsMouseReleaseEvent( QMouseEvent * e ) | ||
594 | { | ||
595 | QListView::contentsMouseReleaseEvent( e ); | ||
596 | menuTimer.stop(); | ||
597 | } | ||
598 | |||
599 | void FileView::cancelMenuTimer() | ||
600 | { | ||
601 | if( menuTimer.isActive() ) | ||
602 | menuTimer.stop(); | ||
603 | } | ||
604 | |||
605 | void FileView::addToDocuments() | ||
606 | { | ||
607 | FileItem * i = (FileItem *) currentItem(); | ||
608 | DocLnk f; | ||
609 | QString n = i->text(0); | ||
610 | n.replace(QRegExp("\\..*"),""); | ||
611 | f.setName( n ); | ||
612 | f.setFile( i->getFilePath() ); | ||
613 | f.writeLink(); | ||
614 | } | ||
615 | |||
616 | void FileView::run() | ||
617 | { | ||
618 | FileItem * i = (FileItem *) currentItem(); | ||
619 | i->launch(); | ||
620 | } | ||
621 | |||
622 | void FileView::showFileMenu() | ||
623 | { | ||
624 | FileItem * i = (FileItem *) currentItem(); | ||
625 | if ( !i ) | ||
626 | return; | ||
627 | |||
628 | QPopupMenu * m = new QPopupMenu( this ); | ||
629 | |||
630 | if ( !i->isDir() ) { | ||
631 | m->insertItem( tr( "Add to Documents" ), this, SLOT( addToDocuments() ) ); | ||
632 | m->insertSeparator(); | ||
633 | } | ||
634 | |||
635 | MimeType mt(i->getFilePath()); | ||
636 | const AppLnk* app = mt.application(); | ||
637 | |||
638 | if ( !i->isDir() ) { | ||
639 | if ( app ) | ||
640 | m->insertItem( app->pixmap(), tr( "Open in " + app->name() ), this, SLOT( run() ) ); | ||
641 | else if( i->isExecutable() ) | ||
642 | m->insertItem( Resource::loadPixmap( i->text( 0 ) ), tr( "Run" ), this, SLOT( run() ) ); | ||
643 | |||
644 | m->insertItem( Resource::loadPixmap( "txt" ), tr( "View as text" ), | ||
645 | this, SLOT( viewAsText() ) ); | ||
646 | |||
647 | m->insertSeparator(); | ||
648 | } | ||
649 | |||
650 | m->insertItem( tr( "Rename" ), this, SLOT( rename() ) ); | ||
651 | m->insertItem( Resource::loadPixmap("cut"), | ||
652 | tr( "Cut" ), this, SLOT( cut() ) ); | ||
653 | m->insertItem( Resource::loadPixmap("copy"), | ||
654 | tr( "Copy" ), this, SLOT( copy() ) ); | ||
655 | m->insertItem( Resource::loadPixmap("paste"), | ||
656 | tr( "Paste" ), this, SLOT( paste() ) ); | ||
657 | m->insertItem( tr( "Delete" ), this, SLOT( del() ) ); | ||
658 | m->insertSeparator(); | ||
659 | m->insertItem( tr( "Select all" ), this, SLOT( selectAll() ) ); | ||
660 | m->insertItem( tr( "Deselect all" ), this, SLOT( deselectAll() ) ); | ||
661 | m->popup( QCursor::pos() ); | ||
662 | } | ||
663 | |||
664 | // | ||
665 | // FileBrowser | ||
666 | // | ||
667 | |||
668 | FileBrowser::FileBrowser( QWidget * parent, | ||
669 | const char * name, WFlags f ) : | ||
670 | QMainWindow( parent, name, f ) | ||
671 | { | ||
672 | init( QDir::current().canonicalPath() ); | ||
673 | } | ||
674 | |||
675 | FileBrowser::FileBrowser( const QString & dir, QWidget * parent, | ||
676 | const char * name, WFlags f ) : | ||
677 | QMainWindow( parent, name, f ) | ||
678 | { | ||
679 | init( dir ); | ||
680 | } | ||
681 | |||
682 | void FileBrowser::init(const QString & dir) | ||
683 | { | ||
684 | setCaption( tr("File Manager") ); | ||
685 | setIcon( Resource::loadPixmap( "filebrowser_icon" ) ); | ||
686 | |||
687 | fileView = new FileView( dir, this ); | ||
688 | fileView->setAllColumnsShowFocus( TRUE ); | ||
689 | |||
690 | setCentralWidget( fileView ); | ||
691 | setToolBarsMovable( FALSE ); | ||
692 | |||
693 | QPEToolBar* toolBar = new QPEToolBar( this ); | ||
694 | toolBar->setHorizontalStretchable( TRUE ); | ||
695 | |||
696 | QPEMenuBar* menuBar = new QPEMenuBar( toolBar ); | ||
697 | |||
698 | dirMenu = new QPopupMenu( this ); | ||
699 | menuBar->insertItem( tr( "Dir" ), dirMenu ); | ||
700 | |||
701 | sortMenu = new QPopupMenu( this ); | ||
702 | menuBar->insertItem( tr( "Sort" ), sortMenu ); | ||
703 | sortMenu->insertItem( tr( "by Name "), this, SLOT( sortName() ) ); | ||
704 | sortMenu->insertItem( tr( "by Size "), this, SLOT( sortSize() ) ); | ||
705 | sortMenu->insertItem( tr( "by Date "), this, SLOT( sortDate() ) ); | ||
706 | sortMenu->insertItem( tr( "by Type "), this, SLOT( sortType() ) ); | ||
707 | sortMenu->insertSeparator(); | ||
708 | sortMenu->insertItem( tr( "Ascending" ), this, SLOT( updateSorting() ) ); | ||
709 | sortMenu->setItemChecked( sortMenu->idAt( 5 ), TRUE ); | ||
710 | sortMenu->setItemChecked( sortMenu->idAt( 0 ), TRUE ); | ||
711 | |||
712 | toolBar = new QPEToolBar( this ); | ||
713 | |||
714 | lastAction = new QAction( tr("Previous dir"), Resource::loadIconSet( "back" ), | ||
715 | QString::null, 0, this, 0 ); | ||
716 | connect( lastAction, SIGNAL( activated() ), fileView, SLOT( lastDir() ) ); | ||
717 | lastAction->addTo( toolBar ); | ||
718 | lastAction->setEnabled( FALSE ); | ||
719 | |||
720 | upAction = new QAction( tr("Parent dir"), Resource::loadIconSet( "up" ), | ||
721 | QString::null, 0, this, 0 ); | ||
722 | connect( upAction, SIGNAL( activated() ), fileView, SLOT( parentDir() ) ); | ||
723 | upAction->addTo( toolBar ); | ||
724 | |||
725 | QAction *a = new QAction( tr("New folder"), Resource::loadPixmap( "newfolder" ), | ||
726 | QString::null, 0, this, 0 ); | ||
727 | connect( a, SIGNAL( activated() ), fileView, SLOT( newFolder() ) ); | ||
728 | a->addTo( toolBar ); | ||
729 | |||
730 | a = new QAction( tr("Cut"), Resource::loadPixmap( "cut" ), | ||
731 | QString::null, 0, this, 0 ); | ||
732 | connect( a, SIGNAL( activated() ), fileView, SLOT( cut() ) ); | ||
733 | a->addTo( toolBar ); | ||
734 | |||
735 | a = new QAction( tr("Copy"), Resource::loadPixmap( "copy" ), | ||
736 | QString::null, 0, this, 0 ); | ||
737 | connect( a, SIGNAL( activated() ), fileView, SLOT( copy() ) ); | ||
738 | a->addTo( toolBar ); | ||
739 | |||
740 | pasteAction = new QAction( tr("Paste"), Resource::loadPixmap( "paste" ), | ||
741 | QString::null, 0, this, 0 ); | ||
742 | connect( pasteAction, SIGNAL( activated() ), fileView, SLOT( paste() ) ); | ||
743 | pasteAction->addTo( toolBar ); | ||
744 | |||
745 | |||
746 | connect( fileView, SIGNAL( dirChanged() ), SLOT( updateDirMenu() ) ); | ||
747 | updateDirMenu(); | ||
748 | |||
749 | QCopChannel* pcmciaChannel = new QCopChannel( "QPE/Card", this ); | ||
750 | connect( pcmciaChannel, SIGNAL(received(const QCString &, const QByteArray &)), | ||
751 | this, SLOT(pcmciaMessage( const QCString &, const QByteArray &)) ); | ||
752 | } | ||
753 | |||
754 | void FileBrowser::pcmciaMessage( const QCString &msg, const QByteArray &) | ||
755 | { | ||
756 | if ( msg == "mtabChanged()" ) { | ||
757 | // ## Only really needed if current dir is on a card | ||
758 | fileView->updateDir(); | ||
759 | } | ||
760 | } | ||
761 | |||
762 | void FileBrowser::dirSelected( int id ) | ||
763 | { | ||
764 | int i = 0, j; | ||
765 | QString dir; | ||
766 | |||
767 | // Bulid target dir from menu | ||
768 | while( (j = dirMenu->idAt( i )) != id ){ | ||
769 | dir += dirMenu->text( j ).stripWhiteSpace(); | ||
770 | if( dirMenu->text( j ) != "/" ) dir += "/"; | ||
771 | i++; | ||
772 | } | ||
773 | dir += dirMenu->text( dirMenu->idAt( i ) ).stripWhiteSpace(); | ||
774 | |||
775 | fileView->setDir( dir ); | ||
776 | } | ||
777 | |||
778 | void FileBrowser::updateDirMenu() | ||
779 | { | ||
780 | QString spc, cd = fileView->cd(); | ||
781 | QStringList l = QStringList::split( "/", cd ); | ||
782 | int i = 0; | ||
783 | |||
784 | dirMenu->clear(); | ||
785 | dirMenu->insertItem( tr( "/" ), this, SLOT( dirSelected(int) ) ); | ||
786 | |||
787 | for ( QStringList::Iterator it = l.begin(); it != l.end(); ++it ) { | ||
788 | spc.fill( ' ', i++); | ||
789 | dirMenu->insertItem( spc + (*it), this, | ||
790 | SLOT( dirSelected(int) ) ); | ||
791 | } | ||
792 | dirMenu->setItemChecked( dirMenu->idAt( l.count() ), TRUE ); | ||
793 | |||
794 | lastAction->setEnabled( fileView->history().count() != 0 ); | ||
795 | upAction->setEnabled( cd != "/" ); | ||
796 | } | ||
797 | |||
798 | void FileBrowser::sortName() | ||
799 | { | ||
800 | fileView->setSorting( 0, sortMenu->isItemChecked( sortMenu->idAt( 5 ) ) ); | ||
801 | fileView->sort(); | ||
802 | sortMenu->setItemChecked( sortMenu->idAt( 0 ), TRUE ); | ||
803 | sortMenu->setItemChecked( sortMenu->idAt( 1 ), FALSE ); | ||
804 | sortMenu->setItemChecked( sortMenu->idAt( 2 ), FALSE ); | ||
805 | sortMenu->setItemChecked( sortMenu->idAt( 3 ), FALSE ); | ||
806 | } | ||
807 | |||
808 | void FileBrowser::sortSize() | ||
809 | { | ||
810 | fileView->setSorting( 1, sortMenu->isItemChecked( sortMenu->idAt( 5 ) ) ); | ||
811 | fileView->sort(); | ||
812 | sortMenu->setItemChecked( sortMenu->idAt( 0 ), FALSE ); | ||
813 | sortMenu->setItemChecked( sortMenu->idAt( 1 ), TRUE ); | ||
814 | sortMenu->setItemChecked( sortMenu->idAt( 2 ), FALSE ); | ||
815 | sortMenu->setItemChecked( sortMenu->idAt( 3 ), FALSE ); | ||
816 | } | ||
817 | |||
818 | void FileBrowser::sortDate() | ||
819 | { | ||
820 | fileView->setSorting( 2, sortMenu->isItemChecked( sortMenu->idAt( 5 ) ) ); | ||
821 | fileView->sort(); | ||
822 | sortMenu->setItemChecked( sortMenu->idAt( 0 ), FALSE ); | ||
823 | sortMenu->setItemChecked( sortMenu->idAt( 1 ), FALSE ); | ||
824 | sortMenu->setItemChecked( sortMenu->idAt( 2 ), TRUE ); | ||
825 | sortMenu->setItemChecked( sortMenu->idAt( 3 ), FALSE ); | ||
826 | } | ||
827 | |||
828 | void FileBrowser::sortType() | ||
829 | { | ||
830 | fileView->setSorting( 3, sortMenu->isItemChecked( sortMenu->idAt( 5 ) ) ); | ||
831 | fileView->sort(); | ||
832 | sortMenu->setItemChecked( sortMenu->idAt( 0 ), FALSE ); | ||
833 | sortMenu->setItemChecked( sortMenu->idAt( 1 ), FALSE ); | ||
834 | sortMenu->setItemChecked( sortMenu->idAt( 2 ), FALSE ); | ||
835 | sortMenu->setItemChecked( sortMenu->idAt( 3 ), TRUE ); | ||
836 | } | ||
837 | |||
838 | void FileBrowser::updateSorting() | ||
839 | { | ||
840 | sortMenu->setItemChecked( sortMenu->idAt( 5 ), !sortMenu->isItemChecked( sortMenu->idAt( 5 ) ) ); | ||
841 | |||
842 | if ( sortMenu->isItemChecked( sortMenu->idAt( 0 ) ) ) | ||
843 | sortName(); | ||
844 | else if ( sortMenu->isItemChecked( sortMenu->idAt( 1 ) ) ) | ||
845 | sortSize(); | ||
846 | else if ( sortMenu->isItemChecked( sortMenu->idAt( 2 ) ) ) | ||
847 | sortDate(); | ||
848 | else | ||
849 | sortType(); | ||
850 | } | ||
diff --git a/noncore/unsupported/filebrowser/filebrowser.h b/noncore/unsupported/filebrowser/filebrowser.h new file mode 100644 index 0000000..2e9e444 --- a/dev/null +++ b/noncore/unsupported/filebrowser/filebrowser.h | |||
@@ -0,0 +1,141 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
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 | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
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. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | #ifndef FILEBROWSER_H | ||
21 | #define FILEBROWSER_H | ||
22 | |||
23 | #include <qlistview.h> | ||
24 | #include <qmainwindow.h> | ||
25 | #include <qfileinfo.h> | ||
26 | #include <qaction.h> | ||
27 | #include <qtimer.h> | ||
28 | #include <qstringlist.h> | ||
29 | |||
30 | class InlineEdit; | ||
31 | |||
32 | class FileItem : public QListViewItem | ||
33 | { | ||
34 | public: | ||
35 | FileItem( QListView * parent, const QFileInfo & fi ); | ||
36 | |||
37 | QString key( int column, bool ascending = TRUE ) const; | ||
38 | QString getFilePath(){ return fileInfo.filePath(); } | ||
39 | QString getFileName(){ return fileInfo.fileName(); } | ||
40 | bool isDir(){ return fileInfo.isDir(); } | ||
41 | bool isExecutable(){ return fileInfo.isExecutable(); } | ||
42 | bool isLib(); | ||
43 | int launch(); | ||
44 | bool rename( const QString & name ); | ||
45 | private: | ||
46 | QString sizeString( unsigned int size ); | ||
47 | QFileInfo fileInfo; | ||
48 | }; | ||
49 | |||
50 | |||
51 | class FileView : public QListView | ||
52 | { | ||
53 | Q_OBJECT | ||
54 | |||
55 | public: | ||
56 | FileView( const QString & dir, QWidget * parent = 0, | ||
57 | const char * name = 0 ); | ||
58 | void setDir( const QString & dir ); | ||
59 | QString cd(){ return currentDir; } | ||
60 | QStringList history() const { return dirHistory; } | ||
61 | |||
62 | public slots: | ||
63 | void updateDir(); | ||
64 | void parentDir(); | ||
65 | void lastDir(); | ||
66 | |||
67 | void rename(); | ||
68 | void copy(); | ||
69 | void paste(); | ||
70 | void del(); | ||
71 | void cut(); | ||
72 | void newFolder(); | ||
73 | void viewAsText(); | ||
74 | |||
75 | protected: | ||
76 | void generateDir( const QString & dir ); | ||
77 | void resizeEvent( QResizeEvent* ); | ||
78 | void contentsMousePressEvent( QMouseEvent * e ); | ||
79 | void contentsMouseReleaseEvent( QMouseEvent * e ); | ||
80 | |||
81 | protected slots: | ||
82 | void itemClicked( QListViewItem * i ); | ||
83 | void itemDblClicked( QListViewItem * i ); | ||
84 | void showFileMenu(); | ||
85 | void cancelMenuTimer(); | ||
86 | void selectAll(){ QListView::selectAll( TRUE ); } | ||
87 | void deselectAll(){ QListView::selectAll( FALSE ); } | ||
88 | void addToDocuments(); | ||
89 | void run(); | ||
90 | void endRenaming(); | ||
91 | |||
92 | private: | ||
93 | QString currentDir; | ||
94 | QStringList dirHistory, flist; | ||
95 | QTimer menuTimer; | ||
96 | InlineEdit * le; | ||
97 | FileItem * itemToRename; | ||
98 | bool selected; | ||
99 | |||
100 | bool copyFile( const QString & dest, const QString & src ); | ||
101 | |||
102 | signals: | ||
103 | void dirChanged(); | ||
104 | void textViewActivated( QWidget * w ); | ||
105 | void textViewDeactivated(); | ||
106 | }; | ||
107 | |||
108 | class FileBrowser : public QMainWindow | ||
109 | { | ||
110 | Q_OBJECT | ||
111 | |||
112 | public: | ||
113 | FileBrowser( QWidget * parent = 0, | ||
114 | const char * name = 0, WFlags f = 0 ); | ||
115 | FileBrowser( const QString & dir, QWidget * parent = 0, | ||
116 | const char * name = 0, WFlags f = 0 ); | ||
117 | private: | ||
118 | void init(const QString & dir); | ||
119 | QString fileToCopy; | ||
120 | QPopupMenu * dirMenu, * sortMenu; | ||
121 | FileView * fileView; | ||
122 | QAction * pasteAction; | ||
123 | QAction*lastAction; | ||
124 | QAction*upAction; | ||
125 | |||
126 | bool copyFile( const QString & dest, const QString & src ); | ||
127 | |||
128 | private slots: | ||
129 | void pcmciaMessage( const QCString &msg, const QByteArray &); | ||
130 | |||
131 | void sortName(); | ||
132 | void sortDate(); | ||
133 | void sortSize(); | ||
134 | void sortType(); | ||
135 | void updateSorting(); | ||
136 | |||
137 | void updateDirMenu(); | ||
138 | void dirSelected( int id ); | ||
139 | }; | ||
140 | |||
141 | #endif | ||
diff --git a/noncore/unsupported/filebrowser/filebrowser.pro b/noncore/unsupported/filebrowser/filebrowser.pro new file mode 100644 index 0000000..34df79a --- a/dev/null +++ b/noncore/unsupported/filebrowser/filebrowser.pro | |||
@@ -0,0 +1,12 @@ | |||
1 | TEMPLATE= app | ||
2 | CONFIG = qt warn_on release | ||
3 | DESTDIR = $(QPEDIR)/bin | ||
4 | HEADERS = inlineedit.h \ | ||
5 | filebrowser.h | ||
6 | SOURCES = filebrowser.cpp \ | ||
7 | inlineedit.cpp \ | ||
8 | main.cpp | ||
9 | INCLUDEPATH += $(QPEDIR)/include | ||
10 | DEPENDPATH+= $(QPEDIR)/include | ||
11 | LIBS += -lqpe | ||
12 | INTERFACES= | ||
diff --git a/noncore/unsupported/filebrowser/inlineedit.cpp b/noncore/unsupported/filebrowser/inlineedit.cpp new file mode 100644 index 0000000..47c500a --- a/dev/null +++ b/noncore/unsupported/filebrowser/inlineedit.cpp | |||
@@ -0,0 +1,30 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
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 | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
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. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | #include "inlineedit.h" | ||
21 | |||
22 | InlineEdit::InlineEdit( QWidget * parent, const char * name ) | ||
23 | : QLineEdit( parent, name ) | ||
24 | { | ||
25 | } | ||
26 | |||
27 | void InlineEdit::focusOutEvent( QFocusEvent * ) | ||
28 | { | ||
29 | emit lostFocus(); | ||
30 | } | ||
diff --git a/noncore/unsupported/filebrowser/inlineedit.h b/noncore/unsupported/filebrowser/inlineedit.h new file mode 100644 index 0000000..3fbfdd6 --- a/dev/null +++ b/noncore/unsupported/filebrowser/inlineedit.h | |||
@@ -0,0 +1,39 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
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 | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
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. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | #ifndef INLINEEDIT_H | ||
21 | #define INLINEEDIT_H | ||
22 | |||
23 | #include <qlineedit.h> | ||
24 | |||
25 | class InlineEdit : public QLineEdit | ||
26 | { | ||
27 | Q_OBJECT | ||
28 | |||
29 | public: | ||
30 | InlineEdit( QWidget * parent = 0, const char * name = 0 ); | ||
31 | |||
32 | signals: | ||
33 | void lostFocus(); | ||
34 | |||
35 | protected: | ||
36 | void focusOutEvent( QFocusEvent * ); | ||
37 | }; | ||
38 | |||
39 | #endif | ||
diff --git a/noncore/unsupported/filebrowser/main.cpp b/noncore/unsupported/filebrowser/main.cpp new file mode 100644 index 0000000..7304786 --- a/dev/null +++ b/noncore/unsupported/filebrowser/main.cpp | |||
@@ -0,0 +1,41 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
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 | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
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. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | |||
21 | #include "filebrowser.h" | ||
22 | |||
23 | #include <qpe/qpeapplication.h> | ||
24 | #include <qpe/mimetype.h> | ||
25 | |||
26 | #include <qmainwindow.h> | ||
27 | #include <qfileinfo.h> | ||
28 | #include <qdir.h> | ||
29 | |||
30 | int main( int argc, char ** argv ) | ||
31 | { | ||
32 | QPEApplication a( argc, argv ); | ||
33 | |||
34 | MimeType::updateApplications(); | ||
35 | FileBrowser mw( QDir::current().canonicalPath() ); | ||
36 | mw.resize( 240, 320 ); | ||
37 | mw.setCaption( FileBrowser::tr("File Manager") ); | ||
38 | a.showMainWidget( &mw ); | ||
39 | |||
40 | return a.exec(); | ||
41 | } | ||
diff --git a/noncore/unsupported/filebrowser/qpe-filebrowser.control b/noncore/unsupported/filebrowser/qpe-filebrowser.control new file mode 100644 index 0000000..c55fe6a --- a/dev/null +++ b/noncore/unsupported/filebrowser/qpe-filebrowser.control | |||
@@ -0,0 +1,9 @@ | |||
1 | Files: bin/filebrowser apps/Applications/filebrowser.desktop | ||
2 | Priority: optional | ||
3 | Section: qpe/applications | ||
4 | Maintainer: Warwick Allison <warwick@trolltech.com> | ||
5 | Architecture: arm | ||
6 | Version: $QPE_VERSION-3 | ||
7 | Depends: qpe-base ($QPE_VERSION) | ||
8 | Description: Browse the file system | ||
9 | The filebrowser for the Qtopia environment. | ||