Diffstat (limited to 'core/apps/helpbrowser/helpbrowser.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/apps/helpbrowser/helpbrowser.cpp | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/core/apps/helpbrowser/helpbrowser.cpp b/core/apps/helpbrowser/helpbrowser.cpp index 8fb0161..336d9fb 100644 --- a/core/apps/helpbrowser/helpbrowser.cpp +++ b/core/apps/helpbrowser/helpbrowser.cpp | |||
@@ -1,228 +1,228 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of the 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 |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
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 | 24 | ||
25 | #include <qpe/qpeapplication.h> | 25 | #include <qpe/qpeapplication.h> |
26 | #include <qpe/resource.h> | 26 | #include <qpe/resource.h> |
27 | 27 | ||
28 | #include <qmenubar.h> | 28 | #include <qmenubar.h> |
29 | #include <qtoolbar.h> | 29 | #include <qtoolbar.h> |
30 | #include <qpe/qcopenvelope_qws.h> | 30 | #include <qpe/qcopenvelope_qws.h> |
31 | #include <qfileinfo.h> | 31 | #include <qfileinfo.h> |
32 | #include <qaction.h> | 32 | #include <qaction.h> |
33 | 33 | ||
34 | #include <cctype> | 34 | #include <cctype> |
35 | 35 | ||
36 | #include "magictextbrowser.h" | 36 | #include "magictextbrowser.h" |
37 | 37 | ||
38 | HelpBrowser::HelpBrowser( QWidget* parent, const char *name, WFlags f ) | 38 | HelpBrowser::HelpBrowser( QWidget* parent, const char *name, WFlags f ) |
39 | : QMainWindow( parent, name, f ), | 39 | : QMainWindow( parent, name, f ), |
40 | selectedURL() | 40 | selectedURL() |
41 | { | 41 | { |
42 | init( "index.html" ); | 42 | init( "index.html" ); |
43 | } | 43 | } |
44 | 44 | ||
45 | 45 | ||
46 | 46 | ||
47 | void HelpBrowser::init( const QString& _home ) | 47 | void HelpBrowser::init( const QString& _home ) |
48 | { | 48 | { |
49 | setIcon( Resource::loadPixmap( "HelpBrowser" ) ); | 49 | setIcon( Resource::loadPixmap( "HelpBrowser" ) ); |
50 | setBackgroundMode( PaletteButton ); | 50 | setBackgroundMode( PaletteButton ); |
51 | 51 | ||
52 | browser = new MagicTextBrowser( this ); | 52 | browser = new MagicTextBrowser( this ); |
53 | browser->setFrameStyle( QFrame::Panel | QFrame::Sunken ); | 53 | browser->setFrameStyle( QFrame::Panel | QFrame::Sunken ); |
54 | connect( browser, SIGNAL( textChanged() ), | 54 | connect( browser, SIGNAL( textChanged() ), |
55 | this, SLOT( textChanged() ) ); | 55 | this, SLOT( textChanged() ) ); |
56 | 56 | ||
57 | setCentralWidget( browser ); | 57 | setCentralWidget( browser ); |
58 | setToolBarsMovable( FALSE ); | 58 | setToolBarsMovable( FALSE ); |
59 | 59 | ||
60 | if ( !_home.isEmpty() ) | 60 | if ( !_home.isEmpty() ) |
61 | browser->setSource( _home ); | 61 | browser->setSource( _home ); |
62 | 62 | ||
63 | QToolBar* toolbar = new QToolBar( this ); | 63 | QToolBar* toolbar = new QToolBar( this ); |
64 | toolbar->setHorizontalStretchable( TRUE ); | 64 | toolbar->setHorizontalStretchable( TRUE ); |
65 | QMenuBar *menu = new QMenuBar( toolbar ); | 65 | QMenuBar *menu = new QMenuBar( toolbar ); |
66 | 66 | ||
67 | toolbar = new QToolBar( this ); | 67 | toolbar = new QToolBar( this ); |
68 | // addToolBar( toolbar, "Toolbar"); | 68 | // addToolBar( toolbar, "Toolbar"); |
69 | 69 | ||
70 | QPopupMenu* go = new QPopupMenu( this ); | 70 | QPopupMenu* go = new QPopupMenu( this ); |
71 | backAction = new QAction( tr( "Backward" ), Resource::loadIconSet( "back" ), QString::null, 0, this, 0 ); | 71 | backAction = new QAction( tr( "Backward" ), Resource::loadIconSet( "back" ), QString::null, 0, this, 0 ); |
72 | connect( backAction, SIGNAL( activated() ), browser, SLOT( backward() ) ); | 72 | connect( backAction, SIGNAL( activated() ), browser, SLOT( backward() ) ); |
73 | connect( browser, SIGNAL( backwardAvailable( bool ) ), | 73 | connect( browser, SIGNAL( backwardAvailable(bool) ), |
74 | backAction, SLOT( setEnabled( bool ) ) ); | 74 | backAction, SLOT( setEnabled(bool) ) ); |
75 | backAction->addTo( go ); | 75 | backAction->addTo( go ); |
76 | backAction->addTo( toolbar ); | 76 | backAction->addTo( toolbar ); |
77 | backAction->setEnabled( FALSE ); | 77 | backAction->setEnabled( FALSE ); |
78 | 78 | ||
79 | forwardAction = new QAction( tr( "Forward" ), Resource::loadIconSet( "forward" ), QString::null, 0, this, 0 ); | 79 | forwardAction = new QAction( tr( "Forward" ), Resource::loadIconSet( "forward" ), QString::null, 0, this, 0 ); |
80 | connect( forwardAction, SIGNAL( activated() ), browser, SLOT( forward() ) ); | 80 | connect( forwardAction, SIGNAL( activated() ), browser, SLOT( forward() ) ); |
81 | connect( browser, SIGNAL( forwardAvailable( bool ) ), | 81 | connect( browser, SIGNAL( forwardAvailable(bool) ), |
82 | forwardAction, SLOT( setEnabled( bool ) ) ); | 82 | forwardAction, SLOT( setEnabled(bool) ) ); |
83 | forwardAction->addTo( go ); | 83 | forwardAction->addTo( go ); |
84 | forwardAction->addTo( toolbar ); | 84 | forwardAction->addTo( toolbar ); |
85 | forwardAction->setEnabled( FALSE ); | 85 | forwardAction->setEnabled( FALSE ); |
86 | 86 | ||
87 | QAction *a = new QAction( tr( "Home" ), Resource::loadIconSet( "home" ), QString::null, 0, this, 0 ); | 87 | QAction *a = new QAction( tr( "Home" ), Resource::loadIconSet( "home" ), QString::null, 0, this, 0 ); |
88 | connect( a, SIGNAL( activated() ), browser, SLOT( home() ) ); | 88 | connect( a, SIGNAL( activated() ), browser, SLOT( home() ) ); |
89 | a->addTo( go ); | 89 | a->addTo( go ); |
90 | a->addTo( toolbar ); | 90 | a->addTo( toolbar ); |
91 | 91 | ||
92 | bookm = new QPopupMenu( this ); | 92 | bookm = new QPopupMenu( this ); |
93 | bookm->insertItem( tr( "Add Bookmark" ), this, SLOT( addBookmark() ) ); | 93 | bookm->insertItem( tr( "Add Bookmark" ), this, SLOT( addBookmark() ) ); |
94 | bookm->insertItem( tr( "Remove from Bookmarks" ), this, SLOT( removeBookmark() ) ); | 94 | bookm->insertItem( tr( "Remove from Bookmarks" ), this, SLOT( removeBookmark() ) ); |
95 | bookm->insertSeparator(); | 95 | bookm->insertSeparator(); |
96 | connect( bookm, SIGNAL( activated( int ) ), | 96 | connect( bookm, SIGNAL( activated(int) ), |
97 | this, SLOT( bookmChosen( int ) ) ); | 97 | this, SLOT( bookmChosen(int) ) ); |
98 | 98 | ||
99 | readBookmarks(); | 99 | readBookmarks(); |
100 | 100 | ||
101 | menu->insertItem( tr("Go"), go ); | 101 | menu->insertItem( tr("Go"), go ); |
102 | menu->insertItem( tr( "Bookmarks" ), bookm ); | 102 | menu->insertItem( tr( "Bookmarks" ), bookm ); |
103 | 103 | ||
104 | resize( 240, 300 ); | 104 | resize( 240, 300 ); |
105 | browser->setFocus(); | 105 | browser->setFocus(); |
106 | browser->setFrameStyle( QFrame::NoFrame ); | 106 | browser->setFrameStyle( QFrame::NoFrame ); |
107 | 107 | ||
108 | #if !defined(QT_NO_COP) | 108 | #if !defined(QT_NO_COP) |
109 | QCopChannel *addressChannel = new QCopChannel("QPE/HelpBrowser" , this ); | 109 | QCopChannel *addressChannel = new QCopChannel("QPE/HelpBrowser" , this ); |
110 | connect (addressChannel, SIGNAL( received(const QCString &, const QByteArray &)), | 110 | connect (addressChannel, SIGNAL( received(const QCString&,const QByteArray&)), |
111 | this, SLOT ( appMessage(const QCString &, const QByteArray &) ) ); | 111 | this, SLOT ( appMessage(const QCString&,const QByteArray&) ) ); |
112 | #endif | 112 | #endif |
113 | 113 | ||
114 | connect( qApp, SIGNAL(appMessage(const QCString&, const QByteArray&)), | 114 | connect( qApp, SIGNAL(appMessage(const QCString&,const QByteArray&)), |
115 | this, SLOT(appMessage(const QCString&, const QByteArray&)) ); | 115 | this, SLOT(appMessage(const QCString&,const QByteArray&)) ); |
116 | } | 116 | } |
117 | 117 | ||
118 | void HelpBrowser::appMessage(const QCString& msg, const QByteArray& data) | 118 | void HelpBrowser::appMessage(const QCString& msg, const QByteArray& data) |
119 | { | 119 | { |
120 | qDebug("reached appMessage"); | 120 | qDebug("reached appMessage"); |
121 | if ( msg == "showFile(QString)" ) { | 121 | if ( msg == "showFile(QString)" ) { |
122 | QDataStream ds(data,IO_ReadOnly); | 122 | QDataStream ds(data,IO_ReadOnly); |
123 | QString fn; | 123 | QString fn; |
124 | ds >> fn; | 124 | ds >> fn; |
125 | setDocument( fn ); | 125 | setDocument( fn ); |
126 | 126 | ||
127 | QPEApplication::setKeepRunning(); | 127 | QPEApplication::setKeepRunning(); |
128 | 128 | ||
129 | showMaximized(); | 129 | showMaximized(); |
130 | setActiveWindow(); | 130 | setActiveWindow(); |
131 | raise(); | 131 | raise(); |
132 | } | 132 | } |
133 | } | 133 | } |
134 | 134 | ||
135 | void HelpBrowser::setDocument( const QString &doc ) | 135 | void HelpBrowser::setDocument( const QString &doc ) |
136 | { | 136 | { |
137 | if ( !doc.isEmpty() ) | 137 | if ( !doc.isEmpty() ) |
138 | browser->setSource( doc ); | 138 | browser->setSource( doc ); |
139 | raise(); | 139 | raise(); |
140 | } | 140 | } |
141 | 141 | ||
142 | 142 | ||
143 | void HelpBrowser::textChanged() | 143 | void HelpBrowser::textChanged() |
144 | { | 144 | { |
145 | if ( browser->documentTitle().isNull() ) | 145 | if ( browser->documentTitle().isNull() ) |
146 | setCaption( tr("Help Browser") ); | 146 | setCaption( tr("Help Browser") ); |
147 | else | 147 | else |
148 | setCaption( browser->documentTitle() ) ; | 148 | setCaption( browser->documentTitle() ) ; |
149 | 149 | ||
150 | selectedURL = caption(); | 150 | selectedURL = caption(); |
151 | } | 151 | } |
152 | 152 | ||
153 | HelpBrowser::~HelpBrowser() | 153 | HelpBrowser::~HelpBrowser() |
154 | { | 154 | { |
155 | QStringList bookmarks; | 155 | QStringList bookmarks; |
156 | QMap<int, Bookmark>::Iterator it2 = mBookmarks.begin(); | 156 | QMap<int, Bookmark>::Iterator it2 = mBookmarks.begin(); |
157 | for ( ; it2 != mBookmarks.end(); ++it2 ) | 157 | for ( ; it2 != mBookmarks.end(); ++it2 ) |
158 | bookmarks.append( (*it2).name + "=" + (*it2).file ); | 158 | bookmarks.append( (*it2).name + "=" + (*it2).file ); |
159 | 159 | ||
160 | QFile f2( Global::applicationFileName("helpbrowser", "bookmarks") ); | 160 | QFile f2( Global::applicationFileName("helpbrowser", "bookmarks") ); |
161 | if ( f2.open( IO_WriteOnly ) ) { | 161 | if ( f2.open( IO_WriteOnly ) ) { |
162 | QDataStream s2( &f2 ); | 162 | QDataStream s2( &f2 ); |
163 | s2 << bookmarks; | 163 | s2 << bookmarks; |
164 | f2.close(); | 164 | f2.close(); |
165 | } | 165 | } |
166 | } | 166 | } |
167 | 167 | ||
168 | void HelpBrowser::pathSelected( const QString &_path ) | 168 | void HelpBrowser::pathSelected( const QString &_path ) |
169 | { | 169 | { |
170 | browser->setSource( _path ); | 170 | browser->setSource( _path ); |
171 | } | 171 | } |
172 | 172 | ||
173 | void HelpBrowser::readBookmarks() | 173 | void HelpBrowser::readBookmarks() |
174 | { | 174 | { |
175 | QString file = Global::applicationFileName("helpbrowser", "bookmarks"); | 175 | QString file = Global::applicationFileName("helpbrowser", "bookmarks"); |
176 | if ( QFile::exists( file ) ) { | 176 | if ( QFile::exists( file ) ) { |
177 | QStringList bookmarks; | 177 | QStringList bookmarks; |
178 | QFile f( file ); | 178 | QFile f( file ); |
179 | if ( f.open( IO_ReadOnly ) ) { | 179 | if ( f.open( IO_ReadOnly ) ) { |
180 | QDataStream s( &f ); | 180 | QDataStream s( &f ); |
181 | s >> bookmarks; | 181 | s >> bookmarks; |
182 | f.close(); | 182 | f.close(); |
183 | } | 183 | } |
184 | QStringList::Iterator it = bookmarks.begin(); | 184 | QStringList::Iterator it = bookmarks.begin(); |
185 | for ( ; it != bookmarks.end(); ++it ) { | 185 | for ( ; it != bookmarks.end(); ++it ) { |
186 | Bookmark b; | 186 | Bookmark b; |
187 | QString current = *it; | 187 | QString current = *it; |
188 | int equal = current.find( "=" ); | 188 | int equal = current.find( "=" ); |
189 | if ( equal < 1 || equal == (int)current.length() - 1 ) | 189 | if ( equal < 1 || equal == (int)current.length() - 1 ) |
190 | continue; | 190 | continue; |
191 | b.name = current.left( equal ); | 191 | b.name = current.left( equal ); |
192 | b.file = current.mid( equal + 1 ); | 192 | b.file = current.mid( equal + 1 ); |
193 | mBookmarks[ bookm->insertItem( b.name ) ] = b; | 193 | mBookmarks[ bookm->insertItem( b.name ) ] = b; |
194 | } | 194 | } |
195 | } | 195 | } |
196 | } | 196 | } |
197 | 197 | ||
198 | void HelpBrowser::bookmChosen( int i ) | 198 | void HelpBrowser::bookmChosen( int i ) |
199 | { | 199 | { |
200 | if ( mBookmarks.contains( i ) ) | 200 | if ( mBookmarks.contains( i ) ) |
201 | browser->setSource( mBookmarks[ i ].file ); | 201 | browser->setSource( mBookmarks[ i ].file ); |
202 | } | 202 | } |
203 | 203 | ||
204 | void HelpBrowser::addBookmark() | 204 | void HelpBrowser::addBookmark() |
205 | { | 205 | { |
206 | Bookmark b; | 206 | Bookmark b; |
207 | b.name = browser->documentTitle(); | 207 | b.name = browser->documentTitle(); |
208 | b.file = browser->source(); | 208 | b.file = browser->source(); |
209 | if (b.name.isEmpty() ) { | 209 | if (b.name.isEmpty() ) { |
210 | b.name = b.file.left( b.file.length() - 5 ); // remove .html | 210 | b.name = b.file.left( b.file.length() - 5 ); // remove .html |
211 | } | 211 | } |
212 | QMap<int, Bookmark>::Iterator it; | 212 | QMap<int, Bookmark>::Iterator it; |
213 | for( it = mBookmarks.begin(); it != mBookmarks.end(); ++it ) | 213 | for( it = mBookmarks.begin(); it != mBookmarks.end(); ++it ) |
214 | if ( (*it).file == b.file ) return; | 214 | if ( (*it).file == b.file ) return; |
215 | mBookmarks[ bookm->insertItem( b.name ) ] = b; | 215 | mBookmarks[ bookm->insertItem( b.name ) ] = b; |
216 | } | 216 | } |
217 | 217 | ||
218 | void HelpBrowser::removeBookmark() | 218 | void HelpBrowser::removeBookmark() |
219 | { | 219 | { |
220 | QString file = browser->source(); | 220 | QString file = browser->source(); |
221 | QMap<int, Bookmark>::Iterator it = mBookmarks.begin(); | 221 | QMap<int, Bookmark>::Iterator it = mBookmarks.begin(); |
222 | for( ; it != mBookmarks.end(); ++it ) | 222 | for( ; it != mBookmarks.end(); ++it ) |
223 | if ( (*it).file == file ) { | 223 | if ( (*it).file == file ) { |
224 | bookm->removeItem( it.key() ); | 224 | bookm->removeItem( it.key() ); |
225 | mBookmarks.remove( it ); | 225 | mBookmarks.remove( it ); |
226 | break; | 226 | break; |
227 | } | 227 | } |
228 | } | 228 | } |