summaryrefslogtreecommitdiff
path: root/noncore
authorllornkcor <llornkcor>2004-06-16 09:00:30 (UTC)
committer llornkcor <llornkcor>2004-06-16 09:00:30 (UTC)
commit80ca3700b54c886d761cf1cd32a529a558541d5c (patch) (side-by-side diff)
tree8612c2b07ef31f6c9a415ba0cb132c2ea7dd3389 /noncore
parent80bf424ffc8394026c8bea825d91413b472d502a (diff)
downloadopie-80ca3700b54c886d761cf1cd32a529a558541d5c.zip
opie-80ca3700b54c886d761cf1cd32a529a558541d5c.tar.gz
opie-80ca3700b54c886d761cf1cd32a529a558541d5c.tar.bz2
dynamic layout and reformat whitespace
Diffstat (limited to 'noncore') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-gutenbrowser/NetworkDialog.cpp426
1 files changed, 185 insertions, 241 deletions
diff --git a/noncore/apps/opie-gutenbrowser/NetworkDialog.cpp b/noncore/apps/opie-gutenbrowser/NetworkDialog.cpp
index d629449..af14aac 100644
--- a/noncore/apps/opie-gutenbrowser/NetworkDialog.cpp
+++ b/noncore/apps/opie-gutenbrowser/NetworkDialog.cpp
@@ -41,30 +41,30 @@ QPushButton* buttonCancel;
static netbuf *conn = NULL;
static int log_progress(netbuf *ctl, int xfered, void *arg) {
- int fsz = *(int *)arg;
- int pct = (xfered * 100) / fsz;
- printf("%3d%%\r", pct);
- fflush(stdout);
- ProgressBar1->setProgress(xfered);
- qApp->processEvents();
-
- return 1;
+ int fsz = *(int *)arg;
+ int pct = (xfered * 100) / fsz;
+ printf("%3d%%\r", pct);
+ fflush(stdout);
+ ProgressBar1->setProgress(xfered);
+ qApp->processEvents();
+
+ return 1;
}
NetworkDialog::NetworkDialog( QWidget* parent, const char* name, bool modal, WFlags fl, const QStringList netL)
- : QDialog( parent, name, modal, fl )
+ : QDialog( parent, name, modal, fl )
{
- ftp_host = netL[0];
- networkUrl = strUrl = netL[0];
+ ftp_host = netL[0];
+ networkUrl = strUrl = netL[0];
- dir = ftp_base_dir = netL[1];
- localFileName = netL[2];
- s_partialFileName = netL[3];
+ dir = ftp_base_dir = netL[1];
+ localFileName = netL[2];
+ s_partialFileName = netL[3];
- resize(240,120);
+ resize(240,120);
- local_library = (QDir::homeDirPath ()) +"/Applications/gutenbrowser/";
+ local_library = (QDir::homeDirPath ()) +"/Applications/gutenbrowser/";
// autoOk = autoDownload;
// if( networkUrl.find("ftp",0,false)== -1 ) {
// if ( !name )
@@ -73,11 +73,11 @@ NetworkDialog::NetworkDialog( QWidget* parent, const char* name, bool modal, WF
// qInitNetworkProtocols(); // registers ftp protocol // for now
// QNetworkProtocol::registerNetworkProtocol( "http", new QNetworkProtocolFactory<Http> );
// } else {
- if ( !name )
- setName( "FTP NetworkDialog" );
- setCaption(tr("FTP Download"));
+ if ( !name )
+ setName( "FTP NetworkDialog" );
+ setCaption(tr("FTP Download"));
// }
- initDialog(); //opens file to be written
+ initDialog(); //opens file to be written
}
NetworkDialog::~NetworkDialog() {
@@ -85,137 +85,81 @@ NetworkDialog::~NetworkDialog() {
void NetworkDialog::initDialog() {
- totalBytesDownloaded=0;
- warnLabel = new QLabel( this, "TextLabel" );
- warnLabel ->setText( tr( "Push Ok to download file...." ) );
- TextLabel3 = new QLabel( this, "TextLabel3" );
- TextLabel3->setText( "");
- QWidget* Layout1 = new QWidget( this, "Layout1" );
-
- hbox = new QHBoxLayout(Layout1);
- hbox->setMargin(4);
-
- ProgressBar1 = new QProgressBar( Layout1, "ProgressBar1" );
- ProgressBar1->setProgress(0);
- hbox->addWidget(ProgressBar1,10,AlignCenter);
-
- // hbox->addStretch(1);
-// buttonOk = new QPushButton( Layout1, "buttonOk" );
-// buttonOk->setText( tr( "&OK" ) );
-// hbox->addWidget(buttonOk,0,AlignRight);
-// hbox->addSpacing(5);
- buttonCancel = new QPushButton( Layout1, "buttonCancel" );
- buttonCancel->setText( tr( "&Cancel" ) );
- buttonCancel->setAutoDefault( TRUE );
- buttonCancel->setDefault( TRUE );
- hbox->addWidget(buttonCancel,0,AlignRight);
-
- ProgressBar1->setFixedSize(150,25);
-// buttonOk->setFixedSize(35,22);
- buttonCancel->setFixedSize(50,25);
- warnLabel ->setGeometry( QRect( 5,1,230,25));
- TextLabel3->setGeometry( QRect( 5,20,230,25));
- Layout1->setGeometry( QRect(1,60,235,50)); //TODO check these!!
-
-// timer= new QTimer(this,"vu timer");
-// connectionTimer=new QTimer(this,"connectionTimeout");
-
-// connect(buttonOk,SIGNAL(clicked()),this,SLOT(doOk()));
- connect(buttonCancel,SIGNAL(clicked()),this,SLOT(reject()));
-// connect( timer, SIGNAL(timeout()), this , SLOT(timeSlot()));
-// connect( connectionTimer,SIGNAL( timeout()),this,SLOT( connectionTimeSlot()));
-// if(autoOk) {
-// buttonOk->setDown(true);
- QTimer::singleShot( 1000, this, SLOT( doOk() ));
-// }
-
-}
-
-void NetworkDialog::timeSlot() {
-
-// if(timerProgess < 19 && posTimer) {
-// ProgressBar1->setProgress(timerProgess);
-// timerProgess++;
-// } else if(timerProgess > 19 && posTimer) {
-// ProgressBar1->setProgress(timerProgess);
-// timerProgess++;
-// posTimer=FALSE;
-// }
-// if(timerProgess > 1 &&!posTimer) {
-// ProgressBar1->setProgress(timerProgess);
-// timerProgess--;
-// } else if(timerProgess > 1 &&!posTimer){
-// ProgressBar1->setProgress(timerProgess);
-// timerProgess--;
-// posTimer=TRUE;
-// }
-// // odebug << "timer event" << oendl;
-// qApp->processEvents();
-// repaint();
-}
+ QGridLayout *layout = new QGridLayout( this );
+ totalBytesDownloaded=0;
+ warnLabel = new QLabel( this, "TextLabel" );
+ warnLabel ->setText( tr( "Download should start shortly" ) );
+ TextLabel3 = new QLabel( this, "TextLabel3" );
+ TextLabel3->setText( "");
+ layout->addMultiCellWidget( warnLabel, 0, 0, 0, 5 );
+ layout->addMultiCellWidget( TextLabel3, 1, 1, 0, 5 );
+
+ ProgressBar1 = new QProgressBar( this, "ProgressBar1" );
+ ProgressBar1->setProgress(0);
+ layout->addMultiCellWidget( ProgressBar1, 3, 3, 0, 4 );
+
+ // hbox->addStretch(1);
+ buttonCancel = new QPushButton( this, "buttonCancel" );
+ buttonCancel->setText( tr( "&Cancel" ) );
+ buttonCancel->setAutoDefault( TRUE );
+ buttonCancel->setDefault( TRUE );
+ layout->addMultiCellWidget( buttonCancel, 3, 3, 5, 5 );
+
+ connect(buttonCancel,SIGNAL(clicked()),this,SLOT(reject()));
+ QTimer::singleShot( 1000, this, SLOT( doOk() ));
-void NetworkDialog::connectionTimeSlot() {
-// odebug << "Connections timed out" << oendl;
-// ftpQuit();
-// qApp->processEvents();
-// repaint();
-// reject();
}
-
/*
-downloads the file networkUrl */
+ downloads the file networkUrl */
bool NetworkDialog::downloadFile( QString networkUrl )
{
- int fsz;
-// timer->start( 250 , FALSE);
-// posTimer=TRUE;
-// connectionTimer->start( 600 , FALSE);
- warnLabel ->setText( "");
- qApp->processEvents();
- odebug << "Downloading: " << networkUrl << "" << oendl;
- odebug << "Into: " << localFileName << "" << oendl;
- if( networkUrl.length() > 5) {
- QString ftp_user = "anonymous";
- QString ftp_pass = "zaurus@gutenbrowser.com";
+ int fsz;
+ warnLabel ->setText( "");
+ qApp->processEvents();
+ odebug << "Downloading: " << networkUrl << "" << oendl;
+ odebug << "Into: " << localFileName << "" << oendl;
+ if( networkUrl.length() > 5) {
+ QString ftp_user = "anonymous";
+ QString ftp_pass = "zaurus@gutenbrowser.com";
// ftp_host= networkUrl.mid(networkUrl.find("ftp://",0, TRUE),
- if(ftp_host.length() < 2) {
- odebug << "Please select an ftp host" << oendl;
- successDownload=false;
- QMessageBox::message("Note","You need to select an ftp host");
- return false;
- }
- QString msg;
- odebug << ftp_host << oendl;
- odebug << "Opening ftp connection." << oendl;
- warnLabel->setText("connecting to: "+ftp_host );
- qApp->processEvents();
- /////////// Open FTP connection
- if (!FtpConnect( ftp_host.latin1(), &conn)) {
- i=0;
- successDownload=false;
- QMessageBox::message("Note","Unable to connect to\n"+ftp_host);
- return false;
- }
- TextLabel3->setText("Opening ftp connection.");
- qApp->processEvents();
- if (!FtpLogin( ftp_user.latin1(), ftp_pass.latin1(),conn )) {
- FtpQuit(conn);
- successDownload=false;
- msg.sprintf("Unable to log in\n%s",FtpLastResponse(conn));
- QMessageBox::message("Note",msg);
- return false;
- }
- odebug << "Changing directories." << oendl;
- TextLabel3->setText("Changing directories.");
- qApp->processEvents();
- if (!FtpChdir( dir.latin1(), conn )) {
- successDownload=false;
- msg.sprintf("Unable to change directories "+dir+"\n%s",FtpLastResponse(conn));
- QMessageBox::message("Note",msg);
- FtpQuit(conn);
- return false;
- }
+ if(ftp_host.length() < 2) {
+ odebug << "Please select an ftp host" << oendl;
+ successDownload=false;
+ QMessageBox::message("Note","You need to select an ftp host");
+ return false;
+ }
+ QString msg;
+ odebug << ftp_host << oendl;
+ odebug << "Opening ftp connection." << oendl;
+ warnLabel->setText("connecting to: "+ftp_host );
+ qApp->processEvents();
+ /////////// Open FTP connection
+ if (!FtpConnect( ftp_host.latin1(), &conn)) {
+ i=0;
+ successDownload=false;
+ QMessageBox::message("Note","Unable to connect to\n"+ftp_host);
+ return false;
+ }
+ TextLabel3->setText("Opening ftp connection.");
+ qApp->processEvents();
+ if (!FtpLogin( ftp_user.latin1(), ftp_pass.latin1(),conn )) {
+ FtpQuit(conn);
+ successDownload=false;
+ msg.sprintf("Unable to log in\n%s",FtpLastResponse(conn));
+ QMessageBox::message("Note",msg);
+ return false;
+ }
+ odebug << "Changing directories." << oendl;
+ TextLabel3->setText("Changing directories.");
+ qApp->processEvents();
+ if (!FtpChdir( dir.latin1(), conn )) {
+ successDownload=false;
+ msg.sprintf("Unable to change directories "+dir+"\n%s",FtpLastResponse(conn));
+ QMessageBox::message("Note",msg);
+ FtpQuit(conn);
+ return false;
+ }
// if (!FtpNlst( "./.guten_temp", dir, conn)) {
// successDownload=false;
// msg.sprintf("Unable to change directories "+dir+"\n%s",FtpLastResponse(conn));
@@ -223,113 +167,113 @@ bool NetworkDialog::downloadFile( QString networkUrl )
// FtpQuit(conn);
// return false;
// }
- odebug << "Requesting directory list." << oendl;
- TextLabel3->setText("Getting directory list.");
- qApp->processEvents();
- if (!FtpDir( "./.guten_temp", dir.latin1(), conn) ) {
- msg.sprintf("Unable to list the directory\n"+dir+"\n%s",FtpLastResponse(conn));
- QMessageBox::message("Note",msg);
- successDownload=false;
- FtpQuit(conn);
- return false;
- }
- QFile tmp("./.guten_temp");
- QString s, File_Name;
-
- if (tmp.open(IO_ReadOnly)) {
- QTextStream t( &tmp ); // use a text stream
- odebug << "Finding partial filename "+s_partialFileName << oendl;
- while ( !t.eof()) {
- s = t.readLine();
-
- if (s.contains(s_partialFileName, FALSE)) {
- QString str = s.right( (s.length()) - (s.find(s_partialFileName, FALSE)) );
-
- if (str.contains(".txt")) {
- File_Name = str;
- odebug << "Found file_name "+ File_Name << oendl;
- break;
- }
+ odebug << "Requesting directory list." << oendl;
+ TextLabel3->setText("Getting directory list.");
+ qApp->processEvents();
+ if (!FtpDir( "./.guten_temp", dir.latin1(), conn) ) {
+ msg.sprintf("Unable to list the directory\n"+dir+"\n%s",FtpLastResponse(conn));
+ QMessageBox::message("Note",msg);
+ successDownload=false;
+ FtpQuit(conn);
+ return false;
+ }
+ QFile tmp("./.guten_temp");
+ QString s, File_Name;
+
+ if (tmp.open(IO_ReadOnly)) {
+ QTextStream t( &tmp ); // use a text stream
+ odebug << "Finding partial filename "+s_partialFileName << oendl;
+ while ( !t.eof()) {
+ s = t.readLine();
+
+ if (s.contains(s_partialFileName, FALSE)) {
+ QString str = s.right( (s.length()) - (s.find(s_partialFileName, FALSE)) );
+
+ if (str.contains(".txt")) {
+ File_Name = str;
+ odebug << "Found file_name "+ File_Name << oendl;
+ break;
+ }
// if (str.contains(".zip")) {
// File_Name = str;
// odebug << "Found file_name "+ File_Name << oendl;
// break;
// }
- }
- } //end of while loop
- tmp.close();
+ }
+ } //end of while loop
+ tmp.close();
// tmp.remove(); ///TODO this is for release version Zaurus
- }
- else
- odebug << "Error opening temp file." << oendl;
-
- Config cfg("Gutenbrowser");
- cfg.setGroup("General");
- QString temp=cfg.readEntry("DownloadDirectory",local_library);
-
- localFileName = temp+File_Name;
- odebug << "Requesting file "+ File_Name << oendl;
- odebug << "Saving as "+localFileName << oendl;
- msg="Requesting file "+ File_Name;
- TextLabel3->setText(msg);
- qApp->processEvents();
- if( File_Name.length()>3) {
- if (!FtpSize( File_Name.latin1(), &fsz, FTPLIB_ASCII, conn))
- fsz = 0;
- QString temp;
- temp.sprintf( File_Name+" "+" %dkb", fsz);
- TextLabel3->setText(temp);
-
- ProgressBar1->setTotalSteps(fsz);
- FtpOptions(FTPLIB_CALLBACK, (long) log_progress, conn);
- FtpOptions(FTPLIB_IDLETIME, (long) 1000, conn);
- FtpOptions(FTPLIB_CALLBACKARG, (long) &fsz, conn);
- FtpOptions(FTPLIB_CALLBACKBYTES, (long) fsz/10, conn);
-
- if (!FtpGet( localFileName.latin1(), File_Name.latin1(), FTPLIB_ASCII, conn)) {
- msg.sprintf("Could not download "+ File_Name+"\n%s",FtpLastResponse(conn));
- successDownload=false;
- QMessageBox::message("Note",msg);
- update();
- }
- } else {
- QMessageBox::message("Note","Could not download file "+ File_Name);
- successDownload=false;
- FtpQuit(conn);
- return false;
- }
- odebug << "Ftp session successful" << oendl;
- successDownload=TRUE;
- FtpQuit(conn);
- return true;
- } //no network url
- return false;
+ }
+ else
+ odebug << "Error opening temp file." << oendl;
+
+ Config cfg("Gutenbrowser");
+ cfg.setGroup("General");
+ QString temp=cfg.readEntry("DownloadDirectory",local_library);
+
+ localFileName = temp+File_Name;
+ odebug << "Requesting file "+ File_Name << oendl;
+ odebug << "Saving as "+localFileName << oendl;
+ msg="Requesting file "+ File_Name;
+ TextLabel3->setText(msg);
+ qApp->processEvents();
+ if( File_Name.length()>3) {
+ if (!FtpSize( File_Name.latin1(), &fsz, FTPLIB_ASCII, conn))
+ fsz = 0;
+ QString temp;
+ temp.sprintf( File_Name+" "+" %dkb", fsz);
+ TextLabel3->setText(temp);
+
+ ProgressBar1->setTotalSteps(fsz);
+ FtpOptions(FTPLIB_CALLBACK, (long) log_progress, conn);
+ FtpOptions(FTPLIB_IDLETIME, (long) 1000, conn);
+ FtpOptions(FTPLIB_CALLBACKARG, (long) &fsz, conn);
+ FtpOptions(FTPLIB_CALLBACKBYTES, (long) fsz/10, conn);
+
+ if (!FtpGet( localFileName.latin1(), File_Name.latin1(), FTPLIB_ASCII, conn)) {
+ msg.sprintf("Could not download "+ File_Name+"\n%s",FtpLastResponse(conn));
+ successDownload=false;
+ QMessageBox::message("Note",msg);
+ update();
+ }
+ } else {
+ QMessageBox::message("Note","Could not download file "+ File_Name);
+ successDownload=false;
+ FtpQuit(conn);
+ return false;
+ }
+ odebug << "Ftp session successful" << oendl;
+ successDownload=TRUE;
+ FtpQuit(conn);
+ return true;
+ } //no network url
+ return false;
}
void NetworkDialog::doOk() {
- owarn << "Do OK" << oendl;
- QString loginStr;
- loginStr = "gutenbrowser";
- if ( !ftp_host.isEmpty() ) {
- if( ftp_host.find( "/", ftp_host.length() - 1,TRUE) != -1 && ftp_host.find("ftp://",0, TRUE) != -1) {
- TextLabel3->setText( tr( "List remote dir:\n" + ftp_host) );
+ owarn << "Do OK" << oendl;
+ QString loginStr;
+ loginStr = "gutenbrowser";
+ if ( !ftp_host.isEmpty() ) {
+ if( ftp_host.find( "/", ftp_host.length() - 1,TRUE) != -1 && ftp_host.find("ftp://",0, TRUE) != -1) {
+ TextLabel3->setText( tr( "List remote dir:\n" + ftp_host) );
// TextLabel2->setText( tr( "local file to download into: " +localFileName ) );
- if( downloadFile(ftp_host))
- successDownload = true;
- else {
- successDownload = false;
- reject();
- }
- } else {
- if(downloadFile(ftp_host))
- successDownload = true;
- else {
- successDownload = false;
- reject();
- }
- }
- }
- accept();
+ if( downloadFile(ftp_host))
+ successDownload = true;
+ else {
+ successDownload = false;
+ reject();
+ }
+ } else {
+ if(downloadFile(ftp_host))
+ successDownload = true;
+ else {
+ successDownload = false;
+ reject();
+ }
+ }
+ }
+ accept();
}