author | dwmw2 <dwmw2> | 2002-05-09 11:59:51 (UTC) |
---|---|---|
committer | dwmw2 <dwmw2> | 2002-05-09 11:59:51 (UTC) |
commit | 67077883f382bd73bf4bdceda8994fa4e47ee5e6 (patch) (unidiff) | |
tree | 66433081886ad27170f95e23ccd36d487d90c95a | |
parent | d9b40786a885451caf3f22612ec401df1edff983 (diff) | |
download | opie-67077883f382bd73bf4bdceda8994fa4e47ee5e6.zip opie-67077883f382bd73bf4bdceda8994fa4e47ee5e6.tar.gz opie-67077883f382bd73bf4bdceda8994fa4e47ee5e6.tar.bz2 |
#include <qpainter.h>
-rw-r--r-- | noncore/unsupported/filebrowser/filebrowser.cpp | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/noncore/unsupported/filebrowser/filebrowser.cpp b/noncore/unsupported/filebrowser/filebrowser.cpp index 1bb7984..8c01655 100644 --- a/noncore/unsupported/filebrowser/filebrowser.cpp +++ b/noncore/unsupported/filebrowser/filebrowser.cpp | |||
@@ -1,236 +1,237 @@ | |||
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 | #include <qpe/config.h> | 28 | #include <qpe/config.h> |
29 | 29 | ||
30 | #include <qcopchannel_qws.h> | 30 | #include <qcopchannel_qws.h> |
31 | #include <qpe/qcopenvelope_qws.h> | 31 | #include <qpe/qcopenvelope_qws.h> |
32 | 32 | ||
33 | #include <qmessagebox.h> | 33 | #include <qmessagebox.h> |
34 | #include <qdir.h> | 34 | #include <qdir.h> |
35 | #include <qregexp.h> | 35 | #include <qregexp.h> |
36 | #include <qheader.h> | 36 | #include <qheader.h> |
37 | #include <qpe/qpetoolbar.h> | 37 | #include <qpe/qpetoolbar.h> |
38 | #include <qpopupmenu.h> | 38 | #include <qpopupmenu.h> |
39 | #include <qpe/qpemenubar.h> | 39 | #include <qpe/qpemenubar.h> |
40 | #include <qaction.h> | 40 | #include <qaction.h> |
41 | #include <qstringlist.h> | 41 | #include <qstringlist.h> |
42 | #include <qcursor.h> | 42 | #include <qcursor.h> |
43 | #include <qmultilineedit.h> | 43 | #include <qmultilineedit.h> |
44 | #include <qfont.h> | 44 | #include <qfont.h> |
45 | #include <qpainter.h> | ||
45 | 46 | ||
46 | #include <unistd.h> | 47 | #include <unistd.h> |
47 | #include <stdlib.h> | 48 | #include <stdlib.h> |
48 | #include <sys/stat.h> | 49 | #include <sys/stat.h> |
49 | 50 | ||
50 | // | 51 | // |
51 | // FileItem | 52 | // FileItem |
52 | // | 53 | // |
53 | FileItem::FileItem( QListView * parent, const QFileInfo & fi ) | 54 | FileItem::FileItem( QListView * parent, const QFileInfo & fi ) |
54 | : QListViewItem( parent ), | 55 | : QListViewItem( parent ), |
55 | fileInfo( fi ) | 56 | fileInfo( fi ) |
56 | { | 57 | { |
57 | QDate d = fi.lastModified().date(); | 58 | QDate d = fi.lastModified().date(); |
58 | 59 | ||
59 | setText( 0, fi.fileName() ); | 60 | setText( 0, fi.fileName() ); |
60 | setText( 1, sizeString( fi.size() ) + " " ); | 61 | setText( 1, sizeString( fi.size() ) + " " ); |
61 | setText( 2, QString().sprintf("%4d-%02d-%02d",d.year(), d.month(), d.day() ) ); | 62 | setText( 2, QString().sprintf("%4d-%02d-%02d",d.year(), d.month(), d.day() ) ); |
62 | 63 | ||
63 | MimeType mt(fi.filePath()); | 64 | MimeType mt(fi.filePath()); |
64 | 65 | ||
65 | if ( fi.isSymLink() ) | 66 | if ( fi.isSymLink() ) |
66 | setText( 3, "symlink" ); | 67 | setText( 3, "symlink" ); |
67 | else if( fi.isDir() ) | 68 | else if( fi.isDir() ) |
68 | setText( 3, "directory" ); | 69 | setText( 3, "directory" ); |
69 | else if( isLib() ) | 70 | else if( isLib() ) |
70 | setText( 3, "library" ); | 71 | setText( 3, "library" ); |
71 | else | 72 | else |
72 | setText( 3, mt.description() ); | 73 | setText( 3, mt.description() ); |
73 | 74 | ||
74 | QPixmap pm; | 75 | QPixmap pm; |
75 | if( fi.isDir() ){ | 76 | if( fi.isDir() ){ |
76 | if( !QDir( fi.filePath() ).isReadable() ) | 77 | if( !QDir( fi.filePath() ).isReadable() ) |
77 | pm = Resource::loadPixmap( "lockedfolder" ); | 78 | pm = Resource::loadPixmap( "lockedfolder" ); |
78 | else | 79 | else |
79 | pm = Resource::loadPixmap( "folder" ); | 80 | pm = Resource::loadPixmap( "folder" ); |
80 | } | 81 | } |
81 | else if( !fi.isReadable() ) | 82 | else if( !fi.isReadable() ) |
82 | pm = Resource::loadPixmap( "locked" ); | 83 | pm = Resource::loadPixmap( "locked" ); |
83 | else if( isLib() ) | 84 | else if( isLib() ) |
84 | pm = Resource::loadPixmap( "library" ); | 85 | pm = Resource::loadPixmap( "library" ); |
85 | else | 86 | else |
86 | pm = mt.pixmap(); | 87 | pm = mt.pixmap(); |
87 | if ( pm.isNull() ) | 88 | if ( pm.isNull() ) |
88 | pm = Resource::loadPixmap("UnknownDocument-14"); | 89 | pm = Resource::loadPixmap("UnknownDocument-14"); |
89 | if( fi.isSymLink() ){ | 90 | if( fi.isSymLink() ){ |
90 | // overlay link image | 91 | // overlay link image |
91 | QPixmap lnk = Resource::loadPixmap( "filebrowser/symlink" ); | 92 | QPixmap lnk = Resource::loadPixmap( "filebrowser/symlink" ); |
92 | QPainter painter( &pm ); | 93 | QPainter painter( &pm ); |
93 | painter.drawPixmap( pm.width()-lnk.width(), pm.height()-lnk.height(), lnk ); | 94 | painter.drawPixmap( pm.width()-lnk.width(), pm.height()-lnk.height(), lnk ); |
94 | pm.setMask( pm.createHeuristicMask( FALSE ) ); | 95 | pm.setMask( pm.createHeuristicMask( FALSE ) ); |
95 | } | 96 | } |
96 | setPixmap(0,pm); | 97 | setPixmap(0,pm); |
97 | } | 98 | } |
98 | 99 | ||
99 | QString FileItem::sizeString( unsigned int s ) | 100 | QString FileItem::sizeString( unsigned int s ) |
100 | { | 101 | { |
101 | double size = s; | 102 | double size = s; |
102 | 103 | ||
103 | if ( size > 1024 * 1024 * 1024 ) | 104 | if ( size > 1024 * 1024 * 1024 ) |
104 | return QString().sprintf( "%.1f", size / ( 1024 * 1024 * 1024 ) ) + "G"; | 105 | return QString().sprintf( "%.1f", size / ( 1024 * 1024 * 1024 ) ) + "G"; |
105 | else if ( size > 1024 * 1024 ) | 106 | else if ( size > 1024 * 1024 ) |
106 | return QString().sprintf( "%.1f", size / ( 1024 * 1024 ) ) + "M"; | 107 | return QString().sprintf( "%.1f", size / ( 1024 * 1024 ) ) + "M"; |
107 | else if ( size > 1024 ) | 108 | else if ( size > 1024 ) |
108 | return QString().sprintf( "%.1f", size / ( 1024 ) ) + "K"; | 109 | return QString().sprintf( "%.1f", size / ( 1024 ) ) + "K"; |
109 | else | 110 | else |
110 | return QString::number( size ) + "B"; | 111 | return QString::number( size ) + "B"; |
111 | } | 112 | } |
112 | 113 | ||
113 | QString FileItem::key( int column, bool ascending ) const | 114 | QString FileItem::key( int column, bool ascending ) const |
114 | { | 115 | { |
115 | QString tmp; | 116 | QString tmp; |
116 | 117 | ||
117 | ascending = ascending; | 118 | ascending = ascending; |
118 | 119 | ||
119 | if( (column == 0) && fileInfo.isDir() ){ // Sort by name | 120 | if( (column == 0) && fileInfo.isDir() ){ // Sort by name |
120 | // We want the directories to appear at the top of the list | 121 | // We want the directories to appear at the top of the list |
121 | tmp = (char) 0; | 122 | tmp = (char) 0; |
122 | return (tmp + text( column ).lower()); | 123 | return (tmp + text( column ).lower()); |
123 | } | 124 | } |
124 | else if( column == 2 ) { // Sort by date | 125 | else if( column == 2 ) { // Sort by date |
125 | QDateTime epoch( QDate( 1980, 1, 1 ) ); | 126 | QDateTime epoch( QDate( 1980, 1, 1 ) ); |
126 | tmp.sprintf( "%08d", epoch.secsTo( fileInfo.lastModified() ) ); | 127 | tmp.sprintf( "%08d", epoch.secsTo( fileInfo.lastModified() ) ); |
127 | return tmp; | 128 | return tmp; |
128 | } | 129 | } |
129 | else if( column == 1 ) { // Sort by size | 130 | else if( column == 1 ) { // Sort by size |
130 | return tmp.sprintf( "%08d", fileInfo.size() ); | 131 | return tmp.sprintf( "%08d", fileInfo.size() ); |
131 | } | 132 | } |
132 | 133 | ||
133 | return text( column ).lower(); | 134 | return text( column ).lower(); |
134 | } | 135 | } |
135 | 136 | ||
136 | bool FileItem::isLib() | 137 | bool FileItem::isLib() |
137 | { | 138 | { |
138 | // This is of course not foolproof | 139 | // This is of course not foolproof |
139 | if( !qstrncmp("lib", fileInfo.baseName(), 3) && | 140 | if( !qstrncmp("lib", fileInfo.baseName(), 3) && |
140 | ( fileInfo.extension().contains( "so" ) || | 141 | ( fileInfo.extension().contains( "so" ) || |
141 | fileInfo.extension().contains( "a" ) ) ) | 142 | fileInfo.extension().contains( "a" ) ) ) |
142 | return TRUE; | 143 | return TRUE; |
143 | else | 144 | else |
144 | return FALSE; | 145 | return FALSE; |
145 | } | 146 | } |
146 | 147 | ||
147 | int FileItem::launch() | 148 | int FileItem::launch() |
148 | { | 149 | { |
149 | DocLnk doc( fileInfo.filePath(), FALSE ); | 150 | DocLnk doc( fileInfo.filePath(), FALSE ); |
150 | doc.execute(); | 151 | doc.execute(); |
151 | listView()->clearSelection(); | 152 | listView()->clearSelection(); |
152 | return 1; | 153 | return 1; |
153 | } | 154 | } |
154 | 155 | ||
155 | bool FileItem::rename( const QString & name ) | 156 | bool FileItem::rename( const QString & name ) |
156 | { | 157 | { |
157 | QString oldpath, newpath; | 158 | QString oldpath, newpath; |
158 | 159 | ||
159 | if ( name.isEmpty() ) | 160 | if ( name.isEmpty() ) |
160 | return FALSE; | 161 | return FALSE; |
161 | 162 | ||
162 | if ( name.contains( QRegExp("[/\\$\"\'\\*\\?]") ) ) | 163 | if ( name.contains( QRegExp("[/\\$\"\'\\*\\?]") ) ) |
163 | return FALSE; | 164 | return FALSE; |
164 | 165 | ||
165 | oldpath = fileInfo.filePath(); | 166 | oldpath = fileInfo.filePath(); |
166 | newpath = fileInfo.dirPath() + "/" + name; | 167 | newpath = fileInfo.dirPath() + "/" + name; |
167 | 168 | ||
168 | if ( ::rename( (const char *) oldpath, (const char *) newpath ) != 0 ) | 169 | if ( ::rename( (const char *) oldpath, (const char *) newpath ) != 0 ) |
169 | return FALSE; | 170 | return FALSE; |
170 | else | 171 | else |
171 | return TRUE; | 172 | return TRUE; |
172 | } | 173 | } |
173 | 174 | ||
174 | // | 175 | // |
175 | // FileView | 176 | // FileView |
176 | // | 177 | // |
177 | FileView::FileView( const QString & dir, QWidget * parent, | 178 | FileView::FileView( const QString & dir, QWidget * parent, |
178 | const char * name, | 179 | const char * name, |
179 | bool hidden, bool symlinks ) | 180 | bool hidden, bool symlinks ) |
180 | : QListView( parent, name ), | 181 | : QListView( parent, name ), |
181 | menuTimer( this ), | 182 | menuTimer( this ), |
182 | le( NULL ), | 183 | le( NULL ), |
183 | itemToRename( NULL ), | 184 | itemToRename( NULL ), |
184 | showHidden( hidden ), | 185 | showHidden( hidden ), |
185 | showSymlinks( symlinks), | 186 | showSymlinks( symlinks), |
186 | menuKeepsOpen( FALSE ) | 187 | menuKeepsOpen( FALSE ) |
187 | { | 188 | { |
188 | addColumn( "Name" ); | 189 | addColumn( "Name" ); |
189 | addColumn( "Size" ); | 190 | addColumn( "Size" ); |
190 | addColumn( "Date" ); | 191 | addColumn( "Date" ); |
191 | addColumn( "Type" ); | 192 | addColumn( "Type" ); |
192 | 193 | ||
193 | setMultiSelection( TRUE ); | 194 | setMultiSelection( TRUE ); |
194 | //header()->hide(); | 195 | //header()->hide(); |
195 | 196 | ||
196 | setColumnWidthMode( 0, Manual ); | 197 | setColumnWidthMode( 0, Manual ); |
197 | setColumnWidthMode( 3, Manual ); | 198 | setColumnWidthMode( 3, Manual ); |
198 | 199 | ||
199 | // right align yize column | 200 | // right align yize column |
200 | setColumnAlignment( 1, AlignRight ); | 201 | setColumnAlignment( 1, AlignRight ); |
201 | 202 | ||
202 | generateDir( dir ); | 203 | generateDir( dir ); |
203 | 204 | ||
204 | connect( this, SIGNAL( clicked( QListViewItem * )), | 205 | connect( this, SIGNAL( clicked( QListViewItem * )), |
205 | SLOT( itemClicked( QListViewItem * )) ); | 206 | SLOT( itemClicked( QListViewItem * )) ); |
206 | connect( this, SIGNAL( doubleClicked( QListViewItem * )), | 207 | connect( this, SIGNAL( doubleClicked( QListViewItem * )), |
207 | SLOT( itemDblClicked( QListViewItem * )) ); | 208 | SLOT( itemDblClicked( QListViewItem * )) ); |
208 | connect( this, SIGNAL( selectionChanged() ), SLOT( cancelMenuTimer() ) ); | 209 | connect( this, SIGNAL( selectionChanged() ), SLOT( cancelMenuTimer() ) ); |
209 | connect( &menuTimer, SIGNAL( timeout() ), SLOT( showFileMenu() ) ); | 210 | connect( &menuTimer, SIGNAL( timeout() ), SLOT( showFileMenu() ) ); |
210 | } | 211 | } |
211 | 212 | ||
212 | void FileView::resizeEvent( QResizeEvent *e ) | 213 | void FileView::resizeEvent( QResizeEvent *e ) |
213 | { | 214 | { |
214 | setColumnWidth( 0, width() - 2 * lineWidth() - 20 - columnWidth( 1 ) - columnWidth( 2 ) ); | 215 | setColumnWidth( 0, width() - 2 * lineWidth() - 20 - columnWidth( 1 ) - columnWidth( 2 ) ); |
215 | 216 | ||
216 | // hide type column, we use it for "sort by type" only | 217 | // hide type column, we use it for "sort by type" only |
217 | //setColumnWidth( 3, 0 ); | 218 | //setColumnWidth( 3, 0 ); |
218 | QListView::resizeEvent( e ); | 219 | QListView::resizeEvent( e ); |
219 | } | 220 | } |
220 | 221 | ||
221 | void FileView::updateDir() | 222 | void FileView::updateDir() |
222 | { | 223 | { |
223 | generateDir( currentDir ); | 224 | generateDir( currentDir ); |
224 | } | 225 | } |
225 | 226 | ||
226 | void FileView::setDir( const QString & dir ) | 227 | void FileView::setDir( const QString & dir ) |
227 | { | 228 | { |
228 | if ( dir.startsWith( "/dev" ) ) { | 229 | if ( dir.startsWith( "/dev" ) ) { |
229 | QMessageBox::warning( this, tr( "File Manager" ), | 230 | QMessageBox::warning( this, tr( "File Manager" ), |
230 | tr( "Can't show /dev/ directory." ), tr( "&Ok" ) ); | 231 | tr( "Can't show /dev/ directory." ), tr( "&Ok" ) ); |
231 | return; | 232 | return; |
232 | } | 233 | } |
233 | dirHistory += currentDir; | 234 | dirHistory += currentDir; |
234 | generateDir( dir ); | 235 | generateDir( dir ); |
235 | } | 236 | } |
236 | 237 | ||