00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "LibraryDialog.h"
00017 #include "output.h"
00018
00019
00020 #include <qpe/applnk.h>
00021 #include <qpe/qpeapplication.h>
00022 #include <qpe/qpedialog.h>
00023
00024
00025
00026 #include <qpushbutton.h>
00027 #include <qmultilineedit.h>
00028
00029
00030
00031 #include <unistd.h>
00032 #include <stdio.h>
00033 #include <stdlib.h>
00034
00035
00036
00037
00038 LibraryDialog::LibraryDialog( QWidget* parent, const char* name , bool , WFlags fl )
00039 : QDialog( parent, name, true, fl )
00040 {
00041 if ( !name )
00042 setName( "LibraryDialog" );
00043 indexLoaded=false;
00044 initDialog();
00045
00046
00047
00048 index = "GUTINDEX.ALL";
00049 local_library = (QDir::homeDirPath ()) +"/Applications/gutenbrowser/";
00050 local_index = local_library + index;
00051
00052 QString iniFile ;
00053 iniFile = local_library + "/gutenbrowserrc";
00054 new_index = local_library + "/PGWHOLE.TXT";
00055 old_index = local_index;
00056
00057
00058
00059
00060 Config config("Gutenbrowser");
00061
00062 config.setGroup( "HttpServer" );
00063 proxy_http = config.readEntry("Preferred", "http://sailor.gutenbook.org");
00064
00065 config.setGroup( "FTPsite" );
00066 ftp_host = config.readEntry("SiteName", "sailor.gutenberg.org");
00067
00068
00069
00070 ftp_base_dir= config.readEntry("base", "/pub/gutenberg");
00071
00072 i_binary = 0;
00073
00074 config.setGroup("SortAuth");
00075 if( config.readEntry("authSort", "false") == "true")
00076 authBox->setChecked(true);
00077
00078 config.setGroup("General");
00079 downDir = config.readEntry( "DownloadDirectory",local_library);
00080
00081 newindexLib.setName( old_index);
00082 indexLib.setName( old_index);
00083
00084 new QPEDialogListener(this);
00085 QTimer::singleShot( 1000, this, SLOT( FindLibrary()) );
00086
00087 }
00088
00089 LibraryDialog::~LibraryDialog()
00090 {
00091 }
00092
00093 void LibraryDialog::clearItems() {
00094 ListView1->clear();
00095 ListView2->clear();
00096 ListView3->clear();
00097 ListView4->clear();
00098 ListView5->clear();
00099 }
00100
00101
00102 void LibraryDialog::Newlibrary()
00103 {
00104 clearItems();
00105 #ifndef Q_WS_QWS //sorry embedded gutenbrowser cant use zip files
00106
00107 if ( newindexLib.open( IO_ReadOnly) ) {
00108 setCaption( tr( "Library Index - using master pg index." ) );
00109 QTextStream indexStream( &newindexLib );
00110 QString indexLine;
00111 while ( !indexStream.atEnd() ) {
00112 indexLine = indexStream.readLine();
00113 if ( ( indexLine.mid(4,4)).toInt() && !( indexLine.left(3)).toInt()) {
00114 year = indexLine.mid(4,4);
00115 file = indexLine.mid( indexLine.find( "[", 0, true )+1, 12 );
00116 number = indexLine.mid( indexLine.find( "]", 0, true ) +1, indexLine.find( " ", 0, true )+1 );
00117 if( year.toInt() < 1984)
00118 number = number.left( number.length() -1 );
00119 title = indexLine.mid( indexLine.find(" ", 26, true), indexLine.length() );
00120
00121 addItems();
00122
00123 }
00124 }
00125 newindexLib.close();
00126 }
00127 #ifndef Q_WS_QWS
00128 setCursor( arrowCursor);
00129 #endif
00130 #endif
00131 }
00132
00133
00134 void LibraryDialog::Library() {
00135 clearItems();
00136
00137
00138 IDontKnowWhy = "";
00139 system("date");
00140 if ( indexLib.open( IO_ReadOnly) ) {
00141
00142 QTextStream indexStream( &indexLib );
00143 QString indexLine;
00144 qApp->processEvents();
00145
00146 bool okToRead = false;
00147 while ( !indexStream.eof() ) {
00148 indexLine = indexStream.readLine();
00149 if(indexLine == "<==Start GUTINDEX.ALL listings==>")
00150 okToRead = true;
00151 if(indexLine == "<==End of GUTINDEX.ALL==>") {
00152 okToRead = false;
00153 indexLib.at(indexLib.size());
00154 }
00155
00156 if(okToRead) {
00157 QStringList token = QStringList::split(' ', indexLine);
00158 int textNumber;
00159 if(( textNumber = token.last().toInt() ))
00160 if(textNumber > 10001) {
00161
00162
00163 if(textNumber < 10626)
00164 year = "2003";
00165 else if(textNumber >= 10626 && textNumber < 14600)
00166 year = "2004";
00167 else if(textNumber >= 14600)
00168 year = "2005";
00169
00170 file = token.last();
00171 title = indexLine.mid(0,72);
00172
00173 addItems();
00174
00175
00176 } else {
00177
00178 if(token[1].toInt() && token[1].toInt() > 1969) {
00179 year = token[1];
00180 file = indexLine.mid(60,12);
00181
00182 if(file.left(1).find("[",0,TRUE) != -1) {
00183 file.remove(1,1);
00184 if( file.find("]",0,TRUE) != -1)
00185 file = file.left( file.find("]",0,TRUE));
00186
00187 if(file.find("?", 0, false) != -1 ) {
00188 QString tmpfile = file.replace(QRegExp("[?]"), "8");
00189 file = tmpfile;
00190 }
00191 title = indexLine.mid( 9, 50);
00192
00193 addItems();
00194 }
00195 } else {
00196 file = token.last();
00197 title = indexLine.mid(0,72);
00198 year = "1980";
00199
00200 addItems();
00201 }
00202 }
00203
00204 }
00205 }
00206 indexLib.close();
00207 } else {
00208 QString sMsg;
00209
00210 sMsg = ( tr("<p>Error opening library index file. Please download a new one.</P> "));
00211 QMessageBox::message( "Error",sMsg);
00212 }
00213 system("date");
00214 sortLists(0);
00215
00216 }
00217
00218
00219
00220
00221 bool LibraryDialog::getAuthor()
00222 {
00223 if( title.contains( ", by", true)) {
00224 int auth;
00225 auth = title.find(", by", 0, true);
00226 author = title.right(title.length() - (auth + 4) );
00227 if( int finder = author.find("[", 0, true)) {
00228 author = author.left(finder);
00229 }
00230 }
00231 else if ( title.contains( "by, ", true) ) {
00232 int auth;
00233 auth = title.find("by, ", 0, true);
00234 author = title.right(title.length() - (auth + 4) );
00235 if( int finder = author.find("[", 0, true)) {
00236 author = author.left( finder);
00237 }
00238 }
00239 else if ( title.contains( " by", true) ) {
00240 int auth;
00241 auth = title.find(" by", 0, true);
00242 author = title.right(title.length() - (auth + 3) );
00243 if( int finder = author.find("[", 0, true)) {
00244 author = author.left( finder);
00245 }
00246 }
00247 else if ( title.contains( "by ", true) ) {
00248 int auth;
00249 auth = title.find("by ", 0, true);
00250 author = title.right(title.length() - (auth + 3) );
00251 if( int finder = author.find("[", 0, true)) {
00252 author = author.left( finder);
00253 }
00254 }
00255 else if ( title.contains( ",", true) ) {
00256 int auth;
00257 auth = title.find(",", 0, true);
00258 author = title.right( title.length() - (auth + 1) );
00259 if ( author.contains( ",", true) ) {
00260 int auth;
00261 auth = author.find(",", 0, true);
00262 author = author.right( author.length() - (auth + 1) );
00263 }
00264 if( int finder = author.find("[", 0, true)) {
00265 author = author.left( finder);
00266 }
00267 }
00268 else if ( title.contains( "/", true) ) {
00269 int auth;
00270 auth = title.find("/", 0, true);
00271 author = title.right(title.length() - (auth + 1) );
00272 if( int finder = author.find("[", 0, true)) {
00273 author = author.left( finder);
00274 }
00275 }
00276 else if ( title.contains( "of", true) ) {
00277 int auth;
00278 auth = title.find("of", 0, true);
00279 author = title.right(title.length() - (auth + 2) );
00280 if( int finder = author.find("[", 0, true))
00281 {
00282 author = author.left( finder);
00283 }
00284 } else {
00285 author = "";
00286 }
00287 if ( author.contains("et. al")) {
00288 int auth;
00289 auth = author.find("et. al", 0, true);
00290 author = author.left( auth );
00291 }
00292 if ( author.contains("#")) {
00293 int auth;
00294 auth = author.find("#", 0, true);
00295 author = author.left( auth);
00296 }
00297 if ( author.contains("(")) {
00298 int auth;
00299 auth = author.find("(", 0, true);
00300 author = author.left( auth);
00301 }
00302 if ( author.contains("et al")) {
00303 int auth;
00304 auth = author.find("et al", 0, true);
00305 author = author.left( auth );
00306 }
00307 QRegExp r = QRegExp("[0-9]", true, false);
00308 if ( author.left(2).find( r) != -1 ) {
00309 author = "";
00310 }
00311
00312 author = author.stripWhiteSpace();
00313 if (authBox->isChecked() == TRUE) {
00314 QString lastName, firstName="";
00315 int finder = author.findRev( ' ', -1, TRUE);
00316 lastName = author.right( author.length()-finder);
00317 firstName = author.left(finder);
00318 lastName = lastName.stripWhiteSpace();
00319 firstName = firstName.stripWhiteSpace();
00320
00321 if( lastName.find( firstName, 0, true) == -1)
00322 author = lastName+", "+firstName;
00323 }
00324 return true;
00325 }
00326
00327 void LibraryDialog::addItems()
00328 {
00329 cleanStrings();
00330 getAuthor();
00331
00332 etext etextStruct;
00333 if(
00335 (title.find( "reserved",0, FALSE) == -1)
00336 && (file.find( "]",0, true) == -1)
00337 &&(title.find( "Audio",0, FALSE) == -1)) {
00338
00339
00340 etextStruct.title = title;
00341 etextStruct.author = author;
00342 etextStruct.year = year;
00343 etextStruct.file = file;
00344
00345 etextLibrary.append( etextStruct);
00346
00347 if( author.isEmpty() )
00348 QList_Item5 = new QListViewItem( ListView5, author, title, year, file );
00349 else {
00350 if( author.find(QRegExp("[^a-fA-F]")) )
00351 QList_Item1 = new QListViewItem( ListView1, author, title, year, file );
00352
00353 else if(author.find(QRegExp("[^g-mG-M]")) )
00354 QList_Item2 = new QListViewItem( ListView2, author, title,year, file );
00355
00356 else if(author.find(QRegExp("[^n-rN-R]")) )
00357 QList_Item3 = new QListViewItem( ListView3, author, title, year, file );
00358
00359 else if(author.find(QRegExp("[^s-zS-Z]")) )
00360 QList_Item4 = new QListViewItem( ListView4, author, title, year, file );
00361 }
00362 }
00363 }
00364
00365
00366
00367 void LibraryDialog::select_title( QListViewItem * item)
00368 {
00369 if(item != NULL) {
00370 i++;
00371 int index = tabWidget->currentPageIndex();
00372 DlglistItemTitle = item->text(0);
00373 DlglistItemYear = item->text(2);
00374 DlglistItemFile = item->text(3);
00375
00376 switch (index) {
00377 case 0: {
00378 ListView1->clearSelection();
00379 }
00380 break;
00381 case 1: {
00382 ListView2->clearSelection();
00383 }
00384 break;
00385 case 2: {
00386 ListView3->clearSelection();
00387 }
00388 break;
00389 case 3: {
00390 ListView4->clearSelection();
00391 }
00392 break;
00393 case 4: {
00394 ListView5->clearSelection();
00395 }
00396 break;
00397 };
00398 }
00399
00400 if(DlglistItemTitle.length() > 2) {
00401 item = 0;
00402
00403
00404 bool ok = false;
00405 qDebug(DlglistItemFile);
00406
00407 if( DlglistItemFile.toInt() > 10000 ) {
00408
00409 if( download_newEtext())
00410 ok = true;
00411 } else {
00412 if(download_Etext())
00413 ok = true;
00414 }
00415 if(ok) {
00416 if(checkBox->isChecked () )
00417 accept();
00418 }
00419 }
00420 }
00421
00422 bool LibraryDialog::download_newEtext()
00423 {
00424 QString fileName = DlglistItemFile;
00425
00426 QString directory;
00427 int stringlength = DlglistItemFile.length();
00428 for(i = 0; i < stringlength - 1; i++ ) {
00429 directory += "/"+ DlglistItemFile[i];
00430 }
00431
00432 directory += "/" + DlglistItemFile;
00433
00434
00435
00436 Config cfg("Gutenbrowser");
00437 cfg.setGroup("FTPsite");
00438 ftp_host = cfg.readEntry("SiteName", "sailor.gutenberg.org");
00439 ftp_base_dir = cfg.readEntry("base", "/pub/gutenberg");
00440
00441 if( ftp_base_dir.find("=",0,true) )
00442 ftp_base_dir.remove( ftp_base_dir.find("=",0,true),1);
00443
00444 QString dir = ftp_base_dir + directory;
00445 QString outputFile = local_library + ".guten_temp";
00446 QString file = fileName + ".txt";
00447
00448 QStringList networkList;
00449 networkList.append((const char *)ftp_host);
00450 networkList.append((const char *)dir);
00451 networkList.append((const char *)outputFile);
00452 networkList.append((const char *)file);
00453
00454 getEtext( networkList);
00455
00456 return true;
00457 }
00458
00459 bool LibraryDialog::getEtext(const QStringList &networkList)
00460 {
00461 NetworkDialog *NetworkDlg;
00462 NetworkDlg = new NetworkDialog( this,"Network Protocol Dialog", true, 0, networkList);
00463
00464
00465 if( NetworkDlg->exec() != 0 ) {
00466 File_Name = NetworkDlg->localFileName;
00467
00468 qDebug("Just downloaded " + NetworkDlg->localFileName);
00469
00470 if(NetworkDlg->successDownload) {
00471
00472 if(File_Name.right(4) == ".txt") {
00473 QString s_fileName = File_Name;
00474 s_fileName.replace( s_fileName.length() - 3, 3, "gtn");
00475
00476 rename( File_Name.latin1(), s_fileName.latin1());
00477 File_Name = s_fileName;
00478
00479
00480
00481 }
00482 if(File_Name.length() > 5 ) {
00483 setTitle();
00484 QFileInfo fi(File_Name);
00485 QString name_file = fi.fileName();
00486 name_file = name_file.left( name_file.length() - 4);
00487
00488
00489 DocLnk lnk;
00490
00491 lnk.setName(name_file);
00492
00493 lnk.setComment(DlglistItemTitle);
00494
00495
00496 lnk.setFile(File_Name);
00497 lnk.setType("guten/plain");
00498 lnk.setExec(File_Name);
00499 lnk.setIcon("gutenbrowser/Gutenbrowser");
00500 if(!lnk.writeLink()) {
00501
00502 } else {
00503 }
00504 } else
00505 QMessageBox::message("Note","<p>There was an error with the file</p>");
00506 }
00507 }
00508
00509 return true;
00510 }
00511
00512 bool LibraryDialog::download_Etext()
00513 {
00514
00515
00516 Config cfg("Gutenbrowser");
00517 cfg.setGroup("FTPsite");
00518 ftp_host = cfg.readEntry("SiteName", "sailor.gutenberg.org");
00519 ftp_base_dir = cfg.readEntry("base", "/pub/gutenberg");
00520
00521 qDebug( "about to network dialog");
00522
00523 QString NewlistItemNumber, NewlistItemYear, ls_result, result_line, s, dir, outputFile;
00524
00526 NewlistItemFile = DlglistItemFile.left(DlglistItemFile.find(".xxx", 1, false)).left(DlglistItemFile.left(DlglistItemFile.find(".xxx", 1, false)).find("x", 1, false));
00527
00528 if( NewlistItemFile.find( DlglistItemFile.left(4) ,0,true) ==-1 ) {
00529 NewlistItemFile.replace( 0,4, DlglistItemFile.left(4));
00530 qDebug("NewlistItemFile is now " + NewlistItemFile);
00531 }
00532
00533 NewlistItemYear = DlglistItemYear.right(2);
00534 int NewlistItemYear_Int = NewlistItemYear.toInt(0, 10);
00535
00536 if (NewlistItemYear_Int < 91 && NewlistItemYear_Int > 70) {
00537 NewlistItemYear = "90";
00538 }
00539
00540 Edir ="etext" +NewlistItemYear;
00541
00542 dir = ftp_base_dir + "/etext" + NewlistItemYear + "/";
00543
00544 if( ftp_base_dir.find("=",0,true) )
00545 ftp_base_dir.remove( ftp_base_dir.find("=",0,true),1);
00546
00547
00548
00549 outputFile = local_library+".guten_temp";
00550
00551 qDebug( "Download file: " +NewlistItemFile);
00552 qDebug("Checking: " + ftp_host + " " + dir + " " + outputFile+" " + NewlistItemFile);
00553
00554
00555 QStringList networkList;
00556 networkList.append((const char *)ftp_host);
00557 networkList.append((const char *)dir);
00558 networkList.append((const char *)outputFile);
00559 networkList.append((const char *)NewlistItemFile);
00560
00561 getEtext( networkList);
00562
00563 return true;
00564 }
00565
00566 bool LibraryDialog::httpDownload()
00567 {
00568 #ifndef Q_WS_QWS
00569 Config config("Gutenbrowser");
00570 config.setGroup( "Browser" );
00571 QString brow = config.readEntry("Preferred", "");
00572 QString file_name = "./.guten_temp";
00573
00574
00575 QString httpName = proxy_http + "/"+Edir;
00576
00577 i++;
00578 if ( brow != "Konq") {
00579
00580
00581 } else {
00582
00583 }
00584 i++;
00585 QFile tmp( file_name);
00586 QString str;
00587 if (tmp.open(IO_ReadOnly)) {
00588 QTextStream t( &tmp );
00589 while ( !t.eof()) {
00590 QString s = t.readLine();
00591 if (s.contains( NewlistItemFile, false) && (s.contains(".txt")) ) {
00592 str = s.mid( s.find( ".txt\">"+NewlistItemFile, 0, true)+6, (s.find( ".txt</A>", 0, true) + 4) - ( s.find( ".txt\">"+NewlistItemFile, 0, true)+6 ) );
00593 httpName += "/" + str;
00594 }
00595 }
00596 }
00597 tmp.close();
00598 m_getFilePath = local_library + str;
00599 i++;
00600 if ( brow != "KFM"){
00601 QString cmd = "lynx -source " + httpName +" | cat >> " + m_getFilePath;
00602
00603 system(cmd);
00604 } else {
00605
00606 }
00607 i++;
00608 #endif
00609 return false;
00610 }
00611
00612 void LibraryDialog::cancelIt()
00613 {
00614 saveConfig();
00615
00616 DlglistItemNumber = "";
00617 this->reject();
00618 }
00619
00620 bool LibraryDialog::setTitle()
00621 {
00622 Config config("Gutenbrowser");
00623
00624
00625
00626 if( DlglistItemTitle.find("[",0,true) != -1)
00627 DlglistItemTitle.replace(DlglistItemTitle.find("[",0,true),1, "(" );
00628 if( DlglistItemTitle.find("]",0,true) !=-1)
00629 DlglistItemTitle.replace(DlglistItemTitle.find("]",0,true),1, ")" );
00630
00631 int test = 0;
00632 QString ramble, temp;
00633 config.setGroup("Files");
00634 QString s_numofFiles = config.readEntry("NumberOfFiles", "0" );
00635 int i_numofFiles = s_numofFiles.toInt();
00636 for ( int i = 0; i <= i_numofFiles; i++){
00637 temp.setNum( i);
00638 ramble = config.readEntry( temp, "" );
00639 if( strcmp( ramble, File_Name) == 0){
00640 test = 1;
00641 }
00642 }
00643
00644 if(test == 0 ) {
00645
00646 config.setGroup("Files");
00647 config.writeEntry( "NumberOfFiles", i_numofFiles +1 );
00648 QString interger;
00649 interger.setNum( i_numofFiles +1);
00650 config.writeEntry( interger, File_Name);
00651 config.setGroup( "Titles" );
00652 config.writeEntry( File_Name, DlglistItemTitle);
00653 }
00654 test = 0;
00655 return true;
00656 }
00657
00658
00659 void LibraryDialog::saveConfig()
00660 {
00661 Config config("Gutenbrowser");
00662 if( httpBox->isChecked() == true) {
00663 checked = 1;
00664 config.setGroup( "Proxy" );
00665 config.writeEntry("IsChecked", "true");
00666 } else {
00667 checked = 0;
00668 config.setGroup( "Proxy" );
00669 config.writeEntry("IsChecked", "false");
00670 }
00671 if (authBox->isChecked() == true) {
00672 config.setGroup("SortAuth");
00673 config.writeEntry("authSort", "true");
00674 } else {
00675 config.setGroup("SortAuth");
00676 config.writeEntry("authSort", "false");
00677 }
00678
00679 }
00680
00681
00682
00683 void LibraryDialog::onButtonSearch()
00684 {
00685 ListView1->clearSelection();
00686 ListView2->clearSelection();
00687 ListView3->clearSelection();
00688 ListView4->clearSelection();
00689 ListView5->clearSelection();
00690
00691 int curTab = tabWidget->currentPageIndex();
00692 SearchDialog* searchDlg;
00693
00694
00695 searchDlg = new SearchDialog( this, "Library Search", true);
00696 searchDlg->setCaption( tr( "Library Search" ) );
00697 searchDlg->setLabel( "- author or title");
00698
00699 QString resultString;
00700
00701 int i_berger = 0;
00702 if( searchDlg->exec() != 0 ) {
00703 QString searcherStr = searchDlg->get_text();
00704 int fluff = 0;
00705
00706 bool cS;
00707 if( searchDlg->caseSensitiveCheckBox->isChecked())
00708 cS = true;
00709 else
00710 cS = false;
00711
00712 etext etextStruct;
00713 QValueList<etext>::Iterator it;
00714
00715 for( it = etextLibrary.begin(); it != etextLibrary.end(); ++it ) {
00716 QString tempTitle = (*it).title;
00717 QString tempAuthor = (*it).author;
00718 QString tempFile = (*it).file;
00719 QString tempYear = (*it).year;
00720 if(tempTitle.find( searcherStr, 0, cS) != -1
00721 || tempAuthor.find( searcherStr, 0, cS) != -1) {
00722 qWarning(tempTitle);
00723 Searchlist.append( tempTitle + " : " + tempYear + " : " + tempFile);
00724 }
00725 }
00726
00727
00728 tabWidget->setCurrentPage( curTab);
00729
00730 Searchlist.sort();
00731 SearchResultsDlg* SearchResultsDialog;
00732 SearchResultsDialog = new SearchResultsDlg( searchDlg, "Results Dialog", true, 0 , Searchlist);
00733
00734 SearchResultsDialog->showMaximized();
00735 if( SearchResultsDialog->exec() != 0) {
00736 texter = SearchResultsDialog->selText;
00737
00738 resultLs = SearchResultsDialog->resultsList;
00739 i_berger = 1;
00740 } else {
00741 resultLs.clear();
00742 }
00743 Searchlist.clear();
00744
00745 QString tester;
00746 for ( QStringList::Iterator it = resultLs.begin(); it != resultLs.end(); ++it ) {
00747 texter.sprintf("%s \n",(*it).latin1());
00748
00749 if( tester!=texter)
00750 parseSearchResults( texter);
00751 tester = texter;
00752 }
00753 if(searchDlg)
00754 delete searchDlg;
00755 }
00756 if(checkBox->isChecked() ) {
00757 accept();
00758 } else {
00759 setActiveWindow();
00760 }
00761 }
00762
00763
00764
00765 void LibraryDialog::parseSearchResults( QString resultStr)
00766 {
00767 int stringLeng = resultStr.length();
00768
00769 QString my;
00770 my.setNum( stringLeng, 10);
00771
00772 if( resultStr.length() > 2 && resultStr.length() < 130) {
00773 QStringList token = QStringList::split(" : ", resultStr);
00774
00775 DlglistItemTitle = token[0];
00776 DlglistItemTitle = DlglistItemTitle.stripWhiteSpace();
00777
00778 DlglistItemYear = token[1];
00779 DlglistItemYear = DlglistItemYear.stripWhiteSpace();
00780
00781 DlglistItemFile = token[2];
00782
00783 DlglistItemFile = DlglistItemFile.stripWhiteSpace();
00784
00785
00786
00787
00788 if(DlglistItemFile.left(1) == "/")
00789 DlglistItemFile = DlglistItemFile.right( DlglistItemFile.length() - 1);
00790
00791 if( DlglistItemFile.toInt() > 10000 || DlglistItemYear == "1980" ) {
00792
00793 download_newEtext();
00794 } else {
00795 download_Etext();
00796 }
00797 }
00798 }
00799
00800 void LibraryDialog::sortLists(int index)
00801 {
00802
00803 ListView1->setSorting(index);
00804 ListView2->setSorting(index);
00805 ListView3->setSorting(index);
00806 ListView4->setSorting(index);
00807 ListView5->setSorting(index);
00808 ListView1->sort();
00809 ListView2->sort();
00810 ListView3->sort();
00811 ListView4->sort();
00812 ListView5->sort();
00813 }
00814
00815
00816
00817 bool LibraryDialog::getItem(QListViewItem *it)
00818 {
00819
00820
00821
00822 DlglistItemTitle = it->text(0);
00823 DlglistItemYear = it->text(2);
00824 DlglistItemFile = it->text(3);
00825
00826 if(download_Etext()) {
00827 if(i_binary == 1) {
00828 }
00829 }
00830 return true;
00831 }
00832
00833
00834
00835 bool LibraryDialog::onButtonDownload()
00836 {
00837
00838
00839 QListViewItemIterator it1( ListView1 );
00840 QListViewItemIterator it2( ListView2 );
00841 QListViewItemIterator it3( ListView3 );
00842 QListViewItemIterator it4( ListView4 );
00843 QListViewItemIterator it5( ListView5 );
00844
00845
00846 for ( ; it1.current(); ++it1 ) {
00847 if ( it1.current()->isSelected() )
00848 getItem(it1.current());
00849 it1.current()->setSelected(false);
00850 }
00851 for ( ; it2.current(); ++it2 ) {
00852 if ( it2.current()->isSelected() )
00853 getItem(it2.current());
00854 it2.current()->setSelected(false);
00855 }
00856 for ( ; it3.current(); ++it3 ) {
00857 if ( it3.current()->isSelected() )
00858 getItem(it3.current());
00859 it3.current()->setSelected(false);
00860 }
00861 for ( ; it4.current(); ++it4 ) {
00862 if ( it4.current()->isSelected() )
00863 getItem(it4.current());
00864 it4.current()->setSelected(false);
00865 }
00866 for ( ; it5.current(); ++it5 ) {
00867 if ( it5.current()->isSelected() )
00868 getItem(it5.current());
00869 it5.current()->setSelected(false);
00870 }
00871 return true;
00872 }
00873
00874
00875
00876
00877 void LibraryDialog::comboSelect(int index)
00878 {
00879
00880 ListView1->setSorting( index, true);
00881 ListView2->setSorting( index, true);
00882 ListView3->setSorting( index, true);
00883 ListView4->setSorting( index, true);
00884 ListView5->setSorting( index, true);
00885
00886 ListView1->sort();
00887 ListView2->sort();
00888 ListView3->sort();
00889 ListView4->sort();
00890 ListView5->sort();
00891
00892
00893
00894
00895
00896
00897 }
00898
00899 void LibraryDialog::newList()
00900 {
00901 if(indexLoaded) {
00902 onButtonDownload();
00903 } else {
00904 Output *outDlg;
00905 buttonNewList->setDown(true);
00906
00907 QString gutenindex1 = local_library + "/GUTINDEX.ALL";
00908
00909 QString cmd="wget -O " + gutenindex1 + " http://www.gutenberg.org/dirs/GUTINDEX.ALL 2>&1";
00910
00911 int result = QMessageBox::warning( this,"Download"
00912 ,"<p>Ok to use /'wget/' to download a new library list?</P>"
00913 ,"Yes","No",0,0,1);
00914 qApp->processEvents();
00915 if(result == 0) {
00916 outDlg = new Output( 0, tr("Downloading Gutenberg Index...."),true);
00917 outDlg->showMaximized();
00918 outDlg->show();
00919 qApp->processEvents();
00920 FILE *fp;
00921 char line[130];
00922 outDlg->OutputEdit->append( tr("Running wget") );
00923 outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,false);
00924 sleep(1);
00925 fp = popen( (const char *) cmd, "r");
00926 if ( !fp ) {
00927 } else {
00928
00929
00930 while ( fgets( line, sizeof line, fp)) {
00931 outDlg->OutputEdit->append(line);
00932 outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,false);
00933 }
00934 pclose(fp);
00935 outDlg->OutputEdit->append("Finished downloading\n");
00936 outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,false);
00937 qApp->processEvents();
00938
00939
00940
00941
00942
00943
00944
00945 }
00946
00947 FindLibrary();
00948 if(outDlg) delete outDlg;
00949 }
00950 buttonNewList->setDown(false);
00951
00952
00953
00954 }
00955 }
00956
00957 bool LibraryDialog::moreInfo()
00958 {
00959
00960 QListViewItem * item;
00961 item = 0;
00962 QString titleString;
00963 item = ListView1->currentItem();
00964 if( item != 0) {
00965 titleString = item->text(0);
00966 ListView1->clearSelection();
00967 item = 0;
00968 }
00969 if( item == 0)
00970 item = ListView2->currentItem();
00971 if( item != 0) {
00972 titleString = item->text(0);
00973 ListView2->clearSelection();
00974 item = 0;
00975 }
00976 if( item == 0)
00977 item = ListView3->currentItem();
00978 if( item != 0) {
00979 titleString = item->text(0);
00980 ListView3->clearSelection();
00981 item = 0;
00982 }
00983 if( item == 0)
00984 item = ListView4->currentItem();
00985 if( item != 0) {
00986 titleString = item->text(0);
00987 ListView4->clearSelection();
00988 item = 0;
00989 }
00990 if( item == 0)
00991 item = ListView5->currentItem();
00992 if( item != 0) {
00993 titleString = item->text(0);
00994 ListView5->clearSelection();
00995 item = 0;
00996 }
00997 item=0;
00998 if(titleString.length()>2) {
00999
01000 titleString.replace( QRegExp("\\s"), "%20");
01001 titleString.replace( QRegExp("'"), "%20");
01002 titleString.replace( QRegExp("\""), "%20");
01003 titleString.replace( QRegExp("&"), "%20");
01004 QString cmd= "http://google.com/search?q="+titleString+"&num=30&sa=Google+Search";
01005 cmd="opera "+cmd;
01006 system(cmd);
01007 } else
01008 QMessageBox::message( "Note","<p>If you select a title, this will search google.com for that title.</p>");
01009 return true;
01010
01011 }
01012
01013
01014
01015 void LibraryDialog::FindLibrary()
01016 {
01017 buttonLibrary->setDown(true);
01018
01019 qApp->processEvents();
01020 if( QFile( new_index).exists() ) {
01021 newindexLib.setName( new_index);
01022 indexLib.setName( new_index);
01023
01024 Newlibrary();
01025 } else {
01026 newindexLib.setName( old_index);
01027 indexLib.setName( old_index);
01028
01029 Library();
01030 }
01031 indexLoaded =true;
01032 buttonSearch->setEnabled(true);
01033 moreInfoButton->setEnabled(true);
01034
01035 buttonLibrary->setDown(false);
01036 buttonNewList->setText("Download");
01037 qApp->processEvents();
01038
01039 }
01040
01041 void LibraryDialog::cleanStrings() {
01042 year = year.stripWhiteSpace();
01043 file = file.stripWhiteSpace();
01044 title = title.stripWhiteSpace();
01045 number = number.stripWhiteSpace();
01046
01047 }
01048
01049 void LibraryDialog::authBoxClicked()
01050 {
01051 qApp->processEvents();
01052 FindLibrary();
01053 }