author | llornkcor <llornkcor> | 2002-03-16 15:16:58 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-03-16 15:16:58 (UTC) |
commit | 1d20ca78752b9da597950087438daa9ff8cb7951 (patch) (side-by-side diff) | |
tree | 5cce2048ba6cd8fd16e98bf9f4ab8c5ead4fe8b3 | |
parent | 585373903040f7d283c8fef1841147739f0510d8 (diff) | |
download | opie-1d20ca78752b9da597950087438daa9ff8cb7951.zip opie-1d20ca78752b9da597950087438daa9ff8cb7951.tar.gz opie-1d20ca78752b9da597950087438daa9ff8cb7951.tar.bz2 |
added cd to stylus hold, so user doesn't have to double click
-rw-r--r-- | noncore/net/opieftp/opieftp.cpp | 29 | ||||
-rw-r--r-- | noncore/net/opieftp/opieftp.h | 6 |
2 files changed, 28 insertions, 7 deletions
diff --git a/noncore/net/opieftp/opieftp.cpp b/noncore/net/opieftp/opieftp.cpp index 523a36c..ed7f4bb 100644 --- a/noncore/net/opieftp/opieftp.cpp +++ b/noncore/net/opieftp/opieftp.cpp @@ -319,404 +319,423 @@ void OpieFtp::connector() } FtpInit(); TabWidget->setCurrentPage(1); QString ftp_host = ServerComboBox->currentText(); QString ftp_user = UsernameComboBox->currentText(); QString ftp_pass = PasswordEdit->text(); QString port=PortSpinBox->cleanText(); port.stripWhiteSpace(); if(ftp_host.find("ftp://",0, TRUE) != -1 ) ftp_host=ftp_host.right(ftp_host.length()-6); ftp_host+=":"+port; if (!FtpConnect( ftp_host.latin1(), &conn)) { QMessageBox::message("Note","Unable to connect to\n"+ftp_host); return ; } if (!FtpLogin( ftp_user.latin1(), ftp_pass.latin1(),conn )) { QString msg; msg.sprintf("Unable to log in\n%s",FtpLastResponse(conn)); msg.replace(QRegExp(":"),"\n"); QMessageBox::message("Note",msg); FtpQuit(conn); return ; } remoteDirList("/") ; setCaption(ftp_host); QCopEnvelope ( "QPE/System", "notBusy()" ); } void OpieFtp::disConnector() { FtpQuit(conn); setCaption("OpieFtp"); currentRemoteDir="/"; Remote_View->clear(); } bool OpieFtp::remoteDirList(const QString &dir) { QCopEnvelope ( "QPE/System", "busy()" ); if (!FtpDir( "./._temp", dir.latin1(), conn) ) { QString msg; msg.sprintf("Unable to list the directory\n"+dir+"\n%s",FtpLastResponse(conn) ); msg.replace(QRegExp(":"),"\n"); QMessageBox::message("Note",msg); // FtpQuit(conn); return false; } populateRemoteView(); QCopEnvelope ( "QPE/System", "notBusy()" ); return true; } bool OpieFtp::remoteChDir(const QString &dir) { QCopEnvelope ( "QPE/System", "busy()" ); if (!FtpChdir( dir.latin1(), conn )) { QString msg; msg.sprintf("Unable to change directories\n"+dir+"\n%s",FtpLastResponse(conn)); msg.replace(QRegExp(":"),"\n"); QMessageBox::message("Note",msg); qDebug(msg); // FtpQuit(conn); QCopEnvelope ( "QPE/System", "notBusy()" ); return FALSE; } QCopEnvelope ( "QPE/System", "notBusy()" ); return TRUE; } void OpieFtp::populateLocalView() { Local_View->clear(); currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); currentDir.setMatchAllDirs(TRUE); currentDir.setNameFilter(filterStr); 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+="/"; // qDebug( fileL); } } item= new QListViewItem( Local_View,fileL,fileS, fileDate); ++it; } Local_View->setSorting( 3,FALSE); currentPathEdit->setText( currentDir.canonicalPath() ); } bool OpieFtp::populateRemoteView() { Remote_View->clear(); QFile tmp("./._temp"); QString s, File_Name; QString fileL, fileS, fileDate; new QListViewItem( Remote_View, "../"); if (tmp.open(IO_ReadOnly)) { QTextStream t( &tmp ); // use a text stream while ( !t.eof()) { s = t.readLine(); fileL = s.right(s.length()-55); fileL = fileL.stripWhiteSpace(); if(s.left(1) == "d") fileL = fileL+"/"; fileS = s.mid( 30, 42-30); fileS = fileS.stripWhiteSpace(); fileDate = s.mid( 42, 55-42); fileDate = fileDate.stripWhiteSpace(); if(fileL.find("total",0,TRUE) == -1) new QListViewItem( Remote_View, fileL, fileS, fileDate); } tmp.close(); - } + } else + qDebug("temp file not opened successfullly"); return true; } void OpieFtp::remoteListClicked(QListViewItem *selectedItem) { QCopEnvelope ( "QPE/System", "busy()" ); QString oldRemoteCurrentDir = currentRemoteDir; QString strItem=selectedItem->text(0); strItem=strItem.simplifyWhiteSpace(); if(strItem == "../") { // the user wants to go ^ if( FtpCDUp( conn) == 0) { QString msg; msg.sprintf("Unable to cd up\n%s",FtpLastResponse(conn)); msg.replace(QRegExp(":"),"\n"); QMessageBox::message("Note",msg); qDebug(msg); } char path[256]; if( FtpPwd( path,sizeof(path),conn) == 0) { //this is easier than fudging the string QString msg; msg.sprintf("Unable to get working dir\n%s",FtpLastResponse(conn)); msg.replace(QRegExp(":"),"\n"); QMessageBox::message("Note",msg); qDebug(msg); } currentRemoteDir=path; } else { if(strItem.find("->",0,TRUE) != -1) { //symlink on some servers strItem=strItem.right( strItem.length() - strItem.find("->",0,TRUE) - 2 ); strItem = strItem.stripWhiteSpace(); currentRemoteDir = strItem; if( !remoteChDir( (const QString &)strItem)) { currentRemoteDir = oldRemoteCurrentDir; strItem=""; populateRemoteView(); qDebug("RemoteCurrentDir1 "+oldRemoteCurrentDir); } } else if(strItem.find("/",0,TRUE) != -1) { // this is a directory qDebug("trying directory"); if( !remoteChDir( (const QString &)currentRemoteDir + strItem)) { currentRemoteDir = oldRemoteCurrentDir; strItem=""; qDebug("RemoteCurrentDir1 "+oldRemoteCurrentDir); populateRemoteView(); } else { currentRemoteDir = currentRemoteDir+strItem; } } else { qDebug("download "+strItem); } } if(currentRemoteDir.right(1) !="/") currentRemoteDir +="/"; currentPathEdit->setText( currentRemoteDir ); remoteDirList( (const QString &)currentRemoteDir); QCopEnvelope ( "QPE/System", "notBusy()" ); } void OpieFtp::localListClicked(QListViewItem *selectedItem) { QString strItem=selectedItem->text(0); QString strSize=selectedItem->text(1); strSize=strSize.stripWhiteSpace(); if(strItem.find("@",0,TRUE) !=-1 || strItem.find("->",0,TRUE) !=-1 ) { //if symlink // is symlink QString strItem2 = strItem.right( (strItem.length() - strItem.find("->",0,TRUE)) - 4); if(QDir(strItem2).exists() ) { currentDir.cd(strItem2, TRUE); populateLocalView(); } } else { // not a symlink if(strItem.find(". .",0,TRUE) && strItem.find("/",0,TRUE)!=-1 ) { if(QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem)).exists() ) { strItem=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem); currentDir.cd(strItem,FALSE); populateLocalView(); } else { currentDir.cdUp(); populateLocalView(); } if(QDir(strItem).exists()){ currentDir.cd(strItem, TRUE); populateLocalView(); } } else { strItem=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem); if( QFile::exists(strItem ) ) { qDebug("upload "+strItem); } } //end not symlink chdir(strItem.latin1()); } } +void OpieFtp::doLocalCd() +{ + localListClicked( Local_View->currentItem()); +} + +void OpieFtp:: doRemoteCd() +{ + remoteListClicked( Remote_View->currentItem()); + +} + void OpieFtp::showHidden() { if (!b) { currentDir.setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All); // currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); b=TRUE; } else { currentDir.setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden*/ | QDir::All); // currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); b=FALSE; } populateLocalView(); } void OpieFtp::ListPressed( int mouse, QListViewItem *item, const QPoint &point, int i) { switch (mouse) { case 1: break; case 2: - showLocalMenu(); + showLocalMenu(item); break; }; } void OpieFtp::RemoteListPressed( int mouse, QListViewItem *item, const QPoint &point, int i) { switch (mouse) { case 1: break; case 2: - showRemoteMenu(); + showRemoteMenu(item); break; }; } -void OpieFtp::showRemoteMenu() +void OpieFtp::showRemoteMenu(QListViewItem * item) { QPopupMenu m;// = new QPopupMenu( Local_View ); + if(item->text(0).right(1) == "/") + m.insertItem( tr( "Change Directory" ), this, SLOT( doRemoteCd() )); + else m.insertItem( tr( "Download" ), this, SLOT( remoteDownload() )); m.insertItem( tr( "Make Directory" ), this, SLOT( remoteMakDir() )); m.insertItem( tr( "Rename" ), this, SLOT( remoteRename() )); m.insertSeparator(); m.insertItem( tr( "Delete" ), this, SLOT( remoteDelete() )); m.exec( QCursor::pos() ); } -void OpieFtp::showLocalMenu() +void OpieFtp::showLocalMenu(QListViewItem * item) { QPopupMenu m; m.insertItem( tr( "Show Hidden Files" ), this, SLOT( showHidden() )); + m.insertSeparator(); + if(item->text(0).right(1) == "/") + m.insertItem( tr( "Change Directory" ), this, SLOT( doLocalCd() )); + else m.insertItem( tr( "Upload" ), this, SLOT( localUpload() )); m.insertItem( tr( "Make Directory" ), this, SLOT( localMakDir() )); m.insertItem( tr( "Rename" ), this, SLOT( localRename() )); m.insertSeparator(); m.insertItem( tr( "Delete" ), this, SLOT( localDelete() )); m.exec( QCursor::pos() ); } void OpieFtp::localMakDir() { 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); } populateLocalView(); } void OpieFtp::localDelete() { QString f = Local_View->currentItem()->text(0); if(QDir(f).exists() ) { switch ( QMessageBox::warning(this,"Delete","Do you really want to delete\n"+f+ " ?\nIt must be empty","Yes","No",0,0,1) ) { case 0: { f=currentDir.canonicalPath()+"/"+f; QString cmd="rmdir "+f; system( cmd.latin1()); populateLocalView(); } 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()); populateLocalView(); } break; case 1: // exit break; }; } } void OpieFtp::remoteMakDir() { InputDialog *fileDlg; fileDlg = new InputDialog(this,"Make Directory",TRUE, 0); fileDlg->exec(); if( fileDlg->result() == 1 ) { QString filename = fileDlg->LineEdit1->text();//+".playlist"; QString tmp=currentRemoteDir+filename; QCopEnvelope ( "QPE/System", "busy()" ); if(FtpMkdir( tmp.latin1(), conn) == 0) { QString msg; msg.sprintf("Unable to make directory\n%s",FtpLastResponse(conn)); msg.replace(QRegExp(":"),"\n"); QMessageBox::message("Note",msg); } QCopEnvelope ( "QPE/System", "notBusy()" ); } populateRemoteView(); } void OpieFtp::remoteDelete() { QString f = Remote_View->currentItem()->text(0); QCopEnvelope ( "QPE/System", "busy()" ); if( f.right(1) =="/") { QString path= currentRemoteDir+f; switch ( QMessageBox::warning(this,"Delete","Do you really want to delete\n"+f+"?" ,"Yes","No",0,0,1) ) { case 0: { f=currentDir.canonicalPath()+"/"+f; if(FtpRmdir( path.latin1(), conn) ==0) { QString msg; msg.sprintf("Unable to remove directory\n%s",FtpLastResponse(conn)); msg.replace(QRegExp(":"),"\n"); QMessageBox::message("Note",msg); } } break; }; } else { switch ( QMessageBox::warning(this,"Delete","Do you really want to delete\n"+f+"?" ,"Yes","No",0,0,1) ) { case 0: { QString path= currentRemoteDir+f; if(FtpDelete( path.latin1(), conn)==0) { QString msg; msg.sprintf("Unable to delete file\n%s",FtpLastResponse(conn)); msg.replace(QRegExp(":"),"\n"); QMessageBox::message("Note",msg); } } break; }; } QCopEnvelope ( "QPE/System", "notBusy()" ); } void OpieFtp::remoteRename() { QString curFile = Remote_View->currentItem()->text(0); InputDialog *fileDlg; fileDlg = new InputDialog(this,"Rename",TRUE, 0); fileDlg->inputText = curFile; fileDlg->exec(); if( fileDlg->result() == 1 ) { QString oldName = currentRemoteDir +"/"+ curFile; QString newName = currentRemoteDir +"/"+ fileDlg->LineEdit1->text();//+".playlist"; QCopEnvelope ( "QPE/System", "busy()" ); if(FtpRename( oldName.latin1(), newName.latin1(),conn) == 0) { QString msg; msg.sprintf("Unable to rename file\n%s",FtpLastResponse(conn)); msg.replace(QRegExp(":"),"\n"); QMessageBox::message("Note",msg); diff --git a/noncore/net/opieftp/opieftp.h b/noncore/net/opieftp/opieftp.h index e00a398..5d1c63d 100644 --- a/noncore/net/opieftp/opieftp.h +++ b/noncore/net/opieftp/opieftp.h @@ -1,95 +1,97 @@ /*************************************************************************** opieftp.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 OPIEFTP_H #define OPIEFTP_H #include <qvariant.h> #include <qdialog.h> #include <qmainwindow.h> #include <qdir.h> #include <qstring.h> #include <qpoint.h> class QVBoxLayout; class QHBoxLayout; class QGridLayout; class QComboBox; class QListView; class QListviewItem; class QLabel; class QProgressBar; class QSpinBox; class QTabWidget; class QWidget; class QPEToolBar; class QPEMenuBar; class QPopupMenu; class QFile; class QListViewItem; class QLineEdit; class OpieFtp : public QMainWindow { Q_OBJECT public: OpieFtp( ); ~OpieFtp(); QTabWidget *TabWidget; QWidget *tab, *tab_2, *tab_3;; QListView *Local_View, *Remote_View; QComboBox *UsernameComboBox, *ServerComboBox; QLineEdit *PasswordEdit, *remotePath, *currentPathEdit; QLabel *TextLabel2, *TextLabel1, *TextLabel3, *TextLabel4;; QSpinBox* PortSpinBox; QPopupMenu *connectionMenu, *localMenu, *remoteMenu; QDir currentDir; QString currentRemoteDir; QString filterStr; QListViewItem * item; bool b; protected slots: - void showLocalMenu( ); - void showRemoteMenu( ); + void showLocalMenu( QListViewItem *); + void showRemoteMenu( QListViewItem *); + void doLocalCd(); + void doRemoteCd(); void localUpload(); void remoteDownload(); void newConnection(); void connector(); void disConnector(); void populateLocalView(); bool populateRemoteView(); void showHidden(); void localListClicked(QListViewItem *); void remoteListClicked(QListViewItem *); void ListPressed( int, QListViewItem *, const QPoint&, int); void RemoteListPressed( int, QListViewItem *, const QPoint&, int); void localMakDir(); void localDelete(); void remoteMakDir(); void remoteDelete(); bool remoteDirList(const QString &); bool remoteChDir(const QString &); void tabChanged(QWidget*); void cleanUp(); void remoteRename(); void localRename(); void currentPathEditChanged(); protected: void nullifyCallBack(); }; #endif // OPIEFTP_H |