Rev 560 | Rev 603 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
564 | cbradney | 1 | /*************************************************************************** |
2 | * Copyright (C) 2004 by Craig Bradney * |
||
3 | * cbradney@zip.com.au * |
||
4 | * * |
||
5 | * This program is free software; you can redistribute it and/or modify * |
||
6 | * it under the terms of the GNU General Public License as published by * |
||
7 | * the Free Software Foundation; either version 2 of the License, or * |
||
8 | * (at your option) any later version. * |
||
9 | * * |
||
10 | * This program is distributed in the hope that it will be useful, * |
||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
||
13 | * GNU General Public License for more details. * |
||
14 | * * |
||
15 | * You should have received a copy of the GNU General Public License * |
||
16 | * along with this program; if not, write to the * |
||
17 | * Free Software Foundation, Inc., * |
||
18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
||
19 | ***************************************************************************/ |
||
560 | cbradney | 20 | |
3 | paul | 21 | #include "helpbrowser.h" |
22 | #include "helpbrowser.moc" |
||
560 | cbradney | 23 | |
3 | paul | 24 | #include <qvariant.h> |
560 | cbradney | 25 | #include <qpushbutton.h> |
26 | #include <qtabwidget.h> |
||
27 | #include <qwidget.h> |
||
28 | #include <qheader.h> |
||
29 | #include <qlistview.h> |
||
30 | #include <qtextbrowser.h> |
||
31 | #include <qlayout.h> |
||
3 | paul | 32 | #include <qtooltip.h> |
560 | cbradney | 33 | #include <qtoolbutton.h> |
34 | #include <qwhatsthis.h> |
||
3 | paul | 35 | #include <qimage.h> |
36 | #include <qpixmap.h> |
||
560 | cbradney | 37 | #include <qpopupmenu.h> |
38 | #include <qfileinfo.h> |
||
3 | paul | 39 | #include <qtextcodec.h> |
560 | cbradney | 40 | #include <qdom.h> |
128 | Franz | 41 | |
42 | #if (_MSC_VER >= 1200) |
||
564 | cbradney | 43 | #include "win-config.h" |
128 | Franz | 44 | #else |
564 | cbradney | 45 | #include "config.h" |
128 | Franz | 46 | #endif |
47 | |||
3 | paul | 48 | extern QPixmap loadIcon(QString nam); |
49 | |||
560 | cbradney | 50 | |
564 | cbradney | 51 | HelpBrowser::HelpBrowser( QWidget* parent, QString caption, QString guiLanguage, QString jumpToSection, QString jumpToFile) |
52 | : QWidget( parent, "Help", WType_TopLevel | WDestructiveClose ) |
||
3 | paul | 53 | { |
560 | cbradney | 54 | QString fileName; |
564 | cbradney | 55 | mHistory.clear(); |
56 | struct histd his; |
||
3 | paul | 57 | |
564 | cbradney | 58 | helpBrowsermainLayout = new QVBoxLayout( this); |
3 | paul | 59 | |
564 | cbradney | 60 | buttonLayout = new QHBoxLayout; |
61 | buttonLayout->setSpacing( 6 ); |
||
62 | buttonLayout->setMargin( 2 ); |
||
3 | paul | 63 | |
564 | cbradney | 64 | homeButton = new QToolButton( this, "homeButton" ); |
65 | homeButton->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, homeButton->sizePolicy().hasHeightForWidth() ) ); |
||
66 | homeButton->setMinimumSize( QSize( 0, 0 ) ); |
||
67 | homeButton->setMaximumSize( QSize( 32767, 32767 ) ); |
||
68 | homeButton->setText( "" ); |
||
69 | homeButton->setPixmap(loadIcon("gohome.png")); |
||
70 | buttonLayout->addWidget( homeButton ); |
||
3 | paul | 71 | |
564 | cbradney | 72 | histMenu = new QPopupMenu( this ); |
73 | backButton = new QToolButton( this, "backButton" ); |
||
74 | backButton->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, backButton->sizePolicy().hasHeightForWidth() ) ); |
||
75 | backButton->setMinimumSize( QSize( 0, 0 ) ); |
||
76 | backButton->setMaximumSize( QSize( 32767, 32767 ) ); |
||
77 | backButton->setPixmap(loadIcon("back.png")); |
||
78 | backButton->setPopup(histMenu); |
||
79 | backButton->setPopupDelay(0); |
||
80 | buttonLayout->addWidget( backButton ); |
||
3 | paul | 81 | |
564 | cbradney | 82 | forwButton = new QToolButton( this, "forwButton" ); |
83 | forwButton->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, forwButton->sizePolicy().hasHeightForWidth() ) ); |
||
84 | forwButton->setMinimumSize( QSize( 0, 0 ) ); |
||
85 | forwButton->setMaximumSize( QSize( 32767, 32767 ) ); |
||
86 | forwButton->setPixmap(loadIcon("forward.png")); |
||
87 | buttonLayout->addWidget( forwButton ); |
||
88 | QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ); |
||
89 | buttonLayout->addItem( spacer ); |
||
560 | cbradney | 90 | helpBrowsermainLayout->addLayout( buttonLayout ); |
91 | |||
564 | cbradney | 92 | helpBrowserLayout = new QHBoxLayout; |
560 | cbradney | 93 | |
564 | cbradney | 94 | tabWidget = new QTabWidget( this, "tabWidget" ); |
95 | tabWidget->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)7, (QSizePolicy::SizeType)7, 1, 0, tabWidget->sizePolicy().hasHeightForWidth() ) ); |
||
96 | tabContents = new QWidget( tabWidget, "tabContents" ); |
||
97 | tabLayout = new QHBoxLayout( tabContents, 11, 6, "tabLayout"); |
||
560 | cbradney | 98 | |
564 | cbradney | 99 | listView = new QListView( tabContents, "listView" ); |
100 | listView->addColumn( tr( "Contents" ) ); |
||
101 | listView->addColumn( tr( "Link" ) , 0 ); |
||
560 | cbradney | 102 | listView->setSorting(-1,-1); |
103 | listView->setRootIsDecorated( true ); |
||
104 | listView->setSelectionMode(QListView::Single); |
||
105 | listView->setDefaultRenameAction(QListView::Reject); |
||
106 | listView->clear(); |
||
564 | cbradney | 107 | tabLayout->addWidget( listView ); |
108 | |||
109 | tabWidget->insertTab( tabContents, QString("Contents") ); |
||
110 | helpBrowserLayout->addWidget( tabWidget ); |
||
560 | cbradney | 111 | |
564 | cbradney | 112 | textBrowser = new QTextBrowser( this, "textBrowser" ); |
113 | textBrowser->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)7, (QSizePolicy::SizeType)7, 2, 0, textBrowser->sizePolicy().hasHeightForWidth() ) ); |
||
114 | textBrowser->setFrameShape( QTextBrowser::StyledPanel ); |
||
115 | helpBrowserLayout->addWidget( textBrowser ); |
||
116 | helpBrowsermainLayout->addLayout( helpBrowserLayout ); |
||
560 | cbradney | 117 | |
564 | cbradney | 118 | languageChange(); |
119 | resize( QSize(602, 491).expandedTo(minimumSizeHint()) ); |
||
120 | clearWState( WState_Polished ); |
||
560 | cbradney | 121 | loadMenu(); |
122 | listView->header()->hide(); |
||
564 | cbradney | 123 | jumpToHelpSection( guiLanguage, jumpToSection, jumpToFile ); |
560 | cbradney | 124 | |
125 | connect( homeButton, SIGNAL( clicked() ), textBrowser, SLOT( home() ) ); |
||
126 | connect( forwButton, SIGNAL( clicked() ), textBrowser, SLOT( forward() ) ); |
||
127 | connect( backButton, SIGNAL( clicked() ), textBrowser, SLOT( backward() ) ); |
||
564 | cbradney | 128 | connect( histMenu, SIGNAL(activated(int)), this, SLOT(histChosen(int))); |
129 | connect( listView, SIGNAL(clicked( QListViewItem *)), this, SLOT(itemSelected( QListViewItem *))); |
||
560 | cbradney | 130 | } |
131 | |||
132 | HelpBrowser::~HelpBrowser() |
||
133 | { |
||
564 | cbradney | 134 | // no need to delete child widgets, Qt does it all for us |
560 | cbradney | 135 | } |
136 | |||
137 | void HelpBrowser::languageChange() |
||
138 | { |
||
564 | cbradney | 139 | setCaption( tr( "Scribus Online Help" ) ); |
140 | listView->header()->setLabel( 0, tr( "Contents" ) ); |
||
141 | listView->clear(); |
||
560 | cbradney | 142 | |
564 | cbradney | 143 | tabWidget->changeTab( tabContents, tr( "Contents" ) ); |
560 | cbradney | 144 | // tabWidget->changeTab( tab_2, tr( "Tab 2" ) ); |
145 | } |
||
146 | |||
147 | |||
148 | void HelpBrowser::sourceChanged(const QString& url) |
||
149 | { |
||
564 | cbradney | 150 | bool inList = false; |
151 | struct histd his; |
||
152 | QString title = ""; |
||
153 | title = textBrowser->documentTitle(); |
||
154 | if (title == "") |
||
155 | title = url; |
||
156 | QMap<int, histd>::Iterator it; |
||
157 | for (it = mHistory.begin(); it != mHistory.end(); ++it) |
||
158 | { |
||
159 | if (it.data().Title == title) |
||
160 | inList = true; |
||
161 | } |
||
162 | if (!inList) |
||
163 | { |
||
164 | his.Title = title; |
||
165 | his.Url = url; |
||
166 | mHistory[histMenu->insertItem(title)] = his; |
||
167 | } |
||
168 | if (mHistory.count() > 15) |
||
169 | { |
||
170 | int itk = histMenu->idAt(0); |
||
171 | mHistory.remove(itk); |
||
172 | histMenu->removeItem(itk); |
||
173 | } |
||
560 | cbradney | 174 | } |
175 | |||
176 | void HelpBrowser::histChosen(int i) |
||
177 | { |
||
564 | cbradney | 178 | if (mHistory.contains(i)) |
179 | textBrowser->setSource(mHistory[i].Url); |
||
560 | cbradney | 180 | } |
181 | |||
564 | cbradney | 182 | void HelpBrowser::jumpToHelpSection(QString guiLanguage, QString jumpToSection, QString jumpToFile) |
560 | cbradney | 183 | { |
184 | QString toLoad; |
||
185 | |||
564 | cbradney | 186 | if (guiLanguage=="") |
187 | { |
||
560 | cbradney | 188 | qDebug("Error: No help language found."); |
189 | guiLanguage="en"; |
||
190 | } |
||
564 | cbradney | 191 | if (jumpToFile=="") |
192 | { |
||
193 | QString pfad = PREL; |
||
194 | toLoad = pfad + "/share/scribus/doc/"; |
||
195 | toLoad += guiLanguage.left(2) + "/"; //clean this later to handle 5 char locales |
||
196 | if (jumpToSection=="") |
||
197 | { |
||
560 | cbradney | 198 | toLoad+="index.html"; |
199 | listView->setSelected( listView->firstChild(), true ); |
||
205 | Franz | 200 | } |
564 | cbradney | 201 | else if (jumpToSection=="scripter") |
202 | { |
||
560 | cbradney | 203 | toLoad+="scripter1.html"; |
204 | QListViewItemIterator it(listView); |
||
564 | cbradney | 205 | while (it.current()) |
206 | { |
||
560 | cbradney | 207 | if (it.current()->text(1)=="scripter1.html") |
208 | listView->setSelected( it.current(), true ); |
||
209 | if (it.current()->text(1)=="developers.html") |
||
210 | it.current()->setOpen( true ); |
||
211 | ++it; |
||
212 | } |
||
213 | } |
||
205 | Franz | 214 | } |
560 | cbradney | 215 | else |
564 | cbradney | 216 | toLoad=jumpToFile; |
3 | paul | 217 | |
560 | cbradney | 218 | loadHelp(toLoad); |
3 | paul | 219 | } |
220 | |||
560 | cbradney | 221 | void HelpBrowser::loadHelp(QString filename) |
68 | Franz | 222 | { |
75 | Franz | 223 | struct histd his; |
564 | cbradney | 224 | bool Avail = true; |
560 | cbradney | 225 | QString toLoad; |
564 | cbradney | 226 | QFileInfo fi; |
227 | fi = QFileInfo(filename); |
||
228 | if (fi.exists()) |
||
560 | cbradney | 229 | toLoad=filename; |
564 | cbradney | 230 | else |
231 | { |
||
232 | QString pfad = PREL; |
||
233 | toLoad = pfad + "/share/scribus/doc/en/index.html"; |
||
234 | fi = QFileInfo(toLoad); |
||
235 | if (!fi.exists()) |
||
236 | { |
||
237 | textBrowser->setText("<h2>"+ tr("Sorry, no manual available! Please see: http://docs.scribus.net for updated docs\nand www.scribus.net for downloads.")+"</h2>"); |
||
238 | Avail = false; |
||
239 | } |
||
240 | } |
||
241 | if (Avail) |
||
242 | { |
||
243 | textBrowser->setSource(toLoad); |
||
244 | his.Title = textBrowser->documentTitle(); |
||
245 | if (his.Title == "") |
||
246 | his.Title = toLoad; |
||
247 | his.Url = toLoad; |
||
248 | mHistory[histMenu->insertItem(his.Title)] = his; |
||
249 | } |
||
560 | cbradney | 250 | } |
251 | |||
252 | void HelpBrowser::loadMenu() |
||
253 | { |
||
564 | cbradney | 254 | QString pfad = PREL; |
255 | QString pfad2; |
||
256 | bool Avail = true; |
||
560 | cbradney | 257 | pfad2 = pfad + "/share/scribus/doc/"+QString(QTextCodec::locale()).left(2)+"/menu.xml"; |
258 | pfad2 = pfad + "/share/scribus/doc/en/menu.xml"; |
||
259 | |||
564 | cbradney | 260 | QFileInfo fi = QFileInfo(pfad2); |
560 | cbradney | 261 | if (fi.exists()) |
564 | cbradney | 262 | { |
560 | cbradney | 263 | textBrowser->setText("menu found"); |
264 | QDomDocument doc( "menuentries" ); |
||
265 | QFile file( pfad2 ); |
||
266 | if ( !file.open( IO_ReadOnly ) ) |
||
267 | return; |
||
564 | cbradney | 268 | if ( !doc.setContent( &file ) ) |
269 | { |
||
560 | cbradney | 270 | file.close(); |
271 | return; |
||
272 | } |
||
273 | file.close(); |
||
274 | |||
275 | QDomElement docElem = doc.documentElement(); |
||
276 | QDomNode n = docElem.firstChild(); |
||
277 | QListViewItem *qlvi=NULL, *qlvi2=NULL, *qlvi3=NULL, *qlvi4=NULL, *qlvi5=NULL, *qlvi6=NULL; |
||
278 | |||
564 | cbradney | 279 | while( !n.isNull() ) |
280 | { |
||
560 | cbradney | 281 | QDomElement e = n.toElement(); // try to convert the node to an element. |
564 | cbradney | 282 | if( !e.isNull() ) |
283 | { |
||
284 | if (e.hasAttribute( "text" ) && e.hasAttribute( "file" )) |
||
285 | { |
||
560 | cbradney | 286 | QDomAttr textAttr = e.attributeNode( "text" ); |
287 | QDomAttr fileAttr = e.attributeNode( "file" ); |
||
288 | if (qlvi2==NULL) |
||
289 | qlvi=new QListViewItem(listView, textAttr.value(), fileAttr.value()); |
||
564 | cbradney | 290 | else |
291 | { |
||
560 | cbradney | 292 | qlvi=new QListViewItem(listView, qlvi2); |
564 | cbradney | 293 | if (qlvi!=NULL) |
294 | { |
||
560 | cbradney | 295 | qlvi->setText(0, textAttr.value()); |
296 | qlvi->setText(1, fileAttr.value()); |
||
297 | } |
||
298 | } |
||
299 | if (qlvi!=NULL) |
||
300 | qlvi2=qlvi; |
||
301 | } |
||
302 | |||
303 | QDomNodeList nl=n.childNodes(); |
||
564 | cbradney | 304 | for(uint i=0 ; i<= nl.count() ; i++) |
305 | { |
||
560 | cbradney | 306 | QDomNode child=nl.item(i); |
564 | cbradney | 307 | if (child.isElement()) |
308 | { |
||
560 | cbradney | 309 | QDomElement ec = child.toElement(); |
564 | cbradney | 310 | if (!ec.isNull()) |
311 | { |
||
312 | if (ec.hasAttribute( "text" ) && ec.hasAttribute( "file" )) |
||
313 | { |
||
560 | cbradney | 314 | QDomAttr textAttr = ec.attributeNode( "text" ); |
315 | QDomAttr fileAttr = ec.attributeNode( "file" ); |
||
316 | if (qlvi4==NULL) |
||
317 | qlvi3=new QListViewItem(qlvi, textAttr.value(), fileAttr.value()); |
||
564 | cbradney | 318 | else |
319 | { |
||
560 | cbradney | 320 | qlvi3=new QListViewItem(qlvi, qlvi4); |
564 | cbradney | 321 | if (qlvi3!=NULL) |
322 | { |
||
560 | cbradney | 323 | qlvi3->setText(0, textAttr.value()); |
324 | qlvi3->setText(1, fileAttr.value()); |
||
325 | } |
||
326 | } |
||
327 | if (qlvi3!=NULL) |
||
328 | qlvi4=qlvi3; |
||
329 | } |
||
330 | //3rd level |
||
331 | QDomNodeList nl2=child.childNodes(); |
||
564 | cbradney | 332 | for(uint i=0 ; i<= nl2.count() ; i++) |
333 | { |
||
560 | cbradney | 334 | QDomNode childchild=nl2.item(i); |
564 | cbradney | 335 | if (childchild.isElement()) |
336 | { |
||
560 | cbradney | 337 | QDomElement ecc = childchild.toElement(); |
564 | cbradney | 338 | if (!ecc.isNull()) |
339 | { |
||
340 | if (ecc.hasAttribute( "text" ) && ecc.hasAttribute( "file" )) |
||
341 | { |
||
560 | cbradney | 342 | QDomAttr textAttr = ecc.attributeNode( "text" ); |
343 | QDomAttr fileAttr = ecc.attributeNode( "file" ); |
||
344 | if (qlvi6==NULL) |
||
345 | qlvi5=new QListViewItem(qlvi3, textAttr.value(), fileAttr.value()); |
||
564 | cbradney | 346 | else |
347 | { |
||
560 | cbradney | 348 | qlvi5=new QListViewItem(qlvi3, qlvi6); |
564 | cbradney | 349 | if (qlvi5!=NULL) |
350 | { |
||
560 | cbradney | 351 | qlvi5->setText(0, textAttr.value()); |
352 | qlvi5->setText(1, fileAttr.value()); |
||
353 | } |
||
354 | } |
||
355 | } |
||
356 | if (qlvi5!=NULL) |
||
357 | qlvi6=qlvi5; |
||
358 | } |
||
359 | } |
||
360 | } |
||
361 | } |
||
362 | } |
||
363 | } |
||
364 | } |
||
365 | n = n.nextSibling(); |
||
366 | } |
||
205 | Franz | 367 | } |
68 | Franz | 368 | } |
369 | |||
560 | cbradney | 370 | void HelpBrowser::itemSelected(QListViewItem *item) |
68 | Franz | 371 | { |
564 | cbradney | 372 | QString pfad = PREL; |
560 | cbradney | 373 | if ( !item ) |
374 | return; |
||
375 | else if (item->text(1)!=QString::null) |
||
376 | loadHelp(pfad + "/share/scribus/doc/en/"+item->text(1)); |
||
68 | Franz | 377 | } |