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