author | erik <erik> | 2007-02-05 20:18:36 (UTC) |
---|---|---|
committer | erik <erik> | 2007-02-05 20:18:36 (UTC) |
commit | b017b14c0ec6d327e061a1f96209e19fdc59885a (patch) (unidiff) | |
tree | 5b4727ced07dd1ef44a736dd4b0d75589f3ba06d | |
parent | 73edac572d9ac9cfd18cc1254fc2019563d55f16 (diff) | |
download | opie-b017b14c0ec6d327e061a1f96209e19fdc59885a.zip opie-b017b14c0ec6d327e061a1f96209e19fdc59885a.tar.gz opie-b017b14c0ec6d327e061a1f96209e19fdc59885a.tar.bz2 |
BUG: My change to a switch statement made opie-gutenbrowser uncompilable.
FIX: The code there is just strange. I tore out the switch statement and
replaced it with a simple if block instead.
-rw-r--r-- | noncore/apps/opie-gutenbrowser/openetext.cpp | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/noncore/apps/opie-gutenbrowser/openetext.cpp b/noncore/apps/opie-gutenbrowser/openetext.cpp index a5d855d..75edacd 100644 --- a/noncore/apps/opie-gutenbrowser/openetext.cpp +++ b/noncore/apps/opie-gutenbrowser/openetext.cpp | |||
@@ -275,203 +275,201 @@ bool OpenEtext::FindTitle( QString filename) | |||
275 | temp.setNum(i); | 275 | temp.setNum(i); |
276 | config.setGroup( "Files" ); | 276 | config.setGroup( "Files" ); |
277 | QString ramble = config.readEntry(temp, "" ); | 277 | QString ramble = config.readEntry(temp, "" ); |
278 | config.setGroup( "Titles" ); | 278 | config.setGroup( "Titles" ); |
279 | QString title1 = config.readEntry(ramble, ""); | 279 | QString title1 = config.readEntry(ramble, ""); |
280 | if(title1==title) | 280 | if(title1==title) |
281 | title+="1"; | 281 | title+="1"; |
282 | i= i_numofFiles+1; | 282 | i= i_numofFiles+1; |
283 | } | 283 | } |
284 | if(title.length()<3) { | 284 | if(title.length()<3) { |
285 | // odebug << "title is empty" << oendl; | 285 | // odebug << "title is empty" << oendl; |
286 | title="Unknown"; | 286 | title="Unknown"; |
287 | } | 287 | } |
288 | config.writeEntry( filename,title); | 288 | config.writeEntry( filename,title); |
289 | } | 289 | } |
290 | } else { | 290 | } else { |
291 | QString sMsg; | 291 | QString sMsg; |
292 | sMsg = "Error opening library file: "+filename; | 292 | sMsg = "Error opening library file: "+filename; |
293 | printf( sMsg+"\n"); | 293 | printf( sMsg+"\n"); |
294 | } | 294 | } |
295 | return true; | 295 | return true; |
296 | } | 296 | } |
297 | 297 | ||
298 | QString OpenEtext::titleFromLibrary( QString fileName) | 298 | QString OpenEtext::titleFromLibrary( QString fileName) |
299 | { | 299 | { |
300 | QFile indexLib( local_index); | 300 | QFile indexLib( local_index); |
301 | QString target; | 301 | QString target; |
302 | int find1 = fileName.findRev("/",-1,TRUE) + 1; | 302 | int find1 = fileName.findRev("/",-1,TRUE) + 1; |
303 | int find2 = fileName.findRev(".gtn",-1,TRUE) - find1; | 303 | int find2 = fileName.findRev(".gtn",-1,TRUE) - find1; |
304 | if(find2== (-1-find1)) | 304 | if(find2== (-1-find1)) |
305 | find2 = fileName.findRev(".etx",-1,TRUE) - find1; | 305 | find2 = fileName.findRev(".etx",-1,TRUE) - find1; |
306 | else if(find2==(-1-find1)) | 306 | else if(find2==(-1-find1)) |
307 | find2 = fileName.findRev(".txt",-1,TRUE) - find1; | 307 | find2 = fileName.findRev(".txt",-1,TRUE) - find1; |
308 | 308 | ||
309 | target = fileName.mid( find1, find2 ); | 309 | target = fileName.mid( find1, find2 ); |
310 | QString checker = target.right(1); | 310 | QString checker = target.right(1); |
311 | bool ok; | 311 | bool ok; |
312 | checker.toInt( &ok,10); | 312 | checker.toInt( &ok,10); |
313 | if( ok) { | 313 | if( ok) { |
314 | target = target.left( target.length()-1); | 314 | target = target.left( target.length()-1); |
315 | checker = target.right(1); | 315 | checker = target.right(1); |
316 | ok = FALSE; | 316 | ok = FALSE; |
317 | checker.toInt( &ok,10); | 317 | checker.toInt( &ok,10); |
318 | if( ok) { | 318 | if( ok) { |
319 | target = target.left( target.length()-1); | 319 | target = target.left( target.length()-1); |
320 | } | 320 | } |
321 | } | 321 | } |
322 | if ( indexLib.open( IO_ReadOnly) ) { | 322 | if ( indexLib.open( IO_ReadOnly) ) { |
323 | // file opened successfully | 323 | // file opened successfully |
324 | QTextStream indexStream( &indexLib ); | 324 | QTextStream indexStream( &indexLib ); |
325 | QString indexLine; | 325 | QString indexLine; |
326 | bool findCheck = FALSE; | 326 | bool findCheck = FALSE; |
327 | while ( !indexStream.atEnd() ) { // until end of file.. | 327 | while ( !indexStream.atEnd() ) { // until end of file.. |
328 | indexLine = indexStream.readLine(); | 328 | indexLine = indexStream.readLine(); |
329 | 329 | ||
330 | if( indexLine.find( target,0,FALSE) > 0 ) { | 330 | if( indexLine.find( target,0,FALSE) > 0 ) { |
331 | findCheck = TRUE; | 331 | findCheck = TRUE; |
332 | title = indexLine.mid( 9, 50); | 332 | title = indexLine.mid( 9, 50); |
333 | title = title.stripWhiteSpace (); | 333 | title = title.stripWhiteSpace (); |
334 | // odebug << "Finally Found the title and it is\n " << title << "" << oendl; | 334 | // odebug << "Finally Found the title and it is\n " << title << "" << oendl; |
335 | // QListBox_1->insertItem ( title); | 335 | // QListBox_1->insertItem ( title); |
336 | } | 336 | } |
337 | } //end while loop | 337 | } //end while loop |
338 | } | 338 | } |
339 | else | 339 | else |
340 | odebug << "Error opening library index "+ local_index << oendl; | 340 | odebug << "Error opening library index "+ local_index << oendl; |
341 | return title; | 341 | return title; |
342 | } | 342 | } |
343 | 343 | ||
344 | bool OpenEtext::checkConf() | 344 | bool OpenEtext::checkConf() |
345 | { | 345 | { |
346 | QString file = fileName; | 346 | QString file = fileName; |
347 | Config config("Gutenbrowser"); | 347 | Config config("Gutenbrowser"); |
348 | config.setGroup( "Files" ); | 348 | config.setGroup( "Files" ); |
349 | QString s_numofFiles = config.readEntry("NumberOfFiles", "0" ); | 349 | QString s_numofFiles = config.readEntry("NumberOfFiles", "0" ); |
350 | int i_numofFiles = s_numofFiles.toInt(); | 350 | int i_numofFiles = s_numofFiles.toInt(); |
351 | 351 | ||
352 | for (int i = 1; i <= i_numofFiles; i++) { | 352 | for (int i = 1; i <= i_numofFiles; i++) { |
353 | QString temp; | 353 | QString temp; |
354 | temp.setNum(i); | 354 | temp.setNum(i); |
355 | config.setGroup( "Files"); | 355 | config.setGroup( "Files"); |
356 | QString ramble = config.readEntry(temp, "" ); | 356 | QString ramble = config.readEntry(temp, "" ); |
357 | 357 | ||
358 | if(ramble == file ) { | 358 | if(ramble == file ) { |
359 | return true; | 359 | return true; |
360 | } | 360 | } |
361 | } | 361 | } |
362 | return false; | 362 | return false; |
363 | } | 363 | } |
364 | 364 | ||
365 | void OpenEtext::remove() | 365 | void OpenEtext::remove() |
366 | { | 366 | { |
367 | title_text = QListBox_1->text( QListBox_1->currentItem() ); | 367 | title_text = QListBox_1->text( QListBox_1->currentItem() ); |
368 | title_text=title_text.stripWhiteSpace(); | 368 | title_text=title_text.stripWhiteSpace(); |
369 | QString msg ="<p>Do you really want to REMOVE\n" + title_text + | 369 | QString msg ="<p>Do you really want to REMOVE\n" + title_text + |
370 | "?\nThis will not delete the file.</P>"; | 370 | "?\nThis will not delete the file.</P>"; |
371 | switch( QMessageBox::information( this, tr("Remove Etext"), | 371 | unsigned short clickVal = |
372 | tr(msg), | 372 | QMessageBox::information( this, tr("Remove Etext"), |
373 | tr("&Yes"), tr("&Cancel"), 0 ) ) | 373 | tr(msg), |
374 | { | 374 | tr("&Yes"), tr("&Cancel"), 0 ); |
375 | case 0: // Yes clicked, | 375 | if ( clickVal == 0 ) { |
376 | removeSelection(); | 376 | // The yes button was clicked |
377 | QListBox_1->clear(); | 377 | removeSelection(); |
378 | getTitles(); | 378 | QListBox_1->clear(); |
379 | break; | 379 | getTitles(); |
380 | case 1: | ||
381 | default: | ||
382 | } | 380 | } |
383 | } | 381 | } |
384 | 382 | ||
385 | /*! | 383 | /*! |
386 | * This removes selected title entry | 384 | * This removes selected title entry |
387 | */ | 385 | */ |
388 | void OpenEtext::removeSelection() | 386 | void OpenEtext::removeSelection() |
389 | { | 387 | { |
390 | Config config("Gutenbrowser"); | 388 | Config config("Gutenbrowser"); |
391 | config.setGroup( "Files" ); | 389 | config.setGroup( "Files" ); |
392 | s_numofFiles = config.readEntry("NumberOfFiles", "0"); | 390 | s_numofFiles = config.readEntry("NumberOfFiles", "0"); |
393 | int rem=0; | 391 | int rem=0; |
394 | int i_numofFiles = s_numofFiles.toInt(); | 392 | int i_numofFiles = s_numofFiles.toInt(); |
395 | QString fileNum2; | 393 | QString fileNum2; |
396 | QString fileNum; | 394 | QString fileNum; |
397 | 395 | ||
398 | for (int i = 1; i <= i_numofFiles; i++) { | 396 | for (int i = 1; i <= i_numofFiles; i++) { |
399 | fileNum.setNum(i); | 397 | fileNum.setNum(i); |
400 | config.setGroup( "Files" ); | 398 | config.setGroup( "Files" ); |
401 | 399 | ||
402 | QString s_filename = config.readEntry(fileNum, "" ); | 400 | QString s_filename = config.readEntry(fileNum, "" ); |
403 | config.setGroup( "Titles" ); | 401 | config.setGroup( "Titles" ); |
404 | 402 | ||
405 | QString file_title = config.readEntry( s_filename, ""); | 403 | QString file_title = config.readEntry( s_filename, ""); |
406 | if(title_text == file_title) { | 404 | if(title_text == file_title) { |
407 | rem=i; | 405 | rem=i; |
408 | //odebug << "file title to remove is "+file_title << oendl; | 406 | //odebug << "file title to remove is "+file_title << oendl; |
409 | selFile = s_filename; | 407 | selFile = s_filename; |
410 | config.removeEntry( s_filename); //removes file=title | 408 | config.removeEntry( s_filename); //removes file=title |
411 | } | 409 | } |
412 | } | 410 | } |
413 | config.setGroup( "Files" ); | 411 | config.setGroup( "Files" ); |
414 | 412 | ||
415 | for(int fg = rem; fg < i_numofFiles ; fg++ ) { //this rewrites Files number entry | 413 | for(int fg = rem; fg < i_numofFiles ; fg++ ) { //this rewrites Files number entry |
416 | fileNum.setNum(fg); | 414 | fileNum.setNum(fg); |
417 | fileNum2.setNum( fg + 1); | 415 | fileNum2.setNum( fg + 1); |
418 | 416 | ||
419 | QString s_filename2 = config.readEntry(fileNum2, "" ); | 417 | QString s_filename2 = config.readEntry(fileNum2, "" ); |
420 | 418 | ||
421 | if (!s_filename2.isEmpty()) { | 419 | if (!s_filename2.isEmpty()) { |
422 | config.writeEntry(fileNum, s_filename2 ); | 420 | config.writeEntry(fileNum, s_filename2 ); |
423 | } | 421 | } |
424 | } | 422 | } |
425 | config.writeEntry("NumberOfFiles", i_numofFiles - 1 ); | 423 | config.writeEntry("NumberOfFiles", i_numofFiles - 1 ); |
426 | config.removeEntry(fileNum2); | 424 | config.removeEntry(fileNum2); |
427 | } | 425 | } |
428 | 426 | ||
429 | /*! | 427 | /*! |
430 | * Removes file title name from list and config file | 428 | * Removes file title name from list and config file |
431 | */ | 429 | */ |
432 | void OpenEtext::remFile() | 430 | void OpenEtext::remFile() |
433 | { | 431 | { |
434 | Config config("Gutenbrowser"); | 432 | Config config("Gutenbrowser"); |
435 | config.setGroup( "Files" ); | 433 | config.setGroup( "Files" ); |
436 | QString remFile; | 434 | QString remFile; |
437 | s_numofFiles = config.readEntry("NumberOfFiles", "0"); | 435 | s_numofFiles = config.readEntry("NumberOfFiles", "0"); |
438 | int i_numofFiles = s_numofFiles.toInt(); | 436 | int i_numofFiles = s_numofFiles.toInt(); |
439 | for (int i = 1; i <= i_numofFiles; i++) { | 437 | for (int i = 1; i <= i_numofFiles; i++) { |
440 | QString fileNum; | 438 | QString fileNum; |
441 | fileNum.setNum(i); | 439 | fileNum.setNum(i); |
442 | QString s_filename = config.readEntry(fileNum, "" ); | 440 | QString s_filename = config.readEntry(fileNum, "" ); |
443 | 441 | ||
444 | if( s_filename == selFile) { | 442 | if( s_filename == selFile) { |
445 | config.removeEntry(selFile); | 443 | config.removeEntry(selFile); |
446 | 444 | ||
447 | for(int fg = i_numofFiles - i; fg < i_numofFiles ; fg++ ) { //this rewrites Files number entry | 445 | for(int fg = i_numofFiles - i; fg < i_numofFiles ; fg++ ) { //this rewrites Files number entry |
448 | QString fileNum2; | 446 | QString fileNum2; |
449 | fileNum2.setNum( fg + 1); | 447 | fileNum2.setNum( fg + 1); |
450 | QString s_filename2 = config.readEntry(fileNum2, "" ); | 448 | QString s_filename2 = config.readEntry(fileNum2, "" ); |
451 | 449 | ||
452 | if (!s_filename2.isEmpty()) | 450 | if (!s_filename2.isEmpty()) |
453 | config.writeEntry(fileNum, s_filename2 ); | 451 | config.writeEntry(fileNum, s_filename2 ); |
454 | } | 452 | } |
455 | } | 453 | } |
456 | } | 454 | } |
457 | config.writeEntry("NumberOfFiles", i_numofFiles - 1 ); | 455 | config.writeEntry("NumberOfFiles", i_numofFiles - 1 ); |
458 | config.removeEntry(s_numofFiles); | 456 | config.removeEntry(s_numofFiles); |
459 | 457 | ||
460 | QListBox_1->triggerUpdate(true); | 458 | QListBox_1->triggerUpdate(true); |
461 | } | 459 | } |
462 | 460 | ||
463 | /*! | 461 | /*! |
464 | * Sorts the list | 462 | * Sorts the list |
465 | */ | 463 | */ |
466 | void OpenEtext::scan() { | 464 | void OpenEtext::scan() { |
467 | 465 | ||
468 | QListBox_1->sort(TRUE); | 466 | QListBox_1->sort(TRUE); |
469 | QListBox_1->triggerUpdate(true); | 467 | QListBox_1->triggerUpdate(true); |
470 | } | 468 | } |
471 | 469 | ||
472 | void OpenEtext::editTitle() { | 470 | void OpenEtext::editTitle() { |
473 | 471 | ||
474 | int currentItem=QListBox_1->currentItem(); | 472 | int currentItem=QListBox_1->currentItem(); |
475 | QString title_text = QListBox_1->text( currentItem); | 473 | QString title_text = QListBox_1->text( currentItem); |
476 | //odebug << "Selected "+title_text << oendl; | 474 | //odebug << "Selected "+title_text << oendl; |
477 | 475 | ||