00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "editTitle.h"
00020 #include "gutenbrowser.h"
00021 #include "LibraryDialog.h"
00022
00023 #include "optionsDialog.h"
00024 #include "helpme.h"
00025 #include "NetworkDialog.h"
00026
00027 #include "openetext.h"
00028 #include "output.h"
00029
00030
00031 #include <opie2/odebug.h>
00032 #include <opie2/oresource.h>
00033
00034 #include <qpe/qpeapplication.h>
00035 #include <qpe/fontdatabase.h>
00036 #include <qpe/config.h>
00037 #include <qpe/qcopenvelope_qws.h>
00038 #include <qpe/mimetype.h>
00039 #include <qpe/applnk.h>
00040
00041
00042 #include <qregexp.h>
00043 #include <qregion.h>
00044 #include <qpaintdevicemetrics.h>
00045 #include <qvaluelist.h>
00046 #include <qlabel.h>
00047 #include <qclipboard.h>
00048 #include <qpainter.h>
00049 #include <qpalette.h>
00050 #include <qobjectlist.h>
00051 #include <qfontdialog.h>
00052 #include <qtextview.h>
00053 #include <qbrush.h>
00054 #include <qfile.h>
00055 #include <qfontinfo.h>
00056 #include <qscrollview.h>
00057 #include <qpoint.h>
00058
00059
00060 #include <stdio.h>
00061 #include <stdlib.h>
00062 #include <unistd.h>
00063 #include <sys/stat.h>
00064 #include <fcntl.h>
00065 #include <errno.h>
00066
00067 static const int nfontsizes = 9;
00068 static const int fontsize[nfontsizes] = {8,9,10,11,12,13,14,18,24};
00069
00070 #ifdef NOQUICKLAUNCH
00071 Gutenbrowser::Gutenbrowser()
00072 Gutenbrowser();
00073 #else
00074 Gutenbrowser::Gutenbrowser(QWidget *,const char*, WFlags )
00075 #endif
00076 : QMainWindow()
00077 {
00078
00079
00080
00081
00082 showMainList=TRUE;
00083 working=false;
00084 this->setUpdatesEnabled(TRUE);
00085
00086 QString msg;
00087 msg="You have now entered unto gutenbrowser,\n";
00088 msg+="make your self at home, sit back, relax and read something great.\n";
00089
00090 local_library = (QDir::homeDirPath ()) +"/Applications/gutenbrowser/";
00091 setCaption("Gutenbrowser");
00092 this->setUpdatesEnabled(TRUE);
00093
00094
00095 topLayout = new QVBoxLayout( this, 0, 0, "topLayout");
00096
00097 menu = new QHBoxLayout(-1,"menu");
00098 buttons2 = new QHBoxLayout(-1,"buttons2");
00099 edits = new QHBoxLayout(-1,"edits");
00100
00101 useSplitter=TRUE;
00102
00103 initConfig();
00104 initMenuBar();
00105 initButtonBar();
00106 initStatusBar();
00107 initView();
00108 initSlots();
00109 qDebug("init finished");
00110 QPEApplication::setStylusOperation( mainList->viewport(),QPEApplication::RightOnHold);
00111
00112 connect( mainList, SIGNAL( mouseButtonPressed( int, QListBoxItem *, const QPoint &)),
00113 this, SLOT( mainListPressed(int, QListBoxItem *, const QPoint &)) );
00114 if( useIcons)
00115 toggleButtonIcons( TRUE);
00116 else
00117 toggleButtonIcons( FALSE);
00118
00119 enableButtons(false);
00120
00121 Config config("Gutenbrowser");
00122 config.setGroup("General");
00123
00124 config.setGroup( "Files" );
00125 QString s_numofFiles = config.readEntry("NumberOfFiles", "0" );
00126 int i_numofFiles = s_numofFiles.toInt();
00127
00128 QString tempFileName;
00129
00130 for (int i = 0; i <= i_numofFiles; i++) {
00131
00132 config.setGroup( "Files" );
00133 QString ramble = config.readEntry( QString::number(i), "" );
00134
00135 config.setGroup( "Titles" );
00136 QString tempTitle = config.readEntry( ramble, "");
00137 config.setGroup( tempTitle);
00138 int index = config.readNumEntry( "LineNumber", -1 );
00139 if( index != -1) {
00140 odebug << tempTitle << oendl;
00141 if(!tempTitle.isEmpty()) bookmarksMenu->insertItem( tempTitle);
00142 }
00143 }
00144
00145 QString gutenIndex = local_library + "/GUTINDEX.ALL";
00146 qDebug("gutenindex "+gutenIndex );
00147
00148 if( QFile( gutenIndex).exists() ) {
00149 indexLib.setName( gutenIndex);
00150 } else {
00151 QString localLibIndexFile = local_library + "/PGWHOLE.TXT";
00152
00153 newindexLib.setName( localLibIndexFile);
00154 }
00155 qDebug("attempting new library");
00156 LibraryDlg = new LibraryDialog( this, "Library Index" );
00157 loadCheck = false;
00158 chdir(local_library);
00159 if(!showMainList) {
00160 Lview->setFocus();
00161
00162
00163 for (int i=1;i< qApp->argc();i++) {
00164 qDebug("Suppose we open somethin");
00165 if(!load(qApp->argv()[i])) return;
00166 }
00167 } else {
00168 fillWithTitles();
00169 mainList->setFocus();
00170
00171
00172 }
00173 writeConfig();
00174 QTimer::singleShot( 250, this, SLOT(hideView()) );
00175 }
00176
00177 Gutenbrowser::~Gutenbrowser() {
00178
00179
00180 odebug << "Exit" << oendl;
00181 }
00182
00183
00184
00185 void Gutenbrowser::InfoBarClick() {
00186 QString text;
00187 if( Lview->hasSelectedText()) {
00188 Lview->copy();
00189 QClipboard *cb = QApplication::clipboard();
00190 text = cb->text();
00191 } else {
00192
00193 text=this->caption();
00194 }
00195 searchGoogle(text);
00196 }
00197
00198
00199
00200 void Gutenbrowser::goGetit( const QString &url, bool showMsg) {
00201 QString cmd;
00202 qApp->processEvents();
00203
00204 QString filename = local_library + "/GUTINDEX.ALL";
00205
00206
00207
00208
00209 Config cfg("Gutenbrowser");
00210 cfg.setGroup("FTPsite");
00211 ftp_host=cfg.readEntry("SiteName", "sailor.gutenberg.org");
00212 ftp_base_dir= cfg.readEntry("base", "/pub/gutenberg");
00213
00214
00215
00216
00217
00218 if(!showMsg) {
00219
00220 cmd="wget -O " + filename +" " + url+" 2>&1" ;
00221 chdir(local_library);
00222
00223
00224 Output *outDlg;
00225
00226 outDlg = new Output( 0, tr("Downloading Gutenberg Index...."),TRUE);
00227
00228 outDlg->showMaximized();
00229 outDlg->show();
00230 qApp->processEvents();
00231 FILE *fp;
00232 char line[130];
00233 outDlg->OutputEdit->append( tr("Running wget") );
00234 outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE);
00235 sleep(1);
00236 fp = popen( (const char *) cmd, "r");
00237 if ( !fp ) {
00238 } else {
00239
00240
00241 while ( fgets( line, sizeof line, fp)) {
00242 outDlg->OutputEdit->append(line);
00243 outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE);
00244 }
00245 pclose(fp);
00246 outDlg->OutputEdit->append("Finished downloading\n");
00247 outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE);
00248 qApp->processEvents();
00249
00250 }
00251 outDlg->close();
00252
00253 if(outDlg)
00254 delete outDlg;
00255 } else {
00256 if( brow == "Konq") {
00257 cmd = "konqueror "+url+" &";
00258 }
00259 if( brow == "Opera") {
00260 cmd = "opera "+url+" &";
00261 }
00262
00263
00264
00265 if( brow == "Mozilla") {
00266 cmd = "mozilla "+url+" &";
00267 }
00268 if( brow == "Netscape") {
00269 cmd = "netscape "+url+" &";
00270 }
00271 if(brow == "wget") {
00272
00273 QString tempHtml=local_library+"webster.html";
00274 cmd="wget -O "+tempHtml+" -q "+url;
00275 }
00276
00277 chdir(local_library);
00278
00279 system(cmd);
00280 }
00281 }
00282
00283 void Gutenbrowser::toggleButtonIcons( bool useEm) {
00284 QString pixDir;
00285 if(useEm)
00286 useEm=TRUE;
00287 pixDir=QPEApplication::qpeDir()+"pics/gutenbrowser";
00288 odebug << "Docdir is "+QPEApplication::documentDir() << oendl;
00289
00290 if( useIcons && QDir( pixDir).exists() ) {
00291 LibraryButton->setPixmap( Opie::Core::OResource::loadPixmap("home", Opie::Core::OResource::SmallIcon ) );
00292 OpenButton->setPixmap( Opie::Core::OResource::loadPixmap("gutenbrowser/openbook", Opie::Core::OResource::SmallIcon ));
00293 ForwardButton->setPixmap( Opie::Core::OResource::loadPixmap("forward", Opie::Core::OResource::SmallIcon ));
00294 BackButton->setPixmap( Opie::Core::OResource::loadPixmap("back", Opie::Core::OResource::SmallIcon ) );
00295 SearchButton->setPixmap( Opie::Core::OResource::loadPixmap("gutenbrowser/search", Opie::Core::OResource::SmallIcon ) );
00296 lastBmkButton->setPixmap( Opie::Core::OResource::loadPixmap("gutenbrowser/bookmark_folder", Opie::Core::OResource::SmallIcon ));
00297 setBookmarkButton->setPixmap( Opie::Core::OResource::loadPixmap("gutenbrowser/bookmark", Opie::Core::OResource::SmallIcon ) );
00298 dictionaryButton->setPixmap( Opie::Core::OResource::loadPixmap("gutenbrowser/spellcheck", Opie::Core::OResource::SmallIcon ) );
00299 InfoBar->setPixmap( Opie::Core::OResource::loadPixmap("gutenbrowser/google", Opie::Core::OResource::SmallIcon ));
00300 }
00301 }
00302
00303
00304 bool Gutenbrowser::queryExit()
00305 {
00306 int exit=QMessageBox::information(this, "Quit...", "Do your really want to quit?",
00307 QMessageBox::Ok, QMessageBox::Cancel);
00308 if (exit==1) {
00309 writeConfig();
00310 qApp->quit();
00311 } else {
00312 };
00313 return (exit==1);
00314 }
00315
00316
00317
00318 void Gutenbrowser::slotFilePrint() {
00319 }
00320
00321 void Gutenbrowser::ByeBye() {
00322 if (b_queryExit)
00323 queryExit();
00324 else {
00325
00326 qApp->quit();
00327 }
00328 }
00329
00330 void Gutenbrowser::HelpBtn() {
00331 HelpMe* HelpDlg;
00332 HelpDlg = new HelpMe( this, "Help Dialog");
00333 HelpDlg->showMaximized();
00334 }
00335
00336 void Gutenbrowser::DownloadIndex() {
00337 #ifndef Q_WS_QWS
00338 {
00339 switch( QMessageBox::information( 0, (tr("Download Library Index, or FTP sites?")),
00340 (tr("Do you want to download the newest\n"
00341 "Project Gutenberg Library Index?\n"
00342 "or select an ftp site?\n")),
00343 (tr("&Library Index")), (tr("&Ftp Site")), (tr("&Cancel")), 2, 2 ) )
00344 {
00345 case 0:
00346 downloadLibIndex();
00347 break;
00348
00349 case 1:
00350 downloadFtpList();
00351 break;
00352
00353 case 2:
00354 break;
00355 };
00356 }
00357 #endif
00358 }
00359
00360
00361 void Gutenbrowser::downloadFtpList() {
00362
00363
00364 qApp->processEvents();
00365 optionsDialog* optDlg;
00366 optDlg = new optionsDialog( this,"Options_Dlg", true);
00367 optDlg->getSite();
00368 if(optDlg)
00369 delete optDlg;
00370 }
00371
00372
00373 void Gutenbrowser::downloadLibIndex() {
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383 QDir dir( local_library);
00384 dir.cd("", TRUE);
00385 goGetit( "http://www.gutenberg.org/dirs/GUTINDEX.ALL", false);
00386
00387
00388
00389
00390
00392
00393
00394
00395 }
00396
00397
00398 void Gutenbrowser::PrintBtn() {
00399 }
00400
00401 void Gutenbrowser::SearchBtn() {
00402 if( loadCheck) {
00403 odebug << "loadCheck: we have a loaded doc" << oendl;
00404 Search();
00405 }
00406
00407
00408 }
00409
00410
00411 void Gutenbrowser::ForwardBtn() {
00412
00413 if( !ForwardButton->autoRepeat() && !ForwardButton->isDown()) {
00414
00415 QString s;
00416 QString insertString;
00417 int pageSize= Lview->PageSize();
00418 Lview->clear();
00419
00420 for(int fd=0; fd < pageSize - 1;fd++) {
00421 f.readLine(s, 256);
00422 if(useWrap)
00423 s.replace(QRegExp("\n"),"");
00424 insertString+=s;
00425 Lview->insertLine( s, -1);
00426
00427 currentLine++;
00428 }
00429
00430 currentFilePos = f.at();
00431
00432
00433 i_pageNum++;
00434 pageStopArray.resize(i_pageNum + 1);
00435
00436
00437 pageStopArray[i_pageNum ] = currentFilePos;
00438 odebug << currentFilePos << " current page is number " << i_pageNum
00439 << ", pagesize " << pageSize << ", length " << Lview->length()
00440 << ", current " << pageStopArray[i_pageNum] << oendl;
00441 setStatus();
00442
00443
00444
00445 } else {
00446 odebug << "bal" << oendl;
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458 }
00459 Lview->setFocus();
00460
00461 odebug << "page number " << i_pageNum << " line number " << currentLine << "" << oendl;
00462 }
00463
00464
00465 void Gutenbrowser::BackBtn() {
00466 if( i_pageNum > 0) {
00467 int pageSize= Lview->PageSize();
00468
00469
00470 i_pageNum--;
00471 currentFilePos = f.at();
00472
00473 odebug << currentFilePos << " move back to " << pageStopArray[i_pageNum - 1 ]
00474 << ", current page number " << i_pageNum
00475 << ", " << pageSize << ", length " << Lview->length() << oendl;
00476
00477 if( i_pageNum < 2) {
00478 f.at( 0);
00479 } else {
00480 if(!f.at( pageStopArray[i_pageNum - 1] ))
00481 odebug << "File positioned backward did not work" << oendl;
00482 }
00483 QString s;
00484
00485 Lview->clear();
00486
00487
00488 for(int fd = 0; fd < pageSize ;fd++) {
00489
00490 f.readLine(s, 256);
00491 if(useWrap)
00492 s.replace(QRegExp("\n"),"");
00493 currentLine++;
00494
00495 Lview->insertLine( s, -1);
00496 }
00497
00498
00499
00500 if( !BackButton->autoRepeat() && !BackButton->isDown()) {
00501 QString topR;
00502 QString lastR;
00503 QString pageR;
00504
00505
00506 if( i_pageNum < 1)
00507 i_pageNum = 1;
00508 setCaption(QString::number(i_pageNum));
00509 } else {
00510
00511
00512 Lview->MultiLine_Ex::pageUp( FALSE);
00513
00514
00515 if( i_pageNum < 1)
00516 i_pageNum = 1;
00517 setStatus();
00518
00519
00520 }
00521 }
00522 Lview->setFocus();
00523 }
00524
00525 void Gutenbrowser::doBeginBtn() {
00526 if(loadCheck) {
00527 qApp->processEvents();
00528 BeginBtn();
00529 }
00530 }
00531
00532
00533 void Gutenbrowser::TopBtn() {
00534
00535 if(loadCheck) {
00536 if( i_pageNum != 0) {
00537 odebug << "top" << oendl;
00538 qApp->processEvents();
00539 currentLine = 0;
00540 i_pageNum = 1;
00541 int pageSize = Lview->PageSize() ;
00542 Lview->clear();
00543 QString s;
00544 f.at(0);
00545 for(int fd=0; fd < pageSize ;fd++) {
00546 f.readLine(s, 256);
00547 if(useWrap)
00548 s.replace(QRegExp("\n"),"");
00549 Lview->insertLine(s ,-1);
00550 currentLine++;
00551 }
00552
00553 i_pageNum=1;
00554 setStatus();
00555 }
00556 Lview->setFocus();
00557 }
00558 }
00559
00560
00561 void Gutenbrowser::BeginBtn() {
00562 i_pageNum = 1;
00563 currentLine = 0;
00564 QString s_pattern="*END*THE SMALL PRINT";
00565 QString sPattern2 = "*END THE SMALL PRINT";
00566
00567 int pageSize = Lview->PageSize();
00568 Lview->clear();
00569
00570
00571 int pos = 0;
00572 int i_topRow = Lview->topRow();
00573
00574 QString LeftText;
00575
00576
00577
00578
00579 i_pageNum = 1;
00580 int lastPage=1;
00581 int lineNo=0;
00582 QString s;
00583 f.at( 0);
00584
00585 while ( !f.atEnd() ) {
00586 f.readLine(s, 256);
00587 lineNo++;
00588 LeftText = s;
00589 currentFilePos = f.at();
00590
00591 i_pageNum = lineNo/pageSize;
00592 if(lastPage < i_pageNum) {
00593 pageStopArray.resize(i_pageNum + 1);
00594 pageStopArray[i_pageNum ] = currentFilePos;
00595
00596 }
00597
00598 if( LeftText.find( s_pattern, 0 , TRUE) != -1 || LeftText.find( sPattern2, 0 , TRUE) != -1 ) {
00599 odebug << "<<<<<< FOUND IT!! new page number " << i_pageNum << ", found at " << currentFilePos << "" << oendl;
00600 break;
00601 }
00602 }
00603 if(f.atEnd())
00604 f.at(0);
00605 Lview->clear();
00606 for(int fd=0; fd < pageSize - 1;fd++) {
00607 f.readLine(s, 256);
00608 if(useWrap)
00609 s.replace(QRegExp("\n"),"");
00610 Lview->insertLine( s, -1);
00611 currentLine++;
00612 }
00613
00614 i_pageNum = lineNo/pageSize;
00615 pageStopArray.resize(i_pageNum + 1);
00616
00617
00618 qApp->processEvents();
00619
00620 if( pos > i_topRow ) {
00621
00622 } else {
00623
00624 }
00625
00626 Lview->deselect();
00627
00628 Lview->setFocus();
00629 }
00630
00631
00632
00633 void Gutenbrowser::setBookmark() {
00634 int eexit=QMessageBox::information(this, "Note",
00635 "Do you really want to \nset this bookmark?."
00636 ,QMessageBox::Yes, QMessageBox::No);
00637 if (eexit== 3) {
00638
00639 currentFilePos = f.at();
00640
00641 Config cfg("Gutenbrowser");
00642 cfg.setGroup("General");
00643 file_name = cfg.readEntry("Current","");
00644 qApp->processEvents();
00645 odebug << "Setting book mark "+file_name << oendl;
00646
00647 cfg.setGroup("Titles");
00648 title = cfg.readEntry(file_name,"");
00649 odebug << "title is "+ title << oendl;
00650
00651 cfg.setGroup( "Bookmarks" );
00652
00653 cfg.writeEntry("File Name",file_name);
00654 cfg.writeEntry("Page Number",QString::number(i_pageNum) );
00655 cfg.writeEntry( "PagePosition", QString::number( pageStopArray[i_pageNum - 1]));
00656 cfg.writeEntry("Title", title);
00657
00658 int row = Lview->topRow();
00659 cfg.writeEntry("LineNumber",QString::number(row) );
00660
00661 cfg.setGroup(title);
00662 cfg.writeEntry("File Name",file_name);
00663 cfg.writeEntry( "LineNumber", QString::number( row));
00664 cfg.writeEntry( "PagePosition", QString::number( pageStopArray[i_pageNum - 1]));
00665 cfg.writeEntry( "Page Number", QString::number( i_pageNum) );
00666 cfg.write();
00667 bookmarksMenu->insertItem( title);
00668 }
00669 }
00670
00671
00672
00673 void Gutenbrowser::Bookmark( int itemId) {
00674
00675
00676 Config config("Gutenbrowser");
00677 config.setGroup( "Bookmarks" );
00678
00679 odebug << "<<<<<< " << Lview->PageSize() << ", " << Lview->lastRow() - Lview->topRow() << "" << oendl;
00680
00681 QString itemString;
00682
00683 odebug << "menu item " << itemId << "" << oendl;
00684 QString tempTitle;
00685 QString s_Bmrkrow;
00686 QString s_pageNum;
00687 int Bmrkrow=0;
00688 int bookmarkPosition = 0;
00689
00690
00691 config.setGroup( "Bookmarks" );
00692 title = config.readEntry("Title", "");
00693 file_name = config.readEntry("File Name", "");
00694 i_pageNum = config.readNumEntry("Page Number", 0);
00695 bookmarkPosition = config.readNumEntry( "PagePosition",0);
00696 Bmrkrow = config.readNumEntry("LineNumber",0);
00697 if( !file_name.contains("/")) {
00698 file_name = local_library + file_name;
00699 }
00700
00701
00702
00703
00704 this->setFocus();
00705
00706 Lview->clear();
00707
00708 if(!load(file_name)) return;
00709
00710 int pageSize = Lview->PageSize();
00711 f.at(0);
00712
00713 QString s;
00714 int lineNo=0;
00715 int lastPage=1;
00716 while ( !f.atEnd() ) {
00717 f.readLine(s, 256);
00718 lineNo++;
00719 currentFilePos = f.at();
00720
00721 i_pageNum = lineNo/pageSize;
00722 if(lastPage < i_pageNum) {
00723 pageStopArray.resize(i_pageNum + 1);
00724 pageStopArray[i_pageNum ] = currentFilePos;
00725
00726 }
00727 if(currentFilePos == bookmarkPosition)
00728 break;
00729 }
00730 if(f.atEnd())
00731 f.at(0);
00732 else
00733 f.at( bookmarkPosition);
00734
00735 for(int fd=0; fd < pageSize - 1;fd++) {
00736 f.readLine(s, 256);
00737 lineNo++;
00738 if(useWrap)
00739 s.replace(QRegExp("\n"),"");
00740 Lview->insertLine( s, -1);
00741 currentLine++;
00742 }
00743
00744 i_pageNum = lineNo/pageSize;
00745 pageStopArray.resize(i_pageNum + 1);
00746
00747 if(showMainList) {
00748 showMainList=FALSE;
00749 mainList->hide();
00750 Lview->show();
00751
00752 }
00753
00754 odebug << "bookmark loaded" << oendl;
00755 setCaption(title);
00756 }
00757
00758
00759 bool Gutenbrowser::load( const char *fileName) {
00760
00761
00762 odebug << "Title is already set as "+title << oendl;
00763 odebug << "sizeHint " << sizeHint().height() << " pageSize " << Lview->PageSize() << "" << oendl;
00764
00765
00766 if( Lview->PageSize() < 4) {
00767
00768
00769 Lview->setMinimumHeight( sizeHint().height() );
00770 pointSize = Lview->fontInfo().pointSize();
00771 odebug << "sizeHint " << sizeHint().height() << " point size " << pointSize << "" << oendl;
00772 if(pointSize < 15)
00773 Lview->setFixedVisibleLines(19);
00774 else
00775 Lview->setFixedVisibleLines( ( (sizeHint().height() / pointSize ) * 2) -2);
00776 }
00777
00778 Config cfg("Gutenbrowser");
00779 cfg.setGroup("General");
00780 cfg.writeEntry("Current",fileName);
00781 cfg.write();
00782 currentLine=0;
00783
00784 file_name=fileName;
00785 QString o_file = fileName;
00786
00787
00788 i_pageNum = 1;
00789
00790 odebug << "ready to open "+o_file << oendl;
00791
00792 if(f.isOpen()) f.close();
00793 f.setName( o_file);
00794
00795 if ( !f.open( IO_ReadOnly)) {
00796 QMessageBox::message( (tr("Note")), (tr("File not opened sucessfully.\n" +o_file)) );
00797 return false;
00798 }
00799 currentFilePos = 0;
00800 pageStopArray.resize(3);
00801 pageStopArray[0] = currentFilePos;
00802
00803 fileHandle = f.handle();
00804 QString insertString;
00805 QTextStream t(&f);
00806 QString s;
00807 for(int fd=0; fd < Lview->PageSize() ;fd++) {
00808 s=t.readLine();
00809
00810 if(useWrap)
00811 s.replace(QRegExp("\n"),"");
00812
00813 Lview->insertLine( s,-1);
00814 currentLine++;
00815 }
00816
00817
00818 currentFilePos = f.at();
00819
00820 pageStopArray[1] = currentFilePos;
00821
00822 odebug << "<<<<<<<<<<<" << currentFilePos << " current page is number " << i_pageNum
00823 << ", length " << Lview->length() << ", current " << pageStopArray[i_pageNum]
00824 << ", pageSize " << Lview->PageSize() << oendl;
00825
00826 Lview->setMaxLines(Lview->PageSize()*2);
00827
00828 setCaption(title);
00829 Lview->setAutoUpdate( TRUE);
00830
00831
00832
00833
00834
00835
00836 loadCheck = true;
00837 enableButtons(true);
00838 if( donateMenu->count() == 3) {
00839 donateMenu->insertItem("Current Title", this, SLOT( InfoBarClick() ));
00840 }
00841 Lview->setFocus();
00842
00843
00844 return true;
00845 }
00846
00847 void Gutenbrowser::Search() {
00848
00849
00850 {
00851 odebug << "Starting search dialog" << oendl;
00852 searchDlg = new SearchDialog( this, "Etext Search", true);
00853 searchDlg->setCaption( tr( "Etext Search" ));
00854
00855 connect( searchDlg,SIGNAL( search_signal()),this,SLOT( search_slot()));
00856 connect( searchDlg,SIGNAL( search_done_signal()),this,SLOT( searchdone_slot()));
00857
00858 QString resultString;
00859 QString string = searchDlg->searchString;
00860 Lview->deselect();
00861 searchDlg->show();
00862 searchDlg->result();
00863 }
00864 }
00865
00866 void Gutenbrowser::search_slot( ) {
00867 int line, col;
00868 if (!searchDlg )
00869 return;
00870
00871 Lview->getCursorPosition(&line,&col);
00872 QString to_find_string=searchDlg->get_text();
00873
00874
00875 if ( last_search != 0 && searchDlg->get_direction() ){
00876 col = col - pattern.length() - 1 ;
00877 }
00878 again:
00879 int result = doSearch( to_find_string , TRUE, searchDlg->forward_search(), line, col);
00880 if(result == 0){
00881 if(!searchDlg->get_direction()){
00882 int query = QMessageBox::information( searchDlg, "Find",
00883 "End of document reached.\nContinue from the beginning?",
00884 "Yes", "No", "", 0,1);
00885 if (query == 0){
00886 line = 0;
00887 col = 0;
00888 goto again;
00889 }
00890 } else {
00891 int query = QMessageBox::information( searchDlg, "Find",
00892 "End of document reached.\nContinue from the beginning?",
00893 "Yes", "No", "", 0,1);
00894 if (query == 0){
00895 QString string = Lview->textLine( Lview->numLines() - 1 );
00896 line = Lview->numLines() - 1;
00897 lineCheck = line;
00898 col = string.length();
00899 last_search = -1;
00900 goto again;
00901 }
00902 }
00903 } else {
00904
00906 }
00907 }
00908
00909 int Gutenbrowser::doSearch( const QString &s_pattern , bool case_sensitive, bool forward, int line, int col ) {
00910 int i, length;
00911 int pos = -1;
00912 if(forward) {
00913 QString string;
00914 for(i = line; i < Lview->numLines(); i++) {
00915
00916 string = Lview->textLine(i);
00917 pos = string.find(s_pattern, i == line ? col : 0, case_sensitive);
00918 if( pos != -1) {
00919 int top = Lview->Top();
00920 length = s_pattern.length();
00921 if( i > Lview->lastRow() ) {
00922
00923 for(int l = 0 ; l < length; l++) {
00924 Lview->cursorRight(TRUE);
00925 }
00926
00927 int newTop = Lview->Top();
00928 if(Lview->lastRow() > i)
00929 Lview->ScrollUp( newTop - top);
00930
00931 } else {
00932
00933 for(int l = 0 ; l < length; l++) {
00934 Lview->cursorRight(TRUE);
00935 }
00936
00937
00938 }
00939 pattern = s_pattern;
00940 last_search = 1;
00941 return 1;
00942 }
00943 }
00944 } else {
00945 QString string;
00946 for( i = line; i >= 0; i--) {
00947 string = Lview->textLine(i);
00948 int line_length = string.length();
00949 pos = string.findRev(s_pattern, line == i ? col : line_length , case_sensitive);
00950 if (pos != -1) {
00951
00952 length = s_pattern.length();
00953 if( i < Lview->Top() ) {
00954 Lview->ScrollDown( Lview->PageSize() );
00955 Lview->MultiLine_Ex::pageUp( FALSE );
00956 if( ! (line == i && pos > col ) ) {
00957
00958 for(int l = 0 ; l < length; l++) {
00959 Lview->cursorRight(TRUE);
00960 }
00961
00962
00963
00964 }
00965 } else {
00966 if( ! (line == i && pos > col ) ) {
00967
00968 for( int l = 0 ; l < length; l++) {
00969 Lview->cursorRight( TRUE);
00970 }
00971
00972 }
00973 pattern = s_pattern;
00974 last_search = -1;
00975 return 1;
00976 }
00977 }
00978 }
00979 }
00980 return 0;
00981 }
00982
00983 void Gutenbrowser::LibraryBtn() {
00984
00985 QString newestLibraryFile ="pgwhole.zip";
00986 QString zipFile;
00987
00988 zipFile="/usr/bin/unzip";
00989
00990 if( QFile::exists( local_library+newestLibraryFile)) {
00991 if( QFile::exists(zipFile) ) {
00992 UnZipIt(newestLibraryFile);
00993 }
00994 else
00995 QMessageBox::message( "Note",( tr("Please install unzip")) );
00996 }
00997
00998 LibraryDlg->setCaption( tr( "Gutenberg Library"));
00999 Config config("Gutenbrowser");
01000 config.setGroup("General");
01001
01002 if(useSplitter)
01003 LibraryDlg->useSmallInterface=FALSE;
01004
01005 LibraryDlg->showMaximized();
01006
01007 if( LibraryDlg->exec() != 0 ) {
01008 listItemNumber = LibraryDlg->DlglistItemNumber;
01009 listItemFile = LibraryDlg->DlglistItemFile;
01010 listItemYear = LibraryDlg->DlglistItemYear;
01011 listItemTitle = LibraryDlg->DlglistItemTitle;
01012 file_name = LibraryDlg->File_Name;
01013
01014 title = listItemTitle;
01015
01016
01017
01018
01019
01020
01021
01022
01023
01024 if ( listItemNumber.isNull()) {
01025 } else {
01026 i_pageNum = 1;
01027 if( file_name !="Error" && file_name.length() >2 && !file_name.isEmpty() ) {
01028
01029
01030
01031
01032
01033 if( file_name.find(".zip"))
01034 {
01035 odebug << "Found zip file\n" << oendl;
01036
01037
01038
01039
01040
01041
01042 QString cmd = "/usr/bin/unzip -o " + local_library+file_name + " -d " + local_library;
01043 odebug << "Issuing the command "+ cmd << oendl;
01044
01045
01046 system(cmd);
01047 remove( file_name);
01048
01049 }
01050
01051
01052 if( LibraryDlg)
01053 delete LibraryDlg;
01054 setTitle();
01055
01056 if( !load( file_name)) return;
01057 } else {
01058 printf("Not opening the file.\n");
01059 }
01060 }
01061 }
01062 if(showMainList) {
01063 if(!Lview->isHidden())
01064 Lview->hide();
01065 qApp->processEvents();
01066 showMainList=TRUE;
01067 if(mainList->isHidden())
01068 mainList->show();
01069 fillWithTitles();
01070 qApp->processEvents();
01071 } else
01072 setCentralWidget( Lview);
01073
01074
01075 }
01076
01077 void Gutenbrowser::OpenBtn() {
01078 QString s_temp;
01079 s_temp = status;
01080 OpenEtext* OpenDlg;
01081 OpenDlg = new OpenEtext(this,"OpenDlg");
01082 OpenDlg->showMaximized();
01083
01084 if( OpenDlg->exec() != 0) {
01085 title = OpenDlg->openFileTitle;
01086 odebug << "title open as "+title << oendl;
01087 file_name = OpenDlg->file;
01088 i_pageNum = 1;
01089
01090 if( !file_name.isEmpty() || file_name.length() > 2 ) {
01091 if(showMainList) {
01092 showMainList=FALSE;
01093 odebug << "ShowMainList is now false" << oendl;
01094 mainList->hide();
01095 Lview->show();
01096 qApp->processEvents();
01097 }
01098 Lview->clear();
01099
01100 if(!load(file_name)) return;
01101 } else {
01102 odebug << "file_name is empty!" << oendl;
01103 if(showMainList) {
01104 if(!Lview->isHidden())
01105 Lview->hide();
01106 qApp->processEvents();
01107 if(mainList->isHidden())
01108 mainList->show();
01109 fillWithTitles();
01110 qApp->processEvents();
01111 }
01112
01113 }
01114 }
01115 if( OpenDlg)
01116 delete OpenDlg;
01117
01118
01119
01120
01121
01122
01123
01124
01125
01126
01127
01128
01129
01130
01131
01132
01133
01134
01135
01136
01137
01138 }
01139
01140 void Gutenbrowser::ChangeFont() {
01141 #ifndef Q_WS_QWS
01142 bool ok;
01143
01144 weight= Lview->fontInfo().weight();
01145 italic = Lview->fontInfo().italic();
01146 bold=Lview->fontInfo().bold();
01147 pointSize= Lview->fontInfo().pointSize();
01148 fontStr=Lview->fontInfo().family();
01149
01150 if(italic == true)
01151 italicStr="TRUE";
01152 else
01153 italicStr="FALSE";
01154
01155 QFont currentfont( fontStr, pointSize, weight, italic );
01156
01157 if (ok) {
01158 QFontInfo fontInfo(font );
01159 fontStr=fontInfo.family();
01160
01161 pointSize= fontInfo.pointSize();
01162
01163 font.setFontSize(pointSize);
01164
01165 pointSizeStr.setNum( pointSize);
01166
01167 weight= fontInfo.weight();
01168 weightStr.setNum( weight);
01169 italic =fontInfo.italic();
01170 bold=fontInfo.bold();
01171
01172 if(italic == true)
01173 italicStr="TRUE";
01174 else
01175 italicStr="FALSE";
01176 if(bold == true)
01177 boldStr="TRUE";
01178 else
01179 boldStr="FALSE";
01180
01181 pointSizeStr.setNum( pointSize);
01182 config.setGroup( "Font" );
01183 config.writeEntry("Family", fontStr );
01184 config.writeEntry("Size", pointSizeStr );
01185 config.writeEntry("Weight", weightStr );
01186 config.writeEntry("Italic", italicStr );
01187 config.writeEntry("Bold", boldStr );
01188
01189
01190 Lview->setFont(font);
01191
01192 QRect lRect;
01193 QRect rRect;
01194 lRect = Lview->rect();
01195 if(useSplitter) {
01196 }
01197
01198
01199
01200 update();
01201 }
01202 #endif
01203 }
01204
01205
01206
01207
01208 void Gutenbrowser::LookupBtn() {
01209 QString text;
01210 if( Lview->hasSelectedText()) {
01211 Lview->copy();
01212 }
01213 QClipboard *cb = QApplication::clipboard();
01214 text = cb->text();
01215 int eexit=QMessageBox::information(this,
01216 "Note","Do you want to lookup\n\""+text+"\"\non websters web dictionary?",
01217 QMessageBox::Yes, QMessageBox::No);
01218 if (eexit== 3) {
01219
01220 qApp->processEvents();
01221 goGetit( "http://www.m-w.com/cgi-bin/dictionary?" + text, true);
01222 }
01223 }
01224
01225 void Gutenbrowser::ClearEdit() {
01226 Lview->setText("");
01227 loadCheck = false;
01228 status = ( tr("Gutenbrowser"));
01229 InfoBar->setText( "");
01230 setCaption( tr("Gutenbrowser"));
01231 i_pageNum = 0;
01232 enableButtons(false);
01233
01234 if(!showMainList) {
01235 Lview->hide();
01236 showMainList=TRUE;
01237 mainList->show();
01238 fillWithTitles();
01239 qApp->processEvents();
01240 }
01241 if(donateMenu->idAt(3) != -1)
01242 donateMenu->removeItemAt(3);
01243 }
01244
01245
01246 bool Gutenbrowser::getTitle( const char *file ) {
01247 QString s_file;
01248 QString filer = file;
01249 if( filer.contains(local_library, TRUE)) {
01250 QFileInfo f(file);
01251 s_file = f.fileName();
01252 } else {
01253 s_file = filer;
01254 }
01255 Config config("Gutenbrowser");
01256 config.setGroup( "Files" );
01257 QString s_numofFiles = config.readEntry("NumberOfFiles", "0" );
01258 int i_numofFiles = s_numofFiles.toInt();
01259
01260 for (int i = 1; i <= i_numofFiles; i++) {
01261 QString temp;
01262 temp.setNum(i);
01263 QString ramble = config.readEntry(temp, "" );
01264
01265 if( strcmp(ramble, s_file) == 0) {
01266 config.setGroup( "Titles" );
01267 title = config.readEntry(ramble, "");
01268
01269 }
01270 }
01271 return true;
01272 }
01273
01274 void Gutenbrowser::searchdone_slot() {
01275
01276
01277
01278
01279 this->setFocus();
01280 last_search = 0;
01281
01282 }
01283
01284
01285
01286 bool Gutenbrowser::setStatus() {
01287
01288 #ifndef Q_WS_QWS
01289 QString s_pages;
01290 s_pages.setNum( pages);
01291 QString chNum;
01292 statusTop = status.left( status.find(" ", TRUE) );
01293 status.append(chNum.setNum( i_pageNum));
01294 status += " / " + s_pages;
01295
01296 if(loadCheck) {
01297 statusBar->message( status);
01298 InfoBar->setText( title);
01299 } else {
01300 }
01301 #else
01302 QString msg;
01303 msg.sprintf(title+" %d", i_pageNum);
01304 setCaption( msg);
01305 #endif
01306 return true;
01307 }
01308
01309 void Gutenbrowser::keyReleaseEvent( QKeyEvent *e) {
01310 switch ( e->key() ) {
01311
01312 case Key_M:
01313
01314 break;
01315 case Key_D:
01316 DownloadIndex();
01317 break;
01318 case Key_L:
01319 LibraryBtn();
01320 break;
01321 case Key_O:
01322 OpenBtn();
01323 break;
01324 case Key_F:
01325 ForwardBtn();
01326 break;
01327 case Key_B:
01328 BackBtn();
01329 break;
01330 case Key_P:
01331 PrintBtn();
01332 break;
01333 case Key_S:
01334 SearchBtn();
01335 break;
01336 case Key_E:
01337 ByeBye();
01338 break;
01339 case Key_R:
01340
01341 break;
01342 case Key_T:
01343 ChangeFont();
01344 break;
01345 case Key_C:
01346 ClearEdit();
01347 break;
01348 case Key_H:
01349 HelpBtn();
01350 break;
01351 case Key_K:
01352 LookupBtn();
01353 break;
01354 case Key_U:
01355 if(menubar->isHidden() )
01356 menubar->show();
01357 else
01358 menubar->hide();
01359 break;
01360 case Key_I:
01361 hideButtons();
01362 break;
01364 case Key_Home:
01365
01366 break;
01367 case Key_F9:
01368 OpenBtn();
01369 break;
01370 case Key_F10:
01371 hideButtons();
01372 break;
01373 case Key_F11:
01374 if(menubar->isHidden() )
01375 menubar->show();
01376 else
01377 menubar->hide();
01378 break;
01379 case Key_F12:
01380 BeginBtn();
01381 break;
01382 case Key_F13:
01383 LibraryBtn();
01384 break;
01385 case Key_Space:
01386 if(loadCheck)
01387 ForwardBtn();
01388
01389
01390 break;
01391 case Key_Down:
01392 if(loadCheck) {
01393
01394
01395
01396
01397
01398 }
01399
01400
01401
01402
01403
01404
01405 break;
01406 case Key_Up:
01407 if(loadCheck) {
01408
01409
01410
01411
01412
01413 }
01414
01415
01416
01417
01418
01419
01420 break;
01421 case Key_Right:
01422 ForwardButton->setFocus();
01423 ForwardBtn();
01424
01425 break;
01426 case Key_Left:
01427 BackBtn();
01428 BackButton->setFocus();
01429
01430 break;
01431 case Key_Escape:
01432 ByeBye();
01433 break;
01434 case Key_PageUp:
01435 BackBtn();
01436 break;
01437 case Key_PageDown:
01438 ForwardBtn();
01439 break;
01440
01442 };
01443 }
01444
01445 void Gutenbrowser::keyPressEvent( QKeyEvent *e) {
01446 switch ( e->key() ) {
01447
01448
01449
01450
01451
01452
01453
01454
01455
01456
01457
01458
01459
01460
01461
01462
01463
01464
01465
01466 }
01467 }
01468
01469 void Gutenbrowser::resizeEvent( QResizeEvent *ev) {
01470
01471
01472 if( !LibraryDlg->isHidden())
01473 LibraryDlg->resize(ev->size().width(),ev->size().height() );
01474
01475
01476
01477
01478
01479 }
01480
01481
01482 void Gutenbrowser::doOptions() {
01483 optionsDialog* optDlg;
01484 optDlg = new optionsDialog( this,"Options_Dlg", true);
01485 QString Ddir;
01486 Config config("Gutenbrowser");
01487 config.setGroup( "General" );
01488 QFont myFont;
01489 optDlg->showMaximized();
01490
01491 if( optDlg->exec() !=0) {
01492 qApp->processEvents();
01493 brow=optDlg->browserName;
01494 toggleButtonIcons( optDlg->useIcon);
01495 ftp_host= optDlg->ftp_host;
01496 ftp_base_dir= optDlg->ftp_base_dir;
01497 brow=optDlg->browserName;
01498 Ddir=optDlg->downloadDirEdit->text();
01499
01500 odebug << "writing library config" << oendl;
01501 Config config("Gutenbrowser");
01502 config.setGroup("General");
01503
01504 QString dirname= optDlg->downloadDirEdit->text();
01505 if(dirname.right(1)!="/")
01506 dirname+="/";
01507 config.writeEntry( "DownloadDirectory",dirname);
01508 QDir newDir( optDlg->downloadDirEdit->text());
01509
01510 if( !newDir.exists() ) {
01511 int exit=QMessageBox::information(this, "Note", "Ok, to make a new directory\n"+Ddir+" ?",
01512 QMessageBox::Ok, QMessageBox::Cancel);
01513 if (exit==1) {
01514 QString cmd="mkdir -p ";
01515 cmd+=Ddir.latin1();
01516 system(cmd);
01517 odebug << "Making new dir "+cmd << oendl;
01518 if(Ddir.right(1)!="/") {
01519 Ddir+="/";
01520 }
01521 config.writeEntry("DownloadDirectory",Ddir);
01522 }
01523 }
01524
01525
01526
01527 if(optDlg->b_qExit==TRUE)
01528 b_queryExit=TRUE;
01529 else
01530 b_queryExit=FALSE;
01531
01532 if(optDlg->fontDlg-> changedFonts) {
01533 odebug << "Setting font" << oendl;
01534 myFont=optDlg->fontDlg->selectedFont;
01535 Lview->setFont( myFont);
01536 }
01537
01538 if(optDlg->useWordWrap_CheckBox->isChecked() ) {
01539 odebug << "WORD WRAP is set" << oendl;
01540 Lview->setWordWrap(QMultiLineEdit::WidgetWidth);
01541 useWrap=true;
01542 } else {
01543 odebug << "Word wrap is NOT set" << oendl;
01544 Lview->setWordWrap(QMultiLineEdit::NoWrap);
01545 useWrap=false;
01546 }
01547 }
01548 if(showMainList) {
01549 if(!Lview->isHidden())
01550 Lview->hide();
01551 qApp->processEvents();
01552 if(mainList->isHidden())
01553 mainList->show();
01554 fillWithTitles();
01555 } else {
01556 Lview->show();
01557 showMainList=FALSE;
01558 mainList->hide();
01559 }
01560 qApp->processEvents();
01561 update();
01562 }
01563
01564 bool Gutenbrowser::setTitle() {
01565 if( file_name.contains( local_library)) {
01566 QFileInfo f( file_name);
01567 QString s_file = f.fileName();
01568 file_name = s_file;
01569 }
01570
01571 int test = 0;
01572 Config config("Gutenbrowser");
01573 config.setGroup( "Files" );
01574 QString s_numofFiles = config.readEntry("NumberOfFiles", "0" );
01575 int i_numofFiles = s_numofFiles.toInt();
01576
01577 for (int i = 1; i <= i_numofFiles; i++) {
01578 QString temp;
01579 temp.setNum(i);
01580 QString ramble = config.readEntry(temp, "" );
01581
01582 if( strcmp(ramble, file_name) == 0) {
01583 test = 1;
01584 }
01585 }
01586 if (test == 0) {
01587 config.writeEntry("NumberOfFiles",i_numofFiles +1 );
01588 QString interger;
01589 interger.setNum( i_numofFiles +1);
01590 config.writeEntry(interger, file_name);
01591
01592 config.setGroup( "Titles" );
01593 config.writeEntry(file_name,listItemTitle);
01594 }
01595 test = 0;
01596
01597 return true;
01598 }
01599
01600 void Gutenbrowser::OnNetworkDialog( const QString &, const QString &)
01601 {
01602
01603
01604
01605
01606
01607
01608
01609
01610
01611
01612
01613 }
01614
01615 void Gutenbrowser::donateGutenberg()
01616 {
01617 int exit=QMessageBox::information(this, "Info", "http://www.gutenberg.org\ndonate@gutenberg.net",
01618 QMessageBox::Ok, QMessageBox::Cancel);
01619
01620 if (exit==1) {
01621 } else {
01622 };
01623 }
01624
01625 void Gutenbrowser::donateByteMonkie()
01626 {
01627 }
01628
01629 void Gutenbrowser::writeConfig()
01630 {
01631
01632
01633
01634
01635
01636
01637
01638
01639
01640
01641
01642
01643
01644
01645
01646
01647
01648
01649
01650
01651
01652
01653
01654
01655
01656
01657
01658
01659
01660
01661
01662
01663
01664 }
01665
01666 void Gutenbrowser::annotations()
01667 {
01668
01669
01670
01671
01672 }
01673
01674 void Gutenbrowser::hideButtons()
01675 {
01676
01677 if( !buttonsHidden) {
01678 buttonsHidden=TRUE;
01679 LibraryButton->hide();
01680 SearchButton->hide();
01681 InfoBar->hide();
01682 OpenButton->hide();
01683 BackButton->hide();
01684 ForwardButton->hide();
01685 setBookmarkButton->hide();
01686 lastBmkButton->hide();
01687 dictionaryButton->hide();
01688 if(useSplitter) {
01689 ClearButton->hide();
01690 PrintButton->hide();
01691 beginButton->hide();
01692 HelpButton->hide();
01693 FontButton->hide();
01694 ExitButton->hide();
01695 OptionsButton->hide();
01696 DownloadButton->hide();
01697 }
01698 } else {
01699 buttonsHidden=FALSE;
01700
01701 LibraryButton->show();
01702 SearchButton->show();
01703 InfoBar->show();
01704 OpenButton->show();
01705 BackButton->show();
01706 ForwardButton->show();
01707 setBookmarkButton->show();
01708 lastBmkButton->show();
01709 dictionaryButton->show();
01710 if(useSplitter) {
01711 ClearButton->show();
01712 PrintButton->show();
01713 beginButton->show();
01714 HelpButton->show();
01715 FontButton->show();
01716 ExitButton->show();
01717 OptionsButton->show();
01718 DownloadButton->show();
01719 }
01720 }
01721 }
01722
01723 void Gutenbrowser::focusInEvent( QFocusEvent* )
01724 {
01725 }
01726 void Gutenbrowser::focusOutEvent( QFocusEvent* )
01727 {
01728 }
01729
01730 void Gutenbrowser::cleanUp( )
01731 {
01732 writeConfig();
01733 QPEApplication::grabKeyboard();
01734
01735 QPEApplication::ungrabKeyboard();
01736
01737 if(f.isOpen()) f.close();
01738 }
01739
01740 void Gutenbrowser::fixKeys()
01741 {
01742 odebug << "Attempting to fix keys" << oendl;
01743
01744 }
01745
01746 void Gutenbrowser::enableButtons(bool b)
01747 {
01748 BackButton->setEnabled(b);
01749 ForwardButton->setEnabled(b);
01750 SearchButton->setEnabled(b);
01751 setBookmarkButton->setEnabled(b);
01752 dictionaryButton->setEnabled(b);
01753 InfoBar->setEnabled(b);
01754
01755 editMenu->setItemEnabled( -5, b);
01756 editMenu->setItemEnabled( -6, b);
01757 editMenu->setItemEnabled( -7, b);
01758 editMenu->setItemEnabled( -8, b);
01759
01760 }
01761
01762 void Gutenbrowser::fillWithTitles() {
01763 Config config("Gutenbrowser");
01764 config.setGroup( "Files" );
01765 int i_numofFiles = config.readNumEntry("NumberOfFiles", 0);
01766 mainList->clear();
01767 QString temp;
01768 for (int i = 1; i <= i_numofFiles; i++) {
01769 temp.setNum(i);
01770 config.setGroup( "Files" );
01771 QString ramble = config.readEntry(temp, "" );
01772 config.setGroup( "Titles" );
01773 temp = config.readEntry(ramble, "");
01774 if( !temp.isEmpty()) {
01775 mainList->insertItem ( Opie::Core::OResource::loadPixmap("gutenbrowser/gutenbrowser_sm",
01776 Opie::Core::OResource::SmallIcon ), temp, -1);
01777 }
01778 }
01779 }
01780
01781 void Gutenbrowser::listClickedSlot( QListBoxItem * index) {
01782
01783
01784 if(index) {
01785
01786 title = index->text();
01787 showMainList=FALSE;
01788 mainList->hide();
01789 Lview->show();
01790 qApp->processEvents();
01791 QString temp;
01792 temp.setNum( mainList->currentItem() + 1);
01793
01794 Config config("Gutenbrowser");
01795 config.setGroup( "Files" );
01796 QString file = config.readEntry(temp, "");
01797 odebug << "About to load" << oendl;
01798 if( Lview->isVisible())
01799 if(!load(file)) return;
01800
01801 config.setGroup( title);
01802 file_name = config.readEntry("File Name", "");
01803 i_pageNum = config.readNumEntry("Page Number", 1);
01804 int Bmrkrow = config.readNumEntry("LineNumber", -1);
01805 if(Bmrkrow > -1) {
01806 if( Bmrkrow > Lview->topRow() ) {
01807
01808 Lview->ScrollUp( Bmrkrow - Lview->topRow() );
01809
01810 }
01811 else if( Bmrkrow < Lview->topRow() ) {
01812
01813 Lview->ScrollDown( Lview->topRow() - Bmrkrow );
01814
01815 }
01816 }
01817 }
01818 }
01819
01820 void Gutenbrowser::infoGutenbrowser() {
01821 QMessageBox::message("Info","Gutenbrowser was developed by\n"
01822 "Lorn Potter\n"
01823 "ljp<ljp@llornkcor.com>\n");
01824 }
01825
01826 void Gutenbrowser::setDocument(const QString & frozenBoogers) {
01827
01828 qWarning("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXSET DOCUMENT\n");
01829 if(showMainList) {
01830 showMainList=FALSE;
01831 if(!mainList->isHidden())
01832 mainList->hide();
01833 if(Lview->isHidden())
01834 Lview->show();
01835 qApp->processEvents();
01836 }
01837 DocLnk lnk;
01838 lnk = DocLnk(frozenBoogers);
01839 qWarning("open "+frozenBoogers);
01840
01841 title=lnk.comment();
01842 if(!load( lnk.file())) return;
01843 this->show();
01844
01845
01846
01847 }
01848
01849 void Gutenbrowser::mainListPressed(int mouse, QListBoxItem * , const QPoint & )
01850 {
01851 switch (mouse) {
01852 case 1:
01853 break;
01854 case 2: {
01855 QPopupMenu m;
01856 m.insertItem( tr( "Open" ), this, SLOT( menuOpen() ));
01857 m.insertSeparator();
01858 m.insertItem( tr( "Search google.com" ), this, SLOT( menuGoogle()));
01859 m.insertItem( tr( "Edit Title" ), this, SLOT( menuEditTitle()));
01860
01861
01862 m.exec( QCursor::pos() );
01863 }
01864 break;
01865 };
01866 }
01867
01868 void Gutenbrowser::menuOpen() {
01869 listClickedSlot( mainList->item( mainList->currentItem()));
01870 }
01871
01872 void Gutenbrowser::menuGoogle() {
01873 searchGoogle( mainList->text(mainList->currentItem()));
01874 }
01875
01876 void Gutenbrowser::searchGoogle( const QString &tempText) {
01877 QString text = tempText;
01878
01879 int eexit=QMessageBox::information(this, "Note","Do you want to search for\n"+text+
01880 "\non google.com?",QMessageBox::Yes, QMessageBox::No);
01881 if (eexit== 3) {
01882 qApp->processEvents();
01883 text.replace( QRegExp("\\s"), "%20");
01884 text.replace( QRegExp("#"), "");
01885 text.replace( QRegExp(","), "%20");
01886 text.replace( QRegExp("'"), "%20");
01887 text.replace( QRegExp("("), "");
01888 text.replace( QRegExp(")"), "");
01889
01890 QString s_lookup = "http://google.com/search?q="+text+"&num=30&sa=Google+Search";
01891 goGetit( s_lookup, true);
01892 }
01893
01894 }
01895
01896 void Gutenbrowser::menuEditTitle()
01897 {
01898 int currentItem = mainList->currentItem();
01899 QString title_text = mainList->text( currentItem);
01900
01901
01902 Config config("Gutenbrowser");
01903 config.setGroup( "Files" );
01904 QString s_numofFiles = config.readEntry("NumberOfFiles", "0");
01905 int i_numofFiles = s_numofFiles.toInt();
01906 QString fileNum;
01907 for (int i = 1; i <= i_numofFiles+1; i++) {
01908
01909 fileNum.setNum(i);
01910 config.setGroup( "Files" );
01911 QString s_filename = config.readEntry(fileNum, "" );
01912 config.setGroup( "Titles" );
01913 QString file_title = config.readEntry( s_filename, "");
01914
01915 if(title_text == file_title ) {
01916
01917
01918 i=i_numofFiles+1;
01919 Edit_Title *titleEdit;
01920 titleEdit = new Edit_Title(this,file_title ,TRUE);
01921 if(titleEdit->exec() !=0) {
01922
01923 config.writeEntry( s_filename, titleEdit->newTitle);
01924 mainList->removeItem(currentItem);
01925 mainList->insertItem ( Opie::Core::OResource::loadPixmap("gutenbrowser/gutenbrowser_sm",
01926 Opie::Core::OResource::SmallIcon ), titleEdit->newTitle, currentItem);
01927 }
01928 }
01929 }
01930
01931
01932 mainList->triggerUpdate(true);
01933
01934 }
01935
01936
01937
01938 bool Gutenbrowser::UnZipIt(const QString &zipFile) {
01939 odebug << zipFile << oendl;
01940 #ifndef Q_WS_QWS
01941 if( QFile::exists( zipFile)) {
01942 bool isPgWhole=false;
01943 QString thatFile;
01944 if(zipFile.find("pgwhole",0,TRUE)) {
01945 isPgWhole=TRUE;
01946 thatFile= local_library +"PGWHOLE.TXT";
01947 }
01948
01949
01950
01951
01952 QString cmd;
01953 #if defined(_WS_X11_)
01954 if( chdir((const char*)local_library.latin1())!=0)
01955 odebug << "chdir failed." << oendl;
01956 cmd = "gunzip -S .zip " + local_library+zipFile;
01957
01958 #endif
01959 #ifdef Q_WS_QWS
01960 if( chdir((const char*)local_library.latin1())!=0)
01961 odebug << "chdir failed." << oendl;
01962 cmd = "unzip " + local_library+zipFile;
01963
01964 #endif
01965 int exit=QMessageBox::information(this, "Ok to unzip?",
01966 "Ok to unnzip\n"+ zipFile+" ?",
01967 QMessageBox::Yes, QMessageBox::No);
01968 if (exit==QMessageBox::Yes) {
01969 #if defined(_WS_X11_)//
01970 odebug << "Issuing the command "+cmd << oendl;
01971 system( cmd);
01972 if( QFile::exists(thatFile))
01973 remove (thatFile);
01974 if(isPgWhole) {
01975 if( rename("pgwhole","PGWHOLE.TXT") !=0)
01976 odebug << "rename failed" << oendl;
01977 } else {
01978 if( rename(thatFile.left(4),thatFile.left(4)+".txt") !=0)
01979 odebug << "rename failed" << oendl;
01980 }
01981 #endif
01982 #ifdef Q_WS_QWS
01983 odebug << "Issuing the command "+cmd << oendl;
01984 system( cmd);
01985 if( QFile::exists(thatFile))
01986 remove(thatFile);
01987 if(isPgWhole) {
01988 if( rename("pgwhole","PGWHOLE.TXT") !=0)
01989 odebug << "rename failed" << oendl;
01990 } else {
01991 if( rename(thatFile.left(4),thatFile.left(4)+".txt") !=0)
01992 odebug << "rename failed" << oendl;
01993 }
01994 #endif
01995
01996 return true;
01997 }
01998 else if(exit==QMessageBox::No) {
01999
02000 return false;
02001 }
02002 }
02003 else
02004 QMessageBox::message( "Note",( tr("Please install unzip in your PATH")) );
02005 #endif
02006 return false;
02007 }
02008
02009