Diffstat (limited to 'noncore/apps/opie-gutenbrowser/openetext.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/apps/opie-gutenbrowser/openetext.cpp | 55 |
1 files changed, 29 insertions, 26 deletions
diff --git a/noncore/apps/opie-gutenbrowser/openetext.cpp b/noncore/apps/opie-gutenbrowser/openetext.cpp index bd44ce6..0267416 100644 --- a/noncore/apps/opie-gutenbrowser/openetext.cpp +++ b/noncore/apps/opie-gutenbrowser/openetext.cpp | |||
@@ -15,26 +15,29 @@ | |||
15 | #include "gutenbrowser.h" | 15 | #include "gutenbrowser.h" |
16 | #include "openetext.h" | 16 | #include "openetext.h" |
17 | #include "editTitle.h" | 17 | #include "editTitle.h" |
18 | 18 | ||
19 | /* OPIE */ | 19 | /* OPIE */ |
20 | #include <opie2/ofiledialog.h> | 20 | #include <opie2/ofiledialog.h> |
21 | #include <opie2/odebug.h> | ||
21 | #include <qpe/applnk.h> | 22 | #include <qpe/applnk.h> |
22 | #include <qpe/config.h> | 23 | #include <qpe/config.h> |
23 | #include <qpe/qpeapplication.h> | 24 | #include <qpe/qpeapplication.h> |
24 | using namespace Opie::Ui; | 25 | using namespace Opie::Ui; |
25 | 26 | ||
26 | #include <stdlib.h> | 27 | /* QT */ |
27 | #include <qtextstream.h> | 28 | #include <qtextstream.h> |
28 | #include <qfileinfo.h> | 29 | #include <qfileinfo.h> |
29 | 30 | ||
31 | /* STD */ | ||
30 | #if defined(_WS_WIN_) | 32 | #if defined(_WS_WIN_) |
31 | #include <windows.h> | 33 | #include <windows.h> |
32 | #else | 34 | #else |
33 | #include <unistd.h> | 35 | #include <unistd.h> |
34 | #include "sys/stat.h" | 36 | #include <stdlib.h> |
37 | #include <sys/stat.h> | ||
35 | #endif | 38 | #endif |
36 | 39 | ||
37 | OpenEtext::OpenEtext(QWidget *parent, QString name) : QDialog(parent,name,true) | 40 | OpenEtext::OpenEtext(QWidget *parent, QString name) : QDialog(parent,name,true) |
38 | { | 41 | { |
39 | local_library = (QDir::homeDirPath ()) +"/Applications/gutenbrowser/"; | 42 | local_library = (QDir::homeDirPath ()) +"/Applications/gutenbrowser/"; |
40 | local_index=local_library+"GUTINDEX.ALL"; | 43 | local_index=local_library+"GUTINDEX.ALL"; |
@@ -131,13 +134,13 @@ OpenFileButton->setDown(TRUE); | |||
131 | 134 | ||
132 | QString str = OFileDialog::getOpenFileName( 2, dir , QString::null, map); | 135 | QString str = OFileDialog::getOpenFileName( 2, dir , QString::null, map); |
133 | 136 | ||
134 | if( !str.isEmpty() && QFile(str).exists() && !QFileInfo(str).isDir() ) { | 137 | if( !str.isEmpty() && QFile(str).exists() && !QFileInfo(str).isDir() ) { |
135 | filer = str; | 138 | filer = str; |
136 | 139 | ||
137 | qDebug("Open file: "+str); | 140 | odebug << "Open file: "+str << oendl; |
138 | 141 | ||
139 | // QStringList::ConstIterator f; | 142 | // QStringList::ConstIterator f; |
140 | // QString fileTemp; | 143 | // QString fileTemp; |
141 | // for ( f = fileList.begin(); f != fileList.end(); f++ ) { | 144 | // for ( f = fileList.begin(); f != fileList.end(); f++ ) { |
142 | // fileTemp = *f; | 145 | // fileTemp = *f; |
143 | // fileTemp.right( fileTemp.length()-5); | 146 | // fileTemp.right( fileTemp.length()-5); |
@@ -161,51 +164,51 @@ OpenFileButton->setDown(TRUE); | |||
161 | QString s_fileName = zipFile.fileName(); | 164 | QString s_fileName = zipFile.fileName(); |
162 | QString cmd; | 165 | QString cmd; |
163 | 166 | ||
164 | if( s_fileName.right(4) == ".zip") { // unzip that sucker.... | 167 | if( s_fileName.right(4) == ".zip") { // unzip that sucker.... |
165 | s_fileName = s_fileName.left( s_fileName.length() - 4); | 168 | s_fileName = s_fileName.left( s_fileName.length() - 4); |
166 | if( chdir((const char*)local_library.latin1())!=0) | 169 | if( chdir((const char*)local_library.latin1())!=0) |
167 | qDebug("chdir failed.");// QString cmd = "gunzip -d " + filer + " -d " + local_library; | 170 | odebug << "chdir failed." << oendl; // QString cmd = "gunzip -d " + filer + " -d " + local_library; |
168 | cmd = "gunzip -S .zip " + filer; | 171 | cmd = "gunzip -S .zip " + filer; |
169 | fileName = local_library + s_fileName + ".txt"; | 172 | fileName = local_library + s_fileName + ".txt"; |
170 | system( cmd); | 173 | system( cmd); |
171 | } | 174 | } |
172 | // this renames the .txt to .etx!! | 175 | // this renames the .txt to .etx!! |
173 | else /*if( s_fileName.right(4) == ".txt" || if( s_fileName.right(4) == ".TXT"))*/ { | 176 | else /*if( s_fileName.right(4) == ".txt" || if( s_fileName.right(4) == ".TXT"))*/ { |
174 | // qDebug("Filename is "+fileName); | 177 | // odebug << "Filename is "+fileName << oendl; |
175 | s_fileName = fileName; | 178 | s_fileName = fileName; |
176 | s_fileName.replace( s_fileName.length()-3,3,"gtn");// s_fileName.replace( s_fileName.length()-3,3,"etx"); | 179 | s_fileName.replace( s_fileName.length()-3,3,"gtn");// s_fileName.replace( s_fileName.length()-3,3,"etx"); |
177 | rename(fileName.latin1(),s_fileName.latin1()); | 180 | rename(fileName.latin1(),s_fileName.latin1()); |
178 | fileName = s_fileName; | 181 | fileName = s_fileName; |
179 | // qDebug("Filename is now "+fileName); | 182 | // odebug << "Filename is now "+fileName << oendl; |
180 | } | 183 | } |
181 | } else | 184 | } else |
182 | fileName = str; | 185 | fileName = str; |
183 | 186 | ||
184 | FindTitle(fileName); | 187 | FindTitle(fileName); |
185 | 188 | ||
186 | QFileInfo fi( fileName); | 189 | QFileInfo fi( fileName); |
187 | name_file = fi.fileName(); | 190 | name_file = fi.fileName(); |
188 | name_file = name_file.left(name_file.length() - 4); | 191 | name_file = name_file.left(name_file.length() - 4); |
189 | 192 | ||
190 | qDebug("Setting doclink"); | 193 | odebug << "Setting doclink" << oendl; |
191 | DocLnk lnk; | 194 | DocLnk lnk; |
192 | qDebug("name is " + name_file); | 195 | odebug << "name is " + name_file << oendl; |
193 | lnk.setName(name_file); //sets file name | 196 | lnk.setName(name_file); //sets file name |
194 | qDebug("Title is "+title); | 197 | odebug << "Title is "+title << oendl; |
195 | lnk.setComment(title); | 198 | lnk.setComment(title); |
196 | 199 | ||
197 | QListBox_1->clear(); | 200 | QListBox_1->clear(); |
198 | getTitles(); | 201 | getTitles(); |
199 | qDebug("Filename is "+fileName); | 202 | odebug << "Filename is "+fileName << oendl; |
200 | lnk.setFile(fileName); //sets File property | 203 | lnk.setFile(fileName); //sets File property |
201 | lnk.setType("guten/plain");// hey is this a REGISTERED mime type?!?!? ;D | 204 | lnk.setType("guten/plain");// hey is this a REGISTERED mime type?!?!? ;D |
202 | lnk.setExec(fileName); | 205 | lnk.setExec(fileName); |
203 | lnk.setIcon("gutenbrowser/Gutenbrowser"); | 206 | lnk.setIcon("gutenbrowser/Gutenbrowser"); |
204 | if(!lnk.writeLink()) | 207 | if(!lnk.writeLink()) |
205 | qDebug("Writing doclink did not work"); | 208 | odebug << "Writing doclink did not work" << oendl; |
206 | 209 | ||
207 | } // end of for each file name.... | 210 | } // end of for each file name.... |
208 | OpenFileButton->setDown(FALSE); | 211 | OpenFileButton->setDown(FALSE); |
209 | } | 212 | } |
210 | 213 | ||
211 | /* | 214 | /* |
@@ -216,19 +219,19 @@ bool OpenEtext::FindTitle( QString filename) | |||
216 | config.setGroup( "Files" ); | 219 | config.setGroup( "Files" ); |
217 | QString s_numofFiles = config.readEntry("NumberOfFiles", "0"); | 220 | QString s_numofFiles = config.readEntry("NumberOfFiles", "0"); |
218 | int i_numofFiles = s_numofFiles.toInt(); | 221 | int i_numofFiles = s_numofFiles.toInt(); |
219 | 222 | ||
220 | QFileInfo fi(filename); | 223 | QFileInfo fi(filename); |
221 | name = fi.fileName(); | 224 | name = fi.fileName(); |
222 | qDebug("filename to open is " + name); | 225 | odebug << "filename to open is " + name << oendl; |
223 | QFile indexLib( filename); | 226 | QFile indexLib( filename); |
224 | bool findCheck = FALSE; | 227 | bool findCheck = FALSE; |
225 | // int Titlenumber=0; | 228 | // int Titlenumber=0; |
226 | 229 | ||
227 | if ( indexLib.open( IO_ReadOnly) ) { | 230 | if ( indexLib.open( IO_ReadOnly) ) { |
228 | qDebug("file opened successfully"); | 231 | odebug << "file opened successfully" << oendl; |
229 | QTextStream indexStream( &indexLib ); | 232 | QTextStream indexStream( &indexLib ); |
230 | QString target = "Project Gutenberg Etext of"; | 233 | QString target = "Project Gutenberg Etext of"; |
231 | QString target2 = "Project Gutenberg Etext"; | 234 | QString target2 = "Project Gutenberg Etext"; |
232 | QString target3 = "Project Gutenberg's Etext of"; | 235 | QString target3 = "Project Gutenberg's Etext of"; |
233 | QString target4 = "Project Gutenberg's Etext"; | 236 | QString target4 = "Project Gutenberg's Etext"; |
234 | QString indexLine; | 237 | QString indexLine; |
@@ -236,42 +239,42 @@ bool OpenEtext::FindTitle( QString filename) | |||
236 | // until end of file.. | 239 | // until end of file.. |
237 | indexLine = indexStream.readLine(); | 240 | indexLine = indexStream.readLine(); |
238 | if( indexLine.find(target, 0, TRUE) > -1 && !findCheck) {findCheck = TRUE; | 241 | if( indexLine.find(target, 0, TRUE) > -1 && !findCheck) {findCheck = TRUE; |
239 | title = indexLine.mid( indexLine.find(target, 0, TRUE) + (target.length()) , indexLine.find("\r", 0, TRUE)); | 242 | title = indexLine.mid( indexLine.find(target, 0, TRUE) + (target.length()) , indexLine.find("\r", 0, TRUE)); |
240 | title = title.left( title.find( "*",0, TRUE)); | 243 | title = title.left( title.find( "*",0, TRUE)); |
241 | title = title.stripWhiteSpace (); | 244 | title = title.stripWhiteSpace (); |
242 | // qDebug("Found the title 1 and it is %s", title.latin1()); | 245 | // odebug << "Found the title 1 and it is " << title << "" << oendl; |
243 | // QListBox_1->insertItem ( title); | 246 | // QListBox_1->insertItem ( title); |
244 | } | 247 | } |
245 | if( indexLine.find( target2, 0, TRUE) > -1 && !findCheck) { | 248 | if( indexLine.find( target2, 0, TRUE) > -1 && !findCheck) { |
246 | findCheck = TRUE; | 249 | findCheck = TRUE; |
247 | title = indexLine.mid( indexLine.find( target2, 0, TRUE ) + ( target2.length()) , indexLine.find("\r", 0, TRUE) ); | 250 | title = indexLine.mid( indexLine.find( target2, 0, TRUE ) + ( target2.length()) , indexLine.find("\r", 0, TRUE) ); |
248 | title = title.left( title.find( "*",0, TRUE)); | 251 | title = title.left( title.find( "*",0, TRUE)); |
249 | title = title.stripWhiteSpace (); | 252 | title = title.stripWhiteSpace (); |
250 | // qDebug("Found the title 2 and it is %s", title.latin1()); | 253 | // odebug << "Found the title 2 and it is " << title << "" << oendl; |
251 | // QListBox_1->insertItem ( title); | 254 | // QListBox_1->insertItem ( title); |
252 | } | 255 | } |
253 | if( indexLine.find( target3, 0, TRUE) > -1 && !findCheck) { | 256 | if( indexLine.find( target3, 0, TRUE) > -1 && !findCheck) { |
254 | findCheck = TRUE; | 257 | findCheck = TRUE; |
255 | title = indexLine.mid( indexLine.find( target3, 0, TRUE) + ( target3.length()) , indexLine.find("\r", 0, TRUE)); | 258 | title = indexLine.mid( indexLine.find( target3, 0, TRUE) + ( target3.length()) , indexLine.find("\r", 0, TRUE)); |
256 | title = title.left( title.find( "*",0, TRUE)); | 259 | title = title.left( title.find( "*",0, TRUE)); |
257 | title = title.stripWhiteSpace (); | 260 | title = title.stripWhiteSpace (); |
258 | // qDebug("Found the title 3 and it is %s", title.latin1()); | 261 | // odebug << "Found the title 3 and it is " << title << "" << oendl; |
259 | } | 262 | } |
260 | if( indexLine.find( target4, 0, TRUE) > -1 && !findCheck) { | 263 | if( indexLine.find( target4, 0, TRUE) > -1 && !findCheck) { |
261 | findCheck = TRUE; | 264 | findCheck = TRUE; |
262 | title = indexLine.mid( indexLine.find( target4, 0, TRUE) + ( target4.length()) , indexLine.find("\r", 0, TRUE)); | 265 | title = indexLine.mid( indexLine.find( target4, 0, TRUE) + ( target4.length()) , indexLine.find("\r", 0, TRUE)); |
263 | title = title.left( title.find( "*",0, TRUE)); | 266 | title = title.left( title.find( "*",0, TRUE)); |
264 | title = title.stripWhiteSpace (); | 267 | title = title.stripWhiteSpace (); |
265 | // qDebug("Found the title 4 and it is %s", title.latin1()); | 268 | // odebug << "Found the title 4 and it is " << title << "" << oendl; |
266 | } | 269 | } |
267 | } //endof file | 270 | } //endof file |
268 | indexLib.close(); | 271 | indexLib.close(); |
269 | 272 | ||
270 | if( !findCheck || title.length() < 2) { | 273 | if( !findCheck || title.length() < 2) { |
271 | qDebug("Trying hard to find title from GUTINDEX.ALL"); | 274 | odebug << "Trying hard to find title from GUTINDEX.ALL" << oendl; |
272 | title = titleFromLibrary( filename); | 275 | title = titleFromLibrary( filename); |
273 | findCheck = TRUE; | 276 | findCheck = TRUE; |
274 | } | 277 | } |
275 | 278 | ||
276 | if ( checkConf() == false && findCheck == TRUE) { | 279 | if ( checkConf() == false && findCheck == TRUE) { |
277 | 280 | ||
@@ -290,13 +293,13 @@ bool OpenEtext::FindTitle( QString filename) | |||
290 | QString title1 = config.readEntry(ramble, ""); | 293 | QString title1 = config.readEntry(ramble, ""); |
291 | if(title1==title) | 294 | if(title1==title) |
292 | title+="1"; | 295 | title+="1"; |
293 | i= i_numofFiles+1; | 296 | i= i_numofFiles+1; |
294 | } | 297 | } |
295 | if(title.length()<3) { | 298 | if(title.length()<3) { |
296 | // qDebug("title is empty"); | 299 | // odebug << "title is empty" << oendl; |
297 | title="Unknown"; | 300 | title="Unknown"; |
298 | } | 301 | } |
299 | config.writeEntry( filename,title); | 302 | config.writeEntry( filename,title); |
300 | } | 303 | } |
301 | } else { | 304 | } else { |
302 | QString sMsg; | 305 | QString sMsg; |
@@ -340,19 +343,19 @@ QString OpenEtext::titleFromLibrary( QString fileName) | |||
340 | 343 | ||
341 | if( indexLine.find( target,0,FALSE) > 0 ) { | 344 | if( indexLine.find( target,0,FALSE) > 0 ) { |
342 | findCheck = TRUE; | 345 | findCheck = TRUE; |
343 | title = indexLine.mid( 9, 50); | 346 | title = indexLine.mid( 9, 50); |
344 | // title = indexLine.mid( 26, indexLine.length() ); | 347 | // title = indexLine.mid( 26, indexLine.length() ); |
345 | title = title.stripWhiteSpace (); | 348 | title = title.stripWhiteSpace (); |
346 | // qDebug("Finally Found the title and it is\n %s", title.latin1()); | 349 | // odebug << "Finally Found the title and it is\n " << title << "" << oendl; |
347 | // QListBox_1->insertItem ( title); | 350 | // QListBox_1->insertItem ( title); |
348 | } | 351 | } |
349 | } //end while loop | 352 | } //end while loop |
350 | } | 353 | } |
351 | else | 354 | else |
352 | qDebug("Error opening library index "+ local_index); | 355 | odebug << "Error opening library index "+ local_index << oendl; |
353 | return title; | 356 | return title; |
354 | } | 357 | } |
355 | 358 | ||
356 | bool OpenEtext::checkConf() | 359 | bool OpenEtext::checkConf() |
357 | { | 360 | { |
358 | QString file = fileName; | 361 | QString file = fileName; |
@@ -411,13 +414,13 @@ void OpenEtext::removeSelection() | |||
411 | QString s_filename = config.readEntry(fileNum, "" ); | 414 | QString s_filename = config.readEntry(fileNum, "" ); |
412 | config.setGroup( "Titles" ); | 415 | config.setGroup( "Titles" ); |
413 | 416 | ||
414 | QString file_title = config.readEntry( s_filename, ""); | 417 | QString file_title = config.readEntry( s_filename, ""); |
415 | if(title_text == file_title) { | 418 | if(title_text == file_title) { |
416 | rem=i; | 419 | rem=i; |
417 | //qDebug("file title to remove is "+file_title); | 420 | //odebug << "file title to remove is "+file_title << oendl; |
418 | selFile = s_filename; | 421 | selFile = s_filename; |
419 | config.removeEntry( s_filename); //removes file=title | 422 | config.removeEntry( s_filename); //removes file=title |
420 | } | 423 | } |
421 | } | 424 | } |
422 | config.setGroup( "Files" ); | 425 | config.setGroup( "Files" ); |
423 | 426 | ||
@@ -479,13 +482,13 @@ void OpenEtext::scan() { | |||
479 | } | 482 | } |
480 | 483 | ||
481 | void OpenEtext::editTitle() { | 484 | void OpenEtext::editTitle() { |
482 | 485 | ||
483 | int currentItem=QListBox_1->currentItem(); | 486 | int currentItem=QListBox_1->currentItem(); |
484 | QString title_text = QListBox_1->text( currentItem); | 487 | QString title_text = QListBox_1->text( currentItem); |
485 | //qDebug("Selected "+title_text); | 488 | //odebug << "Selected "+title_text << oendl; |
486 | 489 | ||
487 | Config config("Gutenbrowser"); | 490 | Config config("Gutenbrowser"); |
488 | config.setGroup( "Files" ); | 491 | config.setGroup( "Files" ); |
489 | s_numofFiles = config.readEntry("NumberOfFiles", "0"); | 492 | s_numofFiles = config.readEntry("NumberOfFiles", "0"); |
490 | int i_numofFiles = s_numofFiles.toInt(); | 493 | int i_numofFiles = s_numofFiles.toInt(); |
491 | QString fileNum; | 494 | QString fileNum; |
@@ -493,21 +496,21 @@ void OpenEtext::editTitle() { | |||
493 | 496 | ||
494 | fileNum.setNum(i); | 497 | fileNum.setNum(i); |
495 | config.setGroup( "Files" ); | 498 | config.setGroup( "Files" ); |
496 | QString s_filename = config.readEntry(fileNum, "" ); | 499 | QString s_filename = config.readEntry(fileNum, "" ); |
497 | config.setGroup( "Titles" ); | 500 | config.setGroup( "Titles" ); |
498 | QString file_title = config.readEntry( s_filename, ""); | 501 | QString file_title = config.readEntry( s_filename, ""); |
499 | //qDebug("file_title is "+file_title); | 502 | //odebug << "file_title is "+file_title << oendl; |
500 | if(title_text == file_title ) { | 503 | if(title_text == file_title ) { |
501 | selFile = s_filename; | 504 | selFile = s_filename; |
502 | //qDebug("Edit: "+ file_title ); | 505 | //odebug << "Edit: "+ file_title << oendl; |
503 | i=i_numofFiles+1; | 506 | i=i_numofFiles+1; |
504 | Edit_Title *titleEdit; | 507 | Edit_Title *titleEdit; |
505 | titleEdit = new Edit_Title(this,file_title ,TRUE); | 508 | titleEdit = new Edit_Title(this,file_title ,TRUE); |
506 | if(titleEdit->exec() !=0) { | 509 | if(titleEdit->exec() !=0) { |
507 | //qDebug(titleEdit->newTitle); | 510 | //odebug << titleEdit->newTitle << oendl; |
508 | config.writeEntry( s_filename, titleEdit->newTitle); | 511 | config.writeEntry( s_filename, titleEdit->newTitle); |
509 | QListBox_1->removeItem(currentItem); | 512 | QListBox_1->removeItem(currentItem); |
510 | QListBox_1->insertItem ( QPixmap( QPEApplication::qpeDir()+"pics/gutenbrowser/gutenbrowser_sm.png"), titleEdit->newTitle, currentItem); | 513 | QListBox_1->insertItem ( QPixmap( QPEApplication::qpeDir()+"pics/gutenbrowser/gutenbrowser_sm.png"), titleEdit->newTitle, currentItem); |
511 | } | 514 | } |
512 | } | 515 | } |
513 | } | 516 | } |