summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-gutenbrowser/LibraryDialog.cpp
Side-by-side diff
Diffstat (limited to 'noncore/apps/opie-gutenbrowser/LibraryDialog.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/apps/opie-gutenbrowser/LibraryDialog.cpp12
1 files changed, 7 insertions, 5 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,71 +1,71 @@
/***************************************************************************
// 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");
@@ -427,124 +427,127 @@ bool LibraryDialog::download_newEtext()
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);
// use new, improved, *INSTANT* network-dialog-file-getterer
if( NetworkDlg->exec() != 0 ) {
File_Name = 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());
+ if (rename( File_Name.latin1(), s_fileName.latin1()) == 1) {
+ owarn << "Failed to rename " << File_Name.latin1() << " to "
+ << s_fileName.latin1() << oendl;
+ return false;
+ }
+
File_Name = s_fileName;
//odebug << "Filename is now "+File_Name << oendl;
}
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 {
}
} else
QMessageBox::message("Note","<p>There was an error with the file</p>");
}
}
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";
@@ -656,97 +659,96 @@ bool LibraryDialog::setTitle()
}
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;
}