/**************************************************************************** ** $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" /* OPIE */ #include #include using namespace Opie::Core; /* QT */ #include #include #include #include /* STD */ #include HelpWindow::HelpWindow( const QString& home_, const QString& _path, QWidget* parent, const char *name ) : QMainWindow( parent, name, WDestructiveClose ), pathCombo( 0 ), selectedURL() { QGridLayout *layout = new QGridLayout( this ); layout->setSpacing( 2); layout->setMargin( 2); odebug << _path << oendl; 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() ) ); if ( !home_.isEmpty() ) browser->setSource( home_ ); QToolBar *toolbar = new QToolBar( this ); QAction *a = new QAction( tr( "Backward" ), Opie::Core::OResource::loadPixmap( "back", Opie::Core::OResource::SmallIcon ), QString::null, 0, this, 0 ); connect( a, SIGNAL( activated() ), browser, SLOT( backward() ) ); a->addTo( toolbar ); a = new QAction( tr( "Forward" ), Opie::Core::OResource::loadPixmap( "forward", Opie::Core::OResource::SmallIcon ), QString::null, 0, this, 0 ); connect( a, SIGNAL( activated() ), browser, SLOT( forward() ) ); a->addTo( toolbar ); layout->addMultiCellWidget( toolbar, 0, 0, 0, 0); layout->addMultiCellWidget( browser, 1, 2, 0, 2); 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( "QpeRec - Helpviewer - " + browser->context() ); selectedURL = browser->context(); } else { setCaption( "QpeRec - Helpviewer - " + 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 #endif } void HelpWindow::newWindow() { ( new HelpWindow(browser->source(), "qbrowser") )->show(); } void HelpWindow::print() { #ifndef QT_NO_PRINTER #endif } 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(); }