-rw-r--r-- | noncore/apps/opie-gutenbrowser/gutenbrowser.cpp | 27 | ||||
-rw-r--r-- | noncore/apps/opie-gutenbrowser/gutenbrowserData.cpp | 18 |
2 files changed, 25 insertions, 20 deletions
diff --git a/noncore/apps/opie-gutenbrowser/gutenbrowser.cpp b/noncore/apps/opie-gutenbrowser/gutenbrowser.cpp index 413ab51..e639d4d 100644 --- a/noncore/apps/opie-gutenbrowser/gutenbrowser.cpp +++ b/noncore/apps/opie-gutenbrowser/gutenbrowser.cpp @@ -1,426 +1,427 @@ /*************************************************************************** gutenbrowser.cpp - description ------------------- begin : Mon Jul 24 22:33:12 MDT 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. * ***************************************************************************/ // http search // http://digital.library.upenn.edu/books/authors.html // http://digital.library.upenn.edu/books/titles.html // ftp://ibiblio.org/pub/docs/books/gutenberg/GUTINDEX.ALL // donate@gutenberg.net #include "editTitle.h" #include "gutenbrowser.h" #include "LibraryDialog.h" //#include "bookmarksdlg.h" #include "optionsDialog.h" #include "helpme.h" #include "NetworkDialog.h" #include "openetext.h" #include "output.h" /* OPIE */ #include <opie2/odebug.h> +#include <opie2/oresource.h> + #include <qpe/qpeapplication.h> #include <qpe/fontdatabase.h> #include <qpe/config.h> #include <qpe/qcopenvelope_qws.h> #include <qpe/mimetype.h> -#include <qpe/resource.h> #include <qpe/applnk.h> /* QT */ #include <qregexp.h> #include <qregion.h> #include <qpaintdevicemetrics.h> #include <qvaluelist.h> #include <qlabel.h> #include <qclipboard.h> #include <qpainter.h> #include <qpalette.h> #include <qobjectlist.h> #include <qfontdialog.h> #include <qtextview.h> #include <qbrush.h> #include <qfile.h> #include <qfontinfo.h> #include <qscrollview.h> #include <qpoint.h> /* STD */ #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/stat.h> #include <fcntl.h> #include <errno.h> static const int nfontsizes = 9; static const int fontsize[nfontsizes] = {8,9,10,11,12,13,14,18,24}; #ifdef NOQUICKLAUNCH Gutenbrowser::Gutenbrowser() Gutenbrowser(); #else Gutenbrowser::Gutenbrowser(QWidget *,const char*, WFlags ) #endif : QMainWindow() { // QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; // QCopEnvelope e("QPE/System", "grabKeyboard(QString)" ); // e << ""; // QPEApplication::grabKeyboard(); showMainList=TRUE; working=false; this->setUpdatesEnabled(TRUE); // #ifndef Q_WS_QWS QString msg; msg="You have now entered unto gutenbrowser,\n"; msg+="make your self at home, sit back, relax and read something great.\n"; local_library = (QDir::homeDirPath ()) +"/Applications/gutenbrowser/"; setCaption("Gutenbrowser");// Embedded " VERSION); this->setUpdatesEnabled(TRUE); // bool firstTime=FALSE; topLayout = new QVBoxLayout( this, 0, 0, "topLayout"); menu = new QHBoxLayout(-1,"menu"); buttons2 = new QHBoxLayout(-1,"buttons2"); edits = new QHBoxLayout(-1,"edits"); useSplitter=TRUE; initConfig(); initMenuBar(); initButtonBar(); initStatusBar(); initView(); initSlots(); qDebug("init finished"); QPEApplication::setStylusOperation( mainList->viewport(),QPEApplication::RightOnHold); connect( mainList, SIGNAL( mouseButtonPressed( int, QListBoxItem *, const QPoint &)), this, SLOT( mainListPressed(int, QListBoxItem *, const QPoint &)) ); if( useIcons) toggleButtonIcons( TRUE); else toggleButtonIcons( FALSE); enableButtons(false); Config config("Gutenbrowser"); // populate menubuttonlist config.setGroup("General"); config.setGroup( "Files" ); QString s_numofFiles = config.readEntry("NumberOfFiles", "0" ); int i_numofFiles = s_numofFiles.toInt(); QString tempFileName; for (int i = 0; i <= i_numofFiles; i++) { // tempFileName.setNum(i); config.setGroup( "Files" ); QString ramble = config.readEntry( QString::number(i), "" ); config.setGroup( "Titles" ); QString tempTitle = config.readEntry( ramble, ""); config.setGroup( tempTitle); int index = config.readNumEntry( "LineNumber", -1 ); if( index != -1) { odebug << tempTitle << oendl; if(!tempTitle.isEmpty()) bookmarksMenu->insertItem( tempTitle); } } QString gutenIndex = local_library + "/GUTINDEX.ALL"; qDebug("gutenindex "+gutenIndex ); if( QFile( gutenIndex).exists() ) { indexLib.setName( gutenIndex); } else { QString localLibIndexFile = local_library + "/PGWHOLE.TXT"; // QString localLibIndexFile= local_library + "PGWHOLE.TXT"; newindexLib.setName( localLibIndexFile); } qDebug("attempting new library"); LibraryDlg = new LibraryDialog( this, "Library Index" /*, TRUE */); loadCheck = false; chdir(local_library); if(!showMainList) { Lview->setFocus(); // if(firstTime) // Bookmark(); for (int i=1;i< qApp->argc();i++) { qDebug("Suppose we open somethin"); if(!load(qApp->argv()[i])) return; } } else { fillWithTitles(); mainList->setFocus(); // mainList->setCurrentItem(0); } writeConfig(); QTimer::singleShot( 250, this, SLOT(hideView()) ); } //end init Gutenbrowser::~Gutenbrowser() { // QPEApplication::grabKeyboard(); // QPEApplication::ungrabKeyboard(); odebug << "Exit" << oendl; } /* Google.com search */ void Gutenbrowser::InfoBarClick() { QString text; if( Lview->hasSelectedText()) { Lview->copy(); QClipboard *cb = QApplication::clipboard(); text = cb->text(); } else { // text=title; text=this->caption(); } searchGoogle(text); } /* download http with wget or preferred browser */ void Gutenbrowser::goGetit( const QString &url, bool showMsg) { QString cmd; qApp->processEvents(); QString filename = local_library + "/GUTINDEX.ALL"; // QString filename = old_index; // filename += url.right( url.length() - url.findRev("/",-1,TRUE) -1); Config cfg("Gutenbrowser"); cfg.setGroup("FTPsite"); ftp_host=cfg.readEntry("SiteName", "sailor.gutenberg.org"); ftp_base_dir= cfg.readEntry("base", "/pub/gutenberg"); // Config config("Gutenbrowser"); // config.setGroup( "Browser" ); // QString brow = config.readEntry("Preferred", "Opera"); // //odebug << "Preferred browser is "+brow << oendl; if(!showMsg) { //if we just get the gutenindex.all // QString cmd="wget -O " + gutenindex1 + " http://sailor.gutenberg.org/GUTINDEX.ALL 2>&1"; cmd="wget -O " + filename +" " + url+" 2>&1" ; chdir(local_library); // //odebug << "Issuing the system command: " << cmd << "" << oendl; Output *outDlg; 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(); } outDlg->close(); if(outDlg) delete outDlg; } else { if( brow == "Konq") { cmd = "konqueror "+url+" &"; } if( brow == "Opera") { //for desktop testing cmd = "opera "+url+" &"; } // if( brow == "Opera") { // on Zaurus // cmd = "operagui "+url+" &"; // } if( brow == "Mozilla") { cmd = "mozilla "+url+" &"; } if( brow == "Netscape") { cmd = "netscape "+url+" &"; } if(brow == "wget") { // cmd="wget -q "+url+" &"; QString tempHtml=local_library+"webster.html"; cmd="wget -O "+tempHtml+" -q "+url; } chdir(local_library); // //odebug << "Issuing the sys command: " << cmd << "" << oendl; system(cmd); } } void Gutenbrowser::toggleButtonIcons( bool useEm) { QString pixDir; if(useEm) useEm=TRUE; pixDir=QPEApplication::qpeDir()+"pics/gutenbrowser"; odebug << "Docdir is "+QPEApplication::documentDir() << oendl; if( useIcons && QDir( pixDir).exists() ) { - LibraryButton->setPixmap( Resource::loadPixmap("home") ); //in inline - OpenButton->setPixmap( Resource::loadPixmap("gutenbrowser/openbook")); - ForwardButton->setPixmap( Resource::loadPixmap("forward"));//in inline - BackButton->setPixmap( Resource::loadPixmap("back") );//in inline - SearchButton->setPixmap( Resource::loadPixmap("gutenbrowser/search") );//in inline - lastBmkButton->setPixmap( Resource::loadPixmap("gutenbrowser/bookmark_folder")); - setBookmarkButton->setPixmap( Resource::loadPixmap("gutenbrowser/bookmark") ); - dictionaryButton->setPixmap( Resource::loadPixmap("gutenbrowser/spellcheck") ); - InfoBar->setPixmap( Resource::loadPixmap("gutenbrowser/google")); + LibraryButton->setPixmap( Opie::Core::OResource::loadPixmap("home", Opie::Core::OResource::SmallIcon ) ); + OpenButton->setPixmap( Opie::Core::OResource::loadPixmap("gutenbrowser/openbook", Opie::Core::OResource::SmallIcon )); + ForwardButton->setPixmap( Opie::Core::OResource::loadPixmap("forward", Opie::Core::OResource::SmallIcon )); + BackButton->setPixmap( Opie::Core::OResource::loadPixmap("back", Opie::Core::OResource::SmallIcon ) ); + SearchButton->setPixmap( Opie::Core::OResource::loadPixmap("gutenbrowser/search", Opie::Core::OResource::SmallIcon ) ); + lastBmkButton->setPixmap( Opie::Core::OResource::loadPixmap("gutenbrowser/bookmark_folder", Opie::Core::OResource::SmallIcon )); + setBookmarkButton->setPixmap( Opie::Core::OResource::loadPixmap("gutenbrowser/bookmark", Opie::Core::OResource::SmallIcon ) ); + dictionaryButton->setPixmap( Opie::Core::OResource::loadPixmap("gutenbrowser/spellcheck", Opie::Core::OResource::SmallIcon ) ); + InfoBar->setPixmap( Opie::Core::OResource::loadPixmap("gutenbrowser/google", Opie::Core::OResource::SmallIcon )); } } bool Gutenbrowser::queryExit() { int exit=QMessageBox::information(this, "Quit...", "Do your really want to quit?", QMessageBox::Ok, QMessageBox::Cancel); if (exit==1) { writeConfig(); qApp->quit(); } else { }; return (exit==1); } // SLOT IMPLEMENTATION void Gutenbrowser::slotFilePrint() { } void Gutenbrowser::ByeBye() { if (b_queryExit) queryExit(); else { // writeConfig(); qApp->quit(); } } void Gutenbrowser::HelpBtn() { HelpMe* HelpDlg; HelpDlg = new HelpMe( this, "Help Dialog"); HelpDlg->showMaximized(); } void Gutenbrowser::DownloadIndex() { #ifndef Q_WS_QWS { switch( QMessageBox::information( 0, (tr("Download Library Index, or FTP sites?")), (tr("Do you want to download the newest\n" "Project Gutenberg Library Index?\n" "or select an ftp site?\n")), (tr("&Library Index")), (tr("&Ftp Site")), (tr("&Cancel")), 2, 2 ) ) { case 0: // index clicked, downloadLibIndex(); break; case 1: // ftp selected downloadFtpList(); break; case 2: // Cancel break; }; } #endif } // end DownloadIndex void Gutenbrowser::downloadFtpList() { // QString cmd="wget http://www.promo.net/pg/list.html"); //system(cmd); qApp->processEvents(); optionsDialog* optDlg; optDlg = new optionsDialog( this,"Options_Dlg", true); optDlg->getSite(); if(optDlg) delete optDlg; } void Gutenbrowser::downloadLibIndex() { // QString dwmloader = local_library + "pgwhole.zip"; // QString cmd = "lynx -source http://www.gutenberg.net/pgwhole.zip | cat >> " + dwmloader; // system(cmd); // QString outputFile= local_library+ "GUTINDEX.ALL"; // config.setGroup( "FTPsite" ); // ftp server config // ftp_host=config.readEntry("SiteName", ""); // ftp_base_dir= config.readEntry("base", ""); // QString networkUrl= "ftp://"+ftp_host+ftp_base_dir+"/GUTINDEX.ALL"; QDir dir( local_library); dir.cd("", TRUE); goGetit( "http://sailor.gutenberg.org/GUTINDEX.ALL", false); // until ghttp works on binaries -qt3 // goGetit( "http://www.gutenberg.net/pgwhole.zip", true); // until ghttp works on binaries -qt3 // NetworkDialog *NetworkDlg; // NetworkDlg = new NetworkDialog( this,"Network Protocol Dialog", TRUE, 0, networkUrl, outputFile ); // if( NetworkDlg->exec() != 0 ) // { // use new, improved, *INSTANT* network-dialog-file-getterer //// QMessageBox::message("Note",""); // } // if(NetworkDlg) // delete NetworkDlg; } void Gutenbrowser::PrintBtn() { } void Gutenbrowser::SearchBtn() { if( loadCheck) { odebug << "loadCheck: we have a loaded doc" << oendl; Search(); } // else // QMessageBox::message("Note","Sorry, can't search. No etext is loaded"); } void Gutenbrowser::ForwardBtn() { if( !ForwardButton->autoRepeat() && !ForwardButton->isDown()) { QString s; QString insertString; int pageSize= Lview->PageSize(); Lview->clear(); for(int fd=0; fd < pageSize - 1;fd++) { f.readLine(s, 256); if(useWrap) s.replace(QRegExp("\n"),""); insertString+=s; Lview->insertLine( s, -1); // odebug << s << oendl; currentLine++; @@ -1646,361 +1647,363 @@ void Gutenbrowser::writeConfig() // config.writeEntry("Frame", s); // config.writeEntry("Position", globalPosition); // if( useIcons==TRUE) // config.writeEntry("Icons", "TRUE"); // else // config.writeEntry("Icons", "FALSE"); // #endif // #ifndef Q_WS_QWS // QString temp; // temp.setNum(styleI, 10); // config.setGroup( "StyleIze" ); // config.writeEntry( "Style", temp); // #endif // config.setGroup("General"); } void Gutenbrowser::annotations() { // #ifndef Q_WS_QWS // QMessageBox::message("Note","hi annotate"); // lastBmkButton->setDown(FALSE); // #endif } void Gutenbrowser::hideButtons() { if( !buttonsHidden) { buttonsHidden=TRUE; LibraryButton->hide(); SearchButton->hide(); InfoBar->hide(); OpenButton->hide(); BackButton->hide(); ForwardButton->hide(); setBookmarkButton->hide(); lastBmkButton->hide(); dictionaryButton->hide(); if(useSplitter) { ClearButton->hide(); PrintButton->hide(); beginButton->hide(); HelpButton->hide(); FontButton->hide(); ExitButton->hide(); OptionsButton->hide(); DownloadButton->hide(); } } else { buttonsHidden=FALSE; LibraryButton->show(); SearchButton->show(); InfoBar->show(); OpenButton->show(); BackButton->show(); ForwardButton->show(); setBookmarkButton->show(); lastBmkButton->show(); dictionaryButton->show(); if(useSplitter) { ClearButton->show(); PrintButton->show(); beginButton->show(); HelpButton->show(); FontButton->show(); ExitButton->show(); OptionsButton->show(); DownloadButton->show(); } } } void Gutenbrowser::focusInEvent( QFocusEvent* ) { } void Gutenbrowser::focusOutEvent( QFocusEvent* ) { } void Gutenbrowser::cleanUp( ) { writeConfig(); QPEApplication::grabKeyboard(); QPEApplication::ungrabKeyboard(); // odebug << "Cleanup" << oendl; if(f.isOpen()) f.close(); } void Gutenbrowser::fixKeys() { odebug << "Attempting to fix keys" << oendl; } void Gutenbrowser::enableButtons(bool b) { BackButton->setEnabled(b); ForwardButton->setEnabled(b); SearchButton->setEnabled(b); setBookmarkButton->setEnabled(b); dictionaryButton->setEnabled(b); InfoBar->setEnabled(b); editMenu->setItemEnabled( -5, b); editMenu->setItemEnabled( -6, b); editMenu->setItemEnabled( -7, b); editMenu->setItemEnabled( -8, b); } void Gutenbrowser::fillWithTitles() { Config config("Gutenbrowser"); config.setGroup( "Files" ); int i_numofFiles = config.readNumEntry("NumberOfFiles", 0); mainList->clear(); QString temp; for (int i = 1; i <= i_numofFiles; i++) { temp.setNum(i); config.setGroup( "Files" ); QString ramble = config.readEntry(temp, "" ); config.setGroup( "Titles" ); temp = config.readEntry(ramble, ""); if( !temp.isEmpty()) { - mainList->insertItem ( Resource::loadPixmap("gutenbrowser/gutenbrowser_sm"), temp, -1); + mainList->insertItem ( Opie::Core::OResource::loadPixmap("gutenbrowser/gutenbrowser_sm", + Opie::Core::OResource::SmallIcon ), temp, -1); } } } void Gutenbrowser::listClickedSlot( QListBoxItem * index) { // if( !working) { // working=true; if(index) { // QCopEnvelope ( "QPE/System", "busy()" ); title = index->text(); showMainList=FALSE; mainList->hide(); Lview->show(); qApp->processEvents(); QString temp; temp.setNum( mainList->currentItem() + 1); // openFileTitle = title; Config config("Gutenbrowser"); config.setGroup( "Files" ); QString file = config.readEntry(temp, ""); odebug << "About to load" << oendl; if( Lview->isVisible()) if(!load(file)) return; config.setGroup( title); file_name = config.readEntry("File Name", ""); i_pageNum = config.readNumEntry("Page Number", 1); int Bmrkrow = config.readNumEntry("LineNumber", -1); if(Bmrkrow > -1) { if( Bmrkrow > Lview->topRow() ) { // Lview->setCursorPosition( Bmrkrow /* - Lview->topRow() */,0, FALSE ); Lview->ScrollUp( Bmrkrow - Lview->topRow() ); // AdjustStatus(); } else if( Bmrkrow < Lview->topRow() ) { // Lview->setCursorPosition( Lview->topRow() - Bmrkrow ,0, FALSE ); Lview->ScrollDown( Lview->topRow() - Bmrkrow ); // AdjustStatus(); } } } } void Gutenbrowser::infoGutenbrowser() { QMessageBox::message("Info","Gutenbrowser was developed by\n" "Lorn Potter\n" "ljp<ljp@llornkcor.com>\n"); } void Gutenbrowser::setDocument(const QString & frozenBoogers) { // this->hide(); qWarning("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXSET DOCUMENT\n"); if(showMainList) { showMainList=FALSE; if(!mainList->isHidden()) mainList->hide(); if(Lview->isHidden()) Lview->show(); qApp->processEvents(); } DocLnk lnk; lnk = DocLnk(frozenBoogers); qWarning("open "+frozenBoogers); // odebug << lnk.file() << oendl; title=lnk.comment(); if(!load( lnk.file())) return; this->show(); // odebug << title << oendl; // qApp->processEvents(); // repaint(); } void Gutenbrowser::mainListPressed(int mouse, QListBoxItem * , const QPoint & ) { switch (mouse) { case 1: break; case 2: { QPopupMenu m;// = new QPopupMenu( Local_View ); m.insertItem( tr( "Open" ), this, SLOT( menuOpen() )); m.insertSeparator(); m.insertItem( tr( "Search google.com" ), this, SLOT( menuGoogle())); m.insertItem( tr( "Edit Title" ), this, SLOT( menuEditTitle())); // m.insertSeparator(); // m.insertItem( tr( "Delete" ), this, SLOT( remoteDelete() )); m.exec( QCursor::pos() ); } break; }; } void Gutenbrowser::menuOpen() { listClickedSlot( mainList->item( mainList->currentItem())); } void Gutenbrowser::menuGoogle() { searchGoogle( mainList->text(mainList->currentItem())); } void Gutenbrowser::searchGoogle( const QString &tempText) { QString text = tempText; int eexit=QMessageBox::information(this, "Note","Do you want to search for\n"+text+ "\non google.com?",QMessageBox::Yes, QMessageBox::No); if (eexit== 3) { qApp->processEvents(); text.replace( QRegExp("\\s"), "%20"); text.replace( QRegExp("#"), ""); text.replace( QRegExp(","), "%20"); text.replace( QRegExp("'"), "%20"); text.replace( QRegExp("("), ""); text.replace( QRegExp(")"), ""); // text.replace( QRegExp("[0-9]"), ""); QString s_lookup = "http://google.com/search?q="+text+"&num=30&sa=Google+Search"; goGetit( s_lookup, true); } } void Gutenbrowser::menuEditTitle() { int currentItem = mainList->currentItem(); QString title_text = mainList->text( currentItem); //odebug << "Selected "+title_text << oendl; Config config("Gutenbrowser"); config.setGroup( "Files" ); QString 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; if(title_text == file_title ) { // selFile = s_filename; //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; config.writeEntry( s_filename, titleEdit->newTitle); mainList->removeItem(currentItem); - mainList->insertItem ( Resource::loadPixmap("gutenbrowser/gutenbrowser_sm"), titleEdit->newTitle, currentItem); + mainList->insertItem ( Opie::Core::OResource::loadPixmap("gutenbrowser/gutenbrowser_sm", + Opie::Core::OResource::SmallIcon ), titleEdit->newTitle, currentItem); } } } // getTitles(); mainList->triggerUpdate(true); } bool Gutenbrowser::UnZipIt(const QString &zipFile) { odebug << zipFile << oendl; #ifndef Q_WS_QWS if( QFile::exists( zipFile)) { // TODO findsome other way of dealingwithzip files. bool isPgWhole=false; QString thatFile; if(zipFile.find("pgwhole",0,TRUE)) { isPgWhole=TRUE; thatFile= local_library +"PGWHOLE.TXT"; } // else { // thatFile=zipFile.left(4); // } // odebug << (const char*)local_library.latin1() << oendl; QString cmd; #if defined(_WS_X11_) if( chdir((const char*)local_library.latin1())!=0) odebug << "chdir failed." << oendl; cmd = "gunzip -S .zip " + local_library+zipFile; //cmd = "gunzip -d " + zipFile /*newestLibraryFile */+" -d " + local_library; #endif #ifdef Q_WS_QWS if( chdir((const char*)local_library.latin1())!=0) odebug << "chdir failed." << oendl; cmd = "unzip " + local_library+zipFile; // cmd = "/usr/bin/unzip -o " + local_library+zipFile +" -d /usr/share/doc/gutenbrowser" ;//+ local_library; #endif int exit=QMessageBox::information(this, "Ok to unzip?", "Ok to unnzip\n"+ zipFile+" ?", QMessageBox::Yes, QMessageBox::No); if (exit==QMessageBox::Yes) { #if defined(_WS_X11_)// odebug << "Issuing the command "+cmd << oendl; system( cmd); if( QFile::exists(thatFile)) remove (thatFile); if(isPgWhole) { if( rename("pgwhole","PGWHOLE.TXT") !=0) odebug << "rename failed" << oendl; } else { if( rename(thatFile.left(4),thatFile.left(4)+".txt") !=0) odebug << "rename failed" << oendl; } #endif #ifdef Q_WS_QWS odebug << "Issuing the command "+cmd << oendl; system( cmd); if( QFile::exists(thatFile)) remove(thatFile); if(isPgWhole) { if( rename("pgwhole","PGWHOLE.TXT") !=0) odebug << "rename failed" << oendl; } else { if( rename(thatFile.left(4),thatFile.left(4)+".txt") !=0) odebug << "rename failed" << oendl; } #endif // remove( zipFile); return true; } else if(exit==QMessageBox::No) { // odebug << "unzip" << oendl; return false; } } else QMessageBox::message( "Note",( tr("Please install unzip in your PATH")) ); #endif return false; } diff --git a/noncore/apps/opie-gutenbrowser/gutenbrowserData.cpp b/noncore/apps/opie-gutenbrowser/gutenbrowserData.cpp index c93dbc5..d384c09 100644 --- a/noncore/apps/opie-gutenbrowser/gutenbrowserData.cpp +++ b/noncore/apps/opie-gutenbrowser/gutenbrowserData.cpp @@ -1,328 +1,330 @@ /*************************************************************************** gutenbrowser.cpp - description ------------------- begin : Mon Jul 24 22:33:12 MDT 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 "gutenbrowserData.h" #include "gutenbrowser.h" #include "multiline_ex.h" /* OPIE */ #include <opie2/odebug.h> +#include <opie2/oresource.h> + #include <qpe/config.h> #include <qpe/fontdatabase.h> #include <qpe/menubutton.h> #include <qpe/resource.h> #include <qpe/qpeapplication.h> /* QT */ #include <qfontinfo.h> #include <qtoolbutton.h> void Gutenbrowser::initSlots() { connect(LibraryButton,SIGNAL(released()),SLOT(LibraryBtn())); connect(OpenButton,SIGNAL(released()),SLOT(OpenBtn())); connect(SearchButton,SIGNAL(released()),SLOT(SearchBtn())); connect(ForwardButton,SIGNAL(clicked()),SLOT(ForwardBtn())); connect(BackButton,SIGNAL(clicked()),SLOT(BackBtn())); connect(setBookmarkButton,SIGNAL(released()),SLOT(setBookmark())); connect(dictionaryButton,SIGNAL(released()),SLOT(LookupBtn())); connect(InfoBar,SIGNAL(clicked()),SLOT(InfoBarClick())); connect(qApp,SIGNAL(aboutToQuit()),SLOT(cleanUp())); connect(mainList,SIGNAL(clicked(QListBoxItem *)),SLOT(listClickedSlot(QListBoxItem *))); connect(bookmarksMenu,SIGNAL(activated(int)),SLOT(Bookmark(int))); } void Gutenbrowser::initConfig() { //odebug << "Starting configuration." << oendl; QDir library(local_library); if ( !library.exists()) { library.mkdir(local_library, TRUE); QString msg; // #ifndef Q_WS_WIN msg = "chmod 755 " + local_library; system(msg); // QDir pixdir(local_library+"pix"); // if ( !pixdir.exists()) { // pixdir.mkdir(local_library+"pix", TRUE); // QString msg; // msg = "chmod 755 " + local_library+"pix"; // system(msg); // } // #endif } qDebug("init file is " + iniFile );; #ifdef Q_WS_QWS useSplitter=FALSE; Config config("Gutenbrowser"); config.setGroup( "General" ); //useWordWrap_CheckBox useIcons=TRUE; #else config.setGroup( "General" ); QString s_Split=config.readEntry("Splitter", "TRUE" ); QWidget *d = QApplication::desktop(); int width=d->width(); int height=d->height(); int w=0, h=0; QString str, str2; this->setMaximumWidth(width); if(s_Split=="TRUE") useSplitter=TRUE; else useSplitter=FALSE; config.setGroup( "Geometry" ); if(width < 1030) { str = config.readEntry("Frame", "700,500"); if( !str.isEmpty() && str.find(',')>=0) { sscanf(str,"%d,%d",&w,&h); resize(w,h); str2.sprintf("%d,%d", (width-w)/2,(height-h)/2); str = config.readEntry( "Position", str2); } else { resize( 740,510 ); str2.sprintf("%d,%d", (width-w)/2,(height-h)/2); str = config.readEntry( "Position",str2); } } else {// desktop is high res str = config.readEntry("Frame", "990,640"); if( !str.isEmpty() && str.find(',')>=0) { sscanf(str,"%d,%d",&w,&h); resize(w,h); str2.sprintf("%d,%d", (width-w)/2,(height-h)/2); str = config.readEntry( "Position", str2); } else { resize( 990,640 ); str2.sprintf("%d,%d", (width-w)/2,(height-h)/2); str = config.readEntry( "Position", str2); } } int posX, posY; bool ok; QString goober; goober=str.left( str.find(",", 0, TRUE) ); posX=goober.toInt( &ok, 10); goober=str.right( str.findRev(",", -1, TRUE) ); posY= goober.toInt( &ok, 10); // move( posX, posY); str = config.readEntry("Icons", "TRUE"); if(str == "TRUE") useIcons=TRUE; else useIcons=FALSE; #endif // #if defined(_WS_WIN_) // move( posX-4, posY-20); // #endif config.setGroup( "Browser" ); brow = config.readEntry( "Preferred", "Opera"); config.setGroup( "FTPsite" ); // ftp server config ftp_host=config.readEntry("SiteName", "sailor.gutenberg.org"); // ftp_host=ftp_host.right(ftp_host.length()-(ftp_host.find(") ",0,TRUE)+1) ); 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"); //bool ok2; QString temp; QString copying; copying=""; config.setGroup("General"); QString qExit; qExit=config.readEntry("queryExit","TRUE"); if(qExit=="TRUE") { b_queryExit=TRUE; qDebug("lease query before leaving the library.");; } else { qDebug("Please DO NOT query before leaving the library."); b_queryExit=FALSE; } // bookmarks // config.setGroup("Titles"); // QString tmpTitle=config.readEntry(file_name,""); }// end initConfig() void Gutenbrowser::initMenuBar() { qDebug("Starting menu init."); // menuBar entry fileMenu menubar = new QPEMenuBar(this); fileMenu=new QPopupMenu(); - fileMenu->insertItem(Resource::loadPixmap("gutenbrowser/openbook"), + fileMenu->insertItem( Opie::Core::OResource::loadPixmap("gutenbrowser/openbook", Opie::Core::OResource::SmallIcon ), "Open Local Library...", this, SLOT( OpenBtn()) ); // fileMenu->insertItem("Download FTPSite", this, SLOT( downloadFtpList()) ); - fileMenu->insertItem( Resource::loadPixmap("home"), + fileMenu->insertItem( Opie::Core::OResource::loadPixmap("home", Opie::Core::OResource::SmallIcon ), "Download Library Index", this, SLOT( downloadLibIndex()) ); - fileMenu->insertItem( Resource::loadPixmap("quit"), + fileMenu->insertItem( Opie::Core::OResource::loadPixmap("quit", Opie::Core::OResource::SmallIcon ), "Quit Gutenbrowser...", this, SLOT( ByeBye()) ); // menuBar entry editMenu editMenu=new QPopupMenu(); - editMenu->insertItem(Resource::loadPixmap("up"), "Top", + editMenu->insertItem( Opie::Core::OResource::loadPixmap("up", Opie::Core::OResource::SmallIcon ), "Top", this, SLOT(TopBtn()) ); - editMenu->insertItem( Resource::loadPixmap("back"), "Beginning", + editMenu->insertItem( Opie::Core::OResource::loadPixmap("back", Opie::Core::OResource::SmallIcon ), "Beginning", this, SLOT(doBeginBtn()) ); - editMenu->insertItem( Resource::loadPixmap("gutenbrowser/search"), "Search", + editMenu->insertItem( Opie::Core::OResource::loadPixmap("gutenbrowser/search", Opie::Core::OResource::SmallIcon ), "Search", this, SLOT(SearchBtn()) ); editMenu->insertItem("Clear", this, SLOT(ClearEdit()) ); optionsMenu= new QPopupMenu(); - optionsMenu->insertItem( Resource::loadPixmap("gutenbrowser/configure"), + optionsMenu->insertItem( Opie::Core::OResource::loadPixmap("gutenbrowser/configure", Opie::Core::OResource::SmallIcon ), "Configure", this, SLOT(doOptions()) ); donateMenu = new QPopupMenu(); // donateMenu->insertItem("Gutenberg", this, SLOT(donateGutenberg()) ); - donateMenu->insertItem( Resource::loadPixmap("gutenbrowser/gutenbrowser_sm"), + donateMenu->insertItem( Opie::Core::OResource::loadPixmap("gutenbrowser/gutenbrowser_sm", Opie::Core::OResource::SmallIcon ), "Gutenbrowser Developer", this, SLOT(infoGutenbrowser()) ); menubar->insertItem("File", fileMenu); menubar->insertItem("Page", editMenu); menubar->insertItem("Options", optionsMenu); // menubar->insertItem("More Info", donateMenu); menu->addWidget( menubar,0); topLayout->addLayout( menu, 0); } void Gutenbrowser::initButtonBar() { qDebug("Starting buttonbar init."); OpenButton = new QPushButton( this, "OpenButton" ); OpenButton->setFocusPolicy( QWidget::TabFocus ); LibraryButton = new QPushButton( this, "LibraryButton" ); LibraryButton->setFocusPolicy( QWidget::TabFocus ); BackButton = new QPushButton( this, "BackButton" ); BackButton->setFocusPolicy( QWidget::TabFocus ); BackButton->setAutoRepeat(TRUE); ForwardButton = new QPushButton( this, "ForwardButton" ); ForwardButton->setFocusPolicy( QWidget::TabFocus ); // ForwardButton->setAutoRepeat(TRUE); SearchButton = new QPushButton( this, "SearchButton" ); SearchButton->setFocusPolicy( QWidget::TabFocus ); setBookmarkButton = new QPushButton( this, "setBookmark" ); setBookmarkButton->setFocusPolicy( QWidget::TabFocus ); lastBmkButton = new MenuButton( this, "lastBmkButton" ); lastBmkButton->setFocusPolicy( QWidget::TabFocus ); bookmarksMenu = new QPopupMenu(); bookmarksMenu->insertItem("Last Set", this, SLOT(Bookmark( int) )); lastBmkButton->setPopup(bookmarksMenu); dictionaryButton = new QPushButton( this, "dictionaryButton" ); dictionaryButton->setFocusPolicy( QWidget::TabFocus ); InfoBar = new QPushButton( this, "Info_Bar" ); // if(!useSplitter) { buttonsHidden=FALSE; buttons2->setSpacing(2); buttons2->addWidget(OpenButton, 0, AlignCenter); buttons2->addWidget(LibraryButton, 0, AlignCenter); buttons2->addWidget(BackButton, 0, AlignCenter); buttons2->addWidget(ForwardButton, 0, AlignCenter); buttons2->addWidget(SearchButton, 0, AlignCenter); buttons2->addWidget(setBookmarkButton, 0, AlignCenter); buttons2->addWidget(lastBmkButton, 0, AlignCenter); buttons2->addWidget(dictionaryButton, 0, AlignCenter); buttons2->addWidget(InfoBar, 0, AlignCenter); topLayout->setSpacing(0); topLayout->addLayout( buttons2,0); } /* STATUSBAR*/ void Gutenbrowser::initStatusBar() { qDebug("statusbar"); // #ifndef Q_WS_QWS // statusBar = new QStatusBar( this, "Status Bar"); // statusBar->message(IDS_STATUS_DEFAULT, 2000); // #endif } void Gutenbrowser::initView() { // set the main widget here // QFont defaultFont( "charter", 10, 50, 0 ); Lview = new MultiLine_Ex(this); Config cfg("Gutenbrowser"); cfg.setGroup("Font"); FontDatabase fdb; QFont defaultFont = Lview->font(); QFontInfo fontInfo(defaultFont); QString family = cfg.readEntry("Family", fontInfo.family()); QString style = cfg.readEntry("Style", fdb.styleString(defaultFont)); int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10); QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) ); defaultFont = fdb.font(family,style,i_size,charSet); QString italic = cfg.readEntry("Italic","FALSE"); if(italic=="TRUE") { qDebug("Set Italic font");; defaultFont = fdb.font( family, "Regular", i_size,charSet); //workaround defaultFont.setItalic(TRUE); } Lview->setFont( defaultFont); update(); cfg.setGroup("General"); if( cfg.readBoolEntry("WordWrap", 1)) { Lview->setWordWrap(QMultiLineEdit::WidgetWidth); useWrap=true; } else { Lview->setWordWrap(QMultiLineEdit::NoWrap); useWrap = false; } mainList = new QListBox(this,"mainlist"); mainList->hide(); // QPEApplication::setStylusOperation( mainList->viewport(),QPEApplication::RightOnHold); // mainList->showMaximized(); // mainList->setGeometry(2,30,230,160); Lview->setReadOnly( true); edits->addWidget( Lview); edits->addWidget(mainList); // if(!showMainList) { // Lview->setText( "\nThis is gutenbrowser for the Sharp Zaurus.\nMake your self at home, sit back, relax and read something great. "); // } // else // Lview->hide(); |