summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-gutenbrowser/gutenbrowser.cpp
authorllornkcor <llornkcor>2004-04-07 13:07:42 (UTC)
committer llornkcor <llornkcor>2004-04-07 13:07:42 (UTC)
commitfc42c7317c956e5bc6e74bfbb1ec185d2faa79f4 (patch) (unidiff)
tree703e89c7178f764aab25028d4525f74340b28dcb /noncore/apps/opie-gutenbrowser/gutenbrowser.cpp
parent9e1ecade17a77c3d50aecc4c92091d852e99e8d9 (diff)
downloadopie-fc42c7317c956e5bc6e74bfbb1ec185d2faa79f4.zip
opie-fc42c7317c956e5bc6e74bfbb1ec185d2faa79f4.tar.gz
opie-fc42c7317c956e5bc6e74bfbb1ec185d2faa79f4.tar.bz2
add gutenbrowser
Diffstat (limited to 'noncore/apps/opie-gutenbrowser/gutenbrowser.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-gutenbrowser/gutenbrowser.cpp1984
1 files changed, 1984 insertions, 0 deletions
diff --git a/noncore/apps/opie-gutenbrowser/gutenbrowser.cpp b/noncore/apps/opie-gutenbrowser/gutenbrowser.cpp
new file mode 100644
index 0000000..2a9a71e
--- a/dev/null
+++ b/noncore/apps/opie-gutenbrowser/gutenbrowser.cpp
@@ -0,0 +1,1984 @@
1/***************************************************************************
2 gutenbrowser.cpp - description
3 -------------------
4 begin : Mon Jul 24 22:33:12 MDT 2000
5 copyright : (C) 2000 -2004 by llornkcor
6 email : ljp@llornkcor.com
7* This program is free software; you can redistribute it and/or modify *
8* it under the terms of the GNU General Public License as published by *
9* the Free Software Foundation; either version 2 of the License, or *
10* (at your option) any later version. *
11***************************************************************************/
12// http search
13// http://digital.library.upenn.edu/books/authors.html
14// http://digital.library.upenn.edu/books/titles.html
15// ftp://ibiblio.org/pub/docs/books/gutenberg/GUTINDEX.ALL
16// donate@gutenberg.net
17#include <qpe/qpeapplication.h>
18#include <qpe/fontdatabase.h>
19#include <qpe/config.h>
20#include <qpe/qcopenvelope_qws.h>
21#include <qpe/mimetype.h>
22#include <qpe/resource.h>
23#include <qpe/applnk.h>
24
25#include "editTitle.h"
26#include "gutenbrowser.h"
27#include "LibraryDialog.h"
28 //#include "bookmarksdlg.h"
29#include "optionsDialog.h"
30#include "helpme.h"
31#include "NetworkDialog.h"
32
33#include "openetext.h"
34#include "output.h"
35
36
37#include <qregexp.h>
38#include <qregion.h>
39#include <qpaintdevicemetrics.h>
40#include <qvaluelist.h>
41#include <qlabel.h>
42#include <qclipboard.h>
43#include <qpainter.h>
44#include <qpalette.h>
45#include <qobjectlist.h>
46#include <qfontdialog.h>
47#include <qtextview.h>
48#include <qbrush.h>
49#include <qfile.h>
50#include <qfontinfo.h>
51#include <qscrollview.h>
52#include <qpoint.h>
53
54#include <stdio.h>
55#include <stdlib.h>
56#include <unistd.h>
57#include <sys/stat.h>
58#include <fcntl.h>
59#include <errno.h>
60
61static const int nfontsizes = 9;
62static const int fontsize[nfontsizes] = {8,9,10,11,12,13,14,18,24};
63
64#ifdef NOQUICKLAUNCH
65Gutenbrowser::Gutenbrowser()
66 Gutenbrowser();
67#else
68Gutenbrowser::Gutenbrowser(QWidget *,const char*, WFlags )
69#endif
70 : QMainWindow()
71 {
72 // QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
73 // QCopEnvelope e("QPE/System", "grabKeyboard(QString)" );
74 // e << "";
75 // QPEApplication::grabKeyboard();
76 showMainList=TRUE;
77 working=false;
78 this->setUpdatesEnabled(TRUE);
79 // #ifndef Q_WS_QWS
80 QString msg;
81 msg="You have now entered unto gutenbrowser,\n";
82 msg+="make your self at home, sit back, relax and read something great.\n";
83
84 local_library = (QDir::homeDirPath ()) +"/Applications/gutenbrowser/";
85 setCaption("Gutenbrowser");// Embedded " VERSION);
86 this->setUpdatesEnabled(TRUE);
87
88 // bool firstTime=FALSE;
89 topLayout = new QVBoxLayout( this, 0, 0, "topLayout");
90
91 menu = new QHBoxLayout(-1,"menu");
92 buttons2 = new QHBoxLayout(-1,"buttons2");
93 edits = new QHBoxLayout(-1,"edits");
94
95 useSplitter=TRUE;
96
97 initConfig();
98 initMenuBar();
99 initButtonBar();
100 initStatusBar();
101 initView();
102 initSlots();
103
104 QPEApplication::setStylusOperation( mainList->viewport(),QPEApplication::RightOnHold);
105
106 connect( mainList, SIGNAL( mouseButtonPressed( int, QListBoxItem *, const QPoint &)),
107 this, SLOT( mainListPressed(int, QListBoxItem *, const QPoint &)) );
108 if( useIcons)
109 toggleButtonIcons( TRUE);
110 else
111 toggleButtonIcons( FALSE);
112
113 enableButtons(false);
114
115 Config config("Gutenbrowser"); // populate menubuttonlist
116 config.setGroup("General");
117
118 config.setGroup( "Files" );
119 QString s_numofFiles = config.readEntry("NumberOfFiles", "0" );
120 int i_numofFiles = s_numofFiles.toInt();
121
122 QString tempFileName;
123
124 for (int i = 0; i <= i_numofFiles; i++) {
125 // tempFileName.setNum(i);
126 config.setGroup( "Files" );
127 QString ramble = config.readEntry( QString::number(i), "" );
128
129 config.setGroup( "Titles" );
130 QString tempTitle = config.readEntry( ramble, "");
131 config.setGroup( tempTitle);
132 int index=config.readNumEntry( "LineNumber", -1 );
133 if( index != -1) {
134 // qDebug( tempTitle);
135 bookmarksMenu->insertItem( tempTitle);
136 }
137 }
138
139 // QString gutenIndex= local_library + "GUTINDEX.ALL";
140 QString gutenIndex= QPEApplication::qpeDir()+ "/etc/gutenbrowser/GUTINDEX.ALL";
141
142 if( QFile( gutenIndex).exists() ) {
143 indexLib.setName( gutenIndex);
144 } else {
145 QString localLibIndexFile = QPEApplication::qpeDir()+ "/etc/gutenbrowser/PGWHOLE.TXT";
146 // QString localLibIndexFile= local_library + "PGWHOLE.TXT";
147 newindexLib.setName( localLibIndexFile);
148 }
149 LibraryDlg = new LibraryDialog( this, "Library Index" /*, TRUE */);
150 loadCheck=false;
151 chdir(local_library);
152 if(!showMainList) {
153 Lview->setFocus();
154 // if(firstTime)
155 // Bookmark();
156 for (int i=1;i< qApp->argc();i++) {
157 qDebug("Suppose we open somethin");
158 load(qApp->argv()[i]);
159 }
160 } else {
161 fillWithTitles();
162 mainList->setFocus();
163 // mainList->setCurrentItem(0);
164
165 }
166 writeConfig();
167} //end init
168
169Gutenbrowser::~Gutenbrowser() {
170 // QPEApplication::grabKeyboard();
171 // QPEApplication::ungrabKeyboard();
172 qDebug("Exit");
173}
174
175 /*
176 Google.com search */
177void Gutenbrowser::InfoBarClick() {
178 QString text;
179 if( Lview->hasSelectedText()) {
180 Lview->copy();
181 QClipboard *cb = QApplication::clipboard();
182 text = cb->text();
183 } else {
184 // text=title;
185 text=this->caption();
186 }
187 searchGoogle(text);
188}
189
190 /*
191 download http with wget or preferred browser */
192void Gutenbrowser::goGetit( const QString &url, bool showMsg) {
193 // int eexit=0;
194 QString cmd;
195 // config.read();
196 qApp->processEvents();
197 QString filename = QPEApplication::qpeDir();
198 if(filename.right(1)!="/")
199 filename+="/etc/gutenbrowser/";
200 else
201 filename+="etc/gutenbrowser/";
202 qDebug("filename "+filename);
203 // QString filename = QDir::homeDirPath()+"/Applications/gutenbrowser/";
204
205 filename += url.right( url.length() - url.findRev("/",-1,TRUE) -1);
206
207 Config config("Gutenbrowser");
208 config.setGroup( "Browser" );
209 QString brow = config.readEntry("Preferred", "Opera");
210 qDebug("Preferred browser is "+brow);
211 if(!showMsg) { //if we just get the gutenindex.all
212 cmd="wget -O " + filename +" " + url+" 2>&1" ;
213 chdir(local_library);
214 qDebug("Issuing the system command: %s", cmd.latin1());
215
216 Output *outDlg;
217 outDlg = new Output(this, tr("Gutenbrowser Output"),FALSE);
218 outDlg->showMaximized();
219 outDlg->show();
220 qApp->processEvents();
221 FILE *fp;
222 char line[130];
223 outDlg->OutputEdit->append( tr("Running wget") );
224 sleep(1);
225 fp = popen( (const char *) cmd, "r");
226 // qDebug("Issuing the command\n"+cmd);
227 // system(cmd);
228 while ( fgets( line, sizeof line, fp)) {
229 outDlg->OutputEdit->append(line);
230 outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE);
231 }
232 pclose(fp);
233 outDlg->close();
234 if(outDlg)
235 delete outDlg;
236 } else {
237 if( brow == "Konq") {
238 cmd = "konqueror "+url+" &";
239 }
240 if( brow == "Opera") { //for desktop testing
241 cmd = "opera "+url+" &";
242 }
243 // if( brow == "Opera") { // on Zaurus
244 // cmd = "operagui "+url+" &";
245 // }
246 if( brow == "Mozilla") {
247 cmd = "mozilla "+url+" &";
248 }
249 if( brow == "Netscape") {
250 cmd = "netscape "+url+" &";
251 }
252 if(brow == "wget") {
253 // cmd="wget -q "+url+" &";
254 QString tempHtml=local_library+"webster.html";
255 cmd="wget -O "+tempHtml+" -q "+url;
256 }
257
258 chdir(local_library);
259 qDebug("Issuing the sys command: %s", cmd.latin1());
260 system(cmd);
261 }
262}
263
264void Gutenbrowser::toggleButtonIcons( bool useEm) {
265 QString pixDir;
266 if(useEm)
267 useEm=TRUE;
268 pixDir=QPEApplication::qpeDir()+"pics/gutenbrowser";
269 qDebug("Docdir is "+QPEApplication::documentDir());
270
271 if( useIcons && QDir( pixDir).exists() ) {
272 LibraryButton->setPixmap( Resource::loadPixmap("home") ); //in inline
273 OpenButton->setPixmap( Resource::loadPixmap("gutenbrowser/openbook"));
274 ForwardButton->setPixmap( Resource::loadPixmap("forward"));//in inline
275 BackButton->setPixmap( Resource::loadPixmap("back") );//in inline
276 SearchButton->setPixmap( Resource::loadPixmap("gutenbrowser/search") );//in inline
277 lastBmkButton->setPixmap( Resource::loadPixmap("gutenbrowser/bookmark_folder"));
278 setBookmarkButton->setPixmap( Resource::loadPixmap("gutenbrowser/bookmark") );
279 dictionaryButton->setPixmap( Resource::loadPixmap("gutenbrowser/spellcheck") );
280 InfoBar->setPixmap( Resource::loadPixmap("gutenbrowser/google"));
281 }
282}
283
284
285bool Gutenbrowser::queryExit()
286{
287 int exit=QMessageBox::information(this, "Quit...", "Do your really want to quit?",
288 QMessageBox::Ok, QMessageBox::Cancel);
289 if (exit==1) {
290 writeConfig();
291 qApp->quit();
292 } else {
293 };
294 return (exit==1);
295}
296
297 // SLOT IMPLEMENTATION
298
299void Gutenbrowser::slotFilePrint() {
300}
301
302void Gutenbrowser::ByeBye() {
303 if (b_queryExit)
304 queryExit();
305 else {
306 // writeConfig();
307 qApp->quit();
308 }
309}
310
311void Gutenbrowser::HelpBtn() {
312 HelpMe* HelpDlg;
313 HelpDlg = new HelpMe( this, "Help Dialog");
314 HelpDlg->showMaximized();
315}
316
317void Gutenbrowser::DownloadIndex() {
318#ifndef Q_WS_QWS
319 {
320 switch( QMessageBox::information( 0, (tr("Download Library Index, or FTP sites?")),
321 (tr("Do you want to download the newest\n"
322 "Project Gutenberg Library Index?\n"
323 "or select an ftp site?\n")),
324 (tr("&Library Index")), (tr("&Ftp Site")), (tr("&Cancel")), 2, 2 ) )
325 {
326 case 0: // index clicked,
327 downloadLibIndex();
328 break;
329
330 case 1: // ftp selected
331 downloadFtpList();
332 break;
333
334 case 2: // Cancel
335 break;
336 };
337 }
338#endif
339} // end DownloadIndex
340
341
342void Gutenbrowser::downloadFtpList() {
343 // QString cmd="wget http://www.promo.net/pg/list.html");
344 //system(cmd);
345 qApp->processEvents();
346 optionsDialog* optDlg;
347 optDlg = new optionsDialog( this,"Options_Dlg", true);
348 optDlg->getSite();
349 if(optDlg)
350 delete optDlg;
351}
352
353
354void Gutenbrowser::downloadLibIndex() {
355 // QString dwmloader = local_library + "pgwhole.zip";
356 // QString cmd = "lynx -source http://www.gutenberg.net/pgwhole.zip | cat >> " + dwmloader;
357 // system(cmd);
358
359 // QString outputFile= local_library+ "GUTINDEX.ALL";
360 // config.setGroup( "FTPsite" ); // ftp server config
361 // ftp_host=config.readEntry("SiteName", "");
362 // ftp_base_dir= config.readEntry("base", "");
363 // QString networkUrl= "ftp://"+ftp_host+ftp_base_dir+"/GUTINDEX.ALL";
364 QDir dir( local_library);
365 dir.cd("", TRUE);
366 goGetit( "http://sailor.gutenberg.org/GUTINDEX.ALL", false); // until ghttp works on binaries -qt3
367 // goGetit( "http://www.gutenberg.net/pgwhole.zip", true); // until ghttp works on binaries -qt3
368 // NetworkDialog *NetworkDlg;
369 // NetworkDlg = new NetworkDialog( this,"Network Protocol Dialog", TRUE, 0, networkUrl, outputFile );
370 // if( NetworkDlg->exec() != 0 )
371 // { // use new, improved, *INSTANT* network-dialog-file-getterer
372 //// QMessageBox::message("Note","");
373 // }
374 // if(NetworkDlg)
375 // delete NetworkDlg;
376}
377
378
379void Gutenbrowser::PrintBtn() {
380}
381
382void Gutenbrowser::SearchBtn() {
383 if( loadCheck) {
384 qDebug("loadCheck: we have a loaded doc");
385 Search();
386 }
387 // else
388 // QMessageBox::message("Note","Sorry, can't search. No etext is loaded");
389}
390
391
392void Gutenbrowser::ForwardBtn() {
393
394 if( !ForwardButton->autoRepeat() && !ForwardButton->isDown()) {
395
396 QString s;
397 QString insertString;
398 int pageSize= Lview->PageSize();
399 Lview->clear();
400
401 for(int fd=0; fd < pageSize - 1;fd++) {
402 f.readLine(s, 256);
403 if(useWrap)
404 s.replace(QRegExp("\n"),"");
405 insertString+=s;
406 Lview->insertLine( s, -1);
407 // qDebug(s);
408 currentLine++;
409 }
410 // Lview->insertAt( insertString,0,0, FALSE);
411 currentFilePos = f.at();
412 // if( i_pageNum != pages) {
413 // Lview->MultiLine_Ex::pageDown( FALSE);
414 i_pageNum++;
415 pageStopArray.resize(i_pageNum + 1);
416 // int length = Lview->length();
417
418 pageStopArray[i_pageNum ] = currentFilePos;
419 // qDebug("%d current page is number %d, pagesize %d, length %d, current %d",
420 // currentFilePos, i_pageNum, pageSize, Lview->length(), pageStopArray[i_pageNum] );
421 setStatus();
422 Lview->setCursorPosition( 0, 0, FALSE);
423 // }
424
425 } else {
426 // qDebug("bal");
427 // if( i_pageNum != pages) {
428
429 // // int newTop = Lview->Top();
430 // // if(Lview->lastRow() > i)
431 // Lview->ScrollUp(1);
432 // // i_pageNum++;
433 // setStatus();
434 // Lview->setCursorPosition( Lview->Top(), 0, FALSE);
435
436 // }
437
438 }
439 Lview->setFocus();
440
441 // qDebug("page number %d line number %d", i_pageNum, currentLine);
442}
443
444
445void Gutenbrowser::BackBtn() {
446 if( i_pageNum > 0) {
447 int pageSize= Lview->PageSize();
448 // int length=Lview->length();
449
450 i_pageNum--;
451 currentFilePos = f.at();
452
453 // qDebug("%d move back to %d, current page number %d, %d, length %d",
454 // currentFilePos, pageStopArray[i_pageNum - 1 ], i_pageNum, pageSize, Lview->length() );
455
456 if( i_pageNum < 2) {
457 f.at( 0);
458 } else {
459 if(!f.at( pageStopArray[i_pageNum - 1] ))
460 qDebug("File positioned backward did not work");
461 }
462 QString s;
463 // int sizeLine=0;
464 Lview->clear();
465 // QString insertString;
466
467 for(int fd = 0; fd < pageSize ;fd++) {
468 // Lview->removeLine( Lview->PageSize() );
469 f.readLine(s, 256);
470 if(useWrap)
471 s.replace(QRegExp("\n"),"");
472 currentLine++;
473 // insertString+=s;
474 Lview->insertLine( s, -1);
475 }
476
477 // Lview->insertAt( insertString,0,0, FALSE);
478
479 if( !BackButton->autoRepeat() && !BackButton->isDown()) {
480 QString topR;
481 QString lastR;
482 QString pageR;
483 // int sizer = Lview->lastRow() - Lview->topRow();
484 // int i_topRow = Lview->topRow();
485 if( i_pageNum < 1)
486 i_pageNum = 1;
487 setCaption(QString::number(i_pageNum));
488 } else {
489 // int newTop = Lview->Top();
490 // if(Lview->lastRow() > i)
491 Lview->MultiLine_Ex::pageUp( FALSE);
492 // Lview->ScrollDown(1);
493 // i_pageNum--;
494 if( i_pageNum < 1)
495 i_pageNum = 1;
496 setStatus();
497 Lview->setCursorPosition( Lview->Top(), 0, FALSE);
498
499 }
500 }
501 Lview->setFocus();
502}
503
504void Gutenbrowser::doBeginBtn() {
505 if(loadCheck) {
506 qApp->processEvents();
507 BeginBtn();
508 }
509}
510
511 // moves text to the very top = 0
512void Gutenbrowser::TopBtn() {
513
514 if(loadCheck) {
515 if( i_pageNum != 0) {
516 qDebug("top");
517 qApp->processEvents();
518 currentLine = 0;
519 i_pageNum = 1;
520 int pageSize = Lview->PageSize() ;
521 Lview->clear();
522 QString s;
523 f.at(0);
524 for(int fd=0; fd < pageSize ;fd++) {
525 f.readLine(s, 256);
526 if(useWrap)
527 s.replace(QRegExp("\n"),"");
528 Lview->insertLine(s ,-1);
529 currentLine++;
530 }
531 Lview->setCursorPosition( 0,0, FALSE);
532 i_pageNum=1;
533 setStatus();
534 }
535 Lview->setFocus();
536 }
537}
538
539 //moves text to the start of the EText
540void Gutenbrowser::BeginBtn() {
541 i_pageNum = 1;
542 currentLine = 0;
543 QString s_pattern="*END*THE SMALL PRINT";
544 QString sPattern2 = "*END THE SMALL PRINT";
545
546 int pageSize = Lview->PageSize();
547 Lview->clear();
548
549 // int lines = Lview->numLines();
550 int pos = 0;//, i = 0;
551 int i_topRow = Lview->topRow();
552
553 QString LeftText;// = Lview->text();
554
555 int linesPerPage = Lview->lastRow() - Lview->topRow();
556 // int pages = (( linesPerPage / Lview->editSize() ) ) +1;
557 // int pageN = 0;
558 i_pageNum = 1;
559 int lastPage=1;
560 int lineNo=0;
561 QString s;
562 f.at( 0);
563
564 while ( !f.atEnd() ) {
565 f.readLine(s, 256);
566 lineNo++;
567 LeftText = s;
568 currentFilePos = f.at();
569
570 i_pageNum = lineNo/pageSize;
571 if(lastPage < i_pageNum) {
572 pageStopArray.resize(i_pageNum + 1);
573 pageStopArray[i_pageNum ] = currentFilePos;
574 // qDebug("new page number %d, found at %d", i_pageNum, currentFilePos);
575 }
576 // lastPage = i_pageNum;
577 if( LeftText.find( s_pattern, 0 , TRUE) != -1 || LeftText.find( sPattern2, 0 , TRUE) != -1 ) {
578 qDebug("<<<<<< FOUND IT!! new page number %d, found at %d", i_pageNum, currentFilePos);
579 break;
580 }
581 }
582 if(f.atEnd()) //in case we didnt find anything, we need to show something
583 f.at(0);
584 Lview->clear();
585 for(int fd=0; fd < pageSize - 1;fd++) {
586 f.readLine(s, 256);
587 if(useWrap)
588 s.replace(QRegExp("\n"),"");
589 Lview->insertLine( s, -1);
590 currentLine++;
591 }
592
593 i_pageNum = lineNo/pageSize;
594 pageStopArray.resize(i_pageNum + 1);
595 // int length = Lview->length();
596
597 qApp->processEvents();
598
599 if( pos > i_topRow ) {
600 Lview->setCursorPosition( pos+linesPerPage+2/* - i_topRow+3 */,0, FALSE);
601 } else {
602 Lview->setCursorPosition( pos+2 , 0, FALSE );
603 }
604
605 Lview->deselect();
606 // AdjustStatus();
607 Lview->setFocus();
608}
609
610 /*
611 sets the current page and place as a bookmark*/
612void Gutenbrowser::setBookmark() {
613 int eexit=QMessageBox::information(this, "Note",
614 "Do you really want to \nset this bookmark?."
615 ,QMessageBox::Yes, QMessageBox::No);
616 if (eexit== 3) {
617
618 currentFilePos = f.at();
619
620 Config cfg("Gutenbrowser");
621 cfg.setGroup("General");
622 file_name=cfg.readEntry("Current","");
623 qApp->processEvents();
624 qDebug("Settingbook mark "+file_name);
625
626 cfg.setGroup("Titles");
627 title=cfg.readEntry(file_name,"");
628 qDebug("title is "+ title);
629
630 cfg.setGroup( "Bookmarks" );
631
632 cfg.writeEntry("File Name",file_name);
633 cfg.writeEntry("Page Number",QString::number(i_pageNum) );
634 cfg.writeEntry( "PagePosition", QString::number( pageStopArray[i_pageNum - 1]));
635 cfg.writeEntry("Title", title);
636
637 int row = Lview->topRow();// Lview->Top();
638 cfg.writeEntry("LineNumber",QString::number(row) );
639
640 cfg.setGroup(title);
641 cfg.writeEntry("File Name",file_name);
642 cfg.writeEntry( "LineNumber", QString::number( row));
643 cfg.writeEntry( "PagePosition", QString::number( pageStopArray[i_pageNum - 1]));
644 cfg.writeEntry( "Page Number", QString::number( i_pageNum) );
645 bookmarksMenu->insertItem( title);
646 }
647} //end setBookmark
648
649
650 /* goes to last set bookmark*/
651void Gutenbrowser::Bookmark( int itemId) {
652
653 // qApp->processEvents();
654 Config config("Gutenbrowser");
655 config.setGroup( "Bookmarks" );
656
657 // qDebug("<<<<<< %d, %d", Lview->PageSize(), Lview->lastRow() - Lview->topRow() );
658
659 QString itemString;
660
661 qDebug("menu item %d", itemId);
662 QString tempTitle;
663 QString s_Bmrkrow;
664 QString s_pageNum;
665 int Bmrkrow=0;
666 int bookmarkPosition = 0;
667
668 // qApp->processEvents();
669 config.setGroup( "Bookmarks" );
670 title = config.readEntry("Title", "");
671 file_name = config.readEntry("File Name", "");
672 i_pageNum = config.readNumEntry("Page Number", 0);
673 bookmarkPosition = config.readNumEntry( "PagePosition",0);
674 Bmrkrow = config.readNumEntry("LineNumber",0);
675 if( !file_name.contains("/")) {
676 file_name = local_library + file_name;
677 }
678
679 // getTitle(file_name);
680 // qApp->processEvents();
681 // Lview->setFocus();
682 this->setFocus();
683
684 Lview->clear();
685
686 load(file_name);
687
688 int pageSize= Lview->PageSize();
689 f.at(0);
690 // Lview->clear();
691 QString s;
692 int lineNo=0;
693 int lastPage=1;
694 while ( !f.atEnd() ) {
695 f.readLine(s, 256);
696 lineNo++;
697 currentFilePos = f.at();
698
699 i_pageNum = lineNo/pageSize;
700 if(lastPage < i_pageNum) {
701 pageStopArray.resize(i_pageNum + 1);
702 pageStopArray[i_pageNum ] = currentFilePos;
703 // qDebug("new page number %d, found at %d", i_pageNum, currentFilePos);
704 }
705 if(currentFilePos == bookmarkPosition)
706 break;
707 }
708 if(f.atEnd())
709 f.at(0);
710 else
711 f.at( bookmarkPosition);
712
713 for(int fd=0; fd < pageSize - 1;fd++) {
714 f.readLine(s, 256);
715 lineNo++;
716 if(useWrap)
717 s.replace(QRegExp("\n"),"");
718 Lview->insertLine( s, -1);
719 currentLine++;
720 }
721
722 i_pageNum = lineNo/pageSize;
723 pageStopArray.resize(i_pageNum + 1);
724
725 if(showMainList) {
726 showMainList=FALSE;
727 mainList->hide();
728 Lview->show();
729 // qApp->processEvents();
730 }
731
732 qDebug("bookmark loaded");
733 setCaption(title);
734}
735
736
737bool Gutenbrowser::load( const char *fileName) {
738
739 // QCopEnvelope ( "QPE/System", "busy()" );
740 // qDebug("Title is already set as "+title);
741 qDebug("sizeHint %d pageSize %d", sizeHint().height(),Lview->PageSize() );
742 if( Lview->PageSize() < 4) {
743
744 Lview->setMaximumHeight( sizeHint().height() );
745 Lview->setMinimumHeight( sizeHint().height() );
746 pointSize = Lview->fontInfo().pointSize();
747 qDebug("sizeHint %d point size %d", sizeHint().height(), pointSize);
748 if(pointSize < 10)
749 Lview->setFixedVisibleLines(19);
750 else
751 Lview->setFixedVisibleLines( ( (sizeHint().height() / pointSize ) * 2) -2);
752 }
753
754 Config cfg("Gutenbrowser");
755 cfg.setGroup("General");
756 cfg.writeEntry("Current",fileName);
757 currentLine=0;
758
759 file_name=fileName;
760 QString o_file = fileName;
761
762 // if (i_pageNum < 1) {
763 i_pageNum = 1;
764 // }
765 qDebug("ready to open "+o_file);
766
767 if(f.isOpen()) f.close();
768 f.setName( o_file);
769
770 if ( !f.open( IO_ReadOnly)) {
771 QMessageBox::message( (tr("Note")), (tr("File not opened sucessfully.\n" +o_file)) );
772 return false;
773 }
774 currentFilePos = 0;
775 pageStopArray.resize(3);
776 pageStopArray[0] = currentFilePos;
777
778 fileHandle = f.handle();
779 QString insertString;
780 QTextStream t(&f);
781 QString s;
782 for(int fd=0; fd < Lview->PageSize() ;fd++) {
783 s=t.readLine();
784 // insertString+=s;
785 if(useWrap)
786 s.replace(QRegExp("\n"),"");
787 // s.replace(QRegExp("\r"),"");
788 Lview->insertLine( s,-1);
789 currentLine++;
790 }
791
792 // int length = Lview->length();
793 currentFilePos = f.at();
794
795 pageStopArray[1] = currentFilePos;
796
797 qDebug("<<<<<<<<<<<%d current page is number %d, length %d, current %d, pageSize %d",
798 currentFilePos, i_pageNum, Lview->length(), pageStopArray[i_pageNum], Lview->PageSize() );
799
800 Lview->setMaxLines(Lview->PageSize()*2);
801 qDebug("Gulped %d", currentLine);
802 setCaption(title);
803 Lview->setAutoUpdate( TRUE);
804
805 Lview->setCursorPosition(0,0,FALSE);
806
807 // pages = (int)(( Lview->numLines() / Lview->editSize() ) / 2 ) +1;
808 //qDebug("number of pages %d", pages);
809
810 loadCheck = true;
811 enableButtons(true);
812 if( donateMenu->count() == 3) {
813 donateMenu->insertItem("Current Title", this, SLOT( InfoBarClick() ));
814 }
815 Lview->setFocus();
816
817 // QCopEnvelope("QPE/System", "notBusy()" );
818 return true;
819} // end load
820
821void Gutenbrowser::Search() {
822
823 // if( searchDlg->isHidden())
824 {
825 qDebug("Starting search dialog");
826 searchDlg = new SearchDialog( this, "Etext Search", true);
827 searchDlg->setCaption( tr( "Etext Search" ));
828 // searchDlg->setLabel( "- searches etext");
829 connect( searchDlg,SIGNAL( search_signal()),this,SLOT( search_slot()));
830 connect( searchDlg,SIGNAL( search_done_signal()),this,SLOT( searchdone_slot()));
831
832 QString resultString;
833 QString string = searchDlg->searchString;
834 Lview->deselect();
835 searchDlg->show();
836 searchDlg->result();
837 }
838}
839
840void Gutenbrowser::search_slot( ) {
841 int line, col;
842 if (!searchDlg /*&& !loadCheck */)
843 return;
844
845 Lview->getCursorPosition(&line,&col);
846 QString to_find_string=searchDlg->get_text();
847
848 // searchDlg->get_direction();// is true if searching backward
849 if ( last_search != 0 && searchDlg->get_direction() ){
850 col = col - pattern.length() - 1 ;
851 }
852 again:
853 int result = doSearch( to_find_string , /* searchDlg->case_sensitive()*/ TRUE, searchDlg->forward_search(), line, col);
854 if(result == 0){
855 if(!searchDlg->get_direction()){ // forward search
856 int query = QMessageBox::information( searchDlg, "Find",
857 "End of document reached.\nContinue from the beginning?",
858 "Yes", "No", "", 0,1);
859 if (query == 0){
860 line = 0;
861 col = 0;
862 goto again;
863 }
864 } else { //backward search
865 int query = QMessageBox::information( searchDlg, "Find",
866 "End of document reached.\nContinue from the beginning?",
867 "Yes", "No", "", 0,1);
868 if (query == 0){
869 QString string = Lview->textLine( Lview->numLines() - 1 );
870 line = Lview->numLines() - 1;
871 lineCheck = line;
872 col = string.length();
873 last_search = -1; //BACKWARD;
874 goto again;
875 }
876 }
877 } else {
878
879 //// emit CursorPositionChanged(); textLine
880 }
881}
882
883int Gutenbrowser::doSearch( const QString &s_pattern , bool case_sensitive, bool forward, int line, int col ) {
884 int i, length;
885 int pos = -1;
886 if(forward) {
887 QString string;
888 for(i = line; i < Lview->numLines(); i++) {
889
890 string = Lview->textLine(i);
891 pos = string.find(s_pattern, i == line ? col : 0, case_sensitive);
892 if( pos != -1) {
893 int top = Lview->Top();
894 length = s_pattern.length();
895 if( i > Lview->lastRow() ) {
896 Lview->setCursorPosition(i,pos,FALSE);
897 for(int l = 0 ; l < length; l++) {
898 Lview->cursorRight(TRUE);
899 }
900 Lview->setCursorPosition( i , pos + length, TRUE );
901 int newTop = Lview->Top();
902 if(Lview->lastRow() > i)
903 Lview->ScrollUp( newTop - top);
904 // AdjustStatus();
905 } else {
906 Lview->setCursorPosition(i,pos,FALSE);
907 for(int l = 0 ; l < length; l++) {
908 Lview->cursorRight(TRUE);
909 }
910 Lview->setCursorPosition( i , pos + length, TRUE );
911 // AdjustStatus();
912 }
913 pattern = s_pattern;
914 last_search = 1; //FORWARD;
915 return 1;
916 }
917 }
918 } else { //////////////// searching backwards
919 QString string;
920 for( i = line; i >= 0; i--) {
921 string = Lview->textLine(i);
922 int line_length = string.length();
923 pos = string.findRev(s_pattern, line == i ? col : line_length , case_sensitive);
924 if (pos != -1) {
925 // int top = Lview->Top();
926 length = s_pattern.length();
927 if( i < Lview->Top() ) {
928 Lview->ScrollDown( Lview->PageSize() );
929 Lview->MultiLine_Ex::pageUp( FALSE );
930 if( ! (line == i && pos > col ) ) {
931 Lview->setCursorPosition( i ,pos ,FALSE );
932 for(int l = 0 ; l < length; l++) {
933 Lview->cursorRight(TRUE);
934 }
935 Lview->setCursorPosition(i ,pos + length ,TRUE );
936 // int newTop = Lview->Top();
937 /* if(useSplitter) Rview->ScrollUp( newTop - top);
938 */ }
939 } else {
940 if( ! (line == i && pos > col ) ) {
941 Lview->setCursorPosition( i, pos, FALSE );
942 for( int l = 0 ; l < length; l++) {
943 Lview->cursorRight( TRUE);
944 }
945 Lview->setCursorPosition( i, pos + length, TRUE );
946 }
947 pattern = s_pattern;
948 last_search = -1;
949 return 1;
950 }
951 }
952 }
953 }
954 return 0;
955}
956
957void Gutenbrowser::LibraryBtn() {
958
959 QString newestLibraryFile ="pgwhole.zip";
960 QString zipFile;
961 // qDebug("Local Library is %s ", local_library.latin1());
962 zipFile="/usr/bin/unzip";
963 // qDebug("newestLibraryFile is %s ", newestLibraryFile.latin1());
964 if( QFile::exists( local_library+newestLibraryFile)) {
965 if( QFile::exists(zipFile) ) {
966 UnZipIt(newestLibraryFile);
967 }
968 else
969 QMessageBox::message( "Note",( tr("Please install unzip")) );
970 }
971 // LibraryDlg = new LibraryDialog( this, "Library Index");
972 LibraryDlg->setCaption( tr( "Gutenberg Library"));
973 Config config("Gutenbrowser");
974 config.setGroup("General");
975 QString tmp=config.readEntry("RunBefore","FALSE");
976 if(tmp=="FALSE") {
977 QMessageBox::message( "Note",
978 "<P>Your first time running gutenbrowser. You'll need to click the \"load library\" button to load the gutenberg index.</P>");
979 config.writeEntry("RunBefore","TRUE");
980 }
981 if(useSplitter)
982 LibraryDlg->useSmallInterface=FALSE;
983
984 LibraryDlg->showMaximized();
985
986 if( LibraryDlg->exec() != 0 ) {
987 listItemNumber = LibraryDlg->DlglistItemNumber;
988 listItemFile = LibraryDlg->DlglistItemFile;
989 listItemYear = LibraryDlg->DlglistItemYear;
990 listItemTitle = LibraryDlg->DlglistItemTitle;
991 file_name = LibraryDlg->File_Name;
992 // qDebug("title is being set as "+title);
993 title = listItemTitle;
994
995 // config.setGroup( "Proxy" );
996 // if( LibraryDlg->checked == 1) {
997 // config.writeEntry("IsChecked", "TRUE");
998 // } else {
999 // config.writeEntry("IsChecked", "FALSE");
1000 // }
1001 // config.write();
1002 // config.read();
1003 if ( listItemNumber.isNull()) {
1004 } else {
1005 i_pageNum = 1;
1006 if( file_name !="Error" && file_name.length() >2 && !file_name.isEmpty() ) {
1007 //replace .zip with txt for opening it.
1008 // printf("\nFile name is now\n");
1009 // printf(file_name);
1010 // printf("\n");
1011 //
1012 if( file_name.find(".zip"))
1013 {
1014 qDebug("Found zip file\n");
1015 // QStringList args;
1016 // args="unzip";
1017 // args+="-o";
1018 // args+=local_library+file_name;
1019 // args+="-d";
1020 // args+=local_library;
1021 QString cmd = "/usr/bin/unzip -o " + local_library+file_name + " -d " + local_library;
1022 qDebug("Issuing the command "+ cmd);
1023 // unzipProc=new QProcess( this, "unzipProc" ); /// fark that idea!
1024 // unzipProc->start();
1025 system(cmd);
1026 remove( file_name);
1027
1028 }
1029 // //
1030 // file_name = file_name.left(4)+ ".txt";
1031 if( LibraryDlg)
1032 delete LibraryDlg;
1033 setTitle();
1034 // QCopEnvelope ( "QPE/System", "busy()" );
1035 load( file_name);
1036 } else {
1037 printf("Not opening the file.\n");
1038 }
1039 }
1040 }
1041 if(showMainList) {
1042 if(!Lview->isHidden())
1043 Lview->hide();
1044 qApp->processEvents();
1045 showMainList=TRUE;
1046 if(mainList->isHidden())
1047 mainList->show();
1048 fillWithTitles();
1049 qApp->processEvents();
1050 } else
1051 setCentralWidget( Lview);
1052 // QPEApplication::grabKeyboard();
1053 // fixKeys();
1054}
1055
1056void Gutenbrowser::OpenBtn() {
1057 QString s_temp;
1058 s_temp = status;
1059 OpenEtext* OpenDlg;
1060 OpenDlg = new OpenEtext(this,"OpenDlg");
1061 OpenDlg->showMaximized();
1062
1063 if( OpenDlg->exec() != 0) {
1064 title = OpenDlg->openFileTitle;
1065 qDebug("title open as "+title);
1066 file_name = OpenDlg->file;
1067 i_pageNum = 1;
1068
1069 if( !file_name.isEmpty() || file_name.length() > 2 ) {
1070 if(showMainList) {
1071 showMainList=FALSE;
1072 qDebug("ShowMainList is now false");
1073 mainList->hide();
1074 Lview->show();
1075 qApp->processEvents();
1076 }
1077 Lview->clear();
1078 // QCopEnvelope ( "QPE/System", "busy()" );
1079 load(file_name);
1080 } else {
1081 qDebug("file_name is empty!");
1082 if(showMainList) {
1083 if(!Lview->isHidden())
1084 Lview->hide();
1085 qApp->processEvents();
1086 if(mainList->isHidden())
1087 mainList->show();
1088 fillWithTitles();
1089 qApp->processEvents();
1090 }
1091
1092 }
1093 }
1094 if( OpenDlg)
1095 delete OpenDlg;
1096 /*
1097 Config config("Gutenbrowser");
1098 config.setGroup( title);
1099 file_name = config.readEntry("File Name", "");
1100 i_pageNum = config.readNumEntry("Page Number", -1);
1101 int Bmrkrow = config.readNumEntry("LineNumber", -1);
1102 if(Bmrkrow > -1) {
1103 if( Bmrkrow > Lview->topRow() ) {
1104 Lview->setCursorPosition( Bmrkrow ,0, FALSE );
1105 Lview->ScrollUp( Bmrkrow - Lview->topRow() );
1106 // AdjustStatus();
1107 }
1108 else if( Bmrkrow < Lview->topRow() ) {
1109 Lview->setCursorPosition( Lview->topRow() - Bmrkrow ,0, FALSE );
1110 Lview->ScrollDown( Lview->topRow() - Bmrkrow );
1111 // AdjustStatus();
1112 }
1113 }
1114 */
1115 // ResizeEdits();
1116
1117}
1118
1119void Gutenbrowser::ChangeFont() {
1120#ifndef Q_WS_QWS
1121 bool ok;
1122
1123 weight= Lview->fontInfo().weight();
1124 italic = Lview->fontInfo().italic();
1125 bold=Lview->fontInfo().bold();
1126 pointSize= Lview->fontInfo().pointSize();
1127 fontStr=Lview->fontInfo().family();
1128
1129 if(italic == true)
1130 italicStr="TRUE";
1131 else
1132 italicStr="FALSE";
1133
1134 QFont currentfont( fontStr, pointSize, weight, italic );
1135
1136 if (ok) {
1137 QFontInfo fontInfo(font );
1138 fontStr=fontInfo.family();
1139
1140 pointSize= fontInfo.pointSize();
1141
1142 font.setFontSize(pointSize);
1143
1144 pointSizeStr.setNum( pointSize);
1145
1146 weight= fontInfo.weight();
1147 weightStr.setNum( weight);
1148 italic =fontInfo.italic();
1149 bold=fontInfo.bold();
1150
1151 if(italic == true)
1152 italicStr="TRUE";
1153 else
1154 italicStr="FALSE";
1155 if(bold == true)
1156 boldStr="TRUE";
1157 else
1158 boldStr="FALSE";
1159
1160 pointSizeStr.setNum( pointSize);
1161 config.setGroup( "Font" );
1162 config.writeEntry("Family", fontStr );
1163 config.writeEntry("Size", pointSizeStr );
1164 config.writeEntry("Weight", weightStr );
1165 config.writeEntry("Italic", italicStr );
1166 config.writeEntry("Bold", boldStr );
1167 // config.write();
1168
1169 Lview->setFont(font);
1170
1171 QRect lRect;
1172 QRect rRect;
1173 lRect = Lview->rect();
1174 if(useSplitter) {
1175 }
1176 // if(loadCheck) {
1177 // ResizeEdits();
1178 // }
1179 update();
1180 }
1181#endif
1182}
1183
1184
1185 /*
1186 performs dictionary look ups on the web */
1187void Gutenbrowser::LookupBtn() {
1188 QString text;
1189 if( Lview->hasSelectedText()) {
1190 Lview->copy();
1191 }
1192 QClipboard *cb = QApplication::clipboard();
1193 text = cb->text();
1194 int eexit=QMessageBox::information(this,
1195 "Note","Do you want to lookup\n\""+text+"\"\non websters web dictionary?",
1196 QMessageBox::Yes, QMessageBox::No);
1197 if (eexit== 3) {
1198 // this link for sale!!
1199 qApp->processEvents();
1200 goGetit( "http://www.m-w.com/cgi-bin/dictionary?" + text, true);
1201 }
1202}
1203
1204void Gutenbrowser::ClearEdit() {
1205 Lview->setText("");
1206 loadCheck = false;
1207 status = ( tr("Gutenbrowser"));
1208 InfoBar->setText( "");
1209 setCaption( tr("Gutenbrowser"));
1210 i_pageNum = 0;
1211 enableButtons(false);
1212
1213 if(!showMainList) {
1214 Lview->hide();
1215 showMainList=TRUE;
1216 mainList->show();
1217 fillWithTitles();
1218 qApp->processEvents();
1219 }
1220 if(donateMenu->idAt(3) != -1)
1221 donateMenu->removeItemAt(3);
1222}
1223
1224
1225bool Gutenbrowser::getTitle( const char *file ) {
1226 QString s_file;
1227 QString filer = file;
1228 if( filer.contains(local_library, TRUE)) {
1229 QFileInfo f(file);
1230 s_file = f.fileName();
1231 } else {
1232 s_file = filer;
1233 }
1234 Config config("Gutenbrowser");
1235 config.setGroup( "Files" );
1236 QString s_numofFiles = config.readEntry("NumberOfFiles", "0" );
1237 int i_numofFiles = s_numofFiles.toInt();
1238
1239 for (int i = 1; i <= i_numofFiles; i++) {
1240 QString temp;
1241 temp.setNum(i);
1242 QString ramble = config.readEntry(temp, "" );
1243
1244 if( strcmp(ramble, s_file) == 0) {
1245 config.setGroup( "Titles" );
1246 title = config.readEntry(ramble, "");
1247 // qDebug("(getTitle)title is being set as "+title);
1248 }
1249 }
1250 return true;
1251}
1252
1253void Gutenbrowser::searchdone_slot() {
1254 // if (!searchDlg)
1255 // return;
1256 // searchDlg->hide();
1257 // Lview->setFocus();
1258 this->setFocus();
1259 last_search = 0;
1260 // ResizeEdits();
1261}
1262
1263 /*
1264 sets the status message */
1265bool Gutenbrowser::setStatus() {
1266
1267#ifndef Q_WS_QWS
1268 QString s_pages;
1269 s_pages.setNum( pages);
1270 QString chNum;
1271 statusTop = status.left( status.find(" ", TRUE) );
1272 status.append(chNum.setNum( i_pageNum));
1273 status += " / " + s_pages;
1274
1275 if(loadCheck) {
1276 statusBar->message( status);
1277 InfoBar->setText( title);
1278 } else {
1279 }
1280#else
1281 QString msg;
1282 msg.sprintf(title+" %d", i_pageNum);
1283 setCaption( msg);
1284#endif
1285 return true;
1286}
1287
1288void Gutenbrowser::keyReleaseEvent( QKeyEvent *e) {
1289 switch ( e->key() ) {
1290
1291 case Key_M:
1292 // Bookmark();
1293 break;
1294 case Key_D:
1295 DownloadIndex();
1296 break;
1297 case Key_L:
1298 LibraryBtn();
1299 break;
1300 case Key_O:
1301 OpenBtn();
1302 break;
1303 case Key_F:
1304 ForwardBtn();
1305 break;
1306 case Key_B:
1307 BackBtn();
1308 break;
1309 case Key_P:
1310 PrintBtn();
1311 break;
1312 case Key_S:
1313 SearchBtn();
1314 break;
1315 case Key_E:
1316 ByeBye();
1317 break;
1318 case Key_R:
1319 // setBookmark();
1320 break;
1321 case Key_T:
1322 ChangeFont();
1323 break;
1324 case Key_C:
1325 ClearEdit();
1326 break;
1327 case Key_H:
1328 HelpBtn();
1329 break;
1330 case Key_K:
1331 LookupBtn();
1332 break;
1333 case Key_U:// hide menu
1334 if(menubar->isHidden() )
1335 menubar->show();
1336 else
1337 menubar->hide();
1338 break;
1339 case Key_I:
1340 hideButtons();
1341 break;
1342 ////////////////////////////// Zaurus keys
1343 case Key_Home:
1344 // BeginBtn();
1345 break;
1346 case Key_F9: //activity
1347 OpenBtn();
1348 break;
1349 case Key_F10: //contacts
1350 hideButtons();
1351 break;
1352 case Key_F11: //menu
1353 if(menubar->isHidden() )
1354 menubar->show();
1355 else
1356 menubar->hide();
1357 break;
1358 case Key_F12: //home
1359 BeginBtn();
1360 break;
1361 case Key_F13: //mail
1362 LibraryBtn();
1363 break;
1364 case Key_Space:
1365 if(loadCheck)
1366 ForwardBtn();
1367 // else
1368 // Bookmark();
1369 break;
1370 case Key_Down:
1371 if(loadCheck) {
1372 // if( !e->isAutoRepeat() )
1373 // AdjustStatus();
1374 // } else {
1375 // LibraryBtn();
1376 // ForwardBtn();
1377 }
1378
1379 // ForwardButton->setFocus();
1380 // Lview->setFocus();
1381 // if(s_Wrap=="FALSE")
1382 // Lview->MultiLine_Ex::ScrollDown( 1);
1383 // LibraryBtn();
1384 break;
1385 case Key_Up:
1386 if(loadCheck) {
1387 // if( !e->isAutoRepeat() )
1388 // AdjustStatus();
1389 // } else {
1390 // OpenBtn();
1391 // BackBtn();
1392 }
1393 // BackButton->setFocus();
1394 // Lview->setFocus();
1395 // if(s_Wrap=="FALSE")
1396 // Lview->MultiLine_Ex::ScrollUp( 1);
1397
1398 // LibraryBtn();
1399 break;
1400 case Key_Right:
1401 ForwardButton->setFocus();
1402 ForwardBtn();
1403 // LibraryBtn();
1404 break;
1405 case Key_Left:
1406 BackBtn();
1407 BackButton->setFocus();
1408 // OpenBtn();
1409 break;
1410 case Key_Escape:
1411 ByeBye();
1412 break;
1413 case Key_PageUp:
1414 BackBtn();
1415 break;
1416 case Key_PageDown:
1417 ForwardBtn();
1418 break;
1419
1420 ////////////////////////////// Zaurus keys
1421 };
1422}
1423
1424void Gutenbrowser::keyPressEvent( QKeyEvent *e) {
1425 switch ( e->key() ) {
1426 // case Key_Next:
1427 // ForwardBtn();
1428 // break;
1429 // case Key_Prior:
1430 // BackBtn();
1431 // break;
1432 // case Key_Space:
1433 // ForwardBtn();
1434 // break;
1435 // case Key_Down:
1436 // Lview->MultiLine_Ex::ScrollUp( 1);
1437 // if(useSplitter) Rview->MultiLine_Ex::ScrollUp( 1);
1438 // break;
1439 // case Key_Up:
1440 // if( Lview->Top() != 0) {
1441 // Lview->MultiLine_Ex::ScrollDown( 1);
1442 // if(useSplitter) Rview->MultiLine_Ex::ScrollDown( 1);
1443 // }
1444 // break;
1445 }
1446}
1447
1448void Gutenbrowser::resizeEvent( QResizeEvent *ev) {
1449 // qDebug("resize: %d,%d\n",ev->size().width(),ev->size().height());
1450
1451 if( !LibraryDlg->isHidden())
1452 LibraryDlg->resize(ev->size().width(),ev->size().height() );
1453
1454 // if( loadCheck == true) {
1455 // ResizeEdits();
1456 // AdjustStatus();
1457 // }
1458}
1459
1460
1461void Gutenbrowser::doOptions() {
1462 optionsDialog* optDlg;
1463 optDlg = new optionsDialog( this,"Options_Dlg", true);
1464 QString Ddir;
1465 Config config("Gutenbrowser");
1466 config.setGroup( "General" );
1467 QFont myFont;
1468 optDlg->showMaximized();
1469
1470 if( optDlg->exec() !=0) {
1471 qApp->processEvents();
1472 brow=optDlg->browserName;
1473 toggleButtonIcons( optDlg->useIcon);
1474 ftp_host= optDlg->ftp_host;
1475 ftp_base_dir= optDlg->ftp_base_dir;
1476 brow=optDlg->browserName;
1477 Ddir=optDlg->downloadDirEdit->text();
1478
1479 qDebug("writing library config");
1480 Config config("Gutenbrowser");
1481 config.setGroup("General");
1482
1483 QString dirname= optDlg->downloadDirEdit->text();
1484 if(dirname.right(1)!="/")
1485 dirname+="/";
1486 config.writeEntry( "DownloadDirectory",dirname);
1487 QDir newDir( optDlg->downloadDirEdit->text());
1488
1489 if( !newDir.exists() ) {
1490 int exit=QMessageBox::information(this, "Note", "Ok, to make a new directory\n"+Ddir+" ?",
1491 QMessageBox::Ok, QMessageBox::Cancel);
1492 if (exit==1) {
1493 QString cmd="mkdir -p ";
1494 cmd+=Ddir.latin1();
1495 system(cmd);
1496 qDebug("Making new dir "+cmd);
1497 if(Ddir.right(1)!="/") {
1498 Ddir+="/";
1499 }
1500 config.writeEntry("DownloadDirectory",Ddir);
1501 }
1502 }
1503
1504// if(optDlg->styleChanged)
1505// setStyle( optDlg->styleInt);
1506 if(optDlg->b_qExit==TRUE)
1507 b_queryExit=TRUE;
1508 else
1509 b_queryExit=FALSE;
1510
1511 if(optDlg->fontDlg-> changedFonts) {
1512 qDebug("Setting font");
1513 myFont=optDlg->fontDlg->selectedFont;
1514 Lview->setFont( myFont);
1515 }
1516
1517 if(optDlg->useWordWrap_CheckBox->isChecked() ) {
1518 qDebug("WORD WRAP is set");
1519 Lview->setWordWrap(QMultiLineEdit::WidgetWidth);
1520 useWrap=true;
1521 } else {
1522 qDebug("Word wrap is NOT set");
1523 Lview->setWordWrap(QMultiLineEdit::NoWrap);
1524 useWrap=false;
1525 }
1526 }
1527 if(showMainList) {
1528 if(!Lview->isHidden())
1529 Lview->hide();
1530 qApp->processEvents();
1531 if(mainList->isHidden())
1532 mainList->show();
1533 fillWithTitles();
1534 } else {
1535 Lview->show();
1536 showMainList=FALSE;
1537 mainList->hide();
1538 }
1539 qApp->processEvents();
1540 update();
1541}
1542
1543bool Gutenbrowser::setTitle() {
1544 if( file_name.contains( local_library)) {
1545 QFileInfo f( file_name);
1546 QString s_file = f.fileName();
1547 file_name = s_file;
1548 }
1549
1550 int test = 0;
1551 Config config("Gutenbrowser");
1552 config.setGroup( "Files" );
1553 QString s_numofFiles = config.readEntry("NumberOfFiles", "0" );
1554 int i_numofFiles = s_numofFiles.toInt();
1555
1556 for (int i = 1; i <= i_numofFiles; i++) {
1557 QString temp;
1558 temp.setNum(i);
1559 QString ramble = config.readEntry(temp, "" );
1560
1561 if( strcmp(ramble, file_name) == 0) {
1562 test = 1;
1563 }
1564 }
1565 if (test == 0) {
1566 config.writeEntry("NumberOfFiles",i_numofFiles +1 );
1567 QString interger;
1568 interger.setNum( i_numofFiles +1);
1569 config.writeEntry(interger, file_name);
1570
1571 config.setGroup( "Titles" );
1572 config.writeEntry(file_name,listItemTitle);
1573 }
1574 test = 0;
1575 // config.write();
1576 return true;
1577}
1578 /*Calls new fangled network dialog */
1579void Gutenbrowser::OnNetworkDialog( const QString &/*networkUrl*/, const QString &/*output*/)
1580{
1581 // qDebug(networkUrl);
1582 // qDebug(output);
1583 // #ifndef Q_WS_QWS
1584 // NetworkDialog *NetworkDlg;
1585 // if( networkUrl.length() < 4 ) networkUrl= "http://sailor.gutenberg.org/mirror.sites.html";
1586 // NetworkDlg = new NetworkDialog( this,"Network Protocol Dialog", TRUE, 0, networkUrl, output);
1587 // if( NetworkDlg->exec() != 0 ) {
1588 // }
1589 // if(NetworkDlg)
1590 // delete NetworkDlg;
1591 // #endif
1592}
1593
1594void Gutenbrowser::donateGutenberg()
1595{
1596 int exit=QMessageBox::information(this,"Info", "http://www.gutenberg.org\ndonate@gutenberg.net",
1597 QMessageBox::Ok, QMessageBox::Cancel);
1598
1599 if (exit==1) {
1600 } else {
1601 };
1602}
1603
1604void Gutenbrowser::donateByteMonkie()
1605{
1606}
1607
1608void Gutenbrowser::writeConfig()
1609{
1610 // config.read();
1611 // Config config("Gutenbrowser");
1612 // #ifndef Q_WS_QWS
1613 // config.setGroup( "Geometry" );
1614 // QString s;
1615 // QString globalPosition;
1616 // QPoint point;
1617 // point=mapToGlobal(QPoint(0,0) );
1618 // int posiX, posiY;
1619 // posiX=point.x();
1620 // posiY=point.y();
1621 // globalPosition.sprintf("%i,%i", posiX, posiY);
1622
1623 // QRect frameRect;
1624 // frameRect = geometry();
1625 // s.sprintf("%i,%i", frameRect.width(), frameRect.height());
1626 // config.writeEntry("Frame", s);
1627 // config.writeEntry("Position", globalPosition);
1628
1629 // if( useIcons==TRUE)
1630 // config.writeEntry("Icons", "TRUE");
1631 // else
1632 // config.writeEntry("Icons", "FALSE");
1633 // #endif
1634
1635 // #ifndef Q_WS_QWS
1636 // QString temp;
1637 // temp.setNum(styleI, 10);
1638 // config.setGroup( "StyleIze" );
1639 // config.writeEntry( "Style", temp);
1640 // #endif
1641
1642 // config.setGroup("General");
1643}
1644
1645void Gutenbrowser::annotations()
1646{
1647 // #ifndef Q_WS_QWS
1648 // QMessageBox::message("Note","hi annotate");
1649 // lastBmkButton->setDown(FALSE);
1650 // #endif
1651}
1652
1653void Gutenbrowser::hideButtons()
1654{
1655
1656 if( !buttonsHidden) {
1657 buttonsHidden=TRUE;
1658 LibraryButton->hide();
1659 SearchButton->hide();
1660 InfoBar->hide();
1661 OpenButton->hide();
1662 BackButton->hide();
1663 ForwardButton->hide();
1664 setBookmarkButton->hide();
1665 lastBmkButton->hide();
1666 dictionaryButton->hide();
1667 if(useSplitter) {
1668 ClearButton->hide();
1669 PrintButton->hide();
1670 beginButton->hide();
1671 HelpButton->hide();
1672 FontButton->hide();
1673 ExitButton->hide();
1674 OptionsButton->hide();
1675 DownloadButton->hide();
1676 }
1677 } else {
1678 buttonsHidden=FALSE;
1679
1680 LibraryButton->show();
1681 SearchButton->show();
1682 InfoBar->show();
1683 OpenButton->show();
1684 BackButton->show();
1685 ForwardButton->show();
1686 setBookmarkButton->show();
1687 lastBmkButton->show();
1688 dictionaryButton->show();
1689 if(useSplitter) {
1690 ClearButton->show();
1691 PrintButton->show();
1692 beginButton->show();
1693 HelpButton->show();
1694 FontButton->show();
1695 ExitButton->show();
1696 OptionsButton->show();
1697 DownloadButton->show();
1698 }
1699 }
1700}
1701
1702void Gutenbrowser::focusInEvent( QFocusEvent* )
1703{
1704}
1705void Gutenbrowser::focusOutEvent( QFocusEvent* )
1706{
1707}
1708
1709void Gutenbrowser::cleanUp( )
1710{
1711 writeConfig();
1712 QPEApplication::grabKeyboard();
1713
1714 QPEApplication::ungrabKeyboard();
1715 // qDebug("Cleanup");
1716 if(f.isOpen()) f.close();
1717}
1718
1719void Gutenbrowser::fixKeys()
1720{
1721 qDebug("Attempting to fix keys");
1722
1723}
1724
1725void Gutenbrowser::enableButtons(bool b)
1726{
1727 BackButton->setEnabled(b);
1728 ForwardButton->setEnabled(b);
1729 SearchButton->setEnabled(b);
1730 setBookmarkButton->setEnabled(b);
1731 dictionaryButton->setEnabled(b);
1732 InfoBar->setEnabled(b);
1733
1734 editMenu->setItemEnabled( -5, b);
1735 editMenu->setItemEnabled( -6, b);
1736 editMenu->setItemEnabled( -7, b);
1737 editMenu->setItemEnabled( -8, b);
1738
1739}
1740
1741void Gutenbrowser::fillWithTitles() {
1742 Config config("Gutenbrowser");
1743 config.setGroup( "Files" );
1744 int i_numofFiles = config.readNumEntry("NumberOfFiles", 0);
1745 mainList->clear();
1746 QString temp;
1747 for (int i = 1; i <= i_numofFiles; i++) {
1748 temp.setNum(i);
1749 config.setGroup( "Files" );
1750 QString ramble = config.readEntry(temp, "" );
1751 config.setGroup( "Titles" );
1752 temp = config.readEntry(ramble, "");
1753 if( !temp.isEmpty()) {
1754 mainList->insertItem ( Resource::loadPixmap("gutenbrowser/gutenbrowser_sm"), temp, -1);
1755 }
1756 }
1757}
1758
1759void Gutenbrowser::listClickedSlot( QListBoxItem * index) {
1760 // if( !working) {
1761 // working=true;
1762 if(index) {
1763 // QCopEnvelope ( "QPE/System", "busy()" );
1764 title = index->text();
1765 showMainList=FALSE;
1766 mainList->hide();
1767 Lview->show();
1768 qApp->processEvents();
1769 QString temp;
1770 temp.setNum( mainList->currentItem() + 1);
1771 // openFileTitle = title;
1772 Config config("Gutenbrowser");
1773 config.setGroup( "Files" );
1774 QString file = config.readEntry(temp, "");
1775 qDebug("About to load");
1776 if( Lview->isVisible())
1777 load(file);
1778
1779 config.setGroup( title);
1780 file_name = config.readEntry("File Name", "");
1781 i_pageNum = config.readNumEntry("Page Number", 1);
1782 int Bmrkrow = config.readNumEntry("LineNumber", -1);
1783 if(Bmrkrow > -1) {
1784 if( Bmrkrow > Lview->topRow() ) {
1785 Lview->setCursorPosition( Bmrkrow /* - Lview->topRow() */,0, FALSE );
1786 Lview->ScrollUp( Bmrkrow - Lview->topRow() );
1787 // AdjustStatus();
1788 }
1789 else if( Bmrkrow < Lview->topRow() ) {
1790 Lview->setCursorPosition( Lview->topRow() - Bmrkrow ,0, FALSE );
1791 Lview->ScrollDown( Lview->topRow() - Bmrkrow );
1792 // AdjustStatus();
1793 }
1794 }
1795 }
1796}
1797
1798void Gutenbrowser::infoGutenbrowser() {
1799 QMessageBox::message("Info","Gutenbrowser was developed by\n"
1800 "Lorn Potter\n"
1801 "ljp<ljp@llornkcor.com>\n");
1802}
1803
1804void Gutenbrowser::setDocument(const QString & frozenBoogers) {
1805 this->hide();
1806 if(showMainList) {
1807 showMainList=FALSE;
1808 if(!mainList->isHidden())
1809 mainList->hide();
1810 if(Lview->isHidden())
1811 Lview->show();
1812 qApp->processEvents();
1813 }
1814 DocLnk lnk;
1815 lnk = DocLnk(frozenBoogers);
1816 // qDebug(lnk.file() );
1817 title=lnk.comment();
1818 load( lnk.file());
1819 this->show();
1820 // qDebug(title);
1821 // qApp->processEvents();
1822 // repaint();
1823}
1824
1825void Gutenbrowser::mainListPressed(int mouse, QListBoxItem * , const QPoint & )
1826{
1827 switch (mouse) {
1828 case 1:
1829 break;
1830 case 2: {
1831 QPopupMenu m;// = new QPopupMenu( Local_View );
1832 m.insertItem( tr( "Open" ), this, SLOT( menuOpen() ));
1833 m.insertSeparator();
1834 m.insertItem( tr( "Search google.com" ), this, SLOT( menuGoogle()));
1835 m.insertItem( tr( "Edit Title" ), this, SLOT( menuEditTitle()));
1836 // m.insertSeparator();
1837 // m.insertItem( tr( "Delete" ), this, SLOT( remoteDelete() ));
1838 m.exec( QCursor::pos() );
1839 }
1840 break;
1841 };
1842}
1843
1844void Gutenbrowser::menuOpen() {
1845 listClickedSlot( mainList->item( mainList->currentItem()));
1846}
1847
1848void Gutenbrowser::menuGoogle() {
1849 searchGoogle( mainList->text(mainList->currentItem()));
1850}
1851
1852void Gutenbrowser::searchGoogle( const QString &tempText) {
1853 QString text = tempText;
1854
1855 int eexit=QMessageBox::information(this, "Note","Do you want to search for\n"+text+
1856 "\non google.com?",QMessageBox::Yes, QMessageBox::No);
1857 if (eexit== 3) {
1858 qApp->processEvents();
1859 text.replace( QRegExp("\\s"), "%20");
1860 text.replace( QRegExp("#"), "");
1861 text.replace( QRegExp(","), "%20");
1862 text.replace( QRegExp("'"), "%20");
1863 text.replace( QRegExp("("), "");
1864 text.replace( QRegExp(")"), "");
1865 // text.replace( QRegExp("[0-9]"), "");
1866 QString s_lookup = "http://google.com/search?q="+text+"&num=30&sa=Google+Search";
1867 goGetit( s_lookup, true);
1868 }
1869
1870}
1871
1872void Gutenbrowser::menuEditTitle()
1873{
1874 int currentItem = mainList->currentItem();
1875 QString title_text = mainList->text( currentItem);
1876 //qDebug("Selected "+title_text);
1877
1878 Config config("Gutenbrowser");
1879 config.setGroup( "Files" );
1880 QString s_numofFiles = config.readEntry("NumberOfFiles", "0");
1881 int i_numofFiles = s_numofFiles.toInt();
1882 QString fileNum;
1883 for (int i = 1; i <= i_numofFiles+1; i++) {
1884
1885 fileNum.setNum(i);
1886 config.setGroup( "Files" );
1887 QString s_filename = config.readEntry(fileNum, "" );
1888 config.setGroup( "Titles" );
1889 QString file_title = config.readEntry( s_filename, "");
1890 //qDebug("file_title is "+file_title);
1891 if(title_text == file_title ) {
1892 // selFile = s_filename;
1893 //qDebug("Edit: "+ file_title );
1894 i=i_numofFiles+1;
1895 Edit_Title *titleEdit;
1896 titleEdit = new Edit_Title(this,file_title ,TRUE);
1897 if(titleEdit->exec() !=0) {
1898 //qDebug(titleEdit->newTitle);
1899 config.writeEntry( s_filename, titleEdit->newTitle);
1900 mainList->removeItem(currentItem);
1901 mainList->insertItem ( Resource::loadPixmap("gutenbrowser/gutenbrowser_sm"), titleEdit->newTitle, currentItem);
1902 }
1903 }
1904 }
1905
1906 // getTitles();
1907 mainList->triggerUpdate(true);
1908
1909}
1910
1911
1912
1913bool Gutenbrowser::UnZipIt(const QString &zipFile) {
1914 qDebug(zipFile);
1915#ifndef Q_WS_QWS
1916 if( QFile::exists( zipFile)) { // TODO findsome other way of dealingwithzip files.
1917 bool isPgWhole=false;
1918 QString thatFile;
1919 if(zipFile.find("pgwhole",0,TRUE)) {
1920 isPgWhole=TRUE;
1921 thatFile= local_library +"PGWHOLE.TXT";
1922 }
1923 // else {
1924 // thatFile=zipFile.left(4);
1925 // }
1926 // qDebug((const char*)local_library.latin1());
1927 QString cmd;
1928#if defined(_WS_X11_)
1929 if( chdir((const char*)local_library.latin1())!=0)
1930 qDebug("chdir failed.");
1931 cmd = "gunzip -S .zip " + local_library+zipFile;
1932 //cmd = "gunzip -d " + zipFile /*newestLibraryFile */+" -d " + local_library;
1933#endif
1934#ifdef Q_WS_QWS
1935 if( chdir((const char*)local_library.latin1())!=0)
1936 qDebug("chdir failed.");
1937 cmd = "unzip " + local_library+zipFile;
1938 // cmd = "/usr/bin/unzip -o " + local_library+zipFile +" -d /usr/share/doc/gutenbrowser" ;//+ local_library;
1939#endif
1940 int exit=QMessageBox::information(this, "Ok to unzip?",
1941 "Ok to unnzip\n"+ zipFile+" ?",
1942 QMessageBox::Yes, QMessageBox::No);
1943 if (exit==QMessageBox::Yes) {
1944#if defined(_WS_X11_)//
1945 qDebug("Issuing the command "+cmd);
1946 system( cmd);
1947 if( QFile::exists(thatFile))
1948 remove (thatFile);
1949 if(isPgWhole) {
1950 if( rename("pgwhole","PGWHOLE.TXT") !=0)
1951 qDebug("rename failed");
1952 } else {
1953 if( rename(thatFile.left(4),thatFile.left(4)+".txt") !=0)
1954 qDebug("rename failed");
1955 }
1956#endif
1957#ifdef Q_WS_QWS
1958 qDebug("Issuing the command "+cmd);
1959 system( cmd);
1960 if( QFile::exists(thatFile))
1961 remove(thatFile);
1962 if(isPgWhole) {
1963 if( rename("pgwhole","PGWHOLE.TXT") !=0)
1964 qDebug("rename failed");
1965 } else {
1966 if( rename(thatFile.left(4),thatFile.left(4)+".txt") !=0)
1967 qDebug("rename failed");
1968 }
1969#endif
1970 // remove( zipFile);
1971 return true;
1972 }
1973 else if(exit==QMessageBox::No) {
1974 // qDebug("unzip");
1975 return false;
1976 }
1977 }
1978 else
1979 QMessageBox::message( "Note",( tr("Please install unzip in your PATH")) );
1980#endif
1981 return false;
1982}
1983
1984