-rw-r--r-- | libopie/ofileselector.cc | 168 |
1 files changed, 142 insertions, 26 deletions
diff --git a/libopie/ofileselector.cc b/libopie/ofileselector.cc index b911d37..61ab2c4 100644 --- a/libopie/ofileselector.cc +++ b/libopie/ofileselector.cc | |||
@@ -17,104 +17,123 @@ | |||
17 | ..}^=.= = ; Library General Public License for more | 17 | ..}^=.= = ; Library General Public License for more |
18 | ++= -. .` .: details. | 18 | ++= -. .` .: details. |
19 | : = ...= . :.=- | 19 | : = ...= . :.=- |
20 | -. .:....=;==+<; You should have received a copy of the GNU | 20 | -. .:....=;==+<; You should have received a copy of the GNU |
21 | -_. . . )=. = Library General Public License along with | 21 | -_. . . )=. = Library General Public License along with |
22 | -- :-=` this library; see the file COPYING.LIB. | 22 | -- :-=` this library; see the file COPYING.LIB. |
23 | If not, write to the Free Software Foundation, | 23 | If not, write to the Free Software Foundation, |
24 | Inc., 59 Temple Place - Suite 330, | 24 | Inc., 59 Temple Place - Suite 330, |
25 | Boston, MA 02111-1307, USA. | 25 | Boston, MA 02111-1307, USA. |
26 | 26 | ||
27 | */ | 27 | */ |
28 | 28 | ||
29 | #include <qnamespace.h> | 29 | #include <qnamespace.h> |
30 | #include <qpushbutton.h> | 30 | #include <qpushbutton.h> |
31 | #include <qcombobox.h> | 31 | #include <qcombobox.h> |
32 | #include <qhbox.h> | 32 | #include <qhbox.h> |
33 | #include <qvbox.h> | 33 | #include <qvbox.h> |
34 | #include <qlayout.h> | 34 | #include <qlayout.h> |
35 | #include <qwidgetstack.h> | 35 | #include <qwidgetstack.h> |
36 | #include <qlineedit.h> | 36 | #include <qlineedit.h> |
37 | #include <qcheckbox.h> | 37 | #include <qcheckbox.h> |
38 | #include <qlabel.h> | 38 | #include <qlabel.h> |
39 | #include <qheader.h> | 39 | #include <qheader.h> |
40 | #include <qdir.h> | 40 | #include <qdir.h> |
41 | #include <qpainter.h> | ||
41 | 42 | ||
42 | #include <qpe/qpeapplication.h> | 43 | #include <qpe/qpeapplication.h> |
43 | #include <qpe/fileselector.h> | 44 | #include <qpe/fileselector.h> |
44 | #include <qpe/applnk.h> | 45 | #include <qpe/applnk.h> |
45 | #include <qpe/global.h> | 46 | #include <qpe/global.h> |
46 | #include <qpe/mimetype.h> | 47 | #include <qpe/mimetype.h> |
48 | #include <qpe/resource.h> | ||
47 | 49 | ||
48 | #include "ofileselector.h" | 50 | #include "ofileselector.h" |
49 | 51 | ||
52 | QMap<QString,QPixmap> *OFileSelector::m_pixmaps = 0; | ||
50 | 53 | ||
51 | OFileSelector::OFileSelector(QWidget *wid, int mode, int selector, const QString &dirName, | 54 | OFileSelector::OFileSelector(QWidget *wid, int mode, int selector, const QString &dirName, |
52 | const QString &fileName, const QStringList mimetypes ) : QWidget( wid ) | 55 | const QString &fileName, const QStringList mimetypes ) : QWidget( wid ) |
53 | { | 56 | { |
54 | m_selector = selector; | 57 | m_selector = selector; |
55 | m_currentDir = dirName; | 58 | m_currentDir = dirName; |
56 | m_name = fileName; | 59 | m_name = fileName; |
57 | m_mimetypes = mimetypes; | 60 | m_mimetypes = mimetypes; |
58 | if( mimetypes.isEmpty() ) | 61 | if( mimetypes.isEmpty() ) |
59 | m_autoMime = true; | 62 | m_autoMime = true; |
60 | 63 | ||
61 | m_mode = mode; | 64 | m_mode = mode; |
62 | m_shTool = true; | 65 | m_shTool = true; |
63 | m_shPerm = true; | 66 | m_shPerm = true; |
64 | m_shLne = true; | 67 | m_shLne = true; |
65 | m_shChooser = true; | 68 | m_shChooser = true; |
66 | m_shYesNo = true; | 69 | m_shYesNo = true; |
67 | // for FILESELECTOR only view is interesting | 70 | // for FILESELECTOR only view is interesting |
68 | m_location = 0; | 71 | m_location = 0; |
69 | m_homeButton = 0; | 72 | m_homeButton = 0; |
70 | m_docButton = 0; | 73 | m_docButton = 0; |
71 | m_hideButton = 0; | 74 | m_hideButton = 0; |
72 | m_ok = 0; | 75 | m_ok = 0; |
73 | m_cancel = 0; | 76 | m_cancel = 0; |
74 | m_reread = 0; | 77 | m_reread = 0; |
75 | m_up = 0; | 78 | m_up = 0; |
76 | m_View = 0; | 79 | m_View = 0; |
77 | m_select = 0; | 80 | m_select = 0; |
78 | m_stack = 0; | 81 | m_stack = 0; |
79 | 82 | ||
80 | m_select = 0; | 83 | m_select = 0; |
81 | m_stack = 0; | 84 | m_stack = 0; |
82 | m_lay = 0; | 85 | m_lay = 0; |
83 | m_boxToolbar = 0; | 86 | m_boxToolbar = 0; |
84 | m_boxOk = 0; | 87 | m_boxOk = 0; |
85 | m_edit = 0; | 88 | m_edit = 0; |
86 | 89 | ||
87 | m_fnLabel = 0; | 90 | m_fnLabel = 0; |
88 | m_checkPerm = 0; | 91 | m_checkPerm = 0; |
89 | m_mimeCheck = 0; | 92 | m_mimeCheck = 0; |
90 | m_viewCheck = 0; | 93 | m_viewCheck = 0; |
91 | 94 | ||
95 | m_dir = true; | ||
96 | m_files = true; | ||
97 | |||
98 | if(m_pixmaps == 0 ) // init the pixmaps | ||
99 | initPics(); | ||
100 | |||
92 | m_lay = new QVBoxLayout(this); | 101 | m_lay = new QVBoxLayout(this); |
93 | init(); | 102 | init(); |
94 | m_edit->setText( fileName ); | 103 | m_edit->setText( fileName ); |
95 | } | 104 | } |
105 | void OFileSelector::initPics() | ||
106 | { | ||
107 | m_pixmaps = new QMap<QString,QPixmap>; | ||
108 | QPixmap pm = Resource::loadPixmap( "folder " ); | ||
109 | QPixmap lnk = Resource::loadPixmap( "symlink" ); | ||
110 | QPainter painter( &pm ); | ||
111 | painter.drawPixmap( pm.width()-lnk.width(), pm.height()-lnk.height(), lnk ); | ||
112 | pm.setMask( pm.createHeuristicMask( FALSE ) ); | ||
113 | m_pixmaps->insert("dirsymlink", pm ); | ||
96 | 114 | ||
115 | }; | ||
97 | // let's initialize the gui | 116 | // let's initialize the gui |
98 | /** | 117 | /** |
99 | -------------------- | 118 | -------------------- |
100 | | cmbBox Button | | 119 | | cmbBox Button | |
101 | -------------------- | 120 | -------------------- |
102 | | FileSlector | | 121 | | FileSlector | |
103 | | or | | 122 | | or | |
104 | | OSelector | | 123 | | OSelector | |
105 | | | | 124 | | | |
106 | | | | 125 | | | |
107 | ____________________ | 126 | ____________________ |
108 | | LineEdit | | 127 | | LineEdit | |
109 | ____________________ | 128 | ____________________ |
110 | | Permission Bar | | 129 | | Permission Bar | |
111 | ____________________ | 130 | ____________________ |
112 | | ViewChoose | | 131 | | ViewChoose | |
113 | ____________________ | 132 | ____________________ |
114 | | Save Cancel| | 133 | | Save Cancel| |
115 | ____________________ | 134 | ____________________ |
116 | */ | 135 | */ |
117 | void OFileSelector::delItems() | 136 | void OFileSelector::delItems() |
118 | { | 137 | { |
119 | QLayoutIterator it = m_lay->iterator(); | 138 | QLayoutIterator it = m_lay->iterator(); |
120 | while ( it.current() != 0 ){ | 139 | while ( it.current() != 0 ){ |
@@ -128,136 +147,165 @@ void OFileSelector::init() | |||
128 | m_select = new FileSelector(m_mimetypes.join(";"), m_stack, "fileselector", FALSE, FALSE ); | 147 | m_select = new FileSelector(m_mimetypes.join(";"), m_stack, "fileselector", FALSE, FALSE ); |
129 | m_stack->addWidget(m_select, NORMAL ); | 148 | m_stack->addWidget(m_select, NORMAL ); |
130 | m_lay->addWidget(m_stack ); | 149 | m_lay->addWidget(m_stack ); |
131 | m_stack->raiseWidget(NORMAL ); | 150 | m_stack->raiseWidget(NORMAL ); |
132 | 151 | ||
133 | if(m_shLne ){ | 152 | if(m_shLne ){ |
134 | initializeName(); | 153 | initializeName(); |
135 | } | 154 | } |
136 | 155 | ||
137 | if(m_shPerm ){ | 156 | if(m_shPerm ){ |
138 | m_checkPerm = new QCheckBox(tr("Set Permission"), this, "Permission" ); | 157 | m_checkPerm = new QCheckBox(tr("Set Permission"), this, "Permission" ); |
139 | m_checkPerm->setChecked( false ); | 158 | m_checkPerm->setChecked( false ); |
140 | m_lay->addWidget(m_checkPerm ); | 159 | m_lay->addWidget(m_checkPerm ); |
141 | } | 160 | } |
142 | 161 | ||
143 | if( m_shChooser ) | 162 | if( m_shChooser ) |
144 | initializeChooser(); | 163 | initializeChooser(); |
145 | 164 | ||
146 | if(m_shYesNo ) | 165 | if(m_shYesNo ) |
147 | initializeYes(); | 166 | initializeYes(); |
148 | 167 | ||
149 | 168 | ||
150 | }; | 169 | }; |
151 | 170 | ||
152 | void OFileSelector::setShowYesCancel( bool show ) | 171 | void OFileSelector::setYesCancelVisible( bool show ) |
153 | { | 172 | { |
154 | if ( show == m_shYesNo ) | 173 | if ( show == m_shYesNo ) |
155 | return; | 174 | return; |
156 | m_shYesNo = show; | 175 | m_shYesNo = show; |
157 | if( !show ){ | 176 | if( !show ){ |
158 | delete m_ok; | 177 | delete m_ok; |
159 | delete m_cancel; | 178 | delete m_cancel; |
160 | m_ok = 0; | 179 | m_ok = 0; |
161 | m_cancel = 0; | 180 | m_cancel = 0; |
162 | // delete m_boxOk; all ready deleted in delItems | 181 | // delete m_boxOk; all ready deleted in delItems |
163 | } | 182 | } |
164 | updateLay(); // recreate it and save the other states | 183 | updateLay(); // recreate it and save the other states |
165 | } | 184 | } |
166 | 185 | ||
167 | void OFileSelector::setShowToolbar( bool show ) | 186 | void OFileSelector::setToolbarVisible( bool show ) |
168 | { | 187 | { |
169 | if ( m_shTool == show ) | 188 | if ( m_shTool == show ) |
170 | return; | 189 | return; |
171 | /* if( show ){ | 190 | /* if( show ){ |
172 | 191 | ||
173 | }else { | 192 | }else { |
174 | 193 | ||
175 | }*/ | 194 | }*/ |
176 | } | 195 | } |
177 | 196 | ||
178 | void OFileSelector::setShowPermissionBar( bool show ) | 197 | void OFileSelector::setPermissionBarVisible( bool show ) |
179 | { | 198 | { |
180 | if( show == m_shPerm ) | 199 | if( show == m_shPerm ) |
181 | return; | 200 | return; |
182 | 201 | ||
183 | m_shPerm = show; | 202 | m_shPerm = show; |
184 | 203 | ||
185 | updateLay(); | 204 | updateLay(); |
186 | } | 205 | } |
187 | void OFileSelector::setShowLineEdit( bool show ) | 206 | void OFileSelector::setLineEditVisible( bool show ) |
188 | { | 207 | { |
189 | if( show == m_shLne ) | 208 | if( show == m_shLne ) |
190 | return; | 209 | return; |
191 | 210 | ||
192 | m_shLne = show; | 211 | m_shLne = show; |
193 | if( !show ){ | 212 | if( !show ){ |
194 | delete m_edit; | 213 | delete m_edit; |
195 | delete m_fnLabel; | 214 | delete m_fnLabel; |
196 | m_edit = 0; | 215 | m_edit = 0; |
197 | m_fnLabel = 0; | 216 | m_fnLabel = 0; |
198 | //delete m_boxName; will be deleted | 217 | //delete m_boxName; will be deleted |
199 | } | 218 | } |
200 | updateLay(); | 219 | updateLay(); |
201 | } | 220 | } |
202 | void OFileSelector::setShowChooser( bool show ) | 221 | void OFileSelector::setChooserVisible( bool show ) |
203 | { | 222 | { |
204 | if( show = m_shChooser ) | 223 | if( show = m_shChooser ) |
205 | return; | 224 | return; |
206 | m_shChooser = show; | 225 | m_shChooser = show; |
207 | if( !show ){ | 226 | if( !show ){ |
208 | delete m_mimeCheck; | 227 | delete m_mimeCheck; |
209 | delete m_viewCheck; | 228 | delete m_viewCheck; |
210 | m_mimeCheck = 0; | 229 | m_mimeCheck = 0; |
211 | m_viewCheck = 0; | 230 | m_viewCheck = 0; |
212 | } | 231 | } |
213 | updateLay(); | 232 | updateLay(); |
214 | } | 233 | } |
215 | QCheckBox* OFileSelector::permissionCheckbox( ) | 234 | QCheckBox* OFileSelector::permissionCheckbox( ) |
216 | { | 235 | { |
217 | return m_checkPerm; | 236 | return m_checkPerm; |
218 | } | 237 | } |
238 | void OFileSelector::setCaseSensetive( bool caSe ) | ||
239 | { | ||
240 | m_case = caSe; | ||
241 | reparse(); | ||
242 | } | ||
243 | void OFileSelector::setShowFiles(bool files ){ | ||
244 | m_files = files; | ||
245 | reparse(); | ||
246 | } | ||
247 | void OFileSelector::setPopupMenu(const QPopupMenu * ) | ||
248 | { | ||
249 | //delete oldpopup; | ||
250 | |||
251 | } | ||
219 | bool OFileSelector::setPermission( ) const | 252 | bool OFileSelector::setPermission( ) const |
220 | { | 253 | { |
221 | if( m_checkPerm == 0 ) | 254 | if( m_checkPerm == 0 ) |
222 | return false; | 255 | return false; |
223 | else | 256 | else |
224 | return m_checkPerm->isChecked(); | 257 | return m_checkPerm->isChecked(); |
225 | } | 258 | } |
226 | void OFileSelector::setPermissionChecked( bool check ) | 259 | void OFileSelector::setPermissionChecked( bool check ) |
227 | { | 260 | { |
228 | if( m_checkPerm == 0 ) | 261 | if( m_checkPerm == 0 ) |
229 | return; | 262 | return; |
230 | m_checkPerm->setChecked( check ); | 263 | m_checkPerm->setChecked( check ); |
231 | } | 264 | } |
232 | QString OFileSelector::selectedName( ) | 265 | QString OFileSelector::selectedName( )const |
233 | { | 266 | { |
234 | QString string; | 267 | QString string; |
268 | if( m_selector == NORMAL ){ | ||
269 | const DocLnk *lnk = m_select->selected(); | ||
270 | string = lnk->file(); | ||
271 | }else if(m_selector == EXTENDED || m_selector == EXTENDED_ALL ) { | ||
272 | QListViewItem *item = m_View->currentItem(); | ||
273 | if(item != 0 ){ | ||
274 | string = item->text( 1 ); | ||
275 | } | ||
276 | } | ||
235 | return string; | 277 | return string; |
236 | } | 278 | } |
237 | const DocLnk* OFileSelector::selectedDocument( )const | 279 | QStringList OFileSelector::selectedNames()const |
238 | { | 280 | { |
239 | return 0; | 281 | QStringList list; |
282 | |||
283 | } | ||
284 | DocLnk OFileSelector::selectedDocument( )const | ||
285 | { | ||
286 | DocLnk lnk; | ||
287 | return lnk; | ||
240 | } | 288 | } |
241 | void OFileSelector::updateLay() | 289 | void OFileSelector::updateLay() |
242 | { | 290 | { |
243 | /* if( m_shTool ) | 291 | /* if( m_shTool ) |
244 | // | 292 | // |
245 | else | 293 | else |
246 | // hide | 294 | // hide |
247 | */ | 295 | */ |
248 | // save the state | 296 | // save the state |
249 | bool check = false; | 297 | bool check = false; |
250 | if( m_checkPerm != 0 ) | 298 | if( m_checkPerm != 0 ) |
251 | check = m_checkPerm->isChecked(); | 299 | check = m_checkPerm->isChecked(); |
252 | QString text; | 300 | QString text; |
253 | 301 | ||
254 | if( m_edit != 0 ) | 302 | if( m_edit != 0 ) |
255 | text = m_edit->text(); | 303 | text = m_edit->text(); |
256 | // save current mimetype | 304 | // save current mimetype |
257 | 305 | ||
258 | delItems(); | 306 | delItems(); |
259 | delete m_checkPerm; | 307 | delete m_checkPerm; |
260 | delete m_edit; | 308 | delete m_edit; |
261 | delete m_fnLabel; | 309 | delete m_fnLabel; |
262 | delete m_ok; | 310 | delete m_ok; |
263 | delete m_cancel; | 311 | delete m_cancel; |
@@ -265,114 +313,130 @@ void OFileSelector::updateLay() | |||
265 | delete m_viewCheck; | 313 | delete m_viewCheck; |
266 | delete m_select; // test | 314 | delete m_select; // test |
267 | delete m_stack; | 315 | delete m_stack; |
268 | //delete m_list; | 316 | //delete m_list; |
269 | init(); | 317 | init(); |
270 | if( m_shLne ) | 318 | if( m_shLne ) |
271 | m_edit->setText(text ); | 319 | m_edit->setText(text ); |
272 | if( m_shPerm ) | 320 | if( m_shPerm ) |
273 | m_checkPerm->setChecked(check ); | 321 | m_checkPerm->setChecked(check ); |
274 | } | 322 | } |
275 | // let's update the mimetypes. Use the current mimefilter for the 2nd QDir retrieve | 323 | // let's update the mimetypes. Use the current mimefilter for the 2nd QDir retrieve |
276 | // insert QListViewItems with the right options | 324 | // insert QListViewItems with the right options |
277 | bool OFileSelector::compliesMime(const QString &path, const QString &mime ) | 325 | bool OFileSelector::compliesMime(const QString &path, const QString &mime ) |
278 | { | 326 | { |
279 | if( mime == "All" ) | 327 | if( mime == "All" ) |
280 | return true; | 328 | return true; |
281 | MimeType type( path ); | 329 | MimeType type( path ); |
282 | if( type.id() == mime ) | 330 | if( type.id() == mime ) |
283 | return true; | 331 | return true; |
284 | return false; | 332 | return false; |
285 | } | 333 | } |
286 | 334 | ||
287 | void OFileSelector::reparse() | 335 | void OFileSelector::reparse() |
288 | { | 336 | { |
289 | if(m_View== 0) | 337 | if(m_View== 0 || m_selector == NORMAL) |
290 | return; | 338 | return; |
291 | 339 | ||
292 | m_View->clear(); | 340 | m_View->clear(); |
293 | 341 | ||
294 | QDir dir( m_currentDir ); | 342 | |
295 | QString currMime =m_mimeCheck->currentText(); | 343 | QString currMime =m_mimeCheck->currentText(); |
296 | // update the mimetype now | 344 | // update the mimetype now |
297 | if( m_autoMime ) { | 345 | if( m_autoMime ) { |
346 | QDir dir( m_currentDir ); | ||
298 | m_mimetypes.clear(); | 347 | m_mimetypes.clear(); |
299 | m_mimeCheck->clear(); | 348 | m_mimeCheck->clear(); |
300 | dir.setFilter( QDir::Files | QDir::Readable ); | 349 | dir.setFilter( QDir::Files | QDir::Readable ); |
301 | dir.setSorting(QDir::Size ); | 350 | dir.setSorting(QDir::Size ); |
302 | const QFileInfoList *list = dir.entryInfoList(); | 351 | const QFileInfoList *list = dir.entryInfoList(); |
303 | QFileInfoListIterator it( *list ); | 352 | QFileInfoListIterator it( *list ); |
304 | QFileInfo *fi; | 353 | QFileInfo *fi; |
305 | while( (fi=it.current()) ){ | 354 | while( (fi=it.current()) ){ |
306 | if(fi->extension() == QString::fromLatin1("desktop") ){ | 355 | if(fi->extension() == QString::fromLatin1("desktop") ){ |
307 | ++it; | 356 | ++it; |
308 | continue; | 357 | continue; |
309 | } | 358 | } |
310 | MimeType type(fi->filePath() ); | 359 | MimeType type(fi->filePath() ); |
311 | if( !m_mimetypes.contains( type.id() ) ) | 360 | if( !m_mimetypes.contains( type.id() ) ) |
312 | m_mimetypes.append( type.id() ); | 361 | m_mimetypes.append( type.id() ); |
313 | 362 | ||
314 | ++it; | 363 | ++it; |
315 | } | 364 | } |
365 | m_mimetypes.prepend("All" ); | ||
316 | m_mimeCheck->insertStringList(m_mimetypes ); | 366 | m_mimeCheck->insertStringList(m_mimetypes ); |
317 | // set it to the current mimetype | 367 | // set it to the current mimetype |
318 | }; | 368 | }; |
319 | dir.setFilter(QDir::All ); | 369 | QDir dir( m_currentDir ); |
320 | dir.setSorting(QDir::Name | QDir::DirsFirst ); | 370 | //dir.setFilter(-1 ); |
371 | dir.setSorting(QDir::Name | QDir::DirsFirst | QDir::Reversed | QDir::IgnoreCase ); | ||
321 | const QFileInfoList *list = dir.entryInfoList(); | 372 | const QFileInfoList *list = dir.entryInfoList(); |
322 | QFileInfoListIterator it( *list ); | 373 | QFileInfoListIterator it( *list ); |
323 | QFileInfo *fi; | 374 | QFileInfo *fi; |
324 | while( (fi=it.current()) ){ | 375 | while( (fi=it.current()) ){ |
376 | if(fi->fileName() == ".." || fi->fileName() == "." ){ | ||
377 | ++it; | ||
378 | continue; | ||
379 | } | ||
380 | qWarning("Test: %s", fi->fileName().latin1() ); | ||
325 | if(fi->isSymLink() ){ | 381 | if(fi->isSymLink() ){ |
382 | qWarning("Symlink %s", fi->fileName().latin1() ); | ||
326 | QString file = fi->readLink(); | 383 | QString file = fi->readLink(); |
384 | qWarning("File ->%s", file.latin1() ); | ||
327 | for(int i=0; i<=4; i++ ){ // prepend from dos | 385 | for(int i=0; i<=4; i++ ){ // prepend from dos |
328 | QFileInfo info( file ); | 386 | QFileInfo info( fi->dirPath()+ "/"+file ); |
329 | if( !info.exists() ){ | 387 | if( !info.exists() ){ |
330 | addSymlink(m_currentDir, info.fileName(), TRUE ); | 388 | qWarning("does not exist" ); |
389 | addSymlink(currMime, fi, TRUE ); | ||
331 | break; | 390 | break; |
332 | }else if( info.isDir() ){ | 391 | }else if( info.isDir() ){ |
333 | //addDir( ); | 392 | qWarning("isDir" ); |
393 | addDir(currMime, fi, TRUE ); | ||
394 | break; | ||
334 | }else if( info.isFile() ){ | 395 | }else if( info.isFile() ){ |
335 | 396 | qWarning("isFile" ); | |
397 | addFile(currMime, fi, TRUE ); | ||
398 | break; | ||
336 | }else if( info.isSymLink() ){ | 399 | }else if( info.isSymLink() ){ |
337 | file = info.readLink(); | 400 | file = info.readLink(); |
401 | qWarning("isSymlink again %s", file.latin1() ); | ||
338 | }else if( i == 4 ){ // just insert it and have the symlink symbol | 402 | }else if( i == 4 ){ // just insert it and have the symlink symbol |
339 | addSymlink(m_currentDir, info.fileName() ); | 403 | addSymlink(currMime, fi ); |
404 | qWarning("level too deep" ); | ||
340 | } | 405 | } |
341 | } | 406 | } |
342 | }else if( fi->isDir() ){ | 407 | }else if( fi->isDir() ){ |
343 | 408 | addDir(currMime, fi ); | |
344 | }else if( fi->isFile() ) { // file ? | 409 | }else if( fi->isFile() ) { // file ? |
345 | 410 | addFile(currMime, fi ); | |
346 | |||
347 | } | 411 | } |
348 | ++it; | 412 | ++it; |
349 | } | 413 | } |
414 | m_View->sort(); | ||
350 | } | 415 | } |
351 | QString OFileSelector::directory() | 416 | QString OFileSelector::directory()const |
352 | { | 417 | { |
353 | QString string; | 418 | return m_currentDir; |
354 | return string; | ||
355 | } | 419 | } |
356 | int OFileSelector::fileCount() | 420 | int OFileSelector::fileCount() |
357 | { | 421 | { |
358 | return 0; | 422 | return 0; |
359 | } | 423 | } |
360 | void OFileSelector::slotOk( ) | 424 | void OFileSelector::slotOk( ) |
361 | { | 425 | { |
362 | emit ok(); | 426 | emit ok(); |
363 | } | 427 | } |
364 | void OFileSelector::slotCancel( ) | 428 | void OFileSelector::slotCancel( ) |
365 | { | 429 | { |
366 | emit cancel(); | 430 | emit cancel(); |
367 | } | 431 | } |
368 | 432 | ||
369 | void OFileSelector::initializeName() | 433 | void OFileSelector::initializeName() |
370 | { | 434 | { |
371 | m_boxName = new QHBoxLayout(this ); | 435 | m_boxName = new QHBoxLayout(this ); |
372 | m_edit = new QLineEdit(this ); | 436 | m_edit = new QLineEdit(this ); |
373 | m_fnLabel = new QLabel(this ); | 437 | m_fnLabel = new QLabel(this ); |
374 | m_fnLabel->setText(tr("Name:") ); | 438 | m_fnLabel->setText(tr("Name:") ); |
375 | m_boxName->addWidget(m_fnLabel ); | 439 | m_boxName->addWidget(m_fnLabel ); |
376 | m_boxName->insertSpacing(1, 8 ); | 440 | m_boxName->insertSpacing(1, 8 ); |
377 | m_boxName->addWidget(m_edit, 100 ); | 441 | m_boxName->addWidget(m_edit, 100 ); |
378 | 442 | ||
@@ -427,50 +491,54 @@ void OFileSelector::slotMimeCheck(const QString &view ){ | |||
427 | m_select = new FileSelector(view == "All" ? QString::null : view | 491 | m_select = new FileSelector(view == "All" ? QString::null : view |
428 | , m_stack, "fileselector", FALSE, FALSE ); | 492 | , m_stack, "fileselector", FALSE, FALSE ); |
429 | m_stack->addWidget( m_select, NORMAL ); | 493 | m_stack->addWidget( m_select, NORMAL ); |
430 | m_stack->raiseWidget( NORMAL ); | 494 | m_stack->raiseWidget( NORMAL ); |
431 | }else{ | 495 | }else{ |
432 | 496 | ||
433 | 497 | ||
434 | } | 498 | } |
435 | } | 499 | } |
436 | 500 | ||
437 | void OFileSelector::slotViewCheck(const QString &view ){ | 501 | void OFileSelector::slotViewCheck(const QString &view ){ |
438 | qWarning("changed: show %s", view.latin1() ); | 502 | qWarning("changed: show %s", view.latin1() ); |
439 | // if the current view is the one | 503 | // if the current view is the one |
440 | QString currMime = m_mimeCheck->currentText(); | 504 | QString currMime = m_mimeCheck->currentText(); |
441 | if( view == QString::fromLatin1("Documents") ){ | 505 | if( view == QString::fromLatin1("Documents") ){ |
442 | // get the mimetype now | 506 | // get the mimetype now |
443 | // check if we're the current widget and return | 507 | // check if we're the current widget and return |
444 | if( m_View != 0) // delete 0 shouldn't crash but it did :( | 508 | if( m_View != 0) // delete 0 shouldn't crash but it did :( |
445 | delete m_View; | 509 | delete m_View; |
446 | m_View = 0; | 510 | m_View = 0; |
447 | delete m_select; | 511 | delete m_select; |
448 | m_select = new FileSelector( currMime == "All" ? QString::null : currMime, | 512 | m_select = new FileSelector( currMime == "All" ? QString::null : currMime, |
449 | m_stack,"fileselector", FALSE, FALSE ); | 513 | m_stack,"fileselector", FALSE, FALSE ); |
450 | m_stack->addWidget( m_select, NORMAL ); | 514 | m_stack->addWidget( m_select, NORMAL ); |
451 | m_stack->raiseWidget( NORMAL ); | 515 | m_mimeCheck->clear(); |
452 | m_selector = NORMAL; | 516 | m_selector = NORMAL; |
517 | updateMimes(); | ||
518 | m_mimeCheck->insertStringList( m_mimetypes ); | ||
519 | m_stack->raiseWidget( NORMAL ); | ||
520 | |||
453 | 521 | ||
454 | }else if(view == QString::fromLatin1("Files") ){ | 522 | }else if(view == QString::fromLatin1("Files") ){ |
455 | // remove from the stack | 523 | // remove from the stack |
456 | delete m_select; | 524 | delete m_select; |
457 | m_select = 0; | 525 | m_select = 0; |
458 | delete m_View; | 526 | delete m_View; |
459 | m_View = 0; | 527 | m_View = 0; |
460 | m_selector = EXTENDED; | 528 | m_selector = EXTENDED; |
461 | // create the ListView or IconView | 529 | // create the ListView or IconView |
462 | initializeListView(); | 530 | initializeListView(); |
463 | 531 | ||
464 | reparse(); | 532 | reparse(); |
465 | }else if(view == QString::fromLatin1("All Files") ) { | 533 | }else if(view == QString::fromLatin1("All Files") ) { |
466 | // remove from the stack | 534 | // remove from the stack |
467 | delete m_select; | 535 | delete m_select; |
468 | m_select = 0; | 536 | m_select = 0; |
469 | delete m_View; | 537 | delete m_View; |
470 | m_View = 0; | 538 | m_View = 0; |
471 | m_selector = EXTENDED_ALL; | 539 | m_selector = EXTENDED_ALL; |
472 | initializeListView(); | 540 | initializeListView(); |
473 | reparse(); | 541 | reparse(); |
474 | }; | 542 | }; |
475 | }; | 543 | }; |
476 | 544 | ||
@@ -489,33 +557,81 @@ void OFileSelector::updateMimes() // lets check which mode is active | |||
489 | m_mimetypes.append( (*dit)->type() ); | 557 | m_mimetypes.append( (*dit)->type() ); |
490 | } | 558 | } |
491 | }else{ | 559 | }else{ |
492 | // should be allreday updatet | 560 | // should be allreday updatet |
493 | 561 | ||
494 | } | 562 | } |
495 | }; | 563 | }; |
496 | void OFileSelector::initializeListView() | 564 | void OFileSelector::initializeListView() |
497 | { | 565 | { |
498 | m_View = new QListView(m_stack, "Extended view" ); | 566 | m_View = new QListView(m_stack, "Extended view" ); |
499 | m_stack->addWidget( m_View, EXTENDED ); | 567 | m_stack->addWidget( m_View, EXTENDED ); |
500 | m_stack->raiseWidget( EXTENDED ); | 568 | m_stack->raiseWidget( EXTENDED ); |
501 | QPEApplication::setStylusOperation( m_View->viewport(),QPEApplication::RightOnHold); | 569 | QPEApplication::setStylusOperation( m_View->viewport(),QPEApplication::RightOnHold); |
502 | // set up the stuff | 570 | // set up the stuff |
503 | // Pixmap Name Date Size mime | 571 | // Pixmap Name Date Size mime |
504 | //(m_View->header() )->hide(); | 572 | //(m_View->header() )->hide(); |
505 | //m_View->setRootIsDecorated(false); | 573 | //m_View->setRootIsDecorated(false); |
506 | m_View->addColumn(" "); | 574 | m_View->addColumn(" "); |
507 | m_View->addColumn(tr("Name") ); | 575 | m_View->addColumn(tr("Name") ); |
508 | m_View->addColumn(tr("Size") ); | 576 | m_View->addColumn(tr("Size") ); |
509 | m_View->addColumn(tr("Date"), 60 ); | 577 | m_View->addColumn(tr("Date"), 60 ); |
510 | m_View->addColumn(tr("Mime Type") ); | 578 | m_View->addColumn(tr("Mime Type") ); |
511 | QHeader *header = m_View->header(); | 579 | QHeader *header = m_View->header(); |
512 | header->hide(); | 580 | header->hide(); |
581 | m_View->setSorting(1 ); | ||
513 | }; | 582 | }; |
514 | 583 | ||
584 | void OFileSelector::addFile(const QString &mime, QFileInfo *info, bool symlink ){ | ||
585 | qWarning("Add Files" ); | ||
586 | if( !m_files ){ | ||
587 | qWarning("not mfiles" ); | ||
588 | return; | ||
589 | } | ||
515 | 590 | ||
591 | MimeType type( info->filePath() ); | ||
592 | if(mime == "All" ){ | ||
593 | ; | ||
594 | }else if( type.id() != mime ) { | ||
595 | return; | ||
596 | } | ||
597 | QPixmap pix = type.pixmap(); | ||
598 | if(pix.isNull() ) | ||
599 | pix = Resource::loadPixmap( "UnknownDocument-14" ); | ||
600 | if( symlink ) // have a blended pic sometime | ||
601 | new OFileSelectorItem( m_View, pix, info->fileName(), | ||
602 | info->lastModified().toString(), | ||
603 | QString::number(info->size() ), | ||
604 | info->dirPath(true) ); | ||
605 | else | ||
606 | new OFileSelectorItem( m_View, pix, info->fileName(), | ||
607 | info->lastModified().toString(), | ||
608 | QString::number(info->size() ), | ||
609 | info->dirPath(true) ); | ||
610 | } | ||
611 | void OFileSelector::addDir(const QString &mime, QFileInfo *info, bool symlink ) | ||
612 | { | ||
613 | if(!m_dir ) | ||
614 | return; | ||
615 | //if( showDirs ) | ||
616 | { | ||
617 | if( symlink){ | ||
618 | QPixmap map = (*m_pixmaps)["dirsymlink" ]; | ||
619 | qWarning("Symlink" ); | ||
620 | new OFileSelectorItem(m_View, map, | ||
621 | info->fileName(), info->lastModified().toString() , | ||
622 | QString::number(info->size() ),info->dirPath(true), true ); | ||
623 | }else | ||
624 | new OFileSelectorItem(m_View, Resource::loadPixmap("folder" ), | ||
625 | info->fileName(), info->lastModified().toString(), | ||
626 | QString::number(info->size() ),info->dirPath(true), true ); | ||
516 | 627 | ||
517 | 628 | } | |
518 | 629 | } | |
630 | void OFileSelector::setShowDirs(bool dir ) | ||
631 | { | ||
632 | m_dir = dir; | ||
633 | reparse(); | ||
634 | } | ||
519 | 635 | ||
520 | 636 | ||
521 | 637 | ||