-rw-r--r-- | noncore/apps/opie-gutenbrowser/LibraryDialog.cpp | 88 | ||||
-rw-r--r-- | noncore/apps/opie-gutenbrowser/openetext.cpp | 174 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/lib.cpp | 30 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/om3u.cpp | 141 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/threadutil.cpp | 17 | ||||
-rw-r--r-- | noncore/net/opiestumbler/opiestumbler.cpp | 3 | ||||
-rw-r--r-- | noncore/settings/networksettings/mainwindow/mainwindowimp.cpp | 11 | ||||
-rw-r--r-- | noncore/settings/networksettings/ppp/modem.cpp | 6 |
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,119 +1,119 @@ /*************************************************************************** // LibraryDialog.cpp - description // ------------------- // begin : Sat Aug 19 2000 // copyright : (C) 2000 - 2004 by llornkcor // email : ljp@llornkcor.com // ***************************************************/ // /*************************************************************************** // * This program is free software; you can redistribute it and/or modify * // * it under the terms of the GNU General Public License as published by * // * the Free Software Foundation; either version 2 of the License, or * // * (at your option) any later version. * // ***************************************************************************/ //ftp://ibiblio.org/pub/docs/books/gutenberg/GUTINDEX.ALL #include "LibraryDialog.h" #include "output.h" /* OPIE */ #include <qpe/applnk.h> #include <qpe/qpeapplication.h> #include <qpe/qpedialog.h> -//#include <opie2///odebug.h> +#include <opie2/odebug.h> /* QT */ #include <qpushbutton.h> #include <qmultilineedit.h> //#include <qlayout.h> /* STD */ #include <unistd.h> #include <stdio.h> #include <stdlib.h> /* * The dialog will by default be modeless, unless you set 'modal' to * true to construct a modal dialog. */ LibraryDialog::LibraryDialog( QWidget* parent, const char* name , bool /*modal*/, WFlags fl ) : QDialog( parent, name, true/* modal*/, fl ) { if ( !name ) setName( "LibraryDialog" ); indexLoaded=false; initDialog(); // this->setMaximumWidth(240); index = "GUTINDEX.ALL"; local_library = (QDir::homeDirPath ()) +"/Applications/gutenbrowser/"; local_index = local_library + index; QString iniFile ; iniFile = local_library + "/gutenbrowserrc"; new_index = local_library + "/PGWHOLE.TXT"; old_index = local_index; // iniFile = local_library+"gutenbrowserrc"; // new_index = local_library + "PGWHOLE.TXT"; // old_index = local_library + "GUTINDEX.ALL"; Config config("Gutenbrowser"); config.setGroup( "HttpServer" ); proxy_http = config.readEntry("Preferred", "http://sailor.gutenbook.org"); config.setGroup( "FTPsite" ); ftp_host = config.readEntry("SiteName", "sailor.gutenberg.org"); //odebug << "Library Dialog: ftp_host is "+ftp_host << oendl; // ftp_host=ftp_host.right(ftp_host.length()-(ftp_host.find(") ",0,true)+1) ); // ftp_host=ftp_host.stripWhiteSpace(); ftp_base_dir= config.readEntry("base", "/pub/gutenberg"); i_binary = 0; config.setGroup("SortAuth"); if( config.readEntry("authSort", "false") == "true") authBox->setChecked(true); config.setGroup("General"); downDir = config.readEntry( "DownloadDirectory",local_library); //odebug << "downDir is "+downDir << oendl; newindexLib.setName( old_index); indexLib.setName( old_index); new QPEDialogListener(this); QTimer::singleShot( 1000, this, SLOT( FindLibrary()) ); } LibraryDialog::~LibraryDialog() { } void LibraryDialog::clearItems() { ListView1->clear(); ListView2->clear(); ListView3->clear(); ListView4->clear(); ListView5->clear(); } /*This groks using PGWHOLE.TXT */ void LibraryDialog::Newlibrary() { clearItems(); #ifndef Q_WS_QWS //sorry embedded gutenbrowser cant use zip files ////odebug << "Opening new library index " << newindexLib << "" << oendl; if ( newindexLib.open( IO_ReadOnly) ) { setCaption( tr( "Library Index - using master pg index." ) );// file opened successfully QTextStream indexStream( &newindexLib ); QString indexLine; while ( !indexStream.atEnd() ) { // until end of file.. indexLine = indexStream.readLine(); if ( ( indexLine.mid(4,4)).toInt() && !( indexLine.left(3)).toInt()) { year = indexLine.mid(4,4); file = indexLine.mid( indexLine.find( "[", 0, true )+1, 12 ); number = indexLine.mid( indexLine.find( "]", 0, true ) +1, indexLine.find( " ", 0, true )+1 ); if( year.toInt() < 1984) number = number.left( number.length() -1 ); title = indexLine.mid( indexLine.find(" ", 26, true), indexLine.length() ); @@ -365,241 +365,244 @@ void LibraryDialog::addItems() /* selected one etext*/ void LibraryDialog::select_title( QListViewItem * item) { if(item != NULL) { i++; int index = tabWidget->currentPageIndex(); DlglistItemTitle = item->text(0); DlglistItemYear = item->text(2); DlglistItemFile = item->text(3); switch (index) { case 0: { ListView1->clearSelection(); } break; case 1: { ListView2->clearSelection(); } break; case 2: { ListView3->clearSelection(); } break; case 3: { ListView4->clearSelection(); } break; case 4: { ListView5->clearSelection(); } break; }; } if(DlglistItemTitle.length() > 2) { item = 0; // todo check for connection here bool ok = false; qDebug(DlglistItemFile); if( DlglistItemFile.toInt() > 10000 ) { // new directory sturcture if( download_newEtext()) ok = true; } else { if(download_Etext()) ok = true; } if(ok) { if(checkBox->isChecked () ) accept(); } } } bool LibraryDialog::download_newEtext() { // ftp method QString fileName = DlglistItemFile; QString directory; int stringlength = DlglistItemFile.length(); for(i = 0; i < stringlength - 1; i++ ) { directory += "/"+ DlglistItemFile[i]; } directory += "/" + DlglistItemFile; // qWarning(directory); Config cfg("Gutenbrowser"); cfg.setGroup("FTPsite"); ftp_host = cfg.readEntry("SiteName", "sailor.gutenberg.org"); ftp_base_dir = cfg.readEntry("base", "/pub/gutenberg"); if( ftp_base_dir.find("=",0,true) ) ftp_base_dir.remove( ftp_base_dir.find("=",0,true),1); QString dir = ftp_base_dir + directory; QString outputFile = local_library + ".guten_temp"; QString file = fileName + ".txt"; QStringList networkList; networkList.append((const char *)ftp_host); //host networkList.append((const char *)dir); //ftp base directory networkList.append((const char *)outputFile); //output filepath networkList.append((const char *)file); //filename getEtext( networkList); return true; } bool LibraryDialog::getEtext(const QStringList &networkList) { - NetworkDialog *NetworkDlg; - NetworkDlg = new NetworkDialog( this,"Network Protocol Dialog", true, 0, networkList); + NetworkDialog *NetworkDlg; + NetworkDlg = new NetworkDialog( this,"Network Protocol Dialog", true, 0, networkList); -// use new, improved, *INSTANT* network-dialog-file-getterer - if( NetworkDlg->exec() != 0 ) { - File_Name = NetworkDlg->localFileName; + // use new, improved, *INSTANT* network-dialog-file-getterer + if( NetworkDlg->exec() != 0 ) { + File_Name = NetworkDlg->localFileName; - qDebug("Just downloaded " + NetworkDlg->localFileName); + qDebug("Just downloaded " + NetworkDlg->localFileName); - if(NetworkDlg->successDownload) { - //odebug << "Filename is "+File_Name << oendl; - if(File_Name.right(4) == ".txt") { - QString s_fileName = File_Name; - s_fileName.replace( s_fileName.length() - 3, 3, "gtn"); - // s_fileName.replace( s_fileName.length()-3,3,"etx"); - rename( File_Name.latin1(), s_fileName.latin1()); - File_Name = s_fileName; + if(NetworkDlg->successDownload) { + //odebug << "Filename is "+File_Name << oendl; + if(File_Name.right(4) == ".txt") { + QString s_fileName = File_Name; + s_fileName.replace( s_fileName.length() - 3, 3, "gtn"); + if (rename( File_Name.latin1(), s_fileName.latin1()) == 1) { + owarn << "Failed to rename " << File_Name.latin1() << " to " + << s_fileName.latin1() << oendl; + return false; + } - //odebug << "Filename is now "+File_Name << oendl; + File_Name = s_fileName; - } - if(File_Name.length() > 5 ) { - setTitle(); - QFileInfo fi(File_Name); - QString name_file = fi.fileName(); - name_file = name_file.left( name_file.length() - 4); - - //odebug << "Setting doclink" << oendl; - DocLnk lnk; - //odebug << "name is "+name_file << oendl; - lnk.setName(name_file); //sets file name - //odebug << "Title is "+DlglistItemTitle << oendl; - lnk.setComment(DlglistItemTitle); + //odebug << "Filename is now "+File_Name << oendl; - //odebug << "Filename is "+File_Name << oendl; - lnk.setFile(File_Name); //sets File property - lnk.setType("guten/plain");// hey is this a REGISTERED mime type?!?!? ;D - lnk.setExec(File_Name); - lnk.setIcon("gutenbrowser/Gutenbrowser"); - if(!lnk.writeLink()) { - //odebug << "Writing doclink did not work" << oendl; - } else { } - } else - QMessageBox::message("Note","<p>There was an error with the file</p>"); - } - } + if(File_Name.length() > 5 ) { + setTitle(); + QFileInfo fi(File_Name); + QString name_file = fi.fileName(); + name_file = name_file.left( name_file.length() - 4); + + //odebug << "Setting doclink" << oendl; + DocLnk lnk; + //odebug << "name is "+name_file << oendl; + lnk.setName(name_file); //sets file name + //odebug << "Title is "+DlglistItemTitle << oendl; + lnk.setComment(DlglistItemTitle); + + //odebug << "Filename is "+File_Name << oendl; + lnk.setFile(File_Name); //sets File property + lnk.setType("guten/plain");// hey is this a REGISTERED mime type?!?!? ;D + lnk.setExec(File_Name); + lnk.setIcon("gutenbrowser/Gutenbrowser"); + if(!lnk.writeLink()) { + //odebug << "Writing doclink did not work" << oendl; + } + } else + QMessageBox::message("Note","<p>There was an error with the file</p>"); + } + } - return true; + return true; } bool LibraryDialog::download_Etext() { // ftp method // might have to use old gpl'd ftp for embedded!! Config cfg("Gutenbrowser"); cfg.setGroup("FTPsite"); ftp_host = cfg.readEntry("SiteName", "sailor.gutenberg.org"); ftp_base_dir = cfg.readEntry("base", "/pub/gutenberg"); qDebug( "about to network dialog"); QString NewlistItemNumber, NewlistItemYear, ls_result, result_line, s, dir, /*networkUrl, */outputFile; //////////////////// FIXME- if 'x' is part of real name.... NewlistItemFile = DlglistItemFile.left(DlglistItemFile.find(".xxx", 1, false)).left(DlglistItemFile.left(DlglistItemFile.find(".xxx", 1, false)).find("x", 1, false)); if( NewlistItemFile.find( DlglistItemFile.left(4) ,0,true) ==-1 ) { NewlistItemFile.replace( 0,4, DlglistItemFile.left(4)); qDebug("NewlistItemFile is now " + NewlistItemFile); } NewlistItemYear = DlglistItemYear.right(2); int NewlistItemYear_Int = NewlistItemYear.toInt(0, 10); //odebug << NewlistItemYear << oendl; if (NewlistItemYear_Int < 91 && NewlistItemYear_Int > 70) { NewlistItemYear = "90"; } Edir ="etext" +NewlistItemYear; dir = ftp_base_dir + "/etext" + NewlistItemYear + "/"; if( ftp_base_dir.find("=",0,true) ) ftp_base_dir.remove( ftp_base_dir.find("=",0,true),1); // networkUrl = "ftp://"+ftp_host+dir; outputFile = local_library+".guten_temp"; qDebug( "Download file: " +NewlistItemFile); qDebug("Checking: " + ftp_host + " " + dir + " " + outputFile+" " + NewlistItemFile); QStringList networkList; networkList.append((const char *)ftp_host); //host networkList.append((const char *)dir); //ftp base directory networkList.append((const char *)outputFile); //output filepath networkList.append((const char *)NewlistItemFile); //filename //<< (char *)ftp_host << (char *)dir << (char *)outputFile << (char *)NewlistItemFile; getEtext( networkList); return true; } bool LibraryDialog::httpDownload() {// httpDownload #ifndef Q_WS_QWS Config config("Gutenbrowser"); config.setGroup( "Browser" ); QString brow = config.readEntry("Preferred", ""); QString file_name = "./.guten_temp"; // config.setGroup( "HttpServer" ); // QString s_http = config.readEntry("Preferred", "http://sailor.gutenbook.org"); QString httpName = proxy_http + "/"+Edir; // progressBar->setProgress( i); i++; if ( brow != "Konq") { /////////// use lynx // QString cmd = "lynx -source " + httpName +" | cat >> " + file_name; // system(cmd); } else { //////////// use KFM // KFM::download( httpName, file_name); } i++; QFile tmp( file_name); QString str; if (tmp.open(IO_ReadOnly)) { QTextStream t( &tmp ); // use a text stream while ( !t.eof()) { QString s = t.readLine(); if (s.contains( NewlistItemFile, false) && (s.contains(".txt")) ) { str = s.mid( s.find( ".txt\">"+NewlistItemFile, 0, true)+6, (s.find( ".txt</A>", 0, true) + 4) - ( s.find( ".txt\">"+NewlistItemFile, 0, true)+6 ) ); httpName += "/" + str; } } //end of while loop } tmp.close(); m_getFilePath = local_library + str; i++; if ( brow != "KFM"){ ///////// use lynx QString cmd = "lynx -source " + httpName +" | cat >> " + m_getFilePath; // QMessageBox::message("Error", cmd); system(cmd); } else { ////////// use KFM // KFM::download( httpName, m_getFilePath); @@ -608,193 +611,192 @@ bool LibraryDialog::httpDownload() #endif return false; } void LibraryDialog::cancelIt() { saveConfig(); DlglistItemNumber = ""; this->reject(); } bool LibraryDialog::setTitle() { Config config("Gutenbrowser"); //odebug << "setting title" << oendl; //odebug << DlglistItemTitle << oendl; if( DlglistItemTitle.find("[",0,true) != -1) DlglistItemTitle.replace(DlglistItemTitle.find("[",0,true),1, "(" ); if( DlglistItemTitle.find("]",0,true) !=-1) DlglistItemTitle.replace(DlglistItemTitle.find("]",0,true),1, ")" ); //odebug << "Title being set is "+DlglistItemTitle << oendl; int test = 0; QString ramble, temp; config.setGroup("Files"); QString s_numofFiles = config.readEntry("NumberOfFiles", "0" ); int i_numofFiles = s_numofFiles.toInt(); for ( int i = 0; i <= i_numofFiles; i++){ temp.setNum( i); ramble = config.readEntry( temp, "" ); if( strcmp( ramble, File_Name) == 0){ test = 1; } } if(test == 0 ) { config.setGroup("Files"); config.writeEntry( "NumberOfFiles", i_numofFiles +1 ); QString interger; interger.setNum( i_numofFiles +1); config.writeEntry( interger, File_Name); config.setGroup( "Titles" ); config.writeEntry( File_Name, DlglistItemTitle); } test = 0; return true; } void LibraryDialog::saveConfig() { Config config("Gutenbrowser"); if( httpBox->isChecked() == true) { checked = 1; config.setGroup( "Proxy" ); config.writeEntry("IsChecked", "true"); } else { checked = 0; config.setGroup( "Proxy" ); config.writeEntry("IsChecked", "false"); } if (authBox->isChecked() == true) { config.setGroup("SortAuth"); config.writeEntry("authSort", "true"); } else { config.setGroup("SortAuth"); config.writeEntry("authSort", "false"); } // config.write(); } /* searches library index for user word*/ void LibraryDialog::onButtonSearch() { ListView1->clearSelection(); ListView2->clearSelection(); ListView3->clearSelection(); ListView4->clearSelection(); ListView5->clearSelection(); int curTab = tabWidget->currentPageIndex(); SearchDialog* searchDlg; // if( resultsList) searchDlg = new SearchDialog( this, "Library Search", true); searchDlg->setCaption( tr( "Library Search" ) ); searchDlg->setLabel( "- author or title"); QString resultString; int i_berger = 0; if( searchDlg->exec() != 0 ) { QString searcherStr = searchDlg->get_text(); - int fluff = 0; bool cS; if( searchDlg->caseSensitiveCheckBox->isChecked()) cS = true; //case sensitive else cS = false; etext etextStruct; QValueList<etext>::Iterator it; for( it = etextLibrary.begin(); it != etextLibrary.end(); ++it ) { QString tempTitle = (*it).title; QString tempAuthor = (*it).author; QString tempFile = (*it).file; QString tempYear = (*it).year; if(tempTitle.find( searcherStr, 0, cS) != -1 || tempAuthor.find( searcherStr, 0, cS) != -1) { qWarning(tempTitle); Searchlist.append( tempTitle + " : " + tempYear + " : " + tempFile); } } tabWidget->setCurrentPage( curTab); Searchlist.sort(); SearchResultsDlg* SearchResultsDialog; SearchResultsDialog = new SearchResultsDlg( searchDlg, "Results Dialog", true, 0 , Searchlist); SearchResultsDialog->showMaximized(); if( SearchResultsDialog->exec() != 0) { texter = SearchResultsDialog->selText; // //odebug << texter << oendl; resultLs = SearchResultsDialog->resultsList; i_berger = 1; } else { resultLs.clear(); } Searchlist.clear(); QString tester; for ( QStringList::Iterator it = resultLs.begin(); it != resultLs.end(); ++it ) { texter.sprintf("%s \n",(*it).latin1()); // //odebug << texter << oendl; if( tester!=texter) parseSearchResults( texter); tester = texter; } if(searchDlg) delete searchDlg; } if(checkBox->isChecked() ) { accept(); } else { setActiveWindow(); } } /* splits the result string and calls download for the current search result*/ void LibraryDialog::parseSearchResults( QString resultStr) { int stringLeng = resultStr.length(); QString my; my.setNum( stringLeng, 10); if( resultStr.length() > 2 && resultStr.length() < 130) { QStringList token = QStringList::split(" : ", resultStr); DlglistItemTitle = token[0]; DlglistItemTitle = DlglistItemTitle.stripWhiteSpace(); DlglistItemYear = token[1]; DlglistItemYear = DlglistItemYear.stripWhiteSpace(); DlglistItemFile = token[2]; DlglistItemFile = DlglistItemFile.stripWhiteSpace(); // qWarning(DlglistItemYear); if(DlglistItemFile.left(1) == "/") DlglistItemFile = DlglistItemFile.right( DlglistItemFile.length() - 1); if( DlglistItemFile.toInt() > 10000 || DlglistItemYear == "1980" ) { // new directory sturcture download_newEtext(); //) } else { download_Etext(); //) } } } void LibraryDialog::sortLists(int index) 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 @@ /*************************************************************************** openetext.cpp - description begin : Sat Dec 4 1999 begin : Tue Jul 25 2000 copyright : (C) 2000 -2004 by llornkcor email : ljp@llornkcor.com ***************************************************************************/ /*************************************************************************** * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * ***************************************************************************/ #include "gutenbrowser.h" #include "openetext.h" #include "editTitle.h" /* OPIE */ #include <opie2/ofiledialog.h> #include <opie2/odebug.h> #include <qpe/applnk.h> #include <qpe/config.h> #include <qpe/qpeapplication.h> using namespace Opie::Ui; /* QT */ #include <qtextstream.h> #include <qfileinfo.h> /* STD */ #if defined(_WS_WIN_) #include <windows.h> #else #include <unistd.h> #include <stdlib.h> #include <sys/stat.h> #endif OpenEtext::OpenEtext(QWidget *parent, QString name) : QDialog(parent,name,true) { local_library = (QDir::homeDirPath ()) +"/Applications/gutenbrowser/"; local_index=local_library+"GUTINDEX.ALL"; initDialog(); connect( QListBox_1, SIGNAL(selected ( int)),this, SLOT(select_title(int)) ); getTitles(); } OpenEtext::~OpenEtext() { } void OpenEtext::getTitles() { QListBox_1->clear(); Config config("Gutenbrowser"); config.setGroup( "Files" ); s_numofFiles = config.readEntry("NumberOfFiles", "0"); - QLabel_1->setText( tr( - s_numofFiles+" etexts in your library.")); + QLabel_1->setText( tr( s_numofFiles+" etexts in your library." ) ); int i_numofFiles = s_numofFiles.toInt(); for (int i = 1; i <= i_numofFiles+1; i++) { QString temp; temp.setNum(i); config.setGroup( "Files" ); QString ramble = config.readEntry(temp, "" ); config.setGroup( "Titles" ); title = config.readEntry(ramble, ""); if( !title.isEmpty()) { - QListBox_1->insertItem ( QPixmap( QPEApplication::qpeDir()+"pics/gutenbrowser/gutenbrowser_sm.png"), title, -1); + QListBox_1->insertItem ( QPixmap( + QPEApplication::qpeDir() + + "pics/gutenbrowser/gutenbrowser_sm.png" + ), + title, + -1); } } } /* opens selected title */ void OpenEtext::OpenTitle() { if( QListBox_1->currentItem() != -1) select_title( QListBox_1->currentItem() ); else { QString sMsg; sMsg = "You must select an Etext to open"; QMessageBox::message( "Error",sMsg); } } void OpenEtext::select_title(int index ) { OpenButton->setDown(TRUE); QString temp; temp.setNum( index + 1); const char * title; title = QListBox_1->text( index ); openFileTitle = title; Config config("Gutenbrowser"); config.setGroup( "Files" ); file = config.readEntry(temp, ""); OpenEtext::accept(); } -/* - This function imports already existing etexts into the local library list*/ +/*! + * This function imports already existing etexts into the local library list + */ void OpenEtext::open() { OpenFileButton->setDown(TRUE); title = ""; QString currDir=""; QString filer; QString name_file; QString local ; local = (QDir::homeDirPath () +"Applications/gutenbrowser"); QDir library( local); -// fileBrowser *browseForFiles; -// browseForFiles=new fileBrowser(this,"Browse for File", TRUE, 0, "guten/plain;text/plain"); -// // browseForFiles=new fileBrowser(this,"fileBrowser",TRUE,0, "*"); -// browseForFiles->setFileView( 0); -// browseForFiles->showMaximized(); -// browseForFiles->exec(); -// QString selFile= browseForFiles->selectedFileName; -// fileList=browseForFiles->fileList; Config cfg("Gutenbrowser"); cfg. setGroup ( "View" ); QString dir = cfg.readEntry("LastOpenDirectory", QPEApplication::documentDir()); QMap<QString, QStringList> map; map.insert(tr("All"), QStringList() ); QStringList text; text << "text/*"; map.insert(tr("Text"), text ); text << "*"; map.insert(tr("All"), text ); QString str = OFileDialog::getOpenFileName( 2, dir , QString::null, map); - if( !str.isEmpty() && QFile(str).exists() && !QFileInfo(str).isDir() ) { - filer = str; - - odebug << "Open file: "+str << oendl; - - // QStringList::ConstIterator f; -// QString fileTemp; -// for ( f = fileList.begin(); f != fileList.end(); f++ ) { -// fileTemp = *f; -// fileTemp.right( fileTemp.length()-5); -// fileName = fileTemp; -// if( !fileName.isEmpty() ){ -// filer = fileName; -// } else { //filename is empty -// // QString sMsg; -// // sMsg = "Error opening library filelist "+fileName; -// } - - if( filer.right(4) == ".txt" - || filer.right(4) == ".TXT" - || filer.right(4) == ".etx" - || filer.right(4) == ".ETX" - || filer.right(4) == ".etx" - || filer.right(4) == ".ETX" - || filer.right(4) == ".zip" - || filer.right(4) == ".ZIP" ) { + if( !str.isEmpty() && QFile(str).exists() && !QFileInfo(str).isDir() ) { + filer = str; + + odebug << "Open file: "+str << oendl; + + if( filer.right(4) == ".txt" || + filer.right(4) == ".TXT" || + filer.right(4) == ".etx" || + filer.right(4) == ".ETX" || + filer.right(4) == ".etx" || + filer.right(4) == ".ETX" || + filer.right(4) == ".zip" || + filer.right(4) == ".ZIP" ) + { QFileInfo zipFile( filer); QString s_fileName = zipFile.fileName(); QString cmd; - if( s_fileName.right(4) == ".zip") { // unzip that sucker.... + if( s_fileName.right(4) == ".zip") { // unzip the file s_fileName = s_fileName.left( s_fileName.length() - 4); if( chdir((const char*)local_library.latin1())!=0) - odebug << "chdir failed." << oendl; // QString cmd = "gunzip -d " + filer + " -d " + local_library; + odebug << "chdir failed." << oendl; cmd = "gunzip -S .zip " + filer; fileName = local_library + s_fileName + ".txt"; system( cmd); - } -// this renames the .txt to .etx!! - else /*if( s_fileName.right(4) == ".txt" || if( s_fileName.right(4) == ".TXT"))*/ { -// odebug << "Filename is "+fileName << oendl; + } else { // else rename .txt to .etx + // odebug << "Filename is "+fileName << oendl; s_fileName = fileName; - s_fileName.replace( s_fileName.length()-3,3,"gtn");// s_fileName.replace( s_fileName.length()-3,3,"etx"); - rename(fileName.latin1(),s_fileName.latin1()); + s_fileName.replace( s_fileName.length()-3,3,"gtn"); + if (rename(fileName.latin1(),s_fileName.latin1()) == -1) + owarn << "Rename of " << fileName.latin1() << " to " + << s_fileName.latin1() << " failed" << oendl; fileName = s_fileName; -// odebug << "Filename is now "+fileName << oendl; + // odebug << "Filename is now "+fileName << oendl; } } else - fileName = str; + fileName = str; FindTitle(fileName); QFileInfo fi( fileName); name_file = fi.fileName(); name_file = name_file.left(name_file.length() - 4); odebug << "Setting doclink" << oendl; DocLnk lnk; odebug << "name is " + name_file << oendl; lnk.setName(name_file); //sets file name odebug << "Title is "+title << oendl; lnk.setComment(title); QListBox_1->clear(); getTitles(); odebug << "Filename is "+fileName << oendl; lnk.setFile(fileName); //sets File property - lnk.setType("guten/plain");// hey is this a REGISTERED mime type?!?!? ;D + // @bug This is probably not a registered MIME type. Perhaps we should + // set a valid MIME type here instead. Or maybe register .etx as a + // Gutenberge etext? + lnk.setType("guten/plain"); lnk.setExec(fileName); lnk.setIcon("gutenbrowser/Gutenbrowser"); if(!lnk.writeLink()) odebug << "Writing doclink did not work" << oendl; } // end of for each file name.... - OpenFileButton->setDown(FALSE); + OpenFileButton->setDown(FALSE); } /* find the title in the config file */ bool OpenEtext::FindTitle( QString filename) { Config config("Gutenbrowser"); config.setGroup( "Files" ); QString s_numofFiles = config.readEntry("NumberOfFiles", "0"); int i_numofFiles = s_numofFiles.toInt(); QFileInfo fi(filename); name = fi.fileName(); odebug << "filename to open is " + name << oendl; QFile indexLib( filename); - bool findCheck = FALSE; - // int Titlenumber=0; + bool findCheck = FALSE; if ( indexLib.open( IO_ReadOnly) ) { - odebug << "file opened successfully" << oendl; + odebug << "file opened successfully" << oendl; QTextStream indexStream( &indexLib ); QString target = "Project Gutenberg Etext of"; QString target2 = "Project Gutenberg Etext"; QString target3 = "Project Gutenberg's Etext of"; QString target4 = "Project Gutenberg's Etext"; QString indexLine; while ( !indexStream.eof() ) { - // until end of file.. + // until end of file.. indexLine = indexStream.readLine(); if( indexLine.find(target, 0, TRUE) > -1 && !findCheck) {findCheck = TRUE; title = indexLine.mid( indexLine.find(target, 0, TRUE) + (target.length()) , indexLine.find("\r", 0, TRUE)); title = title.left( title.find( "*",0, TRUE)); title = title.stripWhiteSpace (); // odebug << "Found the title 1 and it is " << title << "" << oendl; -// QListBox_1->insertItem ( title); +// QListBox_1->insertItem ( title); } if( indexLine.find( target2, 0, TRUE) > -1 && !findCheck) { findCheck = TRUE; title = indexLine.mid( indexLine.find( target2, 0, TRUE ) + ( target2.length()) , indexLine.find("\r", 0, TRUE) ); title = title.left( title.find( "*",0, TRUE)); title = title.stripWhiteSpace (); -// odebug << "Found the title 2 and it is " << title << "" << oendl; -// QListBox_1->insertItem ( title); +// odebug << "Found the title 2 and it is " << title << "" << oendl; +// QListBox_1->insertItem ( title); } if( indexLine.find( target3, 0, TRUE) > -1 && !findCheck) { findCheck = TRUE; title = indexLine.mid( indexLine.find( target3, 0, TRUE) + ( target3.length()) , indexLine.find("\r", 0, TRUE)); title = title.left( title.find( "*",0, TRUE)); title = title.stripWhiteSpace (); // odebug << "Found the title 3 and it is " << title << "" << oendl; } if( indexLine.find( target4, 0, TRUE) > -1 && !findCheck) { findCheck = TRUE; title = indexLine.mid( indexLine.find( target4, 0, TRUE) + ( target4.length()) , indexLine.find("\r", 0, TRUE)); title = title.left( title.find( "*",0, TRUE)); title = title.stripWhiteSpace (); // odebug << "Found the title 4 and it is " << title << "" << oendl; } } //endof file indexLib.close(); if( !findCheck || title.length() < 2) { odebug << "Trying hard to find title from GUTINDEX.ALL" << oendl; title = titleFromLibrary( filename); findCheck = TRUE; } if ( checkConf() == false && findCheck == TRUE) { - config.setGroup( "Files"); config.writeEntry("NumberOfFiles",i_numofFiles + 1 ); QString interger; interger.setNum( i_numofFiles +1); config.writeEntry(interger, filename); config.setGroup( "Titles" ); for (int i = 1; i <= i_numofFiles; i++) { //find dup titles in config file QString temp; temp.setNum(i); config.setGroup( "Files" ); QString ramble = config.readEntry(temp, "" ); config.setGroup( "Titles" ); QString title1 = config.readEntry(ramble, ""); if(title1==title) title+="1"; i= i_numofFiles+1; } if(title.length()<3) { // odebug << "title is empty" << oendl; title="Unknown"; } config.writeEntry( filename,title); } } else { QString sMsg; sMsg = "Error opening library file: "+filename; printf( sMsg+"\n"); } return true; } QString OpenEtext::titleFromLibrary( QString fileName) { QFile indexLib( local_index); QString target; int find1 = fileName.findRev("/",-1,TRUE) + 1; int find2 = fileName.findRev(".gtn",-1,TRUE) - find1; - if(find2==-1-find1) - int find2 = fileName.findRev(".etx",-1,TRUE) - find1; - else if(find2==-1-find1) - int find2 = fileName.findRev(".txt",-1,TRUE) - find1; + if(find2== (-1-find1)) + find2 = fileName.findRev(".etx",-1,TRUE) - find1; + else if(find2==(-1-find1)) + find2 = fileName.findRev(".txt",-1,TRUE) - find1; target = fileName.mid( find1, find2 ); QString checker = target.right(1); bool ok; checker.toInt( &ok,10); if( ok) { target = target.left( target.length()-1); checker = target.right(1); ok = FALSE; checker.toInt( &ok,10); if( ok) { target = target.left( target.length()-1); } } if ( indexLib.open( IO_ReadOnly) ) { - // file opened successfully + // file opened successfully QTextStream indexStream( &indexLib ); QString indexLine; bool findCheck = FALSE; - while ( !indexStream.atEnd() ) { // until end of file.. + while ( !indexStream.atEnd() ) { // until end of file.. indexLine = indexStream.readLine(); if( indexLine.find( target,0,FALSE) > 0 ) { findCheck = TRUE; title = indexLine.mid( 9, 50); -// title = indexLine.mid( 26, indexLine.length() ); title = title.stripWhiteSpace (); // odebug << "Finally Found the title and it is\n " << title << "" << oendl; -// QListBox_1->insertItem ( title); +// QListBox_1->insertItem ( title); } } //end while loop } else - odebug << "Error opening library index "+ local_index << oendl; + odebug << "Error opening library index "+ local_index << oendl; return title; } bool OpenEtext::checkConf() { QString file = fileName; Config config("Gutenbrowser"); config.setGroup( "Files" ); QString s_numofFiles = config.readEntry("NumberOfFiles", "0" ); int i_numofFiles = s_numofFiles.toInt(); for (int i = 1; i <= i_numofFiles; i++) { QString temp; temp.setNum(i); config.setGroup( "Files"); QString ramble = config.readEntry(temp, "" ); if(ramble == file ) { return true; } } return false; } void OpenEtext::remove() { title_text = QListBox_1->text( QListBox_1->currentItem() ); title_text=title_text.stripWhiteSpace(); - QString msg ="<p>Do you really want to REMOVE\n" +title_text +"?\nThis will not delete the file.</P>"; - switch( QMessageBox::information( this, (tr("Remove Etext")), - (tr(msg)), - (tr("&Yes")), (tr("&Cancel")), 0 )){ + QString msg ="<p>Do you really want to REMOVE\n" + title_text + + "?\nThis will not delete the file.</P>"; + switch( QMessageBox::information( this, tr("Remove Etext"), + tr(msg), + tr("&Yes"), tr("&Cancel"), 0 ) ) + { case 0: // Yes clicked, removeSelection(); QListBox_1->clear(); getTitles(); break; - case 1: // Cancel - break; - }; + case 1: + default: + } } -/* - this removes selected title entry*/ +/*! + * This removes selected title entry + */ void OpenEtext::removeSelection() { Config config("Gutenbrowser"); config.setGroup( "Files" ); s_numofFiles = config.readEntry("NumberOfFiles", "0"); int rem=0; int i_numofFiles = s_numofFiles.toInt(); QString fileNum2; QString fileNum; for (int i = 1; i <= i_numofFiles; i++) { fileNum.setNum(i); config.setGroup( "Files" ); QString s_filename = config.readEntry(fileNum, "" ); config.setGroup( "Titles" ); QString file_title = config.readEntry( s_filename, ""); if(title_text == file_title) { rem=i; -//odebug << "file title to remove is "+file_title << oendl; + //odebug << "file title to remove is "+file_title << oendl; selFile = s_filename; config.removeEntry( s_filename); //removes file=title } } config.setGroup( "Files" ); for(int fg = rem; fg < i_numofFiles ; fg++ ) { //this rewrites Files number entry fileNum.setNum(fg); fileNum2.setNum( fg + 1); QString s_filename2 = config.readEntry(fileNum2, "" ); if (!s_filename2.isEmpty()) { config.writeEntry(fileNum, s_filename2 ); } } config.writeEntry("NumberOfFiles", i_numofFiles - 1 ); config.removeEntry(fileNum2); -// remFile(); } -/* - removes file title name from list and config file*/ +/*! + * Removes file title name from list and config file + */ void OpenEtext::remFile() { Config config("Gutenbrowser"); config.setGroup( "Files" ); QString remFile; s_numofFiles = config.readEntry("NumberOfFiles", "0"); int i_numofFiles = s_numofFiles.toInt(); for (int i = 1; i <= i_numofFiles; i++) { QString fileNum; fileNum.setNum(i); QString s_filename = config.readEntry(fileNum, "" ); if( s_filename == selFile) { config.removeEntry(selFile); for(int fg = i_numofFiles - i; fg < i_numofFiles ; fg++ ) { //this rewrites Files number entry QString fileNum2; fileNum2.setNum( fg + 1); QString s_filename2 = config.readEntry(fileNum2, "" ); - if (!s_filename2.isEmpty()) { + if (!s_filename2.isEmpty()) config.writeEntry(fileNum, s_filename2 ); - } } } } config.writeEntry("NumberOfFiles", i_numofFiles - 1 ); config.removeEntry(s_numofFiles); QListBox_1->triggerUpdate(true); } -/* -sorts the list*/ +/*! + * Sorts the list + */ void OpenEtext::scan() { QListBox_1->sort(TRUE); QListBox_1->triggerUpdate(true); } void OpenEtext::editTitle() { int currentItem=QListBox_1->currentItem(); QString title_text = QListBox_1->text( currentItem); -//odebug << "Selected "+title_text << oendl; + //odebug << "Selected "+title_text << oendl; Config config("Gutenbrowser"); config.setGroup( "Files" ); s_numofFiles = config.readEntry("NumberOfFiles", "0"); int i_numofFiles = s_numofFiles.toInt(); QString fileNum; for (int i = 1; i <= i_numofFiles+1; i++) { fileNum.setNum(i); config.setGroup( "Files" ); QString s_filename = config.readEntry(fileNum, "" ); config.setGroup( "Titles" ); QString file_title = config.readEntry( s_filename, ""); -//odebug << "file_title is "+file_title << oendl; + //odebug << "file_title is "+file_title << oendl; if(title_text == file_title ) { selFile = s_filename; -//odebug << "Edit: "+ file_title << oendl; + //odebug << "Edit: "+ file_title << oendl; i=i_numofFiles+1; Edit_Title *titleEdit; titleEdit = new Edit_Title(this,file_title ,TRUE); if(titleEdit->exec() !=0) { -//odebug << titleEdit->newTitle << oendl; + //odebug << titleEdit->newTitle << oendl; config.writeEntry( s_filename, titleEdit->newTitle); QListBox_1->removeItem(currentItem); - QListBox_1->insertItem ( QPixmap( QPEApplication::qpeDir()+"pics/gutenbrowser/gutenbrowser_sm.png"), titleEdit->newTitle, currentItem); + QListBox_1->insertItem ( + QPixmap( QPEApplication::qpeDir()+ + "pics/gutenbrowser/gutenbrowser_sm.png"), + titleEdit->newTitle, currentItem + ); } } } -// getTitles(); + //getTitles(); QListBox_1->triggerUpdate(true); } 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 @@ -1,189 +1,191 @@ /* This file is part of the Opie Project Copyright (c) 2002 Max Reiss <harlekin@handhelds.org> Copyright (c) 2002 LJP <> Copyright (c) 2002 Holger Freyther <zecke@handhelds.org> =. .=l. .>+-= _;:, .> :=|. This program is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. This program is distributed in the hope that + . -:. = it will be useful, but WITHOUT ANY WARRANTY; : .. .:, . . . without even the implied warranty of =_ + =;=|` MERCHANTABILITY or FITNESS FOR A _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU ..}^=.= = ; Library General Public License for more ++= -. .` .: details. : = ...= . :.=- -. .:....=;==+<; You should have received a copy of the GNU -_. . . )=. = Library General Public License along with -- :-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "xinevideowidget.h" #include "lib.h" /* OPIE */ #include <opie2/odebug.h> #include <qpe/global.h> /* QT */ #include <qtextstream.h> #include <qdir.h> #include <qgfx_qws.h> /* STD */ #include <assert.h> #include <unistd.h> typedef void (*display_xine_frame_t) (void *user_data, uint8_t* frame, int width, int height,int bytes ); typedef void (*vo_scale_cb) (void*, int, int, double, int*, int*, int*, int*, double*, int*, int* ); typedef void (*dest_size_cb) (void*, int, int, double, int*, int*, double*); extern "C" { xine_vo_driver_t* init_video_out_plugin( xine_t *xine, void* video, display_xine_frame_t, void *, vo_scale_cb, dest_size_cb ); int null_is_showing_video( const xine_vo_driver_t* self ); void null_set_show_video( const xine_vo_driver_t* self, int show ); void null_set_mode( const xine_vo_driver_t* self, int depth, int rgb ); void null_display_handler( const xine_vo_driver_t* self, display_xine_frame_t t, void* user_data ); } using namespace XINE; Lib::Lib( InitializationMode initMode, XineVideoWidget* widget ) { m_initialized = false; m_duringInitialization = false; m_video = false; m_wid = widget; printf("Lib"); QString configPath = QDir::homeDirPath() + "/Settings/opiexine.cf"; // get the configuration // not really OO, should be an extra class, later if ( !QFile::exists(configPath) ) { QFile f(configPath); - f.open(IO_WriteOnly); - QTextStream ts( &f ); - ts << "misc.memcpy_method:glibc\n"; - ts << "# uncomment if you experience double speed audio \n #audio.oss_sync_method:softsync\n"; - ts << "codec.ffmpeg_pp_quality:3\n"; - ts << "audio.num_buffers:50\n"; - ts << "audio.size_buffers:4096\n"; - ts << "video.num_buffers:20\n"; - ts << "video.size_buffers:4096\n"; - ts << "audio.out_num_audio_buf:16\n"; - ts << "audio.out_size_audio_buf:8096\n"; - ts << "audio.out_size_zero_buf:1024\n"; - ts << "audio.passthrough_offset:0\n"; - f.close(); + if (f.open(IO_WriteOnly)) { + QTextStream ts( &f ); + ts << "misc.memcpy_method:glibc\n"; + ts << "# uncomment if you experience double speed audio \n #audio.oss_sync_method:softsync\n"; + ts << "codec.ffmpeg_pp_quality:3\n"; + ts << "audio.num_buffers:50\n"; + ts << "audio.size_buffers:4096\n"; + ts << "video.num_buffers:20\n"; + ts << "video.size_buffers:4096\n"; + ts << "audio.out_num_audio_buf:16\n"; + ts << "audio.out_size_audio_buf:8096\n"; + ts << "audio.out_size_zero_buf:1024\n"; + ts << "audio.passthrough_offset:0\n"; + f.close(); + } else + owarn << "Failed to open " f.name() << oendl; } if ( initMode == InitializeImmediately ) { initialize(); m_initialized = true; } else start(); } void Lib::run() { odebug << "Lib::run() started" << oendl; initialize(); m_initialized = true; odebug << "Lib::run() finished" << oendl; } void Lib::initialize() { m_duringInitialization = true; m_xine = xine_new( ); QString configPath = QDir::homeDirPath() + "/Settings/opiexine.cf"; xine_config_load( m_xine, QFile::encodeName( configPath ) ); xine_init( m_xine ); // allocate oss for sound // and fb for framebuffer m_audioOutput = xine_open_audio_driver( m_xine, "oss", NULL ); m_videoOutput = ::init_video_out_plugin( m_xine, NULL, xine_display_frame, this, xine_vo_scale_cb, xine_dest_cb ); m_stream = xine_stream_new (m_xine, m_audioOutput, m_videoOutput ); xine_set_param( m_stream, XINE_PARAM_AUDIO_CLOSE_DEVICE, 1); if (m_wid != 0 ) setWidget( m_wid ); m_queue = xine_event_new_queue (m_stream); xine_event_create_listener_thread (m_queue, xine_event_handler, this); m_duringInitialization = false; } Lib::~Lib() { assert( isRunning() == false ); assert( m_initialized ); // free( m_config ); xine_close( m_stream ); xine_event_dispose_queue( m_queue ); xine_dispose( m_stream ); xine_close_audio_driver(m_xine,m_audioOutput); xine_close_video_driver(m_xine,m_videoOutput); xine_exit( m_xine ); /* FIXME either free or delete but valgrind bitches against both */ //free( m_videoOutput ); //delete m_audioOutput; } void Lib::resize ( const QSize &s ) { assert( m_initialized || m_duringInitialization ); if ( s. width ( ) && s. height ( ) ) m_videoSize = s; } int Lib::majorVersion() { int major, minor, sub; xine_get_version ( &major, &minor, &sub ); return major; } int Lib::minorVersion() { int major, minor, sub; xine_get_version ( &major, &minor, &sub ); return minor; } int Lib::subVersion() { int major, minor, sub; xine_get_version ( &major, &minor, &sub ); return sub; } int Lib::setfile(const QString& fileName) { QString str = fileName.stripWhiteSpace(); 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 @@ /* This file is part of the Opie Project Copyright (c) 2002 L. Potter <ljp@llornkcor.com> =. .=l. .>+-= _;:, .> :=|. This program is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. This program is distributed in the hope that + . -:. = it will be useful, but WITHOUT ANY WARRANTY; : .. .:, . . . without even the implied warranty of =_ + =;=|` MERCHANTABILITY or FITNESS FOR A _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU ..}^=.= = ; General Public License for more ++= -. .` .: details. : = ...= . :.=- -. .:....=;==+<; You should have received a copy of the GNU -_. . . )=. = General Public License along with -- :-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "om3u.h" /* OPIE */ #include <opie2/odebug.h> using namespace Opie::Core; //extern PlayListWidget *playList; Om3u::Om3u( const QString &filePath, int mode) - : QStringList (){ -odebug << "<<<<<<<new m3u "+filePath << oendl; - f.setName(filePath); - f.open(mode); + : QStringList () +{ + odebug << "<<<<<<<new m3u "+filePath << oendl; + f.setName(filePath); + if (!f.open(mode)) { + owarn << "Unable to open file " << f.name() << oendl; + } } Om3u::~Om3u(){} void Om3u::readM3u() { -// odebug << "<<<<<<reading m3u "+f.name() << oendl; +// odebug << "<<<<<<reading m3u "+f.name() << oendl; QTextStream t(&f); - t.setEncoding(QTextStream::UnicodeUTF8); - QString s; + t.setEncoding(QTextStream::UnicodeUTF8); + QString s; while ( !t.atEnd() ) { s=t.readLine(); -// odebug << s << oendl; + // odebug << s << oendl; if( s.find( "#", 0, TRUE) == -1 ) { - if( s.left(2) == "E:" || s.left(2) == "P:" ) { - s = s.right( s.length() -2 ); - QFileInfo f( s ); - QString name = f.baseName(); - name = name.right( name.length() - name.findRev( "\\", -1, TRUE ) -1 ); - s=s.replace( QRegExp( "\\" ), "/" ); - append(s); -// odebug << s << oendl; - } else { // is url - QString name; - name = s; - append(name); - } + if( s.left(2) == "E:" || s.left(2) == "P:" ) { + s = s.right( s.length() -2 ); + QFileInfo f( s ); + QString name = f.baseName(); + name = name.right( name.length() - name.findRev( "\\", -1, TRUE ) -1 ); + s=s.replace( QRegExp( "\\" ), "/" ); + append(s); +// odebug << s << oendl; + } else { // is url + QString name; + name = s; + append(name); + } } } } void Om3u::readPls() { //it's a pls file - QTextStream t( &f ); - t.setEncoding(QTextStream::UnicodeUTF8); - QString s; - while ( !t.atEnd() ) { - s = t.readLine(); - if( s.left(4) == "File" ) { - s = s.right( s.length() - s.find("=",0,true)-1 ); - s = s.stripWhiteSpace(); - s.replace( QRegExp( "%20" )," "); -// odebug << "adding " + s + " to playlist" << oendl; - // numberofentries=2 - // File1=http - // Title - // Length - // Version - // File2=http - s = s.replace( QRegExp( "\\" ), "/" ); - QFileInfo f( s ); - QString name = f.baseName(); - if( name.left( 4 ) == "http" ) { - name = s.right( s.length() - 7); - } else { - name = s; - } - name = name.right( name.length() - name.findRev( "\\", -1, TRUE) - 1 ); - if( s.at( s.length() - 4) == '.') // if this is probably a file + QTextStream t( &f ); + t.setEncoding(QTextStream::UnicodeUTF8); + QString s; + while ( !t.atEnd() ) { + s = t.readLine(); + if( s.left(4) == "File" ) { + s = s.right( s.length() - s.find("=",0,true)-1 ); + s = s.stripWhiteSpace(); + s.replace( QRegExp( "%20" )," "); + // odebug << "adding " + s + " to playlist" << oendl; + s = s.replace( QRegExp( "\\" ), "/" ); + QFileInfo f( s ); + QString name = f.baseName(); + if( name.left( 4 ) == "http" ) { + name = s.right( s.length() - 7); + } else { + name = s; + } + name = name.right( name.length() - name.findRev( "\\", -1, TRUE) - 1 ); + if( s.at( s.length() - 4) == '.') // if this is probably a file + append(s); + else { //if its a url append(s); - else { //if its a url -// if( name.right( 1 ).find( '/' ) == -1) { -// s += "/"; -// } - append(s); - } } } + } } void Om3u::write() { //writes list to m3u file - QString list; - QTextStream t(&f); - t.setEncoding(QTextStream::UnicodeUTF8); - if(count()>0) { - for ( QStringList::ConstIterator it = begin(); it != end(); ++it ) { -// odebug << *it << oendl; - t << *it << "\n"; + QString list; + QTextStream t(&f); + t.setEncoding(QTextStream::UnicodeUTF8); + if(count()>0) { + for ( QStringList::ConstIterator it = begin(); it != end(); ++it ) { + // odebug << *it << oendl; + t << *it << "\n"; + } } - } -// f.close(); } void Om3u::add(const QString &filePath) { //adds to m3u file append(filePath); } void Om3u::remove(const QString &filePath) { //removes from m3u list - QString list, currentFile; - if(count()>0) { - for ( QStringList::ConstIterator it = begin(); it != end(); ++it ) { - currentFile=*it; - // odebug << *it << oendl; - - if( filePath != currentFile) - list += currentFile+"\n"; + QString list, currentFile; + if(count()>0) { + for ( QStringList::ConstIterator it = begin(); it != end(); ++it ) { + currentFile=*it; + // odebug << *it << oendl; + + if( filePath != currentFile) + list += currentFile+"\n"; + } + f.writeBlock( list, list.length() ); } - f.writeBlock( list, list.length() ); - } } void Om3u::deleteFile(const QString &/*filePath*/) {//deletes m3u file - f.close(); - f.remove(); + f.close(); + f.remove(); } void Om3u::close() { //closes m3u file f.close(); } 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 @@ -140,198 +140,203 @@ struct Thread::Data void run() { thr->run(); } }; extern "C" { static void terminate_thread( void *arg ) { Thread::Data *data = ( Thread::Data* )arg; assert( data ); AutoLock locker( data->guard ); data->isRunning = false; data->finishCondition.wakeAll(); } static void *start_thread( void *arg ) { Thread::Data *data = ( Thread::Data* )arg; pthread_cleanup_push( terminate_thread, data ); data->isRunning = true; data->run(); pthread_cleanup_pop( true ); Thread::exit(); return 0; // never reached } } Thread::Thread() : d( new Data ) { d->thr = this; } Thread::~Thread() { assert( d->isRunning == false ); delete d; } void Thread::start() { AutoLock lock( d->guard ); if ( d->isRunning ) { odebug << "ThreadUtil::Thread::start() called for running thread." << oendl; return; } pthread_attr_t attributes; pthread_attr_init( &attributes ); pthread_attr_setscope( &attributes, PTHREAD_SCOPE_SYSTEM ); int err = pthread_create( &d->self, &attributes, start_thread, ( void* )d ); if ( err != 0 ) { odebug << "ThreadUtil::Thread::start() : can't create thread: " << strerror( err ) << "" << oendl; pthread_attr_destroy( &attributes ); return; } pthread_attr_destroy( &attributes ); } void Thread::terminate() { AutoLock lock( d->guard ); if ( !d->isRunning ) return; pthread_cancel( d->self ); } bool Thread::wait() { AutoLock lock( d->guard ); if ( !d->isRunning ) return true; return d->finishCondition.wait( d->guard ); } bool Thread::isRunning() const { AutoLock lock( d->guard ); return d->isRunning; } void Thread::exit() { pthread_exit( 0 ); } -OnewayNotifier::OnewayNotifier() -{ - int fds[ 2 ]; - pipe( fds ); - m_readFd = fds[ 0 ]; - m_writeFd = fds[ 1 ]; +OnewayNotifier::OnewayNotifier() : + m_readFd(-1), + m_writeFd(-1) +{ + int fds[ 2 ] = { -1, -1 }; + if (pipe( fds ) == 0) { + m_readFd = fds[ 0 ]; + m_writeFd = fds[ 1 ]; + } else { + owarn << "Call to pipe() failed" << oendl; + } m_notifier = new QSocketNotifier( m_readFd, QSocketNotifier::Read ); connect( m_notifier, SIGNAL( activated(int) ), this, SLOT( wakeUp() ) ); } OnewayNotifier::~OnewayNotifier() { delete m_notifier; ::close( m_readFd ); ::close( m_writeFd ); } void OnewayNotifier::notify() { const char c = 42; ::write( m_writeFd, &c, 1 ); } void OnewayNotifier::wakeUp() { char c = 0; if ( ::read( m_readFd, &c, 1 ) != 1 ) return; emit awake(); } ChannelMessage::ChannelMessage( int type, int data, const char* msg ) : m_type( type ), m_data( data ), m_msg( msg ), m_isCall( false ), m_replied( false ), m_inEventHandler( false ) {} ChannelMessage::~ChannelMessage() { if ( m_guard.isLocked() ) m_guard.unlock(); } void ChannelMessage::reply() { if ( !m_isCall ) { odebug << "ChannelMessage::reply() - can't reply oneway message!" << oendl; return; } if ( m_inEventHandler ) { m_replied = true; return; } m_condition.wakeOne(); m_guard.unlock(); } struct Channel::Private { Private() { ownerThread = pthread_self(); } pthread_t ownerThread; }; Channel::Channel( QObject *parent, const char *name ) : QObject( parent, name ), d( new Private ) { connect( &m_notifier, SIGNAL( awake() ), this, SLOT( deliver() ) ); } Channel::~Channel() { delete d; } void Channel::send( ChannelMessage *message, SendType type ) { if ( type == WaitForReply ) { message->m_guard.lock(); message->m_isCall = true; } m_pendingMessagesGuard.lock(); m_pendingMessages << MsgEnvelope( type, message ); m_pendingMessagesGuard.unlock(); if ( d->ownerThread == pthread_self() ) { assert( type != WaitForReply ); 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 @@ -249,136 +249,137 @@ QString OpieStumbler::manufacturer( const QString &mac, bool extended ) { QString retval; if ( m_db ) if ( extended ) retval = m_db->lookupExt(mac); else retval = m_db->lookup(mac); if ( retval.isEmpty() ) retval = tr("Unknown"); return retval; } void OpieStumbler::slotJoinNetwork() { slotStopScanning(); OWirelessNetworkInterface *wiface = static_cast<OWirelessNetworkInterface*>(ONetwork::instance()->interface(m_interface)); if( !wiface ) return; QListIterator<StumblerStation> it(m_stationsHistory); for(; it.current() && it.current()->st->macAddress.toString() != m_mac; ++it ); if( !it.current() ) return; m_ssid = it.current()->st->ssid.left(it.current()->st->ssid.length()-1); m_splash = new QFrame( this, "splash", false, WStyle_StaysOnTop | WStyle_DialogBorder | WStyle_Customize ); m_splash->setFrameStyle( QFrame::Panel | QFrame::Raised ); m_splashBox = new QVBoxLayout( m_splash, 4, 4 ); m_infoLabel = new QLabel( QString("<center><b>%1 %2</b></center>").arg(tr("Joining Network")).arg(m_ssid), m_splash ); m_pbar = new QProgressBar( 3, m_splash ); m_pbar->setCenterIndicator(true); m_splashBox->addWidget( m_infoLabel ); m_splashBox->addWidget( m_pbar ); int sw = m_splashBox->sizeHint().width() * 2; int sh = m_splashBox->sizeHint().height(); m_splash->setGeometry((qApp->desktop()->width() - sw)/2, (qApp->desktop()->height() - sh)/2, sw, sh); m_splash->show(); m_splash->raise(); Opie::Net::OStation *station = it.current()->st; odebug << "Bringing interface down" << oendl; wiface->setUp(false); odebug << "Setting mode to " << (station->type == "adhoc" ? "adhoc" : "managed") << oendl; wiface->setMode(station->type == "adhoc" ? "adhoc" : "managed" ); odebug << "Setting channel to " << station->channel << oendl; wiface->setChannel(station->channel); odebug << "Setting SSID to " << station->ssid << oendl; wiface->setSSID(station->ssid); wiface->commit(); odebug << "Bringing interface up" << oendl; wiface->setUp(true); m_pbar->setProgress(1); //Wait 5 sec for association QTimer::singleShot(5000, this, SLOT(slotAssociated())); } void OpieStumbler::slotAssociated() { OWirelessNetworkInterface *wiface = static_cast<OWirelessNetworkInterface*>(ONetwork::instance()->interface(m_interface)); if( !wiface ) { slotCleanSplash(); return; } if (!wiface->isAssociated()) { Global::statusMessage(tr("Could not Join")); m_infoLabel->setText(tr("Could not Join")); QTimer::singleShot(5000, this, SLOT(slotCleanSplash())); return; } Global::statusMessage(tr("Joined")); m_pbar->setProgress(2); m_infoLabel->setText(QString("<center><b>%1 %2</b></center>").arg(tr("Joined Network")).arg(m_ssid)); if(m_proc) { m_proc->kill(); delete m_proc; } m_proc = new Opie::Core::OProcess(this); *m_proc << "udhcpc" << "-f" << "-n" << "-i" << m_interface; - m_proc->start(Opie::Core::OProcess::DontCare); + if (!m_proc->start(Opie::Core::OProcess::DontCare)) + owarn << "Execution of udhcpc returned false. Are paths correct?" << oendl; QTimer::singleShot(5000, this, SLOT(slotCheckDHCP())); } void OpieStumbler::slotCheckDHCP() { if(!m_proc->isRunning()) { Global::statusMessage(tr("Could not Obtain an Address")); m_infoLabel->setText(QString("<center><b>%1</b></center>").arg(tr("Could not Obtain an Address"))); delete m_proc; m_proc = NULL; QTimer::singleShot(5000, this, SLOT(slotCleanSplash())); return; } m_listCurrent->show(); m_pbar->setProgress(3); OWirelessNetworkInterface *wiface = static_cast<OWirelessNetworkInterface*>(ONetwork::instance()->interface(m_interface)); QString ipv4 = wiface->ipV4Address().toString(); m_infoLabel->setText(QString("<center><b>%1 %2</b></center>").arg(tr("Obtained IP")).arg(ipv4)); Global::statusMessage(tr("Obtained IP") + " " + ipv4); QTimer::singleShot(5000, this, SLOT(slotCleanSplash())); } void OpieStumbler::slotCleanSplash() { delete m_pbar; m_pbar = 0; delete m_infoLabel; m_infoLabel = 0; delete m_splashBox; m_splashBox = 0; delete m_splash; m_splash = 0; } 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 @@ -103,193 +103,194 @@ MainWindowImp::MainWindowImp(QWidget *parent, const char *name, WFlags) : MainWi } } //getInterfaceList(); connectionList->header()->hide(); Config cfg("NetworkSetup"); profiles = QStringList::split(" ", cfg.readEntry("Profiles", "All")); for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) profilesList->insertItem((*it)); currentProfileLabel->setText(cfg.readEntry("CurrentProfile", "All")); advancedUserMode = cfg.readBoolEntry("AdvancedUserMode", false); scheme = cfg.readEntry("SchemeFile", DEFAULT_SCHEME); QFile file(scheme); if ( file.open(IO_ReadOnly) ) { // file opened successfully QTextStream stream( &file ); // use a text stream while ( !stream.eof() ) { // until end of file... QString line = stream.readLine(); // line of text excluding '\n' if(line.contains("SCHEME")) { line = line.mid(7, line.length()); currentProfileLabel->setText(line); break; } } file.close(); } makeChannel(); initHostname(); } /** * Deconstructor. Save profiles. Delete loaded libraries. */ MainWindowImp::~MainWindowImp() { // Save profiles. Config cfg("NetworkSetup"); cfg.setGroup("General"); cfg.writeEntry("Profiles", profiles.join(" ")); // Delete all interfaces that don't have owners. QMap<Interface*, QListViewItem*>::Iterator iIt; for( iIt = items.begin(); iIt != items.end(); ++iIt ) { if(iIt.key()->getModuleOwner() == NULL) delete iIt.key(); } // Delete Modules and Libraries QMap<Module*, QLibrary*>::Iterator it; for( it = libraries.begin(); it != libraries.end(); ++it ) { delete it.key(); // I wonder why I can't delete the libraries // What fucking shit this is. //delete it.data(); } } /** * Query the kernel for all of the interfaces. */ void MainWindowImp::getAllInterfaces() { int sockfd = socket(PF_INET, SOCK_DGRAM, 0); if(sockfd == -1) return; struct ifreq ifr; QStringList ifaces; QFile procFile(QString(_PROCNETDEV)); int result; Interface *i; if (! procFile.exists()) { struct ifreq ifrs[100]; struct ifconf ifc; ifc.ifc_len = sizeof(ifrs); ifc.ifc_req = ifrs; result = ioctl(sockfd, SIOCGIFCONF, &ifc); for (unsigned int i = 0; i < ifc.ifc_len / sizeof(struct ifreq); i++) { struct ifreq *pifr = &ifrs[i]; if ( !QString( pifr->ifr_name ).startsWith( "wifi" ) ) ifaces += pifr->ifr_name; else odebug << "ignoring hostap control interface " << pifr->ifr_name << oendl; } } else { - procFile.open(IO_ReadOnly); + if (!procFile.open(IO_ReadOnly)) + owarn << "Failed to open proc file " << procFile.name() << oendl; QString line; QTextStream procTs(&procFile); int loc = -1; procTs.readLine(); // eat a line procTs.readLine(); // eat a line while((line = procTs.readLine().simplifyWhiteSpace()) != QString::null) { if((loc = line.find(":")) != -1) { // ignore wifi* (hostap control interfaces) if ( !line.left(loc).startsWith( "wifi" ) ) ifaces += line.left(loc); else odebug << "ignoring hostap control interface " << line.left(loc) << oendl; } } } for (QStringList::Iterator it = ifaces.begin(); it != ifaces.end(); ++it) { int flags = 0; if ( m_handledIfaces.contains( (*it) ) ) { odebug << " " << (*it).latin1() << " is handled by a module" << oendl; continue; } // int family; i = NULL; strcpy(ifr.ifr_name, (*it).latin1()); struct ifreq ifcopy; ifcopy = ifr; result = ioctl(sockfd, SIOCGIFFLAGS, &ifcopy); flags = ifcopy.ifr_flags; i = new Interface(this, ifr.ifr_name, false); i->setAttached(true); if ((flags & IFF_UP) == IFF_UP) i->setStatus(true); else i->setStatus(false); if ((flags & IFF_BROADCAST) == IFF_BROADCAST) i->setHardwareName("Ethernet"); else if ((flags & IFF_POINTOPOINT) == IFF_POINTOPOINT) i->setHardwareName("Point to Point"); else if ((flags & IFF_MULTICAST) == IFF_MULTICAST) i->setHardwareName("Multicast"); else if ((flags & IFF_LOOPBACK) == IFF_LOOPBACK) i->setHardwareName("Loopback"); else i->setHardwareName("Unknown"); owarn << "Adding interface " << ifr.ifr_name << " to interfaceNames\n" << oendl; interfaceNames.insert(i->getInterfaceName(), i); updateInterface(i); connect(i, SIGNAL(updateInterface(Interface*)), this, SLOT(updateInterface(Interface*))); } // now lets ask the plugins too ;) QMap<Module*, QLibrary*>::Iterator it; QList<Interface> ilist; for( it = libraries.begin(); it != libraries.end(); ++it ) { if(it.key()) { ilist = it.key()->getInterfaces(); for( i = ilist.first(); i != 0; i = ilist.next() ) { owarn << "Adding interface " << i->getInterfaceName().latin1() << " to interfaceNames\n" << oendl; interfaceNames.insert(i->getInterfaceName(), i); updateInterface(i); connect(i, SIGNAL(updateInterface(Interface*)), this, SLOT(updateInterface(Interface*))); } } } } /** * Load all modules that are found in the path * @param path a directory that is scaned for any plugins that can be loaded * and attempts to load them */ void MainWindowImp::loadModules(const QString &path) { #ifdef DEBUG odebug << "MainWindowImp::loadModules: " << path.latin1() << "" << oendl; #endif QDir d(path); if(!d.exists()) return; QString lang = ::getenv("LANG"); // Don't want sym links d.setFilter( QDir::Files | QDir::NoSymLinks ); const QFileInfoList *list = d.entryInfoList(); @@ -639,147 +640,149 @@ void MainWindowImp::removeProfile() break; } } } } /** * A new profile has been selected, change. * @param newProfile the new profile. */ void MainWindowImp::changeProfile() { if(profilesList->currentItem() == -1) { QMessageBox::information(this, "Can't Change.","Please select a profile.", QMessageBox::Ok); return; } QString newProfile = profilesList->text(profilesList->currentItem()); if(newProfile != currentProfileLabel->text()) { currentProfileLabel->setText(newProfile); QFile::remove(scheme); QFile file(scheme); if ( file.open(IO_ReadWrite) ) { QTextStream stream( &file ); stream << QString("SCHEME=%1").arg(newProfile); file.close(); } // restart all up devices? if(QMessageBox::information(this, "Question","Restart all running interfaces?", QMessageBox::Ok, QMessageBox::No) == QMessageBox::Ok) { // Go through them one by one QMap<Interface*, QListViewItem*>::Iterator it; for( it = items.begin(); it != items.end(); ++it ) { if(it.key()->getStatus() == true) it.key()->restart(); } } } // TODO change the profile in the modules } void MainWindowImp::makeChannel() { channel = new QCopChannel( "QPE/Application/networksettings", this ); connect( channel, SIGNAL(received(const QCString&,const QByteArray&)), this, SLOT(receive(const QCString&,const QByteArray&)) ); } void MainWindowImp::receive(const QCString &msg, const QByteArray &arg) { bool found = false; odebug << "MainWindowImp::receive QCop msg >"+msg+"<" << oendl; if (msg == "raise") { raise(); return; } QString dest = msg.left(msg.find("(")); QCString param = msg.right(msg.length() - msg.find("(") - 1); param = param.left( param.length() - 1 ); odebug << "dest >" << dest.latin1() << "< param >"+param+"<" << oendl; QMap<Module*, QLibrary*>::Iterator it; for( it = libraries.begin(); it != libraries.end(); ++it ) { odebug << "plugin >" << it.key()->type().latin1() << "<" << oendl; if(it.key()->type() == dest) { it.key()->receive( param, arg ); found = true; } } if (found) QPEApplication::setKeepRunning(); else odebug << "Huh what do ya want" << oendl; } void MainWindowImp::setHostname() { static QRegExp filter("[^A-Za-z0-9_\\-\\.]"); if (filter.match(m_Nameinput->text())!=-1) { odebug << "Wrong hostname" << oendl; QMessageBox::critical(0, tr("Sorry"), tr("This is a wrong name.<br>Please use A-Z, a-z, _, - or a single dot.")); return; } OProcess h; _procTemp=""; h << "hostname" << m_Nameinput->text(); connect(&h,SIGNAL(receivedStderr(Opie::Core::OProcess*,char*,int)),this,SLOT(slotHostname(Opie::Core::OProcess*,char*,int))); - h.start(OProcess::Block,OProcess::Stderr); + if (!h.start(OProcess::Block,OProcess::Stderr)) + owarn << "Failed execution of 'hostname'. Are the paths correct?" << oendl; odebug << "Got " << _procTemp << " - " << h.exitStatus() << oendl; if (h.exitStatus()!=0) { QMessageBox::critical(0, tr("Sorry"), QString(tr("Could not set name.\n%1")).arg(_procTemp.stripWhiteSpace())); return; } _procTemp=""; QFile f(_HOSTFILE); if (f.open(IO_Truncate|IO_WriteOnly)) { QTextStream s(&f); s << m_Nameinput->text(); } else { QMessageBox::critical(0, tr("Sorry"), tr("Could not save name.")); return; } f.close(); f.setName(_IRDANAME); if (f.open(IO_WriteOnly)) { QTextStream s(&f); s << m_Nameinput->text(); } else { QMessageBox::critical(0, tr("Sorry"), tr("Could not set infrared name.")); } } void MainWindowImp::initHostname() { OProcess h; _procTemp=""; h << "hostname"; connect(&h,SIGNAL(receivedStdout(Opie::Core::OProcess*,char*,int)),this,SLOT(slotHostname(Opie::Core::OProcess*,char*,int))); - h.start(OProcess::Block,OProcess::AllOutput); + if (!h.start(OProcess::Block,OProcess::AllOutput)) + owarn << "Could not execute 'hostname'. Are the paths correct?" oendl; odebug << "Got " << _procTemp <<oendl; m_Nameinput->setText(_procTemp.stripWhiteSpace()); _procTemp=""; } -void MainWindowImp::slotHostname(Opie::Core::OProcess */*proc*/, char *buffer, int buflen) +void MainWindowImp::slotHostname(Opie::Core::OProcess * /*proc*/, char *buffer, int buflen) { if (buflen < 1 || buffer==0) return; char*_t = new char[buflen+1]; ::memset(_t,0,buflen+1); ::memcpy(_t,buffer,buflen); _procTemp+=_t; delete[]_t; } 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 @@ -675,194 +675,196 @@ int Modem::openLockfile( QString lockfile, int flags) // } if ((fd = open(lockfile, flags, mode)) == -1) { odebug << "error opening lockfile!" << oendl; lockfile = QString::null; fd = open(DEVNULL, O_RDONLY); } else fchown(fd, 0, 0); return fd; } void alarm_handler(int) { // fprintf(stderr, "alarm_handler(): Received SIGALRM\n"); // jump siglongjmp(jmp_buffer, 1); } const char* Modem::authFile(Auth method, int version) { switch(method|version) { case PAP|Original: return PAP_AUTH_FILE; break; case PAP|New: return PAP_AUTH_FILE".new"; break; case PAP|Old: return PAP_AUTH_FILE".old"; break; case CHAP|Original: return CHAP_AUTH_FILE; break; case CHAP|New: return CHAP_AUTH_FILE".new"; break; case CHAP|Old: return CHAP_AUTH_FILE".old"; break; default: return 0L; } } bool Modem::createAuthFile(Auth method, const char *username, const char *password) { const char *authfile, *oldName, *newName; char line[100]; char regexp[2*MaxStrLen+30]; regex_t preg; if(!(authfile = authFile(method))) return false; if(!(newName = authFile(method, New))) return false; // look for username, "username" or 'username' // if you modify this RE you have to adapt regexp's size above snprintf(regexp, sizeof(regexp), "^[ \t]*%s[ \t]\\|^[ \t]*[\"\']%s[\"\']", username,username); MY_ASSERT(regcomp(&preg, regexp, 0) == 0); // copy to new file pap- or chap-secrets int old_umask = umask(0077); FILE *fout = fopen(newName, "w"); if(fout) { // copy old file FILE *fin = fopen(authfile, "r"); if(fin) { while(fgets(line, sizeof(line), fin)) { if(regexec(&preg, line, 0, 0L, 0) == 0) continue; fputs(line, fout); } fclose(fin); } // append user/pass pair fprintf(fout, "\"%s\"\t*\t\"%s\"\n", username, password); fclose(fout); } // restore umask umask(old_umask); // free memory allocated by regcomp regfree(&preg); if(!(oldName = authFile(method, Old))) return false; // delete old file if any unlink(oldName); - rename(authfile, oldName); - rename(newName, authfile); + if (rename(authfile, oldName) == -1) + return false; + if (rename(newName, authfile) == -1) + return false; return true; } bool Modem::removeAuthFile(Auth method) { const char *authfile, *oldName; if(!(authfile = authFile(method))) return false; if(!(oldName = authFile(method, Old))) return false; if(access(oldName, F_OK) == 0) { unlink(authfile); return (rename(oldName, authfile) == 0); } else return false; } bool Modem::setSecret(int method, const char* name, const char* password) { Auth auth; if(method == AUTH_PAPCHAP) return setSecret(AUTH_PAP, name, password) && setSecret(AUTH_CHAP, name, password); switch(method) { case AUTH_PAP: auth = Modem::PAP; break; case AUTH_CHAP: auth = Modem::CHAP; break; default: return false; } return createAuthFile(auth, name, password); } bool Modem::removeSecret(int method) { Auth auth; switch(method) { case AUTH_PAP: auth = Modem::PAP; break; case AUTH_CHAP: auth = Modem::CHAP; break; default: return false; } return removeAuthFile( auth ); } int checkForInterface() { // I don't know if Linux needs more initialization to get the ioctl to // work, pppd seems to hint it does. But BSD doesn't, and the following // code should compile. #if (defined(HAVE_NET_IF_PPP_H) || defined(HAVE_LINUX_IF_PPP_H)) && !defined(__svr4__) int s, ok; struct ifreq ifr; // extern char *no_ppp_msg; if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) return 1; /* can't tell */ strlcpy(ifr.ifr_name, "ppp0", sizeof (ifr.ifr_name)); ok = ioctl(s, SIOCGIFFLAGS, (caddr_t) &ifr) >= 0; close(s); if (ok == -1) { // This is ifdef'd FreeBSD, because FreeBSD is the only BSD that supports // KLDs, the old LKM interface couldn't handle loading devices // dynamically, and thus can't load ppp support on the fly #ifdef __FreeBSD__ // If we failed to load ppp support and don't have it already. if (kldload("if_ppp") == -1) { return -1; } return 0; #else return -1; #endif } return 0; #else // We attempt to use the SunOS/SysVr4 method and stat /dev/ppp struct stat buf; |