Diffstat (limited to 'noncore/apps/opie-gutenbrowser/helpwindow.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/apps/opie-gutenbrowser/helpwindow.cpp | 34 |
1 files changed, 16 insertions, 18 deletions
diff --git a/noncore/apps/opie-gutenbrowser/helpwindow.cpp b/noncore/apps/opie-gutenbrowser/helpwindow.cpp index 4bdac02..f444a2e 100644 --- a/noncore/apps/opie-gutenbrowser/helpwindow.cpp +++ b/noncore/apps/opie-gutenbrowser/helpwindow.cpp | |||
@@ -151,183 +151,181 @@ void HelpWindow::setBackwardAvailable( bool b) | |||
151 | { | 151 | { |
152 | menuBar()->setItemEnabled( backwardId, b); | 152 | menuBar()->setItemEnabled( backwardId, b); |
153 | } | 153 | } |
154 | 154 | ||
155 | void HelpWindow::setForwardAvailable( bool b) | 155 | void HelpWindow::setForwardAvailable( bool b) |
156 | { | 156 | { |
157 | menuBar()->setItemEnabled( forwardId, b); | 157 | menuBar()->setItemEnabled( forwardId, b); |
158 | } | 158 | } |
159 | 159 | ||
160 | 160 | ||
161 | void HelpWindow::textChanged() | 161 | void HelpWindow::textChanged() |
162 | { | 162 | { |
163 | if ( browser->documentTitle().isNull() ) { | 163 | if ( browser->documentTitle().isNull() ) { |
164 | setCaption( "Gutenbrowser - Helpviewer - " + browser->context() ); | 164 | setCaption( "Gutenbrowser - Helpviewer - " + browser->context() ); |
165 | selectedURL = browser->context(); | 165 | selectedURL = browser->context(); |
166 | } | 166 | } |
167 | else { | 167 | else { |
168 | setCaption( "Gutenbrowser - Helpviewer - " + browser->documentTitle() ) ; | 168 | setCaption( "Gutenbrowser - Helpviewer - " + browser->documentTitle() ) ; |
169 | selectedURL = browser->documentTitle(); | 169 | selectedURL = browser->documentTitle(); |
170 | } | 170 | } |
171 | 171 | ||
172 | if ( !selectedURL.isEmpty() && pathCombo ) { | 172 | if ( !selectedURL.isEmpty() && pathCombo ) { |
173 | bool exists = FALSE; | 173 | bool exists = FALSE; |
174 | int i; | 174 | int i; |
175 | for ( i = 0; i < pathCombo->count(); ++i ) { | 175 | for ( i = 0; i < pathCombo->count(); ++i ) { |
176 | if ( pathCombo->text( i ) == selectedURL ) { | 176 | if ( pathCombo->text( i ) == selectedURL ) { |
177 | exists = TRUE; | 177 | exists = TRUE; |
178 | break; | 178 | break; |
179 | } | 179 | } |
180 | } | 180 | } |
181 | if ( !exists ) { | 181 | if ( !exists ) { |
182 | pathCombo->insertItem( selectedURL, 0 ); | 182 | pathCombo->insertItem( selectedURL, 0 ); |
183 | pathCombo->setCurrentItem( 0 ); | 183 | pathCombo->setCurrentItem( 0 ); |
184 | mHistory[ hist->insertItem( selectedURL ) ] = selectedURL; | 184 | mHistory[ hist->insertItem( selectedURL ) ] = selectedURL; |
185 | } else | 185 | } else |
186 | pathCombo->setCurrentItem( i ); | 186 | pathCombo->setCurrentItem( i ); |
187 | selectedURL = QString::null; | 187 | selectedURL = QString::null; |
188 | } | 188 | } |
189 | } | 189 | } |
190 | 190 | ||
191 | HelpWindow::~HelpWindow() | 191 | HelpWindow::~HelpWindow() |
192 | { | 192 | { |
193 | history.clear(); | 193 | history.clear(); |
194 | QMap<int, QString>::Iterator it = mHistory.begin(); | 194 | QMap<int, QString>::Iterator it = mHistory.begin(); |
195 | for ( ; it != mHistory.end(); ++it ) | 195 | for ( ; it != mHistory.end(); ++it ) |
196 | history.append( *it ); | 196 | history.append( *it ); |
197 | 197 | ||
198 | QFile f( QDir::currentDirPath() + "/.history" ); | 198 | QFile f( QDir::currentDirPath() + "/.history" ); |
199 | f.open( IO_WriteOnly ); | 199 | if ( f.open( IO_WriteOnly ) ) { |
200 | QDataStream s( &f ); | 200 | QDataStream s( &f ); |
201 | s << history; | 201 | s << history; |
202 | f.close(); | 202 | f.close(); |
203 | } | ||
203 | 204 | ||
204 | bookmarks.clear(); | 205 | bookmarks.clear(); |
205 | QMap<int, QString>::Iterator it2 = mBookmarks.begin(); | 206 | QMap<int, QString>::Iterator it2 = mBookmarks.begin(); |
206 | for ( ; it2 != mBookmarks.end(); ++it2 ) | 207 | for ( ; it2 != mBookmarks.end(); ++it2 ) |
207 | bookmarks.append( *it2 ); | 208 | bookmarks.append( *it2 ); |
208 | 209 | ||
209 | QFile f2( QDir::currentDirPath() + "/.bookmarks" ); | 210 | QFile f2( QDir::currentDirPath() + "/.bookmarks" ); |
210 | f2.open( IO_WriteOnly ); | 211 | if ( !f2.open( IO_WriteOnly ) ) |
212 | return; | ||
213 | |||
211 | QDataStream s2( &f2 ); | 214 | QDataStream s2( &f2 ); |
212 | s2 << bookmarks; | 215 | s2 << bookmarks; |
213 | f2.close(); | 216 | f2.close(); |
214 | } | 217 | } |
215 | 218 | ||
216 | // void HelpWindow::about() | ||
217 | // { | ||
218 | // QMessageBox::about( this, "Gutenbrowser", "<p>Thanks to Trolltech for this</p>" ); | ||
219 | // } | ||
220 | |||
221 | // void HelpWindow::aboutQt() | ||
222 | // { | ||
223 | // QMessageBox::aboutQt( this, "QBrowser" ); | ||
224 | // } | ||
225 | |||
226 | void HelpWindow::openFile() | 219 | void HelpWindow::openFile() |
227 | { | 220 | { |
228 | #ifndef QT_NO_FILEDIALOG | 221 | #ifndef QT_NO_FILEDIALOG |
229 | QString fn = QFileDialog::getOpenFileName( QString::null, QString::null, this ); | 222 | QString fn = QFileDialog::getOpenFileName( QString::null, QString::null, this ); |
230 | if ( !fn.isEmpty() ) | 223 | if ( !fn.isEmpty() ) |
231 | browser->setSource( fn ); | 224 | browser->setSource( fn ); |
232 | #endif | 225 | #endif |
233 | } | 226 | } |
234 | 227 | ||
235 | void HelpWindow::newWindow() | 228 | void HelpWindow::newWindow() |
236 | { | 229 | { |
237 | ( new HelpWindow(browser->source(), "qbrowser") )->show(); | 230 | ( new HelpWindow(browser->source(), "qbrowser") )->show(); |
238 | } | 231 | } |
239 | 232 | ||
240 | void HelpWindow::print() | 233 | void HelpWindow::print() |
241 | { | 234 | { |
242 | #ifndef QT_NO_PRINTER | 235 | #ifndef QT_NO_PRINTER |
243 | QPrinter printer; | 236 | QPrinter printer; |
244 | printer.setFullPage(TRUE); | 237 | printer.setFullPage(TRUE); |
245 | if ( printer.setup() ) { | 238 | if ( printer.setup() ) { |
246 | QPainter p( &printer ); | 239 | QPainter p( &printer ); |
247 | QPaintDeviceMetrics metrics(p.device()); | 240 | QPaintDeviceMetrics metrics(p.device()); |
248 | int dpix = metrics.logicalDpiX(); | 241 | int dpix = metrics.logicalDpiX(); |
249 | int dpiy = metrics.logicalDpiY(); | 242 | int dpiy = metrics.logicalDpiY(); |
250 | const int margin = 72; // pt | 243 | const int margin = 72; // pt |
251 | QRect body(margin*dpix/72, margin*dpiy/72, | 244 | QRect body(margin*dpix/72, margin*dpiy/72, |
252 | metrics.width()-margin*dpix/72*2, | 245 | metrics.width()-margin*dpix/72*2, |
253 | metrics.height()-margin*dpiy/72*2 ); | 246 | metrics.height()-margin*dpiy/72*2 ); |
254 | QFont font("times", 10); | 247 | QFont font("times", 10); |
255 | QSimpleRichText richText( browser->text(), font, browser->context(), browser->styleSheet(), | 248 | QSimpleRichText richText( browser->text(), font, browser->context(), browser->styleSheet(), |
256 | browser->mimeSourceFactory(), body.height() ); | 249 | browser->mimeSourceFactory(), body.height() ); |
257 | richText.setWidth( &p, body.width() ); | 250 | richText.setWidth( &p, body.width() ); |
258 | QRect view( body ); | 251 | QRect view( body ); |
259 | int page = 1; | 252 | int page = 1; |
260 | do { | 253 | do { |
261 | p.setClipRect( body ); | 254 | p.setClipRect( body ); |
262 | richText.draw( &p, body.left(), body.top(), view, colorGroup() ); | 255 | richText.draw( &p, body.left(), body.top(), view, colorGroup() ); |
263 | p.setClipping( FALSE ); | 256 | p.setClipping( FALSE ); |
264 | view.moveBy( 0, body.height() ); | 257 | view.moveBy( 0, body.height() ); |
265 | p.translate( 0 , -body.height() ); | 258 | p.translate( 0 , -body.height() ); |
266 | p.setFont( font ); | 259 | p.setFont( font ); |
267 | p.drawText( view.right() - p.fontMetrics().width( QString::number(page) ), | 260 | p.drawText( view.right() - p.fontMetrics().width( QString::number(page) ), |
268 | view.bottom() + p.fontMetrics().ascent() + 5, QString::number(page) ); | 261 | view.bottom() + p.fontMetrics().ascent() + 5, QString::number(page) ); |
269 | if ( view.top() >= richText.height() ) | 262 | if ( view.top() >= richText.height() ) |
270 | break; | 263 | break; |
271 | printer.newPage(); | 264 | printer.newPage(); |
272 | page++; | 265 | page++; |
273 | } while (TRUE); | 266 | } while (TRUE); |
274 | } | 267 | } |
275 | #endif | 268 | #endif |
276 | } | 269 | } |
277 | 270 | ||
278 | void HelpWindow::pathSelected( const QString &_path ) | 271 | void HelpWindow::pathSelected( const QString &_path ) |
279 | { | 272 | { |
280 | browser->setSource( _path ); | 273 | browser->setSource( _path ); |
281 | QMap<int, QString>::Iterator it = mHistory.begin(); | 274 | QMap<int, QString>::Iterator it = mHistory.begin(); |
282 | bool exists = FALSE; | 275 | bool exists = FALSE; |
283 | for ( ; it != mHistory.end(); ++it ) { | 276 | for ( ; it != mHistory.end(); ++it ) { |
284 | if ( *it == _path ) { | 277 | if ( *it == _path ) { |
285 | exists = TRUE; | 278 | exists = TRUE; |
286 | break; | 279 | break; |
287 | } | 280 | } |
288 | } | 281 | } |
289 | if ( !exists ) | 282 | if ( !exists ) |
290 | mHistory[ hist->insertItem( _path ) ] = _path; | 283 | mHistory[ hist->insertItem( _path ) ] = _path; |
291 | } | 284 | } |
292 | 285 | ||
293 | void HelpWindow::readHistory() | 286 | void HelpWindow::readHistory() |
294 | { | 287 | { |
295 | if ( QFile::exists( QDir::currentDirPath() + "/.history" ) ) { | 288 | if ( !QFile::exists( QDir::currentDirPath() + "/.history" ) ) |
289 | return; | ||
290 | |||
296 | QFile f( QDir::currentDirPath() + "/.history" ); | 291 | QFile f( QDir::currentDirPath() + "/.history" ); |
297 | f.open( IO_ReadOnly ); | 292 | if ( !f.open( IO_ReadOnly ) ) |
293 | return; | ||
294 | |||
298 | QDataStream s( &f ); | 295 | QDataStream s( &f ); |
299 | s >> history; | 296 | s >> history; |
300 | f.close(); | 297 | f.close(); |
301 | while ( history.count() > 20 ) | 298 | while ( history.count() > 20 ) |
302 | history.remove( history.begin() ); | 299 | history.remove( history.begin() ); |
303 | } | 300 | } |
304 | } | ||
305 | 301 | ||
306 | void HelpWindow::readBookmarks() | 302 | void HelpWindow::readBookmarks() |
307 | { | 303 | { |
308 | if ( QFile::exists( QDir::currentDirPath() + "/.bookmarks" ) ) { | 304 | if ( !QFile::exists( QDir::currentDirPath() + "/.bookmarks" ) ) |
305 | return; | ||
306 | |||
309 | QFile f( QDir::currentDirPath() + "/.bookmarks" ); | 307 | QFile f( QDir::currentDirPath() + "/.bookmarks" ); |
310 | f.open( IO_ReadOnly ); | 308 | if ( !f.open( IO_ReadOnly ) ) |
309 | return; | ||
311 | QDataStream s( &f ); | 310 | QDataStream s( &f ); |
312 | s >> bookmarks; | 311 | s >> bookmarks; |
313 | f.close(); | 312 | f.close(); |
314 | } | 313 | } |
315 | } | ||
316 | 314 | ||
317 | void HelpWindow::histChosen( int i ) | 315 | void HelpWindow::histChosen( int i ) |
318 | { | 316 | { |
319 | if ( mHistory.contains( i ) ) | 317 | if ( mHistory.contains( i ) ) |
320 | browser->setSource( mHistory[ i ] ); | 318 | browser->setSource( mHistory[ i ] ); |
321 | } | 319 | } |
322 | 320 | ||
323 | void HelpWindow::bookmChosen( int i ) | 321 | void HelpWindow::bookmChosen( int i ) |
324 | { | 322 | { |
325 | if ( mBookmarks.contains( i ) ) | 323 | if ( mBookmarks.contains( i ) ) |
326 | browser->setSource( mBookmarks[ i ] ); | 324 | browser->setSource( mBookmarks[ i ] ); |
327 | } | 325 | } |
328 | 326 | ||
329 | void HelpWindow::addBookmark() | 327 | void HelpWindow::addBookmark() |
330 | { | 328 | { |
331 | mBookmarks[ bookm->insertItem( caption() ) ] = caption(); | 329 | mBookmarks[ bookm->insertItem( caption() ) ] = caption(); |
332 | } | 330 | } |
333 | 331 | ||