-rw-r--r-- | core/apps/textedit/fileBrowser.cpp | 35 | ||||
-rw-r--r-- | core/apps/textedit/fileBrowser.h | 3 |
2 files changed, 28 insertions, 10 deletions
diff --git a/core/apps/textedit/fileBrowser.cpp b/core/apps/textedit/fileBrowser.cpp index 7a3a703..8c942a1 100644 --- a/core/apps/textedit/fileBrowser.cpp +++ b/core/apps/textedit/fileBrowser.cpp | |||
@@ -139,60 +139,56 @@ fileBrowser::fileBrowser( QWidget* parent, const char* name, bool modal, WFlags | |||
139 | SelectionCombo->insertItem( tr( "Hidden files" ) ); | 139 | SelectionCombo->insertItem( tr( "Hidden files" ) ); |
140 | // SelectionCombo->setMaximumWidth(120); | 140 | // SelectionCombo->setMaximumWidth(120); |
141 | layout->addMultiCellWidget( SelectionCombo, 2, 2, 0, 3 ); | 141 | layout->addMultiCellWidget( SelectionCombo, 2, 2, 0, 3 ); |
142 | 142 | ||
143 | connect( SelectionCombo, SIGNAL( activated( const QString & ) ), | 143 | connect( SelectionCombo, SIGNAL( activated( const QString & ) ), |
144 | this, SLOT( selectionChanged( const QString & ) ) ); | 144 | this, SLOT( selectionChanged( const QString & ) ) ); |
145 | 145 | ||
146 | typemb = new MenuButton(this); | 146 | typemb = new MenuButton(this); |
147 | typemb->setLabel(tr("Type: %1")); | 147 | typemb->setLabel(tr("Type: %1")); |
148 | typemb->setMinimumWidth(110); | 148 | typemb->setMinimumWidth(110); |
149 | typemb->setFixedHeight(22); | 149 | typemb->setFixedHeight(22); |
150 | layout->addMultiCellWidget( typemb, 2, 2, 4, 7 ); | 150 | layout->addMultiCellWidget( typemb, 2, 2, 4, 7 ); |
151 | updateMimeTypeMenu() ; | 151 | updateMimeTypeMenu() ; |
152 | 152 | ||
153 | currentDir.setPath(QDir::currentDirPath()); | 153 | currentDir.setPath(QDir::currentDirPath()); |
154 | currentDir.setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden */| QDir::All); | 154 | currentDir.setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden */| QDir::All); |
155 | currentDir.setNameFilter(filterStr); | ||
155 | 156 | ||
156 | populateList(); | 157 | populateList(); |
157 | move(0,15); | 158 | move(0,15); |
158 | } | 159 | } |
159 | 160 | ||
160 | fileBrowser::~fileBrowser() | 161 | fileBrowser::~fileBrowser() |
161 | { | 162 | { |
162 | } | 163 | } |
163 | 164 | ||
164 | void fileBrowser::setMimeType(const QString &type) { | ||
165 | mimeType = type; | ||
166 | } | ||
167 | |||
168 | void fileBrowser::setFileView( int selection ) | 165 | void fileBrowser::setFileView( int selection ) |
169 | { | 166 | { |
170 | SelectionCombo->setCurrentItem( selection ); | 167 | SelectionCombo->setCurrentItem( selection ); |
171 | selectionChanged( SelectionCombo->currentText() ); | 168 | selectionChanged( SelectionCombo->currentText() ); |
172 | } | 169 | } |
173 | 170 | ||
174 | void fileBrowser::populateList() | 171 | void fileBrowser::populateList() |
175 | { | 172 | { |
176 | ListView->clear(); | 173 | ListView->clear(); |
177 | bool isDir=FALSE; | 174 | bool isDir=FALSE; |
178 | //qDebug(currentDir.canonicalPath()); | 175 | //qDebug(currentDir.canonicalPath()); |
179 | currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); | 176 | currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); |
180 | currentDir.setMatchAllDirs(TRUE); | 177 | currentDir.setMatchAllDirs(TRUE); |
181 | 178 | ||
182 | currentDir.setNameFilter(filterStr); | ||
183 | // currentDir.setNameFilter("*.txt;*.etx"); | 179 | // currentDir.setNameFilter("*.txt;*.etx"); |
184 | QString fileL, fileS, fileDate; | 180 | QString fileL, fileS, fileDate; |
185 | const QFileInfoList *list = currentDir.entryInfoList( /*QDir::All*/ /*, QDir::SortByMask*/); | 181 | const QFileInfoList *list = currentDir.entryInfoList( /*QDir::All*/ /*, QDir::SortByMask*/); |
186 | QFileInfoListIterator it(*list); | 182 | QFileInfoListIterator it(*list); |
187 | QFileInfo *fi; | 183 | QFileInfo *fi; |
188 | while ( (fi=it.current()) ) { | 184 | while ( (fi=it.current()) ) { |
189 | 185 | ||
190 | if (fi->isSymLink() ){ | 186 | if (fi->isSymLink() ){ |
191 | QString symLink=fi->readLink(); | 187 | QString symLink=fi->readLink(); |
192 | // qDebug("Symlink detected "+symLink); | 188 | // qDebug("Symlink detected "+symLink); |
193 | QFileInfo sym( symLink); | 189 | QFileInfo sym( symLink); |
194 | fileS.sprintf( "%10li", sym.size() ); | 190 | fileS.sprintf( "%10li", sym.size() ); |
195 | fileL.sprintf( "%s -> %s", sym.fileName().data(),sym.absFilePath().data() ); | 191 | fileL.sprintf( "%s -> %s", sym.fileName().data(),sym.absFilePath().data() ); |
196 | fileDate = sym.lastModified().toString(); | 192 | fileDate = sym.lastModified().toString(); |
197 | } else { | 193 | } else { |
198 | // qDebug("Not a dir: "+currentDir.canonicalPath()+fileL); | 194 | // qDebug("Not a dir: "+currentDir.canonicalPath()+fileL); |
@@ -373,33 +369,33 @@ void fileBrowser::ListPressed( int mouse, QListViewItem *item, const QPoint &poi | |||
373 | switch (mouse) { | 369 | switch (mouse) { |
374 | case 1: | 370 | case 1: |
375 | break; | 371 | break; |
376 | case 2: | 372 | case 2: |
377 | showListMenu(item); | 373 | showListMenu(item); |
378 | break; | 374 | break; |
379 | }; | 375 | }; |
380 | } | 376 | } |
381 | 377 | ||
382 | void fileBrowser::showListMenu(QListViewItem *item) { | 378 | void fileBrowser::showListMenu(QListViewItem *item) { |
383 | 379 | ||
384 | QPopupMenu m;// = new QPopupMenu( Local_View ); | 380 | QPopupMenu m;// = new QPopupMenu( Local_View ); |
385 | if( item->text(0).find("/",0,TRUE)) | 381 | if( item->text(0).find("/",0,TRUE)) |
386 | m.insertItem( tr( "Change Directory" ), this, SLOT( doCd() )); | 382 | m.insertItem( tr( "Change Directory" ), this, SLOT( doCd() )); |
387 | else | 383 | else |
388 | m.insertItem( tr( "Make Directory" ), this, SLOT( makDir() )); | 384 | m.insertItem( tr( "Make Directory" ), this, SLOT( makDir() )); |
389 | m.insertItem( tr( "Rescan" ), this, SLOT( populateList()() )); | 385 | m.insertItem( tr( "Rescan" ), this, SLOT( populateList() )); |
390 | m.insertItem( tr( "Rename" ), this, SLOT( localRename() )); | 386 | m.insertItem( tr( "Rename" ), this, SLOT( localRename() )); |
391 | m.insertSeparator(); | 387 | m.insertSeparator(); |
392 | m.insertItem( tr( "Delete" ), this, SLOT( localDelete() )); | 388 | m.insertItem( tr( "Delete" ), this, SLOT( localDelete() )); |
393 | m.exec( QCursor::pos() ); | 389 | m.exec( QCursor::pos() ); |
394 | 390 | ||
395 | } | 391 | } |
396 | 392 | ||
397 | void fileBrowser::doCd() { | 393 | void fileBrowser::doCd() { |
398 | listClicked( ListView->currentItem()); | 394 | listClicked( ListView->currentItem()); |
399 | } | 395 | } |
400 | 396 | ||
401 | void fileBrowser::makDir() { | 397 | void fileBrowser::makDir() { |
402 | InputDialog *fileDlg; | 398 | InputDialog *fileDlg; |
403 | fileDlg = new InputDialog(this,"Make Directory",TRUE, 0); | 399 | fileDlg = new InputDialog(this,"Make Directory",TRUE, 0); |
404 | fileDlg->exec(); | 400 | fileDlg->exec(); |
405 | if( fileDlg->result() == 1 ) { | 401 | if( fileDlg->result() == 1 ) { |
@@ -468,63 +464,86 @@ void fileBrowser::updateMimeTypeMenu() { | |||
468 | // Type filter | 464 | // Type filter |
469 | QStringList types; | 465 | QStringList types; |
470 | types << tr("All"); | 466 | types << tr("All"); |
471 | types << "--"; | 467 | types << "--"; |
472 | types += getMimeTypes(); | 468 | types += getMimeTypes(); |
473 | prev = typemb->currentText(); | 469 | prev = typemb->currentText(); |
474 | typemb->clear(); | 470 | typemb->clear(); |
475 | typemb->insertItems(types); | 471 | typemb->insertItems(types); |
476 | // typemb->select(prev); | 472 | // typemb->select(prev); |
477 | 473 | ||
478 | connect(typemb, SIGNAL(selected(const QString&)), this, SLOT(showType(const QString&))); | 474 | connect(typemb, SIGNAL(selected(const QString&)), this, SLOT(showType(const QString&))); |
479 | } | 475 | } |
480 | 476 | ||
481 | void fileBrowser::showType(const QString &t) { | 477 | void fileBrowser::showType(const QString &t) { |
482 | 478 | ||
483 | qDebug(t); | 479 | qDebug(t); |
484 | mimeType = t+"/*"; | 480 | if(t.find("All",0,TRUE) != -1) { |
481 | filterStr = "*"; | ||
482 | } else { | ||
483 | QStringList list = mimetypes.grep( t,TRUE); | ||
484 | QString ext; | ||
485 | for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { | ||
486 | mimeType =(*it); | ||
487 | MimeType mt( mimeType); | ||
488 | qDebug("mime "+mimeType); | ||
489 | // qDebug("description "+mt.description()); | ||
490 | // qDebug( "id "+mt.id()); | ||
491 | qDebug("extension "+mt.extension()); | ||
492 | if( mt.extension().isEmpty()) | ||
493 | filterStr = "*"; | ||
494 | else | ||
495 | filterStr = "*."+ mt.extension()+" "; | ||
496 | // printf( "%s \n", (*it).latin1() ); | ||
497 | } | ||
498 | } | ||
499 | currentDir.setNameFilter(filterStr); | ||
500 | |||
501 | populateList(); | ||
502 | update(); | ||
485 | // if(fileSelector) { | 503 | // if(fileSelector) { |
486 | // disconnect( fileSelector, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( docOpen( const DocLnk & ) ) ); | 504 | // disconnect( fileSelector, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( docOpen( const DocLnk & ) ) ); |
487 | // delete fileSelector; | 505 | // delete fileSelector; |
488 | // } | 506 | // } |
489 | // fileSelector = new FileSelector( mimeType, FileStack, "fileselector" , FALSE, FALSE); //buggy | 507 | // fileSelector = new FileSelector( mimeType, FileStack, "fileselector" , FALSE, FALSE); //buggy |
490 | // connect( fileSelector, SIGNAL( closeMe() ), this, SLOT( showEditTools() ) ); | 508 | // connect( fileSelector, SIGNAL( closeMe() ), this, SLOT( showEditTools() ) ); |
491 | // connect( fileSelector, SIGNAL( newSelected( const DocLnk &) ), this, SLOT( newFile( const DocLnk & ) ) ); | 509 | // connect( fileSelector, SIGNAL( newSelected( const DocLnk &) ), this, SLOT( newFile( const DocLnk & ) ) ); |
492 | // connect( fileSelector, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( docOpen( const DocLnk & ) ) ); | 510 | // connect( fileSelector, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( docOpen( const DocLnk & ) ) ); |
493 | // fileSelector->reread(); | 511 | // fileSelector->reread(); |
494 | repaint(); | ||
495 | // if ( t == tr("All") ) { | 512 | // if ( t == tr("All") ) { |
496 | // icons->setTypeFilter("",TRUE); | 513 | // icons->setTypeFilter("",TRUE); |
497 | // } else { | 514 | // } else { |
498 | // icons->setTypeFilter(t+"/*",TRUE); | 515 | // icons->setTypeFilter(t+"/*",TRUE); |
499 | // } | 516 | // } |
500 | 517 | ||
501 | } | 518 | } |
502 | 519 | ||
503 | QStringList fileBrowser::getMimeTypes() { | 520 | QStringList fileBrowser::getMimeTypes() { |
521 | |||
504 | QStringList r; | 522 | QStringList r; |
505 | AppLnkSet apps( QPEApplication::qpeDir() + "apps" ); | 523 | AppLnkSet apps( QPEApplication::qpeDir() + "apps" ); |
506 | QFile file( QPEApplication::qpeDir()+"etc/available.mime"); | 524 | QFile file( QPEApplication::qpeDir()+"etc/available.mime"); |
507 | file.open( IO_WriteOnly|IO_Truncate);//) | 525 | file.open( IO_WriteOnly|IO_Truncate);//) |
508 | for ( QListIterator<AppLnk> it( apps.children() ); it.current(); ++it ) { | 526 | for ( QListIterator<AppLnk> it( apps.children() ); it.current(); ++it ) { |
509 | AppLnk* l; | 527 | AppLnk* l; |
510 | l = it.current(); | 528 | l = it.current(); |
511 | QStringList maj = l->mimeTypes(); | 529 | QStringList maj = l->mimeTypes(); |
512 | QStringList::ConstIterator f; | 530 | QStringList::ConstIterator f; |
513 | for ( f = maj.begin(); f != maj.end(); f++ ) { | 531 | for ( f = maj.begin(); f != maj.end(); f++ ) { |
514 | QString temp = *f; | 532 | QString temp = *f; |
533 | mimetypes << temp; | ||
515 | int sl = temp.find('/'); | 534 | int sl = temp.find('/'); |
516 | if (sl >= 0) { | 535 | if (sl >= 0) { |
517 | QString k = temp.left(sl); | 536 | QString k = temp.left(sl); |
518 | if( r.grep(k,TRUE).isEmpty() ) { | 537 | if( r.grep(k,TRUE).isEmpty() ) { |
519 | r << k; | 538 | r << k; |
520 | k+="\n"; | 539 | k+="\n"; |
521 | file.writeBlock( k.latin1(), k.length()); | 540 | file.writeBlock( k.latin1(), k.length()); |
522 | } | 541 | } |
523 | } | 542 | } |
524 | } | 543 | } |
525 | } | 544 | } |
526 | r.sort(); | 545 | r.sort(); |
527 | file.close(); | 546 | file.close(); |
528 | return r; | 547 | return r; |
529 | } | 548 | } |
530 | 549 | ||
diff --git a/core/apps/textedit/fileBrowser.h b/core/apps/textedit/fileBrowser.h index 1138d80..339483f 100644 --- a/core/apps/textedit/fileBrowser.h +++ b/core/apps/textedit/fileBrowser.h | |||
@@ -45,42 +45,41 @@ class QRegExp; | |||
45 | 45 | ||
46 | 46 | ||
47 | class fileBrowser : public QDialog | 47 | class fileBrowser : public QDialog |
48 | { | 48 | { |
49 | Q_OBJECT | 49 | Q_OBJECT |
50 | 50 | ||
51 | public: | 51 | public: |
52 | fileBrowser( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 ,const QString filter=0); | 52 | fileBrowser( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 ,const QString filter=0); |
53 | ~fileBrowser(); | 53 | ~fileBrowser(); |
54 | 54 | ||
55 | QString selectedFileName; | 55 | QString selectedFileName; |
56 | QFile file; | 56 | QFile file; |
57 | QStringList fileList; | 57 | QStringList fileList; |
58 | QComboBox *SelectionCombo; | 58 | QComboBox *SelectionCombo; |
59 | public slots: | 59 | public slots: |
60 | void setFileView( int ); | 60 | void setFileView( int ); |
61 | void setMimeType(const QString &); | ||
62 | 61 | ||
63 | private: | 62 | private: |
64 | // QDict<void> mimes; | 63 | // QDict<void> mimes; |
65 | QPushButton *buttonOk, *buttonCancel, *homeButton, *docButton, *hideButton, *cdUpButton; | 64 | QPushButton *buttonOk, *buttonCancel, *homeButton, *docButton, *hideButton, *cdUpButton; |
66 | QListView* ListView; | 65 | QListView* ListView; |
67 | QLabel *dirLabel; | 66 | QLabel *dirLabel; |
68 | QString filterStr, mimeType; | 67 | QString filterStr, mimeType; |
69 | QDir currentDir; | 68 | QDir currentDir; |
70 | QStringList dirPathStringList; | 69 | QStringList dirPathStringList, mimetypes; |
71 | QListViewItem * item; | 70 | QListViewItem * item; |
72 | QComboBox *dirPathCombo; | 71 | QComboBox *dirPathCombo; |
73 | MenuButton *typemb; | 72 | MenuButton *typemb; |
74 | QWidgetStack *FileStack; | 73 | QWidgetStack *FileStack; |
75 | FileSelector *fileSelector; | 74 | FileSelector *fileSelector; |
76 | QRegExp tf; | 75 | QRegExp tf; |
77 | QStringList getMimeTypes(); | 76 | QStringList getMimeTypes(); |
78 | void fillCombo( const QString&); | 77 | void fillCombo( const QString&); |
79 | 78 | ||
80 | private slots: | 79 | private slots: |
81 | void populateList(); | 80 | void populateList(); |
82 | void homeButtonPushed(); | 81 | void homeButtonPushed(); |
83 | void docButtonPushed(); | 82 | void docButtonPushed(); |
84 | void ListPressed( int, QListViewItem *, const QPoint&, int); | 83 | void ListPressed( int, QListViewItem *, const QPoint&, int); |
85 | void showListMenu(QListViewItem*); | 84 | void showListMenu(QListViewItem*); |
86 | void doCd(); | 85 | void doCd(); |