author | eilers <eilers> | 2003-08-08 15:09:29 (UTC) |
---|---|---|
committer | eilers <eilers> | 2003-08-08 15:09:29 (UTC) |
commit | b87b33dc1f6e8e1276a7035ab7a3e53b8ed4bd16 (patch) (unidiff) | |
tree | b0f96db67cfb1b9d2476530ecec9a2ba6eacbab1 /libopie/ofileselector.cc | |
parent | 14d394e6c107b037a09a31a92605034fe50f7813 (diff) | |
download | opie-b87b33dc1f6e8e1276a7035ab7a3e53b8ed4bd16.zip opie-b87b33dc1f6e8e1276a7035ab7a3e53b8ed4bd16.tar.gz opie-b87b33dc1f6e8e1276a7035ab7a3e53b8ed4bd16.tar.bz2 |
Merging all changes from BRANCH_1_0.
-rw-r--r-- | libopie/ofileselector.cc | 1310 |
1 files changed, 0 insertions, 1310 deletions
diff --git a/libopie/ofileselector.cc b/libopie/ofileselector.cc deleted file mode 100644 index 6748bec..0000000 --- a/libopie/ofileselector.cc +++ b/dev/null | |||
@@ -1,1310 +0,0 @@ | |||
1 | |||
2 | |||
3 | #include <qwmatrix.h> | ||
4 | #include <qcheckbox.h> | ||
5 | #include <qcombobox.h> | ||
6 | #include <qheader.h> | ||
7 | #include <qlabel.h> | ||
8 | #include <qabstractlayout.h> | ||
9 | #include <qlayout.h> | ||
10 | #include <qlineedit.h> | ||
11 | #include <qlistview.h> | ||
12 | #include <qmessagebox.h> | ||
13 | #include <qpainter.h> | ||
14 | #include <qpushbutton.h> | ||
15 | #include <qwidgetstack.h> | ||
16 | #include <qpopupmenu.h> | ||
17 | #include <qdir.h> | ||
18 | #include <qfile.h> | ||
19 | #include <qfileinfo.h> | ||
20 | #include <qtimer.h> | ||
21 | |||
22 | #include <qpe/qpeapplication.h> | ||
23 | #include <qpe/applnk.h> | ||
24 | #include <qpe/fileselector.h> | ||
25 | #include <qpe/global.h> | ||
26 | #include <qpe/mimetype.h> | ||
27 | #include <qpe/resource.h> | ||
28 | #include <qpe/storage.h> | ||
29 | |||
30 | #include <unistd.h> | ||
31 | #include <stdlib.h> | ||
32 | #include <sys/stat.h> | ||
33 | |||
34 | #include "ofileselector.h" | ||
35 | |||
36 | |||
37 | QMap<QString,QPixmap> *OFileSelector::m_pixmaps = 0; | ||
38 | |||
39 | namespace { | ||
40 | int indexByString( const QComboBox *box, const QString &str ){ | ||
41 | int index= 0; | ||
42 | for(int i= 0; i < box->count(); i++ ){ | ||
43 | if( str == box->text(i ) ){ | ||
44 | index= i; | ||
45 | break; | ||
46 | } | ||
47 | } | ||
48 | return index; | ||
49 | } | ||
50 | class OFileSelectorItem : public QListViewItem { | ||
51 | public: | ||
52 | OFileSelectorItem(QListView *view, const QPixmap &pixmap, const QString &path, | ||
53 | const QString &date, const QString &size, const QString &mDir, | ||
54 | bool isLocked=false, bool isDir=false ): QListViewItem(view) { | ||
55 | setPixmap(0, pixmap ); | ||
56 | setText(1, path ); | ||
57 | setText(2, size ); | ||
58 | setText(3, date ); | ||
59 | //setText(4, mDir ); | ||
60 | m_dir = mDir; | ||
61 | dir = isDir; | ||
62 | mLocked = isLocked; | ||
63 | } | ||
64 | bool isLocked() const{ | ||
65 | return mLocked; | ||
66 | } | ||
67 | QString directory()const{ | ||
68 | return m_dir; | ||
69 | } | ||
70 | bool isDir()const{ | ||
71 | return dir; | ||
72 | } | ||
73 | QString path()const{ | ||
74 | return text(1 ); | ||
75 | } | ||
76 | QString key(int id, bool )const { | ||
77 | QString ke; | ||
78 | if( id == 0 || id == 1 ){ // name | ||
79 | if( dir ){ | ||
80 | ke.append("0" ); | ||
81 | ke.append( text(1) ); | ||
82 | }else{ | ||
83 | ke.append("1" ); | ||
84 | ke.append( text(1) ); | ||
85 | } | ||
86 | }else if( id == 2 ){ // size | ||
87 | return text(2); | ||
88 | }else if( id == 3 ){ // date | ||
89 | return text(3); | ||
90 | } | ||
91 | return ke; | ||
92 | }; | ||
93 | private: | ||
94 | bool mLocked:1; | ||
95 | bool dir:1; | ||
96 | QString m_dir; | ||
97 | }; | ||
98 | }; | ||
99 | |||
100 | |||
101 | OFileSelector::OFileSelector( QWidget *wid, int mode, int selector, | ||
102 | const QString &dirName, | ||
103 | const QString &fileName, | ||
104 | const QMap<QString,QStringList>& mimeTypes) | ||
105 | : QWidget( wid, "OFileSelector") | ||
106 | { | ||
107 | m_mimetypes = mimeTypes; | ||
108 | if (mode == SAVE ) | ||
109 | m_name = fileName; | ||
110 | initVars(); | ||
111 | m_mode = mode; | ||
112 | m_selector = selector; | ||
113 | m_currentDir = dirName; | ||
114 | init(); | ||
115 | //QTimer::singleShot(6*1000, this, SLOT( slotTest() ) ); | ||
116 | } | ||
117 | |||
118 | OFileSelector::OFileSelector(const QString &mimeFilter, QWidget *parent, | ||
119 | const char *name, bool newVisible, | ||
120 | bool closeVisible ) | ||
121 | : QWidget( parent, name ) | ||
122 | { | ||
123 | if (!mimeFilter.isEmpty() ) { | ||
124 | QStringList list = QStringList::split(";", mimeFilter ); | ||
125 | m_mimetypes.insert(mimeFilter, list ); | ||
126 | } | ||
127 | initVars(); | ||
128 | m_currentDir = QPEApplication::documentDir(); | ||
129 | m_mode = FILESELECTOR; | ||
130 | m_selector = NORMAL; | ||
131 | m_shClose = closeVisible; | ||
132 | m_shNew = newVisible; | ||
133 | m_shLne = false; | ||
134 | m_shPerm = false; | ||
135 | m_shYesNo = false; | ||
136 | init(); | ||
137 | |||
138 | } | ||
139 | |||
140 | OFileSelector::~OFileSelector() | ||
141 | { | ||
142 | |||
143 | |||
144 | } | ||
145 | |||
146 | void OFileSelector::setNewVisible( bool visible ) | ||
147 | { | ||
148 | m_shNew = visible; | ||
149 | if( m_selector == NORMAL ){ | ||
150 | delete m_select; | ||
151 | // we need to initialize but keep the selected mimetype | ||
152 | QString mime = currentMimeType(); | ||
153 | m_select = new FileSelector( mime , | ||
154 | m_stack, "fileselector", | ||
155 | m_shNew, m_shClose); | ||
156 | connect(m_select, SIGNAL(fileSelected( const DocLnk & ) ), | ||
157 | this, SLOT( slotFileBridgeSelected(const DocLnk & ) ) ); | ||
158 | connect(m_select, SIGNAL(closeMe() ), | ||
159 | this, SIGNAL(closeMe() ) ); | ||
160 | //connect to close me and other signals as well | ||
161 | m_stack->addWidget( m_select, NORMAL ); | ||
162 | }else{ | ||
163 | m_new->show(); | ||
164 | } | ||
165 | } | ||
166 | void OFileSelector::setCloseVisible( bool visible ) | ||
167 | { | ||
168 | m_shClose = visible; | ||
169 | if( m_selector == NORMAL ){ | ||
170 | setNewVisible( m_shNew ); // yeah baby | ||
171 | }else{ | ||
172 | m_close->show(); | ||
173 | } | ||
174 | } | ||
175 | void OFileSelector::reread() | ||
176 | { | ||
177 | if( m_selector == NORMAL ){ | ||
178 | setNewVisible( m_shNew ); // make it a initializeSelector | ||
179 | }else if ( m_selector == EXTENDED || m_selector == EXTENDED_ALL ){ | ||
180 | reparse(); | ||
181 | //}else{ | ||
182 | //; | ||
183 | } | ||
184 | } | ||
185 | |||
186 | const DocLnk *OFileSelector::selected() | ||
187 | { | ||
188 | DocLnk *lnk = new DocLnk(selectedDocument() ); | ||
189 | return lnk; | ||
190 | } | ||
191 | |||
192 | void OFileSelector::setYesCancelVisible( bool show ) | ||
193 | { | ||
194 | initializeYes(); // FIXME if YesCancel is not shown we will initialize it to hide it :( | ||
195 | m_shYesNo = show; | ||
196 | if( m_shYesNo ) | ||
197 | m_boxOk->show(); | ||
198 | else | ||
199 | m_boxOk->hide(); | ||
200 | |||
201 | } | ||
202 | void OFileSelector::setToolbarVisible( bool show ) | ||
203 | { | ||
204 | m_shTool = show; | ||
205 | initializeListView(); // FIXME see above waste of memory | ||
206 | if(!m_shTool ){ | ||
207 | m_location->hide(); | ||
208 | m_up->hide(); | ||
209 | m_homeButton->hide(); | ||
210 | m_docButton->hide(); | ||
211 | }else{ | ||
212 | m_location->show(); | ||
213 | m_up->show(); | ||
214 | m_homeButton->show(); | ||
215 | m_docButton->show(); | ||
216 | } | ||
217 | } | ||
218 | void OFileSelector::setPermissionBarVisible( bool show ) | ||
219 | { | ||
220 | m_shPerm = show; | ||
221 | initializePerm(); | ||
222 | if( m_shPerm ) | ||
223 | m_checkPerm->show(); | ||
224 | else | ||
225 | m_checkPerm->hide(); | ||
226 | } | ||
227 | void OFileSelector::setLineEditVisible( bool show ) | ||
228 | { | ||
229 | if( show ){ | ||
230 | initializeName(); | ||
231 | m_boxName->show(); | ||
232 | }else{ | ||
233 | if( m_shLne && m_boxName != 0 ){ // check if we showed before this is the way to go | ||
234 | m_boxName->hide(); | ||
235 | } | ||
236 | } | ||
237 | m_shLne = show; | ||
238 | } | ||
239 | |||
240 | void OFileSelector::setChooserVisible( bool show ) | ||
241 | { | ||
242 | m_shChooser = show; | ||
243 | initializeChooser(); | ||
244 | if( m_shChooser ){ | ||
245 | m_boxView->hide(); | ||
246 | }else{ | ||
247 | m_boxView->show(); | ||
248 | } | ||
249 | } | ||
250 | |||
251 | QCheckBox* OFileSelector::permissionCheckbox() | ||
252 | { | ||
253 | if( m_selector == NORMAL ) | ||
254 | return 0l; | ||
255 | else | ||
256 | return m_checkPerm; | ||
257 | } | ||
258 | bool OFileSelector::setPermission()const | ||
259 | { | ||
260 | return m_checkPerm == 0 ? false : m_checkPerm->isChecked(); | ||
261 | } | ||
262 | void OFileSelector::setPermissionChecked( bool check ) | ||
263 | { | ||
264 | if( m_checkPerm ) | ||
265 | m_checkPerm->setChecked( check ); | ||
266 | } | ||
267 | |||
268 | void OFileSelector::setMode(int mode) // FIXME do direct raising | ||
269 | { | ||
270 | m_mode = mode; | ||
271 | if( m_selector == NORMAL ) | ||
272 | return; | ||
273 | } | ||
274 | void OFileSelector::setShowDirs(bool ) | ||
275 | { | ||
276 | m_dir = true; | ||
277 | reparse(); | ||
278 | } | ||
279 | void OFileSelector::setCaseSensetive(bool caSe ) | ||
280 | { | ||
281 | m_case = caSe; | ||
282 | reparse(); | ||
283 | } | ||
284 | void OFileSelector::setShowFiles(bool show ) | ||
285 | { | ||
286 | m_files = show; | ||
287 | reparse(); | ||
288 | } | ||
289 | /// | ||
290 | bool OFileSelector::cd(const QString &path ) | ||
291 | { | ||
292 | m_currentDir = path; | ||
293 | reparse(); | ||
294 | return true; | ||
295 | } | ||
296 | void OFileSelector::setSelector(int mode ) | ||
297 | { | ||
298 | QString text; | ||
299 | switch( mode ){ | ||
300 | case NORMAL: | ||
301 | text = tr("Documents"); | ||
302 | break; | ||
303 | case EXTENDED: | ||
304 | text = tr("Files"); | ||
305 | break; | ||
306 | case EXTENDED_ALL: | ||
307 | text = tr("All Files"); | ||
308 | break; | ||
309 | } | ||
310 | slotViewCheck( text ); | ||
311 | } | ||
312 | |||
313 | void OFileSelector::setPopupMenu(QPopupMenu *popup ) | ||
314 | { | ||
315 | m_custom = popup; | ||
316 | m_showPopup = true; | ||
317 | } | ||
318 | |||
319 | //void OFileSelector::updateL | ||
320 | |||
321 | QString OFileSelector::selectedName() const | ||
322 | { | ||
323 | QString name; | ||
324 | if( m_selector == NORMAL ){ | ||
325 | DocLnk lnk = m_select->selectedDocument(); | ||
326 | name = lnk.file(); | ||
327 | }else if( m_selector == EXTENDED || m_selector == EXTENDED_ALL ){ | ||
328 | if ( m_shLne ) { | ||
329 | name = m_currentDir + "/" +m_edit->text(); | ||
330 | }else{ | ||
331 | QListViewItem *item = m_View->currentItem(); | ||
332 | if( item != 0 ) | ||
333 | name = m_currentDir + "/" + item->text( 1 ); | ||
334 | } | ||
335 | }else { // installed view | ||
336 | ; | ||
337 | } | ||
338 | return name; | ||
339 | } | ||
340 | QStringList OFileSelector::selectedNames()const | ||
341 | { | ||
342 | QStringList list; | ||
343 | if( m_selector == NORMAL ){ | ||
344 | list << selectedName(); | ||
345 | }else if ( m_selector == EXTENDED || m_selector == EXTENDED_ALL ) { | ||
346 | list << selectedName(); // FIXME implement multiple Selections | ||
347 | } | ||
348 | return list; | ||
349 | } | ||
350 | /** If mode is set to the Dir selection this will return the selected path. | ||
351 | * | ||
352 | * | ||
353 | */ | ||
354 | QString OFileSelector::selectedPath()const | ||
355 | { | ||
356 | QString path; | ||
357 | if( m_selector == NORMAL ){ | ||
358 | path = QPEApplication::documentDir(); | ||
359 | }else if( m_selector == EXTENDED || m_selector == EXTENDED_ALL ){ | ||
360 | ; | ||
361 | } | ||
362 | return path; | ||
363 | } | ||
364 | QStringList OFileSelector::selectedPaths() const | ||
365 | { | ||
366 | QStringList list; | ||
367 | list << selectedPath(); | ||
368 | return list; | ||
369 | } | ||
370 | QString OFileSelector::directory()const | ||
371 | { | ||
372 | if( m_selector == NORMAL ) | ||
373 | return QPEApplication::documentDir(); | ||
374 | |||
375 | return QDir(m_currentDir).absPath(); | ||
376 | } | ||
377 | |||
378 | int OFileSelector::fileCount() const | ||
379 | { | ||
380 | int count; | ||
381 | switch( m_selector ){ | ||
382 | case NORMAL: | ||
383 | count = m_select->fileCount(); | ||
384 | break; | ||
385 | //case CUSTOM: | ||
386 | case EXTENDED: | ||
387 | case EXTENDED_ALL: | ||
388 | default: | ||
389 | count = m_View->childCount(); | ||
390 | break; | ||
391 | } | ||
392 | return count; | ||
393 | } | ||
394 | DocLnk OFileSelector::selectedDocument() const | ||
395 | { | ||
396 | DocLnk lnk; | ||
397 | switch( m_selector ){ | ||
398 | case NORMAL:{ | ||
399 | lnk = m_select->selectedDocument(); | ||
400 | break; | ||
401 | } | ||
402 | case EXTENDED: | ||
403 | case EXTENDED_ALL: | ||
404 | default: | ||
405 | lnk = DocLnk( selectedName() ); // new DocLnk | ||
406 | break; | ||
407 | } | ||
408 | return lnk; | ||
409 | } | ||
410 | QValueList<DocLnk> OFileSelector::selectedDocuments() const | ||
411 | { | ||
412 | QValueList<DocLnk> docs; | ||
413 | docs.append( selectedDocument() ); | ||
414 | return docs; | ||
415 | } | ||
416 | |||
417 | |||
418 | // slots internal | ||
419 | |||
420 | void OFileSelector::slotOk() | ||
421 | { | ||
422 | emit ok(); | ||
423 | } | ||
424 | void OFileSelector::slotCancel() | ||
425 | { | ||
426 | emit cancel(); | ||
427 | } | ||
428 | void OFileSelector::slotViewCheck(const QString &sel) | ||
429 | { | ||
430 | if( sel == tr("Documents" ) ){ | ||
431 | if( m_select == 0 ){ | ||
432 | // autMime? fix cause now we use All and not the current | ||
433 | // yes currentMime fixes that for us | ||
434 | QString mime = currentMimeType(); | ||
435 | m_select = new FileSelector(mime, | ||
436 | m_stack, "fileselector", | ||
437 | m_shNew, m_shClose); | ||
438 | connect(m_select, SIGNAL(fileSelected( const DocLnk & ) ), | ||
439 | this, SLOT( slotFileBridgeSelected(const DocLnk & ) ) ); | ||
440 | connect(m_select, SIGNAL(closeMe() ), | ||
441 | this, SIGNAL(closeMe() ) ); | ||
442 | //connect to close me and other signals as well | ||
443 | |||
444 | m_stack->addWidget( m_select, NORMAL ); | ||
445 | } | ||
446 | m_stack->raiseWidget( NORMAL ); | ||
447 | m_selector = NORMAL; | ||
448 | }else if( sel == tr("Files") ){ | ||
449 | m_selector = EXTENDED; | ||
450 | initializeListView(); | ||
451 | reparse(); | ||
452 | m_stack->raiseWidget( EXTENDED ); | ||
453 | }else if( sel == tr("All Files") ){ | ||
454 | m_selector = EXTENDED_ALL; | ||
455 | initializeListView(); | ||
456 | reparse(); | ||
457 | m_stack->raiseWidget( EXTENDED ); // same widget other QFileFilter | ||
458 | } | ||
459 | } | ||
460 | // not yet finished..... | ||
461 | QString OFileSelector::currentMimeType() const{ | ||
462 | QString mime; | ||
463 | QString currentText; | ||
464 | if (m_shChooser ) | ||
465 | currentText = m_mimeCheck->currentText(); | ||
466 | |||
467 | if (tr("All") == currentText ) return QString::null; | ||
468 | else if (currentText.isEmpty() ) { | ||
469 | ; | ||
470 | }else { | ||
471 | QMap<QString, QStringList>::ConstIterator it; | ||
472 | it = m_mimetypes.find( currentText ); | ||
473 | if ( it == m_mimetypes.end() ) { | ||
474 | mime = it.data().join(";"); | ||
475 | }else{ | ||
476 | mime = currentText; | ||
477 | } | ||
478 | } | ||
479 | return mime; | ||
480 | } | ||
481 | void OFileSelector::slotMimeCheck(const QString &mime) | ||
482 | { | ||
483 | if( m_selector == NORMAL ){ | ||
484 | //if( m_autoMime ){ | ||
485 | QString newMimeType; | ||
486 | if (mime != tr("All") ) { | ||
487 | QMap<QString, QStringList>::Iterator it; | ||
488 | it = m_mimetypes.find(mime); | ||
489 | if ( it != m_mimetypes.end() ) { | ||
490 | newMimeType = it.data().join(";"); | ||
491 | }else{ | ||
492 | newMimeType = mime; | ||
493 | } | ||
494 | } | ||
495 | delete m_select; | ||
496 | m_select = new FileSelector( newMimeType, | ||
497 | m_stack, "fileselector", | ||
498 | m_shNew, m_shClose); | ||
499 | |||
500 | connect(m_select, SIGNAL(fileSelected( const DocLnk & ) ), | ||
501 | this, SLOT( slotFileBridgeSelected(const DocLnk & ) ) ); | ||
502 | connect(m_select, SIGNAL(closeMe() ), | ||
503 | this, SIGNAL(closeMe() ) ); | ||
504 | //connect to close me and other signals as well | ||
505 | m_stack->addWidget( m_select, NORMAL ); | ||
506 | m_stack->raiseWidget( NORMAL ); | ||
507 | updateMimes(); | ||
508 | updateMimeCheck(); | ||
509 | m_mimeCheck->setCurrentItem(indexByString( m_mimeCheck, mime) ); | ||
510 | //} | ||
511 | }else{ // others | ||
512 | qWarning("Mime %s", mime.latin1() ); | ||
513 | if(m_shChooser ){ | ||
514 | qWarning("Current Text %s", m_mimeCheck->currentText().latin1() ); | ||
515 | //m_mimeCheck->setCurrentItem(indexByString( m_mimeCheck, mime) ); | ||
516 | } | ||
517 | reparse(); | ||
518 | } | ||
519 | |||
520 | } | ||
521 | /* | ||
522 | * Ok if a non dir gets inserted into this combobox | ||
523 | * we need to change it | ||
524 | * QFileInfo and dirPath will give us the right Dir | ||
525 | */ | ||
526 | void OFileSelector::slotLocationActivated(const QString &file) | ||
527 | { | ||
528 | qWarning("slotLocationActivated"); | ||
529 | QString name = file.left( file.find("<-", 0, TRUE ) ); | ||
530 | QFileInfo info( name ); | ||
531 | if ( info.isFile() ) | ||
532 | cd(info.dirPath( TRUE ) ); //absolute | ||
533 | else | ||
534 | cd(name ); | ||
535 | reparse(); | ||
536 | } | ||
537 | void OFileSelector::slotInsertLocationPath(const QString ¤tPath, int count) | ||
538 | { | ||
539 | QStringList pathList; | ||
540 | bool underDog = FALSE; | ||
541 | for(int i=0;i<count;i++) { | ||
542 | pathList << m_location->text(i); | ||
543 | if( m_location->text(i) == currentPath) | ||
544 | underDog = TRUE; | ||
545 | } | ||
546 | if( !underDog) { | ||
547 | m_location->clear(); | ||
548 | if( currentPath.left(2)=="//") | ||
549 | pathList.append( currentPath.right(currentPath.length()-1) ); | ||
550 | else | ||
551 | pathList.append( currentPath ); | ||
552 | m_location->insertStringList( pathList,-1); | ||
553 | } | ||
554 | } | ||
555 | /* | ||
556 | * Do not crash anymore | ||
557 | * don't try to change dir to a file | ||
558 | */ | ||
559 | void OFileSelector::locationComboChanged() | ||
560 | { | ||
561 | QFileInfo info( m_location->lineEdit()->text() ); | ||
562 | qWarning("info %s %s", info.dirPath(true).latin1(), m_location->lineEdit()->text().latin1() ); | ||
563 | if (info.isFile() ) | ||
564 | cd(info.dirPath(TRUE) ); //absolute path | ||
565 | else | ||
566 | cd( m_location->lineEdit()->text() ); | ||
567 | |||
568 | reparse(); | ||
569 | } | ||
570 | void OFileSelector::init() | ||
571 | { | ||
572 | m_lay = new QVBoxLayout( this ); | ||
573 | m_lay->setSpacing(0 ); | ||
574 | |||
575 | m_stack = new QWidgetStack( this ); | ||
576 | if( m_selector == NORMAL ){ | ||
577 | QString mime; | ||
578 | if (!m_autoMime) { | ||
579 | if (!m_mimetypes.isEmpty() ) { | ||
580 | QMap<QString, QStringList>::Iterator it; | ||
581 | it = m_mimetypes.begin(); // cause we're in the init | ||
582 | mime = it.data().join(";"); | ||
583 | } | ||
584 | } | ||
585 | m_select = new FileSelector(mime, | ||
586 | m_stack, "fileselector", | ||
587 | m_shNew, m_shClose); | ||
588 | |||
589 | connect(m_select, SIGNAL(fileSelected( const DocLnk & ) ), | ||
590 | this, SLOT( slotFileBridgeSelected(const DocLnk & ) ) ); | ||
591 | connect(m_select, SIGNAL(closeMe() ), | ||
592 | this, SIGNAL( closeMe() ) ); | ||
593 | //connect to close me and other signals as well | ||
594 | |||
595 | m_stack->addWidget( m_select, NORMAL ); | ||
596 | m_stack->raiseWidget( NORMAL ); | ||
597 | }else{ // we're in init so it will be EXTENDED or EXTENDED_ALL | ||
598 | // and initializeListview will take care of those | ||
599 | // toolbar get's generade in initializeListView | ||
600 | initializeListView( ); // will raise the widget as well | ||
601 | m_stack->raiseWidget( EXTENDED ); | ||
602 | } | ||
603 | m_lay->addWidget( m_stack, 100 ); // add to the layout 10 = stretch | ||
604 | |||
605 | if( m_shLne ) // the LineEdit with the current FileName | ||
606 | initializeName(); | ||
607 | |||
608 | if( m_shPerm ) // the Permission QCheckBox | ||
609 | initializePerm(); | ||
610 | |||
611 | if( m_shChooser ) // the Chooser for the view and Mimetypes | ||
612 | initializeChooser(); | ||
613 | |||
614 | if( m_shYesNo ) // the Yes No button row | ||
615 | initializeYes( ); | ||
616 | |||
617 | if (m_selector != NORMAL ) | ||
618 | reparse(); | ||
619 | } | ||
620 | void OFileSelector::updateMimes() | ||
621 | { | ||
622 | if( m_autoMime ){ | ||
623 | m_mimetypes.clear(); | ||
624 | m_mimetypes.insert( tr("All"), QString::null ); | ||
625 | if( m_selector == NORMAL ){ | ||
626 | DocLnkSet set; | ||
627 | Global::findDocuments(&set, QString::null ); | ||
628 | QListIterator<DocLnk> dit( set.children() ); | ||
629 | for( ; dit.current(); ++dit ){ | ||
630 | if( !m_mimetypes.contains( (*dit)->type() ) ) | ||
631 | m_mimetypes.insert( (*dit)->type(), (*dit)->type() ); | ||
632 | } | ||
633 | }// else done in reparse | ||
634 | } | ||
635 | } | ||
636 | void OFileSelector::initVars() | ||
637 | { | ||
638 | if( m_mimetypes.isEmpty() ) | ||
639 | m_autoMime = true; | ||
640 | else | ||
641 | m_autoMime = false; | ||
642 | m_shClose = false; | ||
643 | m_shNew = false; | ||
644 | m_shTool = true; | ||
645 | m_shPerm = false; | ||
646 | m_shLne = true; | ||
647 | m_shChooser = true; | ||
648 | m_shYesNo = true; | ||
649 | m_case = false; | ||
650 | m_dir = true; | ||
651 | m_files = true; | ||
652 | m_showPopup = false; | ||
653 | if(m_pixmaps == 0 ) // init the pixmaps | ||
654 | initPics(); | ||
655 | |||
656 | // pointers | ||
657 | m_location = 0; | ||
658 | m_mimeCheck = 0; | ||
659 | m_viewCheck = 0; | ||
660 | m_homeButton = 0; | ||
661 | m_docButton = 0; | ||
662 | m_hideButton = 0; | ||
663 | m_ok = 0; | ||
664 | m_cancel = 0; | ||
665 | m_reread = 0; | ||
666 | m_up = 0; | ||
667 | m_View = 0; | ||
668 | m_checkPerm = 0; | ||
669 | m_pseudo = 0; | ||
670 | m_pseudoLayout = 0; | ||
671 | m_select = 0; | ||
672 | m_stack = 0; | ||
673 | m_lay = 0; | ||
674 | m_Oselector = 0; | ||
675 | m_boxToolbar = 0; | ||
676 | m_boxOk = 0; | ||
677 | m_boxName = 0; | ||
678 | m_boxView = 0; | ||
679 | m_custom = 0; | ||
680 | m_edit = 0; | ||
681 | m_fnLabel = 0; | ||
682 | m_new = 0; | ||
683 | m_close = 0; | ||
684 | } | ||
685 | void OFileSelector::addFile(const QString &/*mime*/, QFileInfo *info, bool symlink) | ||
686 | { | ||
687 | if(!m_files) | ||
688 | return; | ||
689 | // if( !compliesMime(info->absFilePath(), mime ) ) | ||
690 | // return; | ||
691 | MimeType type( info->absFilePath() ); | ||
692 | if (!compliesMime( type.id() ) ) | ||
693 | return; | ||
694 | |||
695 | QPixmap pix = type.pixmap(); | ||
696 | QString dir; | ||
697 | QString name; | ||
698 | bool locked; | ||
699 | if( pix.isNull() ) { | ||
700 | //TODO make this scaled pixmap global, so we dont have to keep doing this | ||
701 | QWMatrix matrix; | ||
702 | QPixmap pixer(Resource::loadPixmap( "UnknownDocument" )); | ||
703 | matrix.scale( .4, .4); | ||
704 | pix = pixer.xForm(matrix); | ||
705 | // pix = Resource::loadPixmap( "UnknownDocument-14"); | ||
706 | } | ||
707 | dir = info->dirPath( true ); | ||
708 | if( symlink ) | ||
709 | name = info->fileName() + " -> " +info->dirPath() + "/" + info->readLink(); | ||
710 | else { | ||
711 | name = info->fileName(); | ||
712 | if( ( m_mode == OPEN && !info->isReadable() )|| | ||
713 | ( m_mode == SAVE && !info->isWritable() ) ){ | ||
714 | |||
715 | locked = true; pix = Resource::loadPixmap("locked"); | ||
716 | } | ||
717 | } | ||
718 | new OFileSelectorItem( m_View, pix, name, | ||
719 | info->lastModified().toString(), | ||
720 | QString::number( info->size() ), | ||
721 | dir, locked ); | ||
722 | } | ||
723 | void OFileSelector::addDir(const QString &/*mime*/, QFileInfo *info, bool symlink ) | ||
724 | { | ||
725 | if(!m_dir) | ||
726 | return; | ||
727 | if( m_selector == EXTENDED_ALL || m_selector == EXTENDED ){ | ||
728 | bool locked = false; | ||
729 | QString name; | ||
730 | QPixmap pix; | ||
731 | if( ( m_mode == OPEN && !info->isReadable() ) || ( m_mode == SAVE && !info->isWritable() ) ){ | ||
732 | locked = true; | ||
733 | if( symlink ) | ||
734 | pix = (*m_pixmaps)["symlinkedlocked"]; | ||
735 | else | ||
736 | pix = Resource::loadPixmap("lockedfolder"); | ||
737 | }else { // readable | ||
738 | pix = symlink ? (*m_pixmaps)["dirsymlink"] : Resource::loadPixmap("folder") ; | ||
739 | } | ||
740 | name = symlink ? info->fileName() + "->" + info->dirPath(true) + "/" +info->readLink() : info->fileName() ; | ||
741 | new OFileSelectorItem( m_View, pix, name, | ||
742 | info->lastModified().toString(), | ||
743 | QString::number( info->size() ), | ||
744 | info->dirPath( true ), locked, | ||
745 | true ); | ||
746 | |||
747 | }// else CUSTOM View | ||
748 | } | ||
749 | void OFileSelector::delItems() | ||
750 | { | ||
751 | |||
752 | } | ||
753 | void OFileSelector::initializeName() | ||
754 | { | ||
755 | /** Name Layout Line | ||
756 | * This is the Layout line arranged in | ||
757 | * horizontal way each components | ||
758 | * are next to each other | ||
759 | * but we will only do this if | ||
760 | * we didn't initialize a while ago. | ||
761 | */ | ||
762 | if( m_boxName == 0 ){ | ||
763 | m_boxName = new QHBox( this ); // remove this this? or use a QHBox | ||
764 | m_fnLabel = new QLabel( m_boxName ); | ||
765 | m_fnLabel->setText( tr("Name:") ); | ||
766 | m_edit = new QLineEdit( m_boxName ); | ||
767 | m_edit->setText( m_name ); | ||
768 | //m_boxName->addWidget( m_fnLabel ); | ||
769 | m_boxName->setMargin( 5 ); | ||
770 | m_boxName->setSpacing( 8 ); | ||
771 | //m_boxName->setStretchFactor(m_edit, 100 ); // 100 is stretch factor | ||
772 | |||
773 | m_lay->addWidget( m_boxName, 0 ); // add it to the topLevel layout | ||
774 | }// else we already initialized | ||
775 | // maybe show the components? | ||
776 | // | ||
777 | } | ||
778 | void OFileSelector::initializeYes() | ||
779 | { | ||
780 | /** The Save Cancel bar | ||
781 | * | ||
782 | */ | ||
783 | if( m_boxOk == 0 ){ | ||
784 | m_boxOk = new QHBox( this ); | ||
785 | m_ok = new QPushButton( tr("&Save"),m_boxOk , "save" ); | ||
786 | m_cancel = new QPushButton( tr("C&ancel"), m_boxOk, "cancel" ); | ||
787 | |||
788 | //m_boxOk->addWidget( m_ok ); | ||
789 | //m_boxOk->addWidget( m_cancel ); | ||
790 | m_boxOk->setMargin( 5 ); | ||
791 | m_boxOk->setSpacing( 10 ); | ||
792 | m_lay->addWidget( m_boxOk, 0 ); | ||
793 | |||
794 | connect( m_ok, SIGNAL( clicked() ), | ||
795 | this, SLOT(slotOk() ) ); | ||
796 | connect( m_cancel, SIGNAL( clicked() ), | ||
797 | this, SLOT( slotCancel() ) ); | ||
798 | } | ||
799 | } | ||
800 | /* | ||
801 | * OK m_mimeCheck is a QComboBox we now want to fill | ||
802 | * out that combobox | ||
803 | * if automime we need to update the mimetypes | ||
804 | */ | ||
805 | void OFileSelector::updateMimeCheck() { | ||
806 | m_mimeCheck->clear(); | ||
807 | if (m_autoMime ) { | ||
808 | //m_mimeCheck->insertItem( tr("All") ); | ||
809 | updateMimes(); | ||
810 | } | ||
811 | |||
812 | QMap<QString, QStringList>::Iterator it; | ||
813 | for (it = m_mimetypes.begin(); it != m_mimetypes.end(); ++it ) { | ||
814 | m_mimeCheck->insertItem( it.key() ); | ||
815 | } | ||
816 | } | ||
817 | |||
818 | void OFileSelector::initializeChooser() | ||
819 | { | ||
820 | if( m_boxView == 0 ){ | ||
821 | m_boxView = new QHBox( this ); | ||
822 | m_viewCheck = new QComboBox( m_boxView, "view check"); | ||
823 | m_mimeCheck = new QComboBox( m_boxView, "mime check"); | ||
824 | m_boxView->setSpacing( 8 ); | ||
825 | m_lay->addWidget(m_boxView, 0 ); | ||
826 | |||
827 | m_viewCheck->insertItem( tr("Documents") ); | ||
828 | m_viewCheck->insertItem( tr("Files") ); | ||
829 | m_viewCheck->insertItem( tr("All Files") ); | ||
830 | updateMimeCheck(); | ||
831 | |||
832 | connect( m_viewCheck, SIGNAL( activated(const QString & ) ), | ||
833 | this, SLOT( slotViewCheck(const QString & ) ) ); | ||
834 | connect( m_mimeCheck, SIGNAL( activated(const QString & ) ), | ||
835 | this, SLOT( slotMimeCheck( const QString & ) ) ); | ||
836 | } | ||
837 | } | ||
838 | void OFileSelector::initializeListView() | ||
839 | { | ||
840 | qWarning("initializeListView"); | ||
841 | if( m_pseudo == 0 ){ | ||
842 | qWarning("init"); | ||
843 | m_pseudo = new QWidget( m_stack, "Pseudo Widget"); | ||
844 | m_pseudoLayout = new QVBoxLayout( m_pseudo ); | ||
845 | // toolbar | ||
846 | m_boxToolbar = new QHBox( m_pseudo ); | ||
847 | m_boxToolbar->setSpacing(0 ); // next to each other please | ||
848 | |||
849 | // toolbar members | ||
850 | { | ||
851 | // location QComboBox | ||
852 | m_location = new QComboBox( m_boxToolbar ); | ||
853 | m_location->setEditable( TRUE ); | ||
854 | m_location->setDuplicatesEnabled( FALSE ); | ||
855 | connect( m_location, SIGNAL(activated(const QString &) ), | ||
856 | this, SLOT( slotLocationActivated(const QString &) ) ); | ||
857 | connect( m_location->lineEdit(), SIGNAL(returnPressed() ), | ||
858 | this, SLOT(locationComboChanged() ) ); | ||
859 | // UP Button | ||
860 | m_up = new QPushButton(Resource::loadIconSet("up"),"", | ||
861 | m_boxToolbar,"cdUpButton"); | ||
862 | m_up->setFixedSize( QSize( 20, 20 ) ); | ||
863 | connect(m_up ,SIGNAL(clicked()),this,SLOT(cdUP() ) ); | ||
864 | m_up->setFlat(TRUE); | ||
865 | |||
866 | // Home Button | ||
867 | m_homeButton = new QPushButton(Resource::loadIconSet("home") , | ||
868 | "", m_boxToolbar); | ||
869 | m_homeButton->setFixedSize( QSize( 20, 20 ) ); | ||
870 | connect(m_homeButton,SIGNAL(clicked()),this,SLOT(slotHome() ) ); | ||
871 | m_homeButton->setFlat(TRUE); | ||
872 | // Documents Button | ||
873 | m_docButton = new QPushButton(Resource::loadIconSet("DocsIcon"),"", | ||
874 | m_boxToolbar,"docsButton"); | ||
875 | m_docButton->setFixedSize( QSize( 20, 20 ) ); | ||
876 | connect(m_homeButton,SIGNAL(clicked()),this,SLOT(slotDoc() ) ); | ||
877 | m_docButton->setFlat(TRUE); | ||
878 | |||
879 | // Close button | ||
880 | m_close = new QPushButton( Resource::loadIconSet( "close"), "", | ||
881 | m_boxToolbar ); | ||
882 | connect( m_close, SIGNAL(clicked() ), this, SIGNAL(closeMe() ) ); | ||
883 | m_close->setFixedSize( 20, 20 ); | ||
884 | |||
885 | m_boxToolbar->setFixedHeight( 20 ); | ||
886 | m_pseudoLayout->addWidget(m_boxToolbar ); | ||
887 | |||
888 | // let;s fill the Location ComboBox | ||
889 | StorageInfo storage; | ||
890 | const QList<FileSystem> &fs = storage.fileSystems(); | ||
891 | QListIterator<FileSystem> it ( fs ); | ||
892 | for( ; it.current(); ++it ){ | ||
893 | const QString disk = (*it)->name(); | ||
894 | const QString path = (*it)->path(); | ||
895 | m_location->insertItem(path+ "<-"+disk ); | ||
896 | } | ||
897 | int count = m_location->count(); | ||
898 | m_location->insertItem( m_currentDir ); | ||
899 | m_location->setCurrentItem( count ); | ||
900 | // due to the New and Close button we can not simply hide m_boxToolBar to not show it | ||
901 | if( !m_shTool ){ | ||
902 | m_location->hide( ); | ||
903 | m_up->hide( ); | ||
904 | m_homeButton->hide( ); | ||
905 | m_docButton->hide( ); | ||
906 | } | ||
907 | if(!m_shClose ) | ||
908 | m_close->hide(); | ||
909 | //if(!m_shNew) | ||
910 | //m_close->hide(); | ||
911 | |||
912 | } // off toolbar | ||
913 | // the Main ListView | ||
914 | // make a QWidgetStack first so Views can share the Toolbar | ||
915 | m_View = new QListView( m_pseudo, "Extended view"); | ||
916 | QPEApplication::setStylusOperation( m_View->viewport(), | ||
917 | QPEApplication::RightOnHold); | ||
918 | m_View->addColumn(" " ); | ||
919 | m_View->addColumn(tr("Name"), 135 ); | ||
920 | m_View->addColumn(tr("Size"), -1 ); | ||
921 | m_View->addColumn(tr("Date"), 60 ); | ||
922 | m_View->addColumn(tr("Mime Type"), -1 ); | ||
923 | QHeader *header = m_View->header(); | ||
924 | header->hide(); | ||
925 | m_View->setSorting( 1 ); | ||
926 | m_View->setAllColumnsShowFocus( TRUE ); | ||
927 | |||
928 | connect(m_View, SIGNAL(selectionChanged() ), | ||
929 | this, SLOT(slotSelectionChanged() ) ); | ||
930 | |||
931 | connect(m_View, SIGNAL(clicked(QListViewItem *) ), | ||
932 | // connect(m_View, SIGNAL(currentChanged(QListViewItem *) ), | ||
933 | this, SLOT(slotCurrentChanged(QListViewItem * ) ) ); | ||
934 | |||
935 | connect(m_View, SIGNAL(mouseButtonClicked(int, QListViewItem*, const QPoint &, int) ), | ||
936 | this, SLOT(slotClicked( int, QListViewItem *, const QPoint &, int) ) ); | ||
937 | |||
938 | connect(m_View, SIGNAL(mouseButtonPressed(int, QListViewItem *, const QPoint &, int )), | ||
939 | this, SLOT(slotRightButton(int, QListViewItem *, const QPoint &, int ) ) ); | ||
940 | |||
941 | m_pseudoLayout->addWidget( m_View, 288 ); | ||
942 | m_stack->addWidget( m_pseudo, EXTENDED ); | ||
943 | } | ||
944 | } | ||
945 | void OFileSelector::initializePerm() | ||
946 | { | ||
947 | if( m_checkPerm == 0 ){ | ||
948 | m_checkPerm = new QCheckBox(tr("Ser Permission"), this, "perm"); | ||
949 | m_checkPerm->setChecked( false ); | ||
950 | m_lay->addWidget( m_checkPerm ); | ||
951 | |||
952 | } | ||
953 | } | ||
954 | void OFileSelector::initPics() | ||
955 | { | ||
956 | m_pixmaps = new QMap<QString,QPixmap>; | ||
957 | QPixmap pm = Resource::loadPixmap( "folder" ); | ||
958 | QPixmap lnk = Resource::loadPixmap( "opie/symlink" ); | ||
959 | QPainter painter( &pm ); | ||
960 | painter.drawPixmap( pm.width()-lnk.width(), pm.height()-lnk.height(), lnk ); | ||
961 | pm.setMask( pm.createHeuristicMask( FALSE ) ); | ||
962 | m_pixmaps->insert("dirsymlink", pm ); | ||
963 | |||
964 | QPixmap pm2 = Resource::loadPixmap( "lockedfolder" ); | ||
965 | QPainter pen(&pm2 ); | ||
966 | pen.drawPixmap(pm2.width()-lnk.width(), pm2.height()-lnk.height(), lnk ); | ||
967 | pm2.setMask( pm2.createHeuristicMask( FALSE ) ); | ||
968 | m_pixmaps->insert("symlinkedlocked", pm2 ); | ||
969 | } | ||
970 | // if a mime complies with the m_mimeCheck->currentItem | ||
971 | bool OFileSelector::compliesMime( const QString &path, const QString &mime ) | ||
972 | { | ||
973 | if( mime == "All" ) | ||
974 | return true; | ||
975 | MimeType type( path ); | ||
976 | if( type.id() == mime ) | ||
977 | return true; | ||
978 | return false; | ||
979 | } | ||
980 | /* check if the mimetype in mime | ||
981 | * complies with the one which is current | ||
982 | */ | ||
983 | /* | ||
984 | * We've the mimetype of the file | ||
985 | * We need to get the stringlist of the current mimetype | ||
986 | * | ||
987 | * mime = image/jpeg | ||
988 | * QStringList = 'image/*' | ||
989 | * or QStringList = image/jpeg;image/png;application/x-ogg | ||
990 | * or QStringList = application/x-ogg;image/*; | ||
991 | * with all these mime filters it should get acceptes | ||
992 | * to do so we need to look if mime is contained inside | ||
993 | * the stringlist | ||
994 | * if it's contained return true | ||
995 | * if not ( I'm no RegExp expert at all ) we'll look if a '/*' | ||
996 | * is contained in the mimefilter and then we will | ||
997 | * look if both are equal until the '/' | ||
998 | */ | ||
999 | bool OFileSelector::compliesMime( const QString& mime ) { | ||
1000 | qWarning("mimetype is %s", mime.latin1() ); | ||
1001 | QString currentText; | ||
1002 | if (m_shChooser ) | ||
1003 | currentText = m_mimeCheck->currentText(); | ||
1004 | |||
1005 | qWarning("current text is %s", currentText.latin1() ); | ||
1006 | QMap<QString, QStringList>::Iterator it; | ||
1007 | QStringList list; | ||
1008 | if ( currentText == tr("All") ) return true; | ||
1009 | else if ( currentText.isEmpty() && !m_mimetypes.isEmpty() ) { | ||
1010 | it = m_mimetypes.begin(); | ||
1011 | list = it.data(); | ||
1012 | }else if ( currentText.isEmpty() ) return true; | ||
1013 | else{ | ||
1014 | it = m_mimetypes.find(currentText ); | ||
1015 | if ( it == m_mimetypes.end() ) qWarning("not there"), list << currentText; | ||
1016 | else qWarning("found"), list = it.data(); | ||
1017 | } | ||
1018 | // dump it now | ||
1019 | //for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { | ||
1020 | // qWarning( "%s", (*it).latin1() ); | ||
1021 | //} | ||
1022 | |||
1023 | |||
1024 | if ( list.contains(mime) ) return true; | ||
1025 | qWarning("list doesn't contain it "); | ||
1026 | QStringList::Iterator it2; | ||
1027 | int pos; | ||
1028 | for ( it2 = list.begin(); it2 != list.end(); ++it2 ) { | ||
1029 | pos = (*it2).findRev("/*"); | ||
1030 | if ( pos >= 0 ) { | ||
1031 | if ( mime.contains( (*it2).left(pos) ) ) return true; | ||
1032 | } | ||
1033 | } | ||
1034 | return false; | ||
1035 | } | ||
1036 | void OFileSelector::slotFileSelected( const QString &string ) | ||
1037 | { | ||
1038 | if( m_shLne ) | ||
1039 | m_edit->setText( string ); | ||
1040 | emit fileSelected( string ); | ||
1041 | } | ||
1042 | void OFileSelector::slotFileBridgeSelected( const DocLnk &lnk ) | ||
1043 | { | ||
1044 | slotFileSelected( lnk.name() ); | ||
1045 | emit fileSelected( lnk ); | ||
1046 | } | ||
1047 | void OFileSelector::slotSelectionChanged() | ||
1048 | { | ||
1049 | |||
1050 | } | ||
1051 | void OFileSelector::slotCurrentChanged(QListViewItem* item ) | ||
1052 | { | ||
1053 | if( item == 0 ) | ||
1054 | return; | ||
1055 | if( m_selector == EXTENDED || m_selector == EXTENDED_ALL ) { | ||
1056 | OFileSelectorItem *sel = (OFileSelectorItem*) item; // start to use the C++ casts ;) | ||
1057 | qWarning("current changed"); | ||
1058 | if(!sel->isDir() ){ | ||
1059 | if( m_shLne ) | ||
1060 | m_edit->setText( sel->text(1) ); | ||
1061 | |||
1062 | if (m_mode == FILESELECTOR ) { | ||
1063 | QStringList str = QStringList::split("->", sel->text(1) ); | ||
1064 | QString path =sel->directory() + "/" + str[0].stripWhiteSpace(); | ||
1065 | emit fileSelected(path ); | ||
1066 | DocLnk lnk( path ); | ||
1067 | emit fileSelected(lnk ); | ||
1068 | } | ||
1069 | } | ||
1070 | } | ||
1071 | } | ||
1072 | void OFileSelector::slotClicked( int button, QListViewItem *item, const QPoint &, int) | ||
1073 | { | ||
1074 | if ( item == 0 ) | ||
1075 | return; | ||
1076 | |||
1077 | if( button != Qt::LeftButton ) | ||
1078 | return; | ||
1079 | |||
1080 | switch( m_selector ){ | ||
1081 | default: | ||
1082 | break; | ||
1083 | case EXTENDED: // fall through | ||
1084 | case EXTENDED_ALL:{ | ||
1085 | OFileSelectorItem *sel = (OFileSelectorItem*)item; | ||
1086 | if(!sel->isLocked() ){ | ||
1087 | QStringList str = QStringList::split("->", sel->text(1) ); | ||
1088 | if( sel->isDir() ){ | ||
1089 | cd( sel->directory() + "/" + str[0].stripWhiteSpace() ); | ||
1090 | // if MODE Dir m_shLne set the Text | ||
1091 | }else{ | ||
1092 | if( m_shLne ) | ||
1093 | m_edit->setText( str[0].stripWhiteSpace() ); | ||
1094 | qWarning("selected here in slot clicked"); | ||
1095 | emit fileSelected( sel->directory() + "/" + str[0].stripWhiteSpace() ); | ||
1096 | DocLnk lnk( sel->directory() + "/" + str[0].stripWhiteSpace() ); | ||
1097 | qWarning("file selected"); | ||
1098 | emit fileSelected( lnk ); | ||
1099 | } | ||
1100 | } | ||
1101 | break; | ||
1102 | } | ||
1103 | } | ||
1104 | } | ||
1105 | void OFileSelector::slotRightButton(int button, QListViewItem *item, const QPoint &, int ) | ||
1106 | { | ||
1107 | if( item == 0 ) | ||
1108 | return; | ||
1109 | |||
1110 | if( button != Qt::RightButton ) | ||
1111 | return; | ||
1112 | slotContextMenu( item ); | ||
1113 | } | ||
1114 | void OFileSelector::slotContextMenu( QListViewItem * /*item*/) | ||
1115 | { | ||
1116 | |||
1117 | } | ||
1118 | void OFileSelector::slotChangedDir() | ||
1119 | { | ||
1120 | OFileSelectorItem *sel = (OFileSelectorItem*)m_View->currentItem(); | ||
1121 | if(sel->isDir() ){ | ||
1122 | QStringList str = QStringList::split("->", sel->text(1) ); | ||
1123 | cd( sel->directory() + "/" + str[0].stripWhiteSpace() ); | ||
1124 | } | ||
1125 | } | ||
1126 | void OFileSelector::slotOpen() | ||
1127 | { | ||
1128 | OFileSelectorItem *sel = (OFileSelectorItem*)m_View->currentItem(); | ||
1129 | if(!sel->isDir() ){ | ||
1130 | QStringList str = QStringList::split("->", sel->text(1) ); | ||
1131 | slotFileSelected( sel->directory() +"/" +str[0].stripWhiteSpace() ); | ||
1132 | qWarning("slot open"); | ||
1133 | // DocLnk lnk( sel->directory() + "/" + str[0].stripWhiteSpace() ); | ||
1134 | //emit fileSelected( lnk ); | ||
1135 | } | ||
1136 | } | ||
1137 | void OFileSelector::slotRescan() | ||
1138 | { | ||
1139 | |||
1140 | } | ||
1141 | void OFileSelector::slotRename() | ||
1142 | { | ||
1143 | reparse(); | ||
1144 | } | ||
1145 | void OFileSelector::slotDelete() | ||
1146 | { | ||
1147 | OFileSelectorItem *sel = (OFileSelectorItem*)m_View->currentItem(); | ||
1148 | QStringList list = QStringList::split("->", sel->text(1) ); | ||
1149 | if( sel->isDir() ){ | ||
1150 | QString str = QString::fromLatin1("rm -rf ") + sel->directory() +"/" + list[0]; //better safe than sorry | ||
1151 | switch ( QMessageBox::warning(this,tr("Delete"),tr("Do you really want to delete\n")+list[0], | ||
1152 | tr("Yes"),tr("No"),0,1,1) ) { | ||
1153 | case 0: | ||
1154 | ::system(str.utf8().data() ); | ||
1155 | break; | ||
1156 | } | ||
1157 | } else { | ||
1158 | QFile::remove( list[0] ); | ||
1159 | } | ||
1160 | m_View->takeItem( sel ); | ||
1161 | delete sel; | ||
1162 | } | ||
1163 | void OFileSelector::cdUP() | ||
1164 | { | ||
1165 | QDir dir( m_currentDir ); | ||
1166 | dir.cdUp(); | ||
1167 | if(dir.exists() ){ | ||
1168 | m_currentDir = dir.absPath(); | ||
1169 | reparse(); | ||
1170 | int count = m_location->count(); | ||
1171 | slotInsertLocationPath( m_currentDir, count); | ||
1172 | m_location->setCurrentItem( indexByString( m_location, m_currentDir)); | ||
1173 | //this wont work in all instances | ||
1174 | // FIXME | ||
1175 | } | ||
1176 | } | ||
1177 | void OFileSelector::slotHome() | ||
1178 | { | ||
1179 | cd(QDir::homeDirPath() ); | ||
1180 | } | ||
1181 | void OFileSelector::slotDoc() | ||
1182 | { | ||
1183 | cd(QPEApplication::documentDir() ); | ||
1184 | } | ||
1185 | void OFileSelector::slotNavigate( ) | ||
1186 | { | ||
1187 | |||
1188 | } | ||
1189 | // fill the View with life | ||
1190 | void OFileSelector::reparse() | ||
1191 | { | ||
1192 | if( m_selector == NORMAL ) | ||
1193 | return; | ||
1194 | if( m_selector == EXTENDED || m_selector == EXTENDED_ALL ) | ||
1195 | m_View->clear(); | ||
1196 | else // custom view | ||
1197 | ; // currentView()->clear(); | ||
1198 | if( m_shChooser) | ||
1199 | qWarning("reparse %s", m_mimeCheck->currentText().latin1() ); | ||
1200 | |||
1201 | QString currentMimeType; | ||
1202 | // let's update the mimetype | ||
1203 | if( m_autoMime ){ | ||
1204 | m_mimetypes.clear(); | ||
1205 | // ok we can change mimetype so we need to be able to give a selection | ||
1206 | if( m_shChooser ) { | ||
1207 | currentMimeType = m_mimeCheck->currentText(); | ||
1208 | m_mimeCheck->clear(); | ||
1209 | |||
1210 | // let's find possible mimetypes | ||
1211 | QDir dir( m_currentDir ); | ||
1212 | if( dir.exists() ){ | ||
1213 | dir.setFilter( QDir::Files | QDir::Readable ); | ||
1214 | dir.setSorting( QDir::Size ); | ||
1215 | const QFileInfoList *list = dir.entryInfoList(); | ||
1216 | QFileInfoListIterator it( *list ); | ||
1217 | QFileInfo *fi; | ||
1218 | while( (fi=it.current() ) ) { | ||
1219 | if( fi->extension() == QString::fromLatin1("desktop") ){ | ||
1220 | ++it; | ||
1221 | continue; | ||
1222 | } | ||
1223 | MimeType type( fi->absFilePath() ); | ||
1224 | if( !m_mimetypes.contains( type.id() ) ){ | ||
1225 | //qWarning("Type %s", type.id().latin1() ); | ||
1226 | m_mimetypes.insert( type.id(), type.id() ); | ||
1227 | } | ||
1228 | |||
1229 | ++it; | ||
1230 | } | ||
1231 | // add them to the chooser | ||
1232 | updateMimeCheck(); | ||
1233 | m_mimeCheck->setCurrentItem( indexByString( m_mimeCheck, currentMimeType ) ); | ||
1234 | currentMimeType = m_mimeCheck->currentText(); | ||
1235 | } | ||
1236 | } | ||
1237 | }else { // no autoMime | ||
1238 | // let the mimetype be set from out side the m_mimeCheck FEATURE | ||
1239 | |||
1240 | if( m_shChooser ){ | ||
1241 | currentMimeType = m_mimeCheck->currentText(); | ||
1242 | // updateMimeCheck(); | ||
1243 | } | ||
1244 | } | ||
1245 | // now we got our mimetypes we can add the files | ||
1246 | |||
1247 | QDir dir( m_currentDir ); | ||
1248 | |||
1249 | if( dir.exists() ){ | ||
1250 | int sort; | ||
1251 | if ( m_case ) | ||
1252 | sort = (QDir::IgnoreCase | QDir::Name | QDir::DirsFirst | QDir::Reversed); | ||
1253 | else | ||
1254 | sort = (QDir::Name | QDir::DirsFirst | QDir::Reversed); | ||
1255 | dir.setSorting( sort ); | ||
1256 | |||
1257 | int filter; | ||
1258 | if( m_selector == EXTENDED_ALL /*|| m_selector ==CUSTOM_ALL */ ){ | ||
1259 | filter = QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All; | ||
1260 | }else | ||
1261 | filter = QDir::Files | QDir::Dirs | QDir::All; | ||
1262 | dir.setFilter( filter ); | ||
1263 | |||
1264 | // now go through all files | ||
1265 | const QFileInfoList *list = dir.entryInfoList(); | ||
1266 | QFileInfoListIterator it( *list ); | ||
1267 | QFileInfo *fi; | ||
1268 | while( (fi=it.current() ) ){ | ||
1269 | //qWarning("True and only" ); | ||
1270 | if( fi->fileName() == QString::fromLatin1("..") || fi->fileName() == QString::fromLatin1(".") ){ | ||
1271 | //qWarning(".. or ." ); | ||
1272 | ++it; | ||
1273 | continue; | ||
1274 | } | ||
1275 | if( fi->isSymLink() ){ | ||
1276 | QString file = fi->dirPath( true ) + "/" + fi->readLink(); | ||
1277 | for( int i = 0; i<=4; i++) { // 5 tries to prevent dos | ||
1278 | QFileInfo info( file ); | ||
1279 | if( !info.exists() ){ | ||
1280 | addSymlink( currentMimeType, fi, TRUE ); | ||
1281 | break; | ||
1282 | }else if( info.isDir() ){ | ||
1283 | addDir( currentMimeType, fi, TRUE ); | ||
1284 | break; | ||
1285 | }else if( info.isFile() ){ | ||
1286 | addFile( currentMimeType, fi, TRUE ); | ||
1287 | break; | ||
1288 | }else if( info.isSymLink() ){ | ||
1289 | file = info.dirPath(true ) + "/" + info.readLink() ; | ||
1290 | break; | ||
1291 | }else if( i == 4){ | ||
1292 | addSymlink( currentMimeType, fi ); | ||
1293 | } | ||
1294 | } // off for loop | ||
1295 | }else if( fi->isDir() ){ | ||
1296 | addDir( currentMimeType, fi ); | ||
1297 | }else if( fi->isFile() ){ | ||
1298 | addFile( currentMimeType, fi ); | ||
1299 | } | ||
1300 | //qWarning( "%s", fi->fileName().latin1() ); | ||
1301 | ++it; | ||
1302 | } // of while loop | ||
1303 | } // if ( dir.exists() ) | ||
1304 | m_View->sort(); | ||
1305 | if( m_shTool ){ | ||
1306 | m_location->insertItem( m_currentDir ); | ||
1307 | |||
1308 | } | ||
1309 | // reenable painting and updates | ||
1310 | } | ||