-rw-r--r-- | noncore/apps/advancedfm/advancedfm.cpp | 55 | ||||
-rw-r--r-- | noncore/apps/advancedfm/advancedfm.h | 7 |
2 files changed, 51 insertions, 11 deletions
diff --git a/noncore/apps/advancedfm/advancedfm.cpp b/noncore/apps/advancedfm/advancedfm.cpp index d4351b0..6b7fa1f 100644 --- a/noncore/apps/advancedfm/advancedfm.cpp +++ b/noncore/apps/advancedfm/advancedfm.cpp @@ -1,252 +1,255 @@ /*************************************************************************** AdvancedFm.cpp ------------------- ** Created: Sat Mar 9 23:33:09 2002 copyright : (C) 2002 by ljp email : ljp@llornkcor.com * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * ***************************************************************************/ #define DEVELOPERS_VERSION #include "advancedfm.h" // #include <opie/ofileselector.h> // #include <opie/ofiledialog.h> #include <opie/otabwidget.h> #include <qpe/filemanager.h> #include <qpe/qcopenvelope_qws.h> #include <qpe/qpeapplication.h> #include <qpe/config.h> #include <qpe/mimetype.h> #include <qpe/applnk.h> #include <qpe/ir.h> #include <qpe/resource.h> #include <qpe/menubutton.h> #include <qdatetime.h> #include <qfile.h> #include <qcombobox.h> #include <qpopupmenu.h> #include <qlistview.h> #include <qlabel.h> #include <qwidget.h> #include <qlayout.h> #include <qimage.h> #include <qmessagebox.h> #include <qlineedit.h> #include <sys/stat.h> #include <time.h> #include <dirent.h> #include <fcntl.h> #include <sys/vfs.h> #include <mntent.h> AdvancedFm::AdvancedFm( ) : QMainWindow( ) { init(); renameBox = 0; unknownXpm = Resource::loadImage( "UnknownDocument" ).smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() ); initConnections(); whichTab=1; rePopulate(); currentPathCombo->setFocus(); + channel = new QCopChannel( "QPE/Application/advancedfm", this ); + connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), + this, SLOT( qcopReceive(const QCString&, const QByteArray&)) ); } AdvancedFm::~AdvancedFm() { } void AdvancedFm::cleanUp() { QString sfile=QDir::homeDirPath(); if(sfile.right(1) != "/") sfile+="/._temp"; else sfile+="._temp"; QFile file( sfile); if(file.exists()) file.remove(); } void AdvancedFm::tabChanged(QWidget *w) { if( w == tab) whichTab = 1; else whichTab = 2; // qDebug("tab changed %d", whichTab ); QString path = CurrentDir()->canonicalPath(); currentPathCombo->lineEdit()->setText( path ); viewMenu->setItemChecked(viewMenu->idAt(0),TRUE); viewMenu->setItemChecked(viewMenu->idAt(1),FALSE); QString fs= getFileSystemType( (const QString &) path); setCaption("AdvancedFm :: "+fs+" :: " +checkDiskSpace( (const QString &) path )+ " kB free" ); chdir( path.latin1()); } void AdvancedFm::populateView() { QPixmap pm; QListView *thisView = CurrentView(); QDir *thisDir = CurrentDir(); QString path = thisDir->canonicalPath(); thisView->clear(); thisDir->setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); thisDir->setMatchAllDirs(TRUE); thisDir->setNameFilter(filterStr); QString fileL, fileS, fileDate; QString fs= getFileSystemType((const QString &) path); setCaption("AdvancedFm :: "+fs+" :: " +checkDiskSpace((const QString &) path)+" kB free" ); bool isDir=FALSE; const QFileInfoList *list = thisDir->entryInfoList( /*QDir::All*/ /*, QDir::SortByMask*/); QFileInfoListIterator it(*list); QFileInfo *fi; while ( (fi=it.current()) ) { if (fi->isSymLink() ) { QString symLink=fi->readLink(); QFileInfo sym( symLink); fileS.sprintf( "%10i", sym.size() ); fileL.sprintf( "%s -> %s", fi->fileName().data(),sym.filePath().data() ); fileDate = sym.lastModified().toString(); } else { fileS.sprintf( "%10i", fi->size() ); fileL.sprintf( "%s",fi->fileName().data() ); fileDate= fi->lastModified().toString(); if( QDir(QDir::cleanDirPath( path +"/"+fileL)).exists() ) { fileL+="/"; isDir=TRUE; } } QFileInfo fileInfo( path + "/" + fileL); if(fileL !="./" && fi->exists()) { item= new QListViewItem( thisView, fileL, fileS , fileDate); if(isDir || fileL.find("/",0,TRUE) != -1) { if( !QDir( fi->filePath() ).isReadable()) //is directory pm = Resource::loadPixmap( "lockedfolder" ); else pm= Resource::loadPixmap( "folder" ); } else if ( fs == "vfat" && fileInfo.filePath().contains("/bin") ) { pm = Resource::loadPixmap( "exec"); } else if( (fileInfo.permission( QFileInfo::ExeUser) | fileInfo.permission( QFileInfo::ExeGroup) | fileInfo.permission( QFileInfo::ExeOther)) && fs != "vfat" ) { pm = Resource::loadPixmap( "exec"); } else if( !fi->isReadable() ) { pm = Resource::loadPixmap( "locked" ); } else { //everything else goes by mimetype MimeType mt(fi->filePath()); pm=mt.pixmap(); //sets the correct pixmap for mimetype if(pm.isNull()) { pm = unknownXpm; } } if( fi->isSymLink() && fileL.find("->",0,TRUE) != -1) { // overlay link image pm= Resource::loadPixmap( "folder" ); QPixmap lnk = Resource::loadPixmap( "opie/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; } if( path.find("dev",0,TRUE) != -1) { struct stat buf; dev_t devT; DIR *dir; struct dirent *mydirent; if((dir = opendir( path.latin1())) != NULL) while ((mydirent = readdir(dir)) != NULL) { lstat( mydirent->d_name, &buf); // qDebug(mydirent->d_name); fileL.sprintf("%s", mydirent->d_name); devT = buf.st_dev; fileS.sprintf("%d, %d", (int) ( devT >>8) &0xFF, (int)devT &0xFF); fileDate.sprintf("%s", ctime( &buf.st_mtime)); if( fileL.find(".") == -1 ) { item= new QListViewItem( thisView, fileL, fileS, fileDate); pm = unknownXpm; item->setPixmap( 0,pm); } } closedir(dir); } thisView->setSorting( 3,FALSE); fillCombo( (const QString &) path ); } void AdvancedFm::rePopulate() { int tmpTab = whichTab; qDebug("%d", tmpTab); for(int i =1; i < 3; i++) { TabWidget->setCurrentTab(i - 1); populateView(); } TabWidget->setCurrentTab( tmpTab - 1); } void AdvancedFm::ListClicked(QListViewItem *selectedItem) { if(selectedItem) { QString strItem=selectedItem->text(0); QString strSize=selectedItem->text(1); strSize=strSize.stripWhiteSpace(); bool isDirectory = false; QString strItem2; if(strItem.find("@",0,TRUE) !=-1 || strItem.find("->",0,TRUE) !=-1 )//if symlink { strItem2 = dealWithSymName((const QString&)strItem); if(QDir(strItem2).exists() ) strItem = strItem2; @@ -617,263 +620,293 @@ void AdvancedFm::showFileMenu() n->insertItem( tr( "Copy Same Dir" ), this, SLOT( copySameDir() )); n->insertItem( tr( "Move" ), this, SLOT( move() )); n->insertSeparator(); n->insertItem( tr( "Delete" ), this, SLOT( doDelete() )); m->insertItem( tr( "Add To Documents" ), this, SLOT( addToDocs() )); m->insertItem( tr( "Run Command" ), this, SLOT( runCommand() )); m->insertItem( tr( "File Info" ), this, SLOT( fileStatus() )); m->insertSeparator(); m->insertItem( tr( "Set Permissions" ), this, SLOT( filePerms() )); #if defined(QT_QWS_OPIE) m->insertItem( tr( "Properties" ), this, SLOT( doProperties() )); #endif m->setCheckable(TRUE); if (!b) m->setItemChecked(m->idAt(0),TRUE); else m->setItemChecked(m->idAt(0),FALSE); if(Ir::supported()) m->insertItem( tr( "Beam File" ), this, SLOT( doBeam() )); m->setFocus(); m->exec( QPoint( 4,QCursor::pos().y()) ); if(m) delete m; } void AdvancedFm::cancelMenuTimer() { // qDebug("selectionChanged: cancel menu timer"); if( menuTimer.isActive() ) menuTimer.stop(); } QString AdvancedFm::checkDiskSpace(const QString &path) { struct statfs fss; if ( !statfs( path.latin1(), &fss ) ) { int blkSize = fss.f_bsize; // int totalBlks = fs.f_blocks; int availBlks = fss.f_bavail; long mult = blkSize / 1024; long div = 1024 / blkSize; if ( !mult ) mult = 1; if ( !div ) div = 1; return QString::number(availBlks * mult / div); } return ""; } void AdvancedFm::addToDocs() { QStringList strListPaths = getPath(); QDir *thisDir = CurrentDir(); if( strListPaths.count() > 0) { QString curFile; for ( QStringList::Iterator it = strListPaths.begin(); it != strListPaths.end(); ++it ) { curFile = thisDir->canonicalPath()+"/"+(*it); // qDebug(curFile); DocLnk f; // curFile.replace(QRegExp("\\..*"),""); f.setName((*it)); f.setFile( curFile); f.writeLink(); } } } void AdvancedFm::customDirsToMenu() { Config cfg("AdvancedFm"); cfg.setGroup("Menu"); QStringList list = cfg.readListEntry( "CustomDir", ','); menuButton->insertItems(list ); // for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) // { // customDirMenu->insertItem(*it ); // } } void AdvancedFm::dirMenuSelected(int item) { qDebug("menu item %d", item); switch(item) { case -21: case 0: addCustomDir(); break; case -22: case 1: removeCustomDir(); break; default: { // gotoCustomDir( menuButton->text(item)); // gotoCustomDir( customDirMenu->text(item)); } break; }; } void AdvancedFm::addCustomDir() { Config cfg("AdvancedFm"); cfg.setGroup("Menu"); QString dir; QStringList list = cfg.readListEntry( (const QString &)"CustomDir", (const QChar)','); dir = CurrentDir()->canonicalPath(); bool addIt=true; for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { if( dir == (*it)) { addIt=false; } } if(addIt) { menuButton->insertItem(dir); // customDirMenu->insertItem(dir); list << dir; } cfg.writeEntry("CustomDir", list, ','); cfg.write(); } void AdvancedFm::removeCustomDir() { // qDebug("remove custom dir"); Config cfg("AdvancedFm"); cfg.setGroup("Menu"); QString dir; QStringList list = cfg.readListEntry( (const QString &)"CustomDir", (const QChar)','); QStringList list2; dir = CurrentDir()->canonicalPath(); int ramble=2; // int ramble=-24; //first remove list if(list.grep(dir,true).isEmpty()) { QMessageBox::message(tr( "AdvancedFm" ), tr("Cannot remove current directory\nfrom bookmarks.\nIt is not bookmarked!")); } else { for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { if((*it) != dir)//current item is not our current dir, so add it to temp list { list2 <<(*it); } else { // customDirMenu->removeItem( ramble); menuButton->remove( ramble); } ramble++; // ramble--; } cfg.writeEntry("CustomDir", list2, ','); cfg.write(); } // customDirsToMenu(); } void AdvancedFm::gotoCustomDir(const QString &dir) { // qDebug("gotoCustomDir(const QString &dir) " +dir ); - QString curDir = dir; - QDir *thisDir = CurrentDir(); +// QString curDir = dir; +// QDir *thisDir = CurrentDir(); // if( curDir.isEmpty()) { // } - if( curDir == s_addBookmark) + if( dir == s_addBookmark) { addCustomDir(); } - if( curDir == s_removeBookmark) + if( dir == s_removeBookmark) { removeCustomDir( ); } else { - if(QDir( curDir).exists() ) - { - thisDir->setPath( curDir ); - chdir( curDir.latin1() ); - thisDir->cd( curDir, TRUE); - populateView(); - } + gotoDirectory( dir); +// if(QDir( curDir).exists() ) +// { +// thisDir->setPath( curDir ); +// chdir( curDir.latin1() ); +// thisDir->cd( curDir, TRUE); +// populateView(); +// } } } QDir *AdvancedFm::CurrentDir() { if ( whichTab == 1) { return ¤tDir; } else { return ¤tRemoteDir; } } QDir *AdvancedFm::OtherDir() { if ( whichTab == 1) { return ¤tRemoteDir; } else { return ¤tDir; } } QListView * AdvancedFm::CurrentView() { if ( whichTab == 1) return Local_View; else return Remote_View; } QListView * AdvancedFm::OtherView() { if ( whichTab == 1) return Remote_View; else return Local_View; } void AdvancedFm::setOtherTabCurrent() { if ( whichTab == 1) TabWidget->setCurrentTab(1); else TabWidget->setCurrentTab(0); } + +void AdvancedFm::qcopReceive(const QCString &msg, const QByteArray &data) { + qDebug("qcop message "+msg ); + QDataStream stream ( data, IO_ReadOnly ); + if ( msg == "openDirectory(QString)" ) { + qDebug("received"); + QString file; + stream >> file; + gotoDirectory( (const QString &) file); + } +} + + void AdvancedFm::setDocument(const QString &file) { + gotoDirectory( file); + + } + +void AdvancedFm::gotoDirectory(const QString &file) { + + QString curDir = file; + QDir *thisDir = CurrentDir(); + + if(QDir( curDir).exists() ) { + thisDir->setPath( curDir ); + chdir( curDir.latin1() ); + thisDir->cd( curDir, TRUE); + populateView(); + } +} diff --git a/noncore/apps/advancedfm/advancedfm.h b/noncore/apps/advancedfm/advancedfm.h index 4480051..c9a5525 100644 --- a/noncore/apps/advancedfm/advancedfm.h +++ b/noncore/apps/advancedfm/advancedfm.h @@ -1,171 +1,178 @@ /*************************************************************************** advancedfm.h ------------------- ** Created: Sat Mar 9 23:33:09 2002 copyright : (C) 2002 by ljp email : ljp@llornkcor.com * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * ***************************************************************************/ #ifndef ADVANCEDFM_H #define ADVANCEDFM_H #define QTOPIA_INTERNAL_FSLP // to get access to fileproperties #define QT_QWS_OPIE //#include <opie/otabwidget.h> #include <opie/oprocess.h> + #include <qpe/ir.h> +#include <qpe/qcopenvelope_qws.h> #include <qvariant.h> #include <qdialog.h> #include <qmainwindow.h> #include <qstringlist.h> #include <qdir.h> #include <qstring.h> #include <qpoint.h> #include <qtimer.h> #include <qpixmap.h> class OTabWidget; class QVBoxLayout; class QHBoxLayout; class QGridLayout; class QComboBox; class QListView; class QListviewItem; class QLabel; class QProgressBar; class QSpinBox; class QTabWidget; class QWidget; class QPopupMenu; class QFile; class QListViewItem; class QLineEdit; class MenuButton; class QToolButton; class Ir; class AdvancedFm : public QMainWindow { Q_OBJECT public: AdvancedFm(); ~AdvancedFm(); protected slots: void selectAll(); void addToDocs(); void doDirChange(); void mkDir(); void del(); void rn(); void populateView(); void rePopulate(); void showHidden(); void showMenuHidden(); void writeConfig(); void readConfig(); void ListClicked(QListViewItem *); void ListPressed( int, QListViewItem *, const QPoint&, int); void makeDir(); void doDelete(); void tabChanged(QWidget*); void cleanUp(); void renameIt(); void runThis(); void runText(); void filePerms(); void doProperties(); void runCommand(); void runCommandStd(); QStringList getPath(); void mkSym(); void switchToLocalTab(); void switchToRemoteTab(); protected: OTabWidget *TabWidget; + QCopChannel * channel; QPixmap unknownXpm; int whichTab; // QTabWidget *TabWidget; QWidget *tab, *tab_2, *tab_3; QListView *Local_View, *Remote_View; QLineEdit *currentPathEdit; QPopupMenu *fileMenu, *localMenu, *remoteMenu, *viewMenu /*, *customDirMenu*/; QToolButton *homeButton, *docButton, *cdUpButton, *sdButton, *cfButton, *qpeDirButton; // QPushButton *homeButton, *docButton, *cdUpButton, *sdButton, *cfButton, *qpeDirButton; QDir currentDir, currentRemoteDir; QComboBox *currentPathCombo; QString filterStr, s_addBookmark, s_removeBookmark; QListViewItem * item; bool b; QStringList fileSystemTypeList, fsList; int currentServerConfig; bool zaurusDevice; QGridLayout *tabLayout, *tabLayout_2, *tabLayout_3; QStringList remoteDirPathStringList, localDirPathStringList; QLineEdit *renameBox; void init(); void initConnections(); void keyReleaseEvent( QKeyEvent *); void keyPressEvent( QKeyEvent *); QString getFileSystemType(const QString &); QString getDiskSpace(const QString &); void parsetab(const QString &fileName); QString checkDiskSpace(const QString &); QString dealWithSymName(const QString &); QDir *CurrentDir(); QDir *OtherDir(); QListView *CurrentView(); QListView *OtherView(); void setOtherTabCurrent(); protected slots: void dirMenuSelected(int); void showFileMenu(); void cancelMenuTimer(); void homeButtonPushed(); void docButtonPushed(); void SDButtonPushed(); void CFButtonPushed(); void QPEButtonPushed(); void upDir(); void currentPathComboChanged(); void copy(); void copyAs(); void copySameDir(); void currentPathComboActivated(const QString &); void fillCombo(const QString &); bool copyFile( const QString & , const QString & ); void move(); void fileStatus(); void doAbout(); void doBeam(); void fileBeamFinished( Ir *); private: MenuButton *menuButton; QString oldName; QTimer menuTimer; void startProcess(const QString &); bool eventFilter( QObject * , QEvent * ); void cancelRename(); void doRename(QListView *); void okRename(); void customDirsToMenu(); void addCustomDir(); void removeCustomDir(); + void gotoDirectory(const QString &); private slots: void processEnded(OProcess *); void oprocessStderr(OProcess *, char *, int); void gotoCustomDir(const QString &); + void qcopReceive(const QCString&, const QByteArray&); + void setDocument(const QString &); + }; #endif // ADVANCEDFM_H |