author | llornkcor <llornkcor> | 2005-02-28 09:24:10 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2005-02-28 09:24:10 (UTC) |
commit | 61fa699140c5efbb6ba0bf2a62f7e8fbf62976be (patch) (unidiff) | |
tree | 7b3695c8a13d694487011526e3ae052b69b6d5fb | |
parent | 7d4beaf7922f15451da6ba65c2e21fb569887b52 (diff) | |
download | opie-61fa699140c5efbb6ba0bf2a62f7e8fbf62976be.zip opie-61fa699140c5efbb6ba0bf2a62f7e8fbf62976be.tar.gz opie-61fa699140c5efbb6ba0bf2a62f7e8fbf62976be.tar.bz2 |
fix index dl from main view, user 8 bit files by default, do not show audio files
-rw-r--r-- | noncore/apps/opie-gutenbrowser/LibraryDialog.cpp | 1553 | ||||
-rw-r--r-- | noncore/apps/opie-gutenbrowser/gutenbrowser.cpp | 27 |
2 files changed, 799 insertions, 781 deletions
diff --git a/noncore/apps/opie-gutenbrowser/LibraryDialog.cpp b/noncore/apps/opie-gutenbrowser/LibraryDialog.cpp index 7426e80..549c1d2 100644 --- a/noncore/apps/opie-gutenbrowser/LibraryDialog.cpp +++ b/noncore/apps/opie-gutenbrowser/LibraryDialog.cpp | |||
@@ -1,1078 +1,1085 @@ | |||
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. */ |
38 | LibraryDialog::LibraryDialog( QWidget* parent, const char* name , bool /*modal*/, WFlags fl ) | 38 | LibraryDialog::LibraryDialog( QWidget* parent, const char* name , bool /*modal*/, WFlags fl ) |
39 | : QDialog( parent, name, true/* modal*/, fl ) | 39 | : QDialog( parent, name, true/* modal*/, fl ) |
40 | { | 40 | { |
41 | if ( !name ) | 41 | if ( !name ) |
42 | setName( "LibraryDialog" ); | 42 | setName( "LibraryDialog" ); |
43 | indexLoaded=false; | 43 | indexLoaded=false; |
44 | initDialog(); | 44 | initDialog(); |
45 | 45 | ||
46 | // this->setMaximumWidth(240); | 46 | // this->setMaximumWidth(240); |
47 | 47 | ||
48 | index = "GUTINDEX.ALL"; | 48 | index = "GUTINDEX.ALL"; |
49 | local_library = (QDir::homeDirPath ()) +"/Applications/gutenbrowser/"; | 49 | local_library = (QDir::homeDirPath ()) +"/Applications/gutenbrowser/"; |
50 | local_index = local_library + index; | 50 | local_index = local_library + index; |
51 | 51 | ||
52 | QString iniFile ; | 52 | QString iniFile ; |
53 | iniFile = QPEApplication::qpeDir()+"etc/gutenbrowser/gutenbrowserrc"; | 53 | iniFile = QPEApplication::qpeDir()+"etc/gutenbrowser/gutenbrowserrc"; |
54 | 54 | ||
55 | new_index =QPEApplication::qpeDir()+"etc/gutenbrowser/PGWHOLE.TXT"; | 55 | new_index =QPEApplication::qpeDir()+"etc/gutenbrowser/PGWHOLE.TXT"; |
56 | 56 | ||
57 | old_index = QPEApplication::qpeDir()+"etc/gutenbrowser/GUTINDEX.ALL"; | 57 | old_index = QPEApplication::qpeDir()+"etc/gutenbrowser/GUTINDEX.ALL"; |
58 | // old_index = QPEApplication::qpeDir()+"etc/gutenbrowser/GUTINDEX.ALL"; | 58 | // old_index = QPEApplication::qpeDir()+"etc/gutenbrowser/GUTINDEX.ALL"; |
59 | 59 | ||
60 | // iniFile = local_library+"gutenbrowserrc"; | 60 | // iniFile = local_library+"gutenbrowserrc"; |
61 | // new_index = local_library + "PGWHOLE.TXT"; | 61 | // new_index = local_library + "PGWHOLE.TXT"; |
62 | // old_index = local_library + "GUTINDEX.ALL"; | 62 | // old_index = local_library + "GUTINDEX.ALL"; |
63 | 63 | ||
64 | Config config("Gutenbrowser"); | 64 | Config config("Gutenbrowser"); |
65 | 65 | ||
66 | config.setGroup( "HttpServer" ); | 66 | config.setGroup( "HttpServer" ); |
67 | proxy_http = config.readEntry("Preferred", "http://sailor.gutenbook.org"); | 67 | proxy_http = config.readEntry("Preferred", "http://sailor.gutenbook.org"); |
68 | 68 | ||
69 | config.setGroup( "FTPsite" ); | 69 | config.setGroup( "FTPsite" ); |
70 | ftp_host=config.readEntry("SiteName", "sailor.gutenberg.org"); | 70 | ftp_host=config.readEntry("SiteName", "sailor.gutenberg.org"); |
71 | odebug << "Library Dialog: ftp_host is "+ftp_host << oendl; | 71 | odebug << "Library Dialog: ftp_host is "+ftp_host << oendl; |
72 | // ftp_host=ftp_host.right(ftp_host.length()-(ftp_host.find(") ",0,TRUE)+1) ); | 72 | // ftp_host=ftp_host.right(ftp_host.length()-(ftp_host.find(") ",0,TRUE)+1) ); |
73 | // ftp_host=ftp_host.stripWhiteSpace(); | 73 | // ftp_host=ftp_host.stripWhiteSpace(); |
74 | ftp_base_dir= config.readEntry("base", "/pub/gutenberg"); | 74 | ftp_base_dir= config.readEntry("base", "/pub/gutenberg"); |
75 | 75 | ||
76 | i_binary = 0; | 76 | i_binary = 0; |
77 | 77 | ||
78 | config.setGroup("SortAuth"); | 78 | config.setGroup("SortAuth"); |
79 | if( config.readEntry("authSort", "FALSE") == "TRUE") | 79 | if( config.readEntry("authSort", "FALSE") == "TRUE") |
80 | authBox->setChecked(TRUE); | 80 | authBox->setChecked(TRUE); |
81 | 81 | ||
82 | config.setGroup("General"); | 82 | config.setGroup("General"); |
83 | downDir =config.readEntry( "DownloadDirectory",local_library); | 83 | downDir =config.readEntry( "DownloadDirectory",local_library); |
84 | odebug << "downDir is "+downDir << oendl; | 84 | odebug << "downDir is "+downDir << oendl; |
85 | newindexLib.setName( old_index); | 85 | newindexLib.setName( old_index); |
86 | indexLib.setName( old_index); | 86 | indexLib.setName( old_index); |
87 | 87 | ||
88 | new QPEDialogListener(this); | 88 | new QPEDialogListener(this); |
89 | QTimer::singleShot( 1000, this, SLOT( FindLibrary()) ); | 89 | QTimer::singleShot( 1000, this, SLOT( FindLibrary()) ); |
90 | 90 | ||
91 | } | 91 | } |
92 | 92 | ||
93 | LibraryDialog::~LibraryDialog() | 93 | LibraryDialog::~LibraryDialog() |
94 | { | 94 | { |
95 | // delete QList_Item2; | 95 | // delete QList_Item2; |
96 | // delete QList_Item1; | 96 | // delete QList_Item1; |
97 | // delete QList_Item3; | 97 | // delete QList_Item3; |
98 | // delete QList_Item4; | 98 | // delete QList_Item4; |
99 | // delete QList_Item5; | 99 | // delete QList_Item5; |
100 | 100 | ||
101 | // saveConfig(); | 101 | // saveConfig(); |
102 | } | 102 | } |
103 | 103 | ||
104 | /*This groks using PGWHOLE.TXT */ | 104 | /*This groks using PGWHOLE.TXT */ |
105 | void LibraryDialog::Newlibrary() | 105 | void LibraryDialog::Newlibrary() |
106 | { | 106 | { |
107 | #ifndef Q_WS_QWS //sorry embedded gutenbrowser cant use zip files | 107 | #ifndef Q_WS_QWS //sorry embedded gutenbrowser cant use zip files |
108 | //odebug << "Opening new library index " << newindexLib << "" << oendl; | 108 | //odebug << "Opening new library index " << newindexLib << "" << oendl; |
109 | if ( newindexLib.open( IO_ReadOnly) ) { | 109 | if ( newindexLib.open( IO_ReadOnly) ) { |
110 | setCaption( tr( "Library Index - using master pg index." ) );// file opened successfully | 110 | setCaption( tr( "Library Index - using master pg index." ) );// file opened successfully |
111 | QTextStream indexStream( &newindexLib ); | 111 | QTextStream indexStream( &newindexLib ); |
112 | QString indexLine; | 112 | QString indexLine; |
113 | while ( !indexStream.atEnd() ) { // until end of file.. | 113 | while ( !indexStream.atEnd() ) { // until end of file.. |
114 | indexLine = indexStream.readLine(); | 114 | indexLine = indexStream.readLine(); |
115 | if ( ( indexLine.mid(4,4)).toInt() && !( indexLine.left(3)).toInt()) { | 115 | if ( ( indexLine.mid(4,4)).toInt() && !( indexLine.left(3)).toInt()) { |
116 | year = indexLine.mid(4,4); | 116 | year = indexLine.mid(4,4); |
117 | year = year.stripWhiteSpace(); | 117 | year = year.stripWhiteSpace(); |
118 | file = indexLine.mid( indexLine.find( "[", 0, TRUE )+1, 12 ); | 118 | file = indexLine.mid( indexLine.find( "[", 0, TRUE )+1, 12 ); |
119 | file = file.stripWhiteSpace(); | 119 | file = file.stripWhiteSpace(); |
120 | number = indexLine.mid( indexLine.find( "]", 0, TRUE ) +1, indexLine.find( " ", 0, TRUE )+1 ); | 120 | number = indexLine.mid( indexLine.find( "]", 0, TRUE ) +1, indexLine.find( " ", 0, TRUE )+1 ); |
121 | if( year.toInt() < 1984) | 121 | if( year.toInt() < 1984) |
122 | number = number.left( number.length() -1 ); | 122 | number = number.left( number.length() -1 ); |
123 | number = number.stripWhiteSpace(); | 123 | number = number.stripWhiteSpace(); |
124 | title = indexLine.mid( indexLine.find(" ", 26, TRUE), indexLine.length() ); | 124 | title = indexLine.mid( indexLine.find(" ", 26, TRUE), indexLine.length() ); |
125 | title = title.stripWhiteSpace(); | 125 | title = title.stripWhiteSpace(); |
126 | 126 | ||
127 | getAuthor(); // groks author | 127 | getAuthor(); // groks author |
128 | author = author.stripWhiteSpace(); | 128 | author = author.stripWhiteSpace(); |
129 | if (authBox->isChecked()) { // this reverses the first name and last name of the author | 129 | if (authBox->isChecked()) { // this reverses the first name and last name of the author |
130 | // odebug << "Sorting last name first" << oendl; | 130 | // odebug << "Sorting last name first" << oendl; |
131 | QString lastName, firstName=""; | 131 | QString lastName, firstName=""; |
132 | int finder=author.findRev( ' ', -1, TRUE); | 132 | int finder=author.findRev( ' ', -1, TRUE); |
133 | lastName=author.right( author.length()-finder); | 133 | lastName=author.right( author.length()-finder); |
134 | firstName=author.left(finder); | 134 | firstName=author.left(finder); |
135 | lastName=lastName.stripWhiteSpace(); | 135 | lastName=lastName.stripWhiteSpace(); |
136 | firstName=firstName.stripWhiteSpace(); | 136 | firstName=firstName.stripWhiteSpace(); |
137 | 137 | ||
138 | if( lastName.find( firstName, 0, true) == -1) // this avoids dup names | 138 | if( lastName.find( firstName, 0, true) == -1) // this avoids dup names |
139 | author=lastName+", "+firstName; | 139 | author=lastName+", "+firstName; |
140 | } | 140 | } |
141 | 141 | ||
142 | if( !number.isEmpty() && (title.find( "reserved",0, FALSE) == -1) && (file.find( "]",0, TRUE) == -1) ) { | 142 | if( !number.isEmpty() |
143 | 143 | && (title.find( "reserved",0, FALSE) == -1) | |
144 | // fill string list or something to be able to resort the whole library | 144 | && (file.find( "]",0, TRUE) == -1) |
145 | if( author.isEmpty() ) | 145 | && (title.find( "Audio",0, FALSE) == -1)) { |
146 | QList_Item5 = new QListViewItem( ListView5, /* number,*/ title, author, year, file ); | 146 | |
147 | else { | 147 | // fill string list or something to be able to resort the whole library |
148 | 148 | if( author.isEmpty() ) | |
149 | if( (author.left(1) >= QString("A") && author.left(1) <= QString("F")) || | 149 | QList_Item5 = new QListViewItem( ListView5, /* number,*/ title, author, year, file ); |
150 | (author.left(1) >= QString("a") && author.left(1) <= QString("f")) ) | 150 | else { |
151 | QList_Item1 = new QListViewItem( ListView1,/* number,*/ title, author, year, file ); | 151 | |
152 | 152 | if( (author.left(1) >= QString("A") && author.left(1) <= QString("F")) || | |
153 | else if( (author.left(1) >= QString("G") && author.left(1) <= QString("M")) || | 153 | (author.left(1) >= QString("a") && author.left(1) <= QString("f")) ) |
154 | (author.left(1) >= QString("g") && author.left(1) <= QString("m")) ) | 154 | QList_Item1 = new QListViewItem( ListView1,/* number,*/ title, author, year, file ); |
155 | QList_Item2 = new QListViewItem( ListView2, /*number, */title, author, year, file ); | 155 | |
156 | 156 | else if( (author.left(1) >= QString("G") && author.left(1) <= QString("M")) || | |
157 | else if( (author.left(1) >= QString("N") && author.left(1) <= QString("R")) || | 157 | (author.left(1) >= QString("g") && author.left(1) <= QString("m")) ) |
158 | (author.left(1) >= QString("n") && author.left(1) <= QString("r")) ) | 158 | QList_Item2 = new QListViewItem( ListView2, /*number, */title, author, year, file ); |
159 | QList_Item3 = new QListViewItem( ListView3, /*number,*/ title, author, year, file ); | 159 | |
160 | 160 | else if( (author.left(1) >= QString("N") && author.left(1) <= QString("R")) || | |
161 | else if( (author.left(1) >= QString("S") && author.left(1) <= QString("Z")) || | 161 | (author.left(1) >= QString("n") && author.left(1) <= QString("r")) ) |
162 | (author.left(1) >= QString("s") && author.left(1) <= QString("z")) ) | 162 | QList_Item3 = new QListViewItem( ListView3, /*number,*/ title, author, year, file ); |
163 | QList_Item4 = new QListViewItem( ListView4, /* number,*/ title, author, year, file ); | 163 | |
164 | 164 | else if( (author.left(1) >= QString("S") && author.left(1) <= QString("Z")) || | |
165 | else | 165 | (author.left(1) >= QString("s") && author.left(1) <= QString("z")) ) |
166 | QList_Item5 = new QListViewItem( ListView5, /* number,*/ title, author, year, file ); | 166 | QList_Item4 = new QListViewItem( ListView4, /* number,*/ title, author, year, file ); |
167 | } | 167 | |
168 | } | 168 | else |
169 | }// end if | 169 | QList_Item5 = new QListViewItem( ListView5, /* number,*/ title, author, year, file ); |
170 | }// end while | 170 | } |
171 | newindexLib.close(); | 171 | } |
172 | } | 172 | }// end if |
173 | }// end while | ||
174 | newindexLib.close(); | ||
175 | } | ||
173 | #ifndef Q_WS_QWS | 176 | #ifndef Q_WS_QWS |
174 | setCursor( arrowCursor); | 177 | setCursor( arrowCursor); |
175 | #endif | 178 | #endif |
176 | #endif | 179 | #endif |
177 | } // end Newlibrary() | 180 | } // end Newlibrary() |
178 | 181 | ||
179 | 182 | ||
180 | void LibraryDialog::Library() | 183 | void LibraryDialog::Library() |
181 | {// old library groking method | 184 | {// old library groking method |
182 | 185 | ||
183 | ListView1->clear(); | 186 | ListView1->clear(); |
184 | ListView2->clear(); | 187 | ListView2->clear(); |
185 | ListView3->clear(); | 188 | ListView3->clear(); |
186 | ListView4->clear(); | 189 | ListView4->clear(); |
187 | ListView5->clear(); | 190 | ListView5->clear(); |
188 | 191 | ||
189 | odebug << "opening GUTINDEX.ALL file" << oendl; | 192 | odebug << "opening GUTINDEX.ALL file" << oendl; |
190 | IDontKnowWhy = ""; | 193 | IDontKnowWhy = ""; |
191 | if ( indexLib.open( IO_ReadOnly) ) { // file opened successfully | 194 | if ( indexLib.open( IO_ReadOnly) ) { // file opened successfully |
192 | QTextStream indexStream( &indexLib ); | 195 | QTextStream indexStream( &indexLib ); |
193 | QString indexLine; | 196 | QString indexLine; |
194 | qApp->processEvents(); | 197 | qApp->processEvents(); |
195 | // int jig; | 198 | // int jig; |
196 | while ( !indexStream.eof() ) { | 199 | while ( !indexStream.eof() ) { |
197 | 200 | ||
198 | indexLine = indexStream.readLine(); | 201 | indexLine = indexStream.readLine(); |
199 | if ( indexLine != "") { | 202 | if ( indexLine != "") { |
200 | if( (indexLine.mid(4,4)).toInt() /* && !( indexLine.left(3)).toInt()*/ ) { | 203 | if( (indexLine.mid(4,4)).toInt() /* && !( indexLine.left(3)).toInt()*/ ) { |
201 | // month = indexLine.left( 3); | 204 | // month = indexLine.left( 3); |
202 | year = indexLine.mid(4,4); | 205 | year = indexLine.mid(4,4); |
203 | // title = indexLine.mid( 9, 50); | 206 | // title = indexLine.mid( 9, 50); |
204 | file = indexLine.mid(60,12); | 207 | file = indexLine.mid(60,12); |
205 | if(file.left(1).find("[",0,TRUE) != -1) | 208 | if(file.left(1).find("[",0,TRUE) != -1) |
206 | file.remove(1,1); | 209 | file.remove(1,1); |
207 | if( file.find("]",0,TRUE) != -1) | 210 | if( file.find("]",0,TRUE) != -1) |
208 | file = file.left( file.find("]",0,TRUE)); | 211 | file = file.left( file.find("]",0,TRUE)); |
209 | //odebug << "file is "+file << oendl; | 212 | |
210 | /// number = indexLine.mid( indexLine.find( "]", 0, TRUE ) +1, indexLine.find( " ", 0, TRUE )+1 ); | 213 | |
211 | number = indexLine.mid(55,5); | 214 | if(file.find("?", 0, false) != -1 ) { |
212 | number = number.stripWhiteSpace(); | 215 | QString tmpfile = file.replace(QRegExp("[?]"), "8"); |
213 | // title = indexLine.mid( indexLine.find(" ", 26, TRUE), indexLine.length() ); | 216 | // qDebug( "file is now " + tmpfile ); |
214 | title = indexLine.mid( 9, 50 ); | 217 | file = tmpfile; |
215 | title = title.stripWhiteSpace(); | 218 | } |
216 | //odebug << "title is "+title << oendl; | 219 | |
217 | getAuthor(); // grok author | 220 | // number = indexLine.mid( indexLine.find( "]", 0, TRUE ) +1, indexLine.find( " ", 0, TRUE )+1 ); |
218 | author = author.stripWhiteSpace(); | 221 | number = indexLine.mid(55,5); |
219 | //odebug << "author is "+author << oendl; | 222 | number = number.stripWhiteSpace(); |
220 | if (authBox->isChecked() == TRUE) { // this reverses the first name and last name of the author | 223 | // title = indexLine.mid( indexLine.find(" ", 26, TRUE), indexLine.length() ); |
221 | QString lastName, firstName=""; | 224 | title = indexLine.mid( 9, 50 ); |
222 | int finder=author.findRev( ' ', -1, TRUE); | 225 | title = title.stripWhiteSpace(); |
223 | lastName=author.right( author.length()-finder); | 226 | //odebug << "title is "+title << oendl; |
224 | firstName=author.left(finder); | 227 | getAuthor(); // grok author |
225 | lastName=lastName.stripWhiteSpace(); | 228 | author = author.stripWhiteSpace(); |
226 | firstName=firstName.stripWhiteSpace(); | 229 | //odebug << "author is "+author << oendl; |
227 | 230 | if (authBox->isChecked() == TRUE) { // this reverses the first name and last name of the author | |
228 | if( lastName.find( firstName, 0, true) == -1) // this avoids dup names | 231 | QString lastName, firstName=""; |
229 | author=lastName+", "+firstName; | 232 | int finder=author.findRev( ' ', -1, TRUE); |
230 | } | 233 | lastName=author.right( author.length()-finder); |
231 | 234 | firstName=author.left(finder); | |
232 | if( !number.isEmpty() && (title.find( "reserved",0, FALSE) == -1) /*&& (file.find( "]",0, TRUE))*/ ) { | 235 | lastName=lastName.stripWhiteSpace(); |
233 | // fill string list or something to be able to sort by Author | 236 | firstName=firstName.stripWhiteSpace(); |
234 | if( author.isEmpty() ) | 237 | |
235 | QList_Item5 = new QListViewItem( ListView5, /*number, */title, author, year, file ); | 238 | if( lastName.find( firstName, 0, true) == -1) // this avoids dup names |
236 | else { | 239 | author=lastName+", "+firstName; |
237 | if( (author.left(1) >= QString("A") && author.left(1) <= QString("F")) || | 240 | } |
238 | (author.left(1) >= QString("a") && author.left(1) <= QString("f")) ) | 241 | |
239 | QList_Item1 = new QListViewItem( ListView1, /* number,*/ title, author, year, file ); | 242 | if( !number.isEmpty() |
240 | 243 | && (title.find( "reserved",0, FALSE) == -1) | |
241 | else if( (author.left(1) >= QString("G") && author.left(1) <= QString("M")) || | 244 | &&(title.find( "Audio",0, FALSE) == -1)) { |
242 | (author.left(1) >= QString("g") && author.left(1) <= QString("m")) ) | 245 | // fill string list or something to be able to sort by Author |
243 | QList_Item2 = new QListViewItem( ListView2, /* number,*/ title, author, year, file ); | 246 | if( author.isEmpty() ) |
244 | 247 | QList_Item5 = new QListViewItem( ListView5, /*number, */title, author, year, file ); | |
245 | else if( (author.left(1) >= QString("N") && author.left(1) <= QString("R")) || | 248 | else { |
246 | (author.left(1) >= QString("n") && author.left(1) <= QString("r")) ) | 249 | if( (author.left(1) >= QString("A") && author.left(1) <= QString("F")) || |
247 | QList_Item3 = new QListViewItem( ListView3, /* number,*/ title, author, year, file ); | 250 | (author.left(1) >= QString("a") && author.left(1) <= QString("f")) ) |
248 | 251 | QList_Item1 = new QListViewItem( ListView1, /* number,*/ title, author, year, file ); | |
249 | else if( (author.left(1) >= QString("S") && author.left(1) <= QString("Z")) || | 252 | |
250 | (author.left(1) >= QString("s") && author.left(1) <= QString("z")) ) | 253 | else if( (author.left(1) >= QString("G") && author.left(1) <= QString("M")) || |
251 | QList_Item4 = new QListViewItem( ListView4, /* number,*/ title, author, year, file ); | 254 | (author.left(1) >= QString("g") && author.left(1) <= QString("m")) ) |
252 | } | 255 | QList_Item2 = new QListViewItem( ListView2, /* number,*/ title, author, year, file ); |
253 | } | 256 | |
254 | } | 257 | else if( (author.left(1) >= QString("N") && author.left(1) <= QString("R")) || |
255 | } | 258 | (author.left(1) >= QString("n") && author.left(1) <= QString("r")) ) |
256 | } | 259 | QList_Item3 = new QListViewItem( ListView3, /* number,*/ title, author, year, file ); |
257 | indexLib.close(); | 260 | |
258 | } else { | 261 | else if( (author.left(1) >= QString("S") && author.left(1) <= QString("Z")) || |
259 | QString sMsg; | 262 | (author.left(1) >= QString("s") && author.left(1) <= QString("z")) ) |
260 | sMsg = ( tr("<p>Error opening local library index:</P> "))+local_index; | 263 | QList_Item4 = new QListViewItem( ListView4, /* number,*/ title, author, year, file ); |
261 | QMessageBox::message( "Error",sMsg); | 264 | } |
262 | } | 265 | } |
266 | } | ||
267 | } | ||
268 | } | ||
269 | indexLib.close(); | ||
270 | } else { | ||
271 | QString sMsg; | ||
272 | sMsg = ( tr("<p>Error opening local library index:</P> "))+local_index; | ||
273 | QMessageBox::message( "Error",sMsg); | ||
274 | } | ||
263 | 275 | ||
264 | } //end Library() | 276 | } //end Library() |
265 | 277 | ||
266 | 278 | ||
267 | /* | 279 | /* |
268 | Groks the author out of the title */ | 280 | Groks the author out of the title */ |
269 | bool LibraryDialog::getAuthor() | 281 | bool LibraryDialog::getAuthor() |
270 | { | 282 | { |
271 | if( title.contains( ", by", TRUE)) { | 283 | if( title.contains( ", by", TRUE)) { |
272 | int auth; | 284 | int auth; |
273 | auth = title.find(", by", 0, TRUE); | 285 | auth = title.find(", by", 0, TRUE); |
274 | author = title.right(title.length() - (auth + 4) ); | 286 | author = title.right(title.length() - (auth + 4) ); |
275 | if( int finder = author.find("[", 0, TRUE)) { | 287 | if( int finder = author.find("[", 0, TRUE)) { |
276 | author = author.left(finder); | 288 | author = author.left(finder); |
277 | } | 289 | } |
278 | } | 290 | } |
279 | else if ( title.contains( "by, ", TRUE) ) { | 291 | else if ( title.contains( "by, ", TRUE) ) { |
280 | int auth; | 292 | int auth; |
281 | auth = title.find("by, ", 0, TRUE); | 293 | auth = title.find("by, ", 0, TRUE); |
282 | author = title.right(title.length() - (auth + 4) ); | 294 | author = title.right(title.length() - (auth + 4) ); |
283 | if( int finder = author.find("[", 0, TRUE)) { | 295 | if( int finder = author.find("[", 0, TRUE)) { |
284 | author = author.left( finder); | 296 | author = author.left( finder); |
285 | } | 297 | } |
286 | } | 298 | } |
287 | else if ( title.contains( " by", TRUE) ) { | 299 | else if ( title.contains( " by", TRUE) ) { |
288 | int auth; | 300 | int auth; |
289 | auth = title.find(" by", 0, TRUE); | 301 | auth = title.find(" by", 0, TRUE); |
290 | author = title.right(title.length() - (auth + 3) ); | 302 | author = title.right(title.length() - (auth + 3) ); |
291 | if( int finder = author.find("[", 0, TRUE)) { | 303 | if( int finder = author.find("[", 0, TRUE)) { |
292 | author = author.left( finder); | 304 | author = author.left( finder); |
293 | } | 305 | } |
294 | } | 306 | } |
295 | else if ( title.contains( "by ", TRUE) ) { | 307 | else if ( title.contains( "by ", TRUE) ) { |
296 | int auth; | 308 | int auth; |
297 | auth = title.find("by ", 0, TRUE); | 309 | auth = title.find("by ", 0, TRUE); |
298 | author = title.right(title.length() - (auth + 3) ); | 310 | author = title.right(title.length() - (auth + 3) ); |
299 | if( int finder = author.find("[", 0, TRUE)) { | 311 | if( int finder = author.find("[", 0, TRUE)) { |
300 | author = author.left( finder); | 312 | author = author.left( finder); |
301 | } | 313 | } |
302 | } | 314 | } |
303 | else if ( title.contains( ",", TRUE) ) { | 315 | else if ( title.contains( ",", TRUE) ) { |
304 | int auth; | 316 | int auth; |
305 | auth = title.find(",", 0, TRUE); | 317 | auth = title.find(",", 0, TRUE); |
306 | author = title.right( title.length() - (auth + 1) ); | 318 | author = title.right( title.length() - (auth + 1) ); |
307 | if ( author.contains( ",", TRUE) ) { | 319 | if ( author.contains( ",", TRUE) ) { |
308 | int auth; | 320 | int auth; |
309 | auth = author.find(",", 0, TRUE); | 321 | auth = author.find(",", 0, TRUE); |
310 | author = author.right( author.length() - (auth + 1) ); | 322 | author = author.right( author.length() - (auth + 1) ); |
311 | } | 323 | } |
312 | if( int finder = author.find("[", 0, TRUE)) { | 324 | if( int finder = author.find("[", 0, TRUE)) { |
313 | author = author.left( finder); | 325 | author = author.left( finder); |
314 | } | 326 | } |
315 | } | 327 | } |
316 | else if ( title.contains( "/", TRUE) ) { | 328 | else if ( title.contains( "/", TRUE) ) { |
317 | int auth; | 329 | int auth; |
318 | auth = title.find("/", 0, TRUE); | 330 | auth = title.find("/", 0, TRUE); |
319 | author = title.right(title.length() - (auth + 1) ); | 331 | author = title.right(title.length() - (auth + 1) ); |
320 | if( int finder = author.find("[", 0, TRUE)) { | 332 | if( int finder = author.find("[", 0, TRUE)) { |
321 | author = author.left( finder); | 333 | author = author.left( finder); |
322 | } | 334 | } |
323 | } | 335 | } |
324 | else if ( title.contains( "of", TRUE) ) { | 336 | else if ( title.contains( "of", TRUE) ) { |
325 | int auth; | 337 | int auth; |
326 | auth = title.find("of", 0, TRUE); | 338 | auth = title.find("of", 0, TRUE); |
327 | author = title.right(title.length() - (auth + 2) ); | 339 | author = title.right(title.length() - (auth + 2) ); |
328 | if( int finder = author.find("[", 0, TRUE)) | 340 | if( int finder = author.find("[", 0, TRUE)) |
329 | { | 341 | { |
330 | author = author.left( finder); | 342 | author = author.left( finder); |
331 | } | 343 | } |
332 | } else { | 344 | } else { |
333 | author = ""; | 345 | author = ""; |
334 | } | 346 | } |
335 | if ( author.contains("et. al")) { | 347 | if ( author.contains("et. al")) { |
336 | int auth; | 348 | int auth; |
337 | auth = author.find("et. al", 0, TRUE); | 349 | auth = author.find("et. al", 0, TRUE); |
338 | author = author.left( auth ); | 350 | author = author.left( auth ); |
339 | } | 351 | } |
340 | if ( author.contains("#")) { | 352 | if ( author.contains("#")) { |
341 | int auth; | 353 | int auth; |
342 | auth = author.find("#", 0, TRUE); | 354 | auth = author.find("#", 0, TRUE); |
343 | author = author.left( auth); | 355 | author = author.left( auth); |
344 | } | 356 | } |
345 | if ( author.contains("(")) { | 357 | if ( author.contains("(")) { |
346 | int auth; | 358 | int auth; |
347 | auth = author.find("(", 0, TRUE); | 359 | auth = author.find("(", 0, TRUE); |
348 | author = author.left( auth); | 360 | author = author.left( auth); |
349 | } | 361 | } |
350 | if ( author.contains("et al")) { | 362 | if ( author.contains("et al")) { |
351 | int auth; | 363 | int auth; |
352 | auth = author.find("et al", 0, TRUE); | 364 | auth = author.find("et al", 0, TRUE); |
353 | author = author.left( auth ); | 365 | author = author.left( auth ); |
354 | } | 366 | } |
355 | QRegExp r = QRegExp("[0-9]", TRUE, FALSE); | 367 | QRegExp r = QRegExp("[0-9]", TRUE, FALSE); |
356 | if ( author.left(2).find( r) != -1 ) { | 368 | if ( author.left(2).find( r) != -1 ) { |
357 | author = ""; | 369 | author = ""; |
358 | } | 370 | } |
359 | // if( author.contains(" ", TRUE)) { | 371 | // if( author.contains(" ", TRUE)) { |
360 | // int suth = author.findRev(" ", -1, TRUE); | 372 | // int suth = author.findRev(" ", -1, TRUE); |
361 | // author = author.right( author.length() - suth); | 373 | // author = author.right( author.length() - suth); |
362 | // } | 374 | // } |
363 | 375 | ||
364 | // title | 376 | // title |
365 | // author | 377 | // author |
366 | return true; | 378 | return true; |
367 | }////// end getAuthor() | 379 | }////// end getAuthor() |
368 | 380 | ||
369 | /* | 381 | /* |
370 | selected one etext*/ | 382 | selected one etext*/ |
371 | void LibraryDialog::select_title( QListViewItem * item) | 383 | void LibraryDialog::select_title( QListViewItem * item) |
372 | { | 384 | { |
373 | if(item != NULL) { | 385 | if(item != NULL) { |
374 | i++; | 386 | i++; |
375 | int index = tabWidget->currentPageIndex(); | 387 | int index = tabWidget->currentPageIndex(); |
376 | DlglistItemTitle = item->text(0); | 388 | DlglistItemTitle = item->text(0); |
377 | DlglistItemYear = item->text(2); | 389 | DlglistItemYear = item->text(2); |
378 | DlglistItemFile = item->text(3); | 390 | DlglistItemFile = item->text(3); |
379 | switch (index) { | 391 | switch (index) { |
380 | case 0: { | 392 | case 0: { |
381 | ListView1->clearSelection(); | 393 | ListView1->clearSelection(); |
382 | } | 394 | } |
383 | break; | 395 | break; |
384 | case 1: { | 396 | case 1: { |
385 | ListView2->clearSelection(); | 397 | ListView2->clearSelection(); |
386 | } | 398 | } |
387 | break; | 399 | break; |
388 | case 2: { | 400 | case 2: { |
389 | ListView3->clearSelection(); | 401 | ListView3->clearSelection(); |
390 | } | 402 | } |
391 | break; | 403 | break; |
392 | case 3: { | 404 | case 3: { |
393 | ListView4->clearSelection(); | 405 | ListView4->clearSelection(); |
394 | } | 406 | } |
395 | break; | 407 | break; |
396 | case 4: { | 408 | case 4: { |
397 | ListView5->clearSelection(); | 409 | ListView5->clearSelection(); |
398 | } | 410 | } |
399 | break; | 411 | break; |
400 | }; | 412 | }; |
401 | } | 413 | } |
402 | 414 | ||
403 | if(DlglistItemTitle.length()>2) { | 415 | if(DlglistItemTitle.length()>2) { |
404 | // DlglistItemNumber = item->text(0); | 416 | // DlglistItemNumber = item->text(0); |
405 | item = 0; | 417 | item = 0; |
406 | odebug << "string from librarydialog is:" << DlglistItemYear << " " << DlglistItemFile << " " << DlglistItemNumber << "" << oendl; | 418 | odebug << "string from librarydialog is:" << DlglistItemYear << " " << DlglistItemFile << " " << DlglistItemNumber << "" << oendl; |
407 | odebug << "Title is "+DlglistItemTitle << oendl; | 419 | odebug << "Title is "+DlglistItemTitle << oendl; |
408 | 420 | ||
409 | // check for connection here | 421 | // check for connection here |
410 | // if( get_extext()) | 422 | // if( get_extext()) |
411 | 423 | ||
412 | if(download_Etext()) { | 424 | if(download_Etext()) { |
413 | // odebug << "get here 2" << oendl; | 425 | // odebug << "get here 2" << oendl; |
414 | if(i_binary == 1) { | 426 | if(i_binary == 1) { |
415 | 427 | ||
416 | } | 428 | } |
417 | if(checkBox->isChecked () ) { | 429 | if(checkBox->isChecked () ) { |
418 | accept(); | 430 | accept(); |
419 | } | 431 | } |
420 | } | 432 | } |
421 | } | 433 | } |
422 | } | 434 | } |
423 | 435 | ||
424 | bool LibraryDialog::download_Etext() | 436 | bool LibraryDialog::download_Etext() |
425 | { // ftp method | 437 | { // ftp method |
426 | // might have to use old gpl'd ftp for embedded!! | 438 | // might have to use old gpl'd ftp for embedded!! |
427 | Config cfg("Gutenbrowser"); | 439 | Config cfg("Gutenbrowser"); |
428 | cfg.setGroup("FTPsite"); | 440 | cfg.setGroup("FTPsite"); |
429 | ftp_host=cfg.readEntry("SiteName", "sailor.gutenberg.org"); | 441 | ftp_host=cfg.readEntry("SiteName", "sailor.gutenberg.org"); |
430 | ftp_base_dir= cfg.readEntry("base", "/pub/gutenberg"); | 442 | ftp_base_dir= cfg.readEntry("base", "/pub/gutenberg"); |
431 | 443 | ||
432 | odebug << "about to network dialog" << oendl; | 444 | odebug << "about to network dialog" << oendl; |
433 | QString NewlistItemNumber, NewlistItemYear, ls_result, result_line, s, dir, networkUrl, outputFile; | 445 | QString NewlistItemNumber, NewlistItemYear, ls_result, result_line, s, dir, networkUrl, outputFile; |
434 | 446 | ||
435 | //////////////////// FIXME- if 'x' is part of real name.... | 447 | //////////////////// FIXME- if 'x' is part of real name.... |
436 | NewlistItemFile = DlglistItemFile.left(DlglistItemFile.find(".xxx", 1, FALSE)).left(DlglistItemFile.left(DlglistItemFile.find(".xxx", 1, FALSE)).find("x", 1, FALSE)); | 448 | NewlistItemFile = DlglistItemFile.left(DlglistItemFile.find(".xxx", 1, FALSE)).left(DlglistItemFile.left(DlglistItemFile.find(".xxx", 1, FALSE)).find("x", 1, FALSE)); |
437 | 449 | ||
438 | if( NewlistItemFile.find( DlglistItemFile.left(4) ,0,TRUE) ==-1 ) { | 450 | if( NewlistItemFile.find( DlglistItemFile.left(4) ,0,TRUE) ==-1 ) { |
439 | NewlistItemFile.replace( 0,4, DlglistItemFile.left(4)); | 451 | NewlistItemFile.replace( 0,4, DlglistItemFile.left(4)); |
440 | odebug << "NewlistItemFile is now "+NewlistItemFile << oendl; | 452 | odebug << "NewlistItemFile is now "+NewlistItemFile << oendl; |
441 | } | 453 | } |
442 | NewlistItemYear = DlglistItemYear.right(2); | 454 | NewlistItemYear = DlglistItemYear.right(2); |
443 | int NewlistItemYear_Int = NewlistItemYear.toInt(0, 10); | 455 | int NewlistItemYear_Int = NewlistItemYear.toInt(0, 10); |
444 | odebug << NewlistItemYear << oendl; | 456 | odebug << NewlistItemYear << oendl; |
445 | if (NewlistItemYear_Int < 91 && NewlistItemYear_Int > 70) { | 457 | if (NewlistItemYear_Int < 91 && NewlistItemYear_Int > 70) { |
446 | NewlistItemYear = "90"; | 458 | NewlistItemYear = "90"; |
447 | } | 459 | } |
448 | Edir ="etext" +NewlistItemYear; | 460 | Edir ="etext" +NewlistItemYear; |
449 | dir= ftp_base_dir + "/etext" +NewlistItemYear+"/"; | 461 | dir= ftp_base_dir + "/etext" +NewlistItemYear+"/"; |
450 | if( ftp_base_dir.find("=",0,true) ) | 462 | if( ftp_base_dir.find("=",0,true) ) |
451 | ftp_base_dir.remove( ftp_base_dir.find("=",0,true),1); | 463 | ftp_base_dir.remove( ftp_base_dir.find("=",0,true),1); |
452 | 464 | ||
453 | networkUrl= "ftp://"+ftp_host+dir; | 465 | networkUrl= "ftp://"+ftp_host+dir; |
454 | 466 | ||
455 | outputFile=local_library+".guten_temp"; | 467 | outputFile=local_library+".guten_temp"; |
456 | //odebug << "Download file:" << NewlistItemFile << "" << oendl; | 468 | //odebug << "Download file:" << NewlistItemFile << "" << oendl; |
457 | odebug << "Checking: "+ftp_host+" "+dir+" "+outputFile+" "+NewlistItemFile << oendl; | 469 | odebug << "Checking: "+ftp_host+" "+dir+" "+outputFile+" "+NewlistItemFile << oendl; |
458 | QStringList networkList; | 470 | QStringList networkList; |
459 | networkList.append((const char *)ftp_host); | 471 | networkList.append((const char *)ftp_host); |
460 | networkList.append((const char *)dir); | 472 | networkList.append((const char *)dir); |
461 | networkList.append((const char *)outputFile); | 473 | networkList.append((const char *)outputFile); |
462 | networkList.append((const char *)NewlistItemFile); | 474 | networkList.append((const char *)NewlistItemFile); |
463 | //<< (char *)ftp_host << (char *)dir << (char *)outputFile << (char *)NewlistItemFile; | 475 | //<< (char *)ftp_host << (char *)dir << (char *)outputFile << (char *)NewlistItemFile; |
464 | 476 | ||
465 | NetworkDialog *NetworkDlg; | 477 | NetworkDialog *NetworkDlg; |
466 | NetworkDlg = new NetworkDialog( this,"Network Protocol Dialog", TRUE, 0, networkList); | 478 | NetworkDlg = new NetworkDialog( this,"Network Protocol Dialog", TRUE, 0, networkList); |
467 | 479 | ||
468 | 480 | ||
469 | if( NetworkDlg->exec() != 0 ) { // use new, improved, *INSTANT* network-dialog-file-getterer | 481 | if( NetworkDlg->exec() != 0 ) { // use new, improved, *INSTANT* network-dialog-file-getterer |
470 | File_Name= NetworkDlg->localFileName; | 482 | File_Name= NetworkDlg->localFileName; |
471 | odebug << "back to Library from Network Dialog" << oendl; | 483 | odebug << "back to Library from Network Dialog" << oendl; |
472 | odebug << "Just downloaded "+NetworkDlg->localFileName << oendl; | 484 | odebug << "Just downloaded "+NetworkDlg->localFileName << oendl; |
473 | 485 | ||
474 | // if (File_Name.find( local_library, 0, TRUE) != -1 ) { //could not be found | 486 | // if (File_Name.find( local_library, 0, TRUE) != -1 ) { //could not be found |
475 | // QString oldName=File_Name; | 487 | // QString oldName=File_Name; |
476 | // File_Name.replace(0,local_library.length(),downDir); | 488 | // File_Name.replace(0,local_library.length(),downDir); |
477 | // odebug << "File_Name now is "+File_Name << oendl; | 489 | // odebug << "File_Name now is "+File_Name << oendl; |
478 | 490 | ||
479 | // } | 491 | // } |
480 | // rename .txt to .etx | 492 | // rename .txt to .etx |
481 | if(NetworkDlg->successDownload) { | 493 | if(NetworkDlg->successDownload) { |
482 | odebug << "Filename is "+File_Name << oendl; | 494 | odebug << "Filename is "+File_Name << oendl; |
483 | if(File_Name.right(4)==".txt") { | 495 | if(File_Name.right(4)==".txt") { |
484 | QString s_fileName=File_Name; | 496 | QString s_fileName=File_Name; |
485 | s_fileName.replace( s_fileName.length()-3,3,"gtn"); | 497 | s_fileName.replace( s_fileName.length()-3,3,"gtn"); |
486 | // s_fileName.replace( s_fileName.length()-3,3,"etx"); | 498 | // s_fileName.replace( s_fileName.length()-3,3,"etx"); |
487 | rename(File_Name.latin1(),s_fileName.latin1()); | 499 | rename(File_Name.latin1(),s_fileName.latin1()); |
488 | File_Name=s_fileName; | 500 | File_Name=s_fileName; |
489 | 501 | ||
490 | odebug << "Filename is now "+File_Name << oendl; | 502 | odebug << "Filename is now "+File_Name << oendl; |
491 | 503 | ||
492 | } | 504 | } |
493 | if(File_Name.length() > 5 ) { | 505 | if(File_Name.length() > 5 ) { |
494 | setTitle(); | 506 | setTitle(); |
495 | QFileInfo fi(File_Name); | 507 | QFileInfo fi(File_Name); |
496 | QString name_file=fi.fileName(); | 508 | QString name_file=fi.fileName(); |
497 | name_file=name_file.left(name_file.length()-4); | 509 | name_file=name_file.left(name_file.length()-4); |
498 | 510 | ||
499 | odebug << "Setting doclink" << oendl; | 511 | odebug << "Setting doclink" << oendl; |
500 | DocLnk lnk; | 512 | DocLnk lnk; |
501 | odebug << "name is "+name_file << oendl; | 513 | odebug << "name is "+name_file << oendl; |
502 | lnk.setName(name_file); //sets file name | 514 | lnk.setName(name_file); //sets file name |
503 | odebug << "Title is "+DlglistItemTitle << oendl; | 515 | odebug << "Title is "+DlglistItemTitle << oendl; |
504 | lnk.setComment(DlglistItemTitle); | 516 | lnk.setComment(DlglistItemTitle); |
505 | 517 | ||
506 | odebug << "Filename is "+File_Name << oendl; | 518 | odebug << "Filename is "+File_Name << oendl; |
507 | lnk.setFile(File_Name); //sets File property | 519 | lnk.setFile(File_Name); //sets File property |
508 | lnk.setType("guten/plain");// hey is this a REGISTERED mime type?!?!? ;D | 520 | lnk.setType("guten/plain");// hey is this a REGISTERED mime type?!?!? ;D |
509 | lnk.setExec(File_Name); | 521 | lnk.setExec(File_Name); |
510 | lnk.setIcon("gutenbrowser/Gutenbrowser"); | 522 | lnk.setIcon("gutenbrowser/Gutenbrowser"); |
511 | if(!lnk.writeLink()) { | 523 | if(!lnk.writeLink()) { |
512 | odebug << "Writing doclink did not work" << oendl; | 524 | odebug << "Writing doclink did not work" << oendl; |
513 | } else { | 525 | } else { |
514 | } | 526 | } |
515 | } else | 527 | } else |
516 | QMessageBox::message("Note","<p>There was an error with the file</p>"); | 528 | QMessageBox::message("Note","<p>There was an error with the file</p>"); |
517 | } | 529 | } |
518 | } | 530 | } |
519 | return true; | 531 | return true; |
520 | } | 532 | } |
521 | 533 | ||
522 | bool LibraryDialog::httpDownload() | 534 | bool LibraryDialog::httpDownload() |
523 | {// httpDownload | 535 | {// httpDownload |
524 | #ifndef Q_WS_QWS | 536 | #ifndef Q_WS_QWS |
525 | Config config("Gutenbrowser"); | 537 | Config config("Gutenbrowser"); |
526 | config.setGroup( "Browser" ); | 538 | config.setGroup( "Browser" ); |
527 | QString brow = config.readEntry("Preferred", ""); | 539 | QString brow = config.readEntry("Preferred", ""); |
528 | QString file_name = "./.guten_temp"; | 540 | QString file_name = "./.guten_temp"; |
529 | // config.setGroup( "HttpServer" ); | 541 | // config.setGroup( "HttpServer" ); |
530 | // QString s_http = config.readEntry("Preferred", "http://sailor.gutenbook.org"); | 542 | // QString s_http = config.readEntry("Preferred", "http://sailor.gutenbook.org"); |
531 | QString httpName = proxy_http + "/"+Edir; | 543 | QString httpName = proxy_http + "/"+Edir; |
532 | // progressBar->setProgress( i); | 544 | // progressBar->setProgress( i); |
533 | i++; | 545 | i++; |
534 | if ( brow != "Konq") { /////////// use lynx | 546 | if ( brow != "Konq") { /////////// use lynx |
535 | // QString cmd = "lynx -source " + httpName +" | cat >> " + file_name; | 547 | // QString cmd = "lynx -source " + httpName +" | cat >> " + file_name; |
536 | // system(cmd); | 548 | // system(cmd); |
537 | } else { //////////// use KFM | 549 | } else { //////////// use KFM |
538 | // KFM::download( httpName, file_name); | 550 | // KFM::download( httpName, file_name); |
539 | } | 551 | } |
540 | i++; | 552 | i++; |
541 | QFile tmp( file_name); | 553 | QFile tmp( file_name); |
542 | QString str; | 554 | QString str; |
543 | if (tmp.open(IO_ReadOnly)) { | 555 | if (tmp.open(IO_ReadOnly)) { |
544 | QTextStream t( &tmp ); // use a text stream | 556 | QTextStream t( &tmp ); // use a text stream |
545 | while ( !t.eof()) { | 557 | while ( !t.eof()) { |
546 | QString s = t.readLine(); | 558 | QString s = t.readLine(); |
547 | if (s.contains( NewlistItemFile, FALSE) && (s.contains(".txt")) ) { | 559 | if (s.contains( NewlistItemFile, FALSE) && (s.contains(".txt")) ) { |
548 | str = s.mid( s.find( ".txt\">"+NewlistItemFile, 0, TRUE)+6, (s.find( ".txt</A>", 0, TRUE) + 4) - ( s.find( ".txt\">"+NewlistItemFile, 0, TRUE)+6 ) ); | 560 | str = s.mid( s.find( ".txt\">"+NewlistItemFile, 0, TRUE)+6, (s.find( ".txt</A>", 0, TRUE) + 4) - ( s.find( ".txt\">"+NewlistItemFile, 0, TRUE)+6 ) ); |
549 | httpName += "/" + str; | 561 | httpName += "/" + str; |
550 | } | 562 | } |
551 | } //end of while loop | 563 | } //end of while loop |
552 | } | 564 | } |
553 | tmp.close(); | 565 | tmp.close(); |
554 | m_getFilePath = local_library + str; | 566 | m_getFilePath = local_library + str; |
555 | i++; | 567 | i++; |
556 | if ( brow != "KFM"){ ///////// use lynx | 568 | if ( brow != "KFM"){ ///////// use lynx |
557 | QString cmd = "lynx -source " + httpName +" | cat >> " + m_getFilePath; | 569 | QString cmd = "lynx -source " + httpName +" | cat >> " + m_getFilePath; |
558 | // QMessageBox::message("Error", cmd); | 570 | // QMessageBox::message("Error", cmd); |
559 | system(cmd); | 571 | system(cmd); |
560 | } else { ////////// use KFM | 572 | } else { ////////// use KFM |
561 | // KFM::download( httpName, m_getFilePath); | 573 | // KFM::download( httpName, m_getFilePath); |
562 | } | 574 | } |
563 | i++; | 575 | i++; |
564 | #endif | 576 | #endif |
565 | return false; | 577 | return false; |
566 | } | 578 | } |
567 | 579 | ||
568 | void LibraryDialog::cancelIt() | 580 | void LibraryDialog::cancelIt() |
569 | { | 581 | { |
570 | saveConfig(); | 582 | saveConfig(); |
571 | 583 | ||
572 | DlglistItemNumber = ""; | 584 | DlglistItemNumber = ""; |
573 | this->reject(); | 585 | this->reject(); |
574 | } | 586 | } |
575 | 587 | ||
576 | bool LibraryDialog::setTitle() | 588 | bool LibraryDialog::setTitle() |
577 | { | 589 | { |
578 | Config config("Gutenbrowser"); | 590 | Config config("Gutenbrowser"); |
579 | odebug << "setting title" << oendl; | 591 | odebug << "setting title" << oendl; |
580 | odebug << DlglistItemTitle << oendl; | 592 | odebug << DlglistItemTitle << oendl; |
581 | 593 | ||
582 | if( DlglistItemTitle.find("[",0,TRUE) != -1) | 594 | if( DlglistItemTitle.find("[",0,TRUE) != -1) |
583 | DlglistItemTitle.replace(DlglistItemTitle.find("[",0,TRUE),1, "(" ); | 595 | DlglistItemTitle.replace(DlglistItemTitle.find("[",0,TRUE),1, "(" ); |
584 | if( DlglistItemTitle.find("]",0,TRUE) !=-1) | 596 | if( DlglistItemTitle.find("]",0,TRUE) !=-1) |
585 | DlglistItemTitle.replace(DlglistItemTitle.find("]",0,TRUE),1, ")" ); | 597 | DlglistItemTitle.replace(DlglistItemTitle.find("]",0,TRUE),1, ")" ); |
586 | odebug << "Title being set is "+DlglistItemTitle << oendl; | 598 | odebug << "Title being set is "+DlglistItemTitle << oendl; |
587 | int test = 0; | 599 | int test = 0; |
588 | QString ramble, temp; | 600 | QString ramble, temp; |
589 | config.setGroup("Files"); | 601 | config.setGroup("Files"); |
590 | QString s_numofFiles = config.readEntry("NumberOfFiles", "0" ); | 602 | QString s_numofFiles = config.readEntry("NumberOfFiles", "0" ); |
591 | int i_numofFiles = s_numofFiles.toInt(); | 603 | int i_numofFiles = s_numofFiles.toInt(); |
592 | for ( int i = 0; i <= i_numofFiles; i++){ | 604 | for ( int i = 0; i <= i_numofFiles; i++){ |
593 | temp.setNum( i); | 605 | temp.setNum( i); |
594 | ramble = config.readEntry( temp, "" ); | 606 | ramble = config.readEntry( temp, "" ); |
595 | if( strcmp( ramble, File_Name) == 0){ | 607 | if( strcmp( ramble, File_Name) == 0){ |
596 | test = 1; | 608 | test = 1; |
597 | } | 609 | } |
598 | } | 610 | } |
611 | config.setGroup("Files"); | ||
612 | config.writeEntry( "NumberOfFiles", i_numofFiles +1 ); | ||
613 | QString interger; | ||
614 | interger.setNum( i_numofFiles +1); | ||
615 | config.writeEntry( interger, File_Name); | ||
616 | config.setGroup( "Titles" ); | ||
617 | config.writeEntry( File_Name, DlglistItemTitle); | ||
599 | 618 | ||
600 | if(test == 0 ) { | ||
601 | |||
602 | config.setGroup("Files"); | ||
603 | config.writeEntry( "NumberOfFiles", i_numofFiles +1 ); | ||
604 | QString interger; | ||
605 | interger.setNum( i_numofFiles +1); | ||
606 | config.writeEntry( interger, File_Name); | ||
607 | config.setGroup( "Titles" ); | ||
608 | config.writeEntry( File_Name, DlglistItemTitle); | ||
609 | } | ||
610 | test = 0; | 619 | test = 0; |
611 | return true; | 620 | return true; |
612 | } | 621 | } |
613 | 622 | ||
614 | 623 | ||
615 | void LibraryDialog::saveConfig() | 624 | void LibraryDialog::saveConfig() |
616 | { | 625 | { |
617 | Config config("Gutenbrowser"); | 626 | Config config("Gutenbrowser"); |
618 | if( httpBox->isChecked() == TRUE) { | 627 | if( httpBox->isChecked() == TRUE) { |
619 | checked = 1; | 628 | checked = 1; |
620 | config.setGroup( "Proxy" ); | 629 | config.setGroup( "Proxy" ); |
621 | config.writeEntry("IsChecked", "TRUE"); | 630 | config.writeEntry("IsChecked", "TRUE"); |
622 | } else { | 631 | } else { |
623 | checked = 0; | 632 | checked = 0; |
624 | config.setGroup( "Proxy" ); | 633 | config.setGroup( "Proxy" ); |
625 | config.writeEntry("IsChecked", "FALSE"); | 634 | config.writeEntry("IsChecked", "FALSE"); |
626 | } | 635 | } |
627 | if (authBox->isChecked() == TRUE) { | 636 | if (authBox->isChecked() == TRUE) { |
628 | config.setGroup("SortAuth"); | 637 | config.setGroup("SortAuth"); |
629 | config.writeEntry("authSort", "TRUE"); | 638 | config.writeEntry("authSort", "TRUE"); |
630 | } else { | 639 | } else { |
631 | config.setGroup("SortAuth"); | 640 | config.setGroup("SortAuth"); |
632 | config.writeEntry("authSort", "FALSE"); | 641 | config.writeEntry("authSort", "FALSE"); |
633 | } | 642 | } |
634 | // config.write(); | 643 | // config.write(); |
635 | } | 644 | } |
636 | 645 | ||
637 | /* | 646 | /* |
638 | searches library index for user word*/ | 647 | searches library index for user word*/ |
639 | void LibraryDialog::onButtonSearch() | 648 | void LibraryDialog::onButtonSearch() |
640 | { | 649 | { |
641 | ListView1->clearSelection(); | 650 | ListView1->clearSelection(); |
642 | ListView2->clearSelection(); | 651 | ListView2->clearSelection(); |
643 | ListView3->clearSelection(); | 652 | ListView3->clearSelection(); |
644 | ListView4->clearSelection(); | 653 | ListView4->clearSelection(); |
645 | ListView5->clearSelection(); | 654 | ListView5->clearSelection(); |
646 | 655 | ||
647 | int curTab=tabWidget->currentPageIndex(); | 656 | int curTab=tabWidget->currentPageIndex(); |
648 | SearchDialog* searchDlg; | 657 | SearchDialog* searchDlg; |
649 | 658 | ||
650 | // if( resultsList) | 659 | // if( resultsList) |
651 | searchDlg = new SearchDialog( this, "Library Search", TRUE); | 660 | searchDlg = new SearchDialog( this, "Library Search", TRUE); |
652 | searchDlg->setCaption( tr( "Library Search" ) ); | 661 | searchDlg->setCaption( tr( "Library Search" ) ); |
653 | searchDlg->setLabel( "- author or title"); | 662 | searchDlg->setLabel( "- author or title"); |
654 | QString resultString; | 663 | QString resultString; |
655 | int i_berger = 0; | 664 | int i_berger = 0; |
656 | if( searchDlg->exec() != 0 ) { | 665 | if( searchDlg->exec() != 0 ) { |
657 | QString searcherStr = searchDlg->get_text(); | 666 | QString searcherStr = searchDlg->get_text(); |
658 | int fluff=0; | 667 | int fluff=0; |
659 | 668 | ||
660 | // int tabPage = tabWidget->currentPageIndex(); | 669 | // int tabPage = tabWidget->currentPageIndex(); |
661 | // TODO ititerate here... struct<listViews>?? | 670 | // TODO ititerate here... struct<listViews>?? |
662 | 671 | ||
663 | QListViewItemIterator it1( ListView1 ); | 672 | QListViewItemIterator it1( ListView1 ); |
664 | QListViewItemIterator it2( ListView2 ); | 673 | QListViewItemIterator it2( ListView2 ); |
665 | QListViewItemIterator it3( ListView3 ); | 674 | QListViewItemIterator it3( ListView3 ); |
666 | QListViewItemIterator it4( ListView4 ); | 675 | QListViewItemIterator it4( ListView4 ); |
667 | QListViewItemIterator it5( ListView5 ); | 676 | QListViewItemIterator it5( ListView5 ); |
668 | 677 | ||
669 | //// this is really pitiful work, | 678 | //// this is really pitiful work, |
670 | /////// | 679 | /////// |
671 | bool cS; | 680 | bool cS; |
672 | if( searchDlg->caseSensitiveCheckBox->isChecked()) | 681 | if( searchDlg->caseSensitiveCheckBox->isChecked()) |
673 | cS=true; //case sensitive | 682 | cS=true; //case sensitive |
674 | else | 683 | else |
675 | cS=false; | 684 | cS=false; |
676 | 685 | ||
677 | if(fluff==0) { | 686 | if(fluff==0) { |
678 | for ( ; it1.current(); ++it1 ) { | 687 | for ( ; it1.current(); ++it1 ) { |
679 | resultString = ( it1.current() )->text(0); | 688 | resultString = ( it1.current() )->text(0); |
680 | resultString += (" : "); | 689 | resultString += (" : "); |
681 | resultString += ( it1.current() )->text(2); | 690 | resultString += ( it1.current() )->text(2); |
682 | resultString += (" : "); | 691 | resultString += (" : "); |
683 | resultString += ( it1.current() )->text(3); | 692 | resultString += ( it1.current() )->text(3); |
684 | if( resultString.find( searcherStr, 0, cS) != -1) | 693 | if( resultString.find( searcherStr, 0, cS) != -1) |
685 | { | 694 | { |
686 | Searchlist.append( resultString); | 695 | Searchlist.append( resultString); |
687 | } | 696 | } |
688 | } | 697 | } |
689 | } | 698 | } |
690 | if(fluff==0) {// search routine here | 699 | if(fluff==0) {// search routine here |
691 | for ( ; it2.current(); ++it2 ) { | 700 | for ( ; it2.current(); ++it2 ) { |
692 | resultString = ( it2.current() )->text(0); | 701 | resultString = ( it2.current() )->text(0); |
693 | resultString += (" : "); | 702 | resultString += (" : "); |
694 | resultString += ( it2.current() )->text(2); | 703 | resultString += ( it2.current() )->text(2); |
695 | resultString += (" : "); | 704 | resultString += (" : "); |
696 | resultString += ( it2.current() )->text(3); | 705 | resultString += ( it2.current() )->text(3); |
697 | if( resultString.find( searcherStr, 0, cS) != -1) { | 706 | if( resultString.find( searcherStr, 0, cS) != -1) { |
698 | Searchlist.append( resultString); | 707 | Searchlist.append( resultString); |
699 | } | 708 | } |
700 | } | 709 | } |
701 | } | 710 | } |
702 | if(fluff==0) {// search routine here | 711 | if(fluff==0) {// search routine here |
703 | for ( ; it3.current(); ++it3 ) { | 712 | for ( ; it3.current(); ++it3 ) { |
704 | resultString = ( it3.current() )->text(0); | 713 | resultString = ( it3.current() )->text(0); |
705 | resultString += (" : "); | 714 | resultString += (" : "); |
706 | resultString += ( it3.current() )->text(2); | 715 | resultString += ( it3.current() )->text(2); |
707 | resultString += (" : "); | 716 | resultString += (" : "); |
708 | resultString += ( it3.current() )->text(3); | 717 | resultString += ( it3.current() )->text(3); |
709 | 718 | ||
710 | if( resultString.find( searcherStr, 0, cS) != -1) { | 719 | if( resultString.find( searcherStr, 0, cS) != -1) { |
711 | Searchlist.append( resultString); | 720 | Searchlist.append( resultString); |
712 | } | ||
713 | } | ||
714 | } | ||
715 | if(fluff==0) { | ||
716 | // search routine here | ||
717 | for ( ; it4.current(); ++it4 ) { | ||
718 | resultString = ( it4.current() )->text(0); | ||
719 | resultString += (" : "); | ||
720 | resultString += ( it4.current() )->text(2); | ||
721 | resultString += (" : "); | ||
722 | resultString += ( it4.current() )->text(3); | ||
723 | if( resultString.find( searcherStr, 0, cS) != -1) { | ||
724 | Searchlist.append( resultString); | ||
725 | } | ||
726 | } | ||
727 | } | ||
728 | if(fluff==0) { // search routine here | ||
729 | for ( ; it5.current(); ++it5 ) { | ||
730 | resultString = ( it5.current() )->text(0); | ||
731 | resultString += (" : "); | ||
732 | resultString += ( it5.current() )->text(2); | ||
733 | resultString += (" : "); | ||
734 | resultString += ( it5.current() )->text(3); | ||
735 | if( resultString.find( searcherStr, 0, cS) != -1) { | ||
736 | Searchlist.append( resultString); | ||
737 | } | ||
738 | } | ||
739 | } | ||
740 | |||
741 | tabWidget->setCurrentPage( curTab); | ||
742 | |||
743 | Searchlist.sort(); | ||
744 | SearchResultsDlg* SearchResultsDialog; | ||
745 | SearchResultsDialog = new SearchResultsDlg( searchDlg, "Results Dialog", true, 0 , Searchlist); | ||
746 | |||
747 | SearchResultsDialog->showMaximized(); | ||
748 | if( SearchResultsDialog->exec() != 0) { | ||
749 | texter = SearchResultsDialog->selText; | ||
750 | // odebug << texter << oendl; | ||
751 | resultLs = SearchResultsDialog->resultsList; | ||
752 | i_berger = 1; | ||
753 | } else { | ||
754 | resultLs.clear(); | ||
755 | } | 721 | } |
756 | Searchlist.clear(); | 722 | } |
757 | 723 | } | |
758 | // if(SearchResultsDialog) | 724 | if(fluff==0) { |
759 | // delete SearchResultsDialog; | 725 | // search routine here |
760 | QString tester; | 726 | for ( ; it4.current(); ++it4 ) { |
761 | for ( QStringList::Iterator it = resultLs.begin(); it != resultLs.end(); ++it ) { | 727 | resultString = ( it4.current() )->text(0); |
762 | texter.sprintf("%s \n",(*it).latin1()); | 728 | resultString += (" : "); |
763 | // odebug << texter << oendl; | 729 | resultString += ( it4.current() )->text(2); |
764 | if( tester!=texter) | 730 | resultString += (" : "); |
765 | parseSearchResults( texter); | 731 | resultString += ( it4.current() )->text(3); |
766 | tester = texter; | 732 | if( resultString.find( searcherStr, 0, cS) != -1) { |
767 | } | 733 | Searchlist.append( resultString); |
768 | if(searchDlg) | 734 | } |
769 | delete searchDlg; | 735 | } |
770 | } | 736 | } |
771 | if(checkBox->isChecked() ) { | 737 | if(fluff==0) { // search routine here |
772 | accept(); | 738 | for ( ; it5.current(); ++it5 ) { |
773 | } else { | 739 | resultString = ( it5.current() )->text(0); |
774 | setActiveWindow(); | 740 | resultString += (" : "); |
775 | } | 741 | resultString += ( it5.current() )->text(2); |
742 | resultString += (" : "); | ||
743 | resultString += ( it5.current() )->text(3); | ||
744 | if( resultString.find( searcherStr, 0, cS) != -1) { | ||
745 | Searchlist.append( resultString); | ||
746 | } | ||
747 | } | ||
748 | } | ||
749 | |||
750 | tabWidget->setCurrentPage( curTab); | ||
751 | |||
752 | Searchlist.sort(); | ||
753 | SearchResultsDlg* SearchResultsDialog; | ||
754 | SearchResultsDialog = new SearchResultsDlg( searchDlg, "Results Dialog", true, 0 , Searchlist); | ||
755 | |||
756 | SearchResultsDialog->showMaximized(); | ||
757 | if( SearchResultsDialog->exec() != 0) { | ||
758 | texter = SearchResultsDialog->selText; | ||
759 | // odebug << texter << oendl; | ||
760 | resultLs= SearchResultsDialog->resultsList; | ||
761 | i_berger = 1; | ||
762 | } | ||
763 | Searchlist.clear(); | ||
764 | |||
765 | // if(SearchResultsDialog) | ||
766 | // delete SearchResultsDialog; | ||
767 | QString tester; | ||
768 | for ( QStringList::Iterator it = resultLs.begin(); it != resultLs.end(); ++it ) { | ||
769 | texter.sprintf("%s \n",(*it).latin1()); | ||
770 | // odebug << texter << oendl; | ||
771 | if( tester!=texter) | ||
772 | parseSearchResults( texter); | ||
773 | tester = texter; | ||
774 | } | ||
775 | if(searchDlg) | ||
776 | delete searchDlg; | ||
777 | } | ||
778 | if(checkBox->isChecked() ) { | ||
779 | accept(); | ||
780 | } else { | ||
781 | setActiveWindow(); | ||
782 | } | ||
776 | } | 783 | } |
777 | 784 | ||
778 | /* | 785 | /* |
779 | splits the result string and calls download for the current search result*/ | 786 | splits the result string and calls download for the current search result*/ |
780 | void LibraryDialog::parseSearchResults( QString resultStr) | 787 | void LibraryDialog::parseSearchResults( QString resultStr) |
781 | { | 788 | { |
782 | 789 | ||
783 | int stringLeng=resultStr.length(); | 790 | int stringLeng=resultStr.length(); |
784 | QString my; | 791 | QString my; |
785 | my.setNum( stringLeng, 10); | 792 | my.setNum( stringLeng, 10); |
786 | 793 | ||
787 | if( resultStr.length() > 2 && resultStr.length() < 130) { | 794 | if( resultStr.length() > 2 && resultStr.length() < 130) { |
788 | int titleInt = resultStr.find( " : ", 0, TRUE); | 795 | int titleInt = resultStr.find( " : ", 0, TRUE); |
789 | DlglistItemTitle = resultStr.left( titleInt); | 796 | DlglistItemTitle = resultStr.left( titleInt); |
790 | int yearInt = resultStr.find( " : ", titleInt+3, TRUE); | 797 | int yearInt = resultStr.find( " : ", titleInt+3, TRUE); |
791 | DlglistItemYear = resultStr.mid( titleInt+3, (yearInt - titleInt)-3); | 798 | DlglistItemYear = resultStr.mid( titleInt+3, (yearInt - titleInt)-3); |
792 | DlglistItemFile = resultStr.right( resultStr.length() - (yearInt + 3)); | 799 | DlglistItemFile = resultStr.right( resultStr.length() - (yearInt + 3)); |
793 | download_Etext(); | 800 | download_Etext(); |
794 | } | 801 | } |
795 | /* | 802 | /* |
796 | printf( DlglistItemTitle+"\n"); printf( DlglistItemYear+"\n"); printf( DlglistItemFile+"\n");*/ | 803 | printf( DlglistItemTitle+"\n"); printf( DlglistItemYear+"\n"); printf( DlglistItemFile+"\n");*/ |
797 | } | 804 | } |
798 | 805 | ||
799 | // bool LibraryDialog::UnzipIt( QString zipFile) { | 806 | // bool LibraryDialog::UnzipIt( QString zipFile) { |
800 | // //////////TODO findsome other way of dealingwithzip files. | 807 | // //////////TODO findsome other way of dealingwithzip files. |
801 | // ///usr/bin/unzip"; | 808 | // ///usr/bin/unzip"; |
802 | // if( QFile::exists( zipFile)) { | 809 | // if( QFile::exists( zipFile)) { |
803 | // // QString thatFile = local_library +"PGWHOLE.TXT"; | 810 | // // QString thatFile = local_library +"PGWHOLE.TXT"; |
804 | // QString cmd; | 811 | // QString cmd; |
805 | // #if defined(_WS_X11_) | 812 | // #if defined(_WS_X11_) |
806 | // cmd = "gunzip -d " + zipFile /*newestLibraryFile */+" -d " + local_library; | 813 | // cmd = "gunzip -d " + zipFile /*newestLibraryFile */+" -d " + local_library; |
807 | // #endif | 814 | // #endif |
808 | // #if defined(_WS_WIN_) | 815 | // #if defined(_WS_WIN_) |
809 | // QString temp= QDir::convertSeparators(local_library); | 816 | // QString temp= QDir::convertSeparators(local_library); |
810 | // zipFile=QDir::convertSeparators( zipFile); | 817 | // zipFile=QDir::convertSeparators( zipFile); |
811 | // cmd = temp+"unzip.exe -o " +zipFile/*newestLibraryFile */+" -d " + temp; | 818 | // cmd = temp+"unzip.exe -o " +zipFile/*newestLibraryFile */+" -d " + temp; |
812 | // #endif | 819 | // #endif |
813 | // #ifndef Q_WS_QWS | 820 | // #ifndef Q_WS_QWS |
814 | // // QString cmd = "gunzip -d " + zipFile /*newestLibraryFile */+" -d " + local_library; | 821 | // // QString cmd = "gunzip -d " + zipFile /*newestLibraryFile */+" -d " + local_library; |
815 | // cmd = "unzip " + zipFile; | 822 | // cmd = "unzip " + zipFile; |
816 | // #endif | 823 | // #endif |
817 | 824 | ||
818 | // int exit=QMessageBox::information(this, "Unzip?", "Ok to unzip "+ zipFile+" ?", QMessageBox::Yes, QMessageBox::No); | 825 | // int exit=QMessageBox::information(this, "Unzip?", "Ok to unzip "+ zipFile+" ?", QMessageBox::Yes, QMessageBox::No); |
819 | // if (exit==QMessageBox::Yes) { | 826 | // if (exit==QMessageBox::Yes) { |
820 | // odebug << "Issuing the command "+cmd << oendl; | 827 | // odebug << "Issuing the command "+cmd << oendl; |
821 | // #if defined(_WS_WIN_) | 828 | // #if defined(_WS_WIN_) |
822 | // WinExec( cmd, SW_HIDE ); | 829 | // WinExec( cmd, SW_HIDE ); |
823 | // #endif | 830 | // #endif |
824 | // #if defined(_WS_X11_) | 831 | // #if defined(_WS_X11_) |
825 | // system( cmd); | 832 | // system( cmd); |
826 | // #endif | 833 | // #endif |
827 | // #ifndef Q_WS_QWS | 834 | // #ifndef Q_WS_QWS |
828 | // system( cmd); | 835 | // system( cmd); |
829 | // #endif | 836 | // #endif |
830 | // // printf("unzip\n"); | 837 | // // printf("unzip\n"); |
831 | // // remove( zipFile /*newestLibraryFile*/); | 838 | // // remove( zipFile /*newestLibraryFile*/); |
832 | // return true; | 839 | // return true; |
833 | // } | 840 | // } |
834 | // else if(exit==QMessageBox::No) { | 841 | // else if(exit==QMessageBox::No) { |
835 | // // printf("unzip\n"); | 842 | // // printf("unzip\n"); |
836 | // return false; | 843 | // return false; |
837 | // } | 844 | // } |
838 | // } else { | 845 | // } else { |
839 | // // QMessageBox::message( "Note",( tr("Please install unzip in your PATH")) ); | 846 | // // QMessageBox::message( "Note",( tr("Please install unzip in your PATH")) ); |
840 | // return false; | 847 | // return false; |
841 | // } | 848 | // } |
842 | // return true; | 849 | // return true; |
843 | // } | 850 | // } |
844 | 851 | ||
845 | void LibraryDialog::sort() | 852 | void LibraryDialog::sort() |
846 | { | 853 | { |
847 | 854 | ||
848 | } | 855 | } |
849 | 856 | ||
850 | /* | 857 | /* |
851 | Downloads the current selected listitem*/ | 858 | Downloads the current selected listitem*/ |
852 | bool LibraryDialog::getItem(QListViewItem *it) | 859 | bool LibraryDialog::getItem(QListViewItem *it) |
853 | { | 860 | { |
854 | // odebug << "selected getItem" << oendl; | 861 | // odebug << "selected getItem" << oendl; |
855 | 862 | ||
856 | // DlglistItemNumber = it->text(0); | 863 | // DlglistItemNumber = it->text(0); |
857 | DlglistItemTitle = it->text(0); | 864 | DlglistItemTitle = it->text(0); |
858 | DlglistItemYear = it->text(2); | 865 | DlglistItemYear = it->text(2); |
859 | DlglistItemFile = it->text(3); | 866 | DlglistItemFile = it->text(3); |
860 | 867 | ||
861 | if(download_Etext()) { | 868 | if(download_Etext()) { |
862 | if(i_binary == 1) { | 869 | if(i_binary == 1) { |
863 | } | 870 | } |
864 | } | 871 | } |
865 | return true; | 872 | return true; |
866 | } | 873 | } |
867 | 874 | ||
868 | /* | 875 | /* |
869 | download button is pushed so we get the current items to download*/ | 876 | download button is pushed so we get the current items to download*/ |
870 | bool LibraryDialog::onButtonDownload() | 877 | bool LibraryDialog::onButtonDownload() |
871 | { | 878 | { |
872 | // odebug << "selected onButtonDownloadz" << oendl; | 879 | // odebug << "selected onButtonDownloadz" << oendl; |
873 | 880 | ||
874 | QListViewItemIterator it1( ListView1 ); | 881 | QListViewItemIterator it1( ListView1 ); |
875 | QListViewItemIterator it2( ListView2 ); | 882 | QListViewItemIterator it2( ListView2 ); |
876 | QListViewItemIterator it3( ListView3 ); | 883 | QListViewItemIterator it3( ListView3 ); |
877 | QListViewItemIterator it4( ListView4 ); | 884 | QListViewItemIterator it4( ListView4 ); |
878 | QListViewItemIterator it5( ListView5 ); | 885 | QListViewItemIterator it5( ListView5 ); |
879 | 886 | ||
880 | // iterate through all items of the listview | 887 | // iterate through all items of the listview |
881 | for ( ; it1.current(); ++it1 ) { | 888 | for ( ; it1.current(); ++it1 ) { |
882 | if ( it1.current()->isSelected() ) | 889 | if ( it1.current()->isSelected() ) |
883 | getItem(it1.current()); | 890 | getItem(it1.current()); |
884 | it1.current()->setSelected(FALSE); | 891 | it1.current()->setSelected(FALSE); |
885 | } | 892 | } |
886 | for ( ; it2.current(); ++it2 ) { | 893 | for ( ; it2.current(); ++it2 ) { |
887 | if ( it2.current()->isSelected() ) | 894 | if ( it2.current()->isSelected() ) |
888 | getItem(it2.current()); | 895 | getItem(it2.current()); |
889 | it2.current()->setSelected(FALSE); | 896 | it2.current()->setSelected(FALSE); |
890 | } | 897 | } |
891 | for ( ; it3.current(); ++it3 ) { | 898 | for ( ; it3.current(); ++it3 ) { |
892 | if ( it3.current()->isSelected() ) | 899 | if ( it3.current()->isSelected() ) |
893 | getItem(it3.current()); | 900 | getItem(it3.current()); |
894 | it3.current()->setSelected(FALSE); | 901 | it3.current()->setSelected(FALSE); |
895 | } | 902 | } |
896 | for ( ; it4.current(); ++it4 ) { | 903 | for ( ; it4.current(); ++it4 ) { |
897 | if ( it4.current()->isSelected() ) | 904 | if ( it4.current()->isSelected() ) |
898 | getItem(it4.current()); | 905 | getItem(it4.current()); |
899 | it4.current()->setSelected(FALSE); | 906 | it4.current()->setSelected(FALSE); |
900 | } | 907 | } |
901 | for ( ; it5.current(); ++it5 ) { | 908 | for ( ; it5.current(); ++it5 ) { |
902 | if ( it5.current()->isSelected() ) | 909 | if ( it5.current()->isSelected() ) |
903 | getItem(it5.current()); | 910 | getItem(it5.current()); |
904 | it5.current()->setSelected(FALSE); | 911 | it5.current()->setSelected(FALSE); |
905 | } | 912 | } |
906 | return true; | 913 | return true; |
907 | } | 914 | } |
908 | 915 | ||
909 | 916 | ||
910 | /* | 917 | /* |
911 | handles the sorting combo box */ | 918 | handles the sorting combo box */ |
912 | void LibraryDialog::comboSelect(int index) | 919 | void LibraryDialog::comboSelect(int index) |
913 | { | 920 | { |
914 | // odebug << "we are sorting" << oendl; | 921 | // odebug << "we are sorting" << oendl; |
915 | ListView1->setSorting( index, TRUE); | 922 | ListView1->setSorting( index, TRUE); |
916 | ListView2->setSorting( index, TRUE); | 923 | ListView2->setSorting( index, TRUE); |
917 | ListView3->setSorting( index, TRUE); | 924 | ListView3->setSorting( index, TRUE); |
918 | ListView4->setSorting( index, TRUE); | 925 | ListView4->setSorting( index, TRUE); |
919 | ListView5->setSorting( index, TRUE); | 926 | ListView5->setSorting( index, TRUE); |
920 | 927 | ||
921 | ListView1->sort(); | 928 | ListView1->sort(); |
922 | ListView2->sort(); | 929 | ListView2->sort(); |
923 | ListView3->sort(); | 930 | ListView3->sort(); |
924 | ListView4->sort(); | 931 | ListView4->sort(); |
925 | ListView5->sort(); | 932 | ListView5->sort(); |
926 | 933 | ||
927 | // ListView1->triggerUpdate(); | 934 | // ListView1->triggerUpdate(); |
928 | // ListView2->triggerUpdate(); | 935 | // ListView2->triggerUpdate(); |
929 | // ListView3->triggerUpdate(); | 936 | // ListView3->triggerUpdate(); |
930 | // ListView4->triggerUpdate(); | 937 | // ListView4->triggerUpdate(); |
931 | // ListView5->triggerUpdate(); | 938 | // ListView5->triggerUpdate(); |
932 | } | 939 | } |
933 | 940 | ||
934 | void LibraryDialog::newList() | 941 | void LibraryDialog::newList() |
935 | { | 942 | { |
936 | if(indexLoaded) { | 943 | if(indexLoaded) { |
937 | onButtonDownload(); | 944 | onButtonDownload(); |
938 | } else { | 945 | } else { |
939 | Output *outDlg; | 946 | Output *outDlg; |
940 | buttonNewList->setDown(TRUE); | 947 | buttonNewList->setDown(TRUE); |
941 | QDir gutDir(QPEApplication::qpeDir()+"etc/gutenbrowser"); | 948 | QDir gutDir(QPEApplication::qpeDir()+"etc/gutenbrowser"); |
942 | if(!gutDir.exists()) gutDir.mkdir(QPEApplication::qpeDir()+"etc/gutenbrowser",true); | 949 | if(!gutDir.exists()) gutDir.mkdir(QPEApplication::qpeDir()+"etc/gutenbrowser",true); |
943 | if( chdir(QPEApplication::qpeDir()+"etc/gutenbrowser") == 0) { | 950 | if( chdir(QPEApplication::qpeDir()+"etc/gutenbrowser") == 0) { |
944 | odebug << "changing dir "+QPEApplication::qpeDir()+"etc/gutenbrowser" << oendl; | 951 | odebug << "changing dir "+QPEApplication::qpeDir()+"etc/gutenbrowser" << oendl; |
945 | QString gutenindex1 = QPEApplication::qpeDir()+"etc/gutenbrowser/GUTINDEX.ALL"; | 952 | QString gutenindex1 = QPEApplication::qpeDir()+"etc/gutenbrowser/GUTINDEX.ALL"; |
946 | QString cmd="wget -O " + gutenindex1 + " http://sailor.gutenberg.org/GUTINDEX.ALL 2>&1"; | 953 | QString cmd="wget -O " + gutenindex1 + " http://sailor.gutenberg.org/GUTINDEX.ALL 2>&1"; |
947 | 954 | ||
948 | int result = QMessageBox::warning( this,"Download" | 955 | int result = QMessageBox::warning( this,"Download" |
949 | ,"<p>Ok to use /'wget/' to download a new library list?</P>" | 956 | ,"<p>Ok to use /'wget/' to download a new library list?</P>" |
950 | ,"Yes","No",0,0,1); | 957 | ,"Yes","No",0,0,1); |
951 | qApp->processEvents(); | 958 | qApp->processEvents(); |
952 | if(result == 0) { | 959 | if(result == 0) { |
953 | outDlg = new Output( 0, tr("Downloading Gutenberg Index...."),TRUE); | 960 | outDlg = new Output( 0, tr("Downloading Gutenberg Index...."),TRUE); |
954 | outDlg->showMaximized(); | 961 | outDlg->showMaximized(); |
955 | outDlg->show(); | 962 | outDlg->show(); |
956 | qApp->processEvents(); | 963 | qApp->processEvents(); |
957 | FILE *fp; | 964 | FILE *fp; |
958 | char line[130]; | 965 | char line[130]; |
959 | outDlg->OutputEdit->append( tr("Running wget") ); | 966 | outDlg->OutputEdit->append( tr("Running wget") ); |
960 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); | 967 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); |
961 | sleep(1); | 968 | sleep(1); |
962 | fp = popen( (const char *) cmd, "r"); | 969 | fp = popen( (const char *) cmd, "r"); |
963 | if ( !fp ) { | 970 | if ( !fp ) { |
964 | } else { | 971 | } else { |
965 | odebug << "Issuing the command\n"+cmd << oendl; | 972 | odebug << "Issuing the command\n"+cmd << oendl; |
966 | // system(cmd); | 973 | // system(cmd); |
967 | while ( fgets( line, sizeof line, fp)) { | 974 | while ( fgets( line, sizeof line, fp)) { |
968 | outDlg->OutputEdit->append(line); | 975 | outDlg->OutputEdit->append(line); |
969 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); | 976 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); |
970 | } | 977 | } |
971 | pclose(fp); | 978 | pclose(fp); |
972 | outDlg->OutputEdit->append("Finished downloading\n"); | 979 | outDlg->OutputEdit->append("Finished downloading\n"); |
973 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); | 980 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); |
974 | qApp->processEvents(); | 981 | qApp->processEvents(); |
975 | 982 | ||
976 | // if( QFile(gutenindex1).exists() ) { | 983 | // if( QFile(gutenindex1).exists() ) { |
977 | // QString gutenindex=QPEApplication::qpeDir()+"etc/gutenbrowser/GUTINDEX.ALL"; | 984 | // QString gutenindex=QPEApplication::qpeDir()+"etc/gutenbrowser/GUTINDEX.ALL"; |
978 | // if( rename(gutenindex1.latin1(),gutenindex.latin1()) !=0) | 985 | // if( rename(gutenindex1.latin1(),gutenindex.latin1()) !=0) |
979 | // odebug << "renaming error" << oendl; | 986 | // odebug << "renaming error" << oendl; |
980 | // } | 987 | // } |
981 | 988 | ||
982 | } | 989 | } |
983 | // outDlg->close(); | 990 | // outDlg->close(); |
984 | FindLibrary(); | 991 | FindLibrary(); |
985 | if(outDlg) delete outDlg; | 992 | if(outDlg) delete outDlg; |
986 | } | 993 | } |
987 | buttonNewList->setDown(FALSE); | 994 | buttonNewList->setDown(FALSE); |
988 | } else { | 995 | } else { |
989 | QMessageBox::message("Note","Could not change directories"); | 996 | QMessageBox::message("Note","Could not change directories"); |
990 | } | 997 | } |
991 | // if(outDlg) | 998 | // if(outDlg) |
992 | // delete outDlg; | 999 | // delete outDlg; |
993 | } | 1000 | } |
994 | } | 1001 | } |
995 | 1002 | ||
996 | bool LibraryDialog::moreInfo() | 1003 | bool LibraryDialog::moreInfo() |
997 | { | 1004 | { |
998 | 1005 | ||
999 | QListViewItem * item; | 1006 | QListViewItem * item; |
1000 | item = 0; | 1007 | item = 0; |
1001 | QString titleString; | 1008 | QString titleString; |
1002 | item = ListView1->currentItem(); | 1009 | item = ListView1->currentItem(); |
1003 | if( item != 0) { | 1010 | if( item != 0) { |
1004 | titleString = item->text(0); | 1011 | titleString = item->text(0); |
1005 | ListView1->clearSelection(); | 1012 | ListView1->clearSelection(); |
1006 | item = 0; | 1013 | item = 0; |
1007 | } | 1014 | } |
1008 | if( item == 0) | 1015 | if( item == 0) |
1009 | item = ListView2->currentItem(); | 1016 | item = ListView2->currentItem(); |
1010 | if( item != 0) { | 1017 | if( item != 0) { |
1011 | titleString = item->text(0); | 1018 | titleString = item->text(0); |
1012 | ListView2->clearSelection(); | 1019 | ListView2->clearSelection(); |
1013 | item = 0; | 1020 | item = 0; |
1014 | } | 1021 | } |
1015 | if( item == 0) | 1022 | if( item == 0) |
1016 | item = ListView3->currentItem(); | 1023 | item = ListView3->currentItem(); |
1017 | if( item != 0) { | 1024 | if( item != 0) { |
1018 | titleString = item->text(0); | 1025 | titleString = item->text(0); |
1019 | ListView3->clearSelection(); | 1026 | ListView3->clearSelection(); |
1020 | item = 0; | 1027 | item = 0; |
1021 | } | 1028 | } |
1022 | if( item == 0) | 1029 | if( item == 0) |
1023 | item = ListView4->currentItem(); | 1030 | item = ListView4->currentItem(); |
1024 | if( item != 0) { | 1031 | if( item != 0) { |
1025 | titleString = item->text(0); | 1032 | titleString = item->text(0); |
1026 | ListView4->clearSelection(); | 1033 | ListView4->clearSelection(); |
1027 | item = 0; | 1034 | item = 0; |
1028 | } | 1035 | } |
1029 | if( item == 0) | 1036 | if( item == 0) |
1030 | item = ListView5->currentItem(); | 1037 | item = ListView5->currentItem(); |
1031 | if( item != 0) { | 1038 | if( item != 0) { |
1032 | titleString = item->text(0); | 1039 | titleString = item->text(0); |
1033 | ListView5->clearSelection(); | 1040 | ListView5->clearSelection(); |
1034 | item = 0; | 1041 | item = 0; |
1035 | } | 1042 | } |
1036 | item=0; | 1043 | item=0; |
1037 | if(titleString.length()>2) { | 1044 | if(titleString.length()>2) { |
1038 | odebug << "Title is "+titleString << oendl; | 1045 | odebug << "Title is "+titleString << oendl; |
1039 | titleString.replace( QRegExp("\\s"), "%20"); | 1046 | titleString.replace( QRegExp("\\s"), "%20"); |
1040 | titleString.replace( QRegExp("'"), "%20"); | 1047 | titleString.replace( QRegExp("'"), "%20"); |
1041 | titleString.replace( QRegExp("\""), "%20"); | 1048 | titleString.replace( QRegExp("\""), "%20"); |
1042 | titleString.replace( QRegExp("&"), "%20"); | 1049 | titleString.replace( QRegExp("&"), "%20"); |
1043 | QString cmd= "http://google.com/search?q="+titleString+"&num=30&sa=Google+Search"; | 1050 | QString cmd= "http://google.com/search?q="+titleString+"&num=30&sa=Google+Search"; |
1044 | cmd="opera "+cmd; | 1051 | cmd="opera "+cmd; |
1045 | system(cmd); | 1052 | system(cmd); |
1046 | } else | 1053 | } else |
1047 | QMessageBox::message( "Note","<p>If you select a title, this will search google.com for that title.</p>"); | 1054 | QMessageBox::message( "Note","<p>If you select a title, this will search google.com for that title.</p>"); |
1048 | return true; | 1055 | return true; |
1049 | 1056 | ||
1050 | } | 1057 | } |
1051 | 1058 | ||
1052 | /* | 1059 | /* |
1053 | This loads the library Index*/ | 1060 | This loads the library Index*/ |
1054 | void LibraryDialog::FindLibrary() | 1061 | void LibraryDialog::FindLibrary() |
1055 | { | 1062 | { |
1056 | buttonLibrary->setDown(TRUE); | 1063 | buttonLibrary->setDown(TRUE); |
1057 | 1064 | ||
1058 | qApp->processEvents(); | 1065 | qApp->processEvents(); |
1059 | if( QFile( new_index).exists() /* && this->isHidden() */) { | 1066 | if( QFile( new_index).exists() /* && this->isHidden() */) { |
1060 | newindexLib.setName( new_index); | 1067 | newindexLib.setName( new_index); |
1061 | indexLib.setName( new_index); | 1068 | indexLib.setName( new_index); |
1062 | odebug << "index file is "+ new_index << oendl; | 1069 | odebug << "index file is "+ new_index << oendl; |
1063 | Newlibrary(); | 1070 | Newlibrary(); |
1064 | } else { | 1071 | } else { |
1065 | newindexLib.setName( old_index); | 1072 | newindexLib.setName( old_index); |
1066 | indexLib.setName( old_index); | 1073 | indexLib.setName( old_index); |
1067 | odebug << "new index nameis "+ old_index << oendl; | 1074 | odebug << "new index nameis "+ old_index << oendl; |
1068 | Library(); | 1075 | Library(); |
1069 | } | 1076 | } |
1070 | indexLoaded=true; | 1077 | indexLoaded=true; |
1071 | buttonSearch->setEnabled(TRUE); | 1078 | buttonSearch->setEnabled(TRUE); |
1072 | moreInfoButton->setEnabled(TRUE); | 1079 | moreInfoButton->setEnabled(TRUE); |
1073 | 1080 | ||
1074 | buttonLibrary->setDown(FALSE); | 1081 | buttonLibrary->setDown(FALSE); |
1075 | buttonNewList->setText("Download"); | 1082 | buttonNewList->setText("Download"); |
1076 | qApp->processEvents(); | 1083 | qApp->processEvents(); |
1077 | 1084 | ||
1078 | } | 1085 | } |
diff --git a/noncore/apps/opie-gutenbrowser/gutenbrowser.cpp b/noncore/apps/opie-gutenbrowser/gutenbrowser.cpp index fac21da..c7cdd83 100644 --- a/noncore/apps/opie-gutenbrowser/gutenbrowser.cpp +++ b/noncore/apps/opie-gutenbrowser/gutenbrowser.cpp | |||
@@ -1,752 +1,763 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | gutenbrowser.cpp - description | 2 | gutenbrowser.cpp - description |
3 | ------------------- | 3 | ------------------- |
4 | begin : Mon Jul 24 22:33:12 MDT 2000 | 4 | begin : Mon Jul 24 22:33:12 MDT 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 | * This program is free software; you can redistribute it and/or modify * | 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 * | 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 * | 9 | * the Free Software Foundation; either version 2 of the License, or * |
10 | * (at your option) any later version. * | 10 | * (at your option) any later version. * |
11 | ***************************************************************************/ | 11 | ***************************************************************************/ |
12 | // http search | 12 | // http search |
13 | // http://digital.library.upenn.edu/books/authors.html | 13 | // http://digital.library.upenn.edu/books/authors.html |
14 | // http://digital.library.upenn.edu/books/titles.html | 14 | // http://digital.library.upenn.edu/books/titles.html |
15 | // ftp://ibiblio.org/pub/docs/books/gutenberg/GUTINDEX.ALL | 15 | // ftp://ibiblio.org/pub/docs/books/gutenberg/GUTINDEX.ALL |
16 | // donate@gutenberg.net | 16 | // donate@gutenberg.net |
17 | 17 | ||
18 | 18 | ||
19 | #include "editTitle.h" | 19 | #include "editTitle.h" |
20 | #include "gutenbrowser.h" | 20 | #include "gutenbrowser.h" |
21 | #include "LibraryDialog.h" | 21 | #include "LibraryDialog.h" |
22 | //#include "bookmarksdlg.h" | 22 | //#include "bookmarksdlg.h" |
23 | #include "optionsDialog.h" | 23 | #include "optionsDialog.h" |
24 | #include "helpme.h" | 24 | #include "helpme.h" |
25 | #include "NetworkDialog.h" | 25 | #include "NetworkDialog.h" |
26 | 26 | ||
27 | #include "openetext.h" | 27 | #include "openetext.h" |
28 | #include "output.h" | 28 | #include "output.h" |
29 | 29 | ||
30 | /* OPIE */ | 30 | /* OPIE */ |
31 | #include <opie2/odebug.h> | 31 | #include <opie2/odebug.h> |
32 | #include <qpe/qpeapplication.h> | 32 | #include <qpe/qpeapplication.h> |
33 | #include <qpe/fontdatabase.h> | 33 | #include <qpe/fontdatabase.h> |
34 | #include <qpe/config.h> | 34 | #include <qpe/config.h> |
35 | #include <qpe/qcopenvelope_qws.h> | 35 | #include <qpe/qcopenvelope_qws.h> |
36 | #include <qpe/mimetype.h> | 36 | #include <qpe/mimetype.h> |
37 | #include <qpe/resource.h> | 37 | #include <qpe/resource.h> |
38 | #include <qpe/applnk.h> | 38 | #include <qpe/applnk.h> |
39 | 39 | ||
40 | /* QT */ | 40 | /* QT */ |
41 | #include <qregexp.h> | 41 | #include <qregexp.h> |
42 | #include <qregion.h> | 42 | #include <qregion.h> |
43 | #include <qpaintdevicemetrics.h> | 43 | #include <qpaintdevicemetrics.h> |
44 | #include <qvaluelist.h> | 44 | #include <qvaluelist.h> |
45 | #include <qlabel.h> | 45 | #include <qlabel.h> |
46 | #include <qclipboard.h> | 46 | #include <qclipboard.h> |
47 | #include <qpainter.h> | 47 | #include <qpainter.h> |
48 | #include <qpalette.h> | 48 | #include <qpalette.h> |
49 | #include <qobjectlist.h> | 49 | #include <qobjectlist.h> |
50 | #include <qfontdialog.h> | 50 | #include <qfontdialog.h> |
51 | #include <qtextview.h> | 51 | #include <qtextview.h> |
52 | #include <qbrush.h> | 52 | #include <qbrush.h> |
53 | #include <qfile.h> | 53 | #include <qfile.h> |
54 | #include <qfontinfo.h> | 54 | #include <qfontinfo.h> |
55 | #include <qscrollview.h> | 55 | #include <qscrollview.h> |
56 | #include <qpoint.h> | 56 | #include <qpoint.h> |
57 | 57 | ||
58 | /* STD */ | 58 | /* STD */ |
59 | #include <stdio.h> | 59 | #include <stdio.h> |
60 | #include <stdlib.h> | 60 | #include <stdlib.h> |
61 | #include <unistd.h> | 61 | #include <unistd.h> |
62 | #include <sys/stat.h> | 62 | #include <sys/stat.h> |
63 | #include <fcntl.h> | 63 | #include <fcntl.h> |
64 | #include <errno.h> | 64 | #include <errno.h> |
65 | 65 | ||
66 | static const int nfontsizes = 9; | 66 | static const int nfontsizes = 9; |
67 | static const int fontsize[nfontsizes] = {8,9,10,11,12,13,14,18,24}; | 67 | static const int fontsize[nfontsizes] = {8,9,10,11,12,13,14,18,24}; |
68 | 68 | ||
69 | #ifdef NOQUICKLAUNCH | 69 | #ifdef NOQUICKLAUNCH |
70 | Gutenbrowser::Gutenbrowser() | 70 | Gutenbrowser::Gutenbrowser() |
71 | Gutenbrowser(); | 71 | Gutenbrowser(); |
72 | #else | 72 | #else |
73 | Gutenbrowser::Gutenbrowser(QWidget *,const char*, WFlags ) | 73 | Gutenbrowser::Gutenbrowser(QWidget *,const char*, WFlags ) |
74 | #endif | 74 | #endif |
75 | : QMainWindow() | 75 | : QMainWindow() |
76 | { | 76 | { |
77 | // QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; | 77 | // QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; |
78 | // QCopEnvelope e("QPE/System", "grabKeyboard(QString)" ); | 78 | // QCopEnvelope e("QPE/System", "grabKeyboard(QString)" ); |
79 | // e << ""; | 79 | // e << ""; |
80 | // QPEApplication::grabKeyboard(); | 80 | // QPEApplication::grabKeyboard(); |
81 | showMainList=TRUE; | 81 | showMainList=TRUE; |
82 | working=false; | 82 | working=false; |
83 | this->setUpdatesEnabled(TRUE); | 83 | this->setUpdatesEnabled(TRUE); |
84 | // #ifndef Q_WS_QWS | 84 | // #ifndef Q_WS_QWS |
85 | QString msg; | 85 | QString msg; |
86 | msg="You have now entered unto gutenbrowser,\n"; | 86 | msg="You have now entered unto gutenbrowser,\n"; |
87 | msg+="make your self at home, sit back, relax and read something great.\n"; | 87 | msg+="make your self at home, sit back, relax and read something great.\n"; |
88 | 88 | ||
89 | local_library = (QDir::homeDirPath ()) +"/Applications/gutenbrowser/"; | 89 | local_library = (QDir::homeDirPath ()) +"/Applications/gutenbrowser/"; |
90 | setCaption("Gutenbrowser");// Embedded " VERSION); | 90 | setCaption("Gutenbrowser");// Embedded " VERSION); |
91 | this->setUpdatesEnabled(TRUE); | 91 | this->setUpdatesEnabled(TRUE); |
92 | 92 | ||
93 | // bool firstTime=FALSE; | 93 | // bool firstTime=FALSE; |
94 | topLayout = new QVBoxLayout( this, 0, 0, "topLayout"); | 94 | topLayout = new QVBoxLayout( this, 0, 0, "topLayout"); |
95 | 95 | ||
96 | menu = new QHBoxLayout(-1,"menu"); | 96 | menu = new QHBoxLayout(-1,"menu"); |
97 | buttons2 = new QHBoxLayout(-1,"buttons2"); | 97 | buttons2 = new QHBoxLayout(-1,"buttons2"); |
98 | edits = new QHBoxLayout(-1,"edits"); | 98 | edits = new QHBoxLayout(-1,"edits"); |
99 | 99 | ||
100 | useSplitter=TRUE; | 100 | useSplitter=TRUE; |
101 | 101 | ||
102 | initConfig(); | 102 | initConfig(); |
103 | initMenuBar(); | 103 | initMenuBar(); |
104 | initButtonBar(); | 104 | initButtonBar(); |
105 | initStatusBar(); | 105 | initStatusBar(); |
106 | initView(); | 106 | initView(); |
107 | initSlots(); | 107 | initSlots(); |
108 | qDebug("init finished"); | 108 | qDebug("init finished"); |
109 | QPEApplication::setStylusOperation( mainList->viewport(),QPEApplication::RightOnHold); | 109 | QPEApplication::setStylusOperation( mainList->viewport(),QPEApplication::RightOnHold); |
110 | 110 | ||
111 | connect( mainList, SIGNAL( mouseButtonPressed( int, QListBoxItem *, const QPoint &)), | 111 | connect( mainList, SIGNAL( mouseButtonPressed( int, QListBoxItem *, const QPoint &)), |
112 | this, SLOT( mainListPressed(int, QListBoxItem *, const QPoint &)) ); | 112 | this, SLOT( mainListPressed(int, QListBoxItem *, const QPoint &)) ); |
113 | if( useIcons) | 113 | if( useIcons) |
114 | toggleButtonIcons( TRUE); | 114 | toggleButtonIcons( TRUE); |
115 | else | 115 | else |
116 | toggleButtonIcons( FALSE); | 116 | toggleButtonIcons( FALSE); |
117 | 117 | ||
118 | enableButtons(false); | 118 | enableButtons(false); |
119 | 119 | ||
120 | Config config("Gutenbrowser"); // populate menubuttonlist | 120 | Config config("Gutenbrowser"); // populate menubuttonlist |
121 | config.setGroup("General"); | 121 | config.setGroup("General"); |
122 | 122 | ||
123 | config.setGroup( "Files" ); | 123 | config.setGroup( "Files" ); |
124 | QString s_numofFiles = config.readEntry("NumberOfFiles", "0" ); | 124 | QString s_numofFiles = config.readEntry("NumberOfFiles", "0" ); |
125 | int i_numofFiles = s_numofFiles.toInt(); | 125 | int i_numofFiles = s_numofFiles.toInt(); |
126 | 126 | ||
127 | QString tempFileName; | 127 | QString tempFileName; |
128 | 128 | ||
129 | for (int i = 0; i <= i_numofFiles; i++) { | 129 | for (int i = 0; i <= i_numofFiles; i++) { |
130 | // tempFileName.setNum(i); | 130 | // tempFileName.setNum(i); |
131 | config.setGroup( "Files" ); | 131 | config.setGroup( "Files" ); |
132 | QString ramble = config.readEntry( QString::number(i), "" ); | 132 | QString ramble = config.readEntry( QString::number(i), "" ); |
133 | 133 | ||
134 | config.setGroup( "Titles" ); | 134 | config.setGroup( "Titles" ); |
135 | QString tempTitle = config.readEntry( ramble, ""); | 135 | QString tempTitle = config.readEntry( ramble, ""); |
136 | config.setGroup( tempTitle); | 136 | config.setGroup( tempTitle); |
137 | int index = config.readNumEntry( "LineNumber", -1 ); | 137 | int index = config.readNumEntry( "LineNumber", -1 ); |
138 | if( index != -1) { | 138 | if( index != -1) { |
139 | odebug << tempTitle << oendl; | 139 | odebug << tempTitle << oendl; |
140 | if(!tempTitle.isEmpty()) bookmarksMenu->insertItem( tempTitle); | 140 | if(!tempTitle.isEmpty()) bookmarksMenu->insertItem( tempTitle); |
141 | } | 141 | } |
142 | } | 142 | } |
143 | 143 | ||
144 | // QString gutenIndex= local_library + "GUTINDEX.ALL"; | 144 | // QString gutenIndex= local_library + "GUTINDEX.ALL"; |
145 | QString gutenIndex = QPEApplication::qpeDir()+ "etc/gutenbrowser/GUTINDEX.ALL"; | 145 | QString gutenIndex = QPEApplication::qpeDir()+ "etc/gutenbrowser/GUTINDEX.ALL"; |
146 | qDebug("gutenindex "+gutenIndex ); | 146 | qDebug("gutenindex "+gutenIndex ); |
147 | if( QFile( gutenIndex).exists() ) { | 147 | if( QFile( gutenIndex).exists() ) { |
148 | indexLib.setName( gutenIndex); | 148 | indexLib.setName( gutenIndex); |
149 | } else { | 149 | } else { |
150 | QString localLibIndexFile = QPEApplication::qpeDir()+ "etc/gutenbrowser/PGWHOLE.TXT"; | 150 | QString localLibIndexFile = QPEApplication::qpeDir()+ "etc/gutenbrowser/PGWHOLE.TXT"; |
151 | // QString localLibIndexFile= local_library + "PGWHOLE.TXT"; | 151 | // QString localLibIndexFile= local_library + "PGWHOLE.TXT"; |
152 | newindexLib.setName( localLibIndexFile); | 152 | newindexLib.setName( localLibIndexFile); |
153 | } | 153 | } |
154 | qDebug("attempting new library"); | 154 | qDebug("attempting new library"); |
155 | LibraryDlg = new LibraryDialog( this, "Library Index" /*, TRUE */); | 155 | LibraryDlg = new LibraryDialog( this, "Library Index" /*, TRUE */); |
156 | loadCheck = false; | 156 | loadCheck = false; |
157 | chdir(local_library); | 157 | chdir(local_library); |
158 | if(!showMainList) { | 158 | if(!showMainList) { |
159 | Lview->setFocus(); | 159 | Lview->setFocus(); |
160 | // if(firstTime) | 160 | // if(firstTime) |
161 | // Bookmark(); | 161 | // Bookmark(); |
162 | for (int i=1;i< qApp->argc();i++) { | 162 | for (int i=1;i< qApp->argc();i++) { |
163 | qDebug("Suppose we open somethin"); | 163 | qDebug("Suppose we open somethin"); |
164 | if(!load(qApp->argv()[i])) return; | 164 | if(!load(qApp->argv()[i])) return; |
165 | } | 165 | } |
166 | } else { | 166 | } else { |
167 | fillWithTitles(); | 167 | fillWithTitles(); |
168 | mainList->setFocus(); | 168 | mainList->setFocus(); |
169 | // mainList->setCurrentItem(0); | 169 | // mainList->setCurrentItem(0); |
170 | 170 | ||
171 | } | 171 | } |
172 | writeConfig(); | 172 | writeConfig(); |
173 | QTimer::singleShot( 250, this, SLOT(hideView()) ); | 173 | QTimer::singleShot( 250, this, SLOT(hideView()) ); |
174 | } //end init | 174 | } //end init |
175 | 175 | ||
176 | Gutenbrowser::~Gutenbrowser() { | 176 | Gutenbrowser::~Gutenbrowser() { |
177 | // QPEApplication::grabKeyboard(); | 177 | // QPEApplication::grabKeyboard(); |
178 | // QPEApplication::ungrabKeyboard(); | 178 | // QPEApplication::ungrabKeyboard(); |
179 | odebug << "Exit" << oendl; | 179 | odebug << "Exit" << oendl; |
180 | } | 180 | } |
181 | 181 | ||
182 | /* | 182 | /* |
183 | Google.com search */ | 183 | Google.com search */ |
184 | void Gutenbrowser::InfoBarClick() { | 184 | void Gutenbrowser::InfoBarClick() { |
185 | QString text; | 185 | QString text; |
186 | if( Lview->hasSelectedText()) { | 186 | if( Lview->hasSelectedText()) { |
187 | Lview->copy(); | 187 | Lview->copy(); |
188 | QClipboard *cb = QApplication::clipboard(); | 188 | QClipboard *cb = QApplication::clipboard(); |
189 | text = cb->text(); | 189 | text = cb->text(); |
190 | } else { | 190 | } else { |
191 | // text=title; | 191 | // text=title; |
192 | text=this->caption(); | 192 | text=this->caption(); |
193 | } | 193 | } |
194 | searchGoogle(text); | 194 | searchGoogle(text); |
195 | } | 195 | } |
196 | 196 | ||
197 | /* | 197 | /* |
198 | download http with wget or preferred browser */ | 198 | download http with wget or preferred browser */ |
199 | void Gutenbrowser::goGetit( const QString &url, bool showMsg) { | 199 | void Gutenbrowser::goGetit( const QString &url, bool showMsg) { |
200 | // int eexit=0; | 200 | // int eexit=0; |
201 | QString cmd; | 201 | QString cmd; |
202 | // config.read(); | 202 | // config.read(); |
203 | qApp->processEvents(); | 203 | qApp->processEvents(); |
204 | QString filename = QPEApplication::qpeDir(); | 204 | QString filename = QPEApplication::qpeDir(); |
205 | if(filename.right(1)!="/") | 205 | if(filename.right(1)!="/") |
206 | filename+="/etc/gutenbrowser/"; | 206 | filename+="/etc/gutenbrowser/"; |
207 | else | 207 | else |
208 | filename+="etc/gutenbrowser/"; | 208 | filename+="etc/gutenbrowser/"; |
209 | odebug << "filename "+filename << oendl; | 209 | odebug << "filename "+filename << oendl; |
210 | // QString filename = QDir::homeDirPath()+"/Applications/gutenbrowser/"; | 210 | // QString filename = QDir::homeDirPath()+"/Applications/gutenbrowser/"; |
211 | 211 | ||
212 | filename += url.right( url.length() - url.findRev("/",-1,TRUE) -1); | 212 | filename += url.right( url.length() - url.findRev("/",-1,TRUE) -1); |
213 | 213 | ||
214 | Config config("Gutenbrowser"); | 214 | Config config("Gutenbrowser"); |
215 | config.setGroup( "Browser" ); | 215 | config.setGroup( "Browser" ); |
216 | QString brow = config.readEntry("Preferred", "Opera"); | 216 | QString brow = config.readEntry("Preferred", "Opera"); |
217 | odebug << "Preferred browser is "+brow << oendl; | 217 | odebug << "Preferred browser is "+brow << oendl; |
218 | if(!showMsg) { //if we just get the gutenindex.all | 218 | if(!showMsg) { //if we just get the gutenindex.all |
219 | cmd="wget -O " + filename +" " + url+" 2>&1" ; | 219 | cmd="wget -O " + filename +" " + url+" 2>&1" ; |
220 | chdir(local_library); | 220 | chdir(local_library); |
221 | odebug << "Issuing the system command: " << cmd << "" << oendl; | 221 | odebug << "Issuing the system command: " << cmd << "" << oendl; |
222 | 222 | ||
223 | Output *outDlg; | 223 | Output *outDlg; |
224 | outDlg = new Output(this, tr("Gutenbrowser Output"),FALSE); | 224 | |
225 | outDlg = new Output( 0, tr("Downloading Gutenberg Index...."),TRUE); | ||
226 | |||
225 | outDlg->showMaximized(); | 227 | outDlg->showMaximized(); |
226 | outDlg->show(); | 228 | outDlg->show(); |
227 | qApp->processEvents(); | 229 | qApp->processEvents(); |
228 | FILE *fp; | 230 | FILE *fp; |
229 | char line[130]; | 231 | char line[130]; |
230 | outDlg->OutputEdit->append( tr("Running wget") ); | 232 | outDlg->OutputEdit->append( tr("Running wget") ); |
233 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); | ||
231 | sleep(1); | 234 | sleep(1); |
232 | fp = popen( (const char *) cmd, "r"); | 235 | fp = popen( (const char *) cmd, "r"); |
233 | odebug << "Issuing the command\n"+cmd << oendl; | 236 | if ( !fp ) { |
234 | // system(cmd); | 237 | } else { |
235 | while ( fgets( line, sizeof line, fp)) { | 238 | //odebug << "Issuing the command\n"+cmd << oendl; |
236 | outDlg->OutputEdit->append(line); | 239 | // system(cmd); |
237 | // outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); | 240 | while ( fgets( line, sizeof line, fp)) { |
241 | outDlg->OutputEdit->append(line); | ||
242 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); | ||
243 | } | ||
244 | pclose(fp); | ||
245 | outDlg->OutputEdit->append("Finished downloading\n"); | ||
246 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); | ||
247 | qApp->processEvents(); | ||
248 | |||
238 | } | 249 | } |
239 | pclose(fp); | 250 | outDlg->close(); |
240 | outDlg->close(); | 251 | |
241 | if(outDlg) | 252 | if(outDlg) |
242 | delete outDlg; | 253 | delete outDlg; |
243 | } else { | 254 | } else { |
244 | if( brow == "Konq") { | 255 | if( brow == "Konq") { |
245 | cmd = "konqueror "+url+" &"; | 256 | cmd = "konqueror "+url+" &"; |
246 | } | 257 | } |
247 | if( brow == "Opera") { //for desktop testing | 258 | if( brow == "Opera") { //for desktop testing |
248 | cmd = "opera "+url+" &"; | 259 | cmd = "opera "+url+" &"; |
249 | } | 260 | } |
250 | // if( brow == "Opera") { // on Zaurus | 261 | // if( brow == "Opera") { // on Zaurus |
251 | // cmd = "operagui "+url+" &"; | 262 | // cmd = "operagui "+url+" &"; |
252 | // } | 263 | // } |
253 | if( brow == "Mozilla") { | 264 | if( brow == "Mozilla") { |
254 | cmd = "mozilla "+url+" &"; | 265 | cmd = "mozilla "+url+" &"; |
255 | } | 266 | } |
256 | if( brow == "Netscape") { | 267 | if( brow == "Netscape") { |
257 | cmd = "netscape "+url+" &"; | 268 | cmd = "netscape "+url+" &"; |
258 | } | 269 | } |
259 | if(brow == "wget") { | 270 | if(brow == "wget") { |
260 | // cmd="wget -q "+url+" &"; | 271 | // cmd="wget -q "+url+" &"; |
261 | QString tempHtml=local_library+"webster.html"; | 272 | QString tempHtml=local_library+"webster.html"; |
262 | cmd="wget -O "+tempHtml+" -q "+url; | 273 | cmd="wget -O "+tempHtml+" -q "+url; |
263 | } | 274 | } |
264 | 275 | ||
265 | chdir(local_library); | 276 | chdir(local_library); |
266 | odebug << "Issuing the sys command: " << cmd << "" << oendl; | 277 | odebug << "Issuing the sys command: " << cmd << "" << oendl; |
267 | system(cmd); | 278 | system(cmd); |
268 | } | 279 | } |
269 | } | 280 | } |
270 | 281 | ||
271 | void Gutenbrowser::toggleButtonIcons( bool useEm) { | 282 | void Gutenbrowser::toggleButtonIcons( bool useEm) { |
272 | QString pixDir; | 283 | QString pixDir; |
273 | if(useEm) | 284 | if(useEm) |
274 | useEm=TRUE; | 285 | useEm=TRUE; |
275 | pixDir=QPEApplication::qpeDir()+"pics/gutenbrowser"; | 286 | pixDir=QPEApplication::qpeDir()+"pics/gutenbrowser"; |
276 | odebug << "Docdir is "+QPEApplication::documentDir() << oendl; | 287 | odebug << "Docdir is "+QPEApplication::documentDir() << oendl; |
277 | 288 | ||
278 | if( useIcons && QDir( pixDir).exists() ) { | 289 | if( useIcons && QDir( pixDir).exists() ) { |
279 | LibraryButton->setPixmap( Resource::loadPixmap("home") ); //in inline | 290 | LibraryButton->setPixmap( Resource::loadPixmap("home") ); //in inline |
280 | OpenButton->setPixmap( Resource::loadPixmap("gutenbrowser/openbook")); | 291 | OpenButton->setPixmap( Resource::loadPixmap("gutenbrowser/openbook")); |
281 | ForwardButton->setPixmap( Resource::loadPixmap("forward"));//in inline | 292 | ForwardButton->setPixmap( Resource::loadPixmap("forward"));//in inline |
282 | BackButton->setPixmap( Resource::loadPixmap("back") );//in inline | 293 | BackButton->setPixmap( Resource::loadPixmap("back") );//in inline |
283 | SearchButton->setPixmap( Resource::loadPixmap("gutenbrowser/search") );//in inline | 294 | SearchButton->setPixmap( Resource::loadPixmap("gutenbrowser/search") );//in inline |
284 | lastBmkButton->setPixmap( Resource::loadPixmap("gutenbrowser/bookmark_folder")); | 295 | lastBmkButton->setPixmap( Resource::loadPixmap("gutenbrowser/bookmark_folder")); |
285 | setBookmarkButton->setPixmap( Resource::loadPixmap("gutenbrowser/bookmark") ); | 296 | setBookmarkButton->setPixmap( Resource::loadPixmap("gutenbrowser/bookmark") ); |
286 | dictionaryButton->setPixmap( Resource::loadPixmap("gutenbrowser/spellcheck") ); | 297 | dictionaryButton->setPixmap( Resource::loadPixmap("gutenbrowser/spellcheck") ); |
287 | InfoBar->setPixmap( Resource::loadPixmap("gutenbrowser/google")); | 298 | InfoBar->setPixmap( Resource::loadPixmap("gutenbrowser/google")); |
288 | } | 299 | } |
289 | } | 300 | } |
290 | 301 | ||
291 | 302 | ||
292 | bool Gutenbrowser::queryExit() | 303 | bool Gutenbrowser::queryExit() |
293 | { | 304 | { |
294 | int exit=QMessageBox::information(this, "Quit...", "Do your really want to quit?", | 305 | int exit=QMessageBox::information(this, "Quit...", "Do your really want to quit?", |
295 | QMessageBox::Ok, QMessageBox::Cancel); | 306 | QMessageBox::Ok, QMessageBox::Cancel); |
296 | if (exit==1) { | 307 | if (exit==1) { |
297 | writeConfig(); | 308 | writeConfig(); |
298 | qApp->quit(); | 309 | qApp->quit(); |
299 | } else { | 310 | } else { |
300 | }; | 311 | }; |
301 | return (exit==1); | 312 | return (exit==1); |
302 | } | 313 | } |
303 | 314 | ||
304 | // SLOT IMPLEMENTATION | 315 | // SLOT IMPLEMENTATION |
305 | 316 | ||
306 | void Gutenbrowser::slotFilePrint() { | 317 | void Gutenbrowser::slotFilePrint() { |
307 | } | 318 | } |
308 | 319 | ||
309 | void Gutenbrowser::ByeBye() { | 320 | void Gutenbrowser::ByeBye() { |
310 | if (b_queryExit) | 321 | if (b_queryExit) |
311 | queryExit(); | 322 | queryExit(); |
312 | else { | 323 | else { |
313 | // writeConfig(); | 324 | // writeConfig(); |
314 | qApp->quit(); | 325 | qApp->quit(); |
315 | } | 326 | } |
316 | } | 327 | } |
317 | 328 | ||
318 | void Gutenbrowser::HelpBtn() { | 329 | void Gutenbrowser::HelpBtn() { |
319 | HelpMe* HelpDlg; | 330 | HelpMe* HelpDlg; |
320 | HelpDlg = new HelpMe( this, "Help Dialog"); | 331 | HelpDlg = new HelpMe( this, "Help Dialog"); |
321 | HelpDlg->showMaximized(); | 332 | HelpDlg->showMaximized(); |
322 | } | 333 | } |
323 | 334 | ||
324 | void Gutenbrowser::DownloadIndex() { | 335 | void Gutenbrowser::DownloadIndex() { |
325 | #ifndef Q_WS_QWS | 336 | #ifndef Q_WS_QWS |
326 | { | 337 | { |
327 | switch( QMessageBox::information( 0, (tr("Download Library Index, or FTP sites?")), | 338 | switch( QMessageBox::information( 0, (tr("Download Library Index, or FTP sites?")), |
328 | (tr("Do you want to download the newest\n" | 339 | (tr("Do you want to download the newest\n" |
329 | "Project Gutenberg Library Index?\n" | 340 | "Project Gutenberg Library Index?\n" |
330 | "or select an ftp site?\n")), | 341 | "or select an ftp site?\n")), |
331 | (tr("&Library Index")), (tr("&Ftp Site")), (tr("&Cancel")), 2, 2 ) ) | 342 | (tr("&Library Index")), (tr("&Ftp Site")), (tr("&Cancel")), 2, 2 ) ) |
332 | { | 343 | { |
333 | case 0: // index clicked, | 344 | case 0: // index clicked, |
334 | downloadLibIndex(); | 345 | downloadLibIndex(); |
335 | break; | 346 | break; |
336 | 347 | ||
337 | case 1: // ftp selected | 348 | case 1: // ftp selected |
338 | downloadFtpList(); | 349 | downloadFtpList(); |
339 | break; | 350 | break; |
340 | 351 | ||
341 | case 2: // Cancel | 352 | case 2: // Cancel |
342 | break; | 353 | break; |
343 | }; | 354 | }; |
344 | } | 355 | } |
345 | #endif | 356 | #endif |
346 | } // end DownloadIndex | 357 | } // end DownloadIndex |
347 | 358 | ||
348 | 359 | ||
349 | void Gutenbrowser::downloadFtpList() { | 360 | void Gutenbrowser::downloadFtpList() { |
350 | // QString cmd="wget http://www.promo.net/pg/list.html"); | 361 | // QString cmd="wget http://www.promo.net/pg/list.html"); |
351 | //system(cmd); | 362 | //system(cmd); |
352 | qApp->processEvents(); | 363 | qApp->processEvents(); |
353 | optionsDialog* optDlg; | 364 | optionsDialog* optDlg; |
354 | optDlg = new optionsDialog( this,"Options_Dlg", true); | 365 | optDlg = new optionsDialog( this,"Options_Dlg", true); |
355 | optDlg->getSite(); | 366 | optDlg->getSite(); |
356 | if(optDlg) | 367 | if(optDlg) |
357 | delete optDlg; | 368 | delete optDlg; |
358 | } | 369 | } |
359 | 370 | ||
360 | 371 | ||
361 | void Gutenbrowser::downloadLibIndex() { | 372 | void Gutenbrowser::downloadLibIndex() { |
362 | // QString dwmloader = local_library + "pgwhole.zip"; | 373 | // QString dwmloader = local_library + "pgwhole.zip"; |
363 | // QString cmd = "lynx -source http://www.gutenberg.net/pgwhole.zip | cat >> " + dwmloader; | 374 | // QString cmd = "lynx -source http://www.gutenberg.net/pgwhole.zip | cat >> " + dwmloader; |
364 | // system(cmd); | 375 | // system(cmd); |
365 | 376 | ||
366 | // QString outputFile= local_library+ "GUTINDEX.ALL"; | 377 | // QString outputFile= local_library+ "GUTINDEX.ALL"; |
367 | // config.setGroup( "FTPsite" ); // ftp server config | 378 | // config.setGroup( "FTPsite" ); // ftp server config |
368 | // ftp_host=config.readEntry("SiteName", ""); | 379 | // ftp_host=config.readEntry("SiteName", ""); |
369 | // ftp_base_dir= config.readEntry("base", ""); | 380 | // ftp_base_dir= config.readEntry("base", ""); |
370 | // QString networkUrl= "ftp://"+ftp_host+ftp_base_dir+"/GUTINDEX.ALL"; | 381 | // QString networkUrl= "ftp://"+ftp_host+ftp_base_dir+"/GUTINDEX.ALL"; |
371 | QDir dir( local_library); | 382 | QDir dir( local_library); |
372 | dir.cd("", TRUE); | 383 | dir.cd("", TRUE); |
373 | goGetit( "http://sailor.gutenberg.org/GUTINDEX.ALL", false); // until ghttp works on binaries -qt3 | 384 | goGetit( "http://sailor.gutenberg.org/GUTINDEX.ALL", false); // until ghttp works on binaries -qt3 |
374 | // goGetit( "http://www.gutenberg.net/pgwhole.zip", true); // until ghttp works on binaries -qt3 | 385 | // goGetit( "http://www.gutenberg.net/pgwhole.zip", true); // until ghttp works on binaries -qt3 |
375 | // NetworkDialog *NetworkDlg; | 386 | // NetworkDialog *NetworkDlg; |
376 | // NetworkDlg = new NetworkDialog( this,"Network Protocol Dialog", TRUE, 0, networkUrl, outputFile ); | 387 | // NetworkDlg = new NetworkDialog( this,"Network Protocol Dialog", TRUE, 0, networkUrl, outputFile ); |
377 | // if( NetworkDlg->exec() != 0 ) | 388 | // if( NetworkDlg->exec() != 0 ) |
378 | // { // use new, improved, *INSTANT* network-dialog-file-getterer | 389 | // { // use new, improved, *INSTANT* network-dialog-file-getterer |
379 | //// QMessageBox::message("Note",""); | 390 | //// QMessageBox::message("Note",""); |
380 | // } | 391 | // } |
381 | // if(NetworkDlg) | 392 | // if(NetworkDlg) |
382 | // delete NetworkDlg; | 393 | // delete NetworkDlg; |
383 | } | 394 | } |
384 | 395 | ||
385 | 396 | ||
386 | void Gutenbrowser::PrintBtn() { | 397 | void Gutenbrowser::PrintBtn() { |
387 | } | 398 | } |
388 | 399 | ||
389 | void Gutenbrowser::SearchBtn() { | 400 | void Gutenbrowser::SearchBtn() { |
390 | if( loadCheck) { | 401 | if( loadCheck) { |
391 | odebug << "loadCheck: we have a loaded doc" << oendl; | 402 | odebug << "loadCheck: we have a loaded doc" << oendl; |
392 | Search(); | 403 | Search(); |
393 | } | 404 | } |
394 | // else | 405 | // else |
395 | // QMessageBox::message("Note","Sorry, can't search. No etext is loaded"); | 406 | // QMessageBox::message("Note","Sorry, can't search. No etext is loaded"); |
396 | } | 407 | } |
397 | 408 | ||
398 | 409 | ||
399 | void Gutenbrowser::ForwardBtn() { | 410 | void Gutenbrowser::ForwardBtn() { |
400 | 411 | ||
401 | if( !ForwardButton->autoRepeat() && !ForwardButton->isDown()) { | 412 | if( !ForwardButton->autoRepeat() && !ForwardButton->isDown()) { |
402 | 413 | ||
403 | QString s; | 414 | QString s; |
404 | QString insertString; | 415 | QString insertString; |
405 | int pageSize= Lview->PageSize(); | 416 | int pageSize= Lview->PageSize(); |
406 | Lview->clear(); | 417 | Lview->clear(); |
407 | 418 | ||
408 | for(int fd=0; fd < pageSize - 1;fd++) { | 419 | for(int fd=0; fd < pageSize - 1;fd++) { |
409 | f.readLine(s, 256); | 420 | f.readLine(s, 256); |
410 | if(useWrap) | 421 | if(useWrap) |
411 | s.replace(QRegExp("\n"),""); | 422 | s.replace(QRegExp("\n"),""); |
412 | insertString+=s; | 423 | insertString+=s; |
413 | Lview->insertLine( s, -1); | 424 | Lview->insertLine( s, -1); |
414 | // odebug << s << oendl; | 425 | // odebug << s << oendl; |
415 | currentLine++; | 426 | currentLine++; |
416 | } | 427 | } |
417 | // Lview->insertAt( insertString,0,0, FALSE); | 428 | // Lview->insertAt( insertString,0,0, FALSE); |
418 | currentFilePos = f.at(); | 429 | currentFilePos = f.at(); |
419 | // if( i_pageNum != pages) { | 430 | // if( i_pageNum != pages) { |
420 | // Lview->MultiLine_Ex::pageDown( FALSE); | 431 | // Lview->MultiLine_Ex::pageDown( FALSE); |
421 | i_pageNum++; | 432 | i_pageNum++; |
422 | pageStopArray.resize(i_pageNum + 1); | 433 | pageStopArray.resize(i_pageNum + 1); |
423 | // int length = Lview->length(); | 434 | // int length = Lview->length(); |
424 | 435 | ||
425 | pageStopArray[i_pageNum ] = currentFilePos; | 436 | pageStopArray[i_pageNum ] = currentFilePos; |
426 | odebug << currentFilePos << " current page is number " << i_pageNum | 437 | odebug << currentFilePos << " current page is number " << i_pageNum |
427 | << ", pagesize " << pageSize << ", length " << Lview->length() | 438 | << ", pagesize " << pageSize << ", length " << Lview->length() |
428 | << ", current " << pageStopArray[i_pageNum] << oendl; | 439 | << ", current " << pageStopArray[i_pageNum] << oendl; |
429 | setStatus(); | 440 | setStatus(); |
430 | // Lview->setCursorPosition( 0, 0, FALSE); | 441 | // Lview->setCursorPosition( 0, 0, FALSE); |
431 | // } | 442 | // } |
432 | 443 | ||
433 | } else { | 444 | } else { |
434 | odebug << "bal" << oendl; | 445 | odebug << "bal" << oendl; |
435 | // if( i_pageNum != pages) { | 446 | // if( i_pageNum != pages) { |
436 | 447 | ||
437 | // // int newTop = Lview->Top(); | 448 | // // int newTop = Lview->Top(); |
438 | // // if(Lview->lastRow() > i) | 449 | // // if(Lview->lastRow() > i) |
439 | // Lview->ScrollUp(1); | 450 | // Lview->ScrollUp(1); |
440 | // // i_pageNum++; | 451 | // // i_pageNum++; |
441 | // setStatus(); | 452 | // setStatus(); |
442 | // Lview->setCursorPosition( Lview->Top(), 0, FALSE); | 453 | // Lview->setCursorPosition( Lview->Top(), 0, FALSE); |
443 | 454 | ||
444 | // } | 455 | // } |
445 | 456 | ||
446 | } | 457 | } |
447 | Lview->setFocus(); | 458 | Lview->setFocus(); |
448 | 459 | ||
449 | odebug << "page number " << i_pageNum << " line number " << currentLine << "" << oendl; | 460 | odebug << "page number " << i_pageNum << " line number " << currentLine << "" << oendl; |
450 | } | 461 | } |
451 | 462 | ||
452 | 463 | ||
453 | void Gutenbrowser::BackBtn() { | 464 | void Gutenbrowser::BackBtn() { |
454 | if( i_pageNum > 0) { | 465 | if( i_pageNum > 0) { |
455 | int pageSize= Lview->PageSize(); | 466 | int pageSize= Lview->PageSize(); |
456 | // int length=Lview->length(); | 467 | // int length=Lview->length(); |
457 | 468 | ||
458 | i_pageNum--; | 469 | i_pageNum--; |
459 | currentFilePos = f.at(); | 470 | currentFilePos = f.at(); |
460 | 471 | ||
461 | odebug << currentFilePos << " move back to " << pageStopArray[i_pageNum - 1 ] | 472 | odebug << currentFilePos << " move back to " << pageStopArray[i_pageNum - 1 ] |
462 | << ", current page number " << i_pageNum | 473 | << ", current page number " << i_pageNum |
463 | << ", " << pageSize << ", length " << Lview->length() << oendl; | 474 | << ", " << pageSize << ", length " << Lview->length() << oendl; |
464 | 475 | ||
465 | if( i_pageNum < 2) { | 476 | if( i_pageNum < 2) { |
466 | f.at( 0); | 477 | f.at( 0); |
467 | } else { | 478 | } else { |
468 | if(!f.at( pageStopArray[i_pageNum - 1] )) | 479 | if(!f.at( pageStopArray[i_pageNum - 1] )) |
469 | odebug << "File positioned backward did not work" << oendl; | 480 | odebug << "File positioned backward did not work" << oendl; |
470 | } | 481 | } |
471 | QString s; | 482 | QString s; |
472 | // int sizeLine=0; | 483 | // int sizeLine=0; |
473 | Lview->clear(); | 484 | Lview->clear(); |
474 | // QString insertString; | 485 | // QString insertString; |
475 | 486 | ||
476 | for(int fd = 0; fd < pageSize ;fd++) { | 487 | for(int fd = 0; fd < pageSize ;fd++) { |
477 | // Lview->removeLine( Lview->PageSize() ); | 488 | // Lview->removeLine( Lview->PageSize() ); |
478 | f.readLine(s, 256); | 489 | f.readLine(s, 256); |
479 | if(useWrap) | 490 | if(useWrap) |
480 | s.replace(QRegExp("\n"),""); | 491 | s.replace(QRegExp("\n"),""); |
481 | currentLine++; | 492 | currentLine++; |
482 | // insertString+=s; | 493 | // insertString+=s; |
483 | Lview->insertLine( s, -1); | 494 | Lview->insertLine( s, -1); |
484 | } | 495 | } |
485 | 496 | ||
486 | // Lview->insertAt( insertString,0,0, FALSE); | 497 | // Lview->insertAt( insertString,0,0, FALSE); |
487 | 498 | ||
488 | if( !BackButton->autoRepeat() && !BackButton->isDown()) { | 499 | if( !BackButton->autoRepeat() && !BackButton->isDown()) { |
489 | QString topR; | 500 | QString topR; |
490 | QString lastR; | 501 | QString lastR; |
491 | QString pageR; | 502 | QString pageR; |
492 | // int sizer = Lview->lastRow() - Lview->topRow(); | 503 | // int sizer = Lview->lastRow() - Lview->topRow(); |
493 | // int i_topRow = Lview->topRow(); | 504 | // int i_topRow = Lview->topRow(); |
494 | if( i_pageNum < 1) | 505 | if( i_pageNum < 1) |
495 | i_pageNum = 1; | 506 | i_pageNum = 1; |
496 | setCaption(QString::number(i_pageNum)); | 507 | setCaption(QString::number(i_pageNum)); |
497 | } else { | 508 | } else { |
498 | // int newTop = Lview->Top(); | 509 | // int newTop = Lview->Top(); |
499 | // if(Lview->lastRow() > i) | 510 | // if(Lview->lastRow() > i) |
500 | Lview->MultiLine_Ex::pageUp( FALSE); | 511 | Lview->MultiLine_Ex::pageUp( FALSE); |
501 | // Lview->ScrollDown(1); | 512 | // Lview->ScrollDown(1); |
502 | // i_pageNum--; | 513 | // i_pageNum--; |
503 | if( i_pageNum < 1) | 514 | if( i_pageNum < 1) |
504 | i_pageNum = 1; | 515 | i_pageNum = 1; |
505 | setStatus(); | 516 | setStatus(); |
506 | // Lview->setCursorPosition( Lview->Top(), 0, FALSE); | 517 | // Lview->setCursorPosition( Lview->Top(), 0, FALSE); |
507 | 518 | ||
508 | } | 519 | } |
509 | } | 520 | } |
510 | Lview->setFocus(); | 521 | Lview->setFocus(); |
511 | } | 522 | } |
512 | 523 | ||
513 | void Gutenbrowser::doBeginBtn() { | 524 | void Gutenbrowser::doBeginBtn() { |
514 | if(loadCheck) { | 525 | if(loadCheck) { |
515 | qApp->processEvents(); | 526 | qApp->processEvents(); |
516 | BeginBtn(); | 527 | BeginBtn(); |
517 | } | 528 | } |
518 | } | 529 | } |
519 | 530 | ||
520 | // moves text to the very top = 0 | 531 | // moves text to the very top = 0 |
521 | void Gutenbrowser::TopBtn() { | 532 | void Gutenbrowser::TopBtn() { |
522 | 533 | ||
523 | if(loadCheck) { | 534 | if(loadCheck) { |
524 | if( i_pageNum != 0) { | 535 | if( i_pageNum != 0) { |
525 | odebug << "top" << oendl; | 536 | odebug << "top" << oendl; |
526 | qApp->processEvents(); | 537 | qApp->processEvents(); |
527 | currentLine = 0; | 538 | currentLine = 0; |
528 | i_pageNum = 1; | 539 | i_pageNum = 1; |
529 | int pageSize = Lview->PageSize() ; | 540 | int pageSize = Lview->PageSize() ; |
530 | Lview->clear(); | 541 | Lview->clear(); |
531 | QString s; | 542 | QString s; |
532 | f.at(0); | 543 | f.at(0); |
533 | for(int fd=0; fd < pageSize ;fd++) { | 544 | for(int fd=0; fd < pageSize ;fd++) { |
534 | f.readLine(s, 256); | 545 | f.readLine(s, 256); |
535 | if(useWrap) | 546 | if(useWrap) |
536 | s.replace(QRegExp("\n"),""); | 547 | s.replace(QRegExp("\n"),""); |
537 | Lview->insertLine(s ,-1); | 548 | Lview->insertLine(s ,-1); |
538 | currentLine++; | 549 | currentLine++; |
539 | } | 550 | } |
540 | // Lview->setCursorPosition( 0,0, FALSE); | 551 | // Lview->setCursorPosition( 0,0, FALSE); |
541 | i_pageNum=1; | 552 | i_pageNum=1; |
542 | setStatus(); | 553 | setStatus(); |
543 | } | 554 | } |
544 | Lview->setFocus(); | 555 | Lview->setFocus(); |
545 | } | 556 | } |
546 | } | 557 | } |
547 | 558 | ||
548 | //moves text to the start of the EText | 559 | //moves text to the start of the EText |
549 | void Gutenbrowser::BeginBtn() { | 560 | void Gutenbrowser::BeginBtn() { |
550 | i_pageNum = 1; | 561 | i_pageNum = 1; |
551 | currentLine = 0; | 562 | currentLine = 0; |
552 | QString s_pattern="*END*THE SMALL PRINT"; | 563 | QString s_pattern="*END*THE SMALL PRINT"; |
553 | QString sPattern2 = "*END THE SMALL PRINT"; | 564 | QString sPattern2 = "*END THE SMALL PRINT"; |
554 | 565 | ||
555 | int pageSize = Lview->PageSize(); | 566 | int pageSize = Lview->PageSize(); |
556 | Lview->clear(); | 567 | Lview->clear(); |
557 | 568 | ||
558 | // int lines = Lview->numLines(); | 569 | // int lines = Lview->numLines(); |
559 | int pos = 0;//, i = 0; | 570 | int pos = 0;//, i = 0; |
560 | int i_topRow = Lview->topRow(); | 571 | int i_topRow = Lview->topRow(); |
561 | 572 | ||
562 | QString LeftText;// = Lview->text(); | 573 | QString LeftText;// = Lview->text(); |
563 | 574 | ||
564 | // int linesPerPage = Lview->lastRow() - Lview->topRow(); | 575 | // int linesPerPage = Lview->lastRow() - Lview->topRow(); |
565 | // int pages = (( linesPerPage / Lview->editSize() ) ) +1; | 576 | // int pages = (( linesPerPage / Lview->editSize() ) ) +1; |
566 | // int pageN = 0; | 577 | // int pageN = 0; |
567 | i_pageNum = 1; | 578 | i_pageNum = 1; |
568 | int lastPage=1; | 579 | int lastPage=1; |
569 | int lineNo=0; | 580 | int lineNo=0; |
570 | QString s; | 581 | QString s; |
571 | f.at( 0); | 582 | f.at( 0); |
572 | 583 | ||
573 | while ( !f.atEnd() ) { | 584 | while ( !f.atEnd() ) { |
574 | f.readLine(s, 256); | 585 | f.readLine(s, 256); |
575 | lineNo++; | 586 | lineNo++; |
576 | LeftText = s; | 587 | LeftText = s; |
577 | currentFilePos = f.at(); | 588 | currentFilePos = f.at(); |
578 | 589 | ||
579 | i_pageNum = lineNo/pageSize; | 590 | i_pageNum = lineNo/pageSize; |
580 | if(lastPage < i_pageNum) { | 591 | if(lastPage < i_pageNum) { |
581 | pageStopArray.resize(i_pageNum + 1); | 592 | pageStopArray.resize(i_pageNum + 1); |
582 | pageStopArray[i_pageNum ] = currentFilePos; | 593 | pageStopArray[i_pageNum ] = currentFilePos; |
583 | // odebug << "new page number " << i_pageNum << ", found at " << currentFilePos << "" << oendl; | 594 | // odebug << "new page number " << i_pageNum << ", found at " << currentFilePos << "" << oendl; |
584 | } | 595 | } |
585 | // lastPage = i_pageNum; | 596 | // lastPage = i_pageNum; |
586 | if( LeftText.find( s_pattern, 0 , TRUE) != -1 || LeftText.find( sPattern2, 0 , TRUE) != -1 ) { | 597 | if( LeftText.find( s_pattern, 0 , TRUE) != -1 || LeftText.find( sPattern2, 0 , TRUE) != -1 ) { |
587 | odebug << "<<<<<< FOUND IT!! new page number " << i_pageNum << ", found at " << currentFilePos << "" << oendl; | 598 | odebug << "<<<<<< FOUND IT!! new page number " << i_pageNum << ", found at " << currentFilePos << "" << oendl; |
588 | break; | 599 | break; |
589 | } | 600 | } |
590 | } | 601 | } |
591 | if(f.atEnd()) //in case we didnt find anything, we need to show something | 602 | if(f.atEnd()) //in case we didnt find anything, we need to show something |
592 | f.at(0); | 603 | f.at(0); |
593 | Lview->clear(); | 604 | Lview->clear(); |
594 | for(int fd=0; fd < pageSize - 1;fd++) { | 605 | for(int fd=0; fd < pageSize - 1;fd++) { |
595 | f.readLine(s, 256); | 606 | f.readLine(s, 256); |
596 | if(useWrap) | 607 | if(useWrap) |
597 | s.replace(QRegExp("\n"),""); | 608 | s.replace(QRegExp("\n"),""); |
598 | Lview->insertLine( s, -1); | 609 | Lview->insertLine( s, -1); |
599 | currentLine++; | 610 | currentLine++; |
600 | } | 611 | } |
601 | 612 | ||
602 | i_pageNum = lineNo/pageSize; | 613 | i_pageNum = lineNo/pageSize; |
603 | pageStopArray.resize(i_pageNum + 1); | 614 | pageStopArray.resize(i_pageNum + 1); |
604 | // int length = Lview->length(); | 615 | // int length = Lview->length(); |
605 | 616 | ||
606 | qApp->processEvents(); | 617 | qApp->processEvents(); |
607 | 618 | ||
608 | if( pos > i_topRow ) { | 619 | if( pos > i_topRow ) { |
609 | // Lview->setCursorPosition( pos+linesPerPage+2/* - i_topRow+3 */,0, FALSE); | 620 | // Lview->setCursorPosition( pos+linesPerPage+2/* - i_topRow+3 */,0, FALSE); |
610 | } else { | 621 | } else { |
611 | // Lview->setCursorPosition( pos+2 , 0, FALSE ); | 622 | // Lview->setCursorPosition( pos+2 , 0, FALSE ); |
612 | } | 623 | } |
613 | 624 | ||
614 | Lview->deselect(); | 625 | Lview->deselect(); |
615 | // AdjustStatus(); | 626 | // AdjustStatus(); |
616 | Lview->setFocus(); | 627 | Lview->setFocus(); |
617 | } | 628 | } |
618 | 629 | ||
619 | /* | 630 | /* |
620 | sets the current page and place as a bookmark*/ | 631 | sets the current page and place as a bookmark*/ |
621 | void Gutenbrowser::setBookmark() { | 632 | void Gutenbrowser::setBookmark() { |
622 | int eexit=QMessageBox::information(this, "Note", | 633 | int eexit=QMessageBox::information(this, "Note", |
623 | "Do you really want to \nset this bookmark?." | 634 | "Do you really want to \nset this bookmark?." |
624 | ,QMessageBox::Yes, QMessageBox::No); | 635 | ,QMessageBox::Yes, QMessageBox::No); |
625 | if (eexit== 3) { | 636 | if (eexit== 3) { |
626 | 637 | ||
627 | currentFilePos = f.at(); | 638 | currentFilePos = f.at(); |
628 | 639 | ||
629 | Config cfg("Gutenbrowser"); | 640 | Config cfg("Gutenbrowser"); |
630 | cfg.setGroup("General"); | 641 | cfg.setGroup("General"); |
631 | file_name = cfg.readEntry("Current",""); | 642 | file_name = cfg.readEntry("Current",""); |
632 | qApp->processEvents(); | 643 | qApp->processEvents(); |
633 | odebug << "Setting book mark "+file_name << oendl; | 644 | odebug << "Setting book mark "+file_name << oendl; |
634 | 645 | ||
635 | cfg.setGroup("Titles"); | 646 | cfg.setGroup("Titles"); |
636 | title = cfg.readEntry(file_name,""); | 647 | title = cfg.readEntry(file_name,""); |
637 | odebug << "title is "+ title << oendl; | 648 | odebug << "title is "+ title << oendl; |
638 | 649 | ||
639 | cfg.setGroup( "Bookmarks" ); | 650 | cfg.setGroup( "Bookmarks" ); |
640 | 651 | ||
641 | cfg.writeEntry("File Name",file_name); | 652 | cfg.writeEntry("File Name",file_name); |
642 | cfg.writeEntry("Page Number",QString::number(i_pageNum) ); | 653 | cfg.writeEntry("Page Number",QString::number(i_pageNum) ); |
643 | cfg.writeEntry( "PagePosition", QString::number( pageStopArray[i_pageNum - 1])); | 654 | cfg.writeEntry( "PagePosition", QString::number( pageStopArray[i_pageNum - 1])); |
644 | cfg.writeEntry("Title", title); | 655 | cfg.writeEntry("Title", title); |
645 | 656 | ||
646 | int row = Lview->topRow();// Lview->Top(); | 657 | int row = Lview->topRow();// Lview->Top(); |
647 | cfg.writeEntry("LineNumber",QString::number(row) ); | 658 | cfg.writeEntry("LineNumber",QString::number(row) ); |
648 | 659 | ||
649 | cfg.setGroup(title); | 660 | cfg.setGroup(title); |
650 | cfg.writeEntry("File Name",file_name); | 661 | cfg.writeEntry("File Name",file_name); |
651 | cfg.writeEntry( "LineNumber", QString::number( row)); | 662 | cfg.writeEntry( "LineNumber", QString::number( row)); |
652 | cfg.writeEntry( "PagePosition", QString::number( pageStopArray[i_pageNum - 1])); | 663 | cfg.writeEntry( "PagePosition", QString::number( pageStopArray[i_pageNum - 1])); |
653 | cfg.writeEntry( "Page Number", QString::number( i_pageNum) ); | 664 | cfg.writeEntry( "Page Number", QString::number( i_pageNum) ); |
654 | cfg.write(); | 665 | cfg.write(); |
655 | bookmarksMenu->insertItem( title); | 666 | bookmarksMenu->insertItem( title); |
656 | } | 667 | } |
657 | } //end setBookmark | 668 | } //end setBookmark |
658 | 669 | ||
659 | 670 | ||
660 | /* goes to last set bookmark*/ | 671 | /* goes to last set bookmark*/ |
661 | void Gutenbrowser::Bookmark( int itemId) { | 672 | void Gutenbrowser::Bookmark( int itemId) { |
662 | 673 | ||
663 | // qApp->processEvents(); | 674 | // qApp->processEvents(); |
664 | Config config("Gutenbrowser"); | 675 | Config config("Gutenbrowser"); |
665 | config.setGroup( "Bookmarks" ); | 676 | config.setGroup( "Bookmarks" ); |
666 | 677 | ||
667 | odebug << "<<<<<< " << Lview->PageSize() << ", " << Lview->lastRow() - Lview->topRow() << "" << oendl; | 678 | odebug << "<<<<<< " << Lview->PageSize() << ", " << Lview->lastRow() - Lview->topRow() << "" << oendl; |
668 | 679 | ||
669 | QString itemString; | 680 | QString itemString; |
670 | 681 | ||
671 | odebug << "menu item " << itemId << "" << oendl; | 682 | odebug << "menu item " << itemId << "" << oendl; |
672 | QString tempTitle; | 683 | QString tempTitle; |
673 | QString s_Bmrkrow; | 684 | QString s_Bmrkrow; |
674 | QString s_pageNum; | 685 | QString s_pageNum; |
675 | int Bmrkrow=0; | 686 | int Bmrkrow=0; |
676 | int bookmarkPosition = 0; | 687 | int bookmarkPosition = 0; |
677 | 688 | ||
678 | // qApp->processEvents(); | 689 | // qApp->processEvents(); |
679 | config.setGroup( "Bookmarks" ); | 690 | config.setGroup( "Bookmarks" ); |
680 | title = config.readEntry("Title", ""); | 691 | title = config.readEntry("Title", ""); |
681 | file_name = config.readEntry("File Name", ""); | 692 | file_name = config.readEntry("File Name", ""); |
682 | i_pageNum = config.readNumEntry("Page Number", 0); | 693 | i_pageNum = config.readNumEntry("Page Number", 0); |
683 | bookmarkPosition = config.readNumEntry( "PagePosition",0); | 694 | bookmarkPosition = config.readNumEntry( "PagePosition",0); |
684 | Bmrkrow = config.readNumEntry("LineNumber",0); | 695 | Bmrkrow = config.readNumEntry("LineNumber",0); |
685 | if( !file_name.contains("/")) { | 696 | if( !file_name.contains("/")) { |
686 | file_name = local_library + file_name; | 697 | file_name = local_library + file_name; |
687 | } | 698 | } |
688 | 699 | ||
689 | // getTitle(file_name); | 700 | // getTitle(file_name); |
690 | // qApp->processEvents(); | 701 | // qApp->processEvents(); |
691 | // Lview->setFocus(); | 702 | // Lview->setFocus(); |
692 | this->setFocus(); | 703 | this->setFocus(); |
693 | 704 | ||
694 | Lview->clear(); | 705 | Lview->clear(); |
695 | 706 | ||
696 | if(!load(file_name)) return; | 707 | if(!load(file_name)) return; |
697 | 708 | ||
698 | int pageSize = Lview->PageSize(); | 709 | int pageSize = Lview->PageSize(); |
699 | f.at(0); | 710 | f.at(0); |
700 | // Lview->clear(); | 711 | // Lview->clear(); |
701 | QString s; | 712 | QString s; |
702 | int lineNo=0; | 713 | int lineNo=0; |
703 | int lastPage=1; | 714 | int lastPage=1; |
704 | while ( !f.atEnd() ) { | 715 | while ( !f.atEnd() ) { |
705 | f.readLine(s, 256); | 716 | f.readLine(s, 256); |
706 | lineNo++; | 717 | lineNo++; |
707 | currentFilePos = f.at(); | 718 | currentFilePos = f.at(); |
708 | 719 | ||
709 | i_pageNum = lineNo/pageSize; | 720 | i_pageNum = lineNo/pageSize; |
710 | if(lastPage < i_pageNum) { | 721 | if(lastPage < i_pageNum) { |
711 | pageStopArray.resize(i_pageNum + 1); | 722 | pageStopArray.resize(i_pageNum + 1); |
712 | pageStopArray[i_pageNum ] = currentFilePos; | 723 | pageStopArray[i_pageNum ] = currentFilePos; |
713 | // odebug << "new page number " << i_pageNum << ", found at " << currentFilePos << "" << oendl; | 724 | // odebug << "new page number " << i_pageNum << ", found at " << currentFilePos << "" << oendl; |
714 | } | 725 | } |
715 | if(currentFilePos == bookmarkPosition) | 726 | if(currentFilePos == bookmarkPosition) |
716 | break; | 727 | break; |
717 | } | 728 | } |
718 | if(f.atEnd()) | 729 | if(f.atEnd()) |
719 | f.at(0); | 730 | f.at(0); |
720 | else | 731 | else |
721 | f.at( bookmarkPosition); | 732 | f.at( bookmarkPosition); |
722 | 733 | ||
723 | for(int fd=0; fd < pageSize - 1;fd++) { | 734 | for(int fd=0; fd < pageSize - 1;fd++) { |
724 | f.readLine(s, 256); | 735 | f.readLine(s, 256); |
725 | lineNo++; | 736 | lineNo++; |
726 | if(useWrap) | 737 | if(useWrap) |
727 | s.replace(QRegExp("\n"),""); | 738 | s.replace(QRegExp("\n"),""); |
728 | Lview->insertLine( s, -1); | 739 | Lview->insertLine( s, -1); |
729 | currentLine++; | 740 | currentLine++; |
730 | } | 741 | } |
731 | 742 | ||
732 | i_pageNum = lineNo/pageSize; | 743 | i_pageNum = lineNo/pageSize; |
733 | pageStopArray.resize(i_pageNum + 1); | 744 | pageStopArray.resize(i_pageNum + 1); |
734 | 745 | ||
735 | if(showMainList) { | 746 | if(showMainList) { |
736 | showMainList=FALSE; | 747 | showMainList=FALSE; |
737 | mainList->hide(); | 748 | mainList->hide(); |
738 | Lview->show(); | 749 | Lview->show(); |
739 | // qApp->processEvents(); | 750 | // qApp->processEvents(); |
740 | } | 751 | } |
741 | 752 | ||
742 | odebug << "bookmark loaded" << oendl; | 753 | odebug << "bookmark loaded" << oendl; |
743 | setCaption(title); | 754 | setCaption(title); |
744 | } | 755 | } |
745 | 756 | ||
746 | 757 | ||
747 | bool Gutenbrowser::load( const char *fileName) { | 758 | bool Gutenbrowser::load( const char *fileName) { |
748 | 759 | ||
749 | // QCopEnvelope ( "QPE/System", "busy()" ); | 760 | // QCopEnvelope ( "QPE/System", "busy()" ); |
750 | odebug << "Title is already set as "+title << oendl; | 761 | odebug << "Title is already set as "+title << oendl; |
751 | odebug << "sizeHint " << sizeHint().height() << " pageSize " << Lview->PageSize() << "" << oendl; | 762 | odebug << "sizeHint " << sizeHint().height() << " pageSize " << Lview->PageSize() << "" << oendl; |
752 | // pointSize = Lview->fontInfo().pointSize(); | 763 | // pointSize = Lview->fontInfo().pointSize(); |