author | llornkcor <llornkcor> | 2004-11-02 02:41:04 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2004-11-02 02:41:04 (UTC) |
commit | e83e5bd3f26270d61a83b8b91e07b35d2657d060 (patch) (unidiff) | |
tree | eec1223a69d28cd684116976dc7e970bbf846054 /noncore | |
parent | 51b7bdf260bc2b5b066c6594a6d0c507add682fd (diff) | |
download | opie-e83e5bd3f26270d61a83b8b91e07b35d2657d060.zip opie-e83e5bd3f26270d61a83b8b91e07b35d2657d060.tar.gz opie-e83e5bd3f26270d61a83b8b91e07b35d2657d060.tar.bz2 |
new mirror site web page requiring new parsing
-rw-r--r-- | noncore/apps/opie-gutenbrowser/ftpsitedlg.cpp | 62 |
1 files changed, 30 insertions, 32 deletions
diff --git a/noncore/apps/opie-gutenbrowser/ftpsitedlg.cpp b/noncore/apps/opie-gutenbrowser/ftpsitedlg.cpp index de9c72b..44ade8d 100644 --- a/noncore/apps/opie-gutenbrowser/ftpsitedlg.cpp +++ b/noncore/apps/opie-gutenbrowser/ftpsitedlg.cpp | |||
@@ -14,14 +14,12 @@ | |||
14 | 14 | ||
15 | #include "optionsDialog.h" | 15 | #include "optionsDialog.h" |
16 | #include "gutenbrowser.h" | 16 | #include "gutenbrowser.h" |
17 | //#include "NetworkDialog.h" | 17 | //#include "NetworkDialog.h" |
18 | #include "output.h" | 18 | #include "output.h" |
19 | 19 | ||
20 | /* OPIE */ | ||
21 | #include <opie2/odebug.h> | ||
22 | #include <qpe/config.h> | 20 | #include <qpe/config.h> |
23 | 21 | ||
24 | /* QT */ | 22 | /* QT */ |
25 | #include <qprogressbar.h> | 23 | #include <qprogressbar.h> |
26 | #include <qurloperator.h> | 24 | #include <qurloperator.h> |
27 | #include <qlistbox.h> | 25 | #include <qlistbox.h> |
@@ -40,13 +38,13 @@ void optionsDialog::ftpSiteDlg( ) | |||
40 | // ListFile = local_library + "ftpList"; | 38 | // ListFile = local_library + "ftpList"; |
41 | ListFile = QPEApplication::qpeDir() + "etc/gutenbrowser"; | 39 | ListFile = QPEApplication::qpeDir() + "etc/gutenbrowser"; |
42 | QDir dir(ListFile); | 40 | QDir dir(ListFile); |
43 | if( !dir.exists()) | 41 | if( !dir.exists()) |
44 | dir.mkdir(ListFile,true); | 42 | dir.mkdir(ListFile,true); |
45 | ListFile+="/ftpList"; | 43 | ListFile+="/ftpList"; |
46 | odebug << "opening "+ListFile << oendl; | 44 | qDebug( "opening "+ListFile ); |
47 | if ( QFile(ListFile).exists() ) { | 45 | if ( QFile(ListFile).exists() ) { |
48 | openSiteList(); | 46 | openSiteList(); |
49 | } else { | 47 | } else { |
50 | switch( QMessageBox::warning( this, "Gutenbrowser", | 48 | switch( QMessageBox::warning( this, "Gutenbrowser", |
51 | "Do you want to download \nan ftp site list?", | 49 | "Do you want to download \nan ftp site list?", |
52 | QMessageBox::Yes, QMessageBox::No)) { | 50 | QMessageBox::Yes, QMessageBox::No)) { |
@@ -68,31 +66,32 @@ void optionsDialog::getSite() | |||
68 | { | 66 | { |
69 | QString file_name; | 67 | QString file_name; |
70 | QString ftp_listFileURL; | 68 | QString ftp_listFileURL; |
71 | QString outputFile; | 69 | QString outputFile; |
72 | // outputFile = local_library+ "list.html"; | 70 | // outputFile = local_library+ "list.html"; |
73 | outputFile = ListFile + "list.html"; | 71 | outputFile = ListFile + "list.html"; |
74 | QString networkUrl= "http://www.gutenberg.org/www/mirror.sites.html"; | 72 | QString networkUrl="http://www.gutenberg.net/catalog/world/selectpermanentmirror?fk_books=12962"; |
73 | // QString networkUrl= "http://www.gutenberg.org/www/mirror.sites.html"; | ||
75 | //http://www.gutenberg.org/index.html"; | 74 | //http://www.gutenberg.org/index.html"; |
76 | // QString networkUrl= "http://llornkcor.com/index.shtml"; | 75 | // QString networkUrl= "http://llornkcor.com/index.shtml"; |
77 | // // "http://www.gutenberg.org/index.html" | 76 | // // "http://www.gutenberg.org/index.html" |
78 | // | 77 | // |
79 | //Qhttp stops working at times.... :( | 78 | //Qhttp stops working at times.... :( |
80 | // NetworkDialog *NetworkDlg; | 79 | // NetworkDialog *NetworkDlg; |
81 | // NetworkDlg = new NetworkDialog( this,"Network Protocol Dialog",TRUE,0,networkUrl,outputFile); | 80 | // NetworkDlg = new NetworkDialog( this,"Network Protocol Dialog",TRUE,0,networkUrl,outputFile); |
82 | // if( NetworkDlg->exec() != 0 ) | 81 | // if( NetworkDlg->exec() != 0 ) |
83 | // { // use new, improved, *INSTANT* network-dialog-file-getterer | 82 | // { // use new, improved, *INSTANT* network-dialog-file-getterer |
84 | // odebug << "gitcha!" << oendl; | 83 | // qDebug( "gitcha!" ); |
85 | // } | 84 | // } |
86 | // delete NetworkDlg; | 85 | // delete NetworkDlg; |
87 | //#ifdef Q_WS_QWS | 86 | //#ifdef Q_WS_QWS |
88 | 87 | ||
89 | // TODO qprocess here | 88 | // TODO qprocess here |
90 | 89 | ||
91 | QString cmd="wget -T 15 -O " +outputFile + " " + networkUrl + " 2>&1" ; | 90 | QString cmd="wget -T 15 -O " +outputFile + " " + networkUrl;// + " 2>&1" ; |
92 | odebug << "Issuing the command "+cmd << oendl; | 91 | qDebug( "Issuing the command "+cmd ); |
93 | Output *outDlg; | 92 | Output *outDlg; |
94 | outDlg = new Output( 0, tr("Downloading ftp sites...."),TRUE); | 93 | outDlg = new Output( 0, tr("Downloading ftp sites...."),TRUE); |
95 | outDlg->showMaximized(); | 94 | outDlg->showMaximized(); |
96 | outDlg->show(); | 95 | outDlg->show(); |
97 | qApp->processEvents(); | 96 | qApp->processEvents(); |
98 | FILE *fp; | 97 | FILE *fp; |
@@ -115,66 +114,63 @@ void optionsDialog::getSite() | |||
115 | } | 114 | } |
116 | 115 | ||
117 | bool optionsDialog::parseFtpList( QString outputFile) | 116 | bool optionsDialog::parseFtpList( QString outputFile) |
118 | { | 117 | { |
119 | // parse ftplist html and extract just the machine names/directories | 118 | // parse ftplist html and extract just the machine names/directories |
120 | // TODO: add locations!! | 119 | // TODO: add locations!! |
121 | odebug << "parse ftplist "+outputFile << oendl; | 120 | qDebug( "parse ftplist "+outputFile ); |
122 | QString ftpList, s_location; | 121 | QString ftpList, s_location; |
123 | QFile f( outputFile ); | 122 | QFile f( outputFile ); |
124 | 123 | ||
125 | if( f.open( IO_ReadWrite )) { | 124 | if( f.open( IO_ReadWrite )) { |
126 | QTextStream t( &f); | 125 | QTextStream t( &f); |
127 | QString countryName; | 126 | QString countryName; |
128 | bool b_gotchTest=false; | 127 | bool b_gotchTest=false; |
129 | 128 | ||
130 | while ( !t.eof() ) { | 129 | while ( !t.eof() ) { |
131 | QString s = t.readLine(); | 130 | QString s = t.readLine(); |
132 | int start; | 131 | int start; |
133 | int end; | 132 | int end; |
134 | if( s.find( "FTP mirror sites for Project Gutenberg:", 0, TRUE) !=-1) { //lower end of this file | 133 | if( s.find( "Select a Default Download Site - Project Gutenberg", 0, TRUE) !=-1) { //lower end of this file |
135 | b_gotchTest = true; | 134 | b_gotchTest = true; |
136 | } | 135 | } |
137 | if( b_gotchTest) { | 136 | if( b_gotchTest) { |
138 | if(( start = s.find( "ftp://", 0, TRUE))!=-1 ) { | 137 | if(( start = s.find( "ftp://", 0, TRUE))!=-1 ) { |
139 | end = s.find( "/\"", 0, TRUE);// ==-1)) { | 138 | // qDebug(s); |
139 | // qDebug("%d", start); | ||
140 | end = s.find( "</td></tr>", 0, TRUE);// ==-1)) { | ||
140 | if( end == -1) { | 141 | if( end == -1) { |
141 | end = s.find( "\">"); | 142 | end = s.find( "\">"); |
142 | } | 143 | } |
144 | // qDebug("end %d", end); | ||
145 | start =start + 6; | ||
143 | ftpSite = s.mid( start, (end - start) ); | 146 | ftpSite = s.mid( start, (end - start) ); |
144 | if(ftpSite.right(1) != "/") { | 147 | if(ftpSite.right(1) != "/") { |
145 | // ftpSite += "/"; | 148 | // ftpSite += "/"; |
146 | } | 149 | } |
147 | ftpSite=ftpSite.right( ftpSite.length()-6); | 150 | // qDebug("ftpsite " + ftpSite); |
148 | if( ftpSite.find("\n", 0, TRUE) ) | ||
149 | ftpSite.remove( ftpSite.find("\n", 0, TRUE), 1); | ||
150 | 151 | ||
151 | if( ftpSite.find("\"", 0, TRUE) ) | 152 | for (int j = 0 ; j<3;j++) { |
152 | ftpSite.remove( ftpSite.find("\"", 0, TRUE), 1); | ||
153 | if( ftpSite.find("a>", 0, TRUE) ) | ||
154 | ftpSite.remove( ftpSite.find("a>", 0, TRUE) -2, 4); | ||
155 | |||
156 | |||
157 | s = t.readLine(); | ||
158 | s = t.readLine(); | 153 | s = t.readLine(); |
159 | if(( start=s.find("<BR>(", 0, TRUE) ) != -1) { | 154 | QString finder="</td><td rowspan=\"3\">"; |
160 | // odebug << "" << s << "" << oendl; | 155 | if(( start = s.find( finder, 0, TRUE) ) != -1) { |
161 | end = s.find( ")", 0, TRUE)+1; | 156 | // qDebug( "%d" + s, start ); |
162 | s_location= s.mid( start+4, (end - start) ); | 157 | end = s.find( finder, start + 2, TRUE) ; |
163 | 158 | // qDebug("end %d",end); | |
164 | // odebug << "" << s_location << "" << oendl; | 159 | s_location = s.mid( start + finder.length() , (end - start)-finder.length() ); |
165 | // ftpList += ftpSite + "\n"; | 160 | // |
166 | // ftp_QListBox_1->sort( TRUE ); | 161 | // qDebug("Location "+s_location ); |
167 | ftpList += s_location+ " "+ftpSite+"\n"; | ||
168 | 162 | ||
163 | ftpList += s_location+ " "+ftpSite+"\n"; | ||
169 | ftp_QListBox_1->sort( TRUE ); | 164 | ftp_QListBox_1->sort( TRUE ); |
170 | QString winbug=" "; | 165 | QString winbug=" "; |
171 | ftp_QListBox_1->insertItem ( s_location.latin1() +winbug+ftpSite); | 166 | ftp_QListBox_1->insertItem ( s_location.latin1() +winbug+ftpSite); |
167 | j=3; | ||
172 | // ftp_QListBox_1->insertItem ( ftpSite+" "+s_location.latin1()); | 168 | // ftp_QListBox_1->insertItem ( ftpSite+" "+s_location.latin1()); |
173 | } | 169 | } |
174 | 170 | } | |
175 | // ftp_QListBox_1->insertItem ( ftpSite); | 171 | // ftp_QListBox_1->insertItem ( ftpSite); |
176 | } | 172 | } |
177 | } // end find ftp:// | 173 | } // end find ftp:// |
178 | 174 | ||
179 | } // end while loop | 175 | } // end while loop |
180 | QFile f2( ListFile); | 176 | QFile f2( ListFile); |
@@ -192,13 +188,13 @@ bool optionsDialog::parseFtpList( QString outputFile) | |||
192 | setActiveWindow(); | 188 | setActiveWindow(); |
193 | return true; | 189 | return true; |
194 | } | 190 | } |
195 | 191 | ||
196 | void optionsDialog::openSiteList() { | 192 | void optionsDialog::openSiteList() { |
197 | 193 | ||
198 | odebug << " just opens the ftp site list" << oendl; | 194 | qDebug( " just opens the ftp site list" ); |
199 | // ListFile = ( QDir::homeDirPath ()) +"/.gutenbrowser/ftpList"; | 195 | // ListFile = ( QDir::homeDirPath ()) +"/.gutenbrowser/ftpList"; |
200 | QFile f( ListFile); | 196 | QFile f( ListFile); |
201 | if(!f.open( IO_ReadWrite )) { | 197 | if(!f.open( IO_ReadWrite )) { |
202 | QMessageBox::message( (tr("Note")), (tr("File not opened sucessfully." )) ); | 198 | QMessageBox::message( (tr("Note")), (tr("File not opened sucessfully." )) ); |
203 | } else { | 199 | } else { |
204 | QTextStream t( &f); | 200 | QTextStream t( &f); |
@@ -232,13 +228,15 @@ void optionsDialog::select_site( const char *index ) | |||
232 | // ftp://ftp.datacanyon.com/pub/gutenberg/ | 228 | // ftp://ftp.datacanyon.com/pub/gutenberg/ |
233 | 229 | ||
234 | s_site = index; | 230 | s_site = index; |
235 | QString s_site2; | 231 | QString s_site2; |
236 | // if(s_site.find("(",0,TRUE)) | 232 | // if(s_site.find("(",0,TRUE)) |
237 | s_site2=s_site.right( s_site.length()-(s_site.find(" ",0,TRUE)+4) ); | 233 | s_site2=s_site.right( s_site.length()-(s_site.find(" ",0,TRUE)+4) ); |
238 | odebug << "Selected ftp site is "+ s_site2 << oendl; | 234 | |
235 | qDebug( "Selected ftp site is "+ s_site2 ); | ||
236 | |||
239 | int i_ftp = s_site2.find("/", 0, FALSE); | 237 | int i_ftp = s_site2.find("/", 0, FALSE); |
240 | ftp_host = s_site2.left(i_ftp ); | 238 | ftp_host = s_site2.left(i_ftp ); |
241 | ftp_base_dir = s_site2.right( s_site2.length() - i_ftp); | 239 | ftp_base_dir = s_site2.right( s_site2.length() - i_ftp); |
242 | 240 | ||
243 | // config->read(); | 241 | // config->read(); |
244 | Config config("Gutenbrowser"); | 242 | Config config("Gutenbrowser"); |