summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-gutenbrowser
Unidiff
Diffstat (limited to 'noncore/apps/opie-gutenbrowser') (more/less context) (show whitespace changes)
-rw-r--r--noncore/apps/opie-gutenbrowser/LibraryDialog.cpp12
-rw-r--r--noncore/apps/opie-gutenbrowser/openetext.cpp124
2 files changed, 65 insertions, 71 deletions
diff --git a/noncore/apps/opie-gutenbrowser/LibraryDialog.cpp b/noncore/apps/opie-gutenbrowser/LibraryDialog.cpp
index 6c246e97..7f21ab3 100644
--- a/noncore/apps/opie-gutenbrowser/LibraryDialog.cpp
+++ b/noncore/apps/opie-gutenbrowser/LibraryDialog.cpp
@@ -1,47 +1,47 @@
1/*************************************************************************** 1/***************************************************************************
2// LibraryDialog.cpp - description 2// LibraryDialog.cpp - description
3// ------------------- 3// -------------------
4// begin : Sat Aug 19 2000 4// begin : Sat Aug 19 2000
5// copyright : (C) 2000 - 2004 by llornkcor 5// copyright : (C) 2000 - 2004 by llornkcor
6// email : ljp@llornkcor.com 6// email : ljp@llornkcor.com
7// ***************************************************/ 7// ***************************************************/
8// /*************************************************************************** 8// /***************************************************************************
9// * This program is free software; you can redistribute it and/or modify * 9// * This program is free software; you can redistribute it and/or modify *
10// * it under the terms of the GNU General Public License as published by * 10// * it under the terms of the GNU General Public License as published by *
11// * the Free Software Foundation; either version 2 of the License, or * 11// * the Free Software Foundation; either version 2 of the License, or *
12// * (at your option) any later version. * 12// * (at your option) any later version. *
13// ***************************************************************************/ 13// ***************************************************************************/
14//ftp://ibiblio.org/pub/docs/books/gutenberg/GUTINDEX.ALL 14//ftp://ibiblio.org/pub/docs/books/gutenberg/GUTINDEX.ALL
15 15
16#include "LibraryDialog.h" 16#include "LibraryDialog.h"
17#include "output.h" 17#include "output.h"
18 18
19/* OPIE */ 19/* OPIE */
20#include <qpe/applnk.h> 20#include <qpe/applnk.h>
21#include <qpe/qpeapplication.h> 21#include <qpe/qpeapplication.h>
22#include <qpe/qpedialog.h> 22#include <qpe/qpedialog.h>
23//#include <opie2///odebug.h> 23#include <opie2/odebug.h>
24 24
25/* QT */ 25/* QT */
26#include <qpushbutton.h> 26#include <qpushbutton.h>
27#include <qmultilineedit.h> 27#include <qmultilineedit.h>
28//#include <qlayout.h> 28//#include <qlayout.h>
29 29
30/* STD */ 30/* STD */
31#include <unistd.h> 31#include <unistd.h>
32#include <stdio.h> 32#include <stdio.h>
33#include <stdlib.h> 33#include <stdlib.h>
34 34
35/* 35/*
36 * The dialog will by default be modeless, unless you set 'modal' to 36 * The dialog will by default be modeless, unless you set 'modal' to
37 * true to construct a modal dialog. */ 37 * true to construct a modal dialog. */
38LibraryDialog::LibraryDialog( QWidget* parent, const char* name , bool /*modal*/, WFlags fl ) 38LibraryDialog::LibraryDialog( QWidget* parent, const char* name , bool /*modal*/, WFlags fl )
39 : QDialog( parent, name, true/* modal*/, fl ) 39 : QDialog( parent, name, true/* modal*/, fl )
40{ 40{
41 if ( !name ) 41 if ( !name )
42 setName( "LibraryDialog" ); 42 setName( "LibraryDialog" );
43 indexLoaded=false; 43 indexLoaded=false;
44 initDialog(); 44 initDialog();
45 45
46 // this->setMaximumWidth(240); 46 // this->setMaximumWidth(240);
47 47
@@ -451,76 +451,79 @@ bool LibraryDialog::download_newEtext()
451 networkList.append((const char *)outputFile); //output filepath 451 networkList.append((const char *)outputFile); //output filepath
452 networkList.append((const char *)file); //filename 452 networkList.append((const char *)file); //filename
453 453
454 getEtext( networkList); 454 getEtext( networkList);
455 455
456 return true; 456 return true;
457} 457}
458 458
459bool LibraryDialog::getEtext(const QStringList &networkList) 459bool LibraryDialog::getEtext(const QStringList &networkList)
460{ 460{
461 NetworkDialog *NetworkDlg; 461 NetworkDialog *NetworkDlg;
462 NetworkDlg = new NetworkDialog( this,"Network Protocol Dialog", true, 0, networkList); 462 NetworkDlg = new NetworkDialog( this,"Network Protocol Dialog", true, 0, networkList);
463 463
464// use new, improved, *INSTANT* network-dialog-file-getterer 464// use new, improved, *INSTANT* network-dialog-file-getterer
465 if( NetworkDlg->exec() != 0 ) { 465 if( NetworkDlg->exec() != 0 ) {
466 File_Name = NetworkDlg->localFileName; 466 File_Name = NetworkDlg->localFileName;
467 467
468 qDebug("Just downloaded " + NetworkDlg->localFileName); 468 qDebug("Just downloaded " + NetworkDlg->localFileName);
469 469
470 if(NetworkDlg->successDownload) { 470 if(NetworkDlg->successDownload) {
471 //odebug << "Filename is "+File_Name << oendl; 471 //odebug << "Filename is "+File_Name << oendl;
472 if(File_Name.right(4) == ".txt") { 472 if(File_Name.right(4) == ".txt") {
473 QString s_fileName = File_Name; 473 QString s_fileName = File_Name;
474 s_fileName.replace( s_fileName.length() - 3, 3, "gtn"); 474 s_fileName.replace( s_fileName.length() - 3, 3, "gtn");
475 // s_fileName.replace( s_fileName.length()-3,3,"etx"); 475 if (rename( File_Name.latin1(), s_fileName.latin1()) == 1) {
476 rename( File_Name.latin1(), s_fileName.latin1()); 476 owarn << "Failed to rename " << File_Name.latin1() << " to "
477 << s_fileName.latin1() << oendl;
478 return false;
479 }
480
477 File_Name = s_fileName; 481 File_Name = s_fileName;
478 482
479 //odebug << "Filename is now "+File_Name << oendl; 483 //odebug << "Filename is now "+File_Name << oendl;
480 484
481 } 485 }
482 if(File_Name.length() > 5 ) { 486 if(File_Name.length() > 5 ) {
483 setTitle(); 487 setTitle();
484 QFileInfo fi(File_Name); 488 QFileInfo fi(File_Name);
485 QString name_file = fi.fileName(); 489 QString name_file = fi.fileName();
486 name_file = name_file.left( name_file.length() - 4); 490 name_file = name_file.left( name_file.length() - 4);
487 491
488 //odebug << "Setting doclink" << oendl; 492 //odebug << "Setting doclink" << oendl;
489 DocLnk lnk; 493 DocLnk lnk;
490 //odebug << "name is "+name_file << oendl; 494 //odebug << "name is "+name_file << oendl;
491 lnk.setName(name_file); //sets file name 495 lnk.setName(name_file); //sets file name
492 //odebug << "Title is "+DlglistItemTitle << oendl; 496 //odebug << "Title is "+DlglistItemTitle << oendl;
493 lnk.setComment(DlglistItemTitle); 497 lnk.setComment(DlglistItemTitle);
494 498
495 //odebug << "Filename is "+File_Name << oendl; 499 //odebug << "Filename is "+File_Name << oendl;
496 lnk.setFile(File_Name); //sets File property 500 lnk.setFile(File_Name); //sets File property
497 lnk.setType("guten/plain");// hey is this a REGISTERED mime type?!?!? ;D 501 lnk.setType("guten/plain");// hey is this a REGISTERED mime type?!?!? ;D
498 lnk.setExec(File_Name); 502 lnk.setExec(File_Name);
499 lnk.setIcon("gutenbrowser/Gutenbrowser"); 503 lnk.setIcon("gutenbrowser/Gutenbrowser");
500 if(!lnk.writeLink()) { 504 if(!lnk.writeLink()) {
501 //odebug << "Writing doclink did not work" << oendl; 505 //odebug << "Writing doclink did not work" << oendl;
502 } else {
503 } 506 }
504 } else 507 } else
505 QMessageBox::message("Note","<p>There was an error with the file</p>"); 508 QMessageBox::message("Note","<p>There was an error with the file</p>");
506 } 509 }
507 } 510 }
508 511
509 return true; 512 return true;
510} 513}
511 514
512bool LibraryDialog::download_Etext() 515bool LibraryDialog::download_Etext()
513{ // ftp method 516{ // ftp method
514 // might have to use old gpl'd ftp for embedded!! 517 // might have to use old gpl'd ftp for embedded!!
515 518
516 Config cfg("Gutenbrowser"); 519 Config cfg("Gutenbrowser");
517 cfg.setGroup("FTPsite"); 520 cfg.setGroup("FTPsite");
518 ftp_host = cfg.readEntry("SiteName", "sailor.gutenberg.org"); 521 ftp_host = cfg.readEntry("SiteName", "sailor.gutenberg.org");
519 ftp_base_dir = cfg.readEntry("base", "/pub/gutenberg"); 522 ftp_base_dir = cfg.readEntry("base", "/pub/gutenberg");
520 523
521 qDebug( "about to network dialog"); 524 qDebug( "about to network dialog");
522 525
523 QString NewlistItemNumber, NewlistItemYear, ls_result, result_line, s, dir, /*networkUrl, */outputFile; 526 QString NewlistItemNumber, NewlistItemYear, ls_result, result_line, s, dir, /*networkUrl, */outputFile;
524 527
525 //////////////////// FIXME- if 'x' is part of real name.... 528 //////////////////// FIXME- if 'x' is part of real name....
526 NewlistItemFile = DlglistItemFile.left(DlglistItemFile.find(".xxx", 1, false)).left(DlglistItemFile.left(DlglistItemFile.find(".xxx", 1, false)).find("x", 1, false)); 529 NewlistItemFile = DlglistItemFile.left(DlglistItemFile.find(".xxx", 1, false)).left(DlglistItemFile.left(DlglistItemFile.find(".xxx", 1, false)).find("x", 1, false));
@@ -680,49 +683,48 @@ void LibraryDialog::saveConfig()
680 683
681/* 684/*
682 searches library index for user word*/ 685 searches library index for user word*/
683void LibraryDialog::onButtonSearch() 686void LibraryDialog::onButtonSearch()
684{ 687{
685 ListView1->clearSelection(); 688 ListView1->clearSelection();
686 ListView2->clearSelection(); 689 ListView2->clearSelection();
687 ListView3->clearSelection(); 690 ListView3->clearSelection();
688 ListView4->clearSelection(); 691 ListView4->clearSelection();
689 ListView5->clearSelection(); 692 ListView5->clearSelection();
690 693
691 int curTab = tabWidget->currentPageIndex(); 694 int curTab = tabWidget->currentPageIndex();
692 SearchDialog* searchDlg; 695 SearchDialog* searchDlg;
693 696
694 // if( resultsList) 697 // if( resultsList)
695 searchDlg = new SearchDialog( this, "Library Search", true); 698 searchDlg = new SearchDialog( this, "Library Search", true);
696 searchDlg->setCaption( tr( "Library Search" ) ); 699 searchDlg->setCaption( tr( "Library Search" ) );
697 searchDlg->setLabel( "- author or title"); 700 searchDlg->setLabel( "- author or title");
698 701
699 QString resultString; 702 QString resultString;
700 703
701 int i_berger = 0; 704 int i_berger = 0;
702 if( searchDlg->exec() != 0 ) { 705 if( searchDlg->exec() != 0 ) {
703 QString searcherStr = searchDlg->get_text(); 706 QString searcherStr = searchDlg->get_text();
704 int fluff = 0;
705 707
706 bool cS; 708 bool cS;
707 if( searchDlg->caseSensitiveCheckBox->isChecked()) 709 if( searchDlg->caseSensitiveCheckBox->isChecked())
708 cS = true; //case sensitive 710 cS = true; //case sensitive
709 else 711 else
710 cS = false; 712 cS = false;
711 713
712 etext etextStruct; 714 etext etextStruct;
713 QValueList<etext>::Iterator it; 715 QValueList<etext>::Iterator it;
714 716
715 for( it = etextLibrary.begin(); it != etextLibrary.end(); ++it ) { 717 for( it = etextLibrary.begin(); it != etextLibrary.end(); ++it ) {
716 QString tempTitle = (*it).title; 718 QString tempTitle = (*it).title;
717 QString tempAuthor = (*it).author; 719 QString tempAuthor = (*it).author;
718 QString tempFile = (*it).file; 720 QString tempFile = (*it).file;
719 QString tempYear = (*it).year; 721 QString tempYear = (*it).year;
720 if(tempTitle.find( searcherStr, 0, cS) != -1 722 if(tempTitle.find( searcherStr, 0, cS) != -1
721 || tempAuthor.find( searcherStr, 0, cS) != -1) { 723 || tempAuthor.find( searcherStr, 0, cS) != -1) {
722 qWarning(tempTitle); 724 qWarning(tempTitle);
723 Searchlist.append( tempTitle + " : " + tempYear + " : " + tempFile); 725 Searchlist.append( tempTitle + " : " + tempYear + " : " + tempFile);
724 } 726 }
725 } 727 }
726 728
727 729
728 tabWidget->setCurrentPage( curTab); 730 tabWidget->setCurrentPage( curTab);
diff --git a/noncore/apps/opie-gutenbrowser/openetext.cpp b/noncore/apps/opie-gutenbrowser/openetext.cpp
index 0267416..a5d855d 100644
--- a/noncore/apps/opie-gutenbrowser/openetext.cpp
+++ b/noncore/apps/opie-gutenbrowser/openetext.cpp
@@ -36,217 +36,204 @@ using namespace Opie::Ui;
36#include <stdlib.h> 36#include <stdlib.h>
37#include <sys/stat.h> 37#include <sys/stat.h>
38#endif 38#endif
39 39
40OpenEtext::OpenEtext(QWidget *parent, QString name) : QDialog(parent,name,true) 40OpenEtext::OpenEtext(QWidget *parent, QString name) : QDialog(parent,name,true)
41{ 41{
42 local_library = (QDir::homeDirPath ()) +"/Applications/gutenbrowser/"; 42 local_library = (QDir::homeDirPath ()) +"/Applications/gutenbrowser/";
43 local_index=local_library+"GUTINDEX.ALL"; 43 local_index=local_library+"GUTINDEX.ALL";
44 initDialog(); 44 initDialog();
45 connect( QListBox_1, SIGNAL(selected ( int)),this, SLOT(select_title(int)) ); 45 connect( QListBox_1, SIGNAL(selected ( int)),this, SLOT(select_title(int)) );
46 46
47 getTitles(); 47 getTitles();
48} 48}
49 49
50OpenEtext::~OpenEtext() 50OpenEtext::~OpenEtext()
51{ 51{
52} 52}
53 53
54void OpenEtext::getTitles() 54void OpenEtext::getTitles()
55{ 55{
56 QListBox_1->clear(); 56 QListBox_1->clear();
57 Config config("Gutenbrowser"); 57 Config config("Gutenbrowser");
58 config.setGroup( "Files" ); 58 config.setGroup( "Files" );
59 s_numofFiles = config.readEntry("NumberOfFiles", "0"); 59 s_numofFiles = config.readEntry("NumberOfFiles", "0");
60 QLabel_1->setText( tr( 60 QLabel_1->setText( tr( s_numofFiles+" etexts in your library." ) );
61 s_numofFiles+" etexts in your library."));
62 int i_numofFiles = s_numofFiles.toInt(); 61 int i_numofFiles = s_numofFiles.toInt();
63 for (int i = 1; i <= i_numofFiles+1; i++) { 62 for (int i = 1; i <= i_numofFiles+1; i++) {
64 QString temp; 63 QString temp;
65 temp.setNum(i); 64 temp.setNum(i);
66 config.setGroup( "Files" ); 65 config.setGroup( "Files" );
67 QString ramble = config.readEntry(temp, "" ); 66 QString ramble = config.readEntry(temp, "" );
68 config.setGroup( "Titles" ); 67 config.setGroup( "Titles" );
69 title = config.readEntry(ramble, ""); 68 title = config.readEntry(ramble, "");
70 if( !title.isEmpty()) { 69 if( !title.isEmpty()) {
71 QListBox_1->insertItem ( QPixmap( QPEApplication::qpeDir()+"pics/gutenbrowser/gutenbrowser_sm.png"), title, -1); 70 QListBox_1->insertItem ( QPixmap(
71 QPEApplication::qpeDir() +
72 "pics/gutenbrowser/gutenbrowser_sm.png"
73 ),
74 title,
75 -1);
72 } 76 }
73 } 77 }
74} 78}
75 79
76/* 80/*
77 opens selected title */ 81 opens selected title */
78void OpenEtext::OpenTitle() 82void OpenEtext::OpenTitle()
79{ 83{
80 if( QListBox_1->currentItem() != -1) 84 if( QListBox_1->currentItem() != -1)
81 select_title( QListBox_1->currentItem() ); 85 select_title( QListBox_1->currentItem() );
82 else { 86 else {
83 QString sMsg; 87 QString sMsg;
84 sMsg = "You must select an Etext to open"; 88 sMsg = "You must select an Etext to open";
85 QMessageBox::message( "Error",sMsg); 89 QMessageBox::message( "Error",sMsg);
86 } 90 }
87} 91}
88 92
89void OpenEtext::select_title(int index ) 93void OpenEtext::select_title(int index )
90{ 94{
91 OpenButton->setDown(TRUE); 95 OpenButton->setDown(TRUE);
92 QString temp; 96 QString temp;
93 temp.setNum( index + 1); 97 temp.setNum( index + 1);
94 const char * title; 98 const char * title;
95 title = QListBox_1->text( index ); 99 title = QListBox_1->text( index );
96 openFileTitle = title; 100 openFileTitle = title;
97 Config config("Gutenbrowser"); 101 Config config("Gutenbrowser");
98 config.setGroup( "Files" ); 102 config.setGroup( "Files" );
99 file = config.readEntry(temp, ""); 103 file = config.readEntry(temp, "");
100 OpenEtext::accept(); 104 OpenEtext::accept();
101} 105}
102 106
103/* 107/*!
104 This function imports already existing etexts into the local library list*/ 108 * This function imports already existing etexts into the local library list
109 */
105void OpenEtext::open() 110void OpenEtext::open()
106{ 111{
107OpenFileButton->setDown(TRUE); 112OpenFileButton->setDown(TRUE);
108 title = ""; 113 title = "";
109 QString currDir=""; 114 QString currDir="";
110 QString filer; 115 QString filer;
111 QString name_file; 116 QString name_file;
112 QString local ; 117 QString local ;
113 local = (QDir::homeDirPath () +"Applications/gutenbrowser"); 118 local = (QDir::homeDirPath () +"Applications/gutenbrowser");
114 QDir library( local); 119 QDir library( local);
115 120
116// fileBrowser *browseForFiles;
117// browseForFiles=new fileBrowser(this,"Browse for File", TRUE, 0, "guten/plain;text/plain");
118// // browseForFiles=new fileBrowser(this,"fileBrowser",TRUE,0, "*");
119// browseForFiles->setFileView( 0);
120// browseForFiles->showMaximized();
121// browseForFiles->exec();
122// QString selFile= browseForFiles->selectedFileName;
123// fileList=browseForFiles->fileList;
124 Config cfg("Gutenbrowser"); 121 Config cfg("Gutenbrowser");
125 cfg. setGroup ( "View" ); 122 cfg. setGroup ( "View" );
126 QString dir = cfg.readEntry("LastOpenDirectory", QPEApplication::documentDir()); 123 QString dir = cfg.readEntry("LastOpenDirectory", QPEApplication::documentDir());
127 QMap<QString, QStringList> map; 124 QMap<QString, QStringList> map;
128 map.insert(tr("All"), QStringList() ); 125 map.insert(tr("All"), QStringList() );
129 QStringList text; 126 QStringList text;
130 text << "text/*"; 127 text << "text/*";
131 map.insert(tr("Text"), text ); 128 map.insert(tr("Text"), text );
132 text << "*"; 129 text << "*";
133 map.insert(tr("All"), text ); 130 map.insert(tr("All"), text );
134 131
135 QString str = OFileDialog::getOpenFileName( 2, dir , QString::null, map); 132 QString str = OFileDialog::getOpenFileName( 2, dir , QString::null, map);
136 133
137 if( !str.isEmpty() && QFile(str).exists() && !QFileInfo(str).isDir() ) { 134 if( !str.isEmpty() && QFile(str).exists() && !QFileInfo(str).isDir() ) {
138 filer = str; 135 filer = str;
139 136
140 odebug << "Open file: "+str << oendl; 137 odebug << "Open file: "+str << oendl;
141 138
142 // QStringList::ConstIterator f; 139 if( filer.right(4) == ".txt" ||
143// QString fileTemp; 140 filer.right(4) == ".TXT" ||
144// for ( f = fileList.begin(); f != fileList.end(); f++ ) { 141 filer.right(4) == ".etx" ||
145// fileTemp = *f; 142 filer.right(4) == ".ETX" ||
146// fileTemp.right( fileTemp.length()-5); 143 filer.right(4) == ".etx" ||
147// fileName = fileTemp; 144 filer.right(4) == ".ETX" ||
148// if( !fileName.isEmpty() ){ 145 filer.right(4) == ".zip" ||
149// filer = fileName; 146 filer.right(4) == ".ZIP" )
150// } else { //filename is empty 147 {
151// // QString sMsg;
152// // sMsg = "Error opening library filelist "+fileName;
153// }
154
155 if( filer.right(4) == ".txt"
156 || filer.right(4) == ".TXT"
157 || filer.right(4) == ".etx"
158 || filer.right(4) == ".ETX"
159 || filer.right(4) == ".etx"
160 || filer.right(4) == ".ETX"
161 || filer.right(4) == ".zip"
162 || filer.right(4) == ".ZIP" ) {
163 QFileInfo zipFile( filer); 148 QFileInfo zipFile( filer);
164 QString s_fileName = zipFile.fileName(); 149 QString s_fileName = zipFile.fileName();
165 QString cmd; 150 QString cmd;
166 151
167 if( s_fileName.right(4) == ".zip") { // unzip that sucker.... 152 if( s_fileName.right(4) == ".zip") { // unzip the file
168 s_fileName = s_fileName.left( s_fileName.length() - 4); 153 s_fileName = s_fileName.left( s_fileName.length() - 4);
169 if( chdir((const char*)local_library.latin1())!=0) 154 if( chdir((const char*)local_library.latin1())!=0)
170 odebug << "chdir failed." << oendl; // QString cmd = "gunzip -d " + filer + " -d " + local_library; 155 odebug << "chdir failed." << oendl;
171 cmd = "gunzip -S .zip " + filer; 156 cmd = "gunzip -S .zip " + filer;
172 fileName = local_library + s_fileName + ".txt"; 157 fileName = local_library + s_fileName + ".txt";
173 system( cmd); 158 system( cmd);
174 } 159 } else { // else rename .txt to .etx
175// this renames the .txt to .etx!!
176 else /*if( s_fileName.right(4) == ".txt" || if( s_fileName.right(4) == ".TXT"))*/ {
177// odebug << "Filename is "+fileName << oendl; 160// odebug << "Filename is "+fileName << oendl;
178 s_fileName = fileName; 161 s_fileName = fileName;
179 s_fileName.replace( s_fileName.length()-3,3,"gtn");// s_fileName.replace( s_fileName.length()-3,3,"etx"); 162 s_fileName.replace( s_fileName.length()-3,3,"gtn");
180 rename(fileName.latin1(),s_fileName.latin1()); 163 if (rename(fileName.latin1(),s_fileName.latin1()) == -1)
164 owarn << "Rename of " << fileName.latin1() << " to "
165 << s_fileName.latin1() << " failed" << oendl;
181 fileName = s_fileName; 166 fileName = s_fileName;
182// odebug << "Filename is now "+fileName << oendl; 167// odebug << "Filename is now "+fileName << oendl;
183 } 168 }
184 } else 169 } else
185 fileName = str; 170 fileName = str;
186 171
187 FindTitle(fileName); 172 FindTitle(fileName);
188 173
189 QFileInfo fi( fileName); 174 QFileInfo fi( fileName);
190 name_file = fi.fileName(); 175 name_file = fi.fileName();
191 name_file = name_file.left(name_file.length() - 4); 176 name_file = name_file.left(name_file.length() - 4);
192 177
193 odebug << "Setting doclink" << oendl; 178 odebug << "Setting doclink" << oendl;
194 DocLnk lnk; 179 DocLnk lnk;
195 odebug << "name is " + name_file << oendl; 180 odebug << "name is " + name_file << oendl;
196 lnk.setName(name_file); //sets file name 181 lnk.setName(name_file); //sets file name
197 odebug << "Title is "+title << oendl; 182 odebug << "Title is "+title << oendl;
198 lnk.setComment(title); 183 lnk.setComment(title);
199 184
200 QListBox_1->clear(); 185 QListBox_1->clear();
201 getTitles(); 186 getTitles();
202 odebug << "Filename is "+fileName << oendl; 187 odebug << "Filename is "+fileName << oendl;
203 lnk.setFile(fileName); //sets File property 188 lnk.setFile(fileName); //sets File property
204 lnk.setType("guten/plain");// hey is this a REGISTERED mime type?!?!? ;D 189 // @bug This is probably not a registered MIME type. Perhaps we should
190 // set a valid MIME type here instead. Or maybe register .etx as a
191 // Gutenberge etext?
192 lnk.setType("guten/plain");
205 lnk.setExec(fileName); 193 lnk.setExec(fileName);
206 lnk.setIcon("gutenbrowser/Gutenbrowser"); 194 lnk.setIcon("gutenbrowser/Gutenbrowser");
207 if(!lnk.writeLink()) 195 if(!lnk.writeLink())
208 odebug << "Writing doclink did not work" << oendl; 196 odebug << "Writing doclink did not work" << oendl;
209 197
210 } // end of for each file name.... 198 } // end of for each file name....
211 OpenFileButton->setDown(FALSE); 199 OpenFileButton->setDown(FALSE);
212} 200}
213 201
214/* 202/*
215find the title in the config file */ 203find the title in the config file */
216bool OpenEtext::FindTitle( QString filename) 204bool OpenEtext::FindTitle( QString filename)
217{ 205{
218 Config config("Gutenbrowser"); 206 Config config("Gutenbrowser");
219 config.setGroup( "Files" ); 207 config.setGroup( "Files" );
220 QString s_numofFiles = config.readEntry("NumberOfFiles", "0"); 208 QString s_numofFiles = config.readEntry("NumberOfFiles", "0");
221 int i_numofFiles = s_numofFiles.toInt(); 209 int i_numofFiles = s_numofFiles.toInt();
222 210
223 QFileInfo fi(filename); 211 QFileInfo fi(filename);
224 name = fi.fileName(); 212 name = fi.fileName();
225 odebug << "filename to open is " + name << oendl; 213 odebug << "filename to open is " + name << oendl;
226 QFile indexLib( filename); 214 QFile indexLib( filename);
227 bool findCheck = FALSE; 215 bool findCheck = FALSE;
228 // int Titlenumber=0;
229 216
230 if ( indexLib.open( IO_ReadOnly) ) { 217 if ( indexLib.open( IO_ReadOnly) ) {
231 odebug << "file opened successfully" << oendl; 218 odebug << "file opened successfully" << oendl;
232 QTextStream indexStream( &indexLib ); 219 QTextStream indexStream( &indexLib );
233 QString target = "Project Gutenberg Etext of"; 220 QString target = "Project Gutenberg Etext of";
234 QString target2 = "Project Gutenberg Etext"; 221 QString target2 = "Project Gutenberg Etext";
235 QString target3 = "Project Gutenberg's Etext of"; 222 QString target3 = "Project Gutenberg's Etext of";
236 QString target4 = "Project Gutenberg's Etext"; 223 QString target4 = "Project Gutenberg's Etext";
237 QString indexLine; 224 QString indexLine;
238 while ( !indexStream.eof() ) { 225 while ( !indexStream.eof() ) {
239 // until end of file.. 226 // until end of file..
240 indexLine = indexStream.readLine(); 227 indexLine = indexStream.readLine();
241 if( indexLine.find(target, 0, TRUE) > -1 && !findCheck) {findCheck = TRUE; 228 if( indexLine.find(target, 0, TRUE) > -1 && !findCheck) {findCheck = TRUE;
242 title = indexLine.mid( indexLine.find(target, 0, TRUE) + (target.length()) , indexLine.find("\r", 0, TRUE)); 229 title = indexLine.mid( indexLine.find(target, 0, TRUE) + (target.length()) , indexLine.find("\r", 0, TRUE));
243 title = title.left( title.find( "*",0, TRUE)); 230 title = title.left( title.find( "*",0, TRUE));
244 title = title.stripWhiteSpace (); 231 title = title.stripWhiteSpace ();
245// odebug << "Found the title 1 and it is " << title << "" << oendl; 232// odebug << "Found the title 1 and it is " << title << "" << oendl;
246// QListBox_1->insertItem ( title); 233// QListBox_1->insertItem ( title);
247 } 234 }
248 if( indexLine.find( target2, 0, TRUE) > -1 && !findCheck) { 235 if( indexLine.find( target2, 0, TRUE) > -1 && !findCheck) {
249 findCheck = TRUE; 236 findCheck = TRUE;
250 title = indexLine.mid( indexLine.find( target2, 0, TRUE ) + ( target2.length()) , indexLine.find("\r", 0, TRUE) ); 237 title = indexLine.mid( indexLine.find( target2, 0, TRUE ) + ( target2.length()) , indexLine.find("\r", 0, TRUE) );
251 title = title.left( title.find( "*",0, TRUE)); 238 title = title.left( title.find( "*",0, TRUE));
252 title = title.stripWhiteSpace (); 239 title = title.stripWhiteSpace ();
@@ -256,266 +243,271 @@ bool OpenEtext::FindTitle( QString filename)
256 if( indexLine.find( target3, 0, TRUE) > -1 && !findCheck) { 243 if( indexLine.find( target3, 0, TRUE) > -1 && !findCheck) {
257 findCheck = TRUE; 244 findCheck = TRUE;
258 title = indexLine.mid( indexLine.find( target3, 0, TRUE) + ( target3.length()) , indexLine.find("\r", 0, TRUE)); 245 title = indexLine.mid( indexLine.find( target3, 0, TRUE) + ( target3.length()) , indexLine.find("\r", 0, TRUE));
259 title = title.left( title.find( "*",0, TRUE)); 246 title = title.left( title.find( "*",0, TRUE));
260 title = title.stripWhiteSpace (); 247 title = title.stripWhiteSpace ();
261// odebug << "Found the title 3 and it is " << title << "" << oendl; 248// odebug << "Found the title 3 and it is " << title << "" << oendl;
262 } 249 }
263 if( indexLine.find( target4, 0, TRUE) > -1 && !findCheck) { 250 if( indexLine.find( target4, 0, TRUE) > -1 && !findCheck) {
264 findCheck = TRUE; 251 findCheck = TRUE;
265 title = indexLine.mid( indexLine.find( target4, 0, TRUE) + ( target4.length()) , indexLine.find("\r", 0, TRUE)); 252 title = indexLine.mid( indexLine.find( target4, 0, TRUE) + ( target4.length()) , indexLine.find("\r", 0, TRUE));
266 title = title.left( title.find( "*",0, TRUE)); 253 title = title.left( title.find( "*",0, TRUE));
267 title = title.stripWhiteSpace (); 254 title = title.stripWhiteSpace ();
268// odebug << "Found the title 4 and it is " << title << "" << oendl; 255// odebug << "Found the title 4 and it is " << title << "" << oendl;
269 } 256 }
270 } //endof file 257 } //endof file
271 indexLib.close(); 258 indexLib.close();
272 259
273 if( !findCheck || title.length() < 2) { 260 if( !findCheck || title.length() < 2) {
274 odebug << "Trying hard to find title from GUTINDEX.ALL" << oendl; 261 odebug << "Trying hard to find title from GUTINDEX.ALL" << oendl;
275 title = titleFromLibrary( filename); 262 title = titleFromLibrary( filename);
276 findCheck = TRUE; 263 findCheck = TRUE;
277 } 264 }
278 265
279 if ( checkConf() == false && findCheck == TRUE) { 266 if ( checkConf() == false && findCheck == TRUE) {
280
281 config.setGroup( "Files"); 267 config.setGroup( "Files");
282 config.writeEntry("NumberOfFiles",i_numofFiles + 1 ); 268 config.writeEntry("NumberOfFiles",i_numofFiles + 1 );
283 QString interger; 269 QString interger;
284 interger.setNum( i_numofFiles +1); 270 interger.setNum( i_numofFiles +1);
285 config.writeEntry(interger, filename); 271 config.writeEntry(interger, filename);
286 config.setGroup( "Titles" ); 272 config.setGroup( "Titles" );
287 for (int i = 1; i <= i_numofFiles; i++) { //find dup titles in config file 273 for (int i = 1; i <= i_numofFiles; i++) { //find dup titles in config file
288 QString temp; 274 QString temp;
289 temp.setNum(i); 275 temp.setNum(i);
290 config.setGroup( "Files" ); 276 config.setGroup( "Files" );
291 QString ramble = config.readEntry(temp, "" ); 277 QString ramble = config.readEntry(temp, "" );
292 config.setGroup( "Titles" ); 278 config.setGroup( "Titles" );
293 QString title1 = config.readEntry(ramble, ""); 279 QString title1 = config.readEntry(ramble, "");
294 if(title1==title) 280 if(title1==title)
295 title+="1"; 281 title+="1";
296 i= i_numofFiles+1; 282 i= i_numofFiles+1;
297 } 283 }
298 if(title.length()<3) { 284 if(title.length()<3) {
299// odebug << "title is empty" << oendl; 285// odebug << "title is empty" << oendl;
300 title="Unknown"; 286 title="Unknown";
301 } 287 }
302 config.writeEntry( filename,title); 288 config.writeEntry( filename,title);
303 } 289 }
304 } else { 290 } else {
305 QString sMsg; 291 QString sMsg;
306 sMsg = "Error opening library file: "+filename; 292 sMsg = "Error opening library file: "+filename;
307 printf( sMsg+"\n"); 293 printf( sMsg+"\n");
308 } 294 }
309 return true; 295 return true;
310} 296}
311 297
312QString OpenEtext::titleFromLibrary( QString fileName) 298QString OpenEtext::titleFromLibrary( QString fileName)
313{ 299{
314 QFile indexLib( local_index); 300 QFile indexLib( local_index);
315 QString target; 301 QString target;
316 int find1 = fileName.findRev("/",-1,TRUE) + 1; 302 int find1 = fileName.findRev("/",-1,TRUE) + 1;
317 int find2 = fileName.findRev(".gtn",-1,TRUE) - find1; 303 int find2 = fileName.findRev(".gtn",-1,TRUE) - find1;
318 if(find2==-1-find1) 304 if(find2== (-1-find1))
319 int find2 = fileName.findRev(".etx",-1,TRUE) - find1; 305 find2 = fileName.findRev(".etx",-1,TRUE) - find1;
320 else if(find2==-1-find1) 306 else if(find2==(-1-find1))
321 int find2 = fileName.findRev(".txt",-1,TRUE) - find1; 307 find2 = fileName.findRev(".txt",-1,TRUE) - find1;
322 308
323 target = fileName.mid( find1, find2 ); 309 target = fileName.mid( find1, find2 );
324 QString checker = target.right(1); 310 QString checker = target.right(1);
325 bool ok; 311 bool ok;
326 checker.toInt( &ok,10); 312 checker.toInt( &ok,10);
327 if( ok) { 313 if( ok) {
328 target = target.left( target.length()-1); 314 target = target.left( target.length()-1);
329 checker = target.right(1); 315 checker = target.right(1);
330 ok = FALSE; 316 ok = FALSE;
331 checker.toInt( &ok,10); 317 checker.toInt( &ok,10);
332 if( ok) { 318 if( ok) {
333 target = target.left( target.length()-1); 319 target = target.left( target.length()-1);
334 } 320 }
335 } 321 }
336 if ( indexLib.open( IO_ReadOnly) ) { 322 if ( indexLib.open( IO_ReadOnly) ) {
337 // file opened successfully 323 // file opened successfully
338 QTextStream indexStream( &indexLib ); 324 QTextStream indexStream( &indexLib );
339 QString indexLine; 325 QString indexLine;
340 bool findCheck = FALSE; 326 bool findCheck = FALSE;
341 while ( !indexStream.atEnd() ) { // until end of file.. 327 while ( !indexStream.atEnd() ) { // until end of file..
342 indexLine = indexStream.readLine(); 328 indexLine = indexStream.readLine();
343 329
344 if( indexLine.find( target,0,FALSE) > 0 ) { 330 if( indexLine.find( target,0,FALSE) > 0 ) {
345 findCheck = TRUE; 331 findCheck = TRUE;
346 title = indexLine.mid( 9, 50); 332 title = indexLine.mid( 9, 50);
347// title = indexLine.mid( 26, indexLine.length() );
348 title = title.stripWhiteSpace (); 333 title = title.stripWhiteSpace ();
349// odebug << "Finally Found the title and it is\n " << title << "" << oendl; 334// odebug << "Finally Found the title and it is\n " << title << "" << oendl;
350// QListBox_1->insertItem ( title); 335// QListBox_1->insertItem ( title);
351 } 336 }
352 } //end while loop 337 } //end while loop
353 } 338 }
354 else 339 else
355 odebug << "Error opening library index "+ local_index << oendl; 340 odebug << "Error opening library index "+ local_index << oendl;
356 return title; 341 return title;
357} 342}
358 343
359bool OpenEtext::checkConf() 344bool OpenEtext::checkConf()
360{ 345{
361 QString file = fileName; 346 QString file = fileName;
362 Config config("Gutenbrowser"); 347 Config config("Gutenbrowser");
363 config.setGroup( "Files" ); 348 config.setGroup( "Files" );
364 QString s_numofFiles = config.readEntry("NumberOfFiles", "0" ); 349 QString s_numofFiles = config.readEntry("NumberOfFiles", "0" );
365 int i_numofFiles = s_numofFiles.toInt(); 350 int i_numofFiles = s_numofFiles.toInt();
366 351
367 for (int i = 1; i <= i_numofFiles; i++) { 352 for (int i = 1; i <= i_numofFiles; i++) {
368 QString temp; 353 QString temp;
369 temp.setNum(i); 354 temp.setNum(i);
370 config.setGroup( "Files"); 355 config.setGroup( "Files");
371 QString ramble = config.readEntry(temp, "" ); 356 QString ramble = config.readEntry(temp, "" );
372 357
373 if(ramble == file ) { 358 if(ramble == file ) {
374 return true; 359 return true;
375 } 360 }
376 } 361 }
377 return false; 362 return false;
378} 363}
379 364
380void OpenEtext::remove() 365void OpenEtext::remove()
381{ 366{
382 title_text = QListBox_1->text( QListBox_1->currentItem() ); 367 title_text = QListBox_1->text( QListBox_1->currentItem() );
383 title_text=title_text.stripWhiteSpace(); 368 title_text=title_text.stripWhiteSpace();
384 QString msg ="<p>Do you really want to REMOVE\n" +title_text +"?\nThis will not delete the file.</P>"; 369 QString msg ="<p>Do you really want to REMOVE\n" + title_text +
385 switch( QMessageBox::information( this, (tr("Remove Etext")), 370 "?\nThis will not delete the file.</P>";
386 (tr(msg)), 371 switch( QMessageBox::information( this, tr("Remove Etext"),
387 (tr("&Yes")), (tr("&Cancel")), 0 )){ 372 tr(msg),
373 tr("&Yes"), tr("&Cancel"), 0 ) )
374 {
388 case 0: // Yes clicked, 375 case 0: // Yes clicked,
389 removeSelection(); 376 removeSelection();
390 QListBox_1->clear(); 377 QListBox_1->clear();
391 getTitles(); 378 getTitles();
392 break; 379 break;
393 case 1: // Cancel 380 case 1:
394 break; 381 default:
395 }; 382 }
396} 383}
397 384
398/* 385/*!
399 this removes selected title entry*/ 386 * This removes selected title entry
387 */
400void OpenEtext::removeSelection() 388void OpenEtext::removeSelection()
401{ 389{
402 Config config("Gutenbrowser"); 390 Config config("Gutenbrowser");
403 config.setGroup( "Files" ); 391 config.setGroup( "Files" );
404 s_numofFiles = config.readEntry("NumberOfFiles", "0"); 392 s_numofFiles = config.readEntry("NumberOfFiles", "0");
405 int rem=0; 393 int rem=0;
406 int i_numofFiles = s_numofFiles.toInt(); 394 int i_numofFiles = s_numofFiles.toInt();
407 QString fileNum2; 395 QString fileNum2;
408 QString fileNum; 396 QString fileNum;
409 397
410 for (int i = 1; i <= i_numofFiles; i++) { 398 for (int i = 1; i <= i_numofFiles; i++) {
411 fileNum.setNum(i); 399 fileNum.setNum(i);
412 config.setGroup( "Files" ); 400 config.setGroup( "Files" );
413 401
414 QString s_filename = config.readEntry(fileNum, "" ); 402 QString s_filename = config.readEntry(fileNum, "" );
415 config.setGroup( "Titles" ); 403 config.setGroup( "Titles" );
416 404
417 QString file_title = config.readEntry( s_filename, ""); 405 QString file_title = config.readEntry( s_filename, "");
418 if(title_text == file_title) { 406 if(title_text == file_title) {
419 rem=i; 407 rem=i;
420//odebug << "file title to remove is "+file_title << oendl; 408//odebug << "file title to remove is "+file_title << oendl;
421 selFile = s_filename; 409 selFile = s_filename;
422 config.removeEntry( s_filename); //removes file=title 410 config.removeEntry( s_filename); //removes file=title
423 } 411 }
424 } 412 }
425 config.setGroup( "Files" ); 413 config.setGroup( "Files" );
426 414
427 for(int fg = rem; fg < i_numofFiles ; fg++ ) { //this rewrites Files number entry 415 for(int fg = rem; fg < i_numofFiles ; fg++ ) { //this rewrites Files number entry
428 fileNum.setNum(fg); 416 fileNum.setNum(fg);
429 fileNum2.setNum( fg + 1); 417 fileNum2.setNum( fg + 1);
430 418
431 QString s_filename2 = config.readEntry(fileNum2, "" ); 419 QString s_filename2 = config.readEntry(fileNum2, "" );
432 420
433 if (!s_filename2.isEmpty()) { 421 if (!s_filename2.isEmpty()) {
434 config.writeEntry(fileNum, s_filename2 ); 422 config.writeEntry(fileNum, s_filename2 );
435 } 423 }
436 } 424 }
437 config.writeEntry("NumberOfFiles", i_numofFiles - 1 ); 425 config.writeEntry("NumberOfFiles", i_numofFiles - 1 );
438 config.removeEntry(fileNum2); 426 config.removeEntry(fileNum2);
439// remFile();
440} 427}
441 428
442/* 429/*!
443 removes file title name from list and config file*/ 430 * Removes file title name from list and config file
431 */
444void OpenEtext::remFile() 432void OpenEtext::remFile()
445{ 433{
446 Config config("Gutenbrowser"); 434 Config config("Gutenbrowser");
447 config.setGroup( "Files" ); 435 config.setGroup( "Files" );
448 QString remFile; 436 QString remFile;
449 s_numofFiles = config.readEntry("NumberOfFiles", "0"); 437 s_numofFiles = config.readEntry("NumberOfFiles", "0");
450 int i_numofFiles = s_numofFiles.toInt(); 438 int i_numofFiles = s_numofFiles.toInt();
451 for (int i = 1; i <= i_numofFiles; i++) { 439 for (int i = 1; i <= i_numofFiles; i++) {
452 QString fileNum; 440 QString fileNum;
453 fileNum.setNum(i); 441 fileNum.setNum(i);
454 QString s_filename = config.readEntry(fileNum, "" ); 442 QString s_filename = config.readEntry(fileNum, "" );
455 443
456 if( s_filename == selFile) { 444 if( s_filename == selFile) {
457 config.removeEntry(selFile); 445 config.removeEntry(selFile);
458 446
459 for(int fg = i_numofFiles - i; fg < i_numofFiles ; fg++ ) { //this rewrites Files number entry 447 for(int fg = i_numofFiles - i; fg < i_numofFiles ; fg++ ) { //this rewrites Files number entry
460 QString fileNum2; 448 QString fileNum2;
461 fileNum2.setNum( fg + 1); 449 fileNum2.setNum( fg + 1);
462 QString s_filename2 = config.readEntry(fileNum2, "" ); 450 QString s_filename2 = config.readEntry(fileNum2, "" );
463 451
464 if (!s_filename2.isEmpty()) { 452 if (!s_filename2.isEmpty())
465 config.writeEntry(fileNum, s_filename2 ); 453 config.writeEntry(fileNum, s_filename2 );
466 } 454 }
467 } 455 }
468 } 456 }
469 }
470 config.writeEntry("NumberOfFiles", i_numofFiles - 1 ); 457 config.writeEntry("NumberOfFiles", i_numofFiles - 1 );
471 config.removeEntry(s_numofFiles); 458 config.removeEntry(s_numofFiles);
472 459
473 QListBox_1->triggerUpdate(true); 460 QListBox_1->triggerUpdate(true);
474} 461}
475 462
476/* 463/*!
477sorts the list*/ 464 * Sorts the list
465 */
478void OpenEtext::scan() { 466void OpenEtext::scan() {
479 467
480 QListBox_1->sort(TRUE); 468 QListBox_1->sort(TRUE);
481 QListBox_1->triggerUpdate(true); 469 QListBox_1->triggerUpdate(true);
482} 470}
483 471
484void OpenEtext::editTitle() { 472void OpenEtext::editTitle() {
485 473
486 int currentItem=QListBox_1->currentItem(); 474 int currentItem=QListBox_1->currentItem();
487 QString title_text = QListBox_1->text( currentItem); 475 QString title_text = QListBox_1->text( currentItem);
488//odebug << "Selected "+title_text << oendl; 476//odebug << "Selected "+title_text << oendl;
489 477
490 Config config("Gutenbrowser"); 478 Config config("Gutenbrowser");
491 config.setGroup( "Files" ); 479 config.setGroup( "Files" );
492 s_numofFiles = config.readEntry("NumberOfFiles", "0"); 480 s_numofFiles = config.readEntry("NumberOfFiles", "0");
493 int i_numofFiles = s_numofFiles.toInt(); 481 int i_numofFiles = s_numofFiles.toInt();
494 QString fileNum; 482 QString fileNum;
495 for (int i = 1; i <= i_numofFiles+1; i++) { 483 for (int i = 1; i <= i_numofFiles+1; i++) {
496 484
497 fileNum.setNum(i); 485 fileNum.setNum(i);
498 config.setGroup( "Files" ); 486 config.setGroup( "Files" );
499 QString s_filename = config.readEntry(fileNum, "" ); 487 QString s_filename = config.readEntry(fileNum, "" );
500 config.setGroup( "Titles" ); 488 config.setGroup( "Titles" );
501 QString file_title = config.readEntry( s_filename, ""); 489 QString file_title = config.readEntry( s_filename, "");
502//odebug << "file_title is "+file_title << oendl; 490//odebug << "file_title is "+file_title << oendl;
503 if(title_text == file_title ) { 491 if(title_text == file_title ) {
504 selFile = s_filename; 492 selFile = s_filename;
505//odebug << "Edit: "+ file_title << oendl; 493//odebug << "Edit: "+ file_title << oendl;
506 i=i_numofFiles+1; 494 i=i_numofFiles+1;
507 Edit_Title *titleEdit; 495 Edit_Title *titleEdit;
508 titleEdit = new Edit_Title(this,file_title ,TRUE); 496 titleEdit = new Edit_Title(this,file_title ,TRUE);
509 if(titleEdit->exec() !=0) { 497 if(titleEdit->exec() !=0) {
510//odebug << titleEdit->newTitle << oendl; 498//odebug << titleEdit->newTitle << oendl;
511 config.writeEntry( s_filename, titleEdit->newTitle); 499 config.writeEntry( s_filename, titleEdit->newTitle);
512 QListBox_1->removeItem(currentItem); 500 QListBox_1->removeItem(currentItem);
513 QListBox_1->insertItem ( QPixmap( QPEApplication::qpeDir()+"pics/gutenbrowser/gutenbrowser_sm.png"), titleEdit->newTitle, currentItem); 501 QListBox_1->insertItem (
502 QPixmap( QPEApplication::qpeDir()+
503 "pics/gutenbrowser/gutenbrowser_sm.png"),
504 titleEdit->newTitle, currentItem
505 );
514 } 506 }
515 } 507 }
516 } 508 }
517 509
518// getTitles(); 510// getTitles();
519 QListBox_1->triggerUpdate(true); 511 QListBox_1->triggerUpdate(true);
520} 512}
521 513