summaryrefslogtreecommitdiff
path: root/core/apps/helpbrowser/helpbrowser.cpp
Unidiff
Diffstat (limited to 'core/apps/helpbrowser/helpbrowser.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/apps/helpbrowser/helpbrowser.cpp103
1 files changed, 52 insertions, 51 deletions
diff --git a/core/apps/helpbrowser/helpbrowser.cpp b/core/apps/helpbrowser/helpbrowser.cpp
index 336d9fb..cbb4059 100644
--- a/core/apps/helpbrowser/helpbrowser.cpp
+++ b/core/apps/helpbrowser/helpbrowser.cpp
@@ -18,26 +18,27 @@
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#define QTOPIA_INTERNAL_LANGLIST 21#define QTOPIA_INTERNAL_LANGLIST
22 22
23#include "helpbrowser.h" 23#include "helpbrowser.h"
24#include "magictextbrowser.h"
24 25
26/* OPIE */
27#include <opie2/odebug.h>
25#include <qpe/qpeapplication.h> 28#include <qpe/qpeapplication.h>
26#include <qpe/resource.h> 29#include <qpe/resource.h>
30using namespace Opie::Core;
27 31
32/* QT */
28#include <qmenubar.h> 33#include <qmenubar.h>
29#include <qtoolbar.h> 34#include <qtoolbar.h>
30#include <qpe/qcopenvelope_qws.h> 35#include <qpe/qcopenvelope_qws.h>
31#include <qfileinfo.h> 36#include <qfileinfo.h>
32#include <qaction.h> 37#include <qaction.h>
33 38
34#include <cctype>
35
36#include "magictextbrowser.h"
37
38HelpBrowser::HelpBrowser( QWidget* parent, const char *name, WFlags f ) 39HelpBrowser::HelpBrowser( QWidget* parent, const char *name, WFlags f )
39 : QMainWindow( parent, name, f ), 40 : QMainWindow( parent, name, f ),
40 selectedURL() 41 selectedURL()
41{ 42{
42 init( "index.html" ); 43 init( "index.html" );
43} 44}
@@ -49,40 +50,40 @@ void HelpBrowser::init( const QString& _home )
49 setIcon( Resource::loadPixmap( "HelpBrowser" ) ); 50 setIcon( Resource::loadPixmap( "HelpBrowser" ) );
50 setBackgroundMode( PaletteButton ); 51 setBackgroundMode( PaletteButton );
51 52
52 browser = new MagicTextBrowser( this ); 53 browser = new MagicTextBrowser( this );
53 browser->setFrameStyle( QFrame::Panel | QFrame::Sunken ); 54 browser->setFrameStyle( QFrame::Panel | QFrame::Sunken );
54 connect( browser, SIGNAL( textChanged() ), 55 connect( browser, SIGNAL( textChanged() ),
55 this, SLOT( textChanged() ) ); 56 this, SLOT( textChanged() ) );
56 57
57 setCentralWidget( browser ); 58 setCentralWidget( browser );
58 setToolBarsMovable( FALSE ); 59 setToolBarsMovable( FALSE );
59 60
60 if ( !_home.isEmpty() ) 61 if ( !_home.isEmpty() )
61 browser->setSource( _home ); 62 browser->setSource( _home );
62 63
63 QToolBar* toolbar = new QToolBar( this ); 64 QToolBar* toolbar = new QToolBar( this );
64 toolbar->setHorizontalStretchable( TRUE ); 65 toolbar->setHorizontalStretchable( TRUE );
65 QMenuBar *menu = new QMenuBar( toolbar ); 66 QMenuBar *menu = new QMenuBar( toolbar );
66 67
67 toolbar = new QToolBar( this ); 68 toolbar = new QToolBar( this );
68 // addToolBar( toolbar, "Toolbar"); 69 // addToolBar( toolbar, "Toolbar");
69 70
70 QPopupMenu* go = new QPopupMenu( this ); 71 QPopupMenu* go = new QPopupMenu( this );
71 backAction = new QAction( tr( "Backward" ), Resource::loadIconSet( "back" ), QString::null, 0, this, 0 ); 72 backAction = new QAction( tr( "Backward" ), Resource::loadIconSet( "back" ), QString::null, 0, this, 0 );
72 connect( backAction, SIGNAL( activated() ), browser, SLOT( backward() ) ); 73 connect( backAction, SIGNAL( activated() ), browser, SLOT( backward() ) );
73 connect( browser, SIGNAL( backwardAvailable(bool) ), 74 connect( browser, SIGNAL( backwardAvailable(bool) ),
74 backAction, SLOT( setEnabled(bool) ) ); 75 backAction, SLOT( setEnabled(bool) ) );
75 backAction->addTo( go ); 76 backAction->addTo( go );
76 backAction->addTo( toolbar ); 77 backAction->addTo( toolbar );
77 backAction->setEnabled( FALSE ); 78 backAction->setEnabled( FALSE );
78 79
79 forwardAction = new QAction( tr( "Forward" ), Resource::loadIconSet( "forward" ), QString::null, 0, this, 0 ); 80 forwardAction = new QAction( tr( "Forward" ), Resource::loadIconSet( "forward" ), QString::null, 0, this, 0 );
80 connect( forwardAction, SIGNAL( activated() ), browser, SLOT( forward() ) ); 81 connect( forwardAction, SIGNAL( activated() ), browser, SLOT( forward() ) );
81 connect( browser, SIGNAL( forwardAvailable(bool) ), 82 connect( browser, SIGNAL( forwardAvailable(bool) ),
82 forwardAction, SLOT( setEnabled(bool) ) ); 83 forwardAction, SLOT( setEnabled(bool) ) );
83 forwardAction->addTo( go ); 84 forwardAction->addTo( go );
84 forwardAction->addTo( toolbar ); 85 forwardAction->addTo( toolbar );
85 forwardAction->setEnabled( FALSE ); 86 forwardAction->setEnabled( FALSE );
86 87
87 QAction *a = new QAction( tr( "Home" ), Resource::loadIconSet( "home" ), QString::null, 0, this, 0 ); 88 QAction *a = new QAction( tr( "Home" ), Resource::loadIconSet( "home" ), QString::null, 0, this, 0 );
88 connect( a, SIGNAL( activated() ), browser, SLOT( home() ) ); 89 connect( a, SIGNAL( activated() ), browser, SLOT( home() ) );
@@ -91,13 +92,13 @@ void HelpBrowser::init( const QString& _home )
91 92
92 bookm = new QPopupMenu( this ); 93 bookm = new QPopupMenu( this );
93 bookm->insertItem( tr( "Add Bookmark" ), this, SLOT( addBookmark() ) ); 94 bookm->insertItem( tr( "Add Bookmark" ), this, SLOT( addBookmark() ) );
94 bookm->insertItem( tr( "Remove from Bookmarks" ), this, SLOT( removeBookmark() ) ); 95 bookm->insertItem( tr( "Remove from Bookmarks" ), this, SLOT( removeBookmark() ) );
95 bookm->insertSeparator(); 96 bookm->insertSeparator();
96 connect( bookm, SIGNAL( activated(int) ), 97 connect( bookm, SIGNAL( activated(int) ),
97 this, SLOT( bookmChosen(int) ) ); 98 this, SLOT( bookmChosen(int) ) );
98 99
99 readBookmarks(); 100 readBookmarks();
100 101
101 menu->insertItem( tr("Go"), go ); 102 menu->insertItem( tr("Go"), go );
102 menu->insertItem( tr( "Bookmarks" ), bookm ); 103 menu->insertItem( tr( "Bookmarks" ), bookm );
103 104
@@ -109,120 +110,120 @@ void HelpBrowser::init( const QString& _home )
109 QCopChannel *addressChannel = new QCopChannel("QPE/HelpBrowser" , this ); 110 QCopChannel *addressChannel = new QCopChannel("QPE/HelpBrowser" , this );
110 connect (addressChannel, SIGNAL( received(const QCString&,const QByteArray&)), 111 connect (addressChannel, SIGNAL( received(const QCString&,const QByteArray&)),
111 this, SLOT ( appMessage(const QCString&,const QByteArray&) ) ); 112 this, SLOT ( appMessage(const QCString&,const QByteArray&) ) );
112#endif 113#endif
113 114
114 connect( qApp, SIGNAL(appMessage(const QCString&,const QByteArray&)), 115 connect( qApp, SIGNAL(appMessage(const QCString&,const QByteArray&)),
115 this, SLOT(appMessage(const QCString&,const QByteArray&)) ); 116 this, SLOT(appMessage(const QCString&,const QByteArray&)) );
116} 117}
117 118
118void HelpBrowser::appMessage(const QCString& msg, const QByteArray& data) 119void HelpBrowser::appMessage(const QCString& msg, const QByteArray& data)
119{ 120{
120 qDebug("reached appMessage"); 121 odebug << "reached appMessage" << oendl;
121 if ( msg == "showFile(QString)" ) { 122 if ( msg == "showFile(QString)" ) {
122 QDataStream ds(data,IO_ReadOnly); 123 QDataStream ds(data,IO_ReadOnly);
123 QString fn; 124 QString fn;
124 ds >> fn; 125 ds >> fn;
125 setDocument( fn ); 126 setDocument( fn );
126 127
127 QPEApplication::setKeepRunning(); 128 QPEApplication::setKeepRunning();
128 129
129 showMaximized(); 130 showMaximized();
130 setActiveWindow(); 131 setActiveWindow();
131 raise(); 132 raise();
132 } 133 }
133} 134}
134 135
135void HelpBrowser::setDocument( const QString &doc ) 136void HelpBrowser::setDocument( const QString &doc )
136{ 137{
137 if ( !doc.isEmpty() ) 138 if ( !doc.isEmpty() )
138 browser->setSource( doc ); 139 browser->setSource( doc );
139 raise(); 140 raise();
140} 141}
141 142
142 143
143void HelpBrowser::textChanged() 144void HelpBrowser::textChanged()
144{ 145{
145 if ( browser->documentTitle().isNull() ) 146 if ( browser->documentTitle().isNull() )
146 setCaption( tr("Help Browser") ); 147 setCaption( tr("Help Browser") );
147 else 148 else
148 setCaption( browser->documentTitle() ) ; 149 setCaption( browser->documentTitle() ) ;
149 150
150 selectedURL = caption(); 151 selectedURL = caption();
151} 152}
152 153
153HelpBrowser::~HelpBrowser() 154HelpBrowser::~HelpBrowser()
154{ 155{
155 QStringList bookmarks; 156 QStringList bookmarks;
156 QMap<int, Bookmark>::Iterator it2 = mBookmarks.begin(); 157 QMap<int, Bookmark>::Iterator it2 = mBookmarks.begin();
157 for ( ; it2 != mBookmarks.end(); ++it2 ) 158 for ( ; it2 != mBookmarks.end(); ++it2 )
158 bookmarks.append( (*it2).name + "=" + (*it2).file ); 159 bookmarks.append( (*it2).name + "=" + (*it2).file );
159 160
160 QFile f2( Global::applicationFileName("helpbrowser", "bookmarks") ); 161 QFile f2( Global::applicationFileName("helpbrowser", "bookmarks") );
161 if ( f2.open( IO_WriteOnly ) ) { 162 if ( f2.open( IO_WriteOnly ) ) {
162 QDataStream s2( &f2 ); 163 QDataStream s2( &f2 );
163 s2 << bookmarks; 164 s2 << bookmarks;
164 f2.close(); 165 f2.close();
165 } 166 }
166} 167}
167 168
168void HelpBrowser::pathSelected( const QString &_path ) 169void HelpBrowser::pathSelected( const QString &_path )
169{ 170{
170 browser->setSource( _path ); 171 browser->setSource( _path );
171} 172}
172 173
173void HelpBrowser::readBookmarks() 174void HelpBrowser::readBookmarks()
174{ 175{
175 QString file = Global::applicationFileName("helpbrowser", "bookmarks"); 176 QString file = Global::applicationFileName("helpbrowser", "bookmarks");
176 if ( QFile::exists( file ) ) { 177 if ( QFile::exists( file ) ) {
177 QStringList bookmarks; 178 QStringList bookmarks;
178 QFile f( file ); 179 QFile f( file );
179 if ( f.open( IO_ReadOnly ) ) { 180 if ( f.open( IO_ReadOnly ) ) {
180 QDataStream s( &f ); 181 QDataStream s( &f );
181 s >> bookmarks; 182 s >> bookmarks;
182 f.close(); 183 f.close();
183 } 184 }
184 QStringList::Iterator it = bookmarks.begin(); 185 QStringList::Iterator it = bookmarks.begin();
185 for ( ; it != bookmarks.end(); ++it ) { 186 for ( ; it != bookmarks.end(); ++it ) {
186 Bookmark b; 187 Bookmark b;
187 QString current = *it; 188 QString current = *it;
188 int equal = current.find( "=" ); 189 int equal = current.find( "=" );
189 if ( equal < 1 || equal == (int)current.length() - 1 ) 190 if ( equal < 1 || equal == (int)current.length() - 1 )
190 continue; 191 continue;
191 b.name = current.left( equal ); 192 b.name = current.left( equal );
192 b.file = current.mid( equal + 1 ); 193 b.file = current.mid( equal + 1 );
193 mBookmarks[ bookm->insertItem( b.name ) ] = b; 194 mBookmarks[ bookm->insertItem( b.name ) ] = b;
194 } 195 }
195 } 196 }
196} 197}
197 198
198void HelpBrowser::bookmChosen( int i ) 199void HelpBrowser::bookmChosen( int i )
199{ 200{
200 if ( mBookmarks.contains( i ) ) 201 if ( mBookmarks.contains( i ) )
201 browser->setSource( mBookmarks[ i ].file ); 202 browser->setSource( mBookmarks[ i ].file );
202} 203}
203 204
204void HelpBrowser::addBookmark() 205void HelpBrowser::addBookmark()
205{ 206{
206 Bookmark b; 207 Bookmark b;
207 b.name = browser->documentTitle(); 208 b.name = browser->documentTitle();
208 b.file = browser->source(); 209 b.file = browser->source();
209 if (b.name.isEmpty() ) { 210 if (b.name.isEmpty() ) {
210 b.name = b.file.left( b.file.length() - 5 ); // remove .html 211 b.name = b.file.left( b.file.length() - 5 ); // remove .html
211 } 212 }
212 QMap<int, Bookmark>::Iterator it; 213 QMap<int, Bookmark>::Iterator it;
213 for( it = mBookmarks.begin(); it != mBookmarks.end(); ++it ) 214 for( it = mBookmarks.begin(); it != mBookmarks.end(); ++it )
214 if ( (*it).file == b.file ) return; 215 if ( (*it).file == b.file ) return;
215 mBookmarks[ bookm->insertItem( b.name ) ] = b; 216 mBookmarks[ bookm->insertItem( b.name ) ] = b;
216} 217}
217 218
218void HelpBrowser::removeBookmark() 219void HelpBrowser::removeBookmark()
219{ 220{
220 QString file = browser->source(); 221 QString file = browser->source();
221 QMap<int, Bookmark>::Iterator it = mBookmarks.begin(); 222 QMap<int, Bookmark>::Iterator it = mBookmarks.begin();
222 for( ; it != mBookmarks.end(); ++it ) 223 for( ; it != mBookmarks.end(); ++it )
223 if ( (*it).file == file ) { 224 if ( (*it).file == file ) {
224 bookm->removeItem( it.key() ); 225 bookm->removeItem( it.key() );
225 mBookmarks.remove( it ); 226 mBookmarks.remove( it );
226 break; 227 break;
227 } 228 }
228} 229}