author | erik <erik> | 2007-01-31 22:06:07 (UTC) |
---|---|---|
committer | erik <erik> | 2007-01-31 22:06:07 (UTC) |
commit | 9395cf2a65184e493714c699bb23b02ea31feef5 (patch) (side-by-side diff) | |
tree | ea07c026298820559c13ad32e612d51048cee0a9 | |
parent | 958e042c5a4d4e38fd1baae50b78a2febfd306ab (diff) | |
download | opie-9395cf2a65184e493714c699bb23b02ea31feef5.zip opie-9395cf2a65184e493714c699bb23b02ea31feef5.tar.gz opie-9395cf2a65184e493714c699bb23b02ea31feef5.tar.bz2 |
I expanded my audit to include any app I could get to compile in i386.
In that expansion a whole new crop of unchecked returns has sprung up.
This commit fixes those weeds or should I say potential bugs.
-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,960 +1,962 @@ /*************************************************************************** // 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() ); addItems(); }// end if }// end while newindexLib.close(); } #ifndef Q_WS_QWS setCursor( arrowCursor); #endif #endif } // end Newlibrary() void LibraryDialog::Library() { clearItems(); // qDebug( "opening GUTINDEX.ALL file"); IDontKnowWhy = ""; system("date"); if ( indexLib.open( IO_ReadOnly) ) { // file opened successfully QTextStream indexStream( &indexLib ); QString indexLine; qApp->processEvents(); bool okToRead = false; while ( !indexStream.eof() ) { indexLine = indexStream.readLine(); if(indexLine == "<==Start GUTINDEX.ALL listings==>") okToRead = true; if(indexLine == "<==End of GUTINDEX.ALL==>") { okToRead = false; indexLib.at(indexLib.size()); } if(okToRead) { QStringList token = QStringList::split(' ', indexLine); int textNumber; if(( textNumber = token.last().toInt() )) if(textNumber > 10001) { // qWarning("Last "+token.last()); // newer files with numbers > 100000 have new dir structure and need to be parsed differently.. if(textNumber < 10626) year = "2003"; else if(textNumber >= 10626 && textNumber < 14600) year = "2004"; else if(textNumber >= 14600) year = "2005"; file = token.last(); title = indexLine.mid(0,72); addItems(); //author and qlistview // qDebug("file number is " + number + " title is " + title ); } else { //end new etexts if(token[1].toInt() && token[1].toInt() > 1969) { year = token[1]; file = indexLine.mid(60,12); if(file.left(1).find("[",0,TRUE) != -1) { file.remove(1,1); if( file.find("]",0,TRUE) != -1) file = file.left( file.find("]",0,TRUE)); if(file.find("?", 0, false) != -1 ) { QString tmpfile = file.replace(QRegExp("[?]"), "8"); file = tmpfile; } title = indexLine.mid( 9, 50); addItems(); } } else { // then try new format texts file = token.last(); title = indexLine.mid(0,72); year = "1980"; addItems(); //author and qlistview } } //end old etexts } //end okToTRead } indexLib.close(); } else { QString sMsg; sMsg = ( tr("<p>Error opening library index file. Please download a new one.</P> ")); QMessageBox::message( "Error",sMsg); } system("date"); sortLists(0); } //end Library() /* Groks the author out of the title */ bool LibraryDialog::getAuthor() { if( title.contains( ", by", true)) { int auth; auth = title.find(", by", 0, true); author = title.right(title.length() - (auth + 4) ); if( int finder = author.find("[", 0, true)) { author = author.left(finder); } } else if ( title.contains( "by, ", true) ) { int auth; auth = title.find("by, ", 0, true); author = title.right(title.length() - (auth + 4) ); if( int finder = author.find("[", 0, true)) { author = author.left( finder); } } else if ( title.contains( " by", true) ) { int auth; auth = title.find(" by", 0, true); author = title.right(title.length() - (auth + 3) ); if( int finder = author.find("[", 0, true)) { author = author.left( finder); } } else if ( title.contains( "by ", true) ) { int auth; auth = title.find("by ", 0, true); author = title.right(title.length() - (auth + 3) ); if( int finder = author.find("[", 0, true)) { author = author.left( finder); } } else if ( title.contains( ",", true) ) { int auth; auth = title.find(",", 0, true); author = title.right( title.length() - (auth + 1) ); if ( author.contains( ",", true) ) { int auth; auth = author.find(",", 0, true); author = author.right( author.length() - (auth + 1) ); } if( int finder = author.find("[", 0, true)) { author = author.left( finder); } } else if ( title.contains( "/", true) ) { int auth; auth = title.find("/", 0, true); author = title.right(title.length() - (auth + 1) ); if( int finder = author.find("[", 0, true)) { author = author.left( finder); } } else if ( title.contains( "of", true) ) { int auth; auth = title.find("of", 0, true); author = title.right(title.length() - (auth + 2) ); if( int finder = author.find("[", 0, true)) { author = author.left( finder); } } else { author = ""; } if ( author.contains("et. al")) { int auth; auth = author.find("et. al", 0, true); author = author.left( auth ); } if ( author.contains("#")) { int auth; auth = author.find("#", 0, true); author = author.left( auth); } if ( author.contains("(")) { int auth; auth = author.find("(", 0, true); author = author.left( auth); } if ( author.contains("et al")) { int auth; auth = author.find("et al", 0, true); author = author.left( auth ); } QRegExp r = QRegExp("[0-9]", true, false); if ( author.left(2).find( r) != -1 ) { author = ""; } author = author.stripWhiteSpace(); if (authBox->isChecked() == TRUE) { // this reverses the first name and last name of the author QString lastName, firstName=""; int finder = author.findRev( ' ', -1, TRUE); lastName = author.right( author.length()-finder); firstName = author.left(finder); lastName = lastName.stripWhiteSpace(); firstName = firstName.stripWhiteSpace(); if( lastName.find( firstName, 0, true) == -1) // this avoids dup names author = lastName+", "+firstName; } return true; }////// end getAuthor() void LibraryDialog::addItems() { cleanStrings(); getAuthor(); // grok author etext etextStruct; if( /*!number.isEmpty() && */ (title.find( "reserved",0, FALSE) == -1) && (file.find( "]",0, true) == -1) &&(title.find( "Audio",0, FALSE) == -1)) { // qDebug("new item "+title); // fill string list or something to be able to sort by Author etextStruct.title = title; etextStruct.author = author; etextStruct.year = year; etextStruct.file = file; etextLibrary.append( etextStruct); if( author.isEmpty() ) QList_Item5 = new QListViewItem( ListView5, /*number, */author, title, year, file ); else { if( author.find(QRegExp("[^a-fA-F]")) ) QList_Item1 = new QListViewItem( ListView1, /* number,*/author, title, year, file ); else if(author.find(QRegExp("[^g-mG-M]")) ) QList_Item2 = new QListViewItem( ListView2, /* number,*/ author, title,year, file ); else if(author.find(QRegExp("[^n-rN-R]")) ) QList_Item3 = new QListViewItem( ListView3, /* number,*/ author, title, year, file ); else if(author.find(QRegExp("[^s-zS-Z]")) ) QList_Item4 = new QListViewItem( ListView4, /* number,*/ author, title, year, file ); } } } /* 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); } i++; #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) { ListView1->setSorting(index); ListView2->setSorting(index); ListView3->setSorting(index); ListView4->setSorting(index); ListView5->setSorting(index); ListView1->sort(); ListView2->sort(); ListView3->sort(); ListView4->sort(); ListView5->sort(); } /* Downloads the current selected listitem*/ bool LibraryDialog::getItem(QListViewItem *it) { // //odebug << "selected getItem" << oendl; // DlglistItemNumber = it->text(0); DlglistItemTitle = it->text(0); DlglistItemYear = it->text(2); DlglistItemFile = it->text(3); if(download_Etext()) { if(i_binary == 1) { } } return true; } /* download button is pushed so we get the current items to download*/ bool LibraryDialog::onButtonDownload() { // //odebug << "selected onButtonDownloadz" << oendl; QListViewItemIterator it1( ListView1 ); QListViewItemIterator it2( ListView2 ); QListViewItemIterator it3( ListView3 ); QListViewItemIterator it4( ListView4 ); QListViewItemIterator it5( ListView5 ); // iterate through all items of the listview for ( ; it1.current(); ++it1 ) { if ( it1.current()->isSelected() ) getItem(it1.current()); it1.current()->setSelected(false); } for ( ; it2.current(); ++it2 ) { if ( it2.current()->isSelected() ) getItem(it2.current()); it2.current()->setSelected(false); } for ( ; it3.current(); ++it3 ) { if ( it3.current()->isSelected() ) getItem(it3.current()); it3.current()->setSelected(false); } for ( ; it4.current(); ++it4 ) { if ( it4.current()->isSelected() ) getItem(it4.current()); it4.current()->setSelected(false); } for ( ; it5.current(); ++it5 ) { if ( it5.current()->isSelected() ) getItem(it5.current()); it5.current()->setSelected(false); } return true; } /* handles the sorting combo box */ void LibraryDialog::comboSelect(int index) { // //odebug << "we are sorting" << oendl; ListView1->setSorting( index, true); ListView2->setSorting( index, true); ListView3->setSorting( index, true); ListView4->setSorting( index, true); ListView5->setSorting( index, true); ListView1->sort(); ListView2->sort(); ListView3->sort(); ListView4->sort(); ListView5->sort(); // ListView1->triggerUpdate(); // ListView2->triggerUpdate(); // ListView3->triggerUpdate(); // ListView4->triggerUpdate(); // ListView5->triggerUpdate(); } void LibraryDialog::newList() { if(indexLoaded) { onButtonDownload(); } else { Output *outDlg; buttonNewList->setDown(true); //odebug << "changing dir "+QPEApplication::qpeDir()+"etc/gutenbrowser" << oendl; QString gutenindex1 = local_library + "/GUTINDEX.ALL"; QString cmd="wget -O " + gutenindex1 + " http://www.gutenberg.org/dirs/GUTINDEX.ALL 2>&1"; int result = QMessageBox::warning( this,"Download" ,"<p>Ok to use /'wget/' to download a new library list?</P>" ,"Yes","No",0,0,1); qApp->processEvents(); if(result == 0) { outDlg = new Output( 0, tr("Downloading Gutenberg Index...."),true); outDlg->showMaximized(); outDlg->show(); qApp->processEvents(); FILE *fp; char line[130]; outDlg->OutputEdit->append( tr("Running wget") ); outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,false); sleep(1); fp = popen( (const char *) cmd, "r"); if ( !fp ) { } else { //odebug << "Issuing the command\n"+cmd << oendl; // system(cmd); while ( fgets( line, sizeof line, fp)) { outDlg->OutputEdit->append(line); outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,false); } pclose(fp); outDlg->OutputEdit->append("Finished downloading\n"); outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,false); qApp->processEvents(); // if( QFile(gutenindex1).exists() ) { // QString gutenindex=QPEApplication::qpeDir()+"etc/gutenbrowser/GUTINDEX.ALL"; // if( rename(gutenindex1.latin1(),gutenindex.latin1()) !=0) // //odebug << "renaming error" << oendl; // } } // outDlg->close(); FindLibrary(); if(outDlg) delete outDlg; } buttonNewList->setDown(false); // if(outDlg) // delete outDlg; } } bool LibraryDialog::moreInfo() { QListViewItem * item; 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,349 +1,351 @@ /* 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(); if ( !xine_open( m_stream, str.utf8().data() ) ) { return 0; } return 1; } int Lib::play( const QString& fileName, int startPos, int start_time ) { assert( m_initialized ); QString str = fileName.stripWhiteSpace(); if ( !xine_open( m_stream, str.utf8().data() ) ) { return 0; } return xine_play( m_stream, startPos, start_time); } void Lib::stop() { assert( m_initialized ); xine_stop( m_stream ); xine_set_param( m_stream, XINE_PARAM_AUDIO_CLOSE_DEVICE, 1); } void Lib::pause( bool toggle ) { assert( m_initialized ); if ( toggle ) { xine_set_param( m_stream, XINE_PARAM_SPEED, XINE_SPEED_PAUSE ); xine_set_param( m_stream, XINE_PARAM_AUDIO_CLOSE_DEVICE, 1); } else { xine_set_param( m_stream, XINE_PARAM_SPEED, XINE_SPEED_NORMAL ); } } int Lib::speed() const { assert( m_initialized ); return xine_get_param ( m_stream, XINE_PARAM_SPEED ); } void Lib::setSpeed( int speed ) { assert( m_initialized ); xine_set_param ( m_stream, XINE_PARAM_SPEED, speed ); } int Lib::status() const { assert( m_initialized ); return xine_get_status( m_stream ); } int Lib::currentPosition() const { assert( m_initialized ); int pos, time, length; xine_get_pos_length( m_stream, &pos, &time, &length ); return pos; } int Lib::currentTime() const { assert( m_initialized ); int pos, time, length; pos = time = length = 0; if ( xine_get_pos_length( m_stream, &pos, &time, &length ) ) return time/1000; else return 0; } int Lib::length() const { assert( m_initialized ); int pos, time, length; /* dilb: patch to solve the wrong stream length reported to the GUI*/ int iRetVal=0, iTestLoop=0; do { iRetVal = xine_get_pos_length( m_stream, &pos, &time, &length ); if (iRetVal) {/* if the function didn't return 0, then pos, time and length are valid.*/ return length/1000; } /*don't poll too much*/ usleep(100000); iTestLoop++; } while ( iTestLoop < 10 ); /* if after 1s, we still don't have any valid stream, then return -1 (this value could be used to make the stream unseekable, but it should never occur!! Mr. Murphy ? :) ) */ return -1; } /* info about current stream */ QSize Lib::videoSize()const { if (!m_initialized||!hasVideo()) return QSize(0,0); int width = xine_get_stream_info(m_stream,XINE_STREAM_INFO_VIDEO_WIDTH); int height = xine_get_stream_info(m_stream,XINE_STREAM_INFO_VIDEO_HEIGHT); return QSize(width,height); } bool Lib::isSeekable() const { assert( m_initialized ); return xine_get_stream_info( m_stream, XINE_STREAM_INFO_SEEKABLE ); } bool Lib::hasVideo() const { assert( m_initialized ); return xine_get_stream_info( m_stream, XINE_STREAM_INFO_HAS_VIDEO); } int Lib::audioBitrate()const { if (!m_initialized) return 0; return xine_get_stream_info( m_stream, XINE_STREAM_INFO_AUDIO_BITRATE); } int Lib::videoBitrate()const { if (!m_initialized||!hasVideo()) return 0; return xine_get_stream_info( m_stream, XINE_STREAM_INFO_VIDEO_BITRATE); } /* end info block */ void Lib::seekTo( int time ) { assert( m_initialized ); odebug << "Seeking to second " << time << oendl; //Keep it paused if it was in that state if ( xine_get_param( m_stream, XINE_PARAM_SPEED ) ) { xine_play( m_stream, 0, time*1000 ); } else { xine_play( m_stream, 0, time*1000 ); xine_set_param( m_stream, XINE_PARAM_SPEED, XINE_SPEED_PAUSE ); } } QString Lib::metaInfo( int number) const { assert( m_initialized ); return xine_get_meta_info( m_stream, number ); } int Lib::error() const { assert( m_initialized ); 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 @@ -1,394 +1,399 @@ /* This file is part of the KDE project Copyright (C) 2002 Simon Hausmann <hausmann@kde.org> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 "threadutil.h" #include <opie2/odebug.h> #include <qsocketnotifier.h> #include <pthread.h> #include <assert.h> #include <unistd.h> #include <errno.h> using namespace ThreadUtil; struct Mutex::Data { Data() { pthread_mutex_init( &mutex, 0 ); } ~Data() { pthread_mutex_destroy( &mutex ); } pthread_mutex_t mutex; }; Mutex::Mutex() : d( new Data ) { } Mutex::~Mutex() { delete d; } void Mutex::lock() { pthread_mutex_lock( &d->mutex ); } void Mutex::unlock() { pthread_mutex_unlock( &d->mutex ); } bool Mutex::tryLock() { return pthread_mutex_trylock( &d->mutex ) == 0; } bool Mutex::isLocked() { if ( !tryLock() ) return true; unlock(); return false; } struct WaitCondition::Data { Data() { int result = pthread_cond_init( &waitCondition, 0 ); assert( result == 0 ); } ~Data() { pthread_cond_destroy( &waitCondition ); } pthread_cond_t waitCondition; }; WaitCondition::WaitCondition() : d( new Data ) { } WaitCondition::~WaitCondition() { delete d; } bool WaitCondition::wait() { Mutex m; m.lock(); return wait( m ); } bool WaitCondition::wait( Mutex &mutex ) { return pthread_cond_wait( &d->waitCondition, &mutex.d->mutex ); } void WaitCondition::wakeOne() { pthread_cond_signal( &d->waitCondition ); } void WaitCondition::wakeAll() { pthread_cond_broadcast( &d->waitCondition ); } struct Thread::Data { Data() : isRunning( false ) {} pthread_t self; Mutex guard; bool isRunning; WaitCondition finishCondition; Thread *thr; 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 ); deliver(); } else m_notifier.notify(); //QThread::postEvent( this, new QCustomEvent( QEvent::User, envelope ) ); if ( type == WaitForReply ) { message->m_condition.wait( message->m_guard ); message->m_guard.unlock(); } } void Channel::deliver() { AutoLock lock( m_pendingMessagesGuard ); while ( !m_pendingMessages.isEmpty() ) { MsgEnvelope envelope = m_pendingMessages.first(); m_pendingMessages.remove( m_pendingMessages.begin() ); m_pendingMessagesGuard.unlock(); deliverOne( envelope ); m_pendingMessagesGuard.lock(); } } void Channel::deliverOne( const MsgEnvelope &envelope ) { ChannelMessage *msg = envelope.msg; assert( msg ); if ( envelope.type == WaitForReply ) { msg->m_guard.lock(); msg->m_inEventHandler = true; } receiveMessage( msg, envelope.type ); if ( envelope.type == WaitForReply ) { msg->m_inEventHandler = false; if ( msg->m_replied ) { msg->m_condition.wakeOne(); // this is a bit tricky. we unlock only when we reply. // reply() does an unlock as well. msg->m_guard.unlock(); } } } /* vim: et sw=4 ts=4 */ 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 @@ -89,296 +89,297 @@ OpieStumbler::OpieStumbler(QWidget *parent, const char *name, WFlags) menuBar()->insertItem(tr("Settings"), configMenu); menuBar()->insertItem(tr("Scanning"), scanMenu); QPEApplication::setStylusOperation(m_listCurrent->viewport(), QPEApplication::RightOnHold); QPEApplication::setStylusOperation(m_listHistory->viewport(), QPEApplication::RightOnHold); m_listCurrent->addColumn(tr("SSID")); m_listCurrent->addColumn(tr("Chan")); m_listCurrent->addColumn(tr("Signal")); m_listCurrent->addColumn(tr("Enc")); m_listCurrent->setSelectionMode( QListView::Extended ); m_listHistory->addColumn(tr("SSID")); m_listHistory->addColumn(tr("Chan")); m_listHistory->addColumn(tr("Max Sig")); m_listHistory->addColumn(tr("Enc")); m_listHistory->addColumn(tr("Vendor")); connect(m_listCurrent, SIGNAL(mouseButtonPressed (int, QListViewItem*, const QPoint&, int)), this, SLOT(slotCurrentMousePressed (int, QListViewItem*, const QPoint&, int))); connect(m_listHistory, SIGNAL(mouseButtonPressed (int, QListViewItem*, const QPoint&, int)), this, SLOT(slotHistoryMousePressed (int, QListViewItem*, const QPoint&, int))); for(int i = CURCHAN; i <= CURENC; ++i) { m_listCurrent->setColumnAlignment( i, Qt::AlignHCenter ); m_listHistory->setColumnAlignment( i, Qt::AlignHCenter ); } loadConfig(); m_stumbler = new Stumbler(m_interface, this); connect(m_stumbler, SIGNAL(newdata()), this, SLOT(slotUpdateStations())); QTimer::singleShot(1000, this, SLOT(slotLoadManufacturers()) ); slotStartScanning(); } void OpieStumbler::slotConfigure() { StumblerSettings settings(this, "Settings", true); if (settings.exec() == QDialog::Accepted) loadConfig(); } void OpieStumbler::loadConfig() { Config cfg("OpieStumbler", Config::User); cfg.setGroup("General"); m_interface = cfg.readEntry("interface", "wlan0"); } void OpieStumbler::slotStartScanning() { setCaption(appCaption() + " (" + tr("Scanning") + ")"); m_stumbler->start(); } void OpieStumbler::slotStopScanning() { setCaption(appCaption()); m_stumbler->stop(); } void OpieStumbler::slotUpdateStations() { m_stationsCurrent->clear(); m_stationsCurrent = m_stumbler->stations(); if (m_stationsCurrent) { QListIterator<Opie::Net::OStation> it(*m_stationsCurrent); for(; it.current(); ++it) { Opie::Net::OStation *station = it.current(); QListIterator<StumblerStation> itr(m_stationsHistory); for( ; itr.current(); ++itr) { if (itr.current()->st->macAddress.toString() == station->macAddress.toString()) { break; } } if (!itr.current()) { //We need to copy the date because m_statiosCurrent has autodelete enabled m_stationsHistory.append(new StumblerStation(new Opie::Net::OStation, QDateTime::currentDateTime())); *(m_stationsHistory.last()->st) = (*station); } else { if ( itr.current()->st->level < station->level ) itr.current()->st->level = station->level; itr.current()->lastTimeSeen = QDateTime::currentDateTime(); } } } displayStations(); } void OpieStumbler::displayStations() { m_listCurrent->clear(); for(QListIterator<Opie::Net::OStation> it(*m_stationsCurrent); it.current(); ++it) new StationViewItem( m_listCurrent, it.current()->ssid, QString::number(it.current()->channel), QString::number(it.current()->level), it.current()->encrypted ? "Y": "N", it.current()->macAddress.toString() ); m_listHistory->clear(); for(QListIterator<StumblerStation> it(m_stationsHistory); it.current(); ++it) new StationViewItem( m_listHistory, it.current()->st->ssid, QString::number(it.current()->st->channel), QString::number(it.current()->st->level), it.current()->st->encrypted ? "Y": "N", manufacturer(it.current()->st->macAddress.toString()), it.current()->st->macAddress.toString() ); } void OpieStumbler::slotMessageReceived( const QCString &message, const QByteArray ¶meters) { Q_UNUSED(const_cast<QByteArray &>(parameters)) if ( message == "show()" ) show(); } void OpieStumbler::slotCurrentMousePressed(int button, QListViewItem * item, const QPoint &point, int c) { Q_UNUSED(c) if ( 2 == button ) { m_mac = item->text(CURENC + 1); m_popupCurrent->popup(point); } } void OpieStumbler::slotHistoryMousePressed(int button, QListViewItem * item, const QPoint &point, int c) { Q_UNUSED(c) if ( 2 == button ) { m_mac = item->text(HISVENDOR + 1); m_popupHistory->popup(point); } } void OpieStumbler::slotShowDetails() { QListIterator<StumblerStation> it(m_stationsHistory); for(; it.current() && it.current()->st->macAddress.toString() != m_mac; ++it ); if( it.current() ) { StationInfo info(it.current()->st->ssid, it.current()->st->type, QString::number(it.current()->st->channel), QString::number(it.current()->st->rates.last()/1000000), QString::number(it.current()->st->level), it.current()->st->encrypted ? "WEP": "No", it.current()->st->macAddress.toString(), manufacturer(it.current()->st->macAddress.toString(), true), it.current()->lastTimeSeen.toString() ,this, "", true); info.exec(); } } void OpieStumbler::slotLoadManufacturers() { m_db = Opie::Net::OManufacturerDB::instance(); } 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 @@ -1,455 +1,456 @@ #include "mainwindowimp.h" #include "addconnectionimp.h" #include "interfaceinformationimp.h" #include "interfacesetupimp.h" #include "interfaces.h" #include "module.h" /* OPIE */ #include <opie2/odebug.h> #include <opie2/oprocess.h> #include <opie2/oresource.h> #include <qpe/applnk.h> #include <qpe/qcopenvelope_qws.h> #include <qpe/qpeapplication.h> #include <qpe/config.h> #include <qpe/qlibrary.h> /* QT */ #include <qpushbutton.h> #include <qlistbox.h> #include <qlineedit.h> #include <qlistview.h> #include <qheader.h> #include <qlabel.h> #include <qtabwidget.h> // in order to disable the profiles tab #include <qmessagebox.h> #include <qtextstream.h> #include <qregexp.h> #if QT_VERSION < 0x030000 #include <qlist.h> #else #include <qptrlist.h> #endif #include <qdir.h> #include <qfile.h> #include <qtextstream.h> #include <qregexp.h> /* STD */ #include <net/if.h> #include <sys/ioctl.h> #include <sys/socket.h> #define DEFAULT_SCHEME "/var/lib/pcmcia/scheme" #define _PROCNETDEV "/proc/net/dev" // is this always right? #define _HOSTFILE "/etc/hostname" #define _IRDANAME "/proc/sys/net/irda/devname" using namespace Opie::Core; MainWindowImp::MainWindowImp(QWidget *parent, const char *name, WFlags) : MainWindow(parent, name, Qt::WStyle_ContextHelp), advancedUserMode(true), scheme(DEFAULT_SCHEME) { connect(addConnectionButton, SIGNAL(clicked()), this, SLOT(addClicked())); connect(removeConnectionButton, SIGNAL(clicked()), this, SLOT(removeClicked())); connect(informationConnectionButton, SIGNAL(clicked()), this, SLOT(informationClicked())); connect(configureConnectionButton, SIGNAL(clicked()), this, SLOT(configureClicked())); //remove tab with no function tabWidget->removePage( tab ); // Load connections. // /usr/local/kde/lib/libinterfaces.la loadModules(QPEApplication::qpeDir() + "plugins/networksettings"); getAllInterfaces(); Interfaces i; QStringList list = i.getInterfaceList(); QMap<QString, Interface*>::Iterator it; for ( QStringList::Iterator ni = list.begin(); ni != list.end(); ++ni ) { /* * we skipped it in getAllInterfaces now * we need to ignore it as well */ if (m_handledIfaces.contains( *ni) ) { odebug << "Not up iface handled by module" << oendl; continue; } bool found = false; for( it = interfaceNames.begin(); it != interfaceNames.end(); ++it ) { if(it.key() == (*ni)) found = true; } if(!found) { if(!(*ni).contains("_")) { Interface *i = new Interface(this, *ni, false); i->setAttached(false); i->setHardwareName(tr("Disconnected")); interfaceNames.insert(i->getInterfaceName(), i); updateInterface(i); connect(i, SIGNAL(updateInterface(Interface*)), this, SLOT(updateInterface(Interface*))); } } } //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(); QFileInfoListIterator it( *list ); QFileInfo *fi; while ( (fi=it.current()) ) { if(fi->fileName().contains(".so")) { /* if loaded install translation */ if( loadPlugin(path + "/" + fi->fileName()) != 0l ){ QTranslator *trans = new QTranslator(qApp); QString fn = QPEApplication::qpeDir()+"i18n/"+lang+"/"+ fi->fileName().left( fi->fileName().find(".") )+".qm"; if( trans->load( fn ) ) qApp->installTranslator( trans ); else delete trans; } odebug << "loaded plugin: >" << QString(path + "/" + fi->fileName()).latin1() << "< " << oendl; } ++it; } } /** * Attempt to load a function and resolve a function. * @param pluginFileName - the name of the file in which to attempt to load * @param resolveString - function pointer to resolve * @return pointer to the function with name resolveString or NULL */ Module* MainWindowImp::loadPlugin(const QString &pluginFileName, const QString &resolveString) { #ifdef DEBUG odebug << "MainWindowImp::loadPlugin: " << pluginFileName.latin1() << ": resolving " << resolveString.latin1() << "" << oendl; #endif QLibrary *lib = new QLibrary(pluginFileName); void *functionPointer = lib->resolve(resolveString); if( !functionPointer ) { #ifdef DEBUG odebug << "MainWindowImp::loadPlugin: Warning: " << pluginFileName.latin1() << " is not a plugin" << oendl; #endif delete lib; return 0; } // Try to get an object. Module *object = ((Module* (*)()) functionPointer)(); if(object == 0) { #ifdef DEBUG odebug << "MainWindowImp: Couldn't create object, but did load library!" << oendl; #endif delete lib; return 0; } m_handledIfaces += object->handledInterfaceNames(); // Store for deletion later libraries.insert(object, lib); return object; } /** * The Add button was clicked. Bring up the add dialog and if OK is hit * load the plugin and append it to the list */ void MainWindowImp::addClicked() { QMap<Module*, QLibrary*>::Iterator it; QMap<QString, QString> list; QMap<QString, Module*> newInterfaceOwners; for( it = libraries.begin(); it != libraries.end(); ++it ) { if(it.key()) { (it.key())->possibleNewInterfaces(list); } } // See if the list has anything that we can add. if(list.count() == 0) { QMessageBox::information(this, "Sorry", "Nothing to add.", QMessageBox::Ok); return; } AddConnectionImp addNewConnection(this, "AddConnectionImp", true); addNewConnection.addConnections(list); if( QDialog::Accepted == QPEApplication::execDialog( &addNewConnection ) ) { QListViewItem *item = addNewConnection.registeredServicesList->currentItem(); if(!item) return; for( it = libraries.begin(); it != libraries.end(); ++it ) { if(it.key()) { Interface *i = (it.key())->addNewInterface(item->text(0)); if(i) { odebug << "iface name " << i->getInterfaceName().latin1() << "" << oendl; interfaceNames.insert(i->getInterfaceName(), i); updateInterface(i); } } } } } /** * Prompt the user to see if they really want to do this. * If they do then remove from the list and unload. */ void MainWindowImp::removeClicked() { QListViewItem *item = connectionList->currentItem(); if(!item) { QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok); return; } Interface *i = interfaceItems[item]; if(i->getModuleOwner() == NULL) { QMessageBox::information(this, "Can't remove interface.", "Interface is built in.", QMessageBox::Ok); } else { if(!i->getModuleOwner()->remove(i)) QMessageBox::information(this, tr("Error"), tr("Unable to remove."), QMessageBox::Ok); else { delete item; // QMessageBox::information(this, "Success", "Interface was removed.", QMessageBox::Ok); } } } /** * Pull up the configure about the currently selected interface. * Report an error if no interface is selected. * If the interface has a module owner then request its configure. */ void MainWindowImp::configureClicked() { QListViewItem *item = connectionList->currentItem(); if(!item) { QMessageBox::information(this, tr("Sorry"),tr("Please select an interface first."), QMessageBox::Ok); return; } QString currentProfileText = currentProfileLabel->text(); if(currentProfileText.upper() == "ALL"); currentProfileText = ""; Interface *i = interfaceItems[item]; if(i->getModuleOwner()) { QWidget *moduleConfigure = i->getModuleOwner()->configure(i); if(moduleConfigure != NULL) @@ -479,307 +480,309 @@ void MainWindowImp::informationClicked() return; } Interface *i = interfaceItems[item]; // if(!i->isAttached()){ // QMessageBox::information(this, "Sorry","No information about\na disconnected interface.", QMessageBox::Ok); // return; // } if(i->getModuleOwner()) { QWidget *moduleInformation = i->getModuleOwner()->information(i); if(moduleInformation != NULL) { QPEApplication::showWidget( moduleInformation ); #ifdef DEBUG odebug << "MainWindowImp::informationClicked:: Module owner has created, we showed." << oendl; #endif return; } } InterfaceInformationImp *information = new InterfaceInformationImp(this, "InterfaceSetupImp", i, Qt::WType_Modal | Qt::WDestructiveClose | Qt::WStyle_Dialog | Qt::WStyle_ContextHelp); QPEApplication::showWidget( information ); } /** * Update this interface. If no QListViewItem exists create one. * @param Interface* pointer to the interface that needs to be updated. */ void MainWindowImp::updateInterface(Interface *i) { if(!advancedUserMode) { if(i->getInterfaceName() == "lo") return; } QListViewItem *item = NULL; // Find the interface, making it if needed. if(items.find(i) == items.end()) { item = new QListViewItem(connectionList, "", "", ""); // See if you can't find a module owner for this interface QMap<Module*, QLibrary*>::Iterator it; for( it = libraries.begin(); it != libraries.end(); ++it ) { if(it.key()->isOwner(i)) i->setModuleOwner(it.key()); } items.insert(i, item); interfaceItems.insert(item, i); } else item = items[i]; // Update the icons and information item->setPixmap( 0, Opie::Core::OResource::loadPixmap( i->getStatus() ? "up" : "down", Opie::Core::OResource::SmallIcon ) ); QString typeName = "lan"; if(i->getInterfaceName() == "lo") typeName = "lo"; if(i->getInterfaceName().contains("irda")) typeName = "irda"; if(i->getInterfaceName().contains("wlan")) typeName = "wlan"; if(i->getInterfaceName().contains("usb")) typeName = "usb"; if(!i->isAttached()) typeName = "connect_no"; // Actually try to use the Module if(i->getModuleOwner() != NULL) typeName = i->getModuleOwner()->getPixmapName(i); item->setPixmap( 1, ( Opie::Core::OResource::loadPixmap( "networksettings/" + typeName, Opie::Core::OResource::SmallIcon ) ) ); item->setText(2, i->getHardwareName()); item->setText(3, QString("(%1)").arg(i->getInterfaceName())); item->setText(4, (i->getStatus()) ? i->getIp() : QString("")); } void MainWindowImp::newProfileChanged(const QString& newText) { if(newText.length() > 0) newProfileButton->setEnabled(true); else newProfileButton->setEnabled(false); } /** * Adds a new profile to the list of profiles. * Don't add profiles that already exists. * Appends to the list and QStringList */ void MainWindowImp::addProfile() { QString newProfileName = newProfile->text(); if(profiles.grep(newProfileName).count() > 0) { QMessageBox::information(this, "Can't Add","Profile already exists.", QMessageBox::Ok); return; } profiles.append(newProfileName); profilesList->insertItem(newProfileName); } /** * Removes the currently selected profile in the combo. * Doesn't delete if there are less then 2 profiles. */ void MainWindowImp::removeProfile() { if(profilesList->count() <= 1) { QMessageBox::information(this, "Can't remove.","At least one profile\nis needed.", QMessageBox::Ok); return; } QString profileToRemove = profilesList->currentText(); if(profileToRemove == "All") { QMessageBox::information(this, "Can't remove.","Can't remove default.", QMessageBox::Ok); return; } // Can't remove the curent profile if(profileToRemove == currentProfileLabel->text()) { QMessageBox::information(this, "Can't remove.",QString("%1 is the current profile.").arg(profileToRemove), QMessageBox::Ok); return; } if(QMessageBox::information(this, "Question",QString("Remove profile: %1").arg(profileToRemove), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok) { profiles = QStringList::split(" ", profiles.join(" ").replace(QRegExp(profileToRemove), "")); profilesList->clear(); for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) profilesList->insertItem((*it)); // Remove any interface settings and mappings. Interfaces interfaces; // Go through them one by one QMap<Interface*, QListViewItem*>::Iterator it; for( it = items.begin(); it != items.end(); ++it ) { QString interfaceName = it.key()->getInterfaceName(); odebug << interfaceName.latin1() << oendl; if(interfaces.setInterface(interfaceName + "_" + profileToRemove)) { interfaces.removeInterface(); if(interfaces.setMapping(interfaceName)) { if(profilesList->count() == 1) interfaces.removeMapping(); else { interfaces.removeMap("map", interfaceName + "_" + profileToRemove); } } interfaces.write(); 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 @@ -515,514 +515,516 @@ QString Modem::parseModemSpeed(const QString &s) { // // Now extract the digits only from the match, which will // then be converted to an int. // if ((idx = rrx[RXMAX-1].match( sub,0,&len )) > -1) { // if ((idx = rrx[RXMAX-1].search( sub )) > -1) { // len = rrx[RXMAX-1].matchedLength(); sub = sub.mid(idx, len); result = sub.toInt(); if(result > 0) { rx = result; break; } } } } for(i = 0; i < TXMAX; i++) { int len, idx, result; if((idx = trx[i].match(s,0,&len)) > -1) { // if((idx = trx[i].search(s)) > -1) { // len = trx[i].matchedLength(); // // trx[i] has been matched, idx contains the start of the match // and len contains how long the match is. Extract the match. // QString sub = s.mid(idx, len); // // Now extract the digits only from the match, which will then // be converted to an int. // if((idx = rrx[RXMAX-1].match(sub,0,&len)) > -1) { // if((idx = rrx[RXMAX-1].search(sub)) > -1) { // len = rrx[RXMAX-1].matchedLength(); sub = sub.mid(idx, len); result = sub.toInt(); if(result > 0) { tx = result; break; } } } } if(rx == -1 && tx == -1) result = QObject::tr("Unknown speed"); else if(tx == -1) result.setNum(rx); else if(rx == -1) // should not happen result.setNum(tx); else result.sprintf("%d/%d", rx, tx); odebug << "The parsed result is: " << result.latin1() << "" << oendl; return result; } // Lock modem device. Returns 0 on success 1 if the modem is locked and -1 if // a lock file can't be created ( permission problem ) int Modem::lockdevice() { int fd; char newlock[80]=""; // safe if(!_pppdata->modemLockFile()) { odebug << "The user doesn't want a lockfile." << oendl; return 0; } if (modem_is_locked) return 1; QString lockfile = LOCK_DIR"/LCK.."; lockfile += _pppdata->modemDevice().mid(5); // append everything after /dev/ if(access(QFile::encodeName(lockfile), F_OK) == 0) { // if ((fd = Requester::rq-> if ((fd = openLockfile(QFile::encodeName(lockfile), O_RDONLY)) >= 0) { // Mario: it's not necessary to read more than lets say 32 bytes. If // file has more than 32 bytes, skip the rest char oldlock[33]; // safe int sz = read(fd, &oldlock, 32); close (fd); if (sz <= 0) return 1; oldlock[sz] = '\0'; odebug << "Device is locked by: " << oldlock << "" << oendl; int oldpid; int match = sscanf(oldlock, "%d", &oldpid); // found a pid in lockfile ? if (match < 1 || oldpid <= 0) return 1; // check if process exists if (kill((pid_t)oldpid, 0) == 0 || errno != ESRCH) return 1; odebug << "lockfile is stale" << oendl; } } fd = openLockfile(_pppdata->modemDevice(),O_WRONLY|O_TRUNC|O_CREAT); if(fd >= 0) { sprintf(newlock,"%010d\n", getpid()); odebug << "Locking Device: " << newlock << "" << oendl; write(fd, newlock, strlen(newlock)); close(fd); modem_is_locked=true; return 0; } return -1; } // UnLock modem device void Modem::unlockdevice() { if (modem_is_locked) { odebug << "UnLocking Modem Device" << oendl; close(modemfd); modemfd = -1; unlink(lockfile); lockfile[0] = '\0'; modem_is_locked=false; } } int Modem::openLockfile( QString lockfile, int flags) { int fd; int mode; flags = O_RDONLY; if(flags == O_WRONLY|O_TRUNC|O_CREAT) mode = 0644; else mode = 0; lockfile = LOCK_DIR; lockfile += "/LCK.."; lockfile += device.right( device.length() - device.findRev("/") -1 ); odebug << "lockfile >" << lockfile.latin1() << "<" << oendl; // TODO: // struct stat st; // if(stat(lockfile.data(), &st) == -1) { // if(errno == EBADF) // return -1; // } else { // // make sure that this is a regular file // if(!S_ISREG(st.st_mode)) // return -1; // } 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; memset(&buf, 0, sizeof(buf)); return stat("/dev/ppp", &buf); #endif } bool Modem::execpppd(const char *arguments) { char buf[MAX_CMDLEN]; char *args[MaxArgs]; pid_t pgrpid; if(modemfd<0) return false; _pppdExitStatus = -1; (void)::pipe( m_pppdLOG ); switch(pppdPid = fork()) { case -1: fprintf(stderr,"In parent: fork() failed\n"); ::close( m_pppdLOG[0] ); ::close( m_pppdLOG[1] ); return false; break; case 0: // let's parse the arguments the user supplied into UNIX suitable form // that is a list of pointers each pointing to exactly one word strlcpy(buf, arguments); parseargs(buf, args); // become a session leader and let /dev/ttySx // be the controlling terminal. pgrpid = setsid(); #ifdef TIOCSCTTY if(ioctl(modemfd, TIOCSCTTY, 0)<0) fprintf(stderr, "ioctl() failed.\n"); #elif defined (TIOCSPGRP) if(ioctl(modemfd, TIOCSPGRP, &pgrpid)<0) fprintf(stderr, "ioctl() failed.\n"); #endif if(tcsetpgrp(modemfd, pgrpid)<0) fprintf(stderr, "tcsetpgrp() failed.\n"); ::close( m_pppdLOG[0] ); ::setenv( "LANG", "C", 1 ); // overwrite dup2(m_pppdLOG[1], 11 ); // for logfd 11 dup2(modemfd, 0); dup2(modemfd, 1); switch (checkForInterface()) { case 1: fprintf(stderr, "Cannot determine if kernel supports ppp.\n"); break; case -1: fprintf(stderr, "Kernel does not support ppp, oops.\n"); break; case 0: fprintf(stderr, "Kernel supports ppp alright.\n"); break; } execve(pppdPath(), args, 0L); _exit(0); break; default: odebug << "In parent: pppd pid " << pppdPid << "\n" << oendl; close(modemfd); ::close( m_pppdLOG[1] ); // set it to nonblocking io int flag = ::fcntl( m_pppdLOG[0], F_GETFL ); if ( !(flag & O_NONBLOCK) ) { odebug << "Setting nonblocking io" << oendl; flag |= O_NONBLOCK; ::fcntl(m_pppdLOG[0], F_SETFL, flag ); } delete m_modemDebug; m_modemDebug = new QSocketNotifier(m_pppdLOG[0], QSocketNotifier::Read, this ); connect(m_modemDebug, SIGNAL(activated(int) ), this, SLOT(slotModemDebug(int) ) ); modemfd = -1; m_pppdDev = QString::fromLatin1("ppp0"); return true; break; } } bool Modem::killpppd() { odebug << "In killpppd and pid is " << pppdPid << "" << oendl; if(pppdPid > 0) { delete m_modemDebug; m_modemDebug = 0; odebug << "In killpppd(): Sending SIGTERM to " << pppdPid << "\n" << oendl; if(kill(pppdPid, SIGTERM) < 0) { odebug << "Error terminating " << pppdPid << ". Sending SIGKILL\n" << oendl; if(kill(pppdPid, SIGKILL) < 0) { odebug << "Error killing " << pppdPid << "\n" << oendl; return false; } } } return true; } void Modem::parseargs(char* buf, char** args) { int nargs = 0; int quotes; while(nargs < MaxArgs-1 && *buf != '\0') { quotes = 0; // Strip whitespace. Use nulls, so that the previous argument is // terminated automatically. while ((*buf == ' ' ) || (*buf == '\t' ) || (*buf == '\n' ) ) *buf++ = '\0'; // detect begin of quoted argument if (*buf == '"' || *buf == '\'') { quotes = *buf; *buf++ = '\0'; } // save the argument if(*buf != '\0') { *args++ = buf; nargs++; } if (!quotes) while ((*buf != '\0') && (*buf != '\n') && (*buf != '\t') && (*buf != ' ')) buf++; else { while ((*buf != '\0') && (*buf != quotes)) buf++; *buf++ = '\0'; } } *args = 0L; } bool Modem::execPPPDaemon(const QString & arguments) { if(execpppd(arguments)) { _pppdata->setpppdRunning(true); return true; } else return false; |