summaryrefslogtreecommitdiff
Unidiff
Diffstat (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
@@ -32,304 +32,248 @@
32 32
33/* STD */ 33/* STD */
34#include <unistd.h> 34#include <unistd.h>
35extern "C" { 35extern "C" {
36#include <ftplib.h> 36#include <ftplib.h>
37} 37}
38 38
39QProgressBar* ProgressBar1; 39QProgressBar* ProgressBar1;
40QPushButton* buttonCancel; 40QPushButton* buttonCancel;
41static netbuf *conn = NULL; 41static netbuf *conn = NULL;
42 42
43static int log_progress(netbuf *ctl, int xfered, void *arg) { 43static int log_progress(netbuf *ctl, int xfered, void *arg) {
44 int fsz = *(int *)arg; 44 int fsz = *(int *)arg;
45 int pct = (xfered * 100) / fsz; 45 int pct = (xfered * 100) / fsz;
46 printf("%3d%%\r", pct); 46 printf("%3d%%\r", pct);
47 fflush(stdout); 47 fflush(stdout);
48 ProgressBar1->setProgress(xfered); 48 ProgressBar1->setProgress(xfered);
49 qApp->processEvents(); 49 qApp->processEvents();
50 50
51 return 1; 51 return 1;
52} 52}
53 53
54NetworkDialog::NetworkDialog( QWidget* parent, const char* name, bool modal, WFlags fl, const QStringList netL) 54NetworkDialog::NetworkDialog( QWidget* parent, const char* name, bool modal, WFlags fl, const QStringList netL)
55 : QDialog( parent, name, modal, fl ) 55 : QDialog( parent, name, modal, fl )
56{ 56{
57 57
58 ftp_host = netL[0]; 58 ftp_host = netL[0];
59 networkUrl = strUrl = netL[0]; 59 networkUrl = strUrl = netL[0];
60 60
61 dir = ftp_base_dir = netL[1]; 61 dir = ftp_base_dir = netL[1];
62 localFileName = netL[2]; 62 localFileName = netL[2];
63 s_partialFileName = netL[3]; 63 s_partialFileName = netL[3];
64 64
65 resize(240,120); 65 resize(240,120);
66 66
67 local_library = (QDir::homeDirPath ()) +"/Applications/gutenbrowser/"; 67 local_library = (QDir::homeDirPath ()) +"/Applications/gutenbrowser/";
68// autoOk = autoDownload; 68// autoOk = autoDownload;
69// if( networkUrl.find("ftp",0,false)== -1 ) { 69// if( networkUrl.find("ftp",0,false)== -1 ) {
70// if ( !name ) 70// if ( !name )
71// setName( "HTTP NetworkDialog" ); 71// setName( "HTTP NetworkDialog" );
72// setCaption( tr( "HTTP Download ) ); 72// setCaption( tr( "HTTP Download ) );
73// qInitNetworkProtocols(); // registers ftp protocol // for now 73// qInitNetworkProtocols(); // registers ftp protocol // for now
74// QNetworkProtocol::registerNetworkProtocol( "http", new QNetworkProtocolFactory<Http> ); 74// QNetworkProtocol::registerNetworkProtocol( "http", new QNetworkProtocolFactory<Http> );
75// } else { 75// } else {
76 if ( !name ) 76 if ( !name )
77 setName( "FTP NetworkDialog" ); 77 setName( "FTP NetworkDialog" );
78 setCaption(tr("FTP Download")); 78 setCaption(tr("FTP Download"));
79// } 79// }
80 initDialog(); //opens file to be written 80 initDialog(); //opens file to be written
81} 81}
82 82
83NetworkDialog::~NetworkDialog() { 83NetworkDialog::~NetworkDialog() {
84} 84}
85 85
86void NetworkDialog::initDialog() { 86void NetworkDialog::initDialog() {
87 87
88 totalBytesDownloaded=0; 88 QGridLayout *layout = new QGridLayout( this );
89 warnLabel = new QLabel( this, "TextLabel" ); 89 totalBytesDownloaded=0;
90 warnLabel ->setText( tr( "Push Ok to download file...." ) ); 90 warnLabel = new QLabel( this, "TextLabel" );
91 TextLabel3 = new QLabel( this, "TextLabel3" ); 91 warnLabel ->setText( tr( "Download should start shortly" ) );
92 TextLabel3->setText( ""); 92 TextLabel3 = new QLabel( this, "TextLabel3" );
93 QWidget* Layout1 = new QWidget( this, "Layout1" ); 93 TextLabel3->setText( "");
94 94 layout->addMultiCellWidget( warnLabel, 0, 0, 0, 5 );
95 hbox = new QHBoxLayout(Layout1); 95 layout->addMultiCellWidget( TextLabel3, 1, 1, 0, 5 );
96 hbox->setMargin(4); 96
97 97 ProgressBar1 = new QProgressBar( this, "ProgressBar1" );
98 ProgressBar1 = new QProgressBar( Layout1, "ProgressBar1" ); 98 ProgressBar1->setProgress(0);
99 ProgressBar1->setProgress(0); 99 layout->addMultiCellWidget( ProgressBar1, 3, 3, 0, 4 );
100 hbox->addWidget(ProgressBar1,10,AlignCenter); 100
101 101 // hbox->addStretch(1);
102 // hbox->addStretch(1); 102 buttonCancel = new QPushButton( this, "buttonCancel" );
103// buttonOk = new QPushButton( Layout1, "buttonOk" ); 103 buttonCancel->setText( tr( "&Cancel" ) );
104// buttonOk->setText( tr( "&OK" ) ); 104 buttonCancel->setAutoDefault( TRUE );
105// hbox->addWidget(buttonOk,0,AlignRight); 105 buttonCancel->setDefault( TRUE );
106// hbox->addSpacing(5); 106 layout->addMultiCellWidget( buttonCancel, 3, 3, 5, 5 );
107 buttonCancel = new QPushButton( Layout1, "buttonCancel" ); 107
108 buttonCancel->setText( tr( "&Cancel" ) ); 108 connect(buttonCancel,SIGNAL(clicked()),this,SLOT(reject()));
109 buttonCancel->setAutoDefault( TRUE ); 109 QTimer::singleShot( 1000, this, SLOT( doOk() ));
110 buttonCancel->setDefault( TRUE );
111 hbox->addWidget(buttonCancel,0,AlignRight);
112
113 ProgressBar1->setFixedSize(150,25);
114// buttonOk->setFixedSize(35,22);
115 buttonCancel->setFixedSize(50,25);
116 warnLabel ->setGeometry( QRect( 5,1,230,25));
117 TextLabel3->setGeometry( QRect( 5,20,230,25));
118 Layout1->setGeometry( QRect(1,60,235,50)); //TODO check these!!
119
120// timer= new QTimer(this,"vu timer");
121// connectionTimer=new QTimer(this,"connectionTimeout");
122
123// connect(buttonOk,SIGNAL(clicked()),this,SLOT(doOk()));
124 connect(buttonCancel,SIGNAL(clicked()),this,SLOT(reject()));
125// connect( timer, SIGNAL(timeout()), this , SLOT(timeSlot()));
126// connect( connectionTimer,SIGNAL( timeout()),this,SLOT( connectionTimeSlot()));
127// if(autoOk) {
128// buttonOk->setDown(true);
129 QTimer::singleShot( 1000, this, SLOT( doOk() ));
130// }
131
132}
133
134void NetworkDialog::timeSlot() {
135
136// if(timerProgess < 19 && posTimer) {
137// ProgressBar1->setProgress(timerProgess);
138// timerProgess++;
139// } else if(timerProgess > 19 && posTimer) {
140// ProgressBar1->setProgress(timerProgess);
141// timerProgess++;
142// posTimer=FALSE;
143// }
144// if(timerProgess > 1 &&!posTimer) {
145// ProgressBar1->setProgress(timerProgess);
146// timerProgess--;
147// } else if(timerProgess > 1 &&!posTimer){
148// ProgressBar1->setProgress(timerProgess);
149// timerProgess--;
150// posTimer=TRUE;
151// }
152// // odebug << "timer event" << oendl;
153// qApp->processEvents();
154// repaint();
155}
156 110
157void NetworkDialog::connectionTimeSlot() {
158// odebug << "Connections timed out" << oendl;
159// ftpQuit();
160// qApp->processEvents();
161// repaint();
162// reject();
163} 111}
164 112
165
166/* 113/*
167downloads the file networkUrl */ 114 downloads the file networkUrl */
168bool NetworkDialog::downloadFile( QString networkUrl ) 115bool NetworkDialog::downloadFile( QString networkUrl )
169{ 116{
170 int fsz; 117 int fsz;
171// timer->start( 250 , FALSE); 118 warnLabel ->setText( "");
172// posTimer=TRUE; 119 qApp->processEvents();
173// connectionTimer->start( 600 , FALSE); 120 odebug << "Downloading: " << networkUrl << "" << oendl;
174 warnLabel ->setText( ""); 121 odebug << "Into: " << localFileName << "" << oendl;
175 qApp->processEvents(); 122 if( networkUrl.length() > 5) {
176 odebug << "Downloading: " << networkUrl << "" << oendl; 123 QString ftp_user = "anonymous";
177 odebug << "Into: " << localFileName << "" << oendl; 124 QString ftp_pass = "zaurus@gutenbrowser.com";
178 if( networkUrl.length() > 5) {
179 QString ftp_user = "anonymous";
180 QString ftp_pass = "zaurus@gutenbrowser.com";
181// ftp_host= networkUrl.mid(networkUrl.find("ftp://",0, TRUE), 125// ftp_host= networkUrl.mid(networkUrl.find("ftp://",0, TRUE),
182 if(ftp_host.length() < 2) { 126 if(ftp_host.length() < 2) {
183 odebug << "Please select an ftp host" << oendl; 127 odebug << "Please select an ftp host" << oendl;
184 successDownload=false; 128 successDownload=false;
185 QMessageBox::message("Note","You need to select an ftp host"); 129 QMessageBox::message("Note","You need to select an ftp host");
186 return false; 130 return false;
187 } 131 }
188 QString msg; 132 QString msg;
189 odebug << ftp_host << oendl; 133 odebug << ftp_host << oendl;
190 odebug << "Opening ftp connection." << oendl; 134 odebug << "Opening ftp connection." << oendl;
191 warnLabel->setText("connecting to: "+ftp_host ); 135 warnLabel->setText("connecting to: "+ftp_host );
192 qApp->processEvents(); 136 qApp->processEvents();
193 /////////// Open FTP connection 137 /////////// Open FTP connection
194 if (!FtpConnect( ftp_host.latin1(), &conn)) { 138 if (!FtpConnect( ftp_host.latin1(), &conn)) {
195 i=0; 139 i=0;
196 successDownload=false; 140 successDownload=false;
197 QMessageBox::message("Note","Unable to connect to\n"+ftp_host); 141 QMessageBox::message("Note","Unable to connect to\n"+ftp_host);
198 return false; 142 return false;
199 } 143 }
200 TextLabel3->setText("Opening ftp connection."); 144 TextLabel3->setText("Opening ftp connection.");
201 qApp->processEvents(); 145 qApp->processEvents();
202 if (!FtpLogin( ftp_user.latin1(), ftp_pass.latin1(),conn )) { 146 if (!FtpLogin( ftp_user.latin1(), ftp_pass.latin1(),conn )) {
203 FtpQuit(conn); 147 FtpQuit(conn);
204 successDownload=false; 148 successDownload=false;
205 msg.sprintf("Unable to log in\n%s",FtpLastResponse(conn)); 149 msg.sprintf("Unable to log in\n%s",FtpLastResponse(conn));
206 QMessageBox::message("Note",msg); 150 QMessageBox::message("Note",msg);
207 return false; 151 return false;
208 } 152 }
209 odebug << "Changing directories." << oendl; 153 odebug << "Changing directories." << oendl;
210 TextLabel3->setText("Changing directories."); 154 TextLabel3->setText("Changing directories.");
211 qApp->processEvents(); 155 qApp->processEvents();
212 if (!FtpChdir( dir.latin1(), conn )) { 156 if (!FtpChdir( dir.latin1(), conn )) {
213 successDownload=false; 157 successDownload=false;
214 msg.sprintf("Unable to change directories "+dir+"\n%s",FtpLastResponse(conn)); 158 msg.sprintf("Unable to change directories "+dir+"\n%s",FtpLastResponse(conn));
215 QMessageBox::message("Note",msg); 159 QMessageBox::message("Note",msg);
216 FtpQuit(conn); 160 FtpQuit(conn);
217 return false; 161 return false;
218 } 162 }
219// if (!FtpNlst( "./.guten_temp", dir, conn)) { 163// if (!FtpNlst( "./.guten_temp", dir, conn)) {
220// successDownload=false; 164// successDownload=false;
221// msg.sprintf("Unable to change directories "+dir+"\n%s",FtpLastResponse(conn)); 165// msg.sprintf("Unable to change directories "+dir+"\n%s",FtpLastResponse(conn));
222// QMessageBox::message("Note",msg); 166// QMessageBox::message("Note",msg);
223// FtpQuit(conn); 167// FtpQuit(conn);
224// return false; 168// return false;
225// } 169// }
226 odebug << "Requesting directory list." << oendl; 170 odebug << "Requesting directory list." << oendl;
227 TextLabel3->setText("Getting directory list."); 171 TextLabel3->setText("Getting directory list.");
228 qApp->processEvents(); 172 qApp->processEvents();
229 if (!FtpDir( "./.guten_temp", dir.latin1(), conn) ) { 173 if (!FtpDir( "./.guten_temp", dir.latin1(), conn) ) {
230 msg.sprintf("Unable to list the directory\n"+dir+"\n%s",FtpLastResponse(conn)); 174 msg.sprintf("Unable to list the directory\n"+dir+"\n%s",FtpLastResponse(conn));
231 QMessageBox::message("Note",msg); 175 QMessageBox::message("Note",msg);
232 successDownload=false; 176 successDownload=false;
233 FtpQuit(conn); 177 FtpQuit(conn);
234 return false; 178 return false;
235 } 179 }
236 QFile tmp("./.guten_temp"); 180 QFile tmp("./.guten_temp");
237 QString s, File_Name; 181 QString s, File_Name;
238 182
239 if (tmp.open(IO_ReadOnly)) { 183 if (tmp.open(IO_ReadOnly)) {
240 QTextStream t( &tmp ); // use a text stream 184 QTextStream t( &tmp ); // use a text stream
241 odebug << "Finding partial filename "+s_partialFileName << oendl; 185 odebug << "Finding partial filename "+s_partialFileName << oendl;
242 while ( !t.eof()) { 186 while ( !t.eof()) {
243 s = t.readLine(); 187 s = t.readLine();
244 188
245 if (s.contains(s_partialFileName, FALSE)) { 189 if (s.contains(s_partialFileName, FALSE)) {
246 QString str = s.right( (s.length()) - (s.find(s_partialFileName, FALSE)) ); 190 QString str = s.right( (s.length()) - (s.find(s_partialFileName, FALSE)) );
247 191
248 if (str.contains(".txt")) { 192 if (str.contains(".txt")) {
249 File_Name = str; 193 File_Name = str;
250 odebug << "Found file_name "+ File_Name << oendl; 194 odebug << "Found file_name "+ File_Name << oendl;
251 break; 195 break;
252 } 196 }
253// if (str.contains(".zip")) { 197// if (str.contains(".zip")) {
254// File_Name = str; 198// File_Name = str;
255// odebug << "Found file_name "+ File_Name << oendl; 199// odebug << "Found file_name "+ File_Name << oendl;
256// break; 200// break;
257// } 201// }
258 202
259 } 203 }
260 } //end of while loop 204 } //end of while loop
261 tmp.close(); 205 tmp.close();
262// tmp.remove(); ///TODO this is for release version Zaurus 206// tmp.remove(); ///TODO this is for release version Zaurus
263 } 207 }
264 else 208 else
265 odebug << "Error opening temp file." << oendl; 209 odebug << "Error opening temp file." << oendl;
266 210
267 Config cfg("Gutenbrowser"); 211 Config cfg("Gutenbrowser");
268 cfg.setGroup("General"); 212 cfg.setGroup("General");
269 QString temp=cfg.readEntry("DownloadDirectory",local_library); 213 QString temp=cfg.readEntry("DownloadDirectory",local_library);
270 214
271 localFileName = temp+File_Name; 215 localFileName = temp+File_Name;
272 odebug << "Requesting file "+ File_Name << oendl; 216 odebug << "Requesting file "+ File_Name << oendl;
273 odebug << "Saving as "+localFileName << oendl; 217 odebug << "Saving as "+localFileName << oendl;
274 msg="Requesting file "+ File_Name; 218 msg="Requesting file "+ File_Name;
275 TextLabel3->setText(msg); 219 TextLabel3->setText(msg);
276 qApp->processEvents(); 220 qApp->processEvents();
277 if( File_Name.length()>3) { 221 if( File_Name.length()>3) {
278 if (!FtpSize( File_Name.latin1(), &fsz, FTPLIB_ASCII, conn)) 222 if (!FtpSize( File_Name.latin1(), &fsz, FTPLIB_ASCII, conn))
279 fsz = 0; 223 fsz = 0;
280 QString temp; 224 QString temp;
281 temp.sprintf( File_Name+" "+" %dkb", fsz); 225 temp.sprintf( File_Name+" "+" %dkb", fsz);
282 TextLabel3->setText(temp); 226 TextLabel3->setText(temp);
283 227
284 ProgressBar1->setTotalSteps(fsz); 228 ProgressBar1->setTotalSteps(fsz);
285 FtpOptions(FTPLIB_CALLBACK, (long) log_progress, conn); 229 FtpOptions(FTPLIB_CALLBACK, (long) log_progress, conn);
286 FtpOptions(FTPLIB_IDLETIME, (long) 1000, conn); 230 FtpOptions(FTPLIB_IDLETIME, (long) 1000, conn);
287 FtpOptions(FTPLIB_CALLBACKARG, (long) &fsz, conn); 231 FtpOptions(FTPLIB_CALLBACKARG, (long) &fsz, conn);
288 FtpOptions(FTPLIB_CALLBACKBYTES, (long) fsz/10, conn); 232 FtpOptions(FTPLIB_CALLBACKBYTES, (long) fsz/10, conn);
289 233
290 if (!FtpGet( localFileName.latin1(), File_Name.latin1(), FTPLIB_ASCII, conn)) { 234 if (!FtpGet( localFileName.latin1(), File_Name.latin1(), FTPLIB_ASCII, conn)) {
291 msg.sprintf("Could not download "+ File_Name+"\n%s",FtpLastResponse(conn)); 235 msg.sprintf("Could not download "+ File_Name+"\n%s",FtpLastResponse(conn));
292 successDownload=false; 236 successDownload=false;
293 QMessageBox::message("Note",msg); 237 QMessageBox::message("Note",msg);
294 update(); 238 update();
295 } 239 }
296 } else { 240 } else {
297 QMessageBox::message("Note","Could not download file "+ File_Name); 241 QMessageBox::message("Note","Could not download file "+ File_Name);
298 successDownload=false; 242 successDownload=false;
299 FtpQuit(conn); 243 FtpQuit(conn);
300 return false; 244 return false;
301 } 245 }
302 odebug << "Ftp session successful" << oendl; 246 odebug << "Ftp session successful" << oendl;
303 successDownload=TRUE; 247 successDownload=TRUE;
304 FtpQuit(conn); 248 FtpQuit(conn);
305 return true; 249 return true;
306 } //no network url 250 } //no network url
307 return false; 251 return false;
308} 252}
309 253
310void NetworkDialog::doOk() { 254void NetworkDialog::doOk() {
311 owarn << "Do OK" << oendl; 255 owarn << "Do OK" << oendl;
312 QString loginStr; 256 QString loginStr;
313 loginStr = "gutenbrowser"; 257 loginStr = "gutenbrowser";
314 if ( !ftp_host.isEmpty() ) { 258 if ( !ftp_host.isEmpty() ) {
315 if( ftp_host.find( "/", ftp_host.length() - 1,TRUE) != -1 && ftp_host.find("ftp://",0, TRUE) != -1) { 259 if( ftp_host.find( "/", ftp_host.length() - 1,TRUE) != -1 && ftp_host.find("ftp://",0, TRUE) != -1) {
316 TextLabel3->setText( tr( "List remote dir:\n" + ftp_host) ); 260 TextLabel3->setText( tr( "List remote dir:\n" + ftp_host) );
317// TextLabel2->setText( tr( "local file to download into: " +localFileName ) ); 261// TextLabel2->setText( tr( "local file to download into: " +localFileName ) );
318 262
319 if( downloadFile(ftp_host)) 263 if( downloadFile(ftp_host))
320 successDownload = true; 264 successDownload = true;
321 else { 265 else {
322 successDownload = false; 266 successDownload = false;
323 reject(); 267 reject();
324 } 268 }
325 } else { 269 } else {
326 if(downloadFile(ftp_host)) 270 if(downloadFile(ftp_host))
327 successDownload = true; 271 successDownload = true;
328 else { 272 else {
329 successDownload = false; 273 successDownload = false;
330 reject(); 274 reject();
331 } 275 }
332 } 276 }
333 } 277 }
334 accept(); 278 accept();
335} 279}