summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-gutenbrowser/openetext.cpp
Unidiff
Diffstat (limited to 'noncore/apps/opie-gutenbrowser/openetext.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-gutenbrowser/openetext.cpp174
1 files changed, 83 insertions, 91 deletions
diff --git a/noncore/apps/opie-gutenbrowser/openetext.cpp b/noncore/apps/opie-gutenbrowser/openetext.cpp
index 0267416..a5d855d 100644
--- a/noncore/apps/opie-gutenbrowser/openetext.cpp
+++ b/noncore/apps/opie-gutenbrowser/openetext.cpp
@@ -57,8 +57,7 @@ void OpenEtext::getTitles()
57 Config config("Gutenbrowser"); 57 Config config("Gutenbrowser");
58 config.setGroup( "Files" ); 58 config.setGroup( "Files" );
59 s_numofFiles = config.readEntry("NumberOfFiles", "0"); 59 s_numofFiles = config.readEntry("NumberOfFiles", "0");
60 QLabel_1->setText( tr( 60 QLabel_1->setText( tr( s_numofFiles+" etexts in your library." ) );
61 s_numofFiles+" etexts in your library."));
62 int i_numofFiles = s_numofFiles.toInt(); 61 int i_numofFiles = s_numofFiles.toInt();
63 for (int i = 1; i <= i_numofFiles+1; i++) { 62 for (int i = 1; i <= i_numofFiles+1; i++) {
64 QString temp; 63 QString temp;
@@ -68,7 +67,12 @@ void OpenEtext::getTitles()
68 config.setGroup( "Titles" ); 67 config.setGroup( "Titles" );
69 title = config.readEntry(ramble, ""); 68 title = config.readEntry(ramble, "");
70 if( !title.isEmpty()) { 69 if( !title.isEmpty()) {
71 QListBox_1->insertItem ( QPixmap( QPEApplication::qpeDir()+"pics/gutenbrowser/gutenbrowser_sm.png"), title, -1); 70 QListBox_1->insertItem ( QPixmap(
71 QPEApplication::qpeDir() +
72 "pics/gutenbrowser/gutenbrowser_sm.png"
73 ),
74 title,
75 -1);
72 } 76 }
73 } 77 }
74} 78}
@@ -100,8 +104,9 @@ void OpenEtext::select_title(int index )
100 OpenEtext::accept(); 104 OpenEtext::accept();
101} 105}
102 106
103/* 107/*!
104 This function imports already existing etexts into the local library list*/ 108 * This function imports already existing etexts into the local library list
109 */
105void OpenEtext::open() 110void OpenEtext::open()
106{ 111{
107OpenFileButton->setDown(TRUE); 112OpenFileButton->setDown(TRUE);
@@ -113,14 +118,6 @@ OpenFileButton->setDown(TRUE);
113 local = (QDir::homeDirPath () +"Applications/gutenbrowser"); 118 local = (QDir::homeDirPath () +"Applications/gutenbrowser");
114 QDir library( local); 119 QDir library( local);
115 120
116// fileBrowser *browseForFiles;
117// browseForFiles=new fileBrowser(this,"Browse for File", TRUE, 0, "guten/plain;text/plain");
118// // browseForFiles=new fileBrowser(this,"fileBrowser",TRUE,0, "*");
119// browseForFiles->setFileView( 0);
120// browseForFiles->showMaximized();
121// browseForFiles->exec();
122// QString selFile= browseForFiles->selectedFileName;
123// fileList=browseForFiles->fileList;
124 Config cfg("Gutenbrowser"); 121 Config cfg("Gutenbrowser");
125 cfg. setGroup ( "View" ); 122 cfg. setGroup ( "View" );
126 QString dir = cfg.readEntry("LastOpenDirectory", QPEApplication::documentDir()); 123 QString dir = cfg.readEntry("LastOpenDirectory", QPEApplication::documentDir());
@@ -134,55 +131,43 @@ OpenFileButton->setDown(TRUE);
134 131
135 QString str = OFileDialog::getOpenFileName( 2, dir , QString::null, map); 132 QString str = OFileDialog::getOpenFileName( 2, dir , QString::null, map);
136 133
137 if( !str.isEmpty() && QFile(str).exists() && !QFileInfo(str).isDir() ) { 134 if( !str.isEmpty() && QFile(str).exists() && !QFileInfo(str).isDir() ) {
138 filer = str; 135 filer = str;
139 136
140 odebug << "Open file: "+str << oendl; 137 odebug << "Open file: "+str << oendl;
141 138
142 // QStringList::ConstIterator f; 139 if( filer.right(4) == ".txt" ||
143// QString fileTemp; 140 filer.right(4) == ".TXT" ||
144// for ( f = fileList.begin(); f != fileList.end(); f++ ) { 141 filer.right(4) == ".etx" ||
145// fileTemp = *f; 142 filer.right(4) == ".ETX" ||
146// fileTemp.right( fileTemp.length()-5); 143 filer.right(4) == ".etx" ||
147// fileName = fileTemp; 144 filer.right(4) == ".ETX" ||
148// if( !fileName.isEmpty() ){ 145 filer.right(4) == ".zip" ||
149// filer = fileName; 146 filer.right(4) == ".ZIP" )
150// } else { //filename is empty 147 {
151// // QString sMsg;
152// // sMsg = "Error opening library filelist "+fileName;
153// }
154
155 if( filer.right(4) == ".txt"
156 || filer.right(4) == ".TXT"
157 || filer.right(4) == ".etx"
158 || filer.right(4) == ".ETX"
159 || filer.right(4) == ".etx"
160 || filer.right(4) == ".ETX"
161 || filer.right(4) == ".zip"
162 || filer.right(4) == ".ZIP" ) {
163 QFileInfo zipFile( filer); 148 QFileInfo zipFile( filer);
164 QString s_fileName = zipFile.fileName(); 149 QString s_fileName = zipFile.fileName();
165 QString cmd; 150 QString cmd;
166 151
167 if( s_fileName.right(4) == ".zip") { // unzip that sucker.... 152 if( s_fileName.right(4) == ".zip") { // unzip the file
168 s_fileName = s_fileName.left( s_fileName.length() - 4); 153 s_fileName = s_fileName.left( s_fileName.length() - 4);
169 if( chdir((const char*)local_library.latin1())!=0) 154 if( chdir((const char*)local_library.latin1())!=0)
170 odebug << "chdir failed." << oendl; // QString cmd = "gunzip -d " + filer + " -d " + local_library; 155 odebug << "chdir failed." << oendl;
171 cmd = "gunzip -S .zip " + filer; 156 cmd = "gunzip -S .zip " + filer;
172 fileName = local_library + s_fileName + ".txt"; 157 fileName = local_library + s_fileName + ".txt";
173 system( cmd); 158 system( cmd);
174 } 159 } else { // else rename .txt to .etx
175// this renames the .txt to .etx!! 160 // odebug << "Filename is "+fileName << oendl;
176 else /*if( s_fileName.right(4) == ".txt" || if( s_fileName.right(4) == ".TXT"))*/ {
177// odebug << "Filename is "+fileName << oendl;
178 s_fileName = fileName; 161 s_fileName = fileName;
179 s_fileName.replace( s_fileName.length()-3,3,"gtn");// s_fileName.replace( s_fileName.length()-3,3,"etx"); 162 s_fileName.replace( s_fileName.length()-3,3,"gtn");
180 rename(fileName.latin1(),s_fileName.latin1()); 163 if (rename(fileName.latin1(),s_fileName.latin1()) == -1)
164 owarn << "Rename of " << fileName.latin1() << " to "
165 << s_fileName.latin1() << " failed" << oendl;
181 fileName = s_fileName; 166 fileName = s_fileName;
182// odebug << "Filename is now "+fileName << oendl; 167 // odebug << "Filename is now "+fileName << oendl;
183 } 168 }
184 } else 169 } else
185 fileName = str; 170 fileName = str;
186 171
187 FindTitle(fileName); 172 FindTitle(fileName);
188 173
@@ -201,14 +186,17 @@ OpenFileButton->setDown(TRUE);
201 getTitles(); 186 getTitles();
202 odebug << "Filename is "+fileName << oendl; 187 odebug << "Filename is "+fileName << oendl;
203 lnk.setFile(fileName); //sets File property 188 lnk.setFile(fileName); //sets File property
204 lnk.setType("guten/plain");// hey is this a REGISTERED mime type?!?!? ;D 189 // @bug This is probably not a registered MIME type. Perhaps we should
190 // set a valid MIME type here instead. Or maybe register .etx as a
191 // Gutenberge etext?
192 lnk.setType("guten/plain");
205 lnk.setExec(fileName); 193 lnk.setExec(fileName);
206 lnk.setIcon("gutenbrowser/Gutenbrowser"); 194 lnk.setIcon("gutenbrowser/Gutenbrowser");
207 if(!lnk.writeLink()) 195 if(!lnk.writeLink())
208 odebug << "Writing doclink did not work" << oendl; 196 odebug << "Writing doclink did not work" << oendl;
209 197
210 } // end of for each file name.... 198 } // end of for each file name....
211 OpenFileButton->setDown(FALSE); 199 OpenFileButton->setDown(FALSE);
212} 200}
213 201
214/* 202/*
@@ -224,11 +212,10 @@ bool OpenEtext::FindTitle( QString filename)
224 name = fi.fileName(); 212 name = fi.fileName();
225 odebug << "filename to open is " + name << oendl; 213 odebug << "filename to open is " + name << oendl;
226 QFile indexLib( filename); 214 QFile indexLib( filename);
227 bool findCheck = FALSE; 215 bool findCheck = FALSE;
228 // int Titlenumber=0;
229 216
230 if ( indexLib.open( IO_ReadOnly) ) { 217 if ( indexLib.open( IO_ReadOnly) ) {
231 odebug << "file opened successfully" << oendl; 218 odebug << "file opened successfully" << oendl;
232 QTextStream indexStream( &indexLib ); 219 QTextStream indexStream( &indexLib );
233 QString target = "Project Gutenberg Etext of"; 220 QString target = "Project Gutenberg Etext of";
234 QString target2 = "Project Gutenberg Etext"; 221 QString target2 = "Project Gutenberg Etext";
@@ -236,22 +223,22 @@ bool OpenEtext::FindTitle( QString filename)
236 QString target4 = "Project Gutenberg's Etext"; 223 QString target4 = "Project Gutenberg's Etext";
237 QString indexLine; 224 QString indexLine;
238 while ( !indexStream.eof() ) { 225 while ( !indexStream.eof() ) {
239 // until end of file.. 226 // until end of file..
240 indexLine = indexStream.readLine(); 227 indexLine = indexStream.readLine();
241 if( indexLine.find(target, 0, TRUE) > -1 && !findCheck) {findCheck = TRUE; 228 if( indexLine.find(target, 0, TRUE) > -1 && !findCheck) {findCheck = TRUE;
242 title = indexLine.mid( indexLine.find(target, 0, TRUE) + (target.length()) , indexLine.find("\r", 0, TRUE)); 229 title = indexLine.mid( indexLine.find(target, 0, TRUE) + (target.length()) , indexLine.find("\r", 0, TRUE));
243 title = title.left( title.find( "*",0, TRUE)); 230 title = title.left( title.find( "*",0, TRUE));
244 title = title.stripWhiteSpace (); 231 title = title.stripWhiteSpace ();
245// odebug << "Found the title 1 and it is " << title << "" << oendl; 232// odebug << "Found the title 1 and it is " << title << "" << oendl;
246// QListBox_1->insertItem ( title); 233// QListBox_1->insertItem ( title);
247 } 234 }
248 if( indexLine.find( target2, 0, TRUE) > -1 && !findCheck) { 235 if( indexLine.find( target2, 0, TRUE) > -1 && !findCheck) {
249 findCheck = TRUE; 236 findCheck = TRUE;
250 title = indexLine.mid( indexLine.find( target2, 0, TRUE ) + ( target2.length()) , indexLine.find("\r", 0, TRUE) ); 237 title = indexLine.mid( indexLine.find( target2, 0, TRUE ) + ( target2.length()) , indexLine.find("\r", 0, TRUE) );
251 title = title.left( title.find( "*",0, TRUE)); 238 title = title.left( title.find( "*",0, TRUE));
252 title = title.stripWhiteSpace (); 239 title = title.stripWhiteSpace ();
253// odebug << "Found the title 2 and it is " << title << "" << oendl; 240// odebug << "Found the title 2 and it is " << title << "" << oendl;
254// QListBox_1->insertItem ( title); 241// QListBox_1->insertItem ( title);
255 } 242 }
256 if( indexLine.find( target3, 0, TRUE) > -1 && !findCheck) { 243 if( indexLine.find( target3, 0, TRUE) > -1 && !findCheck) {
257 findCheck = TRUE; 244 findCheck = TRUE;
@@ -277,7 +264,6 @@ bool OpenEtext::FindTitle( QString filename)
277 } 264 }
278 265
279 if ( checkConf() == false && findCheck == TRUE) { 266 if ( checkConf() == false && findCheck == TRUE) {
280
281 config.setGroup( "Files"); 267 config.setGroup( "Files");
282 config.writeEntry("NumberOfFiles",i_numofFiles + 1 ); 268 config.writeEntry("NumberOfFiles",i_numofFiles + 1 );
283 QString interger; 269 QString interger;
@@ -315,10 +301,10 @@ QString OpenEtext::titleFromLibrary( QString fileName)
315 QString target; 301 QString target;
316 int find1 = fileName.findRev("/",-1,TRUE) + 1; 302 int find1 = fileName.findRev("/",-1,TRUE) + 1;
317 int find2 = fileName.findRev(".gtn",-1,TRUE) - find1; 303 int find2 = fileName.findRev(".gtn",-1,TRUE) - find1;
318 if(find2==-1-find1) 304 if(find2== (-1-find1))
319 int find2 = fileName.findRev(".etx",-1,TRUE) - find1; 305 find2 = fileName.findRev(".etx",-1,TRUE) - find1;
320 else if(find2==-1-find1) 306 else if(find2==(-1-find1))
321 int find2 = fileName.findRev(".txt",-1,TRUE) - find1; 307 find2 = fileName.findRev(".txt",-1,TRUE) - find1;
322 308
323 target = fileName.mid( find1, find2 ); 309 target = fileName.mid( find1, find2 );
324 QString checker = target.right(1); 310 QString checker = target.right(1);
@@ -334,25 +320,24 @@ QString OpenEtext::titleFromLibrary( QString fileName)
334 } 320 }
335 } 321 }
336 if ( indexLib.open( IO_ReadOnly) ) { 322 if ( indexLib.open( IO_ReadOnly) ) {
337 // file opened successfully 323 // file opened successfully
338 QTextStream indexStream( &indexLib ); 324 QTextStream indexStream( &indexLib );
339 QString indexLine; 325 QString indexLine;
340 bool findCheck = FALSE; 326 bool findCheck = FALSE;
341 while ( !indexStream.atEnd() ) { // until end of file.. 327 while ( !indexStream.atEnd() ) { // until end of file..
342 indexLine = indexStream.readLine(); 328 indexLine = indexStream.readLine();
343 329
344 if( indexLine.find( target,0,FALSE) > 0 ) { 330 if( indexLine.find( target,0,FALSE) > 0 ) {
345 findCheck = TRUE; 331 findCheck = TRUE;
346 title = indexLine.mid( 9, 50); 332 title = indexLine.mid( 9, 50);
347// title = indexLine.mid( 26, indexLine.length() );
348 title = title.stripWhiteSpace (); 333 title = title.stripWhiteSpace ();
349// odebug << "Finally Found the title and it is\n " << title << "" << oendl; 334// odebug << "Finally Found the title and it is\n " << title << "" << oendl;
350// QListBox_1->insertItem ( title); 335// QListBox_1->insertItem ( title);
351 } 336 }
352 } //end while loop 337 } //end while loop
353 } 338 }
354 else 339 else
355 odebug << "Error opening library index "+ local_index << oendl; 340 odebug << "Error opening library index "+ local_index << oendl;
356 return title; 341 return title;
357} 342}
358 343
@@ -381,22 +366,25 @@ void OpenEtext::remove()
381{ 366{
382 title_text = QListBox_1->text( QListBox_1->currentItem() ); 367 title_text = QListBox_1->text( QListBox_1->currentItem() );
383 title_text=title_text.stripWhiteSpace(); 368 title_text=title_text.stripWhiteSpace();
384 QString msg ="<p>Do you really want to REMOVE\n" +title_text +"?\nThis will not delete the file.</P>"; 369 QString msg ="<p>Do you really want to REMOVE\n" + title_text +
385 switch( QMessageBox::information( this, (tr("Remove Etext")), 370 "?\nThis will not delete the file.</P>";
386 (tr(msg)), 371 switch( QMessageBox::information( this, tr("Remove Etext"),
387 (tr("&Yes")), (tr("&Cancel")), 0 )){ 372 tr(msg),
373 tr("&Yes"), tr("&Cancel"), 0 ) )
374 {
388 case 0: // Yes clicked, 375 case 0: // Yes clicked,
389 removeSelection(); 376 removeSelection();
390 QListBox_1->clear(); 377 QListBox_1->clear();
391 getTitles(); 378 getTitles();
392 break; 379 break;
393 case 1: // Cancel 380 case 1:
394 break; 381 default:
395 }; 382 }
396} 383}
397 384
398/* 385/*!
399 this removes selected title entry*/ 386 * This removes selected title entry
387 */
400void OpenEtext::removeSelection() 388void OpenEtext::removeSelection()
401{ 389{
402 Config config("Gutenbrowser"); 390 Config config("Gutenbrowser");
@@ -417,7 +405,7 @@ void OpenEtext::removeSelection()
417 QString file_title = config.readEntry( s_filename, ""); 405 QString file_title = config.readEntry( s_filename, "");
418 if(title_text == file_title) { 406 if(title_text == file_title) {
419 rem=i; 407 rem=i;
420//odebug << "file title to remove is "+file_title << oendl; 408 //odebug << "file title to remove is "+file_title << oendl;
421 selFile = s_filename; 409 selFile = s_filename;
422 config.removeEntry( s_filename); //removes file=title 410 config.removeEntry( s_filename); //removes file=title
423 } 411 }
@@ -436,11 +424,11 @@ void OpenEtext::removeSelection()
436 } 424 }
437 config.writeEntry("NumberOfFiles", i_numofFiles - 1 ); 425 config.writeEntry("NumberOfFiles", i_numofFiles - 1 );
438 config.removeEntry(fileNum2); 426 config.removeEntry(fileNum2);
439// remFile();
440} 427}
441 428
442/* 429/*!
443 removes file title name from list and config file*/ 430 * Removes file title name from list and config file
431 */
444void OpenEtext::remFile() 432void OpenEtext::remFile()
445{ 433{
446 Config config("Gutenbrowser"); 434 Config config("Gutenbrowser");
@@ -461,9 +449,8 @@ void OpenEtext::remFile()
461 fileNum2.setNum( fg + 1); 449 fileNum2.setNum( fg + 1);
462 QString s_filename2 = config.readEntry(fileNum2, "" ); 450 QString s_filename2 = config.readEntry(fileNum2, "" );
463 451
464 if (!s_filename2.isEmpty()) { 452 if (!s_filename2.isEmpty())
465 config.writeEntry(fileNum, s_filename2 ); 453 config.writeEntry(fileNum, s_filename2 );
466 }
467 } 454 }
468 } 455 }
469 } 456 }
@@ -473,8 +460,9 @@ void OpenEtext::remFile()
473 QListBox_1->triggerUpdate(true); 460 QListBox_1->triggerUpdate(true);
474} 461}
475 462
476/* 463/*!
477sorts the list*/ 464 * Sorts the list
465 */
478void OpenEtext::scan() { 466void OpenEtext::scan() {
479 467
480 QListBox_1->sort(TRUE); 468 QListBox_1->sort(TRUE);
@@ -485,7 +473,7 @@ void OpenEtext::editTitle() {
485 473
486 int currentItem=QListBox_1->currentItem(); 474 int currentItem=QListBox_1->currentItem();
487 QString title_text = QListBox_1->text( currentItem); 475 QString title_text = QListBox_1->text( currentItem);
488//odebug << "Selected "+title_text << oendl; 476 //odebug << "Selected "+title_text << oendl;
489 477
490 Config config("Gutenbrowser"); 478 Config config("Gutenbrowser");
491 config.setGroup( "Files" ); 479 config.setGroup( "Files" );
@@ -499,23 +487,27 @@ void OpenEtext::editTitle() {
499 QString s_filename = config.readEntry(fileNum, "" ); 487 QString s_filename = config.readEntry(fileNum, "" );
500 config.setGroup( "Titles" ); 488 config.setGroup( "Titles" );
501 QString file_title = config.readEntry( s_filename, ""); 489 QString file_title = config.readEntry( s_filename, "");
502//odebug << "file_title is "+file_title << oendl; 490 //odebug << "file_title is "+file_title << oendl;
503 if(title_text == file_title ) { 491 if(title_text == file_title ) {
504 selFile = s_filename; 492 selFile = s_filename;
505//odebug << "Edit: "+ file_title << oendl; 493 //odebug << "Edit: "+ file_title << oendl;
506 i=i_numofFiles+1; 494 i=i_numofFiles+1;
507 Edit_Title *titleEdit; 495 Edit_Title *titleEdit;
508 titleEdit = new Edit_Title(this,file_title ,TRUE); 496 titleEdit = new Edit_Title(this,file_title ,TRUE);
509 if(titleEdit->exec() !=0) { 497 if(titleEdit->exec() !=0) {
510//odebug << titleEdit->newTitle << oendl; 498 //odebug << titleEdit->newTitle << oendl;
511 config.writeEntry( s_filename, titleEdit->newTitle); 499 config.writeEntry( s_filename, titleEdit->newTitle);
512 QListBox_1->removeItem(currentItem); 500 QListBox_1->removeItem(currentItem);
513 QListBox_1->insertItem ( QPixmap( QPEApplication::qpeDir()+"pics/gutenbrowser/gutenbrowser_sm.png"), titleEdit->newTitle, currentItem); 501 QListBox_1->insertItem (
502 QPixmap( QPEApplication::qpeDir()+
503 "pics/gutenbrowser/gutenbrowser_sm.png"),
504 titleEdit->newTitle, currentItem
505 );
514 } 506 }
515 } 507 }
516 } 508 }
517 509
518// getTitles(); 510 //getTitles();
519 QListBox_1->triggerUpdate(true); 511 QListBox_1->triggerUpdate(true);
520} 512}
521 513