-rw-r--r-- | core/apps/textedit/fileBrowser.cpp | 17 | ||||
-rw-r--r-- | core/apps/textedit/fileBrowser.h | 2 | ||||
-rw-r--r-- | core/apps/textedit/fileSaver.cpp | 45 |
3 files changed, 54 insertions, 10 deletions
diff --git a/core/apps/textedit/fileBrowser.cpp b/core/apps/textedit/fileBrowser.cpp index 8c942a1..8ea8067 100644 --- a/core/apps/textedit/fileBrowser.cpp +++ b/core/apps/textedit/fileBrowser.cpp @@ -166,28 +166,28 @@ void fileBrowser::setFileView( int selection ) { SelectionCombo->setCurrentItem( selection ); selectionChanged( SelectionCombo->currentText() ); } void fileBrowser::populateList() { ListView->clear(); + QListViewItem * item; bool isDir=FALSE; //qDebug(currentDir.canonicalPath()); currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); currentDir.setMatchAllDirs(TRUE); // 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 { @@ -196,17 +196,17 @@ void fileBrowser::populateList() fileL.sprintf( "%s",fi->fileName().data() ); fileDate= fi->lastModified().toString(); if( QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+fileL)).exists() ) { fileL+="/"; isDir=TRUE; // qDebug( fileL); } } - if(fileL !="./") { + if(fileL !="./" && fi->exists()) { item= new QListViewItem( ListView,fileL,fileS , fileDate); QPixmap pm; if(isDir || fileL.find("/",0,TRUE) != -1) { if( !QDir( fi->filePath() ).isReadable()) pm = Resource::loadPixmap( "lockedfolder" ); else pm= Resource::loadPixmap( "folder" ); @@ -229,16 +229,17 @@ void fileBrowser::populateList() QPainter painter( &pm ); painter.drawPixmap( pm.width()-lnk.width(), pm.height()-lnk.height(), lnk ); pm.setMask( pm.createHeuristicMask( FALSE ) ); item->setPixmap( 0, pm); } } isDir=FALSE; ++it; +// } } ListView->setSorting( 3, FALSE); QString currentPath = currentDir.canonicalPath(); fillCombo( (const QString &)currentPath); // dirPathCombo->lineEdit()->setText(currentPath); // if( dirPathStringList.grep(currentPath,TRUE).isEmpty() ) { @@ -258,16 +259,17 @@ void fileBrowser::upDir() currentDir.cd( current, TRUE); populateList(); update(); } // you may want to switch these 2 functions. I like single clicks void fileBrowser::listClicked(QListViewItem *selectedItem) { + if(selectedItem) { QString strItem=selectedItem->text(0); QString strSize=selectedItem->text(1); // qDebug("strItem is "+strItem); strSize.stripWhiteSpace(); // qDebug(strSize); if(strItem.find("@",0,TRUE) !=-1 || strItem.find("->",0,TRUE) !=-1 ) { //if symlink // is symlink @@ -298,16 +300,17 @@ void fileBrowser::listClicked(QListViewItem *selectedItem) //currentDir.canonicalPath() qDebug("We found our files!!"+strItem); OnOK(); } } //end not symlink chdir(strItem.latin1()); } } +} void fileBrowser::OnOK() { QListViewItemIterator it1( ListView); for ( ; it1.current(); ++it1 ) { if ( it1.current()->isSelected() ) { selectedFileName=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+it1.current()->text(0)); qDebug("selected filename is "+selectedFileName); @@ -373,38 +376,43 @@ void fileBrowser::ListPressed( int mouse, QListViewItem *item, const QPoint &poi showListMenu(item); break; }; } void fileBrowser::showListMenu(QListViewItem *item) { QPopupMenu m;// = new QPopupMenu( Local_View ); + if(item) { 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( "Rename" ), this, SLOT( localRename() )); m.insertSeparator(); m.insertItem( tr( "Delete" ), this, SLOT( localDelete() )); - m.exec( QCursor::pos() ); + } else { + m.insertItem( tr( "Make Directory" ), this, SLOT( makDir() )); + m.insertItem( tr( "Rescan" ), this, SLOT( populateList() )); } + 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(); + qDebug("Make dir"); currentDir.mkdir( currentDir.canonicalPath()+"/"+filename); } populateList(); } void fileBrowser::localRename() { QString curFile = ListView->currentItem()->text(0); InputDialog *fileDlg; @@ -431,17 +439,16 @@ void fileBrowser::localDelete() { system( cmd.latin1()); populateList(); } break; case 1: // exit break; }; - } else { switch ( QMessageBox::warning(this,"Delete","Do you really want to delete\n"+f +" ?","Yes","No",0,0,1) ) { case 0: { f=currentDir.canonicalPath()+"/"+f; QString cmd="rm "+f; system( cmd.latin1()); populateList(); diff --git a/core/apps/textedit/fileBrowser.h b/core/apps/textedit/fileBrowser.h index 339483f..e76c7df 100644 --- a/core/apps/textedit/fileBrowser.h +++ b/core/apps/textedit/fileBrowser.h @@ -62,17 +62,17 @@ public slots: private: // QDict<void> mimes; QPushButton *buttonOk, *buttonCancel, *homeButton, *docButton, *hideButton, *cdUpButton; QListView* ListView; QLabel *dirLabel; QString filterStr, mimeType; QDir currentDir; QStringList dirPathStringList, mimetypes; - QListViewItem * item; +/* QListViewItem * item; */ QComboBox *dirPathCombo; MenuButton *typemb; QWidgetStack *FileStack; FileSelector *fileSelector; QRegExp tf; QStringList getMimeTypes(); void fillCombo( const QString&); diff --git a/core/apps/textedit/fileSaver.cpp b/core/apps/textedit/fileSaver.cpp index 07fb5ba..f2a5355 100644 --- a/core/apps/textedit/fileSaver.cpp +++ b/core/apps/textedit/fileSaver.cpp @@ -9,16 +9,17 @@ ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ****************************************************************************/ #include "fileSaver.h" #include <qpe/config.h> #include <qpe/resource.h> +#include <qpe/mimetype.h> #include <qpe/qpeapplication.h> #include <qlistview.h> #include <qpushbutton.h> #include <qfile.h> #include <qmessagebox.h> #include <qlineedit.h> #include <qcheckbox.h> @@ -42,30 +43,33 @@ fileSaver::fileSaver( QWidget* parent, const char* name, bool modal, WFlags fl homeButton = new QPushButton(Resource::loadIconSet("home"),"",this,"homeButton"); homeButton->setGeometry(200,4,25,25); connect(homeButton,SIGNAL(released()),this,SLOT(homeButtonPushed()) ); homeButton->setFlat(TRUE); docButton = new QPushButton(Resource::loadIconSet("DocsIcon"),"",this,"docsButton"); docButton->setGeometry(170,4,25,25); connect( docButton,SIGNAL(released()),this,SLOT( docButtonPushed()) ); + docButton->setFlat(TRUE); hideButton = new QPushButton( Resource::loadIconSet("textedit/s_hidden"),"",this,"hideButton"); hideButton->setGeometry(140,4,25,25); connect( hideButton,SIGNAL(toggled(bool)),this,SLOT( hideButtonPushed(bool)) ); hideButton->setToggleButton(TRUE); hideButton->setFlat(TRUE); ListView = new QListView( this, "ListView" ); ListView->addColumn( tr( "Name" ) ); - ListView->setColumnWidth(0,140); + ListView->setColumnWidth(0,120); ListView->setSorting( 2, FALSE); ListView->addColumn( tr( "Size" ) ); - ListView->setColumnWidth(1,59); + ListView->setColumnWidth(1,-1); + ListView->addColumn( "Date",-1); + ListView->setColumnWidthMode(0,QListView::Manual); ListView->setColumnAlignment(1,QListView::AlignRight); // ListView->setMultiSelection(true); // ListView->setSelectionMode(QListView::Extended); ListView->setAllColumnsShowFocus( TRUE ); ListView->setGeometry( QRect( 10,35,220,125)); @@ -92,21 +96,22 @@ fileSaver::fileSaver( QWidget* parent, const char* name, bool modal, WFlags fl fileSaver::~fileSaver() { } void fileSaver::populateList() { ListView->clear(); + bool isDir=FALSE; currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); currentDir.setMatchAllDirs(TRUE); currentDir.setNameFilter("*"); - QString fileL, fileS; + 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); @@ -115,20 +120,52 @@ void fileSaver::populateList() fileL.sprintf( "%s -> %s", sym.fileName().data(),sym.absFilePath().data() ); } else { // // qDebug("Not a dir: "+currentDir.canonicalPath()+fileL); fileS.sprintf( "%10li", fi->size() ); fileL.sprintf( "%s",fi->fileName().data() ); if( QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+fileL)).exists() ) { fileL+="/"; + isDir=TRUE; // qDebug(currentDir.canonicalPath()+fileL); } } - item= new QListViewItem( ListView,fileL,fileS ); + if(fileL !="./") { + item= new QListViewItem( ListView,fileL,fileS , fileDate); + QPixmap pm; + + if(isDir || fileL.find("/",0,TRUE) != -1) { + if( !QDir( fi->filePath() ).isReadable()) + pm = Resource::loadPixmap( "lockedfolder" ); + else + pm= Resource::loadPixmap( "folder" ); + item->setPixmap( 0,pm ); + } else { + if( !fi->isReadable() ) + pm = Resource::loadPixmap( "locked" ); + else { + MimeType mt(fi->filePath()); + pm=mt.pixmap(); + if(pm.isNull()) + pm = Resource::loadPixmap( "UnknownDocument-14" ); + item->setPixmap( 0,pm); + } + } + if( fileL.find("->",0,TRUE) != -1) { + // overlay link image + pm= Resource::loadPixmap( "folder" ); + QPixmap lnk = Resource::loadPixmap( "symlink" ); + QPainter painter( &pm ); + painter.drawPixmap( pm.width()-lnk.width(), pm.height()-lnk.height(), lnk ); + pm.setMask( pm.createHeuristicMask( FALSE ) ); + item->setPixmap( 0, pm); + } + } + isDir=FALSE; ++it; } ListView->setSorting( 2, FALSE); dirLabel->setText(currentDir.canonicalPath()); } |