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