Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

helpwindow.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002 ** $Id: helpwindow.cpp,v 1.7 2005/05/24 21:48:49 drw Exp $
00003 **
00004 ** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.
00005 **
00006 ** This file is part of an example program for Qt.  This example
00007 ** program may be used, distributed and modified without limitation.
00008 **
00009 *****************************************************************************/
00010 
00011 #include "helpwindow.h"
00012 
00013 /* OPIE */
00014 #include <opie2/odebug.h>
00015 #include <opie2/oresource.h>
00016 using namespace Opie::Core;
00017 
00018 /* QT */
00019 #include <qlayout.h>
00020 #include <qtoolbar.h>
00021 #include <qaction.h>
00022 #include <qmenubar.h>
00023 
00024 /* STD */
00025 #include <ctype.h>
00026 
00027 HelpWindow::HelpWindow( const QString& home_, const QString& _path, QWidget* parent, const char *name )
00028     : QMainWindow( parent, name, WDestructiveClose ), pathCombo( 0 ), selectedURL()
00029 {
00030     QGridLayout *layout = new QGridLayout( this );
00031     layout->setSpacing( 2);
00032     layout->setMargin( 2);
00033     odebug << _path << oendl; 
00034     browser = new QTextBrowser( this );
00035     QStringList Strlist;
00036     Strlist.append( home_);
00037     browser->mimeSourceFactory()->setFilePath( Strlist );
00038     browser->setFrameStyle( QFrame::Panel | QFrame::Sunken );
00039 
00040     connect( browser, SIGNAL( textChanged() ), this, SLOT( textChanged() ) );
00041 
00042     if ( !home_.isEmpty() )
00043         browser->setSource( home_ );
00044     QToolBar *toolbar = new QToolBar( this );
00045 
00046     QAction *a = new QAction( tr( "Backward" ), Opie::Core::OResource::loadPixmap( "back", Opie::Core::OResource::SmallIcon ),
00047                               QString::null, 0, this, 0 );
00048     connect( a, SIGNAL( activated() ), browser, SLOT( backward() ) );
00049     a->addTo( toolbar );
00050 
00051     a = new QAction( tr( "Forward" ), Opie::Core::OResource::loadPixmap( "forward", Opie::Core::OResource::SmallIcon ),
00052                      QString::null, 0, this, 0 );
00053     connect( a, SIGNAL( activated() ), browser, SLOT( forward() ) );
00054     a->addTo( toolbar );
00055 
00056 
00057     layout->addMultiCellWidget( toolbar, 0, 0, 0, 0);
00058 
00059     layout->addMultiCellWidget( browser, 1, 2, 0, 2);
00060     
00061     browser->setFocus();
00062 }
00063 
00064 
00065 void HelpWindow::setBackwardAvailable( bool b)
00066 {
00067     menuBar()->setItemEnabled( backwardId, b);
00068 }
00069 
00070 void HelpWindow::setForwardAvailable( bool b)
00071 {
00072     menuBar()->setItemEnabled( forwardId, b);
00073 }
00074 
00075 
00076 void HelpWindow::textChanged()
00077 {
00078     if ( browser->documentTitle().isNull() ) {
00079   setCaption( "QpeRec - Helpviewer - " + browser->context() );
00080   selectedURL = browser->context();
00081     }
00082     else {
00083   setCaption( "QpeRec - Helpviewer - " + browser->documentTitle() ) ;
00084   selectedURL = browser->documentTitle();
00085     }
00086 
00087 //     if ( !selectedURL.isEmpty() && pathCombo ) {
00088 //   bool exists = FALSE;
00089 //   int i;
00090 //   for ( i = 0; i < pathCombo->count(); ++i ) {
00091 //       if ( pathCombo->text( i ) == selectedURL ) {
00092 //     exists = TRUE;
00093 //     break;
00094 //       }
00095 //   }
00096 //   if ( !exists ) {
00097 //       pathCombo->insertItem( selectedURL, 0 );
00098 //       pathCombo->setCurrentItem( 0 );
00099 //       mHistory[ hist->insertItem( selectedURL ) ] = selectedURL;
00100 //   } else
00101 //       pathCombo->setCurrentItem( i );
00102 //   selectedURL = QString::null;
00103 //     }
00104 }
00105 
00106 HelpWindow::~HelpWindow()
00107 {
00108     history.clear();
00109     QMap<int, QString>::Iterator it = mHistory.begin();
00110     for ( ; it != mHistory.end(); ++it )
00111   history.append( *it );
00112 
00113     QFile f( QDir::currentDirPath() + "/.history" );
00114     f.open( IO_WriteOnly );
00115     QDataStream s( &f );
00116     s << history;
00117     f.close();
00118 
00119     bookmarks.clear();
00120     QMap<int, QString>::Iterator it2 = mBookmarks.begin();
00121     for ( ; it2 != mBookmarks.end(); ++it2 )
00122   bookmarks.append( *it2 );
00123 
00124     QFile f2( QDir::currentDirPath() + "/.bookmarks" );
00125     f2.open( IO_WriteOnly );
00126     QDataStream s2( &f2 );
00127     s2 << bookmarks;
00128     f2.close();
00129 }
00130 
00131 void HelpWindow::openFile()
00132 {
00133 #ifndef QT_NO_FILEDIALOG
00134 #endif
00135 }
00136 
00137 void HelpWindow::newWindow()
00138 {
00139     ( new HelpWindow(browser->source(), "qbrowser") )->show();
00140 }
00141 
00142 void HelpWindow::print()
00143 {
00144 #ifndef QT_NO_PRINTER
00145 #endif
00146 }
00147 
00148 void HelpWindow::pathSelected( const QString &_path )
00149 {
00150     browser->setSource( _path );
00151     QMap<int, QString>::Iterator it = mHistory.begin();
00152     bool exists = FALSE;
00153     for ( ; it != mHistory.end(); ++it ) {
00154   if ( *it == _path ) {
00155       exists = TRUE;
00156       break;
00157   }
00158     }
00159     if ( !exists )
00160   mHistory[ hist->insertItem( _path ) ] = _path;
00161 }
00162 
00163 void HelpWindow::readHistory()
00164 {
00165     if ( QFile::exists( QDir::currentDirPath() + "/.history" ) ) {
00166   QFile f( QDir::currentDirPath() + "/.history" );
00167   f.open( IO_ReadOnly );
00168   QDataStream s( &f );
00169   s >> history;
00170   f.close();
00171   while ( history.count() > 20 )
00172       history.remove( history.begin() );
00173     }
00174 }
00175 
00176 void HelpWindow::readBookmarks()
00177 {
00178     if ( QFile::exists( QDir::currentDirPath() + "/.bookmarks" ) ) {
00179   QFile f( QDir::currentDirPath() + "/.bookmarks" );
00180   f.open( IO_ReadOnly );
00181   QDataStream s( &f );
00182   s >> bookmarks;
00183   f.close();
00184     }
00185 }
00186 
00187 void HelpWindow::histChosen( int i )
00188 {
00189     if ( mHistory.contains( i ) )
00190   browser->setSource( mHistory[ i ] );
00191 }
00192 
00193 void HelpWindow::bookmChosen( int i )
00194 {
00195     if ( mBookmarks.contains( i ) )
00196   browser->setSource( mBookmarks[ i ] );
00197 }
00198 
00199 void HelpWindow::addBookmark()
00200 {
00201     mBookmarks[ bookm->insertItem( caption() ) ] = caption();
00202 }
00203 

Generated on Sat Nov 5 16:16:52 2005 for OPIE by  doxygen 1.4.2