-rw-r--r-- | noncore/apps/opie-gutenbrowser/ftpsitedlg.cpp | 80 |
1 files changed, 39 insertions, 41 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 | |||
@@ -1,252 +1,250 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
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 | ||
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> |
28 | 26 | ||
29 | /* STD */ | 27 | /* STD */ |
30 | #include <stdlib.h> | 28 | #include <stdlib.h> |
31 | #include <unistd.h> | 29 | #include <unistd.h> |
32 | #include <stdio.h> | 30 | #include <stdio.h> |
33 | 31 | ||
34 | // :)~ | 32 | // :)~ |
35 | void optionsDialog::ftpSiteDlg( ) | 33 | void optionsDialog::ftpSiteDlg( ) |
36 | { | 34 | { |
37 | //printf( "ftpSiteDlg: ListFile is "+ ListFile +"\n" ); | 35 | //printf( "ftpSiteDlg: ListFile is "+ ListFile +"\n" ); |
38 | // initDialog(); | 36 | // initDialog(); |
39 | local_library = (QDir::homeDirPath ()) +"/Applications/gutenbrowser/"; | 37 | local_library = (QDir::homeDirPath ()) +"/Applications/gutenbrowser/"; |
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)) { |
53 | case QMessageBox::Yes: // yes | 51 | case QMessageBox::Yes: // yes |
54 | getSite(); | 52 | getSite(); |
55 | break; | 53 | break; |
56 | case QMessageBox::No: // No | 54 | case QMessageBox::No: // No |
57 | // exit | 55 | // exit |
58 | break; | 56 | break; |
59 | } | 57 | } |
60 | 58 | ||
61 | } | 59 | } |
62 | } | 60 | } |
63 | 61 | ||
64 | 62 | ||
65 | /* | 63 | /* |
66 | // get ftp list from web- parse it. */ | 64 | // get ftp list from web- parse it. */ |
67 | void optionsDialog::getSite() | 65 | 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; |
99 | char line[130]; | 98 | char line[130]; |
100 | outDlg->OutputEdit->append( tr("Running wget") ); | 99 | outDlg->OutputEdit->append( tr("Running wget") ); |
101 | sleep(1); | 100 | sleep(1); |
102 | fp = popen( (const char *) cmd, "r"); | 101 | fp = popen( (const char *) cmd, "r"); |
103 | while ( fgets( line, sizeof line, fp)) { | 102 | while ( fgets( line, sizeof line, fp)) { |
104 | outDlg->OutputEdit->append(line); | 103 | outDlg->OutputEdit->append(line); |
105 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); | 104 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); |
106 | } | 105 | } |
107 | pclose(fp); | 106 | pclose(fp); |
108 | outDlg->close(); | 107 | outDlg->close(); |
109 | if(outDlg) | 108 | if(outDlg) |
110 | delete outDlg; | 109 | delete outDlg; |
111 | 110 | ||
112 | // outputFile=ListFile; | 111 | // outputFile=ListFile; |
113 | ftp_QListBox_1->clear(); | 112 | ftp_QListBox_1->clear(); |
114 | parseFtpList( outputFile); // got the html list, now parse it so we can use it | 113 | parseFtpList( outputFile); // got the html list, now parse it so we can use it |
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 | } |
143 | ftpSite = s.mid( start, (end - start) ); | 144 | // qDebug("end %d", end); |
145 | start =start + 6; | ||
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) ) | 151 | |
149 | ftpSite.remove( ftpSite.find("\n", 0, TRUE), 1); | 152 | for (int j = 0 ; j<3;j++) { |
150 | 153 | s = t.readLine(); | |
151 | if( ftpSite.find("\"", 0, TRUE) ) | 154 | QString finder="</td><td rowspan=\"3\">"; |
152 | ftpSite.remove( ftpSite.find("\"", 0, TRUE), 1); | 155 | if(( start = s.find( finder, 0, TRUE) ) != -1) { |
153 | if( ftpSite.find("a>", 0, TRUE) ) | 156 | // qDebug( "%d" + s, start ); |
154 | ftpSite.remove( ftpSite.find("a>", 0, TRUE) -2, 4); | 157 | end = s.find( finder, start + 2, TRUE) ; |
155 | 158 | // qDebug("end %d",end); | |
156 | 159 | s_location = s.mid( start + finder.length() , (end - start)-finder.length() ); | |
157 | s = t.readLine(); | 160 | // |
158 | s = t.readLine(); | 161 | // qDebug("Location "+s_location ); |
159 | if(( start=s.find("<BR>(", 0, TRUE) ) != -1) { | ||
160 | // odebug << "" << s << "" << oendl; | ||
161 | end = s.find( ")", 0, TRUE)+1; | ||
162 | s_location= s.mid( start+4, (end - start) ); | ||
163 | |||
164 | // odebug << "" << s_location << "" << oendl; | ||
165 | // ftpList += ftpSite + "\n"; | ||
166 | // ftp_QListBox_1->sort( TRUE ); | ||
167 | ftpList += s_location+ " "+ftpSite+"\n"; | ||
168 | |||
169 | ftp_QListBox_1->sort( TRUE ); | ||
170 | QString winbug=" "; | ||
171 | ftp_QListBox_1->insertItem ( s_location.latin1() +winbug+ftpSite); | ||
172 | // ftp_QListBox_1->insertItem ( ftpSite+" "+s_location.latin1()); | ||
173 | } | ||
174 | 162 | ||
163 | ftpList += s_location+ " "+ftpSite+"\n"; | ||
164 | ftp_QListBox_1->sort( TRUE ); | ||
165 | QString winbug=" "; | ||
166 | ftp_QListBox_1->insertItem ( s_location.latin1() + winbug + ftpSite); | ||
167 | j=3; | ||
168 | // ftp_QListBox_1->insertItem ( ftpSite+" "+s_location.latin1()); | ||
169 | } | ||
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); |
181 | if(!f2.open( IO_ReadWrite | IO_Truncate)) | 177 | if(!f2.open( IO_ReadWrite | IO_Truncate)) |
182 | QMessageBox::message( (tr("Note")), (tr("File not opened sucessfully.\n"+ListFile )) ); | 178 | QMessageBox::message( (tr("Note")), (tr("File not opened sucessfully.\n"+ListFile )) ); |
183 | f2.writeBlock( ftpList, ftpList.length() ); | 179 | f2.writeBlock( ftpList, ftpList.length() ); |
184 | f.close(); | 180 | f.close(); |
185 | f2.close(); | 181 | f2.close(); |
186 | if( f.exists() ) | 182 | if( f.exists() ) |
187 | f.remove(); | 183 | f.remove(); |
188 | } else { | 184 | } else { |
189 | QMessageBox::message( (tr("ftpSiteDlg")), (tr("List File not opened sucessfully." )) ); | 185 | QMessageBox::message( (tr("ftpSiteDlg")), (tr("List File not opened sucessfully." )) ); |
190 | return false; | 186 | return false; |
191 | } | 187 | } |
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); |
205 | while ( !t.atEnd() ) { | 201 | while ( !t.atEnd() ) { |
206 | QString ftpSite = t.readLine(); | 202 | QString ftpSite = t.readLine(); |
207 | ftp_QListBox_1->sort( TRUE ); | 203 | ftp_QListBox_1->sort( TRUE ); |
208 | ftp_QListBox_1->insertItem ( ftpSite); | 204 | ftp_QListBox_1->insertItem ( ftpSite); |
209 | 205 | ||
210 | } // end while loop | 206 | } // end while loop |
211 | f.close(); | 207 | f.close(); |
212 | } | 208 | } |
213 | 209 | ||
214 | QListBoxItem *itemSel=0; | 210 | QListBoxItem *itemSel=0; |
215 | if( (itemSel=ftp_QListBox_1->findItem( ftp_host)) ) | 211 | if( (itemSel=ftp_QListBox_1->findItem( ftp_host)) ) |
216 | ftp_QListBox_1->setSelected( itemSel, true); | 212 | ftp_QListBox_1->setSelected( itemSel, true); |
217 | } | 213 | } |
218 | 214 | ||
219 | /* | 215 | /* |
220 | List box clicked */ | 216 | List box clicked */ |
221 | void optionsDialog::getSelection( QListBoxItem *item) | 217 | void optionsDialog::getSelection( QListBoxItem *item) |
222 | { | 218 | { |
223 | QString selctionStr; | 219 | QString selctionStr; |
224 | selctionStr = item->text(); | 220 | selctionStr = item->text(); |
225 | // selctionStr = ftp_QListBox_1->currentText(); | 221 | // selctionStr = ftp_QListBox_1->currentText(); |
226 | // printf( selctionStr+"\n" ); | 222 | // printf( selctionStr+"\n" ); |
227 | select_site( selctionStr ); | 223 | select_site( selctionStr ); |
228 | } | 224 | } |
229 | 225 | ||
230 | void optionsDialog::select_site( const char *index ) | 226 | void optionsDialog::select_site( const char *index ) |
231 | { | 227 | { |
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"); |
245 | config.setGroup( "FTPsite" ); | 243 | config.setGroup( "FTPsite" ); |
246 | config.writeEntry("SiteName",ftp_host); | 244 | config.writeEntry("SiteName",ftp_host); |
247 | config.writeEntry("base",ftp_base_dir); | 245 | config.writeEntry("base",ftp_base_dir); |
248 | // config->write(); | 246 | // config->write(); |
249 | TextLabel3->setText( "Current ftp server:\n"+ftp_host /*+ ftp_base_dir*/ ); | 247 | TextLabel3->setText( "Current ftp server:\n" + ftp_host /*+ ftp_base_dir*/ ); |
250 | // optionsDialog::accept(); | 248 | // optionsDialog::accept(); |
251 | } | 249 | } |
252 | 250 | ||