summaryrefslogtreecommitdiff
Side-by-side diff
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
// connect( fileSelector, SIGNAL( closeMe() ), this, SLOT( showEditTools() ) );
// connect( fileSelector, SIGNAL( newSelected( const DocLnk &) ), this, SLOT( newFile( const DocLnk & ) ) );
connect( fileSelector, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( docOpen( const DocLnk & ) ) );
layout->addMultiCellWidget( FileStack, 1, 1, 0, 7 );
SelectionCombo = new QComboBox( FALSE, this, "SelectionCombo" );
SelectionCombo->insertItem( tr( "Documents" ) );
SelectionCombo->insertItem( tr( "All files" ) );
SelectionCombo->insertItem( tr( "Hidden files" ) );
// SelectionCombo->setMaximumWidth(120);
layout->addMultiCellWidget( SelectionCombo, 2, 2, 0, 3 );
connect( SelectionCombo, SIGNAL( activated( const QString & ) ),
this, SLOT( selectionChanged( const QString & ) ) );
typemb = new MenuButton(this);
typemb->setLabel(tr("Type: %1"));
typemb->setMinimumWidth(110);
typemb->setFixedHeight(22);
layout->addMultiCellWidget( typemb, 2, 2, 4, 7 );
updateMimeTypeMenu() ;
currentDir.setPath(QDir::currentDirPath());
currentDir.setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden */| QDir::All);
+ currentDir.setNameFilter(filterStr);
populateList();
move(0,15);
}
fileBrowser::~fileBrowser()
{
}
-void fileBrowser::setMimeType(const QString &type) {
- mimeType = type;
-}
-
void fileBrowser::setFileView( int selection )
{
SelectionCombo->setCurrentItem( selection );
selectionChanged( SelectionCombo->currentText() );
}
void fileBrowser::populateList()
{
ListView->clear();
bool isDir=FALSE;
//qDebug(currentDir.canonicalPath());
currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst);
currentDir.setMatchAllDirs(TRUE);
- currentDir.setNameFilter(filterStr);
// currentDir.setNameFilter("*.txt;*.etx");
QString fileL, fileS, fileDate;
const QFileInfoList *list = currentDir.entryInfoList( /*QDir::All*/ /*, QDir::SortByMask*/);
QFileInfoListIterator it(*list);
QFileInfo *fi;
while ( (fi=it.current()) ) {
if (fi->isSymLink() ){
QString symLink=fi->readLink();
// qDebug("Symlink detected "+symLink);
QFileInfo sym( symLink);
fileS.sprintf( "%10li", sym.size() );
fileL.sprintf( "%s -> %s", sym.fileName().data(),sym.absFilePath().data() );
fileDate = sym.lastModified().toString();
} else {
// qDebug("Not a dir: "+currentDir.canonicalPath()+fileL);
fileS.sprintf( "%10li", fi->size() );
fileL.sprintf( "%s",fi->fileName().data() );
fileDate= fi->lastModified().toString();
if( QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+fileL)).exists() ) {
fileL+="/";
isDir=TRUE;
// qDebug( fileL);
}
@@ -365,49 +361,49 @@ void fileBrowser::selectionChanged( const QString &select )
void fileBrowser::docOpen( const DocLnk &doc )
{
fileList.append( doc.file().latin1() );
accept();
}
void fileBrowser::ListPressed( int mouse, QListViewItem *item, const QPoint &point, int i)
{
switch (mouse) {
case 1:
break;
case 2:
showListMenu(item);
break;
};
}
void fileBrowser::showListMenu(QListViewItem *item) {
QPopupMenu m;// = new QPopupMenu( Local_View );
if( item->text(0).find("/",0,TRUE))
m.insertItem( tr( "Change Directory" ), this, SLOT( doCd() ));
else
m.insertItem( tr( "Make Directory" ), this, SLOT( makDir() ));
- m.insertItem( tr( "Rescan" ), this, SLOT( populateList()() ));
+ m.insertItem( tr( "Rescan" ), this, SLOT( populateList() ));
m.insertItem( tr( "Rename" ), this, SLOT( localRename() ));
m.insertSeparator();
m.insertItem( tr( "Delete" ), this, SLOT( localDelete() ));
m.exec( QCursor::pos() );
}
void fileBrowser::doCd() {
listClicked( ListView->currentItem());
}
void fileBrowser::makDir() {
InputDialog *fileDlg;
fileDlg = new InputDialog(this,"Make Directory",TRUE, 0);
fileDlg->exec();
if( fileDlg->result() == 1 ) {
QString filename = fileDlg->LineEdit1->text();
currentDir.mkdir( currentDir.canonicalPath()+"/"+filename);
}
populateList();
}
void fileBrowser::localRename() {
QString curFile = ListView->currentItem()->text(0);
@@ -460,79 +456,102 @@ void fileBrowser::localDelete() {
void fileBrowser::updateMimeTypeMenu() {
disconnect( typemb, SIGNAL(selected(const QString&)),
this, SLOT(showType(const QString&)) );
QString prev;
// Type filter
QStringList types;
types << tr("All");
types << "--";
types += getMimeTypes();
prev = typemb->currentText();
typemb->clear();
typemb->insertItems(types);
// typemb->select(prev);
connect(typemb, SIGNAL(selected(const QString&)), this, SLOT(showType(const QString&)));
}
void fileBrowser::showType(const QString &t) {
qDebug(t);
- mimeType = t+"/*";
+ if(t.find("All",0,TRUE) != -1) {
+ filterStr = "*";
+ } else {
+ QStringList list = mimetypes.grep( t,TRUE);
+ QString ext;
+ for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) {
+ mimeType =(*it);
+ MimeType mt( mimeType);
+ qDebug("mime "+mimeType);
+// qDebug("description "+mt.description());
+// qDebug( "id "+mt.id());
+ qDebug("extension "+mt.extension());
+ if( mt.extension().isEmpty())
+ filterStr = "*";
+ else
+ filterStr = "*."+ mt.extension()+" ";
+// printf( "%s \n", (*it).latin1() );
+ }
+ }
+ currentDir.setNameFilter(filterStr);
+
+ populateList();
+ update();
// if(fileSelector) {
// disconnect( fileSelector, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( docOpen( const DocLnk & ) ) );
// delete fileSelector;
// }
// fileSelector = new FileSelector( mimeType, FileStack, "fileselector" , FALSE, FALSE); //buggy
// connect( fileSelector, SIGNAL( closeMe() ), this, SLOT( showEditTools() ) );
// connect( fileSelector, SIGNAL( newSelected( const DocLnk &) ), this, SLOT( newFile( const DocLnk & ) ) );
// connect( fileSelector, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( docOpen( const DocLnk & ) ) );
// fileSelector->reread();
- repaint();
// if ( t == tr("All") ) {
// icons->setTypeFilter("",TRUE);
// } else {
// icons->setTypeFilter(t+"/*",TRUE);
// }
}
QStringList fileBrowser::getMimeTypes() {
+
QStringList r;
AppLnkSet apps( QPEApplication::qpeDir() + "apps" );
QFile file( QPEApplication::qpeDir()+"etc/available.mime");
file.open( IO_WriteOnly|IO_Truncate);//)
for ( QListIterator<AppLnk> it( apps.children() ); it.current(); ++it ) {
AppLnk* l;
l = it.current();
QStringList maj = l->mimeTypes();
QStringList::ConstIterator f;
for ( f = maj.begin(); f != maj.end(); f++ ) {
QString temp = *f;
+ mimetypes << temp;
int sl = temp.find('/');
if (sl >= 0) {
QString k = temp.left(sl);
if( r.grep(k,TRUE).isEmpty() ) {
r << k;
k+="\n";
file.writeBlock( k.latin1(), k.length());
}
}
}
}
r.sort();
file.close();
return r;
}
void fileBrowser::receive( const QCString &msg, const QByteArray &data ) {
// QDataStream stream( data, IO_ReadOnly );
// if (msg == "keyRegister(int key, QString channel, QString message)")
// {
// int k;
// QString c, m;
// stream >> k;
// 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;
class QListViewItem;
class QPushButton;
class QComboBox;
class QWidgetStack;
class FileSelector;
class QPoint;
class MenuButton;
class QRegExp;
class fileBrowser : public QDialog
{
Q_OBJECT
public:
fileBrowser( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 ,const QString filter=0);
~fileBrowser();
QString selectedFileName;
QFile file;
QStringList fileList;
QComboBox *SelectionCombo;
public slots:
void setFileView( int );
- void setMimeType(const QString &);
private:
// QDict<void> mimes;
QPushButton *buttonOk, *buttonCancel, *homeButton, *docButton, *hideButton, *cdUpButton;
QListView* ListView;
QLabel *dirLabel;
QString filterStr, mimeType;
QDir currentDir;
- QStringList dirPathStringList;
+ QStringList dirPathStringList, mimetypes;
QListViewItem * item;
QComboBox *dirPathCombo;
MenuButton *typemb;
QWidgetStack *FileStack;
FileSelector *fileSelector;
QRegExp tf;
QStringList getMimeTypes();
void fillCombo( const QString&);
private slots:
void populateList();
void homeButtonPushed();
void docButtonPushed();
void ListPressed( int, QListViewItem *, const QPoint&, int);
void showListMenu(QListViewItem*);
void doCd();
void makDir();
void localRename();
void localDelete();
void receive( const QCString &msg, const QByteArray &data );
void dirPathComboActivated( const QString & );
void upDir();
void listClicked( QListViewItem * );
void selectionChanged( const QString & );