Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

opieftp.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002    opieftp.cpp
00003                              -------------------
00004 ** Created: Sat Mar 9 23:33:09 2002
00005     copyright            : (C) 2002 by ljp
00006     email                : ljp@llornkcor.com
00007  *   This program is free software; you can redistribute it and/or modify  *
00008  *   it under the terms of the GNU General Public License as published by  *
00009  *   the Free Software Foundation; either version 2 of the License, or     *
00010  *   (at your option) any later version.                                   *
00011  ***************************************************************************/
00012 //#define DEVELOPERS_VERSION
00013 
00014 #include "opieftp.h"
00015 
00016 extern "C" {
00017 #include <ftplib.h>
00018 }
00019 
00020 #include "inputDialog.h"
00021 
00022 /* OPIE */
00023 //#include <opie2/odebug.h>
00024 //using namespace Opie::Core;
00025 
00026 #include <opie2/oresource.h>
00027 
00028 #include <qpe/applnk.h>
00029 #include <qpe/config.h>
00030 #include <qpe/mimetype.h>
00031 #include <qpe/qpeapplication.h>
00032 #include <qpe/qpemenubar.h>
00033 
00034 #include <qbitmap.h>
00035 #include <qcombobox.h>
00036 #include <qlabel.h>
00037 #include <qlayout.h>
00038 #include <qlistview.h>
00039 #include <qmenubar.h>
00040 #include <qmessagebox.h>
00041 #include <qprogressbar.h>
00042 #include <qpushbutton.h>
00043 #include <qspinbox.h>
00044 #include <qtabwidget.h>
00045 #include <qtextstream.h>
00046 #include <qtoolbutton.h>
00047 
00048 #include <qlineedit.h>
00049 #include <qlistbox.h>
00050 #include <qvbox.h>
00051 /* STD */
00052 #include <unistd.h>
00053 #include <stdlib.h>
00054 
00055 QProgressBar *ProgressBar;
00056 static netbuf *conn = NULL;
00057 
00058 static int log_progress(netbuf *, int xfered, void *)
00059 {
00060 //    int fsz = *(int *)arg;
00061 //    int pct = (xfered * 100) / fsz;
00062 //      printf("%3d%%\r", pct);
00063 //      fflush(stdout);
00064     ProgressBar->setProgress(xfered);
00065     qApp->processEvents();
00066     return 1;
00067 }
00068 
00069 OpieFtp::OpieFtp( QWidget* , const char*, WFlags)
00070         : QMainWindow( )
00071 {
00072     qDebug("OpieFtp constructor");
00073     setCaption( tr( "OpieFtp" ) );
00074 //              initializeGui();
00075          QTimer::singleShot( 50, this, SLOT(initializeGui() ));
00076 }
00077 
00078 void OpieFtp::initializeGui() {
00079     fuckeduphack=FALSE;
00080 
00081     QVBox* wrapperBox = new QVBox( this );
00082     setCentralWidget( wrapperBox );
00083 
00084     QWidget *view = new QWidget( wrapperBox );
00085 
00086     QGridLayout *layout = new QGridLayout( view );
00087     layout->setSpacing( 1);
00088     layout->setMargin( 1);
00089     connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) );
00090 
00091     QPEMenuBar *menuBar = new QPEMenuBar(view);
00092 //    QMenuBar *menuBar = new QMenuBar(this);
00093 //     QPEToolBar *menuBar = new QPEToolBar(this);
00094 //     menuBar->setHorizontalStretchable( TRUE );
00095 
00096     unknownXpm =  Opie::Core::OResource::loadPixmap( "UnknownDocument", Opie::Core::OResource::SmallIcon );
00097 
00098     connectionMenu  = new QPopupMenu( this );
00099     localMenu  = new QPopupMenu( this );
00100     remoteMenu  = new QPopupMenu( this );
00101     tabMenu = new QPopupMenu( this );
00102 
00103     layout->addMultiCellWidget( menuBar, 0, 0, 0, 2 );
00104 
00105     menuBar->insertItem( tr( "Connection" ), connectionMenu);
00106 //      menuBar->insertItem( tr( "Local" ), localMenu);
00107 //      menuBar->insertItem( tr( "Remote" ), remoteMenu);
00108     menuBar->insertItem( tr( "View" ), tabMenu);
00109 
00110     tabMenu->insertItem( tr( "Local" ), localMenu);
00111     tabMenu->insertItem( tr( "Remote" ), remoteMenu);
00112 
00113     connectionMenu->insertItem( tr( "New" ), this,  SLOT( newConnection() ));
00114     connectionMenu->insertItem( tr( "Connect" ), this,  SLOT( connector() ));
00115     connectionMenu->insertItem( tr( "Disconnect" ), this,  SLOT( disConnector() ));
00116 
00117     localMenu->insertItem( tr( "Show Hidden Files" ), this,  SLOT( showHidden() ));
00118     localMenu->insertSeparator();
00119     localMenu->insertItem( tr( "Upload" ), this, SLOT( localUpload() ));
00120     localMenu->insertItem( tr( "Make Directory" ), this, SLOT( localMakDir() ));
00121     localMenu->insertItem( tr( "Rename" ), this, SLOT( localRename() ));
00122     localMenu->insertSeparator();
00123     localMenu->insertItem( tr( "Delete" ), this, SLOT( localDelete() ));
00124     localMenu->setCheckable(TRUE);
00125 
00126     remoteMenu->insertItem( tr( "Download" ), this, SLOT( remoteDownload() ));
00127     remoteMenu->insertItem( tr( "Make Directory" ), this, SLOT( remoteMakDir() ));
00128     remoteMenu->insertItem( tr( "Rename" ), this, SLOT( remoteRename() ));
00129     remoteMenu->insertSeparator();
00130     remoteMenu->insertItem( tr( "Delete" ), this, SLOT( remoteDelete() ));
00131 
00132     tabMenu->insertSeparator();
00133     tabMenu->insertItem( tr( "Switch to Local" ), this, SLOT( switchToLocalTab() ));
00134     tabMenu->insertItem( tr( "Switch to Remote" ), this, SLOT( switchToRemoteTab() ));
00135     tabMenu->insertItem( tr( "Switch to Config" ), this, SLOT( switchToConfigTab() ));
00136     tabMenu->setCheckable(TRUE);
00137 
00138     bool useBigPix = qApp->desktop()->size().width() > 330;
00139     cdUpButton = new QToolButton( view,"cdUpButton");
00140     cdUpButton->setUsesBigPixmap( useBigPix );
00141     cdUpButton->setPixmap( Opie::Core::OResource::loadPixmap( "up", Opie::Core::OResource::SmallIcon ) );
00142     cdUpButton->setFixedSize( AppLnk::smallIconSize(), AppLnk::smallIconSize() );
00143     connect( cdUpButton ,SIGNAL(released()),this,SLOT( upDir()) );
00144     layout->addMultiCellWidget( cdUpButton, 0, 0, 4, 4 );
00145     cdUpButton->hide();
00146 
00147     homeButton = new QToolButton( view,"homeButton");
00148     homeButton->setUsesBigPixmap( useBigPix );
00149     homeButton->setPixmap( Opie::Core::OResource::loadPixmap( "home", Opie::Core::OResource::SmallIcon ) );
00150     homeButton->setFixedSize( AppLnk::smallIconSize(), AppLnk::smallIconSize() );
00151     connect(homeButton,SIGNAL(released()),this,SLOT(homeButtonPushed()) );
00152     layout->addMultiCellWidget( homeButton, 0, 0, 3, 3);
00153     homeButton->hide();
00154 
00155     TabWidget = new QTabWidget( view, "TabWidget" );
00156     layout->addMultiCellWidget( TabWidget, 1, 1, 0, 4 );
00157 
00158     tab = new QWidget( TabWidget, "tab" );
00159     tabLayout = new QGridLayout( tab );
00160     tabLayout->setSpacing( 2);
00161     tabLayout->setMargin( 2);
00162 
00163     Local_View = new QListView( tab, "Local_View" );
00164 //    Local_View->setResizePolicy( QListView::AutoOneFit );
00165     Local_View->addColumn( tr("File"),150);
00166     Local_View->addColumn( tr("Date"),-1);
00167     Local_View->setColumnAlignment(1,QListView::AlignRight);
00168     Local_View->addColumn( tr("Size"),-1);
00169     Local_View->setColumnAlignment(2,QListView::AlignRight);
00170     Local_View->setAllColumnsShowFocus(TRUE);
00171 
00172     Local_View->setMultiSelection( TRUE);
00173     Local_View->setSelectionMode(QListView::Extended);
00174     Local_View->setFocusPolicy(QWidget::ClickFocus);
00175 
00176     QPEApplication::setStylusOperation( Local_View->viewport(),QPEApplication::RightOnHold);
00177 
00178     tabLayout->addWidget( Local_View, 0, 0 );
00179 
00180      connect( Local_View, SIGNAL( clicked(QListViewItem*)),
00181               this,SLOT( localListClicked(QListViewItem*)) );
00182 //     connect( Local_View, SIGNAL( doubleClicked(QListViewItem*)),
00183 //              this,SLOT( localListClicked(QListViewItem*)) );
00184      connect( Local_View, SIGNAL( mouseButtonPressed(int,QListViewItem*,const QPoint&,int)),
00185               this,SLOT( ListPressed(int,QListViewItem*,const QPoint&,int)) );
00186 
00187     TabWidget->insertTab( tab, tr( "Local" ) );
00188 
00189     tab_2 = new QWidget( TabWidget, "tab_2" );
00190     tabLayout_2 = new QGridLayout( tab_2 );
00191     tabLayout_2->setSpacing( 2);
00192     tabLayout_2->setMargin( 2);
00193 
00194     Remote_View = new QListView( tab_2, "Remote_View" );
00195     Remote_View->addColumn( tr("File"),150);
00196     Remote_View->addColumn( tr("Date"),-1);
00197 //    Remote_View->setColumnAlignment(1,QListView::AlignRight);
00198     Remote_View->addColumn( tr("Size"),-1);
00199     Remote_View->setColumnAlignment(2,QListView::AlignRight);
00200     Remote_View->setColumnAlignment(3,QListView::AlignCenter);
00201     Remote_View->addColumn( tr("Dir"),-1);
00202     Remote_View->setColumnAlignment(4,QListView::AlignRight);
00203     Remote_View->setAllColumnsShowFocus(TRUE);
00204 
00205     Remote_View->setMultiSelection( FALSE);
00206     Remote_View->setSelectionMode(QListView::Extended);
00207     Remote_View->setFocusPolicy(QWidget::ClickFocus);
00208 
00209     QPEApplication::setStylusOperation( Remote_View->viewport(),QPEApplication::RightOnHold);
00210 
00211     connect( Remote_View, SIGNAL( clicked(QListViewItem*)),
00212              this,SLOT( remoteListClicked(QListViewItem*)) );
00213     connect( Remote_View, SIGNAL( mouseButtonPressed(int,QListViewItem*,const QPoint&,int)),
00214              this,SLOT( RemoteListPressed(int,QListViewItem*,const QPoint&,int)) );
00215 
00216     tabLayout_2->addWidget( Remote_View, 0, 0 );
00217 
00218     TabWidget->insertTab( tab_2, tr( "Remote" ) );
00219 
00220     tab_3 = new QWidget( TabWidget, "tab_3" );
00221     tabLayout_3 = new QGridLayout( tab_3 );
00222     tabLayout_3->setSpacing( 2);
00223     tabLayout_3->setMargin( 2);
00224 
00225     TextLabel1 = new QLabel( tab_3, "TextLabel1" );
00226     TextLabel1->setText( tr( "Username" ) );
00227     tabLayout_3->addMultiCellWidget( TextLabel1, 0, 0, 0, 1 );
00228 
00229     UsernameComboBox = new QComboBox( FALSE, tab_3, "UsernameComboBox" );
00230     UsernameComboBox->setEditable(TRUE);
00231     tabLayout_3->addMultiCellWidget( UsernameComboBox, 1, 1, 0, 1 );
00232 
00233     connect( UsernameComboBox,SIGNAL(textChanged(const QString&)),this,
00234              SLOT( UsernameComboBoxEdited(const QString&) ));
00235 
00236     TextLabel2 = new QLabel( tab_3, "TextLabel2" );
00237     TextLabel2->setText( tr( "Password" ) );
00238     tabLayout_3->addMultiCellWidget( TextLabel2, 0, 0, 2, 3 );
00239 
00240     PasswordEdit = new QLineEdit( "", tab_3, "PasswordComboBox" );
00241     PasswordEdit->setEchoMode(QLineEdit::Password);
00242     tabLayout_3->addMultiCellWidget( PasswordEdit, 1, 1, 2, 3 );
00243 
00244     connect( PasswordEdit,SIGNAL(textChanged(const QString&)),this,
00245              SLOT( PasswordEditEdited(const QString&) ));
00246 
00247 //PasswordEdit->setFixedWidth(85);
00248     TextLabel3 = new QLabel( tab_3, "TextLabel3" );
00249     TextLabel3->setText( tr( "Remote server" ) );
00250     tabLayout_3->addMultiCellWidget( TextLabel3, 2, 2, 0, 1 );
00251 
00252     ServerComboBox = new QComboBox( FALSE, tab_3, "ServerComboBox" );
00253     ServerComboBox->setEditable(TRUE);
00254                 ServerComboBox->setAutoCompletion(true);
00255 //              ServerComboBox->blockSignals(true);
00256                 
00257     tabLayout_3->addMultiCellWidget( ServerComboBox, 3, 3, 0, 1 );
00258 
00259     connect(ServerComboBox,SIGNAL(activated(int)),this,SLOT(serverComboSelected(int) ));
00260     connect(ServerComboBox,SIGNAL(textChanged(const QString&)),this,
00261             SLOT(serverComboEdited(const QString&) ));
00262 
00263     QLabel *TextLabel5 = new QLabel( tab_3, "TextLabel5" );
00264     TextLabel5->setText( tr( "Remote path" ) );
00265     tabLayout_3->addMultiCellWidget( TextLabel5, 2, 2, 2, 3 );
00266 
00267 
00268     remotePath = new QLineEdit( "/", tab_3, "remotePath" );
00269     tabLayout_3->addMultiCellWidget( remotePath, 3, 3, 2, 3 );
00270     TextLabel4 = new QLabel( tab_3, "TextLabel4" );
00271     TextLabel4->setText( tr( "Port" ) );
00272     tabLayout_3->addMultiCellWidget( TextLabel4, 4, 4, 0, 1 );
00273 
00274     PortSpinBox = new QSpinBox( tab_3, "PortSpinBox" );
00275     PortSpinBox->setButtonSymbols( QSpinBox::UpDownArrows );
00276     PortSpinBox->setMaxValue(32786);
00277     tabLayout_3->addMultiCellWidget( PortSpinBox, 4, 4, 1, 1);
00278 
00279     serverListView = new QListBox( tab_3, "ServerListView" );
00280     tabLayout_3->addMultiCellWidget( serverListView , 5, 5, 0, 5);
00281 
00282     connect( serverListView, SIGNAL( highlighted(const QString&)),
00283              this,SLOT( serverListClicked(const QString&) ) );
00284 
00285     connectServerBtn = new QPushButton( tr("Connect"), tab_3 , "ConnectButton" );
00286     tabLayout_3->addMultiCellWidget( connectServerBtn, 6, 6, 0, 1);
00287     connectServerBtn->setToggleButton(TRUE);
00288     connect(connectServerBtn,SIGNAL( toggled(bool)),SLOT( connectorBtnToggled(bool) ));
00289 
00290     newServerButton= new QPushButton( tr("Add"), tab_3 , "NewServerButton" );
00291     tabLayout_3->addMultiCellWidget( newServerButton, 6, 6, 2, 2);
00292     connect( newServerButton,SIGNAL( clicked()),SLOT( NewServer() ));
00293 
00294     QPushButton *deleteServerBtn;
00295     deleteServerBtn = new QPushButton( tr("Delete"), tab_3 , "OpenButton" );
00296     tabLayout_3->addMultiCellWidget( deleteServerBtn, 6, 6, 3, 3);
00297 
00298     connect(deleteServerBtn,SIGNAL(clicked()),SLOT(deleteServer()));
00299 
00300 
00301     QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding );
00302     tabLayout_3->addItem( spacer, 5, 0 );
00303 
00304     TabWidget->insertTab( tab_3, tr( "Config" ) );
00305 
00306     connect(TabWidget,SIGNAL(currentChanged(QWidget*)),
00307             this,SLOT(tabChanged(QWidget*)));
00308 
00309     currentDir.setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden*/ | QDir::All);
00310     currentDir.setPath( QDir::currentDirPath());
00311 //      currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst);
00312 
00313     currentPathCombo = new QComboBox( FALSE, view, "currentPathCombo" );
00314     layout->addMultiCellWidget( currentPathCombo, 3, 3, 0, 4);
00315 
00316                 currentPathCombo ->setFixedWidth(220);
00317     currentPathCombo->setEditable(TRUE);
00318     currentPathCombo->lineEdit()->setText( currentDir.canonicalPath());
00319 
00320     connect( currentPathCombo, SIGNAL( activated(const QString&) ),
00321               this, SLOT(  currentPathComboActivated(const QString&) ) );
00322 
00323     connect( currentPathCombo->lineEdit(),SIGNAL(returnPressed()),
00324              this,SLOT(currentPathComboChanged()));
00325      ProgressBar = new QProgressBar( view, "ProgressBar" );
00326      layout->addMultiCellWidget( ProgressBar, 4, 4, 0, 4);
00327      ProgressBar->setMaximumHeight(10);
00328     filterStr="*";
00329     b=FALSE;
00330     populateLocalView();
00331     readConfig();
00332 
00333 //    ServerComboBox->setCurrentItem(currentServerConfig);
00334 
00335     TabWidget->setCurrentPage(2);
00336 //              qDebug("XXXXXXXXXXXX Constructor done");
00337 
00338 }
00339 
00340 OpieFtp::~OpieFtp()
00341 {
00342 }
00343 
00344 void OpieFtp::cleanUp()
00345 {
00346     if(conn)
00347         FtpQuit(conn);
00348     QString sfile=QDir::homeDirPath();
00349     if(sfile.right(1) != "/")
00350         sfile+="/._temp";
00351     else
00352         sfile+="._temp";
00353     QFile file( sfile);
00354     if(file.exists())
00355         file.remove();
00356     Config cfg("opieftp");
00357     cfg.setGroup("Server");
00358     cfg.writeEntry("currentServer", currentServerConfig);
00359 
00360     exit(0);
00361 }
00362 
00363 void OpieFtp::tabChanged(QWidget *)
00364 {
00365     if (TabWidget->currentPageIndex() == 0) {
00366         currentPathCombo->lineEdit()->setText( currentDir.canonicalPath());
00367         tabMenu->setItemChecked(tabMenu->idAt(0),TRUE);
00368         tabMenu->setItemChecked(tabMenu->idAt(1),FALSE);
00369         tabMenu->setItemChecked(tabMenu->idAt(2),FALSE);
00370         if(cdUpButton->isHidden())
00371             cdUpButton->show();
00372         if(homeButton->isHidden())
00373             homeButton->show();
00374                                 if(currentPathCombo->isHidden()) currentPathCombo->show();
00375 
00376     }
00377     if (TabWidget->currentPageIndex() == 1) {
00378         currentPathCombo->lineEdit()->setText( currentRemoteDir );
00379         tabMenu->setItemChecked(tabMenu->idAt(1),TRUE);
00380         tabMenu->setItemChecked(tabMenu->idAt(0),FALSE);
00381         tabMenu->setItemChecked(tabMenu->idAt(2),FALSE);
00382         if(cdUpButton->isHidden())
00383             cdUpButton->show();
00384         homeButton->hide();
00385                                 if(currentPathCombo->isHidden()) currentPathCombo->show();
00386 
00387     }
00388     if (TabWidget->currentPageIndex() == 2) {
00389         tabMenu->setItemChecked(tabMenu->idAt(2),TRUE);
00390         tabMenu->setItemChecked(tabMenu->idAt(0),FALSE);
00391         tabMenu->setItemChecked(tabMenu->idAt(1),FALSE);
00392         cdUpButton->hide();
00393         homeButton->hide();
00394                                 if(!currentPathCombo->isHidden()) currentPathCombo->hide();
00395     }
00396 }
00397 
00398 void OpieFtp::newConnection()
00399 {
00400    UsernameComboBox->lineEdit()->setText("");
00401    PasswordEdit->setText( "" );
00402    ServerComboBox->lineEdit()->setText( "");
00403    remotePath->setText( currentRemoteDir = "/");
00404    PortSpinBox->setValue( 21);
00405    TabWidget->setCurrentPage(2);
00406 }
00407 
00408 void OpieFtp::serverComboEdited(const QString & )
00409 {
00410 //   if(  ServerComboBox->text(currentServerConfig) != edit /*edit.isEmpty() */) {
00411 //       odebug << "ServerComboEdited" << oendl; 
00412 //  //        currentServerConfig = -1;
00413 //      }
00414 }
00415 
00416 void OpieFtp::UsernameComboBoxEdited(const QString &) {
00417 //        currentServerConfig = -1;
00418 }
00419 
00420 void OpieFtp::PasswordEditEdited(const QString & ) {
00421 //        currentServerConfig = -1;
00422 }
00423 
00424 void OpieFtp::connectorBtnToggled(bool On)
00425 {
00426     if(On) {
00427         connector();
00428     } else {
00429         disConnector();
00430     }
00431 
00432 }
00433 
00434 void OpieFtp::connector()
00435 {
00436 //    QCopEnvelope ( "QPE/System", "busy()" );
00437 //    qApp->processEvents();
00438     currentRemoteDir=remotePath->text();
00439 
00440     if( ServerComboBox->currentText().isEmpty()) {
00441 
00442         QMessageBox::warning(this,tr("Ftp"),tr("Please set the server info"),tr("Ok"),0,0);
00443         TabWidget->setCurrentPage(2);
00444         ServerComboBox->setFocus();
00445         connectServerBtn->setOn(FALSE);
00446         connectServerBtn->setText( tr("Connect"));
00447         return;
00448     }
00449 
00450     FtpInit();
00451 
00452     TabWidget->setCurrentPage(1);
00453     QString ftp_host = ServerComboBox->currentText();
00454     QString ftp_user = UsernameComboBox->currentText();
00455     QString ftp_pass = PasswordEdit->text();
00456     QString port=PortSpinBox->cleanText();
00457     port.stripWhiteSpace();
00458 
00459     Config cfg("opieftp");
00460     cfg.setGroup("Server");
00461 //    int current=cfg.readNumEntry("currentServer", 1);
00462 
00463 //      if(ftp_host!= cfg.readEntry(QString::number( current)))
00464 //         currentServerConfig=-1;
00465 //      cfg.setGroup(QString::number(current));
00466 //      if( ftp_user != cfg.readEntry("Username"))
00467 //         currentServerConfig=-1;
00468 //      if(ftp_pass != cfg.readEntry(cfg.readEntry("Username")))
00469 //         currentServerConfig=-1;
00470 
00471 
00472     if(ftp_host.find("ftp://",0, TRUE) != -1 )
00473         ftp_host=ftp_host.right(ftp_host.length()-6);
00474     ftp_host+=":"+port;
00475 
00476     if (!FtpConnect( ftp_host.latin1(), &conn)) {
00477         QMessageBox::message(tr("Note"),tr("Unable to connect to\n")+ftp_host);
00478         connectServerBtn->setOn(FALSE);
00479         connectServerBtn->setText( tr("Connect"));
00480         return ;
00481     }
00482 
00483     if (!FtpLogin( ftp_user.latin1(), ftp_pass.latin1(),conn )) {
00484         QString msg;
00485         msg.sprintf(tr("Unable to log in\n")+"%s",FtpLastResponse(conn));
00486         msg.replace(QRegExp(":"),"\n");
00487         QMessageBox::message(tr("Note"),msg);
00488         if(conn)
00489             FtpQuit(conn);
00490         connectServerBtn->setOn(FALSE);
00491         connectServerBtn->setText( tr("Connect"));
00492         return ;
00493     }
00494 
00495     remoteDirList("/") ;
00496     setCaption(ftp_host);
00497    if( currentServerConfig == -1)
00498         writeConfig();
00499     connectServerBtn->setText( tr("Disconnect"));
00500 //     QCopEnvelope ( "QPE/System", "notBusy()" );
00501 }
00502 
00503 void OpieFtp::disConnector()
00504 {
00505     if(conn)
00506         FtpQuit(conn);
00507     setCaption("OpieFtp");
00508     currentRemoteDir="/";
00509     Remote_View->clear();
00510     connectServerBtn->setText( tr("Connect"));
00511     connectServerBtn->setOn(FALSE);
00512     setCaption("OpieFtp");
00513 }
00514 
00515 void OpieFtp::localUpload()
00516 {
00517     int fsz;
00518 //    QCopEnvelope ( "QPE/System", "busy()" );
00519 //    qApp->processEvents();
00520     QList<QListViewItem> * getSelectedItems( QListView * Local_View );
00521     QListViewItemIterator it( Local_View );
00522     for ( ; it.current(); ++it ) {
00523         if ( it.current()->isSelected() ) {
00524             QString strItem = it.current()->text(0);
00525             QString localFile = currentDir.canonicalPath()+"/"+strItem;
00526             QString remoteFile= currentRemoteDir+strItem;
00527             QFileInfo fi(localFile);
00528             if( !fi.isDir()) {
00529                 fsz=fi.size();
00530                 ProgressBar->setTotalSteps(fsz);
00531 
00532                 FtpOptions(FTPLIB_CALLBACK, (long) log_progress, conn);
00533                 FtpOptions(FTPLIB_IDLETIME, (long) 1000, conn);
00534                 FtpOptions(FTPLIB_CALLBACKARG, (long) &fsz, conn);
00535                 FtpOptions(FTPLIB_CALLBACKBYTES, (long) fsz/10, conn);
00536 //                odebug << "Put: " << localFile.latin1() << ", " << remoteFile.latin1() << "" << oendl; 
00537 
00538                 if( !FtpPut( localFile.latin1(), remoteFile.latin1(),FTPLIB_IMAGE, conn ) ) {
00539                     QString msg;
00540                     msg.sprintf(tr("Unable to upload\n")+"%s",FtpLastResponse(conn));
00541                     msg.replace(QRegExp(":"),"\n");
00542                     QMessageBox::message(tr("Note"),msg);
00543                 }
00544             } else {
00545                 QMessageBox::message(tr("Note"),tr("Cannot upload directories"));
00546             }
00547             ProgressBar->reset();
00548             nullifyCallBack();
00549         it.current()->setSelected(FALSE);
00550         } //end currentSelected
00551     }
00552     for ( ; it.current(); ++it ) {
00553         Local_View->clearSelection();
00554     }
00555     Local_View->clearFocus();
00556     TabWidget->setCurrentPage(1);
00557     remoteDirList( (const QString &)currentRemoteDir); //this also calls populate
00558 //    QCopEnvelope ( "QPE/System", "notBusy()" );
00559 }
00560 
00561 void OpieFtp::nullifyCallBack()
00562 {
00563         FtpOptions(FTPLIB_CALLBACK, 0, conn);
00564         FtpOptions(FTPLIB_IDLETIME, 0, conn);
00565         FtpOptions(FTPLIB_CALLBACKARG, 0, conn);
00566         FtpOptions(FTPLIB_CALLBACKBYTES, 0, conn);
00567 }
00568 
00569 void OpieFtp::remoteDownload()
00570 {
00571 //    qApp->processEvents();
00572     int fsz;
00573 //    QCopEnvelope ( "QPE/System", "busy()" );
00574 
00575     QList<QListViewItem> * getSelectedItems( QListView * Remote_View );
00576     QListViewItemIterator it( Remote_View );
00577     for ( ; it.current(); ++it ) {
00578         if ( it.current()->isSelected() ) {
00579             QString strItem = it.current()->text(0);
00580 //      strItem=strItem.right(strItem.length()-1);
00581             QString localFile = currentDir.canonicalPath();
00582             if(localFile.right(1).find("/",0,TRUE) == -1)
00583                 localFile += "/";
00584             localFile += strItem;
00585 //    QString localFile = currentDir.canonicalPath()+"/"+strItem;
00586             QString remoteFile= currentRemoteDir+strItem;
00587             if (!FtpSize( remoteFile.latin1(), &fsz, FTPLIB_ASCII, conn))
00588                 fsz = 0;
00589             QString temp;
00590             temp.sprintf( remoteFile+" "+" %dkb", fsz);
00591 
00592             ProgressBar->setTotalSteps(fsz);
00593             FtpOptions(FTPLIB_CALLBACK, (long) log_progress, conn);
00594             FtpOptions(FTPLIB_IDLETIME, (long) 1000, conn);
00595             FtpOptions(FTPLIB_CALLBACKARG, (long) &fsz, conn);
00596             FtpOptions(FTPLIB_CALLBACKBYTES, (long) fsz/10, conn);
00597 //            odebug << "Get: " << localFile.latin1() << ", " << remoteFile.latin1() << "" << oendl; 
00598 
00599             if(!FtpGet( localFile.latin1(), remoteFile.latin1(),FTPLIB_IMAGE, conn ) ) {
00600                 QString msg;
00601                 msg.sprintf(tr("Unable to download \n")+"%s",FtpLastResponse(conn));
00602                 msg.replace(QRegExp(":"),"\n");
00603                 QMessageBox::message(tr("Note"),msg);
00604             }
00605             ProgressBar->reset();
00606             nullifyCallBack();
00607         it.current()->setSelected(FALSE);
00608         }
00609     }
00610     for ( ; it.current(); ++it ) {
00611         Remote_View->clearSelection();
00612     }
00613     Remote_View->setFocus();
00614     TabWidget->setCurrentPage(0);
00615     populateLocalView();
00616 //    QCopEnvelope ( "QPE/System", "notBusy()" );
00617 }
00618 
00619 bool OpieFtp::remoteDirList(const QString &dir)
00620 {
00621     QString tmp = QDir::homeDirPath();
00622     if(tmp.right(1) != "/")
00623         tmp+="/._temp";
00624     else
00625         tmp+="._temp";
00626 //    odebug << "Listing remote dir "+tmp << oendl; 
00627 //    QCopEnvelope ( "QPE/System", "busy()" );
00628     if (!FtpDir( tmp.latin1(), dir.latin1(), conn) ) {
00629         QString msg;
00630         msg.sprintf(tr("Unable to list the directory\n")+dir+"\n%s",FtpLastResponse(conn) );
00631         msg.replace(QRegExp(":"),"\n");
00632         QMessageBox::message(tr("Note"),msg);
00633         return false;
00634     }
00635     populateRemoteView() ;
00636 //    QCopEnvelope ( "QPE/System", "notBusy()" );
00637     return true;
00638 }
00639 
00640 bool OpieFtp::remoteChDir(const QString &dir)
00641 {
00642 //    QCopEnvelope ( "QPE/System", "busy()" );
00643     if (!FtpChdir( dir.latin1(), conn )) {
00644         QString msg;
00645         msg.sprintf(tr("Unable to change directories\n")+dir+"\n%s",FtpLastResponse(conn));
00646         msg.replace(QRegExp(":"),"\n");
00647         QMessageBox::message(tr("Note"),msg);
00648 //        odebug << msg << oendl; 
00649 //        QCopEnvelope ( "QPE/System", "notBusy()" );
00650         return FALSE;
00651     }
00652 //    QCopEnvelope ( "QPE/System", "notBusy()" );
00653     return TRUE;
00654 }
00655 
00656 void OpieFtp::populateLocalView()
00657 {
00658     Local_View->clear();
00659     currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst);
00660     currentDir.setMatchAllDirs(TRUE);
00661     currentDir.setNameFilter(filterStr);
00662     QString fileL, fileS, fileDate;
00663     bool isDir=FALSE;
00664     const QFileInfoList *list = currentDir.entryInfoList( /*QDir::All*/ /*, QDir::SortByMask*/);
00665     QFileInfoListIterator it(*list);
00666     QFileInfo *fi;
00667     while ( (fi=it.current()) ) {
00668         if (fi->isSymLink() ){
00669             QString symLink=fi->readLink();
00670 //         odebug << "Symlink detected "+symLink << oendl; 
00671             QFileInfo sym( symLink);
00672             fileS.sprintf( "%10i", sym.size() );
00673             fileL.sprintf( "%s ->  %s",  fi->fileName().data(),sym.absFilePath().data() );
00674             fileDate = sym.lastModified().toString();
00675         } else {
00676 //        odebug << "Not a dir: "+currentDir.canonicalPath()+fileL << oendl; 
00677             fileS.sprintf( "%10i", fi->size() );
00678             fileL.sprintf( "%s",fi->fileName().data() );
00679             fileDate= fi->lastModified().toString();
00680             if( QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+fileL)).exists() ) {
00681                 fileL+="/";
00682                 isDir=TRUE;
00683 //     odebug << fileL << oendl; 
00684             }
00685         }
00686 
00687 
00688         if(fileL !="./" && fi->exists()) {
00689             item = new QListViewItem( Local_View,fileL, fileDate, fileS );
00690             QPixmap pm;
00691 
00692             if(isDir || fileL.find("/",0,TRUE) != -1) {
00693                 if( !QDir( fi->filePath() ).isReadable())
00694                     pm = Opie::Core::OResource::loadPixmap( "lockedfolder", Opie::Core::OResource::SmallIcon );
00695                 else
00696                     pm = Opie::Core::OResource::loadPixmap( "folder", Opie::Core::OResource::SmallIcon );
00697                 item->setPixmap( 0,pm );
00698             } else {
00699                 if( !fi->isReadable() )
00700                     pm = Opie::Core::OResource::loadPixmap( "locked", Opie::Core::OResource::SmallIcon );
00701                 else {
00702                     MimeType mt(fi->filePath());
00703                     pm=mt.pixmap(); //sets the correct pixmap for mimetype
00704                     if(pm.isNull())
00705                         pm =  unknownXpm;
00706                 }
00707             }
00708             if(  fileL.find("->",0,TRUE) != -1) {
00709                   // overlay link image
00710                 pm = Opie::Core::OResource::loadPixmap( "folder", Opie::Core::OResource::SmallIcon );
00711                 QPixmap lnk = Opie::Core::OResource::loadPixmap( "opie/symlink" );
00712                 QPainter painter( &pm );
00713                 painter.drawPixmap( pm.width()-lnk.width(), pm.height()-lnk.height(), lnk );
00714             }
00715             item->setPixmap( 0,pm);
00716         }
00717         isDir=FALSE;
00718         ++it;
00719     }
00720     Local_View->setSorting( 3,FALSE);
00721     currentPathCombo->lineEdit()->setText( currentDir.canonicalPath() );
00722    fillCombo( (const QString &)currentDir.canonicalPath());
00723 }
00724 
00725 bool OpieFtp::populateRemoteView( )
00726 {
00727 //    odebug << "populate remoteview" << oendl; 
00728     QString sfile=QDir::homeDirPath();
00729     if(sfile.right(1) != "/")
00730         sfile+="/._temp";
00731     else
00732         sfile+="._temp";
00733     QFile file( sfile);
00734     Remote_View->clear();
00735     QString s, File_Name;
00736     QListViewItem *itemDir=NULL, *itemFile=NULL;
00737     QRegExp monthRe(" [JFMASOND][eapuecoe][brynlgptvc] [ 0-9][0-9] [ 0-9][0-9][:0-9][0-9][0-9] ");
00738     QString fileL, fileS, fileDate;
00739     if ( file.open(IO_ReadOnly)) {
00740         QTextStream t( &file );   // use a text stream
00741         while ( !t.eof()) {
00742             s = t.readLine();
00743 
00744             if(s.find("total",0,TRUE) == 0)
00745                continue;
00746 
00747            int len, month = monthRe.match(s, 0, &len);
00748            fileDate = s.mid(month + 1, len - 2);       // minus spaces
00749            fileL = s.right(s.length() - month - len);
00750             if(s.left(1) == "d")
00751                 fileL = fileL+"/";
00752             fileS = s.mid(month - 8, 8);  // FIXME
00753             fileS = fileS.stripWhiteSpace();
00754 
00755            if(s.left(1) == "d" || fileL.find("/",0,TRUE) != -1) {
00756                QListViewItem * item = new QListViewItem( Remote_View, fileL, fileDate, fileS,"d");
00757                item->setPixmap( 0, Opie::Core::OResource::loadPixmap( "folder", Opie::Core::OResource::SmallIcon ));
00758 //                      if(itemDir)
00759                      item->moveItem(itemDir);
00760                  itemDir=item;
00761            } else {
00762                QListViewItem * item = new QListViewItem( Remote_View, fileL, fileDate, fileS,"f");
00763                item->setPixmap( 0, Opie::Core::OResource::loadPixmap( "fileopen", Opie::Core::OResource::SmallIcon ));
00764 //                      if(itemFile)
00765                      item->moveItem(itemDir);
00766                      item->moveItem(itemFile);
00767                  itemFile=item;
00768            }
00769         }
00770         QListViewItem * item1 = new QListViewItem( Remote_View, "../");
00771         item1->setPixmap( 0, Opie::Core::OResource::loadPixmap( "folder", Opie::Core::OResource::SmallIcon ));
00772         file.close();
00773         if( file.exists())
00774             file. remove();
00775     } 
00776 //        odebug << "temp file not opened successfully "+sfile << oendl; 
00777     Remote_View->setSorting( 4,TRUE);
00778     return true;
00779 }
00780 
00781 void OpieFtp::remoteListClicked(QListViewItem *selectedItem)
00782 {
00783      if( selectedItem) {
00784         //   if(selectedItem!= NULL) {
00785 //         QCopEnvelope ( "QPE/System", "busy()" );
00786         QString  oldRemoteCurrentDir =  currentRemoteDir;
00787         QString strItem=selectedItem->text(0);
00788         strItem=strItem.simplifyWhiteSpace();
00789         if(strItem == "../") { // the user wants to go ^
00790             if( FtpCDUp( conn) == 0) {
00791                 QString msg;
00792                 msg.sprintf(tr("Unable to cd up\n")+"%s",FtpLastResponse(conn));
00793                 msg.replace(QRegExp(":"),"\n");
00794                 QMessageBox::message(tr("Note"),msg);
00795 //                odebug << msg << oendl; 
00796             }
00797             char path[256];
00798             if( FtpPwd( path,sizeof(path),conn) == 0) { //this is easier than fudging the string
00799                 QString msg;
00800                 msg.sprintf(tr("Unable to get working dir\n")+"%s",FtpLastResponse(conn));
00801                 msg.replace(QRegExp(":"),"\n");
00802                 QMessageBox::message(tr("Note"),msg);
00803 //                odebug << msg << oendl; 
00804             }
00805             currentRemoteDir=path;
00806         } else {
00807             if(strItem.find("->",0,TRUE) != -1) { //symlink on some servers
00808                 strItem=strItem.right( strItem.length() - strItem.find("->",0,TRUE) - 2 );
00809                 strItem = strItem.stripWhiteSpace();
00810                 currentRemoteDir = strItem;
00811                 if( !remoteChDir( (const QString &)strItem)) {
00812                     currentRemoteDir = oldRemoteCurrentDir;
00813                     strItem="";
00814 //                     odebug << "RemoteCurrentDir1 "+oldRemoteCurrentDir << oendl; 
00815                 }
00816             } else if(strItem.find("/",0,TRUE) != -1) { // this is a directory
00817                 if( !remoteChDir( (const QString &)currentRemoteDir + strItem)) {
00818                     currentRemoteDir = oldRemoteCurrentDir;
00819                     strItem="";
00820 //                     odebug << "RemoteCurrentDir1 "+oldRemoteCurrentDir << oendl; 
00821 
00822                 } else {
00823                     currentRemoteDir = currentRemoteDir+strItem;
00824                 }
00825             } else {
00826 //                QCopEnvelope ( "QPE/System", "notBusy()" );
00827                 return;
00828             }
00829         }
00830         remoteDirList( (const QString &)currentRemoteDir); //this also calls populate
00831         if(currentRemoteDir.right(1) !="/")
00832             currentRemoteDir +="/";
00833         currentPathCombo->lineEdit()->setText( currentRemoteDir);
00834         fillRemoteCombo( (const QString &)currentRemoteDir);
00835 //        QCopEnvelope ( "QPE/System", "notBusy()" );
00836     Remote_View->ensureItemVisible(Remote_View->firstChild());
00837 
00838     }
00839 }
00840 
00841 void OpieFtp::localListClicked(QListViewItem *selectedItem)
00842 {
00843     if(selectedItem!= NULL) {
00844 
00845     QString strItem=selectedItem->text(0);
00846         QString strSize=selectedItem->text(1);
00847         strSize=strSize.stripWhiteSpace();
00848         if(strItem.find("@",0,TRUE) !=-1 || strItem.find("->",0,TRUE) !=-1 ) { //if symlink
00849               // is symlink
00850             QString strItem2 = strItem.right( (strItem.length() - strItem.find("->",0,TRUE)) - 4);
00851             if(QDir(strItem2).exists() ) {
00852                 currentDir.cd(strItem2, TRUE);
00853                 populateLocalView();
00854             }
00855         } else { // not a symlink
00856             if(strItem.find(". .",0,TRUE) && strItem.find("/",0,TRUE)!=-1 ) {
00857 
00858                 if(QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem)).exists() ) {
00859                     strItem=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem);
00860                     currentDir.cd(strItem,FALSE);
00861                     populateLocalView();
00862                 } else {
00863                     currentDir.cdUp();
00864                     populateLocalView();
00865                 }
00866                 if(QDir(strItem).exists()){
00867                     currentDir.cd(strItem, TRUE);
00868                     populateLocalView();
00869                 }
00870             } else {
00871                 strItem=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem);
00872                 if( QFile::exists(strItem ) ) {
00873                       //  odebug << "upload "+strItem << oendl; 
00874                     return;
00875                 }
00876             } //end not symlink
00877             chdir(strItem.latin1());
00878         }
00879     Local_View->ensureItemVisible(Local_View->firstChild());
00880     }
00881 }
00882 
00883 void OpieFtp::doLocalCd()
00884 {
00885     localListClicked( Local_View->currentItem());
00886 }
00887 
00888 void OpieFtp:: doRemoteCd()
00889 {
00890     remoteListClicked( Remote_View->currentItem());
00891 
00892 }
00893 
00894 void OpieFtp::showHidden()
00895 {
00896     if (!b) {
00897     currentDir.setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All);
00898     localMenu->setItemChecked(localMenu->idAt(0),TRUE);
00899 //    currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst);
00900     b=TRUE;
00901 
00902     }  else {
00903     currentDir.setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden*/ | QDir::All);
00904     localMenu->setItemChecked(localMenu->idAt(0),FALSE);
00905 //    currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst);
00906     b=FALSE;
00907     }
00908     populateLocalView();
00909 }
00910 
00911 void OpieFtp::ListPressed( int mouse, QListViewItem *item, const QPoint &, int)
00912 {
00913 // if(item)
00914     if (mouse == 2) {
00915         showLocalMenu(item);
00916     }
00917 }
00918 
00919 void OpieFtp::RemoteListPressed( int mouse, QListViewItem *item, const QPoint &, int )
00920 {
00921     if(mouse == 2) {
00922         showRemoteMenu(item);
00923     }
00924 }
00925 
00926 void OpieFtp::showRemoteMenu(QListViewItem * item)
00927 {
00928     QPopupMenu * m;// = new QPopupMenu( Local_View );
00929     m = new QPopupMenu(this);
00930     if(item != NULL ) {
00931        if(  item->text(0).find("/",0,TRUE) != -1)
00932           m->insertItem( tr( "Change Directory" ), this, SLOT( doRemoteCd() ));
00933        else
00934           m->insertItem( tr( "Download" ), this, SLOT( remoteDownload() ));
00935     }
00936     m->insertItem( tr( "Make Directory" ), this, SLOT( remoteMakDir() ));
00937     m->insertItem( tr("Rescan"), this, SLOT( populateLocalView() ));
00938     m->insertItem( tr( "Rename" ), this, SLOT( remoteRename() ));
00939     m->insertSeparator();
00940     m->insertItem( tr( "Delete" ), this, SLOT( remoteDelete() ));
00941     m->exec( QCursor::pos() );
00942     delete m;
00943 }
00944 
00945 void OpieFtp::showLocalMenu(QListViewItem * item)
00946 {
00947 
00948  QPopupMenu  *m;
00949  m = new QPopupMenu( this);
00950     m->insertItem(  tr( "Show Hidden Files" ), this,  SLOT( showHidden() ));
00951     m->insertSeparator();
00952     if(item != NULL ) {
00953        if( item->text(0).find("/",0,TRUE) !=-1)
00954           m->insertItem( tr( "Change Directory" ), this, SLOT( doLocalCd() ));
00955        else
00956           m->insertItem( tr( "Upload" ), this, SLOT( localUpload() ));
00957     }
00958     m->insertItem( tr( "Make Directory" ), this, SLOT( localMakDir() ));
00959     m->insertItem( tr("Rescan"), this, SLOT( populateRemoteView() ));
00960     m->insertItem( tr( "Rename" ), this, SLOT( localRename() ));
00961     m->insertSeparator();
00962     m->insertItem( tr( "Delete" ), this, SLOT( localDelete() ));
00963     m->setCheckable(TRUE);
00964     if (b)
00965         m->setItemChecked(m->idAt(0),TRUE);
00966     else
00967         m->setItemChecked(m->idAt(0),FALSE);
00968 
00969     m->exec( QCursor::pos() );
00970     delete m;
00971 }
00972 
00973 void OpieFtp::localMakDir()
00974 {
00975     InputDialog *fileDlg;
00976     fileDlg = new InputDialog(this,tr("Make Directory"),TRUE, 0);
00977     fileDlg->exec();
00978     if( fileDlg->result() == 1 ) {
00979        QString  filename = fileDlg->LineEdit1->text();
00980        currentDir.mkdir( currentDir.canonicalPath()+"/"+filename);
00981     }
00982     populateLocalView();
00983 }
00984 
00985 void OpieFtp::localDelete()
00986 {
00987     QList<QListViewItem> * getSelectedItems( QListView * Local_View );
00988     QListViewItemIterator it( Local_View );
00989     for ( ; it.current(); ++it ) {
00990         if ( it.current()->isSelected() ) {
00991             QString f = it.current()->text(0);
00992             it.current()->setSelected(FALSE);
00993 
00994 //    QString f = Local_View->currentItem()->text(0);
00995             if(QDir(f).exists() ) {
00996                 switch ( QMessageBox::warning(this,tr("Delete"),tr("Do you really want to delete\n")+f+
00997                                               tr(" ?\nIt must be empty"),tr("Yes"),tr("No"),0,0,1) ) {
00998                   case 0: {
00999                       f=currentDir.canonicalPath()+"/"+f;
01000                       QString cmd="rmdir "+f;
01001                       system( cmd.latin1());
01002                   }
01003                       break;
01004                   case 1:
01005                         // exit
01006                       break;
01007                 };
01008 
01009             } else {
01010                 switch ( QMessageBox::warning(this,tr("Delete"),tr("Do you really want to delete\n")+f
01011                                               +" ?",tr("Yes"),tr("No"),0,0,1) ) {
01012                   case 0: {
01013                       f=currentDir.canonicalPath()+"/"+f;
01014                       QString cmd="rm "+f;
01015                       system( cmd.latin1());
01016                   }
01017                       break;
01018                   case 1:
01019                         // exit
01020                       break;
01021                 };
01022             }
01023         }
01024     }
01025     populateLocalView();
01026 
01027 }
01028 
01029 void OpieFtp::remoteMakDir()
01030 {
01031     InputDialog *fileDlg;
01032     fileDlg = new InputDialog(this,tr("Make Directory"),TRUE, 0);
01033     fileDlg->exec();
01034     if( fileDlg->result() == 1 ) {
01035        QString  filename = fileDlg->LineEdit1->text();//+".playlist";
01036        QString tmp=currentRemoteDir+filename;
01037 //       QCopEnvelope ( "QPE/System", "busy()" );
01038        if(FtpMkdir( tmp.latin1(), conn) == 0) {
01039            QString msg;
01040            msg.sprintf(tr("Unable to make directory\n")+"%s",FtpLastResponse(conn));
01041            msg.replace(QRegExp(":"),"\n");
01042            QMessageBox::message(tr("Note"),msg);
01043        }
01044 //       QCopEnvelope ( "QPE/System", "notBusy()" );
01045     remoteDirList( (const QString &)currentRemoteDir); //this also calls populate
01046     }
01047 }
01048 
01049 void OpieFtp::remoteDelete()
01050 {
01051     QList<QListViewItem> * getSelectedItems( QListView * Remote_View );
01052     QListViewItemIterator it( Remote_View );
01053     for ( ; it.current(); ++it ) {
01054         if ( it.current()->isSelected() ) {
01055             QString f = it.current()->text(0);
01056 //    QString f = Remote_View->currentItem()->text(0);
01057 //            QCopEnvelope ( "QPE/System", "busy()" );
01058             if( f.right(1) =="/") {
01059                 QString path= currentRemoteDir+f;
01060                 switch ( QMessageBox::warning(this,tr("Delete"),tr("Do you really want to delete\n")+f+"?"
01061                                               ,tr("Yes"),tr("No"),0,0,1) ) {
01062                   case 0: {
01063                       f=currentDir.canonicalPath()+"/"+f;
01064                       if(FtpRmdir( path.latin1(), conn) ==0) {
01065                           QString msg;
01066                           msg.sprintf(tr("Unable to remove directory\n")+"%s",FtpLastResponse(conn));
01067                           msg.replace(QRegExp(":"),"\n");
01068                           QMessageBox::message(tr("Note"),msg);
01069                       }
01070                       remoteDirList( (const QString &)currentRemoteDir); //this also calls populate
01071                   }
01072                       break;
01073                 };
01074             } else {
01075                 switch ( QMessageBox::warning(this,tr("Delete"),tr("Do you really want to delete\n")+f+"?"
01076                                               ,tr("Yes"),tr("No"),0,0,1) ) {
01077                   case 0: {
01078                       QString path= currentRemoteDir+f;
01079                       if(FtpDelete( path.latin1(), conn)==0) {
01080                           QString msg;
01081                           msg.sprintf(tr("Unable to delete file\n")+"%s",FtpLastResponse(conn));
01082                           msg.replace(QRegExp(":"),"\n");
01083                           QMessageBox::message(tr("Note"),msg);
01084                       }
01085                       remoteDirList( (const QString &)currentRemoteDir); //this also calls populate
01086                   }
01087                       break;
01088                 };
01089             }
01090         }
01091     }
01092 //    QCopEnvelope ( "QPE/System", "notBusy()" );
01093 }
01094 
01095 void OpieFtp::remoteRename()
01096 {
01097     QString curFile = Remote_View->currentItem()->text(0);
01098     InputDialog *fileDlg;
01099     fileDlg = new InputDialog(this,tr("Rename"),TRUE, 0);
01100     fileDlg->setTextEdit((const QString &)curFile);
01101     fileDlg->exec();
01102     if( fileDlg->result() == 1 ) {
01103         QString oldName = currentRemoteDir +"/"+ curFile;
01104         QString newName = currentRemoteDir  +"/"+ fileDlg->LineEdit1->text();//+".playlist";
01105 //        QCopEnvelope ( "QPE/System", "busy()" );
01106         if(FtpRename( oldName.latin1(), newName.latin1(),conn) == 0) {
01107             QString msg;
01108             msg.sprintf(tr("Unable to rename file\n")+"%s",FtpLastResponse(conn));
01109             msg.replace(QRegExp(":"),"\n");
01110             QMessageBox::message(tr("Note"),msg);
01111         }
01112 //        QCopEnvelope ( "QPE/System", "notBusy()" );
01113     remoteDirList( (const QString &)currentRemoteDir); //this also calls populate
01114     }
01115 }
01116 
01117 void OpieFtp::localRename()
01118 {
01119     QString curFile = Local_View->currentItem()->text(0);
01120     InputDialog *fileDlg;
01121     fileDlg = new InputDialog(this,tr("Rename"),TRUE, 0);
01122     fileDlg->setTextEdit((const QString &)curFile);
01123     fileDlg->exec();
01124     if( fileDlg->result() == 1 ) {
01125         QString oldname =  currentDir.canonicalPath() + "/" + curFile;
01126         QString newName =  currentDir.canonicalPath() + "/" + fileDlg->LineEdit1->text();//+".playlist";
01127         if( rename(oldname.latin1(), newName.latin1())== -1)
01128             QMessageBox::message(tr("Note"),tr("Could not rename"));
01129     }
01130     populateLocalView();
01131 }
01132 
01133 void OpieFtp::currentPathComboActivated(const QString & currentPath) {
01134     if (TabWidget->currentPageIndex() == 0) {
01135     chdir( currentPath.latin1() );
01136     currentDir.cd( currentPath, TRUE);
01137     populateLocalView();
01138     update();
01139     } else {
01140 //     chdir( currentPath.latin1() );
01141 //     currentDir.cd( currentPath, TRUE);
01142 //     populateList();
01143 //     update();
01144 
01145     }
01146 }
01147 
01148 void OpieFtp::fillCombo(const QString &currentPath) {
01149         currentPathCombo->lineEdit()->setText(currentPath);
01150 
01151         if( localDirPathStringList.grep(currentPath,TRUE).isEmpty() ) {
01152                                                 qDebug("Clearing local");
01153             currentPathCombo->clear();
01154             localDirPathStringList.prepend(currentPath );
01155             currentPathCombo->insertStringList( localDirPathStringList,-1);
01156         }
01157 
01158         currentPathCombo->lineEdit()->setText(currentPath);
01159 
01160                                 if( remoteDirPathStringList.grep(currentPath,TRUE).isEmpty() ) {
01161                                                 qDebug("Clearing remote");
01162             currentPathCombo->clear();
01163             remoteDirPathStringList.prepend(currentPath );
01164             currentPathCombo->insertStringList( remoteDirPathStringList,-1);
01165         }
01166 }
01167 
01168 void OpieFtp::fillRemoteCombo(const QString &currentPath) {
01169 
01170         currentPathCombo->lineEdit()->setText(currentPath);
01171         if( remoteDirPathStringList.grep(currentPath,TRUE).isEmpty() ) {
01172             currentPathCombo->clear();
01173             remoteDirPathStringList.prepend(currentPath );
01174             currentPathCombo->insertStringList( remoteDirPathStringList,-1);
01175         }
01176 }
01177 
01178 void OpieFtp::currentPathComboChanged()
01179 {
01180     QString  oldRemoteCurrentDir =  currentRemoteDir;
01181 //    odebug << "oldRemoteCurrentDir "+oldRemoteCurrentDir << oendl; 
01182     if (TabWidget->currentPageIndex() == 0) {
01183         if(QDir( currentPathCombo->lineEdit()->text()).exists()) {
01184             currentDir.setPath( currentPathCombo->lineEdit()->text() );
01185             populateLocalView();
01186         } else {
01187             QMessageBox::message(tr("Note"),tr("That directory does not exist"));
01188         }
01189     }
01190     if (TabWidget->currentPageIndex() == 1) {
01191         currentRemoteDir = currentPathCombo->lineEdit()->text();
01192         if(currentRemoteDir.right(1) !="/") {
01193             currentRemoteDir = currentRemoteDir +"/";
01194             currentPathCombo->lineEdit()->setText( currentRemoteDir );
01195         }
01196             if( !remoteChDir( (const QString &)currentRemoteDir) ) {
01197                 currentRemoteDir = oldRemoteCurrentDir;
01198                 currentPathCombo->lineEdit()->setText( currentRemoteDir );
01199             }
01200 
01201         remoteDirList( (const QString &)currentRemoteDir);
01202     }
01203 }
01204 
01205 void OpieFtp::switchToLocalTab()
01206 {
01207     TabWidget->setCurrentPage(0);
01208 }
01209 
01210 void OpieFtp::switchToRemoteTab()
01211 {
01212     TabWidget->setCurrentPage(1);
01213 }
01214 
01215 void OpieFtp::switchToConfigTab()
01216 {
01217     TabWidget->setCurrentPage(2);
01218 }
01219 
01220 void OpieFtp::readConfig()
01221 {
01222     fillCombos();
01223     Config cfg("opieftp");
01224     cfg.setGroup("Server");
01225     currentServerConfig = cfg.readNumEntry("currentServer", -1);
01226 
01227 //    odebug << "Reading " << currentServerConfig << "" << oendl; 
01228     serverComboSelected( currentServerConfig-1);
01229 
01230 }
01231 
01232 void OpieFtp::writeConfig()
01233 {
01234 //    odebug << "write config" << oendl; 
01235     Config cfg("opieftp");
01236     cfg.setGroup("Server");
01237 
01238     QString username, remoteServerStr, remotePathStr, password, port, temp;
01239 
01240     int numberOfEntries = cfg.readNumEntry("numberOfEntries",0);
01241 
01242     if( currentServerConfig == -1) {
01243 
01244         for (int i = 1; i <= numberOfEntries; i++) {
01245         temp.setNum(i);
01246         cfg.setGroup("Server");
01247         QString tempStr = cfg.readEntry( temp,"");
01248     }
01249 
01250         temp.setNum( numberOfEntries + 1);
01251         cfg.setGroup("Server");
01252 
01253         remoteServerStr = cfg.readEntry( temp,"");
01254 
01255         int divider = remoteServerStr.length() - remoteServerStr.find(":",0,TRUE);
01256         remoteServerStr = remoteServerStr.left(remoteServerStr.length()-divider);
01257 
01258         temp.setNum(numberOfEntries+1);
01259         cfg.setGroup("Server");
01260 
01261         cfg.writeEntry( temp, ServerComboBox->currentText() +":"+PortSpinBox->cleanText() );
01262         cfg.writeEntry("currentServer", numberOfEntries+1);
01263 
01264         currentServerConfig = numberOfEntries+1;
01265 //        odebug << "setting currentserverconfig to " << currentServerConfig << "" << oendl; 
01266 
01267         cfg.setGroup(temp);
01268         if(!newServerName.isEmpty())
01269             cfg.writeEntry("ServerName", newServerName);
01270 
01271         cfg.writeEntry("RemotePath", remotePath->text());
01272 
01273         cfg.writeEntry("Username", UsernameComboBox->currentText());
01274 
01275         cfg.writeEntryCrypt( UsernameComboBox->currentText(), PasswordEdit->text());
01276         cfg.setGroup("Server");
01277 
01278         cfg.writeEntry("numberOfEntries", QString::number(numberOfEntries + 1 ));
01279 
01280     }
01281 }
01282 
01283 void OpieFtp::clearCombos() {
01284 //    odebug << "clearing" << oendl; 
01285     ServerComboBox->clear();
01286     UsernameComboBox->clear();
01287     PasswordEdit->clear();
01288     serverListView->clear();
01289 }
01290 
01291 
01292 void OpieFtp::fillCombos()
01293 {
01294     clearCombos();
01295                 qDebug("did we get here yet?");
01296 
01297     Config cfg("opieftp");
01298     cfg.setGroup("Server");
01299     QString username, remoteServerStr, remotePathStr, password, port, temp;
01300     int numberOfEntries = cfg.readNumEntry("numberOfEntries",0);
01301 
01302     for (int i = 1; i <= numberOfEntries; i++) {
01303         temp.setNum(i);
01304 //        odebug << temp << oendl; 
01305         cfg.setGroup("Server");
01306         remoteServerStr = cfg.readEntry( temp,"");
01307 //        odebug << remoteServerStr << oendl; 
01308 
01309         int divider = remoteServerStr.length() - remoteServerStr.find(":",0,TRUE);
01310         port = remoteServerStr.right( divider - 1);
01311         bool ok;
01312         PortSpinBox->setValue( port.toInt(&ok,10));
01313 
01314         remoteServerStr = remoteServerStr.left(remoteServerStr.length()-divider);
01315 //        odebug << "remote server string "+remoteServerStr << oendl; 
01316         ServerComboBox->insertItem( remoteServerStr );
01317 
01318         cfg.setGroup(temp);
01319 
01320         username = cfg.readEntry(temp);
01321         UsernameComboBox->insertItem(username);
01322         password = cfg.readEntryCrypt(username,"");
01323         PasswordEdit->setText(password);
01324 
01325         serverListView->insertItem( cfg.readEntry("ServerName"));
01326     }
01327 }
01328 
01329 
01330 void OpieFtp::serverComboSelected(int index)
01331 {
01332                 QString servername;
01333     currentServerConfig = index+1;
01334 //    odebug << "server combo selected " << index + 1 << "" << oendl; 
01335     QString username, remoteServerStr, remotePathStr, password, port, temp;
01336     servername = remoteServerStr = ServerComboBox->text(index);
01337                 qDebug("server text "  + remoteServerStr);
01338 
01339     Config cfg("opieftp");
01340     cfg.setGroup("Server");
01341 //    int numberOfEntries = cfg.readNumEntry("numberOfEntries",0);
01342 
01343                         //  for (int i = 1; i <= numberOfEntries; i++) {
01344 //    int numberOfEntries = cfg.readNumEntry("numberOfEntries",0);
01345 
01346     temp.setNum(index + 1);
01347     remoteServerStr = cfg.readEntry( temp,"");
01348 
01349 //    odebug << "Group " +temp << oendl; 
01350     cfg.setGroup(temp);
01351 
01352     int divider = remoteServerStr.length() - remoteServerStr.find(":",0,TRUE);
01353     port = remoteServerStr.right( divider - 1);
01354     bool ok;
01355     int portInt = port.toInt(&ok,10);
01356     if( portInt == 0) portInt = 21;
01357     ServerComboBox->lineEdit()->setText(remoteServerStr.left( remoteServerStr.find(":",0,TRUE)));
01358 
01359     PortSpinBox->setValue( portInt);
01360 
01361     remotePath->setText(cfg.readEntry("RemotePath", "/"));
01362 
01363     username = cfg.readEntry("Username", "anonymous");
01364     UsernameComboBox->lineEdit()->setText(username);
01365 //    odebug << username << oendl; 
01366 //    odebug << "Password is "+cfg.readEntryCrypt(username << oendl; 
01367     PasswordEdit->setText(cfg.readEntryCrypt(username, "me@opieftp.org"));
01368 //   UsernameComboBox
01369 //        PasswordEdit
01370 
01371     cfg.setGroup("Server");
01372     temp.sprintf("%d", currentServerConfig);
01373     cfg.writeEntry("currentServer", temp);
01374     cfg.writeEntry(temp,servername);
01375 
01376                 
01377    fuckeduphack = TRUE;
01378    serverListView->setCurrentItem( index);
01379    fuckeduphack = FALSE;
01380          qDebug( "server list set selected %d "+temp, index);
01381          ServerComboBox->lineEdit()->setText(servername);
01382     update();
01383 }
01384 
01385 void OpieFtp::deleteServer()
01386 {
01387     QString username, remoteServerStr, remotePathStr, password, port, temp, servername;
01388     remoteServerStr = ServerComboBox->currentText( );
01389     username = UsernameComboBox->currentText();
01390     servername=serverListView->currentText();
01391 
01392     Config cfg("opieftp");
01393     cfg.setGroup("Server");
01394     QString tempname;
01395     int numberOfEntries = cfg.readNumEntry("numberOfEntries",0);
01396 
01397     for (int i = 1; i <= numberOfEntries; i++) {
01398         temp.setNum(i);
01399 //        cfg.setGroup("Server");
01400         cfg.setGroup(QString::number(i));
01401         tempname=cfg.readEntry( "ServerName","");
01402 
01403         if( tempname.find( servername,0,TRUE)  != -1 ) {
01404 //             servername.find( cfg.readEntry("ServerName"))  != -1 &&
01405 //             remoteServerStr.find( cfg.readEntry("RemotePath")) != -1 &&
01406 //             username.find( cfg.readEntry("Username")) != -1) {
01407 
01408             serverListView->removeItem(i);
01409 
01410 //            odebug << "OK DELETE "+tempname << oendl; 
01411             cfg.removeEntry(QString::number(i));
01412             for ( ; i <= numberOfEntries; i++) {
01413                 cfg.setGroup("Server");
01414                 cfg.writeEntry("Server", QString::number(numberOfEntries + 1 ));
01415 
01416                 cfg.setGroup(QString::number(i+1)); //get next server config
01417                 servername=cfg.readEntry("ServerName");
01418                 remoteServerStr=cfg.readEntry("RemotePath");
01419                 username=cfg.readEntry("Username");
01420                 password=cfg.readEntryCrypt( username);
01421 
01422                 cfg.setGroup(QString::number(i));
01423 
01424                 cfg.writeEntry("RemotePath", remoteServerStr);
01425                 cfg.writeEntry("ServerName", servername);
01426                 cfg.writeEntry("Username", username);
01427                 cfg.writeEntryCrypt( username, password);
01428 
01429             }
01430             cfg.setGroup("Server");
01431             cfg.writeEntry("numberOfEntries", QString::number(numberOfEntries - 1 ));
01432         }
01433     }
01434     cfg.setGroup(QString::number(numberOfEntries));
01435     cfg.removeEntry("Server");
01436     cfg.removeEntry("RemotePath");
01437     cfg.removeEntry("ServerName");
01438      username=cfg.readEntry("Username");
01439     cfg.removeEntry("Username");
01440     cfg.removeEntry(username);
01441 
01442     currentServerConfig=currentServerConfig-1;
01443 
01444     fillCombos();
01445     update();
01446 }
01447 
01448 void OpieFtp::upDir()
01449 {
01450     if (TabWidget->currentPageIndex() == 0) {
01451         QString current = currentDir.canonicalPath();
01452         QDir dir(current);
01453         dir.cdUp();
01454         current = dir.canonicalPath();
01455         chdir( current.latin1() );
01456         currentDir.cd(  current, TRUE);
01457         populateLocalView();
01458         update();
01459     } else {
01460         if( FtpCDUp( conn) == 0) {
01461             QString msg;
01462             msg.sprintf(tr("Unable to cd up\n")+"%s",FtpLastResponse(conn));
01463             msg.replace(QRegExp(":"),"\n");
01464             QMessageBox::message(tr("Note"),msg);
01465 //                odebug << msg << oendl; 
01466         }
01467         char path[256];
01468         if( FtpPwd( path,sizeof(path),conn) == 0) { //this is easier than fudging the string
01469             QString msg;
01470             msg.sprintf(tr("Unable to get working dir\n")+"%s",FtpLastResponse(conn));
01471             msg.replace(QRegExp(":"),"\n");
01472             QMessageBox::message(tr("Note"),msg);
01473 //                odebug << msg << oendl; 
01474         }
01475         currentRemoteDir=path;
01476         remoteDirList( (const QString &)currentRemoteDir); //this also calls populate
01477         if(currentRemoteDir.right(1) !="/")
01478             currentRemoteDir +="/";
01479         currentPathCombo->lineEdit()->setText( currentRemoteDir);
01480         fillRemoteCombo( (const QString &)currentRemoteDir);
01481 
01482     }
01483 }
01484 
01485 void OpieFtp::docButtonPushed() {
01486     QString current = QPEApplication::documentDir();
01487     chdir( current.latin1() );
01488     currentDir.cd( current, TRUE);
01489      populateLocalView();
01490     update();
01491 
01492 }
01493 
01494 void OpieFtp::homeButtonPushed() {
01495     QString current = QDir::homeDirPath();
01496     chdir( current.latin1() );
01497     currentDir.cd(  current, TRUE);
01498      populateLocalView();
01499     update();
01500 }
01501 
01502 void OpieFtp::doAbout() {
01503     QMessageBox::message("OpieFtp","Opie ftp client is copyright 2002 by\n"
01504                          "L.J.Potter<llornkcor@handhelds.org>\n"
01505                          "and uses ftplib copyright 1996-2000\n"
01506                          "by Thomas Pfau, pfau@cnj.digex.net\n\n"
01507                          "and is licensed by the GPL");
01508 }
01509 
01510 void OpieFtp::NewServer() {
01511     InputDialog *fileDlg;
01512     fileDlg = new InputDialog(this,tr("New Server name"),TRUE, 0);
01513     fileDlg->exec();
01514     Config cfg("opieftp");
01515     if( fileDlg->result() == 1 ) {
01516       newServerName = fileDlg->LineEdit1->text();
01517       for(int i=1;i<serverListView->count();i++) {
01518           cfg.setGroup( QString::number(i));
01519           if(cfg.readEntry("ServerName").find(newServerName,0,TRUE) != -1) {
01520               QMessageBox::message(tr("OpieFtp"),tr("Sorry name already taken"));
01521               return;
01522           }
01523       }
01524       currentServerConfig =-1;
01525       writeConfig();
01526       serverListView->insertItem( newServerName );
01527       serverListView->setCurrentItem( serverListView->count());
01528     }
01529 }
01530 
01531 void OpieFtp::serverListClicked( const QString &item) {
01532     if(item.isEmpty()) return;
01533     Config cfg("opieftp");
01534 //    odebug << "highltined "+item << oendl; 
01535     int numberOfEntries = cfg.readNumEntry("numberOfEntries",0);
01536         for (int i = 1; i <= numberOfEntries; i++) {
01537             cfg.setGroup(QString::number(i));
01538               if(cfg.readEntry( "ServerName").find(item) != -1 && !fuckeduphack)
01539                   serverComboSelected(i-1);
01540     }
01541 }
01542 
01543 void OpieFtp::timerOut() {
01544 
01545 }

Generated on Sat Nov 5 16:17:40 2005 for OPIE by  doxygen 1.4.2