-rw-r--r-- | core/apps/helpbrowser/helpbrowser.cpp | 1 | ||||
-rw-r--r-- | core/apps/helpbrowser/magictextbrowser.cpp | 11 |
2 files changed, 9 insertions, 3 deletions
diff --git a/core/apps/helpbrowser/helpbrowser.cpp b/core/apps/helpbrowser/helpbrowser.cpp index cbb4059..4bd9565 100644 --- a/core/apps/helpbrowser/helpbrowser.cpp +++ b/core/apps/helpbrowser/helpbrowser.cpp @@ -57,129 +57,128 @@ void HelpBrowser::init( const QString& _home ) setCentralWidget( browser ); setToolBarsMovable( FALSE ); if ( !_home.isEmpty() ) browser->setSource( _home ); QToolBar* toolbar = new QToolBar( this ); toolbar->setHorizontalStretchable( TRUE ); QMenuBar *menu = new QMenuBar( toolbar ); toolbar = new QToolBar( this ); // addToolBar( toolbar, "Toolbar"); QPopupMenu* go = new QPopupMenu( this ); backAction = new QAction( tr( "Backward" ), Resource::loadIconSet( "back" ), QString::null, 0, this, 0 ); connect( backAction, SIGNAL( activated() ), browser, SLOT( backward() ) ); connect( browser, SIGNAL( backwardAvailable(bool) ), backAction, SLOT( setEnabled(bool) ) ); backAction->addTo( go ); backAction->addTo( toolbar ); backAction->setEnabled( FALSE ); forwardAction = new QAction( tr( "Forward" ), Resource::loadIconSet( "forward" ), QString::null, 0, this, 0 ); connect( forwardAction, SIGNAL( activated() ), browser, SLOT( forward() ) ); connect( browser, SIGNAL( forwardAvailable(bool) ), forwardAction, SLOT( setEnabled(bool) ) ); forwardAction->addTo( go ); forwardAction->addTo( toolbar ); forwardAction->setEnabled( FALSE ); QAction *a = new QAction( tr( "Home" ), Resource::loadIconSet( "home" ), QString::null, 0, this, 0 ); connect( a, SIGNAL( activated() ), browser, SLOT( home() ) ); a->addTo( go ); a->addTo( toolbar ); bookm = new QPopupMenu( this ); bookm->insertItem( tr( "Add Bookmark" ), this, SLOT( addBookmark() ) ); bookm->insertItem( tr( "Remove from Bookmarks" ), this, SLOT( removeBookmark() ) ); bookm->insertSeparator(); connect( bookm, SIGNAL( activated(int) ), this, SLOT( bookmChosen(int) ) ); readBookmarks(); menu->insertItem( tr("Go"), go ); menu->insertItem( tr( "Bookmarks" ), bookm ); resize( 240, 300 ); browser->setFocus(); browser->setFrameStyle( QFrame::NoFrame ); #if !defined(QT_NO_COP) QCopChannel *addressChannel = new QCopChannel("QPE/HelpBrowser" , this ); connect (addressChannel, SIGNAL( received(const QCString&,const QByteArray&)), this, SLOT ( appMessage(const QCString&,const QByteArray&) ) ); #endif connect( qApp, SIGNAL(appMessage(const QCString&,const QByteArray&)), this, SLOT(appMessage(const QCString&,const QByteArray&)) ); } void HelpBrowser::appMessage(const QCString& msg, const QByteArray& data) { - odebug << "reached appMessage" << oendl; if ( msg == "showFile(QString)" ) { QDataStream ds(data,IO_ReadOnly); QString fn; ds >> fn; setDocument( fn ); QPEApplication::setKeepRunning(); showMaximized(); setActiveWindow(); raise(); } } void HelpBrowser::setDocument( const QString &doc ) { if ( !doc.isEmpty() ) browser->setSource( doc ); raise(); } void HelpBrowser::textChanged() { if ( browser->documentTitle().isNull() ) setCaption( tr("Help Browser") ); else setCaption( browser->documentTitle() ) ; selectedURL = caption(); } HelpBrowser::~HelpBrowser() { QStringList bookmarks; QMap<int, Bookmark>::Iterator it2 = mBookmarks.begin(); for ( ; it2 != mBookmarks.end(); ++it2 ) bookmarks.append( (*it2).name + "=" + (*it2).file ); QFile f2( Global::applicationFileName("helpbrowser", "bookmarks") ); if ( f2.open( IO_WriteOnly ) ) { QDataStream s2( &f2 ); s2 << bookmarks; f2.close(); } } void HelpBrowser::pathSelected( const QString &_path ) { browser->setSource( _path ); } void HelpBrowser::readBookmarks() { QString file = Global::applicationFileName("helpbrowser", "bookmarks"); if ( QFile::exists( file ) ) { QStringList bookmarks; QFile f( file ); if ( f.open( IO_ReadOnly ) ) { QDataStream s( &f ); s >> bookmarks; f.close(); } QStringList::Iterator it = bookmarks.begin(); diff --git a/core/apps/helpbrowser/magictextbrowser.cpp b/core/apps/helpbrowser/magictextbrowser.cpp index 80495c9..44bf19f 100644 --- a/core/apps/helpbrowser/magictextbrowser.cpp +++ b/core/apps/helpbrowser/magictextbrowser.cpp @@ -22,76 +22,83 @@ void MagicTextBrowser::setSource( const QString& source ) { return; if ( magicOpe(source, "applets") || magicOpe(source, "input") ) return; // Just those are magic (for now). Could do CGI here, // or in Qtopia's mime source factory. } bool MagicTextBrowser::magicQpe(const QString& source, const QString& name) { if ( name+".html" == source || "help/"+name+".html" == source) { QString fn = mimeSourceFactory()->makeAbsolute( source, context() ); const QMimeSource* m = mimeSourceFactory()->data( fn, context() ); if ( m ) { QString txt; if ( QTextDrag::decode(m,txt) ) { QRegExp re("<qtopia-"+name+">.*</qtopia-"+name+">"); int start,len; if ( (start=re.match(txt,0,&len))>=0 ) { QString generated = generateQpe(name); txt.replace(start,len,generated); setText(txt); return true; } } } } return false; } bool MagicTextBrowser::magicOpe( const QString& source, const QString& name ) { if ( name+".html" != source && "help/"+name+".html" != source) return false; QString fn = mimeSourceFactory()->makeAbsolute( source, context() ); const QMimeSource* m = mimeSourceFactory()->data(fn, context() ); if (!m) return false; QString txt; if ( !QTextDrag::decode(m, txt ) ) return false; QRegExp re("<opie-"+name+">.*</opie-"+name+">"); int start,len; if ( (start=re.match(txt,0,&len))>=0 ) { QString generated = generateOpe(name); txt.replace(start,len,generated); setText(txt); return true; } return false; } QString MagicTextBrowser::generateOpe(const QString& name)const { if ( name == QString::fromLatin1("applets") ) { return QString::fromLatin1("<h3>No Applets found</h3>"); }else if ( name == QString::fromLatin1("input") ) { return QString::fromLatin1("<h3>No input methods available</h3>"); }else return QString::null; } QString MagicTextBrowser::generateQpe(const QString& name) const { QString dir = MimeType::appsFolderName()+"/"+name[0].upper()+name.mid(1); AppLnkSet lnkset(dir); AppLnk* lnk; QString r; for (QListIterator<AppLnk> it(lnkset.children()); (lnk=it.current()); ++it) { QString name = lnk->name(); QString icon = lnk->icon(); - QString helpFile = lnk->exec()+".html"; + QString exec = lnk->exec(); + QString helpFile = exec+".html"; QStringList helpPath = Global::helpPath(); bool helpExists = FALSE; - for (QStringList::ConstIterator it=helpPath.begin(); it!=helpPath.end() && !helpExists; ++it) + for (QStringList::ConstIterator it=helpPath.begin(); it!=helpPath.end() && !helpExists; ++it) { helpExists = QFile::exists( *it + "/" + helpFile ); + if( !helpExists && QFile::exists( *it + "/" + exec + "/" + helpFile ) ) { + helpFile = exec + "/" + helpFile; + helpExists = true; + } + } + if ( helpExists ) { r += "<h3><a href="+helpFile+"><img src="+icon+">"+name+"</a></h3>\n"; } } return r; } |