summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-gutenbrowser/LibraryDialog.cpp88
-rw-r--r--noncore/apps/opie-gutenbrowser/openetext.cpp174
-rw-r--r--noncore/multimedia/opieplayer2/lib.cpp30
-rw-r--r--noncore/multimedia/opieplayer2/om3u.cpp141
-rw-r--r--noncore/multimedia/opieplayer2/threadutil.cpp17
-rw-r--r--noncore/net/opiestumbler/opiestumbler.cpp3
-rw-r--r--noncore/settings/networksettings/mainwindow/mainwindowimp.cpp11
-rw-r--r--noncore/settings/networksettings/ppp/modem.cpp6
8 files changed, 235 insertions, 235 deletions
diff --git a/noncore/apps/opie-gutenbrowser/LibraryDialog.cpp b/noncore/apps/opie-gutenbrowser/LibraryDialog.cpp
index 6c246e97..7f21ab3 100644
--- a/noncore/apps/opie-gutenbrowser/LibraryDialog.cpp
+++ b/noncore/apps/opie-gutenbrowser/LibraryDialog.cpp
@@ -1,87 +1,87 @@
1/*************************************************************************** 1/***************************************************************************
2// LibraryDialog.cpp - description 2// LibraryDialog.cpp - description
3// ------------------- 3// -------------------
4// begin : Sat Aug 19 2000 4// begin : Sat Aug 19 2000
5// copyright : (C) 2000 - 2004 by llornkcor 5// copyright : (C) 2000 - 2004 by llornkcor
6// email : ljp@llornkcor.com 6// email : ljp@llornkcor.com
7// ***************************************************/ 7// ***************************************************/
8// /*************************************************************************** 8// /***************************************************************************
9// * This program is free software; you can redistribute it and/or modify * 9// * This program is free software; you can redistribute it and/or modify *
10// * it under the terms of the GNU General Public License as published by * 10// * it under the terms of the GNU General Public License as published by *
11// * the Free Software Foundation; either version 2 of the License, or * 11// * the Free Software Foundation; either version 2 of the License, or *
12// * (at your option) any later version. * 12// * (at your option) any later version. *
13// ***************************************************************************/ 13// ***************************************************************************/
14//ftp://ibiblio.org/pub/docs/books/gutenberg/GUTINDEX.ALL 14//ftp://ibiblio.org/pub/docs/books/gutenberg/GUTINDEX.ALL
15 15
16#include "LibraryDialog.h" 16#include "LibraryDialog.h"
17#include "output.h" 17#include "output.h"
18 18
19/* OPIE */ 19/* OPIE */
20#include <qpe/applnk.h> 20#include <qpe/applnk.h>
21#include <qpe/qpeapplication.h> 21#include <qpe/qpeapplication.h>
22#include <qpe/qpedialog.h> 22#include <qpe/qpedialog.h>
23//#include <opie2///odebug.h> 23#include <opie2/odebug.h>
24 24
25/* QT */ 25/* QT */
26#include <qpushbutton.h> 26#include <qpushbutton.h>
27#include <qmultilineedit.h> 27#include <qmultilineedit.h>
28//#include <qlayout.h> 28//#include <qlayout.h>
29 29
30/* STD */ 30/* STD */
31#include <unistd.h> 31#include <unistd.h>
32#include <stdio.h> 32#include <stdio.h>
33#include <stdlib.h> 33#include <stdlib.h>
34 34
35/* 35/*
36 * The dialog will by default be modeless, unless you set 'modal' to 36 * The dialog will by default be modeless, unless you set 'modal' to
37 * true to construct a modal dialog. */ 37 * true to construct a modal dialog. */
38LibraryDialog::LibraryDialog( QWidget* parent, const char* name , bool /*modal*/, WFlags fl ) 38LibraryDialog::LibraryDialog( QWidget* parent, const char* name , bool /*modal*/, WFlags fl )
39 : QDialog( parent, name, true/* modal*/, fl ) 39 : QDialog( parent, name, true/* modal*/, fl )
40{ 40{
41 if ( !name ) 41 if ( !name )
42 setName( "LibraryDialog" ); 42 setName( "LibraryDialog" );
43 indexLoaded=false; 43 indexLoaded=false;
44 initDialog(); 44 initDialog();
45 45
46 // this->setMaximumWidth(240); 46 // this->setMaximumWidth(240);
47 47
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 = local_library + "/gutenbrowserrc"; 53 iniFile = local_library + "/gutenbrowserrc";
54 new_index = local_library + "/PGWHOLE.TXT"; 54 new_index = local_library + "/PGWHOLE.TXT";
55 old_index = local_index; 55 old_index = local_index;
56 // iniFile = local_library+"gutenbrowserrc"; 56 // iniFile = local_library+"gutenbrowserrc";
57 // new_index = local_library + "PGWHOLE.TXT"; 57 // new_index = local_library + "PGWHOLE.TXT";
58 // old_index = local_library + "GUTINDEX.ALL"; 58 // old_index = local_library + "GUTINDEX.ALL";
59 59
60 Config config("Gutenbrowser"); 60 Config config("Gutenbrowser");
61 61
62 config.setGroup( "HttpServer" ); 62 config.setGroup( "HttpServer" );
63 proxy_http = config.readEntry("Preferred", "http://sailor.gutenbook.org"); 63 proxy_http = config.readEntry("Preferred", "http://sailor.gutenbook.org");
64 64
65 config.setGroup( "FTPsite" ); 65 config.setGroup( "FTPsite" );
66 ftp_host = config.readEntry("SiteName", "sailor.gutenberg.org"); 66 ftp_host = config.readEntry("SiteName", "sailor.gutenberg.org");
67 //odebug << "Library Dialog: ftp_host is "+ftp_host << oendl; 67 //odebug << "Library Dialog: ftp_host is "+ftp_host << oendl;
68 // ftp_host=ftp_host.right(ftp_host.length()-(ftp_host.find(") ",0,true)+1) ); 68 // ftp_host=ftp_host.right(ftp_host.length()-(ftp_host.find(") ",0,true)+1) );
69 // ftp_host=ftp_host.stripWhiteSpace(); 69 // ftp_host=ftp_host.stripWhiteSpace();
70 ftp_base_dir= config.readEntry("base", "/pub/gutenberg"); 70 ftp_base_dir= config.readEntry("base", "/pub/gutenberg");
71 71
72 i_binary = 0; 72 i_binary = 0;
73 73
74 config.setGroup("SortAuth"); 74 config.setGroup("SortAuth");
75 if( config.readEntry("authSort", "false") == "true") 75 if( config.readEntry("authSort", "false") == "true")
76 authBox->setChecked(true); 76 authBox->setChecked(true);
77 77
78 config.setGroup("General"); 78 config.setGroup("General");
79 downDir = config.readEntry( "DownloadDirectory",local_library); 79 downDir = config.readEntry( "DownloadDirectory",local_library);
80 //odebug << "downDir is "+downDir << oendl; 80 //odebug << "downDir is "+downDir << oendl;
81 newindexLib.setName( old_index); 81 newindexLib.setName( old_index);
82 indexLib.setName( old_index); 82 indexLib.setName( old_index);
83 83
84 new QPEDialogListener(this); 84 new QPEDialogListener(this);
85 QTimer::singleShot( 1000, this, SLOT( FindLibrary()) ); 85 QTimer::singleShot( 1000, this, SLOT( FindLibrary()) );
86 86
87} 87}
@@ -397,177 +397,180 @@ void LibraryDialog::select_title( QListViewItem * item)
397 }; 397 };
398 } 398 }
399 399
400 if(DlglistItemTitle.length() > 2) { 400 if(DlglistItemTitle.length() > 2) {
401 item = 0; 401 item = 0;
402 // todo check for connection here 402 // todo check for connection here
403 403
404 bool ok = false; 404 bool ok = false;
405 qDebug(DlglistItemFile); 405 qDebug(DlglistItemFile);
406 406
407 if(DlglistItemFile.toInt() > 10000 ) { 407 if(DlglistItemFile.toInt() > 10000 ) {
408 // new directory sturcture 408 // new directory sturcture
409 if( download_newEtext()) 409 if( download_newEtext())
410 ok = true; 410 ok = true;
411 } else { 411 } else {
412 if(download_Etext()) 412 if(download_Etext())
413 ok = true; 413 ok = true;
414 } 414 }
415 if(ok) { 415 if(ok) {
416 if(checkBox->isChecked () ) 416 if(checkBox->isChecked () )
417 accept(); 417 accept();
418 } 418 }
419 } 419 }
420} 420}
421 421
422bool LibraryDialog::download_newEtext() 422bool LibraryDialog::download_newEtext()
423{ // ftp method 423{ // ftp method
424 QString fileName = DlglistItemFile; 424 QString fileName = DlglistItemFile;
425 425
426 QString directory; 426 QString directory;
427 int stringlength = DlglistItemFile.length(); 427 int stringlength = DlglistItemFile.length();
428 for(i = 0; i < stringlength - 1; i++ ) { 428 for(i = 0; i < stringlength - 1; i++ ) {
429 directory += "/"+ DlglistItemFile[i]; 429 directory += "/"+ DlglistItemFile[i];
430 } 430 }
431 431
432 directory += "/" + DlglistItemFile; 432 directory += "/" + DlglistItemFile;
433 433
434// qWarning(directory); 434// qWarning(directory);
435 435
436 Config cfg("Gutenbrowser"); 436 Config cfg("Gutenbrowser");
437 cfg.setGroup("FTPsite"); 437 cfg.setGroup("FTPsite");
438 ftp_host = cfg.readEntry("SiteName", "sailor.gutenberg.org"); 438 ftp_host = cfg.readEntry("SiteName", "sailor.gutenberg.org");
439 ftp_base_dir = cfg.readEntry("base", "/pub/gutenberg"); 439 ftp_base_dir = cfg.readEntry("base", "/pub/gutenberg");
440 440
441 if( ftp_base_dir.find("=",0,true) ) 441 if( ftp_base_dir.find("=",0,true) )
442 ftp_base_dir.remove( ftp_base_dir.find("=",0,true),1); 442 ftp_base_dir.remove( ftp_base_dir.find("=",0,true),1);
443 443
444 QString dir = ftp_base_dir + directory; 444 QString dir = ftp_base_dir + directory;
445 QString outputFile = local_library + ".guten_temp"; 445 QString outputFile = local_library + ".guten_temp";
446 QString file = fileName + ".txt"; 446 QString file = fileName + ".txt";
447 447
448 QStringList networkList; 448 QStringList networkList;
449 networkList.append((const char *)ftp_host); //host 449 networkList.append((const char *)ftp_host); //host
450 networkList.append((const char *)dir); //ftp base directory 450 networkList.append((const char *)dir); //ftp base directory
451 networkList.append((const char *)outputFile); //output filepath 451 networkList.append((const char *)outputFile); //output filepath
452 networkList.append((const char *)file); //filename 452 networkList.append((const char *)file); //filename
453 453
454 getEtext( networkList); 454 getEtext( networkList);
455 455
456 return true; 456 return true;
457} 457}
458 458
459bool LibraryDialog::getEtext(const QStringList &networkList) 459bool LibraryDialog::getEtext(const QStringList &networkList)
460{ 460{
461 NetworkDialog *NetworkDlg; 461 NetworkDialog *NetworkDlg;
462 NetworkDlg = new NetworkDialog( this,"Network Protocol Dialog", true, 0, networkList); 462 NetworkDlg = new NetworkDialog( this,"Network Protocol Dialog", true, 0, networkList);
463 463
464// use new, improved, *INSTANT* network-dialog-file-getterer 464 // use new, improved, *INSTANT* network-dialog-file-getterer
465 if( NetworkDlg->exec() != 0 ) { 465 if( NetworkDlg->exec() != 0 ) {
466 File_Name = NetworkDlg->localFileName; 466 File_Name = NetworkDlg->localFileName;
467 467
468 qDebug("Just downloaded " + NetworkDlg->localFileName); 468 qDebug("Just downloaded " + NetworkDlg->localFileName);
469 469
470 if(NetworkDlg->successDownload) { 470 if(NetworkDlg->successDownload) {
471 //odebug << "Filename is "+File_Name << oendl; 471 //odebug << "Filename is "+File_Name << oendl;
472 if(File_Name.right(4) == ".txt") { 472 if(File_Name.right(4) == ".txt") {
473 QString s_fileName = File_Name; 473 QString s_fileName = File_Name;
474 s_fileName.replace( s_fileName.length() - 3, 3, "gtn"); 474 s_fileName.replace( s_fileName.length() - 3, 3, "gtn");
475 // s_fileName.replace( s_fileName.length()-3,3,"etx"); 475 if (rename( File_Name.latin1(), s_fileName.latin1()) == 1) {
476 rename( File_Name.latin1(), s_fileName.latin1()); 476 owarn << "Failed to rename " << File_Name.latin1() << " to "
477 File_Name = s_fileName; 477 << s_fileName.latin1() << oendl;
478 return false;
479 }
478 480
479 //odebug << "Filename is now "+File_Name << oendl; 481 File_Name = s_fileName;
480 482
481 } 483 //odebug << "Filename is now "+File_Name << oendl;
482 if(File_Name.length() > 5 ) {
483 setTitle();
484 QFileInfo fi(File_Name);
485 QString name_file = fi.fileName();
486 name_file = name_file.left( name_file.length() - 4);
487
488 //odebug << "Setting doclink" << oendl;
489 DocLnk lnk;
490 //odebug << "name is "+name_file << oendl;
491 lnk.setName(name_file); //sets file name
492 //odebug << "Title is "+DlglistItemTitle << oendl;
493 lnk.setComment(DlglistItemTitle);
494 484
495 //odebug << "Filename is "+File_Name << oendl;
496 lnk.setFile(File_Name); //sets File property
497 lnk.setType("guten/plain");// hey is this a REGISTERED mime type?!?!? ;D
498 lnk.setExec(File_Name);
499 lnk.setIcon("gutenbrowser/Gutenbrowser");
500 if(!lnk.writeLink()) {
501 //odebug << "Writing doclink did not work" << oendl;
502 } else {
503 } 485 }
504 } else 486 if(File_Name.length() > 5 ) {
505 QMessageBox::message("Note","<p>There was an error with the file</p>"); 487 setTitle();
506 } 488 QFileInfo fi(File_Name);
507 } 489 QString name_file = fi.fileName();
490 name_file = name_file.left( name_file.length() - 4);
491
492 //odebug << "Setting doclink" << oendl;
493 DocLnk lnk;
494 //odebug << "name is "+name_file << oendl;
495 lnk.setName(name_file); //sets file name
496 //odebug << "Title is "+DlglistItemTitle << oendl;
497 lnk.setComment(DlglistItemTitle);
498
499 //odebug << "Filename is "+File_Name << oendl;
500 lnk.setFile(File_Name); //sets File property
501 lnk.setType("guten/plain");// hey is this a REGISTERED mime type?!?!? ;D
502 lnk.setExec(File_Name);
503 lnk.setIcon("gutenbrowser/Gutenbrowser");
504 if(!lnk.writeLink()) {
505 //odebug << "Writing doclink did not work" << oendl;
506 }
507 } else
508 QMessageBox::message("Note","<p>There was an error with the file</p>");
509 }
510 }
508 511
509 return true; 512 return true;
510} 513}
511 514
512bool LibraryDialog::download_Etext() 515bool LibraryDialog::download_Etext()
513{ // ftp method 516{ // ftp method
514 // might have to use old gpl'd ftp for embedded!! 517 // might have to use old gpl'd ftp for embedded!!
515 518
516 Config cfg("Gutenbrowser"); 519 Config cfg("Gutenbrowser");
517 cfg.setGroup("FTPsite"); 520 cfg.setGroup("FTPsite");
518 ftp_host = cfg.readEntry("SiteName", "sailor.gutenberg.org"); 521 ftp_host = cfg.readEntry("SiteName", "sailor.gutenberg.org");
519 ftp_base_dir = cfg.readEntry("base", "/pub/gutenberg"); 522 ftp_base_dir = cfg.readEntry("base", "/pub/gutenberg");
520 523
521 qDebug( "about to network dialog"); 524 qDebug( "about to network dialog");
522 525
523 QString NewlistItemNumber, NewlistItemYear, ls_result, result_line, s, dir, /*networkUrl, */outputFile; 526 QString NewlistItemNumber, NewlistItemYear, ls_result, result_line, s, dir, /*networkUrl, */outputFile;
524 527
525 //////////////////// FIXME- if 'x' is part of real name.... 528 //////////////////// FIXME- if 'x' is part of real name....
526 NewlistItemFile = DlglistItemFile.left(DlglistItemFile.find(".xxx", 1, false)).left(DlglistItemFile.left(DlglistItemFile.find(".xxx", 1, false)).find("x", 1, false)); 529 NewlistItemFile = DlglistItemFile.left(DlglistItemFile.find(".xxx", 1, false)).left(DlglistItemFile.left(DlglistItemFile.find(".xxx", 1, false)).find("x", 1, false));
527 530
528 if( NewlistItemFile.find( DlglistItemFile.left(4) ,0,true) ==-1 ) { 531 if( NewlistItemFile.find( DlglistItemFile.left(4) ,0,true) ==-1 ) {
529 NewlistItemFile.replace( 0,4, DlglistItemFile.left(4)); 532 NewlistItemFile.replace( 0,4, DlglistItemFile.left(4));
530 qDebug("NewlistItemFile is now " + NewlistItemFile); 533 qDebug("NewlistItemFile is now " + NewlistItemFile);
531 } 534 }
532 535
533 NewlistItemYear = DlglistItemYear.right(2); 536 NewlistItemYear = DlglistItemYear.right(2);
534 int NewlistItemYear_Int = NewlistItemYear.toInt(0, 10); 537 int NewlistItemYear_Int = NewlistItemYear.toInt(0, 10);
535 //odebug << NewlistItemYear << oendl; 538 //odebug << NewlistItemYear << oendl;
536 if (NewlistItemYear_Int < 91 && NewlistItemYear_Int > 70) { 539 if (NewlistItemYear_Int < 91 && NewlistItemYear_Int > 70) {
537 NewlistItemYear = "90"; 540 NewlistItemYear = "90";
538 } 541 }
539 542
540 Edir ="etext" +NewlistItemYear; 543 Edir ="etext" +NewlistItemYear;
541 544
542 dir = ftp_base_dir + "/etext" + NewlistItemYear + "/"; 545 dir = ftp_base_dir + "/etext" + NewlistItemYear + "/";
543 546
544 if( ftp_base_dir.find("=",0,true) ) 547 if( ftp_base_dir.find("=",0,true) )
545 ftp_base_dir.remove( ftp_base_dir.find("=",0,true),1); 548 ftp_base_dir.remove( ftp_base_dir.find("=",0,true),1);
546 549
547// networkUrl = "ftp://"+ftp_host+dir; 550// networkUrl = "ftp://"+ftp_host+dir;
548 551
549 outputFile = local_library+".guten_temp"; 552 outputFile = local_library+".guten_temp";
550 553
551 qDebug( "Download file: " +NewlistItemFile); 554 qDebug( "Download file: " +NewlistItemFile);
552 qDebug("Checking: " + ftp_host + " " + dir + " " + outputFile+" " + NewlistItemFile); 555 qDebug("Checking: " + ftp_host + " " + dir + " " + outputFile+" " + NewlistItemFile);
553 556
554 557
555 QStringList networkList; 558 QStringList networkList;
556 networkList.append((const char *)ftp_host); //host 559 networkList.append((const char *)ftp_host); //host
557 networkList.append((const char *)dir); //ftp base directory 560 networkList.append((const char *)dir); //ftp base directory
558 networkList.append((const char *)outputFile); //output filepath 561 networkList.append((const char *)outputFile); //output filepath
559 networkList.append((const char *)NewlistItemFile); //filename 562 networkList.append((const char *)NewlistItemFile); //filename
560//<< (char *)ftp_host << (char *)dir << (char *)outputFile << (char *)NewlistItemFile; 563//<< (char *)ftp_host << (char *)dir << (char *)outputFile << (char *)NewlistItemFile;
561 getEtext( networkList); 564 getEtext( networkList);
562 565
563 return true; 566 return true;
564} 567}
565 568
566bool LibraryDialog::httpDownload() 569bool LibraryDialog::httpDownload()
567{// httpDownload 570{// httpDownload
568#ifndef Q_WS_QWS 571#ifndef Q_WS_QWS
569 Config config("Gutenbrowser"); 572 Config config("Gutenbrowser");
570 config.setGroup( "Browser" ); 573 config.setGroup( "Browser" );
571 QString brow = config.readEntry("Preferred", ""); 574 QString brow = config.readEntry("Preferred", "");
572 QString file_name = "./.guten_temp"; 575 QString file_name = "./.guten_temp";
573 // config.setGroup( "HttpServer" ); 576 // config.setGroup( "HttpServer" );
@@ -640,129 +643,128 @@ bool LibraryDialog::setTitle()
640 test = 1; 643 test = 1;
641 } 644 }
642 } 645 }
643 646
644 if(test == 0 ) { 647 if(test == 0 ) {
645 648
646 config.setGroup("Files"); 649 config.setGroup("Files");
647 config.writeEntry( "NumberOfFiles", i_numofFiles +1 ); 650 config.writeEntry( "NumberOfFiles", i_numofFiles +1 );
648 QString interger; 651 QString interger;
649 interger.setNum( i_numofFiles +1); 652 interger.setNum( i_numofFiles +1);
650 config.writeEntry( interger, File_Name); 653 config.writeEntry( interger, File_Name);
651 config.setGroup( "Titles" ); 654 config.setGroup( "Titles" );
652 config.writeEntry( File_Name, DlglistItemTitle); 655 config.writeEntry( File_Name, DlglistItemTitle);
653 } 656 }
654 test = 0; 657 test = 0;
655 return true; 658 return true;
656} 659}
657 660
658 661
659void LibraryDialog::saveConfig() 662void LibraryDialog::saveConfig()
660{ 663{
661 Config config("Gutenbrowser"); 664 Config config("Gutenbrowser");
662 if( httpBox->isChecked() == true) { 665 if( httpBox->isChecked() == true) {
663 checked = 1; 666 checked = 1;
664 config.setGroup( "Proxy" ); 667 config.setGroup( "Proxy" );
665 config.writeEntry("IsChecked", "true"); 668 config.writeEntry("IsChecked", "true");
666 } else { 669 } else {
667 checked = 0; 670 checked = 0;
668 config.setGroup( "Proxy" ); 671 config.setGroup( "Proxy" );
669 config.writeEntry("IsChecked", "false"); 672 config.writeEntry("IsChecked", "false");
670 } 673 }
671 if (authBox->isChecked() == true) { 674 if (authBox->isChecked() == true) {
672 config.setGroup("SortAuth"); 675 config.setGroup("SortAuth");
673 config.writeEntry("authSort", "true"); 676 config.writeEntry("authSort", "true");
674 } else { 677 } else {
675 config.setGroup("SortAuth"); 678 config.setGroup("SortAuth");
676 config.writeEntry("authSort", "false"); 679 config.writeEntry("authSort", "false");
677 } 680 }
678 // config.write(); 681 // config.write();
679} 682}
680 683
681/* 684/*
682 searches library index for user word*/ 685 searches library index for user word*/
683void LibraryDialog::onButtonSearch() 686void LibraryDialog::onButtonSearch()
684{ 687{
685 ListView1->clearSelection(); 688 ListView1->clearSelection();
686 ListView2->clearSelection(); 689 ListView2->clearSelection();
687 ListView3->clearSelection(); 690 ListView3->clearSelection();
688 ListView4->clearSelection(); 691 ListView4->clearSelection();
689 ListView5->clearSelection(); 692 ListView5->clearSelection();
690 693
691 int curTab = tabWidget->currentPageIndex(); 694 int curTab = tabWidget->currentPageIndex();
692 SearchDialog* searchDlg; 695 SearchDialog* searchDlg;
693 696
694 // if( resultsList) 697 // if( resultsList)
695 searchDlg = new SearchDialog( this, "Library Search", true); 698 searchDlg = new SearchDialog( this, "Library Search", true);
696 searchDlg->setCaption( tr( "Library Search" ) ); 699 searchDlg->setCaption( tr( "Library Search" ) );
697 searchDlg->setLabel( "- author or title"); 700 searchDlg->setLabel( "- author or title");
698 701
699 QString resultString; 702 QString resultString;
700 703
701 int i_berger = 0; 704 int i_berger = 0;
702 if( searchDlg->exec() != 0 ) { 705 if( searchDlg->exec() != 0 ) {
703 QString searcherStr = searchDlg->get_text(); 706 QString searcherStr = searchDlg->get_text();
704 int fluff = 0;
705 707
706 bool cS; 708 bool cS;
707 if( searchDlg->caseSensitiveCheckBox->isChecked()) 709 if( searchDlg->caseSensitiveCheckBox->isChecked())
708 cS = true; //case sensitive 710 cS = true; //case sensitive
709 else 711 else
710 cS = false; 712 cS = false;
711 713
712 etext etextStruct; 714 etext etextStruct;
713 QValueList<etext>::Iterator it; 715 QValueList<etext>::Iterator it;
714 716
715 for( it = etextLibrary.begin(); it != etextLibrary.end(); ++it ) { 717 for( it = etextLibrary.begin(); it != etextLibrary.end(); ++it ) {
716 QString tempTitle = (*it).title; 718 QString tempTitle = (*it).title;
717 QString tempAuthor = (*it).author; 719 QString tempAuthor = (*it).author;
718 QString tempFile = (*it).file; 720 QString tempFile = (*it).file;
719 QString tempYear = (*it).year; 721 QString tempYear = (*it).year;
720 if(tempTitle.find( searcherStr, 0, cS) != -1 722 if(tempTitle.find( searcherStr, 0, cS) != -1
721 || tempAuthor.find( searcherStr, 0, cS) != -1) { 723 || tempAuthor.find( searcherStr, 0, cS) != -1) {
722 qWarning(tempTitle); 724 qWarning(tempTitle);
723 Searchlist.append( tempTitle + " : " + tempYear + " : " + tempFile); 725 Searchlist.append( tempTitle + " : " + tempYear + " : " + tempFile);
724 } 726 }
725 } 727 }
726 728
727 729
728 tabWidget->setCurrentPage( curTab); 730 tabWidget->setCurrentPage( curTab);
729 731
730 Searchlist.sort(); 732 Searchlist.sort();
731 SearchResultsDlg* SearchResultsDialog; 733 SearchResultsDlg* SearchResultsDialog;
732 SearchResultsDialog = new SearchResultsDlg( searchDlg, "Results Dialog", true, 0 , Searchlist); 734 SearchResultsDialog = new SearchResultsDlg( searchDlg, "Results Dialog", true, 0 , Searchlist);
733 735
734 SearchResultsDialog->showMaximized(); 736 SearchResultsDialog->showMaximized();
735 if( SearchResultsDialog->exec() != 0) { 737 if( SearchResultsDialog->exec() != 0) {
736 texter = SearchResultsDialog->selText; 738 texter = SearchResultsDialog->selText;
737 // //odebug << texter << oendl; 739 // //odebug << texter << oendl;
738 resultLs = SearchResultsDialog->resultsList; 740 resultLs = SearchResultsDialog->resultsList;
739 i_berger = 1; 741 i_berger = 1;
740 } else { 742 } else {
741 resultLs.clear(); 743 resultLs.clear();
742 } 744 }
743 Searchlist.clear(); 745 Searchlist.clear();
744 746
745 QString tester; 747 QString tester;
746 for ( QStringList::Iterator it = resultLs.begin(); it != resultLs.end(); ++it ) { 748 for ( QStringList::Iterator it = resultLs.begin(); it != resultLs.end(); ++it ) {
747 texter.sprintf("%s \n",(*it).latin1()); 749 texter.sprintf("%s \n",(*it).latin1());
748 // //odebug << texter << oendl; 750 // //odebug << texter << oendl;
749 if( tester!=texter) 751 if( tester!=texter)
750 parseSearchResults( texter); 752 parseSearchResults( texter);
751 tester = texter; 753 tester = texter;
752 } 754 }
753 if(searchDlg) 755 if(searchDlg)
754 delete searchDlg; 756 delete searchDlg;
755 } 757 }
756 if(checkBox->isChecked() ) { 758 if(checkBox->isChecked() ) {
757 accept(); 759 accept();
758 } else { 760 } else {
759 setActiveWindow(); 761 setActiveWindow();
760 } 762 }
761} 763}
762 764
763/* 765/*
764 splits the result string and calls download for the current search result*/ 766 splits the result string and calls download for the current search result*/
765void LibraryDialog::parseSearchResults( QString resultStr) 767void LibraryDialog::parseSearchResults( QString resultStr)
766{ 768{
767 int stringLeng = resultStr.length(); 769 int stringLeng = resultStr.length();
768 770
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
@@ -1,521 +1,513 @@
1/*************************************************************************** 1/***************************************************************************
2 openetext.cpp - description 2 openetext.cpp - description
3 begin : Sat Dec 4 1999 3 begin : Sat Dec 4 1999
4 begin : Tue Jul 25 2000 4 begin : Tue Jul 25 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 14
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 <opie2/odebug.h>
22#include <qpe/applnk.h> 22#include <qpe/applnk.h>
23#include <qpe/config.h> 23#include <qpe/config.h>
24#include <qpe/qpeapplication.h> 24#include <qpe/qpeapplication.h>
25using namespace Opie::Ui; 25using namespace Opie::Ui;
26 26
27/* QT */ 27/* QT */
28#include <qtextstream.h> 28#include <qtextstream.h>
29#include <qfileinfo.h> 29#include <qfileinfo.h>
30 30
31/* STD */ 31/* STD */
32#if defined(_WS_WIN_) 32#if defined(_WS_WIN_)
33#include <windows.h> 33#include <windows.h>
34#else 34#else
35#include <unistd.h> 35#include <unistd.h>
36#include <stdlib.h> 36#include <stdlib.h>
37#include <sys/stat.h> 37#include <sys/stat.h>
38#endif 38#endif
39 39
40OpenEtext::OpenEtext(QWidget *parent, QString name) : QDialog(parent,name,true) 40OpenEtext::OpenEtext(QWidget *parent, QString name) : QDialog(parent,name,true)
41{ 41{
42 local_library = (QDir::homeDirPath ()) +"/Applications/gutenbrowser/"; 42 local_library = (QDir::homeDirPath ()) +"/Applications/gutenbrowser/";
43 local_index=local_library+"GUTINDEX.ALL"; 43 local_index=local_library+"GUTINDEX.ALL";
44 initDialog(); 44 initDialog();
45 connect( QListBox_1, SIGNAL(selected ( int)),this, SLOT(select_title(int)) ); 45 connect( QListBox_1, SIGNAL(selected ( int)),this, SLOT(select_title(int)) );
46 46
47 getTitles(); 47 getTitles();
48} 48}
49 49
50OpenEtext::~OpenEtext() 50OpenEtext::~OpenEtext()
51{ 51{
52} 52}
53 53
54void OpenEtext::getTitles() 54void OpenEtext::getTitles()
55{ 55{
56 QListBox_1->clear(); 56 QListBox_1->clear();
57 Config config("Gutenbrowser"); 57 Config config("Gutenbrowser");
58 config.setGroup( "Files" ); 58 config.setGroup( "Files" );
59 s_numofFiles = config.readEntry("NumberOfFiles", "0"); 59 s_numofFiles = config.readEntry("NumberOfFiles", "0");
60 QLabel_1->setText( tr( 60 QLabel_1->setText( tr( s_numofFiles+" etexts in your library." ) );
61 s_numofFiles+" etexts in your library."));
62 int i_numofFiles = s_numofFiles.toInt(); 61 int i_numofFiles = s_numofFiles.toInt();
63 for (int i = 1; i <= i_numofFiles+1; i++) { 62 for (int i = 1; i <= i_numofFiles+1; i++) {
64 QString temp; 63 QString temp;
65 temp.setNum(i); 64 temp.setNum(i);
66 config.setGroup( "Files" ); 65 config.setGroup( "Files" );
67 QString ramble = config.readEntry(temp, "" ); 66 QString ramble = config.readEntry(temp, "" );
68 config.setGroup( "Titles" ); 67 config.setGroup( "Titles" );
69 title = config.readEntry(ramble, ""); 68 title = config.readEntry(ramble, "");
70 if( !title.isEmpty()) { 69 if( !title.isEmpty()) {
71 QListBox_1->insertItem ( QPixmap( QPEApplication::qpeDir()+"pics/gutenbrowser/gutenbrowser_sm.png"), title, -1); 70 QListBox_1->insertItem ( QPixmap(
71 QPEApplication::qpeDir() +
72 "pics/gutenbrowser/gutenbrowser_sm.png"
73 ),
74 title,
75 -1);
72 } 76 }
73 } 77 }
74} 78}
75 79
76/* 80/*
77 opens selected title */ 81 opens selected title */
78void OpenEtext::OpenTitle() 82void OpenEtext::OpenTitle()
79{ 83{
80 if( QListBox_1->currentItem() != -1) 84 if( QListBox_1->currentItem() != -1)
81 select_title( QListBox_1->currentItem() ); 85 select_title( QListBox_1->currentItem() );
82 else { 86 else {
83 QString sMsg; 87 QString sMsg;
84 sMsg = "You must select an Etext to open"; 88 sMsg = "You must select an Etext to open";
85 QMessageBox::message( "Error",sMsg); 89 QMessageBox::message( "Error",sMsg);
86 } 90 }
87} 91}
88 92
89void OpenEtext::select_title(int index ) 93void OpenEtext::select_title(int index )
90{ 94{
91 OpenButton->setDown(TRUE); 95 OpenButton->setDown(TRUE);
92 QString temp; 96 QString temp;
93 temp.setNum( index + 1); 97 temp.setNum( index + 1);
94 const char * title; 98 const char * title;
95 title = QListBox_1->text( index ); 99 title = QListBox_1->text( index );
96 openFileTitle = title; 100 openFileTitle = title;
97 Config config("Gutenbrowser"); 101 Config config("Gutenbrowser");
98 config.setGroup( "Files" ); 102 config.setGroup( "Files" );
99 file = config.readEntry(temp, ""); 103 file = config.readEntry(temp, "");
100 OpenEtext::accept(); 104 OpenEtext::accept();
101} 105}
102 106
103/* 107/*!
104 This function imports already existing etexts into the local library list*/ 108 * This function imports already existing etexts into the local library list
109 */
105void OpenEtext::open() 110void OpenEtext::open()
106{ 111{
107OpenFileButton->setDown(TRUE); 112OpenFileButton->setDown(TRUE);
108 title = ""; 113 title = "";
109 QString currDir=""; 114 QString currDir="";
110 QString filer; 115 QString filer;
111 QString name_file; 116 QString name_file;
112 QString local ; 117 QString local ;
113 local = (QDir::homeDirPath () +"Applications/gutenbrowser"); 118 local = (QDir::homeDirPath () +"Applications/gutenbrowser");
114 QDir library( local); 119 QDir library( local);
115 120
116// fileBrowser *browseForFiles;
117// browseForFiles=new fileBrowser(this,"Browse for File", TRUE, 0, "guten/plain;text/plain");
118// // browseForFiles=new fileBrowser(this,"fileBrowser",TRUE,0, "*");
119// browseForFiles->setFileView( 0);
120// browseForFiles->showMaximized();
121// browseForFiles->exec();
122// QString selFile= browseForFiles->selectedFileName;
123// fileList=browseForFiles->fileList;
124 Config cfg("Gutenbrowser"); 121 Config cfg("Gutenbrowser");
125 cfg. setGroup ( "View" ); 122 cfg. setGroup ( "View" );
126 QString dir = cfg.readEntry("LastOpenDirectory", QPEApplication::documentDir()); 123 QString dir = cfg.readEntry("LastOpenDirectory", QPEApplication::documentDir());
127 QMap<QString, QStringList> map; 124 QMap<QString, QStringList> map;
128 map.insert(tr("All"), QStringList() ); 125 map.insert(tr("All"), QStringList() );
129 QStringList text; 126 QStringList text;
130 text << "text/*"; 127 text << "text/*";
131 map.insert(tr("Text"), text ); 128 map.insert(tr("Text"), text );
132 text << "*"; 129 text << "*";
133 map.insert(tr("All"), text ); 130 map.insert(tr("All"), text );
134 131
135 QString str = OFileDialog::getOpenFileName( 2, dir , QString::null, map); 132 QString str = OFileDialog::getOpenFileName( 2, dir , QString::null, map);
136 133
137 if( !str.isEmpty() && QFile(str).exists() && !QFileInfo(str).isDir() ) { 134 if( !str.isEmpty() && QFile(str).exists() && !QFileInfo(str).isDir() ) {
138 filer = str; 135 filer = str;
139 136
140 odebug << "Open file: "+str << oendl; 137 odebug << "Open file: "+str << oendl;
141 138
142 // QStringList::ConstIterator f; 139 if( filer.right(4) == ".txt" ||
143// QString fileTemp; 140 filer.right(4) == ".TXT" ||
144// for ( f = fileList.begin(); f != fileList.end(); f++ ) { 141 filer.right(4) == ".etx" ||
145// fileTemp = *f; 142 filer.right(4) == ".ETX" ||
146// fileTemp.right( fileTemp.length()-5); 143 filer.right(4) == ".etx" ||
147// fileName = fileTemp; 144 filer.right(4) == ".ETX" ||
148// if( !fileName.isEmpty() ){ 145 filer.right(4) == ".zip" ||
149// filer = fileName; 146 filer.right(4) == ".ZIP" )
150// } else { //filename is empty 147 {
151// // QString sMsg;
152// // sMsg = "Error opening library filelist "+fileName;
153// }
154
155 if( filer.right(4) == ".txt"
156 || filer.right(4) == ".TXT"
157 || filer.right(4) == ".etx"
158 || filer.right(4) == ".ETX"
159 || filer.right(4) == ".etx"
160 || filer.right(4) == ".ETX"
161 || filer.right(4) == ".zip"
162 || filer.right(4) == ".ZIP" ) {
163 QFileInfo zipFile( filer); 148 QFileInfo zipFile( filer);
164 QString s_fileName = zipFile.fileName(); 149 QString s_fileName = zipFile.fileName();
165 QString cmd; 150 QString cmd;
166 151
167 if( s_fileName.right(4) == ".zip") { // unzip that sucker.... 152 if( s_fileName.right(4) == ".zip") { // unzip the file
168 s_fileName = s_fileName.left( s_fileName.length() - 4); 153 s_fileName = s_fileName.left( s_fileName.length() - 4);
169 if( chdir((const char*)local_library.latin1())!=0) 154 if( chdir((const char*)local_library.latin1())!=0)
170 odebug << "chdir failed." << oendl; // QString cmd = "gunzip -d " + filer + " -d " + local_library; 155 odebug << "chdir failed." << oendl;
171 cmd = "gunzip -S .zip " + filer; 156 cmd = "gunzip -S .zip " + filer;
172 fileName = local_library + s_fileName + ".txt"; 157 fileName = local_library + s_fileName + ".txt";
173 system( cmd); 158 system( cmd);
174 } 159 } else { // else rename .txt to .etx
175// this renames the .txt to .etx!! 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
189 QFileInfo fi( fileName); 174 QFileInfo fi( fileName);
190 name_file = fi.fileName(); 175 name_file = fi.fileName();
191 name_file = name_file.left(name_file.length() - 4); 176 name_file = name_file.left(name_file.length() - 4);
192 177
193 odebug << "Setting doclink" << oendl; 178 odebug << "Setting doclink" << oendl;
194 DocLnk lnk; 179 DocLnk lnk;
195 odebug << "name is " + name_file << oendl; 180 odebug << "name is " + name_file << oendl;
196 lnk.setName(name_file); //sets file name 181 lnk.setName(name_file); //sets file name
197 odebug << "Title is "+title << oendl; 182 odebug << "Title is "+title << oendl;
198 lnk.setComment(title); 183 lnk.setComment(title);
199 184
200 QListBox_1->clear(); 185 QListBox_1->clear();
201 getTitles(); 186 getTitles();
202 odebug << "Filename is "+fileName << oendl; 187 odebug << "Filename is "+fileName << oendl;
203 lnk.setFile(fileName); //sets File property 188 lnk.setFile(fileName); //sets File property
204 lnk.setType("guten/plain");// hey is this a REGISTERED mime type?!?!? ;D 189 // @bug This is probably not a registered MIME type. Perhaps we should
190 // set a valid MIME type here instead. Or maybe register .etx as a
191 // Gutenberge etext?
192 lnk.setType("guten/plain");
205 lnk.setExec(fileName); 193 lnk.setExec(fileName);
206 lnk.setIcon("gutenbrowser/Gutenbrowser"); 194 lnk.setIcon("gutenbrowser/Gutenbrowser");
207 if(!lnk.writeLink()) 195 if(!lnk.writeLink())
208 odebug << "Writing doclink did not work" << oendl; 196 odebug << "Writing doclink did not work" << oendl;
209 197
210 } // end of for each file name.... 198 } // end of for each file name....
211 OpenFileButton->setDown(FALSE); 199 OpenFileButton->setDown(FALSE);
212} 200}
213 201
214/* 202/*
215find the title in the config file */ 203find the title in the config file */
216bool OpenEtext::FindTitle( QString filename) 204bool OpenEtext::FindTitle( QString filename)
217{ 205{
218 Config config("Gutenbrowser"); 206 Config config("Gutenbrowser");
219 config.setGroup( "Files" ); 207 config.setGroup( "Files" );
220 QString s_numofFiles = config.readEntry("NumberOfFiles", "0"); 208 QString s_numofFiles = config.readEntry("NumberOfFiles", "0");
221 int i_numofFiles = s_numofFiles.toInt(); 209 int i_numofFiles = s_numofFiles.toInt();
222 210
223 QFileInfo fi(filename); 211 QFileInfo fi(filename);
224 name = fi.fileName(); 212 name = fi.fileName();
225 odebug << "filename to open is " + name << oendl; 213 odebug << "filename to open is " + name << oendl;
226 QFile indexLib( filename); 214 QFile indexLib( filename);
227 bool findCheck = FALSE; 215 bool findCheck = FALSE;
228 // int Titlenumber=0;
229 216
230 if ( indexLib.open( IO_ReadOnly) ) { 217 if ( indexLib.open( IO_ReadOnly) ) {
231 odebug << "file opened successfully" << oendl; 218 odebug << "file opened successfully" << oendl;
232 QTextStream indexStream( &indexLib ); 219 QTextStream indexStream( &indexLib );
233 QString target = "Project Gutenberg Etext of"; 220 QString target = "Project Gutenberg Etext of";
234 QString target2 = "Project Gutenberg Etext"; 221 QString target2 = "Project Gutenberg Etext";
235 QString target3 = "Project Gutenberg's Etext of"; 222 QString target3 = "Project Gutenberg's Etext of";
236 QString target4 = "Project Gutenberg's Etext"; 223 QString target4 = "Project Gutenberg's Etext";
237 QString indexLine; 224 QString indexLine;
238 while ( !indexStream.eof() ) { 225 while ( !indexStream.eof() ) {
239 // until end of file.. 226 // until end of file..
240 indexLine = indexStream.readLine(); 227 indexLine = indexStream.readLine();
241 if( indexLine.find(target, 0, TRUE) > -1 && !findCheck) {findCheck = TRUE; 228 if( indexLine.find(target, 0, TRUE) > -1 && !findCheck) {findCheck = TRUE;
242 title = indexLine.mid( indexLine.find(target, 0, TRUE) + (target.length()) , indexLine.find("\r", 0, TRUE)); 229 title = indexLine.mid( indexLine.find(target, 0, TRUE) + (target.length()) , indexLine.find("\r", 0, TRUE));
243 title = title.left( title.find( "*",0, TRUE)); 230 title = title.left( title.find( "*",0, TRUE));
244 title = title.stripWhiteSpace (); 231 title = title.stripWhiteSpace ();
245// odebug << "Found the title 1 and it is " << title << "" << oendl; 232// odebug << "Found the title 1 and it is " << title << "" << oendl;
246// QListBox_1->insertItem ( title); 233// QListBox_1->insertItem ( title);
247 } 234 }
248 if( indexLine.find( target2, 0, TRUE) > -1 && !findCheck) { 235 if( indexLine.find( target2, 0, TRUE) > -1 && !findCheck) {
249 findCheck = TRUE; 236 findCheck = TRUE;
250 title = indexLine.mid( indexLine.find( target2, 0, TRUE ) + ( target2.length()) , indexLine.find("\r", 0, TRUE) ); 237 title = indexLine.mid( indexLine.find( target2, 0, TRUE ) + ( target2.length()) , indexLine.find("\r", 0, TRUE) );
251 title = title.left( title.find( "*",0, TRUE)); 238 title = title.left( title.find( "*",0, TRUE));
252 title = title.stripWhiteSpace (); 239 title = title.stripWhiteSpace ();
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;
258 title = indexLine.mid( indexLine.find( target3, 0, TRUE) + ( target3.length()) , indexLine.find("\r", 0, TRUE)); 245 title = indexLine.mid( indexLine.find( target3, 0, TRUE) + ( target3.length()) , indexLine.find("\r", 0, TRUE));
259 title = title.left( title.find( "*",0, TRUE)); 246 title = title.left( title.find( "*",0, TRUE));
260 title = title.stripWhiteSpace (); 247 title = title.stripWhiteSpace ();
261// odebug << "Found the title 3 and it is " << title << "" << oendl; 248// odebug << "Found the title 3 and it is " << title << "" << oendl;
262 } 249 }
263 if( indexLine.find( target4, 0, TRUE) > -1 && !findCheck) { 250 if( indexLine.find( target4, 0, TRUE) > -1 && !findCheck) {
264 findCheck = TRUE; 251 findCheck = TRUE;
265 title = indexLine.mid( indexLine.find( target4, 0, TRUE) + ( target4.length()) , indexLine.find("\r", 0, TRUE)); 252 title = indexLine.mid( indexLine.find( target4, 0, TRUE) + ( target4.length()) , indexLine.find("\r", 0, TRUE));
266 title = title.left( title.find( "*",0, TRUE)); 253 title = title.left( title.find( "*",0, TRUE));
267 title = title.stripWhiteSpace (); 254 title = title.stripWhiteSpace ();
268// odebug << "Found the title 4 and it is " << title << "" << oendl; 255// odebug << "Found the title 4 and it is " << title << "" << oendl;
269 } 256 }
270 } //endof file 257 } //endof file
271 indexLib.close(); 258 indexLib.close();
272 259
273 if( !findCheck || title.length() < 2) { 260 if( !findCheck || title.length() < 2) {
274 odebug << "Trying hard to find title from GUTINDEX.ALL" << oendl; 261 odebug << "Trying hard to find title from GUTINDEX.ALL" << oendl;
275 title = titleFromLibrary( filename); 262 title = titleFromLibrary( filename);
276 findCheck = TRUE; 263 findCheck = TRUE;
277 } 264 }
278 265
279 if ( checkConf() == false && findCheck == TRUE) { 266 if ( checkConf() == false && findCheck == TRUE) {
280
281 config.setGroup( "Files"); 267 config.setGroup( "Files");
282 config.writeEntry("NumberOfFiles",i_numofFiles + 1 ); 268 config.writeEntry("NumberOfFiles",i_numofFiles + 1 );
283 QString interger; 269 QString interger;
284 interger.setNum( i_numofFiles +1); 270 interger.setNum( i_numofFiles +1);
285 config.writeEntry(interger, filename); 271 config.writeEntry(interger, filename);
286 config.setGroup( "Titles" ); 272 config.setGroup( "Titles" );
287 for (int i = 1; i <= i_numofFiles; i++) { //find dup titles in config file 273 for (int i = 1; i <= i_numofFiles; i++) { //find dup titles in config file
288 QString temp; 274 QString temp;
289 temp.setNum(i); 275 temp.setNum(i);
290 config.setGroup( "Files" ); 276 config.setGroup( "Files" );
291 QString ramble = config.readEntry(temp, "" ); 277 QString ramble = config.readEntry(temp, "" );
292 config.setGroup( "Titles" ); 278 config.setGroup( "Titles" );
293 QString title1 = config.readEntry(ramble, ""); 279 QString title1 = config.readEntry(ramble, "");
294 if(title1==title) 280 if(title1==title)
295 title+="1"; 281 title+="1";
296 i= i_numofFiles+1; 282 i= i_numofFiles+1;
297 } 283 }
298 if(title.length()<3) { 284 if(title.length()<3) {
299// odebug << "title is empty" << oendl; 285// odebug << "title is empty" << oendl;
300 title="Unknown"; 286 title="Unknown";
301 } 287 }
302 config.writeEntry( filename,title); 288 config.writeEntry( filename,title);
303 } 289 }
304 } else { 290 } else {
305 QString sMsg; 291 QString sMsg;
306 sMsg = "Error opening library file: "+filename; 292 sMsg = "Error opening library file: "+filename;
307 printf( sMsg+"\n"); 293 printf( sMsg+"\n");
308 } 294 }
309 return true; 295 return true;
310} 296}
311 297
312QString OpenEtext::titleFromLibrary( QString fileName) 298QString OpenEtext::titleFromLibrary( QString fileName)
313{ 299{
314 QFile indexLib( local_index); 300 QFile indexLib( local_index);
315 QString target; 301 QString target;
316 int find1 = fileName.findRev("/",-1,TRUE) + 1; 302 int find1 = fileName.findRev("/",-1,TRUE) + 1;
317 int find2 = fileName.findRev(".gtn",-1,TRUE) - find1; 303 int find2 = fileName.findRev(".gtn",-1,TRUE) - find1;
318 if(find2==-1-find1) 304 if(find2== (-1-find1))
319 int find2 = fileName.findRev(".etx",-1,TRUE) - find1; 305 find2 = fileName.findRev(".etx",-1,TRUE) - find1;
320 else if(find2==-1-find1) 306 else if(find2==(-1-find1))
321 int find2 = fileName.findRev(".txt",-1,TRUE) - find1; 307 find2 = fileName.findRev(".txt",-1,TRUE) - find1;
322 308
323 target = fileName.mid( find1, find2 ); 309 target = fileName.mid( find1, find2 );
324 QString checker = target.right(1); 310 QString checker = target.right(1);
325 bool ok; 311 bool ok;
326 checker.toInt( &ok,10); 312 checker.toInt( &ok,10);
327 if( ok) { 313 if( ok) {
328 target = target.left( target.length()-1); 314 target = target.left( target.length()-1);
329 checker = target.right(1); 315 checker = target.right(1);
330 ok = FALSE; 316 ok = FALSE;
331 checker.toInt( &ok,10); 317 checker.toInt( &ok,10);
332 if( ok) { 318 if( ok) {
333 target = target.left( target.length()-1); 319 target = target.left( target.length()-1);
334 } 320 }
335 } 321 }
336 if ( indexLib.open( IO_ReadOnly) ) { 322 if ( indexLib.open( IO_ReadOnly) ) {
337 // file opened successfully 323 // file opened successfully
338 QTextStream indexStream( &indexLib ); 324 QTextStream indexStream( &indexLib );
339 QString indexLine; 325 QString indexLine;
340 bool findCheck = FALSE; 326 bool findCheck = FALSE;
341 while ( !indexStream.atEnd() ) { // until end of file.. 327 while ( !indexStream.atEnd() ) { // until end of file..
342 indexLine = indexStream.readLine(); 328 indexLine = indexStream.readLine();
343 329
344 if( indexLine.find( target,0,FALSE) > 0 ) { 330 if( indexLine.find( target,0,FALSE) > 0 ) {
345 findCheck = TRUE; 331 findCheck = TRUE;
346 title = indexLine.mid( 9, 50); 332 title = indexLine.mid( 9, 50);
347// title = indexLine.mid( 26, indexLine.length() );
348 title = title.stripWhiteSpace (); 333 title = title.stripWhiteSpace ();
349// odebug << "Finally Found the title and it is\n " << title << "" << oendl; 334// odebug << "Finally Found the title and it is\n " << title << "" << oendl;
350// QListBox_1->insertItem ( title); 335// QListBox_1->insertItem ( title);
351 } 336 }
352 } //end while loop 337 } //end while loop
353 } 338 }
354 else 339 else
355 odebug << "Error opening library index "+ local_index << oendl; 340 odebug << "Error opening library index "+ local_index << oendl;
356 return title; 341 return title;
357} 342}
358 343
359bool OpenEtext::checkConf() 344bool OpenEtext::checkConf()
360{ 345{
361 QString file = fileName; 346 QString file = fileName;
362 Config config("Gutenbrowser"); 347 Config config("Gutenbrowser");
363 config.setGroup( "Files" ); 348 config.setGroup( "Files" );
364 QString s_numofFiles = config.readEntry("NumberOfFiles", "0" ); 349 QString s_numofFiles = config.readEntry("NumberOfFiles", "0" );
365 int i_numofFiles = s_numofFiles.toInt(); 350 int i_numofFiles = s_numofFiles.toInt();
366 351
367 for (int i = 1; i <= i_numofFiles; i++) { 352 for (int i = 1; i <= i_numofFiles; i++) {
368 QString temp; 353 QString temp;
369 temp.setNum(i); 354 temp.setNum(i);
370 config.setGroup( "Files"); 355 config.setGroup( "Files");
371 QString ramble = config.readEntry(temp, "" ); 356 QString ramble = config.readEntry(temp, "" );
372 357
373 if(ramble == file ) { 358 if(ramble == file ) {
374 return true; 359 return true;
375 } 360 }
376 } 361 }
377 return false; 362 return false;
378} 363}
379 364
380void OpenEtext::remove() 365void OpenEtext::remove()
381{ 366{
382 title_text = QListBox_1->text( QListBox_1->currentItem() ); 367 title_text = QListBox_1->text( QListBox_1->currentItem() );
383 title_text=title_text.stripWhiteSpace(); 368 title_text=title_text.stripWhiteSpace();
384 QString msg ="<p>Do you really want to REMOVE\n" +title_text +"?\nThis will not delete the file.</P>"; 369 QString msg ="<p>Do you really want to REMOVE\n" + title_text +
385 switch( QMessageBox::information( this, (tr("Remove Etext")), 370 "?\nThis will not delete the file.</P>";
386 (tr(msg)), 371 switch( QMessageBox::information( this, tr("Remove Etext"),
387 (tr("&Yes")), (tr("&Cancel")), 0 )){ 372 tr(msg),
373 tr("&Yes"), tr("&Cancel"), 0 ) )
374 {
388 case 0: // Yes clicked, 375 case 0: // Yes clicked,
389 removeSelection(); 376 removeSelection();
390 QListBox_1->clear(); 377 QListBox_1->clear();
391 getTitles(); 378 getTitles();
392 break; 379 break;
393 case 1: // Cancel 380 case 1:
394 break; 381 default:
395 }; 382 }
396} 383}
397 384
398/* 385/*!
399 this removes selected title entry*/ 386 * This removes selected title entry
387 */
400void OpenEtext::removeSelection() 388void OpenEtext::removeSelection()
401{ 389{
402 Config config("Gutenbrowser"); 390 Config config("Gutenbrowser");
403 config.setGroup( "Files" ); 391 config.setGroup( "Files" );
404 s_numofFiles = config.readEntry("NumberOfFiles", "0"); 392 s_numofFiles = config.readEntry("NumberOfFiles", "0");
405 int rem=0; 393 int rem=0;
406 int i_numofFiles = s_numofFiles.toInt(); 394 int i_numofFiles = s_numofFiles.toInt();
407 QString fileNum2; 395 QString fileNum2;
408 QString fileNum; 396 QString fileNum;
409 397
410 for (int i = 1; i <= i_numofFiles; i++) { 398 for (int i = 1; i <= i_numofFiles; i++) {
411 fileNum.setNum(i); 399 fileNum.setNum(i);
412 config.setGroup( "Files" ); 400 config.setGroup( "Files" );
413 401
414 QString s_filename = config.readEntry(fileNum, "" ); 402 QString s_filename = config.readEntry(fileNum, "" );
415 config.setGroup( "Titles" ); 403 config.setGroup( "Titles" );
416 404
417 QString file_title = config.readEntry( s_filename, ""); 405 QString file_title = config.readEntry( s_filename, "");
418 if(title_text == file_title) { 406 if(title_text == file_title) {
419 rem=i; 407 rem=i;
420//odebug << "file title to remove is "+file_title << oendl; 408 //odebug << "file title to remove is "+file_title << oendl;
421 selFile = s_filename; 409 selFile = s_filename;
422 config.removeEntry( s_filename); //removes file=title 410 config.removeEntry( s_filename); //removes file=title
423 } 411 }
424 } 412 }
425 config.setGroup( "Files" ); 413 config.setGroup( "Files" );
426 414
427 for(int fg = rem; fg < i_numofFiles ; fg++ ) { //this rewrites Files number entry 415 for(int fg = rem; fg < i_numofFiles ; fg++ ) { //this rewrites Files number entry
428 fileNum.setNum(fg); 416 fileNum.setNum(fg);
429 fileNum2.setNum( fg + 1); 417 fileNum2.setNum( fg + 1);
430 418
431 QString s_filename2 = config.readEntry(fileNum2, "" ); 419 QString s_filename2 = config.readEntry(fileNum2, "" );
432 420
433 if (!s_filename2.isEmpty()) { 421 if (!s_filename2.isEmpty()) {
434 config.writeEntry(fileNum, s_filename2 ); 422 config.writeEntry(fileNum, s_filename2 );
435 } 423 }
436 } 424 }
437 config.writeEntry("NumberOfFiles", i_numofFiles - 1 ); 425 config.writeEntry("NumberOfFiles", i_numofFiles - 1 );
438 config.removeEntry(fileNum2); 426 config.removeEntry(fileNum2);
439// remFile();
440} 427}
441 428
442/* 429/*!
443 removes file title name from list and config file*/ 430 * Removes file title name from list and config file
431 */
444void OpenEtext::remFile() 432void OpenEtext::remFile()
445{ 433{
446 Config config("Gutenbrowser"); 434 Config config("Gutenbrowser");
447 config.setGroup( "Files" ); 435 config.setGroup( "Files" );
448 QString remFile; 436 QString remFile;
449 s_numofFiles = config.readEntry("NumberOfFiles", "0"); 437 s_numofFiles = config.readEntry("NumberOfFiles", "0");
450 int i_numofFiles = s_numofFiles.toInt(); 438 int i_numofFiles = s_numofFiles.toInt();
451 for (int i = 1; i <= i_numofFiles; i++) { 439 for (int i = 1; i <= i_numofFiles; i++) {
452 QString fileNum; 440 QString fileNum;
453 fileNum.setNum(i); 441 fileNum.setNum(i);
454 QString s_filename = config.readEntry(fileNum, "" ); 442 QString s_filename = config.readEntry(fileNum, "" );
455 443
456 if( s_filename == selFile) { 444 if( s_filename == selFile) {
457 config.removeEntry(selFile); 445 config.removeEntry(selFile);
458 446
459 for(int fg = i_numofFiles - i; fg < i_numofFiles ; fg++ ) { //this rewrites Files number entry 447 for(int fg = i_numofFiles - i; fg < i_numofFiles ; fg++ ) { //this rewrites Files number entry
460 QString fileNum2; 448 QString fileNum2;
461 fileNum2.setNum( fg + 1); 449 fileNum2.setNum( fg + 1);
462 QString s_filename2 = config.readEntry(fileNum2, "" ); 450 QString s_filename2 = config.readEntry(fileNum2, "" );
463 451
464 if (!s_filename2.isEmpty()) { 452 if (!s_filename2.isEmpty())
465 config.writeEntry(fileNum, s_filename2 ); 453 config.writeEntry(fileNum, s_filename2 );
466 }
467 } 454 }
468 } 455 }
469 } 456 }
470 config.writeEntry("NumberOfFiles", i_numofFiles - 1 ); 457 config.writeEntry("NumberOfFiles", i_numofFiles - 1 );
471 config.removeEntry(s_numofFiles); 458 config.removeEntry(s_numofFiles);
472 459
473 QListBox_1->triggerUpdate(true); 460 QListBox_1->triggerUpdate(true);
474} 461}
475 462
476/* 463/*!
477sorts the list*/ 464 * Sorts the list
465 */
478void OpenEtext::scan() { 466void OpenEtext::scan() {
479 467
480 QListBox_1->sort(TRUE); 468 QListBox_1->sort(TRUE);
481 QListBox_1->triggerUpdate(true); 469 QListBox_1->triggerUpdate(true);
482} 470}
483 471
484void OpenEtext::editTitle() { 472void OpenEtext::editTitle() {
485 473
486 int currentItem=QListBox_1->currentItem(); 474 int currentItem=QListBox_1->currentItem();
487 QString title_text = QListBox_1->text( currentItem); 475 QString title_text = QListBox_1->text( currentItem);
488//odebug << "Selected "+title_text << oendl; 476 //odebug << "Selected "+title_text << oendl;
489 477
490 Config config("Gutenbrowser"); 478 Config config("Gutenbrowser");
491 config.setGroup( "Files" ); 479 config.setGroup( "Files" );
492 s_numofFiles = config.readEntry("NumberOfFiles", "0"); 480 s_numofFiles = config.readEntry("NumberOfFiles", "0");
493 int i_numofFiles = s_numofFiles.toInt(); 481 int i_numofFiles = s_numofFiles.toInt();
494 QString fileNum; 482 QString fileNum;
495 for (int i = 1; i <= i_numofFiles+1; i++) { 483 for (int i = 1; i <= i_numofFiles+1; i++) {
496 484
497 fileNum.setNum(i); 485 fileNum.setNum(i);
498 config.setGroup( "Files" ); 486 config.setGroup( "Files" );
499 QString s_filename = config.readEntry(fileNum, "" ); 487 QString s_filename = config.readEntry(fileNum, "" );
500 config.setGroup( "Titles" ); 488 config.setGroup( "Titles" );
501 QString file_title = config.readEntry( s_filename, ""); 489 QString file_title = config.readEntry( s_filename, "");
502//odebug << "file_title is "+file_title << oendl; 490 //odebug << "file_title is "+file_title << oendl;
503 if(title_text == file_title ) { 491 if(title_text == file_title ) {
504 selFile = s_filename; 492 selFile = s_filename;
505//odebug << "Edit: "+ file_title << oendl; 493 //odebug << "Edit: "+ file_title << oendl;
506 i=i_numofFiles+1; 494 i=i_numofFiles+1;
507 Edit_Title *titleEdit; 495 Edit_Title *titleEdit;
508 titleEdit = new Edit_Title(this,file_title ,TRUE); 496 titleEdit = new Edit_Title(this,file_title ,TRUE);
509 if(titleEdit->exec() !=0) { 497 if(titleEdit->exec() !=0) {
510//odebug << titleEdit->newTitle << oendl; 498 //odebug << titleEdit->newTitle << oendl;
511 config.writeEntry( s_filename, titleEdit->newTitle); 499 config.writeEntry( s_filename, titleEdit->newTitle);
512 QListBox_1->removeItem(currentItem); 500 QListBox_1->removeItem(currentItem);
513 QListBox_1->insertItem ( QPixmap( QPEApplication::qpeDir()+"pics/gutenbrowser/gutenbrowser_sm.png"), titleEdit->newTitle, currentItem); 501 QListBox_1->insertItem (
502 QPixmap( QPEApplication::qpeDir()+
503 "pics/gutenbrowser/gutenbrowser_sm.png"),
504 titleEdit->newTitle, currentItem
505 );
514 } 506 }
515 } 507 }
516 } 508 }
517 509
518// getTitles(); 510 //getTitles();
519 QListBox_1->triggerUpdate(true); 511 QListBox_1->triggerUpdate(true);
520} 512}
521 513
diff --git a/noncore/multimedia/opieplayer2/lib.cpp b/noncore/multimedia/opieplayer2/lib.cpp
index 84d28ce..5f281b7 100644
--- a/noncore/multimedia/opieplayer2/lib.cpp
+++ b/noncore/multimedia/opieplayer2/lib.cpp
@@ -16,142 +16,144 @@ _;:, .> :=|. This program is free software; you can
16 .%`+i> _;_. 16 .%`+i> _;_.
17 .i_,=:_. -<s. This program is distributed in the hope that 17 .i_,=:_. -<s. This program is distributed in the hope that
18 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 18 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
19 : .. .:, . . . without even the implied warranty of 19 : .. .:, . . . without even the implied warranty of
20 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 20 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
21 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU 21 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
22..}^=.= = ; Library General Public License for more 22..}^=.= = ; Library General Public License for more
23++= -. .` .: details. 23++= -. .` .: details.
24: = ...= . :.=- 24: = ...= . :.=-
25-. .:....=;==+<; You should have received a copy of the GNU 25-. .:....=;==+<; You should have received a copy of the GNU
26 -_. . . )=. = Library General Public License along with 26 -_. . . )=. = Library General Public License along with
27 -- :-=` this library; see the file COPYING.LIB. 27 -- :-=` this library; see the file COPYING.LIB.
28 If not, write to the Free Software Foundation, 28 If not, write to the Free Software Foundation,
29 Inc., 59 Temple Place - Suite 330, 29 Inc., 59 Temple Place - Suite 330,
30 Boston, MA 02111-1307, USA. 30 Boston, MA 02111-1307, USA.
31 31
32*/ 32*/
33 33
34#include "xinevideowidget.h" 34#include "xinevideowidget.h"
35#include "lib.h" 35#include "lib.h"
36 36
37/* OPIE */ 37/* OPIE */
38#include <opie2/odebug.h> 38#include <opie2/odebug.h>
39#include <qpe/global.h> 39#include <qpe/global.h>
40 40
41/* QT */ 41/* QT */
42#include <qtextstream.h> 42#include <qtextstream.h>
43#include <qdir.h> 43#include <qdir.h>
44#include <qgfx_qws.h> 44#include <qgfx_qws.h>
45 45
46/* STD */ 46/* STD */
47#include <assert.h> 47#include <assert.h>
48#include <unistd.h> 48#include <unistd.h>
49 49
50typedef void (*display_xine_frame_t) (void *user_data, uint8_t* frame, 50typedef void (*display_xine_frame_t) (void *user_data, uint8_t* frame,
51 int width, int height,int bytes ); 51 int width, int height,int bytes );
52typedef void (*vo_scale_cb) (void*, int, int, double, 52typedef void (*vo_scale_cb) (void*, int, int, double,
53 int*, int*, int*, int*, double*, int*, int* ); 53 int*, int*, int*, int*, double*, int*, int* );
54typedef void (*dest_size_cb) (void*, int, int, double, int*, int*, double*); 54typedef void (*dest_size_cb) (void*, int, int, double, int*, int*, double*);
55 55
56 56
57extern "C" { 57extern "C" {
58 xine_vo_driver_t* init_video_out_plugin( xine_t *xine, void* video, display_xine_frame_t, void *, vo_scale_cb, dest_size_cb ); 58 xine_vo_driver_t* init_video_out_plugin( xine_t *xine, void* video, display_xine_frame_t, void *, vo_scale_cb, dest_size_cb );
59 int null_is_showing_video( const xine_vo_driver_t* self ); 59 int null_is_showing_video( const xine_vo_driver_t* self );
60 void null_set_show_video( const xine_vo_driver_t* self, int show ); 60 void null_set_show_video( const xine_vo_driver_t* self, int show );
61 void null_set_mode( const xine_vo_driver_t* self, int depth, int rgb ); 61 void null_set_mode( const xine_vo_driver_t* self, int depth, int rgb );
62 void null_display_handler( const xine_vo_driver_t* self, display_xine_frame_t t, void* user_data ); 62 void null_display_handler( const xine_vo_driver_t* self, display_xine_frame_t t, void* user_data );
63} 63}
64 64
65using namespace XINE; 65using namespace XINE;
66 66
67Lib::Lib( InitializationMode initMode, XineVideoWidget* widget ) 67Lib::Lib( InitializationMode initMode, XineVideoWidget* widget )
68{ 68{
69 m_initialized = false; 69 m_initialized = false;
70 m_duringInitialization = false; 70 m_duringInitialization = false;
71 m_video = false; 71 m_video = false;
72 m_wid = widget; 72 m_wid = widget;
73 printf("Lib"); 73 printf("Lib");
74 QString configPath = QDir::homeDirPath() + "/Settings/opiexine.cf"; 74 QString configPath = QDir::homeDirPath() + "/Settings/opiexine.cf";
75 // get the configuration 75 // get the configuration
76 76
77 // not really OO, should be an extra class, later 77 // not really OO, should be an extra class, later
78 if ( !QFile::exists(configPath) ) { 78 if ( !QFile::exists(configPath) ) {
79 QFile f(configPath); 79 QFile f(configPath);
80 f.open(IO_WriteOnly); 80 if (f.open(IO_WriteOnly)) {
81 QTextStream ts( &f ); 81 QTextStream ts( &f );
82 ts << "misc.memcpy_method:glibc\n"; 82 ts << "misc.memcpy_method:glibc\n";
83 ts << "# uncomment if you experience double speed audio \n #audio.oss_sync_method:softsync\n"; 83 ts << "# uncomment if you experience double speed audio \n #audio.oss_sync_method:softsync\n";
84 ts << "codec.ffmpeg_pp_quality:3\n"; 84 ts << "codec.ffmpeg_pp_quality:3\n";
85 ts << "audio.num_buffers:50\n"; 85 ts << "audio.num_buffers:50\n";
86 ts << "audio.size_buffers:4096\n"; 86 ts << "audio.size_buffers:4096\n";
87 ts << "video.num_buffers:20\n"; 87 ts << "video.num_buffers:20\n";
88 ts << "video.size_buffers:4096\n"; 88 ts << "video.size_buffers:4096\n";
89 ts << "audio.out_num_audio_buf:16\n"; 89 ts << "audio.out_num_audio_buf:16\n";
90 ts << "audio.out_size_audio_buf:8096\n"; 90 ts << "audio.out_size_audio_buf:8096\n";
91 ts << "audio.out_size_zero_buf:1024\n"; 91 ts << "audio.out_size_zero_buf:1024\n";
92 ts << "audio.passthrough_offset:0\n"; 92 ts << "audio.passthrough_offset:0\n";
93 f.close(); 93 f.close();
94 } else
95 owarn << "Failed to open " f.name() << oendl;
94 } 96 }
95 97
96 if ( initMode == InitializeImmediately ) { 98 if ( initMode == InitializeImmediately ) {
97 initialize(); 99 initialize();
98 m_initialized = true; 100 m_initialized = true;
99 } 101 }
100 else 102 else
101 start(); 103 start();
102} 104}
103 105
104void Lib::run() 106void Lib::run()
105{ 107{
106 odebug << "Lib::run() started" << oendl; 108 odebug << "Lib::run() started" << oendl;
107 initialize(); 109 initialize();
108 m_initialized = true; 110 m_initialized = true;
109 odebug << "Lib::run() finished" << oendl; 111 odebug << "Lib::run() finished" << oendl;
110} 112}
111 113
112void Lib::initialize() 114void Lib::initialize()
113{ 115{
114 m_duringInitialization = true; 116 m_duringInitialization = true;
115 m_xine = xine_new( ); 117 m_xine = xine_new( );
116 118
117 QString configPath = QDir::homeDirPath() + "/Settings/opiexine.cf"; 119 QString configPath = QDir::homeDirPath() + "/Settings/opiexine.cf";
118 xine_config_load( m_xine, QFile::encodeName( configPath ) ); 120 xine_config_load( m_xine, QFile::encodeName( configPath ) );
119 121
120 xine_init( m_xine ); 122 xine_init( m_xine );
121 123
122 // allocate oss for sound 124 // allocate oss for sound
123 // and fb for framebuffer 125 // and fb for framebuffer
124 m_audioOutput = xine_open_audio_driver( m_xine, "oss", NULL ); 126 m_audioOutput = xine_open_audio_driver( m_xine, "oss", NULL );
125 m_videoOutput = ::init_video_out_plugin( m_xine, NULL, 127 m_videoOutput = ::init_video_out_plugin( m_xine, NULL,
126 xine_display_frame, this, 128 xine_display_frame, this,
127 xine_vo_scale_cb, 129 xine_vo_scale_cb,
128 xine_dest_cb ); 130 xine_dest_cb );
129 131
130 m_stream = xine_stream_new (m_xine, m_audioOutput, m_videoOutput ); 132 m_stream = xine_stream_new (m_xine, m_audioOutput, m_videoOutput );
131 xine_set_param( m_stream, XINE_PARAM_AUDIO_CLOSE_DEVICE, 1); 133 xine_set_param( m_stream, XINE_PARAM_AUDIO_CLOSE_DEVICE, 1);
132 134
133 if (m_wid != 0 ) 135 if (m_wid != 0 )
134 setWidget( m_wid ); 136 setWidget( m_wid );
135 137
136 138
137 m_queue = xine_event_new_queue (m_stream); 139 m_queue = xine_event_new_queue (m_stream);
138 xine_event_create_listener_thread (m_queue, xine_event_handler, this); 140 xine_event_create_listener_thread (m_queue, xine_event_handler, this);
139 141
140 m_duringInitialization = false; 142 m_duringInitialization = false;
141} 143}
142 144
143Lib::~Lib() { 145Lib::~Lib() {
144 assert( isRunning() == false ); 146 assert( isRunning() == false );
145 assert( m_initialized ); 147 assert( m_initialized );
146 148
147// free( m_config ); 149// free( m_config );
148 150
149 xine_close( m_stream ); 151 xine_close( m_stream );
150 xine_event_dispose_queue( m_queue ); 152 xine_event_dispose_queue( m_queue );
151 xine_dispose( m_stream ); 153 xine_dispose( m_stream );
152 xine_close_audio_driver(m_xine,m_audioOutput); 154 xine_close_audio_driver(m_xine,m_audioOutput);
153 xine_close_video_driver(m_xine,m_videoOutput); 155 xine_close_video_driver(m_xine,m_videoOutput);
154 xine_exit( m_xine ); 156 xine_exit( m_xine );
155 157
156 /* FIXME either free or delete but valgrind bitches against both */ 158 /* FIXME either free or delete but valgrind bitches against both */
157 //free( m_videoOutput ); 159 //free( m_videoOutput );
diff --git a/noncore/multimedia/opieplayer2/om3u.cpp b/noncore/multimedia/opieplayer2/om3u.cpp
index 790fa09..f2a01d3 100644
--- a/noncore/multimedia/opieplayer2/om3u.cpp
+++ b/noncore/multimedia/opieplayer2/om3u.cpp
@@ -1,152 +1,145 @@
1/* 1/*
2                This file is part of the Opie Project 2                This file is part of the Opie Project
3 3
4 Copyright (c) 2002 L. Potter <ljp@llornkcor.com> 4 Copyright (c) 2002 L. Potter <ljp@llornkcor.com>
5 =. 5 =.
6 .=l. 6 .=l.
7           .>+-= 7           .>+-=
8 _;:,     .>    :=|. This program is free software; you can 8 _;:,     .>    :=|. This program is free software; you can
9.> <`_,   >  .   <= redistribute it and/or modify it under 9.> <`_,   >  .   <= redistribute it and/or modify it under
10:`=1 )Y*s>-.--   : the terms of the GNU General Public 10:`=1 )Y*s>-.--   : the terms of the GNU General Public
11.="- .-=="i,     .._ License as published by the Free Software 11.="- .-=="i,     .._ License as published by the Free Software
12 - .   .-<_>     .<> Foundation; either version 2 of the License, 12 - .   .-<_>     .<> Foundation; either version 2 of the License,
13     ._= =}       : or (at your option) any later version. 13     ._= =}       : or (at your option) any later version.
14    .%`+i>       _;_. 14    .%`+i>       _;_.
15    .i_,=:_.      -<s. This program is distributed in the hope that 15    .i_,=:_.      -<s. This program is distributed in the hope that
16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
17    : ..    .:,     . . . without even the implied warranty of 17    : ..    .:,     . . . without even the implied warranty of
18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
20..}^=.=       =       ; General Public License for more 20..}^=.=       =       ; General Public License for more
21++=   -.     .`     .: details. 21++=   -.     .`     .: details.
22 :     =  ...= . :.=- 22 :     =  ...= . :.=-
23 -.   .:....=;==+<; You should have received a copy of the GNU 23 -.   .:....=;==+<; You should have received a copy of the GNU
24  -_. . .   )=.  = General Public License along with 24  -_. . .   )=.  = General Public License along with
25    --        :-=` this library; see the file COPYING.LIB. 25    --        :-=` this library; see the file COPYING.LIB.
26 If not, write to the Free Software Foundation, 26 If not, write to the Free Software Foundation,
27 Inc., 59 Temple Place - Suite 330, 27 Inc., 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA. 28 Boston, MA 02111-1307, USA.
29 29
30*/ 30*/
31 31
32#include "om3u.h" 32#include "om3u.h"
33 33
34/* OPIE */ 34/* OPIE */
35#include <opie2/odebug.h> 35#include <opie2/odebug.h>
36using namespace Opie::Core; 36using namespace Opie::Core;
37 37
38//extern PlayListWidget *playList; 38//extern PlayListWidget *playList;
39 39
40Om3u::Om3u( const QString &filePath, int mode) 40Om3u::Om3u( const QString &filePath, int mode)
41 : QStringList (){ 41 : QStringList ()
42odebug << "<<<<<<<new m3u "+filePath << oendl; 42{
43 f.setName(filePath); 43 odebug << "<<<<<<<new m3u "+filePath << oendl;
44 f.open(mode); 44 f.setName(filePath);
45 if (!f.open(mode)) {
46 owarn << "Unable to open file " << f.name() << oendl;
47 }
45} 48}
46 49
47Om3u::~Om3u(){} 50Om3u::~Om3u(){}
48 51
49void Om3u::readM3u() { 52void Om3u::readM3u() {
50// odebug << "<<<<<<reading m3u "+f.name() << oendl; 53// odebug << "<<<<<<reading m3u "+f.name() << oendl;
51 QTextStream t(&f); 54 QTextStream t(&f);
52 t.setEncoding(QTextStream::UnicodeUTF8); 55 t.setEncoding(QTextStream::UnicodeUTF8);
53 QString s; 56 QString s;
54 while ( !t.atEnd() ) { 57 while ( !t.atEnd() ) {
55 s=t.readLine(); 58 s=t.readLine();
56// odebug << s << oendl; 59 // odebug << s << oendl;
57 if( s.find( "#", 0, TRUE) == -1 ) { 60 if( s.find( "#", 0, TRUE) == -1 ) {
58 if( s.left(2) == "E:" || s.left(2) == "P:" ) { 61 if( s.left(2) == "E:" || s.left(2) == "P:" ) {
59 s = s.right( s.length() -2 ); 62 s = s.right( s.length() -2 );
60 QFileInfo f( s ); 63 QFileInfo f( s );
61 QString name = f.baseName(); 64 QString name = f.baseName();
62 name = name.right( name.length() - name.findRev( "\\", -1, TRUE ) -1 ); 65 name = name.right( name.length() - name.findRev( "\\", -1, TRUE ) -1 );
63 s=s.replace( QRegExp( "\\" ), "/" ); 66 s=s.replace( QRegExp( "\\" ), "/" );
64 append(s); 67 append(s);
65// odebug << s << oendl; 68// odebug << s << oendl;
66 } else { // is url 69 } else { // is url
67 QString name; 70 QString name;
68 name = s; 71 name = s;
69 append(name); 72 append(name);
70 } 73 }
71 } 74 }
72 } 75 }
73} 76}
74 77
75void Om3u::readPls() { //it's a pls file 78void Om3u::readPls() { //it's a pls file
76 QTextStream t( &f ); 79 QTextStream t( &f );
77 t.setEncoding(QTextStream::UnicodeUTF8); 80 t.setEncoding(QTextStream::UnicodeUTF8);
78 QString s; 81 QString s;
79 while ( !t.atEnd() ) { 82 while ( !t.atEnd() ) {
80 s = t.readLine(); 83 s = t.readLine();
81 if( s.left(4) == "File" ) { 84 if( s.left(4) == "File" ) {
82 s = s.right( s.length() - s.find("=",0,true)-1 ); 85 s = s.right( s.length() - s.find("=",0,true)-1 );
83 s = s.stripWhiteSpace(); 86 s = s.stripWhiteSpace();
84 s.replace( QRegExp( "%20" )," "); 87 s.replace( QRegExp( "%20" )," ");
85// odebug << "adding " + s + " to playlist" << oendl; 88 // odebug << "adding " + s + " to playlist" << oendl;
86 // numberofentries=2 89 s = s.replace( QRegExp( "\\" ), "/" );
87 // File1=http 90 QFileInfo f( s );
88 // Title 91 QString name = f.baseName();
89 // Length 92 if( name.left( 4 ) == "http" ) {
90 // Version 93 name = s.right( s.length() - 7);
91 // File2=http 94 } else {
92 s = s.replace( QRegExp( "\\" ), "/" ); 95 name = s;
93 QFileInfo f( s ); 96 }
94 QString name = f.baseName(); 97 name = name.right( name.length() - name.findRev( "\\", -1, TRUE) - 1 );
95 if( name.left( 4 ) == "http" ) { 98 if( s.at( s.length() - 4) == '.') // if this is probably a file
96 name = s.right( s.length() - 7); 99 append(s);
97 } else { 100 else { //if its a url
98 name = s;
99 }
100 name = name.right( name.length() - name.findRev( "\\", -1, TRUE) - 1 );
101 if( s.at( s.length() - 4) == '.') // if this is probably a file
102 append(s); 101 append(s);
103 else { //if its a url
104// if( name.right( 1 ).find( '/' ) == -1) {
105// s += "/";
106// }
107 append(s);
108 }
109 } 102 }
110 } 103 }
104 }
111} 105}
112 106
113void Om3u::write() { //writes list to m3u file 107void Om3u::write() { //writes list to m3u file
114 QString list; 108 QString list;
115 QTextStream t(&f); 109 QTextStream t(&f);
116 t.setEncoding(QTextStream::UnicodeUTF8); 110 t.setEncoding(QTextStream::UnicodeUTF8);
117 if(count()>0) { 111 if(count()>0) {
118 for ( QStringList::ConstIterator it = begin(); it != end(); ++it ) { 112 for ( QStringList::ConstIterator it = begin(); it != end(); ++it ) {
119// odebug << *it << oendl; 113 // odebug << *it << oendl;
120 t << *it << "\n"; 114 t << *it << "\n";
115 }
121 } 116 }
122 }
123// f.close();
124} 117}
125 118
126void Om3u::add(const QString &filePath) { //adds to m3u file 119void Om3u::add(const QString &filePath) { //adds to m3u file
127 append(filePath); 120 append(filePath);
128} 121}
129 122
130void Om3u::remove(const QString &filePath) { //removes from m3u list 123void Om3u::remove(const QString &filePath) { //removes from m3u list
131 QString list, currentFile; 124 QString list, currentFile;
132 if(count()>0) { 125 if(count()>0) {
133 for ( QStringList::ConstIterator it = begin(); it != end(); ++it ) { 126 for ( QStringList::ConstIterator it = begin(); it != end(); ++it ) {
134 currentFile=*it; 127 currentFile=*it;
135 // odebug << *it << oendl; 128 // odebug << *it << oendl;
136 129
137 if( filePath != currentFile) 130 if( filePath != currentFile)
138 list += currentFile+"\n"; 131 list += currentFile+"\n";
132 }
133 f.writeBlock( list, list.length() );
139 } 134 }
140 f.writeBlock( list, list.length() );
141 }
142} 135}
143 136
144void Om3u::deleteFile(const QString &/*filePath*/) {//deletes m3u file 137void Om3u::deleteFile(const QString &/*filePath*/) {//deletes m3u file
145 f.close(); 138 f.close();
146 f.remove(); 139 f.remove();
147 140
148} 141}
149 142
150void Om3u::close() { //closes m3u file 143void Om3u::close() { //closes m3u file
151 f.close(); 144 f.close();
152} 145}
diff --git a/noncore/multimedia/opieplayer2/threadutil.cpp b/noncore/multimedia/opieplayer2/threadutil.cpp
index b5cac61..5fc8a0b 100644
--- a/noncore/multimedia/opieplayer2/threadutil.cpp
+++ b/noncore/multimedia/opieplayer2/threadutil.cpp
@@ -172,134 +172,139 @@ static void *start_thread( void *arg )
172} 172}
173 173
174Thread::Thread() 174Thread::Thread()
175 : d( new Data ) 175 : d( new Data )
176{ 176{
177 d->thr = this; 177 d->thr = this;
178} 178}
179 179
180Thread::~Thread() 180Thread::~Thread()
181{ 181{
182 assert( d->isRunning == false ); 182 assert( d->isRunning == false );
183 delete d; 183 delete d;
184} 184}
185 185
186void Thread::start() 186void Thread::start()
187{ 187{
188 AutoLock lock( d->guard ); 188 AutoLock lock( d->guard );
189 189
190 if ( d->isRunning ) { 190 if ( d->isRunning ) {
191 odebug << "ThreadUtil::Thread::start() called for running thread." << oendl; 191 odebug << "ThreadUtil::Thread::start() called for running thread." << oendl;
192 return; 192 return;
193 } 193 }
194 194
195 pthread_attr_t attributes; 195 pthread_attr_t attributes;
196 pthread_attr_init( &attributes ); 196 pthread_attr_init( &attributes );
197 pthread_attr_setscope( &attributes, PTHREAD_SCOPE_SYSTEM ); 197 pthread_attr_setscope( &attributes, PTHREAD_SCOPE_SYSTEM );
198 int err = pthread_create( &d->self, &attributes, start_thread, ( void* )d ); 198 int err = pthread_create( &d->self, &attributes, start_thread, ( void* )d );
199 if ( err != 0 ) { 199 if ( err != 0 ) {
200 odebug << "ThreadUtil::Thread::start() : can't create thread: " << strerror( err ) << "" << oendl; 200 odebug << "ThreadUtil::Thread::start() : can't create thread: " << strerror( err ) << "" << oendl;
201 pthread_attr_destroy( &attributes ); 201 pthread_attr_destroy( &attributes );
202 return; 202 return;
203 } 203 }
204 pthread_attr_destroy( &attributes ); 204 pthread_attr_destroy( &attributes );
205} 205}
206 206
207void Thread::terminate() 207void Thread::terminate()
208{ 208{
209 AutoLock lock( d->guard ); 209 AutoLock lock( d->guard );
210 if ( !d->isRunning ) 210 if ( !d->isRunning )
211 return; 211 return;
212 212
213 pthread_cancel( d->self ); 213 pthread_cancel( d->self );
214} 214}
215 215
216bool Thread::wait() 216bool Thread::wait()
217{ 217{
218 AutoLock lock( d->guard ); 218 AutoLock lock( d->guard );
219 if ( !d->isRunning ) 219 if ( !d->isRunning )
220 return true; 220 return true;
221 221
222 return d->finishCondition.wait( d->guard ); 222 return d->finishCondition.wait( d->guard );
223} 223}
224 224
225bool Thread::isRunning() const 225bool Thread::isRunning() const
226{ 226{
227 AutoLock lock( d->guard ); 227 AutoLock lock( d->guard );
228 return d->isRunning; 228 return d->isRunning;
229} 229}
230 230
231void Thread::exit() 231void Thread::exit()
232{ 232{
233 pthread_exit( 0 ); 233 pthread_exit( 0 );
234} 234}
235 235
236OnewayNotifier::OnewayNotifier() 236OnewayNotifier::OnewayNotifier() :
237{ 237 m_readFd(-1),
238 int fds[ 2 ]; 238 m_writeFd(-1)
239 pipe( fds ); 239{
240 m_readFd = fds[ 0 ]; 240 int fds[ 2 ] = { -1, -1 };
241 m_writeFd = fds[ 1 ]; 241 if (pipe( fds ) == 0) {
242 m_readFd = fds[ 0 ];
243 m_writeFd = fds[ 1 ];
244 } else {
245 owarn << "Call to pipe() failed" << oendl;
246 }
242 247
243 m_notifier = new QSocketNotifier( m_readFd, QSocketNotifier::Read ); 248 m_notifier = new QSocketNotifier( m_readFd, QSocketNotifier::Read );
244 connect( m_notifier, SIGNAL( activated(int) ), 249 connect( m_notifier, SIGNAL( activated(int) ),
245 this, SLOT( wakeUp() ) ); 250 this, SLOT( wakeUp() ) );
246} 251}
247 252
248OnewayNotifier::~OnewayNotifier() 253OnewayNotifier::~OnewayNotifier()
249{ 254{
250 delete m_notifier; 255 delete m_notifier;
251 256
252 ::close( m_readFd ); 257 ::close( m_readFd );
253 ::close( m_writeFd ); 258 ::close( m_writeFd );
254} 259}
255 260
256void OnewayNotifier::notify() 261void OnewayNotifier::notify()
257{ 262{
258 const char c = 42; 263 const char c = 42;
259 ::write( m_writeFd, &c, 1 ); 264 ::write( m_writeFd, &c, 1 );
260} 265}
261 266
262void OnewayNotifier::wakeUp() 267void OnewayNotifier::wakeUp()
263{ 268{
264 char c = 0; 269 char c = 0;
265 270
266 if ( ::read( m_readFd, &c, 1 ) != 1 ) 271 if ( ::read( m_readFd, &c, 1 ) != 1 )
267 return; 272 return;
268 273
269 emit awake(); 274 emit awake();
270} 275}
271 276
272ChannelMessage::ChannelMessage( int type, int data, const char* msg ) 277ChannelMessage::ChannelMessage( int type, int data, const char* msg )
273 : m_type( type ), m_data( data ), m_msg( msg ), 278 : m_type( type ), m_data( data ), m_msg( msg ),
274 m_isCall( false ), m_replied( false ), m_inEventHandler( false ) 279 m_isCall( false ), m_replied( false ), m_inEventHandler( false )
275{} 280{}
276 281
277ChannelMessage::~ChannelMessage() 282ChannelMessage::~ChannelMessage()
278{ 283{
279 if ( m_guard.isLocked() ) 284 if ( m_guard.isLocked() )
280 m_guard.unlock(); 285 m_guard.unlock();
281} 286}
282 287
283void ChannelMessage::reply() 288void ChannelMessage::reply()
284{ 289{
285 if ( !m_isCall ) 290 if ( !m_isCall )
286 { 291 {
287 odebug << "ChannelMessage::reply() - can't reply oneway message!" << oendl; 292 odebug << "ChannelMessage::reply() - can't reply oneway message!" << oendl;
288 return; 293 return;
289 } 294 }
290 295
291 if ( m_inEventHandler ) 296 if ( m_inEventHandler )
292 { 297 {
293 m_replied = true; 298 m_replied = true;
294 return; 299 return;
295 } 300 }
296 301
297 m_condition.wakeOne(); 302 m_condition.wakeOne();
298 m_guard.unlock(); 303 m_guard.unlock();
299} 304}
300 305
301struct Channel::Private 306struct Channel::Private
302{ 307{
303 Private() 308 Private()
304 { 309 {
305 ownerThread = pthread_self(); 310 ownerThread = pthread_self();
diff --git a/noncore/net/opiestumbler/opiestumbler.cpp b/noncore/net/opiestumbler/opiestumbler.cpp
index 9b0d099..ab0b8d8 100644
--- a/noncore/net/opiestumbler/opiestumbler.cpp
+++ b/noncore/net/opiestumbler/opiestumbler.cpp
@@ -281,104 +281,105 @@ void OpieStumbler::slotJoinNetwork()
281 m_splash->setFrameStyle( QFrame::Panel | QFrame::Raised ); 281 m_splash->setFrameStyle( QFrame::Panel | QFrame::Raised );
282 m_splashBox = new QVBoxLayout( m_splash, 4, 4 ); 282 m_splashBox = new QVBoxLayout( m_splash, 4, 4 );
283 m_infoLabel = new QLabel( QString("<center><b>%1 %2</b></center>").arg(tr("Joining Network")).arg(m_ssid), m_splash ); 283 m_infoLabel = new QLabel( QString("<center><b>%1 %2</b></center>").arg(tr("Joining Network")).arg(m_ssid), m_splash );
284 m_pbar = new QProgressBar( 3, m_splash ); 284 m_pbar = new QProgressBar( 3, m_splash );
285 m_pbar->setCenterIndicator(true); 285 m_pbar->setCenterIndicator(true);
286 m_splashBox->addWidget( m_infoLabel ); 286 m_splashBox->addWidget( m_infoLabel );
287 m_splashBox->addWidget( m_pbar ); 287 m_splashBox->addWidget( m_pbar );
288 int sw = m_splashBox->sizeHint().width() * 2; 288 int sw = m_splashBox->sizeHint().width() * 2;
289 int sh = m_splashBox->sizeHint().height(); 289 int sh = m_splashBox->sizeHint().height();
290 m_splash->setGeometry((qApp->desktop()->width() - sw)/2, (qApp->desktop()->height() - sh)/2, sw, sh); 290 m_splash->setGeometry((qApp->desktop()->width() - sw)/2, (qApp->desktop()->height() - sh)/2, sw, sh);
291 m_splash->show(); 291 m_splash->show();
292 m_splash->raise(); 292 m_splash->raise();
293 293
294 Opie::Net::OStation *station = it.current()->st; 294 Opie::Net::OStation *station = it.current()->st;
295 295
296 odebug << "Bringing interface down" << oendl; 296 odebug << "Bringing interface down" << oendl;
297 wiface->setUp(false); 297 wiface->setUp(false);
298 298
299 odebug << "Setting mode to " << (station->type == "adhoc" ? "adhoc" : "managed") << oendl; 299 odebug << "Setting mode to " << (station->type == "adhoc" ? "adhoc" : "managed") << oendl;
300 wiface->setMode(station->type == "adhoc" ? "adhoc" : "managed" ); 300 wiface->setMode(station->type == "adhoc" ? "adhoc" : "managed" );
301 301
302 odebug << "Setting channel to " << station->channel << oendl; 302 odebug << "Setting channel to " << station->channel << oendl;
303 wiface->setChannel(station->channel); 303 wiface->setChannel(station->channel);
304 304
305 odebug << "Setting SSID to " << station->ssid << oendl; 305 odebug << "Setting SSID to " << station->ssid << oendl;
306 wiface->setSSID(station->ssid); 306 wiface->setSSID(station->ssid);
307 307
308 wiface->commit(); 308 wiface->commit();
309 309
310 odebug << "Bringing interface up" << oendl; 310 odebug << "Bringing interface up" << oendl;
311 wiface->setUp(true); 311 wiface->setUp(true);
312 m_pbar->setProgress(1); 312 m_pbar->setProgress(1);
313 //Wait 5 sec for association 313 //Wait 5 sec for association
314 QTimer::singleShot(5000, this, SLOT(slotAssociated())); 314 QTimer::singleShot(5000, this, SLOT(slotAssociated()));
315} 315}
316 316
317void OpieStumbler::slotAssociated() 317void OpieStumbler::slotAssociated()
318{ 318{
319 OWirelessNetworkInterface *wiface = static_cast<OWirelessNetworkInterface*>(ONetwork::instance()->interface(m_interface)); 319 OWirelessNetworkInterface *wiface = static_cast<OWirelessNetworkInterface*>(ONetwork::instance()->interface(m_interface));
320 320
321 if( !wiface ) { 321 if( !wiface ) {
322 slotCleanSplash(); 322 slotCleanSplash();
323 return; 323 return;
324 } 324 }
325 325
326 if (!wiface->isAssociated()) { 326 if (!wiface->isAssociated()) {
327 Global::statusMessage(tr("Could not Join")); 327 Global::statusMessage(tr("Could not Join"));
328 m_infoLabel->setText(tr("Could not Join")); 328 m_infoLabel->setText(tr("Could not Join"));
329 QTimer::singleShot(5000, this, SLOT(slotCleanSplash())); 329 QTimer::singleShot(5000, this, SLOT(slotCleanSplash()));
330 return; 330 return;
331 } 331 }
332 332
333 Global::statusMessage(tr("Joined")); 333 Global::statusMessage(tr("Joined"));
334 m_pbar->setProgress(2); 334 m_pbar->setProgress(2);
335 m_infoLabel->setText(QString("<center><b>%1 %2</b></center>").arg(tr("Joined Network")).arg(m_ssid)); 335 m_infoLabel->setText(QString("<center><b>%1 %2</b></center>").arg(tr("Joined Network")).arg(m_ssid));
336 336
337 if(m_proc) { 337 if(m_proc) {
338 m_proc->kill(); 338 m_proc->kill();
339 delete m_proc; 339 delete m_proc;
340 } 340 }
341 341
342 m_proc = new Opie::Core::OProcess(this); 342 m_proc = new Opie::Core::OProcess(this);
343 343
344 *m_proc << "udhcpc" << "-f" << "-n" << "-i" << m_interface; 344 *m_proc << "udhcpc" << "-f" << "-n" << "-i" << m_interface;
345 m_proc->start(Opie::Core::OProcess::DontCare); 345 if (!m_proc->start(Opie::Core::OProcess::DontCare))
346 owarn << "Execution of udhcpc returned false. Are paths correct?" << oendl;
346 QTimer::singleShot(5000, this, SLOT(slotCheckDHCP())); 347 QTimer::singleShot(5000, this, SLOT(slotCheckDHCP()));
347} 348}
348 349
349void OpieStumbler::slotCheckDHCP() 350void OpieStumbler::slotCheckDHCP()
350{ 351{
351 if(!m_proc->isRunning()) { 352 if(!m_proc->isRunning()) {
352 Global::statusMessage(tr("Could not Obtain an Address")); 353 Global::statusMessage(tr("Could not Obtain an Address"));
353 m_infoLabel->setText(QString("<center><b>%1</b></center>").arg(tr("Could not Obtain an Address"))); 354 m_infoLabel->setText(QString("<center><b>%1</b></center>").arg(tr("Could not Obtain an Address")));
354 delete m_proc; 355 delete m_proc;
355 m_proc = NULL; 356 m_proc = NULL;
356 QTimer::singleShot(5000, this, SLOT(slotCleanSplash())); 357 QTimer::singleShot(5000, this, SLOT(slotCleanSplash()));
357 return; 358 return;
358 } 359 }
359 m_listCurrent->show(); 360 m_listCurrent->show();
360 m_pbar->setProgress(3); 361 m_pbar->setProgress(3);
361 362
362 OWirelessNetworkInterface *wiface = static_cast<OWirelessNetworkInterface*>(ONetwork::instance()->interface(m_interface)); 363 OWirelessNetworkInterface *wiface = static_cast<OWirelessNetworkInterface*>(ONetwork::instance()->interface(m_interface));
363 QString ipv4 = wiface->ipV4Address().toString(); 364 QString ipv4 = wiface->ipV4Address().toString();
364 m_infoLabel->setText(QString("<center><b>%1 %2</b></center>").arg(tr("Obtained IP")).arg(ipv4)); 365 m_infoLabel->setText(QString("<center><b>%1 %2</b></center>").arg(tr("Obtained IP")).arg(ipv4));
365 Global::statusMessage(tr("Obtained IP") + " " + ipv4); 366 Global::statusMessage(tr("Obtained IP") + " " + ipv4);
366 QTimer::singleShot(5000, this, SLOT(slotCleanSplash())); 367 QTimer::singleShot(5000, this, SLOT(slotCleanSplash()));
367 368
368} 369}
369 370
370void OpieStumbler::slotCleanSplash() 371void OpieStumbler::slotCleanSplash()
371{ 372{
372 delete m_pbar; 373 delete m_pbar;
373 m_pbar = 0; 374 m_pbar = 0;
374 375
375 delete m_infoLabel; 376 delete m_infoLabel;
376 m_infoLabel = 0; 377 m_infoLabel = 0;
377 378
378 delete m_splashBox; 379 delete m_splashBox;
379 m_splashBox = 0; 380 m_splashBox = 0;
380 381
381 delete m_splash; 382 delete m_splash;
382 m_splash = 0; 383 m_splash = 0;
383} 384}
384 385
diff --git a/noncore/settings/networksettings/mainwindow/mainwindowimp.cpp b/noncore/settings/networksettings/mainwindow/mainwindowimp.cpp
index 650e634..e81f603 100644
--- a/noncore/settings/networksettings/mainwindow/mainwindowimp.cpp
+++ b/noncore/settings/networksettings/mainwindow/mainwindowimp.cpp
@@ -135,129 +135,130 @@ MainWindowImp::MainWindowImp(QWidget *parent, const char *name, WFlags) : MainWi
135 initHostname(); 135 initHostname();
136} 136}
137 137
138/** 138/**
139 * Deconstructor. Save profiles. Delete loaded libraries. 139 * Deconstructor. Save profiles. Delete loaded libraries.
140 */ 140 */
141MainWindowImp::~MainWindowImp() 141MainWindowImp::~MainWindowImp()
142{ 142{
143 // Save profiles. 143 // Save profiles.
144 Config cfg("NetworkSetup"); 144 Config cfg("NetworkSetup");
145 cfg.setGroup("General"); 145 cfg.setGroup("General");
146 cfg.writeEntry("Profiles", profiles.join(" ")); 146 cfg.writeEntry("Profiles", profiles.join(" "));
147 147
148 // Delete all interfaces that don't have owners. 148 // Delete all interfaces that don't have owners.
149 QMap<Interface*, QListViewItem*>::Iterator iIt; 149 QMap<Interface*, QListViewItem*>::Iterator iIt;
150 for( iIt = items.begin(); iIt != items.end(); ++iIt ) 150 for( iIt = items.begin(); iIt != items.end(); ++iIt )
151 { 151 {
152 if(iIt.key()->getModuleOwner() == NULL) 152 if(iIt.key()->getModuleOwner() == NULL)
153 delete iIt.key(); 153 delete iIt.key();
154 } 154 }
155 155
156 // Delete Modules and Libraries 156 // Delete Modules and Libraries
157 QMap<Module*, QLibrary*>::Iterator it; 157 QMap<Module*, QLibrary*>::Iterator it;
158 for( it = libraries.begin(); it != libraries.end(); ++it ) 158 for( it = libraries.begin(); it != libraries.end(); ++it )
159 { 159 {
160 delete it.key(); 160 delete it.key();
161 // I wonder why I can't delete the libraries 161 // I wonder why I can't delete the libraries
162 // What fucking shit this is. 162 // What fucking shit this is.
163 //delete it.data(); 163 //delete it.data();
164 } 164 }
165} 165}
166 166
167/** 167/**
168 * Query the kernel for all of the interfaces. 168 * Query the kernel for all of the interfaces.
169 */ 169 */
170void MainWindowImp::getAllInterfaces() 170void MainWindowImp::getAllInterfaces()
171{ 171{
172 int sockfd = socket(PF_INET, SOCK_DGRAM, 0); 172 int sockfd = socket(PF_INET, SOCK_DGRAM, 0);
173 if(sockfd == -1) 173 if(sockfd == -1)
174 return; 174 return;
175 175
176 struct ifreq ifr; 176 struct ifreq ifr;
177 QStringList ifaces; 177 QStringList ifaces;
178 QFile procFile(QString(_PROCNETDEV)); 178 QFile procFile(QString(_PROCNETDEV));
179 int result; 179 int result;
180 Interface *i; 180 Interface *i;
181 181
182 if (! procFile.exists()) 182 if (! procFile.exists())
183 { 183 {
184 struct ifreq ifrs[100]; 184 struct ifreq ifrs[100];
185 struct ifconf ifc; 185 struct ifconf ifc;
186 ifc.ifc_len = sizeof(ifrs); 186 ifc.ifc_len = sizeof(ifrs);
187 ifc.ifc_req = ifrs; 187 ifc.ifc_req = ifrs;
188 result = ioctl(sockfd, SIOCGIFCONF, &ifc); 188 result = ioctl(sockfd, SIOCGIFCONF, &ifc);
189 189
190 for (unsigned int i = 0; i < ifc.ifc_len / sizeof(struct ifreq); i++) 190 for (unsigned int i = 0; i < ifc.ifc_len / sizeof(struct ifreq); i++)
191 { 191 {
192 struct ifreq *pifr = &ifrs[i]; 192 struct ifreq *pifr = &ifrs[i];
193 if ( !QString( pifr->ifr_name ).startsWith( "wifi" ) ) ifaces += pifr->ifr_name; 193 if ( !QString( pifr->ifr_name ).startsWith( "wifi" ) ) ifaces += pifr->ifr_name;
194 else odebug << "ignoring hostap control interface " << pifr->ifr_name << oendl; 194 else odebug << "ignoring hostap control interface " << pifr->ifr_name << oendl;
195 } 195 }
196 } 196 }
197 else 197 else
198 { 198 {
199 procFile.open(IO_ReadOnly); 199 if (!procFile.open(IO_ReadOnly))
200 owarn << "Failed to open proc file " << procFile.name() << oendl;
200 QString line; 201 QString line;
201 QTextStream procTs(&procFile); 202 QTextStream procTs(&procFile);
202 int loc = -1; 203 int loc = -1;
203 204
204 procTs.readLine(); // eat a line 205 procTs.readLine(); // eat a line
205 procTs.readLine(); // eat a line 206 procTs.readLine(); // eat a line
206 while((line = procTs.readLine().simplifyWhiteSpace()) != QString::null) 207 while((line = procTs.readLine().simplifyWhiteSpace()) != QString::null)
207 { 208 {
208 if((loc = line.find(":")) != -1) 209 if((loc = line.find(":")) != -1)
209 { 210 {
210 // ignore wifi* (hostap control interfaces) 211 // ignore wifi* (hostap control interfaces)
211 if ( !line.left(loc).startsWith( "wifi" ) ) ifaces += line.left(loc); 212 if ( !line.left(loc).startsWith( "wifi" ) ) ifaces += line.left(loc);
212 else odebug << "ignoring hostap control interface " << line.left(loc) << oendl; 213 else odebug << "ignoring hostap control interface " << line.left(loc) << oendl;
213 } 214 }
214 } 215 }
215 } 216 }
216 217
217 for (QStringList::Iterator it = ifaces.begin(); it != ifaces.end(); ++it) 218 for (QStringList::Iterator it = ifaces.begin(); it != ifaces.end(); ++it)
218 { 219 {
219 int flags = 0; 220 int flags = 0;
220 if ( m_handledIfaces.contains( (*it) ) ) 221 if ( m_handledIfaces.contains( (*it) ) )
221 { 222 {
222 odebug << " " << (*it).latin1() << " is handled by a module" << oendl; 223 odebug << " " << (*it).latin1() << " is handled by a module" << oendl;
223 continue; 224 continue;
224 } 225 }
225 // int family; 226 // int family;
226 i = NULL; 227 i = NULL;
227 228
228 strcpy(ifr.ifr_name, (*it).latin1()); 229 strcpy(ifr.ifr_name, (*it).latin1());
229 230
230 struct ifreq ifcopy; 231 struct ifreq ifcopy;
231 ifcopy = ifr; 232 ifcopy = ifr;
232 result = ioctl(sockfd, SIOCGIFFLAGS, &ifcopy); 233 result = ioctl(sockfd, SIOCGIFFLAGS, &ifcopy);
233 flags = ifcopy.ifr_flags; 234 flags = ifcopy.ifr_flags;
234 i = new Interface(this, ifr.ifr_name, false); 235 i = new Interface(this, ifr.ifr_name, false);
235 i->setAttached(true); 236 i->setAttached(true);
236 if ((flags & IFF_UP) == IFF_UP) 237 if ((flags & IFF_UP) == IFF_UP)
237 i->setStatus(true); 238 i->setStatus(true);
238 else 239 else
239 i->setStatus(false); 240 i->setStatus(false);
240 241
241 if ((flags & IFF_BROADCAST) == IFF_BROADCAST) 242 if ((flags & IFF_BROADCAST) == IFF_BROADCAST)
242 i->setHardwareName("Ethernet"); 243 i->setHardwareName("Ethernet");
243 else if ((flags & IFF_POINTOPOINT) == IFF_POINTOPOINT) 244 else if ((flags & IFF_POINTOPOINT) == IFF_POINTOPOINT)
244 i->setHardwareName("Point to Point"); 245 i->setHardwareName("Point to Point");
245 else if ((flags & IFF_MULTICAST) == IFF_MULTICAST) 246 else if ((flags & IFF_MULTICAST) == IFF_MULTICAST)
246 i->setHardwareName("Multicast"); 247 i->setHardwareName("Multicast");
247 else if ((flags & IFF_LOOPBACK) == IFF_LOOPBACK) 248 else if ((flags & IFF_LOOPBACK) == IFF_LOOPBACK)
248 i->setHardwareName("Loopback"); 249 i->setHardwareName("Loopback");
249 else 250 else
250 i->setHardwareName("Unknown"); 251 i->setHardwareName("Unknown");
251 252
252 owarn << "Adding interface " << ifr.ifr_name << " to interfaceNames\n" << oendl; 253 owarn << "Adding interface " << ifr.ifr_name << " to interfaceNames\n" << oendl;
253 interfaceNames.insert(i->getInterfaceName(), i); 254 interfaceNames.insert(i->getInterfaceName(), i);
254 updateInterface(i); 255 updateInterface(i);
255 connect(i, SIGNAL(updateInterface(Interface*)), 256 connect(i, SIGNAL(updateInterface(Interface*)),
256 this, SLOT(updateInterface(Interface*))); 257 this, SLOT(updateInterface(Interface*)));
257 } 258 }
258 // now lets ask the plugins too ;) 259 // now lets ask the plugins too ;)
259 QMap<Module*, QLibrary*>::Iterator it; 260 QMap<Module*, QLibrary*>::Iterator it;
260 QList<Interface> ilist; 261 QList<Interface> ilist;
261 for( it = libraries.begin(); it != libraries.end(); ++it ) 262 for( it = libraries.begin(); it != libraries.end(); ++it )
262 { 263 {
263 if(it.key()) 264 if(it.key())
@@ -671,115 +672,117 @@ void MainWindowImp::changeProfile()
671 // Go through them one by one 672 // Go through them one by one
672 QMap<Interface*, QListViewItem*>::Iterator it; 673 QMap<Interface*, QListViewItem*>::Iterator it;
673 for( it = items.begin(); it != items.end(); ++it ) 674 for( it = items.begin(); it != items.end(); ++it )
674 { 675 {
675 if(it.key()->getStatus() == true) 676 if(it.key()->getStatus() == true)
676 it.key()->restart(); 677 it.key()->restart();
677 } 678 }
678 } 679 }
679 } 680 }
680 // TODO change the profile in the modules 681 // TODO change the profile in the modules
681} 682}
682 683
683 684
684void MainWindowImp::makeChannel() 685void MainWindowImp::makeChannel()
685{ 686{
686 channel = new QCopChannel( "QPE/Application/networksettings", this ); 687 channel = new QCopChannel( "QPE/Application/networksettings", this );
687 connect( channel, SIGNAL(received(const QCString&,const QByteArray&)), 688 connect( channel, SIGNAL(received(const QCString&,const QByteArray&)),
688 this, SLOT(receive(const QCString&,const QByteArray&)) ); 689 this, SLOT(receive(const QCString&,const QByteArray&)) );
689} 690}
690 691
691void MainWindowImp::receive(const QCString &msg, const QByteArray &arg) 692void MainWindowImp::receive(const QCString &msg, const QByteArray &arg)
692{ 693{
693 bool found = false; 694 bool found = false;
694 odebug << "MainWindowImp::receive QCop msg >"+msg+"<" << oendl; 695 odebug << "MainWindowImp::receive QCop msg >"+msg+"<" << oendl;
695 if (msg == "raise") 696 if (msg == "raise")
696 { 697 {
697 raise(); 698 raise();
698 return; 699 return;
699 } 700 }
700 701
701 QString dest = msg.left(msg.find("(")); 702 QString dest = msg.left(msg.find("("));
702 QCString param = msg.right(msg.length() - msg.find("(") - 1); 703 QCString param = msg.right(msg.length() - msg.find("(") - 1);
703 param = param.left( param.length() - 1 ); 704 param = param.left( param.length() - 1 );
704 odebug << "dest >" << dest.latin1() << "< param >"+param+"<" << oendl; 705 odebug << "dest >" << dest.latin1() << "< param >"+param+"<" << oendl;
705 706
706 QMap<Module*, QLibrary*>::Iterator it; 707 QMap<Module*, QLibrary*>::Iterator it;
707 for( it = libraries.begin(); it != libraries.end(); ++it ) 708 for( it = libraries.begin(); it != libraries.end(); ++it )
708 { 709 {
709 odebug << "plugin >" << it.key()->type().latin1() << "<" << oendl; 710 odebug << "plugin >" << it.key()->type().latin1() << "<" << oendl;
710 if(it.key()->type() == dest) 711 if(it.key()->type() == dest)
711 { 712 {
712 it.key()->receive( param, arg ); 713 it.key()->receive( param, arg );
713 found = true; 714 found = true;
714 } 715 }
715 } 716 }
716 717
717 718
718 if (found) QPEApplication::setKeepRunning(); 719 if (found) QPEApplication::setKeepRunning();
719 else odebug << "Huh what do ya want" << oendl; 720 else odebug << "Huh what do ya want" << oendl;
720} 721}
721 722
722void MainWindowImp::setHostname() 723void MainWindowImp::setHostname()
723{ 724{
724 static QRegExp filter("[^A-Za-z0-9_\\-\\.]"); 725 static QRegExp filter("[^A-Za-z0-9_\\-\\.]");
725 if (filter.match(m_Nameinput->text())!=-1) { 726 if (filter.match(m_Nameinput->text())!=-1) {
726 odebug << "Wrong hostname" << oendl; 727 odebug << "Wrong hostname" << oendl;
727 QMessageBox::critical(0, tr("Sorry"), tr("This is a wrong name.<br>Please use A-Z, a-z, _, - or a single dot.")); 728 QMessageBox::critical(0, tr("Sorry"), tr("This is a wrong name.<br>Please use A-Z, a-z, _, - or a single dot."));
728 return; 729 return;
729 } 730 }
730 731
731 OProcess h; 732 OProcess h;
732 _procTemp=""; 733 _procTemp="";
733 h << "hostname" << m_Nameinput->text(); 734 h << "hostname" << m_Nameinput->text();
734 connect(&h,SIGNAL(receivedStderr(Opie::Core::OProcess*,char*,int)),this,SLOT(slotHostname(Opie::Core::OProcess*,char*,int))); 735 connect(&h,SIGNAL(receivedStderr(Opie::Core::OProcess*,char*,int)),this,SLOT(slotHostname(Opie::Core::OProcess*,char*,int)));
735 h.start(OProcess::Block,OProcess::Stderr); 736 if (!h.start(OProcess::Block,OProcess::Stderr))
737 owarn << "Failed execution of 'hostname'. Are the paths correct?" << oendl;
736 odebug << "Got " << _procTemp << " - " << h.exitStatus() << oendl; 738 odebug << "Got " << _procTemp << " - " << h.exitStatus() << oendl;
737 if (h.exitStatus()!=0) { 739 if (h.exitStatus()!=0) {
738 QMessageBox::critical(0, tr("Sorry"), QString(tr("Could not set name.\n%1")).arg(_procTemp.stripWhiteSpace())); 740 QMessageBox::critical(0, tr("Sorry"), QString(tr("Could not set name.\n%1")).arg(_procTemp.stripWhiteSpace()));
739 return; 741 return;
740 } 742 }
741 _procTemp=""; 743 _procTemp="";
742 744
743 QFile f(_HOSTFILE); 745 QFile f(_HOSTFILE);
744 if (f.open(IO_Truncate|IO_WriteOnly)) 746 if (f.open(IO_Truncate|IO_WriteOnly))
745 { 747 {
746 QTextStream s(&f); 748 QTextStream s(&f);
747 s << m_Nameinput->text(); 749 s << m_Nameinput->text();
748 } else { 750 } else {
749 QMessageBox::critical(0, tr("Sorry"), tr("Could not save name.")); 751 QMessageBox::critical(0, tr("Sorry"), tr("Could not save name."));
750 return; 752 return;
751 } 753 }
752 754
753 f.close(); 755 f.close();
754 f.setName(_IRDANAME); 756 f.setName(_IRDANAME);
755 if (f.open(IO_WriteOnly)) 757 if (f.open(IO_WriteOnly))
756 { 758 {
757 QTextStream s(&f); 759 QTextStream s(&f);
758 s << m_Nameinput->text(); 760 s << m_Nameinput->text();
759 } else { 761 } else {
760 QMessageBox::critical(0, tr("Sorry"), tr("Could not set infrared name.")); 762 QMessageBox::critical(0, tr("Sorry"), tr("Could not set infrared name."));
761 } 763 }
762} 764}
763 765
764void MainWindowImp::initHostname() 766void MainWindowImp::initHostname()
765{ 767{
766 OProcess h; 768 OProcess h;
767 _procTemp=""; 769 _procTemp="";
768 770
769 h << "hostname"; 771 h << "hostname";
770 connect(&h,SIGNAL(receivedStdout(Opie::Core::OProcess*,char*,int)),this,SLOT(slotHostname(Opie::Core::OProcess*,char*,int))); 772 connect(&h,SIGNAL(receivedStdout(Opie::Core::OProcess*,char*,int)),this,SLOT(slotHostname(Opie::Core::OProcess*,char*,int)));
771 h.start(OProcess::Block,OProcess::AllOutput); 773 if (!h.start(OProcess::Block,OProcess::AllOutput))
774 owarn << "Could not execute 'hostname'. Are the paths correct?" oendl;
772 odebug << "Got " << _procTemp <<oendl; 775 odebug << "Got " << _procTemp <<oendl;
773 m_Nameinput->setText(_procTemp.stripWhiteSpace()); 776 m_Nameinput->setText(_procTemp.stripWhiteSpace());
774 _procTemp=""; 777 _procTemp="";
775} 778}
776 779
777void MainWindowImp::slotHostname(Opie::Core::OProcess */*proc*/, char *buffer, int buflen) 780void MainWindowImp::slotHostname(Opie::Core::OProcess * /*proc*/, char *buffer, int buflen)
778{ 781{
779 if (buflen < 1 || buffer==0) return; 782 if (buflen < 1 || buffer==0) return;
780 char*_t = new char[buflen+1]; 783 char*_t = new char[buflen+1];
781 ::memset(_t,0,buflen+1); 784 ::memset(_t,0,buflen+1);
782 ::memcpy(_t,buffer,buflen); 785 ::memcpy(_t,buffer,buflen);
783 _procTemp+=_t; 786 _procTemp+=_t;
784 delete[]_t; 787 delete[]_t;
785} 788}
diff --git a/noncore/settings/networksettings/ppp/modem.cpp b/noncore/settings/networksettings/ppp/modem.cpp
index 7b2e2a3..17ada9b 100644
--- a/noncore/settings/networksettings/ppp/modem.cpp
+++ b/noncore/settings/networksettings/ppp/modem.cpp
@@ -707,130 +707,132 @@ const char* Modem::authFile(Auth method, int version) {
707 return CHAP_AUTH_FILE; 707 return CHAP_AUTH_FILE;
708 break; 708 break;
709 case CHAP|New: 709 case CHAP|New:
710 return CHAP_AUTH_FILE".new"; 710 return CHAP_AUTH_FILE".new";
711 break; 711 break;
712 case CHAP|Old: 712 case CHAP|Old:
713 return CHAP_AUTH_FILE".old"; 713 return CHAP_AUTH_FILE".old";
714 break; 714 break;
715 default: 715 default:
716 return 0L; 716 return 0L;
717 } 717 }
718} 718}
719 719
720 720
721bool Modem::createAuthFile(Auth method, const char *username, const char *password) { 721bool Modem::createAuthFile(Auth method, const char *username, const char *password) {
722 const char *authfile, *oldName, *newName; 722 const char *authfile, *oldName, *newName;
723 char line[100]; 723 char line[100];
724 char regexp[2*MaxStrLen+30]; 724 char regexp[2*MaxStrLen+30];
725 regex_t preg; 725 regex_t preg;
726 726
727 if(!(authfile = authFile(method))) 727 if(!(authfile = authFile(method)))
728 return false; 728 return false;
729 729
730 if(!(newName = authFile(method, New))) 730 if(!(newName = authFile(method, New)))
731 return false; 731 return false;
732 732
733 // look for username, "username" or 'username' 733 // look for username, "username" or 'username'
734 // if you modify this RE you have to adapt regexp's size above 734 // if you modify this RE you have to adapt regexp's size above
735 snprintf(regexp, sizeof(regexp), "^[ \t]*%s[ \t]\\|^[ \t]*[\"\']%s[\"\']", 735 snprintf(regexp, sizeof(regexp), "^[ \t]*%s[ \t]\\|^[ \t]*[\"\']%s[\"\']",
736 username,username); 736 username,username);
737 MY_ASSERT(regcomp(&preg, regexp, 0) == 0); 737 MY_ASSERT(regcomp(&preg, regexp, 0) == 0);
738 738
739 // copy to new file pap- or chap-secrets 739 // copy to new file pap- or chap-secrets
740 int old_umask = umask(0077); 740 int old_umask = umask(0077);
741 FILE *fout = fopen(newName, "w"); 741 FILE *fout = fopen(newName, "w");
742 if(fout) { 742 if(fout) {
743 // copy old file 743 // copy old file
744 FILE *fin = fopen(authfile, "r"); 744 FILE *fin = fopen(authfile, "r");
745 if(fin) { 745 if(fin) {
746 while(fgets(line, sizeof(line), fin)) { 746 while(fgets(line, sizeof(line), fin)) {
747 if(regexec(&preg, line, 0, 0L, 0) == 0) 747 if(regexec(&preg, line, 0, 0L, 0) == 0)
748 continue; 748 continue;
749 fputs(line, fout); 749 fputs(line, fout);
750 } 750 }
751 fclose(fin); 751 fclose(fin);
752 } 752 }
753 753
754 // append user/pass pair 754 // append user/pass pair
755 fprintf(fout, "\"%s\"\t*\t\"%s\"\n", username, password); 755 fprintf(fout, "\"%s\"\t*\t\"%s\"\n", username, password);
756 fclose(fout); 756 fclose(fout);
757 } 757 }
758 758
759 // restore umask 759 // restore umask
760 umask(old_umask); 760 umask(old_umask);
761 761
762 // free memory allocated by regcomp 762 // free memory allocated by regcomp
763 regfree(&preg); 763 regfree(&preg);
764 764
765 if(!(oldName = authFile(method, Old))) 765 if(!(oldName = authFile(method, Old)))
766 return false; 766 return false;
767 767
768 // delete old file if any 768 // delete old file if any
769 unlink(oldName); 769 unlink(oldName);
770 770
771 rename(authfile, oldName); 771 if (rename(authfile, oldName) == -1)
772 rename(newName, authfile); 772 return false;
773 if (rename(newName, authfile) == -1)
774 return false;
773 775
774 return true; 776 return true;
775} 777}
776 778
777 779
778bool Modem::removeAuthFile(Auth method) { 780bool Modem::removeAuthFile(Auth method) {
779 const char *authfile, *oldName; 781 const char *authfile, *oldName;
780 782
781 if(!(authfile = authFile(method))) 783 if(!(authfile = authFile(method)))
782 return false; 784 return false;
783 if(!(oldName = authFile(method, Old))) 785 if(!(oldName = authFile(method, Old)))
784 return false; 786 return false;
785 787
786 if(access(oldName, F_OK) == 0) { 788 if(access(oldName, F_OK) == 0) {
787 unlink(authfile); 789 unlink(authfile);
788 return (rename(oldName, authfile) == 0); 790 return (rename(oldName, authfile) == 0);
789 } else 791 } else
790 return false; 792 return false;
791} 793}
792 794
793 795
794bool Modem::setSecret(int method, const char* name, const char* password) 796bool Modem::setSecret(int method, const char* name, const char* password)
795{ 797{
796 798
797 Auth auth; 799 Auth auth;
798 if(method == AUTH_PAPCHAP) 800 if(method == AUTH_PAPCHAP)
799 return setSecret(AUTH_PAP, name, password) && 801 return setSecret(AUTH_PAP, name, password) &&
800 setSecret(AUTH_CHAP, name, password); 802 setSecret(AUTH_CHAP, name, password);
801 803
802 switch(method) { 804 switch(method) {
803 case AUTH_PAP: 805 case AUTH_PAP:
804 auth = Modem::PAP; 806 auth = Modem::PAP;
805 break; 807 break;
806 case AUTH_CHAP: 808 case AUTH_CHAP:
807 auth = Modem::CHAP; 809 auth = Modem::CHAP;
808 break; 810 break;
809 default: 811 default:
810 return false; 812 return false;
811 } 813 }
812 814
813 return createAuthFile(auth, name, password); 815 return createAuthFile(auth, name, password);
814 816
815} 817}
816 818
817bool Modem::removeSecret(int method) 819bool Modem::removeSecret(int method)
818{ 820{
819 Auth auth; 821 Auth auth;
820 822
821 switch(method) { 823 switch(method) {
822 case AUTH_PAP: 824 case AUTH_PAP:
823 auth = Modem::PAP; 825 auth = Modem::PAP;
824 break; 826 break;
825 case AUTH_CHAP: 827 case AUTH_CHAP:
826 auth = Modem::CHAP; 828 auth = Modem::CHAP;
827 break; 829 break;
828 default: 830 default:
829 return false; 831 return false;
830 } 832 }
831 return removeAuthFile( auth ); 833 return removeAuthFile( auth );
832} 834}
833 835
834int checkForInterface() 836int checkForInterface()
835{ 837{
836// I don't know if Linux needs more initialization to get the ioctl to 838// I don't know if Linux needs more initialization to get the ioctl to