summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-gutenbrowser/LibraryDialog.cpp25
1 files changed, 13 insertions, 12 deletions
diff --git a/noncore/apps/opie-gutenbrowser/LibraryDialog.cpp b/noncore/apps/opie-gutenbrowser/LibraryDialog.cpp
index 9858188..6c246e97 100644
--- a/noncore/apps/opie-gutenbrowser/LibraryDialog.cpp
+++ b/noncore/apps/opie-gutenbrowser/LibraryDialog.cpp
@@ -5,1048 +5,1049 @@
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//ftp://ibiblio.org/pub/docs/books/gutenberg/GUTINDEX.ALL 14//ftp://ibiblio.org/pub/docs/books/gutenberg/GUTINDEX.ALL
15 15
16#include "LibraryDialog.h" 16#include "LibraryDialog.h"
17#include "output.h" 17#include "output.h"
18 18
19/* OPIE */ 19/* OPIE */
20#include <qpe/applnk.h> 20#include <qpe/applnk.h>
21#include <qpe/qpeapplication.h> 21#include <qpe/qpeapplication.h>
22#include <qpe/qpedialog.h> 22#include <qpe/qpedialog.h>
23//#include <opie2///odebug.h> 23//#include <opie2///odebug.h>
24 24
25/* QT */ 25/* QT */
26#include <qpushbutton.h> 26#include <qpushbutton.h>
27#include <qmultilineedit.h> 27#include <qmultilineedit.h>
28//#include <qlayout.h> 28//#include <qlayout.h>
29 29
30/* STD */ 30/* STD */
31#include <unistd.h> 31#include <unistd.h>
32#include <stdio.h> 32#include <stdio.h>
33#include <stdlib.h> 33#include <stdlib.h>
34 34
35/* 35/*
36 * The dialog will by default be modeless, unless you set 'modal' to 36 * The dialog will by default be modeless, unless you set 'modal' to
37 * true to construct a modal dialog. */ 37 * true to construct a modal dialog. */
38LibraryDialog::LibraryDialog( QWidget* parent, const char* name , bool /*modal*/, WFlags fl ) 38LibraryDialog::LibraryDialog( QWidget* parent, const char* name , bool /*modal*/, WFlags fl )
39 : QDialog( parent, name, true/* modal*/, fl ) 39 : QDialog( parent, name, true/* modal*/, fl )
40{ 40{
41 if ( !name ) 41 if ( !name )
42 setName( "LibraryDialog" ); 42 setName( "LibraryDialog" );
43 indexLoaded=false; 43 indexLoaded=false;
44 initDialog(); 44 initDialog();
45 45
46 // this->setMaximumWidth(240); 46 // this->setMaximumWidth(240);
47 47
48 index = "GUTINDEX.ALL"; 48 index = "GUTINDEX.ALL";
49 local_library = (QDir::homeDirPath ()) +"/Applications/gutenbrowser/"; 49 local_library = (QDir::homeDirPath ()) +"/Applications/gutenbrowser/";
50 local_index = local_library + index; 50 local_index = local_library + index;
51 51
52 QString iniFile ; 52 QString iniFile ;
53 iniFile = local_library + "/gutenbrowserrc"; 53 iniFile = local_library + "/gutenbrowserrc";
54 new_index = local_library + "/PGWHOLE.TXT"; 54 new_index = local_library + "/PGWHOLE.TXT";
55 old_index = local_index; 55 old_index = local_index;
56 // iniFile = local_library+"gutenbrowserrc"; 56 // iniFile = local_library+"gutenbrowserrc";
57 // new_index = local_library + "PGWHOLE.TXT"; 57 // new_index = local_library + "PGWHOLE.TXT";
58 // old_index = local_library + "GUTINDEX.ALL"; 58 // old_index = local_library + "GUTINDEX.ALL";
59 59
60 Config config("Gutenbrowser"); 60 Config config("Gutenbrowser");
61 61
62 config.setGroup( "HttpServer" ); 62 config.setGroup( "HttpServer" );
63 proxy_http = config.readEntry("Preferred", "http://sailor.gutenbook.org"); 63 proxy_http = config.readEntry("Preferred", "http://sailor.gutenbook.org");
64 64
65 config.setGroup( "FTPsite" ); 65 config.setGroup( "FTPsite" );
66 ftp_host = config.readEntry("SiteName", "sailor.gutenberg.org"); 66 ftp_host = config.readEntry("SiteName", "sailor.gutenberg.org");
67 //odebug << "Library Dialog: ftp_host is "+ftp_host << oendl; 67 //odebug << "Library Dialog: ftp_host is "+ftp_host << oendl;
68 // ftp_host=ftp_host.right(ftp_host.length()-(ftp_host.find(") ",0,true)+1) ); 68 // ftp_host=ftp_host.right(ftp_host.length()-(ftp_host.find(") ",0,true)+1) );
69 // ftp_host=ftp_host.stripWhiteSpace(); 69 // ftp_host=ftp_host.stripWhiteSpace();
70 ftp_base_dir= config.readEntry("base", "/pub/gutenberg"); 70 ftp_base_dir= config.readEntry("base", "/pub/gutenberg");
71 71
72 i_binary = 0; 72 i_binary = 0;
73 73
74 config.setGroup("SortAuth"); 74 config.setGroup("SortAuth");
75 if( config.readEntry("authSort", "false") == "true") 75 if( config.readEntry("authSort", "false") == "true")
76 authBox->setChecked(true); 76 authBox->setChecked(true);
77 77
78 config.setGroup("General"); 78 config.setGroup("General");
79 downDir = config.readEntry( "DownloadDirectory",local_library); 79 downDir = config.readEntry( "DownloadDirectory",local_library);
80 //odebug << "downDir is "+downDir << oendl; 80 //odebug << "downDir is "+downDir << oendl;
81 newindexLib.setName( old_index); 81 newindexLib.setName( old_index);
82 indexLib.setName( old_index); 82 indexLib.setName( old_index);
83 83
84 new QPEDialogListener(this); 84 new QPEDialogListener(this);
85 QTimer::singleShot( 1000, this, SLOT( FindLibrary()) ); 85 QTimer::singleShot( 1000, this, SLOT( FindLibrary()) );
86 86
87} 87}
88 88
89LibraryDialog::~LibraryDialog() 89LibraryDialog::~LibraryDialog()
90{ 90{
91} 91}
92 92
93void LibraryDialog::clearItems() { 93void LibraryDialog::clearItems() {
94 ListView1->clear(); 94 ListView1->clear();
95 ListView2->clear(); 95 ListView2->clear();
96 ListView3->clear(); 96 ListView3->clear();
97 ListView4->clear(); 97 ListView4->clear();
98 ListView5->clear(); 98 ListView5->clear();
99} 99}
100 100
101/*This groks using PGWHOLE.TXT */ 101/*This groks using PGWHOLE.TXT */
102void LibraryDialog::Newlibrary() 102void LibraryDialog::Newlibrary()
103{ 103{
104 clearItems(); 104 clearItems();
105#ifndef Q_WS_QWS //sorry embedded gutenbrowser cant use zip files 105#ifndef Q_WS_QWS //sorry embedded gutenbrowser cant use zip files
106 ////odebug << "Opening new library index " << newindexLib << "" << oendl; 106 ////odebug << "Opening new library index " << newindexLib << "" << oendl;
107 if ( newindexLib.open( IO_ReadOnly) ) { 107 if ( newindexLib.open( IO_ReadOnly) ) {
108 setCaption( tr( "Library Index - using master pg index." ) );// file opened successfully 108 setCaption( tr( "Library Index - using master pg index." ) );// file opened successfully
109 QTextStream indexStream( &newindexLib ); 109 QTextStream indexStream( &newindexLib );
110 QString indexLine; 110 QString indexLine;
111 while ( !indexStream.atEnd() ) { // until end of file.. 111 while ( !indexStream.atEnd() ) { // until end of file..
112 indexLine = indexStream.readLine(); 112 indexLine = indexStream.readLine();
113 if ( ( indexLine.mid(4,4)).toInt() && !( indexLine.left(3)).toInt()) { 113 if ( ( indexLine.mid(4,4)).toInt() && !( indexLine.left(3)).toInt()) {
114 year = indexLine.mid(4,4); 114 year = indexLine.mid(4,4);
115 file = indexLine.mid( indexLine.find( "[", 0, true )+1, 12 ); 115 file = indexLine.mid( indexLine.find( "[", 0, true )+1, 12 );
116 number = indexLine.mid( indexLine.find( "]", 0, true ) +1, indexLine.find( " ", 0, true )+1 ); 116 number = indexLine.mid( indexLine.find( "]", 0, true ) +1, indexLine.find( " ", 0, true )+1 );
117 if( year.toInt() < 1984) 117 if( year.toInt() < 1984)
118 number = number.left( number.length() -1 ); 118 number = number.left( number.length() -1 );
119 title = indexLine.mid( indexLine.find(" ", 26, true), indexLine.length() ); 119 title = indexLine.mid( indexLine.find(" ", 26, true), indexLine.length() );
120 120
121 addItems(); 121 addItems();
122 122
123 }// end if 123 }// end if
124 }// end while 124 }// end while
125 newindexLib.close(); 125 newindexLib.close();
126 } 126 }
127#ifndef Q_WS_QWS 127#ifndef Q_WS_QWS
128 setCursor( arrowCursor); 128 setCursor( arrowCursor);
129#endif 129#endif
130#endif 130#endif
131} // end Newlibrary() 131} // end Newlibrary()
132 132
133 133
134void LibraryDialog::Library() { 134void LibraryDialog::Library() {
135 clearItems(); 135 clearItems();
136 136
137 // qDebug( "opening GUTINDEX.ALL file"); 137 // qDebug( "opening GUTINDEX.ALL file");
138 IDontKnowWhy = ""; 138 IDontKnowWhy = "";
139 system("date"); 139 system("date");
140 if ( indexLib.open( IO_ReadOnly) ) { 140 if ( indexLib.open( IO_ReadOnly) ) {
141// file opened successfully 141// file opened successfully
142 QTextStream indexStream( &indexLib ); 142 QTextStream indexStream( &indexLib );
143 QString indexLine; 143 QString indexLine;
144 qApp->processEvents(); 144 qApp->processEvents();
145 145
146 bool okToRead = false; 146 bool okToRead = false;
147 while ( !indexStream.eof() ) { 147 while ( !indexStream.eof() ) {
148 indexLine = indexStream.readLine(); 148 indexLine = indexStream.readLine();
149 if(indexLine == "<==Start GUTINDEX.ALL listings==>") 149 if(indexLine == "<==Start GUTINDEX.ALL listings==>")
150 okToRead = true; 150 okToRead = true;
151 if(indexLine == "<==End of GUTINDEX.ALL==>") { 151 if(indexLine == "<==End of GUTINDEX.ALL==>") {
152 okToRead = false; 152 okToRead = false;
153 indexLib.at(indexLib.size()); 153 indexLib.at(indexLib.size());
154 } 154 }
155 155
156 if(okToRead) { 156 if(okToRead) {
157 QStringList token = QStringList::split(' ', indexLine); 157 QStringList token = QStringList::split(' ', indexLine);
158 int textNumber; 158 int textNumber;
159 if(( textNumber = token.last().toInt() )) 159 if(( textNumber = token.last().toInt() ))
160 if(textNumber > 10001) { 160 if(textNumber > 10001) {
161// qWarning("Last "+token.last()); 161// qWarning("Last "+token.last());
162// newer files with numbers > 100000 have new dir structure and need to be parsed differently.. 162// newer files with numbers > 100000 have new dir structure and need to be parsed differently..
163 if(textNumber < 10626) 163 if(textNumber < 10626)
164 year = "2003"; 164 year = "2003";
165 else if(textNumber >= 10626 && textNumber < 14600) 165 else if(textNumber >= 10626 && textNumber < 14600)
166 year = "2004"; 166 year = "2004";
167 else if(textNumber >= 14600) 167 else if(textNumber >= 14600)
168 year = "2005"; 168 year = "2005";
169 169
170 file = token.last(); 170 file = token.last();
171 title = indexLine.mid(0,72); 171 title = indexLine.mid(0,72);
172 172
173 addItems(); //author and qlistview 173 addItems(); //author and qlistview
174 //qDebug("file number is " + number + " title is " + title ); 174 //qDebug("file number is " + number + " title is " + title );
175 175
176 } else { //end new etexts 176 } else { //end new etexts
177 177
178 if(token[1].toInt() && token[1].toInt() > 1969) { 178 if(token[1].toInt() && token[1].toInt() > 1969) {
179 year = token[1]; 179 year = token[1];
180 file = indexLine.mid(60,12); 180 file = indexLine.mid(60,12);
181 181
182 if(file.left(1).find("[",0,TRUE) != -1) { 182 if(file.left(1).find("[",0,TRUE) != -1) {
183 file.remove(1,1); 183 file.remove(1,1);
184 if( file.find("]",0,TRUE) != -1) 184 if( file.find("]",0,TRUE) != -1)
185 file = file.left( file.find("]",0,TRUE)); 185 file = file.left( file.find("]",0,TRUE));
186 186
187 if(file.find("?", 0, false) != -1 ) { 187 if(file.find("?", 0, false) != -1 ) {
188 QString tmpfile = file.replace(QRegExp("[?]"), "8"); 188 QString tmpfile = file.replace(QRegExp("[?]"), "8");
189 file = tmpfile; 189 file = tmpfile;
190 } 190 }
191 title = indexLine.mid( 9, 50); 191 title = indexLine.mid( 9, 50);
192 192
193 addItems(); 193 addItems();
194 } 194 }
195 } else { // then try new format texts 195 } else { // then try new format texts
196 file = token.last(); 196 file = token.last();
197 title = indexLine.mid(0,72); 197 title = indexLine.mid(0,72);
198 year = "1980"; 198 year = "1980";
199 199
200 addItems(); //author and qlistview 200 addItems(); //author and qlistview
201 } 201 }
202 } //end old etexts 202 } //end old etexts
203 203
204 } //end okToTRead 204 } //end okToTRead
205 } 205 }
206 indexLib.close(); 206 indexLib.close();
207 } else { 207 } else {
208 QString sMsg; 208 QString sMsg;
209 209
210 sMsg = ( tr("<p>Error opening library index file. Please download a new one.</P> ")); 210 sMsg = ( tr("<p>Error opening library index file. Please download a new one.</P> "));
211 QMessageBox::message( "Error",sMsg); 211 QMessageBox::message( "Error",sMsg);
212 } 212 }
213 system("date"); 213 system("date");
214 sortLists(0); 214 sortLists(0);
215 215
216} //end Library() 216} //end Library()
217 217
218 218
219/* 219/*
220 Groks the author out of the title */ 220 Groks the author out of the title */
221bool LibraryDialog::getAuthor() 221bool LibraryDialog::getAuthor()
222{ 222{
223 if( title.contains( ", by", true)) { 223 if( title.contains( ", by", true)) {
224 int auth; 224 int auth;
225 auth = title.find(", by", 0, true); 225 auth = title.find(", by", 0, true);
226 author = title.right(title.length() - (auth + 4) ); 226 author = title.right(title.length() - (auth + 4) );
227 if( int finder = author.find("[", 0, true)) { 227 if( int finder = author.find("[", 0, true)) {
228 author = author.left(finder); 228 author = author.left(finder);
229 } 229 }
230 } 230 }
231 else if ( title.contains( "by, ", true) ) { 231 else if ( title.contains( "by, ", true) ) {
232 int auth; 232 int auth;
233 auth = title.find("by, ", 0, true); 233 auth = title.find("by, ", 0, true);
234 author = title.right(title.length() - (auth + 4) ); 234 author = title.right(title.length() - (auth + 4) );
235 if( int finder = author.find("[", 0, true)) { 235 if( int finder = author.find("[", 0, true)) {
236 author = author.left( finder); 236 author = author.left( finder);
237 } 237 }
238 } 238 }
239 else if ( title.contains( " by", true) ) { 239 else if ( title.contains( " by", true) ) {
240 int auth; 240 int auth;
241 auth = title.find(" by", 0, true); 241 auth = title.find(" by", 0, true);
242 author = title.right(title.length() - (auth + 3) ); 242 author = title.right(title.length() - (auth + 3) );
243 if( int finder = author.find("[", 0, true)) { 243 if( int finder = author.find("[", 0, true)) {
244 author = author.left( finder); 244 author = author.left( finder);
245 } 245 }
246 } 246 }
247 else if ( title.contains( "by ", true) ) { 247 else if ( title.contains( "by ", true) ) {
248 int auth; 248 int auth;
249 auth = title.find("by ", 0, true); 249 auth = title.find("by ", 0, true);
250 author = title.right(title.length() - (auth + 3) ); 250 author = title.right(title.length() - (auth + 3) );
251 if( int finder = author.find("[", 0, true)) { 251 if( int finder = author.find("[", 0, true)) {
252 author = author.left( finder); 252 author = author.left( finder);
253 } 253 }
254 } 254 }
255 else if ( title.contains( ",", true) ) { 255 else if ( title.contains( ",", true) ) {
256 int auth; 256 int auth;
257 auth = title.find(",", 0, true); 257 auth = title.find(",", 0, true);
258 author = title.right( title.length() - (auth + 1) ); 258 author = title.right( title.length() - (auth + 1) );
259 if ( author.contains( ",", true) ) { 259 if ( author.contains( ",", true) ) {
260 int auth; 260 int auth;
261 auth = author.find(",", 0, true); 261 auth = author.find(",", 0, true);
262 author = author.right( author.length() - (auth + 1) ); 262 author = author.right( author.length() - (auth + 1) );
263 } 263 }
264 if( int finder = author.find("[", 0, true)) { 264 if( int finder = author.find("[", 0, true)) {
265 author = author.left( finder); 265 author = author.left( finder);
266 } 266 }
267 } 267 }
268 else if ( title.contains( "/", true) ) { 268 else if ( title.contains( "/", true) ) {
269 int auth; 269 int auth;
270 auth = title.find("/", 0, true); 270 auth = title.find("/", 0, true);
271 author = title.right(title.length() - (auth + 1) ); 271 author = title.right(title.length() - (auth + 1) );
272 if( int finder = author.find("[", 0, true)) { 272 if( int finder = author.find("[", 0, true)) {
273 author = author.left( finder); 273 author = author.left( finder);
274 } 274 }
275 } 275 }
276 else if ( title.contains( "of", true) ) { 276 else if ( title.contains( "of", true) ) {
277 int auth; 277 int auth;
278 auth = title.find("of", 0, true); 278 auth = title.find("of", 0, true);
279 author = title.right(title.length() - (auth + 2) ); 279 author = title.right(title.length() - (auth + 2) );
280 if( int finder = author.find("[", 0, true)) 280 if( int finder = author.find("[", 0, true))
281 { 281 {
282 author = author.left( finder); 282 author = author.left( finder);
283 } 283 }
284 } else { 284 } else {
285 author = ""; 285 author = "";
286 } 286 }
287 if ( author.contains("et. al")) { 287 if ( author.contains("et. al")) {
288 int auth; 288 int auth;
289 auth = author.find("et. al", 0, true); 289 auth = author.find("et. al", 0, true);
290 author = author.left( auth ); 290 author = author.left( auth );
291 } 291 }
292 if ( author.contains("#")) { 292 if ( author.contains("#")) {
293 int auth; 293 int auth;
294 auth = author.find("#", 0, true); 294 auth = author.find("#", 0, true);
295 author = author.left( auth); 295 author = author.left( auth);
296 } 296 }
297 if ( author.contains("(")) { 297 if ( author.contains("(")) {
298 int auth; 298 int auth;
299 auth = author.find("(", 0, true); 299 auth = author.find("(", 0, true);
300 author = author.left( auth); 300 author = author.left( auth);
301 } 301 }
302 if ( author.contains("et al")) { 302 if ( author.contains("et al")) {
303 int auth; 303 int auth;
304 auth = author.find("et al", 0, true); 304 auth = author.find("et al", 0, true);
305 author = author.left( auth ); 305 author = author.left( auth );
306 } 306 }
307 QRegExp r = QRegExp("[0-9]", true, false); 307 QRegExp r = QRegExp("[0-9]", true, false);
308 if ( author.left(2).find( r) != -1 ) { 308 if ( author.left(2).find( r) != -1 ) {
309 author = ""; 309 author = "";
310 } 310 }
311 311
312 author = author.stripWhiteSpace(); 312 author = author.stripWhiteSpace();
313 if (authBox->isChecked() == TRUE) { // this reverses the first name and last name of the author 313 if (authBox->isChecked() == TRUE) { // this reverses the first name and last name of the author
314 QString lastName, firstName=""; 314 QString lastName, firstName="";
315 int finder = author.findRev( ' ', -1, TRUE); 315 int finder = author.findRev( ' ', -1, TRUE);
316 lastName = author.right( author.length()-finder); 316 lastName = author.right( author.length()-finder);
317 firstName = author.left(finder); 317 firstName = author.left(finder);
318 lastName = lastName.stripWhiteSpace(); 318 lastName = lastName.stripWhiteSpace();
319 firstName = firstName.stripWhiteSpace(); 319 firstName = firstName.stripWhiteSpace();
320 320
321 if( lastName.find( firstName, 0, true) == -1) // this avoids dup names 321 if( lastName.find( firstName, 0, true) == -1) // this avoids dup names
322 author = lastName+", "+firstName; 322 author = lastName+", "+firstName;
323 } 323 }
324 return true; 324 return true;
325}////// end getAuthor() 325}////// end getAuthor()
326 326
327void LibraryDialog::addItems() 327void LibraryDialog::addItems()
328{ 328{
329 cleanStrings(); 329 cleanStrings();
330 getAuthor(); // grok author 330 getAuthor(); // grok author
331 331
332 etext etextStruct; 332 etext etextStruct;
333 if( /*!number.isEmpty() 333 if( /*!number.isEmpty()
334 && */ 334 && */
335 (title.find( "reserved",0, FALSE) == -1) 335 (title.find( "reserved",0, FALSE) == -1)
336 && (file.find( "]",0, true) == -1) 336 && (file.find( "]",0, true) == -1)
337 &&(title.find( "Audio",0, FALSE) == -1)) { 337 &&(title.find( "Audio",0, FALSE) == -1)) {
338 // qDebug("new item "+title); 338 // qDebug("new item "+title);
339 // fill string list or something to be able to sort by Author 339 // fill string list or something to be able to sort by Author
340 etextStruct.title = title; 340 etextStruct.title = title;
341 etextStruct.author = author; 341 etextStruct.author = author;
342 etextStruct.year = year; 342 etextStruct.year = year;
343 etextStruct.file = file; 343 etextStruct.file = file;
344 344
345 etextLibrary.append( etextStruct); 345 etextLibrary.append( etextStruct);
346 346
347 if( author.isEmpty() ) 347 if( author.isEmpty() )
348 QList_Item5 = new QListViewItem( ListView5, /*number, */author, title, year, file ); 348 QList_Item5 = new QListViewItem( ListView5, /*number, */author, title, year, file );
349 else { 349 else {
350 if( author.find(QRegExp("[^a-fA-F]")) ) 350 if( author.find(QRegExp("[^a-fA-F]")) )
351 QList_Item1 = new QListViewItem( ListView1, /* number,*/author, title, year, file ); 351 QList_Item1 = new QListViewItem( ListView1, /* number,*/author, title, year, file );
352 352
353 else if(author.find(QRegExp("[^g-mG-M]")) ) 353 else if(author.find(QRegExp("[^g-mG-M]")) )
354 QList_Item2 = new QListViewItem( ListView2, /* number,*/ author, title,year, file ); 354 QList_Item2 = new QListViewItem( ListView2, /* number,*/ author, title,year, file );
355 355
356 else if(author.find(QRegExp("[^n-rN-R]")) ) 356 else if(author.find(QRegExp("[^n-rN-R]")) )
357 QList_Item3 = new QListViewItem( ListView3, /* number,*/ author, title, year, file ); 357 QList_Item3 = new QListViewItem( ListView3, /* number,*/ author, title, year, file );
358 358
359 else if(author.find(QRegExp("[^s-zS-Z]")) ) 359 else if(author.find(QRegExp("[^s-zS-Z]")) )
360 QList_Item4 = new QListViewItem( ListView4, /* number,*/ author, title, year, file ); 360 QList_Item4 = new QListViewItem( ListView4, /* number,*/ author, title, year, file );
361 } 361 }
362 } 362 }
363} 363}
364 364
365/* 365/*
366 selected one etext*/ 366 selected one etext*/
367void LibraryDialog::select_title( QListViewItem * item) 367void LibraryDialog::select_title( QListViewItem * item)
368{ 368{
369 if(item != NULL) { 369 if(item != NULL) {
370 i++; 370 i++;
371 int index = tabWidget->currentPageIndex(); 371 int index = tabWidget->currentPageIndex();
372 DlglistItemTitle = item->text(0); 372 DlglistItemTitle = item->text(0);
373 DlglistItemYear = item->text(2); 373 DlglistItemYear = item->text(2);
374 DlglistItemFile = item->text(3); 374 DlglistItemFile = item->text(3);
375 375
376 switch (index) { 376 switch (index) {
377 case 0: { 377 case 0: {
378 ListView1->clearSelection(); 378 ListView1->clearSelection();
379 } 379 }
380 break; 380 break;
381 case 1: { 381 case 1: {
382 ListView2->clearSelection(); 382 ListView2->clearSelection();
383 } 383 }
384 break; 384 break;
385 case 2: { 385 case 2: {
386 ListView3->clearSelection(); 386 ListView3->clearSelection();
387 } 387 }
388 break; 388 break;
389 case 3: { 389 case 3: {
390 ListView4->clearSelection(); 390 ListView4->clearSelection();
391 } 391 }
392 break; 392 break;
393 case 4: { 393 case 4: {
394 ListView5->clearSelection(); 394 ListView5->clearSelection();
395 } 395 }
396 break; 396 break;
397 }; 397 };
398 } 398 }
399 399
400 if(DlglistItemTitle.length() > 2) { 400 if(DlglistItemTitle.length() > 2) {
401 item = 0; 401 item = 0;
402 // todo check for connection here 402 // todo check for connection here
403 403
404 bool ok = false; 404 bool ok = false;
405 qDebug(DlglistItemFile); 405 qDebug(DlglistItemFile);
406 406
407 if(DlglistItemFile.toInt() > 10000 ) { 407 if(DlglistItemFile.toInt() > 10000 ) {
408 // new directory sturcture 408 // new directory sturcture
409 if( download_newEtext()) 409 if( download_newEtext())
410 ok = true; 410 ok = true;
411 } else { 411 } else {
412 if(download_Etext()) 412 if(download_Etext())
413 ok = true; 413 ok = true;
414 } 414 }
415 if(ok) { 415 if(ok) {
416 if(checkBox->isChecked () ) 416 if(checkBox->isChecked () )
417 accept(); 417 accept();
418 } 418 }
419 } 419 }
420} 420}
421 421
422bool LibraryDialog::download_newEtext() 422bool LibraryDialog::download_newEtext()
423{ // ftp method 423{ // ftp method
424 QString fileName = DlglistItemFile; 424 QString fileName = DlglistItemFile;
425 425
426 QString directory; 426 QString directory;
427 int stringlength = DlglistItemFile.length(); 427 int stringlength = DlglistItemFile.length();
428 for(i = 0; i < stringlength - 1; i++ ) { 428 for(i = 0; i < stringlength - 1; i++ ) {
429 directory += "/"+ DlglistItemFile[i]; 429 directory += "/"+ DlglistItemFile[i];
430 } 430 }
431 431
432 directory += "/" + DlglistItemFile; 432 directory += "/" + DlglistItemFile;
433 433
434// qWarning(directory); 434// qWarning(directory);
435 435
436 Config cfg("Gutenbrowser"); 436 Config cfg("Gutenbrowser");
437 cfg.setGroup("FTPsite"); 437 cfg.setGroup("FTPsite");
438 ftp_host = cfg.readEntry("SiteName", "sailor.gutenberg.org"); 438 ftp_host = cfg.readEntry("SiteName", "sailor.gutenberg.org");
439 ftp_base_dir = cfg.readEntry("base", "/pub/gutenberg"); 439 ftp_base_dir = cfg.readEntry("base", "/pub/gutenberg");
440 440
441 if( ftp_base_dir.find("=",0,true) ) 441 if( ftp_base_dir.find("=",0,true) )
442 ftp_base_dir.remove( ftp_base_dir.find("=",0,true),1); 442 ftp_base_dir.remove( ftp_base_dir.find("=",0,true),1);
443 443
444 QString dir = ftp_base_dir + directory; 444 QString dir = ftp_base_dir + directory;
445 QString outputFile = local_library + ".guten_temp"; 445 QString outputFile = local_library + ".guten_temp";
446 QString file = fileName + ".txt"; 446 QString file = fileName + ".txt";
447 447
448 QStringList networkList; 448 QStringList networkList;
449 networkList.append((const char *)ftp_host); //host 449 networkList.append((const char *)ftp_host); //host
450 networkList.append((const char *)dir); //ftp base directory 450 networkList.append((const char *)dir); //ftp base directory
451 networkList.append((const char *)outputFile); //output filepath 451 networkList.append((const char *)outputFile); //output filepath
452 networkList.append((const char *)file); //filename 452 networkList.append((const char *)file); //filename
453 453
454 getEtext( networkList); 454 getEtext( networkList);
455 455
456 return true; 456 return true;
457} 457}
458 458
459bool LibraryDialog::getEtext(const QStringList &networkList) 459bool LibraryDialog::getEtext(const QStringList &networkList)
460{ 460{
461 NetworkDialog *NetworkDlg; 461 NetworkDialog *NetworkDlg;
462 NetworkDlg = new NetworkDialog( this,"Network Protocol Dialog", true, 0, networkList); 462 NetworkDlg = new NetworkDialog( this,"Network Protocol Dialog", true, 0, networkList);
463 463
464// use new, improved, *INSTANT* network-dialog-file-getterer 464// use new, improved, *INSTANT* network-dialog-file-getterer
465 if( NetworkDlg->exec() != 0 ) { 465 if( NetworkDlg->exec() != 0 ) {
466 File_Name = NetworkDlg->localFileName; 466 File_Name = NetworkDlg->localFileName;
467 467
468 qDebug("Just downloaded " + NetworkDlg->localFileName); 468 qDebug("Just downloaded " + NetworkDlg->localFileName);
469 469
470 if(NetworkDlg->successDownload) { 470 if(NetworkDlg->successDownload) {
471 //odebug << "Filename is "+File_Name << oendl; 471 //odebug << "Filename is "+File_Name << oendl;
472 if(File_Name.right(4) == ".txt") { 472 if(File_Name.right(4) == ".txt") {
473 QString s_fileName = File_Name; 473 QString s_fileName = File_Name;
474 s_fileName.replace( s_fileName.length() - 3, 3, "gtn"); 474 s_fileName.replace( s_fileName.length() - 3, 3, "gtn");
475 // s_fileName.replace( s_fileName.length()-3,3,"etx"); 475 // s_fileName.replace( s_fileName.length()-3,3,"etx");
476 rename( File_Name.latin1(), s_fileName.latin1()); 476 rename( File_Name.latin1(), s_fileName.latin1());
477 File_Name = s_fileName; 477 File_Name = s_fileName;
478 478
479 //odebug << "Filename is now "+File_Name << oendl; 479 //odebug << "Filename is now "+File_Name << oendl;
480 480
481 } 481 }
482 if(File_Name.length() > 5 ) { 482 if(File_Name.length() > 5 ) {
483 setTitle(); 483 setTitle();
484 QFileInfo fi(File_Name); 484 QFileInfo fi(File_Name);
485 QString name_file = fi.fileName(); 485 QString name_file = fi.fileName();
486 name_file = name_file.left( name_file.length() - 4); 486 name_file = name_file.left( name_file.length() - 4);
487 487
488 //odebug << "Setting doclink" << oendl; 488 //odebug << "Setting doclink" << oendl;
489 DocLnk lnk; 489 DocLnk lnk;
490 //odebug << "name is "+name_file << oendl; 490 //odebug << "name is "+name_file << oendl;
491 lnk.setName(name_file); //sets file name 491 lnk.setName(name_file); //sets file name
492 //odebug << "Title is "+DlglistItemTitle << oendl; 492 //odebug << "Title is "+DlglistItemTitle << oendl;
493 lnk.setComment(DlglistItemTitle); 493 lnk.setComment(DlglistItemTitle);
494 494
495 //odebug << "Filename is "+File_Name << oendl; 495 //odebug << "Filename is "+File_Name << oendl;
496 lnk.setFile(File_Name); //sets File property 496 lnk.setFile(File_Name); //sets File property
497 lnk.setType("guten/plain");// hey is this a REGISTERED mime type?!?!? ;D 497 lnk.setType("guten/plain");// hey is this a REGISTERED mime type?!?!? ;D
498 lnk.setExec(File_Name); 498 lnk.setExec(File_Name);
499 lnk.setIcon("gutenbrowser/Gutenbrowser"); 499 lnk.setIcon("gutenbrowser/Gutenbrowser");
500 if(!lnk.writeLink()) { 500 if(!lnk.writeLink()) {
501 //odebug << "Writing doclink did not work" << oendl; 501 //odebug << "Writing doclink did not work" << oendl;
502 } else { 502 } else {
503 } 503 }
504 } else 504 } else
505 QMessageBox::message("Note","<p>There was an error with the file</p>"); 505 QMessageBox::message("Note","<p>There was an error with the file</p>");
506 } 506 }
507 } 507 }
508 508
509 return true; 509 return true;
510} 510}
511 511
512bool LibraryDialog::download_Etext() 512bool LibraryDialog::download_Etext()
513{ // ftp method 513{ // ftp method
514 // might have to use old gpl'd ftp for embedded!! 514 // might have to use old gpl'd ftp for embedded!!
515 515
516 Config cfg("Gutenbrowser"); 516 Config cfg("Gutenbrowser");
517 cfg.setGroup("FTPsite"); 517 cfg.setGroup("FTPsite");
518 ftp_host = cfg.readEntry("SiteName", "sailor.gutenberg.org"); 518 ftp_host = cfg.readEntry("SiteName", "sailor.gutenberg.org");
519 ftp_base_dir = cfg.readEntry("base", "/pub/gutenberg"); 519 ftp_base_dir = cfg.readEntry("base", "/pub/gutenberg");
520 520
521 qDebug( "about to network dialog"); 521 qDebug( "about to network dialog");
522 522
523 QString NewlistItemNumber, NewlistItemYear, ls_result, result_line, s, dir, /*networkUrl, */outputFile; 523 QString NewlistItemNumber, NewlistItemYear, ls_result, result_line, s, dir, /*networkUrl, */outputFile;
524 524
525 //////////////////// FIXME- if 'x' is part of real name.... 525 //////////////////// FIXME- if 'x' is part of real name....
526 NewlistItemFile = DlglistItemFile.left(DlglistItemFile.find(".xxx", 1, false)).left(DlglistItemFile.left(DlglistItemFile.find(".xxx", 1, false)).find("x", 1, false)); 526 NewlistItemFile = DlglistItemFile.left(DlglistItemFile.find(".xxx", 1, false)).left(DlglistItemFile.left(DlglistItemFile.find(".xxx", 1, false)).find("x", 1, false));
527 527
528 if( NewlistItemFile.find( DlglistItemFile.left(4) ,0,true) ==-1 ) { 528 if( NewlistItemFile.find( DlglistItemFile.left(4) ,0,true) ==-1 ) {
529 NewlistItemFile.replace( 0,4, DlglistItemFile.left(4)); 529 NewlistItemFile.replace( 0,4, DlglistItemFile.left(4));
530 qDebug("NewlistItemFile is now " + NewlistItemFile); 530 qDebug("NewlistItemFile is now " + NewlistItemFile);
531 } 531 }
532 532
533 NewlistItemYear = DlglistItemYear.right(2); 533 NewlistItemYear = DlglistItemYear.right(2);
534 int NewlistItemYear_Int = NewlistItemYear.toInt(0, 10); 534 int NewlistItemYear_Int = NewlistItemYear.toInt(0, 10);
535 //odebug << NewlistItemYear << oendl; 535 //odebug << NewlistItemYear << oendl;
536 if (NewlistItemYear_Int < 91 && NewlistItemYear_Int > 70) { 536 if (NewlistItemYear_Int < 91 && NewlistItemYear_Int > 70) {
537 NewlistItemYear = "90"; 537 NewlistItemYear = "90";
538 } 538 }
539 539
540 Edir ="etext" +NewlistItemYear; 540 Edir ="etext" +NewlistItemYear;
541 541
542 dir = ftp_base_dir + "/etext" + NewlistItemYear + "/"; 542 dir = ftp_base_dir + "/etext" + NewlistItemYear + "/";
543 543
544 if( ftp_base_dir.find("=",0,true) ) 544 if( ftp_base_dir.find("=",0,true) )
545 ftp_base_dir.remove( ftp_base_dir.find("=",0,true),1); 545 ftp_base_dir.remove( ftp_base_dir.find("=",0,true),1);
546 546
547// networkUrl = "ftp://"+ftp_host+dir; 547// networkUrl = "ftp://"+ftp_host+dir;
548 548
549 outputFile = local_library+".guten_temp"; 549 outputFile = local_library+".guten_temp";
550 550
551 qDebug( "Download file: " +NewlistItemFile); 551 qDebug( "Download file: " +NewlistItemFile);
552 qDebug("Checking: " + ftp_host + " " + dir + " " + outputFile+" " + NewlistItemFile); 552 qDebug("Checking: " + ftp_host + " " + dir + " " + outputFile+" " + NewlistItemFile);
553 553
554 554
555 QStringList networkList; 555 QStringList networkList;
556 networkList.append((const char *)ftp_host); //host 556 networkList.append((const char *)ftp_host); //host
557 networkList.append((const char *)dir); //ftp base directory 557 networkList.append((const char *)dir); //ftp base directory
558 networkList.append((const char *)outputFile); //output filepath 558 networkList.append((const char *)outputFile); //output filepath
559 networkList.append((const char *)NewlistItemFile); //filename 559 networkList.append((const char *)NewlistItemFile); //filename
560//<< (char *)ftp_host << (char *)dir << (char *)outputFile << (char *)NewlistItemFile; 560//<< (char *)ftp_host << (char *)dir << (char *)outputFile << (char *)NewlistItemFile;
561 getEtext( networkList); 561 getEtext( networkList);
562 562
563 return true; 563 return true;
564} 564}
565 565
566bool LibraryDialog::httpDownload() 566bool LibraryDialog::httpDownload()
567{// httpDownload 567{// httpDownload
568#ifndef Q_WS_QWS 568#ifndef Q_WS_QWS
569 Config config("Gutenbrowser"); 569 Config config("Gutenbrowser");
570 config.setGroup( "Browser" ); 570 config.setGroup( "Browser" );
571 QString brow = config.readEntry("Preferred", ""); 571 QString brow = config.readEntry("Preferred", "");
572 QString file_name = "./.guten_temp"; 572 QString file_name = "./.guten_temp";
573 // config.setGroup( "HttpServer" ); 573 // config.setGroup( "HttpServer" );
574 // QString s_http = config.readEntry("Preferred", "http://sailor.gutenbook.org"); 574 // QString s_http = config.readEntry("Preferred", "http://sailor.gutenbook.org");
575 QString httpName = proxy_http + "/"+Edir; 575 QString httpName = proxy_http + "/"+Edir;
576 // progressBar->setProgress( i); 576 // progressBar->setProgress( i);
577 i++; 577 i++;
578 if ( brow != "Konq") { /////////// use lynx 578 if ( brow != "Konq") { /////////// use lynx
579 // QString cmd = "lynx -source " + httpName +" | cat >> " + file_name; 579 // QString cmd = "lynx -source " + httpName +" | cat >> " + file_name;
580 // system(cmd); 580 // system(cmd);
581 } else { //////////// use KFM 581 } else { //////////// use KFM
582 // KFM::download( httpName, file_name); 582 // KFM::download( httpName, file_name);
583 } 583 }
584 i++; 584 i++;
585 QFile tmp( file_name); 585 QFile tmp( file_name);
586 QString str; 586 QString str;
587 if (tmp.open(IO_ReadOnly)) { 587 if (tmp.open(IO_ReadOnly)) {
588 QTextStream t( &tmp ); // use a text stream 588 QTextStream t( &tmp ); // use a text stream
589 while ( !t.eof()) { 589 while ( !t.eof()) {
590 QString s = t.readLine(); 590 QString s = t.readLine();
591 if (s.contains( NewlistItemFile, false) && (s.contains(".txt")) ) { 591 if (s.contains( NewlistItemFile, false) && (s.contains(".txt")) ) {
592 str = s.mid( s.find( ".txt\">"+NewlistItemFile, 0, true)+6, (s.find( ".txt</A>", 0, true) + 4) - ( s.find( ".txt\">"+NewlistItemFile, 0, true)+6 ) ); 592 str = s.mid( s.find( ".txt\">"+NewlistItemFile, 0, true)+6, (s.find( ".txt</A>", 0, true) + 4) - ( s.find( ".txt\">"+NewlistItemFile, 0, true)+6 ) );
593 httpName += "/" + str; 593 httpName += "/" + str;
594 } 594 }
595 } //end of while loop 595 } //end of while loop
596 } 596 }
597 tmp.close(); 597 tmp.close();
598 m_getFilePath = local_library + str; 598 m_getFilePath = local_library + str;
599 i++; 599 i++;
600 if ( brow != "KFM"){ ///////// use lynx 600 if ( brow != "KFM"){ ///////// use lynx
601 QString cmd = "lynx -source " + httpName +" | cat >> " + m_getFilePath; 601 QString cmd = "lynx -source " + httpName +" | cat >> " + m_getFilePath;
602 // QMessageBox::message("Error", cmd); 602 // QMessageBox::message("Error", cmd);
603 system(cmd); 603 system(cmd);
604 } else { ////////// use KFM 604 } else { ////////// use KFM
605 // KFM::download( httpName, m_getFilePath); 605 // KFM::download( httpName, m_getFilePath);
606 } 606 }
607 i++; 607 i++;
608#endif 608#endif
609 return false; 609 return false;
610} 610}
611 611
612void LibraryDialog::cancelIt() 612void LibraryDialog::cancelIt()
613{ 613{
614 saveConfig(); 614 saveConfig();
615 615
616 DlglistItemNumber = ""; 616 DlglistItemNumber = "";
617 this->reject(); 617 this->reject();
618} 618}
619 619
620bool LibraryDialog::setTitle() 620bool LibraryDialog::setTitle()
621{ 621{
622 Config config("Gutenbrowser"); 622 Config config("Gutenbrowser");
623 //odebug << "setting title" << oendl; 623 //odebug << "setting title" << oendl;
624 //odebug << DlglistItemTitle << oendl; 624 //odebug << DlglistItemTitle << oendl;
625 625
626 if( DlglistItemTitle.find("[",0,true) != -1) 626 if( DlglistItemTitle.find("[",0,true) != -1)
627 DlglistItemTitle.replace(DlglistItemTitle.find("[",0,true),1, "(" ); 627 DlglistItemTitle.replace(DlglistItemTitle.find("[",0,true),1, "(" );
628 if( DlglistItemTitle.find("]",0,true) !=-1) 628 if( DlglistItemTitle.find("]",0,true) !=-1)
629 DlglistItemTitle.replace(DlglistItemTitle.find("]",0,true),1, ")" ); 629 DlglistItemTitle.replace(DlglistItemTitle.find("]",0,true),1, ")" );
630 //odebug << "Title being set is "+DlglistItemTitle << oendl; 630 //odebug << "Title being set is "+DlglistItemTitle << oendl;
631 int test = 0; 631 int test = 0;
632 QString ramble, temp; 632 QString ramble, temp;
633 config.setGroup("Files"); 633 config.setGroup("Files");
634 QString s_numofFiles = config.readEntry("NumberOfFiles", "0" ); 634 QString s_numofFiles = config.readEntry("NumberOfFiles", "0" );
635 int i_numofFiles = s_numofFiles.toInt(); 635 int i_numofFiles = s_numofFiles.toInt();
636 for ( int i = 0; i <= i_numofFiles; i++){ 636 for ( int i = 0; i <= i_numofFiles; i++){
637 temp.setNum( i); 637 temp.setNum( i);
638 ramble = config.readEntry( temp, "" ); 638 ramble = config.readEntry( temp, "" );
639 if( strcmp( ramble, File_Name) == 0){ 639 if( strcmp( ramble, File_Name) == 0){
640 test = 1; 640 test = 1;
641 } 641 }
642 } 642 }
643 643
644 if(test == 0 ) { 644 if(test == 0 ) {
645 645
646 config.setGroup("Files"); 646 config.setGroup("Files");
647 config.writeEntry( "NumberOfFiles", i_numofFiles +1 ); 647 config.writeEntry( "NumberOfFiles", i_numofFiles +1 );
648 QString interger; 648 QString interger;
649 interger.setNum( i_numofFiles +1); 649 interger.setNum( i_numofFiles +1);
650 config.writeEntry( interger, File_Name); 650 config.writeEntry( interger, File_Name);
651 config.setGroup( "Titles" ); 651 config.setGroup( "Titles" );
652 config.writeEntry( File_Name, DlglistItemTitle); 652 config.writeEntry( File_Name, DlglistItemTitle);
653 } 653 }
654 test = 0; 654 test = 0;
655 return true; 655 return true;
656} 656}
657 657
658 658
659void LibraryDialog::saveConfig() 659void LibraryDialog::saveConfig()
660{ 660{
661 Config config("Gutenbrowser"); 661 Config config("Gutenbrowser");
662 if( httpBox->isChecked() == true) { 662 if( httpBox->isChecked() == true) {
663 checked = 1; 663 checked = 1;
664 config.setGroup( "Proxy" ); 664 config.setGroup( "Proxy" );
665 config.writeEntry("IsChecked", "true"); 665 config.writeEntry("IsChecked", "true");
666 } else { 666 } else {
667 checked = 0; 667 checked = 0;
668 config.setGroup( "Proxy" ); 668 config.setGroup( "Proxy" );
669 config.writeEntry("IsChecked", "false"); 669 config.writeEntry("IsChecked", "false");
670 } 670 }
671 if (authBox->isChecked() == true) { 671 if (authBox->isChecked() == true) {
672 config.setGroup("SortAuth"); 672 config.setGroup("SortAuth");
673 config.writeEntry("authSort", "true"); 673 config.writeEntry("authSort", "true");
674 } else { 674 } else {
675 config.setGroup("SortAuth"); 675 config.setGroup("SortAuth");
676 config.writeEntry("authSort", "false"); 676 config.writeEntry("authSort", "false");
677 } 677 }
678 // config.write(); 678 // config.write();
679} 679}
680 680
681/* 681/*
682 searches library index for user word*/ 682 searches library index for user word*/
683void LibraryDialog::onButtonSearch() 683void LibraryDialog::onButtonSearch()
684{ 684{
685 ListView1->clearSelection(); 685 ListView1->clearSelection();
686 ListView2->clearSelection(); 686 ListView2->clearSelection();
687 ListView3->clearSelection(); 687 ListView3->clearSelection();
688 ListView4->clearSelection(); 688 ListView4->clearSelection();
689 ListView5->clearSelection(); 689 ListView5->clearSelection();
690 690
691 int curTab = tabWidget->currentPageIndex(); 691 int curTab = tabWidget->currentPageIndex();
692 SearchDialog* searchDlg; 692 SearchDialog* searchDlg;
693 693
694 // if( resultsList) 694 // if( resultsList)
695 searchDlg = new SearchDialog( this, "Library Search", true); 695 searchDlg = new SearchDialog( this, "Library Search", true);
696 searchDlg->setCaption( tr( "Library Search" ) ); 696 searchDlg->setCaption( tr( "Library Search" ) );
697 searchDlg->setLabel( "- author or title"); 697 searchDlg->setLabel( "- author or title");
698 698
699 QString resultString; 699 QString resultString;
700 700
701 int i_berger = 0; 701 int i_berger = 0;
702 if( searchDlg->exec() != 0 ) { 702 if( searchDlg->exec() != 0 ) {
703 QString searcherStr = searchDlg->get_text(); 703 QString searcherStr = searchDlg->get_text();
704 int fluff = 0; 704 int fluff = 0;
705 705
706 bool cS; 706 bool cS;
707 if( searchDlg->caseSensitiveCheckBox->isChecked()) 707 if( searchDlg->caseSensitiveCheckBox->isChecked())
708 cS = true; //case sensitive 708 cS = true; //case sensitive
709 else 709 else
710 cS = false; 710 cS = false;
711 711
712 etext etextStruct; 712 etext etextStruct;
713 QValueList<etext>::Iterator it; 713 QValueList<etext>::Iterator it;
714 714
715 for( it = etextLibrary.begin(); it != etextLibrary.end(); ++it ) { 715 for( it = etextLibrary.begin(); it != etextLibrary.end(); ++it ) {
716 QString tempTitle = (*it).title; 716 QString tempTitle = (*it).title;
717 QString tempAuthor = (*it).author; 717 QString tempAuthor = (*it).author;
718 QString tempFile = (*it).file; 718 QString tempFile = (*it).file;
719 QString tempYear = (*it).year; 719 QString tempYear = (*it).year;
720 if(tempTitle.find( searcherStr, 0, cS) != -1 720 if(tempTitle.find( searcherStr, 0, cS) != -1
721 || tempAuthor.find( searcherStr, 0, cS) != -1) { 721 || tempAuthor.find( searcherStr, 0, cS) != -1) {
722 qWarning(tempTitle); 722 qWarning(tempTitle);
723 Searchlist.append( tempTitle + " : " + tempYear + " : " + tempFile); 723 Searchlist.append( tempTitle + " : " + tempYear + " : " + tempFile);
724 } 724 }
725 } 725 }
726 726
727 727
728 tabWidget->setCurrentPage( curTab); 728 tabWidget->setCurrentPage( curTab);
729 729
730 Searchlist.sort(); 730 Searchlist.sort();
731 SearchResultsDlg* SearchResultsDialog; 731 SearchResultsDlg* SearchResultsDialog;
732 SearchResultsDialog = new SearchResultsDlg( searchDlg, "Results Dialog", true, 0 , Searchlist); 732 SearchResultsDialog = new SearchResultsDlg( searchDlg, "Results Dialog", true, 0 , Searchlist);
733 733
734 SearchResultsDialog->showMaximized(); 734 SearchResultsDialog->showMaximized();
735 if( SearchResultsDialog->exec() != 0) { 735 if( SearchResultsDialog->exec() != 0) {
736 texter = SearchResultsDialog->selText; 736 texter = SearchResultsDialog->selText;
737 // //odebug << texter << oendl; 737 // //odebug << texter << oendl;
738 resultLs = SearchResultsDialog->resultsList; 738 resultLs = SearchResultsDialog->resultsList;
739 i_berger = 1; 739 i_berger = 1;
740 } else { 740 } else {
741 resultLs.clear(); 741 resultLs.clear();
742 } 742 }
743 Searchlist.clear(); 743 Searchlist.clear();
744 744
745 QString tester; 745 QString tester;
746 for ( QStringList::Iterator it = resultLs.begin(); it != resultLs.end(); ++it ) { 746 for ( QStringList::Iterator it = resultLs.begin(); it != resultLs.end(); ++it ) {
747 texter.sprintf("%s \n",(*it).latin1()); 747 texter.sprintf("%s \n",(*it).latin1());
748 // //odebug << texter << oendl; 748 // //odebug << texter << oendl;
749 if( tester!=texter) 749 if( tester!=texter)
750 parseSearchResults( texter); 750 parseSearchResults( texter);
751 tester = texter; 751 tester = texter;
752 } 752 }
753 if(searchDlg) 753 if(searchDlg)
754 delete searchDlg; 754 delete searchDlg;
755 } 755 }
756 if(checkBox->isChecked() ) { 756 if(checkBox->isChecked() ) {
757 accept(); 757 accept();
758 } else { 758 } else {
759 setActiveWindow(); 759 setActiveWindow();
760 } 760 }
761} 761}
762 762
763/* 763/*
764 splits the result string and calls download for the current search result*/ 764 splits the result string and calls download for the current search result*/
765void LibraryDialog::parseSearchResults( QString resultStr) 765void LibraryDialog::parseSearchResults( QString resultStr)
766{ 766{
767 int stringLeng = resultStr.length(); 767 int stringLeng = resultStr.length();
768 768
769 QString my; 769 QString my;
770 my.setNum( stringLeng, 10); 770 my.setNum( stringLeng, 10);
771 771
772 if( resultStr.length() > 2 && resultStr.length() < 130) { 772 if( resultStr.length() > 2 && resultStr.length() < 130) {
773 QStringList token = QStringList::split(" : ", resultStr);
773 774
774 int titleInt = resultStr.find( " : ", 0, true); 775 DlglistItemTitle = token[0];
775 DlglistItemTitle = resultStr.left( titleInt); 776 DlglistItemTitle = DlglistItemTitle.stripWhiteSpace();
776 777
777 int yearInt = resultStr.find( " : ", titleInt+3, true); 778 DlglistItemYear = token[1];
778 779 DlglistItemYear = DlglistItemYear.stripWhiteSpace();
779 DlglistItemYear = resultStr.mid( titleInt+3, (yearInt - titleInt)-3); 780
780 781 DlglistItemFile = token[2];
781 DlglistItemFile = resultStr.right( resultStr.length() - (yearInt + 3)); 782
782 DlglistItemFile = DlglistItemFile.left( DlglistItemFile.length() - 2); 783 DlglistItemFile = DlglistItemFile.stripWhiteSpace();
783 784
784 cleanStrings(); 785// qWarning(DlglistItemYear);
786
785 787
786 if(DlglistItemFile.left(1) == "/") 788 if(DlglistItemFile.left(1) == "/")
787 DlglistItemFile = DlglistItemFile.right( DlglistItemFile.length() - 1); 789 DlglistItemFile = DlglistItemFile.right( DlglistItemFile.length() - 1);
788 790
789 791 if(DlglistItemFile.toInt() > 10000 || DlglistItemYear == "1980" ) {
790 if(DlglistItemFile.toInt() > 10000 || yearInt == 1980 ) {
791 // new directory sturcture 792 // new directory sturcture
792 download_newEtext(); //) 793 download_newEtext(); //)
793 } else { 794 } else {
794 download_Etext(); //) 795 download_Etext(); //)
795 } 796 }
796 } 797 }
797} 798}
798 799
799void LibraryDialog::sortLists(int index) 800void LibraryDialog::sortLists(int index)
800{ 801{
801 802
802 ListView1->setSorting(index); 803 ListView1->setSorting(index);
803 ListView2->setSorting(index); 804 ListView2->setSorting(index);
804 ListView3->setSorting(index); 805 ListView3->setSorting(index);
805 ListView4->setSorting(index); 806 ListView4->setSorting(index);
806 ListView5->setSorting(index); 807 ListView5->setSorting(index);
807 ListView1->sort(); 808 ListView1->sort();
808 ListView2->sort(); 809 ListView2->sort();
809 ListView3->sort(); 810 ListView3->sort();
810 ListView4->sort(); 811 ListView4->sort();
811 ListView5->sort(); 812 ListView5->sort();
812} 813}
813 814
814/* 815/*
815 Downloads the current selected listitem*/ 816 Downloads the current selected listitem*/
816bool LibraryDialog::getItem(QListViewItem *it) 817bool LibraryDialog::getItem(QListViewItem *it)
817{ 818{
818 // //odebug << "selected getItem" << oendl; 819 // //odebug << "selected getItem" << oendl;
819 820
820 // DlglistItemNumber = it->text(0); 821 // DlglistItemNumber = it->text(0);
821 DlglistItemTitle = it->text(0); 822 DlglistItemTitle = it->text(0);
822 DlglistItemYear = it->text(2); 823 DlglistItemYear = it->text(2);
823 DlglistItemFile = it->text(3); 824 DlglistItemFile = it->text(3);
824 825
825 if(download_Etext()) { 826 if(download_Etext()) {
826 if(i_binary == 1) { 827 if(i_binary == 1) {
827 } 828 }
828 } 829 }
829 return true; 830 return true;
830} 831}
831 832
832/* 833/*
833 download button is pushed so we get the current items to download*/ 834 download button is pushed so we get the current items to download*/
834bool LibraryDialog::onButtonDownload() 835bool LibraryDialog::onButtonDownload()
835{ 836{
836 // //odebug << "selected onButtonDownloadz" << oendl; 837 // //odebug << "selected onButtonDownloadz" << oendl;
837 838
838 QListViewItemIterator it1( ListView1 ); 839 QListViewItemIterator it1( ListView1 );
839 QListViewItemIterator it2( ListView2 ); 840 QListViewItemIterator it2( ListView2 );
840 QListViewItemIterator it3( ListView3 ); 841 QListViewItemIterator it3( ListView3 );
841 QListViewItemIterator it4( ListView4 ); 842 QListViewItemIterator it4( ListView4 );
842 QListViewItemIterator it5( ListView5 ); 843 QListViewItemIterator it5( ListView5 );
843 844
844 // iterate through all items of the listview 845 // iterate through all items of the listview
845 for ( ; it1.current(); ++it1 ) { 846 for ( ; it1.current(); ++it1 ) {
846 if ( it1.current()->isSelected() ) 847 if ( it1.current()->isSelected() )
847 getItem(it1.current()); 848 getItem(it1.current());
848 it1.current()->setSelected(false); 849 it1.current()->setSelected(false);
849 } 850 }
850 for ( ; it2.current(); ++it2 ) { 851 for ( ; it2.current(); ++it2 ) {
851 if ( it2.current()->isSelected() ) 852 if ( it2.current()->isSelected() )
852 getItem(it2.current()); 853 getItem(it2.current());
853 it2.current()->setSelected(false); 854 it2.current()->setSelected(false);
854 } 855 }
855 for ( ; it3.current(); ++it3 ) { 856 for ( ; it3.current(); ++it3 ) {
856 if ( it3.current()->isSelected() ) 857 if ( it3.current()->isSelected() )
857 getItem(it3.current()); 858 getItem(it3.current());
858 it3.current()->setSelected(false); 859 it3.current()->setSelected(false);
859 } 860 }
860 for ( ; it4.current(); ++it4 ) { 861 for ( ; it4.current(); ++it4 ) {
861 if ( it4.current()->isSelected() ) 862 if ( it4.current()->isSelected() )
862 getItem(it4.current()); 863 getItem(it4.current());
863 it4.current()->setSelected(false); 864 it4.current()->setSelected(false);
864 } 865 }
865 for ( ; it5.current(); ++it5 ) { 866 for ( ; it5.current(); ++it5 ) {
866 if ( it5.current()->isSelected() ) 867 if ( it5.current()->isSelected() )
867 getItem(it5.current()); 868 getItem(it5.current());
868 it5.current()->setSelected(false); 869 it5.current()->setSelected(false);
869 } 870 }
870 return true; 871 return true;
871} 872}
872 873
873 874
874/* 875/*
875 handles the sorting combo box */ 876 handles the sorting combo box */
876void LibraryDialog::comboSelect(int index) 877void LibraryDialog::comboSelect(int index)
877{ 878{
878 // //odebug << "we are sorting" << oendl; 879 // //odebug << "we are sorting" << oendl;
879 ListView1->setSorting( index, true); 880 ListView1->setSorting( index, true);
880 ListView2->setSorting( index, true); 881 ListView2->setSorting( index, true);
881 ListView3->setSorting( index, true); 882 ListView3->setSorting( index, true);
882 ListView4->setSorting( index, true); 883 ListView4->setSorting( index, true);
883 ListView5->setSorting( index, true); 884 ListView5->setSorting( index, true);
884 885
885 ListView1->sort(); 886 ListView1->sort();
886 ListView2->sort(); 887 ListView2->sort();
887 ListView3->sort(); 888 ListView3->sort();
888 ListView4->sort(); 889 ListView4->sort();
889 ListView5->sort(); 890 ListView5->sort();
890 891
891 // ListView1->triggerUpdate(); 892 // ListView1->triggerUpdate();
892 // ListView2->triggerUpdate(); 893 // ListView2->triggerUpdate();
893 // ListView3->triggerUpdate(); 894 // ListView3->triggerUpdate();
894 // ListView4->triggerUpdate(); 895 // ListView4->triggerUpdate();
895 // ListView5->triggerUpdate(); 896 // ListView5->triggerUpdate();
896} 897}
897 898
898void LibraryDialog::newList() 899void LibraryDialog::newList()
899{ 900{
900 if(indexLoaded) { 901 if(indexLoaded) {
901 onButtonDownload(); 902 onButtonDownload();
902 } else { 903 } else {
903 Output *outDlg; 904 Output *outDlg;
904 buttonNewList->setDown(true); 905 buttonNewList->setDown(true);
905 //odebug << "changing dir "+QPEApplication::qpeDir()+"etc/gutenbrowser" << oendl; 906 //odebug << "changing dir "+QPEApplication::qpeDir()+"etc/gutenbrowser" << oendl;
906 QString gutenindex1 = local_library + "/GUTINDEX.ALL"; 907 QString gutenindex1 = local_library + "/GUTINDEX.ALL";
907 908
908 QString cmd="wget -O " + gutenindex1 + " http://www.gutenberg.org/dirs/GUTINDEX.ALL 2>&1"; 909 QString cmd="wget -O " + gutenindex1 + " http://www.gutenberg.org/dirs/GUTINDEX.ALL 2>&1";
909 910
910 int result = QMessageBox::warning( this,"Download" 911 int result = QMessageBox::warning( this,"Download"
911 ,"<p>Ok to use /'wget/' to download a new library list?</P>" 912 ,"<p>Ok to use /'wget/' to download a new library list?</P>"
912 ,"Yes","No",0,0,1); 913 ,"Yes","No",0,0,1);
913 qApp->processEvents(); 914 qApp->processEvents();
914 if(result == 0) { 915 if(result == 0) {
915 outDlg = new Output( 0, tr("Downloading Gutenberg Index...."),true); 916 outDlg = new Output( 0, tr("Downloading Gutenberg Index...."),true);
916 outDlg->showMaximized(); 917 outDlg->showMaximized();
917 outDlg->show(); 918 outDlg->show();
918 qApp->processEvents(); 919 qApp->processEvents();
919 FILE *fp; 920 FILE *fp;
920 char line[130]; 921 char line[130];
921 outDlg->OutputEdit->append( tr("Running wget") ); 922 outDlg->OutputEdit->append( tr("Running wget") );
922 outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,false); 923 outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,false);
923 sleep(1); 924 sleep(1);
924 fp = popen( (const char *) cmd, "r"); 925 fp = popen( (const char *) cmd, "r");
925 if ( !fp ) { 926 if ( !fp ) {
926 } else { 927 } else {
927 //odebug << "Issuing the command\n"+cmd << oendl; 928 //odebug << "Issuing the command\n"+cmd << oendl;
928 // system(cmd); 929 // system(cmd);
929 while ( fgets( line, sizeof line, fp)) { 930 while ( fgets( line, sizeof line, fp)) {
930 outDlg->OutputEdit->append(line); 931 outDlg->OutputEdit->append(line);
931 outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,false); 932 outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,false);
932 } 933 }
933 pclose(fp); 934 pclose(fp);
934 outDlg->OutputEdit->append("Finished downloading\n"); 935 outDlg->OutputEdit->append("Finished downloading\n");
935 outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,false); 936 outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,false);
936 qApp->processEvents(); 937 qApp->processEvents();
937 938
938 // if( QFile(gutenindex1).exists() ) { 939 // if( QFile(gutenindex1).exists() ) {
939 // QString gutenindex=QPEApplication::qpeDir()+"etc/gutenbrowser/GUTINDEX.ALL"; 940 // QString gutenindex=QPEApplication::qpeDir()+"etc/gutenbrowser/GUTINDEX.ALL";
940 // if( rename(gutenindex1.latin1(),gutenindex.latin1()) !=0) 941 // if( rename(gutenindex1.latin1(),gutenindex.latin1()) !=0)
941 // //odebug << "renaming error" << oendl; 942 // //odebug << "renaming error" << oendl;
942 // } 943 // }
943 944
944 } 945 }
945 // outDlg->close(); 946 // outDlg->close();
946 FindLibrary(); 947 FindLibrary();
947 if(outDlg) delete outDlg; 948 if(outDlg) delete outDlg;
948 } 949 }
949 buttonNewList->setDown(false); 950 buttonNewList->setDown(false);
950 951
951 // if(outDlg) 952 // if(outDlg)
952 // delete outDlg; 953 // delete outDlg;
953 } 954 }
954} 955}
955 956
956bool LibraryDialog::moreInfo() 957bool LibraryDialog::moreInfo()
957{ 958{
958 959
959 QListViewItem * item; 960 QListViewItem * item;
960 item = 0; 961 item = 0;
961 QString titleString; 962 QString titleString;
962 item = ListView1->currentItem(); 963 item = ListView1->currentItem();
963 if( item != 0) { 964 if( item != 0) {
964 titleString = item->text(0); 965 titleString = item->text(0);
965 ListView1->clearSelection(); 966 ListView1->clearSelection();
966 item = 0; 967 item = 0;
967 } 968 }
968 if( item == 0) 969 if( item == 0)
969 item = ListView2->currentItem(); 970 item = ListView2->currentItem();
970 if( item != 0) { 971 if( item != 0) {
971 titleString = item->text(0); 972 titleString = item->text(0);
972 ListView2->clearSelection(); 973 ListView2->clearSelection();
973 item = 0; 974 item = 0;
974 } 975 }
975 if( item == 0) 976 if( item == 0)
976 item = ListView3->currentItem(); 977 item = ListView3->currentItem();
977 if( item != 0) { 978 if( item != 0) {
978 titleString = item->text(0); 979 titleString = item->text(0);
979 ListView3->clearSelection(); 980 ListView3->clearSelection();
980 item = 0; 981 item = 0;
981 } 982 }
982 if( item == 0) 983 if( item == 0)
983 item = ListView4->currentItem(); 984 item = ListView4->currentItem();
984 if( item != 0) { 985 if( item != 0) {
985 titleString = item->text(0); 986 titleString = item->text(0);
986 ListView4->clearSelection(); 987 ListView4->clearSelection();
987 item = 0; 988 item = 0;
988 } 989 }
989 if( item == 0) 990 if( item == 0)
990 item = ListView5->currentItem(); 991 item = ListView5->currentItem();
991 if( item != 0) { 992 if( item != 0) {
992 titleString = item->text(0); 993 titleString = item->text(0);
993 ListView5->clearSelection(); 994 ListView5->clearSelection();
994 item = 0; 995 item = 0;
995 } 996 }
996 item=0; 997 item=0;
997 if(titleString.length()>2) { 998 if(titleString.length()>2) {
998 //odebug << "Title is "+titleString << oendl; 999 //odebug << "Title is "+titleString << oendl;
999 titleString.replace( QRegExp("\\s"), "%20"); 1000 titleString.replace( QRegExp("\\s"), "%20");
1000 titleString.replace( QRegExp("'"), "%20"); 1001 titleString.replace( QRegExp("'"), "%20");
1001 titleString.replace( QRegExp("\""), "%20"); 1002 titleString.replace( QRegExp("\""), "%20");
1002 titleString.replace( QRegExp("&"), "%20"); 1003 titleString.replace( QRegExp("&"), "%20");
1003 QString cmd= "http://google.com/search?q="+titleString+"&num=30&sa=Google+Search"; 1004 QString cmd= "http://google.com/search?q="+titleString+"&num=30&sa=Google+Search";
1004 cmd="opera "+cmd; 1005 cmd="opera "+cmd;
1005 system(cmd); 1006 system(cmd);
1006 } else 1007 } else
1007 QMessageBox::message( "Note","<p>If you select a title, this will search google.com for that title.</p>"); 1008 QMessageBox::message( "Note","<p>If you select a title, this will search google.com for that title.</p>");
1008 return true; 1009 return true;
1009 1010
1010} 1011}
1011 1012
1012/* 1013/*
1013 This loads the library Index*/ 1014 This loads the library Index*/
1014void LibraryDialog::FindLibrary() 1015void LibraryDialog::FindLibrary()
1015{ 1016{
1016 buttonLibrary->setDown(true); 1017 buttonLibrary->setDown(true);
1017 1018
1018 qApp->processEvents(); 1019 qApp->processEvents();
1019 if( QFile( new_index).exists() /* && this->isHidden() */) { 1020 if( QFile( new_index).exists() /* && this->isHidden() */) {
1020 newindexLib.setName( new_index); 1021 newindexLib.setName( new_index);
1021 indexLib.setName( new_index); 1022 indexLib.setName( new_index);
1022 //odebug << "index file is "+ new_index << oendl; 1023 //odebug << "index file is "+ new_index << oendl;
1023 Newlibrary(); 1024 Newlibrary();
1024 } else { 1025 } else {
1025 newindexLib.setName( old_index); 1026 newindexLib.setName( old_index);
1026 indexLib.setName( old_index); 1027 indexLib.setName( old_index);
1027 //odebug << "new index nameis "+ old_index << oendl; 1028 //odebug << "new index nameis "+ old_index << oendl;
1028 Library(); 1029 Library();
1029 } 1030 }
1030 indexLoaded =true; 1031 indexLoaded =true;
1031 buttonSearch->setEnabled(true); 1032 buttonSearch->setEnabled(true);
1032 moreInfoButton->setEnabled(true); 1033 moreInfoButton->setEnabled(true);
1033 1034
1034 buttonLibrary->setDown(false); 1035 buttonLibrary->setDown(false);
1035 buttonNewList->setText("Download"); 1036 buttonNewList->setText("Download");
1036 qApp->processEvents(); 1037 qApp->processEvents();
1037 1038
1038} 1039}
1039 1040
1040void LibraryDialog::cleanStrings() { 1041void LibraryDialog::cleanStrings() {
1041 year = year.stripWhiteSpace(); 1042 year = year.stripWhiteSpace();
1042 file = file.stripWhiteSpace(); 1043 file = file.stripWhiteSpace();
1043 title = title.stripWhiteSpace(); 1044 title = title.stripWhiteSpace();
1044 number = number.stripWhiteSpace(); 1045 number = number.stripWhiteSpace();
1045 1046
1046} 1047}
1047 1048
1048void LibraryDialog::authBoxClicked() 1049void LibraryDialog::authBoxClicked()
1049{ 1050{
1050 qApp->processEvents(); 1051 qApp->processEvents();
1051 FindLibrary(); 1052 FindLibrary();
1052} 1053}