summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2002-03-25 05:32:47 (UTC)
committer llornkcor <llornkcor>2002-03-25 05:32:47 (UTC)
commit7c0676ba302dc1cfa4348423544ea2d66417c1bd (patch) (unidiff)
tree4ca7e3471ff88bab34ec476f1ed22528030c96ee
parent2dc3d45e57eb3265fe77e868c76d92fa27f627af (diff)
downloadopie-7c0676ba302dc1cfa4348423544ea2d66417c1bd.zip
opie-7c0676ba302dc1cfa4348423544ea2d66417c1bd.tar.gz
opie-7c0676ba302dc1cfa4348423544ea2d66417c1bd.tar.bz2
more mime
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/apps/textedit/fileBrowser.cpp35
-rw-r--r--core/apps/textedit/fileBrowser.h3
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
@@ -131,76 +131,72 @@ fileBrowser::fileBrowser( QWidget* parent, const char* name, bool modal, WFlags
131// connect( fileSelector, SIGNAL( closeMe() ), this, SLOT( showEditTools() ) ); 131// connect( fileSelector, SIGNAL( closeMe() ), this, SLOT( showEditTools() ) );
132// connect( fileSelector, SIGNAL( newSelected( const DocLnk &) ), this, SLOT( newFile( const DocLnk & ) ) ); 132// connect( fileSelector, SIGNAL( newSelected( const DocLnk &) ), this, SLOT( newFile( const DocLnk & ) ) );
133 connect( fileSelector, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( docOpen( const DocLnk & ) ) ); 133 connect( fileSelector, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( docOpen( const DocLnk & ) ) );
134 layout->addMultiCellWidget( FileStack, 1, 1, 0, 7 ); 134 layout->addMultiCellWidget( FileStack, 1, 1, 0, 7 );
135 135
136 SelectionCombo = new QComboBox( FALSE, this, "SelectionCombo" ); 136 SelectionCombo = new QComboBox( FALSE, this, "SelectionCombo" );
137 SelectionCombo->insertItem( tr( "Documents" ) ); 137 SelectionCombo->insertItem( tr( "Documents" ) );
138 SelectionCombo->insertItem( tr( "All files" ) ); 138 SelectionCombo->insertItem( tr( "All files" ) );
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
160fileBrowser::~fileBrowser() 161fileBrowser::~fileBrowser()
161{ 162{
162} 163}
163 164
164void fileBrowser::setMimeType(const QString &type) {
165 mimeType = type;
166}
167
168void fileBrowser::setFileView( int selection ) 165void 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
174void fileBrowser::populateList() 171void 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);
199 fileS.sprintf( "%10li", fi->size() ); 195 fileS.sprintf( "%10li", fi->size() );
200 fileL.sprintf( "%s",fi->fileName().data() ); 196 fileL.sprintf( "%s",fi->fileName().data() );
201 fileDate= fi->lastModified().toString(); 197 fileDate= fi->lastModified().toString();
202 if( QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+fileL)).exists() ) { 198 if( QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+fileL)).exists() ) {
203 fileL+="/"; 199 fileL+="/";
204 isDir=TRUE; 200 isDir=TRUE;
205// qDebug( fileL); 201// qDebug( fileL);
206 } 202 }
@@ -365,49 +361,49 @@ void fileBrowser::selectionChanged( const QString &select )
365void fileBrowser::docOpen( const DocLnk &doc ) 361void fileBrowser::docOpen( const DocLnk &doc )
366{ 362{
367 fileList.append( doc.file().latin1() ); 363 fileList.append( doc.file().latin1() );
368 accept(); 364 accept();
369} 365}
370 366
371void fileBrowser::ListPressed( int mouse, QListViewItem *item, const QPoint &point, int i) 367void fileBrowser::ListPressed( int mouse, QListViewItem *item, const QPoint &point, int i)
372{ 368{
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
382void fileBrowser::showListMenu(QListViewItem *item) { 378void 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
397void fileBrowser::doCd() { 393void fileBrowser::doCd() {
398 listClicked( ListView->currentItem()); 394 listClicked( ListView->currentItem());
399} 395}
400 396
401void fileBrowser::makDir() { 397void 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 ) {
406 QString filename = fileDlg->LineEdit1->text(); 402 QString filename = fileDlg->LineEdit1->text();
407 currentDir.mkdir( currentDir.canonicalPath()+"/"+filename); 403 currentDir.mkdir( currentDir.canonicalPath()+"/"+filename);
408 } 404 }
409 populateList(); 405 populateList();
410} 406}
411 407
412void fileBrowser::localRename() { 408void fileBrowser::localRename() {
413 QString curFile = ListView->currentItem()->text(0); 409 QString curFile = ListView->currentItem()->text(0);
@@ -460,79 +456,102 @@ void fileBrowser::localDelete() {
460 456
461void fileBrowser::updateMimeTypeMenu() { 457void fileBrowser::updateMimeTypeMenu() {
462 458
463 disconnect( typemb, SIGNAL(selected(const QString&)), 459 disconnect( typemb, SIGNAL(selected(const QString&)),
464 this, SLOT(showType(const QString&)) ); 460 this, SLOT(showType(const QString&)) );
465 461
466 QString prev; 462 QString prev;
467 463
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
481void fileBrowser::showType(const QString &t) { 477void 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
503QStringList fileBrowser::getMimeTypes() { 520QStringList 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
531void fileBrowser::receive( const QCString &msg, const QByteArray &data ) { 550void fileBrowser::receive( const QCString &msg, const QByteArray &data ) {
532// QDataStream stream( data, IO_ReadOnly ); 551// QDataStream stream( data, IO_ReadOnly );
533// if (msg == "keyRegister(int key, QString channel, QString message)") 552// if (msg == "keyRegister(int key, QString channel, QString message)")
534// { 553// {
535// int k; 554// int k;
536// QString c, m; 555// QString c, m;
537// stream >> k; 556// stream >> k;
538// stream >> c; 557// stream >> c;
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
@@ -37,58 +37,57 @@ class QListView;
37class QListViewItem; 37class QListViewItem;
38class QPushButton; 38class QPushButton;
39class QComboBox; 39class QComboBox;
40class QWidgetStack; 40class QWidgetStack;
41class FileSelector; 41class FileSelector;
42class QPoint; 42class QPoint;
43class MenuButton; 43class MenuButton;
44class QRegExp; 44class QRegExp;
45 45
46 46
47class fileBrowser : public QDialog 47class fileBrowser : public QDialog
48{ 48{
49 Q_OBJECT 49 Q_OBJECT
50 50
51public: 51public:
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;
59public slots: 59public slots:
60 void setFileView( int ); 60 void setFileView( int );
61 void setMimeType(const QString &);
62 61
63private: 62private:
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
80private slots: 79private 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();
87 void makDir(); 86 void makDir();
88 void localRename(); 87 void localRename();
89 void localDelete(); 88 void localDelete();
90 void receive( const QCString &msg, const QByteArray &data ); 89 void receive( const QCString &msg, const QByteArray &data );
91 void dirPathComboActivated( const QString & ); 90 void dirPathComboActivated( const QString & );
92 void upDir(); 91 void upDir();
93 void listClicked( QListViewItem * ); 92 void listClicked( QListViewItem * );
94 void selectionChanged( const QString & ); 93 void selectionChanged( const QString & );