summaryrefslogtreecommitdiff
path: root/libopie/ofileselector/ofileselector.cpp
Unidiff
Diffstat (limited to 'libopie/ofileselector/ofileselector.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/ofileselector/ofileselector.cpp1095
1 files changed, 0 insertions, 1095 deletions
diff --git a/libopie/ofileselector/ofileselector.cpp b/libopie/ofileselector/ofileselector.cpp
deleted file mode 100644
index abc2889..0000000
--- a/libopie/ofileselector/ofileselector.cpp
+++ b/dev/null
@@ -1,1095 +0,0 @@
1
2
3#include <qcheckbox.h>
4#include <qcombobox.h>
5#include <qheader.h>
6#include <qlabel.h>
7#include <qabstractlayout.h>
8#include <qlayout.h>
9#include <qlineedit.h>
10#include <qlistview.h>
11#include <qmessagebox.h>
12#include <qpainter.h>
13#include <qpushbutton.h>
14#include <qwidgetstack.h>
15#include <qpopupmenu.h>
16#include <qdir.h>
17#include <qfile.h>
18#include <qfileinfo.h>
19#include <qtimer.h>
20
21#include <qpe/qpeapplication.h>
22#include <qpe/applnk.h>
23#include <qpe/global.h>
24#include <qpe/mimetype.h>
25#include <qpe/resource.h>
26#include <qpe/storage.h>
27
28#include <unistd.h>
29#include <stdlib.h>
30#include <sys/stat.h>
31
32#include "ofileview.h"
33#include "ofileselectormain.h"
34#include "ofileselector.h"
35#include "olocallister.h"
36#include "olister.h"
37#include "odefaultfactories.h"
38
39QMap<QString,QPixmap> *OFileSelector::m_pixmaps = 0;
40
41namespace {
42 /* let's find the index for a specified string */
43 int indexByString( const QComboBox *box, const QString &str ){
44 int index= 0;
45 for(int i= 0; i < box->count(); i++ ){
46 /* found */
47 if( str == box->text(i ) ){
48 index= i;
49 break;
50 }
51 }
52 return index;
53 }
54}
55
56OFileSelector::OFileSelector( QWidget *wid, int mode, int selector,
57 const QString &dirName,
58 const QString &fileName,
59 const QMap<QString,QStringList>& mimeTypes)
60 : QWidget( wid, "OFileSelector")
61{
62 m_mimetypes = mimeTypes;
63 if (mode == Save )
64 m_name = fileName;
65
66 initVars();
67
68 m_mode = mode;
69 m_selector = selector;
70 m_currentDir = dirName;
71 init();
72}
73
74OFileSelector::OFileSelector(const QString &mimeFilter, QWidget *parent,
75 const char *name, bool newVisible,
76 bool closeVisible )
77 : QWidget( parent, name )
78{
79 /* update the mimefilter */
80 if (!mimeFilter.isEmpty() ) {
81 QStringList list = QStringList::split(";", mimeFilter );
82 m_mimetypes.insert(mimeFilter, list );
83 }
84 initVars();
85 m_currentDir = QPEApplication::documentDir();
86 m_mode = Fileselector;
87 m_selector = Normal;
88 m_shClose = closeVisible;
89 m_shNew = newVisible;
90 m_shLne = false;
91 m_shPerm = false;
92 m_shYesNo = false;
93 init();
94
95
96}
97
98OFileSelector::~OFileSelector()
99{
100
101
102}
103
104void OFileSelector::setNewVisible( bool visible )
105{
106 m_shNew = visible;
107 if (m_new )
108 m_new->show();
109}
110void OFileSelector::setCloseVisible( bool visible )
111{
112 m_shClose = visible;
113
114 if( m_close )
115 m_close->show();
116}
117void OFileSelector::reread()
118{
119 if( m_selector == Normal )
120 initializeOldSelector();
121 else
122 reparse();
123}
124
125const DocLnk *OFileSelector::selected()
126{
127 DocLnk *lnk = new DocLnk(selectedDocument() );
128 return lnk;
129}
130
131void OFileSelector::setYesCancelVisible( bool show )
132{
133 initializeYes(); // FIXME if YesCancel is not shown we will initialize it to hide it :(
134 m_shYesNo = show;
135
136 if( m_shYesNo )
137 m_boxOk->show();
138 else
139 m_boxOk->hide();
140
141}
142void OFileSelector::setToolbarVisible( bool show )
143{
144 m_shTool = show;
145
146 if(!m_shTool ){
147 m_location->hide();
148 m_up->hide();
149 m_homeButton->hide();
150 m_docButton->hide();
151 }else{
152 m_location->show();
153 m_up->show();
154 m_homeButton->show();
155 m_docButton->show();
156 }
157}
158void OFileSelector::setPermissionBarVisible( bool show )
159{
160 m_shPerm = show;
161 initializePerm();
162
163 if( m_shPerm )
164 m_checkPerm->show();
165 else
166 m_checkPerm->hide();
167}
168void OFileSelector::setLineEditVisible( bool show )
169{
170 if( show ){
171 initializeName();
172 m_boxName->show();
173 }else{
174 // check if we showed before this is the way to go
175 if( m_shLne && m_boxName != 0 )
176 m_boxName->hide();
177 }
178 m_shLne = show;
179}
180
181void OFileSelector::setChooserVisible( bool show )
182{
183 m_shChooser = show;
184 initializeChooser();
185
186 if( m_shChooser )
187 m_boxView->hide();
188 else
189 m_boxView->show();
190
191}
192
193QCheckBox* OFileSelector::permissionCheckbox()
194{
195 if( m_selector == Normal )
196 return 0l;
197 else
198 return m_checkPerm;
199}
200bool OFileSelector::setPermission()const
201{
202 return m_checkPerm == 0 ? false : m_checkPerm->isChecked();
203}
204void OFileSelector::setPermissionChecked( bool check )
205{
206 if( m_checkPerm )
207 m_checkPerm->setChecked( check );
208}
209
210void OFileSelector::setMode(int mode) // FIXME do direct raising
211{
212 m_mode = mode;
213 if( m_selector == Normal )
214 return;
215}
216void OFileSelector::setShowDirs(bool dir)
217{
218 m_dir = dir;
219 if ( m_selector != Fileselector )
220 reparse();
221}
222void OFileSelector::setCaseSensetive(bool caSe )
223{
224 m_case = caSe;
225
226 if ( m_selector != Fileselector )
227 reparse();
228}
229void OFileSelector::setShowFiles(bool show )
230{
231 m_files = show;
232 reparse();
233}
234///
235bool OFileSelector::cd(const QString &path )
236{
237 m_currentDir = path;
238 reparse();
239 return true;
240}
241void OFileSelector::setSelector(int mode )
242{
243 QString text;
244 switch( mode ){
245 case Normal:
246 text = tr("Documents");
247 break;
248 case Extended:
249 text = tr("List View");
250 break;
251 case ExtendedAll:
252 text = tr("All List View");
253 break;
254 }
255 slotViewCheck( text );
256}
257
258void OFileSelector::setPopupFactory(OPopupMenuFactory */*popup*/ )
259{
260/* m_custom = popup;
261 m_showPopup = true;
262*/
263}
264
265QString OFileSelector::selectedName() const
266{
267 QString name;
268 if( m_selector == Normal ){
269 DocLnk lnk = m_select->selectedDocument();
270 name = lnk.file();
271 }else {
272 name = currentLister()->selectedName();
273 }
274 return name;
275}
276QStringList OFileSelector::selectedNames()const
277{
278 QStringList list;
279 if( m_selector == Normal ){
280 list << selectedName();
281 }else {
282 list << selectedName(); // FIXME implement multiple Selections
283 }
284 return list;
285}
286/** If mode is set to the Dir selection this will return the selected path.
287 *
288 *
289 */
290QString OFileSelector::selectedPath()const
291{
292 QString path;
293 if( m_selector == Normal ){
294 path = QPEApplication::documentDir();
295 } /* normal case to do */
296 return path;
297}
298QStringList OFileSelector::selectedPaths() const
299{
300 QStringList list;
301 list << selectedPath();
302 return list;
303}
304QString OFileSelector::directory()const
305{
306 if( m_selector == Normal )
307 return QPEApplication::documentDir();
308
309 return QDir(m_currentDir).absPath();
310}
311
312int OFileSelector::fileCount()
313{
314 int count;
315 switch( m_selector ){
316 case Normal:
317 count = m_select->fileCount();
318 break;
319 case Extended:
320 case ExtendedAll:
321 default:
322 count = currentView()->fileCount();
323 break;
324 }
325 return count;
326}
327DocLnk OFileSelector::selectedDocument() const
328{
329 DocLnk lnk;
330 switch( m_selector ){
331 case Normal:{
332 lnk = m_select->selectedDocument();
333 break;
334 }
335 case Extended:
336 case ExtendedAll:
337 default:
338 lnk = DocLnk( selectedName() );
339 break;
340 }
341 return lnk;
342}
343QValueList<DocLnk> OFileSelector::selectedDocuments() const
344{
345 QValueList<DocLnk> docs;
346 docs.append( selectedDocument() );
347 return docs;
348}
349
350
351// slots internal
352
353void OFileSelector::slotOk()
354{
355 emit ok();
356}
357void OFileSelector::slotCancel()
358{
359 emit cancel();
360}
361/* switch the views */
362void OFileSelector::slotViewCheck(const QString &sel)
363{
364 setView( sel );
365}
366
367QString OFileSelector::currentMimeType() const{
368 QString mime;
369 QString currentText;
370 if (m_shChooser && m_mimeCheck )
371 currentText = m_mimeCheck->currentText();
372
373 qWarning("CurrentText" + currentText );
374 if (tr("All") == currentText ) return QString::null;
375 else if (currentText.isEmpty() ) {
376 ;
377 }else {
378 QMap<QString, QStringList>::ConstIterator it;
379 it = m_mimetypes.find( currentText );
380 if ( it != m_mimetypes.end() ) {
381 mime = it.data().join(";");
382 }else{
383 mime = currentText;
384 }
385 }
386 return mime;
387}
388void OFileSelector::slotMimeCheck(const QString &mime)
389{
390 if( m_selector == Normal ){
391 initializeOldSelector();
392
393 updateMimes();
394 updateMimeCheck();
395 m_mimeCheck->setCurrentItem(indexByString( m_mimeCheck, mime) );
396 }else{ // others
397 qWarning("Mime %s", mime.latin1() );
398 if(m_shChooser ){
399 qWarning("Current Text %s", m_mimeCheck->currentText().latin1() );
400 //m_mimeCheck->setCurrentItem(indexByString( m_mimeCheck, mime) );
401 }
402 reparse();
403 }
404}
405/*
406 * Ok if a non dir gets inserted into this combobox
407 * we need to change it
408 * QFileInfo and dirPath will give us the right Dir
409 */
410void OFileSelector::slotLocationActivated(const QString &file)
411{
412 qWarning("slotLocationActivated");
413 QString name = file.left( file.find("<-", 0, TRUE ) );
414 QFileInfo info( name );
415 if ( info.isFile() )
416 cd(info.dirPath( TRUE ) ); //absolute
417 else
418 cd(name );
419}
420void OFileSelector::slotInsertLocationPath(const QString &currentPath, int count)
421{
422 QStringList pathList;
423 bool underDog = FALSE;
424 for(int i=0;i<count;i++) {
425 pathList << m_location->text(i);
426 if( m_location->text(i) == currentPath)
427 underDog = TRUE;
428 }
429 if( !underDog) {
430 m_location->clear();
431 if( currentPath.left(2)=="//")
432 pathList.append( currentPath.right(currentPath.length()-1) );
433 else
434 pathList.append( currentPath );
435 m_location->insertStringList( pathList,-1);
436 }
437}
438/*
439 * Do not crash anymore
440 * don't try to change dir to a file
441 */
442void OFileSelector::locationComboChanged()
443{
444 QFileInfo info( m_location->lineEdit()->text() );
445 qWarning("info %s %s", info.dirPath(true).latin1(), m_location->lineEdit()->text().latin1() );
446 if (info.isFile() )
447 cd(info.dirPath(TRUE) ); //absolute path
448 else
449 cd( m_location->lineEdit()->text() );
450}
451void OFileSelector::init()
452{
453 initFactory();
454 m_lay = new QVBoxLayout( this );
455 m_lay->setSpacing(0 );
456
457 /* take care of the main view... */
458 initToolbar();
459 //if( m_shChooser ) // the Chooser for the view and Mimetypes
460 initializeChooser();
461
462 /* initialize the file lister */
463 if( m_selector == Normal ){
464 QString mime;
465 if (!m_autoMime) {
466 if (!m_mimetypes.isEmpty() ) {
467 QMap<QString, QStringList>::Iterator it;
468 it = m_mimetypes.begin(); // cause we're in the init
469 mime = it.data().join(";");
470 }
471 }
472 initializeOldSelector();
473 }else{
474 initializeView();
475 }
476
477 if( m_shLne ) // the LineEdit with the current FileName
478 initializeName();
479
480 if( m_shPerm ) // the Permission QCheckBox
481 initializePerm();
482
483 if( m_shYesNo ) // the Yes No button row
484 initializeYes( );
485
486 if (m_selector != Normal )
487 reparse();
488
489 showMaximized();
490}
491void OFileSelector::updateMimes()
492{
493 if( m_autoMime ){
494 m_mimetypes.clear();
495 m_mimetypes.insert( tr("All"), QString::null );
496 if( m_selector == Normal ){
497 DocLnkSet set;
498 Global::findDocuments(&set, QString::null );
499 QListIterator<DocLnk> dit( set.children() );
500 for( ; dit.current(); ++dit ){
501 if( !m_mimetypes.contains( (*dit)->type() ) )
502 m_mimetypes.insert( (*dit)->type(), (*dit)->type() );
503 }
504 }// else done in reparse
505 }
506}
507void OFileSelector::initVars()
508{
509 if( m_mimetypes.isEmpty() )
510 m_autoMime = true;
511 else
512 m_autoMime = false;
513
514 m_shClose = false;
515 m_shNew = false;
516 m_shTool = true;
517 m_shPerm = false;
518 m_shLne = true;
519 m_shChooser = true;
520 m_shYesNo = true;
521 m_case = false;
522 m_dir = true;
523 m_files = true;
524 m_showPopup = false;
525 m_mainView = 0l;
526 m_fileView = 0l;
527 m_lister = 0l;
528
529 if(m_pixmaps == 0 ) // init the pixmaps
530 initPics();
531
532 // pointers
533 m_location = 0;
534 m_mimeCheck = 0;
535 m_viewCheck = 0;
536 m_homeButton = 0;
537 m_docButton = 0;
538 m_hideButton = 0;
539 m_ok = 0;
540 m_cancel = 0;
541 m_reread = 0;
542 m_up = 0;
543 m_View = 0;
544 m_checkPerm = 0;
545 m_pseudo = 0;
546 m_pseudoLayout = 0;
547 m_select = 0;
548 m_lay = 0;
549 m_Oselector = 0;
550 m_boxToolbar = 0;
551 m_boxOk = 0;
552 m_boxName = 0;
553 m_boxView = 0;
554 m_edit = 0;
555 m_fnLabel = 0;
556 m_new = 0;
557 m_close = 0;
558}
559void OFileSelector::initializeName()
560{
561 /** Name Layout Line
562 * This is the Layout line arranged in
563 * horizontal way each components
564 * are next to each other
565 * but we will only do this if
566 * we didn't initialize a while ago.
567 */
568 if( m_boxName == 0 ){
569 m_boxName = new QHBox( this ); // remove this this? or use a QHBox
570 m_fnLabel = new QLabel( m_boxName );
571 m_fnLabel->setText( tr("Name:") );
572 m_edit = new QLineEdit( m_boxName );
573 m_edit->setText( m_name );
574 //m_boxName->addWidget( m_fnLabel );
575 m_boxName->setMargin( 5 );
576 m_boxName->setSpacing( 8 );
577 //m_boxName->setStretchFactor(m_edit, 100 ); // 100 is stretch factor
578
579 m_lay->addWidget( m_boxName, 0 ); // add it to the topLevel layout
580 }// else we already initialized
581 // maybe show the components?
582 //
583}
584void OFileSelector::initializeYes()
585{
586 /** The Save Cancel bar
587 *
588 */
589 if( m_boxOk == 0 ){
590 m_boxOk = new QHBox( this );
591 m_ok = new QPushButton( tr("&Save"),m_boxOk , "save" );
592 m_cancel = new QPushButton( tr("C&ancel"), m_boxOk, "cancel" );
593
594 //m_boxOk->addWidget( m_ok );
595 //m_boxOk->addWidget( m_cancel );
596 m_boxOk->setMargin( 5 );
597 m_boxOk->setSpacing( 10 );
598 m_lay->addWidget( m_boxOk, 0 );
599
600 connect( m_ok, SIGNAL( clicked() ),
601 this, SLOT(slotOk() ) );
602 connect( m_cancel, SIGNAL( clicked() ),
603 this, SLOT( slotCancel() ) );
604 }
605}
606/*
607 * OK m_mimeCheck is a QComboBox we now want to fill
608 * out that combobox
609 * if automime we need to update the mimetypes
610 */
611void OFileSelector::updateMimeCheck() {
612 m_mimeCheck->clear();
613 if (m_autoMime ) {
614 //m_mimeCheck->insertItem( tr("All") );
615 updateMimes();
616 }
617
618 QMap<QString, QStringList>::Iterator it;
619 for (it = m_mimetypes.begin(); it != m_mimetypes.end(); ++it ) {
620 m_mimeCheck->insertItem( it.key() );
621 }
622}
623
624void OFileSelector::initializeChooser()
625{
626 if( m_boxView == 0 ){
627 m_boxView = new QHBox( this );
628 m_viewCheck = new QComboBox( m_boxView, "view check");
629 m_mimeCheck = new QComboBox( m_boxView, "mime check");
630 m_boxView->setSpacing( 8 );
631 m_lay->addWidget(m_boxView, 0 );
632
633
634 updateMimeCheck();
635 fillList();
636
637 connect( m_viewCheck, SIGNAL( activated(const QString & ) ),
638 this, SLOT( slotViewCheck(const QString & ) ) );
639 connect( m_mimeCheck, SIGNAL( activated(const QString & ) ),
640 this, SLOT( slotMimeCheck( const QString & ) ) );
641 }
642}
643/* generate the buttons for the toolbar */
644void OFileSelector::initToolbar() {
645 m_mainView = new OFileSelectorMain( this );
646
647 /* now generate the tool bar */
648 qWarning( "toolbar" );
649 m_pseudo = new QWidget( m_mainView, "Pseudo Widget" );
650 m_pseudoLayout = new QVBoxLayout( m_pseudo );
651
652 m_boxToolbar = new QHBox( m_pseudo );
653 m_boxToolbar->setSpacing( 0 );
654
655 // tool bar members now
656 m_location = new QComboBox( m_boxToolbar );
657 m_location->setEditable( TRUE );
658 m_location->setDuplicatesEnabled( FALSE );
659 connect( m_location, SIGNAL(activated(const QString& ) ),
660 this, SLOT(slotLocationActivated(const QString& )) );
661 connect( m_location->lineEdit(), SIGNAL(returnPressed() ) ,
662 this, SLOT(locationComboChanged() ) );
663
664 // UP Button
665 m_up = new QPushButton( Resource::loadIconSet("up"), QString::null,
666 m_boxToolbar, "cdUpButton" );
667 m_up->setFixedSize( QSize(20, 20 ) );
668 connect( m_up, SIGNAL( clicked() ), this, SLOT(cdUP() ) );
669 m_up->setFlat( TRUE );
670
671 // Home Button
672 m_homeButton = new QPushButton(Resource::loadIconSet("home"),
673 QString::null, m_boxToolbar );
674 m_homeButton->setFixedSize( QSize(20, 20 ) );
675 connect(m_homeButton, SIGNAL(clicked() ), this, SLOT(slotHome() ) );
676 m_homeButton->setFlat( TRUE );
677
678 // Documents Button
679 m_docButton = new QPushButton( Resource::loadIconSet("DocsIcon"),
680 QString::null, m_boxToolbar,
681 "docsButton" );
682 m_docButton->setFixedSize( QSize(20, 20 ) );
683 m_docButton->setFlat( true );
684 connect( m_docButton, SIGNAL(clicked() ),
685 this, SLOT(slotDoc() ) );
686
687 // close button
688 m_close = new QPushButton( Resource::loadIconSet( "close"), "",
689 m_boxToolbar );
690 connect( m_close, SIGNAL(clicked() ), this, SIGNAL(closeMe() ) );
691 m_close->setFixedSize( 20, 20 );
692
693 m_boxToolbar->setFixedHeight( 20 );
694 m_pseudoLayout->addWidget(m_boxToolbar );
695
696 /* init the locations */
697 initLocations();
698
699 if( !m_shTool ){
700 m_location->hide( );
701 m_up->hide( );
702 m_homeButton->hide( );
703 m_docButton->hide( );
704 }
705 if(!m_shClose )
706 m_close->hide();
707
708 m_mainView->setToolbar( m_pseudo );
709 m_lay->addWidget( m_mainView, 100 );
710}
711/* put default locations into the bar */
712void OFileSelector::initLocations () {
713
714 // let;s fill the Location ComboBox
715 StorageInfo storage;
716 const QList<FileSystem> &fs = storage.fileSystems();
717 QListIterator<FileSystem> it ( fs );
718 for( ; it.current(); ++it ){
719 const QString disk = (*it)->name();
720 const QString path = (*it)->path();
721 m_location->insertItem(path+ "<-"+disk );
722 }
723 int count = m_location->count();
724 m_location->insertItem( m_currentDir );
725 m_location->setCurrentItem( count );
726
727}
728void OFileSelector::initializePerm()
729{
730 if( m_checkPerm == 0 ){
731 m_checkPerm = new QCheckBox(tr("Set Permission"), this, "perm");
732 m_checkPerm->setChecked( false );
733 m_lay->addWidget( m_checkPerm );
734 }
735}
736void OFileSelector::initPics()
737{
738 m_pixmaps = new QMap<QString,QPixmap>;
739 QPixmap pm = Resource::loadPixmap( "folder" );
740 QPixmap lnk = Resource::loadPixmap( "opie/symlink" );
741
742 QPainter painter( &pm );
743 painter.drawPixmap( pm.width()-lnk.width(), pm.height()-lnk.height(), lnk );
744 pm.setMask( pm.createHeuristicMask( FALSE ) );
745 m_pixmaps->insert("dirsymlink", pm );
746
747 QPixmap pm2 = Resource::loadPixmap( "lockedfolder" );
748 QPainter pen(&pm2 );
749 pen.drawPixmap(pm2.width()-lnk.width(), pm2.height()-lnk.height(), lnk );
750 pm2.setMask( pm2.createHeuristicMask( FALSE ) );
751 m_pixmaps->insert("symlinkedlocked", pm2 );
752}
753// if a mime complies with the m_mimeCheck->currentItem
754bool OFileSelector::compliesMime( const QString &path, const QString &mime )
755{
756 if( mime == "All" )
757 return true;
758 MimeType type( path );
759 if( type.id() == mime )
760 return true;
761 return false;
762}
763/* check if the mimetype in mime
764 * complies with the one which is current
765 */
766/*
767 * We've the mimetype of the file
768 * We need to get the stringlist of the current mimetype
769 *
770 * mime = image/jpeg
771 * QStringList = 'image/*'
772 * or QStringList = image/jpeg;image/png;application/x-ogg
773 * or QStringList = application/x-ogg;image/*;
774 * with all these mime filters it should get acceptes
775 * to do so we need to look if mime is contained inside
776 * the stringlist
777 * if it's contained return true
778 * if not ( I'm no RegExp expert at all ) we'll look if a '/*'
779 * is contained in the mimefilter and then we will
780 * look if both are equal until the '/'
781 */
782bool OFileSelector::compliesMime( const QString& mime ) {
783 qWarning("mimetype is %s", mime.latin1() );
784 QString currentText;
785 if (m_shChooser )
786 currentText = m_mimeCheck->currentText();
787
788 qWarning("current text is %s", currentText.latin1() );
789 QMap<QString, QStringList>::Iterator it;
790 QStringList list;
791 if ( currentText == tr("All") ) return true;
792 else if ( currentText.isEmpty() && !m_mimetypes.isEmpty() ) {
793 it = m_mimetypes.begin();
794 list = it.data();
795 }else if ( currentText.isEmpty() ) return true;
796 else{
797 it = m_mimetypes.find(currentText );
798 if ( it == m_mimetypes.end() ) qWarning("not there"), list << currentText;
799 else qWarning("found"), list = it.data();
800 }
801
802
803 if ( list.contains(mime) ) return true;
804 qWarning("list doesn't contain it ");
805 QStringList::Iterator it2;
806 int pos;
807 for ( it2 = list.begin(); it2 != list.end(); ++it2 ) {
808 pos = (*it2).findRev("/*");
809 if ( pos >= 0 ) {
810 if ( mime.contains( (*it2).left(pos) ) ) return true;
811 }
812 }
813 return false;
814}
815void OFileSelector::slotFileSelected( const QString &string )
816{
817 if( m_shLne )
818 m_edit->setText( string );
819 emit fileSelected( string );
820}
821void OFileSelector::slotFileBridgeSelected( const DocLnk &lnk )
822{
823 slotFileSelected( lnk.name() );
824 // emit fileSelected( lnk );
825}
826
827
828void OFileSelector::slotDelete()
829{
830 /*
831 OFileSelectorItem *sel = (OFileSelectorItem*)m_View->currentItem();
832 QStringList list = QStringList::split("->", sel->text(1) );
833 if( sel->isDir() ){
834 QString str = QString::fromLatin1("rm -rf ") + sel->directory() +"/" + list[0]; //better safe than sorry
835 switch ( QMessageBox::warning(this,tr("Delete"),tr("Do you really want to delete\n")+list[0],
836 tr("Yes"),tr("No"),0,1,1) ) {
837 case 0:
838 ::system(str.utf8().data() );
839 break;
840 }
841 } else {
842 QFile::remove( list[0] );
843 }
844 m_View->takeItem( sel );
845 delete sel;
846 */
847}
848void OFileSelector::cdUP()
849{
850 // FIXME won't work on non filesystem based systems
851 // better call the Olister
852 QDir dir( m_currentDir );
853 dir.cdUp();
854 if(dir.exists() ){
855 m_currentDir = dir.absPath();
856 reparse();
857 int count = m_location->count();
858 slotInsertLocationPath( m_currentDir, count);
859 m_location->setCurrentItem( indexByString( m_location, m_currentDir));
860 }
861}
862void OFileSelector::slotHome()
863{
864 cd(QDir::homeDirPath() );
865}
866void OFileSelector::slotDoc()
867{
868 cd(QPEApplication::documentDir() );
869}
870void OFileSelector::slotNavigate( )
871{
872
873}
874// fill the View with life
875void OFileSelector::reparse()
876{
877 if( m_selector == Normal )
878 return;
879
880 currentView()->clear();
881
882 if( m_shChooser)
883 qWarning("reparse %s", m_mimeCheck->currentText().latin1() );
884
885 QString currentMimeType;
886
887 // let's update the mimetype
888 if( m_autoMime ){
889 m_mimetypes.clear();
890 // ok we can change mimetype so we need to be able to give a selection
891 if( m_shChooser ) {
892 currentMimeType = m_mimeCheck->currentText();
893 m_mimeCheck->clear();
894
895 // let's find possible mimetypes
896 m_mimetypes = currentLister()->mimeTypes( m_currentDir );
897
898 // add them to the chooser
899 updateMimeCheck();
900 m_mimeCheck->setCurrentItem( indexByString( m_mimeCheck, currentMimeType ) );
901 currentMimeType = m_mimeCheck->currentText();
902 }
903 }else { // no autoMime
904 // let the mimetype be set from out side the m_mimeCheck FEATURE
905
906 if( m_shChooser )
907 currentMimeType = m_mimeCheck->currentText();
908
909 }
910 // now we got our mimetypes we can add the files
911
912 currentLister()->reparse( m_currentDir );
913 /* we're done with adding let's sort */
914 currentView()->sort();
915
916
917 if( m_shTool ){
918 m_location->insertItem( m_currentDir );
919
920 }
921 // reenable painting and updates
922}
923/* switch lister to @param lister */
924void OFileSelector::setLister(const QString& lister) {
925 QStringList listerList = factory()->lister();
926
927 if (listerList.contains(lister) ) {
928 delete (OLister*) m_lister;
929 m_lister = factory()->lister( lister, this );
930 }else if (!m_lister ) {
931 /*
932 * if we do not have a lister
933 * we need to take the default one
934 */
935 m_lister = new OLocalLister(this);
936 }
937 m_listerName = lister;
938}
939void OFileSelector::setView( const QString& lis ) {
940 qWarning("setView ");
941 fillList();
942 if ( lis == tr("Documents") ) {
943 m_selector = Normal;
944 delete m_lister;
945 delete m_fileView;
946 m_lister = 0l;
947 m_fileView = 0l;
948 initializeOldSelector();
949 }else {
950 qWarning("lis %s", lis.latin1() );
951 QString list;
952
953 delete m_lister;
954 delete m_fileView;
955 delete m_select;
956 m_lister =0l;
957 m_fileView = 0l;
958 m_select = 0l;
959 if ( lis.startsWith("All") ) {
960 m_selector = ExtendedAll;
961 list = lis.mid(4 ).stripWhiteSpace();
962 } else{
963 list = lis;
964 m_selector = Extended;
965 }
966 setLister(m_listerName);
967 m_fileView = factory()->view( list, this, m_mainView );
968 m_mainView->setWidget( m_fileView->widget() );
969 reparse();
970 }
971}
972/*
973 * the factory
974 */
975void OFileSelector::initFactory() {
976 m_fileFactory = new OFileFactory();
977 m_fileFactory->addLister(tr("Files"), newLocalLister );
978 m_fileFactory->addView(tr("List View"), newFileListView );
979 /* dummy entry */
980 m_fileFactory->addView(tr("Documents"), newFileListView );
981}
982
983void OFileSelector::fillList() {
984 qWarning("fill list");
985 if (!m_viewCheck )
986 return;
987
988 m_viewCheck->clear();
989 QStringList list = factory()->views();
990 qWarning("views: " + list.join(";") );
991 for (QStringList::Iterator it = list.begin(); it != list.end(); ++it ) {
992 qWarning( (*it) );
993 if ( (*it) == tr("Documents") ) {
994 m_viewCheck->insertItem( (*it) );
995 }else{
996 m_viewCheck->insertItem( (*it) );
997 m_viewCheck->insertItem( tr("All ") + (*it) );
998 }
999 }
1000}
1001OFileFactory* OFileSelector::factory() {
1002 return m_fileFactory;
1003}
1004
1005
1006OFileView* OFileSelector::currentView() {
1007 return m_fileView;
1008}
1009OFileView* OFileSelector::currentView() const{
1010 return m_fileView;
1011}
1012int OFileSelector::filter() {
1013 int filter;
1014 if ( m_selector == ExtendedAll )
1015 filter = QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All;
1016 else
1017 filter = QDir::Files | QDir::Dirs | QDir::All ;
1018
1019 return filter;
1020}
1021int OFileSelector::sorting() {
1022 int sort;
1023
1024 if (m_case )
1025 sort = ( QDir::IgnoreCase | QDir::Name | QDir::DirsFirst | QDir::Reversed );
1026 else
1027 sort = ( QDir::Name | QDir::DirsFirst | QDir::Reversed );
1028
1029 return sort;
1030}
1031void OFileSelector::internFileSelected( const QString& s) {
1032 emit fileSelected( s );
1033 DocLnk lnk( s );
1034 internFileSelected( lnk );
1035}
1036void OFileSelector::internFileSelected( const DocLnk& d ) {
1037 emit fileSelected( d );
1038}
1039void OFileSelector::internContextMenu() {
1040 emit contextMenu();
1041}
1042void OFileSelector::internChangedDir( const QString& s) {
1043 emit dirSelected( s );
1044 cd(s );
1045}
1046void OFileSelector::internChangedDir( const QDir& s) {
1047 emit dirSelected( s );
1048}
1049QPixmap OFileSelector::pixmap( const QString& s ) {
1050
1051 return (*m_pixmaps)[s];
1052}
1053OLister* OFileSelector::currentLister()const {
1054 return m_lister;
1055}
1056void OFileSelector::initializeOldSelector() {
1057 qWarning("initializeOldSelector");
1058
1059 delete m_select;
1060
1061 // we need to initialize but keep the selected mimetype
1062 /* we default not to show close and new buttons */
1063 QString mime = currentMimeType();
1064 qWarning("MimeType " + mime );
1065 m_select = new FileSelector( mime ,
1066 m_mainView, "fileselector",
1067 FALSE, FALSE);
1068 m_select->setCategorySelectVisible( FALSE );
1069 m_select->setTypeComboVisible( FALSE );
1070
1071 connect(m_select, SIGNAL(fileSelected( const DocLnk & ) ),
1072 this, SLOT( slotFileBridgeSelected(const DocLnk & ) ) );
1073 connect(m_select, SIGNAL(closeMe() ),
1074 this, SIGNAL(closeMe() ) );
1075 //connect to close me and other signals as well
1076 m_mainView->setWidget( m_select );
1077}
1078/*
1079 * initialize the listview
1080 * we will call fillList
1081 * setLister
1082 * with QString::null to get the default
1083 * setView with either Files or All Files
1084 * depending on Extended
1085 */
1086void OFileSelector::initializeView() {
1087 setLister(QString::null);
1088 fillList();
1089 if (m_selector == Extended ) {
1090 setView( tr("List View") );
1091 }else{
1092 setView( tr("All List View") );
1093 }
1094}
1095