-rw-r--r-- | core/apps/helpbrowser/helpbrowser.cpp | 48 | ||||
-rw-r--r-- | core/apps/helpbrowser/helpbrowser.h | 4 | ||||
-rw-r--r-- | core/apps/helpbrowser/helpbrowser.pro | 4 | ||||
-rw-r--r-- | core/apps/helpbrowser/magictextbrowser.cpp | 99 | ||||
-rw-r--r-- | core/apps/helpbrowser/magictextbrowser.h | 42 | ||||
-rw-r--r-- | core/apps/helpbrowser/main.cpp | 9 |
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,6 +1,6 @@ | |||
1 | #/********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of the Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
@@ -19,8 +19,12 @@ | |||
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #define QTOPIA_INTERNAL_LANGLIST | ||
22 | |||
21 | #include "helpbrowser.h" | 23 | #include "helpbrowser.h" |
22 | 24 | ||
23 | #include <qpe/qpeapplication.h> | 25 | #include <qpe/qpeapplication.h> |
24 | #include <qpe/resource.h> | 26 | #include <qpe/resource.h> |
27 | #include <qpe/mimetype.h> | ||
28 | #include <qpe/applnk.h> | ||
25 | #include <qpe/global.h> | 29 | #include <qpe/global.h> |
26 | 30 | ||
@@ -31,4 +35,5 @@ | |||
31 | #include <qpe/qpemenubar.h> | 35 | #include <qpe/qpemenubar.h> |
32 | #include <qpe/qpetoolbar.h> | 36 | #include <qpe/qpetoolbar.h> |
37 | #include <qpe/qcopenvelope_qws.h> | ||
33 | #include <qtoolbutton.h> | 38 | #include <qtoolbutton.h> |
34 | #include <qiconset.h> | 39 | #include <qiconset.h> |
@@ -49,6 +54,7 @@ | |||
49 | #include <qaction.h> | 54 | #include <qaction.h> |
50 | 55 | ||
51 | #include <ctype.h> | 56 | #include <cctype> |
52 | 57 | ||
58 | #include "magictextbrowser.h" | ||
53 | 59 | ||
54 | HelpBrowser::HelpBrowser( QWidget* parent, const char *name, WFlags f ) | 60 | HelpBrowser::HelpBrowser( QWidget* parent, const char *name, WFlags f ) |
@@ -59,9 +65,12 @@ HelpBrowser::HelpBrowser( QWidget* parent, const char *name, WFlags f ) | |||
59 | } | 65 | } |
60 | 66 | ||
67 | |||
68 | |||
61 | void HelpBrowser::init( const QString& _home ) | 69 | void HelpBrowser::init( const QString& _home ) |
62 | { | 70 | { |
63 | setIcon( Resource::loadPixmap( "help_icon" ) ); | 71 | setIcon( Resource::loadPixmap( "HelpBrowser" ) ); |
72 | setBackgroundMode( PaletteButton ); | ||
64 | 73 | ||
65 | browser = new QTextBrowser( this ); | 74 | browser = new MagicTextBrowser( this ); |
66 | browser->setFrameStyle( QFrame::Panel | QFrame::Sunken ); | 75 | browser->setFrameStyle( QFrame::Panel | QFrame::Sunken ); |
67 | connect( browser, SIGNAL( textChanged() ), | 76 | connect( browser, SIGNAL( textChanged() ), |
@@ -81,10 +90,10 @@ void HelpBrowser::init( const QString& _home ) | |||
81 | // addToolBar( toolbar, "Toolbar"); | 90 | // addToolBar( toolbar, "Toolbar"); |
82 | 91 | ||
83 | //QPopupMenu* go = new QPopupMenu( this ); | 92 | QPopupMenu* go = new QPopupMenu( this ); |
84 | backAction = new QAction( tr( "Backward" ), Resource::loadIconSet( "back" ), QString::null, 0, this, 0 ); | 93 | backAction = new QAction( tr( "Backward" ), Resource::loadIconSet( "back" ), QString::null, 0, this, 0 ); |
85 | connect( backAction, SIGNAL( activated() ), browser, SLOT( backward() ) ); | 94 | connect( backAction, SIGNAL( activated() ), browser, SLOT( backward() ) ); |
86 | connect( browser, SIGNAL( backwardAvailable( bool ) ), | 95 | connect( browser, SIGNAL( backwardAvailable( bool ) ), |
87 | backAction, SLOT( setEnabled( bool ) ) ); | 96 | backAction, SLOT( setEnabled( bool ) ) ); |
88 | //backAction->addTo( go ); | 97 | backAction->addTo( go ); |
89 | backAction->addTo( toolbar ); | 98 | backAction->addTo( toolbar ); |
90 | backAction->setEnabled( FALSE ); | 99 | backAction->setEnabled( FALSE ); |
@@ -94,12 +103,11 @@ void HelpBrowser::init( const QString& _home ) | |||
94 | connect( browser, SIGNAL( forwardAvailable( bool ) ), | 103 | connect( browser, SIGNAL( forwardAvailable( bool ) ), |
95 | forwardAction, SLOT( setEnabled( bool ) ) ); | 104 | forwardAction, SLOT( setEnabled( bool ) ) ); |
96 | //forwardAction->addTo( go ); | 105 | forwardAction->addTo( go ); |
97 | forwardAction->addTo( toolbar ); | 106 | forwardAction->addTo( toolbar ); |
98 | forwardAction->setEnabled( FALSE ); | 107 | forwardAction->setEnabled( FALSE ); |
99 | 108 | ||
100 | QAction *a = new QAction( tr( "Home" ), Resource::loadPixmap( | 109 | QAction *a = new QAction( tr( "Home" ), Resource::loadIconSet( "home" ), QString::null, 0, this, 0 ); |
101 | "home" ), QString::null, 0, this, 0 ); | ||
102 | connect( a, SIGNAL( activated() ), browser, SLOT( home() ) ); | 110 | connect( a, SIGNAL( activated() ), browser, SLOT( home() ) ); |
103 | //a->addTo( go ); | 111 | a->addTo( go ); |
104 | a->addTo( toolbar ); | 112 | a->addTo( toolbar ); |
105 | 113 | ||
@@ -113,9 +121,16 @@ void HelpBrowser::init( const QString& _home ) | |||
113 | readBookmarks(); | 121 | readBookmarks(); |
114 | 122 | ||
115 | //menu->insertItem( tr("Go"), go ); | 123 | menu->insertItem( tr("Go"), go ); |
116 | menu->insertItem( tr( "Bookmarks" ), bookm ); | 124 | menu->insertItem( tr( "Bookmarks" ), bookm ); |
117 | 125 | ||
118 | resize( 240, 300 ); | 126 | resize( 240, 300 ); |
119 | browser->setFocus(); | 127 | browser->setFocus(); |
128 | browser->setFrameStyle( QFrame::NoFrame ); | ||
129 | |||
130 | #if !defined(QT_NO_COP) | ||
131 | QCopChannel *addressChannel = new QCopChannel("QPE/HelpBrowser" , this ); | ||
132 | connect (addressChannel, SIGNAL( received(const QCString &, const QByteArray &)), | ||
133 | this, SLOT ( appMessage(const QCString &, const QByteArray &) ) ); | ||
134 | #endif | ||
120 | 135 | ||
121 | connect( qApp, SIGNAL(appMessage(const QCString&, const QByteArray&)), | 136 | connect( qApp, SIGNAL(appMessage(const QCString&, const QByteArray&)), |
@@ -125,4 +140,5 @@ void HelpBrowser::init( const QString& _home ) | |||
125 | void HelpBrowser::appMessage(const QCString& msg, const QByteArray& data) | 140 | void HelpBrowser::appMessage(const QCString& msg, const QByteArray& data) |
126 | { | 141 | { |
142 | qDebug("reached appMessage"); | ||
127 | if ( msg == "showFile(QString)" ) { | 143 | if ( msg == "showFile(QString)" ) { |
128 | QDataStream ds(data,IO_ReadOnly); | 144 | QDataStream ds(data,IO_ReadOnly); |
@@ -130,4 +146,10 @@ void HelpBrowser::appMessage(const QCString& msg, const QByteArray& data) | |||
130 | ds >> fn; | 146 | ds >> fn; |
131 | setDocument( fn ); | 147 | setDocument( fn ); |
148 | |||
149 | QPEApplication::setKeepRunning(); | ||
150 | |||
151 | showMaximized(); | ||
152 | setActiveWindow(); | ||
153 | raise(); | ||
132 | } | 154 | } |
133 | } | 155 | } |
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,6 +1,6 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of the Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
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 | |||
@@ -2,6 +2,6 @@ TEMPLATE = app | |||
2 | CONFIG = qt warn_on release | 2 | CONFIG = qt warn_on release |
3 | DESTDIR = $(OPIEDIR)/bin | 3 | DESTDIR = $(OPIEDIR)/bin |
4 | HEADERS = helpbrowser.h | 4 | HEADERS = helpbrowser.h magictextbrowser.h |
5 | SOURCES = helpbrowser.cpp \ | 5 | SOURCES = helpbrowser.cpp magictextbrowser.cpp \ |
6 | main.cpp | 6 | main.cpp |
7 | INCLUDEPATH += $(OPIEDIR)/include | 7 | INCLUDEPATH += $(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 @@ | |||
1 | #include <qfile.h> | ||
2 | #include <qstring.h> | ||
3 | #include <qdragobject.h> | ||
4 | #include <qregexp.h> | ||
5 | |||
6 | /* need to get Global::helpPath() */ | ||
7 | #define QTOPIA_INTERNAL_LANGLIST | ||
8 | |||
9 | #include <qtopia/global.h> | ||
10 | #include <qtopia/mimetype.h> | ||
11 | #include <qtopia/applnk.h> | ||
12 | |||
13 | #include "magictextbrowser.h" | ||
14 | |||
15 | |||
16 | |||
17 | MagicTextBrowser::MagicTextBrowser(QWidget* parent) : | ||
18 | QTextBrowser(parent){ | ||
19 | } | ||
20 | |||
21 | void MagicTextBrowser::setSource( const QString& source ) { | ||
22 | QTextBrowser::setSource(source); | ||
23 | if ( magicQpe(source,"applications") || magicQpe(source,"games") || magicQpe(source,"settings") || magicQpe(source, "1Pim") ) // No tr | ||
24 | return; | ||
25 | if ( magicOpe(source, "applets") || magicOpe(source, "input") ) | ||
26 | return; | ||
27 | // Just those are magic (for now). Could do CGI here, | ||
28 | // or in Qtopia's mime source factory. | ||
29 | } | ||
30 | |||
31 | bool MagicTextBrowser::magicQpe(const QString& source, const QString& name) { | ||
32 | if ( name+".html" == source || "help/"+name+".html" == source) { | ||
33 | QString fn = mimeSourceFactory()->makeAbsolute( source, context() ); | ||
34 | const QMimeSource* m = mimeSourceFactory()->data( fn, context() ); | ||
35 | if ( m ) { | ||
36 | QString txt; | ||
37 | if ( QTextDrag::decode(m,txt) ) { | ||
38 | QRegExp re("<qtopia-"+name+">.*</qtopia-"+name+">"); | ||
39 | int start,len; | ||
40 | if ( (start=re.match(txt,0,&len))>=0 ) { | ||
41 | QString generated = generateQpe(name); | ||
42 | txt.replace(start,len,generated); | ||
43 | setText(txt); | ||
44 | return true; | ||
45 | } | ||
46 | } | ||
47 | } | ||
48 | } | ||
49 | return false; | ||
50 | } | ||
51 | bool MagicTextBrowser::magicOpe( const QString& source, const QString& name ) { | ||
52 | if ( name+".html" != source && "help/"+name+".html" != source) return false; | ||
53 | |||
54 | QString fn = mimeSourceFactory()->makeAbsolute( source, context() ); | ||
55 | const QMimeSource* m = mimeSourceFactory()->data(fn, context() ); | ||
56 | if (!m) return false; | ||
57 | |||
58 | QString txt; | ||
59 | if ( !QTextDrag::decode(m, txt ) ) return false; | ||
60 | |||
61 | QRegExp re("<opie-"+name+">.*</opie-"+name+">"); | ||
62 | int start,len; | ||
63 | if ( (start=re.match(txt,0,&len))>=0 ) { | ||
64 | QString generated = generateOpe(name); | ||
65 | txt.replace(start,len,generated); | ||
66 | setText(txt); | ||
67 | return true; | ||
68 | } | ||
69 | return false; | ||
70 | } | ||
71 | QString MagicTextBrowser::generateOpe(const QString& name)const { | ||
72 | if ( name == QString::fromLatin1("applets") ) { | ||
73 | return QString::fromLatin1("<h3>No Applets found</h3>"); | ||
74 | }else if ( name == QString::fromLatin1("input") ) { | ||
75 | return QString::fromLatin1("<h3>No input methods available</h3>"); | ||
76 | }else | ||
77 | return QString::null; | ||
78 | } | ||
79 | |||
80 | QString MagicTextBrowser::generateQpe(const QString& name) const { | ||
81 | QString dir = MimeType::appsFolderName()+"/"+name[0].upper()+name.mid(1); | ||
82 | AppLnkSet lnkset(dir); | ||
83 | AppLnk* lnk; | ||
84 | QString r; | ||
85 | for (QListIterator<AppLnk> it(lnkset.children()); (lnk=it.current()); ++it) { | ||
86 | QString name = lnk->name(); | ||
87 | QString icon = lnk->icon(); | ||
88 | QString helpFile = lnk->exec()+".html"; | ||
89 | QStringList helpPath = Global::helpPath(); | ||
90 | bool helpExists = FALSE; | ||
91 | for (QStringList::ConstIterator it=helpPath.begin(); it!=helpPath.end() && !helpExists; ++it) | ||
92 | helpExists = QFile::exists( *it + "/" + helpFile ); | ||
93 | |||
94 | if ( helpExists ) { | ||
95 | r += "<h3><a href="+helpFile+"><img src="+icon+">"+name+"</a></h3>\n"; | ||
96 | } | ||
97 | } | ||
98 | return r; | ||
99 | } | ||
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 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | ||
3 | ** Copyright (C) 2003 zecke | ||
4 | ** | ||
5 | ** This file is part of the Qtopia Environment. | ||
6 | ** | ||
7 | ** This file may be distributed and/or modified under the terms of the | ||
8 | ** GNU General Public License version 2 as published by the Free Software | ||
9 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
10 | ** packaging of this file. | ||
11 | ** | ||
12 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | ||
13 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||
14 | ** | ||
15 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
16 | ** | ||
17 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
18 | ** not clear to you. | ||
19 | ** | ||
20 | **********************************************************************/ | ||
21 | #ifndef HELP_BROWSER_MAGIC_TEXT_BROWSER_H | ||
22 | #define HELP_BROWSER_MAGIC_TEXT_BROWSER_H | ||
23 | |||
24 | #include <qtextbrowser.h> | ||
25 | |||
26 | class MagicTextBrowser : public QTextBrowser { | ||
27 | public: | ||
28 | MagicTextBrowser(QWidget* parent); | ||
29 | |||
30 | void setSource( const QString& source ); | ||
31 | |||
32 | /** honor QPE Attributes */ | ||
33 | bool magicQpe(const QString& source, const QString& name); | ||
34 | /** honor OPIE Attributes */ | ||
35 | bool magicOpe(const QString& source, const QString& name ); | ||
36 | private: | ||
37 | |||
38 | QString generateQpe(const QString& name) const; | ||
39 | QString generateOpe(const QString& name) const; | ||
40 | }; | ||
41 | |||
42 | #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,6 +1,6 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of the Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
@@ -21,5 +21,5 @@ | |||
21 | #include "helpbrowser.h" | 21 | #include "helpbrowser.h" |
22 | 22 | ||
23 | #include <qpe/qpeapplication.h> | 23 | #include <qtopia/qpeapplication.h> |
24 | 24 | ||
25 | int main( int argc, char ** argv ) | 25 | int main( int argc, char ** argv ) |
@@ -28,6 +28,5 @@ int main( int argc, char ** argv ) | |||
28 | 28 | ||
29 | HelpBrowser mw; | 29 | HelpBrowser mw; |
30 | mw.setCaption( HelpBrowser::tr("HelpBrowser") ); | 30 | a.showMainWidget( &mw ); |
31 | a.showMainDocumentWidget( &mw ); | ||
32 | 31 | ||
33 | return a.exec(); | 32 | return a.exec(); |