Rev 663 | Rev 793 | 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> |
786 | cbradney | 41 | #include <qsplitter.h> |
128 | Franz | 42 | |
617 | cbradney | 43 | #ifdef _MSC_VER |
44 | #if (_MSC_VER >= 1200) |
||
45 | #include "win-config.h" |
||
46 | #endif |
||
128 | Franz | 47 | #else |
617 | cbradney | 48 | #include "config.h" |
128 | Franz | 49 | #endif |
50 | |||
3 | paul | 51 | extern QPixmap loadIcon(QString nam); |
52 | |||
560 | cbradney | 53 | |
564 | cbradney | 54 | HelpBrowser::HelpBrowser( QWidget* parent, QString caption, QString guiLanguage, QString jumpToSection, QString jumpToFile) |
55 | : QWidget( parent, "Help", WType_TopLevel | WDestructiveClose ) |
||
3 | paul | 56 | { |
560 | cbradney | 57 | QString fileName; |
564 | cbradney | 58 | mHistory.clear(); |
59 | struct histd his; |
||
3 | paul | 60 | |
564 | cbradney | 61 | helpBrowsermainLayout = new QVBoxLayout( this); |
62 | buttonLayout = new QHBoxLayout; |
||
63 | buttonLayout->setSpacing( 6 ); |
||
64 | buttonLayout->setMargin( 2 ); |
||
3 | paul | 65 | |
564 | cbradney | 66 | homeButton = new QToolButton( this, "homeButton" ); |
67 | homeButton->setText( "" ); |
||
68 | homeButton->setPixmap(loadIcon("gohome.png")); |
||
786 | cbradney | 69 | homeButton->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed, homeButton->sizePolicy().hasHeightForWidth() ) ); |
564 | cbradney | 70 | buttonLayout->addWidget( homeButton ); |
3 | paul | 71 | |
564 | cbradney | 72 | histMenu = new QPopupMenu( this ); |
73 | backButton = new QToolButton( this, "backButton" ); |
||
74 | backButton->setPixmap(loadIcon("back.png")); |
||
786 | cbradney | 75 | backButton->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed, backButton->sizePolicy().hasHeightForWidth() ) ); |
564 | cbradney | 76 | backButton->setPopup(histMenu); |
77 | backButton->setPopupDelay(0); |
||
78 | buttonLayout->addWidget( backButton ); |
||
3 | paul | 79 | |
564 | cbradney | 80 | forwButton = new QToolButton( this, "forwButton" ); |
81 | forwButton->setPixmap(loadIcon("forward.png")); |
||
786 | cbradney | 82 | forwButton->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed, forwButton->sizePolicy().hasHeightForWidth() ) ); |
564 | cbradney | 83 | buttonLayout->addWidget( forwButton ); |
84 | QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ); |
||
85 | buttonLayout->addItem( spacer ); |
||
560 | cbradney | 86 | helpBrowsermainLayout->addLayout( buttonLayout ); |
87 | |||
564 | cbradney | 88 | helpBrowserLayout = new QHBoxLayout; |
786 | cbradney | 89 | splitter = new QSplitter(this, "splitter"); |
90 | splitter->setChildrenCollapsible( false ); |
||
91 | helpBrowserLayout->addWidget( splitter ); |
||
560 | cbradney | 92 | |
786 | cbradney | 93 | tabWidget = new QTabWidget( splitter, "tabWidget" ); |
94 | //tabWidget = new QTabWidget( this, "tabWidget" ); |
||
95 | splitter->setResizeMode(tabWidget, QSplitter::Stretch ); |
||
96 | tabWidget->setSizePolicy( QSizePolicy( QSizePolicy::Maximum, QSizePolicy::Expanding, false) ); |
||
564 | cbradney | 97 | tabContents = new QWidget( tabWidget, "tabContents" ); |
98 | tabLayout = new QHBoxLayout( tabContents, 11, 6, "tabLayout"); |
||
560 | cbradney | 99 | |
564 | cbradney | 100 | listView = new QListView( tabContents, "listView" ); |
101 | listView->addColumn( tr( "Contents" ) ); |
||
102 | listView->addColumn( tr( "Link" ) , 0 ); |
||
786 | cbradney | 103 | listView->setColumnWidthMode( 0, QListView::Maximum ); |
104 | listView->setColumnWidthMode( 1, QListView::Manual ); |
||
560 | cbradney | 105 | listView->setSorting(-1,-1); |
106 | listView->setRootIsDecorated( true ); |
||
107 | listView->setSelectionMode(QListView::Single); |
||
108 | listView->setDefaultRenameAction(QListView::Reject); |
||
109 | listView->clear(); |
||
564 | cbradney | 110 | tabLayout->addWidget( listView ); |
111 | |||
112 | tabWidget->insertTab( tabContents, QString("Contents") ); |
||
786 | cbradney | 113 | //helpBrowserLayout->addWidget( tabWidget ); |
560 | cbradney | 114 | |
786 | cbradney | 115 | textBrowser = new QTextBrowser( splitter, "textBrowser" ); |
116 | splitter->setResizeMode(textBrowser, QSplitter::Stretch); |
||
117 | //textBrowser = new QTextBrowser( this, "textBrowser" ); |
||
118 | textBrowser->setSizePolicy( QSizePolicy( QSizePolicy::Ignored, QSizePolicy::Expanding, false ) ); |
||
564 | cbradney | 119 | textBrowser->setFrameShape( QTextBrowser::StyledPanel ); |
786 | cbradney | 120 | //helpBrowserLayout->addWidget( textBrowser ); |
564 | cbradney | 121 | helpBrowsermainLayout->addLayout( helpBrowserLayout ); |
560 | cbradney | 122 | |
564 | cbradney | 123 | languageChange(); |
124 | resize( QSize(602, 491).expandedTo(minimumSizeHint()) ); |
||
125 | clearWState( WState_Polished ); |
||
786 | cbradney | 126 | loadMenu( guiLanguage ); |
560 | cbradney | 127 | listView->header()->hide(); |
564 | cbradney | 128 | jumpToHelpSection( guiLanguage, jumpToSection, jumpToFile ); |
560 | cbradney | 129 | |
130 | connect( homeButton, SIGNAL( clicked() ), textBrowser, SLOT( home() ) ); |
||
131 | connect( forwButton, SIGNAL( clicked() ), textBrowser, SLOT( forward() ) ); |
||
132 | connect( backButton, SIGNAL( clicked() ), textBrowser, SLOT( backward() ) ); |
||
564 | cbradney | 133 | connect( histMenu, SIGNAL(activated(int)), this, SLOT(histChosen(int))); |
134 | connect( listView, SIGNAL(clicked( QListViewItem *)), this, SLOT(itemSelected( QListViewItem *))); |
||
560 | cbradney | 135 | } |
136 | |||
137 | HelpBrowser::~HelpBrowser() |
||
138 | { |
||
564 | cbradney | 139 | // no need to delete child widgets, Qt does it all for us |
560 | cbradney | 140 | } |
141 | |||
142 | void HelpBrowser::languageChange() |
||
143 | { |
||
564 | cbradney | 144 | setCaption( tr( "Scribus Online Help" ) ); |
145 | listView->header()->setLabel( 0, tr( "Contents" ) ); |
||
146 | listView->clear(); |
||
560 | cbradney | 147 | |
564 | cbradney | 148 | tabWidget->changeTab( tabContents, tr( "Contents" ) ); |
560 | cbradney | 149 | } |
150 | |||
151 | |||
152 | void HelpBrowser::sourceChanged(const QString& url) |
||
153 | { |
||
564 | cbradney | 154 | bool inList = false; |
155 | struct histd his; |
||
156 | QString title = ""; |
||
157 | title = textBrowser->documentTitle(); |
||
158 | if (title == "") |
||
159 | title = url; |
||
786 | cbradney | 160 | for (QMap<int, histd>::Iterator it = mHistory.begin(); it != mHistory.end(); ++it) |
564 | cbradney | 161 | { |
162 | if (it.data().Title == title) |
||
163 | inList = true; |
||
164 | } |
||
165 | if (!inList) |
||
166 | { |
||
167 | his.Title = title; |
||
168 | his.Url = url; |
||
169 | mHistory[histMenu->insertItem(title)] = his; |
||
170 | } |
||
171 | if (mHistory.count() > 15) |
||
172 | { |
||
173 | int itk = histMenu->idAt(0); |
||
174 | mHistory.remove(itk); |
||
175 | histMenu->removeItem(itk); |
||
176 | } |
||
560 | cbradney | 177 | } |
178 | |||
179 | void HelpBrowser::histChosen(int i) |
||
180 | { |
||
564 | cbradney | 181 | if (mHistory.contains(i)) |
182 | textBrowser->setSource(mHistory[i].Url); |
||
560 | cbradney | 183 | } |
184 | |||
786 | cbradney | 185 | void HelpBrowser::jumpToHelpSection(const QString newGuiLanguage, QString jumpToSection, QString jumpToFile) |
560 | cbradney | 186 | { |
187 | QString toLoad; |
||
786 | cbradney | 188 | QString guiLanguage = newGuiLanguage=="" ? "en" : newGuiLanguage; |
560 | cbradney | 189 | |
564 | cbradney | 190 | if (jumpToFile=="") |
191 | { |
||
192 | QString pfad = PREL; |
||
786 | cbradney | 193 | toLoad = pfad + "/share/scribus/doc/" + guiLanguage.left(2) + "/"; //clean this later to handle 5 char locales |
564 | cbradney | 194 | if (jumpToSection=="") |
195 | { |
||
560 | cbradney | 196 | toLoad+="index.html"; |
197 | listView->setSelected( listView->firstChild(), true ); |
||
205 | Franz | 198 | } |
564 | cbradney | 199 | else if (jumpToSection=="scripter") |
200 | { |
||
560 | cbradney | 201 | toLoad+="scripter1.html"; |
202 | QListViewItemIterator it(listView); |
||
564 | cbradney | 203 | while (it.current()) |
204 | { |
||
560 | cbradney | 205 | if (it.current()->text(1)=="scripter1.html") |
206 | listView->setSelected( it.current(), true ); |
||
207 | if (it.current()->text(1)=="developers.html") |
||
208 | it.current()->setOpen( true ); |
||
209 | ++it; |
||
210 | } |
||
211 | } |
||
205 | Franz | 212 | } |
560 | cbradney | 213 | else |
564 | cbradney | 214 | toLoad=jumpToFile; |
3 | paul | 215 | |
560 | cbradney | 216 | loadHelp(toLoad); |
3 | paul | 217 | } |
218 | |||
560 | cbradney | 219 | void HelpBrowser::loadHelp(QString filename) |
68 | Franz | 220 | { |
75 | Franz | 221 | struct histd his; |
564 | cbradney | 222 | bool Avail = true; |
560 | cbradney | 223 | QString toLoad; |
564 | cbradney | 224 | QFileInfo fi; |
225 | fi = QFileInfo(filename); |
||
226 | if (fi.exists()) |
||
560 | cbradney | 227 | toLoad=filename; |
564 | cbradney | 228 | else |
229 | { |
||
230 | QString pfad = PREL; |
||
231 | toLoad = pfad + "/share/scribus/doc/en/index.html"; |
||
232 | fi = QFileInfo(toLoad); |
||
233 | if (!fi.exists()) |
||
234 | { |
||
235 | textBrowser->setText("<h2>"+ tr("Sorry, no manual available! Please see: http://docs.scribus.net for updated docs\nand www.scribus.net for downloads.")+"</h2>"); |
||
236 | Avail = false; |
||
237 | } |
||
238 | } |
||
239 | if (Avail) |
||
240 | { |
||
241 | textBrowser->setSource(toLoad); |
||
242 | his.Title = textBrowser->documentTitle(); |
||
243 | if (his.Title == "") |
||
244 | his.Title = toLoad; |
||
245 | his.Url = toLoad; |
||
246 | mHistory[histMenu->insertItem(his.Title)] = his; |
||
247 | } |
||
560 | cbradney | 248 | } |
249 | |||
786 | cbradney | 250 | void HelpBrowser::loadMenu(const QString newGuiLanguage) |
560 | cbradney | 251 | { |
564 | cbradney | 252 | QString pfad = PREL; |
786 | cbradney | 253 | QString toLoad; |
254 | QString guiLanguage = newGuiLanguage=="" ? "en" : newGuiLanguage; |
||
560 | cbradney | 255 | |
786 | cbradney | 256 | QString baseDir = "/share/scribus/doc/"; |
257 | QString pfad2 = pfad + baseDir + guiLanguage.left(2) + "/menu.xml"; |
||
258 | |||
564 | cbradney | 259 | QFileInfo fi = QFileInfo(pfad2); |
786 | cbradney | 260 | |
261 | if (fi.exists()) |
||
262 | toLoad=pfad2; |
||
263 | else |
||
264 | { |
||
265 | toLoad = pfad + baseDir + "en/menu.xml"; |
||
266 | fi = QFileInfo(toLoad); |
||
267 | qDebug("Scribus help in your selected language does not exist, trying English. Otherwise, please visit http://docs.scribus.net."); |
||
268 | } |
||
269 | |||
560 | cbradney | 270 | if (fi.exists()) |
564 | cbradney | 271 | { |
560 | cbradney | 272 | QDomDocument doc( "menuentries" ); |
786 | cbradney | 273 | QFile file( toLoad ); |
560 | cbradney | 274 | if ( !file.open( IO_ReadOnly ) ) |
275 | return; |
||
564 | cbradney | 276 | if ( !doc.setContent( &file ) ) |
277 | { |
||
560 | cbradney | 278 | file.close(); |
279 | return; |
||
280 | } |
||
281 | file.close(); |
||
282 | |||
283 | QDomElement docElem = doc.documentElement(); |
||
284 | QDomNode n = docElem.firstChild(); |
||
285 | QListViewItem *qlvi=NULL, *qlvi2=NULL, *qlvi3=NULL, *qlvi4=NULL, *qlvi5=NULL, *qlvi6=NULL; |
||
286 | |||
564 | cbradney | 287 | while( !n.isNull() ) |
288 | { |
||
560 | cbradney | 289 | QDomElement e = n.toElement(); // try to convert the node to an element. |
564 | cbradney | 290 | if( !e.isNull() ) |
291 | { |
||
292 | if (e.hasAttribute( "text" ) && e.hasAttribute( "file" )) |
||
293 | { |
||
560 | cbradney | 294 | QDomAttr textAttr = e.attributeNode( "text" ); |
295 | QDomAttr fileAttr = e.attributeNode( "file" ); |
||
296 | if (qlvi2==NULL) |
||
297 | qlvi=new QListViewItem(listView, textAttr.value(), fileAttr.value()); |
||
564 | cbradney | 298 | else |
299 | { |
||
560 | cbradney | 300 | qlvi=new QListViewItem(listView, qlvi2); |
564 | cbradney | 301 | if (qlvi!=NULL) |
302 | { |
||
560 | cbradney | 303 | qlvi->setText(0, textAttr.value()); |
304 | qlvi->setText(1, fileAttr.value()); |
||
305 | } |
||
306 | } |
||
307 | if (qlvi!=NULL) |
||
308 | qlvi2=qlvi; |
||
309 | } |
||
310 | |||
311 | QDomNodeList nl=n.childNodes(); |
||
564 | cbradney | 312 | for(uint i=0 ; i<= nl.count() ; i++) |
313 | { |
||
560 | cbradney | 314 | QDomNode child=nl.item(i); |
564 | cbradney | 315 | if (child.isElement()) |
316 | { |
||
560 | cbradney | 317 | QDomElement ec = child.toElement(); |
564 | cbradney | 318 | if (!ec.isNull()) |
319 | { |
||
320 | if (ec.hasAttribute( "text" ) && ec.hasAttribute( "file" )) |
||
321 | { |
||
560 | cbradney | 322 | QDomAttr textAttr = ec.attributeNode( "text" ); |
323 | QDomAttr fileAttr = ec.attributeNode( "file" ); |
||
324 | if (qlvi4==NULL) |
||
325 | qlvi3=new QListViewItem(qlvi, textAttr.value(), fileAttr.value()); |
||
564 | cbradney | 326 | else |
327 | { |
||
560 | cbradney | 328 | qlvi3=new QListViewItem(qlvi, qlvi4); |
564 | cbradney | 329 | if (qlvi3!=NULL) |
330 | { |
||
560 | cbradney | 331 | qlvi3->setText(0, textAttr.value()); |
332 | qlvi3->setText(1, fileAttr.value()); |
||
333 | } |
||
334 | } |
||
335 | if (qlvi3!=NULL) |
||
336 | qlvi4=qlvi3; |
||
337 | } |
||
338 | //3rd level |
||
339 | QDomNodeList nl2=child.childNodes(); |
||
564 | cbradney | 340 | for(uint i=0 ; i<= nl2.count() ; i++) |
341 | { |
||
560 | cbradney | 342 | QDomNode childchild=nl2.item(i); |
564 | cbradney | 343 | if (childchild.isElement()) |
344 | { |
||
560 | cbradney | 345 | QDomElement ecc = childchild.toElement(); |
564 | cbradney | 346 | if (!ecc.isNull()) |
347 | { |
||
348 | if (ecc.hasAttribute( "text" ) && ecc.hasAttribute( "file" )) |
||
349 | { |
||
560 | cbradney | 350 | QDomAttr textAttr = ecc.attributeNode( "text" ); |
351 | QDomAttr fileAttr = ecc.attributeNode( "file" ); |
||
352 | if (qlvi6==NULL) |
||
353 | qlvi5=new QListViewItem(qlvi3, textAttr.value(), fileAttr.value()); |
||
564 | cbradney | 354 | else |
355 | { |
||
560 | cbradney | 356 | qlvi5=new QListViewItem(qlvi3, qlvi6); |
564 | cbradney | 357 | if (qlvi5!=NULL) |
358 | { |
||
560 | cbradney | 359 | qlvi5->setText(0, textAttr.value()); |
360 | qlvi5->setText(1, fileAttr.value()); |
||
361 | } |
||
362 | } |
||
363 | } |
||
364 | if (qlvi5!=NULL) |
||
365 | qlvi6=qlvi5; |
||
366 | } |
||
367 | } |
||
368 | } |
||
369 | } |
||
370 | } |
||
371 | } |
||
372 | } |
||
373 | n = n.nextSibling(); |
||
374 | } |
||
205 | Franz | 375 | } |
68 | Franz | 376 | } |
377 | |||
560 | cbradney | 378 | void HelpBrowser::itemSelected(QListViewItem *item) |
68 | Franz | 379 | { |
564 | cbradney | 380 | QString pfad = PREL; |
560 | cbradney | 381 | if ( !item ) |
382 | return; |
||
383 | else if (item->text(1)!=QString::null) |
||
384 | loadHelp(pfad + "/share/scribus/doc/en/"+item->text(1)); |
||
68 | Franz | 385 | } |