Diffstat (limited to 'noncore/apps/opie-gutenbrowser/ftpsitedlg.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/opie-gutenbrowser/ftpsitedlg.cpp | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/noncore/apps/opie-gutenbrowser/ftpsitedlg.cpp b/noncore/apps/opie-gutenbrowser/ftpsitedlg.cpp index ad770b5..a9c7346 100644 --- a/noncore/apps/opie-gutenbrowser/ftpsitedlg.cpp +++ b/noncore/apps/opie-gutenbrowser/ftpsitedlg.cpp | |||
@@ -2,52 +2,57 @@ | |||
2 | ftpsitedlg.cpp - description | 2 | ftpsitedlg.cpp - description |
3 | ------------------- | 3 | ------------------- |
4 | begin : Tue Jul 25 2000 | 4 | begin : Tue Jul 25 2000 |
5 | copyright : (C) 2000 -2004 by llornkcor | 5 | copyright : (C) 2000 -2004 by llornkcor |
6 | email : ljp@llornkcor.com | 6 | email : ljp@llornkcor.com |
7 | ***************************************************************************/ | 7 | ***************************************************************************/ |
8 | /*************************************************************************** | 8 | /*************************************************************************** |
9 | * This program is free software; you can redistribute it and/or modify * | 9 | * This program is free software; you can redistribute it and/or modify * |
10 | * it under the terms of the GNU General Public License as published by * | 10 | * it under the terms of the GNU General Public License as published by * |
11 | * the Free Software Foundation; either version 2 of the License, or * | 11 | * the Free Software Foundation; either version 2 of the License, or * |
12 | * (at your option) any later version. * | 12 | * (at your option) any later version. * |
13 | ***************************************************************************/ | 13 | ***************************************************************************/ |
14 | |||
14 | #include "optionsDialog.h" | 15 | #include "optionsDialog.h" |
15 | #include "gutenbrowser.h" | 16 | #include "gutenbrowser.h" |
16 | //#include "NetworkDialog.h" | 17 | //#include "NetworkDialog.h" |
17 | #include "output.h" | 18 | #include "output.h" |
18 | 19 | ||
20 | /* OPIE */ | ||
21 | #include <opie2/odebug.h> | ||
22 | #include <qpe/config.h> | ||
23 | |||
24 | /* QT */ | ||
19 | #include <qprogressbar.h> | 25 | #include <qprogressbar.h> |
20 | #include <stdlib.h> | ||
21 | #include <qurloperator.h> | 26 | #include <qurloperator.h> |
22 | #include <qpe/config.h> | ||
23 | #include <qlistbox.h> | 27 | #include <qlistbox.h> |
24 | 28 | ||
29 | /* STD */ | ||
30 | #include <stdlib.h> | ||
25 | #include <unistd.h> | 31 | #include <unistd.h> |
26 | #include <stdio.h> | 32 | #include <stdio.h> |
27 | #include <stdlib.h> | ||
28 | 33 | ||
29 | // :)~ | 34 | // :)~ |
30 | void optionsDialog::ftpSiteDlg( ) | 35 | void optionsDialog::ftpSiteDlg( ) |
31 | { | 36 | { |
32 | //printf( "ftpSiteDlg: ListFile is "+ ListFile +"\n" ); | 37 | //printf( "ftpSiteDlg: ListFile is "+ ListFile +"\n" ); |
33 | // initDialog(); | 38 | // initDialog(); |
34 | local_library = (QDir::homeDirPath ()) +"/Applications/gutenbrowser/"; | 39 | local_library = (QDir::homeDirPath ()) +"/Applications/gutenbrowser/"; |
35 | // ListFile = local_library + "ftpList"; | 40 | // ListFile = local_library + "ftpList"; |
36 | ListFile = QPEApplication::qpeDir() + "/etc/gutenbrowser"; | 41 | ListFile = QPEApplication::qpeDir() + "/etc/gutenbrowser"; |
37 | QDir dir(ListFile); | 42 | QDir dir(ListFile); |
38 | if( !dir.exists()) | 43 | if( !dir.exists()) |
39 | dir.mkdir(ListFile,true); | 44 | dir.mkdir(ListFile,true); |
40 | ListFile+="/ftpList"; | 45 | ListFile+="/ftpList"; |
41 | qDebug("opening "+ListFile); | 46 | odebug << "opening "+ListFile << oendl; |
42 | if ( QFile(ListFile).exists() ) { | 47 | if ( QFile(ListFile).exists() ) { |
43 | openSiteList(); | 48 | openSiteList(); |
44 | } else { | 49 | } else { |
45 | switch( QMessageBox::warning( this, "Gutenbrowser", | 50 | switch( QMessageBox::warning( this, "Gutenbrowser", |
46 | "Do you want to download \nan ftp site list?", | 51 | "Do you want to download \nan ftp site list?", |
47 | QMessageBox::Yes, QMessageBox::No)) { | 52 | QMessageBox::Yes, QMessageBox::No)) { |
48 | case QMessageBox::Yes: // yes | 53 | case QMessageBox::Yes: // yes |
49 | getSite(); | 54 | getSite(); |
50 | break; | 55 | break; |
51 | case QMessageBox::No: // No | 56 | case QMessageBox::No: // No |
52 | // exit | 57 | // exit |
53 | break; | 58 | break; |
@@ -67,62 +72,62 @@ void optionsDialog::getSite() | |||
67 | // outputFile = local_library+ "list.html"; | 72 | // outputFile = local_library+ "list.html"; |
68 | outputFile = ListFile + "list.html"; | 73 | outputFile = ListFile + "list.html"; |
69 | QString networkUrl= "http://www.gutenberg.org/www/mirror.sites.html"; | 74 | QString networkUrl= "http://www.gutenberg.org/www/mirror.sites.html"; |
70 | //http://www.gutenberg.org/index.html"; | 75 | //http://www.gutenberg.org/index.html"; |
71 | // QString networkUrl= "http://llornkcor.com/index.shtml"; | 76 | // QString networkUrl= "http://llornkcor.com/index.shtml"; |
72 | // // "http://www.gutenberg.org/index.html" | 77 | // // "http://www.gutenberg.org/index.html" |
73 | // | 78 | // |
74 | //Qhttp stops working at times.... :( | 79 | //Qhttp stops working at times.... :( |
75 | // NetworkDialog *NetworkDlg; | 80 | // NetworkDialog *NetworkDlg; |
76 | // NetworkDlg = new NetworkDialog( this,"Network Protocol Dialog",TRUE,0,networkUrl,outputFile); | 81 | // NetworkDlg = new NetworkDialog( this,"Network Protocol Dialog",TRUE,0,networkUrl,outputFile); |
77 | // if( NetworkDlg->exec() != 0 ) | 82 | // if( NetworkDlg->exec() != 0 ) |
78 | // { // use new, improved, *INSTANT* network-dialog-file-getterer | 83 | // { // use new, improved, *INSTANT* network-dialog-file-getterer |
79 | // qDebug("gitcha!"); | 84 | // odebug << "gitcha!" << oendl; |
80 | // } | 85 | // } |
81 | // delete NetworkDlg; | 86 | // delete NetworkDlg; |
82 | //#ifdef Q_WS_QWS | 87 | //#ifdef Q_WS_QWS |
83 | 88 | ||
84 | // TODO qprocess here | 89 | // TODO qprocess here |
85 | 90 | ||
86 | QString cmd="wget -T 15 -O " +outputFile + " " + networkUrl + " 2>&1" ; | 91 | QString cmd="wget -T 15 -O " +outputFile + " " + networkUrl + " 2>&1" ; |
87 | qDebug("Issuing the command "+cmd); | 92 | odebug << "Issuing the command "+cmd << oendl; |
88 | Output *outDlg; | 93 | Output *outDlg; |
89 | outDlg = new Output( 0, tr("Downloading ftp sites...."),TRUE); | 94 | outDlg = new Output( 0, tr("Downloading ftp sites...."),TRUE); |
90 | outDlg->showMaximized(); | 95 | outDlg->showMaximized(); |
91 | outDlg->show(); | 96 | outDlg->show(); |
92 | qApp->processEvents(); | 97 | qApp->processEvents(); |
93 | FILE *fp; | 98 | FILE *fp; |
94 | char line[130]; | 99 | char line[130]; |
95 | outDlg->OutputEdit->append( tr("Running wget") ); | 100 | outDlg->OutputEdit->append( tr("Running wget") ); |
96 | sleep(1); | 101 | sleep(1); |
97 | fp = popen( (const char *) cmd, "r"); | 102 | fp = popen( (const char *) cmd, "r"); |
98 | while ( fgets( line, sizeof line, fp)) { | 103 | while ( fgets( line, sizeof line, fp)) { |
99 | outDlg->OutputEdit->append(line); | 104 | outDlg->OutputEdit->append(line); |
100 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); | 105 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); |
101 | } | 106 | } |
102 | pclose(fp); | 107 | pclose(fp); |
103 | outDlg->close(); | 108 | outDlg->close(); |
104 | if(outDlg) | 109 | if(outDlg) |
105 | delete outDlg; | 110 | delete outDlg; |
106 | 111 | ||
107 | // outputFile=ListFile; | 112 | // outputFile=ListFile; |
108 | ftp_QListBox_1->clear(); | 113 | ftp_QListBox_1->clear(); |
109 | parseFtpList( outputFile); // got the html list, now parse it so we can use it | 114 | parseFtpList( outputFile); // got the html list, now parse it so we can use it |
110 | } | 115 | } |
111 | 116 | ||
112 | bool optionsDialog::parseFtpList( QString outputFile) | 117 | bool optionsDialog::parseFtpList( QString outputFile) |
113 | { | 118 | { |
114 | // parse ftplist html and extract just the machine names/directories | 119 | // parse ftplist html and extract just the machine names/directories |
115 | // TODO: add locations!! | 120 | // TODO: add locations!! |
116 | qDebug("parse ftplist "+outputFile); | 121 | odebug << "parse ftplist "+outputFile << oendl; |
117 | QString ftpList, s_location; | 122 | QString ftpList, s_location; |
118 | QFile f( outputFile ); | 123 | QFile f( outputFile ); |
119 | 124 | ||
120 | if( f.open( IO_ReadWrite )) { | 125 | if( f.open( IO_ReadWrite )) { |
121 | QTextStream t( &f); | 126 | QTextStream t( &f); |
122 | QString countryName; | 127 | QString countryName; |
123 | bool b_gotchTest=false; | 128 | bool b_gotchTest=false; |
124 | 129 | ||
125 | while ( !t.eof() ) { | 130 | while ( !t.eof() ) { |
126 | QString s = t.readLine(); | 131 | QString s = t.readLine(); |
127 | int start; | 132 | int start; |
128 | int end; | 133 | int end; |
@@ -143,63 +148,63 @@ bool optionsDialog::parseFtpList( QString outputFile) | |||
143 | if( ftpSite.find("\n", 0, TRUE) ) | 148 | if( ftpSite.find("\n", 0, TRUE) ) |
144 | ftpSite.remove( ftpSite.find("\n", 0, TRUE), 1); | 149 | ftpSite.remove( ftpSite.find("\n", 0, TRUE), 1); |
145 | 150 | ||
146 | if( ftpSite.find("\"", 0, TRUE) ) | 151 | if( ftpSite.find("\"", 0, TRUE) ) |
147 | ftpSite.remove( ftpSite.find("\"", 0, TRUE), 1); | 152 | ftpSite.remove( ftpSite.find("\"", 0, TRUE), 1); |
148 | if( ftpSite.find("a>", 0, TRUE) ) | 153 | if( ftpSite.find("a>", 0, TRUE) ) |
149 | ftpSite.remove( ftpSite.find("a>", 0, TRUE) -2, 4); | 154 | ftpSite.remove( ftpSite.find("a>", 0, TRUE) -2, 4); |
150 | 155 | ||
151 | 156 | ||
152 | s = t.readLine(); | 157 | s = t.readLine(); |
153 | s = t.readLine(); | 158 | s = t.readLine(); |
154 | if(( start=s.find("<BR>(", 0, TRUE) ) != -1) { | 159 | if(( start=s.find("<BR>(", 0, TRUE) ) != -1) { |
155 | // qDebug("%s",s.latin1()); | 160 | // odebug << "" << s << "" << oendl; |
156 | end = s.find( ")", 0, TRUE)+1; | 161 | end = s.find( ")", 0, TRUE)+1; |
157 | s_location= s.mid( start+4, (end - start) ); | 162 | s_location= s.mid( start+4, (end - start) ); |
158 | 163 | ||
159 | // qDebug("%s", s_location.latin1()); | 164 | // odebug << "" << s_location << "" << oendl; |
160 | // ftpList += ftpSite + "\n"; | 165 | // ftpList += ftpSite + "\n"; |
161 | // ftp_QListBox_1->sort( TRUE ); | 166 | // ftp_QListBox_1->sort( TRUE ); |
162 | ftpList += s_location+ " "+ftpSite+"\n"; | 167 | ftpList += s_location+ " "+ftpSite+"\n"; |
163 | 168 | ||
164 | ftp_QListBox_1->sort( TRUE ); | 169 | ftp_QListBox_1->sort( TRUE ); |
165 | QString winbug=" "; | 170 | QString winbug=" "; |
166 | ftp_QListBox_1->insertItem ( s_location.latin1() +winbug+ftpSite); | 171 | ftp_QListBox_1->insertItem ( s_location.latin1() +winbug+ftpSite); |
167 | // ftp_QListBox_1->insertItem ( ftpSite+" "+s_location.latin1()); | 172 | // ftp_QListBox_1->insertItem ( ftpSite+" "+s_location.latin1()); |
168 | } | 173 | } |
169 | 174 | ||
170 | // ftp_QListBox_1->insertItem ( ftpSite); | 175 | // ftp_QListBox_1->insertItem ( ftpSite); |
171 | } | 176 | } |
172 | } // end find ftp:// | 177 | } // end find ftp:// |
173 | 178 | ||
174 | } // end while loop | 179 | } // end while loop |
175 | QFile f2( ListFile); | 180 | QFile f2( ListFile); |
176 | if(!f2.open( IO_ReadWrite | IO_Truncate)) | 181 | if(!f2.open( IO_ReadWrite | IO_Truncate)) |
177 | QMessageBox::message( (tr("Note")), (tr("File not opened sucessfully.\n"+ListFile )) ); | 182 | QMessageBox::message( (tr("Note")), (tr("File not opened sucessfully.\n"+ListFile )) ); |
178 | f2.writeBlock( ftpList, ftpList.length() ); | 183 | f2.writeBlock( ftpList, ftpList.length() ); |
179 | f.close(); | 184 | f.close(); |
180 | f2.close(); | 185 | f2.close(); |
181 | if( f.exists() ) | 186 | if( f.exists() ) |
182 | f.remove(); | 187 | f.remove(); |
183 | } else { | 188 | } else { |
184 | QMessageBox::message( (tr("ftpSiteDlg")), (tr("List File not opened sucessfully." )) ); | 189 | QMessageBox::message( (tr("ftpSiteDlg")), (tr("List File not opened sucessfully." )) ); |
185 | return false; | 190 | return false; |
186 | } | 191 | } |
187 | setActiveWindow(); | 192 | setActiveWindow(); |
188 | return true; | 193 | return true; |
189 | } | 194 | } |
190 | 195 | ||
191 | void optionsDialog::openSiteList() { | 196 | void optionsDialog::openSiteList() { |
192 | 197 | ||
193 | qDebug(" just opens the ftp site list"); | 198 | odebug << " just opens the ftp site list" << oendl; |
194 | // ListFile = ( QDir::homeDirPath ()) +"/.gutenbrowser/ftpList"; | 199 | // ListFile = ( QDir::homeDirPath ()) +"/.gutenbrowser/ftpList"; |
195 | QFile f( ListFile); | 200 | QFile f( ListFile); |
196 | if(!f.open( IO_ReadWrite )) { | 201 | if(!f.open( IO_ReadWrite )) { |
197 | QMessageBox::message( (tr("Note")), (tr("File not opened sucessfully." )) ); | 202 | QMessageBox::message( (tr("Note")), (tr("File not opened sucessfully." )) ); |
198 | } else { | 203 | } else { |
199 | QTextStream t( &f); | 204 | QTextStream t( &f); |
200 | while ( !t.atEnd() ) { | 205 | while ( !t.atEnd() ) { |
201 | QString ftpSite = t.readLine(); | 206 | QString ftpSite = t.readLine(); |
202 | ftp_QListBox_1->sort( TRUE ); | 207 | ftp_QListBox_1->sort( TRUE ); |
203 | ftp_QListBox_1->insertItem ( ftpSite); | 208 | ftp_QListBox_1->insertItem ( ftpSite); |
204 | 209 | ||
205 | } // end while loop | 210 | } // end while loop |
@@ -221,25 +226,25 @@ void optionsDialog::getSelection( QListBoxItem *item) | |||
221 | // printf( selctionStr+"\n" ); | 226 | // printf( selctionStr+"\n" ); |
222 | select_site( selctionStr ); | 227 | select_site( selctionStr ); |
223 | } | 228 | } |
224 | 229 | ||
225 | void optionsDialog::select_site( const char *index ) | 230 | void optionsDialog::select_site( const char *index ) |
226 | { | 231 | { |
227 | // ftp://ftp.datacanyon.com/pub/gutenberg/ | 232 | // ftp://ftp.datacanyon.com/pub/gutenberg/ |
228 | 233 | ||
229 | s_site = index; | 234 | s_site = index; |
230 | QString s_site2; | 235 | QString s_site2; |
231 | // if(s_site.find("(",0,TRUE)) | 236 | // if(s_site.find("(",0,TRUE)) |
232 | s_site2=s_site.right( s_site.length()-(s_site.find(" ",0,TRUE)+4) ); | 237 | s_site2=s_site.right( s_site.length()-(s_site.find(" ",0,TRUE)+4) ); |
233 | qDebug("Selected ftp site is "+ s_site2); | 238 | odebug << "Selected ftp site is "+ s_site2 << oendl; |
234 | int i_ftp = s_site2.find("/", 0, FALSE); | 239 | int i_ftp = s_site2.find("/", 0, FALSE); |
235 | ftp_host = s_site2.left(i_ftp ); | 240 | ftp_host = s_site2.left(i_ftp ); |
236 | ftp_base_dir = s_site2.right( s_site2.length() - i_ftp); | 241 | ftp_base_dir = s_site2.right( s_site2.length() - i_ftp); |
237 | 242 | ||
238 | // config->read(); | 243 | // config->read(); |
239 | Config config("Gutenbrowser"); | 244 | Config config("Gutenbrowser"); |
240 | config.setGroup( "FTPsite" ); | 245 | config.setGroup( "FTPsite" ); |
241 | config.writeEntry("SiteName",ftp_host); | 246 | config.writeEntry("SiteName",ftp_host); |
242 | config.writeEntry("base",ftp_base_dir); | 247 | config.writeEntry("base",ftp_base_dir); |
243 | // config->write(); | 248 | // config->write(); |
244 | TextLabel3->setText( "Current ftp server:\n"+ftp_host /*+ ftp_base_dir*/ ); | 249 | TextLabel3->setText( "Current ftp server:\n"+ftp_host /*+ ftp_base_dir*/ ); |
245 | // optionsDialog::accept(); | 250 | // optionsDialog::accept(); |