From 535713ea42d091361f0ac3b14b3f44f3899a7102 Mon Sep 17 00:00:00 2001 From: llornkcor Date: Fri, 01 Nov 2002 16:43:34 +0000 Subject: make into symbol lookup --- (limited to 'noncore/todayplugins') diff --git a/noncore/todayplugins/stockticker/stockticker/helpwindow.cpp b/noncore/todayplugins/stockticker/stockticker/helpwindow.cpp new file mode 100644 index 0000000..33dcac0 --- a/dev/null +++ b/noncore/todayplugins/stockticker/stockticker/helpwindow.cpp @@ -0,0 +1,287 @@ +/**************************************************************************** +** $Id$ +** +** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. +** +** This file is part of an example program for Qt. This example +** program may be used, distributed and modified without limitation. +** +*****************************************************************************/ + +#include "helpwindow.h" +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +HelpWindow::HelpWindow( const QString& home_, const QString& _path, QWidget* parent, const char *name ) + : QMainWindow( parent, name, WDestructiveClose ), pathCombo( 0 ), selectedURL() +{ + readHistory(); + readBookmarks(); + + browser = new QTextBrowser( this ); + QStringList Strlist; + Strlist.append( home_); + + browser->mimeSourceFactory()->setFilePath( Strlist ); + + browser->setFrameStyle( QFrame::Panel | QFrame::Sunken ); + + connect( browser, SIGNAL( textChanged() ), + + this, SLOT( textChanged() ) ); + + setCentralWidget( browser ); + + if ( !home_.isEmpty() ) + +//////////////////////////////// + browser->setSource( home_ ); + +//////////////////////////////// + connect( browser, SIGNAL( highlighted( const QString&) ), + statusBar(), SLOT( message( const QString&)) ); + + setGeometry( 0,0,236,280); + + QPopupMenu* file = new QPopupMenu( this ); +// file->insertItem( tr("&New Window"), this, SLOT( newWindow() ), ALT | Key_N ); + file->insertItem( tr("&Open File"), this, SLOT( openFile() ), ALT | Key_O ); +// file->insertItem( tr("&Print"), this, SLOT( print() ), ALT | Key_P ); + file->insertSeparator(); + file->insertItem( tr("&Close"), this, SLOT( close() ), ALT | Key_Q ); +// file->insertItem( tr("E&xit"), qApp, SLOT( closeAllWindows() ), ALT | Key_X ); + + // The same three icons are used twice each. +////F FIXME + QString pixs=(QDir::homeDirPath ()) +"/Applications/gutenbrowser/pix/"; + QIconSet icon_back( QPixmap(pixs+"back.png") ); + QIconSet icon_forward( QPixmap(pixs+"forward.png") ); + QIconSet icon_home( QPixmap(pixs+"home.png") ); + + QPopupMenu* go = new QPopupMenu( this ); + backwardId = go->insertItem( icon_back, tr("&Backward"), browser, SLOT( backward() ), ALT | Key_Left ); + forwardId = go->insertItem( icon_forward, tr("&Forward"), browser, SLOT( forward() ), ALT | Key_Right ); + go->insertItem( icon_home, tr("&Home"), browser, SLOT( home() ) ); + + + hist = new QPopupMenu( this ); + QStringList::Iterator it = history.begin(); + for ( ; it != history.end(); ++it ) + mHistory[ hist->insertItem( *it ) ] = *it; + connect( hist, SIGNAL( activated( int ) ), this, SLOT( histChosen( int ) ) ); + + bookm = new QPopupMenu( this ); + bookm->insertItem( tr( "Add Bookmark" ), this, SLOT( addBookmark() ) ); + bookm->insertSeparator(); + + QStringList::Iterator it2 = bookmarks.begin(); + for ( ; it2 != bookmarks.end(); ++it2 ) + mBookmarks[ bookm->insertItem( *it2 ) ] = *it2; + connect( bookm, SIGNAL( activated( int ) ), + this, SLOT( bookmChosen( int ) ) ); + + menuBar()->insertItem( tr("&File"), file ); + menuBar()->insertItem( tr("&Go"), go ); + menuBar()->insertItem( tr( "History" ), hist ); + menuBar()->insertItem( tr( "Bookmarks" ), bookm ); +// menuBar()->insertSeparator(); +// menuBar()->insertItem( tr("&Help"), help ); + + menuBar()->setItemEnabled( forwardId, FALSE); + menuBar()->setItemEnabled( backwardId, FALSE); + connect( browser, SIGNAL( backwardAvailable( bool ) ), this, SLOT( setBackwardAvailable( bool ) ) ); + connect( browser, SIGNAL( forwardAvailable( bool ) ), this, SLOT( setForwardAvailable( bool ) ) ); + + + QToolBar* toolbar = new QToolBar( this ); + addToolBar( toolbar, "Toolbar"); + QToolButton* button; + + button = new QToolButton( icon_back, tr("Backward"), "", browser, SLOT(backward()), toolbar ); + connect( browser, SIGNAL( backwardAvailable(bool) ), button, SLOT( setEnabled(bool) ) ); + button->setEnabled( FALSE ); + button = new QToolButton( icon_forward, tr("Forward"), "", browser, SLOT(forward()), toolbar ); + connect( browser, SIGNAL( forwardAvailable(bool) ), button, SLOT( setEnabled(bool) ) ); + button->setEnabled( FALSE ); + button = new QToolButton( icon_home, tr("Home"), "", browser, SLOT(home()), toolbar ); + + toolbar->addSeparator(); + + pathCombo = new QComboBox( TRUE, toolbar ); + connect( pathCombo, SIGNAL( activated( const QString & ) ), this, SLOT( pathSelected( const QString & ) ) ); + toolbar->setStretchableWidget( pathCombo ); + +// pathCombo->setMaximumWidth(190); +// setRightJustification( TRUE ); +// setDockEnabled( Left, FALSE ); +// setDockEnabled( Right, FALSE ); + + pathCombo->insertItem( home_ ); + + browser->setFocus(); + + +} + + +void HelpWindow::setBackwardAvailable( bool b) +{ + menuBar()->setItemEnabled( backwardId, b); +} + +void HelpWindow::setForwardAvailable( bool b) +{ + menuBar()->setItemEnabled( forwardId, b); +} + + +void HelpWindow::textChanged() +{ + if ( browser->documentTitle().isNull() ) { + setCaption( "Stockticker Lookup - " + browser->context() ); + selectedURL = browser->context(); + } + else { + setCaption( "Stockticker Lookup - " + browser->documentTitle() ) ; + selectedURL = browser->documentTitle(); + } + + if ( !selectedURL.isEmpty() && pathCombo ) { + bool exists = FALSE; + int i; + for ( i = 0; i < pathCombo->count(); ++i ) { + if ( pathCombo->text( i ) == selectedURL ) { + exists = TRUE; + break; + } + } + if ( !exists ) { + pathCombo->insertItem( selectedURL, 0 ); + pathCombo->setCurrentItem( 0 ); + mHistory[ hist->insertItem( selectedURL ) ] = selectedURL; + } else + pathCombo->setCurrentItem( i ); + selectedURL = QString::null; + } +} + +HelpWindow::~HelpWindow() +{ + history.clear(); + QMap::Iterator it = mHistory.begin(); + for ( ; it != mHistory.end(); ++it ) + history.append( *it ); + + QFile f( QDir::currentDirPath() + "/.history" ); + f.open( IO_WriteOnly ); + QDataStream s( &f ); + s << history; + f.close(); + + bookmarks.clear(); + QMap::Iterator it2 = mBookmarks.begin(); + for ( ; it2 != mBookmarks.end(); ++it2 ) + bookmarks.append( *it2 ); + + QFile f2( QDir::currentDirPath() + "/.bookmarks" ); + f2.open( IO_WriteOnly ); + QDataStream s2( &f2 ); + s2 << bookmarks; + f2.close(); +} + +void HelpWindow::openFile() +{ +#ifndef QT_NO_FILEDIALOG + QString fn = QFileDialog::getOpenFileName( QString::null, QString::null, this ); + if ( !fn.isEmpty() ) + browser->setSource( fn ); +#endif +} + +void HelpWindow::newWindow() +{ + ( new HelpWindow(browser->source(), "qbrowser") )->show(); +} + +void HelpWindow::pathSelected( const QString &_path ) +{ + browser->setSource( _path ); + QMap::Iterator it = mHistory.begin(); + bool exists = FALSE; + for ( ; it != mHistory.end(); ++it ) { + if ( *it == _path ) { + exists = TRUE; + break; + } + } + if ( !exists ) + mHistory[ hist->insertItem( _path ) ] = _path; +} + +void HelpWindow::readHistory() +{ + if ( QFile::exists( QDir::currentDirPath() + "/.history" ) ) { + QFile f( QDir::currentDirPath() + "/.history" ); + f.open( IO_ReadOnly ); + QDataStream s( &f ); + s >> history; + f.close(); + while ( history.count() > 20 ) + history.remove( history.begin() ); + } +} + +void HelpWindow::readBookmarks() +{ + if ( QFile::exists( QDir::currentDirPath() + "/.bookmarks" ) ) { + QFile f( QDir::currentDirPath() + "/.bookmarks" ); + f.open( IO_ReadOnly ); + QDataStream s( &f ); + s >> bookmarks; + f.close(); + } +} + +void HelpWindow::histChosen( int i ) +{ + if ( mHistory.contains( i ) ) + browser->setSource( mHistory[ i ] ); +} + +void HelpWindow::bookmChosen( int i ) +{ + if ( mBookmarks.contains( i ) ) + browser->setSource( mBookmarks[ i ] ); +} + +void HelpWindow::addBookmark() +{ + mBookmarks[ bookm->insertItem( caption() ) ] = caption(); +} + diff --git a/noncore/todayplugins/stockticker/stockticker/helpwindow.h b/noncore/todayplugins/stockticker/stockticker/helpwindow.h new file mode 100644 index 0000000..b572edb --- a/dev/null +++ b/noncore/todayplugins/stockticker/stockticker/helpwindow.h @@ -0,0 +1,62 @@ +/**************************************************************************** +** $Id$ +** +** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. +** +** This file is part of an example program for Qt. This example +** program may be used, distributed and modified without limitation. +** +*****************************************************************************/ + +#ifndef HELPWINDOW_H +#define HELPWINDOW_H + +#include +#include +#include +#include +#include +#include + +class QComboBox; +class QPopupMenu; + +class HelpWindow : public QMainWindow +{ + Q_OBJECT +public: + HelpWindow( const QString& home_, const QString& path, QWidget* parent = 0, const char *name=0 ); + ~HelpWindow(); + +private slots: + void setBackwardAvailable( bool ); + void setForwardAvailable( bool ); + + void textChanged(); + void openFile(); + void newWindow(); + + void pathSelected( const QString & ); + void histChosen( int ); + void bookmChosen( int ); + void addBookmark(); +private: + void readHistory(); + void readBookmarks(); + + QTextBrowser* browser; + QComboBox *pathCombo; + int backwardId, forwardId; + QString selectedURL; + QStringList history, bookmarks; + QMap mHistory, mBookmarks; + QPopupMenu *hist, *bookm; + +}; + + + + + +#endif + diff --git a/noncore/todayplugins/stockticker/stockticker/inputDialog.cpp b/noncore/todayplugins/stockticker/stockticker/inputDialog.cpp index ad841f2..18021c2 100644 --- a/noncore/todayplugins/stockticker/stockticker/inputDialog.cpp +++ b/noncore/todayplugins/stockticker/stockticker/inputDialog.cpp @@ -13,13 +13,17 @@ #include #include #include +#include "helpwindow.h" +#include + +#include +// #include +// #include InputDialog::InputDialog( ) : QMainWindow( 0x0, 0x0, WStyle_ContextHelp ) { - setCaption( tr("Enter Stock Symbols")); - - connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); + setCaption( tr("Symbol Lookup")); QGridLayout *layout = new QGridLayout( this ); layout->setSpacing(6); @@ -27,117 +31,59 @@ InputDialog::InputDialog( ) LineEdit1 = new QLineEdit( this, "LineEdit1" ); LineEdit1->setFocus(); - QWhatsThis::add( LineEdit1, tr("Enter the stock symbols you want to be shown here.")); layout->addMultiCellWidget( LineEdit1, 0, 0, 0, 3); - Config cfg( "stockticker"); - cfg.setGroup( "Symbols" ); - QString symbollist; - symbollist = cfg.readEntry("Symbols", ""); - LineEdit1->setText(symbollist); - QLabel *label; label = new QLabel(this); - label->setText( tr("Enter stock symbols seperated\nby a space.")); + label->setText( tr("Enter something to lookup / search.")); label->setMaximumHeight(60); layout->addMultiCellWidget( label, 1, 1, 0, 3); - cfg.setGroup( "Fields" ); - - timeCheck= new QCheckBox ( "Time",this ); - timeCheck->setChecked( cfg.readBoolEntry("timeCheck",1)); - layout->addMultiCellWidget(timeCheck, 2, 2, 0, 0 ); - QWhatsThis::add( timeCheck, tr("Toggles Time Field")); - - dateCheck= new QCheckBox ( "Date", this ); - dateCheck->setChecked( cfg.readBoolEntry("dateCheck",1)); - layout->addMultiCellWidget( dateCheck, 2, 2, 1, 1 ); - QWhatsThis::add(dateCheck, tr("Toggles date field")); - - symbolCheck= new QCheckBox ( "Symbol", this ); - symbolCheck->setChecked( cfg.readBoolEntry("symbolCheck",1)); - layout->addMultiCellWidget( symbolCheck, 3, 3, 0, 0 ); - QWhatsThis::add(symbolCheck, tr("Toggles Symbol field")); - - nameCheck= new QCheckBox ( "Name", this ); - nameCheck->setChecked( cfg.readBoolEntry("nameCheck",1)); - layout->addMultiCellWidget( nameCheck, 3, 3, 1, 1 ); - QWhatsThis::add(nameCheck, tr("Toggles Name field")); - - currentPriceCheck= new QCheckBox ( "Current Price", this ); - currentPriceCheck->setChecked( cfg.readBoolEntry("currentPriceCheck",1)); - layout->addMultiCellWidget( currentPriceCheck, 4, 4, 0, 0 ); - QWhatsThis::add(currentPriceCheck, tr("Toggles current Price field")); - - - lastPriceCheck= new QCheckBox ( "Last Price", this ); - lastPriceCheck->setChecked( cfg.readBoolEntry("lastPriceCheck",1)); - layout->addMultiCellWidget(lastPriceCheck, 4, 4, 1, 1); - QWhatsThis::add(lastPriceCheck, tr("Toggles last price field")); - - openPriceCheck= new QCheckBox ( "Open Price", this); - openPriceCheck->setChecked( cfg.readBoolEntry("openPriceCheck",1)); - layout->addMultiCellWidget( openPriceCheck, 5, 5, 0, 0 ); - QWhatsThis::add(openPriceCheck, tr("Toggles opening price field")); - - minPriceCheck= new QCheckBox ( "Min Price", this ); - minPriceCheck->setChecked( cfg.readBoolEntry("minPriceCheck",1)); - layout->addMultiCellWidget( minPriceCheck, 5, 5, 1, 1); - QWhatsThis::add(minPriceCheck, tr("Toggles minamum price field")); - - maxPriceCheck= new QCheckBox ( "Max Price", this); - maxPriceCheck->setChecked( cfg.readBoolEntry("maxPriceCheck",1)); - layout->addMultiCellWidget( maxPriceCheck, 6, 6, 0, 0 ); - QWhatsThis::add(maxPriceCheck, tr("Toggles maximum price field")); - - variationCheck= new QCheckBox ( "Variation", this ); - variationCheck->setChecked( cfg.readBoolEntry("variationCheck",1)); - layout->addMultiCellWidget( variationCheck, 6, 6, 1, 1 ); - QWhatsThis::add(variationCheck, tr("Toggles daily variation field")); - - volumeCheck= new QCheckBox ( "Volume", this ); - volumeCheck->setChecked( cfg.readBoolEntry("volumeCheck",1)); - layout->addMultiCellWidget( volumeCheck , 7, 7, 0, 0); - QWhatsThis::add(volumeCheck, tr("Toggles volume field")); - - + connect(LineEdit1,SIGNAL(returnPressed()),this,SLOT(doLookup())); QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Expanding ); layout->addItem( spacer, 8, 0 ); } -QString InputDialog::text() const { - return LineEdit1->text(); -} - InputDialog::~InputDialog() { } -void InputDialog::cleanUp(){ - Config cfg( "stockticker"); - cfg.setGroup( "Symbols" ); - QString outText = text().upper(); - outText.stripWhiteSpace(); - cfg.writeEntry("Symbols", outText ); - qDebug( "<<<<<<<<<<<>>>>>>>>>>>>"+text()); +void InputDialog::doLookup() { +// http://finance.yahoo.com/l?m=&s=siemens&t= - cfg.setGroup( "Fields" ); + QString url = "\"http://finance.yahoo.com/l?m=&s="+LineEdit1->text()+"\""; + QString tempHtml = "/tmp/stockticker.html"; + QString cmd = "wget -O "+tempHtml+" "+url; + qDebug(cmd); - cfg.writeEntry("timeCheck",timeCheck->isChecked()); - cfg.writeEntry("dateCheck",dateCheck->isChecked()); - cfg.writeEntry("symbolCheck",symbolCheck->isChecked()); - cfg.writeEntry("nameCheck",nameCheck->isChecked()); - cfg.writeEntry("currentPriceCheck",currentPriceCheck->isChecked()); - cfg.writeEntry("lastPriceCheck",lastPriceCheck->isChecked()); - cfg.writeEntry("openPriceCheck",openPriceCheck->isChecked()); - cfg.writeEntry("minPriceCheck",minPriceCheck->isChecked()); - cfg.writeEntry("maxPriceCheck",maxPriceCheck->isChecked()); - cfg.writeEntry("variationCheck",variationCheck->isChecked()); - cfg.writeEntry("volumeCheck",volumeCheck->isChecked()); - - - cfg.write(); -} +/* + OProcess proc; + proc << "/usr/bin/wget"; + proc<<"-O"<< tempHtml<< url; + + connect( &proc, SIGNAL( processExited( OProcess *)),this, SLOT( showBrowser(OProcess *))); + proc.start( OProcess::NotifyOnExit); +*/ + system(cmd.latin1()); + HelpWindow *StockLookup = new HelpWindow( tempHtml,".",this, "SymbolLookup"); + StockLookup->setCaption("Symbol"); + StockLookup->showMaximized(); + StockLookup->show(); + LineEdit1->text(); + + +} +void InputDialog::showBrowser(OProcess*) { + qDebug("BLAH"); + QString tempHtml = "/tmp/stockticker.html"; + + HelpWindow *StockLookup = new HelpWindow( tempHtml,".",this, "SymbolLookup"); + StockLookup->setCaption("Symbol"); + StockLookup->showMaximized(); + StockLookup->show(); + LineEdit1->text(); + +} diff --git a/noncore/todayplugins/stockticker/stockticker/inputDialog.h b/noncore/todayplugins/stockticker/stockticker/inputDialog.h index 8fda6ad..15c2f22 100644 --- a/noncore/todayplugins/stockticker/stockticker/inputDialog.h +++ b/noncore/todayplugins/stockticker/stockticker/inputDialog.h @@ -5,6 +5,7 @@ #include #include #include +#include class QLineEdit; class QCheckBox; @@ -14,15 +15,13 @@ class InputDialog : public QMainWindow { public: InputDialog( ); -// InputDialog( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); ~InputDialog(); - QString text()const; private: QLineEdit* LineEdit1; - QCheckBox *timeCheck, *dateCheck, *symbolCheck, *nameCheck, *currentPriceCheck, *lastPriceCheck, *openPriceCheck, *minPriceCheck, *maxPriceCheck, *variationCheck, *volumeCheck; private slots: - void cleanUp(); + void doLookup(); + void showBrowser(OProcess*); protected slots: }; diff --git a/noncore/todayplugins/stockticker/stockticker/stockticker.pro b/noncore/todayplugins/stockticker/stockticker/stockticker.pro index 0e970f1..c5fe885 100644 --- a/noncore/todayplugins/stockticker/stockticker/stockticker.pro +++ b/noncore/todayplugins/stockticker/stockticker/stockticker.pro @@ -1,10 +1,10 @@ TEMPLATE = app CONFIG = qt warn_on release -HEADERS = inputDialog.h -SOURCES = inputDialog.cpp main.cpp +HEADERS = inputDialog.h helpwindow.h +SOURCES = inputDialog.cpp helpwindow.cpp main.cpp INTERFACES = TARGET = stockticker INCLUDEPATH += $(OPIEDIR)/include DEPENDPATH += $(OPIEDIR)/include -LIBS+= -lqpe +LIBS+= -lqpe -lopie DESTDIR = $(OPIEDIR)/bin -- cgit v0.9.0.2