author | llornkcor <llornkcor> | 2002-11-01 16:43:34 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-11-01 16:43:34 (UTC) |
commit | 535713ea42d091361f0ac3b14b3f44f3899a7102 (patch) (unidiff) | |
tree | 800414877b9ebca28b2f0b4022156f39dcf1678c /noncore/todayplugins/stockticker/stockticker/helpwindow.cpp | |
parent | 4c9df59925da5a67d884f8ffb37a263d85948951 (diff) | |
download | opie-535713ea42d091361f0ac3b14b3f44f3899a7102.zip opie-535713ea42d091361f0ac3b14b3f44f3899a7102.tar.gz opie-535713ea42d091361f0ac3b14b3f44f3899a7102.tar.bz2 |
make into symbol lookup
Diffstat (limited to 'noncore/todayplugins/stockticker/stockticker/helpwindow.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/todayplugins/stockticker/stockticker/helpwindow.cpp | 287 |
1 files changed, 287 insertions, 0 deletions
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 @@ | |||
1 | /**************************************************************************** | ||
2 | ** $Id$ | ||
3 | ** | ||
4 | ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. | ||
5 | ** | ||
6 | ** This file is part of an example program for Qt. This example | ||
7 | ** program may be used, distributed and modified without limitation. | ||
8 | ** | ||
9 | *****************************************************************************/ | ||
10 | |||
11 | #include "helpwindow.h" | ||
12 | #include <qstatusbar.h> | ||
13 | #include <qstringlist.h> | ||
14 | |||
15 | #include <qpixmap.h> | ||
16 | #include <qpopupmenu.h> | ||
17 | #include <qmenubar.h> | ||
18 | #include <qtoolbar.h> | ||
19 | #include <qtoolbutton.h> | ||
20 | #include <qiconset.h> | ||
21 | #include <qfile.h> | ||
22 | #include <qtextstream.h> | ||
23 | #include <qstylesheet.h> | ||
24 | #include <qmessagebox.h> | ||
25 | #include <qfiledialog.h> | ||
26 | #include <qapplication.h> | ||
27 | #include <qcombobox.h> | ||
28 | #include <qevent.h> | ||
29 | #include <qlineedit.h> | ||
30 | #include <qobjectlist.h> | ||
31 | #include <qfileinfo.h> | ||
32 | #include <qfile.h> | ||
33 | #include <qdatastream.h> | ||
34 | #include <qprinter.h> | ||
35 | #include <qsimplerichtext.h> | ||
36 | #include <qpaintdevicemetrics.h> | ||
37 | |||
38 | #include <ctype.h> | ||
39 | |||
40 | HelpWindow::HelpWindow( const QString& home_, const QString& _path, QWidget* parent, const char *name ) | ||
41 | : QMainWindow( parent, name, WDestructiveClose ), pathCombo( 0 ), selectedURL() | ||
42 | { | ||
43 | readHistory(); | ||
44 | readBookmarks(); | ||
45 | |||
46 | browser = new QTextBrowser( this ); | ||
47 | QStringList Strlist; | ||
48 | Strlist.append( home_); | ||
49 | |||
50 | browser->mimeSourceFactory()->setFilePath( Strlist ); | ||
51 | |||
52 | browser->setFrameStyle( QFrame::Panel | QFrame::Sunken ); | ||
53 | |||
54 | connect( browser, SIGNAL( textChanged() ), | ||
55 | |||
56 | this, SLOT( textChanged() ) ); | ||
57 | |||
58 | setCentralWidget( browser ); | ||
59 | |||
60 | if ( !home_.isEmpty() ) | ||
61 | |||
62 | //////////////////////////////// | ||
63 | browser->setSource( home_ ); | ||
64 | |||
65 | //////////////////////////////// | ||
66 | connect( browser, SIGNAL( highlighted( const QString&) ), | ||
67 | statusBar(), SLOT( message( const QString&)) ); | ||
68 | |||
69 | setGeometry( 0,0,236,280); | ||
70 | |||
71 | QPopupMenu* file = new QPopupMenu( this ); | ||
72 | // file->insertItem( tr("&New Window"), this, SLOT( newWindow() ), ALT | Key_N ); | ||
73 | file->insertItem( tr("&Open File"), this, SLOT( openFile() ), ALT | Key_O ); | ||
74 | // file->insertItem( tr("&Print"), this, SLOT( print() ), ALT | Key_P ); | ||
75 | file->insertSeparator(); | ||
76 | file->insertItem( tr("&Close"), this, SLOT( close() ), ALT | Key_Q ); | ||
77 | // file->insertItem( tr("E&xit"), qApp, SLOT( closeAllWindows() ), ALT | Key_X ); | ||
78 | |||
79 | // The same three icons are used twice each. | ||
80 | ////F FIXME | ||
81 | QString pixs=(QDir::homeDirPath ()) +"/Applications/gutenbrowser/pix/"; | ||
82 | QIconSet icon_back( QPixmap(pixs+"back.png") ); | ||
83 | QIconSet icon_forward( QPixmap(pixs+"forward.png") ); | ||
84 | QIconSet icon_home( QPixmap(pixs+"home.png") ); | ||
85 | |||
86 | QPopupMenu* go = new QPopupMenu( this ); | ||
87 | backwardId = go->insertItem( icon_back, tr("&Backward"), browser, SLOT( backward() ), ALT | Key_Left ); | ||
88 | forwardId = go->insertItem( icon_forward, tr("&Forward"), browser, SLOT( forward() ), ALT | Key_Right ); | ||
89 | go->insertItem( icon_home, tr("&Home"), browser, SLOT( home() ) ); | ||
90 | |||
91 | |||
92 | hist = new QPopupMenu( this ); | ||
93 | QStringList::Iterator it = history.begin(); | ||
94 | for ( ; it != history.end(); ++it ) | ||
95 | mHistory[ hist->insertItem( *it ) ] = *it; | ||
96 | connect( hist, SIGNAL( activated( int ) ), this, SLOT( histChosen( int ) ) ); | ||
97 | |||
98 | bookm = new QPopupMenu( this ); | ||
99 | bookm->insertItem( tr( "Add Bookmark" ), this, SLOT( addBookmark() ) ); | ||
100 | bookm->insertSeparator(); | ||
101 | |||
102 | QStringList::Iterator it2 = bookmarks.begin(); | ||
103 | for ( ; it2 != bookmarks.end(); ++it2 ) | ||
104 | mBookmarks[ bookm->insertItem( *it2 ) ] = *it2; | ||
105 | connect( bookm, SIGNAL( activated( int ) ), | ||
106 | this, SLOT( bookmChosen( int ) ) ); | ||
107 | |||
108 | menuBar()->insertItem( tr("&File"), file ); | ||
109 | menuBar()->insertItem( tr("&Go"), go ); | ||
110 | menuBar()->insertItem( tr( "History" ), hist ); | ||
111 | menuBar()->insertItem( tr( "Bookmarks" ), bookm ); | ||
112 | // menuBar()->insertSeparator(); | ||
113 | // menuBar()->insertItem( tr("&Help"), help ); | ||
114 | |||
115 | menuBar()->setItemEnabled( forwardId, FALSE); | ||
116 | menuBar()->setItemEnabled( backwardId, FALSE); | ||
117 | connect( browser, SIGNAL( backwardAvailable( bool ) ), this, SLOT( setBackwardAvailable( bool ) ) ); | ||
118 | connect( browser, SIGNAL( forwardAvailable( bool ) ), this, SLOT( setForwardAvailable( bool ) ) ); | ||
119 | |||
120 | |||
121 | QToolBar* toolbar = new QToolBar( this ); | ||
122 | addToolBar( toolbar, "Toolbar"); | ||
123 | QToolButton* button; | ||
124 | |||
125 | button = new QToolButton( icon_back, tr("Backward"), "", browser, SLOT(backward()), toolbar ); | ||
126 | connect( browser, SIGNAL( backwardAvailable(bool) ), button, SLOT( setEnabled(bool) ) ); | ||
127 | button->setEnabled( FALSE ); | ||
128 | button = new QToolButton( icon_forward, tr("Forward"), "", browser, SLOT(forward()), toolbar ); | ||
129 | connect( browser, SIGNAL( forwardAvailable(bool) ), button, SLOT( setEnabled(bool) ) ); | ||
130 | button->setEnabled( FALSE ); | ||
131 | button = new QToolButton( icon_home, tr("Home"), "", browser, SLOT(home()), toolbar ); | ||
132 | |||
133 | toolbar->addSeparator(); | ||
134 | |||
135 | pathCombo = new QComboBox( TRUE, toolbar ); | ||
136 | connect( pathCombo, SIGNAL( activated( const QString & ) ), this, SLOT( pathSelected( const QString & ) ) ); | ||
137 | toolbar->setStretchableWidget( pathCombo ); | ||
138 | |||
139 | // pathCombo->setMaximumWidth(190); | ||
140 | // setRightJustification( TRUE ); | ||
141 | // setDockEnabled( Left, FALSE ); | ||
142 | // setDockEnabled( Right, FALSE ); | ||
143 | |||
144 | pathCombo->insertItem( home_ ); | ||
145 | |||
146 | browser->setFocus(); | ||
147 | |||
148 | |||
149 | } | ||
150 | |||
151 | |||
152 | void HelpWindow::setBackwardAvailable( bool b) | ||
153 | { | ||
154 | menuBar()->setItemEnabled( backwardId, b); | ||
155 | } | ||
156 | |||
157 | void HelpWindow::setForwardAvailable( bool b) | ||
158 | { | ||
159 | menuBar()->setItemEnabled( forwardId, b); | ||
160 | } | ||
161 | |||
162 | |||
163 | void HelpWindow::textChanged() | ||
164 | { | ||
165 | if ( browser->documentTitle().isNull() ) { | ||
166 | setCaption( "Stockticker Lookup - " + browser->context() ); | ||
167 | selectedURL = browser->context(); | ||
168 | } | ||
169 | else { | ||
170 | setCaption( "Stockticker Lookup - " + browser->documentTitle() ) ; | ||
171 | selectedURL = browser->documentTitle(); | ||
172 | } | ||
173 | |||
174 | if ( !selectedURL.isEmpty() && pathCombo ) { | ||
175 | bool exists = FALSE; | ||
176 | int i; | ||
177 | for ( i = 0; i < pathCombo->count(); ++i ) { | ||
178 | if ( pathCombo->text( i ) == selectedURL ) { | ||
179 | exists = TRUE; | ||
180 | break; | ||
181 | } | ||
182 | } | ||
183 | if ( !exists ) { | ||
184 | pathCombo->insertItem( selectedURL, 0 ); | ||
185 | pathCombo->setCurrentItem( 0 ); | ||
186 | mHistory[ hist->insertItem( selectedURL ) ] = selectedURL; | ||
187 | } else | ||
188 | pathCombo->setCurrentItem( i ); | ||
189 | selectedURL = QString::null; | ||
190 | } | ||
191 | } | ||
192 | |||
193 | HelpWindow::~HelpWindow() | ||
194 | { | ||
195 | history.clear(); | ||
196 | QMap<int, QString>::Iterator it = mHistory.begin(); | ||
197 | for ( ; it != mHistory.end(); ++it ) | ||
198 | history.append( *it ); | ||
199 | |||
200 | QFile f( QDir::currentDirPath() + "/.history" ); | ||
201 | f.open( IO_WriteOnly ); | ||
202 | QDataStream s( &f ); | ||
203 | s << history; | ||
204 | f.close(); | ||
205 | |||
206 | bookmarks.clear(); | ||
207 | QMap<int, QString>::Iterator it2 = mBookmarks.begin(); | ||
208 | for ( ; it2 != mBookmarks.end(); ++it2 ) | ||
209 | bookmarks.append( *it2 ); | ||
210 | |||
211 | QFile f2( QDir::currentDirPath() + "/.bookmarks" ); | ||
212 | f2.open( IO_WriteOnly ); | ||
213 | QDataStream s2( &f2 ); | ||
214 | s2 << bookmarks; | ||
215 | f2.close(); | ||
216 | } | ||
217 | |||
218 | void HelpWindow::openFile() | ||
219 | { | ||
220 | #ifndef QT_NO_FILEDIALOG | ||
221 | QString fn = QFileDialog::getOpenFileName( QString::null, QString::null, this ); | ||
222 | if ( !fn.isEmpty() ) | ||
223 | browser->setSource( fn ); | ||
224 | #endif | ||
225 | } | ||
226 | |||
227 | void HelpWindow::newWindow() | ||
228 | { | ||
229 | ( new HelpWindow(browser->source(), "qbrowser") )->show(); | ||
230 | } | ||
231 | |||
232 | void HelpWindow::pathSelected( const QString &_path ) | ||
233 | { | ||
234 | browser->setSource( _path ); | ||
235 | QMap<int, QString>::Iterator it = mHistory.begin(); | ||
236 | bool exists = FALSE; | ||
237 | for ( ; it != mHistory.end(); ++it ) { | ||
238 | if ( *it == _path ) { | ||
239 | exists = TRUE; | ||
240 | break; | ||
241 | } | ||
242 | } | ||
243 | if ( !exists ) | ||
244 | mHistory[ hist->insertItem( _path ) ] = _path; | ||
245 | } | ||
246 | |||
247 | void HelpWindow::readHistory() | ||
248 | { | ||
249 | if ( QFile::exists( QDir::currentDirPath() + "/.history" ) ) { | ||
250 | QFile f( QDir::currentDirPath() + "/.history" ); | ||
251 | f.open( IO_ReadOnly ); | ||
252 | QDataStream s( &f ); | ||
253 | s >> history; | ||
254 | f.close(); | ||
255 | while ( history.count() > 20 ) | ||
256 | history.remove( history.begin() ); | ||
257 | } | ||
258 | } | ||
259 | |||
260 | void HelpWindow::readBookmarks() | ||
261 | { | ||
262 | if ( QFile::exists( QDir::currentDirPath() + "/.bookmarks" ) ) { | ||
263 | QFile f( QDir::currentDirPath() + "/.bookmarks" ); | ||
264 | f.open( IO_ReadOnly ); | ||
265 | QDataStream s( &f ); | ||
266 | s >> bookmarks; | ||
267 | f.close(); | ||
268 | } | ||
269 | } | ||
270 | |||
271 | void HelpWindow::histChosen( int i ) | ||
272 | { | ||
273 | if ( mHistory.contains( i ) ) | ||
274 | browser->setSource( mHistory[ i ] ); | ||
275 | } | ||
276 | |||
277 | void HelpWindow::bookmChosen( int i ) | ||
278 | { | ||
279 | if ( mBookmarks.contains( i ) ) | ||
280 | browser->setSource( mBookmarks[ i ] ); | ||
281 | } | ||
282 | |||
283 | void HelpWindow::addBookmark() | ||
284 | { | ||
285 | mBookmarks[ bookm->insertItem( caption() ) ] = caption(); | ||
286 | } | ||
287 | |||