summaryrefslogtreecommitdiff
path: root/core/apps/helpbrowser
authorkergoth <kergoth>2003-08-09 17:42:14 (UTC)
committer kergoth <kergoth>2003-08-09 17:42:14 (UTC)
commit1ab4ca95e4d2cf24d32b38c9031cb6076351e730 (patch) (side-by-side diff)
tree644d196b01c7f280981bd17da23c7592a18e5643 /core/apps/helpbrowser
parentec14206f63dd93e9fb84c76cbc76fc1968637590 (diff)
downloadopie-1ab4ca95e4d2cf24d32b38c9031cb6076351e730.zip
opie-1ab4ca95e4d2cf24d32b38c9031cb6076351e730.tar.gz
opie-1ab4ca95e4d2cf24d32b38c9031cb6076351e730.tar.bz2
Merge from BRANCH_1_0
Diffstat (limited to 'core/apps/helpbrowser') (more/less context) (ignore whitespace changes)
-rw-r--r--core/apps/helpbrowser/helpbrowser.cpp48
-rw-r--r--core/apps/helpbrowser/helpbrowser.h4
-rw-r--r--core/apps/helpbrowser/helpbrowser.pro4
-rw-r--r--core/apps/helpbrowser/magictextbrowser.cpp99
-rw-r--r--core/apps/helpbrowser/magictextbrowser.h42
-rw-r--r--core/apps/helpbrowser/main.cpp9
6 files changed, 184 insertions, 22 deletions
diff --git a/core/apps/helpbrowser/helpbrowser.cpp b/core/apps/helpbrowser/helpbrowser.cpp
index 48da7c6..531dbff 100644
--- a/core/apps/helpbrowser/helpbrowser.cpp
+++ b/core/apps/helpbrowser/helpbrowser.cpp
@@ -1,7 +1,7 @@
-#/**********************************************************************
-** Copyright (C) 2000 Trolltech AS. All rights reserved.
+/**********************************************************************
+** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
**
-** This file is part of Qtopia Environment.
+** This file is part of the Qtopia Environment.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
@@ -18,10 +18,14 @@
**
**********************************************************************/
+#define QTOPIA_INTERNAL_LANGLIST
+
#include "helpbrowser.h"
#include <qpe/qpeapplication.h>
#include <qpe/resource.h>
+#include <qpe/mimetype.h>
+#include <qpe/applnk.h>
#include <qpe/global.h>
#include <qstatusbar.h>
@@ -30,6 +34,7 @@
#include <qpopupmenu.h>
#include <qpe/qpemenubar.h>
#include <qpe/qpetoolbar.h>
+#include <qpe/qcopenvelope_qws.h>
#include <qtoolbutton.h>
#include <qiconset.h>
#include <qfile.h>
@@ -48,8 +53,9 @@
#include <qpaintdevicemetrics.h>
#include <qaction.h>
-#include <ctype.h>
+#include <cctype>
+#include "magictextbrowser.h"
HelpBrowser::HelpBrowser( QWidget* parent, const char *name, WFlags f )
: QMainWindow( parent, name, f ),
@@ -58,11 +64,14 @@ HelpBrowser::HelpBrowser( QWidget* parent, const char *name, WFlags f )
init( "index.html" );
}
+
+
void HelpBrowser::init( const QString& _home )
{
- setIcon( Resource::loadPixmap( "help_icon" ) );
+ setIcon( Resource::loadPixmap( "HelpBrowser" ) );
+ setBackgroundMode( PaletteButton );
- browser = new QTextBrowser( this );
+ browser = new MagicTextBrowser( this );
browser->setFrameStyle( QFrame::Panel | QFrame::Sunken );
connect( browser, SIGNAL( textChanged() ),
this, SLOT( textChanged() ) );
@@ -80,12 +89,12 @@ void HelpBrowser::init( const QString& _home )
toolbar = new QPEToolBar( this );
// addToolBar( toolbar, "Toolbar");
- //QPopupMenu* go = new QPopupMenu( this );
+ 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( go );
backAction->addTo( toolbar );
backAction->setEnabled( FALSE );
@@ -93,14 +102,13 @@ void HelpBrowser::init( const QString& _home )
connect( forwardAction, SIGNAL( activated() ), browser, SLOT( forward() ) );
connect( browser, SIGNAL( forwardAvailable( bool ) ),
forwardAction, SLOT( setEnabled( bool ) ) );
- //forwardAction->addTo( go );
+ forwardAction->addTo( go );
forwardAction->addTo( toolbar );
forwardAction->setEnabled( FALSE );
- QAction *a = new QAction( tr( "Home" ), Resource::loadPixmap(
-"home" ), QString::null, 0, this, 0 );
+ 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( go );
a->addTo( toolbar );
bookm = new QPopupMenu( this );
@@ -112,11 +120,18 @@ void HelpBrowser::init( const QString& _home )
readBookmarks();
- //menu->insertItem( tr("Go"), go );
+ 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&)) );
@@ -124,11 +139,18 @@ void HelpBrowser::init( const QString& _home )
void HelpBrowser::appMessage(const QCString& msg, const QByteArray& data)
{
+ qDebug("reached appMessage");
if ( msg == "showFile(QString)" ) {
QDataStream ds(data,IO_ReadOnly);
QString fn;
ds >> fn;
setDocument( fn );
+
+ QPEApplication::setKeepRunning();
+
+ showMaximized();
+ setActiveWindow();
+ raise();
}
}
diff --git a/core/apps/helpbrowser/helpbrowser.h b/core/apps/helpbrowser/helpbrowser.h
index 2f7153a..5f7e6b6 100644
--- a/core/apps/helpbrowser/helpbrowser.h
+++ b/core/apps/helpbrowser/helpbrowser.h
@@ -1,7 +1,7 @@
/**********************************************************************
-** Copyright (C) 2000 Trolltech AS. All rights reserved.
+** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
**
-** This file is part of Qtopia Environment.
+** This file is part of the Qtopia Environment.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
diff --git a/core/apps/helpbrowser/helpbrowser.pro b/core/apps/helpbrowser/helpbrowser.pro
index 6bb43bd..3525b7e 100644
--- a/core/apps/helpbrowser/helpbrowser.pro
+++ b/core/apps/helpbrowser/helpbrowser.pro
@@ -1,8 +1,8 @@
TEMPLATE = app
CONFIG = qt warn_on release
DESTDIR = $(OPIEDIR)/bin
-HEADERS = helpbrowser.h
-SOURCES = helpbrowser.cpp \
+HEADERS = helpbrowser.h magictextbrowser.h
+SOURCES = helpbrowser.cpp magictextbrowser.cpp \
main.cpp
INCLUDEPATH += $(OPIEDIR)/include
DEPENDPATH += $(OPIEDIR)/include
diff --git a/core/apps/helpbrowser/magictextbrowser.cpp b/core/apps/helpbrowser/magictextbrowser.cpp
new file mode 100644
index 0000000..8ce0325
--- a/dev/null
+++ b/core/apps/helpbrowser/magictextbrowser.cpp
@@ -0,0 +1,99 @@
+#include <qfile.h>
+#include <qstring.h>
+#include <qdragobject.h>
+#include <qregexp.h>
+
+/* need to get Global::helpPath() */
+#define QTOPIA_INTERNAL_LANGLIST
+
+#include <qtopia/global.h>
+#include <qtopia/mimetype.h>
+#include <qtopia/applnk.h>
+
+#include "magictextbrowser.h"
+
+
+
+MagicTextBrowser::MagicTextBrowser(QWidget* parent) :
+ QTextBrowser(parent){
+}
+
+void MagicTextBrowser::setSource( const QString& source ) {
+ QTextBrowser::setSource(source);
+ if ( magicQpe(source,"applications") || magicQpe(source,"games") || magicQpe(source,"settings") || magicQpe(source, "1Pim") ) // No tr
+ 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";
+ QStringList helpPath = Global::helpPath();
+ bool helpExists = FALSE;
+ for (QStringList::ConstIterator it=helpPath.begin(); it!=helpPath.end() && !helpExists; ++it)
+ helpExists = QFile::exists( *it + "/" + helpFile );
+
+ if ( helpExists ) {
+ r += "<h3><a href="+helpFile+"><img src="+icon+">"+name+"</a></h3>\n";
+ }
+ }
+ return r;
+}
diff --git a/core/apps/helpbrowser/magictextbrowser.h b/core/apps/helpbrowser/magictextbrowser.h
new file mode 100644
index 0000000..ff91e68
--- a/dev/null
+++ b/core/apps/helpbrowser/magictextbrowser.h
@@ -0,0 +1,42 @@
+/**********************************************************************
+** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
+** Copyright (C) 2003 zecke
+**
+** This file is part of the Qtopia Environment.
+**
+** This file may be distributed and/or modified under the terms of the
+** GNU General Public License version 2 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.
+**
+** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+**
+** See http://www.trolltech.com/gpl/ for GPL licensing information.
+**
+** Contact info@trolltech.com if any conditions of this licensing are
+** not clear to you.
+**
+**********************************************************************/
+#ifndef HELP_BROWSER_MAGIC_TEXT_BROWSER_H
+#define HELP_BROWSER_MAGIC_TEXT_BROWSER_H
+
+#include <qtextbrowser.h>
+
+class MagicTextBrowser : public QTextBrowser {
+public:
+ MagicTextBrowser(QWidget* parent);
+
+ void setSource( const QString& source );
+
+ /** honor QPE Attributes */
+ bool magicQpe(const QString& source, const QString& name);
+ /** honor OPIE Attributes */
+ bool magicOpe(const QString& source, const QString& name );
+private:
+
+ QString generateQpe(const QString& name) const;
+ QString generateOpe(const QString& name) const;
+};
+
+#endif
diff --git a/core/apps/helpbrowser/main.cpp b/core/apps/helpbrowser/main.cpp
index 1cb10b7..b1bea56 100644
--- a/core/apps/helpbrowser/main.cpp
+++ b/core/apps/helpbrowser/main.cpp
@@ -1,7 +1,7 @@
/**********************************************************************
-** Copyright (C) 2000 Trolltech AS. All rights reserved.
+** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
**
-** This file is part of Qtopia Environment.
+** This file is part of the Qtopia Environment.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
@@ -20,15 +20,14 @@
#include "helpbrowser.h"
-#include <qpe/qpeapplication.h>
+#include <qtopia/qpeapplication.h>
int main( int argc, char ** argv )
{
QPEApplication a( argc, argv );
HelpBrowser mw;
- mw.setCaption( HelpBrowser::tr("HelpBrowser") );
- a.showMainDocumentWidget( &mw );
+ a.showMainWidget( &mw );
return a.exec();
}